emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r105768: Share code between `isearch-


From: Juri Linkov
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r105768: Share code between `isearch-message' and `isearch-string' in `isearch-fail-pos'.
Date: Wed, 14 Sep 2011 19:07:42 +0300
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 105768
committer: Juri Linkov <address@hidden>
branch nick: trunk
timestamp: Wed 2011-09-14 19:07:42 +0300
message:
  Share code between `isearch-message' and `isearch-string' in 
`isearch-fail-pos'.
  http://lists.gnu.org/archive/html/emacs-devel/2011-09/msg00169.html
  
  * lisp/isearch.el (isearch-fail-pos): Add new arg `msg'.  Doc fix.
  (isearch-edit-string): Use length of `isearch-string' when
  `isearch-fail-pos' returns nil.
  (isearch-message): Remove duplicate code and call
  `isearch-fail-pos' with arg `t'.
modified:
  lisp/ChangeLog
  lisp/isearch.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-09-14 15:14:34 +0000
+++ b/lisp/ChangeLog    2011-09-14 16:07:42 +0000
@@ -1,3 +1,11 @@
+2011-09-14  Juri Linkov  <address@hidden>
+
+       * isearch.el (isearch-fail-pos): Add new arg `msg'.  Doc fix.
+       (isearch-edit-string): Use length of `isearch-string' when
+       `isearch-fail-pos' returns nil.
+       (isearch-message): Remove duplicate code and call
+       `isearch-fail-pos' with arg `t'.
+
 2011-09-14  Chong Yidong  <address@hidden>
 
        * replace.el (occur-mode-goto-occurrence): Don't force using other

=== modified file 'lisp/isearch.el'
--- a/lisp/isearch.el   2011-09-10 11:33:38 +0000
+++ b/lisp/isearch.el   2011-09-14 16:07:42 +0000
@@ -1063,21 +1063,24 @@
 
 (defvar minibuffer-history-symbol) ;; from external package gmhist.el
 
-(defun isearch-fail-pos ()
-  "Position of first mismatch in search string, or its length if none."
-  (let ((cmds isearch-cmds))
-    (if (and isearch-success (not isearch-error))
-        (length isearch-message)
+(defun isearch-fail-pos (&optional msg)
+  "Return position of first mismatch in search string, or nil if none.
+If MSG is non-nil, use `isearch-message', otherwise `isearch-string'."
+  (let ((cmds isearch-cmds)
+       (curr-msg (if msg isearch-message isearch-string))
+       succ-msg)
+    (when (or (not isearch-success) isearch-error)
       (while (or (not (isearch-success-state (car cmds)))
                  (isearch-error-state (car cmds)))
         (pop cmds))
-      (let ((succ-msg (and cmds (isearch-message-state (car cmds)))))
-        (if (and (stringp succ-msg)
-                 (< (length succ-msg) (length isearch-message))
-                 (equal succ-msg
-                        (substring isearch-message 0 (length succ-msg))))
-            (length succ-msg)
-          0)))))
+      (setq succ-msg (and cmds (if msg (isearch-message-state (car cmds))
+                                (isearch-string-state (car cmds)))))
+      (if (and (stringp succ-msg)
+              (< (length succ-msg) (length curr-msg))
+              (equal succ-msg
+                     (substring curr-msg 0 (length succ-msg))))
+         (length succ-msg)
+       0))))
 
 (defun isearch-edit-string ()
   "Edit the search string in the minibuffer.
@@ -1169,7 +1172,8 @@
                (setq isearch-new-string
                       (read-from-minibuffer
                        (isearch-message-prefix nil nil isearch-nonincremental)
-                      (cons isearch-string (1+ (isearch-fail-pos)))
+                      (cons isearch-string (1+ (or (isearch-fail-pos)
+                                                   (length isearch-string))))
                        minibuffer-local-isearch-map nil
                        (if isearch-regexp
                           (cons 'regexp-search-ring
@@ -2174,22 +2178,11 @@
   ;; 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))
-      (add-text-properties
-       (if (and (stringp succ-msg)
-               (< (length succ-msg) (length m))
-               (equal succ-msg (substring m 0 (length succ-msg))))
-          (length succ-msg)
-        0)
-       (length m) '(face isearch-fail) m)
+       (fail-pos (isearch-fail-pos t)))
+    ;; Highlight failed part
+    (when fail-pos
+      (setq m (copy-sequence m))
+      (add-text-properties fail-pos (length m) '(face isearch-fail) m)
       ;; Highlight failed trailing whitespace
       (when (string-match " +$" m)
        (add-text-properties (match-beginning 0) (match-end 0)


reply via email to

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