[ Combined Document ] | Contents | Previous | Next


How do I change the size, position, font, and color attributes of Emacs?

Emacs can run in two different interface modes: the Windows interface, which allows the flexible use and mixture of fonts and colors; and the console interface, which constrains Emacs to the limitations of console windows. The following two sections describe how to specify and change the size, position, font, and color attributes of Emacs in both interface modes.

Windows Interface

With the Windows interface, you can change the size, position, font, and color attributes of Emacs using three different mechanisms: using the mouse with the user interface, by specifying them as command line arguments, or by invoking Emacs Lisp functions. You will probably find it convenient to specify command line arguments in the Properties of the shortcut to the runemacs.exe file, and to invoke the lisp functions in your startup file. For information on how to propagate attributes to new frames, see the section below on frames .

How do I enable color syntax highlighting in Emacs (font-lock)?

Font-lock mode is a mode that performs color syntax highlighting for other major modes in Emacs. To use font-lock, place the following in your startup file:

(cond ((fboundp 'global-font-lock-mode)
       ;; Turn on font-lock in all modes that support it
       (global-font-lock-mode t)
       ;; Maximum colors
       (setq font-lock-maximum-decoration t)))

The above code uses the default faces for decoration. If you would like to customize the attributes of the faces, you can use the following startup code to get started:

(cond ((fboundp 'global-font-lock-mode)
       ;; Customize face attributes
       (setq font-lock-face-attributes
             ;; Symbol-for-Face Foreground Background Bold Italic Underline
             '((font-lock-comment-face       "DarkGreen")
               (font-lock-string-face        "Sienna")
               (font-lock-keyword-face       "RoyalBlue")
               (font-lock-function-name-face "Blue")
               (font-lock-variable-name-face "Black")
               (font-lock-type-face          "Black")
               (font-lock-reference-face     "Purple")
               ))
       ;; Load the font-lock package.
       (require 'font-lock)
       ;; Maximum colors
       (setq font-lock-maximum-decoration t)
       ;; Turn on font-lock in all modes that support it
       (global-font-lock-mode t)))

Also see the help text for the function global-font-lock-mode and the variable font-lock-face-attributes.

To see a list of colors that Emacs understands by name, select the "Edit->Text Properties->Display Colors" menu command.

An alternative to useing font-lock-mode is to use lazy-lock, to do this use the following:

    (setq font-lock-support-mode 'lazy-lock-mode)

Converting font-lock buffers into HTML markup

You can use the htmlize.el package by Hrvoje Niksic <hniksic@srce.hr> to convert font-lock attributes in buffers to HTML markups. See the comments at the top of the file on how to use it.

If you are using a version of Emacs before 19.34.6 and an 8-bit display, then you should download this version of htmlize.el instead. However, this is likely to become out of date with respect to Hrvoje's version, so I would actually recommend upgrading to 19.34.6.

Font-locking embedded code (e.g., ASP) in HTML documents

Gian Uberto Lauri <lauri@mail.eng.it> has modified html-helper-mode to enable font-locking and mode editing of code embedded in HTML documents (ASP, PHP).

How do I change the format of the mode line?

The format of the mode line is determined by the variable mode-line-format, a buffer-local variable. To understand how to interpret the mode line, see the Info node "C-h i m emacs RET m mode line RET". For a description of minor modes that provide additional information on the mode line (like line and column number, current time, and mail status), see the Info node "C-h i m emacs RET m optional mode line features".

You can also directly customize the format by assigning a new format string to the mode-line-format variable in your startup file. For a description of the format codes, see the help string for the variable ("C-h v mode-line-format").

What do I do if I have problems with Emacs and my mouse buttons?

You can use either a two- or three-button mouse with Emacs. If you have trouble with either of these working with Emacs, see below.

How do I use Emacs with a two-button mouse?

Emacs assumes that you have a three-button mouse by default. However, if you have a two-button mouse, you can press both buttons at once to emulate the missing middle button expected by Emacs.

Three variables control mouse button emulation under Emacs: w32-num-mouse-buttons, w32-mouse-button-tolerance, and w32-swap-mouse-buttons (win32-num-mouse-buttons, win32-mouse-button-tolerance. If you use help on w32-num-mouse-buttons (i.e., with "C-h v"), it will tell you how many buttons Emacs thinks your mouse has; if w32-num-mouse-buttons is less than 3, then Emacs will emulate the middle mouse button.

Emacs emulates the middle mouse button by treating simultaneous button presses of the left and right buttons as a middle button press. Since both button presses cannot really be simultaneous, Emacs compares button presses within a specified window of time to determine whether it should emulate the middle button. This window of time is controlled using w32-mouse-button-tolerance. Help on this variable will show you the value Emacs uses by default, and you can change this value to suit your needs.

Depending upon the type of two-button mouse, you may find it useful to swap the mapping of middle and right mouse buttons. By default, the middle button is mapped to mouse-2 and the right button is mapped to mouse-3. If you set w32-swap-mouse-buttons to a non-nil value, then you can swap these two mappings.

How do I get Emacs to recognize the third button on my mouse?

If you have a three-button mouse, Emacs should recognize and support the third (middle) button automatically. However, some people find that they have a three button mouse, but the middle mouse button does not work for them. First check to see if w32-num-mouse-buttons is set correctly. If so, then check to see whether your mouse has been installed with the proper driver (open Control Panel->Mouse to examine the driver being used). If you have the right driver, then, on NT, check if HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Busmouse\Paramete rs\NumberOfButtons is set to 3, and change it to 3 if it is not. If nothing seems to be amiss, then at the very least you can have Emacs emulate the middle button by setting w32-num-mouse-buttons to 2.

Strange two-button mouse behavior on Windows 95.

Some people have reported that using a two-button mouse with Emacs sometimes causes problems when they go to click in other windows or the desktop (e.g., double left-clicks are interpreted as a right-click); apparently this is a known bug in Windows 95, and is not confined to using Emacs. If this is happening to you, you might want to flip through a discussion on the topic.

One workaround is to right-click on the desktop, and then left-click on the desktop, and the mouse should be back in its normal state.

How do I highlight the region between the point and the mark?

To highlight the region between the point and the mark, use the function transient-mark-mode:

(transient-mark-mode t)

How do I highlight matching parentheses?

To highlight matching parentheses, add the following to your startup file:

(show-paren-mode 1)

How do I cut & paste text with null characters?

Because of the way Emacs currently tries to share the clipboard with other Windows applications, you cannot cut and paste text with null characters embedded in it. David Biesack <sasdjb@unx.sas.com> describes a way to get around this, at least for cutting and pasting text just within Emacs.

How do I change the sound of the Emacs beep?

You can use the function set-message-beep to change the sound that Emacs uses for its beep. Emacs allows you to specify one of the Windows system sounds for the beep. For example, to use the ok system sound, place the following in your startup file:

(set-message-beep 'ok)

Look up help for the function for a complete description of how to use the function and which sounds it recognizes.

When I yank previously copied or killed text into a buffer, it appears garbled. How can I fix this?

`selection-coding-system' is most likely still at it's default of `iso-latin-1-dos'. You can change this to a more appropriate coding system using `set-selection-coding-system' (C-x RET x), or temporarily with `set-next-selection-coding-system' (C-x RET X). If you NEVER cut and paste between Emacs and other programs, you can make Emacs behave for all languages with:

(set-selection-coding-system 'emacs-mule)

To copy between Emacs and other apps, you may need to use the appropriate Windows codepage as your coding system. To do this, you need to set up the codepage first:

(codepage-setup 1251)
(set-selection-coding-system 'cp1251)

[ Combined Document ] | Contents | Previous | Next
Steve Kemp, FAQ Maintainer
<skx@tardis.ed.ac.uk>
Valid HTML 4.01!
Last Modified : Thursday 1 August 2002