From 136b986afd76d98480fd2003d28e43e25063d33c Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Mon, 6 Nov 2023 15:52:33 -0600 Subject: [PATCH] Change: (org-ql-find.el) Factor out interactive form And use in org-ql-find-path. --- org-ql-find.el | 56 ++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/org-ql-find.el b/org-ql-find.el index 13c20166..7a3e2307 100644 --- a/org-ql-find.el +++ b/org-ql-find.el @@ -49,7 +49,7 @@ See function `display-buffer'." :type 'sexp) -;;;; Functions +;;;; Commands ;;;###autoload (cl-defun org-ql-find (buffers-files &key query-prefix query-filter @@ -70,19 +70,7 @@ types is filtered before execution (e.g. it could replace spaces with commas to turn multiple tokens, which would normally be treated as multiple predicates, into multiple arguments to a single predicate)." - (interactive - (list (if current-prefix-arg - (mapcar #'get-buffer - (completing-read-multiple - "Buffers: " - (cl-loop for buffer in (buffer-list) - when (eq 'org-mode (buffer-local-value 'major-mode buffer)) - collect (buffer-name buffer)) - nil t)) - (cond ((derived-mode-p 'org-agenda-mode) (or org-ql-view-buffers-files - org-agenda-contributing-files)) - ((derived-mode-p 'org-mode) (current-buffer)) - (t (user-error "This is not an Org-related buffer: %S" (current-buffer))))))) + (interactive (list (org-ql-find--buffers))) (let ((marker (org-ql-completing-read buffers-files :query-prefix query-prefix :query-filter query-filter @@ -138,7 +126,7 @@ which see (but only the files are used)." (defun org-ql-find-path () "Call `org-ql-find' to search outline paths in the current buffer." ;; TODO: Use same interactive form as `org-ql-find'. - (interactive) + (interactive (list (org-ql-find--buffers))) (let ((org-ql-default-predicate 'outline-path)) (org-ql-find (current-buffer)))) @@ -151,20 +139,7 @@ candidates, and the selected one is opened with `org-open-at-point'. Arguments BUFFERS-FILES, QUERY-FILTER, QUERY-PREFIX, and PROMPT are passed to `org-ql-completing-read', which see." - (interactive - ;; FIXME: Factor this out. - (list (if current-prefix-arg - (mapcar #'get-buffer - (completing-read-multiple - "Buffers: " - (cl-loop for buffer in (buffer-list) - when (eq 'org-mode (buffer-local-value 'major-mode buffer)) - collect (buffer-name buffer)) - nil t)) - (progn - (unless (eq major-mode 'org-mode) - (user-error "This is not an Org buffer: %S" (current-buffer))) - (current-buffer))))) + (interactive (list (org-ql-find--buffers))) (let* ((marker (org-ql-completing-read buffers-files :query-prefix query-prefix :query-filter query-filter @@ -193,6 +168,29 @@ which see." (org-with-point-at marker (org-open-at-point)))) +;;;; Functions + +(defun org-ql-find--buffers () + "Return list of buffers to search in. +In a mode derived from `org-agenda-mode', return the value of +`org-ql-view-buffers-files' or `org-agenda-contributing-files'. +In a mode derived from `org-mode', return the current buffer. +When `current-prefix-arg', read a list of buffers in `org-mode' +with completion. To be used in `org-ql-find' commands' +interactive forms." + (if current-prefix-arg + (mapcar #'get-buffer + (completing-read-multiple + "Buffers: " + (cl-loop for buffer in (buffer-list) + when (eq 'org-mode (buffer-local-value 'major-mode buffer)) + collect (buffer-name buffer)) + nil t)) + (cond ((derived-mode-p 'org-agenda-mode) (or org-ql-view-buffers-files + org-agenda-contributing-files)) + ((derived-mode-p 'org-mode) (current-buffer)) + (t (user-error "This is not an Org-related buffer: %S" (current-buffer)))))) + (provide 'org-ql-find) ;;; org-ql-find.el ends here