1

Often I'll search (an ordinary i-search) for a sequence of two spaces, or three, or four.

But on one machine I'm using, emacs by default appears to be in some mode where searches for spaces are special. For example, a search for two spaces will "find" a tab — I guess because a tab "looks like" two (or more) spaces.

Does anyone know what this mode might be, or how to turn it off? (Whatever the mode is, it's active even in Fundamental mode.)

I'm observing this with emacs 24.3.1. I do not observe it with 22.1.1 or 26.1. But I suspect it's a configuration thing, not a version-specific thing.

Drew
  • 75,699
  • 9
  • 109
  • 225
Steve Summit
  • 133
  • 4
  • Duplicate: [Match two spaces with incremental search](https://emacs.stackexchange.com/questions/2819/match-two-spaces-with-incremental-search) (also answered by Drew). Dunno why I couldn't find that first. – Steve Summit Mar 11 '22 at 21:49
  • Thanks for finding the dup. I too didn't find it when searching. I've voted to close this question now. And I added tag `isearch` to the dup question. – Drew Mar 12 '22 at 01:28
  • 1
    Does this answer your question? [Match two spaces with incremental search](https://emacs.stackexchange.com/questions/2819/match-two-spaces-with-incremental-search) – Drew Mar 12 '22 at 01:28

1 Answers1

1

A SPC char normally matches all whitespace defined by option search-whitespace-regexp. You can customize this option, so you get the matching you want by default. C-h v search-whitespace-regexp tells us, in addition to more info about the option:

If the value is nil, or [if] isearch-lax-whitespace is nil for ordinary incremental search, or isearch-regexp-lax-whitespace is nil for regexp incremental search, then each space you type matches literally, against one space.

Use key M-s SPC during Isearch to toggle this behavior. C-h k M-s SPC says:

isearch-toggle-lax-whitespace is an interactive compiled Lisp function in isearch.el. ? (isearch-toggle-lax-whitespace)

Toggle lax-whitespace searching on or off.

In ordinary search, toggles the value of the variable isearch-lax-whitespace. In regexp search, toggles the value of the variable isearch-regexp-lax-whitespace.

You can of course set the default values of those individual variables (they're not user options, however), to define the default behavior you prefer. But a mode etc. can change their values, overriding the values you set. (And a mode can change the value of search-whitespace-regexp, though modes are generally not supposed to override user options.)

At least you can toggle the behavior at any time.

If you are seeing this only for Emacs version 24.3.1, do you also see the problem if you start that Emacs version using emacs -Q (no init file)? If not then bisect your init file to find the culprit.


Not-so-well-known tip:

When regexp isearching, you can use C-q SPC to search for a single space char at a time. No need to fiddle with any lax/strict whitespace matching.

Drew
  • 75,699
  • 9
  • 109
  • 225