comparison lisp/international/mule.el @ 68209:ac1d7b21ddfc

(autoload-coding-system): Prepare for EOL variants.
author Kenichi Handa <handa@m17n.org>
date Mon, 16 Jan 2006 12:07:26 +0000
parents 527e6fc032c7
children a7c2303e1399 432dae1fa952 d88caeac70d7
comparison
equal deleted inserted replaced
68208:4bc30665eef2 68209:ac1d7b21ddfc
1142 "Define SYMBOL as a coding-system that is defined on demand. 1142 "Define SYMBOL as a coding-system that is defined on demand.
1143 1143
1144 FROM is a form to evaluate to define the coding-system." 1144 FROM is a form to evaluate to define the coding-system."
1145 (put symbol 'coding-system-define-form form) 1145 (put symbol 'coding-system-define-form form)
1146 (setq coding-system-alist (cons (list (symbol-name symbol)) 1146 (setq coding-system-alist (cons (list (symbol-name symbol))
1147 coding-system-alist))) 1147 coding-system-alist))
1148 (dolist (elt '("-unix" "-dos" "-mac"))
1149 (let ((name (concat (symbol-name symbol) elt)))
1150 (put (intern name) 'coding-system-define-form form)
1151 (setq coding-system-alist (cons (list name) coding-system-alist)))))
1148 1152
1149 (defun set-buffer-file-coding-system (coding-system &optional force nomodify) 1153 (defun set-buffer-file-coding-system (coding-system &optional force nomodify)
1150 "Set the file coding-system of the current buffer to CODING-SYSTEM. 1154 "Set the file coding-system of the current buffer to CODING-SYSTEM.
1151 This means that when you save the buffer, it will be converted 1155 This means that when you save the buffer, it will be converted
1152 according to CODING-SYSTEM. For a list of possible values of CODING-SYSTEM, 1156 according to CODING-SYSTEM. For a list of possible values of CODING-SYSTEM,
1587 :group 'files 1591 :group 'files
1588 :group 'mule 1592 :group 'mule
1589 :type '(repeat (cons (regexp :tag "Regexp") 1593 :type '(repeat (cons (regexp :tag "Regexp")
1590 (symbol :tag "Coding system")))) 1594 (symbol :tag "Coding system"))))
1591 1595
1596 (defun auto-coding-regexp-alist-lookup (from to)
1597 "Lookup `auto-coding-regexp-alist' for the contents of the current buffer.
1598 The value is a coding system is specified for the region FROM and TO,
1599 or nil."
1600 (save-excursion
1601 (goto-char from)
1602 (let ((alist auto-coding-regexp-alist)
1603 coding-system)
1604 (while (and alist (not coding-system))
1605 (let ((regexp (car (car alist))))
1606 (if enable-multibyte-characters
1607 (setq regexp (string-to-multibyte regexp)))
1608 (if (re-search-forward regexp to t)
1609 (setq coding-system (cdr (car alist)))
1610 (setq alist (cdr alist)))))
1611 coding-system)))
1612
1592 ;; See the bottom of this file for built-in auto coding functions. 1613 ;; See the bottom of this file for built-in auto coding functions.
1593 (defcustom auto-coding-functions '(sgml-xml-auto-coding-function 1614 (defcustom auto-coding-functions '(sgml-xml-auto-coding-function
1594 sgml-html-meta-auto-coding-function) 1615 sgml-html-meta-auto-coding-function)
1595 "A list of functions which attempt to determine a coding system. 1616 "A list of functions which attempt to determine a coding system.
1596 1617
1646 `auto-coding-regexp-alist', `coding:', or `auto-coding-functions' 1667 `auto-coding-regexp-alist', `coding:', or `auto-coding-functions'
1647 indicating by what CODING is specified. Note that the validity 1668 indicating by what CODING is specified. Note that the validity
1648 of CODING is not checked; it's callers responsibility to check 1669 of CODING is not checked; it's callers responsibility to check
1649 it. 1670 it.
1650 1671
1651 If nothing is specified, the return value is nil. 1672 If nothing is specified, the return value is nil."
1652
1653 The variable `set-auto-coding-function' (which see) is set to this
1654 function by default."
1655 (or (let ((coding-system (auto-coding-alist-lookup filename))) 1673 (or (let ((coding-system (auto-coding-alist-lookup filename)))
1656 (if coding-system 1674 (if coding-system
1657 (cons coding-system 'auto-coding-alist))) 1675 (cons coding-system 'auto-coding-alist)))
1658 ;; Try using `auto-coding-regexp-alist'. 1676 ;; Try using `auto-coding-regexp-alist'.
1659 (save-excursion 1677 (let ((coding-system (auto-coding-regexp-alist-lookup (point)
1660 (let ((alist auto-coding-regexp-alist) 1678 (+ (point) size))))
1661 coding-system) 1679 (if coding-system
1662 (while (and alist (not coding-system)) 1680 (cons coding-system 'auto-coding-regexp-alist)))
1663 (let ((regexp (car (car alist))))
1664 (when (re-search-forward regexp (+ (point) size) t)
1665 (setq coding-system (cdr (car alist)))))
1666 (setq alist (cdr alist)))
1667 (if coding-system
1668 (cons coding-system 'auto-coding-regexp-alist))))
1669 (let* ((case-fold-search t) 1681 (let* ((case-fold-search t)
1670 (head-start (point)) 1682 (head-start (point))
1671 (head-end (+ head-start (min size 1024))) 1683 (head-end (+ head-start (min size 1024)))
1672 (tail-start (+ head-start (max (- size 3072) 0))) 1684 (tail-start (+ head-start (max (- size 3072) 0)))
1673 (tail-end (+ head-start size)) 1685 (tail-end (+ head-start size))
1756 (cons coding-system 'auto-coding-functions))))) 1768 (cons coding-system 'auto-coding-functions)))))
1757 1769
1758 (defun set-auto-coding (filename size) 1770 (defun set-auto-coding (filename size)
1759 "Return coding system for a file FILENAME of which SIZE bytes follow point. 1771 "Return coding system for a file FILENAME of which SIZE bytes follow point.
1760 See `find-auto-coding' for how the coding system is found. 1772 See `find-auto-coding' for how the coding system is found.
1761 Return nil if an invalid coding system is found." 1773 Return nil if an invalid coding system is found.
1774
1775 The variable `set-auto-coding-function' (which see) is set to this
1776 function by default."
1762 (let ((found (find-auto-coding filename size))) 1777 (let ((found (find-auto-coding filename size)))
1763 (if (and found (coding-system-p (car found))) 1778 (if (and found (coding-system-p (car found)))
1764 (car found)))) 1779 (car found))))
1765 1780
1766 (setq set-auto-coding-function 'set-auto-coding) 1781 (setq set-auto-coding-function 'set-auto-coding)