From bbad4b7fd40c6d4db0b62a33e97c5dfc28989042 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sat, 31 Aug 2019 11:39:04 +0200 Subject: [PATCH] =?UTF-8?q?[Helm]=20Move=20code=20for=20=E2=80=98db/helm-s?= =?UTF-8?q?hortcuts=E2=80=99=20to=20different=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This keeps ‘db-utils’ require-clean. --- init.el | 44 +++++++++++++++++--------------- site-lisp/db-helm.el | 59 +++++++++++++++++++++++++++++++++++++++++++ site-lisp/db-utils.el | 58 ------------------------------------------ 3 files changed, 82 insertions(+), 79 deletions(-) create mode 100644 site-lisp/db-helm.el diff --git a/init.el b/init.el index 7d4ced3..027e180 100644 --- a/init.el +++ b/init.el @@ -530,26 +530,6 @@ (use-package dash) -(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-utils :commands (endless/fill-or-unfill db/delete-trailing-whitespace-maybe @@ -559,7 +539,6 @@ search commands like `db/helm-shortcuts’." db/run-or-hide-shell db/run-or-hide-eshell db/run-or-hide-ansi-term - db/helm-shortcuts db/hex-to-ascii db/text-to-hex conditionally-enable-lispy @@ -585,6 +564,29 @@ search commands like `db/helm-shortcuts’." 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)) + (use-package hydra :commands (defhydra)) diff --git a/site-lisp/db-helm.el b/site-lisp/db-helm.el new file mode 100644 index 0000000..11dbb9e --- /dev/null +++ b/site-lisp/db-helm.el @@ -0,0 +1,59 @@ +(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) diff --git a/site-lisp/db-utils.el b/site-lisp/db-utils.el index a55ed0d..b8d0122 100644 --- a/site-lisp/db-utils.el +++ b/site-lisp/db-utils.el @@ -349,45 +349,6 @@ output, separated by \\n, when called with "\n")))) (dired (cons "Command output" list-of-files)))) - -;;; helm configuration - -(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) - "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))))) - (defun db/system-open (path) "Open PATH with default program as defined by the underlying system." (cond @@ -398,25 +359,6 @@ path." (t (start-process "" nil "xdg-open" 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") - (require 'helm-files) - (require 'helm-bookmark) - (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))) - ;;; Org Utilities