branch: externals/denote
commit 75e6e5e8f5dfa96fc741936cf2d48049120208bd
Author: Protesilaos Stavrou <i...@protesilaos.com>
Commit: Protesilaos Stavrou <i...@protesilaos.com>

    Make all denote-query-mode commands throw an error if called from elsewhere
---
 denote.el | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/denote.el b/denote.el
index 20556abcfe..4c145fcec3 100644
--- a/denote.el
+++ b/denote.el
@@ -5219,7 +5219,9 @@ It accepts the same arguments as 
`denote-make-links-buffer'.")
 \"Last search\" here means any call to `denote-grep',
 `denote-backlinks', `denote-query-contents-link', or, generally, any
 command that relies on the `denote-make-links-buffer'."
-  (interactive (list (denote-grep-query-prompt :focused)))
+  (interactive (list (denote-grep-query-prompt :focused)) denote-query-mode)
+  (unless (derived-mode-p 'denote-query-mode)
+    (user-error "Only use this command inside the `denote-query-mode'"))
   (denote-make-links-buffer
    query denote-query--last-files
    nil '(display-buffer-same-window))
@@ -5243,7 +5245,9 @@ a list of fixed strings (NOT regexps) to check against 
last matched
 files.  Files that match any of the strings get excluded.  Internally,
 the list is processed using `regexp-opt'.  For an example of this usage,
 see `denote-query-exclude-files-with-keywords'."
-  (interactive (list (denote-grep-file-regexp-prompt)))
+  (interactive (list (denote-grep-file-regexp-prompt)) denote-query-mode)
+  (unless (derived-mode-p 'denote-query-mode)
+    (user-error "Only use this command inside the `denote-query-mode'"))
   (let (final-files)
     (dolist (file denote-query--last-files)
       (unless (string-match
@@ -5263,7 +5267,9 @@ see `denote-query-exclude-files-with-keywords'."
 
 See `denote-query-exclude-files' for details, including the behaviour
 when REGEXP is a list."
-  (interactive (list (denote-grep-file-regexp-prompt :include)))
+  (interactive (list (denote-grep-file-regexp-prompt :include)) 
denote-query-mode)
+  (unless (derived-mode-p 'denote-query-mode)
+    (user-error "Only use this command inside the `denote-query-mode'"))
   (let (final-files)
     (dolist (file denote-query--last-files)
       (when (string-match
@@ -5285,7 +5291,9 @@ KEYWORDS should be a list of keywords (without 
underscore).
 
 Interactively, KEYWORDS are read from the minibuffer using
 `completing-read-multiple', which see."
-  (interactive (denote-grep-keywords-prompt))
+  (interactive (denote-grep-keywords-prompt) denote-query-mode)
+  (unless (derived-mode-p 'denote-query-mode)
+    (user-error "Only use this command inside the `denote-query-mode'"))
   (denote-query-exclude-files
    (mapcar (lambda (kw) (concat "_" kw)) keywords)))
 
@@ -5293,7 +5301,9 @@ Interactively, KEYWORDS are read from the minibuffer using
   "Exclude files without KEYWORDS from current query buffer.
 
 See `denote-query-exclude-files-with-keywords' for details."
-  (interactive (denote-grep-keywords-prompt :include))
+  (interactive (denote-grep-keywords-prompt :include) denote-query-mode)
+  (unless (derived-mode-p 'denote-query-mode)
+    (user-error "Only use this command inside the `denote-query-mode'"))
   (denote-query-only-include-files
    (mapcar (lambda (kw) (concat "_" kw)) keywords)))
 
@@ -5302,7 +5312,9 @@ See `denote-query-exclude-files-with-keywords' for 
details."
 
 This effectively gets ride of any interactive filter applied (by the
 means of e.g. `denote-query-exclude-files')."
-  (interactive)
+  (interactive nil denote-query-mode)
+  (unless (derived-mode-p 'denote-query-mode)
+    (user-error "Only use this command inside the `denote-query-mode'"))
   (denote-make-links-buffer denote-query--last-query)
   (message "Cleared all filters"))
 

Reply via email to