[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Interpretation of a space in regexp isearch?
From: |
Juri Linkov |
Subject: |
Re: Interpretation of a space in regexp isearch? |
Date: |
Fri, 31 Aug 2012 03:07:08 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (x86_64-pc-linux-gnu) |
> Chong Yidong <address@hidden> writes:
>
> Do you want to take a crack at it, or shall I?
The following patch just echoes what was being said
in this discussion so far. Please review it and decide
what to do next.
=== modified file 'lisp/isearch.el'
--- lisp/isearch.el 2012-08-27 04:08:32 +0000
+++ lisp/isearch.el 2012-08-31 00:04:17 +0000
@@ -109,6 +109,19 @@ (defcustom search-nonincremental-instead
:type 'boolean
:group 'isearch)
+(defcustom search-whitespace t
+ "If non-nil, a space will match a sequence of whitespace chars.
+When you enter a space or spaces in the incremental search, it
+will match any sequence matched by the regexp in the variable
+`search-whitespace-regexp'.
+
+If the value is nil, each space you type matches literally,
+against one space."
+ :type '(choice (const :tag "Treat Spaces Literally" nil)
+ (const :tag "Match a sequence of whitespace chars" t))
+ :group 'isearch
+ :version "24.3")
+
(defcustom search-whitespace-regexp (purecopy "\\s-+")
"If non-nil, regular expression to match a sequence of whitespace chars.
When you enter a space or spaces in the incremental search, it
@@ -120,20 +133,10 @@ (defcustom search-whitespace-regexp (pur
incremental search. If the value is nil, each space you type
matches literally, against one space.
-The value can also be a cons cell (REGEXP-1 . REGEXP-2). In that
-case, REGEXP-1 is used as the value for ordinary incremental
-search, and REGEXP-2 is used for regexp incremental search.
-
You might want to use something like \"[ \\t\\r\\n]+\" instead.
In the Customization buffer, that is `[' followed by a space,
a tab, a carriage return (control-M), a newline, and `]+'."
:type '(choice (const :tag "Treat Spaces Literally" nil)
- (cons (choice :tag "For Ordinary Isearch"
- regexp
- (const :tag "Treat Spaces Literally" nil))
- (choice :tag "For Regexp Isearch"
- regexp
- (const :tag "Treat Spaces Literally" nil)))
regexp)
:group 'isearch
:version "24.3")
@@ -510,6 +525,7 @@ (defvar isearch-mode-map
(define-key map "\M-r" 'isearch-toggle-regexp)
(define-key map "\M-e" 'isearch-edit-string)
+ (define-key map "\M-s " 'isearch-toggle-whitespace)
(define-key map "\M-sc" 'isearch-toggle-case-fold)
(define-key map "\M-sr" 'isearch-toggle-regexp)
(define-key map "\M-sw" 'isearch-toggle-word)
@@ -1374,7 +1400,8 @@ (defun isearch-toggle-regexp ()
;; The status stack is left unchanged.
(interactive)
(setq isearch-regexp (not isearch-regexp))
- (if isearch-regexp (setq isearch-word nil))
+ (if isearch-regexp (setq isearch-word nil
+ search-whitespace nil))
(setq isearch-success t isearch-adjusted t)
(isearch-update))
@@ -1383,7 +1410,8 @@ (defun isearch-toggle-word ()
;; The status stack is left unchanged.
(interactive)
(setq isearch-word (not isearch-word))
- (if isearch-word (setq isearch-regexp nil))
+ (if isearch-word (setq isearch-regexp nil
+ search-whitespace nil))
(setq isearch-success t isearch-adjusted t)
(isearch-update))
@@ -1392,6 +1420,8 @@ (defun isearch-toggle-symbol ()
(interactive)
(setq isearch-word (unless (eq isearch-word 'isearch-symbol-regexp)
'isearch-symbol-regexp))
+ (if isearch-word (setq isearch-regexp nil
+ search-whitespace nil))
(setq isearch-success t isearch-adjusted t)
(isearch-update))
@@ -1409,6 +1439,19 @@ (defun isearch-toggle-case-fold ()
(sit-for 1)
(isearch-update))
+(defun isearch-toggle-whitespace ()
+ "Toggle whitespace matching in searching on or off."
+ (interactive)
+ (setq search-whitespace (not search-whitespace))
+ (let ((message-log-max nil))
+ (message "%s%s [whitespace matching %s]"
+ (isearch-message-prefix nil isearch-nonincremental)
+ isearch-message
+ (if search-whitespace "enabled" "disabled")))
+ (setq isearch-success t isearch-adjusted t)
+ (sit-for 1)
+ (isearch-update))
+
;; Word search
@@ -1558,15 +1611,6 @@ (defun isearch-query-replace-regexp (&op
(list current-prefix-arg))
(isearch-query-replace delimited t))
-(defun isearch-whitespace-regexp ()
- "Return the value of `search-whitespace-regexp' for the current search."
- (cond ((not (consp search-whitespace-regexp))
- search-whitespace-regexp)
- (isearch-regexp
- (cdr search-whitespace-regexp))
- (t
- (car search-whitespace-regexp))))
-
(defun isearch-occur (regexp &optional nlines)
"Run `occur' using the last search string as the regexp.
Interactively, REGEXP is constructed using the search string from the
@@ -1606,7 +1650,8 @@ (defun isearch-occur (regexp &optional n
;; Set `search-upper-case' to nil to not call
;; `isearch-no-upper-case-p' in `occur-1'.
(search-upper-case nil)
- (search-spaces-regexp (isearch-whitespace-regexp)))
+ (search-spaces-regexp (if search-whitespace
+ search-whitespace-regexp)))
(occur regexp nlines)))
(declare-function hi-lock-read-face-name "hi-lock" ())
@@ -2428,6 +2488,8 @@ (defun isearch-search-fun ()
(defun isearch-search-fun-default ()
"Return default functions to use for the search."
(cond
+ ((and search-whitespace search-whitespace-regexp (not isearch-regexp))
+ (if isearch-forward 'whitespace-search-forward
'whitespace-search-backward))
(isearch-word
(lambda (string &optional bound noerror count)
;; Use lax versions to not fail at the end of the word while
@@ -2446,12 +2508,12 @@ (defun isearch-search-fun-default ()
(isearch-regexp
(if isearch-forward 're-search-forward 're-search-backward))
(t
- (if isearch-forward 'isearch-search-forward 'isearch-search-backward))))
+ (if isearch-forward 'search-forward 'search-backward))))
-(defun isearch-search-forward (string &optional bound noerror count)
+(defun whitespace-search-forward (string &optional bound noerror count)
(re-search-forward (regexp-quote string) bound noerror count))
-(defun isearch-search-backward (string &optional bound noerror count)
+(defun whitespace-search-backward (string &optional bound noerror count)
(re-search-backward (regexp-quote string) bound noerror count))
(defun isearch-search-string (string bound noerror)
@@ -2503,7 +2565,8 @@ (defun isearch-search ()
search-invisible))
(inhibit-quit nil)
(case-fold-search isearch-case-fold-search)
- (search-spaces-regexp (isearch-whitespace-regexp))
+ (search-spaces-regexp (if search-whitespace
+ search-whitespace-regexp))
(retry t))
(setq isearch-error nil)
(while retry
@@ -2805,7 +2912,8 @@ (defvar isearch-lazy-highlight-window-st
(defvar isearch-lazy-highlight-window-end nil)
(defvar isearch-lazy-highlight-case-fold-search nil)
(defvar isearch-lazy-highlight-regexp nil)
-(defvar isearch-lazy-highlight-space-regexp nil)
+(defvar isearch-lazy-highlight-whitespace nil)
+(defvar isearch-lazy-highlight-whitespace-regexp nil)
(defvar isearch-lazy-highlight-word nil)
(defvar isearch-lazy-highlight-forward nil)
(defvar isearch-lazy-highlight-error nil)
@@ -2873,7 +2981,8 @@ (defun isearch-lazy-highlight-new-loop (
isearch-lazy-highlight-last-string isearch-string
isearch-lazy-highlight-case-fold-search isearch-case-fold-search
isearch-lazy-highlight-regexp isearch-regexp
- isearch-lazy-highlight-space-regexp (isearch-whitespace-regexp)
+ isearch-lazy-highlight-whitespace search-whitespace
+ isearch-lazy-highlight-whitespace-regexp search-whitespace-regexp
isearch-lazy-highlight-word isearch-word
isearch-lazy-highlight-forward isearch-forward)
(unless (equal isearch-string "")
@@ -2887,7 +2996,8 @@ (defun isearch-lazy-highlight-search ()
(condition-case nil
(let ((case-fold-search isearch-lazy-highlight-case-fold-search)
(isearch-regexp isearch-lazy-highlight-regexp)
- (search-spaces-regexp isearch-lazy-highlight-space-regexp)
+ (search-spaces-regexp (if isearch-lazy-highlight-whitespace
+ isearch-lazy-highlight-whitespace-regexp))
(isearch-word isearch-lazy-highlight-word)
(search-invisible nil) ; don't match invisible text
(retry t)
- Re: Interpretation of a space in regexp isearch?, (continued)
- Re: Interpretation of a space in regexp isearch?, Juri Linkov, 2012/08/28
- RE: Interpretation of a space in regexp isearch?, Drew Adams, 2012/08/28
- Re: Interpretation of a space in regexp isearch?, Juri Linkov, 2012/08/29
- RE: Interpretation of a space in regexp isearch?, Drew Adams, 2012/08/29
- Re: Interpretation of a space in regexp isearch?, Juri Linkov, 2012/08/29
- Re: Interpretation of a space in regexp isearch?, Chong Yidong, 2012/08/30
- Re: Interpretation of a space in regexp isearch?, Chong Yidong, 2012/08/30
- Re: Interpretation of a space in regexp isearch?, Juri Linkov, 2012/08/30
- Re: Interpretation of a space in regexp isearch?, Stefan Monnier, 2012/08/30
- Re: Interpretation of a space in regexp isearch?, Juri Linkov, 2012/08/30
- Re: Interpretation of a space in regexp isearch?,
Juri Linkov <=
- Re: Interpretation of a space in regexp isearch?, Chong Yidong, 2012/08/31
- Re: Interpretation of a space in regexp isearch?, Juri Linkov, 2012/08/31
- Re: Interpretation of a space in regexp isearch?, Chong Yidong, 2012/08/31
- Re: Interpretation of a space in regexp isearch?, Juri Linkov, 2012/08/31
- Re: Interpretation of a space in regexp isearch?, Chong Yidong, 2012/08/31
- Re: Interpretation of a space in regexp isearch?, Chong Yidong, 2012/08/29
- Re: Interpretation of a space in regexp isearch?, Juri Linkov, 2012/08/29
- Re: Interpretation of a space in regexp isearch?, Stefan Monnier, 2012/08/29
- Re: Interpretation of a space in regexp isearch?, Dani Moncayo, 2012/08/29
- Re: Interpretation of a space in regexp isearch?, Juri Linkov, 2012/08/29