Emacs: Major Mode
What is Major Mode
- A major mode is a collection of emacs settings and commands, designed for specific task.
- Each buffer is associated with one major mode, and only one.
Example of major modes:
- programing languages:
emacs-lisp-mode
,python-mode
,js-mode
etc. dired
[see Emacs: File Manager, dired]shell
[see Emacs: Run Shell]image-mode
[see Emacs: View Image File]eww
[see Emacs: Eww Web Browser]
For elisp coders, technically a major mode is a command that defines many special commands and sets many Buffer Local Variable, e.g. keymap, syntax table, abbrev table, font-lock-defaults, etc. and or set up text properties, text overlay, hook, etc. [see Elisp: Create Major Mode]
Switch to a Major Mode
Each major mode has a associated command.
e.g. shell
,
js-mode
,
python-mode
.
The command to turn on a major mode usually ends in “-mode”, but not always.
To switch to a major mode, just Alt+x major_mode_command_name
When you open a file, a chosen major mode is automatically turned on, depending on file name or other ways. [see Emacs Init: Set Default Major Mode]
Find the Name of Current Major-Mode
The current major mode's name is stored in a variable major-mode
- major-mode
- A Buffer Local Variable . Value is Symbol of current buffer's major mode. [see Emacs: Show Variable Value]
Major Mode's Display Name
Each major have a display name (a easy-to-understand name, or short name), that is displayed in Mode Line
![emacs major mode mode line 2022-05-15 Gxv4](i/emacs_major_mode_mode_line_2022-05-15_Gxv4.png)