1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985, 86, 87, 93, 94, 95, 97, 99, 2000
3 @c Free Software Foundation, Inc.
4 @c See file emacs.texi for copying conditions.
5 @node Frames, International, Windows, Top
6 @chapter Frames and X Windows
9 When using the X Window System, you can create multiple windows at the
10 X level in a single Emacs session. Each X window that belongs to Emacs
11 displays a @dfn{frame} which can contain one or several Emacs windows.
12 A frame initially contains a single general-purpose Emacs window which
13 you can subdivide vertically or horizontally into smaller windows. A
14 frame normally contains its own echo area and minibuffer, but you can
15 make frames that don't have these---they use the echo area and
16 minibuffer of another frame.
18 Editing you do in one frame also affects the other frames. For
19 instance, if you put text in the kill ring in one frame, you can yank it
20 in another frame. If you exit Emacs through @kbd{C-x C-c} in one frame,
21 it terminates all the frames. To delete just one frame, use @kbd{C-x 5
24 To avoid confusion, we reserve the word ``window'' for the
25 subdivisions that Emacs implements, and never use it to refer to a
28 Emacs compiled for MS-DOS emulates some aspects of the window system
29 so that you can use many of the features described in this chapter.
30 @xref{MS-DOS Input}, for more information.
33 Emacs compiled for MS Windows mostly supports the same features as
34 under X. However, images, tool bars, and tooltips are not yet
35 available on MS Windows as of Emacs version 21.1.
37 Features which rely on text in multiple faces (such as Font Lock
38 mode) will also work on non-windowed terminals that can display more
39 than one face, whether by colors or underlining and emboldening. This
40 includes the console on GNU/Linux. Emacs determines automatically
41 whether the terminal has this capability.
44 * Mouse Commands:: Moving, cutting, and pasting, with the mouse.
45 * Secondary Selection:: Cutting without altering point and mark.
46 * Clipboard:: Using the clipboard for selections.
47 * Mouse References:: Using the mouse to select an item from a list.
48 * Menu Mouse Clicks:: Mouse clicks that bring up menus.
49 * Mode Line Mouse:: Mouse clicks on the mode line.
50 * Creating Frames:: Creating additional Emacs frames with various contents.
51 * Frame Commands:: Iconifying, deleting, and switching frames.
52 * Speedbar:: How to make and use a speedbar frame.
53 * Multiple Displays:: How one Emacs job can talk to several displays.
54 * Special Buffer Frames:: You can make certain buffers have their own frames.
55 * Frame Parameters:: Changing the colors and other modes of frames.
56 * Scroll Bars:: How to enable and disable scroll bars; how to use them.
57 * Wheeled Mice:: Using mouse wheels for scrolling.
58 * Menu Bars:: Enabling and disabling the menu bar.
59 * Tool Bars:: Enabling and disabling the tool bar.
60 * Dialog Boxes:: Controlling use of dialog boxes.
61 * Faces:: How to change the display style using faces.
62 * Font Lock:: Minor mode for syntactic highlighting using faces.
63 * Highlight Changes:: Using colors to show where you changed the buffer.
64 * Highlight Interactively:: Tell Emacs what text to highlight.
65 * Trailing Whitespace:: Showing possibly-spurious trailing whitespace.
66 * Tooltips:: Showing "tooltips", AKA "ballon help" for active text.
67 * Mouse Avoidance:: Moving the mouse pointer out of the way.
68 * Non-Window Terminals:: Multiple frames on terminals that show only one.
69 * XTerm Mouse:: Using the mouse in an XTerm terminal emulator.
73 @section Mouse Commands for Editing
74 @cindex mouse buttons (what they do)
76 The mouse commands for selecting and copying a region are mostly
77 compatible with the @code{xterm} program. You can use the same mouse
78 commands for copying between Emacs and other X client programs.
81 If you select a region with any of these mouse commands, and then
82 immediately afterward type the @key{DELETE} function key, it deletes the
83 region that you selected. The @key{BACKSPACE} function key and the
84 ASCII character @key{DEL} do not do this; if you type any other key
85 in between the mouse command and @key{DELETE}, it does not do this.
87 @findex mouse-set-region
88 @findex mouse-set-point
89 @findex mouse-yank-at-click
90 @findex mouse-save-then-click
96 Move point to where you click (@code{mouse-set-point}).
97 This is normally the left button.
100 Set the region to the text you select by dragging, and copy it to the
101 kill ring (@code{mouse-set-region}). You can specify both ends of the
102 region with this single command.
104 @vindex mouse-scroll-min-lines
105 If you move the mouse off the top or bottom of the window while
106 dragging, the window scrolls at a steady rate until you move the mouse
107 back into the window. This way, you can select regions that don't fit
108 entirely on the screen. The number of lines scrolled per step depends
109 on how far away from the window edge the mouse has gone; the variable
110 @code{mouse-scroll-min-lines} specifies a minimum step size.
113 Yank the last killed text, where you click (@code{mouse-yank-at-click}).
114 This is normally the middle button.
117 This command, @code{mouse-save-then-kill}, has several functions
118 depending on where you click and the status of the region.
120 The most basic case is when you click @kbd{Mouse-1} in one place and
121 then @kbd{Mouse-3} in another. This selects the text between those two
122 positions as the region. It also copies the new region to the kill
123 ring, so that you can copy it to someplace else.
125 If you click @kbd{Mouse-1} in the text, scroll with the scroll bar, and
126 then click @kbd{Mouse-3}, it remembers where point was before scrolling
127 (where you put it with @kbd{Mouse-1}), and uses that position as the
128 other end of the region. This is so that you can select a region that
129 doesn't fit entirely on the screen.
131 More generally, if you do not have a highlighted region, @kbd{Mouse-3}
132 selects the text between point and the click position as the region. It
133 does this by setting the mark where point was, and moving point to where
136 If you have a highlighted region, or if the region was set just before
137 by dragging button 1, @kbd{Mouse-3} adjusts the nearer end of the region
138 by moving it to where you click. The adjusted region's text also
139 replaces the old region's text in the kill ring.
141 If you originally specified the region using a double or triple
142 @kbd{Mouse-1}, so that the region is defined to consist of entire words
143 or lines, then adjusting the region with @kbd{Mouse-3} also proceeds by
144 entire words or lines.
146 If you use @kbd{Mouse-3} a second time consecutively, at the same place,
147 that kills the region already selected.
150 This key sets the region around the word which you click on. If you
151 click on a character with ``symbol'' syntax (such as underscore, in C
152 mode), it sets the region around the symbol surrounding that character.
154 If you click on a character with open-parenthesis or close-parenthesis
155 syntax, it sets the region around the parenthetical grouping (sexp)
156 which that character starts or ends. If you click on a character with
157 string-delimiter syntax (such as a singlequote or doublequote in C), it
158 sets the region around the string constant (using heuristics to figure
159 out whether that character is the beginning or the end of it).
161 @item Double-Drag-Mouse-1
162 This key selects a region made up of the words you drag across.
165 This key sets the region around the line you click on.
167 @item Triple-Drag-Mouse-1
168 This key selects a region made up of the lines you drag across.
171 The simplest way to kill text with the mouse is to press @kbd{Mouse-1}
172 at one end, then press @kbd{Mouse-3} twice at the other end.
173 @xref{Killing}. To copy the text into the kill ring without deleting it
174 from the buffer, press @kbd{Mouse-3} just once---or just drag across the
175 text with @kbd{Mouse-1}. Then you can copy it elsewhere by yanking it.
177 @vindex mouse-yank-at-point
178 To yank the killed or copied text somewhere else, move the mouse there
179 and press @kbd{Mouse-2}. @xref{Yanking}. However, if
180 @code{mouse-yank-at-point} is non-@code{nil}, @kbd{Mouse-2} yanks at
181 point. Then it does not matter where you click, or even which of the
182 frame's windows you click on. The default value is @code{nil}. This
183 variable also affects yanking the secondary selection.
185 @cindex cutting and X
186 @cindex pasting and X
187 @cindex X cutting and pasting
188 To copy text to another X window, kill it or save it in the kill ring.
189 Under X, this also sets the @dfn{primary selection}. Then use the
190 ``paste'' or ``yank'' command of the program operating the other window
191 to insert the text from the selection.
193 To copy text from another X window, use the ``cut'' or ``copy'' command
194 of the program operating the other window, to select the text you want.
195 Then yank it in Emacs with @kbd{C-y} or @kbd{Mouse-2}.
197 These cutting and pasting commands also work on MS-Windows.
199 @cindex primary selection
201 @cindex selection, primary
202 @vindex x-cut-buffer-max
203 When Emacs puts text into the kill ring, or rotates text to the front
204 of the kill ring, it sets the @dfn{primary selection} in the X server.
205 This is how other X clients can access the text. Emacs also stores the
206 text in the cut buffer, but only if the text is short enough
207 (@code{x-cut-buffer-max} specifies the maximum number of characters);
208 putting long strings in the cut buffer can be slow.
210 The commands to yank the first entry in the kill ring actually check
211 first for a primary selection in another program; after that, they check
212 for text in the cut buffer. If neither of those sources provides text
213 to yank, the kill ring contents are used.
215 @node Secondary Selection
216 @section Secondary Selection
217 @cindex secondary selection
219 The @dfn{secondary selection} is another way of selecting text using
220 X. It does not use point or the mark, so you can use it to kill text
221 without setting point or the mark.
224 @findex mouse-set-secondary
225 @kindex M-Drag-Mouse-1
227 Set the secondary selection, with one end at the place where you press
228 down the button, and the other end at the place where you release it
229 (@code{mouse-set-secondary}). The highlighting appears and changes as
232 If you move the mouse off the top or bottom of the window while
233 dragging, the window scrolls at a steady rate until you move the mouse
234 back into the window. This way, you can mark regions that don't fit
235 entirely on the screen.
237 @findex mouse-start-secondary
240 Set one endpoint for the @dfn{secondary selection}
241 (@code{mouse-start-secondary}).
243 @findex mouse-secondary-save-then-kill
246 Make a secondary selection, using the place specified with @kbd{M-Mouse-1}
247 as the other end (@code{mouse-secondary-save-then-kill}). A second click
248 at the same place kills the secondary selection just made.
250 @findex mouse-yank-secondary
253 Insert the secondary selection where you click
254 (@code{mouse-yank-secondary}). This places point at the end of the
258 Double or triple clicking of @kbd{M-Mouse-1} operates on words and
259 lines, much like @kbd{Mouse-1}.
261 If @code{mouse-yank-at-point} is non-@code{nil}, @kbd{M-Mouse-2}
262 yanks at point. Then it does not matter precisely where you click; all
263 that matters is which window you click on. @xref{Mouse Commands}.
266 @section Using the Clipboard
269 @vindex x-select-enable-clipboard
270 @findex menu-bar-enable-clipboard
274 As well as the primary and secondary selection types, X supports a
275 @dfn{clipboard} selection type which is used by some applications,
276 particularly under OpenWindows and Gnome.
278 The command @kbd{M-x menu-bar-enable-clipboard} makes the @code{Cut},
279 @code{Paste} and @code{Copy} menu items, as well as the keys of the same
280 names, all use the clipboard.
282 You can customize the option @code{x-select-enable-clipboard} to make
283 the Emacs yank functions consult the clipboard before the primary
284 selection, and to make the kill functions to store in the clipboard as
285 well as the primary selection. Otherwise they do not access the
286 clipboard at all. Using the clipboard is the default on MS-Windows,
289 @node Mouse References
290 @section Following References with the Mouse
291 @kindex Mouse-2 @r{(selection)}
293 Some Emacs buffers display lists of various sorts. These include
294 lists of files, of buffers, of possible completions, of matches for
295 a pattern, and so on.
297 Since yanking text into these buffers is not very useful, most of them
298 define @kbd{Mouse-2} specially, as a command to use or view the item you
301 For example, if you click @kbd{Mouse-2} on a file name in a Dired
302 buffer, you visit that file. If you click @kbd{Mouse-2} on an error
303 message in the @samp{*Compilation*} buffer, you go to the source code
304 for that error message. If you click @kbd{Mouse-2} on a completion in
305 the @samp{*Completions*} buffer, you choose that completion.
307 You can usually tell when @kbd{Mouse-2} has this special sort of
308 meaning because the sensitive text highlights when you move the mouse
311 @node Menu Mouse Clicks
312 @section Mouse Clicks for Menus
314 Mouse clicks modified with the @key{CTRL} and @key{SHIFT} keys
321 @cindex MSB minor mode
323 This menu is for selecting a buffer.
325 The MSB (`mouse select buffer') global minor mode alters this menu to a
326 form some people prefer and which is customizable. See the Custom group
327 @code{msb} (@pxref{Easy Customization}).
331 This menu is for specifying faces and other text properties
332 for editing formatted text. @xref{Formatted Text}.
336 This menu is mode-specific. For most modes if Menu-bar mode is on, this
337 menu has the same items as all the mode-specific menu-bar menus put
338 together. Some modes may specify a different menu for this
339 button.@footnote{Some systems use @kbd{Mouse-3} for a mode-specific
340 menu. We took a survey of users, and found they preferred to keep
341 @kbd{Mouse-3} for selecting and killing regions. Hence the decision to
342 use @kbd{C-Mouse-3} for this menu.} If Menu-bar mode is off, this menu
343 contains all the items which would be present in the menu bar---not just
344 the mode-specific ones---so that you can access them without having to
345 display the menu bar.
348 This menu is for specifying the frame's principal font.
351 @node Mode Line Mouse
352 @section Mode Line Mouse Commands
353 @cindex mode line, mouse
354 @cindex mouse on mode line
356 You can use mouse clicks on window mode lines to select and manipulate
361 @kindex Mouse-1 @r{(mode line)}
362 @kbd{Mouse-1} on a mode line selects the window above. By dragging
363 @kbd{Mouse-1} on the mode line, you can move it, thus changing the
364 height of the windows above and below.
367 @kindex Mouse-2 @r{(mode line)}
368 @kbd{Mouse-2} on a mode line expands that window to fill its frame.
371 @kindex Mouse-3 @r{(mode line)}
372 @kbd{Mouse-3} on a mode line deletes the window above. If the frame has
373 only one window, it buries the current buffer instead and switches to
377 @kindex C-mouse-2 @r{(mode line)}
378 @kbd{C-Mouse-2} on a mode line splits the window above
379 horizontally, above the place in the mode line where you click.
382 @kindex C-Mouse-2 @r{(scroll bar)}
383 @kbd{C-Mouse-2} on a scroll bar splits the corresponding window
384 vertically, unless you are using an X toolkit's implentation of
385 scroll bars. @xref{Split Window}.
387 The commands above apply to areas of the mode line which do not have
388 special mouse bindings of their own. Some areas, such as the buffer
389 name and the major mode name, have their own special mouse bindings.
390 Emacs displays information about these bindings when you hold the
391 mouse over such a place.
393 @node Creating Frames
394 @section Creating Frames
395 @cindex creating frames
398 The prefix key @kbd{C-x 5} is analogous to @kbd{C-x 4}, with parallel
399 subcommands. The difference is that @kbd{C-x 5} commands create a new
400 frame rather than just a new window in the selected frame (@pxref{Pop
401 Up Window}). If an existing visible or iconified frame already displays
402 the requested material, these commands use the existing frame, after
403 raising or deiconifying as necessary.
405 The various @kbd{C-x 5} commands differ in how they find or create the
411 @findex delete-other-frames
412 Delete all frames except the selected one (@code{delete-other-frames}).
415 @findex make-frame-command
416 Create a new frame (@code{make-frame-command}).
417 @item C-x 5 b @var{bufname} @key{RET}
418 Select buffer @var{bufname} in another frame. This runs
419 @code{switch-to-buffer-other-frame}.
420 @item C-x 5 f @var{filename} @key{RET}
421 Visit file @var{filename} and select its buffer in another frame. This
422 runs @code{find-file-other-frame}. @xref{Visiting}.
423 @item C-x 5 d @var{directory} @key{RET}
424 Select a Dired buffer for directory @var{directory} in another frame.
425 This runs @code{dired-other-frame}. @xref{Dired}.
427 Start composing a mail message in another frame. This runs
428 @code{mail-other-frame}. It is the other-frame variant of @kbd{C-x m}.
431 Find a tag in the current tag table in another frame. This runs
432 @code{find-tag-other-frame}, the multiple-frame variant of @kbd{M-.}.
434 @item C-x 5 r @var{filename} @key{RET}
436 @findex find-file-read-only-other-frame
437 Visit file @var{filename} read-only, and select its buffer in another
438 frame. This runs @code{find-file-read-only-other-frame}.
442 @cindex default-frame-alist
443 @cindex initial-frame-alist
444 You can control the appearance of new frames you create by setting the
445 frame parameters in @code{default-frame-alist}. You can use the
446 variable @code{initial-frame-alist} to specify parameters that affect
447 only the initial frame. @xref{Initial Parameters,,, elisp, The Emacs
448 Lisp Reference Manual}, for more information.
450 @cindex font (default)
451 The easiest way to specify the principal font for all your Emacs
452 frames is with an X resource (@pxref{Font X}), but you can also do it by
453 modifying @code{default-frame-alist} to specify the @code{font}
454 parameter, as shown here:
457 (add-to-list 'default-frame-alist '(font . "10x20"))
461 @section Frame Commands
463 The following commands let you create, delete and operate on frames:
467 @kindex C-z @r{(X windows)}
468 @findex iconify-or-deiconify-frame
469 Iconify the selected Emacs frame (@code{iconify-or-deiconify-frame}).
470 The normal meaning of @kbd{C-z}, to suspend Emacs, is not useful under a
471 window system, so it has a different binding in that case.
473 If you type this command on an Emacs frame's icon, it deiconifies the frame.
478 Delete the selected frame (@code{delete-frame}). This is not allowed if
479 there is only one frame.
484 Select another frame, raise it, and warp the mouse to it so that it
485 stays selected. If you repeat this command, it cycles through all the
486 frames on your terminal.
490 @findex delete-other-frames
491 Delete all frames except the selected one.
495 @section Making and Using a Speedbar Frame
498 An Emacs frame can have a @dfn{speedbar}, which is a vertical window
499 that serves as a scrollable menu of files you could visit and tags
500 within those files. To create a speedbar, type @kbd{M-x speedbar}; this
501 creates a speedbar window for the selected frame. From then on, you can
502 click on a file name in the speedbar to visit that file in the
503 corresponding Emacs frame, or click on a tag name to jump to that tag in
506 Initially the speedbar lists the immediate contents of the current
507 directory, one file per line. Each line also has a box, @samp{[+]} or
508 @samp{<+>}, that you can click on with @kbd{Mouse-2} to ``open up'' the
509 contents of that item. If the line names a directory, opening it adds
510 the contents of that directory to the speedbar display, underneath the
511 directory's own line. If the line lists an ordinary file, opening it up
512 adds a list of the tags in that file to the speedbar display. When a
513 file is opened up, the @samp{[+]} changes to @samp{[-]}; you can click
514 on that box to ``close up'' that file (hide its contents).
516 Some major modes, including Rmail mode, Info, and GUD, have
517 specialized ways of putting useful items into the speedbar for you to
518 select. For example, in Rmail mode, the speedbar shows a list of Rmail
519 files, and lets you move the current message to another Rmail file by
520 clicking on its @samp{<M>} box.
522 A speedbar belongs to one Emacs frame, and always operates on that
523 frame. If you use multiple frames, you can make a speedbar for some or
524 all of the frames; type @kbd{M-x speedbar} in any given frame to make a
527 @node Multiple Displays
528 @section Multiple Displays
529 @cindex multiple displays
531 A single Emacs can talk to more than one X display. Initially, Emacs
532 uses just one display---the one specified with the @env{DISPLAY}
533 environment variable or with the @samp{--display} option (@pxref{Initial
534 Options}). To connect to another display, use the command
535 @code{make-frame-on-display}:
537 @findex make-frame-on-display
539 @item M-x make-frame-on-display @key{RET} @var{display} @key{RET}
540 Create a new frame on display @var{display}.
543 A single X server can handle more than one screen. When you open
544 frames on two screens belonging to one server, Emacs knows they share a
545 single keyboard, and it treats all the commands arriving from these
546 screens as a single stream of input.
548 When you open frames on different X servers, Emacs makes a separate
549 input stream for each server. This way, two users can type
550 simultaneously on the two displays, and Emacs will not garble their
551 input. Each server also has its own selected frame. The commands you
552 enter with a particular X server apply to that server's selected frame.
554 Despite these features, people using the same Emacs job from different
555 displays can still interfere with each other if they are not careful.
556 For example, if any one types @kbd{C-x C-c}, that exits the Emacs job
559 @node Special Buffer Frames
560 @section Special Buffer Frames
562 @vindex special-display-buffer-names
563 You can make certain chosen buffers, for which Emacs normally creates
564 a second window when you have just one window, appear in special frames
565 of their own. To do this, set the variable
566 @code{special-display-buffer-names} to a list of buffer names; any
567 buffer whose name is in that list automatically gets a special frame,
568 when an Emacs command wants to display it ``in another window.''
570 For example, if you set the variable this way,
573 (setq special-display-buffer-names
574 '("*Completions*" "*grep*" "*tex-shell*"))
578 then completion lists, @code{grep} output and the @TeX{} mode shell
579 buffer get individual frames of their own. These frames, and the
580 windows in them, are never automatically split or reused for any other
581 buffers. They continue to show the buffers they were created for,
582 unless you alter them by hand. Killing the special buffer deletes its
585 @vindex special-display-regexps
586 More generally, you can set @code{special-display-regexps} to a list
587 of regular expressions; then a buffer gets its own frame if its name
588 matches any of those regular expressions. (Once again, this applies only
589 to buffers that normally get displayed for you in a separate window.)
591 @vindex special-display-frame-alist
592 The variable @code{special-display-frame-alist} specifies the frame
593 parameters for these frames. It has a default value, so you don't need
596 For those who know Lisp, an element of
597 @code{special-display-buffer-names} or @code{special-display-regexps}
598 can also be a list. Then the first element is the buffer name or
599 regular expression; the rest of the list specifies how to create the
600 frame. It can be an association list specifying frame parameter values;
601 these values take precedence over parameter values specified in
602 @code{special-display-frame-alist}. Alternatively, it can have this
606 (@var{function} @var{args}...)
610 where @var{function} is a symbol. Then the frame is constructed by
611 calling @var{function}; its first argument is the buffer, and its
612 remaining arguments are @var{args}.
614 An analogous feature lets you specify buffers which should be
615 displayed in the selected window. @xref{Force Same Window}. The
616 same-window feature takes precedence over the special-frame feature;
617 therefore, if you add a buffer name to
618 @code{special-display-buffer-names} and it has no effect, check to see
619 whether that feature is also in use for the same buffer name.
621 @node Frame Parameters
622 @section Setting Frame Parameters
624 @cindex Auto-Raise mode
625 @cindex Auto-Lower mode
627 This section describes commands for altering the display style and
628 window management behavior of the selected frame.
630 @findex set-foreground-color
631 @findex set-background-color
632 @findex set-cursor-color
633 @findex set-mouse-color
634 @findex set-border-color
635 @findex auto-raise-mode
636 @findex auto-lower-mode
638 @item M-x set-foreground-color @key{RET} @var{color} @key{RET}
639 Specify color @var{color} for the foreground of the selected frame.
640 (This also changes the foreground color of the default face.)
642 @item M-x set-background-color @key{RET} @var{color} @key{RET}
643 Specify color @var{color} for the background of the selected frame.
644 (This also changes the background color of the default face.)
646 @item M-x set-cursor-color @key{RET} @var{color} @key{RET}
647 Specify color @var{color} for the cursor of the selected frame.
649 @item M-x set-mouse-color @key{RET} @var{color} @key{RET}
650 Specify color @var{color} for the mouse cursor when it is over the
653 @item M-x set-border-color @key{RET} @var{color} @key{RET}
654 Specify color @var{color} for the border of the selected frame.
656 @item M-x list-colors-display
657 Display the defined color names and show what the colors look like.
658 This command is somewhat slow.
660 @item M-x auto-raise-mode
661 Toggle whether or not the selected frame should auto-raise. Auto-raise
662 means that every time you move the mouse onto the frame, it raises the
665 Note that this auto-raise feature is implemented by Emacs itself. Some
666 window managers also implement auto-raise. If you enable auto-raise for
667 Emacs frames in your X window manager, it should work, but it is beyond
668 Emacs's control and therefore @code{auto-raise-mode} has no effect on
671 @item M-x auto-lower-mode
672 Toggle whether or not the selected frame should auto-lower.
673 Auto-lower means that every time you move the mouse off the frame,
674 the frame moves to the bottom of the stack of X windows.
676 The command @code{auto-lower-mode} has no effect on auto-lower
677 implemented by the X window manager. To control that, you must use
678 the appropriate window manager features.
680 @findex set-frame-font
681 @item M-x set-frame-font @key{RET} @var{font} @key{RET}
682 @cindex font (principal)
683 Specify font @var{font} as the principal font for the selected frame.
684 The principal font controls several face attributes of the
685 @code{default} face (@pxref{Faces}). For example, if the principal font
686 has a height of 12 pt, all text will be drawn in 12 pt fonts, unless you
687 use another face that specifies a different height. @xref{Font X}, for
688 ways to list the available fonts on your system.
691 You can also set a frame's principal font through a pop-up menu.
692 Press @kbd{S-Mouse-1} to activate this menu.
695 In Emacs versions that use an X toolkit, the color-setting and
696 font-setting functions don't affect menus and the menu bar, since they
697 are displayed by their own widget classes. To change the appearance of
698 the menus and menu bar, you must use X resources (@pxref{Resources X}).
699 @xref{Colors X}, regarding colors. @xref{Font X}, regarding choice of
702 For information on frame parameters and customization, see @ref{Frame
703 Parameters,,, elisp, The Emacs Lisp Reference Manual}.
707 @cindex Scroll Bar mode
708 @cindex mode, Scroll Bar
710 When using X, Emacs normally makes a @dfn{scroll bar} at the left of
711 each Emacs window.@footnote{Placing it at the left is usually more
712 useful with overlapping frames with text starting at the left margin.}
713 The scroll bar runs the height of the window, and shows a moving
714 rectangular inner box which represents the portion of the buffer
715 currently displayed. The entire height of the scroll bar represents the
716 entire length of the buffer.
718 You can use @kbd{Mouse-2} (normally, the middle button) in the scroll
719 bar to move or drag the inner box up and down. If you move it to the
720 top of the scroll bar, you see the top of the buffer. If you move it to
721 the bottom of the scroll bar, you see the bottom of the buffer.
723 The left and right buttons in the scroll bar scroll by controlled
724 increments. @kbd{Mouse-1} (normally, the left button) moves the line at
725 the level where you click up to the top of the window. @kbd{Mouse-3}
726 (normally, the right button) moves the line at the top of the window
727 down to the level where you click. By clicking repeatedly in the same
728 place, you can scroll by the same distance over and over.
730 If you are using Emacs's own implementation of scroll bars, as opposed
731 to scroll bars from an X toolkit, you can also click @kbd{C-Mouse-2} in
732 the scroll bar to split a window vertically. The split occurs on the
733 line where you click.
735 @findex scroll-bar-mode
736 @vindex scroll-bar-mode
737 You can enable or disable Scroll Bar mode with the command @kbd{M-x
738 scroll-bar-mode}. With no argument, it toggles the use of scroll bars.
739 With an argument, it turns use of scroll bars on if and only if the
740 argument is positive. This command applies to all frames, including
741 frames yet to be created. Customize the option @code{scroll-bar-mode}
742 to control the use of scroll bars at startup. You can use it to specify
743 that they are placed at the right of windows if you prefer that. You
744 can use the X resource @samp{verticalScrollBars} to control the initial
745 setting of Scroll Bar mode similarly. @xref{Resources X}.
747 @findex toggle-scroll-bar
748 To enable or disable scroll bars for just the selected frame, use the
749 @kbd{M-x toggle-scroll-bar} command.
752 @section Scrolling With ``Wheeled'' Mice
755 @findex mouse-wheel-install
756 Some mice have a ``wheel'' instead of a third button. You can usually
757 click the wheel to act as @kbd{Mouse-3}. You can also use the wheel to
758 scroll windows instead of using the scroll bar or keyboard commands.
759 Use @kbd{M-x mouse-wheel-install} to set up the wheel for scrolling or put
760 @samp{(require 'mouse-wheel)} in your @file{.emacs}. (Support for the wheel
761 depends on the system generating appropriate events for Emacs.)
763 @vindex mouse-wheel-follow-mouse
764 @vindex mouse-wheel-scroll-amount
765 The variables @code{mouse-wheel-follow-mouse} and
766 @code{mouse-wheel-scroll-amount} determine where and by how much
767 buffers are scrolled.
771 @cindex Menu Bar mode
772 @cindex mode, Menu Bar
774 You can turn display of menu bars on or off with @kbd{M-x
775 menu-bar-mode} or by customizing the option @code{menu-bar-mode}.
776 With no argument, this command toggles Menu Bar mode, a
777 minor mode. With an argument, the command turns Menu Bar mode on if the
778 argument is positive, off if the argument is not positive. You can use
779 the X resource @samp{menuBarLines} to control the initial setting of
780 Menu Bar mode. @xref{Resources X}.
782 @kindex C-Mouse-3 @r{(when menu bar is disabled)}
783 Expert users often turn off the menu bar, especially on text-only
784 terminals, where this makes one additional line available for text.
785 If the menu bar is off, you can still pop up a menu of its contents
786 with @kbd{C-Mouse-3} on a display which supports popup menus.
787 @xref{Menu Mouse Clicks}.
789 @xref{Menu Bar}, for information on how to invoke commands with the
794 @cindex Tool Bar mode
795 @cindex mode, Tool Bar
796 @cindex icons, tool bar
798 The @dfn{tool bar} is a line (or multiple lines) of icons at the top
799 of the Emacs window. You can click on these icons with the mouse
802 The global tool bar contains general commands. Some major modes
803 define their own tool bars to replace it. A few ``special'' modes
804 that are not designed for ordinary editing remove some items from the
807 Tool bars work only on a graphical display. The tool bar uses colored
808 XPM icons if Emacs was built with XPM support. Otherwise, the tool
809 bar uses monochrome icons (PBM or XBM format).
811 You can turn display of tool bars on or off with @kbd{M-x
815 @section Using Dialog Boxes
818 @vindex use-dialog-box
819 A dialog box is a special kind of menu for asking you a yes-or-no
820 question or some other special question. Many Emacs commands use a
821 dialog box to ask a yes-or-no question, if you used the mouse to
822 invoke the command to begin with.
824 You can customize the option @code{use-dialog-box} to suppress the
825 use of dialog boxes. This also controls whether to use file selection
826 windows (but those are not supported on all platforms).
829 @section Using Multiple Typefaces
832 When using Emacs with a window system, you can set up multiple
833 styles of displaying characters. The aspects of style that you can
834 control are the type font, the foreground color, the background color,
835 and whether to underline. On non-windowed terminals (including
836 MS-DOS, @pxref{MS-DOS}), Emacs supports faces to the extent the
837 terminal can display them.
839 The way you control display style is by defining named @dfn{faces}.
840 Each face can specify a type font, a foreground color, a background
841 color, and an underline flag; but it does not have to specify all of
842 them. Then by specifying the face or faces to use for a given part
843 of the text in the buffer, you control how that text appears.
845 The style of display used for a given character in the text is
846 determined by combining several faces. Any aspect of the display style
847 that isn't specified by overlays or text properties comes from the frame
850 Enriched mode, the mode for editing formatted text, includes several
851 commands and menus for specifying faces. @xref{Format Faces}, for how
852 to specify the font for text in the buffer. @xref{Format Colors}, for
853 how to specify the foreground and background color.
855 To alter the appearance of a face, use the customization buffer.
856 @xref{Face Customization}. You can also use X resources to specify
857 attributes of particular faces (@pxref{Resources X}).
859 @cindex face colors, setting
860 @findex set-face-foreground
861 @findex set-face-background
862 Alternatively, you can change the foreground and background colors
863 of a specific face with @kbd{M-x set-face-foreground} and @kbd{M-x
864 set-face-background}. These commands prompt in the minibuffer for a
865 face name and a color name, with completion, and then set that face to
866 use the specified color.
868 @findex list-faces-display
869 To see what faces are currently defined, and what they look like, type
870 @kbd{M-x list-faces-display}. It's possible for a given face to look
871 different in different frames; this command shows the appearance in the
872 frame in which you type it. Here's a list of the standardly defined
877 This face is used for ordinary text that doesn't specify any other face.
879 This face is used for mode lines. By default, it's drawn with shadows
880 for a ``raised'' effect on window systems, and drawn as the inverse of
881 the default face on non-windowed terminals. @xref{Display Custom}.
883 Similar to @code{mode-line} for a window's header line. Most modes
884 don't use the header line, but the Info mode does.
886 This face is used for highlighting portions of text, in various modes.
887 For example, mouse-sensitive text is highlighted using this face.
889 This face is used for highlighting Isearch matches.
890 @item isearch-lazy-highlight-face
891 This face is used for lazy highlighting of Isearch matches other than
894 This face is used for displaying a selected region (when Transient Mark
895 mode is enabled---see below).
896 @item secondary-selection
897 This face is used for displaying a secondary X selection (@pxref{Secondary
900 This face uses a bold variant of the default font, if it has one.
902 This face uses an italic variant of the default font, if it has one.
904 This face uses a bold italic variant of the default font, if it has one.
906 This face underlines text.
908 The basic fixed-pitch face.
911 The face for the fringes to the left and right of windows on graphic
912 displays. (The fringes are the narrow portions of the Emacs frame
913 between the text area and the frame's border.)
915 This face determines the visual appearance of the scroll bar.
917 This face determines the color of the frame border.
919 This face determines the color of the cursor.
921 This face determines the color of the mouse pointer.
923 This is the basic tool-bar face. No text appears in the tool bar, but the
924 colors of this face affect the appearance of tool bar icons.
926 This face is used for tooltips.
928 This face determines the colors and font of Emacs's menus. Setting the
929 font of LessTif/Motif menus is currently not supported; attempts to set
930 the font are ignored in this case.
931 @item trailing-whitespace
932 The face for highlighting trailing whitespace when
933 @code{show-trailing-whitespace} is non-nil.
935 The basic variable-pitch face.
938 @cindex @code{region} face
939 When Transient Mark mode is enabled, the text of the region is
940 highlighted when the mark is active. This uses the face named
941 @code{region}; you can control the style of highlighting by changing the
942 style of this face (@pxref{Face Customization}). @xref{Transient Mark},
943 for more information about Transient Mark mode and activation and
944 deactivation of the mark.
946 One easy way to use faces is to turn on Font Lock mode. This minor
947 mode, which is always local to a particular buffer, arranges to
948 choose faces according to the syntax of the text you are editing. It
949 can recognize comments and strings in most languages; in several
950 languages, it can also recognize and properly highlight various other
951 important constructs. @xref{Font Lock}, for more information about
952 Font Lock mode and syntactic highlighting.
954 You can print out the buffer with the highlighting that appears
955 on your screen using the command @code{ps-print-buffer-with-faces}.
959 @section Font Lock mode
960 @cindex Font Lock mode
961 @cindex mode, Font Lock
962 @cindex syntax highlighting and coloring
964 Font Lock mode is a minor mode, always local to a particular
965 buffer, which highlights (or ``fontifies'') using various faces
966 according to the syntax of the text you are editing. It can
967 recognize comments and strings in most languages; in several
968 languages, it can also recognize and properly highlight various other
969 important constructs---for example, names of functions being defined
970 or reserved keywords.
972 @findex font-lock-mode
973 @findex turn-on-font-lock
974 The command @kbd{M-x font-lock-mode} turns Font Lock mode on or off
975 according to the argument, and toggles the mode when it has no argument.
976 The function @code{turn-on-font-lock} unconditionally enables Font Lock
977 mode. This is useful in mode-hook functions. For example, to enable
978 Font Lock mode whenever you edit a C file, you can do this:
981 (add-hook 'c-mode-hook 'turn-on-font-lock)
984 @findex global-font-lock-mode
985 @vindex global-font-lock-mode
986 To turn on Font Lock mode automatically in all modes which support
987 it, customize the user option @code{global-font-lock-mode} or use the
988 function @code{global-font-lock-mode} in your @file{.emacs} file, like
992 (global-font-lock-mode 1)
995 Font Lock mode uses several specifically named faces to do its job,
996 including @code{font-lock-string-face}, @code{font-lock-comment-face},
997 and others. The easiest way to find them all is to use completion
998 on the face name in @code{set-face-foreground}.
1000 To change the colors or the fonts used by Font Lock mode to fontify
1001 different parts of text, just change these faces. There are
1006 Invoke @kbd{M-x set-face-foreground} or @kbd{M-x set-face-background}
1007 to change the colors of a particular face used by Font Lock.
1008 @xref{Faces}. The command @kbd{M-x list-faces-display} displays all
1009 the faces currently known to Emacs, including those used by Font Lock.
1012 Customize the faces interactively with @kbd{M-x customize-face}, as
1013 described in @ref{Face Customization}.
1017 @findex font-lock-fontify-block
1018 In Font Lock mode, when you edit the text, the highlighting updates
1019 automatically in the line that you changed. Most changes don't affect
1020 the highlighting of subsequent lines, but occasionally they do. To
1021 rehighlight a range of lines, use the command @kbd{M-g M-g}
1022 (@code{font-lock-fontify-block}).
1024 @vindex font-lock-mark-block-function
1025 In certain major modes, @kbd{M-g M-g} refontifies the entire current
1026 function. (The variable @code{font-lock-mark-block-function} controls
1027 how to find the current function.) In other major modes, @kbd{M-g M-g}
1028 refontifies 16 lines above and below point.
1030 With a prefix argument @var{n}, @kbd{M-g M-g} refontifies @var{n}
1031 lines above and below point, regardless of the mode.
1033 To get the full benefit of Font Lock mode, you need to choose a
1034 default font which has bold, italic, and bold-italic variants; or else
1035 you need to have a color or gray-scale screen.
1037 @vindex font-lock-maximum-decoration
1038 The variable @code{font-lock-maximum-decoration} specifies the
1039 preferred level of fontification, for modes that provide multiple
1040 levels. Level 1 is the least amount of fontification; some modes
1041 support levels as high as 3. The normal default is ``as high as
1042 possible.'' You can specify an integer, which applies to all modes, or
1043 you can specify different numbers for particular major modes; for
1044 example, to use level 1 for C/C++ modes, and the default level
1045 otherwise, use this:
1048 (setq font-lock-maximum-decoration
1049 '((c-mode . 1) (c++-mode . 1)))
1052 @vindex font-lock-maximum-size
1053 Fontification can be too slow for large buffers, so you can suppress
1054 it. The variable @code{font-lock-maximum-size} specifies a buffer size,
1055 beyond which buffer fontification is suppressed.
1057 @c @w is used below to prevent a bad page-break.
1058 @vindex font-lock-beginning-of-syntax-function
1059 Comment and string fontification (or ``syntactic'' fontification)
1060 relies on analysis of the syntactic structure of the buffer text. For
1061 the purposes of speed, some modes including C mode and Lisp mode rely on
1062 a special convention: an open-parenthesis in the leftmost column always
1063 defines the @w{beginning} of a defun, and is thus always outside any string
1064 or comment. (@xref{Defuns}.) If you don't follow this convention,
1065 then Font Lock mode can misfontify the text after an open-parenthesis in
1066 the leftmost column that is inside a string or comment.
1068 The variable @code{font-lock-beginning-of-syntax-function} (always
1069 buffer-local) specifies how Font Lock mode can find a position
1070 guaranteed to be outside any comment or string. In modes which use the
1071 leftmost column parenthesis convention, the default value of the variable
1072 is @code{beginning-of-defun}---that tells Font Lock mode to use the
1073 convention. If you set this variable to @code{nil}, Font Lock no longer
1074 relies on the convention. This avoids incorrect results, but the price
1075 is that, in some cases, fontification for a changed text must rescan
1076 buffer text from the beginning of the buffer.
1078 @findex font-lock-add-keywords
1079 Font Lock highlighting patterns already exist for many modes, but you
1080 may want to fontify additional patterns. You can use the function
1081 @code{font-lock-add-keywords}, to add your own highlighting patterns for
1082 a particular mode. For example, to highlight @samp{FIXME:} words in C
1086 (font-lock-add-keywords
1088 '(("\\<\\(FIXME\\):" 1 font-lock-warning-face t)))
1091 @node Highlight Changes
1092 @section Highlight Changes Mode
1094 @findex highlight-changes-mode
1095 Use @kbd{M-x highlight-changes-mode} to enable a minor mode
1096 that uses faces (colors, typically) to indicate which parts of
1097 the buffer were changed most recently.
1099 @node Highlight Interactively
1100 @section Interactive Highlighting by Matching
1101 @cindex highlighting by matching
1102 @cindex interactive highlighting
1104 It is sometimes useful to highlight the strings that match a certain
1105 regular expression. For example, you might wish to see all the
1106 references to a certain variable in a program source file, or highlight
1107 certain parts in a voluminous output of some program, or make certain
1108 cliches stand out in an article.
1110 @findex hi-lock-mode
1111 Use the @kbd{M-x hi-lock-mode} command to turn on a minor mode that
1112 allows you to specify regular expressions of the text to be
1113 highlighted. Hi-lock mode works like Font Lock (@pxref{Font Lock}),
1114 except that it lets you specify explicitly what parts of text to
1115 highlight. You control Hi-lock mode with these commands:
1118 @item C-x w h @var{regexp} @key{RET} @var{face} @key{RET}
1120 @findex highlight-regexp
1121 Highlight text that matches
1122 @var{regexp} using face @var{face} (@code{highlight-regexp}).
1123 By using this command more than once, you can highlight various
1124 parts of the text in different ways.
1126 @item C-x w r @var{regexp} @key{RET}
1128 @findex unhighlight-regexp
1129 Unhighlight @var{regexp} (@code{unhighlight-regexp}). You must enter
1130 one of the regular expressions currently specified for highlighting.
1131 (You can use completion, or a menu, to enter one of them
1134 @item C-x w l @var{regexp} @key{RET} @var{face} @key{RET}
1136 @findex highlight-lines-matching-regexp
1137 @cindex lines, highlighting
1138 @cindex highlighting lines of text
1139 Highlight lines containing a match for @var{regexp}, using face
1140 @var{face} (@code{highlight-lines-matching-regexp}).
1144 @findex hi-lock-write-interactive-patterns
1145 Insert all the current highlighting regexp/face pairs into the buffer
1146 at point, with comment delimiters to prevent them from changing your
1147 program. This key binding runs the
1148 @code{hi-lock-write-interactive-patterns} command.
1150 These patterns will be read the next time you visit the file while
1151 Hi-lock mode is enabled, or whenever you use the @kbd{M-x
1152 hi-lock-find-patterns} command.
1156 @findex hi-lock-find-patterns
1157 @vindex hi-lock-exclude-modes
1158 Re-read regexp/face pairs in the current buffer
1159 (@code{hi-lock-write-interactive-patterns}). The list of pairs is
1160 found no matter where in the buffer it may be.
1162 This command does nothing if the major mode is a member of the list
1163 @code{hi-lock-exclude-modes}.
1166 @node Trailing Whitespace
1167 @section Trailing Whitespace
1169 @cindex trailing whitespace
1170 @cindex whitespace, trailing
1171 @vindex show-trailing-whitespace
1172 It is easy to leave unnecessary spaces at the end of a line without
1173 realizing it. In most cases, this @dfn{trailing whitespace} has no
1174 effect, but there are special circumstances where it matters.
1176 You can make trailing whitespace visible on the screen by setting
1177 the variable @code{show-trailing-whitespace} to @code{t}. Then Emacs
1178 displays trailing whitespace in the face @code{trailing-whitespace}.
1180 Trailing whitespace is defined as spaces or tabs at the end of a
1181 line. But trailing whitespace is not displayed specially if point is
1182 at the end of the line containing the whitespace. (Doing that looks
1183 ugly while you are typing in new text, and the location of point is
1184 enough in that case to show you that the spaces are present.)
1186 @vindex indicate-empty-lines
1187 @vindex default-indicate-empty-lines
1189 Emacs can indicate empty lines at the end of the buffer with a
1190 special bitmap on the left fringe of the window. To enable this
1191 feature, set the buffer-local variable @code{indicate-empty-lines} to
1192 a non-@code{nil} value. The default value of this variable is
1193 controlled by the variable @code{default-indicate-empty-lines};
1194 by setting that variable, you can enable or disable this feature
1195 for all new buffers.
1198 @section Tooltips (or ``Balloon Help'')
1200 @cindex balloon help
1201 Tooltips are small X windows displaying a help string at the current
1202 mouse position, typically over text---including the mode line---which
1203 can be activated with the mouse or other keys. (This facility is
1204 sometimes known as @dfn{balloon help}.) Help text may be available for
1207 @findex tooltip-mode
1208 To use tooltips, enable Tooltip mode with the command @kbd{M-x
1209 tooltip-mode}. The customization group @code{tooltip} controls
1210 various aspects of how tooltips work. When Tooltip mode is disabled,
1211 the help text is displayed in the echo area instead.
1213 As of Emacs 21.1, tooltips are not supported on MS-Windows.
1215 @node Mouse Avoidance
1216 @section Mouse Avoidance
1217 @cindex avoiding mouse in the way of your typing
1218 @cindex mouse avoidance
1220 @vindex mouse-avoidance-mode
1221 Mouse Avoidance mode keeps the window system mouse pointer away from
1222 point, to avoid obscuring text. Whenever it moves the mouse, it also
1223 raises the frame. To use Mouse Avoidance mode, customize the option
1224 @code{mouse-avoidance-mode}. You can set this to various values to
1225 move the mouse in several ways:
1229 Move the mouse to the upper-right corner on any keypress;
1231 Move the mouse to the corner only if the cursor gets too close,
1232 and allow it to return once the cursor is out of the way;
1234 If the cursor gets too close to the mouse, displace the mouse
1235 a random distance & direction;
1237 As @code{jump}, but shows steps along the way for illusion of motion;
1239 The same as @code{animate};
1241 As @code{animate}, but changes the shape of the mouse pointer too.
1244 @findex mouse-avoidance-mode
1245 You can also use the command @kbd{M-x mouse-avoidance-mode} to enable
1248 @node Non-Window Terminals
1249 @section Non-Window Terminals
1250 @cindex non-window terminals
1251 @cindex single-frame terminals
1253 If your terminal does not have a window system that Emacs supports,
1254 then it can display only one Emacs frame at a time. However, you can
1255 still create multiple Emacs frames, and switch between them. Switching
1256 frames on these terminals is much like switching between different
1257 window configurations.
1259 Use @kbd{C-x 5 2} to create a new frame and switch to it; use @kbd{C-x
1260 5 o} to cycle through the existing frames; use @kbd{C-x 5 0} to delete
1263 Each frame has a number to distinguish it. If your terminal can
1264 display only one frame at a time, the selected frame's number @var{n}
1265 appears near the beginning of the mode line, in the form
1268 @findex set-frame-name
1269 @findex select-frame-by-name
1270 @samp{F@var{n}} is actually the frame's name. You can also specify a
1271 different name if you wish, and you can select a frame by its name. Use
1272 the command @kbd{M-x set-frame-name @key{RET} @var{name} @key{RET}} to
1273 specify a new name for the selected frame, and use @kbd{M-x
1274 select-frame-by-name @key{RET} @var{name} @key{RET}} to select a frame
1275 according to its name. The name you specify appears in the mode line
1276 when the frame is selected.
1279 @section Using a Mouse in Terminal Emulators
1280 @cindex xterm, mouse support
1281 @cindex terminal emulators, mouse support
1283 Some terminal emulators under X support mouse clicks in the terminal
1284 window. In a terminal emulator which is compatible with @code{xterm},
1285 you can use @kbd{M-x xterm-mouse-mode} to enable simple use of the
1286 mouse---only single clicks are supported. The normal @code{xterm} mouse
1287 functionality is still available by holding down the @kbd{SHIFT} key
1288 when you press the mouse button.