diff options
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/format.el | 35 |
2 files changed, 34 insertions, 7 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f8bf2d8f1be..ce496808a6b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2007-08-07 Martin Rudalics <rudalics@gmx.at> | ||
| 2 | |||
| 3 | * format.el (format-insert-file): Make sure that at most one undo | ||
| 4 | entry is recorded for the insertion. Inhibit point-motion and | ||
| 5 | modification hooks around call to insert-file-contents. | ||
| 6 | |||
| 1 | 2007-08-07 Stefan Monnier <monnier@iro.umontreal.ca> | 7 | 2007-08-07 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 8 | ||
| 3 | * vc.el (vc-annotate): Select temp-buffer before running vc-exec-after. | 9 | * vc.el (vc-annotate): Select temp-buffer before running vc-exec-after. |
diff --git a/lisp/format.el b/lisp/format.el index d029e3d4683..35e47efadbf 100644 --- a/lisp/format.el +++ b/lisp/format.el | |||
| @@ -429,13 +429,34 @@ a list (ABSOLUTE-FILE-NAME SIZE)." | |||
| 429 | (fmt (format-read (format "Read file `%s' in format: " | 429 | (fmt (format-read (format "Read file `%s' in format: " |
| 430 | (file-name-nondirectory file))))) | 430 | (file-name-nondirectory file))))) |
| 431 | (list file fmt))) | 431 | (list file fmt))) |
| 432 | (let (value size) | 432 | (let (value size old-undo) |
| 433 | (let ((format-alist nil)) | 433 | ;; Record only one undo entry for the insertion. Inhibit point-motion and |
| 434 | (setq value (insert-file-contents filename nil beg end)) | 434 | ;; modification hooks as with `insert-file-contents'. |
| 435 | (setq size (nth 1 value))) | 435 | (let ((inhibit-point-motion-hooks t) |
| 436 | (if format | 436 | (inhibit-modification-hooks t)) |
| 437 | (setq size (format-decode format size) | 437 | ;; Don't bind `buffer-undo-list' to t here to assert that |
| 438 | value (list (car value) size))) | 438 | ;; `insert-file-contents' may record whether the buffer was unmodified |
| 439 | ;; before. | ||
| 440 | (let ((format-alist nil)) | ||
| 441 | (setq value (insert-file-contents filename nil beg end)) | ||
| 442 | (setq size (nth 1 value))) | ||
| 443 | (when (consp buffer-undo-list) | ||
| 444 | (let ((head (car buffer-undo-list))) | ||
| 445 | (when (and (consp head) | ||
| 446 | (equal (car head) (point)) | ||
| 447 | (equal (cdr head) (+ (point) size))) | ||
| 448 | ;; Remove first entry from `buffer-undo-list', we shall insert | ||
| 449 | ;; another one below. | ||
| 450 | (setq old-undo (cdr buffer-undo-list))))) | ||
| 451 | (when format | ||
| 452 | (let ((buffer-undo-list t)) | ||
| 453 | (setq size (format-decode format size) | ||
| 454 | value (list (car value) size))) | ||
| 455 | (unless (eq buffer-undo-list t) | ||
| 456 | (setq buffer-undo-list | ||
| 457 | (cons (cons (point) (+ (point) size)) old-undo))))) | ||
| 458 | (unless inhibit-modification-hooks | ||
| 459 | (run-hook-with-args 'after-change-functions (point) (+ (point) size) 0)) | ||
| 439 | value)) | 460 | value)) |
| 440 | 461 | ||
| 441 | (defun format-read (&optional prompt) | 462 | (defun format-read (&optional prompt) |