diff options
Diffstat (limited to 'devdocs/elisp/major-modes.html')
| -rw-r--r-- | devdocs/elisp/major-modes.html | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/devdocs/elisp/major-modes.html b/devdocs/elisp/major-modes.html new file mode 100644 index 00000000..0b3d2de0 --- /dev/null +++ b/devdocs/elisp/major-modes.html @@ -0,0 +1,61 @@ + <h3 class="section">Major Modes</h3> <p>Major modes specialize Emacs for editing or interacting with particular kinds of text. Each buffer has exactly one major mode at a time. Every major mode is associated with a <em>major mode command</em>, whose name should end in ‘<samp>-mode</samp>’. This command takes care of switching to that mode in the current buffer, by setting various buffer-local variables such as a local keymap. See <a href="major-mode-conventions">Major Mode Conventions</a>. Note that unlike minor modes there is no way to “turn off” a major mode, instead the buffer must be switched to a different one. However, you can temporarily <em>suspend</em> a major mode and later <em>restore</em> the suspended mode, see below. </p> <p>The least specialized major mode is called <em>Fundamental mode</em>, which has no mode-specific definitions or variable settings. </p> <dl> <dt id="fundamental-mode">Command: <strong>fundamental-mode</strong> +</dt> <dd><p>This is the major mode command for Fundamental mode. Unlike other mode commands, it does <em>not</em> run any mode hooks (see <a href="major-mode-conventions">Major Mode Conventions</a>), since you are not supposed to customize this mode. </p></dd> +</dl> <dl> <dt id="major-mode-suspend">Function: <strong>major-mode-suspend</strong> +</dt> <dd><p>This function works like <code>fundamental-mode</code>, in that it kills all buffer-local variables, but it also records the major mode in effect, so that it could subsequently be restored. This function and <code>major-mode-restore</code> (described next) are useful when you need to put a buffer under some specialized mode other than the one Emacs chooses for it automatically (see <a href="auto-major-mode">Auto Major Mode</a>), but would also like to be able to switch back to the original mode later. </p></dd> +</dl> <dl> <dt id="major-mode-restore">Function: <strong>major-mode-restore</strong> <em>&optional avoided-modes</em> +</dt> <dd><p>This function restores the major mode recorded by <code>major-mode-suspend</code>. If no major mode was recorded, this function calls <code>normal-mode</code> (see <a href="auto-major-mode">normal-mode</a>), but tries to force it not to choose any modes in <var>avoided-modes</var>, if that argument is non-<code>nil</code>. </p></dd> +</dl> <p>The easiest way to write a major mode is to use the macro <code>define-derived-mode</code>, which sets up the new mode as a variant of an existing major mode. See <a href="derived-modes">Derived Modes</a>. We recommend using <code>define-derived-mode</code> even if the new mode is not an obvious derivative of another mode, as it automatically enforces many coding conventions for you. See <a href="basic-major-modes">Basic Major Modes</a>, for common modes to derive from. </p> <p>The standard GNU Emacs Lisp directory tree contains the code for several major modes, in files such as <samp>text-mode.el</samp>, <samp>texinfo.el</samp>, <samp>lisp-mode.el</samp>, and <samp>rmail.el</samp>. You can study these libraries to see how modes are written. </p> <dl> <dt id="major-mode">User Option: <strong>major-mode</strong> +</dt> <dd> +<p>The buffer-local value of this variable holds the symbol for the current major mode. Its default value holds the default major mode for new buffers. The standard default value is <code>fundamental-mode</code>. </p> <p>If the default value is <code>nil</code>, then whenever Emacs creates a new buffer via a command such as <kbd>C-x b</kbd> (<code>switch-to-buffer</code>), the new buffer is put in the major mode of the previously current buffer. As an exception, if the major mode of the previous buffer has a <code>mode-class</code> symbol property with value <code>special</code>, the new buffer is put in Fundamental mode (see <a href="major-mode-conventions">Major Mode Conventions</a>). </p> +</dd> +</dl> <table class="menu" border="0" cellspacing="0"> <tr> +<td align="left" valign="top">• <a href="major-mode-conventions" accesskey="1">Major Mode Conventions</a> +</td> +<td> </td> +<td align="left" valign="top">Coding conventions for keymaps, etc. </td> +</tr> <tr> +<td align="left" valign="top">• <a href="auto-major-mode" accesskey="2">Auto Major Mode</a> +</td> +<td> </td> +<td align="left" valign="top">How Emacs chooses the major mode automatically. </td> +</tr> <tr> +<td align="left" valign="top">• <a href="mode-help" accesskey="3">Mode Help</a> +</td> +<td> </td> +<td align="left" valign="top">Finding out how to use a mode. </td> +</tr> <tr> +<td align="left" valign="top">• <a href="derived-modes" accesskey="4">Derived Modes</a> +</td> +<td> </td> +<td align="left" valign="top">Defining a new major mode based on another major mode. </td> +</tr> <tr> +<td align="left" valign="top">• <a href="basic-major-modes" accesskey="5">Basic Major Modes</a> +</td> +<td> </td> +<td align="left" valign="top">Modes that other modes are often derived from. </td> +</tr> <tr> +<td align="left" valign="top">• <a href="mode-hooks" accesskey="6">Mode Hooks</a> +</td> +<td> </td> +<td align="left" valign="top">Hooks run at the end of major mode functions. </td> +</tr> <tr> +<td align="left" valign="top">• <a href="tabulated-list-mode" accesskey="7">Tabulated List Mode</a> +</td> +<td> </td> +<td align="left" valign="top">Parent mode for buffers containing tabulated data. </td> +</tr> <tr> +<td align="left" valign="top">• <a href="generic-modes" accesskey="8">Generic Modes</a> +</td> +<td> </td> +<td align="left" valign="top">Defining a simple major mode that supports comment syntax and Font Lock mode. </td> +</tr> <tr> +<td align="left" valign="top">• <a href="example-major-modes" accesskey="9">Example Major Modes</a> +</td> +<td> </td> +<td align="left" valign="top">Text mode and Lisp modes. </td> +</tr> </table><div class="_attribution"> + <p class="_attribution-p"> + Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br> + <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Major-Modes.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Major-Modes.html</a> + </p> +</div> |
