Make denote-file-prompt accept a PROMPT-TEXT argument like other prompts

This commit is contained in:
Protesilaos Stavrou 2024-03-23 08:06:39 +02:00
parent ce134fed64
commit 5c10aa2863
No known key found for this signature in database
GPG key ID: 99BD6459CD5CA3EA
2 changed files with 15 additions and 9 deletions

View file

@ -4462,11 +4462,13 @@ might change them without further notice.
#+findex: denote-file-prompt
+ Function ~denote-file-prompt~ :: Prompt for file with identifier in
variable ~denote-directory~. With optional =FILES-MATCHING-REGEXP=,
filter the candidates per the given regular expression. [ As part of
{{{development-version}}}, completion candidates have a relative
file path, but the return value and what is stored in the minibuffer
history is still the full file system path. ]
variable ~denote-directory~. With optional =FILES-MATCHING-REGEXP=,
filter the candidates per the given regular expression. With
optional =PROMPT-TEXT=, use it instead of the default "Select NOTE".
[ As part of {{{development-version}}}, completion candidates have a
relative file path, but the return value and what is stored in the
minibuffer history is still the full file system path. Furthermore,
the =PROMPT-TEXT= is added. ]
#+findex: denote-keywords-prompt
+ Function ~denote-keywords-prompt~ :: Prompt for one or more keywords.

View file

@ -1132,19 +1132,23 @@ file in the returned list."
;; NOTE 2024-02-29: Based on `project--read-file-cpd-relative' from
;; the built-in project.el
(defun denote-file-prompt (&optional files-matching-regexp)
(defun denote-file-prompt (&optional files-matching-regexp prompt-text)
"Prompt for file with identifier in variable `denote-directory'.
With optional FILES-MATCHING-REGEXP, filter the candidates per
the given regular expression."
the given regular expression.
With optional PROMPT-TEXT, use it instead of the default call to
\"Select NOTE\"."
(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-prefix (or prompt-text "Select NOTE"))
(prompt (if (zerop cpd-length)
"Select note: "
(format "Select note in %s: " common-parent-directory)))
(format "%s: " prompt-prefix)
(format "%s in %s: " prompt-prefix common-parent-directory)))
(included-cpd (when (member common-parent-directory all-files)
(setq all-files
(delete common-parent-directory all-files))