]> git.eshelyaron.com Git - emacs.git/commitdiff
(format-insert-file): Make sure that at most one undo
authorMartin Rudalics <rudalics@gmx.at>
Tue, 7 Aug 2007 12:43:40 +0000 (12:43 +0000)
committerMartin Rudalics <rudalics@gmx.at>
Tue, 7 Aug 2007 12:43:40 +0000 (12:43 +0000)
entry is recorded for the insertion.  Inhibit point-motion and
modification hooks around call to insert-file-contents.

lisp/ChangeLog
lisp/format.el

index f8bf2d8f1beec71c3cc54647dadfc3690cad063d..ce496808a6b4f8ef79b14a9ce815e4645f1a4f5e 100644 (file)
@@ -1,3 +1,9 @@
+2007-08-07  Martin Rudalics  <rudalics@gmx.at>
+
+       * format.el (format-insert-file): Make sure that at most one undo
+       entry is recorded for the insertion.  Inhibit point-motion and
+       modification hooks around call to insert-file-contents.
+
 2007-08-07  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * vc.el (vc-annotate): Select temp-buffer before running vc-exec-after.
index d029e3d4683ab141033b77c6a2b0180dbc7c93d5..35e47efadbfe5e1ec2f29ff5b1366eb98f3b37ca 100644 (file)
@@ -429,13 +429,34 @@ a list (ABSOLUTE-FILE-NAME SIZE)."
          (fmt (format-read (format "Read file `%s' in format: "
                                    (file-name-nondirectory file)))))
      (list file fmt)))
-  (let (value size)
-    (let ((format-alist nil))
-      (setq value (insert-file-contents filename nil beg end))
-      (setq size (nth 1 value)))
-    (if format
-       (setq size (format-decode format size)
-             value (list (car value) size)))
+  (let (value size old-undo)
+    ;; Record only one undo entry for the insertion.  Inhibit point-motion and
+    ;; modification hooks as with `insert-file-contents'.
+    (let ((inhibit-point-motion-hooks t)
+         (inhibit-modification-hooks t))
+      ;; Don't bind `buffer-undo-list' to t here to assert that
+      ;; `insert-file-contents' may record whether the buffer was unmodified
+      ;; before.
+      (let ((format-alist nil))
+       (setq value (insert-file-contents filename nil beg end))
+       (setq size (nth 1 value)))
+      (when (consp buffer-undo-list)
+       (let ((head (car buffer-undo-list)))
+         (when (and (consp head)
+                    (equal (car head) (point))
+                    (equal (cdr head) (+ (point) size)))
+           ;; Remove first entry from `buffer-undo-list', we shall insert
+           ;; another one below.
+           (setq old-undo (cdr buffer-undo-list)))))
+      (when format
+       (let ((buffer-undo-list t))
+         (setq size (format-decode format size)
+               value (list (car value) size)))
+       (unless (eq buffer-undo-list t)
+         (setq buffer-undo-list
+               (cons (cons (point) (+ (point) size)) old-undo)))))
+    (unless inhibit-modification-hooks
+      (run-hook-with-args 'after-change-functions (point) (+ (point) size) 0))
     value))
 
 (defun format-read (&optional prompt)