comparison lisp/international/mule.el @ 59119:803b2fab7ec1

(decode-coding-inserted-region): Set buffer-undo-list in a correct and optimal way.
author Richard M. Stallman <rms@gnu.org>
date Mon, 27 Dec 2004 16:12:11 +0000
parents 34e39dcb6763
children a9efc32867d2
comparison
equal deleted inserted replaced
59118:a3caa12a673a 59119:803b2fab7ec1
1876 network-coding-system-alist))))))) 1876 network-coding-system-alist)))))))
1877 1877
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.
1881 The idea is that the text between FROM and TO was just inserted somehow.
1881 Optional arguments VISIT, BEG, END, and REPLACE are the same as those 1882 Optional arguments VISIT, BEG, END, and REPLACE are the same as those
1882 of the function `insert-file-contents'." 1883 of the function `insert-file-contents'.
1884 Part 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)))))
1891 (or coding 1905 (or coding
1892 (setq coding (car (find-operation-coding-system 1906 (setq coding (car (find-operation-coding-system
1897 (setq coding 1911 (setq coding
1898 (coding-system-change-text-conversion coding 'raw-text))) 1912 (coding-system-change-text-conversion coding 'raw-text)))
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.
1906 A translation table is a char table intended for character 1929 A translation table is a char table intended for character
1907 translation in CCL programs. 1930 translation in CCL programs.