I have a read-only file that I open in Emacs. I have created a keyboard shortcut to hide some regions of the file. For example:
(defun hide-beginning ()
(interactive)
(setq buffer-read-only nil)
(put-text-property 1 10 'invisible t)
(setq buffer-read-only t)
)
However, when I exit the buffer with kill-buffer
or rather ido-kill-buffer
, I get the question
Buffer myfile.txt modified; kill anyway? (yes or no)
How can this question be avoided?
buffer-modified-p
andset-buffer-modified-p
to store the modified state and restore it after changing the properties.(set-buffer-modified-p nil)
after I changed the property..buffer-modified-p
at the beginning of the function. That way, if something else modifies the buffer, you will still be prompted about it.