aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorJuri Linkov2018-03-04 00:33:30 +0200
committerJuri Linkov2018-03-04 00:33:30 +0200
commit90ca83d4bf17a334902321e93fa89ccb1f4a5a4e (patch)
treee087ac4e6b558817df3b725348e71908287963ad /lisp
parentb3300c3ec80a40a6fe34a8721b79f273d519f00e (diff)
downloademacs-90ca83d4bf17a334902321e93fa89ccb1f4a5a4e.tar.gz
emacs-90ca83d4bf17a334902321e93fa89ccb1f4a5a4e.zip
* lisp/isearch.el (search-exit-option): Add options ‘shift-move’ and ‘move’.
Change type from ‘boolean’ to ‘choice’. Extend docstring. (isearch-pre-move-point): New variable. (isearch-pre-command-hook, isearch-post-command-hook): Handle search-exit-option for values ‘move’ and ‘shift-move’. * doc/emacs/search.texi (Not Exiting Isearch): Document new values ‘shift-move’ and ‘move’ of search-exit-option. https://lists.gnu.org/archive/html/emacs-devel/2018-03/msg00013.html
Diffstat (limited to 'lisp')
-rw-r--r--lisp/isearch.el52
1 files changed, 46 insertions, 6 deletions
diff --git a/lisp/isearch.el b/lisp/isearch.el
index a41adf0c2cd..96faa27c174 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -67,8 +67,23 @@
67 67
68 68
69(defcustom search-exit-option t 69(defcustom search-exit-option t
70 "Non-nil means random control characters terminate incremental search." 70 "Defines what control characters do in incremental search.
71 :type 'boolean) 71If t, random control and meta characters terminate the search
72and are then executed normally.
73If `edit', edit the search string instead of exiting.
74If `move', extend the search string by motion commands
75that have the `isearch-move' property on their symbols.
76If `shift-move', extend the search string by motion commands
77while holding down the shift key.
78Both `move' and `shift-move' extend the search string by yanking text
79that ends at the new position after moving point in the current buffer.
80If nil, run the command without exiting Isearch."
81 :type '(choice (const :tag "Terminate incremental search" t)
82 (const :tag "Edit the search string" edit)
83 (const :tag "Extend the search string by motion commands" move)
84 (const :tag "Extend the search string by shifted motion keys" shift-move)
85 (const :tag "Don't terminate incremental search" nil))
86 :version "27.1")
72 87
73(defcustom search-slow-window-lines 1 88(defcustom search-slow-window-lines 1
74 "Number of lines in slow search display windows. 89 "Number of lines in slow search display windows.
@@ -2391,6 +2406,7 @@ the bottom."
2391 (goto-char isearch-point)) 2406 (goto-char isearch-point))
2392 2407
2393(defvar isearch-pre-scroll-point nil) 2408(defvar isearch-pre-scroll-point nil)
2409(defvar isearch-pre-move-point nil)
2394 2410
2395(defun isearch-pre-command-hook () 2411(defun isearch-pre-command-hook ()
2396 "Decide whether to exit Isearch mode before executing the command. 2412 "Decide whether to exit Isearch mode before executing the command.
@@ -2398,8 +2414,9 @@ Don't exit Isearch if the key sequence that invoked this command
2398is bound in `isearch-mode-map', or if the invoked command is 2414is bound in `isearch-mode-map', or if the invoked command is
2399a prefix argument command (when `isearch-allow-prefix' is non-nil), 2415a prefix argument command (when `isearch-allow-prefix' is non-nil),
2400or it is a scrolling command (when `isearch-allow-scroll' is non-nil). 2416or it is a scrolling command (when `isearch-allow-scroll' is non-nil).
2401Otherwise, exit Isearch (when `search-exit-option' is non-nil) 2417Otherwise, exit Isearch (when `search-exit-option' is t)
2402before the command is executed globally with terminated Isearch." 2418before the command is executed globally with terminated Isearch.
2419See more for options in `search-exit-option'."
2403 (let* ((key (this-single-command-keys)) 2420 (let* ((key (this-single-command-keys))
2404 (main-event (aref key 0))) 2421 (main-event (aref key 0)))
2405 (cond 2422 (cond
@@ -2427,6 +2444,14 @@ before the command is executed globally with terminated Isearch."
2427 ;; Swallow the up-event. 2444 ;; Swallow the up-event.
2428 (read-event) 2445 (read-event)
2429 (setq this-command 'isearch-edit-string)) 2446 (setq this-command 'isearch-edit-string))
2447 ;; Don't terminate the search for motion commands.
2448 ((or (and (eq search-exit-option 'move)
2449 (symbolp this-command)
2450 (eq (get this-command 'isearch-move) t))
2451 (and (eq search-exit-option 'shift-move)
2452 this-command-keys-shift-translated))
2453 (setq this-command-keys-shift-translated nil)
2454 (setq isearch-pre-move-point (point)))
2430 ;; Other characters terminate the search and are then executed normally. 2455 ;; Other characters terminate the search and are then executed normally.
2431 (search-exit-option 2456 (search-exit-option
2432 (isearch-done) 2457 (isearch-done)
@@ -2436,13 +2461,28 @@ before the command is executed globally with terminated Isearch."
2436 (isearch-process-search-string key key))))) 2461 (isearch-process-search-string key key)))))
2437 2462
2438(defun isearch-post-command-hook () 2463(defun isearch-post-command-hook ()
2439 (when isearch-pre-scroll-point 2464 (cond
2465 (isearch-pre-scroll-point
2440 (let ((ab-bel (isearch-string-out-of-window isearch-pre-scroll-point))) 2466 (let ((ab-bel (isearch-string-out-of-window isearch-pre-scroll-point)))
2441 (if ab-bel 2467 (if ab-bel
2442 (isearch-back-into-window (eq ab-bel 'above) isearch-pre-scroll-point) 2468 (isearch-back-into-window (eq ab-bel 'above) isearch-pre-scroll-point)
2443 (goto-char isearch-pre-scroll-point))) 2469 (goto-char isearch-pre-scroll-point)))
2444 (setq isearch-pre-scroll-point nil) 2470 (setq isearch-pre-scroll-point nil)
2445 (isearch-update))) 2471 (isearch-update))
2472 ((memq search-exit-option '(move shift-move))
2473 (when (and isearch-pre-move-point
2474 (not (eq isearch-pre-move-point (point))))
2475 (let ((string (buffer-substring-no-properties
2476 (or isearch-other-end isearch-opoint) (point))))
2477 (if isearch-regexp (setq string (regexp-quote string)))
2478 (setq isearch-string string)
2479 (setq isearch-message (mapconcat 'isearch-text-char-description
2480 string ""))
2481 (setq isearch-yank-flag t)
2482 (setq isearch-forward (<= (or isearch-other-end isearch-opoint) (point)))
2483 (goto-char isearch-pre-move-point)
2484 (isearch-search-and-update)))
2485 (setq isearch-pre-move-point nil))))
2446 2486
2447(defun isearch-quote-char (&optional count) 2487(defun isearch-quote-char (&optional count)
2448 "Quote special characters for incremental search. 2488 "Quote special characters for incremental search.