changeset 22699:754703e243e6

(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.
author Kenichi Handa <handa@m17n.org>
date Mon, 06 Jul 1998 01:52:48 +0000
parents ea6ef56295b4
children 0931de7fa601
files lisp/international/mule.el
diffstat 1 files changed, 40 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/international/mule.el	Mon Jul 06 01:47:34 1998 +0000
+++ b/lisp/international/mule.el	Mon Jul 06 01:52:48 1998 +0000
@@ -64,6 +64,7 @@
 	(setq preloaded-file-list (cons file preloaded-file-list)))
       (unwind-protect
 	  (let ((load-file-name fullname)
+		(set-auto-coding-for-load t)
 		(inhibit-file-name-operation nil))
 	    (save-excursion
 	      (set-buffer buffer)
@@ -774,12 +775,18 @@
 
 ;;; FILE I/O
 
+(defvar set-auto-coding-for-load nil
+  "Non-nil means look for `load-coding' property instead of `coding'.
+This is used for loading and byte-compiling Emacs Lisp files.")
+
 (defun set-auto-coding (size)
   "Return coding system for a file of which SIZE bytes follow point.
+These bytes should include at least the first 1k of the file
+and the last 3k of the file, but the middle may be omitted.
 
-It checks for a -*- coding: tag in the first one or two lines
-following point.  If no coding: tag is found, it checks local
-variables spec in the last 3K-byte of SIZE bytes.
+It checks for a `coding:' tag in the first one or two lines following
+point.  If no `coding:' tag is found, it checks for alocal 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.
@@ -792,14 +799,16 @@
 	 (tail-start (+ head-start (max (- size 3072) 0)))
 	 (tail-end (+ head-start size))
 	 coding-system head-found tail-found pos)
-    ;; Try a short cut by searching for the string "coding:" at the
-    ;; head and tail of SIZE bytes.
-    (setq head-found (search-forward "coding:" head-end t))
+    ;; Try a short cut by searching for the string "coding:"
+    ;; and for "unibyte:" at th ehead and tail of SIZE bytes.
+    (setq head-found (or (search-forward "coding:" head-end t)
+			 (search-forward "unibyte:" head-end t)))
     (if (and head-found (> head-found tail-start))
 	;; Head and tail are overlapped.
 	(setq tail-found head-found)
       (goto-char tail-start)
-      (setq tail-found (search-forward "coding:" tail-end t)))
+      (setq tail-found (or (search-forward "coding:" tail-end t)
+			   (search-forward "unibyte:" tail-end t))))
 
     ;; At first check the head.
     (when head-found
@@ -816,12 +825,18 @@
       (if pos (setq head-end pos))
       (when (< head-found head-end)
 	(goto-char head-start)
-	(if (re-search-forward
-	     "-\\*-\\(.*;\\)?[ \t]*coding:[ \t]*\\([^ ;]+\\)" head-end t)
-	    (progn
-	      (setq coding-system (intern (match-string 2)))
-	      (or (coding-system-p coding-system)
-		  (setq coding-system nil))))))
+	(when (and set-auto-coding-for-load
+		   (re-search-forward
+		    "-\\*-\\(.*;\\)?[ \t]*unibyte:[ \t]*\\([^ ;]+\\)"
+		    head-end t))
+	  (setq coding-system 'raw-text))
+	(when (and (not coding-system)
+		   (re-search-forward
+		    "-\\*-\\(.*;\\)?[ \t]*coding:[ \t]*\\([^ ;]+\\)"
+		    head-end t))
+	  (setq coding-system (intern (match-string 2)))
+	  (or (coding-system-p coding-system)
+	      (setq coding-system nil)))))
 
     ;; If no coding: tag in the head, check the tail.
     (when (and tail-found (not coding-system))
@@ -838,17 +853,24 @@
 			     "^" prefix
 			     "coding[ \t]*:[ \t]*\\([^ \t]+\\)[ \t]*"
 			     suffix "$"))
+		 (re-unibyte (concat
+			      "^" prefix
+			      "unibyte[ \t]*:[ \t]*\\([^ \t]+\\)[ \t]*"
+			      suffix "$"))
 		 (re-end (concat
 			  "^" prefix "end *:[ \t]*" suffix "$"))
 		 (pos (point)))
 	    (re-search-forward re-end tail-end 'move)
 	    (setq tail-end (point))
 	    (goto-char pos)
-	    (if (re-search-forward re-coding tail-end t)
-		(progn
-		  (setq coding-system (intern (match-string 1)))
-		  (or (coding-system-p coding-system)
-		      (setq coding-system nil)))))))
+	    (when (and set-auto-coding-for-load
+		       (re-search-forward re-unibyte tail-end t))
+	      (setq coding-system 'raw-text))
+	    (when (and (not coding-system)
+		       (re-search-forward re-coding tail-end t))
+	      (setq coding-system (intern (match-string 1)))
+	      (or (coding-system-p coding-system)
+		  (setq coding-system nil))))))
     coding-system))
 
 (setq set-auto-coding-function 'set-auto-coding)