(defvar isearch-error nil) ; Error message for failed search.
(defvar isearch-other-end nil) ; Start (end) of match if forward (backward).
(defvar isearch-wrapped nil) ; Searching restarted from the top (bottom).
-(defvar isearch-barrier 0)
+(defvar isearch-barrier 0
+ "Recorded minimum/maximal point for the current search.")
(defvar isearch-just-started nil)
(defvar isearch-start-hscroll 0) ; hscroll when starting the search.
(or (and transient-mark-mode mark-active)
(progn
(push-mark isearch-opoint t)
- (or executing-kbd-macro (> (minibuffer-depth) 0)
+ (or executing-kbd-macro (> (minibuffer-depth) 0) edit
(message "Mark saved where search started")))))
(and (not edit) isearch-recursive-edit (exit-recursive-edit)))
(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)
+ (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)))))
+
(defun isearch-edit-string ()
"Edit the search string in the minibuffer.
The following additional command keys are active while editing.
;; Save current configuration so we can restore it here.
(isearch-window-configuration (current-window-configuration))
+ ;; This could protect the index of the search rings,
+ ;; but we can't reliably count the number of typed M-p
+ ;; in `read-from-minibuffer' to adjust the index accordingly.
+ ;; So when the following is commented out, `isearch-mode'
+ ;; below resets the index to the predictable value nil.
+ ;; (search-ring-yank-pointer search-ring-yank-pointer)
+ ;; (regexp-search-ring-yank-pointer regexp-search-ring-yank-pointer)
+
;; Temporarily restore `minibuffer-message-timeout'.
(minibuffer-message-timeout
isearch-original-minibuffer-message-timeout)
(unwind-protect
(let* ((message-log-max nil)
+ ;; Protect global value of search rings from updating
+ ;; by `read-from-minibuffer'. It should be updated only
+ ;; by `isearch-update-ring' in `isearch-done', not here.
+ (search-ring search-ring)
+ (regexp-search-ring regexp-search-ring)
;; Binding minibuffer-history-symbol to nil is a work-around
;; for some incompatibility with gmhist.
(minibuffer-history-symbol))
(setq isearch-new-string
(read-from-minibuffer
(isearch-message-prefix nil nil isearch-nonincremental)
- isearch-string
+ (cons isearch-string (1+ (isearch-fail-pos)))
minibuffer-local-isearch-map nil
(if isearch-regexp
(cons 'regexp-search-ring
isearch-word isearch-new-word))
;; Empty isearch-string means use default.
- (if (= 0 (length isearch-string))
- (setq isearch-string (or (car (if isearch-regexp
- regexp-search-ring
- search-ring))
- "")
-
- isearch-message
- (mapconcat 'isearch-text-char-description
- isearch-string ""))
- ;; This used to set the last search string,
- ;; but I think it is not right to do that here.
- ;; Only the string actually used should be saved.
- ))
+ (when (= 0 (length isearch-string))
+ (setq isearch-string (or (car (if isearch-regexp
+ regexp-search-ring
+ search-ring))
+ "")
+
+ isearch-message
+ (mapconcat 'isearch-text-char-description
+ isearch-string ""))
+ ;; After taking the last element, adjust ring to previous one.
+ (isearch-ring-adjust1 nil)))
;; This used to push the state as of before this C-s, but it adds
;; an inconsistent state where part of variables are from the
isearch-message
(mapconcat 'isearch-text-char-description
isearch-string "")
- isearch-case-fold-search isearch-last-case-fold-search))
+ isearch-case-fold-search isearch-last-case-fold-search)
+ ;; After taking the last element, adjust ring to previous one.
+ (isearch-ring-adjust1 nil))
;; If already have what to search for, repeat it.
(or isearch-success
(progn
(t (regexp-quote isearch-string)))
(if current-prefix-arg (prefix-numeric-value current-prefix-arg))))
(let ((case-fold-search isearch-case-fold-search)
- ;; set `search-upper-case' to nil to not call
- ;; `isearch-no-upper-case-p' in `occur-1'
- (search-upper-case nil))
+ ;; Set `search-upper-case' to nil to not call
+ ;; `isearch-no-upper-case-p' in `occur-1'.
+ (search-upper-case nil)
+ (search-spaces-regexp search-whitespace-regexp))
(occur regexp nlines)))
(declare-function hi-lock-read-face-name "hi-lock" ())
()
(set yank-pointer-name
(setq yank-pointer
- (mod (+ (or yank-pointer 0)
+ (mod (+ (or yank-pointer (if advance 0 -1))
(if advance -1 1))
length)))
(setq isearch-string (nth yank-pointer ring)
;; Searching
(defvar isearch-search-fun-function nil
- "Override `isearch-search-fun'.
-This function should return the search function for Isearch to use.
-It will call this function with three arguments
-as if it were `search-forward'.")
+ "Overrides the default `isearch-search-fun' behaviour.
+This variable's value should be a function, which will be called
+with no arguments, and should return a function that takes three
+arguments: STRING, BOUND, and NOERROR.
+
+This returned function will be used by `isearch-search-string' to
+search for the first occurrence of STRING or its translation.")
(defun isearch-search-fun ()
"Return the function to use for the search.
;; If the following character is currently invisible,
;; skip all characters with that same `invisible' property value.
;; Do that over and over.
- (while (and (< (point) end)
- (let ((prop
- (get-char-property (point) 'invisible)))
- (if (eq buffer-invisibility-spec t)
- prop
- (or (memq prop buffer-invisibility-spec)
- (assq prop buffer-invisibility-spec)))))
- (if (get-text-property (point) 'invisible)
+ (while (and (< (point) end) (invisible-p (point)))
+ (if (invisible-p (get-text-property (point) 'invisible))
(progn
(goto-char (next-single-property-change (point) 'invisible
nil end))
(while overlays
(setq o (car overlays)
invis-prop (overlay-get o 'invisible))
- (if (if (eq buffer-invisibility-spec t)
- invis-prop
- (or (memq invis-prop buffer-invisibility-spec)
- (assq invis-prop buffer-invisibility-spec)))
+ (if (invisible-p invis-prop)
(if (overlay-get o 'isearch-open-invisible)
(setq ov-list (cons o ov-list))
;; We found one overlay that cannot be