[Helm] Move code of ‘db/helm-shortcuts’ directly to init.el

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.
This commit is contained in:
dbo 2019-08-31 12:02:02 +02:00
parent bbad4b7fd4
commit e6a5a8d9cd
No known key found for this signature in database
GPG Key ID: 1C7071A75BB72D64
2 changed files with 51 additions and 83 deletions

75
init.el
View File

@ -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

View File

@ -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)