;;; isearch.el --- incremental search minor mode
-;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1999, 2000,
-;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001,
+;; 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
;; Free Software Foundation, Inc.
;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu>
:type 'boolean
:group 'isearch)
-(defcustom search-whitespace-regexp "\\s-+"
+(defcustom search-whitespace-regexp (purecopy "\\s-+")
"If non-nil, regular expression to match a sequence of whitespace chars.
This applies to regular expression incremental search.
When you put a space or spaces in the incremental regexp, it stands for
:group 'isearch
:group 'matching)
+(define-obsolete-variable-alias 'isearch-lazy-highlight-cleanup
+ 'lazy-highlight-cleanup
+ "22.1")
+
(defcustom lazy-highlight-cleanup t
"Controls whether to remove extra highlighting after a search.
If this is nil, extra highlighting can be \"manually\" removed with
\\[lazy-highlight-cleanup]."
:type 'boolean
:group 'lazy-highlight)
-(define-obsolete-variable-alias 'isearch-lazy-highlight-cleanup
- 'lazy-highlight-cleanup
+
+(define-obsolete-variable-alias 'isearch-lazy-highlight-initial-delay
+ 'lazy-highlight-initial-delay
"22.1")
(defcustom lazy-highlight-initial-delay 0.25
"Seconds to wait before beginning to lazily highlight all matches."
:type 'number
:group 'lazy-highlight)
-(define-obsolete-variable-alias 'isearch-lazy-highlight-initial-delay
- 'lazy-highlight-initial-delay
+
+(define-obsolete-variable-alias 'isearch-lazy-highlight-interval
+ 'lazy-highlight-interval
"22.1")
(defcustom lazy-highlight-interval 0 ; 0.0625
"Seconds between lazily highlighting successive matches."
:type 'number
:group 'lazy-highlight)
-(define-obsolete-variable-alias 'isearch-lazy-highlight-interval
- 'lazy-highlight-interval
+
+(define-obsolete-variable-alias 'isearch-lazy-highlight-max-at-a-time
+ 'lazy-highlight-max-at-a-time
"22.1")
(defcustom lazy-highlight-max-at-a-time 20
:type '(choice (const :tag "All" nil)
(integer :tag "Some"))
:group 'lazy-highlight)
-(define-obsolete-variable-alias 'isearch-lazy-highlight-max-at-a-time
- 'lazy-highlight-max-at-a-time
- "22.1")
(defface lazy-highlight
'((((class color) (min-colors 88) (background light))
"Face for lazy highlighting of matches other than the current one."
:group 'lazy-highlight
:group 'basic-faces)
-(put 'isearch-lazy-highlight-face 'face-alias 'lazy-highlight)
-(defvar lazy-highlight-face 'lazy-highlight)
+(define-obsolete-face-alias 'isearch-lazy-highlight-face 'lazy-highlight "22.1")
(define-obsolete-variable-alias 'isearch-lazy-highlight-face
'lazy-highlight-face
"22.1")
+(defvar lazy-highlight-face 'lazy-highlight)
\f
;; Define isearch help map.
(eval-when-compile (require 'help-macro))
(make-help-screen isearch-help-for-help-internal
- "Type a help option: [bkm] or ?"
+ (purecopy "Type a help option: [bkm] or ?")
"You have typed %THIS-KEY%, the help character. Type a Help option:
\(Type \\<help-map>\\[help-quit] to exit the Help command.)
(defvar isearch-just-started nil)
(defvar isearch-start-hscroll 0) ; hscroll when starting the search.
-; case-fold-search while searching.
-; either nil, t, or 'yes. 'yes means the same as t except that mixed
-; case in the search string is ignored.
+;; case-fold-search while searching.
+;; either nil, t, or 'yes. 'yes means the same as t except that mixed
+;; case in the search string is ignored.
(defvar isearch-case-fold-search nil)
(defvar isearch-last-case-fold-search nil)
(setq isearch-mode " Isearch") ;; forward? regexp?
(force-mode-line-update)
- (isearch-push-state)
-
(setq overriding-terminal-local-map isearch-mode-map)
(run-hooks 'isearch-mode-hook)
+
+ ;; Pushing the initial state used to be before running isearch-mode-hook,
+ ;; but a hook might set `isearch-push-state-function' used in
+ ;; `isearch-push-state' to save mode-specific initial state. (Bug#4994)
+ (isearch-push-state)
+
(isearch-update)
(add-hook 'mouse-leave-buffer-hook 'isearch-done)
(defun isearch-cancel ()
"Terminate the search and go back to the starting point."
(interactive)
- (if (functionp (isearch-pop-fun-state (car (last isearch-cmds))))
- (funcall (isearch-pop-fun-state (car (last isearch-cmds)))
- (car (last isearch-cmds))))
- (goto-char isearch-opoint)
+ (if (and isearch-push-state-function isearch-cmds)
+ ;; For defined push-state function, restore the first state.
+ ;; This calls pop-state function and restores original point.
+ (let ((isearch-cmds (last isearch-cmds)))
+ (isearch-top-state))
+ (goto-char isearch-opoint))
(isearch-done t) ; exit isearch
(isearch-clean-overlays)
(signal 'quit nil)) ; and pass on quit signal
(search-upper-case nil))
(occur regexp nlines)))
-(declare-function hi-lock-regexp-okay "hi-lock" (regexp))
(declare-function hi-lock-read-face-name "hi-lock" ())
(defun isearch-highlight-regexp ()
(interactive "p")
(if (eobp)
(insert
- (save-excursion
- (set-buffer (cadr (buffer-list)))
+ (with-current-buffer (cadr (buffer-list))
(buffer-substring-no-properties
(point) (progn (forward-char arg) (point)))))
(forward-char arg)))
(put 'digit-argument 'isearch-scroll t)
(defcustom isearch-allow-scroll nil
- "If non-nil, scrolling commands are allowed during incremental search."
+ "Whether scrolling is allowed during incremental search.
+If non-nil, scrolling commands can be used in Isearch mode.
+However, the current match will never scroll offscreen.
+If nil, scolling commands will first cancel Isearch mode."
:type 'boolean
:group 'isearch)
(windowp window)
(or (> (minibuffer-depth) 0)
(not (window-minibuffer-p window))))
- (save-excursion
- (set-buffer (window-buffer window))
+ (with-current-buffer (window-buffer window)
(isearch-done)
(isearch-clean-overlays))
(isearch-done)
(let* ((func (isearch-search-fun))
(pos1 (save-excursion (funcall func string bound noerror)))
pos2)
- (when (and (char-table-p translation-table-for-input)
- (multibyte-string-p string)
- ;; Minor optimization.
- (string-match-p "[^[:ascii:]]" string))
+ (when (and
+ ;; Avoid "obsolete" warnings for translation-table-for-input.
+ (with-no-warnings
+ (char-table-p translation-table-for-input))
+ (multibyte-string-p string)
+ ;; Minor optimization.
+ (string-match-p "[^[:ascii:]]" string))
(let ((translated
(apply 'string
(mapcar (lambda (c)
- (or (aref translation-table-for-input c) c))
+ (or
+ ;; Avoid "obsolete" warnings for
+ ;; translation-table-for-input.
+ (with-no-warnings
+ (aref translation-table-for-input c))
+ c))
string)))
match-data)
(when translated
(defun isearch-text-char-description (c)
(cond
- ((< c ?\s) (format "^%c" (+ c 64)))
- ((= c ?\^?) "^?")
+ ((< c ?\s) (propertize (format "^%c" (+ c 64)) 'face 'escape-glyph))
+ ((= c ?\^?) (propertize "^?" 'face 'escape-glyph))
(t (char-to-string c))))
;; General function to unread characters or events.
(defvar isearch-lazy-highlight-case-fold-search nil)
(defvar isearch-lazy-highlight-regexp nil)
(defvar isearch-lazy-highlight-space-regexp nil)
+(defvar isearch-lazy-highlight-forward nil)
(defun lazy-highlight-cleanup (&optional force)
"Stop lazy highlighting and remove extra highlighting from current buffer.
(not (= (window-start)
isearch-lazy-highlight-window-start))
(not (= (window-end) ; Window may have been split/joined.
- isearch-lazy-highlight-window-end))))
+ isearch-lazy-highlight-window-end))
+ (not (eq isearch-forward
+ isearch-lazy-highlight-forward))))
;; something important did indeed change
(lazy-highlight-cleanup t) ;kill old loop & remove overlays
(when (not isearch-error)
isearch-lazy-highlight-case-fold-search isearch-case-fold-search
isearch-lazy-highlight-regexp isearch-regexp
isearch-lazy-highlight-wrapped nil
- isearch-lazy-highlight-space-regexp search-whitespace-regexp)
+ isearch-lazy-highlight-space-regexp search-whitespace-regexp
+ isearch-lazy-highlight-forward isearch-forward)
(unless (equal isearch-string "")
(setq isearch-lazy-highlight-timer
(run-with-idle-timer lazy-highlight-initial-delay nil
(search-invisible nil) ; don't match invisible text
(retry t)
(success nil)
- (bound (if isearch-forward
+ (isearch-forward isearch-lazy-highlight-forward)
+ (bound (if isearch-lazy-highlight-forward
(min (or isearch-lazy-highlight-end-limit (point-max))
(if isearch-lazy-highlight-wrapped
isearch-lazy-highlight-start
(select-window isearch-lazy-highlight-window))
(save-excursion
(save-match-data
- (goto-char (if isearch-forward
+ (goto-char (if isearch-lazy-highlight-forward
isearch-lazy-highlight-end
isearch-lazy-highlight-start))
(while looping
(let ((mb (match-beginning 0))
(me (match-end 0)))
(if (= mb me) ;zero-length match
- (if isearch-forward
+ (if isearch-lazy-highlight-forward
(if (= mb (if isearch-lazy-highlight-wrapped
isearch-lazy-highlight-start
(window-end)))
(overlay-put ov 'priority 1000)
(overlay-put ov 'face lazy-highlight-face)
(overlay-put ov 'window (selected-window))))
- (if isearch-forward
+ (if isearch-lazy-highlight-forward
(setq isearch-lazy-highlight-end (point))
(setq isearch-lazy-highlight-start (point)))))
(setq looping nil
nomore t)
(setq isearch-lazy-highlight-wrapped t)
- (if isearch-forward
+ (if isearch-lazy-highlight-forward
(progn
(setq isearch-lazy-highlight-end (window-start))
(goto-char (max (or isearch-lazy-highlight-start-limit (point-min))