aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenichi Handa2006-06-02 06:28:36 +0000
committerKenichi Handa2006-06-02 06:28:36 +0000
commit09e5712dd139c54f445797f70b4c014f4557eecc (patch)
treed3f6456da79c437cb11eb65372c686ff132111f9
parentc55122c32141a07388a13b78dc7b3f72253e6816 (diff)
downloademacs-09e5712dd139c54f445797f70b4c014f4557eecc.tar.gz
emacs-09e5712dd139c54f445797f70b4c014f4557eecc.zip
(enable-character-translation): Put
permanent-local and safe-local-variable properties. (find-auto-coding): Handle char-trans: tag.
-rw-r--r--lisp/international/mule.el41
1 files changed, 35 insertions, 6 deletions
diff --git a/lisp/international/mule.el b/lisp/international/mule.el
index c2d398b440e..e2e9ba62398 100644
--- a/lisp/international/mule.el
+++ b/lisp/international/mule.el
@@ -1655,6 +1655,9 @@ This is used for loading and byte-compiling Emacs Lisp files.")
1655 (setq alist (cdr alist)))) 1655 (setq alist (cdr alist))))
1656 coding-system)) 1656 coding-system))
1657 1657
1658(put 'enable-character-translation 'permanent-local t)
1659(put 'enable-character-translation 'safe-local-variable 'booleanp)
1660
1658(defun find-auto-coding (filename size) 1661(defun find-auto-coding (filename size)
1659 "Find a coding system for a file FILENAME of which SIZE bytes follow point. 1662 "Find a coding system for a file FILENAME of which SIZE bytes follow point.
1660These bytes should include at least the first 1k of the file 1663These bytes should include at least the first 1k of the file
@@ -1692,17 +1695,20 @@ If nothing is specified, the return value is nil."
1692 (head-end (+ head-start (min size 1024))) 1695 (head-end (+ head-start (min size 1024)))
1693 (tail-start (+ head-start (max (- size 3072) 0))) 1696 (tail-start (+ head-start (max (- size 3072) 0)))
1694 (tail-end (+ head-start size)) 1697 (tail-end (+ head-start size))
1695 coding-system head-found tail-found pos) 1698 coding-system head-found tail-found pos char-trans)
1696 ;; Try a short cut by searching for the string "coding:" 1699 ;; Try a short cut by searching for the string "coding:"
1697 ;; and for "unibyte:" at the head and tail of SIZE bytes. 1700 ;; and for "unibyte:" at the head and tail of SIZE bytes.
1698 (setq head-found (or (search-forward "coding:" head-end t) 1701 (setq head-found (or (search-forward "coding:" head-end t)
1699 (search-forward "unibyte:" head-end t))) 1702 (search-forward "unibyte:" head-end t)
1703 (search-forward "char-trans:" head-end t)))
1700 (if (and head-found (> head-found tail-start)) 1704 (if (and head-found (> head-found tail-start))
1701 ;; Head and tail are overlapped. 1705 ;; Head and tail are overlapped.
1702 (setq tail-found head-found) 1706 (setq tail-found head-found)
1703 (goto-char tail-start) 1707 (goto-char tail-start)
1704 (setq tail-found (or (search-forward "coding:" tail-end t) 1708 (setq tail-found (or (search-forward "coding:" tail-end t)
1705 (search-forward "unibyte:" tail-end t)))) 1709 (search-forward "unibyte:" tail-end t)
1710 (search-forward "enable-character-translation:"
1711 tail-end t))))
1706 1712
1707 ;; At first check the head. 1713 ;; At first check the head.
1708 (when head-found 1714 (when head-found
@@ -1720,12 +1726,16 @@ If nothing is specified, the return value is nil."
1720 (re-search-forward 1726 (re-search-forward
1721 "\\(.*;\\)?[ \t]*coding:[ \t]*\\([^ ;]+\\)" 1727 "\\(.*;\\)?[ \t]*coding:[ \t]*\\([^ ;]+\\)"
1722 head-end t)) 1728 head-end t))
1723 (setq coding-system (intern (match-string 2)))))) 1729 (setq coding-system (intern (match-string 2))))
1730 (when (re-search-forward
1731 "\\(.*;\\)?[ \t]*char-trans:[ \t]*\\([^ ;]+\\)"
1732 head-end t)
1733 (setq char-trans (match-string 2)))))
1724 1734
1725 ;; If no coding: tag in the head, check the tail. 1735 ;; If no coding: tag in the head, check the tail.
1726 ;; Here we must pay attention to the case that the end-of-line 1736 ;; Here we must pay attention to the case that the end-of-line
1727 ;; is just "\r" and we can't use "^" nor "$" in regexp. 1737 ;; is just "\r" and we can't use "^" nor "$" in regexp.
1728 (when (and tail-found (not coding-system)) 1738 (when (and tail-found (or (not coding-system) (not char-trans)))
1729 (goto-char tail-start) 1739 (goto-char tail-start)
1730 (re-search-forward "[\r\n]\^L" nil t) 1740 (re-search-forward "[\r\n]\^L" nil t)
1731 (if (re-search-forward 1741 (if (re-search-forward
@@ -1748,6 +1758,11 @@ If nothing is specified, the return value is nil."
1748 "[\r\n]" prefix 1758 "[\r\n]" prefix
1749 "[ \t]*unibyte[ \t]*:[ \t]*\\([^ \t\r\n]+\\)[ \t]*" 1759 "[ \t]*unibyte[ \t]*:[ \t]*\\([^ \t\r\n]+\\)[ \t]*"
1750 suffix "[\r\n]")) 1760 suffix "[\r\n]"))
1761 (re-char-trans
1762 (concat
1763 "[\r\n]" prefix
1764 "[ \t]*enable-character-translation[ \t]*:[ \t]*\\([^ \t\r\n]+\\)[ \t]*"
1765 suffix "[\r\n]"))
1751 (re-end 1766 (re-end
1752 (concat "[\r\n]" prefix "[ \t]*End *:[ \t]*" suffix 1767 (concat "[\r\n]" prefix "[ \t]*End *:[ \t]*" suffix
1753 "[\r\n]?")) 1768 "[\r\n]?"))
@@ -1761,7 +1776,21 @@ If nothing is specified, the return value is nil."
1761 (setq coding-system 'raw-text)) 1776 (setq coding-system 'raw-text))
1762 (when (and (not coding-system) 1777 (when (and (not coding-system)
1763 (re-search-forward re-coding tail-end t)) 1778 (re-search-forward re-coding tail-end t))
1764 (setq coding-system (intern (match-string 1))))))) 1779 (setq coding-system (intern (match-string 1))))
1780 (when (and (not char-trans)
1781 (re-search-forward re-char-trans tail-end t))
1782 (setq char-trans (match-string 1))))))
1783 (if coding-system
1784 ;; If the coding-system name ends with "!", remove it and
1785 ;; set char-trans to "nil".
1786 (let ((name (symbol-name coding-system)))
1787 (if (= (aref name (1- (length name))) ?!)
1788 (setq coding-system (intern (substring name 0 -1))
1789 char-trans "nil"))))
1790 (when (and char-trans
1791 (not (setq char-trans (intern char-trans))))
1792 (make-local-variable 'enable-character-translation)
1793 (setq enable-character-translation nil))
1765 (if coding-system 1794 (if coding-system
1766 (cons coding-system :coding))) 1795 (cons coding-system :coding)))
1767 ;; Finally, try all the `auto-coding-functions'. 1796 ;; Finally, try all the `auto-coding-functions'.