725 |
|
|
726 |
TYPE is an integer value indicating the type of the coding system as follows: |
TYPE is an integer value indicating the type of the coding system as follows: |
727 |
0: Emacs internal format, |
0: Emacs internal format, |
728 |
1: Shift-JIS (or MS-Kanji) used mainly on Japanese PC, |
1: Shift-JIS (or MS-Kanji) used mainly on Japanese PCs, |
729 |
2: ISO-2022 including many variants, |
2: ISO-2022 including many variants, |
730 |
3: Big5 used mainly on Chinese PC, |
3: Big5 used mainly on Chinese PCs, |
731 |
4: private, CCL programs provide encoding/decoding algorithm, |
4: private, CCL programs provide encoding/decoding algorithm, |
732 |
5: Raw-text, which means that text contains random 8-bit codes. |
5: Raw-text, which means that text contains random 8-bit codes. |
733 |
|
|
822 |
|
|
823 |
o mime-charset |
o mime-charset |
824 |
|
|
825 |
The value is a symbol of which name is `MIME-charset' parameter of |
The value is a symbol whose name is the `MIME-charset' parameter of |
826 |
the coding system. |
the coding system. |
827 |
|
|
828 |
o valid-codes (meaningful only for a coding system based on CCL) |
o valid-codes (meaningful only for a coding system based on CCL) |
1489 |
:type '(repeat (cons (regexp :tag "Regexp") |
:type '(repeat (cons (regexp :tag "Regexp") |
1490 |
(symbol :tag "Coding system")))) |
(symbol :tag "Coding system")))) |
1491 |
|
|
1492 |
|
;; See the bottom of this file for built-in auto coding functions. |
1493 |
|
(defcustom auto-coding-functions '(sgml-xml-auto-coding-function) |
1494 |
|
"A list of functions which attempt to determine a coding system. |
1495 |
|
|
1496 |
|
Each function in this list should be written to operate on the current |
1497 |
|
buffer, but should not modify it in any way. It should take one |
1498 |
|
argument SIZE, past which it should not search. If a function |
1499 |
|
succeeds in determining a coding system, it should return that coding |
1500 |
|
system. Otherwise, it should return nil. |
1501 |
|
|
1502 |
|
The functions in this list take priority over `coding:' tags in the |
1503 |
|
file, just as for `auto-coding-regexp-alist'." |
1504 |
|
:group 'files |
1505 |
|
:group 'mule |
1506 |
|
:type '(repeat function)) |
1507 |
|
|
1508 |
(defvar set-auto-coding-for-load nil |
(defvar set-auto-coding-for-load nil |
1509 |
"Non-nil means look for `load-coding' property instead of `coding'. |
"Non-nil means look for `load-coding' property instead of `coding'. |
1510 |
This is used for loading and byte-compiling Emacs Lisp files.") |
This is used for loading and byte-compiling Emacs Lisp files.") |
1520 |
(setq alist (cdr alist)))) |
(setq alist (cdr alist)))) |
1521 |
coding-system)) |
coding-system)) |
1522 |
|
|
|
|
|
1523 |
(defun auto-coding-from-file-contents (size) |
(defun auto-coding-from-file-contents (size) |
1524 |
"Determine a coding system from the contents of the current buffer. |
"Determine a coding system from the contents of the current buffer. |
1525 |
The current buffer contains SIZE bytes starting at point. |
The current buffer contains SIZE bytes starting at point. |
1526 |
Value is either a coding system or nil." |
Value is either a coding system or nil." |
1527 |
(save-excursion |
(save-excursion |
1528 |
(let ((alist auto-coding-regexp-alist) |
(let ((alist auto-coding-regexp-alist) |
1529 |
|
(funcs auto-coding-functions) |
1530 |
coding-system) |
coding-system) |
1531 |
(while (and alist (not coding-system)) |
(while (and alist (not coding-system)) |
1532 |
(let ((regexp (car (car alist)))) |
(let ((regexp (car (car alist)))) |
1533 |
(when (re-search-forward regexp (+ (point) size) t) |
(when (re-search-forward regexp (+ (point) size) t) |
1534 |
(setq coding-system (cdr (car alist))))) |
(setq coding-system (cdr (car alist))))) |
1535 |
(setq alist (cdr alist))) |
(setq alist (cdr alist))) |
1536 |
|
(while (and funcs (not coding-system)) |
1537 |
|
(setq coding-system (condition-case e |
1538 |
|
(save-excursion |
1539 |
|
(funcall (pop funcs) size)) |
1540 |
|
(error nil)))) |
1541 |
coding-system))) |
coding-system))) |
|
|
|
1542 |
|
|
1543 |
(defun set-auto-coding (filename size) |
(defun set-auto-coding (filename size) |
1544 |
"Return coding system for a file FILENAME of which SIZE bytes follow point. |
"Return coding system for a file FILENAME of which SIZE bytes follow point. |
1548 |
It checks FILENAME against the variable `auto-coding-alist'. If |
It checks FILENAME against the variable `auto-coding-alist'. If |
1549 |
FILENAME doesn't match any entries in the variable, it checks the |
FILENAME doesn't match any entries in the variable, it checks the |
1550 |
contents of the current buffer following point against |
contents of the current buffer following point against |
1551 |
`auto-coding-regexp-alist'. If no match is found, it checks for a |
`auto-coding-regexp-alist', and tries calling each function in |
1552 |
|
`auto-coding-functions'. If no match is found, it checks for a |
1553 |
`coding:' tag in the first one or two lines following point. If no |
`coding:' tag in the first one or two lines following point. If no |
1554 |
`coding:' tag is found, it checks for local variables list in the last |
`coding:' tag is found, it checks for local variables list in the last |
1555 |
3K bytes out of the SIZE bytes. |
3K bytes out of the SIZE bytes. |
1919 |
(setq ignore-relative-composition |
(setq ignore-relative-composition |
1920 |
(make-char-table 'ignore-relative-composition)) |
(make-char-table 'ignore-relative-composition)) |
1921 |
|
|
1922 |
|
|
1923 |
|
;;; Built-in auto-coding-functions: |
1924 |
|
|
1925 |
|
(defun sgml-xml-auto-coding-function (size) |
1926 |
|
"Determine whether the buffer is XML, and if so, its encoding. |
1927 |
|
This function is intended to be added to `auto-coding-functions'." |
1928 |
|
(when (re-search-forward "\\`[[:space:]\n]*<\\?xml") |
1929 |
|
(let ((end (save-excursion |
1930 |
|
;; This is a hack. |
1931 |
|
(search-forward "\"\\s-*?>" size t)))) |
1932 |
|
(when end |
1933 |
|
(if (re-search-forward "encoding=\"\\(.+?\\)\"" end t) |
1934 |
|
(let ((match (downcase (match-string 1)))) |
1935 |
|
;; FIXME: what other encodings are valid, and how can we |
1936 |
|
;; translate them to the names of coding systems? |
1937 |
|
(cond ((string= match "utf-8") |
1938 |
|
'utf-8) |
1939 |
|
((string-match "iso-8859-[[:digit:]]+" match) |
1940 |
|
(intern match)) |
1941 |
|
(t nil))) |
1942 |
|
'utf-8))))) |
1943 |
|
|
1944 |
;;; |
;;; |
1945 |
(provide 'mule) |
(provide 'mule) |
1946 |
|
|