emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Interpretation of a space in regexp isearch?


From: Chong Yidong
Subject: Re: Interpretation of a space in regexp isearch?
Date: Wed, 29 Aug 2012 14:46:20 +0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux)

Juri Linkov <address@hidden> writes:

>> The magic of `C-q SPC' is missing for non-regexp searches though.
>
> `C-q SPC' inserts "[ ]" in regexp search.  The problem for non-regexp
> search is how to avoid quoting "[ ]" in `regexp-quote'.

Good point.  Here's how to handle this: when isearch-regexp is nil, make
isearch-process-search-string call regexp-quote for each addition to the
search string; then have isearch-quote-char suppress quoting by passing
an optional arg to isearch-process-search-string.

Then in isearch-search-fun-default, we can use re-search-forward for
plain isearch as well, since the search string will have been
appropriately quoted when processed.  See attached patch.


*** lisp/isearch.el     2012-08-26 04:08:32 +0000
--- lisp/isearch.el     2012-08-29 06:38:42 +0000
***************
*** 2200,2217 ****
    "Quote special characters for incremental search."
    (interactive)
    (let ((char (read-quoted-char (isearch-message t))))
!     ;; Assume character codes 0200 - 0377 stand for characters in some
!     ;; single-byte character set, and convert them to Emacs
!     ;; characters.
!     (if (and isearch-regexp (= char ?\s))
!       (if (subregexp-context-p isearch-string (length isearch-string))
!           (isearch-process-search-string "[ ]" " ")
!         (isearch-process-search-char char))
        (and enable-multibyte-characters
           (>= char ?\200)
           (<= char ?\377)
           (setq char (unibyte-char-to-multibyte char)))
!       (isearch-process-search-char char))))
  
  (defun isearch-printing-char ()
    "Add this ordinary printing character to the search string and search."
--- 2200,2222 ----
    "Quote special characters for incremental search."
    (interactive)
    (let ((char (read-quoted-char (isearch-message t))))
!     (cond
!      ((/= char ?\s)
!       ;; Assume character codes 0200 - 0377 stand for characters in
!       ;; some single-byte character set, and convert them to Emacs
!       ;; characters.
        (and enable-multibyte-characters
           (>= char ?\200)
           (<= char ?\377)
           (setq char (unibyte-char-to-multibyte char)))
!       (isearch-process-search-char char))
!      ((and isearch-regexp
!          (null (subregexp-context-p isearch-string
!                                     (length isearch-string))))
!       (isearch-process-search-char char))
!      ;; Handle C-q SPC by disabling `search-whitespace-regexp' match.
!      (t
!       (isearch-process-search-string "[ ]" " " t)))))
  
  (defun isearch-printing-char ()
    "Add this ordinary printing character to the search string and search."
***************
*** 2239,2245 ****
         (char-to-string char)
       (isearch-text-char-description char))))
  
! (defun isearch-process-search-string (string message)
    (setq isearch-string (concat isearch-string string)
        isearch-message (concat isearch-message message))
    (isearch-search-and-update))
--- 2244,2252 ----
         (char-to-string char)
       (isearch-text-char-description char))))
  
! (defun isearch-process-search-string (string message &optional no-quote)
!   (unless (or isearch-regexp no-quote)
!     (setq string (regexp-quote string)))
    (setq isearch-string (concat isearch-string string)
        isearch-message (concat isearch-message message))
    (isearch-search-and-update))
***************
*** 2443,2458 ****
             (funcall isearch-word string lax)
           (word-search-regexp string lax))
         bound noerror count))))
-    (isearch-regexp
-     (if isearch-forward 're-search-forward 're-search-backward))
     (t
!     (if isearch-forward 'isearch-search-forward 'isearch-search-backward))))
! 
! (defun isearch-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)
!   (re-search-backward (regexp-quote string) bound noerror count))
  
  (defun isearch-search-string (string bound noerror)
    "Search for the first occurrence of STRING or its translation.
--- 2450,2457 ----
             (funcall isearch-word string lax)
           (word-search-regexp string lax))
         bound noerror count))))
     (t
!     (if isearch-forward 're-search-forward 're-search-backward))))
  
  (defun isearch-search-string (string bound noerror)
    "Search for the first occurrence of STRING or its translation.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]