bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#39512: 28.0.50; Add command isearch-yank-region


From: Tino Calancha
Subject: bug#39512: 28.0.50; Add command isearch-yank-region
Date: Sat, 08 Feb 2020 19:04:57 +0100

Severity: wishlist
Tags: patch
X-Debbugs-Cc: 
address@hidden,address@hidden,address@hidden,address@hidden,address@hidden,address@hidden

I wish to have this command; it naturally completes other
isearch-yank-... cases.

This topic has been already discussed in the following links:

https://lists.gnu.org/archive/html/emacs-devel/2019-04/msg01125.html
https://lists.gnu.org/archive/html/emacs-devel/2019-05/msg00003.html

Note that in those threads there were plenty of discussions; here I'd
like to focus just in this proposed command.  If needed, I'd recommend
to open further bugs to discuss about other commands.

I let this command to start the interactive search if we are
not already there; from the above links I realized that
such a functionality was also missing.  This is consistent with
`isearch-yank-kill' (I think we should mention that in its docstring).


--8<-----------------------------cut here---------------start------------->8---
commit 1ea1939929fbf22c6d635b075cfcb2b77a4b8243
Author: Tino Calancha <address@hidden>
Date:   Sat Feb 8 18:39:44 2020 +0100

    Add command isearch-yank-region
    
    During an incremental search, this command appends the region
    to the search string.  Otherwise, start an incremental search
    using the region as the search string.
    
    * lisp/isearch.el (isearch-yank-region): New command; bound to 'M-.'
    in isearch-mode-map.
    
    * doc/emacs/search.texi (Isearch Yank): Document it.
    * etc/NEWS: Announce this change.

diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi
index 16916617a2..b443300b6d 100644
--- a/doc/emacs/search.texi
+++ b/doc/emacs/search.texi
@@ -285,6 +285,11 @@ Isearch Yank
 a prefix numeric argument of @var{n}, the command appends everything
 from point to the @var{n}th occurrence of the specified character.
 
+@kindex M-. @r{(Incremental search)}
+@findex isearch-yank-region
+  Likewise, @kbd{M-.} (@code{isearch-yank-region}) appends to
+the search string the selected region.
+
 @kindex C-y @r{(Incremental search)}
 @kindex M-y @r{(Incremental search)}
 @kindex mouse-2 @r{in the minibuffer (Incremental search)}
diff --git a/etc/NEWS b/etc/NEWS
index 55c1a47fbf..cf63176124 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -91,6 +91,13 @@ shows equivalent key bindings for all commands that have 
them.
 
 * Changes in Specialized Modes and Packages in Emacs 28.1
 
+** Search and Replace
+
++++
+*** New isearch bindings.
+'M-.' invokes new fnction 'isearch-yank-region', which yanks the selected
+region into the search string.
+
 ** Help
 
 +++
diff --git a/lisp/isearch.el b/lisp/isearch.el
index ddf9190dc6..266c311c3d 100644
--- a/lisp/isearch.el
+++ b/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-region]
+      '(menu-item "Active region" isearch-yank-region
+                  :help "Append active region 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"))
@@ -708,6 +711,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-." 'isearch-yank-region)
     (define-key map "\M-\C-z" 'isearch-yank-until-char)
     (define-key map "\M-s\C-e" 'isearch-yank-line)
 
@@ -1007,6 +1011,7 @@ isearch-forward
 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.
+Type \\[isearch-yank-region] to yank the active region.
 Type \\[isearch-yank-pop] to replace string just yanked into search prompt
  with string killed before it.
 Type \\[isearch-quote-char] to quote control character to search for it.
@@ -2473,6 +2478,17 @@ isearch-yank-kill
   (unless isearch-mode (isearch-mode t))
   (isearch-yank-string (current-kill 0)))
 
+(defun isearch-yank-region ()
+  "Pull region into search string.
+If called out of an incremental search, then start an incremental
+search with the region as the search string."
+  (interactive)
+  (cond ((use-region-p)
+         (unless isearch-mode (isearch-mode t))
+         (isearch-yank-string (funcall region-extract-function))
+         (deactivate-mark))
+        (t (user-error "No selected region"))))
+
 (defun isearch-yank-pop ()
   "Replace just-yanked search string with previously killed string."
   (interactive)

--8<-----------------------------cut here---------------end--------------->8---


In GNU Emacs 28.0.50 (build 3, x86_64-pc-linux-gnu, GTK+ Version 3.24.5, cairo 
version 1.16.0)
 of 2020-02-08 built on calancha-pc.dy.bbexcite.jp
Repository revision: fe903c5ab7354b97f80ecf1b01ca3ff1027be446
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12004000
System Description: Debian GNU/Linux 10 (buster)






reply via email to

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