From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Karl Fogel Newsgroups: gmane.emacs.devel Subject: Re: PATCH: isearch-yank-until-char Date: Sat, 24 Aug 2019 21:14:51 -0500 Message-ID: <877e7256uc.fsf@red-bean.com> References: <87tvakfnv4.fsf@red-bean.com> <87lfvvjxjs.fsf@mail.linkov.net> <87sgq1r9rb.fsf@red-bean.com> <87lfvt6m1e.fsf@mail.linkov.net> Reply-To: Karl Fogel Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="33759"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: Emacs developers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Aug 25 04:15:12 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.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1i1i3j-0008ef-NW for ged-emacs-devel@m.gmane.org; Sun, 25 Aug 2019 04:15:11 +0200 Original-Received: from localhost ([::1]:40090 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1i3h-0001FB-KR for ged-emacs-devel@m.gmane.org; Sat, 24 Aug 2019 22:15:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35161) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1i3U-0001F0-8M for emacs-devel@gnu.org; Sat, 24 Aug 2019 22:14:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i1i3S-0001NE-Rd for emacs-devel@gnu.org; Sat, 24 Aug 2019 22:14:56 -0400 Original-Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]:37361) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i1i3S-0001MY-Je for emacs-devel@gnu.org; Sat, 24 Aug 2019 22:14:54 -0400 Original-Received: by mail-io1-xd36.google.com with SMTP id q22so29174885iog.4 for ; Sat, 24 Aug 2019 19:14:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:references:reply-to:date:in-reply-to :message-id:user-agent:mime-version; bh=6l0tVHoSfxtOK8RYTKCgComg9ogLyG5BrjjKXrayoWE=; b=BE5dgWqvetg05SZ8WxrfAaFpaWk/Wv/EuA2Jfs8FRbEZDQhnV+wYYnRSNnQeSK85AH RvcIS8OjFJYgsQIPgXoQoH2qWRJBUW/UAHoG2nYLZ3yoB3NDvRaB1d325GmXiWnneb/6 9gW6BLgMiDLU2bVOjfp9fB1gjSEQpzVsIrakD1xJaDwo5vSPasB+WUThKtu7kFaGpIi0 HL8/XWPC/1V5ZjzVV10OBK3tpF8hUmdCjUiLXREf2WZr95ZA4TRY30bnbkidVRbGRWLn dQztv85Ze2bF9KcvfXddJSmqzpniSCGpOcgND0vSmWBQL4ivP4NKSv2oWLfjwDBz80qG gT2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:references:reply-to:date :in-reply-to:message-id:user-agent:mime-version; bh=6l0tVHoSfxtOK8RYTKCgComg9ogLyG5BrjjKXrayoWE=; b=PUUeFvTFO7KBbdERvKPNUKICchGPEKdRSohs6PX1/MCz2+XOgUo6PiwdZeMOZKiqDo Fd3EtWJvpnwdjrz0i+lY4RDDgRGrNs5GsNWqp+8OKj8QkIvdQmO4Hid5RtrgbAqGW0Dv zGMK06m/BAVLQ+OJuG4bzHUwaWB45Z9M3b3zz+D93jwifCP/t09wcMv4CmHnDhKtegtZ EgVIzd7kQ9QbsvnUAyDvGztrjyG/ljXJXb9/ow0APQzJYU8ElxfpWnf6GFfufb52PLy1 5Wzk+y/Za3tvO5ukUXi88B58Kk4IlwROdnpp34Yb1MYU6MBDBuw3NMDL+AkCjLST6Ouu konQ== X-Gm-Message-State: APjAAAXoG7xK5nioSjEYxuHYyXns494TZooQJv0VEeqMZ4tYFreu5lJn n/caBGSfM/PtxBOQu53k1SRD2+mh X-Google-Smtp-Source: APXvYqwbCKVJue4s/mv0Ki9WJko8tJQ3pi8ntNyjUp99ci8XbCZ9EhS3SxF/01TPSYDFoJxdyGXTzQ== X-Received: by 2002:a6b:90c3:: with SMTP id s186mr17376623iod.114.1566699293358; Sat, 24 Aug 2019 19:14:53 -0700 (PDT) Original-Received: from klen ([2601:240:cb00:9d51::80a0]) by smtp.gmail.com with ESMTPSA id j16sm6799414iok.34.2019.08.24.19.14.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Aug 2019 19:14:52 -0700 (PDT) In-Reply-To: <87lfvt6m1e.fsf@mail.linkov.net> (Juri Linkov's message of "Fri, 16 Aug 2019 20:52:21 +0300") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::d36 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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:239541 Archived-At: --=-=-= Content-Type: text/plain On 16 Aug 2019, Juri Linkov wrote: >>> Should your new command catch this error? >> >> It could. I'm not sure exacly what to do with the error, though. >> The new version below displays a brief message and then returns to the >> isearch prompt: >> >> This feels klugey, but I'm not sure what a better way is. Do you have >> any ideas? > >Isearch used to catch errors and display the error message >at the end of the isearch message by setting `isearch-error'. >Why it doesn't do this now, I don't know, this needs more investigation. >Maybe just setting `isearch-error' to the error message would help. Well, I tried setting `isearch-error' in the error case -- instead of using `message' as the current patch does -- but it didn't seem to have any useful effect. I just got the "I-search:" prompt back immediately, with no indication that the character I had typed was not found. Then I tried keeping the current `message' code and *also* setting `isearch-error', but that seemed to have no effect either. The result was exactly the same as the current message behavior. So I've left the code as-is; the current patch is attached here. Do we have consensus to install it? I don't have a good sense of whether there's consensus yet. We had some discussion about what keybinding to use within isearch, but (I think) the outcome was that M-C-c was an okay choice. We also seemed to agree that the current way of handling the "char not found" error is a bit klugey, but we don't know a better way to do it (or at least I don't know a better way). (Through the discussion, thanks to you Juri, I also learned about the more general `isearch-yank-on-move'. For those who deliberately choose that behavior and won't be confused by it, it's pretty neat! But I think it's orthogonal to this patch, since the point of this patch is to add a transparent new behavior within traditional isearch -- that is, a behavior that won't get in the way or cause any surprises for those who don't learn about it.) Best regards, -Karl --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=isearch-yank-until-char-20190824.txt [[[ Add `isearch-yank-until-char' * lisp/isearch.el (isearch-yank-until-char): New function. (isearch-mode-map, isearch-menu-bar-yank-map): Add it. (isearch-forward): Document the new binding. * doc/emacs/search.texi (Isearch Yanking): Document the feature. * etc/NEWS: Mention the above. ]]] --- doc/emacs/search.texi +++ doc/emacs/search.texi @@ -262,11 +262,17 @@ Isearch Yank @kindex M-s C-e @r{(Incremental search)} @findex isearch-yank-line - Similarly, @kbd{M-s C-e} (@code{isearch-yank-line}) appends the rest + @kbd{M-s C-e} (@code{isearch-yank-line}) appends the rest 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 C-M-c @r{(Incremental search)} +@findex isearch-yank-until-char + Similarly, @kbd{C-M-c} (@code{isearch-yank-until-char}) appends to +the search string everything from point until the next occurence of +a specified character (not including that character). + @kindex C-y @r{(Incremental search)} @kindex M-y @r{(Incremental search)} @kindex mouse-2 @r{in the minibuffer (Incremental search)} --- etc/NEWS +++ etc/NEWS @@ -1202,6 +1202,10 @@ highlight in one iteration while processing the full buffer. +++ *** New isearch bindings. +'C-M-c' invokes new function 'isearch-yank-until-char', which yanks +everything from point to the specified character into the search +string. + 'C-M-w' in isearch changed from 'isearch-del-char' to the new function 'isearch-yank-symbol-or-char'. 'isearch-del-char' is now bound to 'C-M-d'. --- lisp/isearch.el +++ lisp/isearch.el @@ -514,6 +514,9 @@ isearch-menu-bar-yank-map (define-key map [isearch-yank-kill] '(menu-item "Current kill" isearch-yank-kill :help "Append current kill to search string")) + (define-key map [isearch-yank-until-char] + '(menu-item "Until char..." isearch-yank-until-char + :help "Yank from point to specified character into search string")) (define-key map [isearch-yank-line] '(menu-item "Rest of line" isearch-yank-line :help "Yank the rest of the current line on search string")) @@ -705,6 +708,7 @@ isearch-mode-map (define-key map "\M-\C-d" 'isearch-del-char) (define-key map "\M-\C-y" 'isearch-yank-char) (define-key map "\C-y" 'isearch-yank-kill) + (define-key map "\M-\C-c" 'isearch-yank-until-char) (define-key map "\M-s\C-e" 'isearch-yank-line) (define-key map "\M-s\M-<" 'isearch-beginning-of-buffer) @@ -998,6 +1002,8 @@ isearch-forward Type \\[isearch-del-char] to delete character from end of search string. Type \\[isearch-yank-char] to yank char from buffer onto end of search\ string and search for it. +Type \\[isearch-yank-until-char] to yank from point until the next instance\ + of a specified character onto end of search string and search for it. Type \\[isearch-yank-line] to yank rest of line onto end of search string\ and search for it. Type \\[isearch-yank-kill] to yank the last string of killed text. @@ -2562,6 +2568,21 @@ isearch-yank-word (interactive "p") (isearch-yank-internal (lambda () (forward-word arg) (point)))) +(defun isearch-yank-until-char (char) + "Pull everything until next instance of CHAR from buffer into search string. +Interactively, prompt for CHAR." + (interactive "cYank until character: ") + (isearch-yank-internal + (lambda () (let ((inhibit-field-text-motion t)) + (condition-case nil + (progn + (search-forward (char-to-string char)) + (forward-char -1)) + (search-failed + (message "`%c' not found" char) + (sit-for 2))) + (point))))) + (defun isearch-yank-line (&optional arg) "Pull rest of line from buffer into search string. If optional ARG is non-nil, yank the next ARG lines." --=-=-=--