all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: dancol@dancol.org, emacs-devel@gnu.org
Subject: Re: Let's make C-M-w in isearch yank symbol, not delete character
Date: Fri, 02 Mar 2018 00:32:55 +0200	[thread overview]
Message-ID: <87tvtzjvh4.fsf@mail.linkov.net> (raw)
In-Reply-To: <83tvu1zsru.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 28 Feb 2018 05:40:05 +0200")

[-- Attachment #1: Type: text/plain, Size: 421 bytes --]

>> I updated the documentation in the docstring of search-exit-option below.
>
> This should be in NEWS as well.  What about the manual?

Here is a new patch with the NEWS entry.  Regarding the documentation,
I'm pretty sure this is not the final implementation as there will be
more changes in that feature before it's ready to be documented in
(info "(emacs) Not Exiting Isearch") or in (info "(emacs) Isearch Yank").


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: search-exit-option.patch --]
[-- Type: text/x-diff, Size: 4896 bytes --]

diff --git a/etc/NEWS b/etc/NEWS
index 596adf8..0d43913 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -180,6 +180,14 @@ created by 'edit-last-kbd-macro', and to save the macro by 'C-c C-c'.
 ---
 *** New filter ibuffer-filter-by-process; bound to '/E'.
 
+** Search and Replace
+
+*** 'search-exit-option' provides new options 'move' and 'shift-move'
+to extend the search string by yanking text that ends at the new
+position after moving point in the current buffer.  `shift-move'
+extends the search string by motion commands while holding down
+the shift key.
+
 ** Edebug
 
 +++
diff --git a/lisp/isearch.el b/lisp/isearch.el
index a41adf0..524137a 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -67,8 +67,23 @@ isearch
 
 
 (defcustom search-exit-option t
-  "Non-nil means random control characters terminate incremental search."
-  :type 'boolean)
+  "Defines what control characters do in incremental search.
+If t, random control and meta characters terminate the search
+and are then executed normally.
+If `edit', edit the search string instead of exiting.
+If `move', extend the search string by motion commands
+that have the `isearch-move' property on their symbols.
+If `shift-move', extend the search string by motion commands
+while holding down the shift key.
+Both `move' and `shift-move' extend the search string by yanking text
+that ends at the new position after moving point in the current buffer.
+If nil, run the command without exiting Isearch."
+  :type '(choice (const :tag "Terminate incremental search" t)
+                 (const :tag "Edit the search string" edit)
+                 (const :tag "Extend the search string by motion commands" move)
+                 (const :tag "Extend the search string by shifted motion keys" shift-move)
+                 (const :tag "Don't terminate incremental search" nil))
+  :version "27.1")
 
 (defcustom search-slow-window-lines 1
   "Number of lines in slow search display windows.
@@ -2391,6 +2423,7 @@ isearch-back-into-window
   (goto-char isearch-point))
 
 (defvar isearch-pre-scroll-point nil)
+(defvar isearch-pre-move-point nil)
 
 (defun isearch-pre-command-hook ()
   "Decide whether to exit Isearch mode before executing the command.
@@ -2398,8 +2431,9 @@ isearch-pre-command-hook
 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 non-nil)
