diff options
| author | Chong Yidong | 2008-11-17 16:39:04 +0000 |
|---|---|---|
| committer | Chong Yidong | 2008-11-17 16:39:04 +0000 |
| commit | d85f75e285f5e78174c618e705f682b0acf059c0 (patch) | |
| tree | f2255e9454c81a7382c4046ec1ed87a614334f50 | |
| parent | 696f351d5adaf8dc62f0c6a9c23e8acd33688c74 (diff) | |
| download | emacs-d85f75e285f5e78174c618e705f682b0acf059c0.tar.gz emacs-d85f75e285f5e78174c618e705f682b0acf059c0.zip | |
(Minor Modes): Define mode commands and mode variables more precisely.
Recommend using mode commands instead of setting variables directly.
Put minor modes in a list, and add more modes.
| -rw-r--r-- | doc/emacs/custom.texi | 261 |
1 files changed, 132 insertions, 129 deletions
diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi index a78d66808cd..e01dbd1309b 100644 --- a/doc/emacs/custom.texi +++ b/doc/emacs/custom.texi | |||
| @@ -6,33 +6,24 @@ | |||
| 6 | @chapter Customization | 6 | @chapter Customization |
| 7 | @cindex customization | 7 | @cindex customization |
| 8 | 8 | ||
| 9 | This chapter talks about various topics relevant to adapting the | 9 | This chapter describes some simple methods to customize the behavior |
| 10 | behavior of Emacs in ways we have anticipated. | 10 | of Emacs. |
| 11 | |||
| 12 | Apart from the methods described here, see @ref{X Resources} for | ||
| 13 | information about using X resources to customize Emacs, and see | ||
| 14 | @ref{Keyboard Macros} for information about recording and replaying | ||
| 15 | keyboard macros. Making more far-reaching and open-ended changes | ||
| 16 | involves writing Emacs Lisp code; see | ||
| 11 | @iftex | 17 | @iftex |
| 12 | See @cite{The Emacs Lisp Reference Manual} | 18 | @cite{The Emacs Lisp Reference Manual}. |
| 13 | @end iftex | 19 | @end iftex |
| 14 | @ifnottex | 20 | @ifnottex |
| 15 | @xref{Top, Emacs Lisp, Emacs Lisp, elisp, The Emacs Lisp | 21 | @ref{Top, Emacs Lisp, Emacs Lisp, elisp, The Emacs Lisp |
| 16 | Reference Manual}, | 22 | Reference Manual}. |
| 17 | @end ifnottex | 23 | @end ifnottex |
| 18 | for how to make more far-reaching and open-ended changes. @xref{X | ||
| 19 | Resources}, for information on using X resources to customize Emacs. | ||
| 20 | |||
| 21 | Customization that you do within Emacs normally affects only the | ||
| 22 | particular Emacs session that you do it in---it does not persist | ||
| 23 | between sessions unless you save the customization in a file such as | ||
| 24 | your init file (@file{.emacs}) that will affect future sessions. | ||
| 25 | (@xref{Init File}.) When you tell the customization buffer to save | ||
| 26 | customizations for future sessions, this actually works by editing | ||
| 27 | @file{.emacs} for you. | ||
| 28 | |||
| 29 | Another means of customization is the keyboard macro, which is a | ||
| 30 | sequence of keystrokes to be replayed with a single command. | ||
| 31 | @xref{Keyboard Macros}, for full instruction how to record, manage, and | ||
| 32 | replay sequences of keys. | ||
| 33 | 24 | ||
| 34 | @menu | 25 | @menu |
| 35 | * Minor Modes:: Each minor mode is one feature you can turn on | 26 | * Minor Modes:: Each minor mode is a feature you can turn on |
| 36 | independently of any others. | 27 | independently of any others. |
| 37 | * Easy Customization:: Convenient way to browse and change settings. | 28 | * Easy Customization:: Convenient way to browse and change settings. |
| 38 | * Variables:: Many Emacs commands examine Emacs variables | 29 | * Variables:: Many Emacs commands examine Emacs variables |
| @@ -52,136 +43,148 @@ replay sequences of keys. | |||
| 52 | @cindex mode, minor | 43 | @cindex mode, minor |
| 53 | 44 | ||
| 54 | Minor modes are optional features which you can turn on or off. For | 45 | Minor modes are optional features which you can turn on or off. For |
| 55 | example, Auto Fill mode is a minor mode in which @key{SPC} breaks lines | 46 | example, Auto Fill mode is a minor mode in which @key{SPC} breaks |
| 56 | between words as you type. All the minor modes are independent of each | 47 | lines between words as you type. Minor modes are independent of one |
| 57 | other and of the selected major mode. Most minor modes say in the mode | 48 | another and of the selected major mode. Most minor modes say in the |
| 58 | line when they are enabled; for example, @samp{Fill} in the mode line means | 49 | mode line when they are enabled; for example, @samp{Fill} in the mode |
| 59 | that Auto Fill mode is enabled. | 50 | line means that Auto Fill mode is enabled. |
| 60 | 51 | ||
| 61 | You should append @code{-mode} to the name of a minor mode to | 52 | Each minor mode is associated with a command, called the @dfn{mode |
| 62 | produce the name of the command that turns the mode on or off. Thus, | 53 | command}, which turns it on or off. The name of this command consists |
| 63 | the command to enable or disable Auto Fill mode is called | 54 | of the name of the minor mode, followed by @samp{-mode}; for instance, |
| 64 | @code{auto-fill-mode}. These commands are usually invoked with | 55 | the mode command for Auto Fill mode is @code{auto-fill-mode}. Calling |
| 65 | @kbd{M-x}, but you can bind keys to them if you wish. | 56 | the minor mode command with no prefix argument @dfn{toggles} the mode, |
| 66 | 57 | turning it on if it was off, and off if it was on. A positive | |
| 67 | With no argument, the minor mode function turns the mode on if it | 58 | argument always turns the mode on, and a zero or negative argument |
| 68 | was off, and off if it was on. This is known as @dfn{toggling}. A | 59 | always turns it off. Mode commands are usually invoked with |
| 69 | positive argument always turns the mode on, and an explicit zero | 60 | @kbd{M-x}, but you can bind keys to them if you wish (@pxref{Key |
| 70 | argument or a negative argument always turns it off. | 61 | Bindings}). |
| 71 | 62 | ||
| 72 | Some minor modes are global: while enabled, they affect everything | 63 | Most minor modes also have a @dfn{mode variable}, with the same name |
| 73 | you do in the Emacs session, in all buffers. Other minor modes are | 64 | as the mode command. Its value is non-@code{nil} if the mode is |
| 74 | buffer-local; they apply only to the current buffer, so you can enable | 65 | enabled, and @code{nil} if it is disabled. In some minor modes---but |
| 75 | the mode in certain buffers and not others. | 66 | not all---the value of the variable alone determines whether the mode |
| 76 | 67 | is active: the mode command works simply by setting the variable, and | |
| 77 | For most minor modes, the command name is also the name of a | 68 | changing the value of the variable has the same effect as calling the |
| 78 | variable. The variable's value is non-@code{nil} if the mode is | 69 | mode command. Because not all minor modes work this way, we recommend |
| 79 | enabled and @code{nil} if it is disabled. Some minor-mode commands | 70 | that you avoid changing the mode variables directly; use the mode |
| 80 | work by just setting the variable. For example, the command | 71 | commands instead. |
| 81 | @code{abbrev-mode} works by setting the value of @code{abbrev-mode} as | 72 | |
| 82 | a variable; it is this variable that directly turns Abbrev mode on and | 73 | Some minor modes are buffer-local; they apply only to the current |
| 83 | off. You can directly set the variable's value instead of calling the | 74 | buffer, so you can enable the mode in certain buffers and not others. |
| 84 | mode function. For other minor modes, you need to either set the | 75 | Other minor modes are global: while enabled, they affect everything |
| 85 | variable through the Customize interface or call the mode function to | 76 | you do in the Emacs session, in all buffers. Some global minor modes |
| 86 | correctly enable or disable the mode. To check which of these two | 77 | are enabled by default. |
| 87 | possibilities applies to a given minor mode, use @kbd{C-h v} to ask | 78 | |
| 88 | for documentation on the variable name. | 79 | The following is a list of some buffer-local minor modes: |
| 89 | 80 | ||
| 90 | For minor mode commands that work by just setting the minor mode | 81 | @itemize @bullet |
| 91 | variable, that variable provides a good way for Lisp programs to turn | 82 | @item |
| 92 | minor modes on and off; it is also useful in a file's local variables | 83 | Abbrev mode automatically expands text based on pre-defined |
| 93 | list (@pxref{File Variables}). But please think twice before setting | 84 | abbreviation definitions. @xref{Abbrevs}. |
| 94 | minor modes with a local variables list, because most minor modes are | 85 | |
| 95 | a matter of user preference---other users editing the same file might | 86 | @item |
| 96 | not want the same minor modes you prefer. | 87 | Auto Fill mode inserts newlines as you type to prevent lines from |
| 97 | |||
| 98 | The most useful buffer-local minor modes include Abbrev mode, Auto | ||
| 99 | Fill mode, Auto Save mode, Font-Lock mode, Glasses mode, Outline minor | ||
| 100 | mode, Overwrite mode, and Binary Overwrite mode. | ||
| 101 | |||
| 102 | Abbrev mode allows you to define abbreviations that automatically expand | ||
| 103 | as you type them. For example, @samp{amd} might expand to @samp{abbrev | ||
| 104 | mode}. @xref{Abbrevs}, for full information. | ||
| 105 | |||
| 106 | Auto Fill mode allows you to enter filled text without breaking lines | ||
| 107 | explicitly. Emacs inserts newlines as necessary to prevent lines from | ||
| 108 | becoming too long. @xref{Filling}. | 88 | becoming too long. @xref{Filling}. |
| 109 | 89 | ||
| 110 | Auto Save mode saves the buffer contents periodically to reduce the | 90 | @item |
| 91 | Auto Save mode saves the buffer contents periodically to reduce the | ||
| 111 | amount of work you can lose in case of a crash. @xref{Auto Save}. | 92 | amount of work you can lose in case of a crash. @xref{Auto Save}. |
| 112 | 93 | ||
| 113 | Enriched mode enables editing and saving of formatted text. | 94 | @item |
| 95 | Enriched mode enables editing and saving of formatted text. | ||
| 114 | @xref{Formatted Text}. | 96 | @xref{Formatted Text}. |
| 115 | 97 | ||
| 116 | Flyspell mode automatically highlights misspelled words. | 98 | @item |
| 99 | Flyspell mode automatically highlights misspelled words. | ||
| 117 | @xref{Spelling}. | 100 | @xref{Spelling}. |
| 118 | 101 | ||
| 119 | Font-Lock mode automatically highlights certain textual units found | 102 | @item |
| 120 | in programs, such as comments, strings, and function names being | 103 | Font-Lock mode automatically highlights certain textual units found in |
| 121 | defined. This requires a display that can show multiple fonts or | 104 | programs. It is enabled globally by default, but you can disable it |
| 122 | colors. @xref{Faces}. | 105 | in individual buffers. @xref{Faces}. |
| 123 | 106 | ||
| 124 | @ignore | 107 | @findex linum-mode |
| 125 | ISO Accents mode makes the characters @samp{`}, @samp{'}, @samp{"}, | 108 | @cindex Linum mode |
| 126 | @samp{^}, @samp{/} and @samp{~} combine with the following letter, to | 109 | @item |
| 127 | produce an accented letter in the ISO Latin-1 character set. The | 110 | Linum mode displays each line's line number in the window's left |
| 128 | newer and more general feature of input methods more or less | 111 | margin. Its mode command is @code{linum-mode}. |
| 129 | supersedes ISO Accents mode. @xref{Unibyte Mode}. | ||
| 130 | @end ignore | ||
| 131 | 112 | ||
| 132 | Outline minor mode provides the same facilities as the major mode | 113 | @item |
| 133 | called Outline mode; but since it is a minor mode instead, you can | 114 | Outline minor mode provides similar facilities to the major mode |
| 134 | combine it with any major mode. @xref{Outline Mode}. | 115 | called Outline mode. @xref{Outline Mode}. |
| 135 | 116 | ||
| 136 | @cindex Overwrite mode | 117 | @cindex Overwrite mode |
| 137 | @cindex mode, Overwrite | 118 | @cindex mode, Overwrite |
| 138 | Overwrite mode causes ordinary printing characters to replace existing | ||
| 139 | text instead of shoving it to the right. For example, if point is in | ||
| 140 | front of the @samp{B} in @samp{FOOBAR}, then in Overwrite mode typing a | ||
| 141 | @kbd{G} changes it to @samp{FOOGAR}, instead of producing @samp{FOOGBAR} | ||
| 142 | as usual. In Overwrite mode, the command @kbd{C-q} inserts the next | ||
| 143 | character whatever it may be, even if it is a digit---this gives you a | ||
| 144 | way to insert a character instead of replacing an existing character. | ||
| 145 | |||
| 146 | @findex overwrite-mode | 119 | @findex overwrite-mode |
| 147 | @kindex INSERT | 120 | @kindex INSERT |
| 148 | The command @code{overwrite-mode} is an exception to the rule that | 121 | @item |
| 149 | commands which toggle minor modes are normally not bound to keys: it is | 122 | Overwrite mode causes ordinary printing characters to replace existing |
| 150 | bound to the @key{INSERT} function key. This is because many other | 123 | text instead of shoving it to the right. For example, if point is in |
| 151 | programs bind @key{INSERT} to similar functions. | 124 | front of the @samp{B} in @samp{FOOBAR}, then in Overwrite mode typing |
| 125 | a @kbd{G} changes it to @samp{FOOGAR}, instead of producing | ||
| 126 | @samp{FOOGBAR} as usual. In Overwrite mode, the command @kbd{C-q} | ||
| 127 | inserts the next character whatever it may be, even if it is a | ||
| 128 | digit---this gives you a way to insert a character instead of | ||
| 129 | replacing an existing character. The mode command, | ||
| 130 | @code{overwrite-mode}, is bound to the @key{Insert} key. | ||
| 152 | 131 | ||
| 153 | @findex binary-overwrite-mode | 132 | @findex binary-overwrite-mode |
| 154 | Binary Overwrite mode is a variant of Overwrite mode for editing | 133 | @item |
| 155 | binary files; it treats newlines and tabs like other characters, so that | 134 | Binary Overwrite mode is a variant of Overwrite mode for editing |
| 156 | they overwrite other characters and can be overwritten by them. | 135 | binary files; it treats newlines and tabs like other characters, so |
| 157 | In Binary Overwrite mode, digits after @kbd{C-q} specify an | 136 | that they overwrite other characters and can be overwritten by them. |
| 158 | octal character code, as usual. | 137 | In Binary Overwrite mode, digits after @kbd{C-q} specify an octal |
| 159 | 138 | character code, as usual. | |
| 160 | Here are some useful minor modes that normally apply to all buffers | 139 | |
| 161 | at once. Since Line Number mode and Transient Mark mode can be | 140 | @item |
| 162 | enabled or disabled just by setting the value of the minor mode | 141 | Visual Line mode performs ``word wrapping'', causing long lines to be |
| 163 | variable, you @emph{can} set them differently for particular buffers, | 142 | wrapped at word boundaries. @xref{Visual Line Mode}. |
| 164 | by explicitly making the corresponding variable local in those | 143 | @end itemize |
| 165 | buffers. @xref{Locals}. | 144 | |
| 166 | 145 | Here are some useful global minor modes. Since Line Number mode and | |
| 167 | Icomplete mode displays an indication of available completions when | 146 | Transient Mark mode can be enabled or disabled just by setting the |
| 147 | value of the minor mode variable, you @emph{can} set them differently | ||
| 148 | for particular buffers, by explicitly making the corresponding | ||
| 149 | variable local in those buffers. @xref{Locals}. | ||
| 150 | |||
| 151 | @itemize @bullet | ||
| 152 | @item | ||
| 153 | Column Number mode enables display of the current column number in the | ||
| 154 | mode line. @xref{Mode Line}. | ||
| 155 | |||
| 156 | @item | ||
| 157 | Delete Selection mode causes text insertion to first delete the text | ||
| 158 | in the region, if the region is active. @xref{Using Region}. | ||
| 159 | |||
| 160 | @item | ||
| 161 | Icomplete mode displays an indication of available completions when | ||
| 168 | you are in the minibuffer and completion is active. @xref{Completion | 162 | you are in the minibuffer and completion is active. @xref{Completion |
| 169 | Options}. | 163 | Options}. |
| 170 | 164 | ||
| 171 | Line Number mode enables continuous display in the mode line of the | 165 | @item |
| 172 | line number of point, and Column Number mode enables display of the | 166 | Line Number mode enables display of the current line number in the |
| 173 | column number. @xref{Mode Line}. | 167 | mode line. It is enabled by default. @xref{Mode Line}. |
| 174 | 168 | ||
| 175 | Scroll Bar mode gives each window a scroll bar (@pxref{Scroll Bars}). | 169 | @item |
| 176 | Menu Bar mode gives each frame a menu bar (@pxref{Menu Bars}). Both of | 170 | Menu Bar mode gives each frame a menu bar. It is enabled by default. |
| 177 | these modes are enabled by default when you use the X Window System. | 171 | @xref{Menu Bars}. |
| 172 | |||
| 173 | @item | ||
| 174 | Scroll Bar mode gives each window a scroll bar. It is enabled by | ||
| 175 | default, but the scroll bar is only displayed on graphical terminals. | ||
| 176 | @xref{Scroll Bars}. | ||
| 178 | 177 | ||
| 179 | In Transient Mark mode, every change in the buffer contents | 178 | @item |
| 180 | ``deactivates'' the mark, so that commands that operate on the region | 179 | Tool Bar mode gives each frame a tool bar. It is enabled by default, |
| 181 | will get an error. This means you must either set the mark, or | 180 | but the tool bar is only displayed on graphical terminals. @xref{Tool |
| 182 | explicitly ``reactivate'' it, before each command that uses the region. | 181 | Bars}. |
| 183 | The advantage of Transient Mark mode is that Emacs can display the | 182 | |
| 184 | region highlighted. @xref{Mark}. | 183 | @item |
| 184 | Transient Mark mode highlights the region, and makes many Emacs | ||
| 185 | commands operate on the region when the mark is active. It is enabled | ||
| 186 | by default. @xref{Mark}. | ||
| 187 | @end itemize | ||
| 185 | 188 | ||
| 186 | @node Easy Customization | 189 | @node Easy Customization |
| 187 | @section Easy Customization Interface | 190 | @section Easy Customization Interface |