Skip to content

Commit

Permalink
Change: (org-ql-find.el) Factor out interactive form
Browse files Browse the repository at this point in the history
And use in org-ql-find-path.
  • Loading branch information
alphapapa committed Nov 6, 2023
1 parent e885001 commit 136b986
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions org-ql-find.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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))))

Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 136b986

Please sign in to comment.