3.3 Files

  • 3.3.1 Auto Save Mode
  • 3.3.2 Filename Defaulting and Merging
  • 3.3.3 Type Hooks and File Options
  • These commands either read a file into the current buffer or write it out to some file. Various other bookkeeping operations are performed as well. [annotate]

    Find File  (bound to C-x C-f) [Command]
              

    This is the command normally used to get a file into Hemlock. It prompts for the name of a file, and if that file has already been read in, selects that buffer; otherwise, it reads file into a new buffer whose name is derived from the name of the file. If the file does not exist, then the buffer is left empty, and "(New File)" is displayed in the echo area; the file may then be created by saving the buffer. [annotate]

    The buffer name created is in the form "name type directory". This means that the filename "/sys/emacs/teco.mid" has "Teco Mid /Sys/Emacs/" as its the corresponding buffer name. The reason for rearranging the fields in this fashion is that it facilitates recognition since the components most likely to differ are placed first. If the buffer cannot be created because it already exists, but has another file in it (an unlikely occurrence), then the user is prompted for the buffer to use, as by Create Buffer. [annotate]

    Find File takes special action if the file has been modified on disk since it was read into Hemlock. This usually happens when several people are simultaneously editing a file, an unhealthy circumstance. If the buffer is unmodified, Find File just asks for confirmation before reading in the new version. If the buffer is modified, then Find File beeps and prompts for a single key-event to indicate what action to take. It recognizes the following key-events: [annotate]

    Return, Space, y
    Prompt for a file in which to save the current buffer and then read in the file found to be modified on disk. [annotate]
    Delete, Backspace, n
    Forego reading the file. [annotate]
    r
    Read the file found to be modified on disk into the buffer containing the earlier version with modifications. This loses all changes you had in the buffer. [annotate]

    [annotate]

    Save File  (bound to C-x C-s) [Command]
              

    This command writes the current buffer out to its associated file and resets the buffer modification flag. If there is no associated file, then the user is prompted for a file, which is made the associated file. If the buffer is not modified, then the user is asked whether to actually write it or not. [annotate]

    If the file has been modified on disk since the last time it was read, Save File prompts for confirmation before overwriting the file. [annotate]

    [annotate]

    Save All Files  (bound to C-x C-m) [Command]
    Save All Files and Exit  (bound to C-x M-z) [Command]
    Save All Files Confirm  (initial value t) [Variable]
              

    Save All Files does a Save File on all buffers which have an associated file. Save All Files and Exit does the same thing and then exits Hemlock. [annotate]

    When Save All Files Confirm is true, these commands will ask for confirmation before saving a file. [annotate]

    [annotate]

    Visit File  (bound to C-x C-v) [Command]
              

    This command prompts for a file and reads it into the current buffer, setting the associated filename. Since the old contents of the buffer are destroyed, the user is given a chance to save the buffer if it is modified. As for Find File, the file need not actually exist. This command warns if some other buffer also contains the file. [annotate]

    [annotate]

    Write File  (bound to C-x C-w) [Command]
              

    This command prompts for a file and writes the current buffer out to it, changing the associated filename and resetting the modification flag. When the buffer's associated file is specified this command does the same thing as Save File. [annotate]

    [annotate]

    Backup File   [Command]
              

    This command is similar to Write File, but it neither sets the associated filename nor clears the modification flag. This is useful for saving the current state somewhere else, perhaps on a reliable machine. [annotate]

    Since Backup File doesn't update the write date for the buffer, Find File and Save File will get all upset if you back up a buffer on any file that has been read into Hemlock. [annotate]

    [annotate]

    Revert File   [Command]
    Revert File Confirm  (initial value t) [Variable]
              

    This command replaces the text in the current buffer with the contents of the associated file or the checkpoint file for that file, whichever is more recent. The point is put in approximately the same place that it was before the file was read. If the original file is reverted to, then clear the modified flag, otherwise leave it set. If a prefix argument is specified, then always revert to the original file, ignoring any checkpoint file. [annotate]

    If the buffer is modified and Revert File Confirm is true, then the user is asked for confirmation. [annotate]

    [annotate]

    Insert File  (bound to C-x C-r) [Command]
              

    This command prompts for a file and inserts it at the point, pushing a buffer mark before inserting. [annotate]

    [annotate]

    Write Region   [Command]
              

    This command prompts for a file and writes the text in the region out to it. [annotate]

    [annotate]

    Add Newline at EOF on Writing File  (initial value :ask-user) [Variable]
              

    This variable controls whether some file writing commands add a newline at the end of the file if the last line is non-empty. [annotate]

    :ask-user
    Ask the user whether to add a newline. [annotate]
    t
    Automatically add a newline and inform the user. [annotate]
    nil
    Never add a newline and do not ask. [annotate]

    Some programs will lose the text on the last line or get an error when the last line does not have a newline at the end. [annotate]

    [annotate]

    Keep Backup Files  (initial value nil) [Variable]
              

    Whenever a file is written by Save File and similar commands, the old file is renamed by appending ".BAK" to the name, ensuring that some version of the file will survive a system crash during the write. If set to true, this backup file will not deleted even when the write successfully completes. [annotate]

    [annotate]

    3.3.1 Auto Save Mode

    Save mode protects against loss of work in system crashes by periodically saving modified buffers in checkpoint files. [annotate]

    Auto Save Mode   [Command]
              

    This command turns on Save mode if it is not on, and turns off when it is on. Save mode is on by default. [annotate]

    [annotate]

    Auto Save Checkpoint Frequency  (initial value 120) [Variable]
    Auto Save Key Count Threshold  (initial value 256) [Variable]
              

    These variables determine how often modified buffers in Save mode will be checkpointed. Checkpointing is done after Auto Save Checkpoint Frequency seconds, or after Auto Save Key Count Threshold keystrokes that modify the buffer (whichever comes first). Either kind of checkpointing may be disabled by setting the corresponding variable to nil. [annotate]

    [annotate]

    Auto Save Cleanup Checkpoints  (initial value t) [Variable]
              

    If this variable is true, then any checkpoint file for a buffer will be deleted when the buffer is successfully saved in its associated file. [annotate]

    [annotate]

    Auto Save Filename Pattern  (initial value "~A~A.CKP") [Variable]
    Auto Save Pathname Hook  (initial value make-unique-save-pathname) [Variable]
              

    These variables determine the naming of checkpoint files. Auto Save Filename Pattern is a format string used to name the checkpoint files for buffers with associated files. Format is called with two arguments: the directory and file namestrings of the associated file. [annotate]

    Auto Save Pathname Hook is a function called by Save mode to get a checkpoint pathname when there is no pathname associated with a buffer. It should take a buffer as its argument and return either a pathname or nil. If a pathname is returned, then it is used as the name of the checkpoint file. If the function returns nil, or if the hook variable is nil, then Save mode is turned off in the buffer. The default value for this variable returns a pathname in the default directory of the form "save-number", where number is a number used to make the file unique. [annotate]

    [annotate]

    3.3.2 Filename Defaulting and Merging

    When Hemlock prompts for the name of a file, it always offers a default. Except for a few commands that have their own defaults, filename defaults are computed in a standard way. If it exists, the associated file for the current buffer is used as the default, otherwise a more complex mechanism creates a default. [annotate]

    Pathname Defaults  (initial value (pathname "gazonk.del")) [Variable]
    Last Resort Pathname Defaults Function  (initial value ) [Variable]
    Last Resort Pathname Defaults  (initial value (pathname "gazonk")) [Variable]
              

    These variables control the computation of default filename defaults when the current buffer has no associated file. [annotate]

    Pathname Defaults holds a "sticky" filename default. Commands that prompt for files set this to the file specified, and the value is used as a basis for filename defaults. It is undesirable to offer the unmodified value as a default, since it is usually the name of an existing file that we don't want to overwrite. If the current buffer's name is all alphanumeric, then the default is computed by substituting the buffer name for the the name portion of Pathname Defaults. Otherwise, the default is computed by calling Last Resort Pathname Defaults Function with the buffer as an argument. [annotate]

    The default value of Last Resort Pathname Defaults Function merges Last Resort Pathname Defaults with Pathname Defaults. Unlike Pathname Defaults, Last Resort Pathname Defaults is not modified by file commands, so setting it to a silly name ensures that real files aren't inappropriately offered as defaults. [annotate]

    [annotate]

    When a default is present in the prompt for a file, Hemlock merges the given input with the default filename. The semantics of merging, described in the Common Lisp manual, is somewhat involved, but Hemlock has a few rules it uses: [annotate]

    1. If Hemlock can find the user's input as a file on the "default:" search list, then it forgoes merging with the displayed default. Basically, the system favors the files in your current working directory over those found by merging with the defaults offered in the prompt. [annotate]
    2. Merging comes in two flavors, just merge with the displayed default's directory or just merge with the displayed default's file-namestring. If the user only responds with a directory specification, without any name or type information, then Hemlock merges the default's file-namestring. If the user responds with any name or type information, then Hemlock only merges with the default's directory. Specifying relative directories in this second situation coordinates with the displayed defaults, not the current working directory. [annotate]

    3.3.3 Type Hooks and File Options

    When a file is read either by Find File or Visit File, Hemlock attempts to guess the correct mode in which to put the buffer, based on the file's type (the part of the filename after the last dot). Any default action may be overridden by specifying the mode in the file's file options. [annotate]

    The user specifies file options with a special syntax on the first line of a file. If the first line contains the string "-*-", then Hemlock interprets the text between the first such occurrence and the second, which must be contained in one line , as a list of "option: value" pairs separated by semicolons. The following is a typical example: ;;; -*- Mode: Lisp, Editor; Package: Hemlock -*- [annotate]

    These options are currently defined: [annotate]

    Dictionary
    The argument is the filename of a spelling dictionary associated with this file. The handler for this option merges the argument with the name of this file. See Set Buffer Spelling Dictionary. [annotate]
    Log
    The argument is the name of the change log file associated with this file (see page 5.3). The handler for this option merges the argument with the name of this file. [annotate]
    Mode
    The argument is a comma-separated list of the names of modes to turn on in the buffer that the file is read into. [annotate]
    Package
    The argument is the name of the package to be used for reading code in the file. This is only meaningful for Lisp code (see page 9.3.) [annotate]
    Editor
    The handler for this option ignores its argument and turns on Editor mode (see Editor Mode). [annotate]

    If the option list contains no ":" then the entire string is used as the name of the major mode for the buffer. [annotate]

    Process File Options   [Command]
              

    This command processes the file options in the current buffer as described above. This is useful when the options have been changed or when a file is created. [annotate]

    [annotate]