~:: kalyan ::~

May 16, 2008

emacs save all modified files

Filed under: emacs, open-source — Tags: — skalyanasundaram @ 10:43 pm

Few time I got bugged up with the situation where I forgot to save the buffer and trying to blame make, automake tools. It would be nice if there is some function which saves all modified buffers like “Save All” from any IDEs.

I was trying something like this

(setq var (buffer-list))
(unless (null var)
(string-match “.+.[ch].*” (buffer-name (car var)))
(save-buffer (car var))
(setq var (cdr var)))

ofcourse did not work with the last argument of string-match. Latter found save-buffer only saves current buffer and does not take buffer as argument. But which leads me to find save-some-buffers, and this what I was trying to write my own. :-/

save-some-buffers C-x s , saves all modified buffers which are all associated with files. It also ask for many questions. The beauty is if you dont remember what changes have been made in the buffer you can make a diff between the file and the buffer like the below. Review each hunk with M-n

***************
*** 19,25 ****

#include <config.h>

! #include <ctype.h>
#include <stdlib.h>
#include <string.h>
//Test
— 19,25 —-

#include <config.h>

! #kalyaninclude <ctype.h>
#include <stdlib.h>
#include <string.h>
//Test

Diff finished. Fri Jan 18 10:25:55 2008
There is an another option C-r which takes us to the modified buffer too.

Yet another nice feature 🙂

Advertisements

1 Comment »

  1. Tahnks for posting

    Comment by kifsTeli — August 3, 2008 @ 6:56 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: