Mercurial > emacs
comparison src/fileio.c @ 19641:d7f2d75a09d3
(Vset_auto_coding_function): Name changed from
Vauto_file_coding_system.
(syms_of_fileio): Adjusted for the above change. Doc-string
modified.
(Finsert_file_contents): The argument for Vset_auto_coding is a
concatination of the heading 1K-byte and the tailing 3K-byte.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Mon, 01 Sep 1997 07:15:46 +0000 |
parents | 30e299bb4a5d |
children | d206d8b146dc |
comparison
equal
deleted
inserted
replaced
19640:40bed12c4f2e | 19641:d7f2d75a09d3 |
---|---|
168 | 168 |
169 /* Lisp functions for translating file formats */ | 169 /* Lisp functions for translating file formats */ |
170 Lisp_Object Qformat_decode, Qformat_annotate_function; | 170 Lisp_Object Qformat_decode, Qformat_annotate_function; |
171 | 171 |
172 /* Function to be called to decide a coding system of a reading file. */ | 172 /* Function to be called to decide a coding system of a reading file. */ |
173 Lisp_Object Vauto_file_coding_system_function; | 173 Lisp_Object Vset_auto_coding_function; |
174 | 174 |
175 /* Functions to be called to process text properties in inserted file. */ | 175 /* Functions to be called to process text properties in inserted file. */ |
176 Lisp_Object Vafter_insert_file_functions; | 176 Lisp_Object Vafter_insert_file_functions; |
177 | 177 |
178 /* Functions to be called to create text property annotations for file. */ | 178 /* Functions to be called to create text property annotations for file. */ |
3147 val = Vcoding_system_for_read; | 3147 val = Vcoding_system_for_read; |
3148 else if (NILP (current_buffer->enable_multibyte_characters)) | 3148 else if (NILP (current_buffer->enable_multibyte_characters)) |
3149 val = Qemacs_mule; | 3149 val = Qemacs_mule; |
3150 else | 3150 else |
3151 { | 3151 { |
3152 if (SYMBOLP (Vauto_file_coding_system_function) | 3152 if (SYMBOLP (Vset_auto_coding_function) |
3153 && !NILP (Fboundp (Vauto_file_coding_system_function))) | 3153 && !NILP (Fboundp (Vset_auto_coding_function))) |
3154 { | 3154 { |
3155 /* Find a coding system specified in a few lines at the | 3155 /* Find a coding system specified in the heading two lines |
3156 head of the file. We assume that the fist 1K bytes is | 3156 or in the tailing several lines of the file. We assume |
3157 sufficient fot this purpose. */ | 3157 that the 1K-byte and 3K-byte for heading and tailing |
3158 int nread = read (fd, read_buf, 1024); | 3158 respectively are sufficient fot this purpose. */ |
3159 int how_many, nread; | |
3160 | |
3161 if (st.st_size <= (1024 * 4)) | |
3162 nread = read (fd, read_buf, 1024 * 4); | |
3163 else | |
3164 { | |
3165 nread = read (fd, read_buf, 1024); | |
3166 if (nread >= 0) | |
3167 { | |
3168 if (lseek (fd, st.st_size - (1024 * 3), 0) < 0) | |
3169 report_file_error ("Setting file position", | |
3170 Fcons (filename, Qnil)); | |
3171 nread += read (fd, read_buf + nread, 1024 * 3); | |
3172 } | |
3173 } | |
3159 | 3174 |
3160 if (nread < 0) | 3175 if (nread < 0) |
3161 error ("IO error reading %s: %s", | 3176 error ("IO error reading %s: %s", |
3162 XSTRING (filename)->data, strerror (errno)); | 3177 XSTRING (filename)->data, strerror (errno)); |
3163 else if (nread > 0) | 3178 else if (nread > 0) |
3164 { | 3179 { |
3165 val = call1 (Vauto_file_coding_system_function, | 3180 val = call1 (Vset_auto_coding_function, |
3166 make_string (read_buf, nread)); | 3181 make_string (read_buf, nread)); |
3167 /* Rewind the file for the actual read done later. */ | 3182 /* Rewind the file for the actual read done later. */ |
3168 if (lseek (fd, 0, 0) < 0) | 3183 if (lseek (fd, 0, 0) < 0) |
3169 report_file_error ("Setting file position", | 3184 report_file_error ("Setting file position", |
3170 Fcons (filename, Qnil)); | 3185 Fcons (filename, Qnil)); |
5178 (funcall HANDLER 'file-exists-p FILENAME)\n\ | 5193 (funcall HANDLER 'file-exists-p FILENAME)\n\ |
5179 The function `find-file-name-handler' checks this list for a handler\n\ | 5194 The function `find-file-name-handler' checks this list for a handler\n\ |
5180 for its argument."); | 5195 for its argument."); |
5181 Vfile_name_handler_alist = Qnil; | 5196 Vfile_name_handler_alist = Qnil; |
5182 | 5197 |
5183 DEFVAR_LISP ("auto-file-coding-system-function", | 5198 DEFVAR_LISP ("set-auto-coding-function", |
5184 &Vauto_file_coding_system_function, | 5199 &Vset_auto_coding_function, |
5185 "If non-nil, a function to call to decide a coding system of file.\n\ | 5200 "If non-nil, a function to call to decide a coding system of file.\n\ |
5186 One argument is passed to this function: the string of the first\n\ | 5201 One argument is passed to this function: the string of concatination\n\ |
5187 few lines of a file to be read.\n\ | 5202 or the heading 1K-byte and the tailing 3K-byte of a file to be read.\n\ |
5188 This function should return a coding system to decode the file contents\n\ | 5203 This function should return a coding system to decode the file contents\n\ |
5189 specified in the heading lines with the format:\n\ | 5204 specified in the heading lines with the format:\n\ |
5190 -*- ... coding: CODING-SYSTEM; ... -*-"); | 5205 -*- ... coding: CODING-SYSTEM; ... -*-\n\ |
5191 Vauto_file_coding_system_function = Qnil; | 5206 or local variable spec of the tailing lines with `coding:' tag."); |
5207 Vset_auto_coding_function = Qnil; | |
5192 | 5208 |
5193 DEFVAR_LISP ("after-insert-file-functions", &Vafter_insert_file_functions, | 5209 DEFVAR_LISP ("after-insert-file-functions", &Vafter_insert_file_functions, |
5194 "A list of functions to be called at the end of `insert-file-contents'.\n\ | 5210 "A list of functions to be called at the end of `insert-file-contents'.\n\ |
5195 Each is passed one argument, the number of bytes inserted. It should return\n\ | 5211 Each is passed one argument, the number of bytes inserted. It should return\n\ |
5196 the new byte count, and leave point the same. If `insert-file-contents' is\n\ | 5212 the new byte count, and leave point the same. If `insert-file-contents' is\n\ |