tags:

views:

199

answers:

3

When I press C-x s or C-x C-c, emacs displays the names of modified buffers one by one and asks what to do with each (save, diff, pass, ...). Pressing y one by one is slow. Pressing ! doesn't let you see what buffers are being saved.

How can I have the names of all modified buffers displayed first so that I can mark off some of them and save all the other quickly?

+1  A: 

C-x C-b (M-x list-buffers) displays a list of all the buffers. Modified ones will be shown with a * next to them. You can mark a buffer for saving by pressing s. When you're done, press x to save all the buffers you marked.

Unfortunately, as far as I know, there's no way to show only the unsaved buffers or to sort them so they're all at the top.

(I actually prefer M-x ibuffer to M-x list-buffers, but ibuffer provides a similar feature.)

Phil
+1  A: 

Use ibuffer, which should come with all late-model emacsen. Put the following in your .emacs file:

(autoload 'ibuffer "ibuffer" "" t)
(global-set-key (kbd "C-x C-b") 'ibuffer)


(defun my-ibuffer-load-hook ()
  "Hook for when ibuffer is loaded."

  (define-ibuffer-filter unsaved-file-buffers
   "Only show unsaved buffers backed by a real file."
 (:description "unsaved file buffers")
 (and (buffer-local-value 'buffer-file-name buf)
   (buffer-modified-p buf)))

  (define-key ibuffer-mode-map (kbd "/ *") 'ibuffer-filter-by-unsaved-file-buffers)
  )

;; (add-hook 'ibuffer-load-hook 'my-ibuffer-load-hook)

(eval-after-load 'ibuf-ext '(my-ibuffer-load-hook))

Then use C-x C-b to bring up the ibuffer list, and / * to show just unsaved buffers backed by a real file (so you don't see *scratch* in the list, for example). Mark the desired buffers with m and then save them with S.

Joe Casadonte
A: 

In emacs 23, with ibuffer :

  • 'M-x ibuffer' (to open a list of buffers)
  • '*u' (start and u at the same time) to marked all unsaved buffers
  • 'S' to save all marked buffers

Strangely enough, *u does not mark 'special' buffers like scratch, compilation, etc... I suppose i regexps on the name ...

phtrivier