Convert Figma logo to code with AI

jacktasia logodumb-jump

an Emacs "jump to definition" package for 50+ languages

1,655
156
1,655
87

Top Related Projects

1,831

Jump to things in Emacs tree-style

2,355

Ivy - a generic completion frontend for Emacs, Swiper - isearch with an overview, and more. Oh, man!

Emacs :heart: Debug Adapter Protocol

Emacs client/library for the Language Server Protocol

Project Interaction Library for Emacs

Quick Overview

Dumb Jump is an Emacs package that provides a quick way to jump to function definitions in your codebase. It uses grep, ag, rg, or git-grep to find potential definitions and presents them to the user for selection. Dumb Jump aims to be fast and work with minimal configuration across many programming languages.

Pros

  • Works out of the box with minimal setup
  • Supports multiple search tools (grep, ag, rg, git-grep)
  • Language-agnostic, supporting many programming languages
  • Integrates well with existing Emacs workflows

Cons

  • May produce false positives in complex codebases
  • Relies on text-based search, which can be less accurate than AST-based tools
  • Performance may vary depending on the size of the codebase and chosen search tool
  • Limited customization options compared to more specialized language-specific tools

Code Examples

;; Basic usage: Jump to definition
(dumb-jump-go)

;; Jump back to where you were before
(dumb-jump-back)

