unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* PATCH: isearch-yank-until-char
@ 2019-08-14  3:05 Karl Fogel
  2019-08-14 14:20 ` Eli Zaretskii
                   ` (3 more replies)
  0 siblings, 4 replies; 45+ messages in thread
From: Karl Fogel @ 2019-08-14  3:05 UTC (permalink / raw)
  To: Emacs developers

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

This patch implements 'isearch-yank-until-char', a new yank command in isearch.

While in an isearch, one types C-M-c to yank into the search string everything from point up to (but not including) the next instance of a specified character.  It prompts for the character.

For example, assume point is on the "m" after the "#" mark below:

  [example from a recent macro I wrote](#markdown-link-syntax)

Start an isearch with C-s, then do C-M-c followed by ")".  The search string is now "markdown-link-syntax".

I have found this functionality very helpful in macros.

If it's a useful contribution to Emacs, then I'll install it.  I'll wait at least three days to get feedback, both about the feature itself and about the choice of M-C-c as the keybinding.  If there's no response or no consensus, then I won't install it, as being conservative about isearch seems appropriate.

Best regards,
-Karl


[-- Attachment #2: Patch to implement isearch-yank-until-char --]
[-- Type: text/plain, Size: 3495 bytes --]

[[[
Add `isearch-yank-until-char'

* 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.
]]]

diff --git doc/emacs/search.texi doc/emacs/search.texi
index 66af5d4016..2d1980b26e 100644
--- doc/emacs/search.texi
+++ doc/emacs/search.texi
@@ -262,11 +262,17 @@ Isearch Yank
 
 @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 M-s C-e @r{(Incremental search)}
+@findex isearch-yank-line
+  Similarly, @kbd{C-M-c} (@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).
+
 @kindex C-y @r{(Incremental search)}
 @kindex M-y @r{(Incremental search)}
 @kindex mouse-2 @r{in the minibuffer (Incremental search)}
diff --git lisp/isearch.el lisp/isearch.el
index 30f7fc7254..7d2f78f49d 100644
--- lisp/isearch.el
+++ lisp/isearch.el
@@ -514,6 +514,9 @@ isearch-menu-bar-yank-map
     (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 everything until the specified character to 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 @@ isearch-mode-map
     (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-c" '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 @@ isearch-forward
 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 everything 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,16 @@ isearch-yank-word
   (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."
+  (interactive "cYank until character: ")
+  (isearch-yank-internal
+   (lambda () (let ((inhibit-field-text-motion t))
+                (search-forward (char-to-string char))
+                (forward-char -1)
+                (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."

^ permalink raw reply related	[flat|nested] 45+ messages in thread
[parent not found: <<87tvakfnv4.fsf@red-bean.com>]

end of thread, other threads:[~2019-09-17 16:02 UTC | newest]

Thread overview: 45+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-14  3:05 PATCH: isearch-yank-until-char Karl Fogel
2019-08-14 14:20 ` Eli Zaretskii
2019-08-14 16:41   ` Karl Fogel
2019-08-14 16:48     ` Drew Adams
2019-08-14 17:20       ` Eli Zaretskii
2019-08-14 17:22       ` Karl Fogel
2019-08-14 17:51         ` Eli Zaretskii
2019-08-14 17:59 ` Noam Postavsky
2019-08-14 20:39   ` Juri Linkov
2019-08-14 20:34 ` Juri Linkov
2019-08-16  4:53   ` Karl Fogel
2019-08-16 17:52     ` Juri Linkov
2019-08-25  2:14       ` Karl Fogel
2019-08-25  3:22         ` Drew Adams
2019-08-25 20:03           ` Juri Linkov
2019-08-26  1:14             ` Drew Adams
2019-08-26  5:20           ` Karl Fogel
2019-08-26 14:50             ` Drew Adams
2019-08-26 17:51               ` Karl Fogel
2019-08-26 19:36                 ` Drew Adams
2019-08-26 21:29                   ` Karl Fogel
2019-08-26 21:57                     ` Drew Adams
2019-08-26 22:21                       ` Karl Fogel
2019-08-26 22:43                         ` Drew Adams
2019-09-04 16:47                           ` Karl Fogel
2019-09-04 17:00                             ` Eli Zaretskii
2019-09-12 17:44                               ` Karl Fogel
2019-09-16 21:24                   ` Drew Adams
2019-09-17 16:02                     ` Karl Fogel
2019-08-26 21:46                 ` Juri Linkov
2019-08-26 21:52                   ` Karl Fogel
2019-08-26 22:03                   ` Drew Adams
2019-08-26 22:19                     ` Juri Linkov
2019-08-26 22:33                       ` Karl Fogel
2019-08-26 22:40                       ` Drew Adams
2019-08-27 21:31                         ` Juri Linkov
2019-08-27 22:52                           ` Drew Adams
2019-08-27 23:15                             ` Drew Adams
2019-08-25 19:58         ` Juri Linkov
2019-08-14 22:26 ` Stefan Monnier
2019-08-15 18:24   ` Juri Linkov
2019-08-17 12:31     ` Stefan Monnier
2019-08-17 22:51       ` Juri Linkov
2019-08-16  5:11   ` Karl Fogel
     [not found] <<87tvakfnv4.fsf@red-bean.com>
     [not found] ` <<835zmzsuau.fsf@gnu.org>
2019-08-14 15:24   ` Drew Adams

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).