doomemacs/modules/tools/lookup
Henrik Lissner 2bc67d8387 bump: :app :checkers :config :emacs :term :tools :ui
Alexander-Miller/treemacs@a6f9e9f1ce -> Alexander-Miller/treemacs@63e2bc207a
Silex/docker.el@9bcefbe54d -> Silex/docker.el@4fc69969b1
akermu/emacs-libvterm@2b1392cb2b -> akermu/emacs-libvterm@2681120b77
bdarcus/bibtex-actions@6e3a194c3a -> bdarcus/bibtex-actions@08c6ca0e5b
dash-docs-el/dash-docs@dafc8fc9f1 -> dash-docs-el/dash-docs@29848b6b34
dgutov/diff-hl@992559f98a -> dgutov/diff-hl@40c89a7b0d
dimitri/switch-window@2801d9b3a9 -> dimitri/switch-window@8d9fe251d8
editorconfig/editorconfig-emacs@e10fa22b13 -> editorconfig/editorconfig-emacs@2ab86dc9a8
ema2159/centaur-tabs@9c7c936e4e -> ema2159/centaur-tabs@8b4249c405
emacs-circe/circe@d6f1fa1864 -> emacs-circe/circe@77e16de3b9
emacs-lsp/lsp-treemacs@905cc74726 -> emacs-lsp/lsp-treemacs@d82df44d63
emacsorphanage/osx-trash@0f1dc052d0 -> emacsorphanage/osx-trash@af74a2055a
emacsorphanage/quickrun@35e91f4b6c -> emacsorphanage/quickrun@78317951cd
flycheck/flycheck@21d52264aa -> flycheck/flycheck@784f184cdd
hlissner/emacs-doom-themes@9e2680b918 -> hlissner/emacs-doom-themes@65fb964f36
https://git.savannah.gnu.org/git/emms.git@6e0aaaf4c559 -> https://git.savannah.gnu.org/git/emms.git@c42fab572846
ideasman42/emacs-spell-fu@1abcb5594e -> ideasman42/emacs-spell-fu@10823ae58f
ideasman42/emacs-undo-fu@e0ad06b5ef -> ideasman42/emacs-undo-fu@34b27c01da
joostkremers/writeroom-mode@b648b34017 -> joostkremers/writeroom-mode@7f4ec92404
kidd/org-gcal.el@4c2616a4f8 -> kidd/org-gcal.el@80e6f9501f
magnars/expand-region.el@4b8322774d -> magnars/expand-region.el@95a773bd8f
millejoh/emacs-ipython-notebook@09af85821e -> millejoh/emacs-ipython-notebook@0600c286bd
mohkale/consult-eglot@a6aeb6fa07 -> mohkale/consult-eglot@28a09cc839
noctuid/link-hint.el@09ba5727d8 -> noctuid/link-hint.el@d3c5bacc9c
rolandwalker/nav-flash@55786c9582 -> rolandwalker/nav-flash@2e31f32085
skeeto/elfeed@243add9e74 -> skeeto/elfeed@162d7d545e
szermatt/emacs-bash-completion@65e54c6f9c -> szermatt/emacs-bash-completion@c5eaeed156
tarsius/hl-todo@5ac0076cfe -> tarsius/hl-todo@42f744ffb5
tecosaur/emacs-everywhere@64ba2e3f30 -> tecosaur/emacs-everywhere@da88fa2d04
tkf/emacs-request@f3a5b4352e -> tkf/emacs-request@2b68b3ca54
tmalsburg/helm-bibtex@a0d32ab167 -> tmalsburg/helm-bibtex@b85662081d
yoshiki/yaml-mode@3a57058468 -> yoshiki/yaml-mode@63b637f846
yqrashawn/fd-dired@c223aee30a -> yqrashawn/fd-dired@458464771b
2021-09-15 17:47:17 +02:00
..
autoload Fix +lookup/in-docsets's vertico section 2021-07-29 08:21:17 +07:00
config.el refactor: rename orig-fn arg in advice to fn 2021-08-04 01:53:12 -04:00
packages.el bump: :app :checkers :config :emacs :term :tools :ui 2021-09-15 17:47:17 +02:00
README.org Respect dash-docs-browser-func 2021-04-14 23:31:13 -04:00

tools/lookup

Description

This module adds code navigation and documentation lookup tools to help you quickly look up definitions, references, documentation, dictionary definitions or synonyms.

  • Jump-to-definition and find-references implementations that just work.
  • Powerful xref integration for languages that support it.
  • Search online providers like devdocs.io, stackoverflow, google, duckduckgo or youtube (duckduckgo and google have live suggestions).
  • Integration with Dash.app docsets.
  • Support for online (and offline) dictionaries and thesauruses.

Module Flags

  • +dictionary Enable word definition and thesaurus lookup functionality.

    • +offline Install and prefer offline dictionary/thesaurus.
  • +docsets Enable integration with Dash.app docsets.

Plugins

Prerequisites

This module has several soft dependencies:

  • ripgrep as a last-resort fallback for jump-to-definition/find-references.
  • sqlite3 for Dash docset support (if you have +docsets enabled)
  • wordnet for offline dictionary and thesaurus support (if you have +dictionary +offline enabled).

MacOS

brew install ripgrep wordnet

# An older version of sqlite is included in MacOS. If it causes you problems (and
# folks have reported it will), install it through homebrew:
brew install sqlite
# Note that it's keg-only, meaning it isn't symlinked to /usr/local/bin. You'll
# have to add it to PATH yourself (or symlink it into your PATH somewhere). e.g.
export PATH="/usr/local/opt/sqlite/bin:$PATH"

