Mercurial > hg > xemacs-beta
comparison man/xemacs/custom.texi @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | ac2d302a0011 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
1 | |
2 @node Customization, Quitting, Emulation, Top | |
3 @chapter Customization | |
4 @cindex customization | |
5 | |
6 This chapter talks about various topics relevant to adapting the | |
7 behavior of Emacs in minor ways. | |
8 | |
9 All kinds of customization affect only the particular Emacs job that you | |
10 do them in. They are completely lost when you kill the Emacs job, and have | |
11 no effect on other Emacs jobs you may run at the same time or later. The | |
12 only way an Emacs job can affect anything outside of it is by writing a | |
13 file; in particular, the only way to make a customization `permanent' is to | |
14 put something in your @file{.emacs} file or other appropriate file to do the | |
15 customization in each session. @xref{Init File}. | |
16 | |
17 @menu | |
18 * Minor Modes:: Each minor mode is one feature you can turn on | |
19 independently of any others. | |
20 * Variables:: Many Emacs commands examine Emacs variables | |
21 to decide what to do; by setting variables, | |
22 you can control their functioning. | |
23 * Keyboard Macros:: A keyboard macro records a sequence of keystrokes | |
24 to be replayed with a single command. | |
25 * Key Bindings:: The keymaps say what command each key runs. | |
26 By changing them, you can "redefine keys". | |
27 * Syntax:: The syntax table controls how words and expressions | |
28 are parsed. | |
29 * Init File:: How to write common customizations in the @file{.emacs} | |
30 file. | |
31 * Audible Bell:: Changing how Emacs sounds the bell. | |
32 * Faces:: Changing the fonts and colors of a region of text. | |
33 * X Resources:: X resources controlling various aspects of the | |
34 behavior of XEmacs. | |
35 @end menu | |
36 | |
37 @node Minor Modes | |
38 @section Minor Modes | |
39 @cindex minor modes | |
40 | |
41 @cindex mode line | |
42 Minor modes are options which you can use or not. For example, Auto | |
43 Fill mode is a minor mode in which @key{SPC} breaks lines between words | |
44 as you type. All the minor modes are independent of each other and of | |
45 the selected major mode. Most minor modes inform you in the mode line | |
46 when they are on; for example, @samp{Fill} in the mode line means that | |
47 Auto Fill mode is on. | |
48 | |
49 Append @code{-mode} to the name of a minor mode to get the name of a | |
50 command function that turns the mode on or off. Thus, the command to | |
51 enable or disable Auto Fill mode is called @kbd{M-x auto-fill-mode}. These | |
52 commands are usually invoked with @kbd{M-x}, but you can bind keys to them | |
53 if you wish. With no argument, the function turns the mode on if it was | |
54 off and off if it was on. This is known as @dfn{toggling}. A positive | |
55 argument always turns the mode on, and an explicit zero argument or a | |
56 negative argument always turns it off. | |
57 | |
58 @cindex Auto Fill mode | |
59 @findex auto-fill-mode | |
60 Auto Fill mode allows you to enter filled text without breaking lines | |
61 explicitly. Emacs inserts newlines as necessary to prevent lines from | |
62 becoming too long. @xref{Filling}. | |
63 | |
64 @cindex Overwrite mode | |
65 @findex overwrite-mode | |
66 Overwrite mode causes ordinary printing characters to replace existing | |
67 text instead of moving it to the right. For example, if point is in | |
68 front of the @samp{B} in @samp{FOOBAR}, and you type a @kbd{G} in Overwrite | |
69 mode, it changes to @samp{FOOGAR}, instead of @samp{FOOGBAR}.@refill | |
70 | |
71 @cindex Abbrev mode | |
72 @findex abbrev-mode | |
73 Abbrev mode allows you to define abbreviations that automatically expand | |
74 as you type them. For example, @samp{amd} might expand to @samp{abbrev | |
75 mode}. @xref{Abbrevs}, for full information. | |
76 | |
77 @node Variables | |
78 @section Variables | |
79 @cindex variable | |
80 @cindex option | |
81 | |
82 A @dfn{variable} is a Lisp symbol which has a value. Variable names | |
83 can contain any characters, but by convention they are words separated | |
84 by hyphens. A variable can also have a documentation string, which | |
85 describes what kind of value it should have and how the value will be | |
86 used. | |
87 | |
88 Lisp allows any variable to have any kind of value, but most variables | |
89 that Emacs uses require a value of a certain type. Often the value has | |
90 to be a string or a number. Sometimes we say that a certain feature is | |
91 turned on if a variable is ``non-@code{nil},'' meaning that if the | |
92 variable's value is @code{nil}, the feature is off, but the feature is | |
93 on for @i{any} other value. The conventional value to turn on the | |
94 feature---since you have to pick one particular value when you set the | |
95 variable---is @code{t}. | |
96 | |
97 Emacs uses many Lisp variables for internal recordkeeping, as any Lisp | |
98 program must, but the most interesting variables for you are the ones that | |
99 exist for the sake of customization. Emacs does not (usually) change the | |
100 values of these variables; instead, you set the values, and thereby alter | |
101 and control the behavior of certain Emacs commands. These variables are | |
102 called @dfn{options}. Most options are documented in this manual and | |
103 appear in the Variable Index (@pxref{Variable Index}). | |
104 | |
105 One example of a variable which is an option is @code{fill-column}, which | |
106 specifies the position of the right margin (as a number of characters from | |
107 the left margin) to be used by the fill commands (@pxref{Filling}). | |
108 | |
109 @menu | |
110 * Examining:: Examining or setting one variable's value. | |
111 * Edit Options:: Examining or editing list of all variables' values. | |
112 * Locals:: Per-buffer values of variables. | |
113 * File Variables:: How files can specify variable values. | |
114 @end menu | |
115 | |
116 @node Examining | |
117 @subsection Examining and Setting Variables | |
118 @cindex setting variables | |
119 | |
120 @table @kbd | |
121 @item C-h v | |
122 @itemx M-x describe-variable | |
123 Print the value and documentation of a variable. | |
124 @findex set-variable | |
125 @item M-x set-variable | |
126 Change the value of a variable. | |
127 @end table | |
128 | |
129 @kindex C-h v | |
130 @findex describe-variable | |
131 To examine the value of a single variable, use @kbd{C-h v} | |
132 (@code{describe-variable}), which reads a variable name using the | |
133 minibuffer, with completion. It prints both the value and the | |
134 documentation of the variable. | |
135 | |
136 @example | |
137 C-h v fill-column @key{RET} | |
138 @end example | |
139 | |
140 @noindent | |
141 prints something like: | |
142 | |
143 @smallexample | |
144 fill-column's value is 75 | |
145 | |
146 Documentation: | |
147 *Column beyond which automatic line-wrapping should happen. | |
148 Automatically becomes local when set in any fashion. | |
149 @end smallexample | |
150 | |
151 @cindex option | |
152 @noindent | |
153 The star at the beginning of the documentation indicates that this variable | |
154 is an option. @kbd{C-h v} is not restricted to options; it allows any | |
155 variable name. | |
156 | |
157 @findex set-variable | |
158 If you know which option you want to set, you can use @kbd{M-x | |
159 set-variable} to set it. This prompts for the variable name in the | |
160 minibuffer (with completion), and then prompts for a Lisp expression for the | |
161 new value using the minibuffer a second time. For example, | |
162 | |
163 @example | |
164 M-x set-variable @key{RET} fill-column @key{RET} 75 @key{RET} | |
165 @end example | |
166 | |
167 @noindent | |
168 sets @code{fill-column} to 75, as if you had executed the Lisp expression | |
169 @code{(setq fill-column 75)}. | |
170 | |
171 Setting variables in this way, like all means of customizing Emacs | |
172 except where explicitly stated, affects only the current Emacs session. | |
173 | |
174 @node Edit Options | |
175 @subsection Editing Variable Values | |
176 | |
177 @table @kbd | |
178 @item M-x list-options | |
179 Display a buffer listing names, values, and documentation of all options. | |
180 @item M-x edit-options | |
181 Change option values by editing a list of options. | |
182 @end table | |
183 | |
184 @findex list-options | |
185 @kbd{M-x list-options} displays a list of all Emacs option variables in | |
186 an Emacs buffer named @samp{*List Options*}. Each option is shown with its | |
187 documentation and its current value. Here is what a portion of it might | |
188 look like: | |
189 | |
190 @smallexample | |
191 ;; exec-path: | |
192 ("." "/usr/local/bin" "/usr/ucb" "/bin" "/usr/bin" "/u2/emacs/etc") | |
193 *List of directories to search programs to run in subprocesses. | |
194 Each element is a string (directory name) | |
195 or nil (try the default directory). | |
196 ;; | |
197 ;; fill-column: | |
198 75 | |
199 *Column beyond which automatic line-wrapping should happen. | |
200 Automatically becomes local when set in any fashion. | |
201 ;; | |
202 @end smallexample | |
203 | |
204 @findex edit-options | |
205 @kbd{M-x edit-options} goes one step further and immediately selects the | |
206 @samp{*List Options*} buffer; this buffer uses the major mode Options mode, | |
207 which provides commands that allow you to point at an option and change its | |
208 value: | |
209 | |
210 @table @kbd | |
211 @item s | |
212 Set the variable point is in or near to a new value read using the | |
213 minibuffer. | |
214 @item x | |
215 Toggle the variable point is in or near: if the value was @code{nil}, | |
216 it becomes @code{t}; otherwise it becomes @code{nil}. | |
217 @item 1 | |
218 Set the variable point is in or near to @code{t}. | |
219 @item 0 | |
220 Set the variable point is in or near to @code{nil}. | |
221 @item n | |
222 @itemx p | |
223 Move to the next or previous variable. | |
224 @end table | |
225 | |
226 @node Locals | |
227 @subsection Local Variables | |
228 | |
229 @table @kbd | |
230 @item M-x make-local-variable | |
231 Make a variable have a local value in the current buffer. | |
232 @item M-x kill-local-variable | |
233 Make a variable use its global value in the current buffer. | |
234 @item M-x make-variable-buffer-local | |
235 Mark a variable so that setting it will make it local to the | |
236 buffer that is current at that time. | |
237 @end table | |
238 | |
239 @cindex local variables | |
240 You can make any variable @dfn{local} to a specific Emacs buffer. | |
241 This means that the variable's value in that buffer is independent of | |
242 its value in other buffers. A few variables are always local in every | |
243 buffer. All other Emacs variables have a @dfn{global} value which is in | |
244 effect in all buffers that have not made the variable local. | |
245 | |
246 Major modes always make the variables they set local to the buffer. | |
247 This is why changing major modes in one buffer has no effect on other | |
248 buffers. | |
249 | |
250 @findex make-local-variable | |
251 @kbd{M-x make-local-variable} reads the name of a variable and makes it | |
252 local to the current buffer. Further changes in this buffer will not | |
253 affect others, and changes in the global value will not affect this | |
254 buffer. | |
255 | |
256 @findex make-variable-buffer-local | |
257 @cindex per-buffer variables | |
258 @kbd{M-x make-variable-buffer-local} reads the name of a variable and | |
259 changes the future behavior of the variable so that it automatically | |
260 becomes local when it is set. More precisely, once you have marked a | |
261 variable in this way, the usual ways of setting the | |
262 variable will automatically invoke @code{make-local-variable} first. We | |
263 call such variables @dfn{per-buffer} variables. | |
264 | |
265 Some important variables have been marked per-buffer already. They | |
266 include @code{abbrev-mode}, @code{auto-fill-function}, | |
267 @code{case-fold-search}, @code{comment-column}, @code{ctl-arrow}, | |
268 @code{fill-column}, @code{fill-prefix}, @code{indent-tabs-mode}, | |
269 @code{left-margin}, @*@code{mode-line-format}, @code{overwrite-mode}, | |
270 @code{selective-display-ellipses}, @*@code{selective-display}, | |
271 @code{tab-width}, and @code{truncate-lines}. Some other variables are | |
272 always local in every buffer, but they are used for internal | |
273 purposes.@refill | |
274 | |
275 Note: the variable @code{auto-fill-function} was formerly named | |
276 @code{auto-fill-hook}. | |
277 | |
278 @findex kill-local-variable | |
279 If you want a variable to cease to be local to the current buffer, | |
280 call @kbd{M-x kill-local-variable} and provide the name of a variable to | |
281 the prompt. The global value of the variable | |
282 is again in effect in this buffer. Setting the major mode kills all | |
283 the local variables of the buffer. | |
284 | |
285 @findex setq-default | |
286 To set the global value of a variable, regardless of whether the | |
287 variable has a local value in the current buffer, you can use the | |
288 Lisp function @code{setq-default}. It works like @code{setq}. | |
289 If there is a local value in the current buffer, the local value is | |
290 not affected by @code{setq-default}; thus, the new global value may | |
291 not be visible until you switch to another buffer, as in the case of: | |
292 | |
293 @example | |
294 (setq-default fill-column 75) | |
295 @end example | |
296 | |
297 @noindent | |
298 @code{setq-default} is the only way to set the global value of a variable | |
299 that has been marked with @code{make-variable-buffer-local}. | |
300 | |
301 @findex default-value | |
302 Programs can look at a variable's default value with @code{default-value}. | |
303 This function takes a symbol as an argument and returns its default value. | |
304 The argument is evaluated; usually you must quote it explicitly, as in | |
305 the case of: | |
306 | |
307 @example | |
308 (default-value 'fill-column) | |
309 @end example | |
310 | |
311 @node File Variables | |
312 @subsection Local Variables in Files | |
313 @cindex local variables in files | |
314 | |
315 A file can contain a @dfn{local variables list}, which specifies the | |
316 values to use for certain Emacs variables when that file is edited. | |
317 Visiting the file checks for a local variables list and makes each variable | |
318 in the list local to the buffer in which the file is visited, with the | |
319 value specified in the file. | |
320 | |
321 A local variables list goes near the end of the file, in the last page. | |
322 (It is often best to put it on a page by itself.) The local variables list | |
323 starts with a line containing the string @samp{Local Variables:}, and ends | |
324 with a line containing the string @samp{End:}. In between come the | |
325 variable names and values, one set per line, as @samp{@var{variable}:@: | |
326 @var{value}}. The @var{value}s are not evaluated; they are used literally. | |
327 | |
328 The line which starts the local variables list does not have to say | |
329 just @samp{Local Variables:}. If there is other text before @samp{Local | |
330 Variables:}, that text is called the @dfn{prefix}, and if there is other | |
331 text after, that is called the @dfn{suffix}. If a prefix or suffix are | |
332 present, each entry in the local variables list should have the prefix | |
333 before it and the suffix after it. This includes the @samp{End:} line. | |
334 The prefix and suffix are included to disguise the local variables list | |
335 as a comment so the compiler or text formatter will ignore it. | |
336 If you do not need to disguise the local variables list as a comment in | |
337 this way, there is no need to include a prefix or a suffix.@refill | |
338 | |
339 Two ``variable'' names are special in a local variables list: a value | |
340 for the variable @code{mode} sets the major mode, and a value for the | |
341 variable @code{eval} is simply evaluated as an expression and the value | |
342 is ignored. These are not real variables; setting them in any other | |
343 context does not have the same effect. If @code{mode} is used in a | |
344 local variables list, it should be the first entry in the list. | |
345 | |
346 Here is an example of a local variables list: | |
347 @example | |
348 ;;; Local Variables: *** | |
349 ;;; mode:lisp *** | |
350 ;;; comment-column:0 *** | |
351 ;;; comment-start: ";;; " *** | |
352 ;;; comment-end:"***" *** | |
353 ;;; End: *** | |
354 @end example | |
355 | |
356 Note that the prefix is @samp{;;; } and the suffix is @samp{ ***}. | |
357 Note also that comments in the file begin with and end with the same | |
358 strings. Presumably the file contains code in a language which is | |
359 enough like Lisp for Lisp mode to be useful but in which comments | |
360 start and end differently. The prefix and suffix are used in the local | |
361 variables list to make the list look like several lines of comments when | |
362 the compiler or interpreter for that language reads the file. | |
363 | |
364 The start of the local variables list must be no more than 3000 | |
365 characters from the end of the file, and must be in the last page if the | |
366 file is divided into pages. Otherwise, Emacs will not notice it is | |
367 there. The purpose is twofold: a stray @samp{Local Variables:}@: not in | |
368 the last page does not confuse Emacs, and Emacs never needs to search a | |
369 long file that contains no page markers and has no local variables list. | |
370 | |
371 You may be tempted to turn on Auto Fill mode with a local variable | |
372 list. That is inappropriate. Whether you use Auto Fill mode or not is | |
373 a matter of personal taste, not a matter of the contents of particular | |
374 files. If you want to use Auto Fill, set up major mode hooks with your | |
375 @file{.emacs} file to turn it on (when appropriate) for you alone | |
376 (@pxref{Init File}). Don't try to use a local variable list that would | |
377 impose your taste on everyone working with the file. | |
378 | |
379 XEmacs allows you to specify local variables in the first line | |
380 of a file, in addition to specifying them in the @code{Local Variables} | |
381 section at the end of a file. | |
382 | |
383 If the first line of a file contains two occurences of @code{`-*-'}, Emacs | |
384 uses the information between them to determine what the major mode and | |
385 variable settings should be. For example, these are all legal: | |
386 | |
387 @example | |
388 ;;; -*- mode: emacs-lisp -*- | |
389 ;;; -*- mode: postscript; version-control: never -*- | |
390 ;;; -*- tags-file-name: "/foo/bar/TAGS" -*- | |
391 @end example | |
392 | |
393 For historical reasons, the syntax @code{`-*- modename -*-'} is allowed | |
394 as well; for example, you can use: | |
395 | |
396 @example | |
397 ;;; -*- emacs-lisp -*- | |
398 @end example | |
399 | |
400 @vindex enable-local-variables | |
401 The variable @code{enable-local-variables} controls the use of local | |
402 variables lists in files you visit. The value can be @code{t}, | |
403 @code{nil}, or something else. A value of @code{t} means local variables | |
404 lists are obeyed; @code{nil} means they are ignored; anything else means | |
405 query. | |
406 | |
407 The command @code{M-x normal-mode} always obeys local variables lists | |
408 and ignores this variable. | |
409 | |
410 @node Keyboard Macros | |
411 @section Keyboard Macros | |
412 | |
413 @cindex keyboard macros | |
414 A @dfn{keyboard macro} is a command defined by the user to abbreviate a | |
415 sequence of keys. For example, if you discover that you are about to type | |
416 @kbd{C-n C-d} forty times, you can speed your work by defining a keyboard | |
417 macro to invoke @kbd{C-n C-d} and calling it with a repeat count of forty. | |
418 | |
419 @c widecommands | |
420 @table @kbd | |
421 @item C-x ( | |
422 Start defining a keyboard macro (@code{start-kbd-macro}). | |
423 @item C-x ) | |
424 End the definition of a keyboard macro (@code{end-kbd-macro}). | |
425 @item C-x e | |
426 Execute the most recent keyboard macro (@code{call-last-kbd-macro}). | |
427 @item C-u C-x ( | |
428 Re-execute last keyboard macro, then add more keys to its definition. | |
429 @item C-x q | |
430 When this point is reached during macro execution, ask for confirmation | |
431 (@code{kbd-macro-query}). | |
432 @item M-x name-last-kbd-macro | |
433 Give a command name (for the duration of the session) to the most | |
434 recently defined keyboard macro. | |
435 @item M-x insert-kbd-macro | |
436 Insert in the buffer a keyboard macro's definition, as Lisp code. | |
437 @end table | |
438 | |
439 Keyboard macros differ from other Emacs commands in that they are | |
440 written in the Emacs command language rather than in Lisp. This makes it | |
441 easier for the novice to write them and makes them more convenient as | |
442 temporary hacks. However, the Emacs command language is not powerful | |
443 enough as a programming language to be useful for writing anything | |
444 general or complex. For such things, Lisp must be used. | |
445 | |
446 You define a keyboard macro by executing the commands which are its | |
447 definition. Put differently, as you are defining a keyboard macro, the | |
448 definition is being executed for the first time. This way, you see | |
449 what the effects of your commands are, and don't have to figure | |
450 them out in your head. When you are finished, the keyboard macro is | |
451 defined and also has been executed once. You can then execute the same | |
452 set of commands again by invoking the macro. | |
453 | |
454 @menu | |
455 * Basic Kbd Macro:: Defining and running keyboard macros. | |
456 * Save Kbd Macro:: Giving keyboard macros names; saving them in files. | |
457 * Kbd Macro Query:: Keyboard macros that do different things each use. | |
458 @end menu | |
459 | |
460 @node Basic Kbd Macro | |
461 @subsection Basic Use | |
462 | |
463 @kindex C-x ( | |
464 @kindex C-x ) | |
465 @kindex C-x e | |
466 @findex start-kbd-macro | |
467 @findex end-kbd-macro | |
468 @findex call-last-kbd-macro | |
469 To start defining a keyboard macro, type @kbd{C-x (} | |
470 (@code{start-kbd-macro}). From then on, anything you type continues to be | |
471 executed, but also becomes part of the definition of the macro. @samp{Def} | |
472 appears in the mode line to remind you of what is going on. When you are | |
473 finished, the @kbd{C-x )} command (@code{end-kbd-macro}) terminates the | |
474 definition, without becoming part of it. | |
475 | |
476 For example, | |
477 | |
478 @example | |
479 C-x ( M-f foo C-x ) | |
480 @end example | |
481 | |
482 @noindent | |
483 defines a macro to move forward a word and then insert @samp{foo}. | |
484 | |
485 You can give @kbd{C-x )} a repeat count as an argument, in which case it | |
486 repeats the macro that many times right after defining it, but defining | |
487 the macro counts as the first repetition (since it is executed as you | |
488 define it). If you give @kbd{C-x )} an argument of 4, it executes the | |
489 macro immediately 3 additional times. An argument of zero to @kbd{C-x | |
490 e} or @kbd{C-x )} means repeat the macro indefinitely (until it gets an | |
491 error or you type @kbd{C-g}). | |
492 | |
493 Once you have defined a macro, you can invoke it again with the | |
494 @kbd{C-x e} command (@code{call-last-kbd-macro}). You can give the | |
495 command a repeat count numeric argument to execute the macro many times. | |
496 | |
497 To repeat an operation at regularly spaced places in the | |
498 text, define a macro and include as part of the macro the commands to move | |
499 to the next place you want to use it. For example, if you want to change | |
500 each line, you should position point at the start of a line, and define a | |
501 macro to change that line and leave point at the start of the next line. | |
502 Repeating the macro will then operate on successive lines. | |
503 | |
504 After you have terminated the definition of a keyboard macro, you can add | |
505 to the end of its definition by typing @kbd{C-u C-x (}. This is equivalent | |
506 to plain @kbd{C-x (} followed by retyping the whole definition so far. As | |
507 a consequence it re-executes the macro as previously defined. | |
508 | |
509 @node Save Kbd Macro | |
510 @subsection Naming and Saving Keyboard Macros | |
511 | |
512 @findex name-last-kbd-macro | |
513 To save a keyboard macro for longer than until you define the | |
514 next one, you must give it a name using @kbd{M-x name-last-kbd-macro}. | |
515 This reads a name as an argument using the minibuffer and defines that name | |
516 to execute the macro. The macro name is a Lisp symbol, and defining it in | |
517 this way makes it a valid command name for calling with @kbd{M-x} or for | |
518 binding a key to with @code{global-set-key} (@pxref{Keymaps}). If you | |
519 specify a name that has a prior definition other than another keyboard | |
520 macro, Emacs prints an error message and nothing is changed. | |
521 | |
522 @findex insert-kbd-macro | |
523 Once a macro has a command name, you can save its definition in a file. | |
524 You can then use it in another editing session. First visit the file | |
525 you want to save the definition in. Then use the command: | |
526 | |
527 @example | |
528 M-x insert-kbd-macro @key{RET} @var{macroname} @key{RET} | |
529 @end example | |
530 | |
531 @noindent | |
532 This inserts some Lisp code that, when executed later, will define the same | |
533 macro with the same definition it has now. You need not understand Lisp | |
534 code to do this, because @code{insert-kbd-macro} writes the Lisp code for you. | |
535 Then save the file. You can load the file with @code{load-file} | |
536 (@pxref{Lisp Libraries}). If the file you save in is your initialization file | |
537 @file{~/.emacs} (@pxref{Init File}), then the macro will be defined each | |
538 time you run Emacs. | |
539 | |
540 If you give @code{insert-kbd-macro} a prefix argument, it creates | |
541 additional Lisp code to record the keys (if any) that you have bound to the | |
542 keyboard macro, so that the macro is reassigned the same keys when you | |
543 load the file. | |
544 | |
545 @node Kbd Macro Query | |
546 @subsection Executing Macros With Variations | |
547 | |
548 @kindex C-x q | |
549 @findex kbd-macro-query | |
550 You can use @kbd{C-x q} (@code{kbd-macro-query}), to get an effect similar | |
551 to that of @code{query-replace}. The macro asks you each time | |
552 whether to make a change. When you are defining the macro, type @kbd{C-x | |
553 q} at the point where you want the query to occur. During macro | |
554 definition, the @kbd{C-x q} does nothing, but when you invoke the macro, | |
555 @kbd{C-x q} reads a character from the terminal to decide whether to | |
556 continue. | |
557 | |
558 The special answers to a @kbd{C-x q} query are @key{SPC}, @key{DEL}, | |
559 @kbd{C-d}, @kbd{C-l}, and @kbd{C-r}. Any other character terminates | |
560 execution of the keyboard macro and is then read as a command. | |
561 @key{SPC} means to continue. @key{DEL} means to skip the remainder of | |
562 this repetition of the macro, starting again from the beginning in the | |
563 next repetition. @kbd{C-d} means to skip the remainder of this | |
564 repetition and cancel further repetition. @kbd{C-l} redraws the frame | |
565 and asks you again for a character to specify what to do. @kbd{C-r} enters | |
566 a recursive editing level, in which you can perform editing that is not | |
567 part of the macro. When you exit the recursive edit using @kbd{C-M-c}, | |
568 you are asked again how to continue with the keyboard macro. If you | |
569 type a @key{SPC} at this time, the rest of the macro definition is | |
570 executed. It is up to you to leave point and the text in a state such | |
571 that the rest of the macro will do what you want.@refill | |
572 | |
573 @kbd{C-u C-x q}, which is @kbd{C-x q} with a numeric argument, performs a | |
574 different function. It enters a recursive edit reading input from the | |
575 keyboard, both when you type it during the definition of the macro and | |
576 when it is executed from the macro. During definition, the editing you do | |
577 inside the recursive edit does not become part of the macro. During macro | |
578 execution, the recursive edit gives you a chance to do some particularized | |
579 editing. @xref{Recursive Edit}. | |
580 | |
581 @node Key Bindings | |
582 @section Customizing Key Bindings | |
583 | |
584 This section deals with the @dfn{keymaps} that define the bindings | |
585 between keys and functions, and shows how you can customize these bindings. | |
586 @cindex command | |
587 @cindex function | |
588 @cindex command name | |
589 | |
590 A command is a Lisp function whose definition provides for interactive | |
591 use. Like every Lisp function, a command has a function name, which is | |
592 a Lisp symbol whose name usually consists of lower case letters and | |
593 hyphens. | |
594 | |
595 @menu | |
596 * Keymaps:: Definition of the keymap data structure. | |
597 Names of Emacs's standard keymaps. | |
598 * Rebinding:: How to redefine one key's meaning conveniently. | |
599 * Disabling:: Disabling a command means confirmation is required | |
600 before it can be executed. This is done to protect | |
601 beginners from surprises. | |
602 @end menu | |
603 | |
604 @node Keymaps | |
605 @subsection Keymaps | |
606 @cindex keymap | |
607 | |
608 @cindex global keymap | |
609 @vindex global-map | |
610 The bindings between characters and command functions are recorded in | |
611 data structures called @dfn{keymaps}. Emacs has many of these. One, the | |
612 @dfn{global} keymap, defines the meanings of the single-character keys that | |
613 are defined regardless of major mode. It is the value of the variable | |
614 @code{global-map}. | |
615 | |
616 @cindex local keymap | |
617 @vindex c-mode-map | |
618 @vindex lisp-mode-map | |
619 Each major mode has another keymap, its @dfn{local keymap}, which | |
620 contains overriding definitions for the single-character keys that are | |
621 redefined in that mode. Each buffer records which local keymap is | |
622 installed for it at any time, and the current buffer's local keymap is | |
623 the only one that directly affects command execution. The local keymaps | |
624 for Lisp mode, C mode, and many other major modes always exist even when | |
625 not in use. They are the values of the variables @code{lisp-mode-map}, | |
626 @code{c-mode-map}, and so on. For less frequently used major modes, the | |
627 local keymap is sometimes constructed only when the mode is used for the | |
628 first time in a session, to save space. | |
629 | |
630 @cindex minibuffer | |
631 @vindex minibuffer-local-map | |
632 @vindex minibuffer-local-ns-map | |
633 @vindex minibuffer-local-completion-map | |
634 @vindex minibuffer-local-must-match-map | |
635 @vindex repeat-complex-command-map | |
636 @vindex isearch-mode-map | |
637 There are local keymaps for the minibuffer, too; they contain various | |
638 completion and exit commands. | |
639 | |
640 @itemize @bullet | |
641 @item | |
642 @code{minibuffer-local-map} is used for ordinary input (no completion). | |
643 @item | |
644 @code{minibuffer-local-ns-map} is similar, except that @key{SPC} exits | |
645 just like @key{RET}. This is used mainly for Mocklisp compatibility. | |
646 @item | |
647 @code{minibuffer-local-completion-map} is for permissive completion. | |
648 @item | |
649 @code{minibuffer-local-must-match-map} is for strict completion and | |
650 for cautious completion. | |
651 @item | |
652 @code{repeat-complex-command-map} is for use in @kbd{C-x @key{ESC}}. | |
653 @item | |
654 @code{isearch-mode-map} contains the bindings of the special keys which | |
655 are bound in the pseudo-mode entered with @kbd{C-s} and @kbd{C-r}. | |
656 @end itemize | |
657 | |
658 @vindex ctl-x-map | |
659 @vindex help-map | |
660 @vindex esc-map | |
661 Finally, each prefix key has a keymap which defines the key sequences | |
662 that start with it. For example, @code{ctl-x-map} is the keymap used for | |
663 characters following a @kbd{C-x}. | |
664 | |
665 @itemize @bullet | |
666 @item | |
667 @code{ctl-x-map} is the variable name for the map used for characters that | |
668 follow @kbd{C-x}. | |
669 @item | |
670 @code{help-map} is used for characters that follow @kbd{C-h}. | |
671 @item | |
672 @code{esc-map} is for characters that follow @key{ESC}. All Meta | |
673 characters are actually defined by this map. | |
674 @item | |
675 @code{ctl-x-4-map} is for characters that follow @kbd{C-x 4}. | |
676 @item | |
677 @code{mode-specific-map} is for characters that follow @kbd{C-c}. | |
678 @end itemize | |
679 | |
680 The definition of a prefix key is the keymap to use for looking up | |
681 the following character. Sometimes the definition is actually a Lisp | |
682 symbol whose function definition is the following character keymap. The | |
683 effect is the same, but it provides a command name for the prefix key that | |
684 you can use as a description of what the prefix key is for. Thus the | |
685 binding of @kbd{C-x} is the symbol @code{Ctl-X-Prefix}, whose function | |
686 definition is the keymap for @kbd{C-x} commands, the value of | |
687 @code{ctl-x-map}.@refill | |
688 | |
689 Prefix key definitions can appear in either the global | |
690 map or a local map. The definitions of @kbd{C-c}, @kbd{C-x}, @kbd{C-h}, | |
691 and @key{ESC} as prefix keys appear in the global map, so these prefix | |
692 keys are always available. Major modes can locally redefine a key as a | |
693 prefix by putting a prefix key definition for it in the local | |
694 map.@refill | |
695 | |
696 A mode can also put a prefix definition of a global prefix character such | |
697 as @kbd{C-x} into its local map. This is how major modes override the | |
698 definitions of certain keys that start with @kbd{C-x}. This case is | |
699 special, because the local definition does not entirely replace the global | |
700 one. When both the global and local definitions of a key are other | |
701 keymaps, the next character is looked up in both keymaps, with the local | |
702 definition overriding the global one. The character after the | |
703 @kbd{C-x} is looked up in both the major mode's own keymap for redefined | |
704 @kbd{C-x} commands and in @code{ctl-x-map}. If the major mode's own keymap | |
705 for @kbd{C-x} commands contains @code{nil}, the definition from the global | |
706 keymap for @kbd{C-x} commands is used.@refill | |
707 | |
708 @node Rebinding | |
709 @subsection Changing Key Bindings | |
710 @cindex key rebinding, this session | |
711 @cindex rebinding keys, this session | |
712 | |
713 You can redefine an Emacs key by changing its entry in a keymap. | |
714 You can change the global keymap, in which case the change is effective in | |
715 all major modes except those that have their own overriding local | |
716 definitions for the same key. Or you can change the current buffer's | |
717 local map, which affects all buffers using the same major mode. | |
718 | |
719 @menu | |
720 * Interactive Rebinding:: Changing Key Bindings Interactively | |
721 * Programmatic Rebinding:: Changing Key Bindings Programmatically | |
722 * Key Bindings Using Strings::Using Strings for Changing Key Bindings | |
723 @end menu | |
724 | |
725 @node Interactive Rebinding | |
726 @subsubsection Changing Key Bindings Interactively | |
727 @findex global-set-key | |
728 @findex local-set-key | |
729 @findex local-unset-key | |
730 | |
731 @table @kbd | |
732 @item M-x global-set-key @key{RET} @var{key} @var{cmd} @key{RET} | |
733 Defines @var{key} globally to run @var{cmd}. | |
734 @item M-x local-set-key @key{RET} @var{keys} @var{cmd} @key{RET} | |
735 Defines @var{key} locally (in the major mode now in effect) to run | |
736 @var{cmd}. | |
737 @item M-x local-unset-key @key{RET} @var{keys} @key{RET} | |
738 Removes the local binding of @var{key}. | |
739 @end table | |
740 | |
741 @var{cmd} is a symbol naming an interactively-callable function. | |
742 | |
743 When called interactively, @var{key} is the next complete key sequence | |
744 that you type. When called as a function, @var{key} is a string, a | |
745 vector of events, or a vector of key-description lists as described in | |
746 the @code{define-key} function description. The binding goes in | |
747 the current buffer's local map, which is shared with other buffers in | |
748 the same major mode. | |
749 | |
750 The following example: | |
751 | |
752 @example | |
753 M-x global-set-key @key{RET} C-f next-line @key{RET} | |
754 @end example | |
755 | |
756 @noindent | |
757 redefines @kbd{C-f} to move down a line. The fact that @var{cmd} is | |
758 read second makes it serve as a kind of confirmation for @var{key}. | |
759 | |
760 These functions offer no way to specify a particular prefix keymap as | |
761 the one to redefine in, but that is not necessary, as you can include | |
762 prefixes in @var{key}. @var{key} is read by reading characters one by | |
763 one until they amount to a complete key (that is, not a prefix key). | |
764 Thus, if you type @kbd{C-f} for @var{key}, Emacs enters | |
765 the minibuffer immediately to read @var{cmd}. But if you type | |
766 @kbd{C-x}, another character is read; if that character is @kbd{4}, | |
767 another character is read, and so on. For example,@refill | |
768 | |
769 @example | |
770 M-x global-set-key @key{RET} C-x 4 $ spell-other-window @key{RET} | |
771 @end example | |
772 | |
773 @noindent | |
774 redefines @kbd{C-x 4 $} to run the (fictitious) command | |
775 @code{spell-other-window}. | |
776 | |
777 @findex define-key | |
778 @findex substitute-key-definition | |
779 The most general way to modify a keymap is the function | |
780 @code{define-key}, used in Lisp code (such as your @file{.emacs} file). | |
781 @code{define-key} takes three arguments: the keymap, the key to modify | |
782 in it, and the new definition. @xref{Init File}, for an example. | |
783 @code{substitute-key-definition} is used similarly; it takes three | |
784 arguments, an old definition, a new definition, and a keymap, and | |
785 redefines in that keymap all keys that were previously defined with the | |
786 old definition to have the new definition instead. | |
787 | |
788 @node Programmatic Rebinding | |
789 @subsubsection Changing Key Bindings Programmatically | |
790 | |
791 You can use the functions @code{global-set-key} and @code{define-key} | |
792 to rebind keys under program control. | |
793 | |
794 @findex define-key | |
795 @findex global-set-key | |
796 | |
797 @table @kbd | |
798 @item @code{(global-set-key @var{keys} @var{cmd})} | |
799 Defines @var{keys} globally to run @var{cmd}. | |
800 @item @code{(define-key @var{keymap} @var{keys} @var{def})} | |
801 Defines @var{keys} to run @var{def} in the keymap @var{keymap}. | |
802 @end table | |
803 | |
804 @var{keymap} is a keymap object. | |
805 | |
806 @var{keys} is the sequence of keystrokes to bind. | |
807 | |
808 @var{def} is anything that can be a key's definition: | |
809 | |
810 @itemize @bullet | |
811 @item | |
812 @code{nil}, meaning key is undefined in this keymap | |
813 @item | |
814 A command, that is, a Lisp function suitable for interactive calling | |
815 @item | |
816 A string or key sequence vector, which is treated as a keyboard macro | |
817 @item | |
818 A keymap to define a prefix key | |
819 @item | |
820 A symbol so that when the key is looked up, the symbol stands for its | |
821 function definition, which should at that time be one of the above, | |
822 or another symbol whose function definition is used, and so on | |
823 @item | |
824 A cons, @code{(string . defn)}, meaning that @var{defn} is the definition | |
825 (@var{defn} should be a valid definition in its own right) | |
826 @item | |
827 A cons, @code{(keymap . char)}, meaning use the definition of | |
828 @var{char} in map @var{keymap} | |
829 @end itemize | |
830 | |
831 For backward compatibility, XEmacs allows you to specify key | |
832 sequences as strings. However, the preferred method is to use the | |
833 representations of key sequences as vectors of keystrokes. | |
834 @xref{Keystrokes}, for more information about the rules for constructing | |
835 key sequences. | |
836 | |
837 Emacs allows you to abbreviate representations for key sequences in | |
838 most places where there is no ambiguity. | |
839 Here are some rules for abbreviation: | |
840 | |
841 @itemize @bullet | |
842 @item | |
843 The keysym by itself is equivalent to a list of just that keysym, i.e., | |
844 @code{f1} is equivalent to @code{(f1)}. | |
845 @item | |
846 A keystroke by itself is equivalent to a vector containing just that | |
847 keystroke, i.e., @code{(control a)} is equivalent to @code{[(control a)]}. | |
848 @item | |
849 You can use ASCII codes for keysyms that have them. i.e., | |
850 @code{65} is equivalent to @code{A}. (This is not so much an | |
851 abbreviation as an alternate representation.) | |
852 @end itemize | |
853 | |
854 Here are some examples of programmatically binding keys: | |
855 | |
856 @example | |
857 | |
858 ;;; Bind @code{my-command} to @key{f1} | |
859 (global-set-key 'f1 'my-command) | |
860 | |
861 ;;; Bind @code{my-command} to @kbd{Shift-f1} | |
862 (global-set-key '(shift f1) 'my-command) | |
863 | |
864 ;;; Bind @code{my-command} to @kbd{C-c Shift-f1} | |
865 (global-set-key '[(control c) (shift f1)] 'my-command) | |
866 | |
867 ;;; Bind @code{my-command} to the middle mouse button. | |
868 (global-set-key 'button2 'my-command) | |
869 | |
870 ;;; Bind @code{my-command} to @kbd{@key{META} @key{CTL} @key{Right Mouse Button}} | |
871 ;;; in the keymap that is in force when you are running @code{dired}. | |
872 (define-key dired-mode-map '(meta control button3) 'my-command) | |
873 | |
874 @end example | |
875 | |
876 @comment ;; note that these next four lines are not synonymous: | |
877 @comment ;; | |
878 @comment (global-set-key '(meta control delete) 'my-command) | |
879 @comment (global-set-key '(meta control backspace) 'my-command) | |
880 @comment (global-set-key '(meta control h) 'my-command) | |
881 @comment (global-set-key '(meta control H) 'my-command) | |
882 @comment | |
883 @comment ;; note that this binds two key sequences: ``control-j'' and ``linefeed''. | |
884 @comment ;; | |
885 @comment (global-set-key "\^J" 'my-command) | |
886 | |
887 @node Key Bindings Using Strings | |
888 @subsubsection Using Strings for Changing Key Bindings | |
889 | |
890 For backward compatibility, you can still use strings to represent | |
891 key sequences. Thus you can use comands like the following: | |
892 | |
893 @example | |
894 ;;; Bind @code{end-of-line} to @kbd{C-f} | |
895 (global-set-key "\C-f" 'end-of-line) | |
896 @end example | |
897 | |
898 Note, however, that in some cases you may be binding more than one | |
899 key sequence by using a single command. This situation can | |
900 arise because in ASCII, @kbd{C-i} and @key{TAB} have | |
901 the same representation. Therefore, when Emacs sees: | |
902 | |
903 @example | |
904 (global-set-key "\C-i" 'end-of-line) | |
905 @end example | |
906 | |
907 it is unclear whether the user intended to bind @kbd{C-i} or @key{TAB}. | |
908 The solution XEmacs adopts is to bind both of these key | |
909 sequences. | |
910 | |
911 @cindex redefining keys | |
912 After binding a command to two key sequences with a form like: | |
913 | |
914 @example | |
915 (define-key global-map "\^X\^I" 'command-1) | |
916 @end example | |
917 | |
918 it is possible to redefine only one of those sequences like so: | |
919 | |
920 @example | |
921 (define-key global-map [(control x) (control i)] 'command-2) | |
922 (define-key global-map [(control x) tab] 'command-3) | |
923 @end example | |
924 | |
925 This applies only when running under a window system. If you are | |
926 talking to Emacs through an ASCII-only channel, you do not get any of | |
927 these features. | |
928 | |
929 Here is a table of pairs of key sequences that behave in a | |
930 similar fashion: | |
931 | |
932 @example | |
933 control h backspace | |
934 control l clear | |
935 control i tab | |
936 control m return | |
937 control j linefeed | |
938 control [ escape | |
939 control @@ control space | |
940 @end example | |
941 | |
942 @node Disabling | |
943 @subsection Disabling Commands | |
944 @cindex disabled command | |
945 | |
946 Disabling a command marks it as requiring confirmation before it | |
947 can be executed. The purpose of disabling a command is to prevent | |
948 beginning users from executing it by accident and being confused. | |
949 | |
950 The direct mechanism for disabling a command is to have a non-@code{nil} | |
951 @code{disabled} property on the Lisp symbol for the command. These | |
952 properties are normally set by the user's @file{.emacs} file with | |
953 Lisp expressions such as: | |
954 | |
955 @example | |
956 (put 'delete-region 'disabled t) | |
957 @end example | |
958 | |
959 If the value of the @code{disabled} property is a string, that string | |
960 is included in the message printed when the command is used: | |
961 | |
962 @example | |
963 (put 'delete-region 'disabled | |
964 "Text deleted this way cannot be yanked back!\n") | |
965 @end example | |
966 | |
967 @findex disable-command | |
968 @findex enable-command | |
969 You can disable a command either by editing the @file{.emacs} file | |
970 directly or with the command @kbd{M-x disable-command}, which edits the | |
971 @file{.emacs} file for you. @xref{Init File}. | |
972 | |
973 When you attempt to invoke a disabled command interactively in Emacs, | |
974 a window is displayed containing the command's name, its | |
975 documentation, and some instructions on what to do next; then | |
976 Emacs asks for input saying whether to execute the command as requested, | |
977 enable it and execute, or cancel it. If you decide to enable the | |
978 command, you are asked whether to do this permanently or just for the | |
979 current session. Enabling permanently works by automatically editing | |
980 your @file{.emacs} file. You can use @kbd{M-x enable-command} at any | |
981 time to enable any command permanently. | |
982 | |
983 Whether a command is disabled is independent of what key is used to | |
984 invoke it; it also applies if the command is invoked using @kbd{M-x}. | |
985 Disabling a command has no effect on calling it as a function from Lisp | |
986 programs. | |
987 | |
988 @node Syntax | |
989 @section The Syntax Table | |
990 @cindex syntax table | |
991 | |
992 All the Emacs commands which parse words or balance parentheses are | |
993 controlled by the @dfn{syntax table}. The syntax table specifies which | |
994 characters are opening delimiters, which are parts of words, which are | |
995 string quotes, and so on. Actually, each major mode has its own syntax | |
996 table (though sometimes related major modes use the same one) which it | |
997 installs in each buffer that uses that major mode. The syntax table | |
998 installed in the current buffer is the one that all commands use, so we | |
999 call it ``the'' syntax table. A syntax table is a Lisp object, a vector of | |
1000 length 256 whose elements are numbers. | |
1001 | |
1002 @menu | |
1003 * Entry: Syntax Entry. What the syntax table records for each character. | |
1004 * Change: Syntax Change. How to change the information. | |
1005 @end menu | |
1006 | |
1007 @node Syntax Entry | |
1008 @subsection Information About Each Character | |
1009 | |
1010 The syntax table entry for a character is a number that encodes six | |
1011 pieces of information: | |
1012 | |
1013 @itemize @bullet | |
1014 @item | |
1015 The syntactic class of the character, represented as a small integer | |
1016 @item | |
1017 The matching delimiter, for delimiter characters only | |
1018 (the matching delimiter of @samp{(} is @samp{)}, and vice versa) | |
1019 @item | |
1020 A flag saying whether the character is the first character of a | |
1021 two-character comment starting sequence | |
1022 @item | |
1023 A flag saying whether the character is the second character of a | |
1024 two-character comment starting sequence | |
1025 @item | |
1026 A flag saying whether the character is the first character of a | |
1027 two-character comment ending sequence | |
1028 @item | |
1029 A flag saying whether the character is the second character of a | |
1030 two-character comment ending sequence | |
1031 @end itemize | |
1032 | |
1033 The syntactic classes are stored internally as small integers, but are | |
1034 usually described to or by the user with characters. For example, @samp{(} | |
1035 is used to specify the syntactic class of opening delimiters. Here is a | |
1036 table of syntactic classes, with the characters that specify them. | |
1037 | |
1038 @table @samp | |
1039 @item @w{ } | |
1040 The class of whitespace characters. | |
1041 @item w | |
1042 The class of word-constituent characters. | |
1043 @item _ | |
1044 The class of characters that are part of symbol names but not words. | |
1045 This class is represented by @samp{_} because the character @samp{_} | |
1046 has this class in both C and Lisp. | |
1047 @item . | |
1048 The class of punctuation characters that do not fit into any other | |
1049 special class. | |
1050 @item ( | |
1051 The class of opening delimiters. | |
1052 @item ) | |
1053 The class of closing delimiters. | |
1054 @item ' | |
1055 The class of expression-adhering characters. These characters are | |
1056 part of a symbol if found within or adjacent to one, and are part | |
1057 of a following expression if immediately preceding one, but are like | |
1058 whitespace if surrounded by whitespace. | |
1059 @item " | |
1060 The class of string-quote characters. They match each other in pairs, | |
1061 and the characters within the pair all lose their syntactic | |
1062 significance except for the @samp{\} and @samp{/} classes of escape | |
1063 characters, which can be used to include a string-quote inside the | |
1064 string. | |
1065 @item $ | |
1066 The class of self-matching delimiters. This is intended for @TeX{}'s | |
1067 @samp{$}, which is used both to enter and leave math mode. Thus, | |
1068 a pair of matching @samp{$} characters surround each piece of math mode | |
1069 @TeX{} input. A pair of adjacent @samp{$} characters act like a single | |
1070 one for purposes of matching. | |
1071 | |
1072 @item / | |
1073 The class of escape characters that always just deny the following | |
1074 character its special syntactic significance. The character after one | |
1075 of these escapes is always treated as alphabetic. | |
1076 @item \ | |
1077 The class of C-style escape characters. In practice, these are | |
1078 treated just like @samp{/}-class characters, because the extra | |
1079 possibilities for C escapes (such as being followed by digits) have no | |
1080 effect on where the containing expression ends. | |
1081 @item < | |
1082 The class of comment-starting characters. Only single-character | |
1083 comment starters (such as @samp{;} in Lisp mode) are represented this | |
1084 way. | |
1085 @item > | |
1086 The class of comment-ending characters. Newline has this syntax in | |
1087 Lisp mode. | |
1088 @end table | |
1089 | |
1090 @vindex parse-sexp-ignore-comments | |
1091 The characters flagged as part of two-character comment delimiters can | |
1092 have other syntactic functions most of the time. For example, @samp{/} and | |
1093 @samp{*} in C code, when found separately, have nothing to do with | |
1094 comments. The comment-delimiter significance overrides when the pair of | |
1095 characters occur together in the proper order. Only the list and sexp | |
1096 commands use the syntax table to find comments; the commands specifically | |
1097 for comments have other variables that tell them where to find comments. | |
1098 Moreover, the list and sexp commands notice comments only if | |
1099 @code{parse-sexp-ignore-comments} is non-@code{nil}. This variable is set | |
1100 to @code{nil} in modes where comment-terminator sequences are liable to | |
1101 appear where there is no comment, for example, in Lisp mode where the | |
1102 comment terminator is a newline but not every newline ends a comment. | |
1103 | |
1104 @node Syntax Change | |
1105 @subsection Altering Syntax Information | |
1106 | |
1107 It is possible to alter a character's syntax table entry by storing a new | |
1108 number in the appropriate element of the syntax table, but it would be hard | |
1109 to determine what number to use. Emacs therefore provides a command that | |
1110 allows you to specify the syntactic properties of a character in a | |
1111 convenient way. | |
1112 | |
1113 @findex modify-syntax-entry | |
1114 @kbd{M-x modify-syntax-entry} is the command to change a character's | |
1115 syntax. It can be used interactively and is also used by major | |
1116 modes to initialize their own syntax tables. Its first argument is the | |
1117 character to change. The second argument is a string that specifies the | |
1118 new syntax. When called from Lisp code, there is a third, optional | |
1119 argument, which specifies the syntax table in which to make the change. If | |
1120 not supplied, or if this command is called interactively, the third | |
1121 argument defaults to the current buffer's syntax table. | |
1122 | |
1123 @enumerate | |
1124 @item | |
1125 The first character in the string specifies the syntactic class. It | |
1126 is one of the characters in the previous table (@pxref{Syntax Entry}). | |
1127 | |
1128 @item | |
1129 The second character is the matching delimiter. For a character that | |
1130 is not an opening or closing delimiter, this should be a space, and may | |
1131 be omitted if no following characters are needed. | |
1132 | |
1133 @item | |
1134 The remaining characters are flags. The flag characters allowed are: | |
1135 | |
1136 @table @samp | |
1137 @item 1 | |
1138 Flag this character as the first of a two-character comment starting sequence. | |
1139 @item 2 | |
1140 Flag this character as the second of a two-character comment starting sequence. | |
1141 @item 3 | |
1142 Flag this character as the first of a two-character comment ending sequence. | |
1143 @item 4 | |
1144 Flag this character as the second of a two-character comment ending sequence. | |
1145 @end table | |
1146 @end enumerate | |
1147 | |
1148 @kindex C-h s | |
1149 @findex describe-syntax | |
1150 Use @kbd{C-h s} (@code{describe-syntax}) to display a description of | |
1151 the contents of the current syntax table. The description of each | |
1152 character includes both the string you have to pass to | |
1153 @code{modify-syntax-entry} to set up that character's current syntax, | |
1154 and some English to explain that string if necessary. | |
1155 | |
1156 @node Init File | |
1157 @section The Init File, .emacs | |
1158 @cindex init file | |
1159 @cindex Emacs initialization file | |
1160 @cindex key rebinding, permanent | |
1161 @cindex rebinding keys, permanently | |
1162 | |
1163 When you start Emacs, it normally loads the file @file{.emacs} in your | |
1164 home directory. This file, if it exists, should contain Lisp code. It | |
1165 is called your initialization file or @dfn{init file}. Use the command | |
1166 line switches @samp{-q} and @samp{-u} to tell Emacs whether to load an | |
1167 init file (@pxref{Entering Emacs}). | |
1168 | |
1169 @vindex init-file-user | |
1170 When the @file{.emacs} file is read, the variable @code{init-file-user} | |
1171 says which user's init file it is. The value may be the null string or a | |
1172 string containing a user's name. If the value is a null string, it means | |
1173 that the init file was taken from the user that originally logged in. | |
1174 | |
1175 In all cases, @code{(concat "~" init-file-user "/")} evaluates to the | |
1176 directory name of the directory where the @file{.emacs} file was looked | |
1177 for. | |
1178 | |
1179 At some sites there is a @dfn{default init file}, which is the | |
1180 library named @file{default.el}, found via the standard search path for | |
1181 libraries. The Emacs distribution contains no such library; your site | |
1182 may create one for local customizations. If this library exists, it is | |
1183 loaded whenever you start Emacs. But your init file, if any, is loaded | |
1184 first; if it sets @code{inhibit-default-init} non-@code{nil}, then | |
1185 @file{default} is not loaded. | |
1186 | |
1187 If you have a large amount of code in your @file{.emacs} file, you | |
1188 should move it into another file named @file{@var{something}.el}, | |
1189 byte-compile it (@pxref{Lisp Libraries}), and load that file from your | |
1190 @file{.emacs} file using @code{load}. | |
1191 | |
1192 @menu | |
1193 * Init Syntax:: Syntax of constants in Emacs Lisp. | |
1194 * Init Examples:: How to do some things with an init file. | |
1195 * Terminal Init:: Each terminal type can have an init file. | |
1196 @end menu | |
1197 | |
1198 @node Init Syntax | |
1199 @subsection Init File Syntax | |
1200 | |
1201 The @file{.emacs} file contains one or more Lisp function call | |
1202 expressions. Each consists of a function name followed by | |
1203 arguments, all surrounded by parentheses. For example, @code{(setq | |
1204 fill-column 60)} represents a call to the function @code{setq} which is | |
1205 used to set the variable @code{fill-column} (@pxref{Filling}) to 60. | |
1206 | |
1207 The second argument to @code{setq} is an expression for the new value | |
1208 of the variable. This can be a constant, a variable, or a function call | |
1209 expression. In @file{.emacs}, constants are used most of the time. | |
1210 They can be: | |
1211 | |
1212 @table @asis | |
1213 @item Numbers | |
1214 Integers are written in decimal, with an optional initial minus sign. | |
1215 | |
1216 If a sequence of digits is followed by a period and another sequence | |
1217 of digits, it is interpreted as a floating point number. | |
1218 | |
1219 @item Strings | |
1220 Lisp string syntax is the same as C string syntax with a few extra | |
1221 features. Use a double-quote character to begin and end a string constant. | |
1222 | |
1223 Newlines and special characters may be present literally in strings. They | |
1224 can also be represented as backslash sequences: @samp{\n} for newline, | |
1225 @samp{\b} for backspace, @samp{\r} for return, @samp{\t} for tab, | |
1226 @samp{\f} for formfeed (control-l), @samp{\e} for escape, @samp{\\} for a | |
1227 backslash, @samp{\"} for a double-quote, or @samp{\@var{ooo}} for the | |
1228 character whose octal code is @var{ooo}. Backslash and double-quote are | |
1229 the only characters for which backslash sequences are mandatory. | |
1230 | |
1231 You can use @samp{\C-} as a prefix for a control character, as in | |
1232 @samp{\C-s} for ASCII Control-S, and @samp{\M-} as a prefix for | |
1233 a Meta character, as in @samp{\M-a} for Meta-A or @samp{\M-\C-a} for | |
1234 Control-Meta-A.@refill | |
1235 | |
1236 @item Characters | |
1237 Lisp character constant syntax consists of a @samp{?} followed by | |
1238 either a character or an escape sequence starting with @samp{\}. | |
1239 Examples: @code{?x}, @code{?\n}, @code{?\"}, @code{?\)}. Note that | |
1240 strings and characters are not interchangeable in Lisp; some contexts | |
1241 require one and some contexts require the other. | |
1242 | |
1243 @item True | |
1244 @code{t} stands for `true'. | |
1245 | |
1246 @item False | |
1247 @code{nil} stands for `false'. | |
1248 | |
1249 @item Other Lisp objects | |
1250 Write a single-quote (') followed by the Lisp object you want. | |
1251 @end table | |
1252 | |
1253 @node Init Examples | |
1254 @subsection Init File Examples | |
1255 | |
1256 Here are some examples of doing certain commonly desired things with | |
1257 Lisp expressions: | |
1258 | |
1259 @itemize @bullet | |
1260 @item | |
1261 Make @key{TAB} in C mode just insert a tab if point is in the middle of a | |
1262 line. | |
1263 | |
1264 @example | |
1265 (setq c-tab-always-indent nil) | |
1266 @end example | |
1267 | |
1268 Here we have a variable whose value is normally @code{t} for `true' | |
1269 and the alternative is @code{nil} for `false'. | |
1270 | |
1271 @item | |
1272 Make searches case sensitive by default (in all buffers that do not | |
1273 override this). | |
1274 | |
1275 @example | |
1276 (setq-default case-fold-search nil) | |
1277 @end example | |
1278 | |
1279 This sets the default value, which is effective in all buffers that do | |
1280 not have local values for the variable. Setting @code{case-fold-search} | |
1281 with @code{setq} affects only the current buffer's local value, which | |
1282 is probably not what you want to do in an init file. | |
1283 | |
1284 @item | |
1285 Make Text mode the default mode for new buffers. | |
1286 | |
1287 @example | |
1288 (setq default-major-mode 'text-mode) | |
1289 @end example | |
1290 | |
1291 Note that @code{text-mode} is used because it is the command for entering | |
1292 the mode we want. A single-quote is written before it to make a symbol | |
1293 constant; otherwise, @code{text-mode} would be treated as a variable name. | |
1294 | |
1295 @item | |
1296 Turn on Auto Fill mode automatically in Text mode and related modes. | |
1297 | |
1298 @example | |
1299 (setq text-mode-hook | |
1300 '(lambda () (auto-fill-mode 1))) | |
1301 @end example | |
1302 | |
1303 Here we have a variable whose value should be a Lisp function. The | |
1304 function we supply is a list starting with @code{lambda}, and a single | |
1305 quote is written in front of it to make it (for the purpose of this | |
1306 @code{setq}) a list constant rather than an expression. Lisp functions | |
1307 are not explained here; for mode hooks it is enough to know that | |
1308 @code{(auto-fill-mode 1)} is an expression that will be executed when | |
1309 Text mode is entered. You could replace it with any other expression | |
1310 that you like, or with several expressions in a row. | |
1311 | |
1312 @example | |
1313 (setq text-mode-hook 'turn-on-auto-fill) | |
1314 @end example | |
1315 | |
1316 This is another way to accomplish the same result. | |
1317 @code{turn-on-auto-fill} is a symbol whose function definition is | |
1318 @code{(lambda () (auto-fill-mode 1))}. | |
1319 | |
1320 @item | |
1321 Load the installed Lisp library named @file{foo} (actually a file | |
1322 @file{foo.elc} or @file{foo.el} in a standard Emacs directory). | |
1323 | |
1324 @example | |
1325 (load "foo") | |
1326 @end example | |
1327 | |
1328 When the argument to @code{load} is a relative pathname, not starting | |
1329 with @samp{/} or @samp{~}, @code{load} searches the directories in | |
1330 @code{load-path} (@pxref{Loading}). | |
1331 | |
1332 @item | |
1333 Load the compiled Lisp file @file{foo.elc} from your home directory. | |
1334 | |
1335 @example | |
1336 (load "~/foo.elc") | |
1337 @end example | |
1338 | |
1339 Here an absolute file name is used, so no searching is done. | |
1340 | |
1341 @item | |
1342 Rebind the key @kbd{C-x l} to run the function @code{make-symbolic-link}. | |
1343 | |
1344 @example | |
1345 (global-set-key "\C-xl" 'make-symbolic-link) | |
1346 @end example | |
1347 | |
1348 or | |
1349 | |
1350 @example | |
1351 (define-key global-map "\C-xl" 'make-symbolic-link) | |
1352 @end example | |
1353 | |
1354 Note once again the single-quote used to refer to the symbol | |
1355 @code{make-symbolic-link} instead of its value as a variable. | |
1356 | |
1357 @item | |
1358 Do the same thing for C mode only. | |
1359 | |
1360 @example | |
1361 (define-key c-mode-map "\C-xl" 'make-symbolic-link) | |
1362 @end example | |
1363 | |
1364 @item | |
1365 Bind the function key @key{F1} to a command in C mode. | |
1366 Note that the names of function keys must be lower case. | |
1367 | |
1368 @example | |
1369 (define-key c-mode-map 'f1 'make-symbolic-link) | |
1370 @end example | |
1371 | |
1372 @item | |
1373 Bind the shifted version of @key{F1} to a command. | |
1374 | |
1375 @example | |
1376 (define-key c-mode-map '(shift f1) 'make-symbolic-link) | |
1377 @end example | |
1378 | |
1379 @item | |
1380 Redefine all keys which now run @code{next-line} in Fundamental mode | |
1381 to run @code{forward-line} instead. | |
1382 | |
1383 @example | |
1384 (substitute-key-definition 'next-line 'forward-line | |
1385 global-map) | |
1386 @end example | |
1387 | |
1388 @item | |
1389 Make @kbd{C-x C-v} undefined. | |
1390 | |
1391 @example | |
1392 (global-unset-key "\C-x\C-v") | |
1393 @end example | |
1394 | |
1395 One reason to undefine a key is so that you can make it a prefix. | |
1396 Simply defining @kbd{C-x C-v @var{anything}} would make @kbd{C-x C-v} | |
1397 a prefix, but @kbd{C-x C-v} must be freed of any non-prefix definition | |
1398 first. | |
1399 | |
1400 @item | |
1401 Make @samp{$} have the syntax of punctuation in Text mode. | |
1402 Note the use of a character constant for @samp{$}. | |
1403 | |
1404 @example | |
1405 (modify-syntax-entry ?\$ "." text-mode-syntax-table) | |
1406 @end example | |
1407 | |
1408 @item | |
1409 Enable the use of the command @code{eval-expression} without confirmation. | |
1410 | |
1411 @example | |
1412 (put 'eval-expression 'disabled nil) | |
1413 @end example | |
1414 @end itemize | |
1415 | |
1416 @node Terminal Init | |
1417 @subsection Terminal-Specific Initialization | |
1418 | |
1419 Each terminal type can have a Lisp library to be loaded into Emacs when | |
1420 it is run on that type of terminal. For a terminal type named | |
1421 @var{termtype}, the library is called @file{term/@var{termtype}} and it is | |
1422 found by searching the directories @code{load-path} as usual and trying the | |
1423 suffixes @samp{.elc} and @samp{.el}. Normally it appears in the | |
1424 subdirectory @file{term} of the directory where most Emacs libraries are | |
1425 kept.@refill | |
1426 | |
1427 The usual purpose of the terminal-specific library is to define the | |
1428 escape sequences used by the terminal's function keys using the library | |
1429 @file{keypad.el}. See the file | |
1430 @file{term/vt100.el} for an example of how this is done.@refill | |
1431 | |
1432 When the terminal type contains a hyphen, only the part of the name | |
1433 before the first hyphen is significant in choosing the library name. | |
1434 Thus, terminal types @samp{aaa-48} and @samp{aaa-30-rv} both use | |
1435 the library @file{term/aaa}. The code in the library can use | |
1436 @code{(getenv "TERM")} to find the full terminal type name.@refill | |
1437 | |
1438 @vindex term-file-prefix | |
1439 The library's name is constructed by concatenating the value of the | |
1440 variable @code{term-file-prefix} and the terminal type. Your @file{.emacs} | |
1441 file can prevent the loading of the terminal-specific library by setting | |
1442 @code{term-file-prefix} to @code{nil}. | |
1443 | |
1444 @vindex term-setup-hook | |
1445 The value of the variable @code{term-setup-hook}, if not @code{nil}, is | |
1446 called as a function of no arguments at the end of Emacs initialization, | |
1447 after both your @file{.emacs} file and any terminal-specific library have | |
1448 been read. You can set the value in the @file{.emacs} file to override | |
1449 part of any of the terminal-specific libraries and to define | |
1450 initializations for terminals that do not have a library.@refill | |
1451 | |
1452 @node Audible Bell | |
1453 @section Changing the Bell Sound | |
1454 @cindex audible bell, changing | |
1455 @cindex bell, changing | |
1456 @vindex sound-alist | |
1457 @findex load-default-sounds | |
1458 @findex play-sound | |
1459 | |
1460 You can now change how the audible bell sounds using the variable | |
1461 @code{sound-alist}. | |
1462 | |
1463 @code{sound-alist}'s value is an list associating symbols with, among | |
1464 other things, strings of audio-data. When @code{ding} is called with | |
1465 one of the symbols, the associated sound data is played instead of the | |
1466 standard beep. This only works if you are logged in on the console of a | |
1467 machine with audio hardware. To listen to a sound of the provided type, | |
1468 call the function @code{play-sound} with the argument @var{sound}. You | |
1469 can also set the volume of the sound with the optional argument | |
1470 @var{volume}.@refill | |
1471 @cindex ding | |
1472 | |
1473 Each element of @code{sound-alist} is a list describing a sound. | |
1474 The first element of the list is the name of the sound being defined. | |
1475 Subsequent elements of the list are alternating keyword/value pairs: | |
1476 | |
1477 @table @code | |
1478 @item sound | |
1479 A string of raw sound data, or the name of another sound to play. | |
1480 The symbol @code{t} here means use the default X beep. | |
1481 | |
1482 @item volume | |
1483 An integer from 0-100, defaulting to @code{bell-volume}. | |
1484 | |
1485 @item pitch | |
1486 If using the default X beep, the pitch (Hz) to generate. | |
1487 | |
1488 @item duration | |
1489 If using the default X beep, the duration (milliseconds). | |
1490 @end table | |
1491 | |
1492 For compatibility, elements of `sound-alist' may also be of the form: | |
1493 | |
1494 @example | |
1495 ( @var{sound-name} . @var{<sound>} ) | |
1496 ( @var{sound-name} @var{<volume>} @var{<sound>} ) | |
1497 @end example | |
1498 | |
1499 You should probably add things to this list by calling the function | |
1500 @code{load-sound-file}. | |
1501 | |
1502 Note that you can only play audio data if running on the console screen | |
1503 of a machine with audio hardware which emacs understands, which at this | |
1504 time means a Sun SparcStation, SGI, or HP9000s700. | |
1505 | |
1506 Also note that the pitch, duration, and volume options are available | |
1507 everywhere, but most X servers ignore the `pitch' option. | |
1508 | |
1509 @vindex bell-volume | |
1510 The variable @code{bell-volume} should be an integer from 0 to 100, | |
1511 with 100 being loudest, which controls how loud the sounds emacs makes | |
1512 should be. Elements of the @code{sound-alist} may override this value. | |
1513 This variable applies to the standard X bell sound as well as sound files. | |
1514 | |
1515 If the symbol @code{t} is in place of a sound-string, Emacs uses the | |
1516 default X beep. This allows you to define beep-types of | |
1517 different volumes even when not running on the console. | |
1518 | |
1519 @findex load-sound-file | |
1520 You can add things to this list by calling the function | |
1521 @code{load-sound-file}, which reads in an audio-file and adds its data to | |
1522 the sound-alist. You can specify the sound with the @var{sound-name} | |
1523 argument and the file into which the sounds are loaded with the | |
1524 @var{filename} argument. The optional @var{volume} argument sets the | |
1525 volume. | |
1526 | |
1527 @code{load-sound-file (@var{filename sound-name} &optional @var{volume})} | |
1528 | |
1529 To load and install some sound files as beep-types, use the function | |
1530 @code{load-default-sounds} (note that this only works if you are on | |
1531 display 0 of a machine with audio hardware). | |
1532 | |
1533 The following beep-types are used by Emacs itself. Other Lisp | |
1534 packages may use other beep types, but these are the ones that the C | |
1535 kernel of Emacs uses. | |
1536 | |
1537 @table @code | |
1538 @item auto-save-error | |
1539 An auto-save does not succeed | |
1540 | |
1541 @item command-error | |
1542 The Emacs command loop catches an error | |
1543 | |
1544 @item undefined-key | |
1545 You type a key that is undefined | |
1546 | |
1547 @item undefined-click | |
1548 You use an undefined mouse-click combination | |
1549 | |
1550 @item no-completion | |
1551 Completion was not possible | |
1552 | |
1553 @item y-or-n-p | |
1554 You type something other than the required @code{y} or @code{n} | |
1555 | |
1556 @item yes-or-no-p | |
1557 You type something other than @code{yes} or @code{no} | |
1558 @end table | |
1559 | |
1560 @comment node-name, next, previous, up | |
1561 @node Faces | |
1562 @section Faces | |
1563 | |
1564 XEmacs has objects called extents and faces. An @dfn{extent} | |
1565 is a region of text and a @dfn{face} is a collection of textual | |
1566 attributes, such as fonts and colors. Every extent is displayed in some | |
1567 face; therefore, changing the properties of a face immediately updates the | |
1568 display of all associated extents. Faces can be frame-local: you can | |
1569 have a region of text that displays with completely different | |
1570 attributes when its buffer is viewed from a different X window. | |
1571 | |
1572 The display attributes of faces may be specified either in Lisp or through | |
1573 the X resource manager. | |
1574 | |
1575 @subsection Customizing Faces | |
1576 | |
1577 You can change the face of an extent with the functions in | |
1578 this section. All the functions prompt for a @var{face} as an | |
1579 argument; use completion for a list of possible values. | |
1580 | |
1581 @table @kbd | |
1582 @item M-x invert-face | |
1583 Swap the foreground and background colors of the given @var{face}. | |
1584 @item M-x make-face-bold | |
1585 Make the font of the given @var{face} bold. When called from a | |
1586 program, returns @code{nil} if this is not possible. | |
1587 @item M-x make-face-bold-italic | |
1588 Make the font of the given @var{face} bold italic. | |
1589 When called from a program, returns @code{nil} if not possible. | |
1590 @item M-x make-face-italic | |
1591 Make the font of the given @var{face} italic. | |
1592 When called from a program, returns @code{nil} if not possible. | |
1593 @item M-x make-face-unbold | |
1594 Make the font of the given @var{face} non-bold. | |
1595 When called from a program, returns @code{nil} if not possible. | |
1596 @item M-x make-face-unitalic | |
1597 Make the font of the given @var{face} non-italic. | |
1598 When called from a program, returns @code{nil} if not possible. | |
1599 @item M-x make-face-larger | |
1600 Make the font of the given @var{face} a little larger. | |
1601 When called from a program, returns @code{nil} if not possible. | |
1602 @item M-x make-face-smaller | |
1603 Make the font of the given @var{face} a little smaller. | |
1604 When called from a program, returns @code{nil} if not possible. | |
1605 @item M-x set-face-background | |
1606 Change the background color of the given @var{face}. | |
1607 @item M-x set-face-background-pixmap | |
1608 Change the background pixmap of the given @var{face}. | |
1609 @item M-x set-face-font | |
1610 Change the font of the given @var{face}. | |
1611 @item M-x set-face-foreground | |
1612 Change the foreground color of the given @var{face}. | |
1613 @item M-x set-face-underline-p | |
1614 Change whether the given @var{face} is underlined. | |
1615 @end table | |
1616 | |
1617 @findex make-face-bold | |
1618 @findex make-face-bold-italic | |
1619 @findex make-face-italic | |
1620 @findex make-face-unbold | |
1621 @findex make-face-unitalic | |
1622 @findex make-face-larger | |
1623 @findex make-face-smaller | |
1624 | |
1625 @findex invert-face | |
1626 You can exchange the foreground and background color of the selected | |
1627 @var{face} with the function @code{invert-face}. If the face does not | |
1628 specify both foreground and background, then its foreground and | |
1629 background are set to the background and foreground of the default face. | |
1630 When calling this from a program, you can supply the optional argument | |
1631 @var{frame} to specify which frame is affected; otherwise, all frames | |
1632 are affected. | |
1633 | |
1634 @findex set-face-background | |
1635 You can set the background color of the specified @var{face} with the | |
1636 function @code{set-face-background}. The argument @code{color} should | |
1637 be a string, the name of a color. When called from a program, if the | |
1638 optional @var{frame} argument is provided, the face is changed only | |
1639 in that frame; otherwise, it is changed in all frames. | |
1640 | |
1641 @findex set-face-background-pixmap | |
1642 You can set the background pixmap of the specified @var{face} with the | |
1643 function @code{set-face-background-pixmap}. The pixmap argument | |
1644 @var{name} should be a string, the name of a file of pixmap data. The | |
1645 directories listed in the @code{x-bitmap-file-path} variable are | |
1646 searched. The bitmap may also be a list of the form @code{(@var{width | |
1647 height data})}, where @var{width} and @var{height} are the size in | |
1648 pixels, and @var{data} is a string containing the raw bits of the | |
1649 bitmap. If the optional @var{frame} argument is provided, the face is | |
1650 changed only in that frame; otherwise, it is changed in all frames. | |
1651 | |
1652 The variable @code{x-bitmap-file-path} takes as a value a list of the | |
1653 directories in which X bitmap files may be found. If the value is | |
1654 @code{nil}, the list is initialized from the @code{*bitmapFilePath} | |
1655 resource. | |
1656 | |
1657 If the environment variable @b{XBMLANGPATH} is set, then it is consulted | |
1658 before the @code{x-bitmap-file-path} variable. | |
1659 | |
1660 @findex set-face-font | |
1661 You can set the font of the specified @var{face} with the function | |
1662 @code{set-face-font}. The @var{font} argument should be a string, the | |
1663 name of a font. When called from a program, if the | |
1664 optional @var{frame} argument is provided, the face is changed only | |
1665 in that frame; otherwise, it is changed in all frames. | |
1666 | |
1667 @findex set-face-foreground | |
1668 You can set the foreground color of the specified @var{face} with the | |
1669 function @code{set-face-foreground}. The argument @var{color} should be | |
1670 a string, the name of a color. If the optional @var{frame} argument is | |
1671 provided, the face is changed only in that frame; otherwise, it is | |
1672 changed in all frames. | |
1673 | |
1674 @findex set-face-underline-p | |
1675 You can set underline the specified @var{face} with the function | |
1676 @code{set-face-underline-p}. The argument @var{underline-p} can be used | |
1677 to make underlining an attribute of the face or not. If the optional | |
1678 @var{frame} argument is provided, the face is changed only in that | |
1679 frame; otherwise, it is changed in all frames. | |
1680 | |
1681 @node X Resources | |
1682 @section X Resources | |
1683 @cindex X resources | |
1684 @findex x-create-frame | |
1685 | |
1686 The Emacs resources are generally set per-frame. Each Emacs frame can have | |
1687 its own name or the same name as another, depending on the name passed to the | |
1688 @code{make-frame} function. | |
1689 | |
1690 You can specify resources for all frames with the syntax: | |
1691 | |
1692 @example | |
1693 Emacs*parameter: value | |
1694 @end example | |
1695 @noindent | |
1696 | |
1697 or | |
1698 | |
1699 @example | |
1700 Emacs*EmacsFrame.parameter:value | |
1701 @end example | |
1702 @noindent | |
1703 | |
1704 You can specify resources for a particular frame with the syntax: | |
1705 | |
1706 @example | |
1707 Emacs*FRAME-NAME.parameter: value | |
1708 @end example | |
1709 @noindent | |
1710 | |
1711 @menu | |
1712 * Geometry Resources:: Controlling the size and position of frames. | |
1713 * Iconic Resources:: Controlling whether frames come up iconic. | |
1714 * Resource List:: List of resources settable on a frame or device. | |
1715 * Face Resources:: Controlling faces using resources. | |
1716 * Widgets:: The widget hierarchy for XEmacs. | |
1717 * Menubar Resources:: Specifying resources for the menubar. | |
1718 @end menu | |
1719 | |
1720 @node Geometry Resources | |
1721 @subsection Geometry Resources | |
1722 | |
1723 To make the default size of all Emacs frames be 80 columns by 55 lines, | |
1724 do this: | |
1725 | |
1726 @example | |
1727 Emacs*EmacsFrame.geometry: 80x55 | |
1728 @end example | |
1729 @noindent | |
1730 | |
1731 To set the geometry of a particular frame named @samp{fred}, do this: | |
1732 | |
1733 @example | |
1734 Emacs*fred.geometry: 80x55 | |
1735 @end example | |
1736 @noindent | |
1737 | |
1738 Important! Do not use the following syntax: | |
1739 | |
1740 @example | |
1741 Emacs*geometry: 80x55 | |
1742 @end example | |
1743 @noindent | |
1744 | |
1745 You should never use @code{*geometry} with any X application. It does | |
1746 not say "make the geometry of Emacs be 80 columns by 55 lines." It | |
1747 really says, "make Emacs and all subwindows thereof be 80x55 in whatever | |
1748 units they care to measure in." In particular, that is both telling the | |
1749 Emacs text pane to be 80x55 in characters, and telling the menubar pane | |
1750 to be 80x55 pixels, which is surely not what you want. | |
1751 | |
1752 As a special case, this geometry specification also works (and sets the | |
1753 default size of all Emacs frames to 80 columns by 55 lines): | |
1754 | |
1755 @example | |
1756 Emacs.geometry: 80x55 | |
1757 @end example | |
1758 @noindent | |
1759 | |
1760 since that is the syntax used with most other applications (since most | |
1761 other applications have only one top-level window, unlike Emacs). In | |
1762 general, however, the top-level shell (the unmapped ApplicationShell | |
1763 widget named @samp{Emacs} that is the parent of the shell widgets that | |
1764 actually manage the individual frames) does not have any interesting | |
1765 resources on it, and you should set the resources on the frames instead. | |
1766 | |
1767 The @code{-geometry} command-line argument sets only the geometry of the | |
1768 initial frame created by Emacs. | |
1769 | |
1770 A more complete explanation of geometry-handling is | |
1771 | |
1772 @itemize @bullet | |
1773 @item | |
1774 The @code{-geometry} command-line option sets the @code{Emacs.geometry} | |
1775 resource, that is, the geometry of the ApplicationShell. | |
1776 | |
1777 @item | |
1778 For the first frame created, the size of the frame is taken from the | |
1779 ApplicationShell if it is specified, otherwise from the geometry of the | |
1780 frame. | |
1781 | |
1782 @item | |
1783 For subsequent frames, the order is reversed: First the frame, and then | |
1784 the ApplicationShell. | |
1785 | |
1786 @item | |
1787 For the first frame created, the position of the frame is taken from the | |
1788 ApplicationShell (@code{Emacs.geometry}) if it is specified, otherwise | |
1789 from the geometry of the frame. | |
1790 | |
1791 @item | |
1792 For subsequent frames, the position is taken only from the frame, and | |
1793 never from the ApplicationShell. | |
1794 @end itemize | |
1795 | |
1796 This is rather complicated, but it does seem to provide the most | |
1797 intuitive behavior with respect to the default sizes and positions of | |
1798 frames created in various ways. | |
1799 | |
1800 @node Iconic Resources | |
1801 @subsection Iconic Resources | |
1802 | |
1803 Analogous to @code{-geometry}, the @code{-iconic} command-line option | |
1804 sets the iconic flag of the ApplicationShell (@code{Emacs.iconic}) and | |
1805 always applies to the first frame created regardless of its name. | |
1806 However, it is possible to set the iconic flag on particular frames (by | |
1807 name) by using the @code{Emacs*FRAME-NAME.iconic} resource. | |
1808 | |
1809 @node Resource List | |
1810 @subsection Resource List | |
1811 | |
1812 Emacs frames accept the following resources: | |
1813 | |
1814 @table @asis | |
1815 @item @code{geometry} (class @code{Geometry}): string | |
1816 Initial geometry for the frame. @xref{Geometry Resources} for a | |
1817 complete discussion of how this works. | |
1818 | |
1819 @item @code{iconic} (class @code{Iconic}): boolean | |
1820 Whether this frame should appear in the iconified state. | |
1821 | |
1822 @item @code{internalBorderWidth} (class @code{InternalBorderWidth}): int | |
1823 How many blank pixels to leave between the text and the edge of the | |
1824 window. | |
1825 | |
1826 @item @code{interline} (class @code{Interline}): int | |
1827 How many pixels to leave between each line (may not be implemented). | |
1828 | |
1829 @item @code{menubar} (class @code{Menubar}): boolean | |
1830 Whether newly-created frames should initially have a menubar. Set to | |
1831 true by default. | |
1832 | |
1833 @item @code{initiallyUnmapped} (class @code{InitiallyUnmapped}): boolean | |
1834 Whether XEmacs should leave the initial frame unmapped when it starts | |
1835 up. This is useful if you are starting XEmacs as a server (e.g. in | |
1836 conjunction with gnuserv or the external client widget). You can also | |
1837 control this with the @code{-unmapped} command-line option. | |
1838 | |
1839 @item @code{barCursor} (class @code{BarColor}): boolean | |
1840 Whether the cursor should be displayed as a bar, or the traditional box. | |
1841 | |
1842 @item @code{cursorColor} (class @code{CursorColor}): color-name | |
1843 The color of the text cursor. | |
1844 | |
1845 @item @code{scrollBarWidth} (class @code{ScrollBarWidth}): integer | |
1846 How wide the vertical scrollbars should be, in pixels; 0 means no | |
1847 vertical scrollbars. You can also use a resource specification of the | |
1848 form @code{*scrollbar.width}, or the usual toolkit scrollbar resources: | |
1849 @code{*XmScrollBar.width} (Motif), @code{*XlwScrollBar.width} (Lucid), | |
1850 or @code{*Scrollbar.thickness} (Athena). We don't recommend that you | |
1851 use the toolkit resources, though, because they're dependent on how | |
1852 exactly your particular build of XEmacs was configured. | |
1853 | |
1854 @item @code{scrollBarHeight} (class @code{ScrollBarHeight}): integer | |
1855 How high the horizontal scrollbars should be, in pixels; 0 means no | |
1856 horizontal scrollbars. You can also use a resource specification of the | |
1857 form @code{*scrollbar.height}, or the usual toolkit scrollbar resources: | |
1858 @code{*XmScrollBar.height} (Motif), @code{*XlwScrollBar.height} (Lucid), | |
1859 or @code{*Scrollbar.thickness} (Athena). We don't recommend that you use | |
1860 the toolkit resources, though, because they're dependent on how exactly | |
1861 your particular build of XEmacs was configured. | |
1862 | |
1863 @item @code{scrollBarPlacement} (class @code{ScrollBarPlacement}): string | |
1864 Where the horizontal and vertical scrollbars should be positioned. This | |
1865 should be one of the four strings @samp{bottom-left}, | |
1866 @samp{bottom-right}, @samp{top-left}, and @samp{top-right}. Default is | |
1867 @samp{bottom-right} for the Motif and Lucid scrollbars and | |
1868 @samp{bottom-left} for the Athena scrollbars. | |
1869 | |
1870 @item @code{topToolBarHeight} (class @code{TopToolBarHeight}): integer | |
1871 @itemx @code{bottomToolBarHeight} (class @code{BottomToolBarHeight}): integer | |
1872 @itemx @code{leftToolBarWidth} (class @code{LeftToolBarWidth}): integer | |
1873 @itemx @code{rightToolBarWidth} (class @code{RightToolBarWidth}): integer | |
1874 Height and width of the four possible toolbars. | |
1875 | |
1876 @item @code{topToolBarShadowColor} (class @code{TopToolBarShadowColor}): color-name | |
1877 @itemx @code{bottomToolBarShadowColor} (class @code{BottomToolBarShadowColor}): color-name | |
1878 Color of the top and bottom shadows for the toolbars. NOTE: These resources | |
1879 do @emph{not} have anything to do with the top and bottom toolbars (i.e. the | |
1880 toolbars at the top and bottom of the frame)! Rather, they affect the top | |
1881 and bottom shadows around the edges of all four kinds of toolbars. | |
1882 | |
1883 @item @code{topToolBarShadowPixmap} (class @code{TopToolBarShadowPixmap}): pixmap-name | |
1884 @itemx @code{bottomToolBarShadowPixmap} (class @code{BottomToolBarShadowPixmap}): pixmap-name | |
1885 Pixmap of the top and bottom shadows for the toolbars. If set, these | |
1886 resources override the corresponding color resources. NOTE: These | |
1887 resources do @emph{not} have anything to do with the top and bottom | |
1888 toolbars (i.e. the toolbars at the top and bottom of the frame)! | |
1889 Rather, they affect the top and bottom shadows around the edges of all | |
1890 four kinds of toolbars. | |
1891 | |
1892 @item @code{toolBarShadowThickness} (class @code{ToolBarShadowThickness}): integer | |
1893 Thickness of the shadows around the toolbars, in pixels. | |
1894 | |
1895 @item @code{visualBell} (class @code{VisualBell}): boolean | |
1896 Whether XEmacs should flash the screen rather than making an audible beep. | |
1897 | |
1898 @item @code{bellVolume} (class @code{BellVolume}): integer | |
1899 Volume of the audible beep. | |
1900 | |
1901 @item @code{useBackingStore} (class @code{UseBackingStore}): boolean | |
1902 Whether XEmacs should set the backing-store attribute of the X windows | |
1903 it creates. This increases the memory usage of the X server but decreases | |
1904 the amount of X traffic necessary to update the screen, and is useful | |
1905 when the connection to the X server goes over a low-bandwidth line | |
1906 such as a modem connection. | |
1907 @end table | |
1908 | |
1909 Emacs devices accept the following resources: | |
1910 | |
1911 @table @asis | |
1912 @item @code{textPointer} (class @code{Cursor}): cursor-name | |
1913 The cursor to use when the mouse is over text. This resource is used to | |
1914 initialize the variable @code{x-pointer-shape}. | |
1915 | |
1916 @item @code{selectionPointer} (class @code{Cursor}): cursor-name | |
1917 The cursor to use when the mouse is over a selectable text region (an | |
1918 extent with the @samp{highlight} property; for example, an Info | |
1919 cross-reference). This resource is used to initialize the variable | |
1920 @code{x-selection-pointer-shape}. | |
1921 | |
1922 @item @code{spacePointer} (class @code{Cursor}): cursor-name | |
1923 The cursor to use when the mouse is over a blank space in a buffer (that | |
1924 is, after the end of a line or after the end-of-file). This resource is | |
1925 used to initialize the variable @code{x-nontext-pointer-shape}. | |
1926 | |
1927 @item @code{modeLinePointer} (class @code{Cursor}): cursor-name | |
1928 The cursor to use when the mouse is over a modeline. This resource is | |
1929 used to initialize the variable @code{x-mode-pointer-shape}. | |
1930 | |
1931 @item @code{gcPointer} (class @code{Cursor}): cursor-name | |
1932 The cursor to display when a garbage-collection is in progress. This | |
1933 resource is used to initialize the variable @code{x-gc-pointer-shape}. | |
1934 | |
1935 @item @code{scrollbarPointer} (class @code{Cursor}): cursor-name | |
1936 The cursor to use when the mouse is over the scrollbar. This resource | |
1937 is used to initialize the variable @code{x-scrollbar-pointer-shape}. | |
1938 | |
1939 @item @code{pointerColor} (class @code{Foreground}): color-name | |
1940 @itemx @code{pointerBackground} (class @code{Background}): color-name | |
1941 The foreground and background colors of the mouse cursor. These | |
1942 resources are used to initialize the variables | |
1943 @code{x-pointer-foreground-color} and @code{x-pointer-background-color}. | |
1944 @end table | |
1945 | |
1946 @node Face Resources | |
1947 @subsection Face Resources | |
1948 | |
1949 The attributes of faces are also per-frame. They can be specified as: | |
1950 | |
1951 @example | |
1952 Emacs.FACE_NAME.parameter: value | |
1953 @end example | |
1954 @noindent | |
1955 | |
1956 or | |
1957 | |
1958 @example | |
1959 Emacs*FRAME_NAME.FACE_NAME.parameter: value | |
1960 @end example | |
1961 @noindent | |
1962 | |
1963 Faces accept the following resources: | |
1964 | |
1965 @table @asis | |
1966 @item @code{attributeFont} (class @code{AttributeFont}): font-name | |
1967 The font of this face. | |
1968 | |
1969 @item @code{attributeForeground} (class @code{AttributeForeground}): color-name | |
1970 @itemx @code{attributeBackground} (class @code{AttributeBackground}): color-name | |
1971 The foreground and background colors of this face. | |
1972 | |
1973 @item @code{attributeBackgroundPixmap} (class @code{AttributeBackgroundPixmap}): file-name | |
1974 The name of an @sc{XBM} file (or @sc{XPM} file, if your version of Emacs | |
1975 supports @sc{XPM}), to use as a background stipple. | |
1976 | |
1977 @item @code{attributeUnderline} (class @code{AttributeUnderline}): boolean | |
1978 Whether text in this face should be underlined. | |
1979 @end table | |
1980 | |
1981 All text is displayed in some face, defaulting to the face named | |
1982 @code{default}. To set the font of normal text, use | |
1983 @code{Emacs*default.attributeFont}. To set it in the frame named | |
1984 @code{fred}, use @code{Emacs*fred.default.attributeFont}. | |
1985 | |
1986 These are the names of the predefined faces: | |
1987 | |
1988 @table @code | |
1989 @item default | |
1990 Everything inherits from this. | |
1991 | |
1992 @item bold | |
1993 If this is not specified in the resource database, Emacs tries to find a | |
1994 bold version of the font of the default face. | |
1995 | |
1996 @item italic | |
1997 If this is not specified in the resource database, Emacs tries to find | |
1998 an italic version of the font of the default face. | |
1999 | |
2000 @item bold-italic | |
2001 If this is not specified in the resource database, Emacs tries to find a | |
2002 bold-italic version of the font of the default face. | |
2003 | |
2004 @item modeline | |
2005 This is the face that the modeline is displayed in. If not specified in | |
2006 the resource database, it is determined from the default face by | |
2007 reversing the foreground and background colors. | |
2008 | |
2009 @item highlight | |
2010 This is the face that highlighted extents (for example, Info | |
2011 cross-references and possible completions, when the mouse passes over | |
2012 them) are displayed in. | |
2013 | |
2014 @item left-margin | |
2015 @itemx right-margin | |
2016 These are the faces that the left and right annotation margins are | |
2017 displayed in. | |
2018 | |
2019 @item zmacs-region | |
2020 This is the face that mouse selections are displayed in. | |
2021 | |
2022 @item isearch | |
2023 This is the face that the matched text being searched for is displayed | |
2024 in. | |
2025 | |
2026 @item info-node | |
2027 This is the face of info menu items. If unspecified, it is copied from | |
2028 @code{bold-italic}. | |
2029 | |
2030 @item info-xref | |
2031 This is the face of info cross-references. If unspecified, it is copied | |
2032 from @code{bold}. (Note that, when the mouse passes over a | |
2033 cross-reference, the cross-reference's face is determined from a | |
2034 combination of the @code{info-xref} and @code{highlight} faces.) | |
2035 @end table | |
2036 | |
2037 Other packages might define their own faces; to see a list of all faces, | |
2038 use any of the interactive face-manipulation commands such as | |
2039 @code{set-face-font} and type @samp{?} when you are prompted for the | |
2040 name of a face. | |
2041 | |
2042 If the @code{bold}, @code{italic}, and @code{bold-italic} faces are not | |
2043 specified in the resource database, then XEmacs attempts to derive them | |
2044 from the font of the default face. It can only succeed at this if you | |
2045 have specified the default font using the XLFD (X Logical Font | |
2046 Description) format, which looks like | |
2047 | |
2048 @example | |
2049 *-courier-medium-r-*-*-*-120-*-*-*-*-*-* | |
2050 @end example | |
2051 @noindent | |
2052 | |
2053 If you use any of the other, less strict font name formats, some of which | |
2054 look like | |
2055 | |
2056 @example | |
2057 lucidasanstypewriter-12 | |
2058 fixed | |
2059 9x13 | |
2060 @end example | |
2061 | |
2062 then XEmacs won't be able to guess the names of the bold and italic | |
2063 versions. All X fonts can be referred to via XLFD-style names, so you | |
2064 should use those forms. See the man pages for @samp{X(1)}, | |
2065 @samp{xlsfonts(1)}, and @samp{xfontsel(1)}. | |
2066 | |
2067 @node Widgets | |
2068 @subsection Widgets | |
2069 | |
2070 There are several structural widgets between the terminal EmacsFrame | |
2071 widget and the top level ApplicationShell; the exact names and types of | |
2072 these widgets change from release to release (for example, they changed | |
2073 between 19.8 and 19.9, 19.9 and 19.10, and 19.10 and 19.12) and are | |
2074 subject to further change in the future, so you should avoid mentioning | |
2075 them in your resource database. The above-mentioned syntaxes should be | |
2076 forward- compatible. As of 19.13, the exact widget hierarchy is as | |
2077 follows: | |
2078 | |
2079 @example | |
2080 INVOCATION-NAME "shell" "container" FRAME-NAME | |
2081 x-emacs-application-class "EmacsShell" "EmacsManager" "EmacsFrame" | |
2082 @end example | |
2083 | |
2084 where INVOCATION-NAME is the terminal component of the name of the | |
2085 XEmacs executable (usually @samp{xemacs}), and | |
2086 @samp{x-emacs-application-class} is generally @samp{Emacs}. | |
2087 | |
2088 @node Menubar Resources | |
2089 @subsection Menubar Resources | |
2090 | |
2091 As the menubar is implemented as a widget which is not a part of XEacs | |
2092 proper, it does not use the fac" mechanism for specifying fonts and | |
2093 colors: It uses whatever resources are appropriate to the type of widget | |
2094 which is used to implement it. | |
2095 | |
2096 If Emacs was compiled to use only the Motif-lookalike menu widgets, then one | |
2097 way to specify the font of the menubar would be | |
2098 | |
2099 @example | |
2100 Emacs*menubar*font: *-courier-medium-r-*-*-*-120-*-*-*-*-*-* | |
2101 @end example | |
2102 | |
2103 If the Motif library is being used, then one would have to use | |
2104 | |
2105 @example | |
2106 Emacs*menubar*fontList: *-courier-medium-r-*-*-*-120-*-*-*-*-*-* | |
2107 @end example | |
2108 | |
2109 because the Motif library uses the @code{fontList} resource name instead | |
2110 of @code{font}, which has subtly different semantics. | |
2111 | |
2112 The same is true of the scrollbars: They accept whichever resources are | |
2113 appropriate for the toolkit in use. |