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 72b9934
Showing 1 changed file with 42 additions and 34 deletions.
76 changes: 42 additions & 34 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 @@ -135,12 +123,16 @@ which see (but only the files are used)."
(org-ql-find (org-ql-search-directories-files)))

;;;###autoload
(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)
(defun org-ql-find-path (buffers-files)
"Call `org-ql-find' to search outline paths in BUFFERS-FILES.
Interactively, search the buffers and files relevant to the
current buffer (i.e. in `org-agenda-mode', the value of
`org-ql-view-buffers-files' or `org-agenda-contributing-files';
in `org-mode', that buffer). With universal prefix, select
multiple buffers to search with completion and PROMPT."
(interactive (list (org-ql-find--buffers)))
(let ((org-ql-default-predicate 'outline-path))
(org-ql-find (current-buffer))))
(org-ql-find buffers-files)))

;;;###autoload
(cl-defun org-ql-open-link (buffers-files &key query-prefix query-filter
Expand All @@ -150,21 +142,14 @@ Links found in entries matching the input query are offered as
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)))))
which see.
Interactively, search the buffers and files relevant to the
current buffer (i.e. in `org-agenda-mode', the value of
`org-ql-view-buffers-files' or `org-agenda-contributing-files';
in `org-mode', that buffer). With universal prefix, select
multiple buffers to search with completion and PROMPT."
(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 +178,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 72b9934

Please sign in to comment.