;;; isearch.el --- incremental search minor mode
-;; Copyright (C) 1992-1997, 1999-2013 Free Software Foundation, Inc.
+;; Copyright (C) 1992-1997, 1999-2014 Free Software Foundation, Inc.
;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu>
-;; Maintainer: FSF
+;; Maintainer: emacs-devel@gnu.org
;; Keywords: matching
;; Package: emacs
:version "24.3")
(defcustom search-invisible 'open
- "If t incremental search can match hidden text.
+ "If t incremental search/query-replace can match hidden text.
A nil value means don't match invisible text.
When the value is `open', if the text matched is made invisible by
an overlay having an `invisible' property and that overlay has a property
`isearch-open-invisible', then incremental search will show the contents.
\(This applies when using `outline.el' and `hideshow.el'.)
+
+To temporarily change the value for an active incremental search,
+use \\<isearch-mode-map>\\[isearch-toggle-invisible].
+
+See also the related option `isearch-hide-immediately'.
+
See also `reveal-mode' if you want overlays to automatically be opened
whenever point is in one of them."
:type '(choice (const :tag "Match hidden text" t)
(defcustom isearch-hide-immediately t
"If non-nil, re-hide an invisible match right away.
This variable makes a difference when `search-invisible' is set to `open'.
-It means that after search makes some invisible text visible
-to show the match, it makes the text invisible again when the match moves.
-Ordinarily the text becomes invisible again at the end of the search."
+If nil then do not re-hide opened invisible text when the match moves.
+Whatever the value, all opened invisible text is hidden again after exiting
+the search."
:type 'boolean
:group 'isearch)
to the search status stack.")
(defvar isearch-filter-predicate #'isearch-filter-visible
- "Predicate that filter the search hits that would normally be available.
+ "Predicate that filters the search hits that would normally be available.
Search hits that dissatisfy the predicate are skipped. The function
has two arguments: the positions of start and end of text matched by
the search. If this function returns nil, continue searching without
;; would be simpler to disable the global keymap, and/or have a
;; default local key binding for any key not otherwise bound.
(let ((meta-map (make-sparse-keymap)))
- (define-key map (char-to-string meta-prefix-char) meta-map)
- (define-key map [escape] meta-map))
+ (define-key map (char-to-string meta-prefix-char) meta-map))
;; Several non-printing chars change the searching behavior.
(define-key map "\C-s" 'isearch-repeat-forward)
(define-key map "\M-\C-s" 'isearch-repeat-forward)
(define-key map "\M-\C-r" 'isearch-repeat-backward)
(define-key map "\177" 'isearch-delete-char)
+ (define-key map [backspace] 'isearch-delete-char)
(define-key map "\C-g" 'isearch-abort)
;; This assumes \e is the meta-prefix-char.
(or (= ?\e meta-prefix-char)
(error "Inconsistency in isearch.el"))
(define-key map "\e\e\e" 'isearch-cancel)
- (define-key map [escape escape escape] 'isearch-cancel)
(define-key map "\C-q" 'isearch-quote-char)
(define-key map "\r" 'isearch-exit)
+ (define-key map [return] 'isearch-exit)
(define-key map "\C-j" 'isearch-printing-char)
(define-key map "\t" 'isearch-printing-char)
(define-key map [?\S-\ ] 'isearch-printing-char)
(define-key map "\M-r" 'isearch-toggle-regexp)
(define-key map "\M-e" 'isearch-edit-string)
+ (put 'isearch-toggle-case-fold :advertised-binding "\M-sc")
+ (put 'isearch-toggle-regexp :advertised-binding "\M-sr")
+ (put 'isearch-edit-string :advertised-binding "\M-se")
+
+ (define-key map "\M-se" 'isearch-edit-string)
(define-key map "\M-sc" 'isearch-toggle-case-fold)
(define-key map "\M-si" 'isearch-toggle-invisible)
(define-key map "\M-sr" 'isearch-toggle-regexp)
variable by the command `isearch-toggle-lax-whitespace'.")
(defvar isearch-cmds nil
- "Stack of search status sets.
-Each set is a vector of the form:
+ "Stack of search status elements.
+Each element is an `isearch--state' struct where the slots are
[STRING MESSAGE POINT SUCCESS FORWARD OTHER-END WORD
INVALID-REGEXP WRAPPED BARRIER WITHIN-BRACKETS CASE-FOLD-SEARCH]")
(isearch-done)
(isearch-clean-overlays))
-(defvar minibuffer-history-symbol) ;; from external package gmhist.el
-
(defun isearch-fail-pos (&optional msg)
"Return position of first mismatch in search string, or nil if none.
If MSG is non-nil, use variable `isearch-message', otherwise `isearch-string'."
(isearch-abort) ;; outside of let to restore outside global values
)))
+(defvar minibuffer-history-symbol) ;; from external package gmhist.el
+
(defun isearch-edit-string ()
"Edit the search string in the minibuffer.
The following additional command keys are active while editing.
(re-search-backward regexp bound noerror count)))
\f
-(defun isearch-query-replace (&optional delimited regexp-flag)
+(defun isearch-query-replace (&optional arg regexp-flag)
"Start `query-replace' with string to replace from last search string.
-The arg DELIMITED (prefix arg if interactive), if non-nil, means replace
-only matches surrounded by word boundaries. Note that using the prefix arg
+The ARG (prefix arg if interactive), if non-nil, means replace
+only matches surrounded by word boundaries. A negative prefix
+arg means replace backward. Note that using the prefix arg
is possible only when `isearch-allow-scroll' is non-nil or
`isearch-allow-prefix' is non-nil, and it doesn't always provide the
correct matches for `query-replace', so the preferred way to run word
isearch-lax-whitespace)
(replace-regexp-lax-whitespace
isearch-regexp-lax-whitespace)
+ (delimited (and arg (not (eq arg '-))))
+ (backward (and arg (eq arg '-)))
;; Set `isearch-recursive-edit' to nil to prevent calling
;; `exit-recursive-edit' in `isearch-done' that terminates
;; the execution of this command when it is non-nil.
(isearch-done nil t)
(isearch-clean-overlays)
(if (and isearch-other-end
- (< isearch-other-end (point))
+ (if backward
+ (> isearch-other-end (point))
+ (< isearch-other-end (point)))
(not (and transient-mark-mode mark-active
- (< (mark) (point)))))
+ (if backward
+ (> (mark) (point))
+ (< (mark) (point))))))
(goto-char isearch-other-end))
(set query-replace-from-history-variable
(cons isearch-string
" word"))
"")
(if isearch-regexp " regexp" "")
+ (if backward " backward" "")
(if (and transient-mark-mode mark-active) " in region" ""))
isearch-regexp)
t isearch-regexp (or delimited isearch-word) nil nil
(if (and transient-mark-mode mark-active) (region-beginning))
- (if (and transient-mark-mode mark-active) (region-end))))
+ (if (and transient-mark-mode mark-active) (region-end))
+ backward))
(and isearch-recursive-edit (exit-recursive-edit)))
-(defun isearch-query-replace-regexp (&optional delimited)
+(defun isearch-query-replace-regexp (&optional arg)
"Start `query-replace-regexp' with string to replace from last search string.
See `isearch-query-replace' for more information."
(interactive
(list current-prefix-arg))
- (isearch-query-replace delimited t))
+ (isearch-query-replace arg t))
(defun isearch-occur (regexp &optional nlines)
"Run `occur' using the last search string as the regexp.
(forward-char arg)))
(defun isearch-yank-char (&optional arg)
- "Pull next character from buffer into search string."
+ "Pull next character from buffer into search string.
+If optional ARG is non-nil, pull in the next ARG characters."
(interactive "p")
(isearch-yank-internal (lambda () (forward-char arg) (point))))
(forward-char 1)) (point))))
(defun isearch-yank-word (&optional arg)
- "Pull next word from buffer into search string."
+ "Pull next word from buffer into search string.
+If optional ARG is non-nil, pull in the next ARG words."
(interactive "p")
(isearch-yank-internal (lambda () (forward-word arg) (point))))
(defun isearch-yank-line (&optional arg)
- "Pull rest of line from buffer into search string."
+ "Pull rest of line from buffer into search string.
+If optional ARG is non-nil, yank the next ARG lines."
(interactive "p")
(isearch-yank-internal
(lambda () (let ((inhibit-field-text-motion t))
(main-event (aref key 0)))
(cond
;; Don't exit Isearch if we're in the middle of some
- ;; set-temporary-overlay-map thingy like universal-argument--mode.
+ ;; `set-transient-map' thingy like `universal-argument--mode'.
((not (eq overriding-terminal-local-map isearch--saved-overriding-local-map)))
;; Don't exit Isearch for isearch key bindings.
((commandp (lookup-key isearch-mode-map key nil)))
(memq this-command '(universal-argument
digit-argument negative-argument)))
(and isearch-allow-scroll
+ (symbolp this-command)
(or (eq (get this-command 'isearch-scroll) t)
(eq (get this-command 'scroll-command) t))))
(when isearch-allow-scroll
With argument, add COUNT copies of the character."
(interactive "p")
(let ((char (read-quoted-char (isearch-message t))))
+ (unless (characterp char)
+ (user-error "%s is not a valid character"
+ (key-description (vector char))))
;; Assume character codes 0200 - 0377 stand for characters in some
;; single-byte character set, and convert them to Emacs
;; characters.