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

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

Re: tricky - undo function - planning info


From: Bob Proulx
Subject: Re: tricky - undo function - planning info
Date: Sun, 7 Jun 2015 17:06:17 -0600
User-agent: Mutt/1.5.23 (2014-03-12)

Emanuel Berg wrote:
> gnuist006@gmail.com writes:
> 
> > Normally M-x undo would undo each step.
> 
> Bind that to a key if it isn't already. Short and
> close. I have that M-0 but I think the standard is C-/
> among others. Train your fingers with the one you like
> the most.

It is bound to C-x u, C-_, C-/ at the least plus others.

  C-h f undo

  undo is an interactive compiled Lisp function in `simple.el'.
  It is bound to C-_, <undo>, C-/, C-x u, <menu-bar> <edit> <undo>.

I remember C-x u being the key binding in emacs v18.  But it is much
more convenient having it be a single key action rather than a
sequence.  Too easy to make a mistake with a sequence and start
undoing the undo.  Also M-x undo-only is very useful.

> > A function may comprise one or more steps.
> > When a function is applied, and then undone, it is
> > not clear how many steps of undo are really needed.

Interactive undo is meant to be interactive.  You should be able to
tell when the buffer has been undone to where you want.  Are you
trying to invoke undo programatically as part of an elisp function?  I
don't think that is the way to go.  I will assume otherwise and talk
about some other points of undo.

Very useful is restricting undo to within an active region.  Don't
undo globally.  Undo only within the restriction of the active region.
Here are the docs on it:

     When there is an active region, any use of ‘undo’ performs "selective
  undo": it undoes the most recent change within the region, instead of
  the entire buffer.  However, when Transient Mark mode is off (*note
  Disabled Transient Mark::), ‘C-/’ always operates on the entire buffer,
  ignoring the region.  In this case, you can perform selective undo by
  supplying a prefix argument to the ‘undo’ command: ‘C-u C-/’.  To undo
  further changes in the same region, repeat the ‘undo’ command (no prefix
  argument is needed).

The above is really cool.  Play with it a little and I am sure you
will agree.  Restricting undo to within a region rocks.

Also if I am making edits that might affect the entire buffer such as
a search and replace or running a quick macro it is very good to
narrow-to-region so that only a smaller section of the file can be
modified.

  narrow-to-region            C-x n n
     Restrict editing in this buffer to the current region.

Use C-x n w to widen back to the full buffer again after the change.
Using narrow-to-region to keep edits restricted is another really cool
feature.  Play with it a little and you will love it.  And wonder why
it is disabled by default.  It doesn't see more dangerous than any
other command.

> > This is really a very basic need and should have
> > been addressed - and solved decades ago.
> 
> Centuries! :)

Last millennium! :-)

Bob



reply via email to

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