2019-04-21 19:59:44 -04:00
|
|
|
;;; tools/lookup/config.el -*- lexical-binding: t; -*-
|
2018-01-04 17:05:37 -05:00
|
|
|
|
|
|
|
;; "What am I looking at?" This module helps you answer this question.
|
|
|
|
;;
|
|
|
|
;; + `+lookup/definition': a jump-to-definition that should 'just work'
|
2020-05-12 00:43:16 +09:00
|
|
|
;; + `+lookup/implementations': find a symbol's implementations in the current
|
|
|
|
;; project
|
2018-01-04 17:05:37 -05:00
|
|
|
;; + `+lookup/references': find a symbol's references in the current project
|
2019-04-16 20:22:17 -04:00
|
|
|
;; + `+lookup/file': open the file referenced at point
|
2018-01-04 17:05:37 -05:00
|
|
|
;; + `+lookup/online'; look up a symbol on online resources
|
2018-08-28 20:48:49 +02:00
|
|
|
;; + `+lookup/in-docsets': look up in Dash docsets
|
2018-01-04 17:05:37 -05:00
|
|
|
;;
|
|
|
|
;; This module uses `xref', an experimental new library in Emacs. It may change
|
|
|
|
;; in the future. When xref can't be depended on it will fall back to
|
|
|
|
;; `dumb-jump' to find what you want.
|
|
|
|
|
|
|
|
(defvar +lookup-provider-url-alist
|
2020-01-09 19:11:49 -05:00
|
|
|
(append '(("Doom Emacs issues" "https://github.com/hlissner/doom-emacs/issues?q=is%%3Aissue+%s")
|
|
|
|
("Google" +lookup--online-backend-google "https://google.com/search?q=%s")
|
2019-12-15 17:59:20 -05:00
|
|
|
("Google images" "https://www.google.com/images?q=%s")
|
|
|
|
("Google maps" "https://maps.google.com/maps?q=%s")
|
|
|
|
("Project Gutenberg" "http://www.gutenberg.org/ebooks/search/?query=%s")
|
2019-12-29 19:21:09 -05:00
|
|
|
("DuckDuckGo" +lookup--online-backend-duckduckgo "https://duckduckgo.com/?q=%s")
|
2019-12-15 17:59:20 -05:00
|
|
|
("DevDocs.io" "https://devdocs.io/#q=%s")
|
|
|
|
("StackOverflow" "https://stackoverflow.com/search?q=%s")
|
|
|
|
("Github" "https://github.com/search?ref=simplesearch&q=%s")
|
|
|
|
("Youtube" "https://youtube.com/results?aq=f&oq=&search_query=%s")
|
|
|
|
("Wolfram alpha" "https://wolframalpha.com/input/?i=%s")
|
2020-12-08 22:20:56 -05:00
|
|
|
("Wikipedia" "https://wikipedia.org/search-redirect.php?language=en&go=Go&search=%s")
|
|
|
|
("MDN" "https://developer.mozilla.org/en-US/search?q=%s"))
|
2019-07-09 17:55:35 +02:00
|
|
|
(when (featurep! :lang rust)
|
2020-06-23 22:17:08 +01:00
|
|
|
'(("Rust Docs" "https://doc.rust-lang.org/std/?search=%s"))))
|
2019-12-15 17:59:20 -05:00
|
|
|
"An alist that maps online resources to either:
|
|
|
|
|
|
|
|
1. A search url (needs on '%s' to substitute with an url encoded query),
|
|
|
|
2. A non-interactive function that returns the search url in #1,
|
|
|
|
3. An interactive command that does its own search for that provider.
|
|
|
|
|
|
|
|
Used by `+lookup/online'.")
|
2018-01-04 17:05:37 -05:00
|
|
|
|
|
|
|
(defvar +lookup-open-url-fn #'browse-url
|
|
|
|
"Function to use to open search urls.")
|
|
|
|
|
2018-09-12 23:11:22 -04:00
|
|
|
(defvar +lookup-definition-functions
|
2020-08-06 00:19:56 -04:00
|
|
|
'(+lookup-dictionary-definition-backend-fn
|
|
|
|
+lookup-xref-definitions-backend-fn
|
2019-07-22 23:45:31 +02:00
|
|
|
+lookup-dumb-jump-backend-fn
|
|
|
|
+lookup-project-search-backend-fn
|
|
|
|
+lookup-evil-goto-definition-backend-fn)
|
2018-04-22 23:55:49 -04:00
|
|
|
"Functions for `+lookup/definition' to try, before resorting to `dumb-jump'.
|
|
|
|
Stops at the first function to return non-nil or change the current
|
2018-05-11 20:22:37 +02:00
|
|
|
window/point.
|
|
|
|
|
|
|
|
If the argument is interactive (satisfies `commandp'), it is called with
|
|
|
|
`call-interactively' (with no arguments). Otherwise, it is called with one
|
2019-05-03 20:44:23 -04:00
|
|
|
argument: the identifier at point. See `set-lookup-handlers!' about adding to
|
|
|
|
this list.")
|
2018-01-04 17:05:37 -05:00
|
|
|
|
2020-05-12 00:43:16 +09:00
|
|
|
(defvar +lookup-implementations-functions ()
|
|
|
|
"Function for `+lookup/implementations' to try. Stops at the first function to
|
|
|
|
return non-nil or change the current window/point.
|
|
|
|
|
|
|
|
If the argument is interactive (satisfies `commandp'), it is called with
|
|
|
|
`call-interactively' (with no arguments). Otherwise, it is called with one
|
|
|
|
argument: the identifier at point. See `set-lookup-handlers!' about adding to
|
|
|
|
this list.")
|
|
|
|
|
2020-05-12 01:06:23 +09:00
|
|
|
(defvar +lookup-type-definition-functions ()
|
|
|
|
"Functions for `+lookup/type-definition' to try. Stops at the first function to
|
|
|
|
return non-nil or change the current window/point.
|
|
|
|
|
|
|
|
If the argument is interactive (satisfies `commandp'), it is called with
|
|
|
|
`call-interactively' (with no arguments). Otherwise, it is called with one
|
|
|
|
argument: the identifier at point. See `set-lookup-handlers!' about adding to
|
|
|
|
this list.")
|
|
|
|
|
2018-09-12 23:11:22 -04:00
|
|
|
(defvar +lookup-references-functions
|
2020-08-06 00:19:56 -04:00
|
|
|
'(+lookup-thesaurus-definition-backend-fn
|
|
|
|
+lookup-xref-references-backend-fn
|
2019-07-22 23:45:31 +02:00
|
|
|
+lookup-project-search-backend-fn)
|
2018-04-22 23:55:49 -04:00
|
|
|
"Functions for `+lookup/references' to try, before resorting to `dumb-jump'.
|
|
|
|
Stops at the first function to return non-nil or change the current
|
2018-05-11 20:22:37 +02:00
|
|
|
window/point.
|
|
|
|
|
|
|
|
If the argument is interactive (satisfies `commandp'), it is called with
|
|
|
|
`call-interactively' (with no arguments). Otherwise, it is called with one
|
2019-05-03 20:44:23 -04:00
|
|
|
argument: the identifier at point. See `set-lookup-handlers!' about adding to
|
|
|
|
this list.")
|
2018-04-22 23:55:49 -04:00
|
|
|
|
2018-09-12 23:11:22 -04:00
|
|
|
(defvar +lookup-documentation-functions
|
2019-07-22 23:45:31 +02:00
|
|
|
'(+lookup-online-backend-fn)
|
2018-04-22 23:55:49 -04:00
|
|
|
"Functions for `+lookup/documentation' to try, before resorting to
|
|
|
|
`dumb-jump'. Stops at the first function to return non-nil or change the current
|
2018-05-11 20:22:37 +02:00
|
|
|
window/point.
|
|
|
|
|
|
|
|
If the argument is interactive (satisfies `commandp'), it is called with
|
|
|
|
`call-interactively' (with no arguments). Otherwise, it is called with one
|
2019-05-03 20:44:23 -04:00
|
|
|
argument: the identifier at point. See `set-lookup-handlers!' about adding to
|
|
|
|
this list.")
|
2018-05-11 20:22:37 +02:00
|
|
|
|
2020-10-29 15:01:04 -04:00
|
|
|
(defvar +lookup-file-functions
|
2021-04-29 14:30:17 -04:00
|
|
|
'(+lookup-bug-reference-backend-fn
|
|
|
|
+lookup-ffap-backend-fn)
|
2018-05-11 20:22:37 +02:00
|
|
|
"Function for `+lookup/file' to try, before restoring to `find-file-at-point'.
|
|
|
|
Stops at the first function to return non-nil or change the current
|
|
|
|
window/point.
|
|
|
|
|
|
|
|
If the argument is interactive (satisfies `commandp'), it is called with
|
|
|
|
`call-interactively' (with no arguments). Otherwise, it is called with one
|
2019-05-03 20:44:23 -04:00
|
|
|
argument: the identifier at point. See `set-lookup-handlers!' about adding to
|
|
|
|
this list.")
|
2018-01-04 17:05:37 -05:00
|
|
|
|
2020-01-25 16:55:04 -05:00
|
|
|
(defvar +lookup-dictionary-prefer-offline (featurep! +offline)
|
2019-12-20 00:43:36 -05:00
|
|
|
"If non-nil, look up dictionaries online.
|
|
|
|
|
|
|
|
Setting this to nil will force it to use offline backends, which may be less
|
|
|
|
than perfect, but available without an internet connection.
|
|
|
|
|
2020-01-25 16:55:04 -05:00
|
|
|
Used by `+lookup/dictionary-definition' and `+lookup/synonyms'.
|
2019-12-20 00:43:36 -05:00
|
|
|
|
2020-01-25 16:55:04 -05:00
|
|
|
For `+lookup/dictionary-definition', this is ignored on Mac, where Emacs users
|
2019-12-20 00:43:36 -05:00
|
|
|
Dictionary.app behind the scenes to get definitions.")
|
|
|
|
|
2018-01-04 17:05:37 -05:00
|
|
|
|
|
|
|
;;
|
2019-04-16 20:22:17 -04:00
|
|
|
;;; dumb-jump
|
2018-01-04 17:05:37 -05:00
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! dumb-jump
|
2018-05-25 00:46:11 +02:00
|
|
|
:commands dumb-jump-result-follow
|
2018-01-04 17:05:37 -05:00
|
|
|
:config
|
|
|
|
(setq dumb-jump-default-project doom-emacs-dir
|
2020-04-26 16:50:26 -04:00
|
|
|
dumb-jump-prefer-searcher 'rg
|
2018-01-04 17:05:37 -05:00
|
|
|
dumb-jump-aggressive nil
|
|
|
|
dumb-jump-selector
|
|
|
|
(cond ((featurep! :completion ivy) 'ivy)
|
|
|
|
((featurep! :completion helm) 'helm)
|
2019-04-21 23:22:06 -04:00
|
|
|
('popup)))
|
|
|
|
(add-hook 'dumb-jump-after-jump-hook #'better-jumper-set-jump))
|
2018-01-04 17:05:37 -05:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
2019-04-16 20:22:17 -04:00
|
|
|
;;; xref
|
2018-01-04 17:05:37 -05:00
|
|
|
|
2019-07-13 15:46:15 +02:00
|
|
|
;; The lookup commands are superior, and will consult xref if there are no
|
|
|
|
;; better backends available.
|
|
|
|
(global-set-key [remap xref-find-definitions] #'+lookup/definition)
|
|
|
|
(global-set-key [remap xref-find-references] #'+lookup/references)
|
|
|
|
|
2019-04-30 15:11:23 -04:00
|
|
|
(after! xref
|
|
|
|
;; We already have `projectile-find-tag' and `evil-jump-to-tag', no need for
|
|
|
|
;; xref to be one too.
|
2019-05-03 20:03:32 -04:00
|
|
|
(remove-hook 'xref-backend-functions #'etags--xref-backend)
|
2019-05-03 20:44:23 -04:00
|
|
|
;; ...however, it breaks `projectile-find-tag', unless we put it back.
|
2021-08-04 01:18:06 -04:00
|
|
|
(defadvice! +lookup--projectile-find-tag-a (fn)
|
2019-07-22 23:45:31 +02:00
|
|
|
:around #'projectile-find-tag
|
2019-05-03 20:44:23 -04:00
|
|
|
(let ((xref-backend-functions '(etags--xref-backend t)))
|
2021-08-04 01:18:06 -04:00
|
|
|
(funcall fn)))
|
2019-05-03 20:44:23 -04:00
|
|
|
|
2020-10-09 04:41:45 -04:00
|
|
|
;; This integration is already built into evil
|
|
|
|
(unless (featurep! :editor evil)
|
|
|
|
;; Use `better-jumper' instead of xref's marker stack
|
|
|
|
(advice-add #'xref-push-marker-stack :around #'doom-set-jump-a))
|
2018-01-04 17:05:37 -05:00
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! ivy-xref
|
2019-05-12 01:45:48 -04:00
|
|
|
:when (featurep! :completion ivy)
|
2019-05-14 21:35:30 -04:00
|
|
|
:config
|
2020-04-24 15:12:33 -04:00
|
|
|
(set-popup-rule! "^\\*xref\\*$" :ignore t)
|
2021-07-10 15:52:19 +03:00
|
|
|
(setq xref-show-definitions-function #'ivy-xref-show-defs
|
|
|
|
xref-show-xrefs-function #'ivy-xref-show-xrefs)
|
2020-12-08 22:44:53 -05:00
|
|
|
|
|
|
|
;; HACK Fix #4386: `ivy-xref-show-xrefs' calls `fetcher' twice, which has
|
|
|
|
;; side effects that breaks in some cases (i.e. on `dired-do-find-regexp').
|
2021-08-04 01:18:06 -04:00
|
|
|
(defadvice! +lookup--fix-ivy-xrefs (fn fetcher alist)
|
2020-12-08 22:44:53 -05:00
|
|
|
:around #'ivy-xref-show-xrefs
|
|
|
|
(when (functionp fetcher)
|
|
|
|
(setf (alist-get 'fetched-xrefs alist)
|
|
|
|
(funcall fetcher)))
|
2021-08-04 01:18:06 -04:00
|
|
|
(funcall fn fetcher alist)))
|
2018-01-04 17:05:37 -05:00
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! helm-xref
|
2021-05-08 23:36:14 +03:00
|
|
|
:when (featurep! :completion helm))
|
|
|
|
|
|
|
|
(use-package! consult-xref
|
2021-07-09 20:16:11 +03:00
|
|
|
:when (featurep! :completion vertico)
|
2021-05-08 23:36:14 +03:00
|
|
|
:init
|
|
|
|
(setq xref-show-xrefs-function #'consult-xref
|
|
|
|
xref-show-definitions-function #'consult-xref)))
|
2018-01-04 17:05:37 -05:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
2019-04-16 20:22:17 -04:00
|
|
|
;;; Dash docset integration
|
2018-01-04 17:05:37 -05:00
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! dash-docs
|
2018-06-22 01:48:04 +02:00
|
|
|
:when (featurep! +docsets)
|
2019-11-08 04:10:16 -05:00
|
|
|
:defer t
|
2018-06-22 01:48:04 +02:00
|
|
|
:init
|
2019-07-22 23:45:31 +02:00
|
|
|
(add-hook '+lookup-documentation-functions #'+lookup-dash-docsets-backend-fn)
|
2018-06-22 01:48:04 +02:00
|
|
|
:config
|
2020-05-25 02:58:07 -04:00
|
|
|
(setq dash-docs-enable-debugging doom-debug-p
|
2019-05-12 01:45:48 -04:00
|
|
|
dash-docs-docsets-path (concat doom-etc-dir "docsets/")
|
|
|
|
dash-docs-min-length 2
|
|
|
|
dash-docs-browser-func #'eww)
|
|
|
|
|
2020-04-23 23:49:35 -04:00
|
|
|
(cond ((featurep! :completion helm)
|
|
|
|
(require 'helm-dash nil t))
|
|
|
|
((featurep! :completion ivy)
|
|
|
|
(require 'counsel-dash nil t))))
|
2019-12-20 00:43:36 -05:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;;; Dictionary integration
|
|
|
|
|
|
|
|
(use-package! define-word
|
|
|
|
:when (featurep! +dictionary)
|
|
|
|
:unless IS-MAC
|
|
|
|
:defer t
|
|
|
|
:config
|
2021-09-27 21:27:55 +02:00
|
|
|
;; REVIEW Temporarily fix abo-abo/define-word#31
|
|
|
|
(defadvice! +lookup--fix-define-word-a (fn &rest args)
|
|
|
|
"Fix `define-word' backends that require a user agent (like wordnik)."
|
|
|
|
:around #'define-word
|
|
|
|
(let ((url-request-extra-headers
|
|
|
|
'(("User-Agent" .
|
|
|
|
"Mozilla/5.0 (Macintosh; Intel Mac OS X 11_5_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36"))))
|
|
|
|
(apply fn args)))
|
|
|
|
|
2019-12-20 00:43:36 -05:00
|
|
|
(setq define-word-displayfn-alist
|
|
|
|
(cl-loop for (service . _) in define-word-services
|
|
|
|
collect (cons service #'+eval-display-results-in-popup))))
|
|
|
|
|
|
|
|
|
2020-01-25 16:55:04 -05:00
|
|
|
;;;###package synosaurus
|
|
|
|
(setq synosaurus-choose-method 'default) ; use ivy/helm instead of ido
|