2

How can I jump to the next character matching a regex (see example below)? And if possible, enable highlighting of all the matching characters in the buffer when I jump for the first time.

[^\x20-\x7eéèëê]

This article says how to do it for non-ASCII, but I want to allow certain non-ASCII characters. I tried occur, but it doesn't seem to accept \x##. Regardless, jump and highlight is highly preferable.

Update: To use isearch for my purpose, I modified this snippet. However, it seems to do a literal search, even if I have t as argument. How do I make it do a regex search?

(defun my-search-word ()
  (interactive)
  (isearch-forward t 1)
  (isearch-yank-string "[^ -~éèëê
]"))

Note: I had to include a literal newline in the search string to prevent highlighting all newlines.

forthrin
  • 451
  • 2
  • 10
  • `\x##` is an elisp *read syntax* escape sequence for chars and strings, so you can use it in elisp code, but you can't use it when entering a regexp *interactively*. e.g. Interactively the regexp `[\x20]` matches any one of `\ `, `x`, `2`, and `0`. – phils Apr 07 '18 at 22:07
  • That said, if you have `enable-recursive-minibuffers` set (preferably with `minibuffer-depth-indicate-mode` enabled) then you can use elisp evaluation to enter an interactive value. e.g. At the regexp prompt, type `C-u M-: "[^\x20-\x7eéèëê]" RET` (double-quotes included), and then you edit the double-quotes out of the result. – phils Apr 07 '18 at 22:14

1 Answers1

2

During Isearch, including regexp searches, you can use C-x 8 RET to input any Unicode character. Completion is available against the character names, and you can alternatively enter the code point.

So you can search directly for the pattern [^ -~éèëê] instead of [^\x20-\x7eéèëê].

You can also use character composition and input methods during Isearch, as far as I know.

These approaches let you see the characters you are searching, in the regexp pattern itself.

Drew
  • 75,699
  • 9
  • 109
  • 225