emacs space regex search
I want to search for x spaces at the start of a line, using interactive regular search ^SPC<
selects all lines starting with a variable number of spaces. According to emacs wiki
(setq search-whitespace-regexp " ")
Should solve this, but this reverses behavior: it selects one space when i'm entering multiple spaces in my search. I do n开发者_C百科ot remember this behavior from earlier emacs (using 23.2 now). Is there a way to make interactive search select one space when entered one space and x spaces when entered x spaces?
cheers Jeroen
I think the behavior you observe is the intended one. From the documentation of search-whitespace-regexp
:
If non-nil, regular expression to match a sequence of whitespace chars. [...] When you put a space or spaces in the incremental regexp, it stands for this.
Note the second sentence - whenever you put a single (or multiple) space character(s) in your regex, that gets interpreted as if you entered the value of search-whitespace-regexp
. Since you defined that variable to be a single space character, one or multiple space character(s) in your regexp will only match a single space character in your buffer.
Probably the easiest way to achieve what you want is thus to simply set the variable to nil
, in which case space characters are no longer treated in a special way in interactive regexp searches. A single space character in your regex will only match a single space character in the buffer.
(setq search-whitespace-regexp nil)
You could try ^[ ]\{5\}<
to get lines beginning with 5 spaces, followed by a <
.
精彩评论