branch: externals/denote commit 32d98143fd544f8673b5a130430d825ef53cbdb9 Merge: d92fad4cdb e77ef96ccb Author: Protesilaos Stavrou <i...@protesilaos.com> Commit: Protesilaos Stavrou <i...@protesilaos.com>
Merge remote-tracking branch 'origin/excluded-files-regexp' --- README.org | 69 +++++++++++++++++++++++++++++++++++++++++++------------------- denote.el | 21 +++++++++++++++++++ 2 files changed, 69 insertions(+), 21 deletions(-) diff --git a/README.org b/README.org index 2f23b72f77..fb0fc2018a 100644 --- a/README.org +++ b/README.org @@ -1187,6 +1187,27 @@ greater convenience. For example: (define-key global-map (kbd "C-c n j") #'my-denote-journal-extras-new-or-existing-entry) #+end_src +** Exclude certain files from file prompts +:PROPERTIES: +:CUSTOM_ID: h:53db09de-2cec-4670-b163-5cb791f997b4 +:END: + +[ Part of {{{development-version}}}. ] + +#+vindex: denote-excluded-files-regexp +The user option ~denote-excluded-files-regexp~ is a regular expression +that matches files names which should be excluded from all Denote file +prompts. Such prompts are present when linking to a file with one of +the many commands, like ~denote-link~ ([[#h:fc913d54-26c8-4c41-be86-999839e8ad31][Linking notes]]), or when trying +to open a file that may or may not exist ([[#h:ad91ca39-cf10-4e16-b224-fdf78f093883][Open an existing note or create it if missing]]). + +Functions that check for files include ~denote-directory-files~ and +~denote-file-prompt~. + +The match is performed with ~string-match-p~. + +[[#h:c916d8c5-540a-409f-b780-6ccbd90e088e][For developers or advanced users]]. + ** Exclude certain directories from all operations :PROPERTIES: :CUSTOM_ID: h:8458f716-f9c2-4888-824b-2bf01cc5850a @@ -4452,14 +4473,17 @@ might change them without further notice. #+findex: denote-directory-files + Function ~denote-directory-files~ :: Return list of absolute file - paths in variable ~denote-directory~. Files only need to have an - identifier. The return value may thus include file types that are not - implied by ~denote-file-type~. With optional =FILES-MATCHING-REGEXP=, - restrict files to those matching the given regular expression. With - optional =OMIT-CURRENT= as a non-nil value, do not include the current - Denote file in the returned list. With optional =TEXT-ONLY= as a - non-nil value, limit the results to text files that satisfy - ~denote-file-is-note-p~. + paths in variable ~denote-directory~. Files that match + ~denote-excluded-files-regexp~ are excluded from the list. Files + only need to have an identifier. The return value may thus include + file types that are not implied by ~denote-file-type~. With optional + =FILES-MATCHING-REGEXP=, restrict files to those matching the given + regular expression. With optional =OMIT-CURRENT= as a non-nil value, + do not include the current Denote file in the returned list. With + optional =TEXT-ONLY= as a non-nil value, limit the results to text + files that satisfy ~denote-file-is-note-p~. [ Updated as part of + {{{development-version}}} to exclude files that match the + ~denote-excluded-files-regexp~ ([[#h:53db09de-2cec-4670-b163-5cb791f997b4][Exclude certain files from file prompts]]). ] #+findex: denote-directory-subdirectories + Function ~denote-directory-subdirectories~ :: Return list of @@ -4639,14 +4663,16 @@ might change them without further notice. #+findex: denote-file-prompt + Function ~denote-file-prompt~ :: Prompt for file in 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 call to select a file. - With optional =NO-REQUIRE-MATCH= accept the given input as-is. Return - the absolute path to the matching file. [ Revised as part of - {{{development-version}}} to include the new =NO-REQUIRE-MATCH= - parameter. This is to simplify how we use the various "... or create" - commands internally. ] + ~denote-directory~. Files that match ~denote-excluded-files-regexp~ + are excluded from the list. With optional =FILES-MATCHING-REGEXP=, + filter the candidates per the given regular expression. With + optional =PROMPT-TEXT=, use it instead of the default call to select + a file. With optional =NO-REQUIRE-MATCH= accept the given input + as-is. Return the absolute path to the matching file. [ Revised as + part of {{{development-version}}} to include the new + =NO-REQUIRE-MATCH= parameter. This is to simplify how we use the + various "... or create" commands internally. Also, the prompt + respects the user option ~denote-excluded-files-regexp~ ([[#h:53db09de-2cec-4670-b163-5cb791f997b4][Exclude certain files from file prompts]]).] #+findex: denote-keywords-prompt + Function ~denote-keywords-prompt~ :: Prompt for one or more keywords. @@ -5643,11 +5669,12 @@ Denote is meant to be a collective effort. Every bit of help matters. Johan Bolmsjö, Jousimies, Juanjo Presa, Julian Hoch, Kai von Fintel, Kaushal Modi, Kolmas, M. Hadi Timachi, Maikol Solis, Mark Olson, Mirko Hernandez, Niall Dooley, Paul van Gelder, Peter Prevos, Peter - Smith, Suhail Singh, Shreyas Ragavan, Stefan Thesing, Summer Emacs, - Sven Seebeck, Taoufik, TJ Stankus, Vick (VicZz), Viktor Haag, Wade - Mealing, Yi Liu, Ypot, atanasj, azegas, babusri, doolio, duli, - drcxd, elge70, fingerknight, hpgisler, mentalisttraceur, pRot0ta1p, - rbenit68, relict007, sienic, sundar bp. + Smith, Samuel W. Flint, Suhail Singh, Shreyas Ragavan, Stefan + Thesing, Summer Emacs, Sven Seebeck, Taoufik, TJ Stankus, Vick + (VicZz), Viktor Haag, Wade Mealing, Yi Liu, Ypot, atanasj, azegas, + babusri, doolio, duli, drcxd, elge70, fingerknight, hpgisler, + mentalisttraceur, pRot0ta1p, rbenit68, relict007, sienic, sundar bp, + zadca123 Special thanks to Peter Povinec who helped refine the file-naming scheme, which is the cornerstone of this project. diff --git a/denote.el b/denote.el index 0874ffd9e9..f35874b86d 100644 --- a/denote.el +++ b/denote.el @@ -595,6 +595,16 @@ The match is performed with `string-match-p'." :package-version '(denote . "1.2.0") :type 'string) +(defcustom denote-excluded-files-regexp nil + "Regular expression of files that are excluded from Denote file prompts. +Files are provided for completion when using commands like `denote-link' +and `denote-open-or-create'. + +The match is performed with `string-match-p' on the full file path." + :group 'denote + :package-version '(denote . "3.0.0") + :type 'string) + (defcustom denote-after-new-note-hook nil "Normal hook that runs after the `denote' command. This also covers all convenience functions that call `denote' @@ -1064,6 +1074,11 @@ Avoids traversing dotfiles (unconditionally) and whatever matches #'denote--directory-files-recursively-predicate :follow-symlinks)) +(defun denote--file-excluded-p (file) + "Return non-file if FILE matches `denote-excluded-files-regexp'." + (and denote-excluded-files-regexp + (string-match-p denote-excluded-files-regexp file))) + (defun denote--directory-get-files () "Return list with full path of valid files in variable `denote-directory'. Consider files that satisfy `denote-file-has-identifier-p' and @@ -1074,11 +1089,14 @@ are not backups." (lambda (file) (and (file-regular-p file) (denote-file-has-identifier-p file) + (not (denote--file-excluded-p file)) (not (backup-file-name-p file)))) (denote--directory-all-files-recursively)))) (defun denote-directory-files (&optional files-matching-regexp omit-current text-only) "Return list of absolute file paths in variable `denote-directory'. +Files that match `denote-excluded-files-regexp' are excluded from the +list. Files only need to have an identifier. The return value may thus include file types that are not implied by `denote-file-type'. @@ -1189,6 +1207,9 @@ the title prompt of `denote-open-or-create' and related commands.") (defun denote-file-prompt (&optional files-matching-regexp prompt-text no-require-match) "Prompt for file in variable `denote-directory'. +Files that match `denote-excluded-files-regexp' are excluded from the +list. + With optional FILES-MATCHING-REGEXP, filter the candidates per the given regular expression.