Adding dumb-jump to navigate my code trees
This commit is contained in:
parent
71f47a5490
commit
8ba7f8161d
2 changed files with 49 additions and 16 deletions
|
@ -826,16 +826,33 @@ Let's try this out with a Hydra since some I can /repeat/ some commands (e.g. en
|
||||||
(ha-leader "w" '("windows" . hydra-window-resize/body))
|
(ha-leader "w" '("windows" . hydra-window-resize/body))
|
||||||
#+end_src
|
#+end_src
|
||||||
*** Search Operations
|
*** Search Operations
|
||||||
Ways to search for information goes under the ~s~ key. This primarily depends on the [[https://github.com/dajva/rg.el][rg]] package, which builds on the internal =grep= system, and creates a =*rg*= window with =compilation= mode, so ~C-j~ and ~C-k~ will move and show the results by loading those files.
|
Ways to search for information goes under the ~s~ key. The venerable sage has always been =grep=, but we now have new-comers, like [[https://github.com/BurntSushi/ripgrep][ripgrep]], which are really fast.
|
||||||
|
**** ripgrep
|
||||||
|
Install the [[https://github.com/dajva/rg.el][rg]] package, which builds on the internal =grep= system, and creates a =*rg*= window with =compilation= mode, so ~C-j~ and ~C-k~ will move and show the results by loading those files.
|
||||||
|
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
(use-package rg
|
(use-package rg
|
||||||
:init ; I sometimes call `grep`:
|
:general (:states 'normal "gr" 'rg-dwim)
|
||||||
; (grep-apply-setting 'grep-command "rg -n -H --no-heading -e ")
|
|
||||||
|
|
||||||
:config
|
:config
|
||||||
|
;; Make an interesting Magit-like menu of options, which I don't use much:
|
||||||
(rg-enable-default-bindings (kbd "M-R"))
|
(rg-enable-default-bindings (kbd "M-R"))
|
||||||
|
|
||||||
|
;; In case I call (or something else) calls `grep':
|
||||||
|
(grep-apply-setting 'grep-command "rg -n -H --no-heading -e ")
|
||||||
|
|
||||||
|
;; Old habits die hard ...
|
||||||
|
(define-key global-map [remap xref-find-references] 'rg-dwim)
|
||||||
|
|
||||||
|
(advice-add 'wgrep-change-to-wgrep-mode :after #'evil-normal-state)
|
||||||
|
(advice-add 'wgrep-to-original-mode :after #'evil-motion-state)
|
||||||
|
(defvar rg-mode-map)
|
||||||
|
(add-to-list 'evil-motion-state-modes 'rg-mode)
|
||||||
|
(evil-add-hjkl-bindings rg-mode-map 'motion
|
||||||
|
"e" #'wgrep-change-to-wgrep-mode
|
||||||
|
"g" #'rg-recompile
|
||||||
|
"t" #'rg-rerun-change-literal)
|
||||||
|
|
||||||
(ha-leader
|
(ha-leader
|
||||||
"s" '(:ignore t :which-key "search")
|
"s" '(:ignore t :which-key "search")
|
||||||
"s q" '("close" . ha-rg-close-results-buffer)
|
"s q" '("close" . ha-rg-close-results-buffer)
|
||||||
|
@ -873,9 +890,9 @@ Ways to search for information goes under the ~s~ key. This primarily depends on
|
||||||
(previous-error-no-select)
|
(previous-error-no-select)
|
||||||
(compile-goto-error)))
|
(compile-goto-error)))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
Note we bind the key ~M-R~ to the [[help:rg-menu][rg-menu]], which is a Magit-like interface to =ripgrep=.
|
||||||
|
**** wgrep
|
||||||
The [[https://github.com/mhayashi1120/Emacs-wgrep][wgrep package]] integrates with =ripgrep=. Typically, you hit ~i~ to automatically go into =wgrep-mode= and edit away, but since I typically want to edit everything at the same time, I have a toggle that should work as well:
|
The [[https://github.com/mhayashi1120/Emacs-wgrep][wgrep package]] integrates with =ripgrep=. Typically, you hit ~i~ to automatically go into =wgrep-mode= and edit away, but since I typically want to edit everything at the same time, I have a toggle that should work as well:
|
||||||
|
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
(use-package wgrep
|
(use-package wgrep
|
||||||
:after rg
|
:after rg
|
||||||
|
|
|
@ -171,6 +171,22 @@ To take advantage of this, type:
|
||||||
- ~z a~ :: Toggles open to close
|
- ~z a~ :: Toggles open to close
|
||||||
|
|
||||||
Note: Yes, we could use [[https://github.com/mrkkrp/vimish-fold][vimish-fold]] (and its cousin, [[https://github.com/alexmurray/evil-vimish-fold][evil-vimish-fold]]) and we’ll see if I need those.
|
Note: Yes, we could use [[https://github.com/mrkkrp/vimish-fold][vimish-fold]] (and its cousin, [[https://github.com/alexmurray/evil-vimish-fold][evil-vimish-fold]]) and we’ll see if I need those.
|
||||||
|
** Navigation
|
||||||
|
Once upon a time, we use to create a =TAGS= file that contained the database for navigating code bases, but with new faster versions of grep, e.g. [[https://beyondgrep.com][ack]], [[https://github.com/ggreer/the_silver_searcher][ag]] (aka, the Silver Searcher), [[https://github.com/Genivia/ugrep][ugrep]] and [[https://github.com/BurntSushi/ripgrep][ripgrep]], we should just be able to use them. but I want to:
|
||||||
|
- Be in a function, and see its callers. For this, the [[help:rg-dwim][rg-dwim]] function is my bread-and-butter.
|
||||||
|
- Be on a function, and jump to the definition. For this, I use [[https://github.com/jacktasia/dumb-jump][dumb-jump]], which uses the above utilities.
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(use-package dumb-jump
|
||||||
|
:config
|
||||||
|
(setq xref-show-definitions-function #'xref-show-definitions-completing-read)
|
||||||
|
(add-hook 'xref-backend-functions #'dumb-jump-xref-activate))
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
Remember the following:
|
||||||
|
- ~g d~ jumps to definition of symbol at point … which is amazeballs.
|
||||||
|
- ~g r~ shows us all entries of the symbol at point, like [[help:xref-find-references][xref-find-references]]
|
||||||
|
- ~M-,~ to go back along the jump history
|
||||||
** Language Server Protocol (LSP) Integration
|
** Language Server Protocol (LSP) Integration
|
||||||
The [[https://microsoft.github.io/language-server-protocol/][LSP]] is a way to connect /editors/ (like Emacs) to /languages/ (like Lisp)… wait, no, it was originally designed for VS Code and probably Python, but we now abstract away [[https://github.com/davidhalter/jedi][Jedi]] and the [[http://tkf.github.io/emacs-jedi/latest/][Emacs integration to Jedi]] (and duplicate everything for Ruby, and Clojure, and…).
|
The [[https://microsoft.github.io/language-server-protocol/][LSP]] is a way to connect /editors/ (like Emacs) to /languages/ (like Lisp)… wait, no, it was originally designed for VS Code and probably Python, but we now abstract away [[https://github.com/davidhalter/jedi][Jedi]] and the [[http://tkf.github.io/emacs-jedi/latest/][Emacs integration to Jedi]] (and duplicate everything for Ruby, and Clojure, and…).
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue