How can I work with additional Emacs buffers at the same time?

I am looking for the equivalent of the :bufdoVim command in Emacs. :bufdotakes an argument - another command - and executes the command for all open buffers. I haven't found a similar feature in Emacs yet.

+5
source share
3 answers

Depending on your team, you can:

M-: (mapc (lambda (b) (set-buffer b) (*command*)) (buffer-list))

But I have a feeling that you want something not too lazy. See keyboard macros . Namely, decide what you want to do:

C-x ( <do-your-command> C-x )
M-: (mapc (lambda (b) (set-buffer b) (kmacro-end-and-call-macro)) (buffer-list))

You will probably want to define this last part as a function if you use it a lot:

(defun bufdo ()
   "execute last macro on all buffers, ala bufdo from vi"
   (interactive)
   (mapc (lambda (b) 
            (with-current-buffer b
              (kmacro-end-and-call-macro)))
         (buffer-list)))

Note: code not verified

+9
source

ibuffer, , m, - E. , . query-replace Q. (C-h m).

, dired, , , eval.

+6

- (). ( BUFFER). . mapcar ( ). , set-buffer, Emacs Lisp, .

+2

All Articles