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-modeetc. 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 command 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 the major mode is designed for. 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 and Doc〕
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, hook
Emacs Principle
- Emacs: Principle, Command, Keys
- Emacs: Jargons (Glossary)
- Emacs: Mode Line (Status Bar)
- Emacs: Major Mode
- Emacs: Minor Mode
- Emacs Init: Hook
- Emacs: Minibuffer
- Emacs: Messages Buffer
- Emacs: Universal Argument (C-u prefix arg)
- Emacs: Repeat Last Command
- Emacs: Jump to Previous Position
- Emacs: Narrow to Region