From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ergus via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#39512: 28.0.50; Add command isearch-yank-region Date: Mon, 10 Aug 2020 03:19:54 +0200 Message-ID: <20200810011954.ro4utplq3ohpob2d@Ergus> References: <87eev52bw6.fsf@calancha-pc.dy.bbexcite.jp> <877e0wiosp.fsf@mail.linkov.net> <87v9hst5wv.fsf@gnus.org> <87mu33zchk.fsf@mail.linkov.net> Reply-To: Ergus Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34498"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Tino Calancha , npostavs@gmail.com, 39512@debbugs.gnu.org, contovob@tcd.ie, Lars Ingebrigtsen , eliz@gnu.org, drew.adams@oracle.com To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Aug 10 03:21:13 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 1k4wUx-0008o4-5R for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 10 Aug 2020 03:21:11 +0200 Original-Received: from localhost ([::1]:56866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k4wUv-0007eU-Vr for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 09 Aug 2020 21:21:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55530) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k4wUo-0007eC-S9 for bug-gnu-emacs@gnu.org; Sun, 09 Aug 2020 21:21:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50439) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k4wUo-0003SY-JO for bug-gnu-emacs@gnu.org; Sun, 09 Aug 2020 21:21:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1k4wUo-0004t5-GM for bug-gnu-emacs@gnu.org; Sun, 09 Aug 2020 21:21:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ergus Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 10 Aug 2020 01:21: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.159702240818701 (code B ref 39512); Mon, 10 Aug 2020 01:21:02 +0000 Original-Received: (at 39512) by debbugs.gnu.org; 10 Aug 2020 01:20:08 +0000 Original-Received: from localhost ([127.0.0.1]:33752 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k4wTw-0004rZ-Dp for submit@debbugs.gnu.org; Sun, 09 Aug 2020 21:20:08 -0400 Original-Received: from sonic316-12.consmr.mail.bf2.yahoo.com ([74.6.130.122]:44452) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k4wTt-0004qu-HJ for 39512@debbugs.gnu.org; Sun, 09 Aug 2020 21:20:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1597022400; bh=k7AahIZJxreQ9cDNkSvK1m/m7T+QQ/jZQ2A4EkTrUHI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From:Subject; b=hssOQAoeut1O6frLru6UexH2Z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M5SCiaEHOJzoPp Vx2z30fxTclSBkX7F43y2FqiACmx6mZRhqbPN8moJWsI.pKpb50HG3.4H2la8l.K32gCKGgHEf6x 3xt.IC42xkh1CoDFcIg05ZnBl06Z7MuBuuAknDa2IR Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic316.consmr.mail.bf2.yahoo.com with HTTP; Mon, 10 Aug 2020 01:20:00 +0000 Original-Received: by smtp425.mail.ir2.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID a7df0314bc331c1dd5cb49bfd66410bb; Mon, 10 Aug 2020 01:19:58 +0000 (UTC) Content-Disposition: inline In-Reply-To: <87mu33zchk.fsf@mail.linkov.net> X-Mailer: WebService/1.1.16436 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.aol Apache-HttpAsyncClient/4.1.4 (Java/11.0.7) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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:184469 Archived-At: On Mon, Aug 10, 2020 at 02:23:59AM +0300, Juri Linkov wrote: >>> Thanks for creating a new feature request that unlike these discussions >>> on emacs-devel won't fall into oblivion. >> >> This was in February, though, and the patch still hasn't been applied. :-/ >> >> I think this addition makes sense... was there any particular reason >> it's not applied? > >I really don't see a need for adding isearch-yank-region. I think that >isearch-forward-region proposed by Ergus should be sufficient because >typing 'M-s M-.' (bound globally to isearch-forward-region) even when >isearch mode is active, will exit Isearch and restart Isearch with the >contents of the still active region added to the search string. >This will cover all cases requested here with just one new command: > > (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)))) > > (define-key search-map "\M-." 'isearch-forward-region) Hi Juri: I didn't add this command to vanilla at the end because there were many arguments about the bindings to use. And I consider that without a default binding it is pretty much useless for the general user. Now I am using swiper which has an improved version for thing-at-point (something like `thing-at-point-or-region` called `ivy-thing-at-point`) which actually is much more useful and avoids an extra binding. https://github.com/abo-abo/swiper/blob/c6b60d34ac37bf4d91a25f16d22e528f85e06938/ivy.el#L426 Implementing something like that in vanilla is (in my opinion) the best default behaviors for isearch-forward-symbol-at-point. But I don't want to go in that discussion in the mailing list because it is difficult to get an agreement what touching old commands. But you are free to do it if you want. Something more or less like this should work: (defcustom isearch-thing-at-point-use-region nil "isearch-forward-symbol-at-point use region when active." :type 'boolean) (defun bounds-thing-at-pt-or-region () "Return current 'thing-at-point' or region bounds" (and (not (nth 3 (syntax-ppss))) ;; global skip (cond ((and isearch-thing-at-point-use-region (region-active-p)) (let* ((beg (region-beginning)) (end (region-end)) (eol (save-excursion (goto-char beg) (line-end-position)))) (and (< beg end) ;; no empty region (<= end eol) ;; no multiline region (cons beg end)))) ((find-tag-default-bounds))))) (defun isearch-forward-symbol-at-point (&optional arg) "Do incremental search forward for a symbol found near point. Like ordinary incremental search except that the symbol found at point is added to the search string initially as a regexp surrounded by symbol boundary constructs \\_< and \\_>. See the command `isearch-forward-symbol' for more information. With a prefix argument, search for ARGth symbol forward if ARG is positive, or search for ARGth symbol backward if ARG is negative." (interactive "P") (isearch-forward-symbol nil 1) (let ((bounds (bounds-thing-at-pt-or-region)) (count (and arg (prefix-numeric-value arg)))) (cond (bounds (when (< (car bounds) (point)) (goto-char (car bounds))) (isearch-yank-string (buffer-substring-no-properties (car bounds) (cdr bounds))) (when count (isearch-repeat-forward count))) (t (if isearch-thing-at-point-use-region (setq isearch-error "No symbol at point or active region.") (setq isearch-error "No symbol at point")) (isearch-push-state) (isearch-update))))) Best, Ergus