I found a snippet to close all dired buffers, which I want to use in sunrise commander:
(defun er/kill-all-dired-buffers()
"Kill all dired buffers."
(interactive)
(save-excursion
(let((count 0))
(dolist(buffer (buffer-list))
(set-buffer buffer)
(when (equal major-mode 'sr-mode)
(or (equal major-mode 'dired-mode))
(setq count (1+ count))
(kill-buffer buffer)))
(message "Killed %i dired buffer(s)." count ))))
(setq sr-quit-hook 'er/kill-all-dired-buffers)
Issue being, I can't make it work both for sr-mode and dired-mode together. How do I check "if major mode is sr-mode OR dired-mode"?
EDIT: Just a syntax error. Should be
(when (or (equal major-mode 'dired-mode) (equal major-mode 'sr-mode))
Have to admit it's not too intuitive.
The mode of a data set is the number that occurs most frequently in the set. To easily find the mode, put the numbers in order from least to greatest and count how many times each number occurs. The number that occurs the most is the mode!
Usually, the major mode is automatically set by Emacs, when you first visit a file or create a buffer (see Choosing File Modes). You can explicitly select a new major mode by using an M-x command.
The standard default value is fundamental-mode . If the default value is nil , then whenever Emacs creates a new buffer via a command such as C-x b ( switch-to-buffer ), the new buffer is put in the major mode of the previously current buffer.
A mode is a set of definitions that customize Emacs behavior in useful ways. There are two varieties of modes: minor modes, which provide features that users can turn on and off while editing; and major modes, which are used for editing or interacting with a particular kind of text.
The canonical way would be (when (derived-mode-p 'sr-mode 'dired-mode) ...)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With