branch: externals/denote commit ffad320332645abb922b26d1d83781066eeff937 Author: Protesilaos Stavrou <i...@protesilaos.com> Commit: Protesilaos Stavrou <i...@protesilaos.com>
Make 'denote-all-files' accept optional OMIT-CURRENT We had this before and it was used to omit the current file from the 'denote-link' prompt (i.e. not give users the option to link the file to itself). We probably lost that when 'denote-all-files' was introduced, though I believe it was not by design. I am adding it back in, as I see no obvious downside with this. --- README.org | 6 ++++++ denote.el | 15 ++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.org b/README.org index 9b84cf138f..b62b288752 100644 --- a/README.org +++ b/README.org @@ -3683,6 +3683,12 @@ might change them without further notice. + Function ~denote-directory-files-matching-regexp~ :: Return list of files matching =REGEXP= in ~denote-directory-files~. +#+findex: denote-all-files ++ Function ~denote-all-files~ :: Return the list of Denote files in + the variable ~denote-directory~. With optional =OMIT-CURRENT=, do + not include the current Denote file in the returned list. [ The + =OMIT-CURRENT= is part of {{{development-version}}}. ] + #+findex: denote-file-name-relative-to-denote-directory + Function ~denote-file-name-relative-to-denote-directory~ :: Return name of =FILE= relative to the variable ~denote-directory~. =FILE= diff --git a/denote.el b/denote.el index f553cba535..642e9b7e31 100644 --- a/denote.el +++ b/denote.el @@ -892,12 +892,17 @@ The path is relative to DIRECTORY (default: ‘default-directory’)." (string-match-p regexp (denote-get-file-name-relative-to-denote-directory f))) (denote-directory-files))) -(defun denote-all-files () - "Return the list of Denote files in variable `denote-directory'." +(defun denote-all-files (&optional omit-current) + "Return the list of Denote files in variable `denote-directory'. +With optional OMIT-CURRENT, do not include the current Denote +file in the returned list." (let* ((project-find-functions #'denote-project-find) (project (project-current nil (denote-directory))) - (dirs (list (project-root project)))) - (project-files project dirs))) + (dirs (list (project-root project))) + (files (project-files project dirs))) + (if (and omit-current (denote-file-has-identifier-p buffer-file-name)) + (delete buffer-file-name files) + files))) (defvar denote--file-history nil "Minibuffer history of `denote-file-prompt'.") @@ -908,7 +913,7 @@ With optional FILES-MATCHING-REGEXP, filter the candidates per the given regular expression." (when-let ((files (if files-matching-regexp (denote-directory-files-matching-regexp files-matching-regexp) - (denote-all-files))) + (denote-all-files :omit-current))) (file (funcall project-read-file-name-function ;; FIXME 2023-10-15: Why do I get an empty history at the prompt even ;; though it is given as an argument and it is not empty?