Last active
January 30, 2023 21:16
-
-
Save mtwomey/629bb4b2163450117b7a4c8fdcc8eb4a to your computer and use it in GitHub Desktop.
Quickly run occur from your previous search regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun occur-from-search () | |
"Runs occur on the regex used in the last '/' search. This is useful for capturing | |
all the matches (just the matches, not the whole lines) into the occur buffer so | |
you can do something with them. | |
Note: Assumes evil search, so you may need to tweak for your needs." | |
(interactive) | |
(let ((search-pattern evil-ex-search-pattern)) | |
(if search-pattern | |
(let ((capture-type (if (zerop (regexp-opt-depth (nth 0 search-pattern))) | |
"\\&" ;; No subexpression so collect the entire match. | |
"\\1"))) ;; Get the first subexpression | |
(occur (nth 0 search-pattern) | |
capture-type)) | |
(message "First search with '/'.")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Most excellent hack!