:feature was a "catch-all" category. Many of its modules fit better in other categories, so they've been moved: - feature/debugger -> tools/debugger - feature/evil -> editor/evil - feature/eval -> tools/eval - feature/lookup -> tools/lookup - feature/snippets -> editor/snippets - feature/file-templates -> editor/file-templates - feature/workspaces -> ui/workspaces More potential changes in the future: - A new :term category for terminal emulation modules (eshell, term and vterm). - A new :os category for modules dedicated to os-specific functionality. The :tools macos module would fit here, but so would modules for nixos and arch. - A new :services category for web-service integration, like wakatime, twitter, elfeed, gist and pastebin services.
6.9 KiB
tools/lookup
Table of Contents TOC
Description
Integrates with code navigation and documentation tools to help you quickly look up definitions, references and documentation.
- Jump-to-definition and find-references implementations that just work.
- Powerful xref integration for languages that support it.
- Documentation lookup for a variety of online sources (like devdocs.io, stackoverflow or youtube).
- Integration with Dash.app docsets.
Module Flags
+docsetsEnable integration with Dash.app docsets.
Plugins
Install
To enable the module add :tools lookup to your doom! block in
~/.emacs.d/init.el.
Module flags
This module provides two flags:
+docsetsEnables integration with Dash docsets.
Dependencies
This module has several soft dependencies:
the_silver_searcherand/orripgrepas a last-resort fallback for jump-to-definition/find-references.- Optionally,
sqlite3for Dash docset support.
MacOS
brew install the_silver_searcher ripgrep
# An older version of sqlite is included in MacOS. If it causes you problems (and
# it has been reported that 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 the_silver_searcher ripgrep
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:
- Whatever
:definitionfunction is registered for the current buffer with the:lookupsetting (see "Configuration" section). - Any available xref backends.
dumb-jump(a text search with aides to reduce false positives).- An ordinary project-wide text search with ripgrep or the_silver_searcher.
- If
evil-modeis active, useevil-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:
- Whatever
:referencesfunction is registered for the current buffer with the:lookupsetting (see "Configuration" section). - Any available xref backends.
- An ordinary project-wide text search with ripgrep or the_silver_searcher.
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:
- Whatever
:documentationfunction is registered for the current buffer with the:lookupsetting (see "Configuration" section). - Any Dash.app docsets, if any are installed for the current major mode.
- devdocs.io, if it has a docset for the current mode.
- An online search; using the last engine used (it will prompt you the first
time, or if
current-prefix-argis non-nil).
Search a specific documentation backend
You can perform a documentation lookup on any backends directly:
- Dash Docsets:
+lookup/in-docsets, or:dash QUERYfor evil users. - devdocs.io:
+lookup/in-devdocs, or:dd QUERYfor evil users. - Online (generic):
+lookup/onlineor+lookup/online-select(bound toSPC / o), or:lo[okup] QUERYfor evil users.
Configuration
Settings
This module provides two setters:
set-lookup-handlers! MODES &rest PLIST
Defines a lookup target for major MODES (one major-mode symbol or a 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 for a major-mode. With this, :definition and :references are unnecessary.
Example
;; 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.
set-docsets! MODES &rest DOCSETS
Registers 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.
(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")
Open in eww instead of browser
(setq +lookup-open-url-fn 'eww)
Appendix
Commands
+lookup/definition+lookup/references+lookup/documentation+lookup/online+lookup/online-select+lookup/in-devdocs+lookup/in-docsets