Combined Document | Split Document


GNU Emacs FAQ For Windows 95/98/ME/NT/XP and 2000

The latest version of Emacs is 21.2

 

0. Notes

1. Introduction

2. Getting Emacs

3. Installing Emacs.

4. Display Settings

5. Fonts, and text translation

6. Printing

7. Sub-processes

8. Mail, News, and Network access

9. Text, and utility, modes for Emacs

10. Developing with Emacs

11. Other Unix Ports, and further information

What is Emacs?

 "Emacs is the extensible, customizable, self-documenting real-time display editor. "

For a more detailed description, see the GNU pages at http://www.gnu.org/software/emacs/emacs.html.

Which versions of Windows are supported?

This port is known to run on all versions of Windows 95, Windows 98, Windows ME, Windows NT, Windows XP, and Windows 2000.

The Windows port is built using the Windows Win32 API and supports most of the features of the Unix version, there are some omissions at this time, which will be available in the future, these are:

MSDOS and Windows 3.11

Eli Zaretskii <eliz@is.elta.co.il> maintains the port of GNU Emacs for MSDOS and MS Windows. You can download precompiled versions with the latest DJGPP archives:

Eli strongly recommends that you start with the emacs.README file: it contains crucial info about what's in the other 10 zip files and how to install them and get started with Emacs on MSDOS/MS-Windows platforms.

More from Eli:

It might be of interest to Windows users that this version of Emacs supports long filenames (Windows 9x only - not Windows NT, or Windows 2000) and the Windows clipboard (all versions of MS-Windows). It also supports multiple frames, but they all overlap, like when Emacs runs on a ``glass teletype'' terminal.

People who would like to run Emacs on plain DOS (as opposed to Windows) will need to download and install a DPMI host at this URL:

ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2misc/csdpmi3b.zip

MULE/Meadow

Hisashi Miyashita <himi@bird.scphys.kyoto-u.ac.jp> maintains MULE, multilingual Emacs, and its descendant; Meadow. You can get distributions of MULE at ftp://ftp.tokyonet.AD.JP/pub/windows/win32/mule-win32. With the multilingual support now merged into NTEmacs in 20.4, it is no longer necessary to use a special version of Emacs for other languages, but MULE users may find upgrading to Meadow easier than to NTEmacs because of slight differences in the way they handle fonts. Meadow also has a couple of features that are still missing from NTEmacs, such as support for native IMEs and the special keys on Japanese keyboards.

DJGPP

 There is a version of Emacs which has been compiled using the Free compiler, DJGPP, (a version of GCC), available at http://www.delorie.com.

XEmacs

There are a couple of XEmacs for Windows NT/9X porting projects. See the XEmacs FAQ entry for more info, as well as Hrvoje Niksic's XEmacs on Windows FAQ.

MacOS

Occasionally I get requests for information about ports of Emacs to the Mac. Here are the ones that I know about:

Where can I get the source distribution?

The latest source distribution can be found in http://ftp.gnu.org/gnu/windows/emacs/latest. It is distributed in two formats: one large gzipped tar file (emacs*.tar.gz), and a collection of smaller zip files that can be copied to 1.44 Mbyte floppies (em-src-_?.zip).

In the same directory you should also find patch files that enable you to upgrade source distributions to the latest version. These patch files are mirrors of the ones on the FSF server at http://ftp.gnu.org/gnu.

You can also browse the source online; look in http://ftp.gnu.org/gnu/windows/emacs/latest for a directory named "emacs-<version>".

For more information about the contents of the various files you should read the README file contained in the FTP directory.

Can I get the source via CVS?

 Yes you can - Emacs sources can now be obtained via CVS. This will allow you to keep up to date with the latest bug fixes, and incremental updates.

 In order to get source in this manner you'll need some form of CVS client - see here for details of where to find one.

 Once you have a working CVS setup you can find download the source :

 Emacs CVS repository can be checked out through anonymous (pserver) CVS with the following instructions. When prompted for a password for anoncvs, simply press the Enter key.

 The following commands should checkout the current version of the source:

c:\>cvs -d:pserver:anoncvs@subversions.gnu.org:/cvsroot/emacs login
c:\>cvs -d:pserver:anoncvs@subversions.gnu.org:/cvsroot/emacs checkout emacs

Where can I get precompiled versions?

Starting with Emacs 20.4, precompiled distributions are being hosted at ftp.gnu.org. Distributions for the latest version are at:

Distributions for all architectures and the source are now in the same directory; look for the architecture-specific binary distribution for your machine (e.g., Intel NT and Win9X have "bin-i386" in the distribution name).

Now that the precompiled distributions are hosted on ftp.gnu.org, they also take advantage of all of the gnu ftp mirrors. A list of gnu mirror sites can be found at http://www.gnu.org/order/ftp.html; once you are at one of those sites, look in the gnu/windows/emacs sudirectory to find the NT Emacs directory.

There are also a number of sites that just mirror the NT Emacs distributions:

Regarding ftp.cs.washington.edu: I've had numerous reports from people outside North America saying that their ftp connection aborts for no apparent reason roughly a third of the way through a transfer of a full distribution. Marc Haber <s_haber@ira.uka.de> said that he suffered from the same problem, and later found that a timeout configured into his WWW proxy would cancel the transfer when the link to the US was very busy. Going around his proxy solved the problem. Andy Moreton <ajm@atml.co.uk> describes his situation when using SOCKS:

The FAQ page mentions some people have problems downloading - I may be able to shed some light on it. Our site has a reasonably secure firewall, and so all access to the outside world requires use of SOCKS based connections via a SOCKS5 server (i.e. a circuit-level gateway).

When doing an FTP transfer, two connections are up - a telnet for the control connection, and the data transfer on another. As the telnet connection is idle during the file transfer, the SOCKS server disconnects it. Some FTP servers get upset by this (especially the NT FTP server), and drop the data connection if the control connection goes down.

If you do have trouble downloading the full distribution, try downloading it in the 1.44MB chunks, or try one of the mirror sites.

I dont want the precompiled version. How do I compile Emacs myself?

To compile Emacs, you will need either Microsoft C compiler package or the Cygwin compiler.

For Windows NT the Microsoft C copmiler can be any of the SDK compilers from NT 3.1 and up, Microsoft Visual C++ for NT (versions 1.0 and up), or Microsoft Visual C++ (versions 2.0 and up). For Windows 95, this can be Microsoft Visual C++ versions 2.0 and up.

Download and place the source distribution in a directory (say, c:\emacs). Unpack the distribution, and go to the nt subdirectory of the emacs directory that gets created in the unpacking process. Read the README and INSTALL files included with the distribution for the full details of this process.

How do I use a debugger on Emacs?

Emacs is just like any other Windows application compiled and linked using MSVC, and it can be debugged using Windows debuggers like DevStudio. By default, Emacs will compile with debugging options turned on. Once compiled, you should be able to load either temacs.exe, the undumped executable, or emacs.exe, the dumped executable, into the debugger (almost always you will want to debug emacs.exe).

Note that Emacs has conventions for naming built-in C identifiers corresponding to lisp functions and variables. You will, of course, need to use the C identifier names when examining variables and setting breakpoints. The C identifier versions of lisp identifiers have dashes converted to underscores, and they are prefixed with a capital letter denoting the type of lisp object that they refer to (functions use 'F', variables use 'V', etc.). For example, the C function implementing the lisp function expand-file-name is Fexpand_file_name, and the C variable corresponding to the lisp variable load-path is Vload_path.

What are the differences between Emacs 21.x, and 20.x

There have been many changes from the older versions of Emacs, 19.x, and 20.x to the latest versions, 21.x.

