Use consult for querying Org refile locations

This commit is contained in:
Daniel Borchmann 2025-08-17 17:17:50 +02:00
parent 44fb922b66
commit 1ccc8d927d
No known key found for this signature in database
GPG Key ID: 50EA937BF472ADD1
2 changed files with 30 additions and 1 deletions

10
init.el
View File

@ -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)

View File

@ -480,6 +480,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
(warn "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