diff --git a/init.el b/init.el index c008c01..9f1cd8c 100644 --- a/init.el +++ b/init.el @@ -703,6 +703,7 @@ split horizontally again, but this extra work should not matter much." db/org-clock-goto-first-open-checkbox) :autoload (db/check-special-org-files-in-agenda db/verify-refile-target + db/org-refile-get-location db/find-parent-task db/ensure-running-clock db/save-current-org-task-to-file @@ -948,7 +949,14 @@ split horizontally again, but this extra work should not matter much." (org-agenda-redo-all)) ;; Inhibit direct input when point is at the beginning of a headline. - (add-to-list 'org-speed-command-hook 'db/org-ignore-insert-on-headline-start))) + (add-to-list 'org-speed-command-hook 'db/org-ignore-insert-on-headline-start) + + ;; Use consult for querying refile targets + (define-advice org-refile-get-location (:around + (orig-func prompt default-buffer new-nodes) + use-consult-instead) + (ignore orig-func) + (db/org-refile-get-location prompt default-buffer new-nodes)))) (use-package org-cycle :autoload (org-cycle-hide-drawers) diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index 3ac4f45..9be4098 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -478,6 +478,27 @@ Via %%(with-temp-buffer (db/org-add-link-to-current-clock) (string-trim (buffer- ;; any agenda when a super-item is tagged with :HOLD:. (not (member "HOLD" (org-get-tags (point)))))) +(defun db/org-refile-get-location (prompt default-buffer new-nodes) + "Replacement function for `org-refile-get-location' using `consult'. + +This function can be used instead of `org-refile-get-location', +e.g. using `define-advice'. The parameters PROMPT, DEFAULT-BUFFER, and +NEW-NODES have the same meaning. However, setting NEW-NODES to a +non-nil value will result in a warning, as creating new headlings is not +supported with this function. + +Also note that the usual variables governing the behavior of +`org-refile' do not have any effect here. In particular, +`org-refile-verify-target-function' is not (yet) considered." + (when new-nodes + (error "Cannot create new nodes (yet) with consult interface for `org-refile'")) + (let ((pom (with-current-buffer (or default-buffer (current-buffer)) + (db/org-get-location t nil (concat prompt " "))))) ; TODO: incorporate verify function + (list (buffer-name (marker-buffer pom)) + (buffer-file-name (marker-buffer pom)) + "" ; some regexp matching the headline? + (marker-position pom)))) + ;;; Helper Functions for Clocking