Hacker News new | comments | show | ask | jobs | submit login
Dumb-jump: an Emacs “jump to definition” package (github.com)
131 points by jacktasia 563 days ago | hide | past | web | favorite | 50 comments



I was planning to write this as a comment here, but it ended up growing so I published it on my blog post: https://kozikow.wordpress.com/2016/05/21/nice-new-emacs-pack... .

BTW, did you know that you can just do README.org and github parses it? I noticed that you have org file checked in, but README is in md. For example see https://github.com/kozikow/keyremaplinux .


Wow, thanks for writing that blog post! You highlight pretty much all the reasons why I made dumb-jump. Please don't hesitate to make issues on github if/when you run into issues/ideas.


Ah yes, yet another proof that the Wrong Thing™ isn't necessarily the wrong thing. Sure it's objectively worse than [ce]tags, but haven't you heard? Worse is Better. :-D


I am not sure "proof" is the appropriate word.

> Dumb Jump uses The Silver Searcher ag (and falls back to grep) ... [and] a set of regular expressions

If you're going to install ag, you might as well install universal-ctags[1], a revival of ctags with many improved and new parsers. It allowed me to discard my C and javascript ctags config entirely.

Combined with gutentags[2] you have a "just works" and "Less Dumb" setup.

[1] https://github.com/universal-ctags/ctags

[2] https://github.com/ludovicchabant/vim-gutentags


The advantage of ag is that it is dumb brute (very brute) force. You do not need an up to date index as it will search whatever is on disk.

I have rtags set up, but it periodically stops working (too many parsing errors, indexer crashes, etc) or it is just slow, then I fall back to ag. It can search a ~1M lines C++ codebase in seconds (and you can start browsing the results while the search is in progress of course). Of couse it also works if you do not have a project setup, or you just switched to a wildly diverged git branch.

I'm definitely going to try this dumb-jump.


