* question about markers, replace-match, and undo
@ 2007-04-27 16:44 Drew Adams
2007-04-27 17:43 ` Johan Bockgård
2007-04-28 4:07 ` Richard Stallman
0 siblings, 2 replies; 9+ messages in thread
From: Drew Adams @ 2007-04-27 16:44 UTC (permalink / raw)
To: Emacs-Devel
I have some text, with a marker before it and a marker after it. For
instance, the first marker is at position 41, just before `m', and the
second is at position 48, just after `s':
41 48
mnopqrs
I match this text, and then call (replace-match "ABC"), with the result that
the first marker is still at position 41 and the second marker is now at
position 44, just after `C', which is what I would expect and what I want:
41 44
ABC
I use `undo', and the result is that both markers are now at position 41:
41
41
mnopqrs
I get the same behavior if I use various additional args to `replace-match'.
I've also tried (progn (undo-boundary) (replace-match "ABC")), with no
change.
I'm not saying there is necessarily a bug here; I don't know. I'm asking how
I can get `undo' to restore not only the text but the marker positions. If I
use, for instance, `delete-region' and `insert', there is no problem, but I
need to be able to use `replace-match' here.
What also seems odd is that (buffer-has-markers-at 48) returns t, but
`mark-ring' shows only two markers, both at position 41, and the mark itself
is somewhere else altogether (e.g. 18). I also used a library `mark.el' from
Emacs Wiki that lets you access the markers in a buffer, and it does not
show any marker at 48. So perhaps `buffer-has-markers-at' is reporting
erroneously here?
[BTW, I also wonder why we have `buffer-has-markers-at', but we apparently
have no function that returns the list of markers at a given position.]
Can anyone help with my question of how to get `undo' to act as an inverse
of `replace-match' wrt the markers? Thx.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: question about markers, replace-match, and undo
2007-04-27 16:44 question about markers, replace-match, and undo Drew Adams
@ 2007-04-27 17:43 ` Johan Bockgård
2007-04-27 18:13 ` Drew Adams
2007-04-28 4:07 ` Richard Stallman
1 sibling, 1 reply; 9+ messages in thread
From: Johan Bockgård @ 2007-04-27 17:43 UTC (permalink / raw)
To: emacs-devel
"Drew Adams" <drew.adams@oracle.com> writes:
> I'm not saying there is necessarily a bug here; I don't know. I'm asking how
> I can get `undo' to restore not only the text but the marker positions.
FWIW, the markers are correctly restored in Emacs 21.
--
Johan Bockgård
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: question about markers, replace-match, and undo
2007-04-27 17:43 ` Johan Bockgård
@ 2007-04-27 18:13 ` Drew Adams
0 siblings, 0 replies; 9+ messages in thread
From: Drew Adams @ 2007-04-27 18:13 UTC (permalink / raw)
To: Johan "Bockgård", emacs-devel
> > I'm not saying there is necessarily a bug here; I don't know.
> > I'm asking how I can get `undo' to restore not only the text
> > but the marker positions.
>
> FWIW, the markers are correctly restored in Emacs 21.
Ah, thanks Johan.
So is this an Emacs 22 bug, or is the current behavior intended and a fix for an Emacs 21 bug?
If this is the intended behavior, can anyone help with how to force the previous behavior (i.e. restore the markers to their original positions)?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: question about markers, replace-match, and undo
2007-04-27 16:44 question about markers, replace-match, and undo Drew Adams
2007-04-27 17:43 ` Johan Bockgård
@ 2007-04-28 4:07 ` Richard Stallman
2007-04-28 4:13 ` Drew Adams
1 sibling, 1 reply; 9+ messages in thread
From: Richard Stallman @ 2007-04-28 4:07 UTC (permalink / raw)
To: Drew Adams; +Cc: emacs-devel
I have some text, with a marker before it and a marker after it. For
instance, the first marker is at position 41, just before `m', and the
second is at position 48, just after `s':
41 48
mnopqrs
I match this text, and then call (replace-match "ABC"), with the result that
the first marker is still at position 41 and the second marker is now at
position 44, just after `C', which is what I would expect and what I want:
41 44
ABC
I use `undo', and the result is that both markers are now at position 41:
41
41
mnopqrs
That is definitely a bug. Does this fix it?
*** insdel.c 02 Mar 2007 03:28:13 -0500 1.190
--- insdel.c 27 Apr 2007 23:55:23 -0400
***************
*** 1603,1610 ****
if (! EQ (current_buffer->undo_list, Qt))
{
record_delete (from, deletion);
- record_insert (from, inschars);
}
GAP_SIZE -= outgoing_insbytes;
--- 1603,1614 ----
if (! EQ (current_buffer->undo_list, Qt))
{
+ /* Record the insertion first, so that when we undo,
+ the deletion will be undone first. Thus, undo
+ will insert before deleting, and thus will keep
+ the markers before and after this text separate. */
+ record_insert (from + SCHARS (deletion), inschars);
record_delete (from, deletion);
}
GAP_SIZE -= outgoing_insbytes;
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: question about markers, replace-match, and undo
2007-04-28 4:07 ` Richard Stallman
@ 2007-04-28 4:13 ` Drew Adams
2007-04-29 14:27 ` Richard Stallman
0 siblings, 1 reply; 9+ messages in thread
From: Drew Adams @ 2007-04-28 4:13 UTC (permalink / raw)
To: rms; +Cc: emacs-devel
> That is definitely a bug. Does this fix it?
I cannot tell; I don't build from C sources. If someone else could have a
look, that would be great. Thanks.
> *** insdel.c 02 Mar 2007 03:28:13 -0500 1.190
> --- insdel.c 27 Apr 2007 23:55:23 -0400
> ***************
> *** 1603,1610 ****
>
> if (! EQ (current_buffer->undo_list, Qt))
> {
> record_delete (from, deletion);
> - record_insert (from, inschars);
> }
>
> GAP_SIZE -= outgoing_insbytes;
> --- 1603,1614 ----
>
> if (! EQ (current_buffer->undo_list, Qt))
> {
> + /* Record the insertion first, so that when we undo,
> + the deletion will be undone first. Thus, undo
> + will insert before deleting, and thus will keep
> + the markers before and after this text separate. */
> + record_insert (from + SCHARS (deletion), inschars);
> record_delete (from, deletion);
> }
>
> GAP_SIZE -= outgoing_insbytes;
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: question about markers, replace-match, and undo
2007-04-28 4:13 ` Drew Adams
@ 2007-04-29 14:27 ` Richard Stallman
2007-04-29 15:19 ` Johan Bockgård
0 siblings, 1 reply; 9+ messages in thread
From: Richard Stallman @ 2007-04-29 14:27 UTC (permalink / raw)
To: Drew Adams; +Cc: emacs-devel
Can you send a program to construct the test case that fails for you?
Then I will test my patch and make sure it fixes your problem.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: question about markers, replace-match, and undo
2007-04-29 14:27 ` Richard Stallman
@ 2007-04-29 15:19 ` Johan Bockgård
2007-04-29 16:08 ` Drew Adams
2007-04-30 22:09 ` Richard Stallman
0 siblings, 2 replies; 9+ messages in thread
From: Johan Bockgård @ 2007-04-29 15:19 UTC (permalink / raw)
To: emacs-devel
Richard Stallman <rms@gnu.org> writes:
> Can you send a program to construct the test case that fails for you?
> Then I will test my patch and make sure it fixes your problem.
I tested it like this:
$ emacs -Q
---------- Buffer: *scratch* ----------
123456
(defun a ()
(interactive)
(setq a (copy-marker 1))
(setq b (copy-marker 7))
(goto-char (point-min))
(re-search-forward "123456")
(replace-match "000"))
(defun b ()
(interactive)
(message "%s, %s" a b))
---------- Buffer: *scratch* ----------
Eval the buffer.
M-x a RET
Undo (C-/)
M-x b RET
Emacs 21
=> #<marker at 1 in *scratch*>, #<marker at 7 in *scratch*>
Emacs 22
=> #<marker at 1 in *scratch*>, #<marker at 1 in *scratch*>
Emacs 22 after your patch
=> #<marker at 1 in *scratch*>, #<marker at 7 in *scratch*>
--
Johan Bockgård
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: question about markers, replace-match, and undo
2007-04-29 15:19 ` Johan Bockgård
@ 2007-04-29 16:08 ` Drew Adams
2007-04-30 22:09 ` Richard Stallman
1 sibling, 0 replies; 9+ messages in thread
From: Drew Adams @ 2007-04-29 16:08 UTC (permalink / raw)
To: emacs-devel
> > Can you send a program to construct the test case that fails for you?
> > Then I will test my patch and make sure it fixes your problem.
>
Johan> I tested it like this:
...
What Johan did is essentially what I did, so I think this is fixed. Thanks.
What I did (see my initial report):
emacs -Q
type mnopqrs in a buffer
C-SPC at (before) m
C-SPC after s
C-s mnopqrs RET
(replace-match "ABC")
C-_
Look at mark-ring and (mark).
I also reported a bug (?) about `buffer-has-markers-at'. In this case, even though the bugged result above is two markers before m and no marker after s, `buffer-has-markers-at' returns t for the position after s.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: question about markers, replace-match, and undo
2007-04-29 15:19 ` Johan Bockgård
2007-04-29 16:08 ` Drew Adams
@ 2007-04-30 22:09 ` Richard Stallman
1 sibling, 0 replies; 9+ messages in thread
From: Richard Stallman @ 2007-04-30 22:09 UTC (permalink / raw)
To: Johan Bockgård; +Cc: emacs-devel
Thanks. Now I am confident this is fixed.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2007-04-30 22:09 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-27 16:44 question about markers, replace-match, and undo Drew Adams
2007-04-27 17:43 ` Johan Bockgård
2007-04-27 18:13 ` Drew Adams
2007-04-28 4:07 ` Richard Stallman
2007-04-28 4:13 ` Drew Adams
2007-04-29 14:27 ` Richard Stallman
2007-04-29 15:19 ` Johan Bockgård
2007-04-29 16:08 ` Drew Adams
2007-04-30 22:09 ` Richard Stallman
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).