[Helm] Speed up recursive directory traversal in helm shortcut
By copying and adapting the code of ‘directory-files-recursively’
This commit is contained in:
parent
a0b5d317a1
commit
26e44b1d55
|
@ -291,15 +291,32 @@ If FILE is not given, prompt for one."
|
||||||
:type 'string)
|
:type 'string)
|
||||||
|
|
||||||
(defun db/important-documents ()
|
(defun db/important-documents ()
|
||||||
"Recursively return paths of all important documents found in `db/important-documents-path’."
|
"Recursively return paths of all files found in `db/important-documents-path’.
|
||||||
(when (file-directory-p db/important-documents-path)
|
The result will be a list of cons cells, where the car is the
|
||||||
(delete-if ; FIXME: dump, make better
|
path relative to `db/important-documents’ and the cdr is the full
|
||||||
(lambda (spec)
|
path."
|
||||||
(eq ?. (elt (car spec) 0)))
|
;; code adapted from `directory-files-recursively’
|
||||||
(mapcar (lambda (path)
|
(cl-labels ((all-files-in-dir (dir)
|
||||||
(cons (string-remove-prefix db/important-documents-path path)
|
(let ((result nil)
|
||||||
path))
|
(files nil))
|
||||||
(directory-files-recursively db/important-documents-path "")))))
|
(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)
|
(defun db/system-open (path)
|
||||||
"Open PATH with default program as defined by the underlying system."
|
"Open PATH with default program as defined by the underlying system."
|
||||||
|
|
Loading…
Reference in New Issue