Major Mode Skeleton
These are the steps involved in defining a major mode.
Choose a name. The name for our mode is
quip.Create a file called name.el to contain the code for the mode.
Define a variable called name-
mode-hook. This will contain the user's hook functions to execute when entering the mode.(defvar quip-mode-hook nil "*List of functions to call when entering Quip mode.")
If appropriate, define a mode-specific keymap (see Keymaps later in this chapter). Put it in a variable called name-
mode-map. Create a mode's keymap like this:(defvar name-mode-map nil "Keymap for name major mode.") (if name-mode-map nil (setq name-mode-map (make-keymap)) (define-key name-mode-map keysequence command) ...)
Instead of
make-keymap, you could usemake-sparse-keymap, which is better suited to keymaps that contain only a few keybindings.If appropriate, define a mode-specific syntax table (see the section called Minor Adjustments in Chapter 7). Put it in a variable named name-
mode-syntax-table.If appropriate, define a mode-specific abbrev table. Put it in a variable named name-
mode-abbrev-table.Define a command named name-
mode. This is the major mode command, and it takes no arguments (unlike a minor mode command, which takes one optional argument). When executed, it should cause the current buffer to enter name-modeby performing the following steps:It must call
kill-all-local-variables, which removes the definitions for all buffer-local variables. This effectively turns off whatever modes, major ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access