Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if major mode is equal one of several emacs

Tags:

emacs

elisp

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.

like image 924
Devon Ville Avatar asked Apr 26 '13 17:04

Devon Ville


People also ask

How do you find the major mode?

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!

How do I change my major mode in Emacs?

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.

What is the default mode of Emacs?

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.

What are Emacs modes?

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.


1 Answers

The canonical way would be (when (derived-mode-p 'sr-mode 'dired-mode) ...).

like image 55
Stefan Avatar answered Sep 23 '22 18:09

Stefan