Mercurial > hg > xemacs-beta
comparison man/new-users-guide/custom2.texi @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | 859a2309aef8 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
1 @comment node-name, next, previous, up | |
2 @node Other Customizations, Select and Move, Files, Top | |
3 @chapter Other Customizations | |
4 @cindex customize | |
5 @cindex hook | |
6 @cindex font-lock-mode | |
7 | |
8 You can modify the behavior of Emacs in minor ways permanently by | |
9 putting your changes in your @file{.emacs} file. This file contains Lisp | |
10 function call expressions. Each of these expressions will consist of a | |
11 function name followed by arguments, all surrounded by parentheses. For | |
12 example, to turn on the auto-fill-mode (i.e. break lines automatically | |
13 when they become too long) , put the following line in your | |
14 @file{.emacs} file: | |
15 | |
16 @example | |
17 (add-hook 'text-mode-hook | |
18 '(lambda() (auto-fill-mode 1))) | |
19 @end example | |
20 | |
21 @noindent | |
22 Emacs has a function named "turn-on-auto-fill" which is defined as | |
23 "(lambda() (auto-fill-mode 1))". Therefore you can also write the above | |
24 as: | |
25 | |
26 @example | |
27 (add-hook 'text-mode-hook 'turn-on-auto-fill) | |
28 @end example | |
29 | |
30 @noindent | |
31 Emacs provides a number of hooks for the sake of customization. The hook | |
32 variables contain list of functions to be called with no arguments. To | |
33 turn on the auto-fill-mode, add the appropriate hook as shown in the | |
34 example above. | |
35 | |
36 Similarly, to enable the "font-lock mode" which displays your program in | |
37 different fonts and colors(@pxref{Modes}), put the following in your | |
38 @file{.emacs} file. The comments above the statement explain what the | |
39 statements do. | |
40 | |
41 @example | |
42 ;;; enables the font-lock-mode in Lisp Mode | |
43 (add-hook 'lisp-mode-hook 'turn-on-font-lock) | |
44 | |
45 ;;; enables the font-lock-mode in Texinfo Mode | |
46 (add-hook 'texinfo-mode-hook 'turn-on-font-lock) | |
47 | |
48 ;;; enables the font-lock mode in C Mode | |
49 (add-hook 'c-mode-hook 'turn-on-font-lock) | |
50 @end example | |
51 | |
52 To turn on the font-lock mode in other Major Modes like emacs-lisp, just | |
53 put the name of the mode with "-hook" appended to it as the middle | |
54 parameter in the above examples. You can also select the color that the | |
55 functions, comments or other keywords should be displayed in : | |
56 | |
57 @example | |
58 ;;; the function names will now be displayed in blue color | |
59 (set-face-foreground 'font-lock-function-name-face "blue") | |
60 | |
61 ;;; the comments will be displayed in forest green | |
62 (set-face-foreground 'font-lock-comment-face "forest green") | |
63 @end example | |
64 | |
65 @noindent | |
66 For other customizations regarding the font-lock face, look at the file | |
67 @file{/usr/local/lib/xemacs-19.11/etc/sample.emacs}. | |
68 | |
69 | |
70 | |
71 @comment node-name, next, previous, up | |
72 @menu | |
73 * Setting Variables:: Customizing Emacs variables | |
74 * Init File:: Some examples of Lisp expressions in | |
75 .emacs file | |
76 @end menu | |
77 | |
78 @node Setting Variables, Init File, Other Customizations, Other Customizations | |
79 @section Other Customizations | |
80 @cindex setting variables | |
81 @findex describe-variable | |
82 | |
83 In XEmacs, @dfn{variables} are used for internal record-keeping and | |
84 customizations. There are some variables called "options" which you can | |
85 use for customizations. To examine a variable use: | |
86 | |
87 @example | |
88 ;;; print the value and documentation of the variable, use either of the | |
89 ;;; following commands | |
90 C-h v | |
91 M-x describe variable | |
92 @end example | |
93 | |
94 After you type any of the above commands, you will be prompted for a | |
95 variable name in the @dfn{echo area}. Type in the name of the variable, | |
96 for example, type @var{case-fold-search} @key{RET} | |
97 Your window will split into two and you will see the following message | |
98 in that window: | |
99 | |
100 @example | |
101 case-fold-search's value is t | |
102 This value is specific to the current buffer. | |
103 | |
104 Documentation: | |
105 *Non-nil if searches should ignore case. | |
106 Automatically becomes buffer-local when set in any fashion. | |
107 | |
108 @end example | |
109 | |
110 @noindent | |
111 Since this variable's value is 't' searches will ignore case. If you | |
112 want case-sensitive-search (i.e. if you are searching for "Foo" and you do | |
113 not want "foo" to be included in the search, you need to set this | |
114 variable to "nil". In order to do that, use: | |
115 | |
116 @findex set-variable | |
117 @example | |
118 M-x set-variable | |
119 @end example | |
120 | |
121 @noindent | |
122 Emacs will prompt you for the variable which you wish to set. Type in | |
123 "case-fold-search" and hit @key{RET}. You will see the following | |
124 message: | |
125 | |
126 @example | |
127 Set case-fold-search to value: | |
128 @end example | |
129 | |
130 @noindent | |
131 Type "nil" and hit @key{RET}. Now if you again use @kbd{M-x describe | |
132 variable} , you will see that the new value of case-fold-search will be | |
133 "nil" and your searches will be case-sensitive. This will be effective | |
134 only for that Emacs session. If you want to change the value of a | |
135 variable permanently put the following statement in your @file{.emacs} | |
136 file : | |
137 | |
138 @example | |
139 (setq case-fold-search nil) | |
140 @end example | |
141 | |
142 @noindent | |
143 This statement will make searches case-sensitive only in the current | |
144 buffer which is the @file{.emacs} file. This will not be very useful. To | |
145 make searches case-sensitive globally in all buffers, use: | |
146 | |
147 @example | |
148 (setq-default case-fold-search nil) | |
149 @end example | |
150 | |
151 If you want to change the value of any other variable, use : | |
152 | |
153 @example | |
154 (setq <variable-name> <new value>) | |
155 @end example | |
156 | |
157 @noindent | |
158 "setq" will assign the "new value" to the "variable-name" . | |
159 | |
160 | |
161 If you want a list of the "options" i.e. the variables available for | |
162 customization type: | |
163 | |
164 @findex list-options | |
165 @findex edit-options | |
166 @example | |
167 | |
168 ;;; displays a buffer listing names, values and documentation of options | |
169 M-x list-options | |
170 | |
171 ;;; displays options and allows you to edit those list of options | |
172 M-x edit-options | |
173 | |
174 @end example | |
175 | |
176 @noindent | |
177 Try these options. If you are using edit-options to edit a variable, | |
178 just point at the variable you wish to edit and use one of the following | |
179 commands: | |
180 | |
181 @table @b | |
182 @item 1 | |
183 Set the value of the variable to t (non-nil). | |
184 @item 0 | |
185 Set the value of the variable to nil. | |
186 @item n | |
187 Move to the next variable. | |
188 @item p | |
189 Move to the previous variable. | |
190 @end table | |
191 | |
192 | |
193 There are some other options available to make the value of a variable | |
194 local to a buffer and then to switch to its global value. You can also | |
195 have a @dfn{local variables list} in a file which specifies the values | |
196 to use for certain Emacs variables when you edit that | |
197 file. @xref{Variables,,,,XEmacs User's Manual}, for information on | |
198 these options. | |
199 | |
200 | |
201 @comment node-name, next, previous, up | |
202 @node Init File, , Setting Variables, Other Customizations | |
203 @section Init File Examples | |
204 @cindex init file examples | |
205 | |
206 For customizing Emacs, you need to put Lisp expressions in your | |
207 @file{.emacs} file. The following are some useful Lisp expressions. If | |
208 you find any of them useful, just type them in your @file{.emacs} file: | |
209 | |
210 @itemize @bullet | |
211 @item | |
212 The following expression will make @key{TAB} in C mode insert a real tab | |
213 character if the cursor or point is in the middle of the line. Now | |
214 hitting the @key{TAB} key will indent a line only if the cursor is at | |
215 the left margin or in the line's indentation: | |
216 | |
217 @example | |
218 (setq c-tab-always-indent nil) | |
219 @end example | |
220 | |
221 @noindent | |
222 The value of the variable @var{c-tab-always-indent} is usually @samp{t} | |
223 for @samp{true}. When this variable is true, then hitting the @key{TAB} | |
224 key always indents the current line. | |
225 | |
226 @item | |
227 This expression will turn on the @var{auto-fill-mode} when you are in | |
228 text mode: | |
229 | |
230 @example | |
231 (setq text-mode-hook 'turn-on-auto-fill) | |
232 @end example | |
233 | |
234 This mode will automatically break lines when you type a space so that | |
235 the lines don't become too long. The length of the lines is controlled | |
236 by the variable @var{fill-column}. You can set this variable to a value | |
237 you wish. Look at the documentation for this variable to see its default | |
238 value. To change the value to 75 for example, use: | |
239 | |
240 @vindex fill-column | |
241 @example | |
242 (setq-default fill-column 75) | |
243 @end example | |
244 | |
245 @noindent | |
246 This will change the value of this variable globally. | |
247 | |
248 @item | |
249 @findex eval-expression | |
250 The following expression will enable the use of @var{eval-expression} | |
251 without confirmation: | |
252 | |
253 @example | |
254 (put 'eval-expression 'disabled nil) | |
255 @end example | |
256 | |
257 @noindent | |
258 Now when you use @var{eval-expression}, it will print the value of the | |
259 expression you specify in the @dfn{echo area} without confirming with | |
260 you. | |
261 | |
262 @item | |
263 This expression will remove the binding of @kbd{C-x C-c}, because its | |
264 easy to hit this key by mistake and you will exit Emacs | |
265 unintentionally. You can use the @b{Exit Emacs} option from the @b{File} | |
266 menu to exit Emacs. | |
267 | |
268 @example | |
269 (global-set-key "\C-x\C-c" nil) | |
270 @end example | |
271 | |
272 @noindent | |
273 Now if you type @kbd{C-x C-c}, you won't exit Emacs. | |
274 | |
275 @item | |
276 The following expression will make the @key{BACKSPACE} and the @key{DEL} | |
277 key work in the same manner: | |
278 | |
279 @example | |
280 (global-set-key 'backspace [delete]) | |
281 @end example | |
282 | |
283 @item | |
284 This expression will make searches case sensitive: | |
285 | |
286 @example | |
287 (setq-default case-fold-search nil) | |
288 @end example | |
289 | |
290 @noindent | |
291 If we use "setq" instead of "setq-default" then searches will be | |
292 case-sensitive only in the current buffer's local value. In this case the | |
293 buffer would be the @file{.emacs} file. Since this would not be too | |
294 helpful and we want to have case-sensitive searches in all buffers, we | |
295 have to use "setq-default". | |
296 | |
297 @item | |
298 This expression will enable the font-lock mode when you are using | |
299 texinfo mode: | |
300 | |
301 @example | |
302 (add-hook 'texinfo-mode-hook 'turn-on-font-lock) | |
303 @end example | |
304 | |
305 @noindent | |
306 @xref{Minor Modes}, for information on font-lock mode. | |
307 | |
308 @item | |
309 Rebinds the key @kbd{C-x l} to run the function | |
310 @code{make-symbolic-link}: | |
311 | |
312 @example | |
313 (global-set-key "\C-xl" 'make-symbolic-link) | |
314 @end example | |
315 | |
316 @noindent | |
317 We use the single quote before "make-symbolic-link" because its a | |
318 function name. You can also use the following expression which does the | |
319 same thing: | |
320 | |
321 @example | |
322 (define-key global-map "C-xl" 'make-symbolic-link) | |
323 @end example | |
324 | |
325 @item | |
326 The following expression will bind @kbd{C-x l} to run the function | |
327 @code{make-symbolic-link} in C mode only: | |
328 | |
329 @example | |
330 (define-key c-mode-map "C-xl" 'make-symbolic-link) | |
331 @end example | |
332 | |
333 @noindent | |
334 Instead of binding @kbd{C-xl} to run @code{make-symbolic-link}, you can | |
335 bind the @key{F1} key to run this function: | |
336 | |
337 @example | |
338 (define-key c-mode-map 'f1 'make-symbolic-link) | |
339 @end example | |
340 | |
341 @noindent | |
342 Here, you have to use lower case for naming function keys like @key{F1}. | |
343 | |
344 @item | |
345 You can bind the function @code{undo} i.e. @kbd{C-x u} to any key, for | |
346 example to @key{F2}: | |
347 | |
348 @example | |
349 (global-set-key 'f2 'undo) | |
350 @end example | |
351 | |
352 @item | |
353 The following statement will display the current time in the modeline of | |
354 the buffer: | |
355 | |
356 @vindex display-time | |
357 @cindex displaying time | |
358 @example | |
359 (display-time) | |
360 @end example | |
361 | |
362 @item | |
363 This displays the current line number on which the cursor is present in | |
364 the modeline: | |
365 | |
366 @example | |
367 (setq line-number-mode t) | |
368 @end example | |
369 | |
370 @item | |
371 If you don't want the text to be highlighted when you use commands for | |
372 marking regions so as to use the @dfn{kill} and @dfn{yank} commands | |
373 later, you can use the following expression in your @file{.emacs} file: | |
374 | |
375 @vindex zmacs-regions | |
376 @example | |
377 (setq zmacs-regions nil) | |
378 @end example | |
379 | |
380 @noindent | |
381 Now if you use a command like @kbd{C-x C-p} (@code{mark-page}), the text | |
382 will not be highlighted. | |
383 | |
384 @item | |
385 To control the number of buffers listed when you select the @b{Buffers} | |
386 menu, you need to set the variable @var{buffers-menu-max-size} to | |
387 whatever value you wish. For example, if you want 20 buffers to be listed | |
388 when you select @b{Buffers} use: | |
389 | |
390 @vindex buffers-menu-max-size | |
391 @example | |
392 (setq buffers-menu-max-size 20) | |
393 @end example | |
394 | |
395 @item | |
396 If you want the window title area to display the full directory/name of | |
397 the current buffer's file, and not just the name, use: | |
398 | |
399 @vindex frame-title-format | |
400 @example | |
401 (setq frame-title-format "%S: %f") | |
402 @end example | |
403 | |
404 @item | |
405 To get rid of the menu, use : | |
406 | |
407 @example | |
408 (set-menubar nil) | |
409 @end example | |
410 | |
411 @item | |
412 If you want an extensive menu-bar use the following expression in your | |
413 @file{.emacs} file. | |
414 | |
415 @example | |
416 (load "big-menubar") | |
417 @end example | |
418 | |
419 @noindent | |
420 If you want to write your own menus, you can look at some of the | |
421 examples in | |
422 @file{/usr/local/lib/xemacs-19.13/lisp/packages/big-menubar.el} file. | |
423 | |
424 @end itemize | |
425 | |
426 For more information on initializing your @file{.emacs} file, | |
427 @xref{Init File,,,,XEmacs User's Manual}. You should also look at | |
428 @file{/usr/local/lib/xemacs-19.13/etc/sample.emacs}, which is a sample | |
429 @file{.emacs} file. It contains some of the commonly desired | |
430 customizations in Emacs. | |
431 | |
432 | |
433 | |
434 | |
435 | |
436 | |
437 | |
438 | |
439 | |
440 | |
441 |