Search code examples
emacselispmodeline

Find from elisp if Emacs buffer is modified


I'm customizing mode line and i want to put a string "Unsaved" on it, if the file is modified. How to find out directly from elisp, whether the current buffer in Emacs is modified?


Solution

  • Found out there is a function buffer-modified-p:

    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.

    Source: Emacs Lisp Reference/Buffers