From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Ergus Newsgroups: gmane.emacs.devel Subject: Re: isearch region or thing at point. Date: Wed, 1 May 2019 13:20:25 +0200 Message-ID: <20190501112025.fnsynkbmkvllapyv@Ergus> References: <20190427001453.isjx247kc3lu5fe4@Ergus> <87a7gcp51i.fsf@tcd.ie> <20190429004135.rn5tp2gnmbjovrxj@Ergus> <87h8agy4yf.fsf@mail.linkov.net> <20190430162501.xmqh5r5h57sjjlq5@Ergus> <87h8af15kg.fsf@tcd.ie> <20190430231614.l423x6eqta5fbhor@Ergus> <874l6f132f.fsf@tcd.ie> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="7v5gouqlfdcerlz5" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="31964"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: NeoMutt/20180716 Cc: Juri Linkov , emacs-devel@gnu.org To: "Basil L. Contovounesios" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed May 01 13:20:50 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hLnI9-00089i-D4 for ged-emacs-devel@m.gmane.org; Wed, 01 May 2019 13:20:49 +0200 Original-Received: from localhost ([127.0.0.1]:54994 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLnI8-0001BX-Aa for ged-emacs-devel@m.gmane.org; Wed, 01 May 2019 07:20:48 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:50589) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLnHy-0001Az-TK for emacs-devel@gnu.org; Wed, 01 May 2019 07:20:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hLnHv-00062p-Rt for emacs-devel@gnu.org; Wed, 01 May 2019 07:20:38 -0400 Original-Received: from sonic313-20.consmr.mail.ir2.yahoo.com ([77.238.179.187]:45351) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hLnHt-00061V-TN for emacs-devel@gnu.org; Wed, 01 May 2019 07:20:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1556709630; bh=VmlwGPNMf+IOF60DBgVhna/4+MMu17p5y3YSswzvn3c=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From:Subject; b=UN48eq0zv4kfzeoWncUkm/r1o8EvC+k+ptV1DwxqEaq2qIIrOi5cjtP8SB65TIVOuTTN7o/3u3XNVT7TnYXBTecVJV2RrogQ1aTnbyTC741dzYR/SeDCUNnbcjQCGk8Zi8Iseqx3KMaubkVc/Re4ZqlstqOMhOcm3PNijko8x3KgXe8HAVkTQDNtwww2baqGd8JPp3NTRjDUefzUBa8Gs5A9K5QzOna1jP5T04+B43BZLT7B7qUtMGTjRxPxs7bV1R2C0k3LWGiNtYr5/DZNXjcWA1YgQ3YD6cTyXS+4gtQztxGldOO+/H0Jdhd/fhS4PlO5gFwW274KrTRSkMAFgg== X-YMail-OSG: cas6licVM1lDmy9KAdFlQzWlJtLrNE4XJaQT3k87mKZ1OfHUd1JdE4hmXqDgbn6 QJbXhG2d5oWTqnoNyJfdL4pAoOdYgLmzS9inVz7FFXeJacQh95ZXEaeP_03SajZLyRezw8nsueXC l.PJ.6K4QghF9BM26lEXLplMjUBXeR4cVF6UNzzQHUvILr4.iRrCvsP0NigyzCui8dOrn1OX6ztX HRtenmjirT8D28qcm._wvJITJGQXSJ0CTYJXWDdci0NwqYHV.uWkxjVDG7AbRhMBcPvvuzWUifKJ hPBFfNZB48sAr5Ikj8le0I3C.e4yh2Tji1gw_tEkvIGk8BaMp7a0zLstM_5f0E1aOfpci89HrSVk YEuj3o7FGC3ixJsFDXClkH34ZPt8x0UOipoEOx_hm11Z65Ts3XtQRIa_MGh9TTWHLtkFZJANN1r2 C.zeL332L1Y7mxTCynLORZ2H.V9dxlojuDAgZs2bzwtP3WIwvoZYc5CS4AU3KHixlSzwyT7d23Rl c3t15z7JcL17O4iZtuqFDz_9Jbshiiby45uW5_tiFTQnS_UVmDHSFlkxwElEDKKnwOsthGnVpD7J iKlCZgoPlbFn4MWp4dIsVon0cVPuSDXLLGwSWdxY8WAJLRNDR1vydVrKOtdWIMmep3UmzP3CSiDd SldZ4lbaq.om1p4jfiDiYVyHKeC1r_tSd_ZpbDKbMLCG68bXlu.K6JIWMqtfPlXg4FmVPNEEeT2g oimRd1NoNHi2bEN7s53Lbfd0Bef.hK1e1n9fBbnEdRsIacTYf5CJRlyCDxYlJwQ9Tk9pO_Vnw9Mw E5YR.v3KWRx7NkGDuiOtY4MYetmsy2xPSFk_W4uyj0 Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic313.consmr.mail.ir2.yahoo.com with HTTP; Wed, 1 May 2019 11:20:30 +0000 Original-Received: from 2.152.205.184.dyn.user.ono.com (EHLO Ergus) ([2.152.205.184]) by smtp426.mail.ir2.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 41e2a4cdb751cc3263c1b11a4237fd2b; Wed, 01 May 2019 11:20:27 +0000 (UTC) Content-Disposition: inline In-Reply-To: <874l6f132f.fsf@tcd.ie> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 77.238.179.187 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:236089 Archived-At: --7v5gouqlfdcerlz5 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline Hi all: Here is attached a patch with all my proposed changes to isearch. I added documentation in the manual for one of the two functions, but for the other I don't find the right place. There is still a pending agreement about the questions I made in the last email, but, meanwhile you can check the rest of the patch and make all the corrections you think are needed. Thanks in advance for your comments, Ergus On Wed, May 01, 2019 at 12:33:12AM +0100, Basil L. Contovounesios wrote: >Ergus writes: > >> On Tue, Apr 30, 2019 at 11:39:11PM +0100, Basil L. Contovounesios wrote: >>>Ergus writes: >>> >>>> (region-bounds))) >>>> (contiguous (= (length bounds) 1)) ;; Region is contiguous >>> >>>Better to use the function region-noncontiguous-p. >>> >> I already had the bounds.. I didn't want to do the funcall again... but >> I know it is probably not important.. I am just an obsessed. > >The higher-level and more flexible region-extract-function will handle >this for you in any case. > >>>> (region-string (and (= (count-lines region-beg region-end) 1) >>>> (buffer-substring-no-properties >>>> region-beg region-end))) >>> >>>Why can't the region span multiple lines? Better to use >>>region-extract-function for this, as it is more flexible. >>> >> I don't thing that searching multiple lines will be very useful in >> practice and could potentially produce some corner cases. But I >> will think about that a bit more. > >AFAIK, isearch is designed to work perfectly fine with multiple lines, >and I use this feature a lot, especially in the context of lax >whitespace matches in Info manuals, for example. > >Providing a dedicated region isearch command which is limited to a >single line sounds hardly better than using isearch-yank-word-or-char or >similar. > >>>> (isearch-yank-string region-string) >>>> >>>> (when-let (count (and arg (prefix-numeric-value arg))) >>>> (isearch-repeat-forward count))) >>> >>>This can be simplified as per Noam's suggestion. >> Yes, sorry, I was concerned if somehow the prefix could be non-nil, but >> (prefix-numeric-value arg) could return nil... I don't really know the >> fancy valued that prefix could potentially have. But probably there is >> not any danger there. > >All potential prefix values are listed under (info "(elisp) Prefix >Command Arguments"), and prefix-numeric-value is guaranteed to return an >integer. > >Thanks, > >-- >Basil > --7v5gouqlfdcerlz5 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="isearch_yank_region.patch" diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi index a1c987c125..93c26f5c97 100644 --- a/doc/emacs/search.texi +++ b/doc/emacs/search.texi @@ -267,6 +267,14 @@ 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-w @r{(Incremental search)} +@findex isearch-yank-region + @kbd{M-w} (@code{isearch-yank-region}) appends the text in the +active region if @code{transient-mark-mode} is @code{non-nil}. This is +an easy way to insert the text in the region without needing to exit +@code{isearch-mode}. The region is deactivated during the search, but +it is reactivated if the @code{isearch-cancel} is called. + @kindex C-y @r{(Incremental search)} @kindex M-y @r{(Incremental search)} @kindex mouse-2 @r{in the minibuffer (Incremental search)} diff --git a/lisp/isearch.el b/lisp/isearch.el index 6280afebdc..78414dbfcd 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -53,7 +53,9 @@ ;;; Code: -(eval-when-compile (require 'cl-lib)) +(eval-when-compile + (require 'cl-lib) + (require 'subr-x)) (declare-function tmm-menubar-keymap "tmm.el") ;; Some additional options and constants. @@ -701,6 +703,7 @@ This is like `describe-bindings', but displays only Isearch keys." (define-key map "\M-\C-y" 'isearch-yank-char) (define-key map "\C-y" 'isearch-yank-kill) (define-key map "\M-s\C-e" 'isearch-yank-line) + (define-key map "\M-w" 'isearch-yank-region) (define-key map "\M-s\M-<" 'isearch-beginning-of-buffer) (define-key map "\M-s\M->" 'isearch-end-of-buffer) @@ -937,6 +940,8 @@ Each element is an `isearch--state' struct where the slots are (defvar isearch--saved-overriding-local-map nil) +(defvar isearch--deactivated-mark nil) + ;; Minor-mode-alist changes - kind of redundant with the ;; echo area, but if isearching in multiple windows, it can be useful. ;; Also, clicking the mode-line indicator pops up @@ -961,6 +966,8 @@ Each element is an `isearch--state' struct where the slots are (define-key search-map "w" 'isearch-forward-word) (define-key search-map "_" 'isearch-forward-symbol) (define-key search-map "." 'isearch-forward-symbol-at-point) +(define-key search-map "\M-w" 'isearch-forward-region) + ;; Entry points to isearch-mode. @@ -1133,6 +1140,22 @@ positive, or search for ARGth symbol backward if ARG is negative." (isearch-push-state) (isearch-update))))) +(defun isearch-forward-region (&optional arg) + "Do incremental search forward for text in active region. +Like ordinary incremental search except that the text in the +active region is added to the search string initially +if`transient-mark-mode' is enabled. See the command +`isearch-forward' for more information. +With a prefix argument, search for ARGth occurrence forward if +ARG is positive, or ARGth occurrence backward if ARG is +negative." + (interactive "P") + (isearch-forward nil 1) + (isearch-yank-region) + (when (and isearch--deactivated-mark + arg) + (isearch-repeat-forward (prefix-numeric-value arg)))) + ;; isearch-mode only sets up incremental search for the minor mode. ;; All the work is done by the isearch-mode commands. @@ -1203,9 +1226,10 @@ used to set the value of `isearch-regexp-function'." isearch-pre-move-point nil ;; Save the original value of `minibuffer-message-timeout', and - ;; set it to nil so that isearch's messages don't get timed out. - isearch-original-minibuffer-message-timeout minibuffer-message-timeout - minibuffer-message-timeout nil) + ;; set it to nil so that isearch's messages don't get timed out. + isearch-original-minibuffer-message-timeout minibuffer-message-timeout + minibuffer-message-timeout nil + isearch--deactivated-mark nil) (if (local-variable-p 'tool-bar-map) (setq isearch-tool-bar-old-map tool-bar-map)) @@ -1783,6 +1807,9 @@ The following additional command keys are active while editing. (goto-char isearch-opoint)) (isearch-done t) ; Exit isearch.. (isearch-clean-overlays) + (when isearch--deactivated-mark + (setq isearch--deactivated-mark nil + mark-active t)) (signal 'quit nil)) ; ..and pass on quit signal. (defun isearch-abort () @@ -2446,6 +2473,27 @@ If search string is empty, just beep." ;; then it "used" the mark which we should hence deactivate. (when select-active-regions (deactivate-mark))) +(defun isearch-yank-region () + "Pull current active region text into search string. +The text in the active region is added to the search string if +variable `transient-mark-mode' is non nil." + (interactive) + (let ((region (and (use-region-p) + (funcall region-extract-function nil)))) + (if (and (stringp region) + (not (string-empty-p region))) + (progn + (when (string-empty-p isearch-string) + (goto-char (region-beginning))) + + (setq isearch--deactivated-mark t) + (deactivate-mark) + (isearch-yank-string region)) + + (setq isearch-error "Invalid region") + (isearch-push-state) + (isearch-update)))) + (defun isearch-mouse-2 (click) "Handle mouse-2 in Isearch mode. --7v5gouqlfdcerlz5--