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

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

Using undo from code?


From: Hannu Koivisto
Subject: Using undo from code?
Date: Mon, 02 Dec 2002 13:54:56 +0200
User-agent: Gnus/5.090007 (Oort Gnus v0.07) Emacs/21.2 (i686-pc-linux-gnu)

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?

-- 
Hannu


reply via email to

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