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'.
This commit is contained in:
parent
d2eea5b594
commit
7277997612
2 changed files with 30 additions and 29 deletions
|
@ -1,3 +1,11 @@
|
|||
2011-09-14 Juri Linkov <juri@jurta.org>
|
||||
|
||||
* 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 <cyd@stupidchicken.com>
|
||||
|
||||
* replace.el (occur-mode-goto-occurrence): Don't force using other
|
||||
|
|
|
@ -1063,21 +1063,24 @@ nonincremental search instead via `isearch-edit-string'."
|
|||
|
||||
(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 @@ The following additional command keys are active while editing.
|
|||
(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 @@ If there is no completion possible, say so and continue searching."
|
|||
;; 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)
|
||||
|
|
Loading…
Add table
Reference in a new issue