From 9be7e37adb1704113c46dcf41df83d93720f0773 Mon Sep 17 00:00:00 2001 From: Gerard Vermeulen Date: Sun, 7 May 2023 17:05:46 +0200 Subject: [PATCH] Steal `multi-occur-in-this-mode' from Mastering Emacs --- README.org | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.org b/README.org index 92adc7f..31b7efc 100644 --- a/README.org +++ b/README.org @@ -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