For C/C++ RTags (https://github.com/Andersbakken/rtags) together with company-mode and fly-check can do jump-to-definition, auto-completion and on-the-fly-syntax-checking. Super easy to use if using cmake as build system.

Respond to this comment if you need pointers on how to set things up.


Any equivalent options for make?


For make you could use bear (https://github.com/rizsotto/Bear). It allows you to generate a compilation database that is equivalent to that of cmake projects.


This is neat, and useful as a general purpose jump-to feature. It's probably worth mentioning that some languages have packages with better functionality for that language, such as tern-mode for JavaScript.


I must be missing something, but what is the advantage of this over something like Emacs Tags (https://www.emacswiki.org/emacs/EmacsTags) ?


One major advantage is that approaches like this just work, with zero configuration, and zero persistent state to be wrong. `git grep` (and ag) are very fast on modern laptops. That changes considerations dramatically from 10 or 20 years ago or whenever TAGS were introduced.


Building a tags file is not trivial.For example if you cloned a random repository on github you'd want to just jump around and not have to have the additional step of generating it and keeping it up to date.


Can't it just be done automatically and on-the-fly using ctags or another appropriate command?


Maybe this changed in the last few years but the problem with TAGS files was that you have to rebuild it at every change you make. I had a cron that rebuilt the ones of the projects I was working on, but it's not efficient and not up to date. Maybe a process that monitors changes to files is a better approach. Still, rebuilding the TAGS file is useless if ag is fast enough. SSDs and lots of RAM to cache files help.

The only problem with ag is that it can't find definitions until you save the buffer to a file. Not that ctags does any better. Some tool running inside emacs could do that too but it's not so important.


It shouldn't be too hard to write a grep-buffers command (I was using one version for a while), exclude open files from ag searches and merge the result of ag+grep-buffers in a single output (eh, in fact I should just write it).


Perhaps, but I've never seen a straightforward guide to doing that. Particuarly that was generic enough that would automatically work with new projects, but I'd be thrilled to be proven wrong.


I really love how well this works with Cider though, for Clojure projects. It even lets you jump to the definition of Java or Clojure files that live outside your current project, e.g. in third party libraries or even the Java standard library. Why, just today I jumped to the definition of java.time.Month because I had never actually seen a real live Java enum before. (Sure enough, it's defined with the keyword `enum`. Neat!) Cider has become essential to my Clojure workflow at work.


This is cool, I've also been writing a similar emacs package: it uses `git grep` and `git ls-files` to quickly find patterns and file names in the current git repo, and has a simple interface for filtering the search results to narrow down to what you were looking for (and also uses a regexp heuristic for jumping to definitions).

https://github.com/dandavison/emacs-search-files


What do people use to get something like this for C/C++? Also is there any package for auto-completion in C/C++?


Eclipse CDT (Juno) does it even better. Just hover a mouse over any function call and you can see the body of that function in a scrollable tooltip. You don't need to jump back and forth - you simply follow the code logic and see what the called function does in a tooltip window. This is a huge productivity boost for me and I haven't seen any other IDE doing it.

One other thing no other tool does (AFAIK) is that you can get a "call hierarchy" for a function or any variable and it's laid out as a tree and you can expand each node to trace the calls. This makes understanding the code and refactoring faster by an order of magnitude.

I have avoided Eclipse for years because of cpu/memory usage, but ever since I got a computer with Intel i7 CPU and 16GB of RAM, I have completely switched to Eclipse because it makes me so much more productive than any other environment I tried.


RTags works pretty well and always jump to the right definition for me. You pass it to a compilation database json file that you can make using CMake. It runs in the background as a daemon and provides robust go-to-definition as well as autocomplete for both C and C++.

https://github.com/Andersbakken/rtags


EmacsTags + CompanyMode and you should be good to go. You'll need to install the correct tags package for your system, but it's only about 10 minutes of minor annoyance.

Whenever the point is over a word in a C++ codebase, e.g. FooSystem, it will be underlined, and you can click on it and jump to definition, show all references, etc. Then if you type Foo, CompanyMode should pop up a dialog box that will autocomplete FooManager.

I think you can also install a fuzzy matching package for CompanyMode which allows you to type e.g. "FSy" to complete "FooSystem", though I may be confusing Helm and CompanyMode.

You may also want to check out the Projectile package. It's for large project navigation, and I think it helps with automatically running ETags / GTags on an as-needed basis.


CEDET could be replacement, although sometimes very slow, and requires customization for complex projects. I made it working with Java as well, but for last 2 years, I didn't have a chance to contribute anymore, and my fork with better Java support is outdated...

I wrote an article that should be introduction to CEDET: http://alexott.net/en/writings/emacs-devenv/EmacsCedet.html - maybe it will be useful



I prefer https://github.com/abingham/emacs-ycmd – the engine is also used by the corresponding vim plugin. Gives completion and "jump to".

Rtags is a also nice alternative. Both packages work as daemons outside emacs that read your compile commands.



Thanks! This worked the best out of all...


Relies on cmake integration but worth a look: https://github.com/atilaneves/cmake-ide


Nice! Just tried it out and it seems to work well.

Why does dumb-jump-go want me to save my files before jumping?


I assume because it uses an external tool that looks at your files, not the state of your emacs buffers, to find references.


Nice package! Unfortunately is completely falling on its face for my ruby on rails project, but I'm sure it can be improved.


Sorry to hear it didn't work for you. Would you consider opening an issue on github outlining what you were trying to do?


Agreed. Was so hopeful that it would "just work". Still hopeful that it will improve, because the README just sounds sooo good.


Sorry to hear it didn't work for you. Would you consider opening an issue on github outlining what you were trying to do? Then you can be more than just hopeful that it will improve.


Why is so much Emacs stuff hosted on GitHub these days? It seems antithetical to the spirit of the project as a whole.


As opposed to what? Buying a domain and hosting your own server? To answer your question: Some small programs would probably not exist at all without a service like github.


It's not necessary to buy a domain and host one's own server. For example, there is https://savannah.gnu.org/ , which is where Emacs itself is hosted.


What spirit of the project are you thinking of, and how is hosting stuff on Github antithetical to it?


>What spirit of the project are you thinking of

Free Software: http://www.gnu.org/philosophy/free-sw.html

>how is hosting stuff on Github antithetical to it?

Github is s a proprietary cloud service: http://www.gnu.org/philosophy/who-does-that-server-really-se...


Thanks for providing these links.


this looks neat.

i notice one of the supported languages is go -- if you're doing much go, i recommend installing godef and using go-mode.el. no tags files or anything like that, and works perfectly well for jumping to definition.

(i also highly recommend gorename and guru.)


Still learning VIM user here, do we have something like this?


Vim can do ctags out of the box. If I remember right, the command is C-] (ctrl+ close bracket) to jump to a ctags definition.

For rails projects I wrote a script that kicks off ctags with the following options. "ctags --tag-relative -Rf.git/tags.$$ --exclude=.git --exclude=log --exclude=tmp --exclude=public --languages=ruby --languages=javascript `bundle show --paths` $MY_RUBY_HOME ."

I'd wager there is a better way. That's just the way I roll.


I have this in my vimrc under vundle:

    Plugin 'majutsushi/tagbar'
    Plugin 'xolox/vim-easytags'
    Plugin 'xolox/vim-misc'
Later on I have:

    nnoremap <silent> <Leader>b :TagbarToggle<CR>
I may have also separately installed ctags, but I don't remember.

Now you can have an outline of the file you're working on in a small pane to the right. You can use this to navigate or see what arguments a function needs (or what attributes a class has). Whenever you save, ctags are automatically generated so you never have to worry about setting that up. ctrl+] will bring directly to the definition, including if it is in another file entirely. Use ctrl+T to go back to where you came. More often than not, I use this not because I forgot what the code says, but because I made an alteration to how I wanted a function or class to behave and I need to go back and change a line or two.


On first blush, this looks like ctags[0] (or etags[1]). In nvi, I go to a function or structure I want to see the definition of and (/me loads nvi to see what I actually do...) ^] (ctrl-bracket) to jump to a definition, and ^T (ctrl-t) to pop that ctag jump off the stack that it maintains. Because it's stack oriented, that means that you can jump through to definitions until you're satisfied, and pop back the same route you took getting to your ultimate destination.

[0] https://en.wikipedia.org/wiki/Ctags

[1] http://ctags.sourceforge.net/


Are you aware of '*' and '#', and 'gd'?

http://vim.wikia.com/wiki/Go_to_definition_using_g


It never seems to work for me. If I put the cursor over a word and type gd, it seems to go to the first line that the word is mentioned, not necessarily the definition. It's handy, for sure, but not too reliable. I think it can be improved with some plugins though.


These only work if your definition is in the same file, though.


Not exactly similar but https://github.com/ludovicchabant/vim-gutentags is pretty great.


It's essentially similar to gd, but in theory project-wide and with a better algorithm.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: