简体   繁体   中英

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 not 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)

您可以尝试^[ ]\\{5\\}<以获得以5个空格开头的行,然后是<

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM