all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Noam Postavsky <npostavs@users.sourceforge.net>
To: Jay Kamat <jaygkamat@gmail.com>
Cc: 29821@debbugs.gnu.org, Andreas Schwab <schwab@linux-m68k.org>
Subject: bug#29821: Ensure quick substitution only occurs at start of line
Date: Tue, 02 Jan 2018 20:51:36 -0500	[thread overview]
Message-ID: <87o9mbso9j.fsf@users.sourceforge.net> (raw)
In-Reply-To: <87wp105ezz.fsf@gmail.com> (Jay Kamat's message of "Tue, 02 Jan 2018 09:48:00 -0800")

Jay Kamat <jaygkamat@gmail.com> writes:

> Noam Postavsky <npostavs@users.sourceforge.net> 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).





  reply	other threads:[~2018-01-03  1:51 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-22 23:57 bug#29821: Ensure quick substitution only occurs at start of line Jay Kamat
2018-01-01  0:33 ` Noam Postavsky
2018-01-01  9:56   ` Andreas Schwab
2018-01-02  1:29     ` Noam Postavsky
2018-01-02  2:30       ` Jay Kamat
2018-01-02  3:58         ` Noam Postavsky
2018-01-02 17:48           ` Jay Kamat
2018-01-03  1:51             ` Noam Postavsky [this message]
2018-01-04  1:17               ` Jay Kamat
2018-01-04  3:10                 ` Noam Postavsky
2018-01-04 20:26                   ` Jay Kamat
2018-01-05  1:04                     ` Noam Postavsky
2018-01-05  1:53                       ` Jay Kamat
2018-01-05 14:31                         ` Noam Postavsky
2018-01-01 23:44   ` Jay Kamat

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o9mbso9j.fsf@users.sourceforge.net \
    --to=npostavs@users.sourceforge.net \
    --cc=29821@debbugs.gnu.org \
    --cc=jaygkamat@gmail.com \
    --cc=schwab@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.