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.

  • \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 7 '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 7 '18 at 22:14
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.

  • Do you know how to make my snippet work, so I can easily jump into this mode of searching? – forthrin Apr 10 '18 at 12:44
  • Did you try using \n instead of a literal newline char? – Drew Apr 10 '18 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.