emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Aaron Ecay <aaronecay@gmail.com>
To: Eric Schulte <schulte.eric@gmail.com>,
	Samuel Wales <samologist@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [bug] [babel] babel corrupts undo history
Date: Wed, 28 Aug 2013 12:03:53 -0400	[thread overview]
Message-ID: <87hae9ajz2.fsf@gmail.com> (raw)
In-Reply-To: <87d2oxanct.fsf@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1138 bytes --]

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’t want the first invocation
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’ve been running with this patch for a while and not noticed any ill
effects.  But I haven’t made a concerted attempt to test undo around
code blocks, which is why I’ve held off on pushing it.  If it fixes
Samuel’s problem and looks good, perhaps it is ready to go.


[-- Attachment #2: 0001-Fix-org-src-edit-interaction-with-undo.patch --]
[-- Type: text/x-diff, Size: 1781 bytes --]

From 4a55d50e46eeebe9346cd10173b8c3a5a8baa7c6 Mon Sep 17 00:00:00 2001
From: Aaron Ecay <aaronecay@gmail.com>
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=UTF-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 “change” from the point of view 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))
-- 
1.8.4


[-- Attachment #3: Type: text/plain, Size: 15 bytes --]


--
Aaron Ecay

  reply	other threads:[~2013-08-28 16:04 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-28  1:13 [bug] [babel] babel corrupts undo history Samuel Wales
2013-08-28 14:42 ` Eric Schulte
2013-08-28 16:03   ` Aaron Ecay [this message]
2013-08-28 18:52     ` Eric Schulte
2013-08-28 19:41       ` Samuel Wales
2013-08-28 19:43         ` Samuel Wales
2013-08-28 19:51           ` Samuel Wales
2013-10-28 19:17             ` Aaron Ecay
2013-10-28 19:45               ` Samuel Wales
2013-10-28 20:07                 ` Aaron Ecay
2013-10-28 21:26                   ` Samuel Wales
2014-03-10  2:46                     ` Samuel Wales
2014-03-18 20:48                       ` Bastien
2014-03-21 21:34                         ` Samuel Wales
2014-03-21 22:07                           ` Bastien
2014-03-21 22:42                             ` Samuel Wales
2014-03-21 22:45                               ` Samuel Wales
2014-03-21 23:40                               ` Bastien
2014-03-22  0:11                                 ` Samuel Wales
2014-03-22  0:18                                   ` Bastien
2014-03-22  0:37                                     ` Samuel Wales
2014-03-22  0:44                                       ` Samuel Wales
2014-03-22  8:43                                         ` Bastien
2014-03-22  8:57                                           ` Samuel Wales
2013-08-28 17:08   ` Samuel Wales
2013-08-28 17:18     ` Samuel Wales

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

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87hae9ajz2.fsf@gmail.com \
    --to=aaronecay@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=samologist@gmail.com \
    --cc=schulte.eric@gmail.com \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).