all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: martin rudalics <rudalics@gmx.at>
To: Chris Moore <christopher.ian.moore@gmail.com>
Cc: emacs-pretest-bug@gnu.org
Subject: Re: undo after repeatedly calling 'repeat' leaves cursor in the wrong place
Date: Sun, 16 Sep 2007 15:12:25 +0200	[thread overview]
Message-ID: <46ED2BB9.6090606@gmx.at> (raw)
In-Reply-To: <a9691ee20709151432r579a186du41e8a160e2aff88a@mail.gmail.com>

 > Type
 >   "x C-x z z z z C-x u"
 > (to insert an 'x', repeat the insert 4 times, then undo the last of the 4)
 >
 > Before the "C-x u" there were 5 'x's with the cursor after them all.
 > After the "C-x u" there are 4 'x's, as expected, but the cursor is on
 > the 2nd one, whereas I would expect it to be after the 4th one.
 >
 > If "C-x z" is used in full each time, instead of just hitting 'z' over
 > and over, then the undo works as expected.

`repeat' has the loop

         (while (eq (read-event) repeat-repeat-char)
	  ;; Make each repetition undo separately.
	  (undo-boundary)
           (repeat repeat-arg))

Note that `read-event' does not update `last_point_position' and
`undo-boundary' inserts nil into `buffer-undo-list' which prevents
combining the insertions.  `record_insert' calls `record_point' with the
positions where an "x" shall be inserted (2, 3, ...) but `record_point'
still relies on the old position (namely 2) stored for
`last_point_position', decides that it is not equal to point in

       if (last_point_position != pt)
	current_buffer->undo_list
	  = Fcons (make_number (last_point_position), current_buffer->undo_list);

and repeatedly inserts a 2 into `buffer-undo-list'.  Note that
replacing the latter by

       if (last_point_position != pt)
	{
	  current_buffer->undo_list
	    = Fcons (make_number (last_point_position), current_buffer->undo_list);
	  last_point_position = pt;
	}

still gets an off-by-one error.  I think two changes are needed:

(1) For a self-insert-command `repeat' should not construct undo
boundaries.  This would correct the bug reported by Chris but fail for
more complex commands.

(2) Use a separate variable, locally bound in `repeat' around the
recursive call to itself, to assert that `record_point' updates
`last_point_position' before comparing it with `pt'.  Maybe someone has
an idea how to avoid such a variable.  I'd rather not remove such items
from `buffer-undo-list' manually.

  reply	other threads:[~2007-09-16 13:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-15 21:32 undo after repeatedly calling 'repeat' leaves cursor in the wrong place Chris Moore
2007-09-16 13:12 ` martin rudalics [this message]
2007-10-04  8:27 ` martin rudalics

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=46ED2BB9.6090606@gmx.at \
    --to=rudalics@gmx.at \
    --cc=christopher.ian.moore@gmail.com \
    --cc=emacs-pretest-bug@gnu.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.