[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote a701764b0e 1/9: Start implementing not-regexp fe
From: |
ELPA Syncer |
Subject: |
[elpa] externals/denote a701764b0e 1/9: Start implementing not-regexp feature to exclude those files |
Date: |
Wed, 4 Dec 2024 09:58:03 -0500 (EST) |
branch: externals/denote
commit a701764b0e8fb6fa116e2934b894ac618d1726c5
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Start implementing not-regexp feature to exclude those files
---
denote-sort.el | 61 ++++++++++++++++++++++++++++++++++++++++++----------------
denote.el | 15 ++++++++++++---
2 files changed, 56 insertions(+), 20 deletions(-)
diff --git a/denote-sort.el b/denote-sort.el
index 9daa8b9df4..d21db255b7 100644
--- a/denote-sort.el
+++ b/denote-sort.el
@@ -1,4 +1,4 @@
-;;; denote-sort.el --- Sort Denote files based on a file name component -*-
lexical-binding: t -*-
+;;; denote-sort.el --- Sort Denote files based on a file name component -*-
lexical-binding: t -*-
;; Copyright (C) 2023-2024 Free Software Foundation, Inc.
@@ -82,8 +82,9 @@ done according to `denote-sort-dired-default-sort-component'
and
:type '(radio (const :tag "Do not prompt for anything" nil)
(set :tag "Available prompts" :greedy t
(const :tag "Sort by file name component"
sort-by-component)
- (const :tag "Reverse the sort" reverse-sort)))
- :package-version '(denote . "3.1.0")
+ (const :tag "Reverse the sort" reverse-sort)
+ (const :tag "Exclude files matching regexp"
exclude-regexp)))
+ :package-version '(denote . "3.2.0")
:group 'denote-sort)
(defcustom denote-sort-dired-default-sort-component 'identifier
@@ -156,7 +157,7 @@ With optional REVERSE as a non-nil value, reverse the sort
order."
(reverse sorted-files)
sorted-files)))
-(defun denote-sort-get-directory-files (files-matching-regexp
sort-by-component &optional reverse omit-current)
+(defun denote-sort-get-directory-files (files-matching-regexp
sort-by-component &optional reverse omit-current exclude-regexp)
"Return sorted list of files in variable `denote-directory'.
With FILES-MATCHING-REGEXP as a string limit files to those
@@ -169,13 +170,17 @@ name component.
With optional REVERSE as a non-nil value, reverse the sort order.
With optional OMIT-CURRENT, do not include the current file in
-the list."
+the list.
+
+With optional EXCLUDE-REGEXP exclude the files that match the given
+regular expression. This is done after FILES-MATCHING-REGEXP and
+OMIT-CURRENT have been applied."
(denote-sort-files
- (denote-directory-files files-matching-regexp omit-current)
+ (denote-directory-files files-matching-regexp omit-current nil
exclude-regexp)
sort-by-component
reverse))
-(defun denote-sort-get-links (files-matching-regexp sort-by-component
current-file-type id-only &optional reverse)
+(defun denote-sort-get-links (files-matching-regexp sort-by-component
current-file-type id-only &optional reverse exclude-regexp)
"Return sorted typographic list of links for FILES-MATCHING-REGEXP.
With FILES-MATCHING-REGEXP as a string, match files stored in the
@@ -194,9 +199,13 @@ unknown non-nil value, default to the Org notation.
With ID-ONLY as a non-nil value, produce links that consist only
of the identifier, thus deviating from CURRENT-FILE-TYPE.
-With optional REVERSE as a non-nil value, reverse the sort order."
+With optional REVERSE as a non-nil value, reverse the sort order.
+
+With optional EXCLUDE-REGEXP exclude the files that match the given
+regular expression. This is done after FILES-MATCHING-REGEXP and
+OMIT-CURRENT have been applied."
(denote-link--prepare-links
- (denote-sort-get-directory-files files-matching-regexp sort-by-component
reverse)
+ (denote-sort-get-directory-files files-matching-regexp sort-by-component
reverse exclude-regexp)
current-file-type
id-only))
@@ -215,24 +224,37 @@ With optional REVERSE as a non-nil value, reverse the
sort order."
denote-sort-components nil :require-match
nil 'denote-sort-component-history default))))
+(defvar denote-sort-exclude-files-history nil
+ "Minibuffer history for `denote-sort-exclude-files-prompt'.")
+
+(defun denote-sort-exclude-files-prompt ()
+ "Prompt for regular expression of files to exclude."
+ ;; TODO 2024-12-03: Maybe use `read-regexp'? We do not use it
+ ;; elsewhere, so maybe this is fine.
+ (let ((default (car denote-sort-exclude-files-history)))
+ (read-string
+ (format-prompt "Exclude files matching REGEXP" default)
+ default 'denote-sort-exclude-files-history)))
+
(defvar-local denote-sort--dired-buffer nil
"Buffer object of current `denote-sort-dired'.")
(defun denote-sort-dired--prompts ()
"Return list of prompts per `denote-sort-dired-extra-prompts'."
- (let (sort-by-component reverse-sort)
+ (let (sort-by-component reverse-sort exclude-rx)
(dolist (prompt denote-sort-dired-extra-prompts)
(pcase prompt
('sort-by-component (setq sort-by-component
(denote-sort-component-prompt)))
- ('reverse-sort (setq reverse-sort (y-or-n-p "Reverse sort? ")))))
- (list sort-by-component reverse-sort)))
+ ('reverse-sort (setq reverse-sort (y-or-n-p "Reverse sort? ")))
+ ('exclude-regexp (setq exclude-rx
(denote-sort-exclude-files-prompt)))))
+ (list sort-by-component reverse-sort exclude-rx)))
;;;###autoload
-(defun denote-sort-dired (files-matching-regexp sort-by-component reverse)
+(defun denote-sort-dired (files-matching-regexp sort-by-component reverse
exclude-regexp)
"Produce Dired buffer with sorted files from variable `denote-directory'.
When called interactively, prompt for FILES-MATCHING-REGEXP and,
depending on the value of the user option `denote-sort-dired-extra-prompts',
-also prompt for SORT-BY-COMPONENT and REVERSE.
+also prompt for SORT-BY-COMPONENT, REVERSE, and EXCLUDE-REGEXP.
1. FILES-MATCHING-REGEXP limits the list of Denote files to
those matching the provided regular expression.
@@ -248,6 +270,10 @@ also prompt for SORT-BY-COMPONENT and REVERSE.
`denote-sort-dired-default-reverse-sort', falling back to
nil (i.e. no reverse sort).
+4. EXCLUDE-REGEXP excludes the files that match the given regular
+ expression. This is done after FILES-MATCHING-REGEXP and
+ OMIT-CURRENT have been applied.
+
When called from Lisp, the arguments are a string, a symbol among
`denote-sort-components', and a non-nil value, respectively."
(interactive
@@ -257,9 +283,10 @@ When called from Lisp, the arguments are a string, a
symbol among
'identifier))
(reverse-sort (or reverse
denote-sort-dired-default-reverse-sort
- nil)))
+ nil))
+ (exclude-rx (or exclude-regexp nil)))
(if-let* ((default-directory (denote-directory))
- (files (denote-sort-get-directory-files files-matching-regexp
component reverse-sort))
+ (files (denote-sort-get-directory-files files-matching-regexp
component reverse-sort exclude-rx))
;; NOTE 2023-12-04: Passing the FILES-MATCHING-REGEXP as
;; buffer-name produces an error if the regexp contains a
;; wildcard for a directory. I can reproduce this in emacs
@@ -274,7 +301,7 @@ When called from Lisp, the arguments are a string, a symbol
among
(setq-local revert-buffer-function
(lambda (&rest _)
(kill-buffer dired-buffer)
- (denote-sort-dired files-matching-regexp component
reverse-sort))))
+ (denote-sort-dired files-matching-regexp component
reverse-sort exclude-rx))))
;; Because of the above NOTE, I am printing a message. Not
;; what I want, but it is better than nothing...
(message denote-sort-dired-buffer-name))
diff --git a/denote.el b/denote.el
index 1b08dae15b..f5ba8372d3 100644
--- a/denote.el
+++ b/denote.el
@@ -1261,7 +1261,7 @@ are not backups."
(not (backup-file-name-p file))))
(denote--directory-all-files-recursively))))
-(defun denote-directory-files (&optional files-matching-regexp omit-current
text-only)
+(defun denote-directory-files (&optional files-matching-regexp omit-current
text-only exclude-regexp)
"Return list of absolute file paths in variable `denote-directory'.
Files that match `denote-excluded-files-regexp' are excluded from the
list.
@@ -1277,7 +1277,11 @@ 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-filename-is-note-p'."
+text files that satisfy `denote-filename-is-note-p'.
+
+With optional EXCLUDE-REGEXP exclude the files that match the given
+regular expression. This is done after FILES-MATCHING-REGEXP and
+OMIT-CURRENT have been applied."
(let ((files (denote--directory-get-files)))
(when (and omit-current buffer-file-name (denote-file-has-identifier-p
buffer-file-name))
(setq files (delete buffer-file-name files)))
@@ -1288,7 +1292,12 @@ text files that satisfy `denote-filename-is-note-p'."
files)))
(when text-only
(setq files (seq-filter #'denote-filename-is-note-p files)))
- files))
+ (if exclude-regexp
+ (seq-remove
+ (lambda (file)
+ (string-match-p exclude-regexp file))
+ files)
+ files)))
(defun denote-directory-subdirectories ()
"Return list of subdirectories in variable `denote-directory'.
- [elpa] externals/denote updated (7f4a66d802 -> de786b5e8f), ELPA Syncer, 2024/12/04
- [elpa] externals/denote 4205708b2c 3/9: Document in the manual denote-sort-dired-extra-prompts new exclude-regexp symbol, ELPA Syncer, 2024/12/04
- [elpa] externals/denote d6b3269a17 8/9: Merge branch 'not-regexp', ELPA Syncer, 2024/12/04
- [elpa] externals/denote 663e6e0206 2/9: Document denote-directory-files EXCLUDE-REGEXP in the manual, ELPA Syncer, 2024/12/04
- [elpa] externals/denote a701764b0e 1/9: Start implementing not-regexp feature to exclude those files,
ELPA Syncer <=
- [elpa] externals/denote 821095844c 4/9: Clarify the wording about default behaviour of denote-sort-dired command, ELPA Syncer, 2024/12/04
- [elpa] externals/denote 89a6f7c8c2 5/9: Fix bug to make denote-sort-dired exclude files matching regexp (see a701764), ELPA Syncer, 2024/12/04
- [elpa] externals/denote a703f2b686 6/9: Implement WORK-IN-PROGRESS support for :not-regexp to omit files in Org dynamic blocks, ELPA Syncer, 2024/12/04
- [elpa] externals/denote fba0bb2650 7/9: Document the :not-regexp parameter of the Org dynamic blocks, ELPA Syncer, 2024/12/04
- [elpa] externals/denote de786b5e8f 9/9: Define helper function to parse rx, ELPA Syncer, 2024/12/04