GNU 23.1.1
By clicking the F5 button I can compile my project. However, I want to extend this so that any unsaved work would be saved and then compiled.
Normally I just do C-x-s to save then click F5. But can I add a line that will save without having to ask me do I want to save then it will compile, all done automatically?
; Compile program using <F5>
; Save all unsaved files here, then compile
(global-set-key [f5] 'compile)
Hope you understand me?
Many thanks for any advice,
You can use
(save-some-buffers 1)to save all buffers containing changes.Wrap it up with a function together with
compilelike so:Then set F5 to run this function instead of plain compile.
Use
(save-some-buffers)(no argument) if you prefer Emacs to ask you about each buffer to be saved. Also, you might want to make the compilation-command customisable, as it is withcompile… I’ll leave that to you though.Getting it to work
You also have to add
(interactive), see full example below.