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〕
Technical Meaning of Emacs Major Mode
For elisp coders, technically a major mode means:
- A command that initiate the mode, mostly setting many Buffer Local Variable. This is required.
- The Buffer Local Variable includes syntax table, keymap, abbrev table, font-lock-defaults, etc. Some of these such as syntax table is not technically a buffer local variable, but is a value local for each buffer.
- Many special commands for a specific task. E.g. In programing language modes, commands for formatting code etc, or special mode such as dired, Emacs: eshell, Emacs: View Image File, 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