PascalVKooten
PascalVKooten

Reputation: 21443

Check whether mode is on emacs

How to check whether in the current buffer a mode is on?

I tried this for LaTeX, for which I wanted to have an align function align on &, but only if I am in a LaTeX buffer, not in an ESS mode buffer.

How to do a check for this? I tried:

(if (equal reftex-mode t) (message "TRUE"))

and

(if (equal LaTeX-mode t) (message "TRUE"))

but reftex is set globally and LaTeX stuff does not work at all. Ideas?

Also, how to prevent the error "void variable" in the case these variables are not initiated?

Upvotes: 3

Views: 1062

Answers (1)

Daniel Martín
Daniel Martín

Reputation: 7845

Test against the "major-mode" variable:

(defun a-function()
    (if (eq major-mode 'latex-mode)
        (message "LaTeX mode is ON")
      (message "LaTeX mode is OFF")))

Upvotes: 9

Related Questions