diff options
| author | Kenichi Handa | 1998-07-06 01:52:48 +0000 |
|---|---|---|
| committer | Kenichi Handa | 1998-07-06 01:52:48 +0000 |
| commit | 1c4cc63a3c63771302f01700ddafb93bec60f9b4 (patch) | |
| tree | 4959e2ef804ebc36678f277f70bba50a6e48ef8e | |
| parent | 8f2917e4dc59d1394a34e49371e19e29fac9966d (diff) | |
| download | emacs-1c4cc63a3c63771302f01700ddafb93bec60f9b4.tar.gz emacs-1c4cc63a3c63771302f01700ddafb93bec60f9b4.zip | |
(set-auto-coding-for-load): New variable.
(set-auto-coding): If set-auto-coding-for-load is non-nil,
look for "unibyte" file variable first, then for "coding".
(load-with-code-conversion): Bind set-auto-coding-for-load to t.
| -rw-r--r-- | lisp/international/mule.el | 58 |
1 files changed, 40 insertions, 18 deletions
diff --git a/lisp/international/mule.el b/lisp/international/mule.el index 923ff1178fb..bb05a12bbc1 100644 --- a/lisp/international/mule.el +++ b/lisp/international/mule.el | |||
| @@ -64,6 +64,7 @@ Return t if file exists." | |||
| 64 | (setq preloaded-file-list (cons file preloaded-file-list))) | 64 | (setq preloaded-file-list (cons file preloaded-file-list))) |
| 65 | (unwind-protect | 65 | (unwind-protect |
| 66 | (let ((load-file-name fullname) | 66 | (let ((load-file-name fullname) |
| 67 | (set-auto-coding-for-load t) | ||
| 67 | (inhibit-file-name-operation nil)) | 68 | (inhibit-file-name-operation nil)) |
| 68 | (save-excursion | 69 | (save-excursion |
| 69 | (set-buffer buffer) | 70 | (set-buffer buffer) |
| @@ -774,12 +775,18 @@ LIST is a list of coding categories ordered by priority." | |||
| 774 | 775 | ||
| 775 | ;;; FILE I/O | 776 | ;;; FILE I/O |
| 776 | 777 | ||
| 778 | (defvar set-auto-coding-for-load nil | ||
| 779 | "Non-nil means look for `load-coding' property instead of `coding'. | ||
| 780 | This is used for loading and byte-compiling Emacs Lisp files.") | ||
| 781 | |||
| 777 | (defun set-auto-coding (size) | 782 | (defun set-auto-coding (size) |
| 778 | "Return coding system for a file of which SIZE bytes follow point. | 783 | "Return coding system for a file of which SIZE bytes follow point. |
| 784 | These bytes should include at least the first 1k of the file | ||
| 785 | and the last 3k of the file, but the middle may be omitted. | ||
| 779 | 786 | ||
| 780 | It checks for a -*- coding: tag in the first one or two lines | 787 | It checks for a `coding:' tag in the first one or two lines following |
| 781 | following point. If no coding: tag is found, it checks local | 788 | point. If no `coding:' tag is found, it checks for alocal variables |
| 782 | variables spec in the last 3K-byte of SIZE bytes. | 789 | list in the last 3K bytes out of the SIZE bytes. |
| 783 | 790 | ||
| 784 | The return value is the specified coding system, | 791 | The return value is the specified coding system, |
| 785 | or nil if nothing specified. | 792 | or nil if nothing specified. |
| @@ -792,14 +799,16 @@ function by default." | |||
| 792 | (tail-start (+ head-start (max (- size 3072) 0))) | 799 | (tail-start (+ head-start (max (- size 3072) 0))) |
| 793 | (tail-end (+ head-start size)) | 800 | (tail-end (+ head-start size)) |
| 794 | coding-system head-found tail-found pos) | 801 | coding-system head-found tail-found pos) |
| 795 | ;; Try a short cut by searching for the string "coding:" at the | 802 | ;; Try a short cut by searching for the string "coding:" |
| 796 | ;; head and tail of SIZE bytes. | 803 | ;; and for "unibyte:" at th ehead and tail of SIZE bytes. |
| 797 | (setq head-found (search-forward "coding:" head-end t)) | 804 | (setq head-found (or (search-forward "coding:" head-end t) |
| 805 | (search-forward "unibyte:" head-end t))) | ||
| 798 | (if (and head-found (> head-found tail-start)) | 806 | (if (and head-found (> head-found tail-start)) |
| 799 | ;; Head and tail are overlapped. | 807 | ;; Head and tail are overlapped. |
| 800 | (setq tail-found head-found) | 808 | (setq tail-found head-found) |
| 801 | (goto-char tail-start) | 809 | (goto-char tail-start) |
| 802 | (setq tail-found (search-forward "coding:" tail-end t))) | 810 | (setq tail-found (or (search-forward "coding:" tail-end t) |
| 811 | (search-forward "unibyte:" tail-end t)))) | ||
| 803 | 812 | ||
| 804 | ;; At first check the head. | 813 | ;; At first check the head. |
| 805 | (when head-found | 814 | (when head-found |
| @@ -816,12 +825,18 @@ function by default." | |||
| 816 | (if pos (setq head-end pos)) | 825 | (if pos (setq head-end pos)) |
| 817 | (when (< head-found head-end) | 826 | (when (< head-found head-end) |
| 818 | (goto-char head-start) | 827 | (goto-char head-start) |
| 819 | (if (re-search-forward | 828 | (when (and set-auto-coding-for-load |
| 820 | "-\\*-\\(.*;\\)?[ \t]*coding:[ \t]*\\([^ ;]+\\)" head-end t) | 829 | (re-search-forward |
| 821 | (progn | 830 | "-\\*-\\(.*;\\)?[ \t]*unibyte:[ \t]*\\([^ ;]+\\)" |
| 822 | (setq coding-system (intern (match-string 2))) | 831 | head-end t)) |
| 823 | (or (coding-system-p coding-system) | 832 | (setq coding-system 'raw-text)) |
| 824 | (setq coding-system nil)))))) | 833 | (when (and (not coding-system) |
| 834 | (re-search-forward | ||
| 835 | "-\\*-\\(.*;\\)?[ \t]*coding:[ \t]*\\([^ ;]+\\)" | ||
| 836 | head-end t)) | ||
| 837 | (setq coding-system (intern (match-string 2))) | ||
| 838 | (or (coding-system-p coding-system) | ||
| 839 | (setq coding-system nil))))) | ||
| 825 | 840 | ||
| 826 | ;; If no coding: tag in the head, check the tail. | 841 | ;; If no coding: tag in the head, check the tail. |
| 827 | (when (and tail-found (not coding-system)) | 842 | (when (and tail-found (not coding-system)) |
| @@ -838,17 +853,24 @@ function by default." | |||
| 838 | "^" prefix | 853 | "^" prefix |
| 839 | "coding[ \t]*:[ \t]*\\([^ \t]+\\)[ \t]*" | 854 | "coding[ \t]*:[ \t]*\\([^ \t]+\\)[ \t]*" |
| 840 | suffix "$")) | 855 | suffix "$")) |
| 856 | (re-unibyte (concat | ||
| 857 | "^" prefix | ||
| 858 | "unibyte[ \t]*:[ \t]*\\([^ \t]+\\)[ \t]*" | ||
| 859 | suffix "$")) | ||
| 841 | (re-end (concat | 860 | (re-end (concat |
| 842 | "^" prefix "end *:[ \t]*" suffix "$")) | 861 | "^" prefix "end *:[ \t]*" suffix "$")) |
| 843 | (pos (point))) | 862 | (pos (point))) |
| 844 | (re-search-forward re-end tail-end 'move) | 863 | (re-search-forward re-end tail-end 'move) |
| 845 | (setq tail-end (point)) | 864 | (setq tail-end (point)) |
| 846 | (goto-char pos) | 865 | (goto-char pos) |
| 847 | (if (re-search-forward re-coding tail-end t) | 866 | (when (and set-auto-coding-for-load |
| 848 | (progn | 867 | (re-search-forward re-unibyte tail-end t)) |
| 849 | (setq coding-system (intern (match-string 1))) | 868 | (setq coding-system 'raw-text)) |
| 850 | (or (coding-system-p coding-system) | 869 | (when (and (not coding-system) |
| 851 | (setq coding-system nil))))))) | 870 | (re-search-forward re-coding tail-end t)) |
| 871 | (setq coding-system (intern (match-string 1))) | ||
| 872 | (or (coding-system-p coding-system) | ||
| 873 | (setq coding-system nil)))))) | ||
| 852 | coding-system)) | 874 | coding-system)) |
| 853 | 875 | ||
| 854 | (setq set-auto-coding-function 'set-auto-coding) | 876 | (setq set-auto-coding-function 'set-auto-coding) |