From e6a5a8d9cd20004e42f133c3fe12dc89032af21b Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sat, 31 Aug 2019 12:02:02 +0200 Subject: [PATCH] =?UTF-8?q?[Helm]=20Move=20code=20of=20=E2=80=98db/helm-sh?= =?UTF-8?q?ortcuts=E2=80=99=20directly=20to=20init.el?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes ‘db-helm’ obsolete again (already after one commit!). The function to extract all files from ‘db/important-path’ has also been dropped in favor of the standard ‘directory-files-recursively’. It’s not clear yet whether this will also work on Windows, though. --- init.el | 75 ++++++++++++++++++++++++++++++-------------- site-lisp/db-helm.el | 59 ---------------------------------- 2 files changed, 51 insertions(+), 83 deletions(-) delete mode 100644 site-lisp/db-helm.el diff --git a/init.el b/init.el index 027e180..88a0ac7 100644 --- a/init.el +++ b/init.el @@ -562,30 +562,8 @@ db/org-onenote-open db/org-outlook-open db/org-rfc-open - db/dired-from-shell-command)) - -(defcustom db/frequently-used-features - '(("Mail" . db/gnus) - ("Agenda" . db/org-agenda) - ("Init File" . db/find-user-init-file) - ("EMMS" . emms) - ("Shell" . shell) - ("EShell" . eshell) - ("scratch" . db/scratch)) - "Mapping of frequently used features to functions implementing -them. Can be used in application shortcuts such as -`db/helm-shortcuts’." - :group 'personal-settings - :type '(alist :key-type string :value-type sexp)) - -(defcustom db/important-documents-path "~/Documents/library/" - "Path to look for documents that can be listed in extended -search commands like `db/helm-shortcuts’." - :group 'personal-settings - :type 'string) - -(use-package db-helm - :commands (db/helm-shortcuts)) + db/dired-from-shell-command + db/system-open)) (use-package hydra :commands (defhydra)) @@ -636,6 +614,55 @@ search commands like `db/helm-shortcuts’." (use-package exec-path-from-shell :commands (exec-path-from-shell-copy-envs)) + +;; * Start Menu via Helm + +(defcustom db/frequently-used-features + '(("Mail" . db/gnus) + ("Agenda" . db/org-agenda) + ("Init File" . db/find-user-init-file) + ("EMMS" . emms) + ("Shell" . shell) + ("EShell" . eshell) + ("scratch" . db/scratch)) + "Mapping of frequently used features to functions implementing +them. Can be used in application shortcuts such as +`db/helm-shortcuts’." + :group 'personal-settings + :type '(alist :key-type string :value-type sexp)) + +(defcustom db/important-documents-path "~/Documents/library/" + "Path to look for documents that can be listed in extended +search commands like `db/helm-shortcuts’." + :group 'personal-settings + :type 'string) + +(defun db/helm-shortcuts (arg) + "Open helm completion on common locations. +With given ARG, display files in `db/important-document-path’." + (interactive "p") + (require 'helm-bookmark) + (helm :sources (list + (helm-make-source "Frequently Used" 'helm-source-sync + :candidates #'db/frequently-used-features + :action '(("Open" . funcall)) + :filtered-candidate-transformer #'helm-adaptive-sort) + + helm-source-bookmarks + helm-source-bookmark-set + + ;; if prefix arg is given, extrac files from + ;; `db/important-documents-path’ and list them as well + (when (and (= arg 4) + (file-directory-p db/important-documents-path)) + (let ((search-path (expand-file-name db/important-documents-path))) + (helm-make-source "Important files" 'helm-source-sync + :candidates (mapcar #'(lambda (file) + (string-remove-prefix search-path file)) + (directory-files-recursively search-path "")) + :action '(("Open externally" . db/system-open) + ("Find file" . find-file)))))))) + ;; * Org diff --git a/site-lisp/db-helm.el b/site-lisp/db-helm.el deleted file mode 100644 index 11dbb9e..0000000 --- a/site-lisp/db-helm.el +++ /dev/null @@ -1,59 +0,0 @@ -(require 'helm-files) -(require 'helm-bookmark) -(require 'helm-source) -(require 'helm) - -(defvar db/helm-source-frequently-used-features - (helm-make-source "Frequently Used" 'helm-source-sync - :candidates #'db/frequently-used-features - :action '(("Open" . funcall)) - :filtered-candidate-transformer #'helm-adaptive-sort) ; effect? - "Helm source for `db/helm-frequently-used-features’.") - -(defun db/important-documents () - "Recursively return paths of all files found in `db/important-documents-path’. -The result will be a list of cons cells, where the car is the -path relative to `db/important-documents’ and the cdr is the full -path." - ;; code adapted from `directory-files-recursively’ - (let ((db/important-documents-path (expand-file-name db/important-documents-path))) - (cl-labels ((all-files-in-dir (dir) - (let ((result nil) - (files nil)) - (dolist (file (sort (file-name-all-completions "" dir) - 'string<)) - (unless (eq ?. (aref file 0)) ; omit hidden files - (if (directory-name-p file) - (let* ((leaf (substring file 0 (1- (length file)))) - (full-file (expand-file-name leaf dir))) - ;; Don't follow symlinks to other directories. - (unless (file-symlink-p full-file) - (setq result - (nconc result (all-files-in-dir full-file))))) - (push (cons - (string-remove-prefix db/important-documents-path - (expand-file-name file dir)) - (expand-file-name file dir)) - files)))) - (nconc result (nreverse files))))) - (when (file-directory-p db/important-documents-path) - (all-files-in-dir db/important-documents-path))))) - -(defvar db/helm-source-important-documents - (helm-make-source "Important files" 'helm-source-sync - :candidates #'db/important-documents - :action '(("Open externally" . db/system-open) - ("Find file" . find-file))) - "Helm source for important documents.") - -(defun db/helm-shortcuts (arg) - "Open helm completion on common locations." - (interactive "p") - (helm :sources `(db/helm-source-frequently-used-features - ,(when (and (= arg 4) - (file-directory-p db/important-documents-path)) - 'db/helm-source-important-documents) - helm-source-bookmarks - helm-source-bookmark-set))) - -(provide 'db-helm)