Arch Linux

sudo pacman -S sqlite ripgrep
yay -S wordnet-cli

NixOS

environment.systemPackages = with pkgs; [
  ripgrep
  sqlite
  wordnet
];

Features

Jump to definition

Use +lookup/definition (bound to gd in normal mode) to jump to the definition of the symbol at point

This module provides a goto-definition implementation that will try the following sources before giving up:

  1. Whatever :definition function is registered for the current buffer with the :lookup setting (see "Configuration" section).
  2. Any available xref backends.
  3. dumb-jump (a text search with aides to reduce false positives).
  4. An ordinary project-wide text search with ripgrep.
  5. If evil-mode is active, use evil-goto-definition, which preforms a simple text search within the current buffer.

If there are multiple results, you will be prompted to select one.

Find references

Use +lookup/references (bound to gD in normal mode) to see a list of references for the symbol at point from throughout your project.

Like +lookup/definition, this tries a number of sources before giving up. It will try:

  1. Whatever :references function is registered for the current buffer with the :lookup setting (see "Configuration" section).
  2. Any available xref backends.
  3. An ordinary project-wide text search with ripgrep.

If there are multiple results, you will be prompted to select one.

Look up documentation

+lookup/documentation (bound to K in normal mode) will open documentation for the symbol at point.

Depending on your configuration, this will try a list of sources:

  1. Whatever :documentation function is registered for the current buffer with the :lookup setting (see "Configuration" section).
  2. Any Dash.app docsets, if any are installed for the current major mode.
  3. devdocs.io, if it has a docset for the current mode.
  4. An online search; using the last engine used (it will prompt you the first time, or if current-prefix-arg is non-nil).

Search a specific documentation backend

You can perform a documentation lookup on any backends directly:

  • Dash Docsets: +lookup/in-docsets, or :dash QUERY for evil users.
  • Online (generic): +lookup/online or +lookup/online-select (bound to SPC / o), or :lo[okup] QUERY for evil users.

Dash.app Docset integration

You can install dash docsets with M-x dash-docset-install-docset and search them offline with M-x +lookup/in-docsets, or with +lookup/documentation in modes that don't have a specialized :documentation lookup handler.

Configuration

Associating lookup handlers with major modes

set-lookup-handlers! MODES &key DEFINITION REFERENCES DOCUMENTATION FILE XREF-BACKEND ASYNC

Use set-lookup-handlers! to register lookup targets for MODES (a major or minor mode symbol or list thereof). PLIST accepts the following optional properties:

:definition FN
Run when jumping to a symbol's definition. Used by +lookup/definition.
:references FN
Run when looking for usage references of a symbol in the current project. Used by +lookup/references.
:documentation FN
Run when looking up documentation for a symbol. Used by +lookup/documentation.
:file FN
Run when looking up the file for a symbol/string. Typically a file path. Used by +lookup/file.
:xref-backend FN
Defines an xref backend, which implicitly provides :definition and :references handlers. If you specify them anyway, they will take precedence over the xref backend, however.

e.g.

;; For python-mode, anaconda-mode offers a backend for all three lookup
;; functions. We can register them like so:
(set-lookup-handlers! 'python-mode
  :definition #'anaconda-mode-find-definitions
  :references #'anaconda-mode-find-references
  :documentation #'anaconda-mode-show-doc)

;; If a language or plugin provides a custom xref backend available for it, use
;; that instead. It will provide the best jump-to-definition and find-references
;; experience. You can specify custom xref backends with:
(set-lookup-handlers! 'js2-mode :xref-backend #'xref-js2-xref-backend)
;; NOTE: xref doesn't provide a :documentation backend.

Associating Dash docsets with major modes

set-docsets! MODES &rest DOCSETS...

Use set-docsets! to register DOCSETS (one string or list of strings) for MODES (one major mode symbol or a list of them). It is used by +lookup/in-docsets and +lookup/documentation.

e.g.

(set-docsets! 'js2-mode "JavaScript" "JQuery")
;; Add docsets to minor modes by starting DOCSETS with :add
(set-docsets! 'rjsx-mode :add "React")
;; Or remove docsets from minor modes
(set-docsets! 'nodejs-mode :remove "JQuery")

This determines what docsets to implicitly search for when you use +lookup/documentation in a mode with no :documentation handler. Those docsets must be installed with dash-docset-install-docset.

Open in eww instead of browser

+lookup/online opens the search results with in +lookup-open-url-fn (default: #'browse-url). Here is how to change this to EWW (so it opens inside Emacs):

(setq +lookup-open-url-fn #'eww)

+lookup/in-docsets consults dash-docs-browser-func instead, which is already set to #'eww by default.

Open in Xwidget WebKit instead of browser

To open results from +lookup/online or +lookup/in-docsets in Xwidget WebKit instead of your system browser, set +lookup-open-url-fn and/or dash-docs-browser-func to +lookup-xwidget-webkit-open-url-fn (needs Emacs with Xwidgets support):

(setq +lookup-open-url-fn #'+lookup-xwidget-webkit-open-url-fn)
(after! dash-docs
  (setq dash-docs-browser-func #'+lookup-xwidget-webkit-open-url-fn))

Appendix

Commands

  • +lookup/definition
  • +lookup/references
  • +lookup/documentation
  • +lookup/online
  • +lookup/online-select
  • +lookup/in-devdocs
  • +lookup/in-docsets