I often open temp files and I don't care about saving the contents when I modify the buffer. How can I tell Emacs to ignore buffer changes when the filename matches a pattern, so that I don't get prompted to save the buffer when I kill it?

Edit: I am loading files from the command line, so I'd like to auto-detect this situation and configure the buffer accordingly.


I use scratch buffers for that purpose.

(defun python-scratch () 
  (let ((python-scratch-buffer (get-buffer-create "*python-scratch*")))
    (switch-to-buffer python-scratch-buffer)

You can convert the buffer with the file to a scratch buffer.

(defun my-detach-buffer-from-file ()
  (setq buffer-file-name nil))
  • I am loading the file from the command line. How can I automatically have the file load into a scratch buffer? – jdigital Oct 26 '16 at 18:44
  • How can this be done automatically, when the file is loaded? I don't want to have to run a command. – jdigital Oct 26 '16 at 19:21
  • How do you load your files ? From a command line in emacs ? And how do you want to auto detect this situation ? You have to distinguish between loading a file and loading its contents in a scratch buffer. – bertfred Oct 26 '16 at 19:33
  • I am loading from the command line (cmd.exe). I can specify a regex and when that matches, I'd like to have the buffer set to the equivalent of scratch mode. – jdigital Oct 26 '16 at 19:42
  • In a new instance of emacs or an already exisiting ? Btw that's a pretty exotic usage of emacs :D – bertfred Oct 26 '16 at 19:48

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.