I'm writing a lot of Markdown for input to pandoc, so my files contain a lot of Unicode non-breaking spaces (U+00A0). I'd like those to search as whitespace with isearch-forward, so I tried adding the character to my search-whitespace-regexp variable. But it doesn't work. I suspect there might be a UTF-8 issue somewhere.

I've tried

(set (make-local-variable 'search-whitespace-regexp)
 "[ \t\r\n\f~\u00a0]+")

and I've also tried just hard-coding the character between the square brackets. Neither works. By contrast, I can search the ~ character as white space just fine---so I know something is working.

How can I persuade Emacs that the U+00A0 should be accepted as a space character, for purposes of search?

I'm running Emacs 24.5, a stock Emacs from Debian jessie.

Edited to add: following a comment from steveooo, I've determined that

M-x eval (search-forward-regexp "cise[ \t\r\n\f~\u00a0]6")

correctly finds the string I'm looking for, but isearch-forward still does not work.

Edited to add: In Emacs 25, nothing seems to have changed.

  • Data point: When I test (using re-builder) a regexp "[\u00a0]+" on a buffer that contains non-breaking spaces, it matches properly. This is with emacs 26.0.50 (built from upstream source in the last month or so). – NickD Mar 15 '17 at 15:18
  • This is odd - calling (search-forward-regexp "[ \t\r\n\f~\u00a0]+") works as expected so it doesn't look as though it's a problem with the regexp itself. I wonder if this means that it's a problem with isearch - which I assume is what you mean by searching? – stevoooo Mar 21 '17 at 18:23
  • @stevoooo it is very odd. I have edited to add that using M-x eval with your command works for me, but using M-x search-forward-regexp does not. I feel like there ought to be a clue there, but I don't know what it is. – Norman Ramsey Mar 23 '17 at 14:45
  • "enter the same regexp in the minibuffer (without the double quotes)" - I don't think that prompt interprets character escape syntax, i.e., you're searching for cise[ trnf~u0a]6. – npostavs Mar 23 '17 at 14:58
  • @npostavs Thanks. Removed that reference. – Norman Ramsey Mar 23 '17 at 17:24

Your Answer

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

Browse other questions tagged or ask your own question.