/[emacs]/emacs/lisp/international/mule.el
ViewVC logotype

Diff of /emacs/lisp/international/mule.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.224 by handa, Thu Jul 7 06:21:30 2005 UTC revision 1.225 by handa, Tue Jul 19 02:30:29 2005 UTC
# Line 1621  This is used for loading and byte-compil Line 1621  This is used for loading and byte-compil
1621          (setq alist (cdr alist))))          (setq alist (cdr alist))))
1622      coding-system))      coding-system))
1623    
1624  (defun set-auto-coding (filename size)  (defun find-auto-coding (filename size)
1625    "Return coding system for a file FILENAME of which SIZE bytes follow point.    "Find a coding system for a file FILENAME of which SIZE bytes follow point.
1626  These bytes should include at least the first 1k of the file  These bytes should include at least the first 1k of the file
1627  and the last 3k of the file, but the middle may be omitted.  and the last 3k of the file, but the middle may be omitted.
1628    
# Line 1636  contents of the current buffer following Line 1636  contents of the current buffer following
1636  succeed, it checks to see if any function in `auto-coding-functions'  succeed, it checks to see if any function in `auto-coding-functions'
1637  gives a match.  gives a match.
1638    
1639  The return value is the specified coding system, or nil if nothing is  If a coding system is specifed, the return value is a
1640  specified.  cons (CODING . SOURCE), where CODING is the specified coding
1641    system and SOURCE is a symbol `auto-coding-alist',
1642    `auto-coding-regexp-alist', `coding:', or `auto-coding-functions'
1643    indicating by what CODING is specified.  Note that the validity
1644    of CODING is not checked; it's callers responsibility to check
1645    it.
1646    
1647    If nothing is specified, the return value is nil.
1648    
1649  The variable `set-auto-coding-function' (which see) is set to this  The variable `set-auto-coding-function' (which see) is set to this
1650  function by default."  function by default."
1651    (or (auto-coding-alist-lookup filename)    (or (let ((coding-system (auto-coding-alist-lookup filename)))
1652            (if coding-system
1653                (cons coding-system 'auto-coding-alist)))
1654        ;; Try using `auto-coding-regexp-alist'.        ;; Try using `auto-coding-regexp-alist'.
1655        (save-excursion        (save-excursion
1656          (let ((alist auto-coding-regexp-alist)          (let ((alist auto-coding-regexp-alist)
# Line 1651  function by default." Line 1660  function by default."
1660                (when (re-search-forward regexp (+ (point) size) t)                (when (re-search-forward regexp (+ (point) size) t)
1661                  (setq coding-system (cdr (car alist)))))                  (setq coding-system (cdr (car alist)))))
1662              (setq alist (cdr alist)))              (setq alist (cdr alist)))
1663            coding-system))            (if coding-system
1664                  (cons coding-system 'auto-coding-regexp-alist))))
1665        (let* ((case-fold-search t)        (let* ((case-fold-search t)
1666               (head-start (point))               (head-start (point))
1667               (head-end (+ head-start (min size 1024)))               (head-end (+ head-start (min size 1024)))
# Line 1685  function by default." Line 1695  function by default."
1695                         (re-search-forward                         (re-search-forward
1696                          "\\(.*;\\)?[ \t]*coding:[ \t]*\\([^ ;]+\\)"                          "\\(.*;\\)?[ \t]*coding:[ \t]*\\([^ ;]+\\)"
1697                          head-end t))                          head-end t))
1698                (setq coding-system (intern (match-string 2)))                (setq coding-system (intern (match-string 2))))))
               (or (coding-system-p coding-system)  
                   (setq coding-system nil)))))  
1699    
1700          ;; If no coding: tag in the head, check the tail.          ;; If no coding: tag in the head, check the tail.
1701          ;; Here we must pay attention to the case that the end-of-line          ;; Here we must pay attention to the case that the end-of-line
# Line 1728  function by default." Line 1736  function by default."
1736                    (setq coding-system 'raw-text))                    (setq coding-system 'raw-text))
1737                  (when (and (not coding-system)                  (when (and (not coding-system)
1738                             (re-search-forward re-coding tail-end t))                             (re-search-forward re-coding tail-end t))
1739                    (setq coding-system (intern (match-string 1)))                    (setq coding-system (intern (match-string 1)))))))
1740                    (or (coding-system-p coding-system)          (if coding-system
1741                        (setq coding-system nil))))))              (cons coding-system :coding)))
         coding-system)  
1742        ;; Finally, try all the `auto-coding-functions'.        ;; Finally, try all the `auto-coding-functions'.
1743        (let ((funcs auto-coding-functions)        (let ((funcs auto-coding-functions)
1744              (coding-system nil))              (coding-system nil))
# Line 1741  function by default." Line 1748  function by default."
1748                                      (goto-char (point-min))                                      (goto-char (point-min))
1749                                      (funcall (pop funcs) size))                                      (funcall (pop funcs) size))
1750                                  (error nil))))                                  (error nil))))
1751          coding-system)))          (if coding-system
1752                (cons coding-system 'auto-coding-functions)))))
1753    
1754    (defun set-auto-coding (filename size)
1755      "Return coding system for a file FILENAME of which SIZE bytes follow point.
1756    See `find-auto-coding' for how the coding system is found.
1757    Return nil if an invalid coding system is found."
1758      (let ((found (find-auto-coding filename size)))
1759        (if (and found (coding-system-p (car found)))
1760            (car found))))
1761    
1762  (setq set-auto-coding-function 'set-auto-coding)  (setq set-auto-coding-function 'set-auto-coding)
1763    

Legend:
Removed from v.1.224  
changed lines
  Added in v.1.225

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26