Change: (org-ql-search) Switch to keyword arguments

And order arguments like other org-ql functions.

Note that the code shown in the animation in the readme doesn't
reflect this change.
This commit is contained in:
Adam Porter 2019-01-14 18:31:37 -06:00
parent f2be12acf8
commit 20d563452f

View file

@ -117,18 +117,19 @@ is used, rather than binding it locally."
;; it uses `org-ql-agenda--agenda'. Maybe this could be better organized. ;; it uses `org-ql-agenda--agenda'. Maybe this could be better organized.
;;;###autoload ;;;###autoload
(defun org-ql-search (query &optional buffers-files narrow group sort) (cl-defun org-ql-search (buffers-files query &key narrow groups sort)
"Read QUERY and search with `org-ql'. "Read QUERY and search with `org-ql'.
Interactively, prompt for these variables: Interactively, prompt for these variables:
BUFFERS-FILES: A list of buffers and/or files to search, or an BUFFERS-FILES: A list of buffers and/or files to search.
expression which evaluates to such a list. Interactively, may also be an expression which evaluates to such
a list.
GROUP: An `org-super-agenda' auto-grouping selector. See GROUPS: An `org-super-agenda' group set. See variable
variable `org-super-agenda-auto-selector-keywords'. `org-super-agenda-groups'.
NARROW: Don't widen buffers before searching. Buffers are NARROW: When non-nil, don't widen buffers before
widened by default. With prefix, leave narrowed. searching. Interactively, with prefix, leave narrowed.
SORT: One or a list of `org-ql' sorting functions, like `date' or SORT: One or a list of `org-ql' sorting functions, like `date' or
`priority'." `priority'."
@ -136,35 +137,35 @@ SORT: One or a list of `org-ql' sorting functions, like `date' or
(when (and current-prefix-arg (when (and current-prefix-arg
(not (derived-mode-p 'org-mode))) (not (derived-mode-p 'org-mode)))
(user-error "Not an Org buffer: %s" (buffer-name))) (user-error "Not an Org buffer: %s" (buffer-name)))
(list (read-minibuffer "Query: ") (list (--if-let (read-from-minibuffer "Buffers/Files (blank for current buffer): ")
(--if-let (read-from-minibuffer "Buffers/Files (blank for current buffer): ")
;; TODO: Add glob matching? Buffer mode matching? ;; TODO: Add glob matching? Buffer mode matching?
(pcase it (pcase it
("" (current-buffer)) ("" (current-buffer))
((rx bos "(") (-flatten (eval (read it)))) ((rx bos "(") (-flatten (eval (read it))))
(_ (s-split (rx (1+ space)) it))) (_ (s-split (rx (1+ space)) it)))
(current-buffer)) (current-buffer))
(eq current-prefix-arg '(4)) (read-minibuffer "Query: ")
(pcase (completing-read "Group by: " :narrow (eq current-prefix-arg '(4))
(cons "Don't group" :groups (pcase (completing-read "Group by: "
(cl-loop for type in org-super-agenda-auto-selector-keywords (cons "Don't group"
collect (substring (symbol-name type) 6)))) (cl-loop for type in org-super-agenda-auto-selector-keywords
("Don't group" nil) collect (substring (symbol-name type) 6))))
(property (list (list (intern (concat ":auto-" property)))))) ("Don't group" nil)
(pcase (completing-read "Sort by: " (property (list (list (intern (concat ":auto-" property))))))
(list "Don't sort" :sort (pcase (completing-read "Sort by: "
"date" (list "Don't sort"
"deadline" "date"
"priority" "deadline"
"scheduled" "priority"
"todo")) "scheduled"
("Don't sort" nil) "todo"))
(sort (intern sort)))))) ("Don't sort" nil)
(sort (intern sort))))))
(org-ql-agenda--agenda buffers-files (org-ql-agenda--agenda buffers-files
query query
:narrow narrow :narrow narrow
:sort sort :sort sort
:super-groups group)) :super-groups groups))
;;;; Functions ;;;; Functions