I recently discovered emacs's "regex-builder" mode and am absolutely loving it. However, there doesn't seem to be an easy way to type in an expression in the "RE-Bulider" buffer and use that expression to search for matches.
My use case for regexp-builder is currently to write a regular expression, and once I see some matches, I scan through the document manually to see all the matching strings. I currently use the "string" regex syntax for my regexp-builder, as recommended here, so I don't think I would need to modify the
Right now, if I type in an expression in the RE-Builder buffer and press
C-M-r (isearch forward/backward regexp), I get whichever regular expression I used with
isearch last, which is oftentimes different than what I'm currently searching for. Additionally, these isearch commands only perform their search on the current buffer, which happens to be the regex-builder buffer, which leads to no matches being performed on the buffer I want to search.
What I want to do is to bind the
C-r keys to
re-search-backward functions on the buffer I'm searching in whenever I begin using the regex builder.
I've made the following function in my
~/.emacs, but after evaluating the buffer, putting an expression in the
RE Builder buffer and pressing the corresponding shortcuts, I still get
isearch-forward, the default behavior.
(require 're-builder) (setq reb-re-syntax 'string) ;; Improve regex searching through regexp builder (defun regexp-builder-mode-config() "For use in `reb-mode-hook'." (local-set-key (kbd "C-s") 're-search-forward) (local-set-key (kbd "C-r") 're-search-backward) ) (add-hook 'reb-mode-hook 'regexp-builder-mode-config)
Essentially, what I want this to do is two-fold:
Once I make a regular expression, press the key combination
<C-r>and be able to search for a regular expression in the buffer.
Solve the problem of emacs implicitly converting from one syntax (string) to the other (read). When I copy the expression I'm building to the kill ring
(C-c C-w), emacs adds a bunch of extraneous backslashes (which I presume is due to how it handles regular expressions in the interactive buffer), which makes my regex not work anymore.
At the moment, I believe I'm close to solving the first point, which is being able to edit a regex and then conveniently search for it in the buffer I'm working on. However, when I press
C-r, I get the usual
isearch-forward/backward functionality I'm trying to avoid, almost as if me changing the hook didn't affect anything.
I checked the documentation, and I'm fairly sure I'm using the correct hook, but any and all help is welcome!