From unknown Wed Jun 18 23:18:38 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#29821 <29821@debbugs.gnu.org> To: bug#29821 <29821@debbugs.gnu.org> Subject: Status: eshell: Ensure quick substitution only occurs at start of line Reply-To: bug#29821 <29821@debbugs.gnu.org> Date: Thu, 19 Jun 2025 06:18:38 +0000 retitle 29821 eshell: Ensure quick substitution only occurs at start of line reassign 29821 emacs submitter 29821 Jay Kamat severity 29821 normal tag 29821 fixed thanks From debbugs-submit-bounces@debbugs.gnu.org Fri Dec 22 18:57:27 2017 Received: (at submit) by debbugs.gnu.org; 22 Dec 2017 23:57:27 +0000 Received: from localhost ([127.0.0.1]:48473 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eSXBt-00062v-Ei for submit@debbugs.gnu.org; Fri, 22 Dec 2017 18:57:25 -0500 Received: from eggs.gnu.org ([208.118.235.92]:36285) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eSXBr-00062h-C4 for submit@debbugs.gnu.org; Fri, 22 Dec 2017 18:57:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eSXBk-0006O6-JF for submit@debbugs.gnu.org; Fri, 22 Dec 2017 18:57:17 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:56744) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eSXBk-0006Nu-Es for submit@debbugs.gnu.org; Fri, 22 Dec 2017 18:57:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55486) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSXBj-0006n5-2J for bug-gnu-emacs@gnu.org; Fri, 22 Dec 2017 18:57:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eSXBg-0006L0-18 for bug-gnu-emacs@gnu.org; Fri, 22 Dec 2017 18:57:15 -0500 Received: from mail-pf0-x235.google.com ([2607:f8b0:400e:c00::235]:32787) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eSXBf-0006Jh-O0 for bug-gnu-emacs@gnu.org; Fri, 22 Dec 2017 18:57:11 -0500 Received: by mail-pf0-x235.google.com with SMTP id y89so15880580pfk.0 for ; Fri, 22 Dec 2017 15:57:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:message-id:date:user-agent:mime-version; bh=6VUoQ4HSNBP6sVqJ/8A4OMNi60H3rmjrs9bV5P+dVVw=; b=TiLZ7J2aQJtU5T2YWCvjvAhJDDtV5T8MjjYmXD3w8YtuipDlQUSEdFkTt4F3TFMWwL 25IrcEe6LOBU8hcCR5vYYfcCDMfTMSr0rB+CtyD8g+j17Bp+PbiN3Yr30DHKd0EcPsge 1oAbdsNQBsG7ieVwZyuGRc7k1Bjyg2Bm+GOBVIZE++vU4VrxHXZt94qKTKPg3sWsyIB2 msk9arqgeuqTUaE9EisGhyg19aIwzU0Ir90+kYlZXileYeZhL6Psb3XatS0UamESfT8w Pb+/LfMwt73D8wNuo33Abv2SkUN3hs4PuGw0lDEda9wOczncKLXM+i/ccao3O+32wQF3 uWVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:message-id:date:user-agent :mime-version; bh=6VUoQ4HSNBP6sVqJ/8A4OMNi60H3rmjrs9bV5P+dVVw=; b=V/HzgXbxb0Ij5gpVHgQfY76Ah+8JyhVnOf11z5dW/F2U3AcqQNxbkBjNgIQRww+SRM Hla+j7wHOdkdXeKe4bNfaNyUqpo6TxAKOZ/1HbuwsI+DDlsznwE7nUkikuIV13dyn6US 78Hfn9FZEHFp30AIHBaLaHoMLSvrrDge712ZoK5SmezHRO2L++8D2ICVznB3Hc3FNfwL nQz6NqyR+mM3YD8+TIGijcaNkNVj3e71p+TsShSaTQsHNyIyIglIMMV9kvnXVzcJpphR Yw2jwCDK2ixDsSfivr/K58I85gUwhrAIDYYyLNsJ/Zz6rt9y9gT+l6kjN7MOb0rcN2im /Yqg== X-Gm-Message-State: AKGB3mLy/f84I83O42c4s5RUYv21D9DHiGKzVwpLJ4hGm8jlklZAgzOm +g6aO0K6g7LngfYMSiQwtW248bOD X-Google-Smtp-Source: ACJfBovcCpFAbJrd+nIRujVnBDVN3N2yzMS0TYt/yNcGc0z3KxPa+Th2LMO8uYzBCUt6LfB9yjk5Lg== X-Received: by 10.99.143.67 with SMTP id r3mr13970609pgn.224.1513987030050; Fri, 22 Dec 2017 15:57:10 -0800 (PST) Received: from laythe (c-67-161-9-47.hsd1.ca.comcast.net. [67.161.9.47]) by smtp.gmail.com with ESMTPSA id s68sm46805900pfj.81.2017.12.22.15.57.09 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Dec 2017 15:57:09 -0800 (PST) From: Jay Kamat To: bug-gnu-emacs@gnu.org Subject: Ensure quick substitution only occurs at start of line Message-ID: <87fu8272h6.fsf@gmail.com> Date: Fri, 22 Dec 2017 15:57:08 -0800 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi! I'm filing this separately from #29157, because I think that issue got a bit overloaded with multiple eshell problems and is very hard to follow. I recently noticed the changes in #29157, and I'm disappointed that we came to the conclusion to disable history expansion completely. I find it's rather useful, especially for things like: $ mv one.txt two.txtt # whoops! $ mv !!:$ two.txt This is preferred (in my opinion) over lisp functions to keep muscle memory working between shells. If anything, I would suggest disabling quick substitution (as I don't find it more useful than using history directly most of the time) I've created a patch to try to fix the bug found in #29157, which was: > echo $PATH | sed "s/[^o]foo[^o]/bar/g" > Unknown predicate character =E2=80=98b=E2=80=99 The fix is rather simple, it simply limits the quick substitution to the start of the line only (as observed in bash, as Andreas noted in the previous thread). I hope that we reconsider the decision to disable history expansion by default, it's a nice feature of eshell (which I have another patch I would like to submit later to try to expand it's functionality a bit more). Please let me know if you think this is a poor way of solving this issue (or if anything else seems wrong or missing), and I'll try to follow up. Thanks, -Jay --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Prevent-expansion-of-quick-substitutions-when-not-at.patch >From 2c14085989a1edb5d3420150dcf91bc0914f012b Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Fri, 22 Dec 2017 15:34:44 -0800 Subject: [PATCH] Prevent expansion of quick substitutions when not at start of line See bug #29157 for an initial report * lisp/eshell/em-hist.el (eshell-expand-history-references): Calculate and send a start-of-line variable to eshell-history-reference (eshell-history-reference): Use start-of-line variable to force expansion of quick substitutions only on start of line --- lisp/eshell/em-hist.el | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lisp/eshell/em-hist.el b/lisp/eshell/em-hist.el index df462a7058..9561d8b988 100644 --- a/lisp/eshell/em-hist.el +++ b/lisp/eshell/em-hist.el @@ -588,8 +588,9 @@ eshell-expand-history-references (pose (nreverse (nth 2 result)))) (save-excursion (while textargs - (let ((str (eshell-history-reference (car textargs)))) - (unless (eq str (car textargs)) + (let ((str (eshell-history-reference (car textargs) + (not (cdr-safe textargs))))) + (unless (eq str (car textargs)) (goto-char (car posb)) (insert-and-inherit str) (delete-char (- (car pose) (car posb))))) @@ -630,7 +631,7 @@ eshell-complete-history-reference (setq history (cdr history))) (cdr fhist))))))) -(defun eshell-history-reference (reference) +(defun eshell-history-reference (reference start-of-line) "Expand directory stack REFERENCE. The syntax used here was taken from the Bash info manual. Returns the resultant reference, or the same string REFERENCE if none @@ -638,7 +639,8 @@ eshell-history-reference ;; `^string1^string2^' ;; Quick Substitution. Repeat the last command, replacing ;; STRING1 with STRING2. Equivalent to `!!:s/string1/string2/' - (if (and (eshell-using-module 'eshell-pred) + (if (and start-of-line + (eshell-using-module 'eshell-pred) (string-match "\\^\\([^^]+\\)\\^\\([^^]+\\)\\^?\\s-*$" reference)) (setq reference (format "!!:s/%s/%s/" -- 2.11.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sun Dec 31 19:33:32 2017 Received: (at 29821) by debbugs.gnu.org; 1 Jan 2018 00:33:32 +0000 Received: from localhost ([127.0.0.1]:59114 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eVo2m-0000WD-3o for submit@debbugs.gnu.org; Sun, 31 Dec 2017 19:33:32 -0500 Received: from mail-it0-f52.google.com ([209.85.214.52]:45972) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eVo2j-0000Vs-Of for 29821@debbugs.gnu.org; Sun, 31 Dec 2017 19:33:30 -0500 Received: by mail-it0-f52.google.com with SMTP id z6so35671469iti.4 for <29821@debbugs.gnu.org>; Sun, 31 Dec 2017 16:33:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=dETnxQmA3L44CUEhynSUVjE6MD9sBTp7NFNEJZT4FSA=; b=XLHHnau686QsFX7zTqCRSTWNOg1xKhfvI1GnAFvyTlRbk0zqUrv4oTCzfA0UlB+L1U DsGyLktnoULhUh3GCfzl5DxZ5AA4/HNNecsw/Y7egH2QY4YwmygU70YM6yzQ1Lswq5wB r3WVF7RbkW/PhY2+EYRnMMeeiv8ncoxOqPd1yI15KOKqkv2ufJ2cExld0BBDdiGXeTt/ CWuO0mjs3OLhjOcUTW08HZH9nJhLRg46q4gas6As1hXHIkaEROOtnwovR7B63If0FdDO RBxBWSrbA9Y2g8DUBaD8uUnsjbWoLvgQeViKku4yC4Xnb62LK4KRdHDY5y/b6WZJCIAI 7b5Q== 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:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version :content-transfer-encoding; bh=dETnxQmA3L44CUEhynSUVjE6MD9sBTp7NFNEJZT4FSA=; b=hwtfGUDAw8WueYO4tr2R8rvcYREZytpl0LLFzZwL4dGVmqQ9KYZeaBG43+fqgpWu6p cSJLK2ZOwyiQMh4Rwp/VFLWAc/yDz78EyjTzoMU/tUTIZ5B0nCR0SLUM8R0epe+0rsyH qahfZht5VbvH/OhlBlq4nv31rmd7X2IhjS1+95KoFc+boQyVbgY5fU5QuWvZxlqhV6+z BbyShzj7ROH3Iajfw7TPGb1/BdZpNF1+Yxhnq/IzRAX6lfSFonLKjXFdBfxnVHyj4T5+ EW1ls1Tj5WbwTWkJ7WoYT92URny/Yp6fXjfoZgukp4iqd5lDo46AITpOM0ZF4PQecvb1 jhsw== X-Gm-Message-State: AKGB3mIIy7NCeah2CKMegLMQVyRLeHybY1FmXHH49uJhsKrvJEcUbpQk nNOHd9b2yvtR1kXGOy9IY3iLDw== X-Google-Smtp-Source: ACJfBouMV1SGnfz1NF/GIl0pvkcz31qMLt0VR4oQo6t/MD+U9d7BGRTE3WQjNr9Ei9GDELH92PkxLQ== X-Received: by 10.36.10.135 with SMTP id 129mr55706179itw.145.1514766803885; Sun, 31 Dec 2017 16:33:23 -0800 (PST) Received: from zebian ([45.2.119.34]) by smtp.googlemail.com with ESMTPSA id 139sm3921337itm.2.2017.12.31.16.33.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 31 Dec 2017 16:33:22 -0800 (PST) From: Noam Postavsky To: Jay Kamat Subject: Re: bug#29821: Ensure quick substitution only occurs at start of line References: <87fu8272h6.fsf@gmail.com> Date: Sun, 31 Dec 2017 19:33:20 -0500 In-Reply-To: <87fu8272h6.fsf@gmail.com> (Jay Kamat's message of "Fri, 22 Dec 2017 15:57:08 -0800") Message-ID: <87shbqto33.fsf@users.sourceforge.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 29821 Cc: 29821@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) Jay Kamat writes: > I'm filing this separately from #29157, because I think that issue got a > bit overloaded with multiple eshell problems and is very hard to follow. Yes, thanks. > I recently noticed the changes in #29157, and I'm disappointed that we > came to the conclusion to disable history expansion completely. I find > it's rather useful, especially for things like: > > $ mv one.txt two.txtt > # whoops! > $ mv !!:$ two.txt Hmm, using history expansion would mean typing M-p DEL C-a M-f M-d M-d ! ! : $ to get mv !!:$ two.txt vs=20 M-p C-a M-f M-d M-d C-k C-y C-y DEL to get mv two.txtt two.txt Hardly seems worth the trouble of learning this syntax (and occasionally triggering accidentally, which is why I disable it in bash too). Is having history expansion enabled by default very important? You can still enable it in your config. > This is preferred (in my opinion) over lisp functions to keep muscle > memory working between shells. If anything, I would suggest disabling > quick substitution (as I don't find it more useful than using history > directly most of the time) (PS my suggestion is almost compatible with bash readline too, just M-p needs to be C-p instead, and that incompatibility is present in the history expansion case too). > I've created a patch to try to fix the bug found in #29157, which was: > >> echo $PATH | sed "s/[^o]foo[^o]/bar/g" >> Unknown predicate character =E2=80=98b=E2=80=99 > > The fix is rather simple, it simply limits the quick substitution to the > start of the line only (as observed in bash, as Andreas noted in the > previous thread). > > I hope that we reconsider the decision to disable history expansion by > default, it's a nice feature of eshell (which I have another patch I > would like to submit later to try to expand it's functionality a bit > more). > > Please let me know if you think this is a poor way of solving this issue > (or if anything else seems wrong or missing), and I'll try to follow up. I guess it's an improvement on what we have currently (the feature is rather underspecified). Should we consider also handling spaces like bash does? In bash I can do this: ~/tmp$ echo foo bar foo bar ~/tmp$ ^foo bar^blah^ echo blah blah In eshell (with and without your patch) I get: ~/src/emacs $ echo foo bar ("foo" "bar") ~/src/emacs $ ^foo bar^blah^ ^foo: command not found From debbugs-submit-bounces@debbugs.gnu.org Mon Jan 01 04:57:03 2018 Received: (at 29821) by debbugs.gnu.org; 1 Jan 2018 09:57:03 +0000 Received: from localhost ([127.0.0.1]:59232 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eVwq6-0008TG-Tw for submit@debbugs.gnu.org; Mon, 01 Jan 2018 04:57:03 -0500 Received: from mail-out.m-online.net ([212.18.0.10]:48294) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eVwq4-0008Sr-PI for 29821@debbugs.gnu.org; Mon, 01 Jan 2018 04:57:01 -0500 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 3z9CK74fPzz1qsVs; Mon, 1 Jan 2018 10:56:59 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3z9CK740cDz26T1r; Mon, 1 Jan 2018 10:56:59 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id 9Gz3JA1MLnYE; Mon, 1 Jan 2018 10:56:58 +0100 (CET) X-Auth-Info: pv71DrJts9XD5wUf9lmdsUIERvlLzMmUkvhSEs2dbKfDClzKtRP7stK0ww8+nRMF Received: from linux.local (ppp-188-174-159-253.dynamic.mnet-online.de [188.174.159.253]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Mon, 1 Jan 2018 10:56:58 +0100 (CET) Received: by linux.local (Postfix, from userid 501) id 762131E5507; Mon, 1 Jan 2018 10:56:34 +0100 (CET) From: Andreas Schwab To: Noam Postavsky Subject: Re: bug#29821: Ensure quick substitution only occurs at start of line References: <87fu8272h6.fsf@gmail.com> <87shbqto33.fsf@users.sourceforge.net> X-Yow: I'm EXCITED!! I want a FLANK STEAK WEEK-END!! I think I'm JULIA CHILD!! Date: Mon, 01 Jan 2018 10:56:31 +0100 In-Reply-To: <87shbqto33.fsf@users.sourceforge.net> (Noam Postavsky's message of "Sun, 31 Dec 2017 19:33:20 -0500") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.5 (/) X-Debbugs-Envelope-To: 29821 Cc: 29821@debbugs.gnu.org, Jay Kamat X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.5 (/) On Dez 31 2017, Noam Postavsky wrote: > Hmm, using history expansion would mean typing > > M-p DEL C-a M-f M-d M-d ! ! : $ > > to get > > mv !!:$ two.txt History expansion was invented when command line editing wasn't available, it typically makes only sense for entering a new command line (while referencing parts of the previous ones). Andreas. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different." From debbugs-submit-bounces@debbugs.gnu.org Mon Jan 01 16:02:22 2018 Received: (at control) by debbugs.gnu.org; 1 Jan 2018 21:02:22 +0000 Received: from localhost ([127.0.0.1]:60231 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eW7Dy-0002Fy-HF for submit@debbugs.gnu.org; Mon, 01 Jan 2018 16:02:22 -0500 Received: from mail-it0-f46.google.com ([209.85.214.46]:37763) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eW7Dw-0002Fm-Lg for control@debbugs.gnu.org; Mon, 01 Jan 2018 16:02:20 -0500 Received: by mail-it0-f46.google.com with SMTP id d137so37708879itc.2 for ; Mon, 01 Jan 2018 13:02:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:mime-version; bh=zEL88dNAJ/Ephg+7xs0o97T6ESp7uTCojTAjiMk/Hzg=; b=Q7bIly7MMcdMcIuEO0mFEvYteDcDoaxfku/Z4On6ggBPLw6eqHZ8FdKM9MPaTdkMJZ 5rLDI1yhREcby586BZlL9Ot08VhHhCBsOJlTxZi6Fw7pNnMKGHBF2h2XEHWgGFH4BBt7 7tN714bBAU4I/QU77GZQQ/ypCEzpubbnPcMl9juJ0Ikct/yqhQ4ralW0QZZu3JQ2VNnG sRYQVqLwISZRD3umCamJsAIZAfqogoUxADYOMSvQye08NgBPFLBqppxxC3acZXx9EIvt s03rZL85sw7PdjkVta7TRBAHXoT7COGSyQwM8CcqyIfXWatcmUJgeHxNENVZ1NtYpdpa 57aw== 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:date:message-id :mime-version; bh=zEL88dNAJ/Ephg+7xs0o97T6ESp7uTCojTAjiMk/Hzg=; b=Zq844/e0M41xk+Y9r5k/u0qD3vUJzrOeysXXvBJ5X+/FlOFD7e5RosShQidutIGQ1N h1L0HC2060S8JbOrug/v+nBrv5gK6Jft4EcBVwEqjFtxAQxQWS48Sn5Ebk54HekkG/jt RoigCpDmNmcBWL2OXorc4Tcm35eC0yOA7dlgvXK/yG5kLUhghwSRQ1lVZj5IMROr2oGh UZr9OvlLgZUaEWvc5WSIuPKZVPzvmXhjKTUokD8tHzIz6tu6pnxS/dbygxgfj6p5a+Hm i5RJSsxabm8kAPgY0MdKkaQNAkrx3mxPthRawxMblyQxbQITvtTktKyAHgtX8uCGDut6 p/bQ== X-Gm-Message-State: AKGB3mLQc6ZiCUvN1W18TSvJbhlOgvlq8Izt7gYkFkKqGBZVoEpN1tmM 4CdhRLccyyo4KdniCHkft4n2SQ== X-Google-Smtp-Source: ACJfBosXqyW8+XhAcSkxtUB7b0UDjyxeEt4IAVjseFA93RA3JVBtt8I3S2wFISO1Dse1OK+mj3/tUg== X-Received: by 10.36.122.17 with SMTP id a17mr60434367itc.30.1514840534939; Mon, 01 Jan 2018 13:02:14 -0800 (PST) Received: from zebian ([45.2.119.34]) by smtp.googlemail.com with ESMTPSA id n1sm3454708iob.3.2018.01.01.13.02.13 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Jan 2018 13:02:13 -0800 (PST) From: Noam Postavsky To: control@debbugs.gnu.org Subject: control message for bug #29821 Date: Mon, 01 Jan 2018 16:02:12 -0500 Message-ID: <877et1thrf.fsf@users.sourceforge.net> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) retitle 29821 eshell: Ensure quick substitution only occurs at start of line quit From debbugs-submit-bounces@debbugs.gnu.org Mon Jan 01 18:45:12 2018 Received: (at 29821) by debbugs.gnu.org; 1 Jan 2018 23:45:12 +0000 Received: from localhost ([127.0.0.1]:60295 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eW9lW-0001HX-BV for submit@debbugs.gnu.org; Mon, 01 Jan 2018 18:45:10 -0500 Received: from mail-pg0-f49.google.com ([74.125.83.49]:38998) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eW9lT-0001HJ-Q1 for 29821@debbugs.gnu.org; Mon, 01 Jan 2018 18:45:08 -0500 Received: by mail-pg0-f49.google.com with SMTP id 81so4177719pgf.6 for <29821@debbugs.gnu.org>; Mon, 01 Jan 2018 15:45:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=Okrz+2aX5a+J4qJUPryPZ0lJvMmoLD5ch/9agNI+Am0=; b=TO7+ok3fAIDD3Odlj10xU4WBozSXb2kctBMP7rAd84+UHrsGA+vXZ/rZunOzLHgGW/ OtnHleHTcVCjj9ZNGeUCs7h32+vlVKNgJ/nxB5FWlnXWjYQV/YbfZOIj0aiHgkEn6Rq3 hp8DT19aEy7BL9FoW2FZq9r4nkYJJFGnv8i/20ZUYlwrIgnBxNYwqIIiCxwurb8G9JJi HySpIPcWKxgjSrgVfnChjKhJ7M9P9bPTBny0XkWPDqzHEn7OS67ESBvmSaRFo9WvZtNJ H0+gZS+M0Y4jyBef+NAeqmxQ4sbL2e3zFqQXJgVVWEhO5JXpDUMEfldZ80rjeFCg0T8Q RI7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=Okrz+2aX5a+J4qJUPryPZ0lJvMmoLD5ch/9agNI+Am0=; b=eVsZEGZMUmBOZnh1EKj6Gx/1BDUNsiQiuiM4kO4tMctBL0C32LRLl/e6GxMZqy0bQu OFXyiuc3I07wrvUCX+fgpfEB8ggUBzPP9kJPeWbgaIX9qo4nVIBwevx+DwaCcQRTGZnX TzxW/kjOiAj7wqtTtPnBsyFFSFC1otB2thBGS+W8BQvnDHqTn6My6Qe+XZtHj7DhInsD ZdxavHcOP3WeZ8uNBAuy6okvhKn2sugr/ijRhwf1iBrpvNKJbsNlHMMjgVuOmbccLUrJ njyjLWxvwIOZlZjF2vi85epVodNWsFiqLp5Or7uSdouoXq4Bgh3QotgoddSIvqu9sOhv l/Sw== X-Gm-Message-State: AKGB3mKYPkDN5/zD+KpjfVs9zpVpnKWsHB5dQQEulcojMkkKZeOZGlvU zEqdx75VlBZMfDOCVbHxQPqNIdIa X-Google-Smtp-Source: ACJfBosQa4qyfJ+OUONHz502TvGJSBkHilZHCTkHwuDPhS4xnNu1HmspePRLYMspowWyIbEYTcJhRg== X-Received: by 10.98.39.68 with SMTP id n65mr43636481pfn.175.1514850301564; Mon, 01 Jan 2018 15:45:01 -0800 (PST) Received: from laythe (c-67-161-9-47.hsd1.ca.comcast.net. [67.161.9.47]) by smtp.gmail.com with ESMTPSA id f15sm2422023pgv.38.2018.01.01.15.44.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Jan 2018 15:45:00 -0800 (PST) From: Jay Kamat To: Noam Postavsky Subject: Re: bug#29821: Ensure quick substitution only occurs at start of line References: <87fu8272h6.fsf@gmail.com> <87shbqto33.fsf@users.sourceforge.net> Date: Mon, 01 Jan 2018 15:44:59 -0800 In-Reply-To: <87shbqto33.fsf@users.sourceforge.net> (Noam Postavsky's message of "Sun, 31 Dec 2017 19:33:20 -0500") Message-ID: <87608l6t50.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 29821 Cc: 29821@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --=-=-= Content-Type: text/plain Noam Postavsky writes: > Hmm, using history expansion would mean typing > > M-p DEL C-a M-f M-d M-d ! ! : $ > > to get > > mv !!:$ two.txt > > vs > > M-p C-a M-f M-d M-d C-k C-y C-y DEL > > to get > > mv two.txtt two.txt > > Hardly seems worth the trouble of learning this syntax (and occasionally > triggering accidentally, which is why I disable it in bash too). Is > having history expansion enabled by default very important? You can > still enable it in your config. I do suppose that is true, but I still find myself preferring history substitution in some cases, such as typing a new command but preserving the last argument. I don't think it's too important that history expansion is enabled by default, but I do think it's important to have it available as an option. I think that turning it off would startle some users, especially because it's featured in some popular 'getting started' articles for eshell (such as this one: https://masteringemacs.org/article/complete-guide-mastering-eshell), but the decision is up to you. I would much prefer a variable (perhaps defaulting to off) to tweak this setting on or of rather than adding/removing a function to the hook. Removing it in the current way makes it feel more 'deprecated' to me, rather than 'disabled by default'. Would you mind if I submitted a patch to add a new `eshell-history-expansion-enabled' variable (or similar)? > I guess it's an improvement on what we have currently (the feature is > rather underspecified). Should we consider also handling spaces like > bash does? In bash I can do this: > > ~/tmp$ echo foo bar > foo bar > ~/tmp$ ^foo bar^blah^ > echo blah > blah > > In eshell (with and without your patch) I get: > > ~/src/emacs $ echo foo bar > ("foo" "bar") > ~/src/emacs $ ^foo bar^blah^ > ^foo: command not found I've attached a new patch which attempts to solve this as well. I'm unfamiliar with eshell internals though, so I'm not sure if it's done properly. Let me know if anyone sees any issues with it! Thanks, -Jay --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Prevent-expansion-of-quick-substitutions-when-not-at.patch >From 573b03a76798496b3bcfcada1557f1a9d83cc987 Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Fri, 22 Dec 2017 15:34:44 -0800 Subject: [PATCH] Prevent expansion of quick substitutions when not at start of line See bug #29157 for an initial report Also, allow spaces inside substitutions, so ^foo bar^baz works. * lisp/eshell/em-hist.el (eshell-expand-history-references): Expand history substitution before other types of expansions, and expand them with the whole line. (eshell-history-substitution): New function to expand only substitutions, taking in the entire typed line rather than individual arguments. --- lisp/eshell/em-hist.el | 57 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/lisp/eshell/em-hist.el b/lisp/eshell/em-hist.el index df462a7058..d4d4b93b81 100644 --- a/lisp/eshell/em-hist.el +++ b/lisp/eshell/em-hist.el @@ -581,21 +581,30 @@ eshell-hist-parse-arguments (defun eshell-expand-history-references (beg end) "Parse and expand any history references in current input." - (let ((result (eshell-hist-parse-arguments beg end))) + (let ((result (eshell-hist-parse-arguments beg end)) + (full-line (buffer-substring-no-properties beg end))) (when result (let ((textargs (nreverse (nth 0 result))) (posb (nreverse (nth 1 result))) - (pose (nreverse (nth 2 result)))) + (pose (nreverse (nth 2 result))) + (full-line-subst (eshell-history-substitution full-line))) (save-excursion - (while textargs - (let ((str (eshell-history-reference (car textargs)))) - (unless (eq str (car textargs)) - (goto-char (car posb)) - (insert-and-inherit str) - (delete-char (- (car pose) (car posb))))) - (setq textargs (cdr textargs) - posb (cdr posb) - pose (cdr pose)))))))) + (if full-line-subst + ;; Found a ^foo^bar substitution + (progn + (goto-char beg) + (insert-and-inherit full-line-subst) + (delete-char (- end beg))) + ;; Try to expand other substitutions + (while textargs + (let ((str (eshell-history-reference (car textargs)))) + (unless (eq str (car textargs)) + (goto-char (car posb)) + (insert-and-inherit str) + (delete-char (- (car pose) (car posb))))) + (setq textargs (cdr textargs) + posb (cdr posb) + pose (cdr pose))))))))) (defvar pcomplete-stub) (defvar pcomplete-last-completion-raw) @@ -630,20 +639,28 @@ eshell-complete-history-reference (setq history (cdr history))) (cdr fhist))))))) +(defun eshell-history-substitution (line) + "Expand whole-line history substitutions by converting them to +!!:s/a/b/ syntax. +Returns nil if no match found." + ;; `^string1^string2^' + ;; Quick Substitution. Repeat the last command, replacing + ;; STRING1 with STRING2. Equivalent to `!!:s/string1/string2/' + (when (and (eshell-using-module 'eshell-pred) + (string-match "^\\^\\([^^]+\\)\\^\\([^^]+\\)\\^?\\s-*$" + line)) + (let* ((reference (format "!!:s/%s/%s/" + (match-string 1 line) + (match-string 2 line))) + (result (eshell-history-reference reference))) + (unless (eq result reference) + result)))) + (defun eshell-history-reference (reference) "Expand directory stack REFERENCE. The syntax used here was taken from the Bash info manual. Returns the resultant reference, or the same string REFERENCE if none matched." - ;; `^string1^string2^' - ;; Quick Substitution. Repeat the last command, replacing - ;; STRING1 with STRING2. Equivalent to `!!:s/string1/string2/' - (if (and (eshell-using-module 'eshell-pred) - (string-match "\\^\\([^^]+\\)\\^\\([^^]+\\)\\^?\\s-*$" - reference)) - (setq reference (format "!!:s/%s/%s/" - (match-string 1 reference) - (match-string 2 reference)))) ;; `!' ;; Start a history substitution, except when followed by a ;; space, tab, the end of the line, = or (. -- 2.11.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Mon Jan 01 20:29:31 2018 Received: (at 29821) by debbugs.gnu.org; 2 Jan 2018 01:29:31 +0000 Received: from localhost ([127.0.0.1]:60346 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWBOU-0003i7-6Z for submit@debbugs.gnu.org; Mon, 01 Jan 2018 20:29:30 -0500 Received: from mail-it0-f48.google.com ([209.85.214.48]:40169) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWBOS-0003hr-9c for 29821@debbugs.gnu.org; Mon, 01 Jan 2018 20:29:28 -0500 Received: by mail-it0-f48.google.com with SMTP id f190so37980219ita.5 for <29821@debbugs.gnu.org>; Mon, 01 Jan 2018 17:29:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=LgpMAdgGFC+CWltvP++Ll4mZilZ4Inh7jKI/GMyilQM=; b=rJbrvnS4WBoPNr2UBi5ncQGkR1b7iGuC4ul3CjCpuVyNZT2VY1aTeewuLv3XmuTbnn AGNrUFGEz199qUOYreceK8nvEusNVz53yEMw/GSgos/PdrS5RYzq56CtFfRGkxJ18tu9 wmg6cv9SE4/mjkY6paHf1/kStRxwgxP+lKJRsiCGqjRJQ/JQXb4Db8RdQPkYcdBb8bL+ 09zN4e/vlmylOc0JkqKAC2ZZc9a1A+4yhebAD4lJHiaX+MeZ1WSgbWDTY+Lf2Hc8aCgK n6GEhJZBUaQbHo0ebSOQTdTXdSvCaxX1P6PVl6Rn/kBplqH0YIa0ZTTJpgTP9wTWluxJ jeQg== 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:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=LgpMAdgGFC+CWltvP++Ll4mZilZ4Inh7jKI/GMyilQM=; b=fgKE4WS4f9TKrjEmNvJvnNiWQEfYg7zLN4yTMhoy6Fopg+hhJaYOXr4NuhmkO/fvZL L7tbodO75+g+HMd6pjMyWVIOTaZ9t1kAVxrkITveOpoRbbDYtmnGEdwcIQVWvvKjb1sr 3xI3Rvn0N+QikiWJJFknfIF6U8tzYpaYR3zqS9G9urdky+BRwADKbDY4lAqEdrytwdIG UT2YYjyGpEqkaBxdfrG8agg8/nHVsY/JvvqtUZJ6VQ+ikF+QT8p20aqaZEp/qLjtcqGc 19NAzVxf3oQjbtS/NZnPltj4SDAAATMQ06kCo673ItEmJ4A6VLWN4ItSovcUHJYp5MUa /rQA== X-Gm-Message-State: AKGB3mJhP16tcqFioQUDFqnsSw/yh07c72I9TWfSJkFEkNb5+iaMQD08 FXL3cskdeaQoIZ3uELZBTEM= X-Google-Smtp-Source: ACJfBosaj4nfSxMOzaPyeoO8qu3kIMWAnHO6M8WtS4ByXnsK2yX30uZ+PuNaASEP73zTQxWuRVN8KQ== X-Received: by 10.36.101.16 with SMTP id u16mr57874252itb.90.1514856562515; Mon, 01 Jan 2018 17:29:22 -0800 (PST) Received: from zebian ([45.2.119.34]) by smtp.googlemail.com with ESMTPSA id g130sm23409685ioe.78.2018.01.01.17.29.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Jan 2018 17:29:21 -0800 (PST) From: Noam Postavsky To: Andreas Schwab Subject: Re: bug#29821: Ensure quick substitution only occurs at start of line References: <87fu8272h6.fsf@gmail.com> <87shbqto33.fsf@users.sourceforge.net> Date: Mon, 01 Jan 2018 20:29:20 -0500 In-Reply-To: (Andreas Schwab's message of "Mon, 01 Jan 2018 10:56:31 +0100") Message-ID: <87wp11rqtr.fsf@users.sourceforge.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 29821 Cc: 29821@debbugs.gnu.org, Jay Kamat X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) Andreas Schwab writes: > On Dez 31 2017, Noam Postavsky wrote: > >> Hmm, using history expansion would mean typing >> >> M-p DEL C-a M-f M-d M-d ! ! : $ >> >> to get >> >> mv !!:$ two.txt > > History expansion was invented when command line editing wasn't > available, it typically makes only sense for entering a new command line > (while referencing parts of the previous ones). Yes, but I didn't want to handicap the history expansion case unfairly by rejecting use of other history/editing commands. Jay Kamat writes: > I would much prefer a variable (perhaps defaulting to off) to tweak this > setting on or of rather than adding/removing a function to the hook. > Removing it in the current way makes it feel more 'deprecated' to me, > rather than 'disabled by default'. > > Would you mind if I submitted a patch to add a new > `eshell-history-expansion-enabled' variable (or similar)? Seems like pointless duplication to me. I think I would prefer having history expansion enabled by default to that (it wouldn't be that hard to disable it, after all). >> In eshell (with and without your patch) I get: >> >> ~/src/emacs $ echo foo bar >> ("foo" "bar") >> ~/src/emacs $ ^foo bar^blah^ >> ^foo: command not found > > I've attached a new patch which attempts to solve this as well. I'm > unfamiliar with eshell internals though, so I'm not sure if it's done > properly. Let me know if anyone sees any issues with it! With your patch, if I do ~/src/emacs $ ^this string not present in history^blah^ I get the latest entry in the history substituted and re-executed. In bash I get ~/tmp$ ^this string not present in history^blah^ bash: :s^this string not present in history^blah^: substitution failed (if it's easier, I think it would be okay if eshell prints an error using the !!:s/foo/bar/ syntax, but this case must be an error) From debbugs-submit-bounces@debbugs.gnu.org Mon Jan 01 21:30:53 2018 Received: (at 29821) by debbugs.gnu.org; 2 Jan 2018 02:30:53 +0000 Received: from localhost ([127.0.0.1]:60356 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWCLt-00056C-05 for submit@debbugs.gnu.org; Mon, 01 Jan 2018 21:30:53 -0500 Received: from mail-pg0-f41.google.com ([74.125.83.41]:46944) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWCLr-00055x-Fr for 29821@debbugs.gnu.org; Mon, 01 Jan 2018 21:30:51 -0500 Received: by mail-pg0-f41.google.com with SMTP id r2so8436603pgq.13 for <29821@debbugs.gnu.org>; Mon, 01 Jan 2018 18:30:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=iNXn6j9KF3SELNgYFwp5O37rwC76RNsrjWH350Xa+xk=; b=tKAiQcVE+C9Jn5fEAG9DJEvarZPpx5LOSxstNlbFNAvLMPByk+DnETXqh2xkCqrHby oDl1HqoS7+Wp6Twg380cva3KSKSTITJE2uoLk5Aabebw6maHEysv0V3tpsgDc3C9TuG8 sz3JNAEpX8vB9j7Q0342gYytjNbkvwEcaeuE2lxehgvEaCVlb/4XyVcF/f5pmgb3CCrL dPMYDWIeYviKVZkDlKB3kw7mQJIfKLLBIimda5mdqwmYItEJXrqzG5Ty1HGr/uK2Dia4 DousPQy3yXTiB8vQJ7UnTOSuO3o1aYe3deduhIsTCZcDsfwS5vkA16WnYwj1MDo7FFIQ EnrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=iNXn6j9KF3SELNgYFwp5O37rwC76RNsrjWH350Xa+xk=; b=AQ8TSjGH1V+woLIJQOFx7zAJ0Z5knnCYhz2+DVh09eW8dSftZpw3mAYizLzMb3Oazr PSzoxsW3PR6Cs3sB4G4WR38OrbS0XqYX+RuuIQM6dZoZyGZ6jkBD0214sqGCsnqVtD3h S2bP6MQFATbT2ylSRlsS0hpTjXtRpg7R4BdWurXOQFBcMgzY/KYlAdZ8SglTXwy/4+9J 4WA5Ef+mttYdMc6rqUcS/zKYigfoEOCzBe9a0Y/xf3cSS/PZZIb84ZSUimOn4wsafizw 1b01ZMe+ciwJr8N8MO8jRMe9IhTtEmzcdfLfisxQOwxCJecCa/+j/gemuHvsIDNqLZod u0yw== X-Gm-Message-State: AKGB3mL8G2X8+aXNUHX98ITQOTL2DH/OmTnLjjpaLkPGGa7Ea9cZUtci AQqo/e4XaAMdYMHcMEp0PZ6Pz1YC X-Google-Smtp-Source: ACJfBotcx/d5mXOt7psgPXSjiv9SUnKDVlTITFJGimyXoPQgO8s12FAH7D+7oYXzUhR54wgqL1CJHg== X-Received: by 10.98.8.202 with SMTP id 71mr35395013pfi.204.1514860245478; Mon, 01 Jan 2018 18:30:45 -0800 (PST) Received: from laythe (c-67-161-9-47.hsd1.ca.comcast.net. [67.161.9.47]) by smtp.gmail.com with ESMTPSA id e8sm20509312pgs.44.2018.01.01.18.30.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Jan 2018 18:30:43 -0800 (PST) From: Jay Kamat To: Noam Postavsky Subject: Re: bug#29821: Ensure quick substitution only occurs at start of line References: <87fu8272h6.fsf@gmail.com> <87shbqto33.fsf@users.sourceforge.net> <87wp11rqtr.fsf@users.sourceforge.net> Date: Mon, 01 Jan 2018 18:30:41 -0800 In-Reply-To: <87wp11rqtr.fsf@users.sourceforge.net> (Noam Postavsky's message of "Mon, 01 Jan 2018 20:29:20 -0500") Message-ID: <871sj96lgu.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 29821 Cc: 29821@debbugs.gnu.org, Andreas Schwab X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --=-=-= Content-Type: text/plain Noam Postavsky writes: > With your patch, if I do > > ~/src/emacs $ ^this string not present in history^blah^ > > I get the latest entry in the history substituted and re-executed. In > bash I get > > ~/tmp$ ^this string not present in history^blah^ > bash: :s^this string not present in history^blah^: substitution failed > > (if it's easier, I think it would be okay if eshell prints an error > using the !!:s/foo/bar/ syntax, but this case must be an error) Ah, I did notice that, but I was not sure whether it was a bug or desired behavior (as it seemed to occur for me even before this patch). I've added a tiny change to the patch to fix that, but it has the side effect of doing: > *[j@laythe emacs-bisect]$ echo "foo"(:s/bar/baz/) > foo: substitution failed But I think that's an OK change, especially if we want to error out on ^bar^baz when no search is found. I also discovered another issue (which existed before as well): > *[j@laythe emacs-bisect]$ echo one one one > ("one" "one" "one") > *[j@laythe emacs-bisect]$ !!:sg/one/two > :sg/one/two > Wrong type argument: integer-or-marker-p, nil but I'd rather take a look at that later on to avoid cluttering this changeset. (and I'm not sure if I'm just using the feature incorrectly). Thanks, -Jay --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Prevent-expansion-of-quick-substitutions-when-not-at.patch >From d4ba97c7b15c48d3394b8567b05fae31874220a7 Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Fri, 22 Dec 2017 15:34:44 -0800 Subject: [PATCH] Prevent expansion of quick substitutions when not at start of line See bug #29157 for an initial report Also, allow spaces inside substitutions, so ^foo bar^baz works. * lisp/eshell/em-hist.el (eshell-expand-history-references): Expand history substitution before other types of expansions, and expand them with the whole line. (eshell-history-substitution): New function to expand only substitutions, taking in the entire typed line rather than individual arguments. --- lisp/eshell/em-hist.el | 57 ++++++++++++++++++++++++++++++++------------------ lisp/eshell/em-pred.el | 3 ++- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/lisp/eshell/em-hist.el b/lisp/eshell/em-hist.el index df462a7058..d4d4b93b81 100644 --- a/lisp/eshell/em-hist.el +++ b/lisp/eshell/em-hist.el @@ -581,21 +581,30 @@ eshell-hist-parse-arguments (defun eshell-expand-history-references (beg end) "Parse and expand any history references in current input." - (let ((result (eshell-hist-parse-arguments beg end))) + (let ((result (eshell-hist-parse-arguments beg end)) + (full-line (buffer-substring-no-properties beg end))) (when result (let ((textargs (nreverse (nth 0 result))) (posb (nreverse (nth 1 result))) - (pose (nreverse (nth 2 result)))) + (pose (nreverse (nth 2 result))) + (full-line-subst (eshell-history-substitution full-line))) (save-excursion - (while textargs - (let ((str (eshell-history-reference (car textargs)))) - (unless (eq str (car textargs)) - (goto-char (car posb)) - (insert-and-inherit str) - (delete-char (- (car pose) (car posb))))) - (setq textargs (cdr textargs) - posb (cdr posb) - pose (cdr pose)))))))) + (if full-line-subst + ;; Found a ^foo^bar substitution + (progn + (goto-char beg) + (insert-and-inherit full-line-subst) + (delete-char (- end beg))) + ;; Try to expand other substitutions + (while textargs + (let ((str (eshell-history-reference (car textargs)))) + (unless (eq str (car textargs)) + (goto-char (car posb)) + (insert-and-inherit str) + (delete-char (- (car pose) (car posb))))) + (setq textargs (cdr textargs) + posb (cdr posb) + pose (cdr pose))))))))) (defvar pcomplete-stub) (defvar pcomplete-last-completion-raw) @@ -630,20 +639,28 @@ eshell-complete-history-reference (setq history (cdr history))) (cdr fhist))))))) +(defun eshell-history-substitution (line) + "Expand whole-line history substitutions by converting them to +!!:s/a/b/ syntax. +Returns nil if no match found." + ;; `^string1^string2^' + ;; Quick Substitution. Repeat the last command, replacing + ;; STRING1 with STRING2. Equivalent to `!!:s/string1/string2/' + (when (and (eshell-using-module 'eshell-pred) + (string-match "^\\^\\([^^]+\\)\\^\\([^^]+\\)\\^?\\s-*$" + line)) + (let* ((reference (format "!!:s/%s/%s/" + (match-string 1 line) + (match-string 2 line))) + (result (eshell-history-reference reference))) + (unless (eq result reference) + result)))) + (defun eshell-history-reference (reference) "Expand directory stack REFERENCE. The syntax used here was taken from the Bash info manual. Returns the resultant reference, or the same string REFERENCE if none matched." - ;; `^string1^string2^' - ;; Quick Substitution. Repeat the last command, replacing - ;; STRING1 with STRING2. Equivalent to `!!:s/string1/string2/' - (if (and (eshell-using-module 'eshell-pred) - (string-match "\\^\\([^^]+\\)\\^\\([^^]+\\)\\^?\\s-*$" - reference)) - (setq reference (format "!!:s/%s/%s/" - (match-string 1 reference) - (match-string 2 reference)))) ;; `!' ;; Start a history substitution, except when followed by a ;; space, tab, the end of the line, = or (. diff --git a/lisp/eshell/em-pred.el b/lisp/eshell/em-pred.el index 72a7bc4afc..86a9d4262a 100644 --- a/lisp/eshell/em-pred.el +++ b/lisp/eshell/em-pred.el @@ -545,7 +545,8 @@ eshell-pred-substitute (function (lambda (str) (if (string-match ,match str) - (setq str (replace-match ,replace t nil str))) + (setq str (replace-match ,replace t nil str)) + (error (concat str ": substitution failed"))) str)) lst))))) (defun eshell-include-members (&optional invert-p) -- 2.11.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Mon Jan 01 22:58:17 2018 Received: (at 29821) by debbugs.gnu.org; 2 Jan 2018 03:58:17 +0000 Received: from localhost ([127.0.0.1]:60367 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWDiS-00070j-PW for submit@debbugs.gnu.org; Mon, 01 Jan 2018 22:58:16 -0500 Received: from mail-io0-f171.google.com ([209.85.223.171]:42639) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWDiR-00070U-0W for 29821@debbugs.gnu.org; Mon, 01 Jan 2018 22:58:15 -0500 Received: by mail-io0-f171.google.com with SMTP id x67so41623200ioi.9 for <29821@debbugs.gnu.org>; Mon, 01 Jan 2018 19:58:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=ZYFoTDEQPEZuAKJl6XLi0+onjceKI/xh31ZylYv15PE=; b=owXa8CJLqRktYAMbsdwaLpqlxRjh1gnfnDKF/AQeUSILYMmIAzUWH4OVLQhykXnk6w bOQ92NuTJPvXqmJRgfPnrN7acPiV+dMPKi0u+5UHDTTQ2FEWyvijUqg3wad5kFf4jDdO K+QYFyAAjul1rWF6NCQbnPSIYYuR/Xu/2tkA5EIoSzpPowqcr+qZMARiotwnuoIEpQjn i4MSTtk2qO1BlPXPEMehhP00NsM/NALBeNPOKZX380jWGqGKG6fmR9d9i8T1Fr+YDdQZ p8XJa8y4wDmt5mqRvwRlkRq6FDtB5qoTEv5Lp9NCE5NeGei2K6Y+TOq5nBuwVw2nLcKC KKvw== 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:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=ZYFoTDEQPEZuAKJl6XLi0+onjceKI/xh31ZylYv15PE=; b=cIIhRKiwh4XbcXFu/j1DXIyIHVH/a8l24l/jgCNDOSdXH1iWrgg0czjv/d9UJgp0L5 jQkVQVg9uE458IFncXJXTKohZGoRJDzDW61F+mH1C/sZWpQO4SGDVPs2db/r012USDc6 6+FblY/HdZ6Wy68FrDUdrquDM9MC12032dYTdrKuWm4MMcKslu4lIe411N2zc+u/yqTb A32meJL9g+VLDNqq8YawznuevQV3fewjVD436csWlP1Or/i9y3356hBF1fimHv0fFnsw jU3wmuEleuhs/nJgnWicssP4nV73R++8RPC+rMSuo3oMgaqHHYNq7S7GMBfz8x1/y241 jzYw== X-Gm-Message-State: AKGB3mLTtVG2R8akBCAO2A6cXtPm5p4AszNRvbQxgcl3cyS/ZD8pyD0r +Z+LiGzgoiFyYP/Snqkz1PU= X-Google-Smtp-Source: ACJfBosXzfwm0KiKpy3L4Ogif6YbEcQqOQjMwgZS3A3nCm9kW2khfZTrr9IsBoOV3ftRM7g3wLF9Bw== X-Received: by 10.107.51.212 with SMTP id z203mr57974348ioz.126.1514865489054; Mon, 01 Jan 2018 19:58:09 -0800 (PST) Received: from zebian ([45.2.119.34]) by smtp.googlemail.com with ESMTPSA id 86sm18155615iom.31.2018.01.01.19.58.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Jan 2018 19:58:07 -0800 (PST) From: Noam Postavsky To: Jay Kamat Subject: Re: bug#29821: Ensure quick substitution only occurs at start of line References: <87fu8272h6.fsf@gmail.com> <87shbqto33.fsf@users.sourceforge.net> <87wp11rqtr.fsf@users.sourceforge.net> <871sj96lgu.fsf@gmail.com> Date: Mon, 01 Jan 2018 22:58:06 -0500 In-Reply-To: <871sj96lgu.fsf@gmail.com> (Jay Kamat's message of "Mon, 01 Jan 2018 18:30:41 -0800") Message-ID: <87tvw4syi9.fsf@users.sourceforge.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 29821 Cc: 29821@debbugs.gnu.org, Andreas Schwab X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) Jay Kamat writes: > Ah, I did notice that, but I was not sure whether it was a bug or > desired behavior (as it seemed to occur for me even before this > patch). Oh right, I didn't notice because I tested with spaces. Still, I think since we're trying to make this behave like bash, we should try to get as close as possible. > I've added a tiny change to the patch to fix that, but it has the side > effect of doing: > >> *[j@laythe emacs-bisect]$ echo "foo"(:s/bar/baz/) >> foo: substitution failed > > But I think that's an OK change, especially if we want to error out on > ^bar^baz when no search is found. > I also discovered another issue (which existed before as well): > >> *[j@laythe emacs-bisect]$ echo one one one >> ("one" "one" "one") >> *[j@laythe emacs-bisect]$ !!:sg/one/two >> :sg/one/two >> Wrong type argument: integer-or-marker-p, nil > > but I'd rather take a look at that later on to avoid cluttering this > changeset. (and I'm not sure if I'm just using the feature incorrectly). !!:gs/one/two/ seems to work. The error message could be improved though (but yes, we should do that separately). > +(defun eshell-history-substitution (line) > + "Expand whole-line history substitutions by converting them to > +!!:s/a/b/ syntax. > +Returns nil if no match found." Couldn't you error here (if the line matches ^...^...^) instead of returning nil, and then avoid affecting the other substitution? (although I agree signaling an error in the other place is probably acceptable) From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 02 12:48:12 2018 Received: (at 29821) by debbugs.gnu.org; 2 Jan 2018 17:48:12 +0000 Received: from localhost ([127.0.0.1]:33394 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWQfb-000385-Q8 for submit@debbugs.gnu.org; Tue, 02 Jan 2018 12:48:12 -0500 Received: from mail-pf0-f174.google.com ([209.85.192.174]:35697) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWQfa-00037q-4B for 29821@debbugs.gnu.org; Tue, 02 Jan 2018 12:48:10 -0500 Received: by mail-pf0-f174.google.com with SMTP id j124so25929578pfc.2 for <29821@debbugs.gnu.org>; Tue, 02 Jan 2018 09:48:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=33awApRBJvMfDQxlLK5sZ3cLsgqmt8NtqpAQwmsYb98=; b=W5HjHBVw7K2aTznDncwtNwl8xGbGqkW3idan84SQGJSyjVr3muTGxbZYyrfHCch+kJ Pg0QbA7aRjxBTAwYvjwlCU5YpGpcOe45CCvOAVIxsznWzdO+kEGt8K/ubTyuhCOmDToz gMa/euJJxBWl5a/WUrXLrozg9LNjl/DskFUNhmzKQY5zmCJnOaQ++TlU01XH7UAtgKs8 tcDlHyuNRyf9Hl3TZwdL1Ba5RB+PrnsKss1nX1z4OSsNepbTFTdE/AAVEq3y9YC/isJu oGkkx0PzSU9PsIB36uh/xnATV2lMgcGMc+Ie+pTqYhW3FOBn3KkXuGrOkU1iEltl88T7 5ejw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=33awApRBJvMfDQxlLK5sZ3cLsgqmt8NtqpAQwmsYb98=; b=KN8VmFvg7KpPnkS/upryGlvQuEFC8TjIuUWh2fTiNpJWT8q3GiWLxZlAFZIVE4ubkF R7w3QD4X40z0w5zlFxo3rlLhiyjf0X0PqOCt2odrxbKu6N2PczlcNhSFzWJh1Q+4UjW2 xEGG2HhmOhjrZEj6HX18OyCiadzpGNWb1RArxYNfL1U48j/JORnXVfRQnuRcUddEOFXa hwE2fIZdMjKmzekU/FGoivdj21hLcSZfFx9AuCZu0J48uVQbBFOZQ50uKBaraRfPQnpD yerhlPycGppq7TQh/+EMoJ1uEXtn0lTFUa03jkKKjTz0J2U15IKpZRkhRoVNOG7vAUYB jYTQ== X-Gm-Message-State: AKGB3mJIq484NaiOtK15i1mn+AtBP5aJL3/iXWJ74tslqvsd2ASM43qd PgcPV4BprRcb8tF05xFwbE0= X-Google-Smtp-Source: ACJfBosNi/ySRGLdKOTUSkyOlbmSXWM47h/MQHcEXMagJgX2e4i8IxGhR3TAOW7AABCDUKOV9VE9ow== X-Received: by 10.101.65.205 with SMTP id b13mr25543671pgq.30.1514915282018; Tue, 02 Jan 2018 09:48:02 -0800 (PST) Received: from laythe (c-67-161-9-47.hsd1.ca.comcast.net. [67.161.9.47]) by smtp.gmail.com with ESMTPSA id c2sm22930661pgq.48.2018.01.02.09.48.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Jan 2018 09:48:01 -0800 (PST) From: Jay Kamat To: Noam Postavsky Subject: Re: bug#29821: Ensure quick substitution only occurs at start of line References: <87fu8272h6.fsf@gmail.com> <87shbqto33.fsf@users.sourceforge.net> <87wp11rqtr.fsf@users.sourceforge.net> <871sj96lgu.fsf@gmail.com> <87tvw4syi9.fsf@users.sourceforge.net> Date: Tue, 02 Jan 2018 09:48:00 -0800 In-Reply-To: <87tvw4syi9.fsf@users.sourceforge.net> (Noam Postavsky's message of "Mon, 01 Jan 2018 22:58:06 -0500") Message-ID: <87wp105ezz.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 29821 Cc: 29821@debbugs.gnu.org, Andreas Schwab X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) Noam Postavsky writes: > Couldn't you error here (if the line matches ^...^...^) instead of > returning nil, and then avoid affecting the other substitution? > (although I agree signaling an error in the other place is probably > acceptable) I could be missing something, but I don't think this is that easy. In the case of a failed search for something like '!!:s/a/b/', `eshell-history-reference' previously returned the previous line, unmodified. I could pull the previous line and compare it with the one returned to see if `eshell-history-reference' has modified it, but I don't like that solution, it seems like a bit of a hack. Let me know if you think that's better though, or if I have it wrong... If we really want to preserve the previous behavior of 'echo "foo"(:s/bar/baz/)', I would prefer setting a lexical variable around functions like `eshell-pred-substitute' so it can figure out which type of substitution it's in and error accordingly. Thanks, -Jay From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 02 20:51:47 2018 Received: (at 29821) by debbugs.gnu.org; 3 Jan 2018 01:51:47 +0000 Received: from localhost ([127.0.0.1]:33638 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWYDb-0007Tt-Fr for submit@debbugs.gnu.org; Tue, 02 Jan 2018 20:51:47 -0500 Received: from mail-it0-f49.google.com ([209.85.214.49]:35003) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWYDa-0007Tg-1w for 29821@debbugs.gnu.org; Tue, 02 Jan 2018 20:51:46 -0500 Received: by mail-it0-f49.google.com with SMTP id f143so214910itb.0 for <29821@debbugs.gnu.org>; Tue, 02 Jan 2018 17:51:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=JlMfH6vEQ5AFDNnNg1P5SmiHGsTxKPTwgL0Zj+UvU4E=; b=TafijPCHFcaaYw0Aj+erzMGvvbdGuKQH02N3sOkwLQOBfLS/OV1lzoMSGRVjrmRxX0 hf6PkFM5II8jX6qw1T1SM4eMZKP6TmVAAVDqzrOsjkoUR1arMhJP7TAzrL2cYRoS3CKL t9uHyFxazafTYZzAm8LtbmN+JD2VTe3NzfGPHhGlfLl6UNhWC/zn4vC+2LgMqEPHqtjo Ld++dkZNajgaLYeoeBrqYmEuYGEpau+nmADJqhqpb0v/X50vW5UAkOYqoVHfUtie60ai XLSj5S7LwrEJWwl9VjkQRBX8HTTcZsYf/2l9lF2vrwGBEVDW+izFmo06tM9xohmGh1ap IQzg== 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:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=JlMfH6vEQ5AFDNnNg1P5SmiHGsTxKPTwgL0Zj+UvU4E=; b=edgtk/lwb2jTOkOuDoeWPuFCIulbbfBCvOaV6xXeEDgxA/CxQjxzzLThohcoIoWrPI kCHNrWPNLO75HvOzbLzMXqBNKR78hHTtSDurHa6JSKLpZ1tqpzWC9hGzCM/6QHDeoZXu 8d/PRTWJRp1xymzQ/ab6Zk0iBDWZMYxOpdaUAiIvkPK4UqvKAF7gyZfLcJLbbSzbnPBq BZySfGr2IRmfCVHms9lE5o9D5JU3kW4mSbrRGfJObMR3BLiAcb/I9PJlMcxtaDs2hBLf /dw759YLar8vqMorVMMtYGfVwjiMd+HrA3GMy9hdrCSIjwq7tlCIhIEgX1BtBfsPiZGP +a7Q== X-Gm-Message-State: AKGB3mL8YDgOODc41S+HTTCFiAOWxeuya/7Kj7Fqe5XfrbhZa3EJj+ox N8MMXyRWjXLSM1/ODGpFE54= X-Google-Smtp-Source: ACJfBotbKWvpBbOxBK2Wxzp0XrQkMsa9Lr+STmxMu0IQTyLKNTDVGnSfFBMkyfyKSRDOCPXvYPo9EQ== X-Received: by 10.36.170.14 with SMTP id b14mr200409itf.13.1514944300262; Tue, 02 Jan 2018 17:51:40 -0800 (PST) Received: from zebian ([45.2.119.34]) by smtp.googlemail.com with ESMTPSA id 1sm2965095ion.51.2018.01.02.17.51.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Jan 2018 17:51:38 -0800 (PST) From: Noam Postavsky To: Jay Kamat Subject: Re: bug#29821: Ensure quick substitution only occurs at start of line References: <87fu8272h6.fsf@gmail.com> <87shbqto33.fsf@users.sourceforge.net> <87wp11rqtr.fsf@users.sourceforge.net> <871sj96lgu.fsf@gmail.com> <87tvw4syi9.fsf@users.sourceforge.net> <87wp105ezz.fsf@gmail.com> Date: Tue, 02 Jan 2018 20:51:36 -0500 In-Reply-To: <87wp105ezz.fsf@gmail.com> (Jay Kamat's message of "Tue, 02 Jan 2018 09:48:00 -0800") Message-ID: <87o9mbso9j.fsf@users.sourceforge.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 29821 Cc: 29821@debbugs.gnu.org, Andreas Schwab X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) Jay Kamat writes: > Noam Postavsky writes: > >> Couldn't you error here (if the line matches ^...^...^) instead of >> returning nil, and then avoid affecting the other substitution? >> (although I agree signaling an error in the other place is probably >> acceptable) > > I could be missing something, but I don't think this is that easy. In > the case of a failed search for something like '!!:s/a/b/', > `eshell-history-reference' previously returned the previous line, > unmodified. Oh, yes, I was confused by your docstring. By "if no match found" you meant when the line doesn't match ^foo^bar^ at all; I had somehow got the impression you meant that there was no match for "foo". > +(defun eshell-history-substitution (line) > + "Expand whole-line history substitutions by converting them to > +!!:s/a/b/ syntax. > +Returns nil if no match found." > + ;; `^string1^string2^' > + ;; Quick Substitution. Repeat the last command, replacing > + ;; STRING1 with STRING2. Equivalent to `!!:s/string1/string2/' > + (when (and (eshell-using-module 'eshell-pred) > + (string-match "^\\^\\([^^]+\\)\\^\\([^^]+\\)\\^?\\s-*$" > + line)) > + (let* ((reference (format "!!:s/%s/%s/" > + (match-string 1 line) > + (match-string 2 line))) > + (result (eshell-history-reference reference))) > + (unless (eq result reference) This eq test will always be nil, right? Because the only time it's t is when you pass something that's not a history reference, but the thing we passed is a history reference by construction. So this could be simplified to (when (and (eshell-using-module 'eshell-pred) (string-match "^\\^\\([^^]+\\)\\^\\([^^]+\\)\\^?\\s-*$" line)) (eshell-history-reference (format "!!:s/%s/%s/" (match-string 1 line) (match-string 2 line)))) That, plus rephrasing the docstring so the first sentence fits on one line (it should probably also mention ^foo^bar^ syntax), and I think the patch is good to go (for master). From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 03 20:17:37 2018 Received: (at 29821) by debbugs.gnu.org; 4 Jan 2018 01:17:37 +0000 Received: from localhost ([127.0.0.1]:34843 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWuA5-0003iC-89 for submit@debbugs.gnu.org; Wed, 03 Jan 2018 20:17:37 -0500 Received: from mail-pl0-f42.google.com ([209.85.160.42]:43985) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWuA3-0003hw-FH for 29821@debbugs.gnu.org; Wed, 03 Jan 2018 20:17:35 -0500 Received: by mail-pl0-f42.google.com with SMTP id z5so131753plo.10 for <29821@debbugs.gnu.org>; Wed, 03 Jan 2018 17:17:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=xxy40rcFKJSBQBc0bIH2L2UmO3Xd4+LePPtP7BnfP3g=; b=lGqh4ODOMQBt7TyUUbSaj4dfuCVEmH1NPmYybuwIG/l7oZZOaa+Sqtbbek/PdT+J61 Nf8c4YC0iOy8kxJmXZrJUWxSi7BwzUuKuLP4ALIp+Q2Lk0sI1tYYMNstMYSTzOFPvfVl r985/UOOY7OVMeWGfjkx8L8iv330eQjl+HiEivSHvsXFWXbrVAW6n9+31+TPZpwlVuIe vcfgc33ClE3uk1Q4dPQiUpTi46qjcabBTHDrsk0QcDWzEGKzoGxjpvmCa0TRDzfDIo0C w2cgj1XZ3/8esonBFFlVd8LDIq/QJdPb5m79NY7y5/m2rvnQQ4v9Y32YGd3yb5C+cMJt qBqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=xxy40rcFKJSBQBc0bIH2L2UmO3Xd4+LePPtP7BnfP3g=; b=pd6bwh4mr/Zv71Hm5xFqTiMg1fQWAkKbXjgwN0gN5k13dZfltHGlnayjUPiHjQXot+ cJoVsVYcVvY2RYhdmweTgZkf3aDFQhvdeLZEYoK+GfWPBnCGwu6HY82Lz4lNeMVvNxAp pqUU/c5IChGmXBUIv+YW8uHHRQAYp55nGWQCNXzME0CLjt8i+VlGoLXgEGh2+93qerzH VJjC7quouebQ/yloGq6xkbuJKrlFQjC2ac3WMtlaP9QY9HqQIU4ldnhDZ7FtcSvdQah0 YaCzCoVx3MpfPeUHwzPmhwPVUG8iU7+QiZHqtyt8iAe5WAiyG7BiQg1aKS2GgnSYOazk QoaQ== X-Gm-Message-State: AKGB3mI4vaquCIrHgTlE1fV4lWPKSCm4C6I5aSD0BBNHVT58BClcHzYH 22Q3yeHTEoFhpItgLnia658= X-Google-Smtp-Source: ACJfBouYfanCXKLrSKEP/10F31HaKzF3H9Hl7RWzIi7a3uMRujibcdPoxFA2cyOYZ3usCQyvxsN4wg== X-Received: by 10.84.246.20 with SMTP id k20mr3073975pll.209.1515028649474; Wed, 03 Jan 2018 17:17:29 -0800 (PST) Received: from laythe (c-67-161-9-47.hsd1.ca.comcast.net. [67.161.9.47]) by smtp.gmail.com with ESMTPSA id b9sm5124433pfl.108.2018.01.03.17.17.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 03 Jan 2018 17:17:28 -0800 (PST) From: Jay Kamat To: Noam Postavsky Subject: Re: bug#29821: Ensure quick substitution only occurs at start of line References: <87fu8272h6.fsf@gmail.com> <87shbqto33.fsf@users.sourceforge.net> <87wp11rqtr.fsf@users.sourceforge.net> <871sj96lgu.fsf@gmail.com> <87tvw4syi9.fsf@users.sourceforge.net> <87wp105ezz.fsf@gmail.com> <87o9mbso9j.fsf@users.sourceforge.net> Date: Wed, 03 Jan 2018 17:17:27 -0800 In-Reply-To: <87o9mbso9j.fsf@users.sourceforge.net> (Noam Postavsky's message of "Tue, 02 Jan 2018 20:51:36 -0500") Message-ID: <87po6q5sns.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 29821 Cc: 29821@debbugs.gnu.org, Andreas Schwab X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --=-=-= Content-Type: text/plain Noam Postavsky writes: > Oh, yes, I was confused by your docstring. By "if no match found" you > meant when the line doesn't match ^foo^bar^ at all; I had somehow got > the impression you meant that there was no match for "foo". Ah, yes, I'll try to make the docstring a bit more clear! > This eq test will always be nil, right? Because the only time it's t > is when you pass something that's not a history reference, but the thing > we passed is a history reference by construction. So this could be > simplified to Yup, that's true, I'll simplify that down. Here's a patch which tries to fix those issues. Thanks again, -Jay --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Prevent-expansion-of-quick-substitutions-when-not-at.patch >From e7632214858e9f12eed5d9c3cba1fb3c37529db5 Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Fri, 22 Dec 2017 15:34:44 -0800 Subject: [PATCH] Prevent expansion of quick substitutions when not at start of line See bug #29157 for an initial report Also, allow spaces inside substitutions, so ^foo bar^baz works. * lisp/eshell/em-hist.el (eshell-expand-history-references): Expand history substitution before other types of expansions, and expand them with the whole line. (eshell-history-substitution): New function to expand only substitutions, taking in the entire typed line rather than individual arguments. --- lisp/eshell/em-hist.el | 55 ++++++++++++++++++++++++++++++++------------------ lisp/eshell/em-pred.el | 3 ++- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/lisp/eshell/em-hist.el b/lisp/eshell/em-hist.el index df462a7058..b75d218110 100644 --- a/lisp/eshell/em-hist.el +++ b/lisp/eshell/em-hist.el @@ -581,21 +581,30 @@ eshell-hist-parse-arguments (defun eshell-expand-history-references (beg end) "Parse and expand any history references in current input." - (let ((result (eshell-hist-parse-arguments beg end))) + (let ((result (eshell-hist-parse-arguments beg end)) + (full-line (buffer-substring-no-properties beg end))) (when result (let ((textargs (nreverse (nth 0 result))) (posb (nreverse (nth 1 result))) - (pose (nreverse (nth 2 result)))) + (pose (nreverse (nth 2 result))) + (full-line-subst (eshell-history-substitution full-line))) (save-excursion - (while textargs - (let ((str (eshell-history-reference (car textargs)))) - (unless (eq str (car textargs)) - (goto-char (car posb)) - (insert-and-inherit str) - (delete-char (- (car pose) (car posb))))) - (setq textargs (cdr textargs) - posb (cdr posb) - pose (cdr pose)))))))) + (if full-line-subst + ;; Found a ^foo^bar substitution + (progn + (goto-char beg) + (insert-and-inherit full-line-subst) + (delete-char (- end beg))) + ;; Try to expand other substitutions + (while textargs + (let ((str (eshell-history-reference (car textargs)))) + (unless (eq str (car textargs)) + (goto-char (car posb)) + (insert-and-inherit str) + (delete-char (- (car pose) (car posb))))) + (setq textargs (cdr textargs) + posb (cdr posb) + pose (cdr pose))))))))) (defvar pcomplete-stub) (defvar pcomplete-last-completion-raw) @@ -630,20 +639,26 @@ eshell-complete-history-reference (setq history (cdr history))) (cdr fhist))))))) +(defun eshell-history-substitution (line) + "Expand quick hist substitutions formatted as ^foo^bar^. +Returns nil if string does not match quick substitution format, +and acts like !!:s/foo/bar/ otherwise." + ;; `^string1^string2^' + ;; Quick Substitution. Repeat the last command, replacing + ;; STRING1 with STRING2. Equivalent to `!!:s/string1/string2/' + (when (and (eshell-using-module 'eshell-pred) + (string-match "^\\^\\([^^]+\\)\\^\\([^^]+\\)\\^?\\s-*$" + line)) + (eshell-history-reference + (format "!!:s/%s/%s/" + (match-string 1 line) + (match-string 2 line))))) + (defun eshell-history-reference (reference) "Expand directory stack REFERENCE. The syntax used here was taken from the Bash info manual. Returns the resultant reference, or the same string REFERENCE if none matched." - ;; `^string1^string2^' - ;; Quick Substitution. Repeat the last command, replacing - ;; STRING1 with STRING2. Equivalent to `!!:s/string1/string2/' - (if (and (eshell-using-module 'eshell-pred) - (string-match "\\^\\([^^]+\\)\\^\\([^^]+\\)\\^?\\s-*$" - reference)) - (setq reference (format "!!:s/%s/%s/" - (match-string 1 reference) - (match-string 2 reference)))) ;; `!' ;; Start a history substitution, except when followed by a ;; space, tab, the end of the line, = or (. diff --git a/lisp/eshell/em-pred.el b/lisp/eshell/em-pred.el index 72a7bc4afc..86a9d4262a 100644 --- a/lisp/eshell/em-pred.el +++ b/lisp/eshell/em-pred.el @@ -545,7 +545,8 @@ eshell-pred-substitute (function (lambda (str) (if (string-match ,match str) - (setq str (replace-match ,replace t nil str))) + (setq str (replace-match ,replace t nil str)) + (error (concat str ": substitution failed"))) str)) lst))))) (defun eshell-include-members (&optional invert-p) -- 2.11.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 03 22:11:08 2018 Received: (at 29821) by debbugs.gnu.org; 4 Jan 2018 03:11:08 +0000 Received: from localhost ([127.0.0.1]:34892 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWvvv-0001zG-TR for submit@debbugs.gnu.org; Wed, 03 Jan 2018 22:11:08 -0500 Received: from mail-it0-f51.google.com ([209.85.214.51]:38643) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWvvs-0001yd-6c for 29821@debbugs.gnu.org; Wed, 03 Jan 2018 22:11:04 -0500 Received: by mail-it0-f51.google.com with SMTP id r6so800561itr.3 for <29821@debbugs.gnu.org>; Wed, 03 Jan 2018 19:11:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=kBlHL0RRY/VzWAmPDM2E9W6Almkgbr3EusthonUJHyI=; b=PVZjhpY928WovrKcMHdbTBgopiaF4k1+X46iwmefmIW/FNu3oDGK/XXM7vz589z5m3 JpmASZ8hKVQA5JEoTO+aWZ9+ynbeW6PkyazXBcSFdP+JyEkh4f7X8IQUr9HeDomHdDFz LzejVKVsvRRUsz4go8hEMajkZImyr6BxT7Ige+QuwhZG0oPomHSGo/QuFidxTJ86id5K /0OJ35KAxN1d0Cnc5sYOsTDH/G3bKmpNKD03rkCjMvTVXB7H9OLFl6MrLgTKmUYrJOBt cTYTttNWU5cMs4WvX/WhUh0QNQgtgQGmVo9Y7YgZHrzrRI79h/zKpJzjC4opGG3zKbX6 Wd9Q== 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:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=kBlHL0RRY/VzWAmPDM2E9W6Almkgbr3EusthonUJHyI=; b=FRZtSkYc/IF5hXq+0EIkToJkwkUW+nUVd/+h/ZTiJropLDsZB49xCFSQscDryOOzMG TFDvICOUa6rk5ugTuoLrAuGX40G2EXCrm0JCYeTd1PzCWnEFCEkie2EpGth6h6ANlVGt VZQo6mRFP71Rfa7xHAO5wZmDJAreeLn9IGlWtNvF77yCxdRiJRMX8xCdFb5p/a1KdBo9 BvLKZnpo6W0yNhaRkL4OG523pnbeOAoikX1+5UotB86PkTcyBdC89Tbp4zlnzoJ4FH33 jwLCquCk2EwDNE49rcYqBSiGL9bdjuGAX8Obgc1Cx80mow63u/d+dv+rLpW5/LVmdfdv jJrg== X-Gm-Message-State: AKGB3mJRs9FSt6ZJh2Ux00pcDS68ir9IKPwefC7/auZzacBr0/3LOTpU Gcg9hE9+xhqdn4Yb+vVl1F4= X-Google-Smtp-Source: ACJfBotLIOqiLnHiaXgbR5rrL4r+eyBvUv+WP9edA3HXDUTgAsx+tKPZ0H237/sF8fFlbNMQ3TY0YQ== X-Received: by 10.36.86.10 with SMTP id o10mr4045903itb.86.1515035458685; Wed, 03 Jan 2018 19:10:58 -0800 (PST) Received: from zebian ([45.2.119.34]) by smtp.googlemail.com with ESMTPSA id x97sm1407692ita.9.2018.01.03.19.10.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 03 Jan 2018 19:10:57 -0800 (PST) From: Noam Postavsky To: Jay Kamat Subject: Re: bug#29821: Ensure quick substitution only occurs at start of line References: <87fu8272h6.fsf@gmail.com> <87shbqto33.fsf@users.sourceforge.net> <87wp11rqtr.fsf@users.sourceforge.net> <871sj96lgu.fsf@gmail.com> <87tvw4syi9.fsf@users.sourceforge.net> <87wp105ezz.fsf@gmail.com> <87o9mbso9j.fsf@users.sourceforge.net> <87po6q5sns.fsf@gmail.com> Date: Wed, 03 Jan 2018 22:10:56 -0500 In-Reply-To: <87po6q5sns.fsf@gmail.com> (Jay Kamat's message of "Wed, 03 Jan 2018 17:17:27 -0800") Message-ID: <87a7xus4hr.fsf@users.sourceforge.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 29821 Cc: 29821@debbugs.gnu.org, Andreas Schwab X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) Jay Kamat writes: > Noam Postavsky writes: >> Oh, yes, I was confused by your docstring. By "if no match found" you >> meant when the line doesn't match ^foo^bar^ at all; I had somehow got >> the impression you meant that there was no match for "foo". > > Ah, yes, I'll try to make the docstring a bit more clear! Thanks, looks good now. > Here's a patch which tries to fix those issues. I almost regret to prolong this, but I found another mismatch with bash. It seems the quick substitution does not need to take up the entire line: ~/tmp$ echo foo bar foo bar ~/tmp$ ^foo^blah^ etc echo blah bar etc blah bar etc Whereas, with your patch: ~/src/emacs $ echo foo bar ("foo" "bar") ~/src/emacs $ ^foo^blah^ etc ^foo^blah^: command not found From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 04 15:26:21 2018 Received: (at 29821) by debbugs.gnu.org; 4 Jan 2018 20:26:21 +0000 Received: from localhost ([127.0.0.1]:36038 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eXC5k-0000OW-Vt for submit@debbugs.gnu.org; Thu, 04 Jan 2018 15:26:21 -0500 Received: from mail-pl0-f45.google.com ([209.85.160.45]:44597) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eXC5k-0000OJ-0c for 29821@debbugs.gnu.org; Thu, 04 Jan 2018 15:26:20 -0500 Received: by mail-pl0-f45.google.com with SMTP id n13so1677335plp.11 for <29821@debbugs.gnu.org>; Thu, 04 Jan 2018 12:26:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=og+UJj9hcww1+vaSaeEsxDqBzFORY3F7GniEisKPAng=; b=gzYaRMFgAP3aZBZ88sUG+wbvKKzBD6VmlNZny9Ubt4R8PcijCPZPE6CfrMPJ7gNRNg O20JKcceFqej/rgfMEKHPYdv0TvWq4EdY+hKj2jddGz6ACPLMEY0J/a2VAPqOGs8XFbu 2daguT5ACJ3U54Vs2lxKx4yPdQbjtqVlPhlqR95JCEXgoB1+fXI0qmisl/pFGgFmjV9B 6ApJuaiSQlLvGdkftdKhHc/h26Nfd0KqR0jnwUkI65ep+vWdkjbjhHtdngHPThNhMfJk 6UNUbxj9sgogEL8Ko/4yAWsJ4jBF8zJhvXOVicQ5qoyJFGGBT1NOkFjm+d/eNdNtPu2j oSIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=og+UJj9hcww1+vaSaeEsxDqBzFORY3F7GniEisKPAng=; b=av2IznT+DCmr9S7B3DVmIAEbi6lqMpavX1PyyS0pwm9QHu5Ynk5C33duiD6fDOtvZ3 oM17c1En3JNM8wBR0YKUSa2pJ7WMORM6YE1ei8NoQVOxWGOxMhYpGVWn98yBnJtA3E4i j4unRX3F70ww61her8iEwyL18hhOe5E7lh9IWgjjOaQiZBxvk2N84DgVtI7CTEtt17++ MX96stuX6FpfP4/L2ICDCPHIeaaboYVQ7dENcQO06aKCY00JGyqiX0MgD73MVeHZ7hB+ tZ9lUcHNl9jTQ0AxIE6FvS4qgsMOQ5FDRlenZ4qZNdbs7HPodA0qgO6yNUYbQomI+w+7 Fnhw== X-Gm-Message-State: AKGB3mK9lw814vJ2ZL0BVHPed7JsP6con6uKL9IXzVhxHb6rl3nXwWYD KEW2I3BJnwyNJk+tsh4KzFk= X-Google-Smtp-Source: ACJfBotpGx8VTjpK3c5+2igqYnNQGjCCs3AUUuqITvHJTXMt9kWRvb9cKw31ElO37Btt02yQpREKbw== X-Received: by 10.84.252.142 with SMTP id y14mr700899pll.275.1515097574005; Thu, 04 Jan 2018 12:26:14 -0800 (PST) Received: from laythe (c-67-161-9-47.hsd1.ca.comcast.net. [67.161.9.47]) by smtp.gmail.com with ESMTPSA id h81sm10905072pfh.119.2018.01.04.12.26.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jan 2018 12:26:12 -0800 (PST) From: Jay Kamat To: Noam Postavsky Subject: Re: bug#29821: Ensure quick substitution only occurs at start of line References: <87fu8272h6.fsf@gmail.com> <87shbqto33.fsf@users.sourceforge.net> <87wp11rqtr.fsf@users.sourceforge.net> <871sj96lgu.fsf@gmail.com> <87tvw4syi9.fsf@users.sourceforge.net> <87wp105ezz.fsf@gmail.com> <87o9mbso9j.fsf@users.sourceforge.net> <87po6q5sns.fsf@gmail.com> <87a7xus4hr.fsf@users.sourceforge.net> Date: Thu, 04 Jan 2018 12:26:11 -0800 In-Reply-To: <87a7xus4hr.fsf@users.sourceforge.net> (Noam Postavsky's message of "Wed, 03 Jan 2018 22:10:56 -0500") Message-ID: <877esxid5o.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 29821 Cc: 29821@debbugs.gnu.org, Andreas Schwab X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --=-=-= Content-Type: text/plain Noam Postavsky writes: > I almost regret to prolong this, but I found another mismatch with bash. > It seems the quick substitution does not need to take up the entire > line: > > ~/tmp$ echo foo bar > foo bar > ~/tmp$ ^foo^blah^ etc > echo blah bar etc > blah bar etc > > Whereas, with your patch: > > ~/src/emacs $ echo foo bar > ("foo" "bar") > ~/src/emacs $ ^foo^blah^ etc > ^foo^blah^: command not found Ah, nice catch! I've updated the patch to handle that case as well. I've tested it as well as I could and it seems good to me, but in order to fix that case, I had to mess with the regexes a bit, so It's possible I might have missed a few cases. *[j@laythe emacs]$ echo one two three ("one" "two" "three") *[j@laythe emacs]$ ^one two^five six^ seven eight *[j@laythe emacs]$ echo five six three seven eight ("five" "six" "three" "seven" "eight") *[j@laythe emacs]$ Thanks, -Jay --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Prevent-expansion-of-quick-substitutions-when-not-at.patch >From 729a73af7352b2870e65f8366c97cde49e5b1e78 Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Fri, 22 Dec 2017 15:34:44 -0800 Subject: [PATCH] Prevent expansion of quick substitutions when not at start of line See bug #29157 for an initial report In Addition: - Allow spaces inside substitutions, so ^foo bar^baz works. - Allow trailing characters after substitution, so ^foo^bar^ trailing works. - Throw an error when substitution does not match. * lisp/eshell/em-hist.el (eshell-expand-history-references): Expand history substitution before other types of expansions, and expand them with the whole line. (eshell-history-substitution): New function to expand only substitutions, taking in the entire typed line rather than individual arguments. --- lisp/eshell/em-hist.el | 60 +++++++++++++++++++++++++++++++++----------------- lisp/eshell/em-pred.el | 3 ++- 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/lisp/eshell/em-hist.el b/lisp/eshell/em-hist.el index df462a7058..f77b831b56 100644 --- a/lisp/eshell/em-hist.el +++ b/lisp/eshell/em-hist.el @@ -581,21 +581,30 @@ eshell-hist-parse-arguments (defun eshell-expand-history-references (beg end) "Parse and expand any history references in current input." - (let ((result (eshell-hist-parse-arguments beg end))) + (let ((result (eshell-hist-parse-arguments beg end)) + (full-line (buffer-substring-no-properties beg end))) (when result (let ((textargs (nreverse (nth 0 result))) (posb (nreverse (nth 1 result))) - (pose (nreverse (nth 2 result)))) + (pose (nreverse (nth 2 result))) + (full-line-subst (eshell-history-substitution full-line))) (save-excursion - (while textargs - (let ((str (eshell-history-reference (car textargs)))) - (unless (eq str (car textargs)) - (goto-char (car posb)) - (insert-and-inherit str) - (delete-char (- (car pose) (car posb))))) - (setq textargs (cdr textargs) - posb (cdr posb) - pose (cdr pose)))))))) + (if full-line-subst + ;; Found a ^foo^bar substitution + (progn + (goto-char beg) + (insert-and-inherit full-line-subst) + (delete-char (- end beg))) + ;; Try to expand other substitutions + (while textargs + (let ((str (eshell-history-reference (car textargs)))) + (unless (eq str (car textargs)) + (goto-char (car posb)) + (insert-and-inherit str) + (delete-char (- (car pose) (car posb))))) + (setq textargs (cdr textargs) + posb (cdr posb) + pose (cdr pose))))))))) (defvar pcomplete-stub) (defvar pcomplete-last-completion-raw) @@ -630,20 +639,31 @@ eshell-complete-history-reference (setq history (cdr history))) (cdr fhist))))))) +(defun eshell-history-substitution (line) + "Expand quick hist substitutions formatted as ^foo^bar^. +Returns nil if string does not match quick substitution format, +and acts like !!:s/foo/bar/ otherwise." + ;; `^string1^string2^' + ;; Quick Substitution. Repeat the last command, replacing + ;; STRING1 with STRING2. Equivalent to `!!:s/string1/string2/' + (when (and (eshell-using-module 'eshell-pred) + (string-match + "^\\^\\([^^]+\\)\\^\\([^^]+\\)\\(\\^\\(\\s-+.*\\)?\\)?\\s-*$" + line)) + ;; Save trailing match as `eshell-history-reference' runs string-match. + (let ((matched-end (match-string 4 line))) + (concat + (eshell-history-reference + (format "!!:s/%s/%s/" + (match-string 1 line) + (match-string 2 line))) + matched-end)))) + (defun eshell-history-reference (reference) "Expand directory stack REFERENCE. The syntax used here was taken from the Bash info manual. Returns the resultant reference, or the same string REFERENCE if none matched." - ;; `^string1^string2^' - ;; Quick Substitution. Repeat the last command, replacing - ;; STRING1 with STRING2. Equivalent to `!!:s/string1/string2/' - (if (and (eshell-using-module 'eshell-pred) - (string-match "\\^\\([^^]+\\)\\^\\([^^]+\\)\\^?\\s-*$" - reference)) - (setq reference (format "!!:s/%s/%s/" - (match-string 1 reference) - (match-string 2 reference)))) ;; `!' ;; Start a history substitution, except when followed by a ;; space, tab, the end of the line, = or (. diff --git a/lisp/eshell/em-pred.el b/lisp/eshell/em-pred.el index 72a7bc4afc..86a9d4262a 100644 --- a/lisp/eshell/em-pred.el +++ b/lisp/eshell/em-pred.el @@ -545,7 +545,8 @@ eshell-pred-substitute (function (lambda (str) (if (string-match ,match str) - (setq str (replace-match ,replace t nil str))) + (setq str (replace-match ,replace t nil str)) + (error (concat str ": substitution failed"))) str)) lst))))) (defun eshell-include-members (&optional invert-p) -- 2.11.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 04 20:04:20 2018 Received: (at 29821) by debbugs.gnu.org; 5 Jan 2018 01:04:20 +0000 Received: from localhost ([127.0.0.1]:36161 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eXGQm-0001nt-8Z for submit@debbugs.gnu.org; Thu, 04 Jan 2018 20:04:20 -0500 Received: from mail-io0-f169.google.com ([209.85.223.169]:45750) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eXGQj-0001nf-Ds for 29821@debbugs.gnu.org; Thu, 04 Jan 2018 20:04:19 -0500 Received: by mail-io0-f169.google.com with SMTP id e20so4107362iof.12 for <29821@debbugs.gnu.org>; Thu, 04 Jan 2018 17:04:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=DsSJ6uKqS/XpRQwAHYXdcX54GcggeJW+BviW8dWy/P0=; b=NyWnrsUSvxiwjG2X1B7W6vjFGftBu9uh3/HK/k48eb34SCj8/uXVk+VOWM1dRNTkjU S5L/aygfD5q3bwPQe7gi0fAO2uo98HuMBFiT2EqrfgY0GCgN6MAtcOH9SWjQRNSsmAcc bU7yonOQW/EjrV3O8ZAcahvXPj5TM7TvnpmMabmDINkf+fDYie//D9s9QJlvXchv5sd+ 0MOJXabLKwD/2iIgsd57L4ecghFvOc9kzQ1EXVkTxXEKRi1QkkVcHx2/EwPnC1Q1WtIE LdERs7IvPLhCGt5WyjMYAQkVA65qLVzsoxaSOsgzNIauc4FxGroGRwxaMaJwvRHOV4Jw McTw== 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:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=DsSJ6uKqS/XpRQwAHYXdcX54GcggeJW+BviW8dWy/P0=; b=WPapf0bMgFHCHlo6z1oQbYl6/Pot+g2YWEEpUeT4fvU4XMlvQUFDz4FjlmaswVifRC Spe1g25gD14fIpRj4/X9+QYg6mjl1WKpU0HwUavWm46VrOLFUAZW60t7bdns1z0OUFS7 b6Y58CrYDlKgVI2yRRpCYf38qfrO1KdenYWfmrCv8g5q1uU5UgPOdrjpOOHbcr76IKQh VA0HXIE2w0m/kiJhSNCq2h0RQDTlCTBPgUTruquXKP3rJO2CZmj/IH6iXgBhI0EqJ2Q+ zN/hL7lFg6hdeJSCPf2Cdux2grB12hjCQjNPxH0y+uqB5zmtCKy6RnqWqWShC+R4FQI2 6XBA== X-Gm-Message-State: AKGB3mJ/vwzCVqP3/E3NQMtAbA+9F+62nk2Gi+lZ1EBAmVA1oxnKFElD aMSV83w49qYTg4bjZIPyBds= X-Google-Smtp-Source: ACJfBovNZhAVkxnBRLD+Pu1GDBsOvKLBBSBRUVHQ8xBlImKBA/qd7qArbBoH6aNe8j2lCNUtQI4bBA== X-Received: by 10.107.186.139 with SMTP id k133mr1629964iof.208.1515114251942; Thu, 04 Jan 2018 17:04:11 -0800 (PST) Received: from zebian ([45.2.119.34]) by smtp.googlemail.com with ESMTPSA id x72sm2675628ite.43.2018.01.04.17.04.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jan 2018 17:04:10 -0800 (PST) From: Noam Postavsky To: Jay Kamat Subject: Re: bug#29821: Ensure quick substitution only occurs at start of line References: <87fu8272h6.fsf@gmail.com> <87shbqto33.fsf@users.sourceforge.net> <87wp11rqtr.fsf@users.sourceforge.net> <871sj96lgu.fsf@gmail.com> <87tvw4syi9.fsf@users.sourceforge.net> <87wp105ezz.fsf@gmail.com> <87o9mbso9j.fsf@users.sourceforge.net> <87po6q5sns.fsf@gmail.com> <87a7xus4hr.fsf@users.sourceforge.net> <877esxid5o.fsf@gmail.com> Date: Thu, 04 Jan 2018 20:04:09 -0500 In-Reply-To: <877esxid5o.fsf@gmail.com> (Jay Kamat's message of "Thu, 04 Jan 2018 12:26:11 -0800") Message-ID: <877esxru9i.fsf@users.sourceforge.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 29821 Cc: 29821@debbugs.gnu.org, Andreas Schwab X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) Jay Kamat writes: > Ah, nice catch! I've updated the patch to handle that case as well. I've > tested it as well as I could and it seems good to me, but in order to > fix that case, I had to mess with the regexes a bit, so It's possible I > might have missed a few cases. There doesn't need to be trailing whitespace between the last "^" and subsequent text, bash: ~/tmp$ echo foo bar foo bar ~/tmp$ ^foo^blah^x echo blah barx blah barx eshell (with your patch): ~/src/emacs $ echo foo bar ("foo" "bar") ~/src/emacs $ ^foo^blah^x ^foo^blah^x: command not found And as far as I can tell, trailing whitespace should not be dropped (though it's hard to come up with cases where it matters): ~/tmp$ echo 'foo bar ' foo bar ~/tmp$ ^bar^zz echo 'foo zz ' foo zz So I think this should do it? ... (string-match "^\\^\\([^^]+\\)\\^\\([^^]+\\)\\(?:\\^\\(.*\\)\\)?$" line)) ;; Save trailing match as `eshell-history-reference' runs string-match. (let ((matched-end (match-string 3 line))) ... From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 04 20:53:24 2018 Received: (at 29821) by debbugs.gnu.org; 5 Jan 2018 01:53:24 +0000 Received: from localhost ([127.0.0.1]:36180 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eXHCG-0002uP-92 for submit@debbugs.gnu.org; Thu, 04 Jan 2018 20:53:24 -0500 Received: from mail-pg0-f45.google.com ([74.125.83.45]:34286) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eXHCF-0002uB-2Y for 29821@debbugs.gnu.org; Thu, 04 Jan 2018 20:53:23 -0500 Received: by mail-pg0-f45.google.com with SMTP id j4so1446479pgp.1 for <29821@debbugs.gnu.org>; Thu, 04 Jan 2018 17:53:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=sl9Fc7yYos9GAxrp0gazOnBLDqkbJSEbmuqlsfF7TWA=; b=BJ2SlHeDNXCiGMNCM6m2Wxoolh5cQFxLoThe6QiPaDTN05qLdTxCCnRmFLj7Bs6xKA CvnsykaJ59eJod8TeGtZPIelRM69F2Ck46FgSqHufEaDVIO5I9HW15V9qdVdgLnMYn0D KanI8V+Uj9dojapfxO1Q0LbGYL16yuwzYUKqiyRlPPtVBgNBYWqZC8dsFly0mK1pbKif oMrzXg4qVfQN8EVglQbqSHv/TTfJtJ2Gv6LOKPdmgqU0CN1fHw6JCZYrrexEOGjjnEfz eEHpXeAkgaubZ6sWKgv8xhfWnfYpoCg5AfiYMd0l94OD7FRPZYJF947+bPUwHwbaUbUX RNEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=sl9Fc7yYos9GAxrp0gazOnBLDqkbJSEbmuqlsfF7TWA=; b=en1hzDg2G/IG1jouOO/Gs5fzLSI96YaoxcDAIOmp2VmAJJLd3E6BDzbLzqFfwHGIG7 xzahVN+6/lAI3h36JPpvH4xYscHmb364Slv+L8QXQVZDoeViNUqXUSSNj6Ho/7RI3pve hsvfUyZQ+7qiYJLsW7rNnfY0hH1wfZ1TBTaEH3wX7KtrZB015abUOU//KltSX6fnWSsY YRqg9/vDC1bJBjvw7k6Qw5jFosXQK8sCmsehpMP3nTjqJKR53bf3fx+HQfx0cLMgQoOg ATaV5X4/TT9xEs5uLqXLGIJeU2aY7rRjUp8efqMEluBWaX2e4M+j2QpwwF06zCpgYZ96 Y+gA== X-Gm-Message-State: AKGB3mIwpFsPof8/BADQ3NA90cOhsoy0U41yOpA6voFZJT067thAcTqk oX53c42ICU2DCVxJIIDIekI= X-Google-Smtp-Source: ACJfBovHadWk3hWo151UeXmrIwPUl98sC6PLOF2lLsb/64DL3ntDp/JUT4iafEkaruq+IoG9FkUgPA== X-Received: by 10.99.96.69 with SMTP id u66mr1192399pgb.355.1515117197148; Thu, 04 Jan 2018 17:53:17 -0800 (PST) Received: from laythe (c-67-161-9-47.hsd1.ca.comcast.net. [67.161.9.47]) by smtp.gmail.com with ESMTPSA id g1sm8384925pgc.32.2018.01.04.17.53.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jan 2018 17:53:15 -0800 (PST) From: Jay Kamat To: Noam Postavsky Subject: Re: bug#29821: Ensure quick substitution only occurs at start of line References: <87fu8272h6.fsf@gmail.com> <87shbqto33.fsf@users.sourceforge.net> <87wp11rqtr.fsf@users.sourceforge.net> <871sj96lgu.fsf@gmail.com> <87tvw4syi9.fsf@users.sourceforge.net> <87wp105ezz.fsf@gmail.com> <87o9mbso9j.fsf@users.sourceforge.net> <87po6q5sns.fsf@gmail.com> <87a7xus4hr.fsf@users.sourceforge.net> <877esxid5o.fsf@gmail.com> <877esxru9i.fsf@users.sourceforge.net> Date: Thu, 04 Jan 2018 17:53:14 -0800 In-Reply-To: <877esxru9i.fsf@users.sourceforge.net> (Noam Postavsky's message of "Thu, 04 Jan 2018 20:04:09 -0500") Message-ID: <87373lhy0l.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 29821 Cc: 29821@debbugs.gnu.org, Andreas Schwab X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --=-=-= Content-Type: text/plain Noam Postavsky writes: > There doesn't need to be trailing whitespace between the last "^" and > subsequent text, bash: > So I think this should do it? > > ... > (string-match > "^\\^\\([^^]+\\)\\^\\([^^]+\\)\\(?:\\^\\(.*\\)\\)?$" > line)) > ;; Save trailing match as `eshell-history-reference' runs string-match. > (let ((matched-end (match-string 3 line))) > ... Yup, that regex works perfectly for everything I tried, and preserves the white-space at the end of the target (as bash does). I think it's a good idea to follow bash as closely as possible. For convenience, I've attached a new patch with those changes. Thanks, -Jay --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Prevent-expansion-of-quick-substitutions-when-not-at.patch >From b901ce56d646d7145989825f7c4b8d408bc500ac Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Fri, 22 Dec 2017 15:34:44 -0800 Subject: [PATCH] Prevent expansion of quick substitutions when not at start of line See bug #29157 for an initial report In Addition: - Allow spaces inside substitutions, so ^foo bar^baz works. - Allow trailing characters after substitution, so ^foo^bar^ trailing works. - Throw an error when substitution does not match. * lisp/eshell/em-hist.el (eshell-expand-history-references): Expand history substitution before other types of expansions, and expand them with the whole line. (eshell-history-substitution): New function to expand only substitutions, taking in the entire typed line rather than individual arguments. --- lisp/eshell/em-hist.el | 60 +++++++++++++++++++++++++++++++++----------------- lisp/eshell/em-pred.el | 3 ++- 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/lisp/eshell/em-hist.el b/lisp/eshell/em-hist.el index df462a7058..f923ca679b 100644 --- a/lisp/eshell/em-hist.el +++ b/lisp/eshell/em-hist.el @@ -581,21 +581,30 @@ eshell-hist-parse-arguments (defun eshell-expand-history-references (beg end) "Parse and expand any history references in current input." - (let ((result (eshell-hist-parse-arguments beg end))) + (let ((result (eshell-hist-parse-arguments beg end)) + (full-line (buffer-substring-no-properties beg end))) (when result (let ((textargs (nreverse (nth 0 result))) (posb (nreverse (nth 1 result))) - (pose (nreverse (nth 2 result)))) + (pose (nreverse (nth 2 result))) + (full-line-subst (eshell-history-substitution full-line))) (save-excursion - (while textargs - (let ((str (eshell-history-reference (car textargs)))) - (unless (eq str (car textargs)) - (goto-char (car posb)) - (insert-and-inherit str) - (delete-char (- (car pose) (car posb))))) - (setq textargs (cdr textargs) - posb (cdr posb) - pose (cdr pose)))))))) + (if full-line-subst + ;; Found a ^foo^bar substitution + (progn + (goto-char beg) + (insert-and-inherit full-line-subst) + (delete-char (- end beg))) + ;; Try to expand other substitutions + (while textargs + (let ((str (eshell-history-reference (car textargs)))) + (unless (eq str (car textargs)) + (goto-char (car posb)) + (insert-and-inherit str) + (delete-char (- (car pose) (car posb))))) + (setq textargs (cdr textargs) + posb (cdr posb) + pose (cdr pose))))))))) (defvar pcomplete-stub) (defvar pcomplete-last-completion-raw) @@ -630,20 +639,31 @@ eshell-complete-history-reference (setq history (cdr history))) (cdr fhist))))))) +(defun eshell-history-substitution (line) + "Expand quick hist substitutions formatted as ^foo^bar^. +Returns nil if string does not match quick substitution format, +and acts like !!:s/foo/bar/ otherwise." + ;; `^string1^string2^' + ;; Quick Substitution. Repeat the last command, replacing + ;; STRING1 with STRING2. Equivalent to `!!:s/string1/string2/' + (when (and (eshell-using-module 'eshell-pred) + (string-match + "^\\^\\([^^]+\\)\\^\\([^^]+\\)\\(?:\\^\\(.*\\)\\)?$" + line)) + ;; Save trailing match as `eshell-history-reference' runs string-match. + (let ((matched-end (match-string 3 line))) + (concat + (eshell-history-reference + (format "!!:s/%s/%s/" + (match-string 1 line) + (match-string 2 line))) + matched-end)))) + (defun eshell-history-reference (reference) "Expand directory stack REFERENCE. The syntax used here was taken from the Bash info manual. Returns the resultant reference, or the same string REFERENCE if none matched." - ;; `^string1^string2^' - ;; Quick Substitution. Repeat the last command, replacing - ;; STRING1 with STRING2. Equivalent to `!!:s/string1/string2/' - (if (and (eshell-using-module 'eshell-pred) - (string-match "\\^\\([^^]+\\)\\^\\([^^]+\\)\\^?\\s-*$" - reference)) - (setq reference (format "!!:s/%s/%s/" - (match-string 1 reference) - (match-string 2 reference)))) ;; `!' ;; Start a history substitution, except when followed by a ;; space, tab, the end of the line, = or (. diff --git a/lisp/eshell/em-pred.el b/lisp/eshell/em-pred.el index 72a7bc4afc..86a9d4262a 100644 --- a/lisp/eshell/em-pred.el +++ b/lisp/eshell/em-pred.el @@ -545,7 +545,8 @@ eshell-pred-substitute (function (lambda (str) (if (string-match ,match str) - (setq str (replace-match ,replace t nil str))) + (setq str (replace-match ,replace t nil str)) + (error (concat str ": substitution failed"))) str)) lst))))) (defun eshell-include-members (&optional invert-p) -- 2.11.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 05 09:31:46 2018 Received: (at 29821) by debbugs.gnu.org; 5 Jan 2018 14:31:47 +0000 Received: from localhost ([127.0.0.1]:36420 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eXT2A-0001dC-N1 for submit@debbugs.gnu.org; Fri, 05 Jan 2018 09:31:46 -0500 Received: from mail-io0-f169.google.com ([209.85.223.169]:41302) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eXT28-0001cv-UU; Fri, 05 Jan 2018 09:31:45 -0500 Received: by mail-io0-f169.google.com with SMTP id f6so5932853ioh.8; Fri, 05 Jan 2018 06:31:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=7pPaTdT8VyNLy9MsKxifvZZzUzPcF0O8S2yNKcpqCzY=; b=nUYVTWAAqva844LhUOTULHGuayk94GZ9AH/yJpRKKviopQJJJIHMYgf4sZn3We/NoE BroJIeOBwn4fRhNiEozmF06x985gVcI6iDjpcFP/XsnvA2/9pCvXTNyCiVCsUWpI1D70 PVrbd+GgYSMjqHEbOA6A4MCGZvV4ik4GxPjIn/WMzbDQs+Ea3RE9fH0mkb0EwdD0IeIo viHfOcWHIzy4I10qptRDlatlZyjcHC1xd/jJbFcGhhCz+Pce6AzGrdqcMOx2V3EdzEGf fL7Ge8W+9DejiDChcuoAgs/FUUHLJDEfu74ITw+cJMW94/7dIQ/oAXc8hIpWDqS2bWuX dIVw== 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:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=7pPaTdT8VyNLy9MsKxifvZZzUzPcF0O8S2yNKcpqCzY=; b=PczbA8NgRNwIGKLicfFyU497ZLwNywyZcpXnwwLdaQh3oZ93eKdKd3Af1tAwyxoo/8 DbOk3TbNUt+ggnMFPJ9s/mibmw0n4gefnL+17x8PGSD/FTCiXG8AWzab/HB1P42POhXq N+zBkyz48seAELZ7lZrZWuH/qspL+v9icOLO542cIXL/BS639plYV9hbLwgkxNJHmmFc X2ph1WGbV44CDhRA7rMkVNvGJzsIGh+egDDy481DvfOtx75QGYzvyCb0SrMMpeXqM3tw U7HtgX1cn1GQYI1OJPCHPT/Y32ZBPlvivAR0D3Dy0sCBP9ecrrynWO8kJ5567Ho7YJF2 iSNQ== X-Gm-Message-State: AKGB3mLPFoi06EvpQLQ/3LuO0Aw9cR2rugw5VliYIoY8mr5ZmbO7i8s6 WFeKoJwQYfmBp3fbI/EIv2GKHQ== X-Google-Smtp-Source: ACJfBouIpkQ7ecFO50xEHOB8MkqYFzbqbiahTiXUp3O0MEtwh4suN099BiqJZEZgfDxpTNZuWjL3VQ== X-Received: by 10.107.169.149 with SMTP id f21mr3062604ioj.182.1515162699090; Fri, 05 Jan 2018 06:31:39 -0800 (PST) Received: from zebian ([45.2.119.34]) by smtp.googlemail.com with ESMTPSA id 86sm3709298iom.31.2018.01.05.06.31.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 05 Jan 2018 06:31:37 -0800 (PST) From: Noam Postavsky To: Jay Kamat Subject: Re: bug#29821: Ensure quick substitution only occurs at start of line References: <87fu8272h6.fsf@gmail.com> <87shbqto33.fsf@users.sourceforge.net> <87wp11rqtr.fsf@users.sourceforge.net> <871sj96lgu.fsf@gmail.com> <87tvw4syi9.fsf@users.sourceforge.net> <87wp105ezz.fsf@gmail.com> <87o9mbso9j.fsf@users.sourceforge.net> <87po6q5sns.fsf@gmail.com> <87a7xus4hr.fsf@users.sourceforge.net> <877esxid5o.fsf@gmail.com> <877esxru9i.fsf@users.sourceforge.net> <87373lhy0l.fsf@gmail.com> Date: Fri, 05 Jan 2018 09:31:36 -0500 In-Reply-To: <87373lhy0l.fsf@gmail.com> (Jay Kamat's message of "Thu, 04 Jan 2018 17:53:14 -0800") Message-ID: <87y3lcqsvr.fsf@users.sourceforge.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 29821 Cc: 29821@debbugs.gnu.org, Andreas Schwab X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) tags 29821 fixed close 29821 27.1 quit Jay Kamat writes: > Yup, that regex works perfectly for everything I tried, and preserves > the white-space at the end of the target (as bash does). I think it's a > good idea to follow bash as closely as possible. > > For convenience, I've attached a new patch with those changes. Thanks, pushed to master (with slight changes to the commit message to better reflect the expanded scope of this bug). [1: 933d8fc0b7]: 2018-01-05 09:29:00 -0500 Make eshell history expansion more like bash (Bug#29821) https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=933d8fc0b70452f8a266e761231e58a759a7c80a From unknown Wed Jun 18 23:18:38 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sat, 03 Feb 2018 12:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator