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'
|
|
|
|
;; + `+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
|
2019-07-09 17:55:35 +02:00
|
|
|
(append '(("Google" . "https://google.com/search?q=%s")
|
|
|
|
("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")
|
|
|
|
("DuckDuckGo" . "https://duckduckgo.com/?q=%s")
|
|
|
|
("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")
|
|
|
|
("Wikipedia" . "https://wikipedia.org/search-redirect.php?language=en&go=Go&search=%s"))
|
|
|
|
(when (featurep! :lang rust)
|
|
|
|
'(("Rust Docs" . "https://doc.rust-lang.org/edition-guide/?search=%s"))))
|
2018-01-04 17:05:37 -05:00
|
|
|
"An alist that maps online resources to their search url or a function that
|
|
|
|
produces an url. Used by `+lookup/online'.")
|
|
|
|
|
|
|
|
(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
|
2019-07-22 23:45:31 +02:00
|
|
|
'(+lookup-xref-definitions-backend-fn
|
|
|
|
+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
|
|
|
|
2018-09-12 23:11:22 -04:00
|
|
|
(defvar +lookup-references-functions
|
2019-07-22 23:45:31 +02:00
|
|
|
'(+lookup-xref-references-backend-fn
|
|
|
|
+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
|
|
|
|
|
|
|
(defvar +lookup-file-functions ()
|
|
|
|
"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
|
|
|
|
|
|
|
|
|
|
|
;;
|
2019-04-16 20:22:17 -04:00
|
|
|
;;; dumb-jump
|
2018-01-04 17:05:37 -05:00
|
|
|
|
|
|
|
(def-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
|
|
|
|
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.
|
2019-07-22 23:45:31 +02:00
|
|
|
(def-advice! +lookup-projectile-find-tag-a (orig-fn)
|
|
|
|
:around #'projectile-find-tag
|
2019-05-03 20:44:23 -04:00
|
|
|
(let ((xref-backend-functions '(etags--xref-backend t)))
|
|
|
|
(funcall orig-fn)))
|
|
|
|
|
|
|
|
;; Use `better-jumper' instead of xref's marker stack
|
:boom: revise advice naming convention (1/2)
This is first of three big naming convention updates that have been a
long time coming. With 2.1 on the horizon, all the breaking updates will
batched together in preparation for the long haul.
In this commit, we do away with the asterix to communicate that a
function is an advice function, and we replace it with the '-a' suffix.
e.g.
doom*shut-up -> doom-shut-up-a
doom*recenter -> doom-recenter-a
+evil*static-reindent -> +evil--static-reindent-a
The rationale behind this change is:
1. Elisp's own formatting/indenting tools would occasionally struggle
with | and * (particularly pp and cl-prettyprint). They have no
problem with / and :, fortunately.
2. External syntax highlighters (like pygmentize, discord markdown or
github markdown) struggle with it, sometimes refusing to highlight
code beyond these symbols.
3. * and | are less expressive than - and -- in communicating the
intended visibility, versatility and stability of a function.
4. It complicated the regexps we must use to search for them.
5. They were arbitrary and over-complicated to begin with, decided
on haphazardly way back when Doom was simply "my private config".
Anyhow, like how predicate functions have the -p suffix, we'll adopt the
-a suffix for advice functions, -h for hook functions and -fn for
variable functions.
Other noteable changes:
- Replaces advice-{add,remove}! macro with new def-advice!
macro. The old pair weren't as useful. The new def-advice! saves on a
lot of space.
- Removed "stage" assertions to make sure you were using the right
macros in the right place. Turned out to not be necessary, we'll
employ better checks later.
2019-07-18 15:42:52 +02:00
|
|
|
(advice-add #'xref-push-marker-stack :around #'doom-set-jump-a)
|
2018-01-04 17:05:37 -05:00
|
|
|
|
2019-05-12 01:45:48 -04:00
|
|
|
(def-package! ivy-xref
|
|
|
|
:when (featurep! :completion ivy)
|
2019-05-14 21:35:30 -04:00
|
|
|
:config
|
|
|
|
(setq xref-show-xrefs-function #'ivy-xref-show-xrefs)
|
|
|
|
(set-popup-rule! "^\\*xref\\*$" :ignore t))
|
2018-01-04 17:05:37 -05:00
|
|
|
|
2019-05-12 01:45:48 -04:00
|
|
|
(def-package! helm-xref
|
|
|
|
:when (featurep! :completion helm)
|
|
|
|
:config (setq xref-show-xrefs-function #'helm-xref-show-xrefs)))
|
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-05-12 01:45:48 -04:00
|
|
|
(def-package! dash-docs
|
2018-06-22 01:48:04 +02:00
|
|
|
:when (featurep! +docsets)
|
|
|
|
: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
|
2019-05-12 01:45:48 -04:00
|
|
|
(setq dash-docs-enable-debugging doom-debug-mode
|
|
|
|
dash-docs-docsets-path (concat doom-etc-dir "docsets/")
|
|
|
|
dash-docs-min-length 2
|
|
|
|
dash-docs-browser-func #'eww)
|
|
|
|
|
2019-05-15 23:59:03 -04:00
|
|
|
;; Before `gnutls' is loaded, `gnutls-algorithm-priority' is treated as a
|
|
|
|
;; lexical variable, which breaks `+lookup*fix-gnutls-error'
|
2019-05-16 00:10:56 -04:00
|
|
|
(defvar gnutls-algorithm-priority)
|
2019-07-22 23:45:31 +02:00
|
|
|
(def-advice! +lookup-fix-gnutls-error-a (orig-fn url)
|
2019-05-15 23:50:29 -04:00
|
|
|
"Fixes integer-or-marker-p errors emitted from Emacs' url library,
|
|
|
|
particularly, the `url-retrieve-synchronously' call in
|
|
|
|
`dash-docs-read-json-from-url'. This is part of a systemic issue with Emacs 26's
|
|
|
|
networking library (fixed in Emacs 27+, apparently).
|
|
|
|
|
|
|
|
See https://github.com/magit/ghub/issues/81"
|
2019-07-22 23:45:31 +02:00
|
|
|
:around #'dash-docs-read-json-from-url
|
2019-05-15 23:40:27 -04:00
|
|
|
(let ((gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3"))
|
|
|
|
(funcall orig-fn url)))
|
|
|
|
|
2019-05-12 01:45:48 -04:00
|
|
|
(def-package! helm-dash
|
|
|
|
:when (featurep! :completion helm))
|
|
|
|
|
|
|
|
(def-package! counsel-dash
|
|
|
|
:when (featurep! :completion ivy)))
|