Fork me on GitHub
#emacs
<
2022-07-24
>
teodorlu14:07:00

is this the best way to check if I'm in a certain mode?

(when (eq major-mode 'clojure-mode)
  (message "in clojure-mode"))
I looked for things like clojure-mode-p, but coudn't find anything more compact.

馃憤 1
Karol W贸jcik14:07:15

This is idiomatic way of checking if you in some mode ;)

馃憤 1
dakra14:07:28

I think checking the major-mode variable is ok. But depending on the use-case derived-mode-p is often better. E.e. (derived-mode-p 'clojure-mode) would work also in cljs and cljc files while your (eq major-mode 'clojure-mode) is only non-nil for clj files.

馃憤 3