If I am editing a .tex file in emacs, by default (for me) the bottom right corner of the frame will say "LaTeX/P". However, I won't get to that mode by typing "M-x LaTeX/P-mode"; I can only get to it by typing "M-x latex-mode".

Other than Googling it, how am I supposed to know the thing I type to get to that mode is "latex-mode"?


I think the simplest way is to check the value of the buffer-local major-mode variable, with either of:

  • C-hv major-mode RET
  • M-: major-mode RET
  • How to check if the major-mode is org-mode for example? (equal major-mode "org-mode") always return nil even when I'm in org-mode. – Student Apr 21 '20 at 2:00
  • 1
    @Student That's because you're comparing two entirely different data types: "org-mode" is a string, whereas the value of major-mode is a symbol, so naturally they are not (cannot be) equal. (equal major-mode 'org-mode) would be t in org-mode buffers. Generally to test the current buffer's major mode you would use (derived-mode-p 'org-mode), which will return non-nil not only for org-mode itself, but also for any mode which was derived from org-mode. – phils Apr 21 '20 at 2:07
  • As a emacs noob, I thank you for your answer! Also for those who are new, you can use (type-of major-mode) to check that it's actually a symbol but not a string! – Student Apr 21 '20 at 2:14

C-h m gives you help on the current mode, and it typically tells you the name of the command that turns the mode on.

For example, in Emacs-Lisp mode C-h m tells you that you are in Emacs-Lisp mode. The command that turns the mode on is just emacs-lisp-mode.

C-h m also provides a link to the library that defines the mode, and if you click on that link it takes you to the definition of the mode command. For example, in Emacs-Lisp mode C-h m tells you:

Emacs-Lisp mode defined in `lisp-mode.el'

And if you click the link lisp-mode.el then Emacs takes you to the definition of command emacs-lisp-mode, which is the command that turns the mode on:

(define-derived-mode emacs-lisp-mode prog-mode "Emacs-Lisp"
  "Major mode for editing Lisp code to run in Emacs.

It's possible to get the major mode just by evaluating this expression:

(print major-mode)

  • 2
    This seems to repeat @phils's answer: examine variable major-mode (emacs.stackexchange.com/a/18084/105). – Drew Sep 9 '18 at 23:15
  • 1
    Yes we are evaluating the same thing variable ofcourse, since that's what stores the value of the major-mode. Difference is just how you want to implement that function. maybe we can define a function, with this command in place and bind it with a key. So my point being elisp vs using emacs mode line. – sidharth arya Oct 5 '18 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.