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 01:16:16 +0200 Message-ID: <20190430231614.l423x6eqta5fbhor@Ergus> References: <20190427001453.isjx247kc3lu5fe4@Ergus> <87a7gcp51i.fsf@tcd.ie> <20190429004135.rn5tp2gnmbjovrxj@Ergus> <87h8agy4yf.fsf@mail.linkov.net> <20190430162501.xmqh5r5h57sjjlq5@Ergus> <87h8af15kg.fsf@tcd.ie> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="100777"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: NeoMutt/20180716 Cc: emacs-devel@gnu.org, Juri Linkov To: "Basil L. Contovounesios" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed May 01 01:34:24 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 1hLcGW-000Q4x-2O for ged-emacs-devel@m.gmane.org; Wed, 01 May 2019 01:34:24 +0200 Original-Received: from localhost ([127.0.0.1]:55076 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLcGU-0006WK-V6 for ged-emacs-devel@m.gmane.org; Tue, 30 Apr 2019 19:34:23 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:34548) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLcBH-0002xJ-6m for emacs-devel@gnu.org; Tue, 30 Apr 2019 19:29:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hLbz4-0001hV-PE for emacs-devel@gnu.org; Tue, 30 Apr 2019 19:16:24 -0400 Original-Received: from sonic310-12.consmr.mail.ir2.yahoo.com ([77.238.177.33]:38206) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hLbz4-0001gx-Ap for emacs-devel@gnu.org; Tue, 30 Apr 2019 19:16:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1556666180; bh=A7f29j6wnNd8zsdk9W+jv4objMGoPZF5N0ZnZaX6FWE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From:Subject; b=uRdxxm1msC6FH8n1kiNqiO0c4KdH9k6akUjiliLzB9ne4m9M4W/CgjZiIH1FfhW9t/RgII/sGhA+KvYIb3ocoRnAdiUlk00HMmm9qN8YeBUbpAaoUpuDCz3FsJteL0ie+lJ2utIfOob3+QVr6Rm3fapjHZafv6nTgueAkzCaLcMI8ysMqjZT5P2MHBBjyXMBFJvKc8YYKgk0RN2Vd6vayKsjniidTcN8i25I7vNNZ6qH3azOHfMqY4TZxtBg9+DXM+WA5tG4FGxmqtF8w7zdKEmSTniOFX9vNudb0uGnItxDmZq5EhKe6dmL0PWSveSy7eabKb154ijiaLX/NrcifQ== X-YMail-OSG: f5Ym0OoVM1l57wZfWzjIUG6VxIFiSj1.I6T6VRRoqjPKrCLAj8Uvb1tTRqBK4zf 6zwa0cb5L.QYQwmdSO4kplICGJK1XMRMFFoELc1R4TDFAgBV8.KTq8Myj_xNVP_BwMZPZNAnGDVz 50Ba76UQHa1e.aZfELHjBP01z9bODCBozPrc7glQpyOxcGFiW9YmnSQP32UagnDyH_4rzltg76wh 8MbB9bixtcQ4k2JoXzsVf_wG7DA3LAHumJNOVGc1tuHtbGAyrLTO9yJYbcn6Umtc55MifpH4wJ5S Mb3oYlIo406MsbCz0o4F9C.9Pv3.NBWzpaiUxGntHiGbQs91bOCBHL8_1GcBsChAWVbLtuONJM6q ZD9haot9yn7laORqfaHfli2njQPJhp6siEHR5iNXL3fsFsWMUJM96IbJuCg01sObzA9P7XfuyZny PHSmekdfsWwakNh6tBV2XP3UGQUI5dwObMR8hN1djcu04jzUIYYYhfRmWCdcH.7pFM2ZaLYOfvy0 Qnnq60u85fkR.2nwVQZLOrP_M4ZqH_PmQ6jYR9AcIDzxoqNMHBjo2m8_CwZzB3W6TWa0fzdMBF8b dzMFuc0mFYHiOk9YxZRKAOxcsKZ.7mZoN9iU8J5A5zZkbHCcf7s8blBETC4VcDUAKLFGpQRgqn63 BxIlWwHfp5DYpDehQlIZ4PB013dDF1uPX2zcKvrJ7.VL__sH0IZNa1MhreQ8ygl5TaEq1UmgyxGA C_o15Qd2JA9R3p9PoLSYMKddOaee93Y9z7fu0mnq0uwPV3ZOhiOm_fjppY7gNVLfGbtyVp_p7ro. XBTmi3tN8_hWdeUDu6IZh5LOvRQ1y69Uy_vTiJZSMg Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.ir2.yahoo.com with HTTP; Tue, 30 Apr 2019 23:16:20 +0000 Original-Received: from 2.152.205.184.dyn.user.ono.com (EHLO Ergus) ([2.152.205.184]) by smtp423.mail.ir2.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 5f2acbcd27bcb088735ae155f7ff01dc; Tue, 30 Apr 2019 23:16:19 +0000 (UTC) Content-Disposition: inline In-Reply-To: <87h8af15kg.fsf@tcd.ie> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 77.238.177.33 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:236082 Archived-At: On Tue, Apr 30, 2019 at 11:39:11PM +0100, Basil L. Contovounesios wrote: >Ergus writes: > > >Thanks, I have some questions and minor comments: > >> (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 variable >> `transient-mark-mode' is non nil. > >Perhaps "if `transient-mark-mode' is enabled" instead. > >> See the command `isearch-forward-symbol' for more information. > >Which information is that? Why not refer to isearch-forward instead? > Yes, The docstring was not finished actually, I was just trying the code functionality.. > >> (interactive "P") >> (isearch-forward nil 1) >> (if-let* ((bounds (and (use-region-p) ;; Region and transient non-nil > >RHS comments usually start with a single semicolon; >see (info "(elisp) Comment Tips"). I will delete those comments > >> (string-empty-p isearch-string) > >Why must this be empty? > This is a condition I will change. The idea is that if the search-string is empty in this moment we need to goto the region-beginning, That's a latter change I will make. >> (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. > >Also, you shouldn't leave bound symbols unused. The most common way to >short-circuit conditionals is via the special forms 'and' and 'or'. >In the case of if-let et al., you can also use the following syntax: > > (if-let* ((len (length foo)) > ((zerop len))) > 'empty > 'nonempty) > >> (region-beg (car (car bounds))) >> (region-end (cdr (car bounds))) > >Nitpick: caar/cdar, also not important. > >> (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. >> (noempty (not (string-blank-p region-string)))) > >Why can't the search string be blank? > >> (progn >> (goto-char region-beg) >> (setq mark-active nil >> isearch--deactivated-mark t) > >Where is isearch--deactivated-mark defined? What does it do? >Shouldn't this set/call deactivate-mark or similar instead? > This is somewhere else, but I did't included it here because is was not related with the issue I had >> (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. > >> (setq isearch-error "Invalid region for isearch") >> (isearch-push-state) >> (isearch-update))) > >Here's a suggestion which addresses some of my comments: > >(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) > (let ((region (and (use-region-p) > (string-empty-p isearch-string) > (funcall region-extract-function nil)))) > (cond ((and (stringp region) > (not (string-empty-p region))) > (goto-char (region-beginning)) > (deactivate-mark) > (isearch-yank-string region) > (when arg > (isearch-repeat-forward (prefix-numeric-value arg)))) > (t > (setq isearch-error "Invalid region") > (isearch-push-state) > (isearch-update))))) > >Feel free to adapt it as you please. > >Thanks, > >-- >Basil