* org-ql-find added initial-input parameter

This commit is contained in:
Konstantin Borisov 2025-03-07 02:49:22 +07:00
parent 98c62ab0a6
commit b947fd620c
2 changed files with 10 additions and 5 deletions

View file

@ -134,7 +134,7 @@ value, or nil."
;;;###autoload ;;;###autoload
(cl-defun org-ql-completing-read (cl-defun org-ql-completing-read
(buffers-files &key query-prefix query-filter narrowp (buffers-files &key query-prefix query-filter narrowp initial-input
(action #'org-ql-completing-read-action) (action #'org-ql-completing-read-action)
;; FIXME: Unused argument. ;; FIXME: Unused argument.
;; (annotate #'org-ql-completing-read-snippet) ;; (annotate #'org-ql-completing-read-snippet)
@ -156,7 +156,9 @@ QUERY-FILTER may be a function through which the query the user
types is filtered before execution (e.g. it could replace spaces types is filtered before execution (e.g. it could replace spaces
with commas to turn multiple tokens, which would normally be with commas to turn multiple tokens, which would normally be
treated as multiple predicates, into multiple arguments to a treated as multiple predicates, into multiple arguments to a
single predicate)." single predicate).
INITIAL-INPUT may be a string to initially be filled in the query."
(declare (indent defun)) (declare (indent defun))
;; Emacs's completion API is not always easy to understand, especially when using "programmed ;; Emacs's completion API is not always easy to understand, especially when using "programmed
;; completion." This code was made possible by the example Clemens Radermacher shared at ;; completion." This code was made possible by the example Clemens Radermacher shared at
@ -351,7 +353,7 @@ single predicate)."
(abort-recursive-edit)))) (abort-recursive-edit))))
((symbol-function 'embark-export) ((symbol-function 'embark-export)
(symbol-function 'org-ql-completing-read-export))) (symbol-function 'org-ql-completing-read-export)))
(completing-read prompt #'collection nil t))))) (completing-read prompt #'collection nil t initial-input)))))
;; (debug-message "SELECTED:%S KEYS:%S" selected (hash-table-keys table)) ;; (debug-message "SELECTED:%S KEYS:%S" selected (hash-table-keys table))
(or (gethash selected table) (or (gethash selected table)
;; If there are completions in the table, but none of them exactly match the user input ;; If there are completions in the table, but none of them exactly match the user input

View file

@ -55,7 +55,7 @@ See function `display-buffer'."
;;;###autoload ;;;###autoload
(cl-defun org-ql-find (buffers-files &key query-prefix query-filter widen (cl-defun org-ql-find (buffers-files &key query-prefix query-filter widen
(prompt "Find entry: ")) initial-input (prompt "Find entry: "))
"Go to an Org entry in BUFFERS-FILES selected by searching entries with `org-ql'. "Go to an Org entry in BUFFERS-FILES selected by searching entries with `org-ql'.
Interactively, search the buffers and files relevant to the Interactively, search the buffers and files relevant to the
current buffer (i.e. in `org-agenda-mode', the value of current buffer (i.e. in `org-agenda-mode', the value of
@ -75,7 +75,9 @@ QUERY-FILTER may be a function through which the query the user
types is filtered before execution (e.g. it could replace spaces types is filtered before execution (e.g. it could replace spaces
with commas to turn multiple tokens, which would normally be with commas to turn multiple tokens, which would normally be
treated as multiple predicates, into multiple arguments to a treated as multiple predicates, into multiple arguments to a
single predicate)." single predicate).
INITIAL-INPUT may be a string to initially be filled in the query."
(interactive (list (org-ql-find--buffers (interactive (list (org-ql-find--buffers
:read-buffer-p (equal '(16) current-prefix-arg)) :read-buffer-p (equal '(16) current-prefix-arg))
:widen current-prefix-arg)) :widen current-prefix-arg))
@ -86,6 +88,7 @@ single predicate)."
:narrowp (not widen) :narrowp (not widen)
:query-prefix query-prefix :query-prefix query-prefix
:query-filter query-filter :query-filter query-filter
:initial-input initial-input
:prompt prompt)))) :prompt prompt))))
(set-buffer (or (buffer-base-buffer (marker-buffer marker)) (set-buffer (or (buffer-base-buffer (marker-buffer marker))
(marker-buffer marker))) (marker-buffer marker)))