Skip to content

Latest commit

 

History

History
90 lines (84 loc) · 4.64 KB

dumb.org

File metadata and controls

90 lines (84 loc) · 4.64 KB

Nice new emacs package - dumb-jump.el

I really like the new emacs package I just found on Hacker news, dumb jump. Even if I use some “specialized” plugins like Jedi, ggtags supposed to be “open a random repo in a language I don’t use regularly, and navigate effectively”. ggtags have failed me at this and dumb-jump is promising.

Why is it better than ctags/ggtags?

So far dumb-jump works quickly and accurately on a few repos I tried it. On the other hand, I got upset a few times by weird errors of ctags/ggtags/etags.

No additional per OS configuration (assuming that you use ag anyway)

I switch between Mac/Linux and inconsistent ggtags/ctags configuration annoys me. The same .ctags and gtags.conf files do not work between OSes. This seems to be not a problem for dumb-jump

Reuse the ag configuration

I use ag anyway, since it’s the best “grep” alternative. This lets me to reuse my ag configuration.

I don’t have to rebuild ctags

I don’t have to think about rebuilding ctags.

Easier to debug, since it uses familiar tools

dump-jump is built on two things I know well - elisp and regular expressions. It is much easier to navigate elisp, since I know debugger and language well. Debugging ctags/ggtags required me to learn tools I didn’t use in years. The fact that dumb-jump uses familiar and “simple” tools it opens room for customizations like adapting regex to your custom Scala setup at your company.

Tip: Tweak ag command used by dumb-jump based on current directory.

Through Emacs advice system you can tweak flags to ag based on your directory. In particular you can use it as an alternative to .dumbjump file.

(require 's)

(defun tweak-dumb-per-project (&rest not-used-args)
  "Tweak the ag advice before dumbjump"
  (if (s-contains-p "/dotfiles/" (my-buffer-file-name))
      (setq dumb-jump-ag-cmd "ag --hidden")
    (setq dumb-jump-ag-cmd "ag"))
  )

(advice-add 'dumb-jump-go :before #'tweak-ag-per-project)

Things I may improve one day

TODO Adapt to scala

I think that just adapting regex configuration from https://leonard.io/blog/2013/04/editing-scala-with-vim/ should work.

TODO It would be nice to use helm

For example, I like to be able to call helm-resume to switch to other completion, if i went to wrong place.

TODO Better sorting after adding helm

I have been toying with an idea of better sorting completions returned by ag/tags/projectile. I plan to implement smarter sorting for helm one day. It could work with ag,dumb-jump, helm-projectile-find-file, completions, etc.

Comparison hierarchy

The comparison would be hierarchical, with the following rules priority:

1. Compare by file extension

Firstly show files with the same extension as currently visited file. Demote some “junk” extensions like .csv towards the bottom of the list. Define some order for remaining extensions (e.g. how often they occur together on all github repos). Provide way of jumping to the next extension group in the helm buffer.

2. Compare by longest common path

Find the lowest common ancestor of current file, and file returned by ag.

3. Compare by path length

Less nested paths are shown on the top.

TODO Possible generalization

dumb-jump runs additional regular expressions on result of your ag command. Such concept does not have to be unique to jumping to definition. I can’t think of good example where it could be useful, but I’ll write it down if I find something.

Slightly unrelated plug - Equivalent of IntelliJ Show Usages

Since the HN post mentions IntelliJ and ag - I was missing ability of helm-projectile-ag to search “symbol at point”. I wrote an elisp that does it, but it’s a bit hacky:

;; http://emacs.stackexchange.com/questions/10393/how-can-i-answer-a-minibuffer-prompt-from-elisp
(defun insert-symbol-at-point ()
  (if (> (length cached-symbol-at-point) 0)
      (insert cached-symbol-at-point))
  (remove-hook 'post-command-hook 'insert-symbol-at-point)
  )

(defun helm-projectile-ag-symbol-at-point ()
  "Search for number at point using helm-projectile-ag"
  (interactive)
  (setq cached-symbol-at-point (thing-at-point `symbol))
  (add-hook 'post-command-hook 'insert-symbol-at-point)
  (helm-projectile-ag)
  )

(global-set-key (kbd "C-s") 'helm-projectile-ag-symbol-at-point)
(global-set-key (kbd "C-S-f") 'helm-projectile-ag)