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
|improve this answer|||||

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.
|improve this answer|||||

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

(print major-mode)

|improve this answer|||||
  • 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.