From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#39512: 28.0.50; Add command isearch-yank-region Date: Sun, 09 Feb 2020 13:38:14 +0100 Message-ID: <878slc2ax5.fsf@calancha-pc.dy.bbexcite.jp> References: <87eev52bw6.fsf@calancha-pc.dy.bbexcite.jp> <877e0wiosp.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="37495"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: spacibba@aol.com, npostavs@gmail.com, 39512@debbugs.gnu.org, contovob@tcd.ie To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 09 13:39:20 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j0lrs-0009eo-19 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 09 Feb 2020 13:39:20 +0100 Original-Received: from localhost ([::1]:49922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j0lrq-0002hb-N0 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 09 Feb 2020 07:39:18 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49502) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j0lrc-0002hT-5s for bug-gnu-emacs@gnu.org; Sun, 09 Feb 2020 07:39:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j0lra-00039p-GX for bug-gnu-emacs@gnu.org; Sun, 09 Feb 2020 07:39:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:46200) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j0lra-00039j-BJ for bug-gnu-emacs@gnu.org; Sun, 09 Feb 2020 07:39:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1j0lra-0001Uk-8A for bug-gnu-emacs@gnu.org; Sun, 09 Feb 2020 07:39:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 09 Feb 2020 12:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 39512 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 39512-submit@debbugs.gnu.org id=B39512.15812519055704 (code B ref 39512); Sun, 09 Feb 2020 12:39:02 +0000 Original-Received: (at 39512) by debbugs.gnu.org; 9 Feb 2020 12:38:25 +0000 Original-Received: from localhost ([127.0.0.1]:52173 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j0lqz-0001Tw-DY for submit@debbugs.gnu.org; Sun, 09 Feb 2020 07:38:25 -0500 Original-Received: from mail-wr1-f53.google.com ([209.85.221.53]:36128) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j0lqx-0001Tj-4y for 39512@debbugs.gnu.org; Sun, 09 Feb 2020 07:38:23 -0500 Original-Received: by mail-wr1-f53.google.com with SMTP id z3so4173999wru.3 for <39512@debbugs.gnu.org>; Sun, 09 Feb 2020 04:38:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=GXjp6AWeDOZr76ps8eK/xFBcTI+6zCRcm6obH7KBbe4=; b=GPETkJSYa2tRfl8u4SQ4MwI4i1qkk2EPuI/mLKC/Y1BO+7qBqNMcwsBL4swUQg6m+a NHkVNBr1h3t2+LFwFfU/+ZIiyBepVqKswkHejChd7CsDoZBSPdMZJVvERli+wlgBEpfz qE3VQX9nCExBskcSECQTBXwnXHGkb30c8TxQWSuYKK2woTvzgQtN8nSe5Pen8B+HNP1e U0E0uNeBdE38qiXTqLR4CVXslPUcNVK8ODZUgjJ3QuiGx3FPev5poJft8n+UoZ63qfUl WMTTJxMh2paBl/p2IrC1qOxBJ6Hq4wmOV85w9OQ8SwOXQLbbHv4iPzqJvESpjKGAeEwM P8Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=GXjp6AWeDOZr76ps8eK/xFBcTI+6zCRcm6obH7KBbe4=; b=lfr/ljo4dMYEDdtvV1PMC520iF5N93FsNrwKtxWM/fq/Mbb9OiXGeO9CWs5Oayqhm7 pzbMhAEsLPdYMM0aM72YKNM5tbN09wpj341CZz5GWc/ZqGwxWy+yTz41D2fjSnOiDdoW ppCRJDjaTG3E/GMGiJDJwzYFRIEczJlzfAnvTJXP8dvbPyGesbK2i/4Zwg5nDipXCESF 5/vwhdl8WbQZd12f7nVfmr6suHYdhYiiNtDD5mlP0h35nwIdE6PC2/5+mzkNdlFWI159 nLpOThjloeWnEUge1B+Qu/Y/44Hb62oDmDGXAPSGAZPUBV7ywr7dCCNnn9Aa349OKN4c xHfA== X-Gm-Message-State: APjAAAXOhOI/lrOuPfX1ZzBFPy9cU7DJCLOUMutQh92nNy0mMdHY03/E j4ROAAF+8obgX6KpaCfX31o= X-Google-Smtp-Source: APXvYqzjXIGuKrqBFERT44jx2Z6z0v0Cgn2/ZEPkzXv4vPly9HYdrOdQC3jYgnObu857jPKhq8LbPw== X-Received: by 2002:adf:f28c:: with SMTP id k12mr11454697wro.360.1581251897091; Sun, 09 Feb 2020 04:38:17 -0800 (PST) Original-Received: from calancha-pc.dy.bbexcite.jp ([31.7.242.222]) by smtp.gmail.com with ESMTPSA id t13sm11668435wrw.19.2020.02.09.04.38.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Feb 2020 04:38:16 -0800 (PST) In-Reply-To: <877e0wiosp.fsf@mail.linkov.net> (Juri Linkov's message of "Sun, 09 Feb 2020 02:31:50 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:175821 Archived-At: Juri Linkov writes: >> such a functionality was also missing. This is consistent with >> `isearch-yank-kill' (I think we should mention that in its docstring). > > Please add this useful feature of `isearch-yank-kill' to the documentation. > Maybe it should be bound to a special key on the global `M-s' prefix map. > The most natural key would be `M-s C-y'. Done. Added global binding `M-s C-y' for `isearch-yank-kill'. Updated its docstring and the NEWS. > (defun isearch-forward-region () > "Do incremental search forward for text from the active region. > Like ordinary incremental search except that text from the region > is added to the search string initially if the region is active." > (interactive) > (isearch-forward nil 1) > (cond > ((use-region-p) > (when (< (mark) (point)) > (exchange-point-and-mark)) > (isearch-yank-string > (buffer-substring-no-properties (region-beginning) (region-end))) > (deactivate-mark)) > (t > (setq isearch-error "No active region") > (isearch-push-state) > (isearch-update)))) I got inspired by your function; I took you default case in the `cond' to not exit the interactive search, as I was doing. I have added global keybinding `M-s M-.' for my `isearch-yank-region'. This naturally open the following question. `isearch-yank-kill' and `isearch-yank-region' are good names for the use case of calling them once we are in an interactive search. The names are not any good for the use case of calling them directly (from a global keybinding). We might want: 1. aliases `isearch-forward-kill', `isearch-forward-region' 2. restrict the use of them for just inside the interactive search, and define the new commands (`isearch-forward-kill',`isearch-forward-region') as those calling `isearch-mode' at the beginning. [might case a regression of Bug#21419.] --8<-----------------------------cut here---------------start------------->8--- commit 9cfe28b2b9661ca5cb11b0a99649faad5d6cf708 Author: Tino Calancha Date: Sun Feb 9 13:19:51 2020 +0100 Add command isearch-yank-region Right after start an interactive search, set the search string equal to the active region; this is analogous to other 'isearch-yank-...' commands. Calling the command out of an interactive search, then it starts an interactive search with the region as the search string. This is consistent with `isearch-yank-kill'. * lisp/isearch.el (isearch-yank-region): New command; bound to 'M-.' in isearch-mode-map. Bind it globally to 'M-s M-.'. (isearch-yank-kill): Update dosctring. Bind this command globally to 'M-s C-y'. * doc/emacs/search.texi (Isearch Yank): Document these changes. * etc/NEWS: Announce these changes. diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi index 16916617a2..07a40c18cf 100644 --- a/doc/emacs/search.texi +++ b/doc/emacs/search.texi @@ -250,6 +250,16 @@ Isearch Yank search string. The commands described in this subsection let you do that conveniently. +@kindex M-. @r{(Incremental search)} +@kindex M-s M-. +@findex isearch-yank-region + @kbd{M-.} (@code{isearch-yank-region}) sets the search string equal +to the active region. This is useful when you have selected a string +that you now want to search for. Then you can start the interactive +search and use @kbd{M-.}. Alternatively, you can use @kbd{M-s M-.} +to start directly an interactive search with the region as the +search string. + @kindex C-w @r{(Incremental search)} @findex isearch-yank-word-or-char @kbd{C-w} (@code{isearch-yank-word-or-char}) appends the next @@ -287,6 +297,7 @@ Isearch Yank @kindex C-y @r{(Incremental search)} @kindex M-y @r{(Incremental search)} +@kindex M-s C-y @kindex mouse-2 @r{in the minibuffer (Incremental search)} @findex isearch-yank-kill @findex isearch-yank-pop diff --git a/etc/NEWS b/etc/NEWS index 55c1a47fbf..ecb8048ade 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -91,6 +91,14 @@ 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 command 'isearch-yank-region', which yanks the selected +region into the search string. It's globally bound to 'M-s M-.'. +'isearch-yank-kill' now is globally bound to 'M-s C-y'. + ** Help +++ diff --git a/lisp/isearch.el b/lisp/isearch.el index ddf9190dc6..c5ae96033d 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) @@ -973,6 +977,8 @@ isearch--saved-overriding-local-map (defvar-local isearch-mode nil) ;; Name of the minor mode, if non-nil. (define-key global-map "\C-s" 'isearch-forward) +(define-key global-map "\M-s\M-." 'isearch-yank-region) +(define-key global-map "\M-s\C-y" 'isearch-yank-kill) (define-key esc-map "\C-s" 'isearch-forward-regexp) (define-key global-map "\C-r" 'isearch-backward) (define-key esc-map "\C-r" 'isearch-backward-regexp) @@ -1007,6 +1013,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. @@ -2468,11 +2475,28 @@ isearch-yank-string string (mapconcat 'isearch-text-char-description string ""))) (defun isearch-yank-kill () - "Pull string from kill ring into search string." + "Pull string from kill ring into search string. +If called out of an incremental search, then start an incremental +search with the last string of killed text as the search string." (interactive) (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) + (unless isearch-mode (isearch-mode t)) + (cond ((use-region-p) + (isearch-yank-string (funcall region-extract-function nil)) + (deactivate-mark)) + (t + (setq isearch-error "No active region") + (isearch-push-state) + (isearch-update)))) + + (defun isearch-yank-pop () "Replace just-yanked search string with previously killed string." (interactive) --8<-----------------------------cut here---------------end--------------->8---