unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Tino Calancha <tino.calancha@gmail.com>
Cc: 31492@debbugs.gnu.org
Subject: bug#31492: 26.1; query-replace-regexp undo fails in regexps w/o printable chars
Date: Sun, 20 May 2018 12:29:07 +0300	[thread overview]
Message-ID: <83vabifzfg.fsf@gnu.org> (raw)
In-Reply-To: <87tvr3zpm4.fsf@gmail.com> (message from Tino Calancha on Sat, 19 May 2018 23:28:35 +0900)

> From: Tino Calancha <tino.calancha@gmail.com>
> Cc: 31492@debbugs.gnu.org
> Date: Sat, 19 May 2018 23:28:35 +0900
> 
> > The relevant
> > element of the replacement stack (whose structure, btw, seems not to
> > be documented anywhere), is (4 4 *scratch*), whereas I'd expect to see
> > (1 4 *scratch) instead, because the replacement was at position 1;
> > then setting match-data from this would DTRT.
> Yes, that is the logic.  The thing is, for some unknown reason to me,
> the reported match-data is inexact when there are no printable chars
> in the regexp (maybe it's expected and I am wrong on my assumptions).

The reason for that is that match-data is recorded as markers, and so
the positions move if text is inserted.  In your example, the position
of $ moved due to insertion, so the marker's position was updated as
part of the replacement.

> (with-temp-buffer
>   (insert "foo")
>   (goto-char 1)
>   (progn (re-search-forward "$" nil t)
> 	 (save-match-data (replace-match "ZZZ"))
> 	 (list (point) (match-beginning 0) (match-end 0))))
> => (7 7 7)
> ;; If this would be (7 4 7), then we could use `looking-at'; we are to
> ;; the right of the replacement, then we use `looking-back'.
>   
> 
> ;; But the match was at 4 not at 7
> (with-temp-buffer
>   (insert "foo")
>   (goto-char 1)
>   (progn (re-search-forward "$" nil t)
> 	 (list (point) (match-beginning 0) (match-end 0))))
> => (4 4 4)

Right, and so I submit that the problem is where the replacement stack
is updated: it should account for these subtleties and adjust the
stack positions accordingly, since it has the opportunity to look at
the match position before the matched text is replaced.  It is IMO
suboptimal to make these adjustments where the stack is used, because
you've lost the information about the actual match point, and you are
deducing it using heuristics, which I'm not sure is 100% reliable.

Thanks.





  reply	other threads:[~2018-05-20  9:29 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-18 13:27 bug#31492: 26.1; query-replace-regexp undo fails in regexps w/o printable chars Tino Calancha
2018-05-18 14:16 ` Eli Zaretskii
2018-05-18 14:22   ` Tino Calancha
2018-05-18 15:07     ` Eli Zaretskii
2018-05-19  1:46       ` Tino Calancha
2018-05-19  7:50         ` Eli Zaretskii
2018-05-19 14:28           ` Tino Calancha
2018-05-20  9:29             ` Eli Zaretskii [this message]
2018-05-20 11:51               ` Tino Calancha
2018-05-20 11:59                 ` Eli Zaretskii
2018-05-20 12:06                   ` Tino Calancha
2018-05-20 12:48                     ` Eli Zaretskii
2018-05-20 13:46                       ` Tino Calancha
2018-05-20 15:47                         ` Eli Zaretskii
2018-05-21  1:51                           ` Tino Calancha
2018-05-21 15:05                             ` Eli Zaretskii
2018-05-23  9:22                               ` Tino Calancha

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=83vabifzfg.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=31492@debbugs.gnu.org \
    --cc=tino.calancha@gmail.com \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).