Integration with ripgrep and wgrep
And a code change just to verify it!
This commit is contained in:
parent
6fdd2bb756
commit
9f28c9a51a
3 changed files with 28 additions and 15 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -4,7 +4,3 @@
|
||||||
/elisp/gourmet-projects.el
|
/elisp/gourmet-projects.el
|
||||||
/ha-private.org
|
/ha-private.org
|
||||||
/incubate.org
|
/incubate.org
|
||||||
/elisp/beep.el
|
|
||||||
/elisp/boxes-extras.el
|
|
||||||
/elisp/boxes.el
|
|
||||||
/elisp/ha-focus.el
|
|
||||||
|
|
|
@ -3,9 +3,12 @@
|
||||||
#+DATE: 2021-11-01 November
|
#+DATE: 2021-11-01 November
|
||||||
#+TAGS: emacs
|
#+TAGS: emacs
|
||||||
|
|
||||||
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).
|
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
|
#+BEGIN_SRC sh
|
||||||
./initialize
|
./initialize
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
@ -31,4 +34,4 @@ This creates [[file:~/.emacs.d/init.el][~/.emacs.d/init.el]] that starts the pro
|
||||||
- [[file:ha-programming.org][ha-programming.org]] :: configuration for /all/ programming languages, or at least, the simple ones.
|
- [[file:ha-programming.org][ha-programming.org]] :: configuration for /all/ programming languages, or at least, the simple ones.
|
||||||
- [[file:ha-programming-python.org][ha-programming-python.org]] :: configuration for working with Python and LSP.
|
- [[file:ha-programming-python.org][ha-programming-python.org]] :: configuration for working with Python and LSP.
|
||||||
|
|
||||||
*Note:* Other functions and files come from essays written on [[http://www.howardism.org][my blog]]. To help with this, see [[file:support/final-initialize.el][support/final-initialize.el]] file.
|
*Note:* Other functions and files come from essays written on [[http://www.howardism.org][my blog]]. To help with this, see [[file:support/final-initialize.el][support/final-initialize.el]] file.
|
||||||
|
|
|
@ -393,7 +393,7 @@ And ways to stop the system:
|
||||||
*** File Operations
|
*** 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:
|
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
|
#+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.
|
"Return the FILEPATH without the HOME directory and typical filing locations.
|
||||||
The expectation is that this will return a filepath with the proejct name."
|
The expectation is that this will return a filepath with the proejct name."
|
||||||
(let* ((home-re (rx (literal (getenv "HOME")) "/"))
|
(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)))
|
((string-match home-re filepath) (substring filepath (match-end 0)))
|
||||||
(t filepath))))
|
(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."
|
"Copy the file path of the buffer relative to my 'work' directory, ROOT."
|
||||||
(interactive)
|
(interactive)
|
||||||
(if-let (filename (buffer-file-name (buffer-base-buffer)))
|
(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
|
(kill-new (abbreviate-file-name
|
||||||
(if root
|
(if root
|
||||||
(file-relative-name filename root)
|
(file-relative-name filename root)
|
||||||
(ha/relative-filepath filename)))))
|
(ha-relative-filepath filename)))))
|
||||||
(error "Couldn't find filename in current buffer")))
|
(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.
|
"Copy the file path of the buffer relative to the file's project.
|
||||||
If ROOT is given, they copies the filepath relative to that."
|
If ROOT is given, they copies the filepath relative to that."
|
||||||
(interactive)
|
(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 c" '("copy" . copy-file)
|
||||||
"f R" '("rename" . rename-file)
|
"f R" '("rename" . rename-file)
|
||||||
"f D" '("delete" . delete-file)
|
"f D" '("delete" . delete-file)
|
||||||
"f y" '("yank path" . ha/yank-buffer-path)
|
"f y" '("yank path" . ha-yank-buffer-path)
|
||||||
"f Y" '("yank path from project" . ha/yank-project-buffer-path)
|
"f Y" '("yank path from project" . ha-yank-project-buffer-path)
|
||||||
"f d" '("dired" . dired))
|
"f d" '("dired" . dired))
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
*** Buffer Operations
|
*** 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:
|
Putting the entire visible contents of the buffer on the clipboard is often useful:
|
||||||
#+BEGIN_SRC emacs-lisp
|
#+BEGIN_SRC emacs-lisp
|
||||||
(defun ha/yank-buffer-contents ()
|
(defun ha-yank-buffer-contents ()
|
||||||
"Copy narrowed contents of the buffer to the clipboard."
|
"Copy narrowed contents of the buffer to the clipboard."
|
||||||
(interactive)
|
(interactive)
|
||||||
(kill-new (buffer-substring-no-properties
|
(kill-new (buffer-substring-no-properties
|
||||||
|
@ -473,7 +473,7 @@ And the collection of useful operations:
|
||||||
"b S" '("save all" . evil-write-all)
|
"b S" '("save all" . evil-write-all)
|
||||||
"b n" '("next" . next-buffer)
|
"b n" '("next" . next-buffer)
|
||||||
"b p" '("previous" . previous-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" '("bury" . bury-buffer)
|
||||||
"b Z" '("unbury" . unbury-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)
|
(previous-error-no-select)
|
||||||
(compile-goto-error)))
|
(compile-goto-error)))
|
||||||
#+END_SRC
|
#+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
|
*** Text Operations
|
||||||
Stealing much of this from Spacemacs.
|
Stealing much of this from Spacemacs.
|
||||||
#+BEGIN_SRC emacs-lisp
|
#+BEGIN_SRC emacs-lisp
|
||||||
|
|
Loading…
Reference in a new issue