From mboxrd@z Thu Jan 1 00:00:00 1970 From: Aaron Ecay Subject: Re: [bug] [babel] babel corrupts undo history Date: Wed, 28 Aug 2013 12:03:53 -0400 Message-ID: <87hae9ajz2.fsf@gmail.com> References: <87d2oxanct.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50602) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VEiEb-0003VB-Iq for emacs-orgmode@gnu.org; Wed, 28 Aug 2013 12:04:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VEiEU-00029q-7b for emacs-orgmode@gnu.org; Wed, 28 Aug 2013 12:04:41 -0400 Received: from mail-qe0-f42.google.com ([209.85.128.42]:34065) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VEiEU-00029O-3E for emacs-orgmode@gnu.org; Wed, 28 Aug 2013 12:04:34 -0400 Received: by mail-qe0-f42.google.com with SMTP id w7so3611331qeb.1 for ; Wed, 28 Aug 2013 09:03:55 -0700 (PDT) In-Reply-To: <87d2oxanct.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Eric Schulte , Samuel Wales Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Eric and Samuel, As I understand it, the problem is that the undo history gets scrambled by the interleaving of user edits (in the indirect source-editing buffer) and automatic changes introduced by org (un- and re-indenting the source code). I have the following patch, which seems to prevent the misbehavior Samuel noticed. It has the drawback of not keeping the fine-grained undo information: after org-src-edit-exit, all changes made during the edit are seen as only one change, and undone as a unit. I think the problem of interleaving the automatic and user-driven changes in a sensible way is tricky. We don=E2=80=99t want the first invoc= ation of undo after org-src-edit-exit to remove the contents of the code block, which is what a naive approach gives (since org-src-edit-exit deletes then reinserts the code block contents). I=E2=80=99ve been running with this patch for a while and not noticed any i= ll effects. But I haven=E2=80=99t made a concerted attempt to test undo around code blocks, which is why I=E2=80=99ve held off on pushing it. If it fixes Samuel=E2=80=99s problem and looks good, perhaps it is ready to go. --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=0001-Fix-org-src-edit-interaction-with-undo.patch Content-Transfer-Encoding: quoted-printable >From 4a55d50e46eeebe9346cd10173b8c3a5a8baa7c6 Mon Sep 17 00:00:00 2001 From: Aaron Ecay Date: Wed, 28 Aug 2013 11:50:53 -0400 Subject: [PATCH] Fix org-src-edit interaction with undo. MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit * org-src.el (org-edit-src-exit): Place an undo boundary before writing changes back to parent buffer. The previous code attempted to preserve the undo information in the indirect buffer editing the source code, but this interacts poorly with the undo system, and can lead to undo operations scrambling the buffer. The new approach means that edits made in the indirect buffer cannot be undone piece-by-piece (instead, all changes made in the indirect buffer constitute one =E2=80=9Cchange=E2=80=9D from the point of v= iew of undo), but the misbehavior of undo is (hopefully) now avoided. --- lisp/org-src.el | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lisp/org-src.el b/lisp/org-src.el index 0f88174..96a413e 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -753,12 +753,12 @@ with \",*\", \",#+\", \",,*\" and \",,#+\"." (kill-buffer buffer)) (goto-char beg) (when allow-write-back-p - (let ((buffer-undo-list t)) - (delete-region beg (max beg end)) - (unless (string-match "\\`[ \t]*\\'" code) - (insert code)) - (goto-char beg) - (if single (just-one-space)))) + (undo-boundary) + (delete-region beg (max beg end)) + (unless (string-match "\\`[ \t]*\\'" code) + (insert code)) + (goto-char beg) + (if single (just-one-space))) (if (memq t (mapcar (lambda (overlay) (eq (overlay-get overlay 'invisible) 'org-hide-block)) --=20 1.8.4 --=-=-= Content-Type: text/plain -- Aaron Ecay --=-=-=--