From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Bob Proulx Newsgroups: gmane.emacs.help Subject: Re: tricky - undo function - planning info Date: Sun, 7 Jun 2015 17:06:17 -0600 Message-ID: <20150607164109515566967@bob.proulx.com> References: <27847c65-cbde-47aa-976b-30e2721a3c83@googlegroups.com> <87h9qjb1xx.fsf@debian.uxu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1433718409 11287 80.91.229.3 (7 Jun 2015 23:06:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 7 Jun 2015 23:06:49 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jun 08 01:06:43 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Z1jeN-0001ak-5n for geh-help-gnu-emacs@m.gmane.org; Mon, 08 Jun 2015 01:06:43 +0200 Original-Received: from localhost ([::1]:55387 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z1jeL-0004p3-Nt for geh-help-gnu-emacs@m.gmane.org; Sun, 07 Jun 2015 19:06:41 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33901) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z1je7-0004ox-RL for help-gnu-emacs@gnu.org; Sun, 07 Jun 2015 19:06:29 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z1jdz-0006GG-53 for help-gnu-emacs@gnu.org; Sun, 07 Jun 2015 19:06:27 -0400 Original-Received: from joseki.proulx.com ([216.17.153.58]:55014) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z1jdy-0006Dl-U3 for help-gnu-emacs@gnu.org; Sun, 07 Jun 2015 19:06:19 -0400 Original-Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id 9D47721232 for ; Sun, 7 Jun 2015 17:06:17 -0600 (MDT) Original-Received: by hysteria.proulx.com (Postfix, from userid 1000) id 7C89F2DC48; Sun, 7 Jun 2015 17:06:17 -0600 (MDT) Mail-Followup-To: help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <87h9qjb1xx.fsf@debian.uxu> User-Agent: Mutt/1.5.23 (2014-03-12) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 216.17.153.58 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:104825 Archived-At: Emanuel Berg wrote: > gnuist006@gmail.com writes: >=20 > > Normally M-x undo would undo each step. >=20 > 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-_, , C-/, C-x u, . 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 =E2=80=98undo=E2=80=99 pe= rforms "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::), =E2=80=98C-/=E2=80=99 always operates on th= e entire buffer, ignoring the region. In this case, you can perform selective undo by supplying a prefix argument to the =E2=80=98undo=E2=80=99 command: =E2=80= =98C-u C-/=E2=80=99. To undo further changes in the same region, repeat the =E2=80=98undo=E2=80=99 c= ommand (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. >=20 > Centuries! :) Last millennium! :-) Bob