[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

27.5 Buffer Modification

Emacs keeps a flag called the modified flag for each buffer, to record whether you have changed the text of the buffer. This flag is set to t whenever you alter the contents of the buffer, and cleared to nil when you save it. Thus, the flag shows whether there are unsaved changes. The flag value is normally shown in the mode line (see section 23.3.2 Variables Used in the Mode Line), and controls saving (see section 25.2 Saving Buffers) and auto-saving (see section 26.2 Auto-Saving).

Some Lisp programs set the flag explicitly. For example, the function set-visited-file-name sets the flag to t, because the text does not match the newly-visited file, even if it is unchanged from the file formerly visited.

The functions that modify the contents of buffers are described in 32. Text.

Function: buffer-modified-p &optional buffer
This function returns t if the buffer buffer has been modified since it was last read in from a file or saved, or nil otherwise. If buffer is not supplied, the current buffer is tested.

Function: set-buffer-modified-p flag
This function marks the current buffer as modified if flag is non-nil, or as unmodified if the flag is nil.

Another effect of calling this function is to cause unconditional redisplay of the mode line for the current buffer. In fact, the function force-mode-line-update works by doing this:

 
(set-buffer-modified-p (buffer-modified-p))

Command: not-modified
This command marks the current buffer as unmodified, and not needing to be saved. With prefix arg, it marks the buffer as modified, so that it will be saved at the next suitable occasion.

Don't use this function in programs, since it prints a message in the echo area; use set-buffer-modified-p (above) instead.

Function: buffer-modified-tick &optional buffer
This function returns buffer's modification-count. This is a counter that increments every time the buffer is modified. If buffer is nil (or omitted), the current buffer is used.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on May 2, 2002 using texi2html