Check if native mode matches one of several emacs

I found a snippet to close all processed buffers that I want to use with the 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) 

The problem is that I cannot get it to work for both sr-mode and dired-mode together. How to check "if the main mode is sr-mode or dired-mode"?


EDIT: Just a syntax error. Must be

 (when (or (equal major-mode 'dired-mode) (equal major-mode 'sr-mode)) 

I must admit it is not too intuitive.

+6
source share
2 answers

The canonical path will be (when (derived-mode-p 'sr-mode 'dired-mode) ...) .

+11
source

I tried something and found that it works on my emacs-ielm - maybe this might also help:

 (if (member major-mode '(fsharp-mode c-mode java-mode inferior-emacs-lisp-mode)) (message "yeah right")) 
+2
source

Source: https://habr.com/ru/post/943736/


All Articles