summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRavi R Kiran <aine.marina@gmail.com>2022-04-03 02:57:39 (GMT)
committerRavi R Kiran <aine.marina@gmail.com>2022-04-03 02:57:39 (GMT)
commit5965037037e8ea97d4036aede6bf9dd5ff612f07 (patch)
treeab954e622bb4dd32ffc14b8b050507e0501b2add
parentd19ad0f585cbf4d8d771565ed114636b7f1a2117 (diff)
downloaddotemacs-5965037037e8ea97d4036aede6bf9dd5ff612f07.zip
dotemacs-5965037037e8ea97d4036aede6bf9dd5ff612f07.tar.gz
dotemacs-5965037037e8ea97d4036aede6bf9dd5ff612f07.tar.bz2
Marginalia and embark integration
-rw-r--r--lisp/consult-dash.el53
1 files changed, 49 insertions, 4 deletions
diff --git a/lisp/consult-dash.el b/lisp/consult-dash.el
index 25594d7..b78b65f 100644
--- a/lisp/consult-dash.el
+++ b/lisp/consult-dash.el
@@ -93,11 +93,16 @@
(when (string-prefix-p consult-dash--docset-prefix str)
(setq consult-dash--current-docset (substring str (length consult-dash--docset-prefix))))
(let ((name (cadr current-candidate))
- (type (car current-candidate)))
+ (type (car current-candidate))
+ (path (caddr current-candidate))
+ (anchor (cadddr current-candidate)))
(add-face-text-property 0 (length name) 'consult-key nil name)
- (put-text-property 0 (length name) 'consult-dash-docset consult-dash--current-docset name)
+ (put-text-property 0 (length name)
+ 'consult-dash-docinfo
+ (list consult-dash--current-docset type path anchor)
+ name)
(push (list
- (format "%s (%s)" name type)
+ name ;; replaces(format "%s (%s)" name type)
consult-dash--current-docset
current-candidate)
candidates)))))
@@ -106,7 +111,24 @@
(defun consult-dash--group (candidate transform)
(if transform
candidate
- (get-text-property 0 'consult-dash-docset candidate)))
+ (car (get-text-property 0 'consult-dash-docinfo candidate))))
+
+(defun consult-dash--annotate (candidate)
+ (seq-let (docset-name type filename anchor) (get-text-property 0 'consult-dash-docinfo candidate)
+ (format " %s %s: %s%s" docset-name type filename (if anchor (format "#%s" anchor) ""))))
+
+(defun consult-dash-candidate-url (candidate)
+ (seq-let (docset-name type filename anchor) (get-text-property 0 'consult-dash-docinfo candidate)
+ (dash-docs-result-url docset-name filename anchor)))
+
+(defun consult-dash-yank-candidate-url (candidate)
+ (if-let (url (consult-dash-candidate-url candidate))
+ (kill-new url)
+ (message "No URL for this candidate")))
+
+(defun consult-dash--open-url (candidate)
+ (seq-let (docset-name type filename anchor) (get-text-property 0 'consult-dash-docinfo candidate)
+ (funcall dash-docs-browser-func (dash-docs-result-url docset-name filename anchor))))
(defun consult-dash (&optional initial)
(interactive)
@@ -122,6 +144,8 @@
:require-match t
:group #'consult-dash--group
:lookup #'consult--lookup-cdr
+ :category 'consult-dash-result
+ :annotate #'consult-dash--annotate
:initial (consult--async-split-initial initial)
:add-history (consult--async-split-thingatpt 'symbol)
:history '(:input consult-dash--history))))
@@ -131,5 +155,26 @@
(interactive)
(consult-dash (thing-at-point 'symbol)))
+;; Embark integration
+(with-eval-after-load "embark"
+ (embark-define-keymap consult-dash-embark-keymap
+ "Actions for consult dash results"
+ ("RET" consult-dash--open-url)
+ ("y" consult-dash-yank-candidate-url))
+ (add-to-list 'embark-keymap-alist
+ '(consult-dash-result . consult-dash-embark-keymap)))
+
+;; Marginalia integration
+(with-eval-after-load "marginalia"
+ (defun consult-dash--annotate-marginalia (candidate)
+ (seq-let (docset-name type filename anchor) (get-text-property 0 'consult-dash-docinfo candidate)
+ (when (and type filename docset-name)
+ (marginalia--fields
+ (docset-name)
+ (type)
+ ((format "%s%s" filename (if anchor (format "#%s" anchor) "")))))))
+ (add-to-list 'marginalia-annotator-registry
+ '(consult-dash-result consult-dash--annotate-marginalia)))
+
(provide 'consult-dash)
;;; consult-dash.el ends here