This commit is contained in:
Ihor Radchenko 2025-05-04 23:59:42 +00:00 committed by GitHub
commit 81b0a9ab6e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -99,6 +99,17 @@ Based on `helm-map'.")
:type '(alist :key-type (string :tag "Description") :type '(alist :key-type (string :tag "Description")
:value-type (function :tag "Command"))) :value-type (function :tag "Command")))
(defcustom helm-org-ql-create-new t
"When non-nil, allow creating new heading using the search query.
New heading will be added using `org-capture' according to
`helm-org-ql-create-new-capture-template'."
:type 'boolean)
(defcustom helm-org-ql-create-new-capture-template nil
"Capture template used to create a new heading.
When non-nil, it should be a string associated with a template in `org-capture-templates'."
:type '(choice boolean string))
;;;; Commands ;;;; Commands
;;;###autoload ;;;###autoload
@ -137,7 +148,11 @@ Is transformed into this query:
(let ((boolean (if current-prefix-arg 'or boolean)) (let ((boolean (if current-prefix-arg 'or boolean))
(helm-input-idle-delay helm-org-ql-input-idle-delay)) (helm-input-idle-delay helm-org-ql-input-idle-delay))
(helm :prompt (format "Query (boolean %s): " (-> boolean symbol-name upcase)) (helm :prompt (format "Query (boolean %s): " (-> boolean symbol-name upcase))
:sources (helm-org-ql-source buffers-files :name name)))) :sources (let ((main-source (helm-org-ql-source buffers-files :name name)))
(if helm-org-ql-create-new
(list main-source
(helm-org-ql-create-new-source))
main-source)))))
;;;###autoload ;;;###autoload
(defun helm-org-ql-agenda-files () (defun helm-org-ql-agenda-files ()
@ -208,6 +223,24 @@ Is transformed into this query:
:keymap helm-org-ql-map :keymap helm-org-ql-map
:action helm-org-ql-actions)) :action helm-org-ql-actions))
(defun helm-org-ql-create-new-source ()
"Helm source used to capture new headings."
(helm-build-sync-source "Create new"
:candidates
(lambda ()
(if (string-empty-p helm-pattern)
(list "New note")
(list (format "New note: \"%s\"" (string-clean-whitespace helm-pattern)))))
:match #'identity
:match-dynamic t
:nohighlight t
:action
'(("New note" . (lambda (_)
(progn
(org-link-store-props :annotation helm-pattern)
(let ((org-capture-link-is-already-stored t))
(org-capture nil helm-org-ql-create-new-capture-template))))))))
(defun helm-org-ql--heading (window-width) (defun helm-org-ql--heading (window-width)
"Return string for Helm for heading at point. "Return string for Helm for heading at point.
WINDOW-WIDTH should be the width of the Helm window." WINDOW-WIDTH should be the width of the Helm window."