diff options
| author | Ravi R Kiran <aine.marina@gmail.com> | 2022-03-27 20:32:40 (GMT) |
|---|---|---|
| committer | Ravi R Kiran <aine.marina@gmail.com> | 2022-03-27 20:32:40 (GMT) |
| commit | f79eb3de1cb18941f22e512853d983cea3c00c8f (patch) | |
| tree | 65d8a6b6d6051488c72cf3b22f92269d39b8bf3d /lisp/ravi-init-completion.el | |
| parent | a0488d12d96af50fb2d73ad13ab08d8ae5dd9496 (diff) | |
| download | dotemacs-f79eb3de1cb18941f22e512853d983cea3c00c8f.zip dotemacs-f79eb3de1cb18941f22e512853d983cea3c00c8f.tar.gz dotemacs-f79eb3de1cb18941f22e512853d983cea3c00c8f.tar.bz2 | |
Implementation of dash-at-point with consult
Diffstat (limited to 'lisp/ravi-init-completion.el')
| -rw-r--r-- | lisp/ravi-init-completion.el | 94 |
1 files changed, 12 insertions, 82 deletions
diff --git a/lisp/ravi-init-completion.el b/lisp/ravi-init-completion.el index 9cc9ef5..1c973d8 100644 --- a/lisp/ravi-init-completion.el +++ b/lisp/ravi-init-completion.el @@ -335,89 +335,19 @@ (use-package dash-docs :if (member ravi/use-selection-system '(selectrum vertico)) :after (avy) - :bind (("M-s d" . 'ravi/dash) - ("M-s D" . 'ravi/dash-at-point)) + :commands (consult-dash) + :bind (("M-s d" . consult-dash-at-point)) :config - (require 'cl-lib) ; for cl-remove-duplicates, cl-find-if - (require 'subr-x) ; for when-let - - (defvar ravi/dash-history-input nil) - (defvar ravi/dash--results nil - "Stores the previously retrieved docset results") - (defvar-local ravi/dash-docsets nil - "Docsets to use for this buffer") - - (advice-add #'dash-docs-buffer-local-docsets :around - (lambda (old-fun &rest args) - (let ((old (apply old-fun args))) - (cl-remove-duplicates (append old ravi/dash-docsets))))) - - (defun ravi/dash--collection (s &rest _) - "Given a string S, query docsets and retrieve result." - (message "Trying to search for: %s" (prin1-to-string s)) - (setq ravi/dash--results (dash-docs-search s)) - (mapcar 'car ravi/dash--results)) - - (defun ravi/dash--browse-matching-result (match) - "Given a MATCH, find matching result and browse it's url." - (when-let ((result - (cdr (cl-find-if (lambda (e) - (string= match (car e))) ravi/dash--results)))) - (dash-docs-browse-url result))) - - ;; The following does not work, because vertico and selectrum don't support dynamic completions - (defun ravi/dash (&optional initial) - "Query dash docsets. -INITIAL will be used as the initial input, if given." - (interactive) - (dash-docs-initialize-debugging-buffer) - (dash-docs-create-buffer-connections) - (dash-docs-create-common-connections) - (if t - (ravi/dash--browse-matching-result - (let ((cb (current-buffer))) - (completing-read - "Documentation for: " - ;; (completion-table-dynamic (lambda (s) (with-current-buffer cb (ravi/dash--collection s)))) - (completion-table-dynamic #'ravi/dash--collection t) - nil ; predicate - t ; require-match - nil ; initial-input - 'ravi/dash-history-input ; history - (when-let ((sym (thing-at-point 'symbol))) (substring-no-properties sym))))) ; default, a.k.a future history - (message "%s" (prin1-to-string (ravi/dash--collection "C++ throw"))))) - - (defun ravi/dash-at-point-what-it-should-be () - "Bring up a `ravi/dash' search interface with symbol at point." - (interactive) - (ravi/dash - (substring-no-properties (or (thing-at-point 'symbol) "")))) - - (defun ravi/dash-at-point () - "Bring up a `ravi/dash' search interface with symbol at point." - (interactive) - (dash-docs-initialize-debugging-buffer) - (dash-docs-create-buffer-connections) - (dash-docs-create-common-connections) - (if-let* ((sym (thing-at-point 'symbol)) - (sym-only (substring-no-properties sym)) - (cb (current-buffer)) - (table (with-current-buffer cb (ravi/dash--collection sym-only))) - (result (completing-read (format "Documentation for '%s':" sym-only) - table nil t nil 'ravi/dash-history-input))) - (progn - (ravi/dash--browse-matching-result result) - (add-to-list 'ravi/dash-history-input sym-only)) - (user-error "No symbol at point or documentation not found"))) - - (defun avy-action-dash-at-point (pt) - (save-excursion - (goto-char pt) - (ravi/dash-at-point)) - (select-window (cdr (ring-ref avy-ring 0))) - t) - (setf (alist-get ?D avy-dispatch-alist) 'avy-action-dash-at-point) - ) + (use-package consult-dash + :config + (defun avy-action-dash-at-point (pt) + (save-excursion + (goto-char pt) + (consult-dash-at-point)) + (select-window (cdr (ring-ref avy-ring 0))) + t) + (setf (alist-get ?D avy-dispatch-alist) 'avy-action-dash-at-point) + :ensure nil)) (use-package consult-dir :commands (consult-dir) |
