Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force Emacs to save even if it thinks (no changes need to be saved)

Tags:

emacs

save

This happens to me all the time:

  • I have a file open in emacs,
  • I save it ('save-buffer),
  • the file changes on disk (or get's deleted, moved, etc.)
  • but I want it back, so I try to save again in emacs ('save-buffer) and instead of saving it says "(no changes need to be saved)" and does nothing.

Is there a different function, or a setting, that I can use to force emacs to save?

like image 470
sligocki Avatar asked Jul 09 '10 19:07

sligocki


2 Answers

Wrap a function around save-buffer that marks the buffer modified first:

(defun save-buffer-always ()
  "Save the buffer even if it is not modified."
  (interactive)
  (set-buffer-modified-p t)
  (save-buffer))
like image 149
scottfrazer Avatar answered Nov 22 '22 04:11

scottfrazer


You can save as, with C-x C-w. That should save unconditionally. You can also just type a space then backspace over it. Emacs is smart enough to realize that if you undo everything you've done so far the buffer has no changes, but if you make changes and then manually reverse them it will consider the buffer to have been changed.

like image 31
Tagore Smith Avatar answered Nov 22 '22 04:11

Tagore Smith