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: Mon, 29 Apr 2019 02:41:35 +0200 Message-ID: <20190429004135.rn5tp2gnmbjovrxj@Ergus> References: <20190427001453.isjx247kc3lu5fe4@Ergus> <87a7gcp51i.fsf@tcd.ie> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="27d2gxpr5jwkxf5b" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="77341"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: NeoMutt/20180716 Cc: emacs-devel@gnu.org To: "Basil L. Contovounesios" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Apr 29 02:42:42 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 1hKuNV-000Jy3-Lt for ged-emacs-devel@m.gmane.org; Mon, 29 Apr 2019 02:42:42 +0200 Original-Received: from localhost ([127.0.0.1]:50105 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hKuNU-0004MO-Gq for ged-emacs-devel@m.gmane.org; Sun, 28 Apr 2019 20:42:40 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:34500) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hKuMg-0004MD-0w for emacs-devel@gnu.org; Sun, 28 Apr 2019 20:41:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hKuMd-0006tW-Qg for emacs-devel@gnu.org; Sun, 28 Apr 2019 20:41:49 -0400 Original-Received: from sonic306-21.consmr.mail.ir2.yahoo.com ([77.238.176.207]:45808) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hKuMd-0006sV-Ab for emacs-devel@gnu.org; Sun, 28 Apr 2019 20:41:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1556498504; bh=KaQz7GFMBgSYinNRg9YzI+C3OHxgteMKzbVUuJ3RCTo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From:Subject; b=c58BuswfulPlnkq+pWhcWuF/jtATTT4sp1qkjfjHMPQwF7EUGkBZGaMKSx8MOEPyLT7ppJR38LWojWWdTe7aDxhCNGF6bhuycec6nQZ7J1rP2ZwegrKRRPmk8USweg+SvXvuQwVf2nQ2B2W7cZZsPzNteGSMuc4B/WXlG29DuxgtYKhMrNU7GF1Pdk1fUVMYZ5WickqektfxGKe9NVRbSaXnbn3//ePC6wTLvzxrvAkdd+IWyk3bYoG/afPtQ4NdmVcaWRsOOSqyld6RNj5XEMeQnZ0ZPjz83xh4+L5e7oCO5iheEDMfGt55eQOzKfCeXPU0ADWf0U1Tmeu30Nr9nw== X-YMail-OSG: TCx27WgVM1neIPclstV8fsFE2_P0.3KbEhzIXIbZY5ea3xvbtdqEImlc4eivbiW XDJWWIV3YSW2wQrISL0o5KTPGtT6soViUaD9GB8JMnQYKS2E1KWIHw_P_9RG039.llMDm.dwPwNp DT3mel3.8jLez0S.msVCyTAdEHw32Vndlpmvm4joWx5JZJbai.Oza2zqqAyR4HpARmY_37jN4Teo y6fdr5Xct3Mc3u2dL2I5jVfMDBuOP27BGPrVIrOipY70WsFnNOEpC5_XIQ230G4sC_qBaGB32puH lmExBt8Q6lO0PiJvUQ0BN52kZKhjGGwOyMZy6YsqiEx1CfEDRvnZI9xRhkc5yTeQA1LYvbsE6b8Z _2puPenG9ZlS_1YQxZe3Ok7hPn7vYPu1qi8ygaUwDqr6tY_qW4M.AKJKGf9WrsA0mlozmGe_FUYS ZoihDOmZahR3oKvYfl9LzRffDMKbOrrAMj9pZU9v1U6KNryvJT5B4Th1Ii1DAPPgV4gylnafehQ6 BWt_cJ1CCEORev2NVtFZ2NikUFqBjRoBp9mNv3xABM0vyDQJ9J5b13vczXzdwshi.b2ZodEvgop6 CXal_3GmxcxrXJyaOPo1_SkC6CflZUlJAXVsxQgaUDaJXOcqwbNVR7Rat7t9jZDsdFWemXfwN_qa AOaJPBZb45R45DDa_bq95GwD5MjYGPEvWqRwpPezXXOW_CwUFJXgz3o8O20W0ml9ua1l7bejmQYy 2IOV0nUul_g9OX0RX75SBdS2uQ0oAUkIpLuemIK9r_NQomsajk9xuZiMqEyzIZRO3ViwCJ2kTzsN OGvEcBQsAWinbXGmXwbbMwFGNoJdigoRT3oWStnfEo Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.ir2.yahoo.com with HTTP; Mon, 29 Apr 2019 00:41:44 +0000 Original-Received: from 2.152.205.184.dyn.user.ono.com (EHLO Ergus) ([2.152.205.184]) by smtp404.mail.ir2.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID ee95810b603bfda72bc41e480de8e664; Mon, 29 Apr 2019 00:41:40 +0000 (UTC) Content-Disposition: inline In-Reply-To: <87a7gcp51i.fsf@tcd.ie> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 77.238.176.207 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:236017 Archived-At: --27d2gxpr5jwkxf5b Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline On Sat, Apr 27, 2019 at 03:15:21AM +0100, Basil L. Contovounesios wrote: >Ergus writes: > >> I am looking in the manual for two isearch functionalities that maybe >> are already implemented, but I don't find them. Else maybe it is not >> so complex to do in elisp (at least for my config) And you could suggest >> a right way to implement it. >> >> 1) isearch-yank-thing-at-point, this should be similar to >> isearch-yank-word, but if the cursor is in the middle of a word >> it may insert the whole word not just the rest of the current word. >> >> (swiper provides this with M-n) > >The closest to this that I'm aware of is >isearch-forward-symbol-at-point, bound to 'M-s .' by default. > >> 2) In "transient-mark-mode" if the region is active before C-s, the >> initial input could be the text in the region. Is it there a way to >> enable that behavior? >> >> An alternative for this is a command that yanks the region's text in the >> minibuffer when isearch is active so we could bind it in the isearch-map >> (for example to M-f). >> >> Are some of these already implemented? > >I'm not familiar with any built-in versions of the rest of the >functionality you describe, but I'm no expert. If it is indeed not >currently present, I for one would welcome such additions. > >Thanks, > >-- >Basil > Hi Basil: I just made a small change in isearch.el to enable region text auto insertion in transient-mark-mode. (patch attached) I did it as simple as I could. So please if you (or any anyone) could give a look and correct/improve/expose corner cases, or suggest a better implementation will be very nice. I don't have corner cases right now, but I just started testing it. So any correction/suggestion/recommendation is very appreciated. Thanks in advance, Ergus --27d2gxpr5jwkxf5b Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="isearch-autoinsert.patch" diff --git a/lisp/isearch.el b/lisp/isearch.el index 6280afebdc..3de0493c8a 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -413,6 +413,17 @@ and doesn't remove full-buffer highlighting after a search." :group 'lazy-count :version "27.1") +(defcustom isearch-autoinsert-region nil + "If non-nil, the text in the region will be auto-inserted for searching. +This works only if the variable `transient-mark-mode' is enabled +and the region is active." + :type 'boolean + :group 'isearch + :version "27.1") + +(defvar isearch-deactivated-mark nil + "If for some reason isearch removed the mark on start.") + ;; Define isearch help map. @@ -1205,7 +1216,8 @@ used to set the value of `isearch-regexp-function'." ;; 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) + minibuffer-message-timeout nil + isearch-deactivated-mark nil) (if (local-variable-p 'tool-bar-map) (setq isearch-tool-bar-old-map tool-bar-map)) @@ -1244,6 +1256,15 @@ used to set the value of `isearch-regexp-function'." ;; `isearch-push-state' to save mode-specific initial state. (Bug#4994) (isearch-push-state) + (when (and isearch-autoinsert-region ;; Check option + (use-region-p) + (not (region-noncontiguous-p)) + (= (count-lines (region-beginning) (region-end)) 1)) + (isearch-yank-string + (buffer-substring-no-properties (region-beginning) (region-end))) + (setq mark-active nil + isearch-deactivated-mark t)) + (isearch-update) (add-hook 'pre-command-hook 'isearch-pre-command-hook) @@ -1782,6 +1803,9 @@ The following additional command keys are active while editing. (isearch--set-state (car isearch-cmds))) (goto-char isearch-opoint)) (isearch-done t) ; Exit isearch.. + (when isearch-deactivated-mark + (setq isearch-deactivated-mark nil + activate-mark t) (isearch-clean-overlays) (signal 'quit nil)) ; ..and pass on quit signal. --27d2gxpr5jwkxf5b--