aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2004-12-27 16:12:11 +0000
committerRichard M. Stallman2004-12-27 16:12:11 +0000
commit9c8483538f3f7a8ec57bbd50af8aec45c0778622 (patch)
tree35cdbcc3f96602abdc5b9b0da2951e11f056320f
parent75e6b97059b6e5b012b1084677070add5c5b0c19 (diff)
downloademacs-9c8483538f3f7a8ec57bbd50af8aec45c0778622.tar.gz
emacs-9c8483538f3f7a8ec57bbd50af8aec45c0778622.zip
(decode-coding-inserted-region):
Set buffer-undo-list in a correct and optimal way.
-rw-r--r--lisp/international/mule.el33
1 files changed, 28 insertions, 5 deletions
diff --git a/lisp/international/mule.el b/lisp/international/mule.el
index bec20a66df5..144bd0360ca 100644
--- a/lisp/international/mule.el
+++ b/lisp/international/mule.el
@@ -1878,13 +1878,27 @@ or a function symbol which, when called, returns such a cons cell."
1878(defun decode-coding-inserted-region (from to filename 1878(defun decode-coding-inserted-region (from to filename
1879 &optional visit beg end replace) 1879 &optional visit beg end replace)
1880 "Decode the region between FROM and TO as if it is read from file FILENAME. 1880 "Decode the region between FROM and TO as if it is read from file FILENAME.
1881The idea is that the text between FROM and TO was just inserted somehow.
1881Optional arguments VISIT, BEG, END, and REPLACE are the same as those 1882Optional arguments VISIT, BEG, END, and REPLACE are the same as those
1882of the function `insert-file-contents'." 1883of the function `insert-file-contents'.
1884Part of the job of this function is setting `buffer-undo-list' appropriately."
1883 (save-excursion 1885 (save-excursion
1884 (save-restriction 1886 (save-restriction
1885 (narrow-to-region from to) 1887 (let ((coding coding-system-for-read)
1886 (goto-char (point-min)) 1888 undo-list-saved)
1887 (let ((coding coding-system-for-read)) 1889 (if visit
1890 ;; Temporarily turn off undo recording, if we're decoding the
1891 ;; text of a visited file.
1892 (setq buffer-undo-list t)
1893 ;; Otherwise, if we can recognize the undo elt for the insertion,
1894 ;; remove it and get ready to replace it later.
1895 ;; In the mean time, turn off undo recording.
1896 (let ((last (car buffer-undo-list)))
1897 (if (and (consp last) (eql (car last) from) (eql (cdr last) to))
1898 (setq undo-list-saved (cdr buffer-undo-list)
1899 buffer-undo-list t))))
1900 (narrow-to-region from to)
1901 (goto-char (point-min))
1888 (or coding 1902 (or coding
1889 (setq coding (funcall set-auto-coding-function 1903 (setq coding (funcall set-auto-coding-function
1890 filename (- (point-max) (point-min))))) 1904 filename (- (point-max) (point-min)))))
@@ -1899,7 +1913,16 @@ of the function `insert-file-contents'."
1899 (setq coding nil)) 1913 (setq coding nil))
1900 (if coding 1914 (if coding
1901 (decode-coding-region (point-min) (point-max) coding) 1915 (decode-coding-region (point-min) (point-max) coding)
1902 (setq last-coding-system-used coding)))))) 1916 (setq last-coding-system-used coding))
1917 ;; If we're decoding the text of a visited file,
1918 ;; the undo list should start out empty.
1919 (if visit
1920 (setq buffer-undo-list nil)
1921 ;; If we decided to replace the undo entry for the insertion,
1922 ;; do so now.
1923 (if undo-list-saved
1924 (setq buffer-undo-list
1925 (cons (cons from (point-max)) undo-list-saved))))))))
1903 1926
1904(defun make-translation-table (&rest args) 1927(defun make-translation-table (&rest args)
1905 "Make a translation table from arguments. 1928 "Make a translation table from arguments.