]> git.eshelyaron.com Git - emacs.git/commitdiff
Add `isearch-yank-until-char'
authorKarl Fogel <kfogel@red-bean.com>
Thu, 12 Sep 2019 17:42:13 +0000 (12:42 -0500)
committerKarl Fogel <kfogel@red-bean.com>
Thu, 12 Sep 2019 17:42:13 +0000 (12:42 -0500)
* lisp/isearch.el (isearch-yank-until-char): New function.
  (isearch-mode-map, isearch-menu-bar-yank-map): Add it.
  (isearch-forward): Document the new binding.

* doc/emacs/search.texi (Isearch Yanking): Document the feature.

* etc/NEWS: Mention the above.

doc/emacs/search.texi
etc/NEWS
lisp/isearch.el

index 66af5d4016297dc03aa9e465cb795d9401306360..38ef49ed64d71bf142b4d59ea37cd0e72b4a47d7 100644 (file)
@@ -262,11 +262,19 @@ of whether to copy a character or a symbol is heuristic.)
 
 @kindex M-s C-e @r{(Incremental search)}
 @findex isearch-yank-line
-  Similarly, @kbd{M-s C-e} (@code{isearch-yank-line}) appends the rest
+  @kbd{M-s C-e} (@code{isearch-yank-line}) appends the rest
 of the current line to the search string.  If point is already at the
 end of a line, it appends the next line.  With a prefix argument
 @var{n}, it appends the next @var{n} lines.
 
+@kindex C-M-z @r{(Incremental search)}
+@findex isearch-yank-until-char
+  Similarly, @kbd{C-M-z} (@code{isearch-yank-until-char}) appends to
+the search string everything from point until the next occurence of
+a specified character (not including that character).  This is especially
+useful for keyboard macros, for example in programming languages or
+markup languages in which that character marks a token boundary.
+
 @kindex C-y @r{(Incremental search)}
 @kindex M-y @r{(Incremental search)}
 @kindex mouse-2 @r{in the minibuffer (Incremental search)}
index 87666740df663d95dee20d24bb2eaab725818b60..1bde9c442b779711df6e64a41ec47152940c8d50 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1255,6 +1255,11 @@ highlight in one iteration while processing the full buffer.
 +++
 *** New isearch bindings.
 
+'C-M-z' invokes new function 'isearch-yank-until-char', which yanks
+everything from point up to but not including the specified
+character into the search string.  This is especially useful for
+keyboard macros.
+
 'C-M-w' in isearch changed from 'isearch-del-char' to the new function
 'isearch-yank-symbol-or-char'.  'isearch-del-char' is now bound to
 'C-M-d'.
index 30f7fc7254cb63ac818d21ba04075bfc9b969ce3..9401e8c06d30b8d4094e2262fa679137f0bcfd90 100644 (file)
@@ -514,6 +514,9 @@ This is like `describe-bindings', but displays only Isearch keys."
     (define-key map [isearch-yank-kill]
       '(menu-item "Current kill" isearch-yank-kill
                   :help "Append current kill to search string"))
+    (define-key map [isearch-yank-until-char]
+      '(menu-item "Until char..." isearch-yank-until-char
+                  :help "Yank from point to specified character into search string"))
     (define-key map [isearch-yank-line]
       '(menu-item "Rest of line" isearch-yank-line
                   :help "Yank the rest of the current line on search string"))
@@ -705,6 +708,7 @@ This is like `describe-bindings', but displays only Isearch keys."
     (define-key map "\M-\C-d" 'isearch-del-char)
     (define-key map "\M-\C-y" 'isearch-yank-char)
     (define-key map    "\C-y" 'isearch-yank-kill)
+    (define-key map "\M-\C-z" 'isearch-yank-until-char)
     (define-key map "\M-s\C-e" 'isearch-yank-line)
 
     (define-key map "\M-s\M-<" 'isearch-beginning-of-buffer)
@@ -998,6 +1002,8 @@ Type \\[isearch-yank-word-or-char] to yank next word or character in buffer
 Type \\[isearch-del-char] to delete character from end of search string.
 Type \\[isearch-yank-char] to yank char from buffer onto end of search\
  string and search for it.
+Type \\[isearch-yank-until-char] to yank from point until the next instance of a
+ specified character onto end of search string and search for it.
 Type \\[isearch-yank-line] to yank rest of line onto end of search string\
  and search for it.
 Type \\[isearch-yank-kill] to yank the last string of killed text.
@@ -2562,6 +2568,23 @@ If optional ARG is non-nil, pull in the next ARG words."
   (interactive "p")
   (isearch-yank-internal (lambda () (forward-word arg) (point))))
 
+(defun isearch-yank-until-char (char)
+  "Pull everything until next instance of CHAR from buffer into search string.
+Interactively, prompt for CHAR.
+This is often useful for keyboard macros, for example in programming
+languages or markup languages in which CHAR marks a token boundary."
+  (interactive "cYank until character: ")
+  (isearch-yank-internal
+   (lambda () (let ((inhibit-field-text-motion t))
+                (condition-case nil
+                    (progn
+                      (search-forward (char-to-string char))
+                      (forward-char -1))
+                  (search-failed
+                   (message "`%c' not found" char)
+                   (sit-for 2)))
+                (point)))))
+
 (defun isearch-yank-line (&optional arg)
   "Pull rest of line from buffer into search string.
 If optional ARG is non-nil, yank the next ARG lines."