Function: isearch-mode

isearch-mode is a byte-compiled function defined in isearch.el.gz.

Signature

(isearch-mode FORWARD &optional REGEXP OP-FUN RECURSIVE-EDIT REGEXP-FUNCTION)

Documentation

Start Isearch minor mode.

It is called by the function isearch-forward(var)/isearch-forward(fun) and other related functions.

The non-nil arg FORWARD means searching in the forward direction.

The non-nil arg REGEXP does an incremental regular expression search.

The arg OP-FUN is a function to be called after each input character is processed. (It is not called after characters that exit the search.)

When the arg RECURSIVE-EDIT is non-nil, this function behaves modally and does not return to the calling function until the search is completed. To behave this way it enters a recursive edit and exits it when done isearching.

The arg REGEXP-FUNCTION, if non-nil, should be a function. It is used to set the value of isearch-regexp-function.

Source Code

;; Defined in /usr/src/emacs/lisp/isearch.el.gz
;; isearch-mode only sets up incremental search for the minor mode.
;; All the work is done by the isearch-mode commands.

;; Not used yet:
;;(defvar isearch-commands '(isearch-forward isearch-backward
;;			     isearch-forward-regexp isearch-backward-regexp)
;;  "List of commands for which isearch-mode does not recursive-edit.")

(defun isearch-mode (forward &optional regexp op-fun recursive-edit regexp-function)
  "Start Isearch minor mode.
It is called by the function `isearch-forward' and other related functions.

The non-nil arg FORWARD means searching in the forward direction.

The non-nil arg REGEXP does an incremental regular expression search.

The arg OP-FUN is a function to be called after each input character
is processed.  (It is not called after characters that exit the search.)

When the arg RECURSIVE-EDIT is non-nil, this function behaves modally and
does not return to the calling function until the search is completed.
To behave this way it enters a recursive edit and exits it when done
isearching.

The arg REGEXP-FUNCTION, if non-nil, should be a function.  It is
used to set the value of `isearch-regexp-function'."

  ;; Initialize global vars.
  (setq isearch-forward forward
	isearch-regexp (or regexp
                           (and (not regexp-function)
                                (eq search-default-mode t)))
	isearch-regexp-function (or regexp-function
                                    (and (functionp search-default-mode)
                                         (not regexp)
                                         search-default-mode))
	isearch-op-fun op-fun
	isearch-last-case-fold-search isearch-case-fold-search
	isearch-case-fold-search case-fold-search
	isearch-invisible search-invisible
	isearch-string ""
	isearch-message ""
	isearch-cmds nil
	isearch-success t
	isearch-wrapped nil
	isearch-barrier (point)
	isearch-adjusted nil
	isearch-yank-flag nil
	isearch-error nil
	isearch-slow-terminal-mode (and (<= baud-rate search-slow-speed)
					(> (window-height)
					   (* 4
					      (abs search-slow-window-lines))))
	isearch-other-end nil
	isearch-small-window nil
	isearch-just-started t
	isearch-start-hscroll (window-hscroll)
	isearch-match-data nil

	isearch-opoint (point)
	search-ring-yank-pointer nil
	isearch-opened-overlays nil
	isearch-input-method-function input-method-function
	regexp-search-ring-yank-pointer nil

	isearch-pre-scroll-point nil
	isearch-pre-move-point nil

	isearch-lazy-count-current nil
	isearch-lazy-count-total nil

	;; Save the original value of `minibuffer-message-timeout', and
	;; set it to nil so that isearch's messages don't get timed out.
	isearch-original-minibuffer-message-timeout minibuffer-message-timeout
	minibuffer-message-timeout nil)

  (if (local-variable-p 'tool-bar-map)
      (setq isearch-tool-bar-old-map tool-bar-map))
  (setq-local tool-bar-map isearch-tool-bar-map)

  ;; We must bypass input method while reading key.  When a user type
  ;; printable character, appropriate input method is turned on in
  ;; minibuffer to read multibyte characters.
  (setq-local input-method-function nil)

  (looking-at "")
  (setq isearch-window-configuration
	(if isearch-slow-terminal-mode (current-window-configuration) nil))

  ;; Maybe make minibuffer frame visible and/or raise it.
  (let ((frame (window-frame (minibuffer-window))))
    (unless (memq (frame-live-p frame) '(nil t))
      (unless (frame-visible-p frame)
	(make-frame-visible frame))
      (if minibuffer-auto-raise
	  (raise-frame frame))))

  (setq	isearch-mode " Isearch")  ;; forward? regexp?
  (force-mode-line-update)

  (setq overriding-terminal-local-map isearch-mode-map)
  (run-hooks 'isearch-mode-hook)
  ;; Remember the initial map possibly modified
  ;; by external packages in isearch-mode-hook.  (Bug#16035)
  (setq isearch--saved-overriding-local-map overriding-terminal-local-map)

  ;; 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 'pre-command-hook 'isearch-pre-command-hook)
  (add-hook 'post-command-hook 'isearch-post-command-hook)
  (add-hook 'mouse-leave-buffer-hook 'isearch-mouse-leave-buffer)
  (add-hook 'kbd-macro-termination-hook 'isearch-done)

  ;; isearch-mode can be made modal (in the sense of not returning to
  ;; the calling function until searching is completed) by entering
  ;; a recursive-edit and exiting it when done isearching.
  (if recursive-edit
      (let ((isearch-recursive-edit t))
	(recursive-edit)))
  isearch-success)