help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using undo from code?


From: Kevin Rodgers
Subject: Re: Using undo from code?
Date: Mon, 02 Dec 2002 15:39:38 -0700
User-agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:0.9.4.1) Gecko/20020406 Netscape6/6.2.2

Hannu Koivisto wrote:

Greetings,

I have the following function:

(defun se:move-past-close-and-just-one-space ()
  "Move past next `)' and ensure just one space after it."
  (interactive)
  (up-list)
  (just-one-space))

I decided that I want consecutive invocations of the function to
undo the (just-one-space) of the previous invocation.  I thought
"easy, I just utilize last-command and undo" and thus wrote:

(defun se:move-past-close-and-just-one-space ()
  "Move past next `)' and ensure just one space after it."
  (interactive)
  (when (eq 'se:move-past-close-and-just-one-space last-command)
    (undo))
  (up-list)
  (just-one-space))

But this doesn't really work and I cannot even explain how it does
not work; it behaves pretty erratically.  I can only give two
examples.  Let's say that the function is bound to s-n.  Given

M-( M-( M-( s-n s-n s-n

the behaviour is expected except after the last s-n; in that case
the effect of the last just-one-space is not undone.  I.e. it works
twice but not three times.  Also, given

M-( M-( M-( s-n s-n C-_

I end up with

((<point>) )

instead of

((() <point>))

where the latter is what I want.  I guess I would have understood
((() )<point>) as well.

It seems clear that my attempt to use undo this way was not exactly
a good idea.  Or perhaps the idea of using undo is ok, but I need
to generate undo information in a way specific to my function.
What approach would you suggest?


Perhaps you need to call undo-boundary before moving point and modifying the
buffer.

--
<a href="mailto:&lt;kevin.rodgers&#64;ihs.com&gt;";>Kevin Rodgers</a>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]