comparison lispref/files.texi @ 45979:87962bf716e3

*** empty log message ***
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sun, 23 Jun 2002 22:15:43 +0000
parents cd1cd95ca64e
children 2c01ee3e5305
comparison
equal deleted inserted replaced
45978:a8fbafaa31ad 45979:87962bf716e3
139 The @code{find-file-noselect} function normally calls 139 The @code{find-file-noselect} function normally calls
140 @code{after-find-file} after reading the file (@pxref{Subroutines of 140 @code{after-find-file} after reading the file (@pxref{Subroutines of
141 Visiting}). That function sets the buffer major mode, parses local 141 Visiting}). That function sets the buffer major mode, parses local
142 variables, warns the user if there exists an auto-save file more recent 142 variables, warns the user if there exists an auto-save file more recent
143 than the file just visited, and finishes by running the functions in 143 than the file just visited, and finishes by running the functions in
144 @code{find-file-hooks}. 144 @code{find-file-hook}.
145 145
146 If the optional argument @var{rawfile} is non-@code{nil}, then 146 If the optional argument @var{rawfile} is non-@code{nil}, then
147 @code{after-find-file} is not called, and the 147 @code{after-find-file} is not called, and the
148 @code{find-file-not-found-hooks} are not run in case of failure. What's 148 @code{find-file-not-found-functions} are not run in case of failure. What's
149 more, a non-@code{nil} @var{rawfile} value suppresses coding system 149 more, a non-@code{nil} @var{rawfile} value suppresses coding system
150 conversion (@pxref{Coding Systems}) and format conversion (@pxref{Format 150 conversion (@pxref{Coding Systems}) and format conversion (@pxref{Format
151 Conversion}). 151 Conversion}).
152 152
153 The @code{find-file-noselect} function usually returns the buffer that 153 The @code{find-file-noselect} function usually returns the buffer that
198 commands check for wildcard characters and visit all the files that 198 commands check for wildcard characters and visit all the files that
199 match them. If this is @code{nil}, then wildcard characters are 199 match them. If this is @code{nil}, then wildcard characters are
200 not treated specially. 200 not treated specially.
201 @end defvar 201 @end defvar
202 202
203 @defvar find-file-hooks 203 @defvar find-file-hook
204 The value of this variable is a list of functions to be called after a 204 The value of this variable is a list of functions to be called after a
205 file is visited. The file's local-variables specification (if any) will 205 file is visited. The file's local-variables specification (if any) will
206 have been processed before the hooks are run. The buffer visiting the 206 have been processed before the hooks are run. The buffer visiting the
207 file is current when the hook functions are run. 207 file is current when the hook functions are run.
208 208
209 This variable works just like a normal hook, but we think that renaming 209 This variable works just like a normal hook, but we think that renaming
210 it would not be advisable. @xref{Hooks}. 210 it would not be advisable. @xref{Hooks}.
211 @end defvar 211 @end defvar
212 212
213 @defvar find-file-not-found-hooks 213 @defvar find-file-not-found-functions
214 The value of this variable is a list of functions to be called when 214 The value of this variable is a list of functions to be called when
215 @code{find-file} or @code{find-file-noselect} is passed a nonexistent 215 @code{find-file} or @code{find-file-noselect} is passed a nonexistent
216 file name. @code{find-file-noselect} calls these functions as soon as 216 file name. @code{find-file-noselect} calls these functions as soon as
217 it detects a nonexistent file. It calls them in the order of the list, 217 it detects a nonexistent file. It calls them in the order of the list,
218 until one of them returns non-@code{nil}. @code{buffer-file-name} is 218 until one of them returns non-@code{nil}. @code{buffer-file-name} is
283 effect, but some mode functions and hook functions check the value 283 effect, but some mode functions and hook functions check the value
284 of this variable. 284 of this variable.
285 285
286 If @var{nomodes} is non-@code{nil}, that means don't alter the buffer's 286 If @var{nomodes} is non-@code{nil}, that means don't alter the buffer's
287 major mode, don't process local variables specifications in the file, 287 major mode, don't process local variables specifications in the file,
288 and don't run @code{find-file-hooks}. This feature is used by 288 and don't run @code{find-file-hook}. This feature is used by
289 @code{revert-buffer} in some cases. 289 @code{revert-buffer} in some cases.
290 290
291 The last thing @code{after-find-file} does is call all the functions 291 The last thing @code{after-find-file} does is call all the functions
292 in the list @code{find-file-hooks}. 292 in the list @code{find-file-hook}.
293 @end defun 293 @end defun
294 294
295 @node Saving Buffers 295 @node Saving Buffers
296 @section Saving Buffers 296 @section Saving Buffers
297 297
360 360
361 Saving a buffer runs several hooks. It also performs format 361 Saving a buffer runs several hooks. It also performs format
362 conversion (@pxref{Format Conversion}), and may save text properties in 362 conversion (@pxref{Format Conversion}), and may save text properties in
363 ``annotations'' (@pxref{Saving Properties}). 363 ``annotations'' (@pxref{Saving Properties}).
364 364
365 @defvar write-file-hooks 365 @defvar write-file-functions
366 The value of this variable is a list of functions to be called before 366 The value of this variable is a list of functions to be called before
367 writing out a buffer to its visited file. If one of them returns 367 writing out a buffer to its visited file. If one of them returns
368 non-@code{nil}, the file is considered already written and the rest of 368 non-@code{nil}, the file is considered already written and the rest of
369 the functions are not called, nor is the usual code for writing the file 369 the functions are not called, nor is the usual code for writing the file
370 executed. 370 executed.
371 371
372 If a function in @code{write-file-hooks} returns non-@code{nil}, it 372 If a function in @code{write-file-functions} returns non-@code{nil}, it
373 is responsible for making a backup file (if that is appropriate). 373 is responsible for making a backup file (if that is appropriate).
374 To do so, execute the following code: 374 To do so, execute the following code:
375 375
376 @example 376 @example
377 (or buffer-backed-up (backup-buffer)) 377 (or buffer-backed-up (backup-buffer))
379 379
380 You might wish to save the file modes value returned by 380 You might wish to save the file modes value returned by
381 @code{backup-buffer} and use that to set the mode bits of the file that 381 @code{backup-buffer} and use that to set the mode bits of the file that
382 you write. This is what @code{save-buffer} normally does. 382 you write. This is what @code{save-buffer} normally does.
383 383
384 The hook functions in @code{write-file-hooks} are also responsible for 384 The hook functions in @code{write-file-functions} are also responsible for
385 encoding the data (if desired): they must choose a suitable coding 385 encoding the data (if desired): they must choose a suitable coding
386 system (@pxref{Lisp and Coding Systems}), perform the encoding 386 system (@pxref{Lisp and Coding Systems}), perform the encoding
387 (@pxref{Explicit Encoding}), and set @code{last-coding-system-used} to 387 (@pxref{Explicit Encoding}), and set @code{last-coding-system-used} to
388 the coding system that was used (@pxref{Encoding and I/O}). 388 the coding system that was used (@pxref{Encoding and I/O}).
389 389
390 Do not make this variable buffer-local. To set up buffer-specific hook 390 If you set this hook locally in a buffer, it is assumed to be
391 functions, use @code{write-contents-hooks} instead. 391 associated with the file or the way the contents of the buffer were
392 obtained. Thus the variable is marked as a permanent local, so that
393 changing the major mode does not alter a buffer-local value. On the
394 other hand, calling @code{set-visited-file-name} will reset it.
395 If this is not what you want, you might like to use
396 @code{write-contents-functions} instead.
392 397
393 Even though this is not a normal hook, you can use @code{add-hook} and 398 Even though this is not a normal hook, you can use @code{add-hook} and
394 @code{remove-hook} to manipulate the list. @xref{Hooks}. 399 @code{remove-hook} to manipulate the list. @xref{Hooks}.
395 @end defvar 400 @end defvar
396 401
397 @c Emacs 19 feature 402 @c Emacs 19 feature
398 @defvar local-write-file-hooks 403 @defvar write-contents-functions
399 This works just like @code{write-file-hooks}, but it is intended to be 404 This works just like @code{write-file-functions}, but it is intended for
400 made buffer-local in particular buffers, and used for hooks that pertain
401 to the file name or the way the buffer contents were obtained.
402
403 The variable is marked as a permanent local, so that changing the major
404 mode does not alter a buffer-local value. This is convenient for
405 packages that read ``file'' contents in special ways, and set up hooks
406 to save the data in a corresponding way.
407 @end defvar
408
409 @c Emacs 19 feature
410 @defvar write-contents-hooks
411 This works just like @code{write-file-hooks}, but it is intended for
412 hooks that pertain to the contents of the file, as opposed to hooks that 405 hooks that pertain to the contents of the file, as opposed to hooks that
413 pertain to where the file came from. Such hooks are usually set up by 406 pertain to where the file came from. Such hooks are usually set up by
414 major modes, as buffer-local bindings for this variable. 407 major modes, as buffer-local bindings for this variable.
415 408
416 This variable automatically becomes buffer-local whenever it is set; 409 This variable automatically becomes buffer-local whenever it is set;
417 switching to a new major mode always resets this variable. When you use 410 switching to a new major mode always resets this variable.
418 @code{add-hooks} to add an element to this hook, you should @emph{not}
419 specify a non-@code{nil} @var{local} argument, since this variable is
420 used @emph{only} buffer-locally.
421 @end defvar 411 @end defvar
422 412
423 @c Emacs 19 feature 413 @c Emacs 19 feature
424 @defvar after-save-hook 414 @defvar after-save-hook
425 This normal hook runs after a buffer has been saved in its visited file. 415 This normal hook runs after a buffer has been saved in its visited file.
512 502
513 @defun insert-file-contents-literally filename &optional visit beg end replace 503 @defun insert-file-contents-literally filename &optional visit beg end replace
514 This function works like @code{insert-file-contents} except that it does 504 This function works like @code{insert-file-contents} except that it does
515 not do format decoding (@pxref{Format Conversion}), does not do 505 not do format decoding (@pxref{Format Conversion}), does not do
516 character code conversion (@pxref{Coding Systems}), does not run 506 character code conversion (@pxref{Coding Systems}), does not run
517 @code{find-file-hooks}, does not perform automatic uncompression, and so 507 @code{find-file-hook}, does not perform automatic uncompression, and so
518 on. 508 on.
519 @end defun 509 @end defun
520 510
521 If you want to pass a file name to another process so that another 511 If you want to pass a file name to another process so that another
522 program can read the file, use the function @code{file-local-copy}; see 512 program can read the file, use the function @code{file-local-copy}; see