Integration with ripgrep and wgrep

And a code change just to verify it!
This commit is contained in:
Howard Abrams 2021-12-29 09:34:48 -08:00
parent 6fdd2bb756
commit 9f28c9a51a
3 changed files with 28 additions and 15 deletions

4
.gitignore vendored
View file

@ -4,7 +4,3 @@
/elisp/gourmet-projects.el
/ha-private.org
/incubate.org
/elisp/beep.el
/elisp/boxes-extras.el
/elisp/boxes.el
/elisp/ha-focus.el

View file

@ -5,7 +5,10 @@
My Emacs configuration, that I'm cheekily calling /hamacs/ is a literate programming model heavily inspired by my recent journey into [[https://www.youtube.com/watch?v=LKegZI9vWUU][Henrik Lissner's]] [[https://github.com/hlissner/doom-emacs][Doom Emacs]] and [[https://www.spacemacs.org/][Spacemacs]]. I used both extensively, but decided that I would /roll my own/ as Emacs people tend to be /control freaks/ (at least a little bit).
Why yes, feel free to steal whatever you find interesting, as sharing is what makes our community great. Hit me up with questions =@howardabrams=. If you want to try this out, after installing Emacs, and cloning this repo, run:
The other advantage to rolling yer own is that you are more likely to /use/ what you add, leading to less bloat, and a more fun experience.
Why yes, feel free to steal whatever you find interesting, as sharing is what makes our community great. Notice that functions and features that I have written begin with =ha-=, however, everything else is either /stock Emacs/ or a /package/ that I download using [[https://github.com/raxod502/straight.el][straight]] (see [[file:bootstrap.org][bootstrap]] for how) and configured with [[https://github.com/jwiegley/use-package][use-package]] (see either [[https://ianyepan.github.io/posts/setting-up-use-package/][this introduction]] or [[https://www.emacswiki.org/emacs/UsePackage][this wiki page]] for details)... meaning that most blocks of code should /just work/ on its own.
Hit me up with questions, =@howardabrams=. If you want to try this out, after installing Emacs, and cloning this repo, run:
#+BEGIN_SRC sh
./initialize
#+END_SRC

View file

@ -393,7 +393,7 @@ And ways to stop the system:
*** File Operations
Obviously, =find-file= is still my bread and butter, but I do like getting information about the file associated with the buffer. For instance, the file path:
#+BEGIN_SRC emacs-lisp
(defun ha/relative-filepath (filepath)
(defun ha-relative-filepath (filepath)
"Return the FILEPATH without the HOME directory and typical filing locations.
The expectation is that this will return a filepath with the proejct name."
(let* ((home-re (rx (literal (getenv "HOME")) "/"))
@ -407,7 +407,7 @@ The expectation is that this will return a filepath with the proejct name."
((string-match home-re filepath) (substring filepath (match-end 0)))
(t filepath))))
(defun ha/yank-buffer-path (&optional root)
(defun ha-yank-buffer-path (&optional root)
"Copy the file path of the buffer relative to my 'work' directory, ROOT."
(interactive)
(if-let (filename (buffer-file-name (buffer-base-buffer)))
@ -415,10 +415,10 @@ The expectation is that this will return a filepath with the proejct name."
(kill-new (abbreviate-file-name
(if root
(file-relative-name filename root)
(ha/relative-filepath filename)))))
(ha-relative-filepath filename)))))
(error "Couldn't find filename in current buffer")))
(defun ha/yank-project-buffer-path (&optional root)
(defun ha-yank-project-buffer-path (&optional root)
"Copy the file path of the buffer relative to the file's project.
If ROOT is given, they copies the filepath relative to that."
(interactive)
@ -441,8 +441,8 @@ With these helper functions in place, I can create a leader collection for file-
"f c" '("copy" . copy-file)
"f R" '("rename" . rename-file)
"f D" '("delete" . delete-file)
"f y" '("yank path" . ha/yank-buffer-path)
"f Y" '("yank path from project" . ha/yank-project-buffer-path)
"f y" '("yank path" . ha-yank-buffer-path)
"f Y" '("yank path from project" . ha-yank-project-buffer-path)
"f d" '("dired" . dired))
#+END_SRC
*** Buffer Operations
@ -450,7 +450,7 @@ This section groups buffer-related operations under the "SPC b" sequence.
Putting the entire visible contents of the buffer on the clipboard is often useful:
#+BEGIN_SRC emacs-lisp
(defun ha/yank-buffer-contents ()
(defun ha-yank-buffer-contents ()
"Copy narrowed contents of the buffer to the clipboard."
(interactive)
(kill-new (buffer-substring-no-properties
@ -473,7 +473,7 @@ And the collection of useful operations:
"b S" '("save all" . evil-write-all)
"b n" '("next" . next-buffer)
"b p" '("previous" . previous-buffer)
"b y" '("copy contents" . ha/yank-buffer-contents)
"b y" '("copy contents" . ha-yank-buffer-contents)
"b z" '("bury" . bury-buffer)
"b Z" '("unbury" . unbury-buffer)
@ -659,6 +659,20 @@ Ways to search for information goes under the ~s~ key. This primarily depends on
(previous-error-no-select)
(compile-goto-error)))
#+END_SRC
The [[https://github.com/mhayashi1120/Emacs-wgrep][wgrep package]] integrates with ripgrep. Typically, you can just his ~i~ to automatically go into =wgrep-mode= and edit away, however, I typically want to edit everything at the same time, so I have a toggle that should work as well:
#+BEGIN_SRC emacs-lisp
(use-package wgrep
:after rg
:commands wgrep-rg-setup
:hook (rg-mode-hook . wgrep-rg-setup)
:config
(ha-leader
:keymaps 'rg-mode-map ; Actually, just `i` works!
"s w" '("wgrep-mode" . wgrep-change-to-wgrep-mode)
"t w" '("wgrep-mode" . wgrep-change-to-wgrep-mode)))
#+END_SRC
*** Text Operations
Stealing much of this from Spacemacs.
#+BEGIN_SRC emacs-lisp