[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Let's make C-M-w in isearch yank symbol, not delete character

From: Juri Linkov
Subject: Re: Let's make C-M-w in isearch yank symbol, not delete character
Date: Sun, 25 Feb 2018 22:55:40 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu)

> Right now, C-w in search-mode yanks a word from the buffer and globs it
> onto the end of the search result. I usually want to search for symbols,
> not words, so I end up pressing C-w multiple times. C-M-w would be the
> natural keybinding for yanking a symbol instead of a word, but it's already
> taken by isearch-del-char. How about moving isearch-del-char somewhere
> else, like C-d, and making C-M-w yank a whole symbol?

But isn't the prefix 'C-M-' usually reserved for keys that operate on
whole expressions, not just symbols?

Fortunately, it's easy to add support for yanking an expression:
in addition to the existing option 'edit' of 'search-exit-option'
we can also provide a new option 'move' that will sync the current
search string with the new position in the buffer after moving point
using all standard motion commands, e.g. `C-f' will add the next char
to the end of the search string, `C-M-f' will add the next expression,
`M-f' will add the next word, `C-b' will delete text from the end of
the search string, etc.  Here is the implementation:

diff --git a/lisp/isearch.el b/lisp/isearch.el
index a41adf0..4c3672e 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -2428,7 +2428,7 @@ isearch-pre-command-hook
       (setq this-command 'isearch-edit-string))
      ;; Other characters terminate the search and are then executed normally.
-     (search-exit-option
+     ((not (eq search-exit-option 'move))
      ;; If search-exit-option is nil, run the command without exiting Isearch.
@@ -2436,6 +2436,12 @@ isearch-pre-command-hook
       (isearch-process-search-string key key)))))
 (defun isearch-post-command-hook ()
+  (when (eq search-exit-option 'move)
+    (let ((string (buffer-substring-no-properties
+                   (or isearch-other-end isearch-opoint) (point))))
+      (setq isearch-string string
+            isearch-message string)
+      (isearch-search-and-update)))
   (when isearch-pre-scroll-point
     (let ((ab-bel (isearch-string-out-of-window isearch-pre-scroll-point)))
       (if ab-bel

reply via email to

[Prev in Thread] Current Thread [Next in Thread]