(M-40132'): Unify GT-53970.
[chise/xemacs-chise.git-] / info / lispref.info-23
1 This is ../info/lispref.info, produced by makeinfo version 4.0b from
2 lispref/lispref.texi.
3
4 INFO-DIR-SECTION XEmacs Editor
5 START-INFO-DIR-ENTRY
6 * Lispref: (lispref).           XEmacs Lisp Reference Manual.
7 END-INFO-DIR-ENTRY
8
9    Edition History:
10
11    GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
12 Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
13 Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
14 XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
15 GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
16 Programmer's Manual (for 19.13) Third Edition, July 1995 XEmacs Lisp
17 Reference Manual (for 19.14 and 20.0) v3.1, March 1996 XEmacs Lisp
18 Reference Manual (for 19.15 and 20.1, 20.2, 20.3) v3.2, April, May,
19 November 1997 XEmacs Lisp Reference Manual (for 21.0) v3.3, April 1998
20
21    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
22 Foundation, Inc.  Copyright (C) 1994, 1995 Sun Microsystems, Inc.
23 Copyright (C) 1995, 1996 Ben Wing.
24
25    Permission is granted to make and distribute verbatim copies of this
26 manual provided the copyright notice and this permission notice are
27 preserved on all copies.
28
29    Permission is granted to copy and distribute modified versions of
30 this manual under the conditions for verbatim copying, provided that the
31 entire resulting derived work is distributed under the terms of a
32 permission notice identical to this one.
33
34    Permission is granted to copy and distribute translations of this
35 manual into another language, under the above conditions for modified
36 versions, except that this permission notice may be stated in a
37 translation approved by the Foundation.
38
39    Permission is granted to copy and distribute modified versions of
40 this manual under the conditions for verbatim copying, provided also
41 that the section entitled "GNU General Public License" is included
42 exactly as in the original, and provided that the entire resulting
43 derived work is distributed under the terms of a permission notice
44 identical to this one.
45
46    Permission is granted to copy and distribute translations of this
47 manual into another language, under the above conditions for modified
48 versions, except that the section entitled "GNU General Public License"
49 may be included in a translation approved by the Free Software
50 Foundation instead of in the original English.
51
52 \1f
53 File: lispref.info,  Node: Help Functions,  Next: Obsoleteness,  Prev: Describing Characters,  Up: Documentation
54
55 Help Functions
56 ==============
57
58    XEmacs provides a variety of on-line help functions, all accessible
59 to the user as subcommands of the prefix `C-h', or on some keyboards,
60 `help'.  For more information about them, see *Note Help: (emacs)Help.
61 Here we describe some program-level interfaces to the same information.
62
63  - Command: apropos regexp &optional do-all predicate
64      This function finds all symbols whose names contain a match for the
65      regular expression REGEXP, and returns a list of them (*note
66      Regular Expressions::).  It also displays the symbols in a buffer
67      named `*Help*', each with a one-line description.
68
69      If DO-ALL is non-`nil', then `apropos' also shows key bindings for
70      the functions that are found.
71
72      If PREDICATE is non-`nil', it should be a function to be called on
73      each symbol that has matched REGEXP.  Only symbols for which
74      PREDICATE returns a non-`nil' value are listed or displayed.
75
76      In the first of the following examples, `apropos' finds all the
77      symbols with names containing `exec'.  In the second example, it
78      finds and returns only those symbols that are also commands.  (We
79      don't show the output that results in the `*Help*' buffer.)
80
81           (apropos "exec")
82                => (Buffer-menu-execute command-execute exec-directory
83               exec-path execute-extended-command execute-kbd-macro
84               executing-kbd-macro executing-macro)
85           
86           (apropos "exec" nil 'commandp)
87                => (Buffer-menu-execute execute-extended-command)
88
89      `apropos' is used by various user-level commands, such as `C-h a'
90      (`hyper-apropos'), a graphical front-end to `apropos'; and `C-h A'
91      (`command-apropos'), which does an apropos over only those
92      functions which are user commands.  `command-apropos' calls
93      `apropos', specifying a PREDICATE to restrict the output to
94      symbols that are commands.  The call to `apropos' looks like this:
95
96           (apropos string t 'commandp)
97
98  - Variable: help-map
99      The value of this variable is a local keymap for characters
100      following the Help key, `C-h'.
101
102  - Prefix Command: help-command
103      This symbol is not a function; its function definition is actually
104      the keymap known as `help-map'.  It is defined in `help.el' as
105      follows:
106
107           (define-key global-map "\C-h" 'help-command)
108           (fset 'help-command help-map)
109
110  - Function: print-help-return-message &optional function
111      This function builds a string that explains how to restore the
112      previous state of the windows after a help command.  After
113      building the message, it applies FUNCTION to it if FUNCTION is
114      non-`nil'.  Otherwise it calls `message' to display it in the echo
115      area.
116
117      This function expects to be called inside a
118      `with-output-to-temp-buffer' special form, and expects
119      `standard-output' to have the value bound by that special form.
120      For an example of its use, see the long example in *Note Accessing
121      Documentation::.
122
123  - Variable: help-char
124      The value of this variable is the help character--the character
125      that XEmacs recognizes as meaning Help.  By default, it is the
126      character `?\^H' (ASCII 8), which is `C-h'.  When XEmacs reads this
127      character, if `help-form' is non-`nil' Lisp expression, it
128      evaluates that expression, and displays the result in a window if
129      it is a string.
130
131      `help-char' can be a character or a key description such as `help'
132      or `(meta h)'.
133
134      Usually the value of `help-form''s value is `nil'.  Then the help
135      character has no special meaning at the level of command input, and
136      it becomes part of a key sequence in the normal way.  The standard
137      key binding of `C-h' is a prefix key for several general-purpose
138      help features.
139
140      The help character is special after prefix keys, too.  If it has no
141      binding as a subcommand of the prefix key, it runs
142      `describe-prefix-bindings', which displays a list of all the
143      subcommands of the prefix key.
144
145  - Variable: help-form
146      If this variable is non-`nil', its value is a form to evaluate
147      whenever the character `help-char' is read.  If evaluating the form
148      produces a string, that string is displayed.
149
150      A command that calls `next-command-event' or `next-event' probably
151      should bind `help-form' to a non-`nil' expression while it does
152      input.  (The exception is when `C-h' is meaningful input.)
153      Evaluating this expression should result in a string that explains
154      what the input is for and how to enter it properly.
155
156      Entry to the minibuffer binds this variable to the value of
157      `minibuffer-help-form' (*note Minibuffer Misc::).
158
159  - Variable: prefix-help-command
160      This variable holds a function to print help for a prefix
161      character.  The function is called when the user types a prefix
162      key followed by the help character, and the help character has no
163      binding after that prefix.  The variable's default value is
164      `describe-prefix-bindings'.
165
166  - Command: describe-prefix-bindings
167      This function calls `describe-bindings' to display a list of all
168      the subcommands of the prefix key of the most recent key sequence.
169      The prefix described consists of all but the last event of that
170      key sequence.  (The last event is, presumably, the help character.)
171
172    The following two functions are found in the library `helper'.  They
173 are for modes that want to provide help without relinquishing control,
174 such as the "electric" modes.  You must load that library with
175 `(require 'helper)' in order to use them.  Their names begin with
176 `Helper' to distinguish them from the ordinary help functions.
177
178  - Command: Helper-describe-bindings
179      This command pops up a window displaying a help buffer containing a
180      listing of all of the key bindings from both the local and global
181      keymaps.  It works by calling `describe-bindings'.
182
183  - Command: Helper-help
184      This command provides help for the current mode.  It prompts the
185      user in the minibuffer with the message `Help (Type ? for further
186      options)', and then provides assistance in finding out what the key
187      bindings are, and what the mode is intended for.  It returns `nil'.
188
189      This can be customized by changing the map `Helper-help-map'.
190
191 \1f
192 File: lispref.info,  Node: Obsoleteness,  Prev: Help Functions,  Up: Documentation
193
194 Obsoleteness
195 ============
196
197    As you add functionality to a package, you may at times want to
198 replace an older function with a new one.  To preserve compatibility
199 with existing code, the older function needs to still exist; but users
200 of that function should be told to use the newer one instead.  XEmacs
201 Lisp lets you mark a function or variable as "obsolete", and indicate
202 what should be used instead.
203
204  - Command: make-obsolete function new
205      This function indicates that FUNCTION is an obsolete function, and
206      the function NEW should be used instead.  The byte compiler will
207      issue a warning to this effect when it encounters a usage of the
208      older function, and the help system will also note this in the
209      function's documentation.  NEW can also be a string (if there is
210      not a single function with the same functionality any more), and
211      should be a descriptive statement, such as "use FOO or BAR
212      instead" or "this function is unnecessary".
213
214  - Command: make-obsolete-variable variable new
215      This is like `make-obsolete' but is for variables instead of
216      functions.
217
218  - Function: define-obsolete-function-alias oldfun newfun
219      This function combines `make-obsolete' and `define-function',
220      declaring OLDFUN to be an obsolete variant of NEWFUN and defining
221      OLDFUN as an alias for NEWFUN.
222
223  - Function: define-obsolete-variable-alias oldvar newvar
224      This is like `define-obsolete-function-alias' but for variables.
225
226    Note that you should not normally put obsoleteness information
227 explicitly in a function or variable's doc string.  The obsoleteness
228 information that you specify using the above functions will be displayed
229 whenever the doc string is displayed, and by adding it explicitly the
230 result is redundancy.
231
232    Also, if an obsolete function is substantially the same as a newer
233 one but is not actually an alias, you should consider omitting the doc
234 string entirely (use a null string `""' as the doc string).  That way,
235 the user is told about the obsoleteness and is forced to look at the
236 documentation of the new function, making it more likely that he will
237 use the new function.
238
239  - Function: function-obsoleteness-doc function
240      If FUNCTION is obsolete, this function returns a string describing
241      this.  This is the message that is printed out during byte
242      compilation or in the function's documentation.  If FUNCTION is
243      not obsolete, `nil' is returned.
244
245  - Function: variable-obsoleteness-doc variable
246      This is like `function-obsoleteness-doc' but for variables.
247
248    The obsoleteness information is stored internally by putting a
249 property `byte-obsolete-info' (for functions) or
250 `byte-obsolete-variable' (for variables) on the symbol that specifies
251 the obsolete function or variable.  For more information, see the
252 implementation of `make-obsolete' and `make-obsolete-variable' in
253 `lisp/bytecomp/bytecomp-runtime.el'.
254
255 \1f
256 File: lispref.info,  Node: Files,  Next: Backups and Auto-Saving,  Prev: Documentation,  Up: Top
257
258 Files
259 *****
260
261    In XEmacs, you can find, create, view, save, and otherwise work with
262 files and file directories.  This chapter describes most of the
263 file-related functions of XEmacs Lisp, but a few others are described in
264 *Note Buffers::, and those related to backups and auto-saving are
265 described in *Note Backups and Auto-Saving::.
266
267    Many of the file functions take one or more arguments that are file
268 names.  A file name is actually a string.  Most of these functions
269 expand file name arguments using `expand-file-name', so that `~' is
270 handled correctly, as are relative file names (including `../').  These
271 functions don't recognize environment variable substitutions such as
272 `$HOME'.  *Note File Name Expansion::.
273
274 * Menu:
275
276 * Visiting Files::           Reading files into Emacs buffers for editing.
277 * Saving Buffers::           Writing changed buffers back into files.
278 * Reading from Files::       Reading files into buffers without visiting.
279 * Writing to Files::         Writing new files from parts of buffers.
280 * File Locks::               Locking and unlocking files, to prevent
281                                simultaneous editing by two people.
282 * Information about Files::  Testing existence, accessibility, size of files.
283 * Changing File Attributes:: Renaming files, changing protection, etc.
284 * File Names::               Decomposing and expanding file names.
285 * Contents of Directories::  Getting a list of the files in a directory.
286 * Create/Delete Dirs::       Creating and Deleting Directories.
287 * Magic File Names::         Defining "magic" special handling
288                                for certain file names.
289 * Partial Files::            Treating a section of a buffer as a file.
290 * Format Conversion::        Conversion to and from various file formats.
291 * Files and MS-DOS::         Distinguishing text and binary files on MS-DOS.
292
293 \1f
294 File: lispref.info,  Node: Visiting Files,  Next: Saving Buffers,  Up: Files
295
296 Visiting Files
297 ==============
298
299    Visiting a file means reading a file into a buffer.  Once this is
300 done, we say that the buffer is "visiting" that file, and call the file
301 "the visited file" of the buffer.
302
303    A file and a buffer are two different things.  A file is information
304 recorded permanently in the computer (unless you delete it).  A buffer,
305 on the other hand, is information inside of XEmacs that will vanish at
306 the end of the editing session (or when you kill the buffer).  Usually,
307 a buffer contains information that you have copied from a file; then we
308 say the buffer is visiting that file.  The copy in the buffer is what
309 you modify with editing commands.  Such changes to the buffer do not
310 change the file; therefore, to make the changes permanent, you must
311 "save" the buffer, which means copying the altered buffer contents back
312 into the file.
313
314    In spite of the distinction between files and buffers, people often
315 refer to a file when they mean a buffer and vice-versa.  Indeed, we say,
316 "I am editing a file," rather than, "I am editing a buffer that I will
317 soon save as a file of the same name."  Humans do not usually need to
318 make the distinction explicit.  When dealing with a computer program,
319 however, it is good to keep the distinction in mind.
320
321 * Menu:
322
323 * Visiting Functions::         The usual interface functions for visiting.
324 * Subroutines of Visiting::    Lower-level subroutines that they use.
325
326 \1f
327 File: lispref.info,  Node: Visiting Functions,  Next: Subroutines of Visiting,  Up: Visiting Files
328
329 Functions for Visiting Files
330 ----------------------------
331
332    This section describes the functions normally used to visit files.
333 For historical reasons, these functions have names starting with
334 `find-' rather than `visit-'.  *Note Buffer File Name::, for functions
335 and variables that access the visited file name of a buffer or that
336 find an existing buffer by its visited file name.
337
338    In a Lisp program, if you want to look at the contents of a file but
339 not alter it, the fastest way is to use `insert-file-contents' in a
340 temporary buffer.  Visiting the file is not necessary and takes longer.
341 *Note Reading from Files::.
342
343  - Command: find-file filename
344      This command selects a buffer visiting the file FILENAME, using an
345      existing buffer if there is one, and otherwise creating a new
346      buffer and reading the file into it.  It also returns that buffer.
347
348      The body of the `find-file' function is very simple and looks like
349      this:
350
351           (switch-to-buffer (find-file-noselect filename))
352
353      (See `switch-to-buffer' in *Note Displaying Buffers::.)
354
355      When `find-file' is called interactively, it prompts for FILENAME
356      in the minibuffer.
357
358  - Function: find-file-noselect filename &optional nowarn
359      This function is the guts of all the file-visiting functions.  It
360      finds or creates a buffer visiting the file FILENAME, and returns
361      it.  It uses an existing buffer if there is one, and otherwise
362      creates a new buffer and reads the file into it.  You may make the
363      buffer current or display it in a window if you wish, but this
364      function does not do so.
365
366      When `find-file-noselect' uses an existing buffer, it first
367      verifies that the file has not changed since it was last visited or
368      saved in that buffer.  If the file has changed, then this function
369      asks the user whether to reread the changed file.  If the user says
370      `yes', any changes previously made in the buffer are lost.
371
372      If `find-file-noselect' needs to create a buffer, and there is no
373      file named FILENAME, it displays the message `New file' in the
374      echo area, and leaves the buffer empty.
375
376      If NOWARN is non-`nil', various warnings that XEmacs normally
377      gives (e.g. if another buffer is already visiting FILENAME but
378      FILENAME has been removed from disk since that buffer was created)
379      are suppressed.
380
381      The `find-file-noselect' function calls `after-find-file' after
382      reading the file (*note Subroutines of Visiting::).  That function
383      sets the buffer major mode, parses local variables, warns the user
384      if there exists an auto-save file more recent than the file just
385      visited, and finishes by running the functions in
386      `find-file-hooks'.
387
388      The `find-file-noselect' function returns the buffer that is
389      visiting the file FILENAME.
390
391           (find-file-noselect "/etc/fstab")
392                => #<buffer fstab>
393
394  - Command: find-file-other-window filename
395      This command selects a buffer visiting the file FILENAME, but does
396      so in a window other than the selected window.  It may use another
397      existing window or split a window; see *Note Displaying Buffers::.
398
399      When this command is called interactively, it prompts for FILENAME.
400
401  - Command: find-file-read-only filename
402      This command selects a buffer visiting the file FILENAME, like
403      `find-file', but it marks the buffer as read-only.  *Note Read
404      Only Buffers::, for related functions and variables.
405
406      When this command is called interactively, it prompts for FILENAME.
407
408  - Command: view-file filename &optional other-window-p
409      This command visits FILENAME in View mode, and displays it in a
410      recursive edit, returning to the previous buffer when done.  View
411      mode is a mode that allows you to skim rapidly through the file
412      but does not let you modify it.  Entering View mode runs the
413      normal hook `view-mode-hook'.  *Note Hooks::.
414
415      When `view-file' is called interactively, it prompts for FILENAME.
416
417      With non-`nil' prefix arg OTHER-WINDOW-P, visit FILENAME in
418      another window.
419
420  - Variable: find-file-hooks
421      The value of this variable is a list of functions to be called
422      after a file is visited.  The file's local-variables specification
423      (if any) will have been processed before the hooks are run.  The
424      buffer visiting the file is current when the hook functions are
425      run.
426
427      This variable works just like a normal hook, but we think that
428      renaming it would not be advisable.
429
430  - Variable: find-file-not-found-hooks
431      The value of this variable is a list of functions to be called when
432      `find-file' or `find-file-noselect' is passed a nonexistent file
433      name.  `find-file-noselect' calls these functions as soon as it
434      detects a nonexistent file.  It calls them in the order of the
435      list, until one of them returns non-`nil'.  `buffer-file-name' is
436      already set up.
437
438      This is not a normal hook because the values of the functions are
439      used and they may not all be called.
440
441 \1f
442 File: lispref.info,  Node: Subroutines of Visiting,  Prev: Visiting Functions,  Up: Visiting Files
443
444 Subroutines of Visiting
445 -----------------------
446
447    The `find-file-noselect' function uses the `create-file-buffer' and
448 `after-find-file' functions as subroutines.  Sometimes it is useful to
449 call them directly.
450
451  - Function: create-file-buffer filename
452      This function creates a suitably named buffer for visiting
453      FILENAME, and returns it.  It uses FILENAME (sans directory) as
454      the name if that name is free; otherwise, it appends a string such
455      as `<2>' to get an unused name.  See also *Note Creating Buffers::.
456
457      *Please note:* `create-file-buffer' does _not_ associate the new
458      buffer with a file and does not select the buffer.  It also does
459      not use the default major mode.
460
461           (create-file-buffer "foo")
462                => #<buffer foo>
463           (create-file-buffer "foo")
464                => #<buffer foo<2>>
465           (create-file-buffer "foo")
466                => #<buffer foo<3>>
467
468      This function is used by `find-file-noselect'.  It uses
469      `generate-new-buffer' (*note Creating Buffers::).
470
471  - Function: after-find-file &optional error warn noauto
472      This function sets the buffer major mode, and parses local
473      variables (*note Auto Major Mode::).  It is called by
474      `find-file-noselect' and by the default revert function (*note
475      Reverting::).
476
477      If reading the file got an error because the file does not exist,
478      but its directory does exist, the caller should pass a non-`nil'
479      value for ERROR.  In that case, `after-find-file' issues a warning:
480      `(New File)'.  For more serious errors, the caller should usually
481      not call `after-find-file'.
482
483      If WARN is non-`nil', then this function issues a warning if an
484      auto-save file exists and is more recent than the visited file.
485
486      If NOAUTO is non-`nil', then this function does not turn on
487      auto-save mode; otherwise, it does.
488
489      The last thing `after-find-file' does is call all the functions in
490      `find-file-hooks'.
491
492 \1f
493 File: lispref.info,  Node: Saving Buffers,  Next: Reading from Files,  Prev: Visiting Files,  Up: Files
494
495 Saving Buffers
496 ==============
497
498    When you edit a file in XEmacs, you are actually working on a buffer
499 that is visiting that file--that is, the contents of the file are
500 copied into the buffer and the copy is what you edit.  Changes to the
501 buffer do not change the file until you "save" the buffer, which means
502 copying the contents of the buffer into the file.
503
504  - Command: save-buffer &optional backup-option
505      This function saves the contents of the current buffer in its
506      visited file if the buffer has been modified since it was last
507      visited or saved.  Otherwise it does nothing.
508
509      `save-buffer' is responsible for making backup files.  Normally,
510      BACKUP-OPTION is `nil', and `save-buffer' makes a backup file only
511      if this is the first save since visiting the file.  Other values
512      for BACKUP-OPTION request the making of backup files in other
513      circumstances:
514
515         * With an argument of 4 or 64, reflecting 1 or 3 `C-u''s, the
516           `save-buffer' function marks this version of the file to be
517           backed up when the buffer is next saved.
518
519         * With an argument of 16 or 64, reflecting 2 or 3 `C-u''s, the
520           `save-buffer' function unconditionally backs up the previous
521           version of the file before saving it.
522
523  - Command: save-some-buffers &optional save-silently-p exiting
524      This command saves some modified file-visiting buffers.  Normally
525      it asks the user about each buffer.  But if SAVE-SILENTLY-P is
526      non-`nil', it saves all the file-visiting buffers without querying
527      the user.
528
529      The optional EXITING argument, if non-`nil', requests this
530      function to offer also to save certain other buffers that are not
531      visiting files.  These are buffers that have a non-`nil' local
532      value of `buffer-offer-save'.  (A user who says yes to saving one
533      of these is asked to specify a file name to use.)  The
534      `save-buffers-kill-emacs' function passes a non-`nil' value for
535      this argument.
536
537  - Variable: buffer-offer-save
538      When this variable is non-`nil' in a buffer, XEmacs offers to save
539      the buffer on exit even if the buffer is not visiting a file.  The
540      variable is automatically local in all buffers.  Normally, Mail
541      mode (used for editing outgoing mail) sets this to `t'.
542
543  - Command: write-file filename
544      This function writes the current buffer into file FILENAME, makes
545      the buffer visit that file, and marks it not modified.  Then it
546      renames the buffer based on FILENAME, appending a string like `<2>'
547      if necessary to make a unique buffer name.  It does most of this
548      work by calling `set-visited-file-name' and `save-buffer'.
549
550  - Variable: write-file-hooks
551      The value of this variable is a list of functions to be called
552      before writing out a buffer to its visited file.  If one of them
553      returns non-`nil', the file is considered already written and the
554      rest of the functions are not called, nor is the usual code for
555      writing the file executed.
556
557      If a function in `write-file-hooks' returns non-`nil', it is
558      responsible for making a backup file (if that is appropriate).  To
559      do so, execute the following code:
560
561           (or buffer-backed-up (backup-buffer))
562
563      You might wish to save the file modes value returned by
564      `backup-buffer' and use that to set the mode bits of the file that
565      you write.  This is what `save-buffer' normally does.
566
567      Even though this is not a normal hook, you can use `add-hook' and
568      `remove-hook' to manipulate the list.  *Note Hooks::.
569
570  - Variable: local-write-file-hooks
571      This works just like `write-file-hooks', but it is intended to be
572      made local to particular buffers.  It's not a good idea to make
573      `write-file-hooks' local to a buffer--use this variable instead.
574
575      The variable is marked as a permanent local, so that changing the
576      major mode does not alter a buffer-local value.  This is
577      convenient for packages that read "file" contents in special ways,
578      and set up hooks to save the data in a corresponding way.
579
580  - Variable: write-contents-hooks
581      This works just like `write-file-hooks', but it is intended for
582      hooks that pertain to the contents of the file, as opposed to
583      hooks that pertain to where the file came from.  Such hooks are
584      usually set up by major modes, as buffer-local bindings for this
585      variable.  Switching to a new major mode always resets this
586      variable.
587
588  - Variable: after-save-hook
589      This normal hook runs after a buffer has been saved in its visited
590      file.
591
592  - Variable: file-precious-flag
593      If this variable is non-`nil', then `save-buffer' protects against
594      I/O errors while saving by writing the new file to a temporary
595      name instead of the name it is supposed to have, and then renaming
596      it to the intended name after it is clear there are no errors.
597      This procedure prevents problems such as a lack of disk space from
598      resulting in an invalid file.
599
600      As a side effect, backups are necessarily made by copying.  *Note
601      Rename or Copy::.  Yet, at the same time, saving a precious file
602      always breaks all hard links between the file you save and other
603      file names.
604
605      Some modes set this variable non-`nil' locally in particular
606      buffers.
607
608  - User Option: require-final-newline
609      This variable determines whether files may be written out that do
610      _not_ end with a newline.  If the value of the variable is `t',
611      then `save-buffer' silently adds a newline at the end of the file
612      whenever the buffer being saved does not already end in one.  If
613      the value of the variable is non-`nil', but not `t', then
614      `save-buffer' asks the user whether to add a newline each time the
615      case arises.
616
617      If the value of the variable is `nil', then `save-buffer' doesn't
618      add newlines at all.  `nil' is the default value, but a few major
619      modes set it to `t' in particular buffers.
620
621 \1f
622 File: lispref.info,  Node: Reading from Files,  Next: Writing to Files,  Prev: Saving Buffers,  Up: Files
623
624 Reading from Files
625 ==================
626
627    You can copy a file from the disk and insert it into a buffer using
628 the `insert-file-contents' function.  Don't use the user-level command
629 `insert-file' in a Lisp program, as that sets the mark.
630
631  - Function: insert-file-contents filename &optional visit start end
632           replace
633      This function inserts the contents of file FILENAME into the
634      current buffer after point.  It returns a list of the absolute
635      file name and the length of the data inserted.  An error is
636      signaled if FILENAME is not the name of a file that can be read.
637
638      The function `insert-file-contents' checks the file contents
639      against the defined file formats, and converts the file contents if
640      appropriate.  *Note Format Conversion::.  It also calls the
641      functions in the list `after-insert-file-functions'; see *Note
642      Saving Properties::.
643
644      If VISIT is non-`nil', this function additionally marks the buffer
645      as unmodified and sets up various fields in the buffer so that it
646      is visiting the file FILENAME: these include the buffer's visited
647      file name and its last save file modtime.  This feature is used by
648      `find-file-noselect' and you probably should not use it yourself.
649
650      If START and END are non-`nil', they should be integers specifying
651      the portion of the file to insert.  In this case, VISIT must be
652      `nil'.  For example,
653
654           (insert-file-contents filename nil 0 500)
655
656      inserts the first 500 characters of a file.
657
658      If the argument REPLACE is non-`nil', it means to replace the
659      contents of the buffer (actually, just the accessible portion)
660      with the contents of the file.  This is better than simply
661      deleting the buffer contents and inserting the whole file, because
662      (1) it preserves some marker positions and (2) it puts less data
663      in the undo list.
664
665    If you want to pass a file name to another process so that another
666 program can read the file, use the function `file-local-copy'; see
667 *Note Magic File Names::.
668
669 \1f
670 File: lispref.info,  Node: Writing to Files,  Next: File Locks,  Prev: Reading from Files,  Up: Files
671
672 Writing to Files
673 ================
674
675    You can write the contents of a buffer, or part of a buffer, directly
676 to a file on disk using the `append-to-file' and `write-region'
677 functions.  Don't use these functions to write to files that are being
678 visited; that could cause confusion in the mechanisms for visiting.
679
680  - Command: append-to-file start end filename
681      This function appends the contents of the region delimited by
682      START and END in the current buffer to the end of file FILENAME.
683      If that file does not exist, it is created.  If that file exists
684      it is overwritten.  This function returns `nil'.
685
686      An error is signaled if FILENAME specifies a nonwritable file, or
687      a nonexistent file in a directory where files cannot be created.
688
689  - Command: write-region start end filename &optional append visit
690      This function writes the region delimited by START and END in the
691      current buffer into the file specified by FILENAME.
692
693      If START is a string, then `write-region' writes or appends that
694      string, rather than text from the buffer.
695
696      If APPEND is non-`nil', then the specified text is appended to the
697      existing file contents (if any).
698
699      If VISIT is `t', then XEmacs establishes an association between
700      the buffer and the file: the buffer is then visiting that file.
701      It also sets the last file modification time for the current
702      buffer to FILENAME's modtime, and marks the buffer as not
703      modified.  This feature is used by `save-buffer', but you probably
704      should not use it yourself.
705
706      If VISIT is a string, it specifies the file name to visit.  This
707      way, you can write the data to one file (FILENAME) while recording
708      the buffer as visiting another file (VISIT).  The argument VISIT
709      is used in the echo area message and also for file locking; VISIT
710      is stored in `buffer-file-name'.  This feature is used to
711      implement `file-precious-flag'; don't use it yourself unless you
712      really know what you're doing.
713
714      The function `write-region' converts the data which it writes to
715      the appropriate file formats specified by `buffer-file-format'.
716      *Note Format Conversion::.  It also calls the functions in the list
717      `write-region-annotate-functions'; see *Note Saving Properties::.
718
719      Normally, `write-region' displays a message `Wrote file FILENAME'
720      in the echo area.  If VISIT is neither `t' nor `nil' nor a string,
721      then this message is inhibited.  This feature is useful for
722      programs that use files for internal purposes, files that the user
723      does not need to know about.
724
725 \1f
726 File: lispref.info,  Node: File Locks,  Next: Information about Files,  Prev: Writing to Files,  Up: Files
727
728 File Locks
729 ==========
730
731    When two users edit the same file at the same time, they are likely
732 to interfere with each other.  XEmacs tries to prevent this situation
733 from arising by recording a "file lock" when a file is being modified.
734 XEmacs can then detect the first attempt to modify a buffer visiting a
735 file that is locked by another XEmacs process, and ask the user what to
736 do.
737
738    File locks do not work properly when multiple machines can share
739 file systems, such as with NFS.  Perhaps a better file locking system
740 will be implemented in the future.  When file locks do not work, it is
741 possible for two users to make changes simultaneously, but XEmacs can
742 still warn the user who saves second.  Also, the detection of
743 modification of a buffer visiting a file changed on disk catches some
744 cases of simultaneous editing; see *Note Modification Time::.
745
746  - Function: file-locked-p &optional filename
747      This function returns `nil' if the file FILENAME is not locked by
748      this XEmacs process.  It returns `t' if it is locked by this
749      XEmacs, and it returns the name of the user who has locked it if it
750      is locked by someone else.
751
752           (file-locked-p "foo")
753                => nil
754
755  - Function: lock-buffer &optional filename
756      This function locks the file FILENAME, if the current buffer is
757      modified.  The argument FILENAME defaults to the current buffer's
758      visited file.  Nothing is done if the current buffer is not
759      visiting a file, or is not modified.
760
761  - Function: unlock-buffer
762      This function unlocks the file being visited in the current buffer,
763      if the buffer is modified.  If the buffer is not modified, then
764      the file should not be locked, so this function does nothing.  It
765      also does nothing if the current buffer is not visiting a file.
766
767  - Function: ask-user-about-lock filename other-user
768      This function is called when the user tries to modify FILENAME,
769      but it is locked by another user named OTHER-USER.  The value it
770      returns determines what happens next:
771
772         * A value of `t' says to grab the lock on the file.  Then this
773           user may edit the file and OTHER-USER loses the lock.
774
775         * A value of `nil' says to ignore the lock and let this user
776           edit the file anyway.
777
778         * This function may instead signal a `file-locked' error, in
779           which case the change that the user was about to make does
780           not take place.
781
782           The error message for this error looks like this:
783
784                error--> File is locked: FILENAME OTHER-USER
785
786           where FILENAME is the name of the file and OTHER-USER is the
787           name of the user who has locked the file.
788
789      The default definition of this function asks the user to choose
790      what to do.  If you wish, you can replace the `ask-user-about-lock'
791      function with your own version that decides in another way.  The
792      code for its usual definition is in `userlock.el'.
793
794 \1f
795 File: lispref.info,  Node: Information about Files,  Next: Changing File Attributes,  Prev: File Locks,  Up: Files
796
797 Information about Files
798 =======================
799
800    The functions described in this section all operate on strings that
801 designate file names.  All the functions have names that begin with the
802 word `file'.  These functions all return information about actual files
803 or directories, so their arguments must all exist as actual files or
804 directories unless otherwise noted.
805
806 * Menu:
807
808 * Testing Accessibility::   Is a given file readable?  Writable?
809 * Kinds of Files::          Is it a directory?  A symbolic link?
810 * Truenames::               Eliminating symbolic links from a file name.
811 * File Attributes::         How large is it?  Any other names?  Etc.
812
813 \1f
814 File: lispref.info,  Node: Testing Accessibility,  Next: Kinds of Files,  Up: Information about Files
815
816 Testing Accessibility
817 ---------------------
818
819    These functions test for permission to access a file in specific
820 ways.
821
822  - Function: file-exists-p filename
823      This function returns `t' if a file named FILENAME appears to
824      exist.  This does not mean you can necessarily read the file, only
825      that you can find out its attributes.  (On Unix, this is true if
826      the file exists and you have execute permission on the containing
827      directories, regardless of the protection of the file itself.)
828
829      If the file does not exist, or if fascist access control policies
830      prevent you from finding the attributes of the file, this function
831      returns `nil'.
832
833  - Function: file-readable-p filename
834      This function returns `t' if a file named FILENAME exists and you
835      can read it.  It returns `nil' otherwise.
836
837           (file-readable-p "files.texi")
838                => t
839           (file-exists-p "/usr/spool/mqueue")
840                => t
841           (file-readable-p "/usr/spool/mqueue")
842                => nil
843
844  - Function: file-executable-p filename
845      This function returns `t' if a file named FILENAME exists and you
846      can execute it.  It returns `nil' otherwise.  If the file is a
847      directory, execute permission means you can check the existence and
848      attributes of files inside the directory, and open those files if
849      their modes permit.
850
851  - Function: file-writable-p filename
852      This function returns `t' if the file FILENAME can be written or
853      created by you, and `nil' otherwise.  A file is writable if the
854      file exists and you can write it.  It is creatable if it does not
855      exist, but the specified directory does exist and you can write in
856      that directory.
857
858      In the third example below, `foo' is not writable because the
859      parent directory does not exist, even though the user could create
860      such a directory.
861
862           (file-writable-p "~/foo")
863                => t
864           (file-writable-p "/foo")
865                => nil
866           (file-writable-p "~/no-such-dir/foo")
867                => nil
868
869  - Function: file-accessible-directory-p dirname
870      This function returns `t' if you have permission to open existing
871      files in the directory whose name as a file is DIRNAME; otherwise
872      (or if there is no such directory), it returns `nil'.  The value
873      of DIRNAME may be either a directory name or the file name of a
874      directory.
875
876      Example: after the following,
877
878           (file-accessible-directory-p "/foo")
879                => nil
880
881      we can deduce that any attempt to read a file in `/foo/' will give
882      an error.
883
884  - Function: file-ownership-preserved-p filename
885      This function returns `t' if deleting the file FILENAME and then
886      creating it anew would keep the file's owner unchanged.
887
888  - Function: file-newer-than-file-p filename1 filename2
889      This function returns `t' if the file FILENAME1 is newer than file
890      FILENAME2.  If FILENAME1 does not exist, it returns `nil'.  If
891      FILENAME2 does not exist, it returns `t'.
892
893      In the following example, assume that the file `aug-19' was written
894      on the 19th, `aug-20' was written on the 20th, and the file
895      `no-file' doesn't exist at all.
896
897           (file-newer-than-file-p "aug-19" "aug-20")
898                => nil
899           (file-newer-than-file-p "aug-20" "aug-19")
900                => t
901           (file-newer-than-file-p "aug-19" "no-file")
902                => t
903           (file-newer-than-file-p "no-file" "aug-19")
904                => nil
905
906      You can use `file-attributes' to get a file's last modification
907      time as a list of two numbers.  *Note File Attributes::.
908
909 \1f
910 File: lispref.info,  Node: Kinds of Files,  Next: Truenames,  Prev: Testing Accessibility,  Up: Information about Files
911
912 Distinguishing Kinds of Files
913 -----------------------------
914
915    This section describes how to distinguish various kinds of files,
916 such as directories, symbolic links, and ordinary files.
917
918  - Function: file-symlink-p filename
919      If the file FILENAME is a symbolic link, the `file-symlink-p'
920      function returns the file name to which it is linked.  This may be
921      the name of a text file, a directory, or even another symbolic
922      link, or it may be a nonexistent file name.
923
924      If the file FILENAME is not a symbolic link (or there is no such
925      file), `file-symlink-p' returns `nil'.
926
927           (file-symlink-p "foo")
928                => nil
929           (file-symlink-p "sym-link")
930                => "foo"
931           (file-symlink-p "sym-link2")
932                => "sym-link"
933           (file-symlink-p "/bin")
934                => "/pub/bin"
935
936
937  - Function: file-directory-p filename
938      This function returns `t' if FILENAME is the name of an existing
939      directory, `nil' otherwise.
940
941           (file-directory-p "~rms")
942                => t
943           (file-directory-p "~rms/lewis/files.texi")
944                => nil
945           (file-directory-p "~rms/lewis/no-such-file")
946                => nil
947           (file-directory-p "$HOME")
948                => nil
949           (file-directory-p
950            (substitute-in-file-name "$HOME"))
951                => t
952
953  - Function: file-regular-p filename
954      This function returns `t' if the file FILENAME exists and is a
955      regular file (not a directory, symbolic link, named pipe,
956      terminal, or other I/O device).
957
958 \1f
959 File: lispref.info,  Node: Truenames,  Next: File Attributes,  Prev: Kinds of Files,  Up: Information about Files
960
961 Truenames
962 ---------
963
964    The "truename" of a file is the name that you get by following
965 symbolic links until none remain, then expanding to get rid of `.' and
966 `..' as components.  Strictly speaking, a file need not have a unique
967 truename; the number of distinct truenames a file has is equal to the
968 number of hard links to the file.  However, truenames are useful
969 because they eliminate symbolic links as a cause of name variation.
970
971  - Function: file-truename filename &optional default
972      The function `file-truename' returns the true name of the file
973      FILENAME.  This is the name that you get by following symbolic
974      links until none remain.
975
976      If the filename is relative, DEFAULT is the directory to start
977      with.  If DEFAULT is `nil' or missing, the current buffer's value
978      of `default-directory' is used.
979
980    *Note Buffer File Name::, for related information.
981
982 \1f
983 File: lispref.info,  Node: File Attributes,  Prev: Truenames,  Up: Information about Files
984
985 Other Information about Files
986 -----------------------------
987
988    This section describes the functions for getting detailed information
989 about a file, other than its contents.  This information includes the
990 mode bits that control access permission, the owner and group numbers,
991 the number of names, the inode number, the size, and the times of access
992 and modification.
993
994  - Function: file-modes filename
995      This function returns the mode bits of FILENAME, as an integer.
996      The mode bits are also called the file permissions, and they
997      specify access control in the usual Unix fashion.  If the
998      low-order bit is 1, then the file is executable by all users, if
999      the second-lowest-order bit is 1, then the file is writable by all
1000      users, etc.
1001
1002      The highest value returnable is 4095 (7777 octal), meaning that
1003      everyone has read, write, and execute permission, that the SUID bit
1004      is set for both others and group, and that the sticky bit is set.
1005
1006           (file-modes "~/junk/diffs")
1007                => 492               ; Decimal integer.
1008           (format "%o" 492)
1009                => "754"             ; Convert to octal.
1010           
1011           (set-file-modes "~/junk/diffs" 438)
1012                => nil
1013           
1014           (format "%o" 438)
1015                => "666"             ; Convert to octal.
1016           
1017           % ls -l diffs
1018             -rw-rw-rw-  1 lewis 0 3063 Oct 30 16:00 diffs
1019
1020  - Function: file-nlinks filename
1021      This functions returns the number of names (i.e., hard links) that
1022      file FILENAME has.  If the file does not exist, then this function
1023      returns `nil'.  Note that symbolic links have no effect on this
1024      function, because they are not considered to be names of the files
1025      they link to.
1026
1027           % ls -l foo*
1028           -rw-rw-rw-  2 rms       4 Aug 19 01:27 foo
1029           -rw-rw-rw-  2 rms       4 Aug 19 01:27 foo1
1030           
1031           (file-nlinks "foo")
1032                => 2
1033           (file-nlinks "doesnt-exist")
1034                => nil
1035
1036  - Function: file-attributes filename
1037      This function returns a list of attributes of file FILENAME.  If
1038      the specified file cannot be opened, it returns `nil'.
1039
1040      The elements of the list, in order, are:
1041
1042        0. `t' for a directory, a string for a symbolic link (the name
1043           linked to), or `nil' for a text file.
1044
1045        1. The number of names the file has.  Alternate names, also
1046           known as hard links, can be created by using the
1047           `add-name-to-file' function (*note Changing File
1048           Attributes::).
1049
1050        2. The file's UID.
1051
1052        3. The file's GID.
1053
1054        4. The time of last access, as a list of two integers.  The
1055           first integer has the high-order 16 bits of time, the second
1056           has the low 16 bits.  (This is similar to the value of
1057           `current-time'; see *Note Time of Day::.)
1058
1059        5. The time of last modification as a list of two integers (as
1060           above).
1061
1062        6. The time of last status change as a list of two integers (as
1063           above).
1064
1065        7. The size of the file in bytes.
1066
1067        8. The file's modes, as a string of ten letters or dashes, as in
1068           `ls -l'.
1069
1070        9. `t' if the file's GID would change if file were deleted and
1071           recreated; `nil' otherwise.
1072
1073       10. The file's inode number.
1074
1075       11. The file system number of the file system that the file is
1076           in.  This element and the file's inode number together give
1077           enough information to distinguish any two files on the
1078           system--no two files can have the same values for both of
1079           these numbers.
1080
1081      For example, here are the file attributes for `files.texi':
1082
1083           (file-attributes "files.texi")
1084                =>  (nil
1085                     1
1086                     2235
1087                     75
1088                     (8489 20284)
1089                     (8489 20284)
1090                     (8489 20285)
1091                     14906
1092                     "-rw-rw-rw-"
1093                     nil
1094                     129500
1095                     -32252)
1096
1097      and here is how the result is interpreted:
1098
1099     `nil'
1100           is neither a directory nor a symbolic link.
1101
1102     `1'
1103           has only one name (the name `files.texi' in the current
1104           default directory).
1105
1106     `2235'
1107           is owned by the user with UID 2235.
1108
1109     `75'
1110           is in the group with GID 75.
1111
1112     `(8489 20284)'
1113           was last accessed on Aug 19 00:09. Use `format-time-string' to
1114           ! convert this number into a time string.  *Note Time
1115           Conversion::.
1116
1117     `(8489 20284)'
1118           was last modified on Aug 19 00:09.
1119
1120     `(8489 20285)'
1121           last had its inode changed on Aug 19 00:09.
1122
1123     `14906'
1124           is 14906 characters long.
1125
1126     `"-rw-rw-rw-"'
1127           has a mode of read and write access for the owner, group, and
1128           world.
1129
1130     `nil'
1131           would retain the same GID if it were recreated.
1132
1133     `129500'
1134           has an inode number of 129500.
1135
1136     `-32252'
1137           is on file system number -32252.
1138