New answers tagged

1

You can use the write-file-functions hook to do this. It's what's called an "abnormal" hook, which means its return value is taken into account, unlike before-save-hook. In this case, if it returns t, the `save-buffer' command returns without saving the buffer. E.g. (add-hook 'write-file-functions #'foo) (defun foo () (when (and (buffer-file-...


1

You can do this: (add-hook 'before-save-hook 'foo) (defun foo () (when (and (buffer-file-name) (not (file-exists-p (buffer-file-name)))) (unless (y-or-n-p "No such file. Create it?") (error "OK, not saved")))) However, this could be regarded as a feature: Emacs creates a file for a buffer you ask it to save. But if you don'...


Top 50 recent answers are included