Function: isearch-done

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

Signature

(isearch-done &optional NOPUSH EDIT)

Documentation

Exit Isearch mode.

For successful search, pass no args. For a failing search, NOPUSH is t. For going to the minibuffer to edit the search string, NOPUSH is t and EDIT is t.

Source Code

;; Defined in /usr/src/emacs/lisp/isearch.el.gz
(defun isearch-done (&optional nopush edit)
  "Exit Isearch mode.
For successful search, pass no args.
For a failing search, NOPUSH is t.
For going to the minibuffer to edit the search string,
NOPUSH is t and EDIT is t."

  (when isearch-resume-in-command-history
    (add-to-history 'command-history
                    `(isearch-resume ,isearch-string ,isearch-regexp
                                     ,isearch-regexp-function ,isearch-forward
                                     ,isearch-message
                                     ',isearch-case-fold-search)))

  (remove-hook 'pre-command-hook 'isearch-pre-command-hook)
  (remove-hook 'post-command-hook 'isearch-post-command-hook)
  (remove-hook 'mouse-leave-buffer-hook 'isearch-mouse-leave-buffer)
  (remove-hook 'kbd-macro-termination-hook 'isearch-done)
  (when (buffer-live-p isearch--current-buffer)
    (with-current-buffer isearch--current-buffer
      (setq isearch--current-buffer nil)
      (setq cursor-sensor-inhibit (delq 'isearch cursor-sensor-inhibit))))

  ;; Called by all commands that terminate isearch-mode.
  ;; If NOPUSH is non-nil, we don't push the string on the search ring.
  (setq overriding-terminal-local-map nil)
  ;; (setq pre-command-hook isearch-old-pre-command-hook) ; for lemacs
  (setq minibuffer-message-timeout isearch-original-minibuffer-message-timeout)
  (isearch-dehighlight)
  (lazy-highlight-cleanup lazy-highlight-cleanup)
  (setq isearch-lazy-highlight-last-string nil)
  (let ((found-start (window-group-start))
	(found-point (point)))
    (when isearch-window-configuration
      (set-window-configuration isearch-window-configuration)
      (if isearch-small-window
	  (goto-char found-point)
	;; set-window-configuration clobbers window-start; restore it.
	;; This has an annoying side effect of clearing the last_modiff
	;; field of the window, which can cause unwanted scrolling,
	;; so don't do it unless truly necessary.
	(set-window-group-start (selected-window) found-start t))))

  (setq isearch-mode nil)
  (if isearch-input-method-function
      (setq-local input-method-function isearch-input-method-function)
    (kill-local-variable 'input-method-function))

  (if isearch-tool-bar-old-map
      (progn
        (setq-local tool-bar-map isearch-tool-bar-old-map)
        (setq isearch-tool-bar-old-map nil))
    (kill-local-variable 'tool-bar-map))

  (force-mode-line-update)

  ;; If we ended in the middle of some intangible text,
  ;; move to the further end of that intangible text.
  (let ((after (if (eobp) nil
		 (get-text-property (point) 'intangible)))
	(before (if (bobp) nil
		  (get-text-property (1- (point)) 'intangible))))
    (when (and before after (eq before after))
      (goto-char
       (if isearch-forward
           (next-single-property-change (point) 'intangible)
         (previous-single-property-change (point) 'intangible)))))

  (if (and (> (length isearch-string) 0) (not nopush))
      ;; Update the ring data.
      (isearch-update-ring isearch-string isearch-regexp))

  (let ((isearch-mode-end-hook-quit (and nopush (not edit))))
    (run-hooks 'isearch-mode-end-hook))

  ;; If there was movement, mark the starting position.
  ;; Maybe should test difference between and set mark only if > threshold.
  (if (/= (point) isearch-opoint)
      (or (and transient-mark-mode mark-active)
	  (progn
	    (push-mark isearch-opoint t)
	    (or executing-kbd-macro (> (minibuffer-depth) 0) edit
		(message "Mark saved where search started")))))

  (and (not edit) isearch-recursive-edit (exit-recursive-edit)))