emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/international/mule.el


From: Kenichi Handa
Subject: [Emacs-diffs] Changes to emacs/lisp/international/mule.el
Date: Tue, 11 Jun 2002 20:15:39 -0400

Index: emacs/lisp/international/mule.el
diff -c emacs/lisp/international/mule.el:1.146 
emacs/lisp/international/mule.el:1.147
*** emacs/lisp/international/mule.el:1.146      Wed May 22 23:40:16 2002
--- emacs/lisp/international/mule.el    Sat Jun  8 16:58:59 2002
***************
*** 1490,1496 ****
                       (symbol :tag "Coding system"))))
  
  ;; See the bottom of this file for built-in auto coding functions.
! (defcustom auto-coding-functions '(sgml-xml-auto-coding-function)
    "A list of functions which attempt to determine a coding system.
  
  Each function in this list should be written to operate on the current
--- 1490,1497 ----
                       (symbol :tag "Coding system"))))
  
  ;; See the bottom of this file for built-in auto coding functions.
! (defcustom auto-coding-functions '(sgml-xml-auto-coding-function
!                                  sgml-html-meta-auto-coding-function)
    "A list of functions which attempt to determine a coding system.
  
  Each function in this list should be written to operate on the current
***************
*** 1499,1506 ****
  succeeds in determining a coding system, it should return that coding
  system.  Otherwise, it should return nil.
  
! The functions in this list take priority over `coding:' tags in the
! file, just as for `auto-coding-regexp-alist'."
    :group 'files
    :group 'mule
    :type '(repeat function))
--- 1500,1507 ----
  succeeds in determining a coding system, it should return that coding
  system.  Otherwise, it should return nil.
  
! Any `coding:' tags present have a higher priority than the
! functions in this list."
    :group 'files
    :group 'mule
    :type '(repeat function))
***************
*** 1520,1545 ****
        (setq alist (cdr alist))))
      coding-system))
  
- (defun auto-coding-from-file-contents (size)
-   "Determine a coding system from the contents of the current buffer.
- The current buffer contains SIZE bytes starting at point.
- Value is either a coding system or nil."
-   (save-excursion
-     (let ((alist auto-coding-regexp-alist)
-         (funcs auto-coding-functions)
-         coding-system)
-       (while (and alist (not coding-system))
-       (let ((regexp (car (car alist))))
-         (when (re-search-forward regexp (+ (point) size) t)
-           (setq coding-system (cdr (car alist)))))
-       (setq alist (cdr alist)))
-       (while (and funcs (not coding-system))
-       (setq coding-system (condition-case e
-                               (save-excursion
-                                 (funcall (pop funcs) size))
-                             (error nil))))
-       coding-system)))
- 
  (defun set-auto-coding (filename size)
    "Return coding system for a file FILENAME of which SIZE bytes follow point.
  These bytes should include at least the first 1k of the file
--- 1521,1526 ----
***************
*** 1548,1558 ****
  It checks FILENAME against the variable `auto-coding-alist'.  If
  FILENAME doesn't match any entries in the variable, it checks the
  contents of the current buffer following point against
! `auto-coding-regexp-alist', and tries calling each function in
! `auto-coding-functions'.  If no match is found, it checks for a
  `coding:' tag in the first one or two lines following point.  If no
  `coding:' tag is found, it checks for local variables list in the last
! 3K bytes out of the SIZE bytes.
  
  The return value is the specified coding system,
  or nil if nothing specified.
--- 1529,1540 ----
  It checks FILENAME against the variable `auto-coding-alist'.  If
  FILENAME doesn't match any entries in the variable, it checks the
  contents of the current buffer following point against
! `auto-coding-regexp-alist'.  If no match is found, it checks for a
  `coding:' tag in the first one or two lines following point.  If no
  `coding:' tag is found, it checks for local variables list in the last
! 3K bytes out of the SIZE bytes.  Finally, if none of these methods
! succeed, then it checks to see if any function in
! `auto-coding-functions' gives a match.
  
  The return value is the specified coding system,
  or nil if nothing specified.
***************
*** 1560,1566 ****
  The variable `set-auto-coding-function' (which see) is set to this
  function by default."
    (or (auto-coding-alist-lookup filename)
!       (auto-coding-from-file-contents size)
        (let* ((case-fold-search t)
             (head-start (point))
             (head-end (+ head-start (min size 1024)))
--- 1542,1557 ----
  The variable `set-auto-coding-function' (which see) is set to this
  function by default."
    (or (auto-coding-alist-lookup filename)
!       ;; Try using `auto-coding-regexp-alist'.
!       (save-excursion
!       (let ((alist auto-coding-regexp-alist)
!             coding-system)
!         (while (and alist (not coding-system))
!           (let ((regexp (car (car alist))))
!             (when (re-search-forward regexp (+ (point) size) t)
!               (setq coding-system (cdr (car alist)))))
!           (setq alist (cdr alist))) 
!         coding-system))
        (let* ((case-fold-search t)
             (head-start (point))
             (head-end (+ head-start (min size 1024)))
***************
*** 1635,1640 ****
--- 1626,1641 ----
                  (setq coding-system (intern (match-string 1)))
                  (or (coding-system-p coding-system)
                      (setq coding-system nil))))))
+       coding-system)
+       ;; Finally, try all the `auto-coding-functions'.
+       (let ((funcs auto-coding-functions)
+           (coding-system nil))
+       (while (and funcs (not coding-system))
+         (setq coding-system (condition-case e
+                                 (save-excursion
+                                   (goto-char (point-min))
+                                   (funcall (pop funcs) size))
+                               (error nil))))
        coding-system)))
  
  (setq set-auto-coding-function 'set-auto-coding)
***************
*** 1931,1946 ****
                 (re-search-forward "\"\\s-*\\?>" size t))))
        (when end
        (if (re-search-forward "encoding=\"\\(.+?\\)\"" end t)
!           (let ((match (downcase (match-string 1))))
!             (cond ((member match '("utf-8" "iso-2022-jp"
!                                    "euc-jp" "shift_jis"))
!                    (intern match))
!                   ((string-match "iso-8859-[[:digit:]]+" match)
!                    (intern match))
!                   (t (message "Warning: unknown XML encoding %s" match)
!                      nil)))
          'utf-8)))))
  
  ;;;
  (provide 'mule)
  
--- 1932,1962 ----
                 (re-search-forward "\"\\s-*\\?>" size t))))
        (when end
        (if (re-search-forward "encoding=\"\\(.+?\\)\"" end t)
!           (let* ((match (match-string 1))
!                  (sym (intern (downcase match))))
!             (if (coding-system-p sym)
!                 sym
!               (message "Warning: unknown coding system \"%s\"" match)
!               nil))
          'utf-8)))))
  
+ (defun sgml-html-meta-auto-coding-function (size)
+   "If the buffer has an HTML meta tag, use it to determine encoding.
+ This function is intended to be added to `auto-coding-functions'."
+   (setq size (min size
+                 ;; Only search forward 10 lines
+                 (save-excursion
+                   (forward-line 10)
+                   (point))))
+   (when (and (search-forward "<html>" size t)
+            (re-search-forward 
"<meta\\s-+http-equiv=\"content-type\"\\s-+content=\"text/\\sw+;\\s-*charset=\\(.+?\\)\""
 size t))
+       (let* ((match (match-string 1))
+            (sym (intern (downcase match))))
+       (if (coding-system-p sym)
+           sym
+         (message "Warning: unknown coding system \"%s\"" match)
+         nil))))
+       
  ;;;
  (provide 'mule)
  



reply via email to

[Prev in Thread] Current Thread [Next in Thread]