Function: isearch-pre-command-hook

isearch-pre-command-hook is a byte-compiled function defined in isearch.el.gz.

Signature

(isearch-pre-command-hook)

Documentation

Decide whether to exit Isearch mode before executing the command.

Don't exit Isearch if the key sequence that invoked this command is bound in isearch-mode-map, or if the invoked command is a prefix argument command (when isearch-allow-prefix is non-nil), or it is a scrolling command (when isearch-allow-scroll is non-nil). Otherwise, exit Isearch (when search-exit-option is t) before the command is executed globally with terminated Isearch. See more for options in search-exit-option.

Source Code

;; Defined in /usr/src/emacs/lisp/isearch.el.gz
(defun isearch-pre-command-hook ()
  "Decide whether to exit Isearch mode before executing the command.
Don't exit Isearch if the key sequence that invoked this command
is bound in `isearch-mode-map', or if the invoked command is
a prefix argument command (when `isearch-allow-prefix' is non-nil),
or it is a scrolling command (when `isearch-allow-scroll' is non-nil).
Otherwise, exit Isearch (when `search-exit-option' is t)
before the command is executed globally with terminated Isearch.
See more for options in `search-exit-option'."
  (let* ((key (this-single-command-keys))
	 (main-event (aref key 0)))
    (cond
     ;; Don't exit Isearch if we're in the middle of some
     ;; `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.
     ((or (commandp (lookup-key isearch-mode-map key nil))
          (commandp
           (lookup-key
            `(keymap (tool-bar menu-item nil ,isearch-tool-bar-map)) key))))
     ;; Allow key bindings that open a menubar.
     ((memq this-command isearch-menu-bar-commands))
     ;; Optionally edit the search string instead of exiting.
     ((eq search-exit-option 'edit)
      (setq this-command 'isearch-edit-string))
     ;; Handle motion command functions.
     ((and isearch-allow-motion
           (symbolp this-command)
           (get this-command 'isearch-motion)
           ;; Don't override `isearch-yank-on-move' used below.
           (not (and (eq isearch-yank-on-move 'shift)
                     this-command-keys-shift-translated)))
      (let* ((property (get this-command 'isearch-motion))
             (function (car property))
             (current-direction (if isearch-forward 'forward 'backward))
             (direction (or (cdr property)
                            (if isearch-forward 'forward 'backward))))
        (funcall function)
        (setq isearch-just-started t)
        (let ((isearch-repeat-on-direction-change nil))
          (isearch-repeat direction))
        (when (and isearch-success (not isearch-motion-changes-direction))
          (unless (eq direction current-direction)
            (let ((isearch-repeat-on-direction-change nil))
              (isearch-repeat current-direction))))
        (setq this-command 'ignore)))
     ;; Handle a scrolling function or prefix argument.
     ((or (and isearch-allow-prefix
               (memq this-command '(universal-argument universal-argument-more
				    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
	(unless (eq isearch-allow-scroll 'unlimited)
          (setq isearch-pre-scroll-point (point)))))
     ;; A mouse click on the isearch message starts editing the search string.
     ((and (eq (car-safe main-event) 'down-mouse-1)
	   (window-minibuffer-p (posn-window (event-start main-event))))
      ;; Swallow the up-event.
      (read--potential-mouse-event)
      (setq this-command 'isearch-edit-string))
     ;; Don't terminate the search for motion commands.
     ((and isearch-yank-on-move
           (symbolp this-command)
           (not (eq (get this-command 'isearch-move) 'disabled))
           (or (eq (get this-command 'isearch-move) 'enabled)
               (and (eq isearch-yank-on-move t)
                    (stringp (nth 1 (interactive-form this-command)))
                    (string-match-p "^\\^"
				    (nth 1 (interactive-form this-command))))
               (and (eq isearch-yank-on-move 'shift)
                    this-command-keys-shift-translated)))
      (setq this-command-keys-shift-translated nil)
      (setq isearch-pre-move-point (point)))
     ;; Append control characters to the search string
     ((eq search-exit-option 'append)
      (unless (memq nil (mapcar #'characterp key))
        (isearch-process-search-string key key))
      (setq this-command 'ignore))
     ;; Other characters terminate the search and are then executed normally.
     (search-exit-option
      (isearch-done)
      (isearch-clean-overlays)))))