Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply a function to all buffers in emacs

Tags:

emacs

emacs23

Suppone that I want to apply delete-trailing-whitespace to all buffers in an Emacs session. How can I do that?

I have in this session many buffers. So instead to apply M-x delete-trailing-whitespaceto manually each buffer, I need some way to make it automatically.

Thank you very much

like image 736
Israel Avatar asked Dec 04 '11 23:12

Israel


2 Answers

This should do it:

(defun delete-trailing-whitespace-each-buffer ()
  (interactive)
  (mapc (lambda (buffer)
          (condition-case nil
              (with-current-buffer buffer
                (delete-trailing-whitespace))
            (buffer-read-only nil)))
        (buffer-list)))

It won't do anything on read-only buffers.

like image 148
Michael Hoffman Avatar answered Sep 23 '22 16:09

Michael Hoffman


ibuffer is another option. You can quickly select the buffers you want (maybe by regexp), and press E to evaluate a form in each buffer. This works for any form.

like image 36
event_jr Avatar answered Sep 26 '22 16:09

event_jr