Go to the first, previous, next, last section, table of contents.


Writing Buffers

After a buffer containing a file has been edited it must be written back to a file on disk, otherwise the modifications will disappear when Jade is exited!

Function: write-buffer &optional file-name buffer
The primitive to save a buffer's contents. The contents of the buffer buffer (or the current buffer) is written to the file file-name (or the buffer-file-name component of the buffer).

Function: write-buffer-area start-pos end-pos file-name &optional buffer
Writes the region of text from start-pos up to, but not including, end-pos to the file file-name.

Function: write-file buffer &optional file-name
Writes the contents of the buffer buffer to a file on disk. If the optional argument file-name is defined it names the file to write to. Otherwise, the value of the buffer's buffer-file-name component is used.

The hook write-file-hook is used to try and write the file, if this fails (i.e. the hook returns nil) the buffer is saved normally.

A backup may be made of the file to be overwritten (see section Making Backups) and the protection-modes of the overwritten file will be preserved if possible.

Hook: write-file-hook
This hook is called by the write-file function when a buffer is to be saved. If no member of the hook actually writes the buffer to a file (i.e. the hook returns nil) write-file will do it itself in a standard way.

The hook function is responsible for creating any required backup file (use the function backup-file, see section Making Backups) and resetting the protection-modes of the new file to their original value.

See the file `gzip.jl' in the Lisp library directory for an example, it uses it to compress certain files automatically.

Remember to make sure that if a member of the hook writes the buffer it returns a non-nil value!

The following code fragment defines a function which does what the default action of write-file is,

(defun write-file-default-action (buffer name)
  (let
      ((modes (when (file-exists-p name) (file-modes name))))
    (backup-file name)
    (when (write-buffer name buffer)
      (when modes
        (set-file-modes name modes))
       t)))

The following commands call the write-file function to write out a buffer, they also update the various variables containing information about the state of the buffer. It is normally unnecessary to call write-file yourself; these commands should suffice.

Command: save-file &optional buffer
This command writes the buffer to the file that it was loaded from and then updates all the necessary buffer-local variables.

If the file on disk has been modified since it was read into the buffer the user is asked if they really want to save it (and risk losing a version of the file).

If no modifications have been made to the file since it was last saved it won't be saved again.

Any auto-saved version of the file is deleted.

Command: save-file-as new-name &optional buffer
This command saves the buffer buffer (or the current buffer) to the file called new-name. The buffer-file-name is set to new-name and all the necessary buffer-local variables are updated.

If an auto-saved version of file-name exists it is deleted.

When called interactively new-name will be prompted for.

Command: save-some-buffers
For each buffer which contains unsaved modifications the user is asked whether or not to save the buffer.

t is returned if no unsaved modifications exist in any buffers (i.e. the user replied `yes' to all files which could be saved).

Command: save-and-quit
Calls save-some-buffers then quits Jade (after asking the user if any unsaved buffers may be discarded).


Go to the first, previous, next, last section, table of contents.