The variable format-alist
defines a list of file formats,
which describe textual representations used in files for the data (text,
text-properties, and possibly other information) in an Emacs buffer.
Emacs performs format conversion if appropriate when reading and writing
files.
Each format definition is a list of this form:
(name doc-string regexp from-fn to-fn modify mode-fn)
Here is what the elements in a format definition mean:
(position . string)
, where position is an
integer specifying the relative position in the text to be written, and
string is the annotation to add there. The list must be sorted in
order of position when to-fn returns it.
When write-region
actually writes the text from the buffer to the
file, it intermixes the specified annotations at the corresponding
positions. All this takes place without modifying the buffer.
t
if the encoding function modifies the buffer, and
nil
if it works by returning a list of annotations.
The function insert-file-contents
automatically recognizes file
formats when it reads the specified file. It checks the text of the
beginning of the file against the regular expressions of the format
definitions, and if it finds a match, it calls the decoding function for
that format. Then it checks all the known formats over again.
It keeps checking them until none of them is applicable.
Visiting a file, with find-file-noselect
or the commands that use
it, performs conversion likewise (because it calls
insert-file-contents
); it also calls the mode function for each
format that it decodes. It stores a list of the format names in the
buffer-local variable buffer-file-format
.
When write-region
writes data into a file, it first calls the
encoding functions for the formats listed in buffer-file-format
,
in the order of appearance in the list.
The argument format is a list of format names. If format is
nil
, no conversion takes place. Interactively, typing just
RET for format specifies nil
.
nil
, they specify which part of the file to read, as in
insert-file-contents
(see section Reading from Files).
The return value is like what insert-file-contents
returns: a
list of the absolute file name and the length of the data inserted
(after conversion).
The argument format is a list of format names. If format is
nil
, no conversion takes place. Interactively, typing just
RET for format specifies nil
.
buffer-file-format
; however, it is used instead of
buffer-file-format
for writing auto-save files. This variable is
always buffer-local in all buffers.
Go to the first, previous, next, last section, table of contents.