mirror of
https://github.com/protesilaos/denote.git
synced 2026-09-15 09:46:24 -04:00
Make 'denote-file-prompt' not choke on an empty 'denote-directory-files' return value
This commit is contained in:
parent
6a486173a5
commit
8b6c01915b
64
denote.el
64
denote.el
|
|
@ -1119,38 +1119,38 @@ file in the returned list."
|
|||
"Prompt for file with identifier in variable `denote-directory'.
|
||||
With optional FILES-MATCHING-REGEXP, filter the candidates per
|
||||
the given regular expression."
|
||||
(let* ((all-files (denote-directory-files files-matching-regexp :omit-current))
|
||||
(common-parent-directory
|
||||
(let ((common-prefix (try-completion "" all-files)))
|
||||
(if (> (length common-prefix) 0)
|
||||
(file-name-directory common-prefix))))
|
||||
(cpd-length (length common-parent-directory))
|
||||
(prompt (if (zerop cpd-length)
|
||||
"Select note: "
|
||||
(format "Select note in %s: " common-parent-directory)))
|
||||
(included-cpd (when (member common-parent-directory all-files)
|
||||
(setq all-files
|
||||
(delete common-parent-directory all-files))
|
||||
t))
|
||||
(substrings (mapcar (lambda (s) (substring s cpd-length)) all-files))
|
||||
(_ (when included-cpd
|
||||
(setq substrings (cons "./" substrings))))
|
||||
(new-collection (denote--completion-table 'file substrings))
|
||||
(abs-cpd (expand-file-name common-parent-directory))
|
||||
(abs-cpd-length (length abs-cpd))
|
||||
(relname (cl-letf* ((non-essential t) ;Avoid new Tramp connections.
|
||||
((symbol-value 'denote-file-history)
|
||||
(mapcan
|
||||
(lambda (s)
|
||||
(setq s (expand-file-name s))
|
||||
(and (string-prefix-p abs-cpd s)
|
||||
(not (eq abs-cpd-length (length s)))
|
||||
(list (substring s abs-cpd-length))))
|
||||
(symbol-value 'denote-file-history))))
|
||||
(completing-read prompt new-collection nil nil nil 'denote-file-history)))
|
||||
(absname (expand-file-name relname common-parent-directory)))
|
||||
(add-to-history 'denote-file-history absname)
|
||||
absname))
|
||||
(when-let ((all-files (denote-directory-files files-matching-regexp :omit-current)))
|
||||
(let* ((common-parent-directory
|
||||
(let ((common-prefix (try-completion "" all-files)))
|
||||
(if (> (length common-prefix) 0)
|
||||
(file-name-directory common-prefix))))
|
||||
(cpd-length (length common-parent-directory))
|
||||
(prompt (if (zerop cpd-length)
|
||||
"Select note: "
|
||||
(format "Select note in %s: " common-parent-directory)))
|
||||
(included-cpd (when (member common-parent-directory all-files)
|
||||
(setq all-files
|
||||
(delete common-parent-directory all-files))
|
||||
t))
|
||||
(substrings (mapcar (lambda (s) (substring s cpd-length)) all-files))
|
||||
(_ (when included-cpd
|
||||
(setq substrings (cons "./" substrings))))
|
||||
(new-collection (denote--completion-table 'file substrings))
|
||||
(abs-cpd (expand-file-name common-parent-directory))
|
||||
(abs-cpd-length (length abs-cpd))
|
||||
(relname (cl-letf* ((non-essential t) ;Avoid new Tramp connections.
|
||||
((symbol-value 'denote-file-history)
|
||||
(mapcan
|
||||
(lambda (s)
|
||||
(setq s (expand-file-name s))
|
||||
(and (string-prefix-p abs-cpd s)
|
||||
(not (eq abs-cpd-length (length s)))
|
||||
(list (substring s abs-cpd-length))))
|
||||
(symbol-value 'denote-file-history))))
|
||||
(completing-read prompt new-collection nil nil nil 'denote-file-history)))
|
||||
(absname (expand-file-name relname common-parent-directory)))
|
||||
(add-to-history 'denote-file-history absname)
|
||||
absname)))
|
||||
|
||||
;;;; Keywords
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue