Skip to content

Commit

Permalink
consult-org: Extract consult-org--group, add buffer name property
Browse files Browse the repository at this point in the history
  • Loading branch information
minad committed Mar 23, 2024
1 parent f356474 commit 8943a4a
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions consult-org.el
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
(apply #'append (mapcar #'cdr org-todo-keywords))))))
(list :predicate
(lambda (cand)
(pcase-let ((`(,level ,todo . ,prio)
(pcase-let ((`(,level ,todo ,prio . ,_)
(get-text-property 0 'consult-org--heading cand)))
(cond
((<= ?1 consult--narrow ?9) (<= level (- consult--narrow ?0)))
Expand Down Expand Up @@ -79,28 +79,31 @@ MATCH, SCOPE and SKIP are as in `org-map-entries'."
(put-text-property 0 (length todo) 'face (org-get-todo-face todo) todo))
(when tags
(put-text-property 0 (length tags) 'face 'org-tag tags))
(setq cand (if prefix
(concat buffer " " cand (and tags " ")
tags (consult--tofu-encode idx))
(concat cand (and tags " ")
tags (consult--tofu-encode idx))))
(setq cand (concat (and prefix buffer) (and prefix " ") cand (and tags " ")
tags (consult--tofu-encode idx)))
(cl-incf idx)
(add-text-properties 0 1
`(org-marker ,(point-marker)
consult-org--heading (,level ,todo . ,prio))
consult-org--heading (,level ,todo ,prio . ,(and prefix buffer)))
cand)
cand))
match scope skip)))

(defun consult-org--annotate (cand)
"Annotate CAND for `consult-org-heading'."
(pcase-let ((`(,_level ,todo . ,prio)
(pcase-let ((`(,_level ,todo ,prio . ,_)
(get-text-property 0 'consult-org--heading cand)))
(consult--annotate-align
cand
(concat todo
(and prio (format #(" [#%c]" 1 6 (face org-priority)) prio))))))

(defun consult-org--group (cand transform)
"Return title for CAND or TRANSFORM the candidate."
(pcase-let ((`(,_level ,_todo ,_prio . ,buffer)
(get-text-property 0 'consult-org--heading cand)))
(if transform (substring cand (1+ (length buffer))) buffer)))

;;;###autoload
(defun consult-org-heading (&optional match scope)
"Jump to an Org heading.
Expand All @@ -123,13 +126,7 @@ buffer are offered."
:narrow (consult-org--narrow)
:state (consult--jump-state)
:annotate #'consult-org--annotate
:group
(when prefix
(lambda (cand transform)
(let ((name (buffer-name
(marker-buffer
(get-text-property 0 'org-marker cand)))))
(if transform (substring cand (1+ (length name))) name))))
:group (and prefix #'consult-org--group)
:lookup (apply-partially #'consult--lookup-prop 'org-marker))))

;;;###autoload
Expand Down

0 comments on commit 8943a4a

Please sign in to comment.