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 03:31:14 +0200 Message-ID: <20190429013114.l2igb3wk27qfew2d@Ergus> References: <20190427001453.isjx247kc3lu5fe4@Ergus> <87a7gcp51i.fsf@tcd.ie> <20190429004135.rn5tp2gnmbjovrxj@Ergus> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="wgthtlq5k5cl457q" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="66749"; 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 03:42:19 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 1hKvJC-000HEv-Id for ged-emacs-devel@m.gmane.org; Mon, 29 Apr 2019 03:42:19 +0200 Original-Received: from localhost ([127.0.0.1]:50548 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hKvJB-0004WS-6T for ged-emacs-devel@m.gmane.org; Sun, 28 Apr 2019 21:42:17 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:41177) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hKvHy-00045J-Kq for emacs-devel@gnu.org; Sun, 28 Apr 2019 21:41:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hKv8b-0001Dg-C8 for emacs-devel@gnu.org; Sun, 28 Apr 2019 21:31:22 -0400 Original-Received: from sonic303-21.consmr.mail.ir2.yahoo.com ([77.238.178.202]:34701) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hKv8b-0001DS-5b for emacs-devel@gnu.org; Sun, 28 Apr 2019 21:31:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1556501480; bh=wTa3JZCQid/FDkHnnJ8bg6U+Mezpm+WcOp+vewQWUuQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From:Subject; b=uKMmLctQhb2aVX/gIXbyTN72Zip/gz3yBMcr1+gbTJony7JuMev8WfdMaJl+dZVx0z6e5YsoErGCX421HOmV7zd/TEoa41h66Y3D5BQHAlL+oa0ILSXhs7Udt/4FCCg7Dv4+deieP6+oTMe5XYHc/QU9eahL+XVD1A1gCepZ/Z19rQSIDef2gD/I8DQ/LzKzxMlkJhY3miHmAUADRg1k59l5P9YPtqCBP1+Xu0s4RgoPlNbVzARMyEq0XJNnrbkshv7Cb2d4DSNFkcr6deGxRprBcuPI8eT9FPGZS2RjXaITrm+j5hUZrteNn2k6U0amkhniHOdZ4D5Rz8vg6UWEMw== X-YMail-OSG: ugsB0DoVM1lExipKUh11luTTvgYdfH1PwI9lzuJWOZPUZyXhyn9ZQzglNLz9ufo q9UyVRGVLAwqwfbfsZECerA1TImCFlEf.WH21cq3d3HMmJsCmzu3VnWPsTj2UESMKc7zQbkxid5R aaabxHtZ7zAF2nE4uxg7_fREZX6o9kEyCZvbMRbWezqt.zZatDWEeLYwIOdBU3bIpvdHRaMO0OJR fuHgpwDApGLwXsXyb89fg29wFlGr6COVFtmi11O_c8vLKSvZaT6BF8wnPNTOD.BRM1HBrBX7H9Ly UP4OdnvNYZGB3PM7Fo8PsuXduohunbbklb3lgYK1_NcFkN9suLsMGWuRqUGHYowGUi_6ZCHdJJJL vexbKIg50bsqHCNs94ZZjXL1ScYU4JU0HOpqmxe4NjXHgq.j38TvsV1Jb9MKxc2hQXqKsVvfjVwr eZt0u64JtWsSGr00HjuKBUruXJDuolclvgcXhKv6RQYNT0qWqMZNxXjFxfVmom7g5GV80wnp0C36 OAmnyqSUVQIIuL7CqMsXMXmgHEFEysO8QwHVpTXa8RV9jBkety_FPs4YI.kc6ZSuEG_6BNItw4fl TJqMYiOpiNxzSjlB74wiNRgCx1ocabMGqysdHD_spd5T11Nb1cmGhMM9VJfaG7LAdsO_61pdXxli Me.j6ZvfliYoc.SD1rohR48A1rPYzbV5SX0Wyw0Q6yPLjwZGLYXCVIPsQOtg_OsIyvT956eVoKo5 _Q4CTyrzI_4fjA0bTXHmGR7FgcBmAbxIlyhPKsngBWOk5XG5ZPA_GtsdvkqXZeuTW2P2vrCq3n_T KbxBH2s8xfT2v7c_P4lYAdRVFVrrbEYjAy1e68ukmx Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.ir2.yahoo.com with HTTP; Mon, 29 Apr 2019 01:31:20 +0000 Original-Received: from 2.152.205.184.dyn.user.ono.com (EHLO Ergus) ([2.152.205.184]) by smtp405.mail.ir2.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID a283e50e1fa93bb4747900f322baa6de; Mon, 29 Apr 2019 01:31:18 +0000 (UTC) Content-Disposition: inline In-Reply-To: <20190429004135.rn5tp2gnmbjovrxj@Ergus> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 77.238.178.202 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:236018 Archived-At: --wgthtlq5k5cl457q Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline On Mon, Apr 29, 2019 at 02:41:35AM +0200, Ergus wrote: >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 > >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. > --wgthtlq5k5cl457q 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..d5cfceb57c 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,22 @@ 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) + (string-empty-p isearch-string)) + + (let ((region-string (buffer-substring-no-properties + (region-beginning) (region-end)))) + (if isearch-forward + (goto-char (region-beginning)) + (goto-char (region-end))) + (isearch-yank-string region-string) + + (setq mark-active nil + isearch-deactivated-mark t))) + (isearch-update) (add-hook 'pre-command-hook 'isearch-pre-command-hook) @@ -1782,6 +1810,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 + mark-active t)) (isearch-clean-overlays) (signal 'quit nil)) ; ..and pass on quit signal. --wgthtlq5k5cl457q--