all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* tricky - undo function - planning info
@ 2015-06-07 20:42 gnuist006
  2015-06-07 22:15 ` Emanuel Berg
  2015-06-08  2:35 ` Stefan Monnier
  0 siblings, 2 replies; 4+ messages in thread
From: gnuist006 @ 2015-06-07 20:42 UTC (permalink / raw
  To: help-gnu-emacs

Hi All.

Normally M-x undo would undo each step. 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. This is really a very basic need and should have been addressed - and solved decades ago. I am looking for a good plan of what to do to achieve this functionality and basic facility. For example, something from the interpreter needs to be accessed about each function executed to indicate its number of elementary steps and this data stored elsewhere so an undo-function can be applied without any bugs.

Then again, maybe it is already implemented and undocumented, or there is a simple solution.

Bolega


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: tricky - undo function - planning info
  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
  2015-06-08  2:35 ` Stefan Monnier
  1 sibling, 1 reply; 4+ messages in thread
From: Emanuel Berg @ 2015-06-07 22:15 UTC (permalink / raw
  To: help-gnu-emacs

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.

> 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.

I don't think you should rely on `undo' to be safe
from such things too much. Better undo basic editing
mistakes (as in when you change your mind) and such
things. Sometimes tho undo is a lifesaver but I'd
recommend not relying on it too much to fix mistakes.
Instead, focus on not doing mistakes (actually
gradually making fewer and fewer). Behave like a pro
that is what you become.

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

Centuries! :)

> I am looking for a good plan of what to do to
> achieve this functionality and basic facility.

I suppose you can poll `buffer-undo-list' and examine
how it grows. You can have a function echo that digit
(the number of steps), or have it appear in the mode
line. Will this actually be better than hitting the
undo keystroke repeatedly? With a doubt: maybe.

> Then again, maybe it is already implemented and
> undocumented, or there is a simple solution.

Indeed, you don't know that and there is no foolproof
way of knowing to my knowledge.

-- 
underground experts united
http://user.it.uu.se/~embe8573


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: tricky - undo function - planning info
  2015-06-07 22:15 ` Emanuel Berg
@ 2015-06-07 23:06   ` Bob Proulx
  0 siblings, 0 replies; 4+ messages in thread
From: Bob Proulx @ 2015-06-07 23:06 UTC (permalink / raw
  To: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: tricky - undo function - planning info
  2015-06-07 20:42 tricky - undo function - planning info gnuist006
  2015-06-07 22:15 ` Emanuel Berg
@ 2015-06-08  2:35 ` Stefan Monnier
  1 sibling, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2015-06-08  2:35 UTC (permalink / raw
  To: help-gnu-emacs

> Normally M-x undo would undo each step. A function may comprise one or more
> steps.

Emacs doesn't care much about function boundaries.  So, if you really
mean "function", your needs are clearly out.  If you actually meant
"command", then at least there's a chance you might get it to do what
you want.
Still, a command may stop in the middle, calling recusrive-edit and
hence calling other sub-commands, at which point it can become far from
clear what you mean by "undo 1 command".

> Then again, maybe it is already implemented and undocumented, or there
> is a simple solution.

I doubt it.  Maybe all you want is atomic-change-group.  But Maybe your
needs are very unusual.  If you describe them, maybe someone can show you
how to do it.


        Stefan




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-06-08  2:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2015-06-08  2:35 ` Stefan Monnier

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.