So this is probably a weird question but out of muscle memory I tend to save files constantly. This becomes a slight inconvenience when I have a compilation buffer then accidentally save that. I was wondering if there was a way to disable saving a file or something for buffers like this. Thanks.

  • 2
    Not too clear to me just what you're doing. Maybe show a step-by-step recipe. If the buffer is not associated with a file or have a file-associated mode (auto-mode-alist) then C-x C-s asks you whether to save it. Is that what you're doing - confirming to save it? If so, what is it that you want Emacs to do, to prevent you from confirming? ;-) – Drew Jul 18 '18 at 4:41

Something like this, perhaps:

(defun my-save-buffer (&optional arg)
  "Like `save-buffer', but does nothing in certain modes."
  (interactive "p")
  (unless (derived-mode-p 'compilation-mode
                          ;; etc...
    (save-buffer arg)))

(global-set-key [remap save-buffer] #'my-save-buffer)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.