-before the command is executed globally with terminated Isearch."
+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
@@ -2427,6 +2461,14 @@ isearch-pre-command-hook
       ;; Swallow the up-event.
       (read-event)
       (setq this-command 'isearch-edit-string))
+     ;; Don't terminate the search for motion commands.
+     ((or (and (eq search-exit-option 'move)
+               (symbolp this-command)
+               (eq (get this-command 'isearch-move) t))
+          (and (eq search-exit-option 'shift-move)
+               this-command-keys-shift-translated))
+      (setq this-command-keys-shift-translated nil)
+      (setq isearch-pre-move-point (point)))
      ;; Other characters terminate the search and are then executed normally.
      (search-exit-option
       (isearch-done)
@@ -2436,13 +2478,28 @@ isearch-pre-command-hook
       (isearch-process-search-string key key)))))
 
 (defun isearch-post-command-hook ()
-  (when isearch-pre-scroll-point
+  (cond
+   (isearch-pre-scroll-point
     (let ((ab-bel (isearch-string-out-of-window isearch-pre-scroll-point)))
       (if ab-bel
 	  (isearch-back-into-window (eq ab-bel 'above) isearch-pre-scroll-point)
 	(goto-char isearch-pre-scroll-point)))
     (setq isearch-pre-scroll-point nil)
-    (isearch-update)))
+    (isearch-update))
+   ((memq search-exit-option '(move shift-move))
+    (when (and isearch-pre-move-point
+               (not (eq isearch-pre-move-point (point))))
+      (let ((string (buffer-substring-no-properties
+                     (or isearch-other-end isearch-opoint) (point))))
+        (if isearch-regexp (setq string (regexp-quote string)))
+        (setq isearch-string string)
+        (setq isearch-message (mapconcat 'isearch-text-char-description
+                                         string ""))
+        (setq isearch-yank-flag t)
+        (setq isearch-forward (<= (or isearch-other-end isearch-opoint) (point)))
+        (goto-char isearch-pre-move-point)
+        (isearch-search-and-update)))
+    (setq isearch-pre-move-point nil))))
 
 (defun isearch-quote-char (&optional count)
   "Quote special characters for incremental search.

  reply	other threads:[~2018-03-01 22:32 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-22 19:10 Let's make C-M-w in isearch yank symbol, not delete character Daniel Colascione
2018-02-23  0:44 ` John Wiegley
2018-02-25 20:55 ` Juri Linkov
2018-02-25 21:12   ` H. Dieter Wilhelm
2018-02-25 21:43   ` Daniel Colascione
2018-03-01 22:39     ` Isearch interaction model (was: Let's make C-M-w in isearch yank symbol, not delete character) Juri Linkov
2018-03-02  0:12       ` Isearch interaction model Daniel Colascione
2018-03-02  0:19         ` Davis Herring
2018-03-02  0:26           ` dancol
2018-03-03 22:50             ` Juri Linkov
2018-03-03 23:46               ` Clément Pit-Claudel
2018-03-04 21:42                 ` Juri Linkov
2018-03-08 22:55                 ` Juri Linkov
2018-03-04 15:39               ` Eli Zaretskii
2018-03-04 17:13                 ` Daniel Colascione
2018-03-04 17:26                   ` Clément Pit-Claudel
2018-03-04 21:58                     ` Juri Linkov
2018-03-04 22:03                     ` Daniel Colascione
2018-03-05  3:33                       ` Eli Zaretskii
2018-03-05 21:33                       ` Juri Linkov
2018-03-04 21:50                   ` Juri Linkov
2018-03-06 21:47           ` Juri Linkov
2018-03-06 22:22             ` dancol
2018-03-07 22:30               ` Juri Linkov
2018-03-07 22:55                 ` dancol
2018-03-08 22:41                   ` Juri Linkov
2018-03-09 11:01                     ` Daniel Colascione
2018-03-10 21:20                       ` Juri Linkov
2018-03-10 21:36                         ` Daniel Colascione
2018-03-11 21:58                           ` Juri Linkov
2018-03-12  3:29                             ` Eli Zaretskii
2018-03-12  8:23                             ` Daniel Colascione
2018-03-12  9:29                               ` Yuri Khan
2018-03-02 16:01       ` Isearch interaction model (was: Let's make C-M-w in isearch yank symbol, not delete character) Richard Stallman
2018-02-26  3:26   ` Let's make C-M-w in isearch yank symbol, not delete character Eli Zaretskii
2018-02-27 21:28     ` Juri Linkov
2018-02-28  3:40       ` Eli Zaretskii
2018-03-01 22:32         ` Juri Linkov [this message]
2018-03-02  8:17           ` Eli Zaretskii
2018-03-03 22:34             ` Juri Linkov
2018-03-04 15:47               ` Eli Zaretskii
2018-03-04 21:36                 ` Juri Linkov
2018-03-05  3:31                   ` Eli Zaretskii
2018-03-05 15:59                     ` Eli Zaretskii
2018-03-05 21:25                       ` Juri Linkov
2018-03-06  3:28                         ` Eli Zaretskii
2018-03-06 22:07                           ` Juri Linkov
2018-03-10 11:59                             ` Eli Zaretskii
2018-03-10 18:34                             ` John Shahid
2018-03-10 21:15                               ` Juri Linkov
2018-03-11  2:37                                 ` Stefan Monnier
2018-03-11 21:52                                   ` Juri Linkov
2018-03-12 17:38                                     ` John Shahid
2018-03-12 18:24                                     ` Alan Mackenzie
2018-03-12 21:19                                       ` Juri Linkov
2018-03-12 21:36                                         ` Juri Linkov
2018-03-11  3:38                                 ` Eli Zaretskii
2018-03-11 14:32                                 ` Herring, Davis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tvtzjvh4.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=dancol@dancol.org \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.