These changes have been made in two main areas:

 If you are using an older version of NTEmacs, and are having problems the recommended action is to upgrade to the latest version.

 Then if you still have problems you should send mail to the list, describing your problem in as much detail as possible.

One of the biggest changes for the Windows version fo Emacs is the support for proportional fonts. Still to come is the support for inline images, tooltips, and toolbars, (which are present in the Unix version).

How do I unpack the distributions?

Open a command prompt (MSDOS) window. Decide on a directory in which to place Emacs. Move the distribution to that directory, and then unpack it. If you have the gzipped tar version, first use gunzip to uncompress the tar file, and then use tar with the "xvfm" flags to extract the files from the tar file:

% gunzip -c -d emacs.tar.gz | tar xvf -

(Note: Apparently the alpha version of gunzip cannot handle long file names, so you will need to rename the file to something like "emacstar.gz" before uncompressing it.)

The "-d" flag forces gunzip to decompress (its behavior depends upon the case of the name of the executable, and sometimes it doesn't recognize that it is really gunzip), and the "-c" flag tells it to pipe its output to stdout. Similarly, the "-" flag to tar tells it to read the tar file from stdin. Unpacking the distribution this way leaves the distribution in compressed form so it takes up less space.

You may see messages from tar about not being able to change the modification time on directories, and from gunzip complaining about a broken pipe. These messages are harmless and you can ignore them.

If for some reason you also want to have the tar file gunzipped, then invoke gunzip without the -c option:

% gunzip -d emacs.tar.gz

If you have the zip version, use unzip with the "-x" flag on all of the .zip files (note that you cannot use pkunzip on these files, as pkunzipwill not preserve the long filenames):

% unzip -x emacs-_1.zip
% (repeat for the remaining .zip files)

You can find precompiled versions of all of the compression and archive utilities in http://ftp.gnu.org/gnu/windows/emacs/utilities (ftp mirrors).

How do I install Emacs, after unpacking?

After unpacking the archive there's very little left to do, you have the choice of:

If you run "addpm.exe", and answer OK to the message box that pops up then GNU Emacs will be added to your start menu, and certain registry keys will be created for you. This isn't compulsorary as in previous releases - so the choice is yours.

What do I do if Emacs does not work?

See the section below on troubleshooting Emacs if, after downloading a precompiled distribution and unpacking it according to the instructions above, you have trouble running Emacs.

How do I customize Emacs?

 At its core Emacs contains a Lisp interpreter, this engine is used to implement most of the core functionality of Emacs.

 To customize Emacs mostly involves writing extra functions in Lisp, or changing variables that affect the behaviour which is already present.

 Emacs reads a file ".emacs" when it starts up, this is where it expects to find any customizations that you have made.

What is a .emacs file?

When Emacs starts up it attempts to load, and execute the contents of a file called ".emacs", or "_emacs". This file is where all the customizations are saved, and restored from when you restart Emacs. All of these settings are stored as Lisp expressions, for a general introduction to Lisp you could see : http://cons.org, more Emacs Specific information can be found in the Emacs Lisp Manual.

Where do I put my .emacs, (or _emacs), file?

Your startup file can be named either _emacs or .emacs, and should be placed in your "home" directory. If you have both files in your home directory, Emacs will load the .emacs file and ignore _emacs.

Your home directory is where the HOME configuration variable tells Emacs it is. As with the other Emacs configuration variables, HOME can be set in a number of ways:

If Emacs cannot find HOME set in any of the above locations, it will assume your HOME directory is "C:/".

The directory specified by HOME is also the directory substituted for tildes (~) in file names used in Emacs (so, by definition, you can always load your startup file in Emacs by doing C-x C-f "~/.emacs").

Troubleshooting: If you've set HOME to a directory using one of the above methods, and Emacs still doesn't load your startup file, the first thing you should do is check to see what Emacs thinks HOME is set to. You can do this by evaluating the following expression in the *scratch* buffer using C-x C-e:

(insert (getenv "HOME"))

Look carefully at what is printed and make sure the value is valid. For example, if the value has trailing whitespace, Emacs won't be able to find the directory. Also, be sure that the value isn't a relative drive letter (e.g., "d:" without a backslash); if it is, then HOME is going to be whatever the current directory on that drive is, which is likely not what you want to happen.

Sample .emacs Files

Ingo Koch <ingo.koch@ikoch.de> maintains a web site of sample .emacs files contributed by various users. His site is at http://www.dotemacs.de/.

There is also a small selection of sample .emacs files available at http://www.dotfiles.com

How can I have Emacs prompt me before closing?

If you would like to have Emacs prompt you before closing, add the following to your startup file:

(setq kill-emacs-query-functions
      (cons (lambda () (yes-or-no-p "Really kill Emacs? "))
            kill-emacs-query-functions))

How do I associate files with Emacs (i.e., use Emacs as a server with gnuserv/gnuclient)?

You can use a package like gnuserv to associate files with Emacs so that opening a file outside of Emacs (e.g., by double-clicking on its icon) will create a new frame in a running Emacs displaying that file. It now works on all the Windows platforms that NTEmacs supports, and has a number of usefull features.

http://www.wyrdrune.com/Files/gnuserv.zip
This is the download location for the latest version of GNUServe
http://www.wyrdrune.com/index.html?gnuserv.html~main
This is the accompanying page, which describes its features, and setup.

Be sure to place the gnuserv executables in your path (or modify your path or Emacs' exec-path to include them), and be sure that runemacs.exe is in your path if you use gnuserv to launch Emacs.

Note that you can set up file associations in Windows 95/98/NT 4.0 using Explorer by selecting the "View->Options..." menu operation, and then clicking on the "File Types" tab in the dialog that pops up. Clicking on a file type will allow you to edit it and associate the file with gnuclient.exe.

Warning: Be sure to quote the %1 in the association so that filenames with blanks in them are treated as one argument when sent to Emacs, e.g.:

C:\bin\gnuclientw.exe "%1"

[Discussion of other problems and solutions]

Controlling the use of frames

By default, gnuserv will load files into new frames. If you would rather have gnuserv load files into an existing frame, then evaluate the following in the chosen frame:

(setq gnuserv-frame (selected-frame))

Placing the above in your startup file, for example, will have gnuserv load files into the original Emacs frame. Note: one drawback of this approach is that if the frame associated with gnuserv is ever closed, gnuserv won't have a frame in which to place buffers.

For use with Internet Explorer

You can use Emacs as the editor for composing mail for mailto: links, reading news for news: links, and editing HTML files in Internet Explorer. You first need to install the gnuserv utilities above, and then modify or create the following registry entries using regedit:

Mail

Key: HKEY_CLASSES_ROOT\mailto\shell\open\command(Default)
Value: gnudoit -q (message-mail (substring \"%1\" 7))
News
Key: HKEY_CLASSES_ROOT\news\shell\open\command(Default)
Value: gnudoit -q (gnus-fetch-group (substring \"%1\" 5))
Edit HTML
Key: HKEY_CLASSES_ROOT\htmlfile\shell\edit\command(Default)
Value: gnuclientw %1

Thanks to Jason Rumney <jasonr@gnu.org> and Sigbjorn Finne <sigbjorn@cse.ogi.edu> for these tips.

For use with Netscape

You can use Emacs to view document source from Netscape 3.1. First install the gnuserv utilities, and then edit the Preferences->Apps tab. In the "View Source" field, enter "gnuclientw.exe". Amy Abascal <vhchelp@wsos.com> describes what to do with Netscape 4.

I don't know of any way to have Netscape use Emacs for mailto: and news: links as with IE above.

PIF file for gnuserv

Jerrad Pierce <belg4mit@mit.edu> has packaged together a PIF file and batch file for associating Emacs with file-types via gnuserv.

How do I use find-file to load files that are on the desktop?

Files that you add to the desktop are stored in a directory somewhere under your Windows directory. On NT 4.0, this directory is %USERPROFILE%\desktop (in other words, c:\winnt\profiles(user)\desktop if you installed NT in c:\winnt).

How do I make the active window follow the mouse?

 If you're running Emacs in a windowing mode, and not in the console you may use a package called follow-mouse to make the current frame, or buffer the one with the mouse over it.

Find it here.

How do I swap CapsLock and Control?

CapsLock and Control cannot be swapped from within Emacs, and Windows does not have a convenient mechanism like xmodmap to change virtual key bindings. Instead, new keyboard layouts or device drivers can be installed, or the registry can be modified, to swap the two keys.

WARNING: If you use a new keyboard layout to switch CapsLock and Control, beware of the option to use hotkey sequences to switch keyboard layouts. This option is in Control Panel->Keyboard under the Language (Windows 95) or Input Locales (Windows NT) tabs; the sequences themselves are "Left Alt+Control" and "Ctrl+Shift". If you enable one of these options, then you will likely at some point switch keyboard layouts while trying to use an Emacs key combination.

NT 4.0:

NT 3.5, 3.51: James Kittock has provided a program for NT that installs a new keyboard layout with the two keys swapped. Once installed, you can then select it using the "International" control panel applet. Windows 95: Microsoft has placed a keyboard remapping program for Windows 95 on their ftp site (keyremap). For more info, take a look at their Kernel Toys page.

Mark Russinovich has also written a freeware VxD that swaps CapsLock and Control under Windows 95. (I've been told that you might have to hit the real Control key once after installing the VxD to jumpstart the mapping.)

Windows 98: I've been told that the Windows 95 keyremap utility also works on Windows 98, despite the warnings on the web page.

How can I modify Emacs to be more like a Windows app?

 There are several differences in the way in which Emacs behaves compared to a standard Windows application, however most of the functionality is already present within Emacs, its just a matter of enabling it.

Keypad keys, highlighting selections, etc.

Some behaviors typically found in other Windows apps, such as deleting typed-over highlighted selections, are not configured by default in Emacs. You can, however, enable them by loading various packages. If you would like to highlight the region between the point and the mark, see the help text for transient-mark-mode; if you would like highlighted selections to be deleted when you type over them, see the help text for delete-selection-mode; if you would like to change the semantics of keypad keys such as "home" and "end", see the help text for pc-selection-mode.

Standard Windows application keymaps (C-c, C-v, C-x, etc.)

If you are used to standard Windows application keybindings, such as C-c for copy, C-v for paste, and C-x for cut, or selecting text with <shift>-movement, then you probably want to use Kim Storms <storm@cua.dk> cua.el.

Window operations (maximize, minimize, etc.)

As of Emacs 20.4.1 there is native support for maximizing, and minimizing the Emacs window from Lisp, the following functions will do the job for you:
  (defun w32-restore-frame ()
    "Restore a minimized frame"
     (interactive)
     (w32-send-sys-command 61728))

  (defun w32-maximize-frame ()
    "Maximize the current frame"
     (interactive)
     (w32-send-sys-command 61488))

Open File dialog box

Binu Jose Philip <binu@teil.soft.net> has written the dlgopen package to use the Windows Open File dialog box for opening files. Download dlgopen.zip, unpack, and read the top of the dlgopen.el file for directions on using the package.

How do I uninstall Emacs?

The only thing that Emacs changes in your system is the registry (if you used addpm to install it). Emacs does not, for example, install any files in your system directory. If you don't mind the registry settings remaining in the registry, then you don't need to do anything to uninstall Emacs.

If you want to remove the registry settings, then you can use the regedt32 program to remove the Emacs registry keys. Depending upon what kind of permissions you have, the registry entries could have been installed in either HKEY_LOCAL_MACHINE\SOFTWARE\GNU\Emacs or HKEY_CURRENT_USER\SOFTWARE\GNU\Emacs.

When I run Emacs, nothing happens. Whats the deal?

Emacs could have failed to run for a number of reasons. The most common symptom is that, when Emacs is started, the cursor changes for a second but nothing happens. If this happens to you, it is quite likely that the distribution was unpacked incorrectly.

Check for the following to see if there was a problem during unpacking:

  1. Be sure to disable the CR/LF translation or the executables will be unusable. Older versions of WinZipNT would enable this translation by default. If you are using WinZipNT, disable it.
  2. Check that filenames were not truncated to 8.3. For example, in Emacs 19.34.6 there should be a file lisp\term\win32-win.el (it has been renamed to w32-win.el in Emacs 20); if this has been truncated to win32-wi.el, your distribution has been corrupted while unpacking and Emacs will not start.
  3. I've also had reports that the GNU Windows port of tar corrupts the executables. Use the version of tar on my ftp site instead.

If you are in doubt about whether the utilities you used unpacked the distribution incorrectly, use the gunzip, tar, and unzip executables provided in the utilities directory. These are the ones I use to create and test the distributions. My advice would be to use these utilities from the start.

If it is still not working, send mail to the list, describing what you've done, and what you are seeing. (The more information you send the more likely it is that you'll receive a helpfull response..

I just upgraded the operating system, and Emacs no longer works.

I have received reports that, after upgrading the operating system (e.g., from NT 3.51 to NT 4.0), an installed Emacs will start but will not accept keyboard or mouse input. Apparantly, running addpm.exe as described in the installation section above fixes the problem.

I use anti-virus software. What problems can this cause?

Some anti-virus software seems to interact badly with older version of Emacs, these programs shouldn't cause any problems if you are running a version of Emacs newer than 20.3.

Dr. Solomons

A number of users have reported that Dr. Solomon's WinGuard prevent shell-related commands from working properly within Emacs. Turning off "Scan all files" makes it work, though.

McAfee

A similar report from Charles Curley. <ccurley@wyoming.com> It has also been reported that you only need to select "Programming Files Only" instead of "All Files" to prevent Emacs from hanging.

Norton

A third report from Peter Haas about Norton Antivirus 2000 (Emacs 20.5.1, Win98): a DOS shell cannot be started within Emacs without disabling the antivirus autoprotect feature (e.g., clicking on the icon in the system tray).

Does Emacs contain a virus?

 There have been reports from some people that the McAfee virus scanner, (versions unreported), claims that the latest version of NTEmacs contains a virus.

 Assuming that you are downloading from the official gnu.org site, then these are false positives which you might see in the following files:

 These warnings seem to be artifacts of the way in which Emacs is built - the process of compiling a program, then using a "dumping" process to ensure that things are pre-loaded in the emacs.exe executable - and can be safely ignored.

 To remove these warnings, update your virus scanner to the latest version.

Sometimes when I exit Emacs, my machine hangs or crashes immediately.

Have you installed an Iomega Zip drive recently? The Iomega driver and Emacs appear to have a conflict that causes this crash. At present, the only solution is to disable the driver, reboot, and then use Emacs normally. To do this, look in the Startup folder (inside the Programs folder in the taskbar), locate the Iomega-related programs, and move them to a different folder. Then reboot. Emacs will work normally. If you want to use the Zip drive, manually execute the Iomega programs you moved. Then reboot before you use Emacs again. It's not convenient, but at least ou won't crash. Thanks to Will Duquette for this information.

How does Emacs determine the name of my computer?

Emacs initializes the variable "system-name" with the name of your computer upon startup. However, Emacs uses two different methods for determining the computer name depending upon whether Winsock is loaded by default when Emacs starts up. If Winsock is automatically loaded, then Emacs uses gethostname, otherwise Emacs uses GetComputerName. Alternatively, you can override all of this by explicitly setting system-name in your startup file (also look at user-mail-address for composing mail messages).

By default, Emacs does not automatically load Winsock because doing so will cause Winsock to establish a connection to the network. If you are connected to a LAN, then nothing will happen, but if you dialup to an ISP then invoking Emacs (thereby loading Winsock) will prompt you to unexpectedly dialup to your ISP.

You can have Emacs automatically load Winsock by defining the environment variable PRELOAD_WINSOCK. You can set it to an arbitrary value; Emacs just checks to see if it is defined. Similarly, you can create a registry entry PRELOAD_WINSOCK with the other Emacs registry entries (in HKEY_LOCAL_MACHINE\SOFTWARE\GNU\Emacs or HKEY_CURRENT_USER\SOFTWARE\GNU\Emacs), which will do the same thing.

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)

FONTS

Fonts in Emacs are named using the standard X Windows format for fonts.

For an explanation of what each element in a font string means and how Emacs on NT uses it, see Andrew's note.

These font names are the names that can be used as arguments on the command line or in lisp functions. To see the font name corresponding to a font chosen using the font selection dialog, execute the following elisp code in the *scratch* buffer:

(insert (prin1-to-string (w32-select-font)))   ; Emacs 20

To see the complete list of fonts that Emacs has access to, execute the following elisp code in the *scratch* buffer:

(insert (prin1-to-string (x-list-fonts "*")))

The font support currently is a little rough around the edges. In particular, italic fonts give Emacs some problems; see below for more info about using italic fonts. Generally it performs as expected, but occasionally you might get unexpected results (e.g., Emacs didn't quite use the font you told it to use). Work is underway to fix these problems, but for now I suggest experimenting if you encounter problems.

Also, X Windows has the luxury of a set of font aliases (such as fixed) that are convenient names for referring to specific fonts. Work is underway to provide an equivalent alias mechanism under Windows so that naming fonts does not have to be as cumbersome as it currently is.

To customize fonts for specific frames, see the section on customizing frames below.

User Interface
To change the default font that Emacs uses, shift click the left mouse button (i.e., [shift-mouse-1]) and a font selection dialog will pop up. Select the font that you would like to use, and click on the OK button to close the dialog and use the selected font. (Note that the dialog only displays fixed-pitch and screen fonts since Emacs cannot handle variable-pitched fonts.)
Command Line
To start Emacs with a particular font, use the the -font X Windows command line option. For example, to start Emacs with the Courier font of size 10 and font style Regular, invoke Emacs using:
emacs -font "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1"
Emacs Lisp
To change the default font of Emacs using elisp, use the set-default-font function:
(set-default-font "-*-Courier-normal-r-*-*-13-*-*-*-c-*-*-iso8859-1")

To set the font of a particular face, use the set-face-font function.

Registry
To change the default font of Emacs frames using registry entries, create a value in the key HKEY_CURRENT_USER\Software\GNU\Emacs:
Value Name: Emacs.Font
Value Type: REG_SZ
String: -*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1

Since the font strings are rather cumbersome, I would suggest cutting the font string into the kill-ring (which will place it in the clipboard, too) and pasting it (Ctrl-V) into the regedit dialog. (Note that you shouldn't place quotes around the font string in the registry.)

If you have Emacs frames with specific names, you can also specify a font for that frame. For the Value Name of the entry, use the name of the frame instead of Emacs (e.g., RMAIL.Font for your RMAIL frame).

ITALICS

Emacs currently requires that italic versions of fonts have the same width as the normal version of the font. However, most of the default fonts have italic and italic bold versions whose character widths are larger than the normal version (the only default font that appears to have viable italic and bold versions is Courier New). Because of this, Emacs by default disables the use of italic faces.

You can still enable the use of italic faces with Emacs by setting the variable w32-enable-italics to t in your startup file:

(setq w32-enable-italics t)    ; This must be done before font settings! (Emacs 20.x)
(set-face-font 'italic "-*-Courier New-normal-i-*-*-11-*-*-*-c-*-iso8859-1")
(set-face-font 'bold-italic "-*-Courier New-bold-i-*-*-11-*-*-*-c-*-iso8859-1")

Although this works best with Courier New, there is still one minor glitch: the italics versions are one pixel higher than the other versions, so the line spacing is increased by a pixel when italics are enabled. FONT

Under NT, open the "-" menu. Select "Fonts...", and use the dialog to set the window font to the one you want. Be sure to check the "Save Configuration" checkbox so that your font change will be used in future invocations. Click on "OK", and the window will get resized.

Under Windows 95/98, simply use the popup font menu in the upper left-hand corner of the window. Or click on the font icon in the icon toolbar. Or click on the properties icon in the icon toolbar and go to the "Font" tab and choose the font that you want to use.

Emacs multilingual font support

(Applies to version 20.4 and later)

Is it now possible to display correctly the sample of various scripts and languages accessible from the MULE menu?

If you have a Windows font for the script or language, then you should be able to display it using Emacs 20.4. Emacs 20.4 also supports the bdf fonts that were used with the older MULE for Windows version of Emacs and the more recent Meadow versions (as well as the X Windows versions of Emacs). For details on using the bdf fonts with Emacs, see below .

More about using Windows fonts:

There are a number of languages for which Windows fonts are not yet available, or are not in an appropriate format for Emacs to use, so you will not get every language to display. I also had some problem getting Japanese, Chinese, Cantonese and Korean to display all at once, but this was on Windows 95, and I suspect is a limitation of the OS, rather than a bug in Emacs, as those languages look fine when displayed one at a time (there is a note on the Microsoft language packs that only one may be installed at a time, which I suspect is because of this limitation).

Because some languages can only use proportional fonts, limited support has been added for proportional fonts as the non-ASCII font in fontsets. It should be general enough to work with any font, but it is not full proportional support, so the characters may not appear exactly as you expect. You may need to try several fonts to find one that appears reasonably correct if you wish to use Emacs with languages like Thai which use composition and hence use only proportional Windows fonts.

How do I get Emacs to display characters other than ISO-8859-1 (West European)?

If you are content with the size and style of font that Emacs uses at startup (Courier New 10), you could try using `fontset-standard', which will give you most languages that you have fonts for and Emacs supports. To use `fontset-standard' for all frames, place the following in your startup file:

(setq default-frame-alist
        (append
        '((font . "fontset-startup"))
        default-frame-alist))

or, to change for the current frame only:

(set-frame-font "fontset-startup")

To have more control over which fonts are used in a fontset, you need to specify the fontset manually.

If only one character set is needed, the easiest way to do this is to use `create-fontset-from-ascii-font' whereever you define a font.

(setq default-frame-alist
      (append
       '((font . (create-fontset-from-ascii-font
                  "-*-Andale Mono-normal-r-*-*-13-*-*-*-c-*-iso8859-2")))
       default-frame-alist))

If you require support for a number of languages, you should use `create-fontset-from-fontset-spec'. Note that installing more than one of the East Asian language packs is not supported by Microsoft, and does not work on Windows 95 at least. It is very difficult to get your system stable again after trying, so it is recommended that you only install the one that you will use the most, and use BDF fonts for the other languages:

(create-fontset-from-fontset-spec
 "-*-Courier New-normal-r-*-*-12-*-*-*-c-*-fontset-most,
 latin-iso8859-2:-*-Courier New-normal-r-*-*-12-*-*-*-c-*-iso8859-2,
 latin-iso8859-3:-*-Courier New-normal-r-*-*-12-*-*-*-c-*-iso8859-3,
 latin-iso8859-4:-*-Courier New-normal-r-*-*-12-*-*-*-c-*-iso8859-4,
 cyrillic-iso8859-5:-*-Courier New-normal-r-*-*-12-*-*-*-c-*-iso8859-5,
 greek-iso8859-7:-*-Courier New-normal-r-*-*-12-*-*-*-c-*-iso8859-7,
 latin-iso8859-9:-*-Courier New-normal-r-*-*-12-*-*-*-c-*-iso8859-9,
 japanese-jisx0208:-*-MS Gothic-normal-r-*-*-12-*-*-*-c-*-jisx0208-sjis,
 katakana-jisx0201:-*-MS Gothic-normal-r-*-*-12-*-*-*-c-*-jisx0208-sjis,
 latin-jisx0201:-*-MS Gothic-normal-r-*-*-12-*-*-*-c-*-jisx0208-sjis,
 japanese-jisx0208-1978:-*-MS Gothic-normal-r-*-*-12-*-*-*-c-*-jisx0208-sjis,
 korean-ksc5601:-*-Gulim-normal-r-*-*-12-*-*-*-c-*-ksc5601-*,
 chinese-gb2312:-*-MS Song-normal-r-*-*-12-*-*-*-c-*-gb2312-*,
 chinese-big5-1:-*-MingLiU-normal-r-*-*-12-*-*-*-c-*-big5-*,
 chinese-big5-2:-*-MingLiU-normal-r-*-*-12-*-*-*-c-*-big5-*" t)

If you leave character sets out of the fontset-spec above, a font will be chosen at random (not necessarily matching any of the other fonts in the fontset). The fontset name is used to generate the "default" font, which covers ASCII and iso8859-1.

To get a full list of character-sets use "M-x describe-fontset" to describe `fontset-standard'.

Where can I find fonts for other languages?

MS Windows fonts The Windows installation CDROM contains fonts for most European languages. If you did not install "Multilanguage Support" when you installed Windows, you can install it from the "Add Programs" Control Panel. East Asian Language (Chinese, Japanese, Korean) support for Microsoft Word and Internet Explorer can also be used by Emacs. These are available from http://www.microsoft.com, or on the installation CDROMs. IE5 also has fonts for Thai, Vietnamese and other languages, although it is not known how well these work with Emacs. Fonts for many other languages are available on the WWW; a good starting point is http://babel.uoregon.edu/yamada/guides.html.

X Windows fonts There is a collection of international fonts for use with X Windows, and a set can be found at ftp.gnu.org. They are distributed in the bdf font file format, a format that can be handled by Emacs starting with version 20.3.5.1. For details on how to use these fonts with Emacs, see the section below on using bdf fonts with Emacs.

How do I use third party programs for displaying multibyte characters with Emacs?

Define a fontset ( see above ) listing any font of an appropriate size which works with the third party program for the appropriate character set(s). Change the character set to the character set you want displayed so Emacs knows how to display it. For example:

(create-fontset-from-fontset-spec
 "-*-Courier New-normal-r-*-*-13-*-*-*-c-*-fontset-asian,
 korean-ksc5601:-*-Courier New-normal-r-*-*-13-*-*-*-c-*-ksc5601-*,
 chinese-gb2312:-*-Courier New-normal-r-*-*-13-*-*-*-c-*-gb2312-*,
 chinese-big5-1:-*-Courier New-normal-r-*-*-13-*-*-*-c-*-big5-*,
 chinese-big5-2:-*-Courier New-normal-r-*-*-13-*-*-*-c-*-big5-*,
 japanese-jisx0208:-*-Courier New-normal-r-*-*-13-*-*-*-c-*-jisx0208-sjis,
 katakana-jisx0201:-*-Courier New-normal-r-*-*-13-*-*-*-c-*-jisx0201-sjis,
 latin-jisx0201:-*-Courier New-normal-r-*-*-13-*-*-*-c-*-jisx0201-sjis,
 japanese-jisx0208-1978:-*-Courier New-normal-r-*-*-13-*-*-*-c-*-jisx0208-sjis")

If this doesn't work, you may need to set `w32-enable-unicode-output' to nil.

How do I use a font with a name in my language?

This is most applicable to East Asian users. Others can probably get their fonts working (with a strange looking name), but it is nice to have the names of fonts displayed correctly.

You need to use the function `set-w32-system-coding-system' before the font is specified. If you are setting the font from your .emacs, you will need to make sure the coding-system of your .emacs supports the character set for the font name. An example (for Traditional Chinese) follows:

;; Top line of .emacs: -*- coding: chinese-big-5; -*-
(set-w32-system-coding-system 'chinese-big-5)

For Japanese, you would use japanese-shift-jis; for Simplified Chinese, chinese-iso-8bit; for Korean, korean-iso-8bit.

How can I use bdf fonts with Emacs?

To use bdf fonts with Emacs, you need to tell Emacs where the fonts are located, create fontsets for them, and then use them. We'll use the 16 dot international fonts from ftp.gnu.org/intlfonts as an example put together by Jason Rumney <jasonr@gnu.org>

Download the 16dots.tar.gz file and unpack it; I'll assume that they are in "c:\intlfonts". Then set w32-bdf-filename-alist to the list of fonts returned by using w32-find-bdf-fonts to enumerate all of the font files. It is a good idea to set the variable bdf-directory-list at the same time so ps-print knows where to find the fonts:

(setq bdf-directory-list
      '("c:/intlfonts/Asian" "c:/intlfonts/Chinese" "c:/intlfonts/Chinese-X"
        "c:/intlfonts/Ethiopic" "c:/intlfonts/European" "c:/intlfonts/Japanese"
        "c:/intlfonts/Japanese-X" "c:/intlfonts/Korean-X" "c:/intlfonts/Misc/"))
(setq w32-bdf-filename-alist
      (w32-find-bdf-fonts bdf-directory-list))

Then create fontsets for the BDF fonts:

(create-fontset-from-fontset-spec
 "-*-fixed-medium-r-normal-*-16-*-*-*-c-*-fontset-bdf,
 japanese-jisx0208:-*-*-medium-r-normal-*-16-*-*-*-c-*-jisx0208.1983-*,
 katakana-jisx0201:-*-*-medium-r-normal-*-16-*-*-*-c-*-jisx0201*-*,
 latin-jisx0201:-*-*-medium-r-normal-*-16-*-*-*-c-*-jisx0201*-*,
 japanese-jisx0208-1978:-*-*-medium-r-normal-*-16-*-*-*-c-*-jisx0208.1978-*,
 thai-tis620:-misc-fixed-medium-r-normal--16-160-72-72-m-80-tis620.2529-1,
 lao:-misc-fixed-medium-r-normal--16-160-72-72-m-80-MuleLao-1,
 tibetan-1-column:-TibMdXA-fixed-medium-r-normal--16-160-72-72-m-80-MuleTibetan-1,
 ethiopic:-Admas-Ethiomx16f-Medium-R-Normal--16-150-100-100-M-160-Ethiopic-Unicode,
 tibetan:-TibMdXA-fixed-medium-r-normal--16-160-72-72-m-160-MuleTibetan-0")

Many of the international bdf fonts from gnu.org are type 0, and therefore need to be added to font-encoding-alist:

;; Need to add some fonts to font-encoding-alist since the bdf fonts
;; are type 0 not the default type 1.
(setq font-encoding-alist
      (append '(("MuleTibetan-0" (tibetan . 0))
                ("GB2312"        (chinese-gb2312 . 0))
                ("JISX0208"      (japanese-jisx0208 . 0))
                ("JISX0212"      (japanese-jisx0212 . 0))
                ("VISCII"        (vietnamese-viscii-lower . 0))
                ("KSC5601"       (korean-ksc5601 . 0))
                ("MuleArabic-0"  (arabic-digit . 0))
                ("MuleArabic-1"  (arabic-1-column . 0))
                ("MuleArabic-2"  (arabic-2-column . 0))) font-encoding-alist))

You can now use the Emacs font menu (not the popup dialog; see below ) to select the "bdf: 16-dot medium" fontset, or you can select it by setting the default font:

(set-default-font "fontset-bdf")

Try loading the file etc/HELLO, and you should be able to see the various international fonts displayed (except for Hindi, which is not included in the 16-dot font distribution).

How can I have Emacs use a font menu similar to the one it uses on Unix (with fonts and fontsets listed)?

Place the following in your startup file:

(setq w32-use-w32-font-dialog nil)

The font I want to use is not in the font menu, how can I put it there?

If you have set w32-use-w32-font-dialog to nil, you can add fonts to the font menu by changing `w32-fixed-font-alist'. For example:

(setq w32-fixed-font-alist
      (append w32-fixed-font-alist
              '(("Monotype.com"
   ("8" "-*-Monotype.com-normal-r-*-*-11-*-*-*-c-iso8859-1")
   ("9" "-*-Monotype.com-normal-r-*-*-12-*-*-*-c-iso8859-1")
   ("10" "-*-Monotype.com-normal-r-*-*-13-*-*-*-c-iso8859-1")
   ("11" "-*-Monotype.com-normal-r-*-*-15-*-*-*-c-iso8859-1")))))

How can I control CR/LF translation (e.g., to access UNIX files via NFS)?

There are a number of methods by which you can control automatic CR/LF translation in Emacs, a situation that reflects the fact that the default support isn't very robust. For a discussion of this issue, take a look at this collection of email messages on the topic.

By file extension

The first method is by file extension using the alist file-name-buffer-file-type-alist. This alist contains pairs of regular expressions and booleans that determine whether a file is opened in binary (untranslated) or text (translated) mode. The alist already contains a number of pairs that you can use as examples for creating your own; do a "C-h v" on the variable name to see the help text and the default pairs.

You could add your own pairs to the alist, or change the alist entirely. For example, if you wanted to open every file in binary mode except for batch files, you could add the following to your startup file:

(setq file-name-buffer-file-type-alist '(("\.bat$" . nil) (".*" . t)))

The first pair says anything ending with the .bat extension should be opened in text mode, and the second pair opens everything else that doesn't match the first pair in binary mode.

By file system

A second method for controlling translation is with the functions at the end of untranslate.el. These functions enable you to turn on and off translation on a filesystem basis (e.g., open anything on C: in translated mode, and anything on U: in untranslated mode). If you want to use these functions, download and place untranslate.el in your load-path and have it loaded from your startup file. Then you can place calls to add-untranslated-filesystem to selectively access filesystems in binary mode.

Automatic

A third method for controlling translation is to have Emacs scan files and automatically determine whether they are binary or text by looking at the line breaks in the file (i.e., no line breaks or just linefeeds imply binary, carriage return/linefeed pairs imply text). Chris Weikart <chris@weikart.com> contributed the following code snippet from his .emacs file:

 (defun set-buffer-file-eol-type (eol-type)
   "Set the file end-of-line conversion type of the current buffer to
 EOL-TYPE.
 This means that when you save the buffer, line endings will be converted
 according to EOL-TYPE.

 EOL-TYPE is one of three symbols:

   unix (LF)
   dos (CRLF)
   mac (CR)

 This function marks the buffer modified so that the succeeding
 \\[save-buffer]
 surely saves the buffer with EOL-TYPE.  From a program, if you don't want
 to mark the buffer modified, use coding-system-change-eol-conversion
 directly [weikart]."
   (interactive "SEOL type for visited file (unix, dos, or mac): ")
   (setq buffer-file-coding-system (coding-system-change-eol-conversion
                      buffer-file-coding-system eol-type))
   (set-buffer-modified-p t)
   (force-mode-line-update))

 (global-set-key "\^Cu" (lambda () (interactive) (set-buffer-file-eol-type 'unix)))
 (global-set-key "\^Cd" (lambda () (interactive) (set-buffer-file-eol-type 'dos)))
 (global-set-key "\^Cm" (lambda () (interactive) (set-buffer-file-eol-type 'mac)))

 ;; Make the mode-line display the standard EOL-TYPE symbols (used above)...
(setq eol-mnemonic-undecided "(?)"  ;; unknown EOL type
       eol-mnemonic-unix  "(unix)" ;; LF
       eol-mnemonic-dos  "(dos)"  ;; CRLF
       eol-mnemonic-mac  "(mac)") ;; CR

How do I print from Emacs?

20.4

Please read Andrew's note on how to print from Emacs in 20.4. What you need to do depends upon how you connect your printer to your machine.

Tim Sherrill <sherritp@sagian.com> has a very informative page on 2-up (n-up) printing from Emacs.

Holger Mueller <hmueller@bigfoot.com> has taken over maintaining print-NT.el [V 1.15, 6/29/98] (previously maintained by Brian Gorka <gorkab@cyberpass.net>).

Theodore Jump <tjump@tertius.com> has also written w32-print.el, a relatively complete package for printing from Emacs on Windows systems (Postscript, plain-text, 2- and 4-up, 19.34.X and 20.X, UNC and local device paths, etc.). [V1.11, 12/7/98]

Pascal Obry has a nice example of how to set up some variables to get printing to work on NT.

Jeff Paquette <paquette@mediaone.net> has a version of pr for use with Emacs, and instructions on how to set it up.

Anders Lindgren <andersl@csd.uu.se> has written a lpr.bat batch file that can be subsituted transparently for lpr on NT (Windows 95 batch files don't redirect stdin correctly).

A number of other people have put together packages to print from Emacs. I haven't had the time to go through them and piece everything together, but I recommend that you flip through this collection of messages.

For info on 2-up printing from Emacs, take a look at these messages.

For clever tricks for specific printers, take a look at these messages.

Bill Carpenter on printing in color:

It's relatively easy to set up the ps-print package, which can
generate color PostScript output.  You can then run the results
through Ghostscript if you don't happen to have a color PS printer
laying around.

To try it manually, do something like this:

        (require 'ps-print)
        (ps-spool-buffer-with-faces)

and then look for the buffer "*PostScript*".

You can also turn your font-locked buffers into HTML, and then use a browser to print them out. See the section on htmlize.el.

Printing via Ghostscript

 Alec Clews reports success at using Ghostscript to perform his printing - using gsview version 3.4, and Ghostscript version 6.01

 The configuration is straightforward, here's his settings, (which you should modify to suit).

      (setq ps-lpr-command "c:\\Ghostgum\\gsview\\gsprint.exe")

      ;; THis line causes ghostscript to query which printer to
      ;; use - which you may not need if, for example, you only
      ;; have one printer.
      (setq ps-lpr-switches '("-query"))

      (setq ps-printer-name t)

 The commandline options are documented in the gsprint.htm file which comes with Ghostscript.

How do I print all these languages that Emacs is now displaying?

 Emacs 20.4 has the ability to print non Western languages in two ways. Both use the "Postscript Print" functions, so if you do not have a Postscript printer, you will need to configure Emacs to print through Ghostscript.

  1. Using built-in support in the printer (or in Ghostscript).
  2. Using BDF fonts.

The variable `ps-multibyte-buffer' controls how non-latin characters are printed. If you are using built in support in the printer or Ghostscript, then setting this variable appropriately is all that needs to be done. To use BDF fonts, you will need to tell ps-print where to find them. This is done by setting `bdf-directory-list'. For example:

(setq ps-multibyte-buffer 'bdf-font
      ps-mule-font-info-database ps-mule-font-info-database-bdf
      bdf-directory-list '("c:/intlfonts/European" "c:/intlfonts/Chinese"
                           "c:/intlfonts/Japanese" "c:/intlfonts/Korean-X"))

By default, Emacs uses 24 dot BDF fonts for normal text, 16 dot for bold and italic and 40 dot for some (uncommon) Chinese and Japanese character sets.

How do I print to a printer that is directly connected to a network?

 If you have a printer which doesn't require a print server and is just connected directly to a hub you may find this information useful - it was contributed by Ed Grissom <egrissom@ziimaging.com>

While there may be better ways to do this, I have used the solution below to solve this problem if other Win32 apps _can_ print to the printer (Like Word or Notepad ).

Go to the printer properties and "share" the printer from your machine.

Then tell Emacs the printer is \\yourmachine\yoursharename and it should work

 You may need more slashes or the opposite type of slash depending on which Emacs printing subsystem (i.e. lpr, ps-print, print-nt, w32-print, etc.) you are using. Just look at the subsystem's example for a networked printer, and substitute your machine name as the server and your share name as the printer name.

Quoting issues

The quoting rules for Windows shells and Cygnus shells have some subtle differences. When Emacs spawns subprocesses, it tries to determine whether the process is a Cygnus program and changes its quoting mechanism appropriately. [Discussion]

Programs reading input hang

Programs that explicitly use a handle to the console ("CON" or "CON:") instead of stdin and stdout cannot be used as subprocesses to Emacs, and they will also not work in shell-mode (the default ftp clients on Windows 95 and NT are examples of such programs - this ftp program is fine for use with ange-ftp, but not for M-x ftp). There is no convenient way for either Emacs or any shell used in shell-mode to redirect the input and output of such processes from the console to input and output pipes. The only workaround is to use a different implementation of the program that does not use the console directly (see the discussion on ange-ftp for a replacement for the default ftp clients).

Buffering in shells

You may notice that some programs, when run in a shell in shell-mode, have their output buffered (e.g., people have found this happening to them with sql-mode). When the program has a lot of output, it overflows the buffering and gets printed to the shell buffer; however, if the program only outputs a small amount of text, it will remain buffered and won't appear in the shell buffer.

Although it may at first seem like the shell is buffering the output from the program, it is actually the program that is buffering output. The C runtime typically decides how to buffer output based upon whether stdout is bound to a handle to a console window or not. If bound to a console window, output is buffered line by line; if bound to a block device, such as a file, output is buffered block by block.

In a shell buffer, stdout is a pipe handle and so is buffered in blocks. If you would like the buffering behavior of your program to behave differently, the program itself is going to have to be changed; you can use setbuf and setvbuf to manipulate the buffering semantics.

Some programs handle this by having an explicit flag to control their buffering behaviour, typically "-i". Other programs manage to detect that they are running under Emacs, by using getenve("emacs") internally.

Perl script buffering.

A handy solution for Perl scripts is to use:

      # Turn all buffering off.
      select((select(STDOUT), $| = 1)[0]);
      select((select(STDERR), $| = 1)[0]);
      select((select(STDIN),  $| = 1)[0]);

DOS subprocesses

You can run DOS subprocesses under Emacs, with either the native command shell, or one of the alternatives, such as bash, tcsh, or 4NT, instead of command.com/cmd.exe; see the section below on other tools for pointers to other sites.

16-bit subprocesses accessing the A: drive.

If you are finding that running 16-bit programs as subprocesses cause your A: drive to be accessed (hanging Emacs until a timeout occurs if no floppy is in the drive), check to see if you have McAfee Virus Shield installed. Users have found that disabling Virus Shield causes the problem to go away. Also, if you have a better fix for this problem, let me know or send mail to the list.

A followup from Bill Carpenter <bill@bubblegum.net>.

Killing subprocesses on Windows 95/98

Emacs cannot guarantee that a subprocess gets killed on Windows 95/98, and is a difficult limitation to work around. For the forseeable future, you should always let subprocesses run to completion, including explicitly exiting interactive shells.

If you find that shutting down Windows 95/98 complains that there is a running cmdproxy even though you've exited all programs and it doesn't show up in the Task Manager until you shutdown, this could be a bad interaction with Norton VirusChecker.

Francis Wright has written a nice little package which tries to automatically tell shell buffer(s) to "exit" if you try to kill them, it is called msdos-shell-fix.el, and can be found at : http://centaur.maths.qmw.ac.uk/Emacs/.

Sending eof to subprocesses in Emacs (e.g., C-c C-d in shell buffers)

When an eof is sent to a subprocess running in an interactive shell via process-send-eof, the shell terminates unexpectedly as if its input were closed. See this description for more info and an example.

How do I use a shell in Emacs?

You can use an interactive subshell in Emacs by typing "M-x shell". Emacs uses the SHELL configuration variable to determine which program to use as the shell. If you installed Emacs using the addpm.exe program, then addpm.exe will associate the value %COMSPEC% with SHELL in the registry. Emacs will then use the value of the COMSPEC environment variable when it starts up, unless the SHELL environment variable is explicitly defined (as when using the emacs.bat batch file).

If you would like to specify a different shell for Emacs to use, then you should do one of two things. You should either explicitly set the environment variable SHELL to be the shell you want to use, or, if you want to have the COMSPEC environment variable determine the shell, then you need to install Emacs using the addpm.exe program and ensure that the SHELL environment variable is not defined when you start up Emacs.

Any replacement shell should follow Unix convention for the -c option, or else be invoked via cmdproxy.exe if it follows the DOS convention.

Note that sh-script.el does not recognize shell names when they have the '.exe' extension on them. If you use sh-script, you should omit the '.exe' extension when specifying the SHELL variable.

Alternatively, if you do not want to mess with the SHELL or COMSPEC variables, you can explicitly place the following in your startup file:

;; For the interactive shell
(setq explicit-shell-file-name "c:/bin/tcsh.exe")

;; For subprocesses invoked via the shell (e.g., "shell -c command")
(setq shell-file-name "c:/bin/tcsh.exe")

bash

You can get a version of bash with the Cygnus tools at http://www.cygnus.com/misc/gnu-win32. To use bash with Emacs, place the following in your startup file:

(defun my-shell-setup ()
  "For Cygwin bash under Emacs 20"
  (setq comint-scroll-show-maximum-output 'this)
  (setq comint-completion-addsuffix t)
  ;; (setq comint-process-echoes t) ;; reported that this is no longer needed
  (setq comint-eol-on-send t)
  (setq w32-quote-process-args ?\")
  (make-variable-buffer-local 'comint-completion-addsuffix))

(setq shell-mode-hook 'my-shell-setup)

Richard M. Heiberger's <rmh@fisher.stat.temple.edu> setup for Cygnus B19.

For more configuration information with bash, take a look at Jonathan Payne's <jpayne@marimba.com> setup.

If you find that you are having trouble with Emacs tracking drive changes with bash, see Mike Fabian's note <mike.fabian@it-mannesmann.de>

The package cygwin32-mount.el teaches Emacs about cygwin32 mount points.

WARNING:The latest version of bash sets and uses the environment variable PID. For some as yet unknown reason, if PID is set and Emacs passes it on to bash subshells, bash croaks (Emacs can inherit the PID variable if it's started from a bash shell). If you clear the PID variable in your startup file, you should be able to continue to use bash as your subshell:

(setenv "PID" nil)

ksh

For a version of ksh by David Korn, take a look at http://www.research.att.com/sw/tools/uwin. I haven't tried this shell with Emacs, but I'm guessing that it works under Emacs and that you need the following for it to work properly:

(setq w32-quote-process-args t)     ; Emacs 20
(setq shell-command-switch "-c")

If you find out otherwise, let me know and I'll update this section.

WARNING: People have reported that UWIN 1.5 ksh doesn't work with Emacs. I do not know why yet. If you figure out why, please send mail to the list.

MKS ksh

To use MKS ksh, place the following in your startup file:

(setq w32-quote-process-args t)   ; Emacs 20
(setq shell-command-switch "-c")

tcsh

You can find tcsh at ftp://ftp.blarg.net/users/amol/tcsh. To use tcsh, place the following in your startup file:

(setenv "SHELL" "tcsh.exe")
(setq w32-quote-process-args t)   ; Emacs 20
(setq shell-command-switch "-cf")

For more configuration information with tcsh, take a look at Chris McMahan's <cmcmahan@surefirev.com> setup.

zsh

You can find zsh at ftp://ftp.blarg.net/users/amol/zsh/

How do I make dired use my external ls program?

 To make dired, (the directory editor), use an external 'ls' program, which will allow you to see symbolic links, and such like you need to set two variables:

	(setq ls-lisp-use-insert-directory-program t)      ;; use external ls
	(setq insert-directory-program "c:/cygwin/bin/ls") ;; ls program name
         ;; Change this to your absolute path --^

How do I prevent shell commands from being echoed?

Some shells echo the commands that you send to them, and the echoed commands appear in the output buffer. In particular, the default shells, command.com on Windows 95 and cmd.exe on NT, have this behavior.

To prevent echoed commands from being printed, you can place the following in your startup file:

(defun my-comint-init ()
  (setq comint-process-echoes t))
(add-hook 'comint-mode-hook 'my-comint-init)

If shell-mode still is not stripping echoed commands, then you'll have to explicitly tell the shell to not echo commands. You can do this by setting the explicit-SHELL-args variable appropriately, where SHELL is the value of your shell environment variable (do a "M-: (getenv "SHELL")" to see what it is currently set to). Assuming that you are on NT and that your SHELL environment variable is set to cmd.exe, then placing the following in your startup file will tell cmd.exe to not echo commands:

(setq explicit-cmd.exe-args '("/q"))

The comint package will use the value of this variable as an argument to cmd.exe every time it starts up a new shell (as in shell-mode); the /q is the argument to cmd.exe that stops the echoing (in a shell, invoking "cmd /?" will show you all of the command line arguments to cmd.exe).

Note that this variable is case sensitive; if the value of your SHELL environment variable is CMD.EXE instead, then this variable needs to be named explicit-CMD.EXE-args instead.

How do I have Emacs complete directories with / instead of "?

The character appended to directory names when completing in shell-mode is determined by the value of the variable comint-completion-addsuffix. If the value of this variable it t, then a '/' is appended to directory names. If the value of this variable is a cons pair, then the first value of the pair is appended.

When I run programs within a shell I get Incorrect DOS version messages. Why?

This might happen if, for example, you invoke nmake in a shell and it tries to create subshells. The problem is related to the one above where, again, when the shell is initially created, the first argument to the shell is not the directory in which the shell program resides. When this happens, command.com fabricates a value for its COMSPEC environment variable that is incorrect. Then, when other programs go to use COMSPEC to find the shell, they are given the wrong value.

The fix for this is to either prevent any arguments from being sent to the shell when it starts up (in which case command.com will use a default, and correct, value for COMSPEC), or to have the first argument be the directory in which the shell executable resides.

When I do any shell-related commands, nothing happens. What could be wrong?

Chris Boucher <chris@sorted.org> reports that Dr. Solomon's WinGuard prevents any shell related commands from working. He found that turning off "Scan all files" makes it work, though.

How do I use mail with Emacs?

You do not need to do much to use mail with Emacs under Windows, but you do need to be able to communicate with local mail daemons and mail servers (they do most of the work) to both receive and send mail from your system. These daemons and servers are typically running on the machines in your local network that are already handling mail for you and/or other users on other systems.

Outgoing

For outgoing mail, you need to use smtpmail.el, which enables Emacs to talk SMTP with mail daemons (smtpmail.el was originally written by Tomoji Kagatani <kagatani@rbc.ncl.omron.co.jp> and is now included in the Emacs distribution). You also need to add the following to your startup file (be sure to customize for you and your system):

(setq user-full-name "Your full name")
(setq user-mail-address "Your email address")

(setq smtpmail-default-smtp-server "Domain name of machine with SMTP server")
(setq smtpmail-local-domain nil)
(setq send-mail-function 'smtpmail-send-it)

(load-library "smtpmail")

Note that if you want to change the name of the smtp server after you've loaded smtpmail.el, you'll want to change the variable smtpmail-smtp-server.

If you are using GNUS to send mail, then you will also need:

(load-library "message")
(setq message-send-mail-function 'smtpmail-send-it)

If you are experiencing problems with sending large messages, check the value of the variable smtpmail-debug-info. If it is non-nil, you should set it to nil:

(setq smtpmail-debug-info nil)

Outgoing: Queued

If you would like to queue your outgoing mail so that you can then later send it all as a batch (e.g., when you are working disconnected on a laptop), you can use the feedmail package written by Bill Carpenter <bill@bubblegum.net>.

Feedmail comes with Emacs 20.

Fabio Somenzi <Fabio@Colorado.EDU> also sent the following as an example of setting up Feemail:

(setq send-mail-function 'feedmail-send-it)
(autoload 'feedmail-send-it "feedmail")
(autoload 'feedmail-run-the-queue "feedmail")
(setq feedmail-buffer-eating-function 'feedmail-buffer-to-smtpmail)
(setq feedmail-enable-queue t) ; optional
(setq feedmail-queue-chatty nil) ; optional

Fabio also redefined the function make-auto-save-file-name to auto-save files in one local directory ($HOME/.save) and to strip out invalid characters in file names . Note that all files will auto-save to this directory; this allows Emacs to auto-save even when the folder files are on an inaccessible remote machine. Place the following definition of make-auto-save-file-name in your startup file to override the definition in winnt.el.

Lastly, if you would like to protect the primary folder from crashes while it is being written back to disk, then also place the following in your startup file (assuming you use VM):

(add-hook 'vm-mode-hook
          '(lambda ()
             (make-local-variable 'file-precious-flag)
             (setq file-precious-flag t)))

Incoming: RMAIL and POP3

For incoming mail using the RMAIL package and a POP3 mail server, you need only place the following in your startup file (again, be sure to customize):

(setenv "MAILHOST" "Domain name of machine with POP3 server")
(setq rmail-primary-inbox-list
    '("po:Your login") rmail-pop-password-required t)

Note that you will need to customize the Domain name of machine with POP3 server and Your login fields to be the name of your POP server and your login name.

Incoming: VM and POP3

For incoming mail using the VM package and a POP3 mail server, you first need the vm package (check any elisp archive) and then you need to place the following in your .vm configuration file:

(setq vm-spool-files
      (list
       (list "~/INBOX"
             "POP3 server:110:pass:POP user name:*"
             "~/INBOX.CRASH")))

Note that you will need to customize the POP3 server and POP user name fields to be your login name and the name of your POP server. You will also probably want to customize the name of your inbox and crash files (~/INBOX and ~/INBOX.CRASH in the example above.)

Incoming: GNUS

You should be able to use Gnus 5.2 and above as a mail reader. The following was sent as an example by Marc Fleischeuers <Marc.Fleischeuers@kub.nl>:

(load-library "message")

;; For sending mail
(setq message-send-mail-function 'smtpmail-send-it)

;; For reading mail (other backends can be substituted for nnml)
(setq gnus-secondary-select-methods '((nnml "")))
(setq nnmail-spool-file "po:POP user name")
(setq nnmail-pop-password-required t)

Be sure to customize the POP user name field appropriately.

Using GNUS with IMAP

 Setting up Gnus for reading IMAP email.

There are a number of different mail packages available