;; Show results in a separate window
(dumb-jump-go-other-window)
;; Configure Dumb Jump to use ripgrep as the search tool
(setq dumb-jump-force-searcher 'rg)
;; Enable Dumb Jump in xref (Emacs 25+)
(add-hook 'xref-backend-functions #'dumb-jump-xref-activate)

Getting Started

To get started with Dumb Jump, add the following to your Emacs configuration:

(use-package dumb-jump
  :ensure t
  :bind (("M-g o" . dumb-jump-go-other-window)
         ("M-g j" . dumb-jump-go)
         ("M-g b" . dumb-jump-back)
         ("M-g i" . dumb-jump-go-prompt)
         ("M-g x" . dumb-jump-go-prefer-external)
         ("M-g z" . dumb-jump-go-prefer-external-other-window))
  :config (setq dumb-jump-selector 'ivy) ;; (setq dumb-jump-selector 'helm)
  :init (dumb-jump-mode))

This configuration sets up key bindings for common Dumb Jump functions and enables the package globally. Adjust the key bindings and selector as needed for your preferred setup.

Competitor Comparisons

1,831

Jump to things in Emacs tree-style

Pros of avy

  • More versatile, offering various navigation and selection methods beyond just jumping to definitions
  • Highly customizable with many options for key bindings and visual feedback
  • Supports multiple modes of operation (e.g., goto-char, goto-line, goto-word)

Cons of avy

  • Steeper learning curve due to its many features and options
  • May be overkill for users who only need simple definition jumping functionality
  • Requires more setup and configuration to get the most out of it

Code comparison

avy:

(avy-goto-char-timer)
(avy-goto-word-1 (thing-at-point 'word))
(avy-goto-line)

dumb-jump:

(dumb-jump-go)
(dumb-jump-back)
(dumb-jump-quick-look)

Summary

avy is a more comprehensive navigation tool that offers a wide range of features for moving around in buffers, while dumb-jump focuses specifically on jumping to definitions. avy provides more flexibility and customization options, but may be more complex to set up and use. dumb-jump, on the other hand, is simpler and more straightforward for its specific use case of definition jumping.

2,355

Ivy - a generic completion frontend for Emacs, Swiper - isearch with an overview, and more. Oh, man!

Pros of Swiper

  • More versatile, offering multiple search and navigation functionalities beyond just code jumping
  • Provides a smoother, more interactive search experience with real-time results
  • Integrates well with other Emacs packages and has a larger, more active community

Cons of Swiper

  • Steeper learning curve due to more complex features and customization options
  • Requires more setup and configuration to achieve optimal functionality
  • May have a higher performance impact on larger codebases compared to Dumb Jump

Code Comparison

Swiper:

(ivy-mode 1)
(global-set-key "\C-s" 'swiper)
(global-set-key (kbd "C-c C-r") 'ivy-resume)
(global-set-key (kbd "<f6>") 'ivy-resume)
(global-set-key (kbd "M-x") 'counsel-M-x)

Dumb Jump:

(require 'dumb-jump)
(add-hook 'xref-backend-functions #'dumb-jump-xref-activate)
(setq xref-show-definitions-function #'xref-show-definitions-completing-read)

While Swiper offers a more comprehensive search and navigation solution with additional features, Dumb Jump provides a simpler, more focused approach to code jumping. Swiper requires more configuration but offers greater flexibility, whereas Dumb Jump aims for a more straightforward setup and usage.

Emacs :heart: Debug Adapter Protocol

Pros of dap-mode

  • Provides a comprehensive debugging environment with support for multiple languages
  • Integrates seamlessly with Language Server Protocol (LSP) for enhanced functionality
  • Offers a rich set of features including breakpoints, watch expressions, and step debugging

Cons of dap-mode

  • Steeper learning curve due to more complex setup and configuration
  • Requires additional dependencies and language-specific adapters
  • May be overkill for simple navigation tasks or smaller projects

Code Comparison

dap-mode configuration example:

(require 'dap-mode)
(require 'dap-python)
(dap-mode 1)
(dap-ui-mode 1)
(dap-tooltip-mode 1)

dumb-jump usage example:

(require 'dumb-jump)
(add-hook 'xref-backend-functions #'dumb-jump-xref-activate)
(setq xref-show-definitions-function #'xref-show-definitions-completing-read)

Summary

dap-mode is a powerful debugging tool that integrates with LSP, offering advanced features for multiple languages. It's ideal for complex projects requiring in-depth debugging capabilities. However, it comes with a steeper learning curve and more complex setup.

dumb-jump, on the other hand, is a simpler, language-agnostic jump-to-definition package. It's easier to set up and use, making it suitable for quick navigation tasks across various languages. However, it lacks the advanced debugging features provided by dap-mode.

Choose dap-mode for comprehensive debugging needs in larger projects, and dumb-jump for simpler, quick navigation tasks in multi-language environments.

Emacs client/library for the Language Server Protocol

Pros of lsp-mode

  • Provides comprehensive language support with features like code completion, refactoring, and diagnostics
  • Supports a wide range of programming languages through Language Server Protocol (LSP)
  • Offers more advanced code navigation and analysis capabilities

Cons of lsp-mode

  • Requires more setup and configuration compared to dumb-jump
  • Can be resource-intensive, especially for larger projects
  • May have a steeper learning curve for users new to LSP

Code Comparison

lsp-mode:

(use-package lsp-mode
  :hook ((python-mode . lsp)
         (rust-mode . lsp))
  :commands lsp)

dumb-jump:

(use-package dumb-jump
  :bind (("M-g o" . dumb-jump-go-other-window)
         ("M-g j" . dumb-jump-go))
  :config (setq dumb-jump-selector 'ivy))

lsp-mode offers more comprehensive language support and advanced features, but requires more setup and resources. dumb-jump is simpler to configure and use, but provides more basic code navigation functionality. The choice between the two depends on the user's needs and project requirements.

Project Interaction Library for Emacs

Pros of Projectile

  • Comprehensive project management features beyond just code navigation
  • Integrates with many other Emacs packages and tools
  • Supports a wide range of project types and version control systems

Cons of Projectile

  • Steeper learning curve due to more complex functionality
  • Requires more configuration and setup for optimal use
  • May be overkill for users who only need simple code navigation

Code Comparison

Projectile (project root detection):

(defun projectile-project-root ()
  (let ((dir (file-truename default-directory)))
    (or (projectile-root-top-down dir projectile-project-root-files)
        (projectile-root-bottom-up dir projectile-project-root-files-bottom-up)
        (projectile-root-top-down-recurring dir projectile-project-root-files-top-down-recurring))))

Dumb Jump (jump to definition):

(defun dumb-jump-go ()
  (interactive)
  (dumb-jump-go-internal :use-tooltip t))

While both projects aim to improve developer productivity in Emacs, Projectile offers a more comprehensive suite of project management tools, whereas Dumb Jump focuses specifically on quick and simple code navigation. Projectile's broader scope comes with increased complexity, while Dumb Jump prioritizes simplicity and ease of use for its core functionality.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

dumb-jump

CI Coverage Status MELPA MELPA Stable

Dumb Jump GIF

About

Dumb Jump is an Emacs "jump to definition" package with support for 50+ programming languages that favors "just working". This means minimal -- and ideally zero -- configuration with absolutely no stored indexes (TAGS) or persistent background processes. Dumb Jump requires at least GNU Emacs 24.3.

How it works

Dumb Jump uses The Silver Searcher ag, ripgrep rg, or grep to find potential definitions of a function or variable under point. It uses a set of regular expressions based on the file extension, or major-mode, of the current buffer. The matches are run through a shared set of heuristic methods to find the best candidate to jump to. If it can't decide it will present the user with a list in a pop-menu, helm, or ivy (see dumb-jump-selector).

Success Rate

For the currently supported languages it seems to do a good job of finding what you want. If you find a case where it does not work as expected do not hesitate to open an issue. It can be slow if it needs to use grep and/or a project is large. Although it can be sped up by installing ag or installing rg and/or creating a .dumbjump file in your project's root directory with paths that should be excluded (see configuration).

Supported Languages

There is currently basic support for the following languages:

  • Apex
  • Bash
  • C/C++
  • C#
  • Clojure
  • CoffeeScript
  • Common Lisp
  • Coq
  • Crystal
  • Dart
  • Elixir
  • Emacs Lisp
  • Erlang
  • F#
  • Faust
  • Fennel
  • Fortran
  • Go
  • Groovy
  • Haskell
  • Java
  • JavaScript
  • Julia
  • Kotlin
  • LaTeX
  • Lua
  • Matlab
  • Nim
  • Nix
  • Objective-C
  • OCaml
  • Odin
  • OpenSCAD
  • Org mode
  • Pascal
  • Perl
  • PHP
  • Protocol Buffers
  • Python
  • R
  • Racket
  • Ruby
  • Rust
  • Sass
  • Scala
  • Scheme
  • SML
  • Solidity
  • SQL
  • Swift
  • SystemVerilog
  • Tcl
  • Terraform / HCL
  • TypeScript
  • Vala
  • VHDL
  • Zig

If you have any issues with the existing languages, or you want support for another one, then please open an issue. PRs are also welcome. If you'd like to add a language these PRs for lua and rust are good examples.

Installing

The recommended way to install Dumb Jump is via package.el. It's available on MELPA: M-x package-install dumb-jump

Spacemacs

If you're using an up-to-date Spacemacs, then you already have Dumb Jump by default just make sure you install ag or rg (see below) to ensure you have the best experience.

Installing ag or rg

Dumb Jump performs best with The Silver Searcher ag (ag install instructions) or ripgrep rg (rg install instructions) installed on your system.

Usage

Basic

To enable the xref backend, evaluate

(add-hook 'xref-backend-functions #'dumb-jump-xref-activate)

or add it to your initialisation file. Using this, you can now use M-. (or gd when using Evil).

Xref can be customized to use completing-read to select a target. That way a completion framework of your choice (Icomplete, Helm, Ivy, ...) will be used instead of the default pop-up buffer. To do this, evaluate

(setq xref-show-definitions-function #'xref-show-definitions-completing-read)

Note that the function xref-show-definitions-completing-read requires at least Xref 1.1.0. This can either be downloaded from ELPA or is bundled with Emacs 28.1 or newer.

Configuration

Excluding project directories

Dumb Jump will automatically look for a project root. If it's not finding one then either put a .dumbjump file in your project root and optionally add excluded directories to make it faster.

Project root directory denoters: .dumbjump .projectile .git .hg .fslckout .bzr _darcs .svn Makefile PkgInfo -pkg.el.

If you want to stop a directory from registering as the project root (and have Dumb Jump keep looking) add an empty .dumbjumpignore file in that directory.

Example .dumbjump
-tests
-node_modules
-build
-images
+../some-lib/src
+/usr/lib/src

NOTE When adding paths outside of the project (using +) ensure you use dumb-jump-force-searcher of either 'ag or 'rg (see below). This is required because the default searcher (git-grep) won't be able to search outside of the project root. This edge case will be fixed in a future release. That is, git-grep will NOT be set as the default searcher if a .dumbjump is present with a + path outside of the repo.

.emacs options
  • (setq dumb-jump-default-project "~/code") to change default project if one is not found (defaults to ~)
  • (setq dumb-jump-quiet t) if Dumb Jump is too chatty.
  • To support more languages and/or definition types customize dumb-jump-find-rules variable.
  • (setq dumb-jump-force-searcher 'rg) to force the search program Dumb Jump should use. It will always use this searcher. If not set (nil) Dumb Jump will use git-grep if it's a git project and if not will try searchers in the following order ag, rg, grep (first installed wins). This is necessary if you want full control over the searcher Dumb Jump uses.
  • (setq dumb-jump-prefer-searcher 'rg) to let Dumb Jump know your searcher preference. If set this will still use git-grep if it's a git project (because it's the fastest), but will you use whatever you set here in any other situation. If not set Dumb Jump will follow the same order as mentioned in the dumb-jump-force-searcher description. At this time setting this value is only necessary if you prefer rg but have ag installed too.
  • (setq dumb-jump-git-grep-search-args "") to set additional command line arguments when using git-grep for searching (defaults to "").
  • (setq dumb-jump-ag-search-args "") to set additional command line arguments when using ag for searching (defaults to "").
  • (setq dumb-jump-rg-search-args "") to set additional command line arguments when using rg for searching (defaults to "--pcre2").

If your project has multi-line method signatures you should use ag or rg version 0.10.0 or higher.

To learn more about how Dumb Jump picks a searcher see this issue and this pull request.

Hydra for effieciency

If you have Hydra installed, the following is an example hydra for easily using Dumb-Jump and not needing to remember the bindings or function names:

(defhydra dumb-jump-hydra (:color blue :columns 3)
    "Dumb Jump"
    ("j" dumb-jump-go "Go")
    ("o" dumb-jump-go-other-window "Other window")
    ("e" dumb-jump-go-prefer-external "Go external")
    ("x" dumb-jump-go-prefer-external-other-window "Go external other window")
    ("i" dumb-jump-go-prompt "Prompt")
    ("l" dumb-jump-quick-look "Quick look")
    ("b" dumb-jump-back "Back"))

It can be explicitly bound or used inside another hydra (if you already use something like Avy/Ace or similar for general "jumping").

Debugging a jump

  1. M-x set-variable dumb-jump-debug t
  2. try to jump
  3. go to buffer *Messages*

More details here. Thanks to @cweiske and @Glumanda99

Obsolete commands and options

Older versions of dumb jump didn't use xref, and instead had custom commands. These, while marked obsolete, can still be used:

  • dumb-jump-go (former) core functionality. Attempts to jump to the definition for the thing under point. This has been replaced in the new interface with xref-find-definitions (M-.).
  • dumb-jump-back jumps back to where you were when you jumped. These are chained so if you go down a rabbit hole you can get back out or where you want to be. This has been replaced with xref-pop-marker-stack (M-,), but is mostly equivalent.
  • dumb-jump-quick-look like dumb-jump-go but only shows tooltip with file, line, and context it does not jump.
  • dumb-jump-go-other-window exactly like dumb-jump-go but uses find-file-other-window instead of find-file
  • dumb-jump-go-prefer-external like dumb-jump-go but will prefer definitions not in the current buffer
  • dumb-jump-go-prefer-external-other-window expected combination of dumb-jump-go-prefer-external and dumb-jump-go-other-window
  • dumb-jump-go-prompt exactly like dumb-jump-go but prompts user for function to jump to

A few user options only have an effect when used with the legacy interface. These are:

  • dumb-jump-after-jump-hook (use xref-after-jump-hook instead)
  • dumb-jump-before-jump-hook (use xref-after-return-hook instead)
  • dumb-jump-selector
  • dumb-jump-aggressive
  • dumb-jump-use-visible-window
  • dumb-jump-confirm-jump-to-modified-file

The minor mode dumb-jump-mode binds a few of these commands by default.

If you still use Emacs 24 or older, you won't have xref, and have to use the legacy interface instead. In that case, there will also be no "obsolete" warnings.

Why?

I wanted "jump to definition" functionality to "just work" in emacs. I use IntelliJ for Java and this functionality is basically the only thing I miss when I switch back to emacs for work in other languages. There are certainly other packages that offer this type of functionality, but they all require significantly more configuration and are often limited to a particular language. An alternative may be worth setting up if you are in a specific project or language often (see alternatives).

Contributing

Feedback is very welcome via GitHub issues. I will consider supporting other languages either via issue request or PR. If submitting a PR then please add tests as well.

Running Tests

Opening a PR will use CircleCI to run all the tests against all the supported emacs versions and search programs.

Running tests locally

There are a lot of options for running the tests locally:

Basic/Classic

requires Cask using your local emacs

cd /path/to/dumb-jump
cask
make test

Concurrent

requires golang and Cask using your local emacs

cd /path/to/dumb-jump
cask
make test-concurrent

Docker (latest emacs)

only requires docker and runs tests against emacs 26.1

cd /path/to/dumb-jump
cask
make test-in-docker

Docker (all supported emacs versions)

only requires docker and runs tests against all supported emacs versions

cd /path/to/dumb-jump
cask
make test-all-in-docker

Alternatives

Here is a list of potential alternative packages for emacs:

Most of these were sourced from this emacs StackExchange answer.