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")
|
|
|
|
("Wikipedia" "https://wikipedia.org/search-redirect.php?language=en&go=Go&search=%s"))
|
2019-07-09 17:55:35 +02:00
|
|
|
(when (featurep! :lang rust)
|
2019-12-15 17:59:20 -05:00
|
|
|
'(("Rust Docs" "https://doc.rust-lang.org/edition-guide/?search=%s"))))
|
|
|
|
"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
|
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
|
|
|
|
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
|
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
|
|
|
|
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.")
|
|
|
|
|
2020-05-07 09:06:36 +09:00
|
|
|
(defvar +lookup--dash-docs-xwidget-webkit-last-session-buffer nil)
|
|
|
|
|
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.
|
2019-07-23 17:24:56 +02:00
|
|
|
(defadvice! +lookup--projectile-find-tag-a (orig-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)))
|
|
|
|
(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-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)
|
|
|
|
;; xref initialization is different in Emacs 27 - there are two different
|
|
|
|
;; variables which can be set rather than just one
|
|
|
|
(when EMACS27+
|
|
|
|
(setq xref-show-definitions-function #'ivy-xref-show-defs))
|
|
|
|
;; Necessary in Emacs <27. In Emacs 27 it will affect all xref-based
|
|
|
|
;; commands other than xref-find-definitions too (eg project-find-regexp)
|
|
|
|
(setq xref-show-xrefs-function #'ivy-xref-show-xrefs))
|
2018-01-04 17:05:37 -05:00
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! helm-xref
|
2020-04-24 15:12:33 -04:00
|
|
|
:when (featurep! :completion helm)))
|
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)
|
|
|
|
|
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-23 17:24:56 +02:00
|
|
|
(defadvice! +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)))
|
|
|
|
|
2020-05-07 01:05:57 +09:00
|
|
|
;; Dash docset + Xwidget integration
|
2020-05-07 09:19:41 +09:00
|
|
|
(when (featurep! +xwidget)
|
2020-05-08 09:59:15 +09:00
|
|
|
(defun +lookup-dash-docs-xwidget-webkit-browse-url-fn (url &optional new-session)
|
2020-05-07 09:19:41 +09:00
|
|
|
(if (not (display-graphic-p))
|
|
|
|
(eww url new-session)
|
|
|
|
(setq xwidget-webkit-last-session-buffer +lookup--dash-docs-xwidget-webkit-last-session-buffer)
|
|
|
|
(save-window-excursion
|
|
|
|
(xwidget-webkit-browse-url url new-session))
|
2020-06-06 01:04:41 -04:00
|
|
|
(with-popup-rules! '(("^\\*xwidget" :vslot -11 :size 0.35 :select nil))
|
2020-05-07 09:19:41 +09:00
|
|
|
(pop-to-buffer xwidget-webkit-last-session-buffer))
|
|
|
|
(setq +lookup--dash-docs-xwidget-webkit-last-session-buffer xwidget-webkit-last-session-buffer
|
|
|
|
xwidget-webkit-last-session-buffer nil)))
|
2020-05-08 09:59:15 +09:00
|
|
|
(setq dash-docs-browser-func #'+lookup-dash-docs-xwidget-webkit-browse-url-fn))
|
2020-05-07 09:06:36 +09:00
|
|
|
|
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
|
|
|
|
(setq define-word-displayfn-alist
|
|
|
|
(cl-loop for (service . _) in define-word-services
|
|
|
|
collect (cons service #'+eval-display-results-in-popup))))
|
|
|
|
|
|
|
|
|
|
|
|
(when (featurep! +dictionary)
|
|
|
|
(define-key! text-mode-map
|
2020-01-02 20:03:50 -05:00
|
|
|
[remap +lookup/definition] #'+lookup/dictionary-definition
|
|
|
|
[remap +lookup/references] #'+lookup/synonyms))
|
2020-01-25 16:55:04 -05:00
|
|
|
|
|
|
|
|
|
|
|
;;;###package synosaurus
|
|
|
|
(setq synosaurus-choose-method 'default) ; use ivy/helm instead of ido
|