diff options
| author | Chong Yidong | 2011-08-29 18:02:21 -0400 |
|---|---|---|
| committer | Chong Yidong | 2011-08-29 18:02:21 -0400 |
| commit | 3fd50d5c65684312f9603c4f28e1e1c3010887cd (patch) | |
| tree | a7d99f56b782d010dbe51e4b981516c7549e4c9c /doc | |
| parent | 9a45d6c33122eba90f3e7378dd091494d10faba7 (diff) | |
| download | emacs-3fd50d5c65684312f9603c4f28e1e1c3010887cd.tar.gz emacs-3fd50d5c65684312f9603c4f28e1e1c3010887cd.zip | |
Update and edit manual sections on major modes.
* doc/emacs/modes.texi (Choosing Modes): auto-mode-case-fold is now t.
* doc/lispref/modes.texi (Basic Major Modes): New node. Callers updated.
(Major Modes): Document fundamental-mode and major-mode.
(Major Mode Basics): Node deleted; text moved to Major Modes.
(Derived Modes): Document derived-mode-p.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/emacs/ChangeLog | 4 | ||||
| -rw-r--r-- | doc/emacs/modes.texi | 13 | ||||
| -rw-r--r-- | doc/lispref/ChangeLog | 7 | ||||
| -rw-r--r-- | doc/lispref/elisp.texi | 5 | ||||
| -rw-r--r-- | doc/lispref/modes.texi | 337 | ||||
| -rw-r--r-- | doc/lispref/vol1.texi | 7 | ||||
| -rw-r--r-- | doc/lispref/vol2.texi | 7 |
7 files changed, 201 insertions, 179 deletions
diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog index 58b98189e29..2407d7dd18f 100644 --- a/doc/emacs/ChangeLog +++ b/doc/emacs/ChangeLog | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | 2011-08-29 Chong Yidong <cyd@stupidchicken.com> | ||
| 2 | |||
| 3 | * modes.texi (Choosing Modes): auto-mode-case-fold is now t. | ||
| 4 | |||
| 1 | 2011-08-28 Chong Yidong <cyd@stupidchicken.com> | 5 | 2011-08-28 Chong Yidong <cyd@stupidchicken.com> |
| 2 | 6 | ||
| 3 | * files.texi (File Archives): | 7 | * files.texi (File Archives): |
diff --git a/doc/emacs/modes.texi b/doc/emacs/modes.texi index 314d5d4347e..d82423a73b4 100644 --- a/doc/emacs/modes.texi +++ b/doc/emacs/modes.texi | |||
| @@ -353,12 +353,13 @@ the element has the form @code{(@var{regexp} @var{mode-function} | |||
| 353 | @var{regexp} and searches the list again for another match. | 353 | @var{regexp} and searches the list again for another match. |
| 354 | 354 | ||
| 355 | @vindex auto-mode-case-fold | 355 | @vindex auto-mode-case-fold |
| 356 | On systems with case-insensitive file names, such as Microsoft | 356 | On GNU/Linux and other systems with case-sensitive file names, Emacs |
| 357 | Windows, Emacs performs a single case-insensitive search through | 357 | performs a case-sensitive search through @code{auto-mode-alist}; if |
| 358 | @code{auto-mode-alist}. On other systems, Emacs normally performs a | 358 | this search fails, it performs a second case-insensitive search |
| 359 | single case-sensitive search through the alist. However, if you | 359 | through the alist. To suppress the second search, change the variable |
| 360 | change the variable @code{auto-mode-case-fold} to @code{t}, Emacs | 360 | @code{auto-mode-case-fold} to @code{nil}. On systems with |
| 361 | performs a second case-insensitive search if the first search fails. | 361 | case-insensitive file names, such as Microsoft Windows, Emacs performs |
| 362 | a single case-insensitive search through @code{auto-mode-alist}. | ||
| 362 | 363 | ||
| 363 | @vindex magic-fallback-mode-alist | 364 | @vindex magic-fallback-mode-alist |
| 364 | Finally, if Emacs @emph{still} hasn't found a major mode to use, it | 365 | Finally, if Emacs @emph{still} hasn't found a major mode to use, it |
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index aae0be5a054..57dde5ac4cb 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2011-08-29 Chong Yidong <cyd@stupidchicken.com> | ||
| 2 | |||
| 3 | * modes.texi (Basic Major Modes): New node. Callers updated. | ||
| 4 | (Major Modes): Document fundamental-mode and major-mode. | ||
| 5 | (Major Mode Basics): Node deleted; text moved to Major Modes. | ||
| 6 | (Derived Modes): Document derived-mode-p. | ||
| 7 | |||
| 1 | 2011-08-28 Chong Yidong <cyd@stupidchicken.com> | 8 | 2011-08-28 Chong Yidong <cyd@stupidchicken.com> |
| 2 | 9 | ||
| 3 | * files.texi (Changing Files, Create/Delete Dirs): Document new | 10 | * files.texi (Changing Files, Create/Delete Dirs): Document new |
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi index bb05f1b4a0b..a19af903027 100644 --- a/doc/lispref/elisp.texi +++ b/doc/lispref/elisp.texi | |||
| @@ -765,8 +765,7 @@ Major and Minor Modes | |||
| 765 | * Major Modes:: Defining major modes. | 765 | * Major Modes:: Defining major modes. |
| 766 | * Minor Modes:: Defining minor modes. | 766 | * Minor Modes:: Defining minor modes. |
| 767 | * Mode Line Format:: Customizing the text that appears in the mode line. | 767 | * Mode Line Format:: Customizing the text that appears in the mode line. |
| 768 | * Imenu:: How a mode can provide a menu | 768 | * Imenu:: Providing a menu of definitions made in a buffer. |
| 769 | of definitions in the buffer. | ||
| 770 | * Font Lock Mode:: How modes can highlight text according to syntax. | 769 | * Font Lock Mode:: How modes can highlight text according to syntax. |
| 771 | * Desktop Save Mode:: How modes can have buffer state saved between | 770 | * Desktop Save Mode:: How modes can have buffer state saved between |
| 772 | Emacs sessions. | 771 | Emacs sessions. |
| @@ -778,12 +777,12 @@ Hooks | |||
| 778 | 777 | ||
| 779 | Major Modes | 778 | Major Modes |
| 780 | 779 | ||
| 781 | * Major Mode Basics:: | ||
| 782 | * Major Mode Conventions:: Coding conventions for keymaps, etc. | 780 | * Major Mode Conventions:: Coding conventions for keymaps, etc. |
| 783 | * Auto Major Mode:: How Emacs chooses the major mode automatically. | 781 | * Auto Major Mode:: How Emacs chooses the major mode automatically. |
| 784 | * Mode Help:: Finding out how to use a mode. | 782 | * Mode Help:: Finding out how to use a mode. |
| 785 | * Derived Modes:: Defining a new major mode based on another major | 783 | * Derived Modes:: Defining a new major mode based on another major |
| 786 | mode. | 784 | mode. |
| 785 | * Basic Major Modes:: Modes that other modes are often derived from. | ||
| 787 | * Generic Modes:: Defining a simple major mode that supports | 786 | * Generic Modes:: Defining a simple major mode that supports |
| 788 | comment syntax and Font Lock mode. | 787 | comment syntax and Font Lock mode. |
| 789 | * Mode Hooks:: Hooks run at the end of major mode functions. | 788 | * Mode Hooks:: Hooks run at the end of major mode functions. |
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi index a354265b365..586fc0bbbfb 100644 --- a/doc/lispref/modes.texi +++ b/doc/lispref/modes.texi | |||
| @@ -19,16 +19,15 @@ user. For related topics such as keymaps and syntax tables, see | |||
| 19 | @ref{Keymaps}, and @ref{Syntax Tables}. | 19 | @ref{Keymaps}, and @ref{Syntax Tables}. |
| 20 | 20 | ||
| 21 | @menu | 21 | @menu |
| 22 | * Hooks:: How to use hooks; how to write code that provides hooks. | 22 | * Hooks:: How to use hooks; how to write code that provides hooks. |
| 23 | * Major Modes:: Defining major modes. | 23 | * Major Modes:: Defining major modes. |
| 24 | * Minor Modes:: Defining minor modes. | 24 | * Minor Modes:: Defining minor modes. |
| 25 | * Mode Line Format:: Customizing the text that appears in the mode line. | 25 | * Mode Line Format:: Customizing the text that appears in the mode line. |
| 26 | * Imenu:: How a mode can provide a menu | 26 | * Imenu:: Providing a menu of definitions made in a buffer. |
| 27 | of definitions in the buffer. | 27 | * Font Lock Mode:: How modes can highlight text according to syntax. |
| 28 | * Font Lock Mode:: How modes can highlight text according to syntax. | 28 | * Auto-Indentation:: How to teach Emacs to indent for a major mode. |
| 29 | * Auto-Indentation:: How to teach Emacs to indent for a major mode. | 29 | * Desktop Save Mode:: How modes can have buffer state saved between |
| 30 | * Desktop Save Mode:: How modes can have buffer state saved between | 30 | Emacs sessions. |
| 31 | Emacs sessions. | ||
| 32 | @end menu | 31 | @end menu |
| 33 | 32 | ||
| 34 | @node Hooks | 33 | @node Hooks |
| @@ -48,12 +47,12 @@ convention, whenever the hook name ends in @samp{-hook}, that tells | |||
| 48 | you it is normal. We try to make all hooks normal, as much as | 47 | you it is normal. We try to make all hooks normal, as much as |
| 49 | possible, so that you can use them in a uniform way. | 48 | possible, so that you can use them in a uniform way. |
| 50 | 49 | ||
| 51 | Every major mode function is supposed to run a normal hook called | 50 | Every major mode command is supposed to run a normal hook called the |
| 52 | the @dfn{mode hook} as the one of the last steps of initialization. | 51 | @dfn{mode hook} as the one of the last steps of initialization. This |
| 53 | This makes it easy for a user to customize the behavior of the mode, | 52 | makes it easy for a user to customize the behavior of the mode, by |
| 54 | by overriding the buffer-local variable assignments already made by | 53 | overriding the buffer-local variable assignments already made by the |
| 55 | the mode. Most minor mode functions also run a mode hook at the end. | 54 | mode. Most minor mode functions also run a mode hook at the end. But |
| 56 | But hooks are used in other contexts too. For example, the hook | 55 | hooks are used in other contexts too. For example, the hook |
| 57 | @code{suspend-hook} runs just before Emacs suspends itself | 56 | @code{suspend-hook} runs just before Emacs suspends itself |
| 58 | (@pxref{Suspending Emacs}). | 57 | (@pxref{Suspending Emacs}). |
| 59 | 58 | ||
| @@ -78,8 +77,8 @@ convention. | |||
| 78 | its value is just a single function, not a list of functions. | 77 | its value is just a single function, not a list of functions. |
| 79 | 78 | ||
| 80 | @menu | 79 | @menu |
| 81 | * Running Hooks:: How to run a hook. | 80 | * Running Hooks:: How to run a hook. |
| 82 | * Setting Hooks:: How to put functions on a hook, or remove them. | 81 | * Setting Hooks:: How to put functions on a hook, or remove them. |
| 83 | @end menu | 82 | @end menu |
| 84 | 83 | ||
| 85 | @node Running Hooks | 84 | @node Running Hooks |
| @@ -195,115 +194,98 @@ from the buffer-local hook list instead of from the global hook list. | |||
| 195 | @section Major Modes | 194 | @section Major Modes |
| 196 | @cindex major mode | 195 | @cindex major mode |
| 197 | 196 | ||
| 197 | @cindex major mode command | ||
| 198 | Major modes specialize Emacs for editing particular kinds of text. | 198 | Major modes specialize Emacs for editing particular kinds of text. |
| 199 | Each buffer has only one major mode at a time. For each major mode | 199 | Each buffer has one major mode at a time. Every major mode is |
| 200 | there is a function to switch to that mode in the current buffer; its | 200 | associated with a @dfn{major mode command}, whose name should end in |
| 201 | name should end in @samp{-mode}. These functions work by setting | 201 | @samp{-mode}. This command takes care of switching to that mode in the |
| 202 | buffer-local variable bindings and other data associated with the | 202 | current buffer, by setting various buffer-local variables such as a |
| 203 | buffer, such as a local keymap. The effect lasts until you switch | 203 | local keymap. @xref{Major Mode Conventions}. |
| 204 | to another major mode in the same buffer. | 204 | |
| 205 | The least specialized major mode is called @dfn{Fundamental mode}, | ||
| 206 | which has no mode-specific definitions or variable settings. | ||
| 207 | |||
| 208 | @deffn Command fundamental-mode | ||
| 209 | This is the major mode command for Fundamental mode. Unlike other mode | ||
| 210 | commands, it does @emph{not} run any mode hooks (@pxref{Major Mode | ||
| 211 | Conventions}), since you are not supposed to customize this mode. | ||
| 212 | @end deffn | ||
| 213 | |||
| 214 | The easiest way to write a major mode is to use the macro | ||
| 215 | @code{define-derived-mode}, which sets up the new mode as a variant of | ||
| 216 | an existing major mode. @xref{Derived Modes}. We recommend using | ||
| 217 | @code{define-derived-mode} even if the new mode is not an obvious | ||
| 218 | derivative of another mode, as it automatically enforces many coding | ||
| 219 | conventions for you. @xref{Basic Major Modes}, for common modes to | ||
| 220 | derive from. | ||
| 221 | |||
| 222 | The standard GNU Emacs Lisp directory tree contains the code for | ||
| 223 | several major modes, in files such as @file{text-mode.el}, | ||
| 224 | @file{texinfo.el}, @file{lisp-mode.el}, and @file{rmail.el}. You can | ||
| 225 | study these libraries to see how modes are written. | ||
| 226 | |||
| 227 | @defopt major-mode | ||
| 228 | The buffer-local value of this variable is a symbol naming the buffer's | ||
| 229 | current major mode. Its default value holds the default major mode for | ||
| 230 | new buffers. The standard default value is @code{fundamental-mode}. | ||
| 231 | |||
| 232 | If the default value is @code{nil}, then whenever Emacs creates a new | ||
| 233 | buffer via a command such as @kbd{C-x b} (@code{switch-to-buffer}), the | ||
| 234 | new buffer is put in the major mode of the previously current buffer. | ||
| 235 | As an exception, if the major mode of the previous buffer has a | ||
| 236 | @code{mode-class} symbol property with value @code{special}, the new | ||
| 237 | buffer is put in Fundamental mode (@pxref{Major Mode Conventions}). | ||
| 238 | @end defopt | ||
| 205 | 239 | ||
| 206 | @menu | 240 | @menu |
| 207 | * Major Mode Basics:: | 241 | * Major Mode Conventions:: Coding conventions for keymaps, etc. |
| 208 | * Major Mode Conventions:: Coding conventions for keymaps, etc. | 242 | * Auto Major Mode:: How Emacs chooses the major mode automatically. |
| 209 | * Auto Major Mode:: How Emacs chooses the major mode automatically. | 243 | * Mode Help:: Finding out how to use a mode. |
| 210 | * Mode Help:: Finding out how to use a mode. | 244 | * Derived Modes:: Defining a new major mode based on another major |
| 211 | * Derived Modes:: Defining a new major mode based on another major | ||
| 212 | mode. | 245 | mode. |
| 213 | * Generic Modes:: Defining a simple major mode that supports | 246 | * Basic Major Modes:: Modes that other modes are often derived from. |
| 247 | * Generic Modes:: Defining a simple major mode that supports | ||
| 214 | comment syntax and Font Lock mode. | 248 | comment syntax and Font Lock mode. |
| 215 | * Mode Hooks:: Hooks run at the end of major mode functions. | 249 | * Mode Hooks:: Hooks run at the end of major mode commands. |
| 216 | * Example Major Modes:: Text mode and Lisp modes. | 250 | * Example Major Modes:: Text mode and Lisp modes. |
| 217 | @end menu | 251 | @end menu |
| 218 | 252 | ||
| 219 | @node Major Mode Basics | ||
| 220 | @subsection Major Mode Basics | ||
| 221 | @cindex Fundamental mode | ||
| 222 | |||
| 223 | The least specialized major mode is called @dfn{Fundamental mode}. | ||
| 224 | This mode has no mode-specific definitions or variable settings, so each | ||
| 225 | Emacs command behaves in its default manner, and each option is in its | ||
| 226 | default state. All other major modes redefine various keys and options. | ||
| 227 | For example, Lisp Interaction mode provides special key bindings for | ||
| 228 | @kbd{C-j} (@code{eval-print-last-sexp}), @key{TAB} | ||
| 229 | (@code{lisp-indent-line}), and other keys. | ||
| 230 | |||
| 231 | When you need to write several editing commands to help you perform a | ||
| 232 | specialized editing task, creating a new major mode is usually a good | ||
| 233 | idea. In practice, writing a major mode is easy (in contrast to | ||
| 234 | writing a minor mode, which is often difficult). | ||
| 235 | |||
| 236 | If the new mode is similar to an old one, it is often unwise to | ||
| 237 | modify the old one to serve two purposes, since it may become harder | ||
| 238 | to use and maintain. Instead, copy and rename an existing major mode | ||
| 239 | definition and alter the copy---or use the @code{define-derived-mode} | ||
| 240 | macro to define a @dfn{derived mode} (@pxref{Derived Modes}). For | ||
| 241 | example, Rmail Edit mode is a major mode that is very similar to Text | ||
| 242 | mode except that it provides two additional commands. Its definition | ||
| 243 | is distinct from that of Text mode, but uses that of Text mode. | ||
| 244 | |||
| 245 | Even if the new mode is not an obvious derivative of any other mode, | ||
| 246 | we recommend to use @code{define-derived-mode}, since it automatically | ||
| 247 | enforces the most important coding conventions for you. | ||
| 248 | |||
| 249 | For a very simple programming language major mode that handles | ||
| 250 | comments and fontification, you can use @code{define-generic-mode}. | ||
| 251 | @xref{Generic Modes}. | ||
| 252 | |||
| 253 | Rmail Edit mode offers an example of changing the major mode | ||
| 254 | temporarily for a buffer, so it can be edited in a different way (with | ||
| 255 | ordinary Emacs commands rather than Rmail commands). In such cases, the | ||
| 256 | temporary major mode usually provides a command to switch back to the | ||
| 257 | buffer's usual mode (Rmail mode, in this case). You might be tempted to | ||
| 258 | present the temporary redefinitions inside a recursive edit and restore | ||
| 259 | the usual ones when the user exits; but this is a bad idea because it | ||
| 260 | constrains the user's options when it is done in more than one buffer: | ||
| 261 | recursive edits must be exited most-recently-entered first. Using an | ||
| 262 | alternative major mode avoids this limitation. @xref{Recursive | ||
| 263 | Editing}. | ||
| 264 | |||
| 265 | The standard GNU Emacs Lisp library directory tree contains the code | ||
| 266 | for several major modes, in files such as @file{text-mode.el}, | ||
| 267 | @file{texinfo.el}, @file{lisp-mode.el}, @file{c-mode.el}, and | ||
| 268 | @file{rmail.el}. They are found in various subdirectories of the | ||
| 269 | @file{lisp} directory. You can study these libraries to see how modes | ||
| 270 | are written. Text mode is perhaps the simplest major mode aside from | ||
| 271 | Fundamental mode. Rmail mode is a complicated and specialized mode. | ||
| 272 | |||
| 273 | @node Major Mode Conventions | 253 | @node Major Mode Conventions |
| 274 | @subsection Major Mode Conventions | 254 | @subsection Major Mode Conventions |
| 275 | @cindex major mode conventions | 255 | @cindex major mode conventions |
| 276 | @cindex conventions for writing major modes | 256 | @cindex conventions for writing major modes |
| 277 | 257 | ||
| 278 | The code for existing major modes follows various coding conventions, | 258 | The code for every major mode should follow various coding |
| 279 | including conventions for local keymap and syntax table initialization, | 259 | conventions, including conventions for local keymap and syntax table |
| 280 | global names, and hooks. Please follow these conventions when you | 260 | initialization, function and variable names, and hooks. |
| 281 | define a new major mode. (Fundamental mode is an exception to many | 261 | |
| 282 | of these conventions, because its definition is to present the global | 262 | If you use the @code{define-derived-mode} macro, it will take care of |
| 283 | state of Emacs.) | 263 | many of these conventions automatically. @xref{Derived Modes}. Note |
| 264 | also that fundamental mode is an exception to many of these conventions, | ||
| 265 | because its definition is to present the global state of Emacs. | ||
| 284 | 266 | ||
| 285 | This list of conventions is only partial, because each major mode | 267 | The following list of conventions is only partial. Each major mode |
| 286 | should aim for consistency in general with other Emacs major modes. | 268 | should aim for consistency in general with other Emacs major modes, as |
| 287 | This makes Emacs as a whole more coherent. It is impossible to list | 269 | this makes Emacs as a whole more coherent. It is impossible to list |
| 288 | here all the possible points where this issue might come up; if the | 270 | here all the possible points where this issue might come up; if the |
| 289 | Emacs developers point out an area where your major mode deviates from | 271 | Emacs developers point out an area where your major mode deviates from |
| 290 | the usual conventions, please make it compatible. | 272 | the usual conventions, please make it compatible. |
| 291 | 273 | ||
| 292 | @itemize @bullet | 274 | @itemize @bullet |
| 293 | @item | 275 | @item |
| 294 | Define a command whose name ends in @samp{-mode}, with no arguments, | 276 | Define a major mode command whose name ends in @samp{-mode}. When |
| 295 | that switches to the new mode in the current buffer. This command | 277 | called with no arguments, this command should switch to the new mode in |
| 296 | should set up the keymap, syntax table, and buffer-local variables in an | 278 | the current buffer by setting up the keymap, syntax table, and |
| 297 | existing buffer, without changing the buffer's contents. | 279 | buffer-local variables in an existing buffer. It should not change the |
| 280 | buffer's contents. | ||
| 298 | 281 | ||
| 299 | @item | 282 | @item |
| 300 | Write a documentation string for this command that describes the | 283 | Write a documentation string for this command that describes the special |
| 301 | special commands available in this mode. @kbd{C-h m} | 284 | commands available in this mode. @xref{Mode Help}. |
| 302 | (@code{describe-mode}) in your mode will display this string. | ||
| 303 | 285 | ||
| 304 | The documentation string may include the special documentation | 286 | The documentation string may include the special documentation |
| 305 | substrings, @samp{\[@var{command}]}, @samp{\@{@var{keymap}@}}, and | 287 | substrings, @samp{\[@var{command}]}, @samp{\@{@var{keymap}@}}, and |
| 306 | @samp{\<@var{keymap}>}, which enable the documentation to adapt | 288 | @samp{\<@var{keymap}>}, which allow the help display to adapt |
| 307 | automatically to the user's own key bindings. @xref{Keys in | 289 | automatically to the user's own key bindings. @xref{Keys in |
| 308 | Documentation}. | 290 | Documentation}. |
| 309 | 291 | ||
| @@ -527,10 +509,9 @@ mode when creating new buffers (@pxref{Auto Major Mode}), but with such | |||
| 527 | Dired, Rmail, and Buffer List use this feature. | 509 | Dired, Rmail, and Buffer List use this feature. |
| 528 | 510 | ||
| 529 | The @code{define-derived-mode} macro automatically marks the derived | 511 | The @code{define-derived-mode} macro automatically marks the derived |
| 530 | mode as special if the parent mode is special. The special mode | 512 | mode as special if the parent mode is special. Special mode is a |
| 531 | @code{special-mode} provides a convenient parent for other special | 513 | convenient parent for such modes to inherit from; @xref{Basic Major |
| 532 | modes to inherit from; it sets @code{buffer-read-only} to @code{t}, | 514 | Modes}. |
| 533 | and does little else. | ||
| 534 | 515 | ||
| 535 | @item | 516 | @item |
| 536 | If you want to make the new mode the default for files with certain | 517 | If you want to make the new mode the default for files with certain |
| @@ -564,16 +545,6 @@ Even if you never load the file more than once, someone else will. | |||
| 564 | automatically selects a major mode for the new buffer when a file is | 545 | automatically selects a major mode for the new buffer when a file is |
| 565 | visited. It also processes local variables specified in the file text. | 546 | visited. It also processes local variables specified in the file text. |
| 566 | 547 | ||
| 567 | @deffn Command fundamental-mode | ||
| 568 | Fundamental mode is a major mode that is not specialized for anything | ||
| 569 | in particular. Other major modes are defined in effect by comparison | ||
| 570 | with this one---their definitions say what to change, starting from | ||
| 571 | Fundamental mode. The @code{fundamental-mode} function does @emph{not} | ||
| 572 | run any mode hooks; you're not supposed to customize it. (If you want Emacs | ||
| 573 | to behave differently in Fundamental mode, change the @emph{global} | ||
| 574 | state of Emacs.) | ||
| 575 | @end deffn | ||
| 576 | |||
| 577 | @deffn Command normal-mode &optional find-file | 548 | @deffn Command normal-mode &optional find-file |
| 578 | This function establishes the proper major mode and buffer-local variable | 549 | This function establishes the proper major mode and buffer-local variable |
| 579 | bindings for the current buffer. First it calls @code{set-auto-mode} | 550 | bindings for the current buffer. First it calls @code{set-auto-mode} |
| @@ -599,23 +570,22 @@ by the default value of @code{major-mode} (see below). | |||
| 599 | 570 | ||
| 600 | @cindex file mode specification error | 571 | @cindex file mode specification error |
| 601 | @code{normal-mode} uses @code{condition-case} around the call to the | 572 | @code{normal-mode} uses @code{condition-case} around the call to the |
| 602 | major mode function, so errors are caught and reported as a @samp{File | 573 | major mode command, so errors are caught and reported as a @samp{File |
| 603 | mode specification error}, followed by the original error message. | 574 | mode specification error}, followed by the original error message. |
| 604 | @end deffn | 575 | @end deffn |
| 605 | 576 | ||
| 606 | @defun set-auto-mode &optional keep-mode-if-same | 577 | @defun set-auto-mode &optional keep-mode-if-same |
| 607 | @cindex visited file mode | 578 | @cindex visited file mode |
| 608 | This function selects the major mode that is appropriate for the | 579 | This function selects the major mode that is appropriate for the |
| 609 | current buffer. It bases its decision (in order of precedence) on | 580 | current buffer. It bases its decision (in order of precedence) on the |
| 610 | the @w{@samp{-*-}} line, on any @samp{mode:} local variable near the | 581 | @w{@samp{-*-}} line, on any @samp{mode:} local variable near the end of |
| 611 | end of a file, on the @w{@samp{#!}} line (using | 582 | a file, on the @w{@samp{#!}} line (using @code{interpreter-mode-alist}), |
| 612 | @code{interpreter-mode-alist}), on the text at the beginning of the | 583 | on the text at the beginning of the buffer (using |
| 613 | buffer (using @code{magic-mode-alist}), and finally on the visited | 584 | @code{magic-mode-alist}), and finally on the visited file name (using |
| 614 | file name (using @code{auto-mode-alist}). @xref{Choosing Modes, , How | 585 | @code{auto-mode-alist}). @xref{Choosing Modes, , How Major Modes are |
| 615 | Major Modes are Chosen, emacs, The GNU Emacs Manual}. | 586 | Chosen, emacs, The GNU Emacs Manual}. If @code{enable-local-variables} |
| 616 | If @code{enable-local-variables} is @code{nil}, @code{set-auto-mode} | 587 | is @code{nil}, @code{set-auto-mode} does not check the @w{@samp{-*-}} |
| 617 | does not check the @w{@samp{-*-}} line, or near the end of the file, | 588 | line, or near the end of the file, for any mode tag. |
| 618 | for any mode tag. | ||
| 619 | 589 | ||
| 620 | If @var{keep-mode-if-same} is non-@code{nil}, this function does not | 590 | If @var{keep-mode-if-same} is non-@code{nil}, this function does not |
| 621 | call the mode command if the buffer is already in the proper major | 591 | call the mode command if the buffer is already in the proper major |
| @@ -624,21 +594,6 @@ mode. For instance, @code{set-visited-file-name} sets this to | |||
| 624 | have set. | 594 | have set. |
| 625 | @end defun | 595 | @end defun |
| 626 | 596 | ||
| 627 | @defopt major-mode | ||
| 628 | The buffer-local value of this variable holds the major mode | ||
| 629 | currently active. The default value of this variable holds the | ||
| 630 | default major mode for new buffers. The standard default value is | ||
| 631 | @code{fundamental-mode}. | ||
| 632 | |||
| 633 | If the default value of @code{major-mode} is @code{nil}, Emacs uses | ||
| 634 | the (previously) current buffer's major mode as the default major mode | ||
| 635 | of a new buffer. However, if that major mode symbol has a @code{mode-class} | ||
| 636 | property with value @code{special}, then it is not used for new buffers; | ||
| 637 | Fundamental mode is used instead. The modes that have this property are | ||
| 638 | those such as Dired and Rmail that are useful only with text that has | ||
| 639 | been specially prepared. | ||
| 640 | @end defopt | ||
| 641 | |||
| 642 | @defun set-buffer-major-mode buffer | 597 | @defun set-buffer-major-mode buffer |
| 643 | This function sets the major mode of @var{buffer} to the default value of | 598 | This function sets the major mode of @var{buffer} to the default value of |
| 644 | @code{major-mode}; if that is @code{nil}, it uses the | 599 | @code{major-mode}; if that is @code{nil}, it uses the |
| @@ -745,18 +700,17 @@ init file.) | |||
| 745 | @cindex help for major mode | 700 | @cindex help for major mode |
| 746 | @cindex documentation for major mode | 701 | @cindex documentation for major mode |
| 747 | 702 | ||
| 748 | The @code{describe-mode} function is used to provide information | 703 | The @code{describe-mode} function is provides information about major |
| 749 | about major modes. It is normally called with @kbd{C-h m}. The | 704 | modes. It is normally bound to @kbd{C-h m}. It uses the value of the |
| 750 | @code{describe-mode} function uses the value of @code{major-mode}, | 705 | variable @code{major-mode} (which is why every major mode command needs |
| 751 | which is why every major mode function needs to set the | 706 | to set this variable). |
| 752 | @code{major-mode} variable. | ||
| 753 | 707 | ||
| 754 | @deffn Command describe-mode | 708 | @deffn Command describe-mode |
| 755 | This function displays the documentation of the current major mode. | 709 | This function displays the documentation of the current major mode. |
| 756 | 710 | ||
| 757 | The @code{describe-mode} function calls the @code{documentation} | 711 | The @code{describe-mode} function calls the @code{documentation} |
| 758 | function using the value of @code{major-mode} as an argument. Thus, it | 712 | function using the value of @code{major-mode} as an argument. Thus, it |
| 759 | displays the documentation string of the major mode function. | 713 | displays the documentation string of the major mode command. |
| 760 | (@xref{Accessing Documentation}.) | 714 | (@xref{Accessing Documentation}.) |
| 761 | @end deffn | 715 | @end deffn |
| 762 | 716 | ||
| @@ -772,11 +726,12 @@ documentation of the major mode. | |||
| 772 | @subsection Defining Derived Modes | 726 | @subsection Defining Derived Modes |
| 773 | @cindex derived mode | 727 | @cindex derived mode |
| 774 | 728 | ||
| 775 | The recommended way to define a new major mode is to derive it | 729 | The recommended way to define a new major mode is to derive it from an |
| 776 | from an existing one using @code{define-derived-mode}. If there is no | 730 | existing one using @code{define-derived-mode}. If there is no closely |
| 777 | closely related mode, you can inherit from @code{text-mode}, | 731 | related mode, you should inherit from either @code{text-mode}, |
| 778 | @code{special-mode}, @code{prog-mode}, or in the worst case | 732 | @code{special-mode}, or @code{prog-mode}. @xref{Basic Major Modes}. If |
| 779 | @code{fundamental-mode}. | 733 | none of these are suitable, you can inherit from @code{fundamental-mode} |
| 734 | (@pxref{Major Modes}). | ||
| 780 | 735 | ||
| 781 | @defmac define-derived-mode variant parent name docstring keyword-args@dots{} body@dots{} | 736 | @defmac define-derived-mode variant parent name docstring keyword-args@dots{} body@dots{} |
| 782 | This macro defines @var{variant} as a major mode command, using | 737 | This macro defines @var{variant} as a major mode command, using |
| @@ -877,6 +832,64 @@ Do not write an @code{interactive} spec in the definition; | |||
| 877 | @code{define-derived-mode} does that automatically. | 832 | @code{define-derived-mode} does that automatically. |
| 878 | @end defmac | 833 | @end defmac |
| 879 | 834 | ||
| 835 | @defun derived-mode-p &rest modes | ||
| 836 | This function returns non-@code{nil} if the current major mode is | ||
| 837 | derived from any of the major modes given by the symbols @var{modes}. | ||
| 838 | @end defun | ||
| 839 | |||
| 840 | @node Basic Major Modes | ||
| 841 | @subsection Basic Major Modes | ||
| 842 | |||
| 843 | Apart from Fundamental mode, there are three major modes that other | ||
| 844 | major modes commonly derive from: Text mode, Prog mode, and Special | ||
| 845 | mode. While Text mode is useful in its own right (e.g. for editing | ||
| 846 | files ending in @file{.txt}), Prog mode and Special mode exist mainly to | ||
| 847 | let other modes derive from them. | ||
| 848 | |||
| 849 | @vindex prog-mode-hook | ||
| 850 | As far as possible, new major modes should be derived, either directly | ||
| 851 | or indirectly, from one of these three modes. One reason is that this | ||
| 852 | allows users to customize a single mode hook | ||
| 853 | (e.g. @code{prog-mode-hook}) for an entire family of relevant modes | ||
| 854 | (e.g. all programming language modes). | ||
| 855 | |||
| 856 | @deffn Command text-mode | ||
| 857 | Text mode is a major mode for editing human languages. It defines the | ||
| 858 | @samp{"} and @samp{\} characters as having punctuation syntax | ||
| 859 | (@pxref{Syntax Class Table}), and binds @kbd{M-@key{TAB}} to | ||
| 860 | @code{ispell-complete-word} (@pxref{Spelling,,, emacs, The GNU Emacs | ||
| 861 | Manual}). | ||
| 862 | |||
| 863 | An example of a major mode derived from Text mode is HTML mode. | ||
| 864 | @xref{HTML Mode,,SGML and HTML Modes, emacs, The GNU Emacs Manual}. | ||
| 865 | @end deffn | ||
| 866 | |||
| 867 | @deffn Command prog-mode | ||
| 868 | Prog mode is a basic major mode for buffers containing programming | ||
| 869 | language source code. Most of the programming language major modes | ||
| 870 | built into Emacs are derived from it. | ||
| 871 | |||
| 872 | Prog mode binds @code{parse-sexp-ignore-comments} to @code{t} | ||
| 873 | (@pxref{Motion via Parsing}) and @code{bidi-paragraph-direction} to | ||
| 874 | @code{left-to-right} (@pxref{Bidirectional Display}). | ||
| 875 | @end deffn | ||
| 876 | |||
| 877 | @deffn Command special-mode | ||
| 878 | Special mode is a basic major mode for buffers containing text that is | ||
| 879 | produced specially by Emacs, rather than from a file. Major modes | ||
| 880 | derived from Special mode are given a @code{mode-class} property of | ||
| 881 | @code{special} (@pxref{Major Mode Conventions}). | ||
| 882 | |||
| 883 | Special mode sets the buffer to read-only. Its keymap defines several | ||
| 884 | common bindings, including @kbd{q} for @code{quit-window}, @kbd{z} for | ||
| 885 | @code{kill-this-buffer}, and @kbd{g} for @code{revert-buffer} | ||
| 886 | (@pxref{Reverting}). | ||
| 887 | |||
| 888 | An example of a major mode derived from Special mode is Buffer Menu | ||
| 889 | mode, which is used by the @samp{*Buffer List*} buffer. @xref{List | ||
| 890 | Buffers,,Listing Existing Buffers, emacs, The GNU Emacs Manual}. | ||
| 891 | @end deffn | ||
| 892 | |||
| 880 | @node Generic Modes | 893 | @node Generic Modes |
| 881 | @subsection Generic Modes | 894 | @subsection Generic Modes |
| 882 | @cindex generic mode | 895 | @cindex generic mode |
| @@ -921,7 +934,7 @@ before it runs the mode hook variable @code{@var{mode}-hook}. | |||
| 921 | @node Mode Hooks | 934 | @node Mode Hooks |
| 922 | @subsection Mode Hooks | 935 | @subsection Mode Hooks |
| 923 | 936 | ||
| 924 | Every major mode function should finish by running its mode hook and | 937 | Every major mode command should finish by running its mode hook and |
| 925 | the mode-independent normal hook @code{after-change-major-mode-hook}. | 938 | the mode-independent normal hook @code{after-change-major-mode-hook}. |
| 926 | It does this by calling @code{run-mode-hooks}. If the major mode is a | 939 | It does this by calling @code{run-mode-hooks}. If the major mode is a |
| 927 | derived mode, that is if it calls another major mode (the parent mode) | 940 | derived mode, that is if it calls another major mode (the parent mode) |
| @@ -966,7 +979,7 @@ construct. | |||
| 966 | 979 | ||
| 967 | @defvar after-change-major-mode-hook | 980 | @defvar after-change-major-mode-hook |
| 968 | This is a normal hook run by @code{run-mode-hooks}. It is run at the | 981 | This is a normal hook run by @code{run-mode-hooks}. It is run at the |
| 969 | very end of every properly-written major mode function. | 982 | very end of every properly-written major mode command. |
| 970 | @end defvar | 983 | @end defvar |
| 971 | 984 | ||
| 972 | @node Example Major Modes | 985 | @node Example Major Modes |
| @@ -1194,8 +1207,8 @@ And here is the code to set up the keymap for Lisp mode: | |||
| 1194 | @end group | 1207 | @end group |
| 1195 | @end smallexample | 1208 | @end smallexample |
| 1196 | 1209 | ||
| 1197 | Finally, here is the complete major mode function definition for | 1210 | Finally, here is the complete major mode command definition for Lisp |
| 1198 | Lisp mode. | 1211 | mode. |
| 1199 | 1212 | ||
| 1200 | @smallexample | 1213 | @smallexample |
| 1201 | @group | 1214 | @group |
| @@ -2752,10 +2765,10 @@ highlighting patterns. See the variables | |||
| 2752 | @code{c-font-lock-extra-types}, @code{c++-font-lock-extra-types}, | 2765 | @code{c-font-lock-extra-types}, @code{c++-font-lock-extra-types}, |
| 2753 | and @code{java-font-lock-extra-types}, for example. | 2766 | and @code{java-font-lock-extra-types}, for example. |
| 2754 | 2767 | ||
| 2755 | @strong{Warning:} major mode functions must not call | 2768 | @strong{Warning:} major mode commands must not call |
| 2756 | @code{font-lock-add-keywords} under any circumstances, either directly | 2769 | @code{font-lock-add-keywords} under any circumstances, either directly |
| 2757 | or indirectly, except through their mode hooks. (Doing so would lead | 2770 | or indirectly, except through their mode hooks. (Doing so would lead to |
| 2758 | to incorrect behavior for some minor modes.) They should set up their | 2771 | incorrect behavior for some minor modes.) They should set up their |
| 2759 | rules for search-based fontification by setting | 2772 | rules for search-based fontification by setting |
| 2760 | @code{font-lock-keywords}. | 2773 | @code{font-lock-keywords}. |
| 2761 | @end defun | 2774 | @end defun |
diff --git a/doc/lispref/vol1.texi b/doc/lispref/vol1.texi index 3b7718814b5..c192e3bf4b7 100644 --- a/doc/lispref/vol1.texi +++ b/doc/lispref/vol1.texi | |||
| @@ -786,8 +786,7 @@ Major and Minor Modes | |||
| 786 | * Major Modes:: Defining major modes. | 786 | * Major Modes:: Defining major modes. |
| 787 | * Minor Modes:: Defining minor modes. | 787 | * Minor Modes:: Defining minor modes. |
| 788 | * Mode Line Format:: Customizing the text that appears in the mode line. | 788 | * Mode Line Format:: Customizing the text that appears in the mode line. |
| 789 | * Imenu:: How a mode can provide a menu | 789 | * Imenu:: Providing a menu of definitions made in a buffer. |
| 790 | of definitions in the buffer. | ||
| 791 | * Font Lock Mode:: How modes can highlight text according to syntax. | 790 | * Font Lock Mode:: How modes can highlight text according to syntax. |
| 792 | * Desktop Save Mode:: How modes can have buffer state saved between | 791 | * Desktop Save Mode:: How modes can have buffer state saved between |
| 793 | Emacs sessions. | 792 | Emacs sessions. |
| @@ -799,15 +798,15 @@ Hooks | |||
| 799 | 798 | ||
| 800 | Major Modes | 799 | Major Modes |
| 801 | 800 | ||
| 802 | * Major Mode Basics:: | ||
| 803 | * Major Mode Conventions:: Coding conventions for keymaps, etc. | 801 | * Major Mode Conventions:: Coding conventions for keymaps, etc. |
| 804 | * Auto Major Mode:: How Emacs chooses the major mode automatically. | 802 | * Auto Major Mode:: How Emacs chooses the major mode automatically. |
| 805 | * Mode Help:: Finding out how to use a mode. | 803 | * Mode Help:: Finding out how to use a mode. |
| 806 | * Derived Modes:: Defining a new major mode based on another major | 804 | * Derived Modes:: Defining a new major mode based on another major |
| 807 | mode. | 805 | mode. |
| 806 | * Basic Major Modes:: Modes that other modes are often derived from. | ||
| 808 | * Generic Modes:: Defining a simple major mode that supports | 807 | * Generic Modes:: Defining a simple major mode that supports |
| 809 | comment syntax and Font Lock mode. | 808 | comment syntax and Font Lock mode. |
| 810 | * Mode Hooks:: Hooks run at the end of major mode functions. | 809 | * Mode Hooks:: Hooks run at the end of major mode commands. |
| 811 | * Example Major Modes:: Text mode and Lisp modes. | 810 | * Example Major Modes:: Text mode and Lisp modes. |
| 812 | 811 | ||
| 813 | Minor Modes | 812 | Minor Modes |
diff --git a/doc/lispref/vol2.texi b/doc/lispref/vol2.texi index 22a51d3235c..8e78a5fb5ca 100644 --- a/doc/lispref/vol2.texi +++ b/doc/lispref/vol2.texi | |||
| @@ -785,8 +785,7 @@ Major and Minor Modes | |||
| 785 | * Major Modes:: Defining major modes. | 785 | * Major Modes:: Defining major modes. |
| 786 | * Minor Modes:: Defining minor modes. | 786 | * Minor Modes:: Defining minor modes. |
| 787 | * Mode Line Format:: Customizing the text that appears in the mode line. | 787 | * Mode Line Format:: Customizing the text that appears in the mode line. |
| 788 | * Imenu:: How a mode can provide a menu | 788 | * Imenu:: Providing a menu of definitions made in a buffer. |
| 789 | of definitions in the buffer. | ||
| 790 | * Font Lock Mode:: How modes can highlight text according to syntax. | 789 | * Font Lock Mode:: How modes can highlight text according to syntax. |
| 791 | * Desktop Save Mode:: How modes can have buffer state saved between | 790 | * Desktop Save Mode:: How modes can have buffer state saved between |
| 792 | Emacs sessions. | 791 | Emacs sessions. |
| @@ -798,15 +797,15 @@ Hooks | |||
| 798 | 797 | ||
| 799 | Major Modes | 798 | Major Modes |
| 800 | 799 | ||
| 801 | * Major Mode Basics:: | ||
| 802 | * Major Mode Conventions:: Coding conventions for keymaps, etc. | 800 | * Major Mode Conventions:: Coding conventions for keymaps, etc. |
| 803 | * Auto Major Mode:: How Emacs chooses the major mode automatically. | 801 | * Auto Major Mode:: How Emacs chooses the major mode automatically. |
| 804 | * Mode Help:: Finding out how to use a mode. | 802 | * Mode Help:: Finding out how to use a mode. |
| 805 | * Derived Modes:: Defining a new major mode based on another major | 803 | * Derived Modes:: Defining a new major mode based on another major |
| 806 | mode. | 804 | mode. |
| 805 | * Basic Major Modes:: Modes that other modes are often derived from. | ||
| 807 | * Generic Modes:: Defining a simple major mode that supports | 806 | * Generic Modes:: Defining a simple major mode that supports |
| 808 | comment syntax and Font Lock mode. | 807 | comment syntax and Font Lock mode. |
| 809 | * Mode Hooks:: Hooks run at the end of major mode functions. | 808 | * Mode Hooks:: Hooks run at the end of major mode commands. |
| 810 | * Example Major Modes:: Text mode and Lisp modes. | 809 | * Example Major Modes:: Text mode and Lisp modes. |
| 811 | 810 | ||
| 812 | Minor Modes | 811 | Minor Modes |