all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Bob Proulx <bob@proulx.com>
To: help-gnu-emacs@gnu.org
Subject: Re: tricky - undo function - planning info
Date: Sun, 7 Jun 2015 17:06:17 -0600	[thread overview]
Message-ID: <20150607164109515566967@bob.proulx.com> (raw)
In-Reply-To: <87h9qjb1xx.fsf@debian.uxu>

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	other threads:[~2015-06-07 23:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-07 20:42 tricky - undo function - planning info gnuist006
2015-06-07 22:15 ` Emanuel Berg
2015-06-07 23:06   ` Bob Proulx [this message]
2015-06-08  2:35 ` Stefan Monnier

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=20150607164109515566967@bob.proulx.com \
    --to=bob@proulx.com \
    --cc=help-gnu-emacs@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.