comparison lispref/modes.texi @ 17278:8ed8412c1ce7

Document key binding conventions for major modes and minor modes.
author Richard M. Stallman <rms@gnu.org>
date Tue, 01 Apr 1997 23:35:50 +0000
parents 6f58503776e5
children 66d807bdc5b4
comparison
equal deleted inserted replaced
17277:6ee6f94817dc 17278:8ed8412c1ce7
127 @item 127 @item
128 @cindex functions in modes 128 @cindex functions in modes
129 Since all global names are in the same name space, all the global 129 Since all global names are in the same name space, all the global
130 variables, constants, and functions that are part of the mode should 130 variables, constants, and functions that are part of the mode should
131 have names that start with the major mode name (or with an abbreviation 131 have names that start with the major mode name (or with an abbreviation
132 of it if the name is long). @xref{Style Tips}. 132 of it if the name is long). @xref{Coding Conventions}.
133 133
134 @item 134 @item
135 @cindex keymaps in modes 135 @cindex keymaps in modes
136 The major mode should usually have its own keymap, which is used as the 136 The major mode should usually have its own keymap, which is used as the
137 local keymap in all buffers in that mode. The major mode function 137 local keymap in all buffers in that mode. The major mode function
142 @code{@var{modename}-mode-map}. Normally the library that defines the 142 @code{@var{modename}-mode-map}. Normally the library that defines the
143 mode sets this variable. 143 mode sets this variable.
144 144
145 @xref{Tips for Defining}, for advice about how to write the code to set 145 @xref{Tips for Defining}, for advice about how to write the code to set
146 up the mode's keymap variable. 146 up the mode's keymap variable.
147
148 @item
149 The key sequences bound in a major mode keymap should usually start with
150 @kbd{C-c}, followed by a control-character, a digit, or @kbd{@{},
151 @kbd{@}}, @kbd{<}, @kbd{>}, @kbd{:} or @kbd{;}. The other punctuation
152 characters are reserved for minor modes, and ordinary letters are
153 reserved for users.
154
155 It is reasonable for a major mode to rebind a key sequence with a
156 standard meaning, if it implements a command that does ``the same job''
157 in a way that fits the major mode better. For example, a major mode for
158 editing a programming language might redefine @kbd{C-M-a} to ``move to
159 the beginning of a function'' in a way that works better for that
160 language.
161
162 Major modes such as Dired or Rmail that do not allow self-insertion of
163 text can reasonably redefine letters and other printing characters as
164 editing commands. Dired and Rmail both do this.
147 165
148 @item 166 @item
149 @cindex syntax tables in modes 167 @cindex syntax tables in modes
150 The mode may have its own syntax table or may share one with other 168 The mode may have its own syntax table or may share one with other
151 related modes. If it has its own syntax table, it should store this in 169 related modes. If it has its own syntax table, it should store this in
199 @cindex mode hook 217 @cindex mode hook
200 @cindex major mode hook 218 @cindex major mode hook
201 Each major mode should have a @dfn{mode hook} named 219 Each major mode should have a @dfn{mode hook} named
202 @code{@var{modename}-mode-hook}. The major mode command should run that 220 @code{@var{modename}-mode-hook}. The major mode command should run that
203 hook, with @code{run-hooks}, as the very last thing it 221 hook, with @code{run-hooks}, as the very last thing it
204 does. @xref{Hooks}. 222 does. @xref{Hooks}.
205 223
206 @item 224 @item
207 The major mode command may also run the hooks of some more basic modes. 225 The major mode command may also run the hooks of some more basic modes.
208 For example, @code{indented-text-mode} runs @code{text-mode-hook} as 226 For example, @code{indented-text-mode} runs @code{text-mode-hook} as
209 well as @code{indented-text-mode-hook}. It may run these other hooks 227 well as @code{indented-text-mode-hook}. It may run these other hooks
892 facilities for customizing @code{self-insert-command} are limited to 910 facilities for customizing @code{self-insert-command} are limited to
893 special cases (designed for abbrevs and Auto Fill mode). (Do not try 911 special cases (designed for abbrevs and Auto Fill mode). (Do not try
894 substituting your own definition of @code{self-insert-command} for the 912 substituting your own definition of @code{self-insert-command} for the
895 standard one. The editor command loop handles this function specially.) 913 standard one. The editor command loop handles this function specially.)
896 914
915 The key sequences bound in a minor mode should consist of @kbd{C-c}
916 followed by a punctuation character @emph{other than} @kbd{@{},
917 @kbd{@}}, @kbd{<}, @kbd{>}, @kbd{:} or @kbd{;}. (Those few punctuation
918 characters are reserved for major modes.)
919
897 @node Mode Line Format 920 @node Mode Line Format
898 @section Mode Line Format 921 @section Mode Line Format
899 @cindex mode line 922 @cindex mode line
900 923
901 Each Emacs window (aside from minibuffer windows) includes a mode line, 924 Each Emacs window (aside from minibuffer windows) includes a mode line,