Mercurial > emacs
comparison man/display.texi @ 36554:9904afd52408
(Faces, Font Lock, Highlight Changes)
(Highlight Interactively, Trailing Whitespace): Moved here from
frames.texi.
(Faces): Changes for new face implementation.
(Font Lock): Remove dscription of M-g M-g since it isn't necessary
with jit-lock being the default.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Mon, 05 Mar 2001 19:59:46 +0000 |
parents | 11db0318031d |
children | ff26f01b3c8d |
comparison
equal
deleted
inserted
replaced
36553:714ab908c5e1 | 36554:9904afd52408 |
---|---|
1 @c This is part of the Emacs manual. | 1 @c This is part of the Emacs manual. |
2 @c Copyright (C) 1985, 86, 87, 93, 94, 95, 1997, 2000 Free Software Foundation, Inc. | 2 @c Copyright (C) 1985, 86, 87, 93, 94, 95, 1997, 2000, 2001 |
3 @c Free Software Foundation, Inc. | |
3 @c See file emacs.texi for copying conditions. | 4 @c See file emacs.texi for copying conditions. |
4 @node Display, Search, Registers, Top | 5 @node Display, Search, Registers, Top |
5 @chapter Controlling the Display | 6 @chapter Controlling the Display |
6 | 7 |
7 Since only part of a large buffer fits in the window, Emacs tries to | 8 Since only part of a large buffer fits in the window, Emacs tries to |
8 show a part that is likely to be interesting. Display-control commands | 9 show a part that is likely to be interesting. Display-control commands |
9 allow you to specify which part of the text you want to see, and how to | 10 allow you to specify which part of the text you want to see, and how to |
10 display it. | 11 display it. |
11 | 12 |
12 @menu | 13 @menu |
14 * Faces:: How to change the display style using faces. | |
15 * Font Lock:: Minor mode for syntactic highlighting using faces. | |
16 * Highlight Changes:: Using colors to show where you changed the buffer. | |
17 * Highlight Interactively:: Tell Emacs what text to highlight. | |
18 * Trailing Whitespace:: Showing possibly-spurious trailing whitespace. | |
13 * Scrolling:: Moving text up and down in a window. | 19 * Scrolling:: Moving text up and down in a window. |
14 * Horizontal Scrolling:: Moving text left and right in a window. | 20 * Horizontal Scrolling:: Moving text left and right in a window. |
15 * Follow Mode:: Follow mode lets two windows scroll as one. | 21 * Follow Mode:: Follow mode lets two windows scroll as one. |
16 * Selective Display:: Hiding lines with lots of indentation. | 22 * Selective Display:: Hiding lines with lots of indentation. |
17 * Optional Mode Line:: Optional mode line display features. | 23 * Optional Mode Line:: Optional mode line display features. |
18 * Text Display:: How text characters are normally displayed. | 24 * Text Display:: How text characters are normally displayed. |
19 * Display Custom:: Information on variables for customizing display. | 25 * Display Custom:: Information on variables for customizing display. |
20 * Cursor Display:: Features for displaying the cursor. | 26 * Cursor Display:: Features for displaying the cursor. |
21 @end menu | 27 @end menu |
28 | |
29 @node Faces | |
30 @section Using Multiple Typefaces | |
31 @cindex faces | |
32 | |
33 When using Emacs with a window system, you can set up multiple | |
34 styles of displaying characters. Some of the aspects of style that | |
35 you can control are the type font, the foreground color, the | |
36 background color, and whether or not to underline text, and in which | |
37 color. | |
38 | |
39 Features which rely on text in multiple faces (such as Font Lock | |
40 mode) will also work on non-windowed terminals (including | |
41 MS-DOS@pxref{MS-DOS}), that can display more than one face, whether by | |
42 colors or underlining and emboldening. This includes the console on | |
43 GNU/Linux. Emacs determines automatically whether the terminal has | |
44 this capability. | |
45 | |
46 The way you control display style is by defining named @dfn{faces}. | |
47 Each face can specify various attributes, like the type font's height, | |
48 weight and slant, foreground and background color, and underlining, | |
49 but it does not have to specify all of them. By specifying the face | |
50 or faces to use for a given part of the text in the buffer, you | |
51 control how that text appears. | |
52 | |
53 The style of display used for a given character in the text is | |
54 determined by combining several faces. Any aspect of the display | |
55 style that isn't specified by overlays or text properties comes from a | |
56 default face which inherits its settings from the frame itself. | |
57 | |
58 Enriched mode, the mode for editing formatted text, includes several | |
59 commands and menus for specifying faces. @xref{Format Faces}, for how | |
60 to specify the font for text in the buffer. @xref{Format Colors}, for | |
61 how to specify the foreground and background color. | |
62 | |
63 To alter the appearance of a face, use the customization buffer. | |
64 @xref{Face Customization}. You can also use X resources to specify | |
65 attributes of particular faces (@pxref{Resources X}). | |
66 | |
67 @cindex face colors, setting | |
68 @findex set-face-foreground | |
69 @findex set-face-background | |
70 Alternatively, you can change the foreground and background colors | |
71 of a specific face with @kbd{M-x set-face-foreground} and @kbd{M-x | |
72 set-face-background}. These commands prompt in the minibuffer for a | |
73 face name and a color name, with completion, and then set that face to | |
74 use the specified color. | |
75 | |
76 @findex list-faces-display | |
77 To see what faces are currently defined, and what they look like, type | |
78 @kbd{M-x list-faces-display}. It's possible for a given face to look | |
79 different in different frames; this command shows the appearance in the | |
80 frame in which you type it. Here's a list of the standardly defined | |
81 faces: | |
82 | |
83 @table @code | |
84 @item default | |
85 This face is used for ordinary text that doesn't specify any other face. | |
86 @item mode-line | |
87 This face is used for mode lines. By default, it's drawn with shadows | |
88 for a ``raised'' effect on window systems, and drawn as the inverse of | |
89 the default face on non-windowed terminals. @xref{Display Custom}. | |
90 @item header-line | |
91 Similar to @code{mode-line} for a window's header line. Most modes | |
92 don't use the header line, but the Info mode does. | |
93 @item highlight | |
94 This face is used for highlighting portions of text, in various modes. | |
95 For example, mouse-sensitive text is highlighted using this face. | |
96 @item isearch | |
97 This face is used for highlighting Isearch matches. | |
98 @item isearch-lazy-highlight-face | |
99 This face is used for lazy highlighting of Isearch matches other than | |
100 the current one. | |
101 @item region | |
102 This face is used for displaying a selected region (when Transient Mark | |
103 mode is enabled---see below). | |
104 @item secondary-selection | |
105 This face is used for displaying a secondary X selection (@pxref{Secondary | |
106 Selection}). | |
107 @item bold | |
108 This face uses a bold variant of the default font, if it has one. | |
109 @item italic | |
110 This face uses an italic variant of the default font, if it has one. | |
111 @item bold-italic | |
112 This face uses a bold italic variant of the default font, if it has one. | |
113 @item underline | |
114 This face underlines text. | |
115 @item fixed-pitch | |
116 The basic fixed-pitch face. | |
117 @item fringe | |
118 @cindex fringe | |
119 The face for the fringes to the left and right of windows on graphic | |
120 displays. (The fringes are the narrow portions of the Emacs frame | |
121 between the text area and the frame's border.) | |
122 @item scroll-bar | |
123 This face determines the visual appearance of the scroll bar. | |
124 @item border | |
125 This face determines the color of the frame border. | |
126 @item cursor | |
127 This face determines the color of the cursor. | |
128 @item mouse | |
129 This face determines the color of the mouse pointer. | |
130 @item tool-bar | |
131 This is the basic tool-bar face. No text appears in the tool bar, but the | |
132 colors of this face affect the appearance of tool bar icons. | |
133 @item tooltip | |
134 This face is used for tooltips. | |
135 @item menu | |
136 This face determines the colors and font of Emacs's menus. Setting the | |
137 font of LessTif/Motif menus is currently not supported; attempts to set | |
138 the font are ignored in this case. | |
139 @item trailing-whitespace | |
140 The face for highlighting trailing whitespace when | |
141 @code{show-trailing-whitespace} is non-nil. | |
142 @item variable-pitch | |
143 The basic variable-pitch face. | |
144 @end table | |
145 | |
146 @cindex @code{region} face | |
147 When Transient Mark mode is enabled, the text of the region is | |
148 highlighted when the mark is active. This uses the face named | |
149 @code{region}; you can control the style of highlighting by changing the | |
150 style of this face (@pxref{Face Customization}). @xref{Transient Mark}, | |
151 for more information about Transient Mark mode and activation and | |
152 deactivation of the mark. | |
153 | |
154 One easy way to use faces is to turn on Font Lock mode. This minor | |
155 mode, which is always local to a particular buffer, arranges to | |
156 choose faces according to the syntax of the text you are editing. It | |
157 can recognize comments and strings in most languages; in several | |
158 languages, it can also recognize and properly highlight various other | |
159 important constructs. @xref{Font Lock}, for more information about | |
160 Font Lock mode and syntactic highlighting. | |
161 | |
162 You can print out the buffer with the highlighting that appears | |
163 on your screen using the command @code{ps-print-buffer-with-faces}. | |
164 @xref{PostScript}. | |
165 | |
166 @node Font Lock | |
167 @section Font Lock mode | |
168 @cindex Font Lock mode | |
169 @cindex mode, Font Lock | |
170 @cindex syntax highlighting and coloring | |
171 | |
172 Font Lock mode is a minor mode, always local to a particular | |
173 buffer, which highlights (or ``fontifies'') using various faces | |
174 according to the syntax of the text you are editing. It can | |
175 recognize comments and strings in most languages; in several | |
176 languages, it can also recognize and properly highlight various other | |
177 important constructs---for example, names of functions being defined | |
178 or reserved keywords. | |
179 | |
180 @findex font-lock-mode | |
181 @findex turn-on-font-lock | |
182 The command @kbd{M-x font-lock-mode} turns Font Lock mode on or off | |
183 according to the argument, and toggles the mode when it has no argument. | |
184 The function @code{turn-on-font-lock} unconditionally enables Font Lock | |
185 mode. This is useful in mode-hook functions. For example, to enable | |
186 Font Lock mode whenever you edit a C file, you can do this: | |
187 | |
188 @example | |
189 (add-hook 'c-mode-hook 'turn-on-font-lock) | |
190 @end example | |
191 | |
192 @findex global-font-lock-mode | |
193 @vindex global-font-lock-mode | |
194 To turn on Font Lock mode automatically in all modes which support | |
195 it, customize the user option @code{global-font-lock-mode} or use the | |
196 function @code{global-font-lock-mode} in your @file{.emacs} file, like | |
197 this: | |
198 | |
199 @example | |
200 (global-font-lock-mode 1) | |
201 @end example | |
202 | |
203 Font Lock mode uses several specifically named faces to do its job, | |
204 including @code{font-lock-string-face}, @code{font-lock-comment-face}, | |
205 and others. The easiest way to find them all is to use completion | |
206 on the face name in @code{set-face-foreground}. | |
207 | |
208 To change the colors or the fonts used by Font Lock mode to fontify | |
209 different parts of text, just change these faces. There are | |
210 two ways to do it: | |
211 | |
212 @itemize @bullet | |
213 @item | |
214 Invoke @kbd{M-x set-face-foreground} or @kbd{M-x set-face-background} | |
215 to change the colors of a particular face used by Font Lock. | |
216 @xref{Faces}. The command @kbd{M-x list-faces-display} displays all | |
217 the faces currently known to Emacs, including those used by Font Lock. | |
218 | |
219 @item | |
220 Customize the faces interactively with @kbd{M-x customize-face}, as | |
221 described in @ref{Face Customization}. | |
222 @end itemize | |
223 | |
224 To get the full benefit of Font Lock mode, you need to choose a | |
225 default font which has bold, italic, and bold-italic variants; or else | |
226 you need to have a color or gray-scale screen. | |
227 | |
228 @vindex font-lock-maximum-decoration | |
229 The variable @code{font-lock-maximum-decoration} specifies the | |
230 preferred level of fontification, for modes that provide multiple | |
231 levels. Level 1 is the least amount of fontification; some modes | |
232 support levels as high as 3. The normal default is ``as high as | |
233 possible.'' You can specify an integer, which applies to all modes, or | |
234 you can specify different numbers for particular major modes; for | |
235 example, to use level 1 for C/C++ modes, and the default level | |
236 otherwise, use this: | |
237 | |
238 @example | |
239 (setq font-lock-maximum-decoration | |
240 '((c-mode . 1) (c++-mode . 1))) | |
241 @end example | |
242 | |
243 @vindex font-lock-maximum-size | |
244 Fontification can be too slow for large buffers, so you can suppress | |
245 it. The variable @code{font-lock-maximum-size} specifies a buffer size, | |
246 beyond which buffer fontification is suppressed. | |
247 | |
248 @c @w is used below to prevent a bad page-break. | |
249 @vindex font-lock-beginning-of-syntax-function | |
250 Comment and string fontification (or ``syntactic'' fontification) | |
251 relies on analysis of the syntactic structure of the buffer text. For | |
252 the purposes of speed, some modes including C mode and Lisp mode rely on | |
253 a special convention: an open-parenthesis in the leftmost column always | |
254 defines the @w{beginning} of a defun, and is thus always outside any string | |
255 or comment. (@xref{Defuns}.) If you don't follow this convention, | |
256 then Font Lock mode can misfontify the text after an open-parenthesis in | |
257 the leftmost column that is inside a string or comment. | |
258 | |
259 The variable @code{font-lock-beginning-of-syntax-function} (always | |
260 buffer-local) specifies how Font Lock mode can find a position | |
261 guaranteed to be outside any comment or string. In modes which use the | |
262 leftmost column parenthesis convention, the default value of the variable | |
263 is @code{beginning-of-defun}---that tells Font Lock mode to use the | |
264 convention. If you set this variable to @code{nil}, Font Lock no longer | |
265 relies on the convention. This avoids incorrect results, but the price | |
266 is that, in some cases, fontification for a changed text must rescan | |
267 buffer text from the beginning of the buffer. | |
268 | |
269 @findex font-lock-add-keywords | |
270 Font Lock highlighting patterns already exist for many modes, but you | |
271 may want to fontify additional patterns. You can use the function | |
272 @code{font-lock-add-keywords}, to add your own highlighting patterns for | |
273 a particular mode. For example, to highlight @samp{FIXME:} words in C | |
274 comments, use this: | |
275 | |
276 @example | |
277 (font-lock-add-keywords | |
278 'c-mode | |
279 '(("\\<\\(FIXME\\):" 1 font-lock-warning-face t))) | |
280 @end example | |
281 | |
282 @node Highlight Changes | |
283 @section Highlight Changes Mode | |
284 | |
285 @findex highlight-changes-mode | |
286 Use @kbd{M-x highlight-changes-mode} to enable a minor mode | |
287 that uses faces (colors, typically) to indicate which parts of | |
288 the buffer were changed most recently. | |
289 | |
290 @node Highlight Interactively | |
291 @section Interactive Highlighting by Matching | |
292 @cindex highlighting by matching | |
293 @cindex interactive highlighting | |
294 | |
295 It is sometimes useful to highlight the strings that match a certain | |
296 regular expression. For example, you might wish to see all the | |
297 references to a certain variable in a program source file, or highlight | |
298 certain parts in a voluminous output of some program, or make certain | |
299 cliches stand out in an article. | |
300 | |
301 @findex hi-lock-mode | |
302 Use the @kbd{M-x hi-lock-mode} command to turn on a minor mode that | |
303 allows you to specify regular expressions of the text to be | |
304 highlighted. Hi-lock mode works like Font Lock (@pxref{Font Lock}), | |
305 except that it lets you specify explicitly what parts of text to | |
306 highlight. You control Hi-lock mode with these commands: | |
307 | |
308 @table @kbd | |
309 @item C-x w h @var{regexp} @key{RET} @var{face} @key{RET} | |
310 @kindex C-x w h | |
311 @findex highlight-regexp | |
312 Highlight text that matches | |
313 @var{regexp} using face @var{face} (@code{highlight-regexp}). | |
314 By using this command more than once, you can highlight various | |
315 parts of the text in different ways. | |
316 | |
317 @item C-x w r @var{regexp} @key{RET} | |
318 @kindex C-x w r | |
319 @findex unhighlight-regexp | |
320 Unhighlight @var{regexp} (@code{unhighlight-regexp}). You must enter | |
321 one of the regular expressions currently specified for highlighting. | |
322 (You can use completion, or a menu, to enter one of them | |
323 conveniently.) | |
324 | |
325 @item C-x w l @var{regexp} @key{RET} @var{face} @key{RET} | |
326 @kindex C-x w l | |
327 @findex highlight-lines-matching-regexp | |
328 @cindex lines, highlighting | |
329 @cindex highlighting lines of text | |
330 Highlight lines containing a match for @var{regexp}, using face | |
331 @var{face} (@code{highlight-lines-matching-regexp}). | |
332 | |
333 @item C-x w b | |
334 @kindex C-x w b | |
335 @findex hi-lock-write-interactive-patterns | |
336 Insert all the current highlighting regexp/face pairs into the buffer | |
337 at point, with comment delimiters to prevent them from changing your | |
338 program. This key binding runs the | |
339 @code{hi-lock-write-interactive-patterns} command. | |
340 | |
341 These patterns will be read the next time you visit the file while | |
342 Hi-lock mode is enabled, or whenever you use the @kbd{M-x | |
343 hi-lock-find-patterns} command. | |
344 | |
345 @item C-x w i | |
346 @kindex C-x w i | |
347 @findex hi-lock-find-patterns | |
348 @vindex hi-lock-exclude-modes | |
349 Re-read regexp/face pairs in the current buffer | |
350 (@code{hi-lock-write-interactive-patterns}). The list of pairs is | |
351 found no matter where in the buffer it may be. | |
352 | |
353 This command does nothing if the major mode is a member of the list | |
354 @code{hi-lock-exclude-modes}. | |
355 @end table | |
356 | |
357 @node Trailing Whitespace | |
358 @section Trailing Whitespace | |
359 | |
360 @cindex trailing whitespace | |
361 @cindex whitespace, trailing | |
362 @vindex show-trailing-whitespace | |
363 It is easy to leave unnecessary spaces at the end of a line without | |
364 realizing it. In most cases, this @dfn{trailing whitespace} has no | |
365 effect, but there are special circumstances where it matters. | |
366 | |
367 You can make trailing whitespace visible on the screen by setting | |
368 the variable @code{show-trailing-whitespace} to @code{t}. Then Emacs | |
369 displays trailing whitespace in the face @code{trailing-whitespace}. | |
370 | |
371 Trailing whitespace is defined as spaces or tabs at the end of a | |
372 line. But trailing whitespace is not displayed specially if point is | |
373 at the end of the line containing the whitespace. (Doing that looks | |
374 ugly while you are typing in new text, and the location of point is | |
375 enough in that case to show you that the spaces are present.) | |
376 | |
377 @vindex indicate-empty-lines | |
378 @vindex default-indicate-empty-lines | |
379 @cindex empty lines | |
380 Emacs can indicate empty lines at the end of the buffer with a | |
381 special bitmap on the left fringe of the window. To enable this | |
382 feature, set the buffer-local variable @code{indicate-empty-lines} to | |
383 a non-@code{nil} value. The default value of this variable is | |
384 controlled by the variable @code{default-indicate-empty-lines}; | |
385 by setting that variable, you can enable or disable this feature | |
386 for all new buffers. | |
22 | 387 |
23 @node Scrolling | 388 @node Scrolling |
24 @section Scrolling | 389 @section Scrolling |
25 | 390 |
26 If a buffer contains text that is too large to fit entirely within a | 391 If a buffer contains text that is too large to fit entirely within a |