mirror of
https://github.com/protesilaos/denote.git
synced 2026-09-10 07:16:20 -04:00
Redefine denote-query-only-include-files and denote-query-exclude-files to use helper function
The macro we had before was okay, but this feels easier to reason about.
This commit is contained in:
parent
d78ad3f74e
commit
9b8c96f5e8
52
denote.el
52
denote.el
|
|
@ -5991,35 +5991,31 @@ generally, any command that relies on the `denote-make-links-buffer'."
|
|||
(denote-make-links-buffer query denote-query--last-files nil '(display-buffer-same-window))
|
||||
(message "Searching `%s' in files: `%S'" query denote-query--last-files))
|
||||
|
||||
(defmacro denote--define-include-or-exclude-files (include-or-exclude)
|
||||
"Define a function to include or exclude from the `denote-query-mode' buffer."
|
||||
(unless (or (eq include-or-exclude 'include)
|
||||
(eq include-or-exclude 'exclude))
|
||||
(error "The argument has to be `include' or `exclude.'"))
|
||||
`(defun ,(intern (format "denote-query-%s-files" include-or-exclude)) (regexp)
|
||||
,(if (eq include-or-exclude 'include)
|
||||
"Only show files matching REGEXP in the current Denote query buffer.
|
||||
REGEXP is matched against the file name."
|
||||
"Exclude files matching REGEXP from the current Denote query buffer.
|
||||
REGEXP is matched against the file name.")
|
||||
(interactive
|
||||
(or (denote--user-error-if-not-major-mode 'denote-query-mode)
|
||||
(list (denote-query-prompt ,(intern (format ":%s" include-or-exclude)))))
|
||||
denote-query-mode)
|
||||
(denote--user-error-if-not-major-mode 'denote-query-mode)
|
||||
(let ((final-files nil))
|
||||
(dolist (file denote-query--last-files)
|
||||
(,(if (eq include-or-exclude 'include)
|
||||
'when
|
||||
'unless) (string-match-p regexp file)
|
||||
(push file final-files)))
|
||||
(if final-files
|
||||
(denote-make-links-buffer denote-query--last-query final-files (buffer-name) '(display-buffer-same-window))
|
||||
(user-error "No remaining files when applying that filter"))
|
||||
(message "No files matching `%s'" regexp))))
|
||||
(defun denote-query--filter-files (regexp include-p)
|
||||
"Filter `denote-query--last-files' with REGEXP.
|
||||
If INCLUDE-P is non-nil, only include matches. Otherwise exclude them."
|
||||
(if-let* ((filter-fn (if include-p #'seq-filter #'seq-remove))
|
||||
(final-files (funcall filter-fn (lambda (file) (string-match-p regexp file)) denote-query--last-files)))
|
||||
(denote-make-links-buffer denote-query--last-query final-files (buffer-name) '(display-buffer-same-window))
|
||||
(user-error "No remaining files when applying that filter")))
|
||||
|
||||
(denote--define-include-or-exclude-files include)
|
||||
(denote--define-include-or-exclude-files exclude)
|
||||
(defun denote-query-exclude-files (regexp)
|
||||
"Exclude files matching REGEXP from the current Denote query buffer.
|
||||
REGEXP is matched against the file name."
|
||||
(interactive
|
||||
(or (denote--user-error-if-not-major-mode 'denote-query-mode)
|
||||
(list (denote-query-prompt :exclude)))
|
||||
denote-query-mode)
|
||||
(denote-query--filter-files regexp nil))
|
||||
|
||||
(defun denote-query-only-include-files (regexp)
|
||||
"Only show files matching REGEXP in the current Denote query buffer.
|
||||
REGEXP is matched against the file name."
|
||||
(interactive
|
||||
(or (denote--user-error-if-not-major-mode 'denote-query-mode)
|
||||
(list (denote-query-prompt :include)))
|
||||
denote-query-mode)
|
||||
(denote-query--filter-files regexp :include))
|
||||
|
||||
(defun denote-query--keywords-as-regexp (keywords)
|
||||
"Return KEYWORDS as a single regular expression.
|
||||
|
|
|
|||
Loading…
Reference in a new issue