开发者

How do I save multiple buffers (of my choosing) at the same time in Emacs?

When I press C-x s (save-some-buffers) or 开发者_StackOverflowC-x C-c (save-buffers-kill-terminal), 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?


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.)


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 ...


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.


The answer to the question in the title is to pass an argument to save-buffers-kill-emacs (or -kill-terminal), ie. use the key combo C-u C-x C-c which will silently save all buffers and exit (or C-u C-x s to just silently save all buffers).


In emacs 23

  • C-x C-b (M-x list-buffers) to view buffer list
  • m to mark buffers to save
  • S to save marked buffers
  • u to unmark buffers individually or M-x dired-unmark-all-marks for all


I have googled now for this question and found the solution here http://johntellsall.blogspot.com.es/2013/03/emacs-save-all-modified-buffers.html

You have to add this config to your ~/.emacs.d/init.el emacs configuration

(global-set-key 
 (kbd "M-*")
 (lambda ()
   (interactive)
   (save-some-buffers t)))

save and eval the buffer (M-evalb-buffer) of the init.el file, and then when you want to save all the modified files you only have to press Meta key with "*" as is indicated in the second line

I hope this solution works!

Juan

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