Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How I can prevent Emacs from saving my buffer when it contains syntax errors ?

It would by especially useful for editing source code.

I'm writing some source code into the buffer, hit C-x C-s and Emacs should position the cursor on the line containing the error. I'm correcting the error, hit the save command again, and Emacs should save the file.

share|improve this question
1  
You do not say what sources you would like to check. There are different tools for different types. And ways these can be integrated into emacs. – Benjamin Bannier Mar 5 '10 at 17:05

My approach to this problem would be to rebind C-x C-s to astropanic-save-buffer which would be an elisp function that would run the contents of the current buffer through whatever your compiler/build process is. If it passed, it would run save-buffer and if there was an error it would create a new buffer/window split with the error message so you could fix it.

Consider also using the write-file-functions(more info) hook to attach workflow to save-buffer, but I'm wary of this on the grounds that while I might think that I'd want this in some modes, I wouldn't in all modes.

share|improve this answer

Emacs flymake mode may be close to what you want. It does dynamic compiling/syntax checking of source code for the current buffer.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .