emacs-devel
[Top][All Lists]
Advanced

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

Re: highlight failed part of isearch input


From: Juri Linkov
Subject: Re: highlight failed part of isearch input
Date: Sun, 24 Feb 2008 19:29:19 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

>> There is one regression after installing this patch: `C-s M-p' now
>> doesn't put the previous search string from the search ring to the
>> isearch minibuffer.
>
> The patch below fixes this problem.  When the first message from the
> isearch-cmds stack is not the same as isearch-message (this happens when
> isearch-edit-string sets a different value) then it uses this value
> for succ-msg.

I discovered another problem that requires a different fix.

`C-s foo M-r' (in a buffer without this text) completely discards the
failed part and doesn't display it.

The best fix for this and related problems is to always keep the
original isearch-message intact, and just to add text properties to it.

The patch below also fixed another problem.  `C-M-s [a-z]' (typed
in the empty buffer) highlights as failed part only the closing bracket.
This patch uses `isearch-error' to highlight the whole `[a-z]' part:

Index: lisp/isearch.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/isearch.el,v
retrieving revision 1.310
diff -c -r1.310 isearch.el
*** lisp/isearch.el     12 Feb 2008 00:50:44 -0000      1.310
--- lisp/isearch.el     24 Feb 2008 17:28:43 -0000
***************
*** 1959,1980 ****
  (defun isearch-message (&optional c-q-hack ellipsis)
    ;; Generate and print the message string.
    (let ((cursor-in-echo-area ellipsis)
!           (cmds isearch-cmds)
!           succ-msg m)
!       (while (not (isearch-success-state (car cmds))) (pop cmds))
!       (setq succ-msg (and cmds (isearch-message-state (car cmds))))
!       (setq m (concat
!           (isearch-message-prefix c-q-hack ellipsis isearch-nonincremental)
!                succ-msg
!                (and (not isearch-success)
!                     (string-match (regexp-quote succ-msg) isearch-message)
!                     (not (string= succ-msg isearch-message))
!                     (propertize (substring isearch-message (match-end 0))
!                                 'face 'isearch-fail))))
!       (when (and (not isearch-success) (string-match " +$" m))
!         (put-text-property (match-beginning 0) (length m) 'face 
'trailing-whitespace m))
!       (setq m (concat m (isearch-message-suffix c-q-hack ellipsis)))
!       (if c-q-hack m (let ((message-log-max nil)) (message "%s" m)))))
  
  (defun isearch-message-prefix (&optional c-q-hack ellipsis nonincremental)
    ;; If about to search, and previous search regexp was invalid,
--- 1979,2006 ----
  (defun isearch-message (&optional c-q-hack ellipsis)
    ;; Generate and print the message string.
    (let ((cursor-in-echo-area ellipsis)
!       (m isearch-message)
!       (cmds isearch-cmds)
!       succ-msg)
!     (when (or (not isearch-success) isearch-error)
!       ;; Highlight failed part
!       (while (or (not (isearch-success-state (car cmds)))
!                (isearch-error-state (car cmds)))
!       (pop cmds))
!       (setq succ-msg (and cmds (isearch-message-state (car cmds)))
!           m (copy-sequence m))
!       (when (and (stringp succ-msg) (< (length succ-msg) (length m)))
!       (add-text-properties (length succ-msg) (length m)
!                            '(face isearch-fail) m))
!       ;; Highlight failed trailing whitespace
!       (when (string-match " +$" m)
!       (add-text-properties (match-beginning 0) (match-end 0)
!                            '(face trailing-whitespace) m)))
!     (setq m (concat
!            (isearch-message-prefix c-q-hack ellipsis isearch-nonincremental)
!            m
!            (isearch-message-suffix c-q-hack ellipsis)))
!     (if c-q-hack m (let ((message-log-max nil)) (message "%s" m)))))
  
  (defun isearch-message-prefix (&optional c-q-hack ellipsis nonincremental)
    ;; If about to search, and previous search regexp was invalid,

-- 
Juri Linkov
http://www.jurta.org/emacs/




reply via email to

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