Steal `multi-occur-in-this-mode' from Mastering Emacs

This commit is contained in:
Gerard Vermeulen 2023-05-07 17:05:46 +02:00
parent eaa7e41d1a
commit 9be7e37adb
1 changed files with 26 additions and 0 deletions

View File

@ -1580,6 +1580,32 @@ the current [[https://en.wikipedia.org/wiki/Version_control][VCS]] directory tre
(keymap-set deadgrep-mode-map "C-c C-w" #'deadgrep-edit-mode)))
#+end_src
** [[https://www.masteringemacs.org/article/searching-buffers-occur-mode][Searching and Editing in Buffers with Occur Mode]]
:PROPERTIES:
:CUSTOM_ID: sec:occur
:END:
#+caption[Define =multi-occur-in-this-mode=]:
#+caption: Define =multi-occur-in-this-mode=.
#+name: lst:multi-occur-in-this-mode
#+begin_src emacs-lisp -n :results silent
(defun get-buffers-matching-mode (mode)
"Return a list of buffers whose major-mode is equal to MODE."
(let ((buffer-mode-matches '()))
(dolist (buf (buffer-list))
(with-current-buffer buf
(when (eq mode major-mode)
(push buf buffer-mode-matches))))
buffer-mode-matches))
(defun multi-occur-in-this-mode ()
"Show all lines matching REGEXP in buffers with this major mode."
(interactive)
(multi-occur
(get-buffers-matching-mode major-mode)
(car (occur-read-primary-args))))
#+end_src
** [[https://www.genivia.com/get-ugrep.html][Ugrep]]
:PROPERTIES:
:CUSTOM_ID: sec:ugrep