[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote-menu fa8c098d5c 1/2: Added `denote-menu-filter-o
|
From: |
ELPA Syncer |
|
Subject: |
[elpa] externals/denote-menu fa8c098d5c 1/2: Added `denote-menu-filter-out-keyword' |
|
Date: |
Tue, 16 May 2023 12:57:53 -0400 (EDT) |
branch: externals/denote-menu
commit fa8c098d5c553635ee812c9a54b18f6f611f3f93
Author: Mohamed Suliman <sulimanm@tcd.ie>
Commit: Mohamed Suliman <sulimanm@tcd.ie>
Added `denote-menu-filter-out-keyword'
This commit provides a function that allows to filter out denote files
from the menu view. See issue
https://github.com/namilus/denote-menu/issues/9 for more details.
---
denote-menu.el | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/denote-menu.el b/denote-menu.el
index 867f79107b..5e75c09bdb 100644
--- a/denote-menu.el
+++ b/denote-menu.el
@@ -44,6 +44,7 @@
(require 'tabulated-list)
(require 'denote)
(require 'dired)
+(require 'seq)
(defgroup denote-menu ()
"View Denote files"
@@ -220,9 +221,32 @@ Revert the *Denotes* buffer to include only the matching
entries."
"Prompt for KEYWORDS and filters the list accordingly.
When called from Lisp, KEYWORDS is a list of strings."
(interactive (list (denote-keywords-prompt)))
- (let ((regex (concat "\\(" (mapconcat (lambda (keyword) (format "_%s"
keyword)) keywords "\\|") "\\)")))
+ (let ((regex (denote-menu--keywords-to-regex keywords)))
(setq denote-menu-current-regex regex)
(denote-menu-update-entries)))
+
+(defun denote-menu--keywords-to-regex (keywords)
+ "Converts KEYWORDS into a regex that matches denote files that
+contain at least one of the keywords."
+ (concat "\\(" (mapconcat (lambda (keyword) (format "_%s" keyword)) keywords
"\\|") "\\)"))
+
+
+(defun denote-menu-filter-out-keyword (keywords)
+ "Prompt for KEYWORDS and filters out of the list those denote
+files that contain one of the keywords. When called from Lisp,
+ KEYWORDS is a list of strings."
+ (interactive (list (denote-keywords-prompt)))
+ ;; need to get a list of the denote files that do not include the
+ ;; keywords and set tabulated entries to be those.
+ (let* ((regex (denote-menu--keywords-to-regex keywords))
+ (non-matching-files (seq-filter
+ (lambda (f)
+ (not (string-match-p regex
(denote-get-file-name-relative-to-denote-directory f))))
+ (denote-menu--entries-to-paths))))
+ (setq tabulated-list-entries
+ (lambda ()
+ (mapcar #'denote-menu--path-to-entry non-matching-files))))
+ (revert-buffer))
(defun denote-menu-clear-filters ()
"Reset filters to `denote-menu-initial-regex' and update buffer."