Mercurial > emacs
comparison lispref/tips.texi @ 60273:a0cca815ceaa
(Coding Conventions): Clarify.
Put all the major mode key reservations together.
Mention the Mouse-1 => Mouse-2 conventions.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 27 Feb 2005 00:14:20 +0000 |
parents | 7c9759696709 |
children | 0b041af08b4a e4694597cbf4 |
comparison
equal
deleted
inserted
replaced
60272:881cc84dd099 | 60273:a0cca815ceaa |
---|---|
44 outweigh the costs.} Then take care to begin the names of all global | 44 outweigh the costs.} Then take care to begin the names of all global |
45 variables, constants, and functions in your program with the chosen | 45 variables, constants, and functions in your program with the chosen |
46 prefix. This helps avoid name conflicts. | 46 prefix. This helps avoid name conflicts. |
47 | 47 |
48 This recommendation applies even to names for traditional Lisp | 48 This recommendation applies even to names for traditional Lisp |
49 primitives that are not primitives in Emacs Lisp---even to | 49 primitives that are not primitives in Emacs Lisp---such as |
50 @code{copy-list}. Believe it or not, there is more than one plausible | 50 @code{copy-list}. Believe it or not, there is more than one plausible |
51 way to define @code{copy-list}. Play it safe; append your name prefix | 51 way to define @code{copy-list}. Play it safe; append your name prefix |
52 to produce a name like @code{foo-copy-list} or @code{mylib-copy-list} | 52 to produce a name like @code{foo-copy-list} or @code{mylib-copy-list} |
53 instead. | 53 instead. |
54 | 54 |
99 run time. Use of this package is optional, and it is not part of the | 99 run time. Use of this package is optional, and it is not part of the |
100 standard Emacs namespace. If your package loads @code{cl} at run time, | 100 standard Emacs namespace. If your package loads @code{cl} at run time, |
101 that could cause name clashes for users who don't use that package. | 101 that could cause name clashes for users who don't use that package. |
102 | 102 |
103 However, there is no problem with using the @code{cl} package at compile | 103 However, there is no problem with using the @code{cl} package at compile |
104 time, for the sake of macros. You do that like this: | 104 time, with @code{(eval-when-compile (require 'cl))}. |
105 | |
106 @example | |
107 (eval-when-compile (require 'cl)) | |
108 @end example | |
109 | 105 |
110 @item | 106 @item |
111 When defining a major mode, please follow the major mode | 107 When defining a major mode, please follow the major mode |
112 conventions. @xref{Major Mode Conventions}. | 108 conventions. @xref{Major Mode Conventions}. |
113 | 109 |
132 follow the naming conventions for hooks. @xref{Hooks}. | 128 follow the naming conventions for hooks. @xref{Hooks}. |
133 | 129 |
134 @item | 130 @item |
135 @cindex reserved keys | 131 @cindex reserved keys |
136 @cindex keys, reserved | 132 @cindex keys, reserved |
137 Please do not define @kbd{C-c @var{letter}} as a key in your major | 133 Please do not define @kbd{C-c @var{letter}} as a key in Lisp programs. |
138 modes. Sequences consisting of @kbd{C-c} and a letter (either upper | 134 Sequences consisting of @kbd{C-c} and a letter (either upper or lower |
139 or lower case) are reserved for users; they are the @strong{only} | 135 case) are reserved for users; they are the @strong{only} sequences |
140 sequences reserved for users, so do not block them. | 136 reserved for users, so do not block them. |
141 | 137 |
142 Changing all the Emacs major modes to respect this convention was a | 138 Changing all the Emacs major modes to respect this convention was a |
143 lot of work; abandoning this convention would make that work go to | 139 lot of work; abandoning this convention would make that work go to |
144 waste, and inconvenience users. Please comply with it. | 140 waste, and inconvenience users. Please comply with it. |
141 | |
142 @item | |
143 Function keys @key{F5} through @key{F9} without modifier keys are | |
144 also reserved for users to define. | |
145 | |
146 @item | |
147 Applications should not bind mouse events based on button 1 with the | |
148 shift key held down. These events include @kbd{S-mouse-1}, | |
149 @kbd{M-S-mouse-1}, @kbd{C-S-mouse-1}, and so on. They are reserved for | |
150 users. | |
145 | 151 |
146 @item | 152 @item |
147 Sequences consisting of @kbd{C-c} followed by a control character or a | 153 Sequences consisting of @kbd{C-c} followed by a control character or a |
148 digit are reserved for major modes. | 154 digit are reserved for major modes. |
149 | 155 |
154 @item | 160 @item |
155 Sequences consisting of @kbd{C-c} followed by any other punctuation | 161 Sequences consisting of @kbd{C-c} followed by any other punctuation |
156 character are allocated for minor modes. Using them in a major mode is | 162 character are allocated for minor modes. Using them in a major mode is |
157 not absolutely prohibited, but if you do that, the major mode binding | 163 not absolutely prohibited, but if you do that, the major mode binding |
158 may be shadowed from time to time by minor modes. | 164 may be shadowed from time to time by minor modes. |
159 | |
160 @item | |
161 Function keys @key{F5} through @key{F9} without modifier keys are | |
162 reserved for users to define. | |
163 | 165 |
164 @item | 166 @item |
165 Do not bind @kbd{C-h} following any prefix character (including | 167 Do not bind @kbd{C-h} following any prefix character (including |
166 @kbd{C-c}). If you don't bind @kbd{C-h}, it is automatically available | 168 @kbd{C-c}). If you don't bind @kbd{C-h}, it is automatically available |
167 as a help character for listing the subcommands of the prefix character. | 169 as a help character for listing the subcommands of the prefix character. |
187 after @key{ESC}. In these states, you should define @kbd{@key{ESC} | 189 after @key{ESC}. In these states, you should define @kbd{@key{ESC} |
188 @key{ESC} @key{ESC}} as the way to escape. Otherwise, define | 190 @key{ESC} @key{ESC}} as the way to escape. Otherwise, define |
189 @kbd{@key{ESC} @key{ESC}} instead. | 191 @kbd{@key{ESC} @key{ESC}} instead. |
190 | 192 |
191 @item | 193 @item |
192 Applications should not bind mouse events based on button 1 with the | |
193 shift key held down. These events include @kbd{S-mouse-1}, | |
194 @kbd{M-S-mouse-1}, @kbd{C-S-mouse-1}, and so on. They are reserved for | |
195 users. | |
196 | |
197 @item | |
198 @cindex mouse-2 | 194 @cindex mouse-2 |
199 @cindex references, following | 195 @cindex references, following |
200 Special major modes used for read-only text should usually redefine | 196 Special major modes used for read-only text should usually redefine |
201 @kbd{mouse-2} and @key{RET} to trace some sort of reference in the text. | 197 @kbd{mouse-2} and @key{RET} to trace some sort of reference in the text. |
202 Modes such as Dired, Info, Compilation, and Occur redefine it in this | 198 Modes such as Dired, Info, Compilation, and Occur redefine it in this |
203 way. | 199 way. |
200 | |
201 In addition, they should mark the text as a kind of ``link'' so that | |
202 @kbd{mouse-1} will follow it also. @xref{Links and Mouse-1}. | |
204 | 203 |
205 @item | 204 @item |
206 When a package provides a modification of ordinary Emacs behavior, it is | 205 When a package provides a modification of ordinary Emacs behavior, it is |
207 good to include a command to enable and disable the feature, provide a | 206 good to include a command to enable and disable the feature, provide a |
208 command named @code{@var{whatever}-mode} which turns the feature on or | 207 command named @code{@var{whatever}-mode} which turns the feature on or |
380 not to warn about uses of the variable @code{foo} in this file. | 379 not to warn about uses of the variable @code{foo} in this file. |
381 | 380 |
382 @item | 381 @item |
383 If you use many functions and variables from a certain file, you can | 382 If you use many functions and variables from a certain file, you can |
384 add a @code{require} for that package to avoid compilation warnings | 383 add a @code{require} for that package to avoid compilation warnings |
385 for them. It is better if the @code{require} acts only at compile | 384 for them. For instance, |
386 time. Here's how to do this: | |
387 | 385 |
388 @example | 386 @example |
389 (eval-when-compile | 387 (eval-when-compile |
390 (require 'foo)) | 388 (require 'foo)) |
391 @end example | 389 @end example |
432 ;; MA 02111-1307 USA | 430 ;; MA 02111-1307 USA |
433 @end smallexample | 431 @end smallexample |
434 | 432 |
435 If you have signed papers to assign the copyright to the Foundation, | 433 If you have signed papers to assign the copyright to the Foundation, |
436 then use @samp{Free Software Foundation, Inc.} as @var{name}. | 434 then use @samp{Free Software Foundation, Inc.} as @var{name}. |
437 Otherwise, use your name. | 435 Otherwise, use your name. See also @xref{Library Headers}. |
438 @end itemize | 436 @end itemize |
439 | 437 |
440 @node Compilation Tips | 438 @node Compilation Tips |
441 @section Tips for Making Compiled Code Fast | 439 @section Tips for Making Compiled Code Fast |
442 @cindex execution speed | 440 @cindex execution speed |