Mercurial > hg > xemacs-beta
comparison lisp/files.el @ 5682:dae33b5feffe
Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
src/ChangeLog addition:
2012-09-07 Aidan Kehoe <kehoea@parhasard.net>
* file-coding.c:
* file-coding.c (snarf_coding_system):
Take a new parameter, FIND_CODING_SYSTEM_P, which indicates that
find_coding_system() should be called.
* file-coding.c (look_for_coding_system_magic_cookie):
* file-coding.c (determine_real_coding_system):
* file-coding.c (undecided_convert):
Use this parameter.
* file-coding.c (Ffind_coding_system_magic_cookie_in_file):
New, moved from files.el, so we can use
look_for_coding_system_magic_cookie's implementation.
* file-coding.c (syms_of_file_coding):
Make Ffind_coding_system_magic_cookie_in_file available.
lisp/ChangeLog addition:
2012-09-07 Aidan Kehoe <kehoea@parhasard.net>
* files.el:
* files.el (find-coding-system-magic-cookie-in-file):
Removed. Move this to C, so we can use
look_for_coding_system_magic_cookie().
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Fri, 07 Sep 2012 22:06:01 +0100 |
parents | ee95ef1e644c |
children | cc852bdbdbaa |
comparison
equal
deleted
inserted
replaced
5681:4af5a3435c94 | 5682:dae33b5feffe |
---|---|
2124 (set var val)) | 2124 (set var val)) |
2125 (message "Ignoring `eval:' in the local variables list"))) | 2125 (message "Ignoring `eval:' in the local variables list"))) |
2126 ;; Ordinary variable, really set it. | 2126 ;; Ordinary variable, really set it. |
2127 (t (make-local-variable var) | 2127 (t (make-local-variable var) |
2128 (set var val)))) | 2128 (set var val)))) |
2129 | |
2130 (defun find-coding-system-magic-cookie-in-file (file) | |
2131 "Look for the coding-system magic cookie in FILE. | |
2132 The coding-system magic cookie is either the local variable specification | |
2133 -*- ... coding: ... -*- on the first line, or the exact string | |
2134 \";;;###coding system: \" somewhere within the first 3000 characters | |
2135 of the file. If found, the coding system name (as a string) is returned; | |
2136 otherwise nil is returned. Note that it is extremely unlikely that | |
2137 either such string would occur coincidentally as the result of encoding | |
2138 some characters in a non-ASCII charset, and that the spaces make it | |
2139 even less likely since the space character is not a valid octet in any | |
2140 ISO 2022 encoding of most non-ASCII charsets." | |
2141 (save-excursion | |
2142 (with-temp-buffer | |
2143 (let ((coding-system-for-read 'raw-text)) | |
2144 (insert-file-contents file nil 0 3000)) | |
2145 (goto-char (point-min)) | |
2146 (or (and (looking-at | |
2147 "^[^\n]*-\\*-[^\n]*coding: \\([^ \t\n;]+\\)[^\n]*-\\*-") | |
2148 (buffer-substring (match-beginning 1) (match-end 1))) | |
2149 ;; (save-excursion | |
2150 ;; (let (start end) | |
2151 ;; (and (re-search-forward "^;+[ \t]*Local Variables:" nil t) | |
2152 ;; (setq start (match-end 0)) | |
2153 ;; (re-search-forward "\n;+[ \t]*End:") | |
2154 ;; (setq end (match-beginning 0)) | |
2155 ;; (save-restriction | |
2156 ;; (narrow-to-region start end) | |
2157 ;; (goto-char start) | |
2158 ;; (re-search-forward "^;;; coding: \\([^\n]+\\)$" nil t) | |
2159 ;; ) | |
2160 ;; (let ((codesys | |
2161 ;; (intern (buffer-substring | |
2162 ;; (match-beginning 1)(match-end 1))))) | |
2163 ;; (if (find-coding-system codesys) codesys)) | |
2164 ;; ))) | |
2165 (let ((case-fold-search nil)) | |
2166 (if (search-forward | |
2167 ";;;###coding system: " (+ (point-min) 3000) t) | |
2168 (let ((start (point)) | |
2169 (end (progn | |
2170 (skip-chars-forward "^ \t\n\r") | |
2171 (point)))) | |
2172 (if (> end start) (buffer-substring start end)) | |
2173 ))) | |
2174 )))) | |
2175 | 2129 |
2176 | 2130 |
2177 (defcustom change-major-mode-with-file-name t | 2131 (defcustom change-major-mode-with-file-name t |
2178 "*Non-nil means \\[write-file] should set the major mode from the file name. | 2132 "*Non-nil means \\[write-file] should set the major mode from the file name. |
2179 However, the mode will not be changed if | 2133 However, the mode will not be changed if |