Sams Teach Yourself Emacs in 24 Hours

ContentsIndex

Hour 2: Using Emacs in Microsoft Windows

Previous HourNext Hour

Sections in this Hour:

 

Setting Up for Printing


For most people setting the printer for NT Emacs is simple. You leave it alone and Emacs prints to the default printer.

If that doesn't work, you have some experimenting to do. You have to set the name of the printer. You can use customize (see Hour 10, "The Emacs Help System and Configuration System") or put a Lisp expression in your .emacs, such as the following:


(setq printer-name "LPT1:")

Put this or something like it into your .emacs file. Although PRN is the preferred default printer for Windows (it always points to your default printer), sometimes you are better off selecting a specific printer such as LPT1.

You can also set your printer to a network shared printer:


(setq printer-name "//server/deskjet")

To test printing, select a small region of a buffer, and pull down the Tools menu with your mouse. Under Print select Print Region.

If you can't get printing working any other way, make your printer sharable, and print to its share name. It's ugly but it gets you there.

PostScript Printing

PostScript printing is very nice under Emacs. Emacs provides a banner in the top inch of the first page, which makes it easy to identify printouts. Also, if font-lock mode is active in the buffer you print, PostScript printing picks up the colors. Black-and-white printers print grayscale for the colors. Color printers print your file in full color.

To set up PostScript printing, set the variable ps-printer-name. This snippet of elisp code sets Emacs's printer to be the printer deskjet on the server named server:


(setq ps-printer-name "//server/deskjet")

If you don't have a PostScript printer, you can also send PostScript printing to a shared printer. Maybe someone else on the network has one.

Tip - Not all Windows NT servers are true Windows NT servers. If you operate in a mixed Windows and UNIX environment, you should look into Samba as a way to share files and printers on UNIX machines with Windows computers. See http://samba.anu.edu.au/pub/samba/ for more information.

Ghostscript

If you don't have access to a PostScript printer, you can fake it. Ghostscript is a free program that takes a PostScript file as input and prints it on your printer. It is available under the Aladdin Free Public License, which is similar to the General Public License under which Emacs is distributed. Check out http://www.cs.wisc.edu/~ghost/. Unfortunately, due to licensing restrictions, Sams was unable to include it on the CD-ROM that accompanies this book.

If you use Ghostscript, you can adjust Emacs's variables to run Ghostscript directly. Use something such as the following in your .emacs file:


    (setq ps-printer-name t) 
    (setq ps-lpr-command "gswin32c") 
    (setq ps-lpr-switches '("-q" "-dNOPAUSE" "-")) 

Customizing Emacs

Emacs is probably the most customized program in the known universe. There are all sorts of things that you can do, and some of them will be covered in other hours. Here, I'll look at customizing Emacs to look more like a Windows application, and customizing Windows to look more like UNIX.

Emacs on Windows finds itself bridging two worlds, that of UNIX and that of Windows. I'll describe how to make Emacs look more like a typical Windows application, and how to make Windows look a bit more like UNIX.

Windows

If you are accustomed to Windows and its predecessors, you are accustomed to applications working in certain ways. IBM and Microsoft, back when they were talking to each other, set out certain standards for the ways applications would treat certain keystrokes. For example, the Home key should move the cursor to the left end of the line. This standard is called Common User Access (CUA).

Emacs doesn't do that. It has its own standards. If you are accustomed to the way most applications work on Windows, that can be frustrating. Fortunately, there is a way to deal with that. Two, in fact.

delsel

delsel is short for delete-select. It lets you mark a region, as you would for normal killing. But you can simply replace the region from the clipboard or by typing, without having to delete it first. For example, you can type the word foo and block it out using the normal Emacs selection method. Then, to replace foo with bar, type the b. That replaces the word foo. Type ar, and you're finished.

To activate it, press M-x (delete-selection-mode).

pc-select

pc-select lets you use the Windows standard keystrokes to select text and mark it. For example, with this mode enabled, you can mark a region by moving point and holding the Shift key down. To activate it, press M-x (pc-selection-mode).

Check the FAQ at http://www.cs.washington.edu/homes/voelker/ntemacs.html from time to time. New tricks show up there.

UNIX

There are also people who are accustomed to UNIX and find themselves dragged, kicking and screaming, to Windows, and pine for the good old days on UNIX. Well, I have some relief for them.

Microsoft has some tools that will let you make your Windows system more like X. Check out http://www.microsoft.com/windows/downloads/contents/wutoys/w95pwrtoyset . Note that these are unsupported freebies.

One bit of customizing you probably won't have to do is to set Emacs to use a three-button mouse. It should do so automatically. If not, check the FAQ.

There are a number of ports of UNIX shells available for Win32. Some are included on the accompanying CD-ROM. Check the Windows NT Emacs FAQ for details. Setting up Emacs to run the shell of your choice is a matter of setting some variables. I recommend the Cygnus GNU tools port, which is included on the CD-ROM, only in part because it is licensed under the General Public License. It includes Bash, which is probably the UNIX shell most used by NT Emacs users.

Windows Notes - Note that setting Emacs to use a shell other than command.com or cmd.exe affects interactive compiles from Emacs ( M-x; compile), so you might not want to use another shell if you use Microsoft Visual Studio or any of the Microsoft Visual products.


Check the FAQ at http://www.cs.washington.edu/homes/voelker/ntemacs.html occasionally.

Sams Teach Yourself Emacs in 24 Hours

ContentsIndex

Hour 2: Using Emacs in Microsoft Windows

Previous HourNext Hour

Sections in this Hour: