简体   繁体   中英

Apply a function to all buffers in emacs

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 Mx delete-trailing-whitespace to manually each buffer, I need some way to make it automatically.

Thank you very much

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM