Previous: , Up: Files   [Contents][Index]


13.4 File Reading and Writing

Common Lisp pathnames are used by the file primitives. For probing, checking write dates, and so forth, all of the Common Lisp file functions are available.

Function: read-file pathname mark

This inserts the file named by pathname at mark.

Hemlock Variable: Keep Backup Files (initial value nil)
Function: Function write-file region pathname &key :keep-backup :access :append

This function writes the contents of region to the file named by pathname. This writes region using a stream as if it were opened with :if-exists supplied as :rename-and-delete.

When keep-backup, which defaults to the value of Keep Backup Files, is non-nil, this opens the stream as if :if-exists were :rename. If append is non-nil, this writes the file as if it were opened with :if-exists supplied as :append.

This signals an error if both append and keep-backup are supplied as non-nil.

Access is an implementation dependent value that is suitable for setting pathname’s access or protection bits.

Hemlock Variable: Write File Hook
Hemlock Variable: Add Newline at EOF on Writing File (initial value :ask-user)
Function: write-buffer-file buffer pathname

write-buffer-file writes buffer to the file named by pathname including the following:

  • It assumes pathname is somehow related to buffer’s pathname: if the buffer’s write date is not the same as pathname’s, then this prompts the user for confirmation before overwriting the file.
  • It consults Add Newline at EOF on Writing File (see Hemlock User’s Manual for possible values) and interacts with the user if necessary.
  • It sets Pathname Defaults, and after using write-file, marks buffer unmodified.
  • It updates Buffer’s pathname and write date.
  • It renames the buffer according to the new pathname if possible.
  • It invokes Write File Hook.

Write File Hook is a list of functions that take the newly written buffer as an argument.

Hemlock Variable: Read File Hook
Function: read-buffer-file pathname buffer

read-buffer-file deletes buffer’s region and uses read-file to read pathname into it, including the following:

  • It sets buffer’s write date to the file’s write date if the file exists; otherwise, it message’s that this is a new file and sets buffer’s write date to nil.
  • It moves buffer’s point to the beginning.
  • It sets buffer’s unmodified status.
  • It sets buffer’s pathname to the result of probing pathname if the file exists; otherwise, this function sets buffer’s pathname to the result of merging pathname with default-directory.
  • It sets Pathname Defaults to the result of the previous item.
  • It processes the file options.
  • It invokes Read File Hook.

Read File Hook is a list functions that take two arguments — the buffer read into and whether the file existed, t if so.

Function: find-file-buffer pathname

This returns a buffer assoicated with the pathname, reading the file into a new buffer if necessary. This returns a second value indicating whether a new buffer was created, t if so. If the file has already been read, this checks to see if the file has been modified on disk since it was read, giving the user various recovery options. This is the basis of the Find File command.


Previous: File Groups, Up: Files   [Contents][Index]