aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2011-09-14 19:07:42 +0300
committerJuri Linkov2011-09-14 19:07:42 +0300
commit727799761264b1fc990ea19b2aed1aab3a14df11 (patch)
tree6041399af920d7ad247a8fe2047ab5deb24a01d4
parentd2eea5b594ddfb4f5d99c1dcf710d279ae923a2c (diff)
downloademacs-727799761264b1fc990ea19b2aed1aab3a14df11.tar.gz
emacs-727799761264b1fc990ea19b2aed1aab3a14df11.zip
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'.
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/isearch.el51
2 files changed, 30 insertions, 29 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 1ea29f1e65d..1a70c0c3f07 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12011-09-14 Juri Linkov <juri@jurta.org>
2
3 * isearch.el (isearch-fail-pos): Add new arg `msg'. Doc fix.
4 (isearch-edit-string): Use length of `isearch-string' when
5 `isearch-fail-pos' returns nil.
6 (isearch-message): Remove duplicate code and call
7 `isearch-fail-pos' with arg `t'.
8
12011-09-14 Chong Yidong <cyd@stupidchicken.com> 92011-09-14 Chong Yidong <cyd@stupidchicken.com>
2 10
3 * replace.el (occur-mode-goto-occurrence): Don't force using other 11 * replace.el (occur-mode-goto-occurrence): Don't force using other
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 00ed9b4aed2..e07f1429119 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -1063,21 +1063,24 @@ nonincremental search instead via `isearch-edit-string'."
1063 1063
1064(defvar minibuffer-history-symbol) ;; from external package gmhist.el 1064(defvar minibuffer-history-symbol) ;; from external package gmhist.el
1065 1065
1066(defun isearch-fail-pos () 1066(defun isearch-fail-pos (&optional msg)
1067 "Position of first mismatch in search string, or its length if none." 1067 "Return position of first mismatch in search string, or nil if none.
1068 (let ((cmds isearch-cmds)) 1068If MSG is non-nil, use `isearch-message', otherwise `isearch-string'."
1069 (if (and isearch-success (not isearch-error)) 1069 (let ((cmds isearch-cmds)
1070 (length isearch-message) 1070 (curr-msg (if msg isearch-message isearch-string))
1071 succ-msg)
1072 (when (or (not isearch-success) isearch-error)
1071 (while (or (not (isearch-success-state (car cmds))) 1073 (while (or (not (isearch-success-state (car cmds)))
1072 (isearch-error-state (car cmds))) 1074 (isearch-error-state (car cmds)))
1073 (pop cmds)) 1075 (pop cmds))
1074 (let ((succ-msg (and cmds (isearch-message-state (car cmds))))) 1076 (setq succ-msg (and cmds (if msg (isearch-message-state (car cmds))
1075 (if (and (stringp succ-msg) 1077 (isearch-string-state (car cmds)))))
1076 (< (length succ-msg) (length isearch-message)) 1078 (if (and (stringp succ-msg)
1077 (equal succ-msg 1079 (< (length succ-msg) (length curr-msg))
1078 (substring isearch-message 0 (length succ-msg)))) 1080 (equal succ-msg
1079 (length succ-msg) 1081 (substring curr-msg 0 (length succ-msg))))
1080 0))))) 1082 (length succ-msg)
1083 0))))
1081 1084
1082(defun isearch-edit-string () 1085(defun isearch-edit-string ()
1083 "Edit the search string in the minibuffer. 1086 "Edit the search string in the minibuffer.
@@ -1169,7 +1172,8 @@ The following additional command keys are active while editing.
1169 (setq isearch-new-string 1172 (setq isearch-new-string
1170 (read-from-minibuffer 1173 (read-from-minibuffer
1171 (isearch-message-prefix nil nil isearch-nonincremental) 1174 (isearch-message-prefix nil nil isearch-nonincremental)
1172 (cons isearch-string (1+ (isearch-fail-pos))) 1175 (cons isearch-string (1+ (or (isearch-fail-pos)
1176 (length isearch-string))))
1173 minibuffer-local-isearch-map nil 1177 minibuffer-local-isearch-map nil
1174 (if isearch-regexp 1178 (if isearch-regexp
1175 (cons 'regexp-search-ring 1179 (cons 'regexp-search-ring
@@ -2174,22 +2178,11 @@ If there is no completion possible, say so and continue searching."
2174 ;; Generate and print the message string. 2178 ;; Generate and print the message string.
2175 (let ((cursor-in-echo-area ellipsis) 2179 (let ((cursor-in-echo-area ellipsis)
2176 (m isearch-message) 2180 (m isearch-message)
2177 (cmds isearch-cmds) 2181 (fail-pos (isearch-fail-pos t)))
2178 succ-msg) 2182 ;; Highlight failed part
2179 (when (or (not isearch-success) isearch-error) 2183 (when fail-pos
2180 ;; Highlight failed part 2184 (setq m (copy-sequence m))
2181 (while (or (not (isearch-success-state (car cmds))) 2185 (add-text-properties fail-pos (length m) '(face isearch-fail) m)
2182 (isearch-error-state (car cmds)))
2183 (pop cmds))
2184 (setq succ-msg (and cmds (isearch-message-state (car cmds)))
2185 m (copy-sequence m))
2186 (add-text-properties
2187 (if (and (stringp succ-msg)
2188 (< (length succ-msg) (length m))
2189 (equal succ-msg (substring m 0 (length succ-msg))))
2190 (length succ-msg)
2191 0)
2192 (length m) '(face isearch-fail) m)
2193 ;; Highlight failed trailing whitespace 2186 ;; Highlight failed trailing whitespace
2194 (when (string-match " +$" m) 2187 (when (string-match " +$" m)
2195 (add-text-properties (match-beginning 0) (match-end 0) 2188 (add-text-properties (match-beginning 0) (match-end 0)