13.3. Emacs and Windows


You can also download and install Emacs 21.3 for the various Windows platforms (Win95, Win98, Win2K, WinXP, and so on). As most Windows machines do not ship with the tools required to build Emacs from scratch, we'll look at downloading and installing prebuilt executables.[7]

[7] Okay, okay. If you want to build it on Windows, you certainly can. We suggest grabbing the various development tools like make and gcc from the Cygwin project (http://www.cygwin.com) and then following the Unix build instructions.

13.3.1 Installing Emacs

As with all platforms, you have choices when installing Emacs on Windows. You can install a binary hosted by the FSF (likely to be older, but certainly stable). You can find a more recent binary online (we'll point you to the one we prefer). You could also build Emacs from CVS, but if you're doing that on Windows, chances are you are not reading this book. Windows comes with no default compilers.

13.3.1.1 Installing the latest binaries: Nqmacs

Our source for the latest binaries is Nqmacs (http://sourceforge.net/projects/nqmacs/). This is simply a build of the latest version of GNU Emacs from CVS sources, not a separate version of Emacs as the name may imply. Windows binaries are posted here on a regular basis, giving Windows users access to the latest version without having to build it themselves.

To install on Windows, simply download the latest binaries, unpack into a new folder using WinZip or Windows own decompression utilities, go to the bin subfolder and double-click on runemacs.exe. By right-clicking on the icon, you can send a copy of the icon to the desktop.

13.3.1.2 Installing Emacs from the FSF

As we mentioned, the binaries at the FSF are stable but generally older. For example, at this writing, the Nqmacs site provides binaries built on 7/25/04 while the FSF's site provides binaries from 3/10/2004.

To download Emacs from the FSF, simply point your browser at http://ftp.gnu.org/pub/gnu/emacs/. Scroll down to find the windows folder. In there, you should find several downloads. The binaries come in three flavors:

  • bare (barebin) the bare minimum you need to get going

  • standard (bin) what most folks need to get running

  • full (fullbin) the full meal deal; everything and then some

Grab the one you want and download it. You can use WinZip (http://www.winzip.com) to unpack it. If you have the Cygwin utilities installed, you can also use gunzip and tar as we discussed in the Unix installation section.

Be careful! The README.W32 file notes that you may run into some small problems if you unpack your Emacs distribution into a path where one or more of the directory names contains spaces. For example, don't unpack Emacs in the Program Files directory. If you don't like adding things directly to your C: drive, create an Applications folder or something similar and unpack Emacs in that folder.


After that's unpacked, you're 99 percent of the way there. The latest versions of Emacs need nothing else, actually; you just double-click on runemacs.exe (in the bin directory of your Emacs folder) and off you go! If you like, you can create shortcuts in your Start menu or on the desktop. Just point them at runemacs.exe and you should be set.

13.3.2 Where to Put Your .emacs File

Probably the single biggest Windows consideration is the location of the .emacs file. This file goes in your "home" directory. We use quotes there because the Windows world doesn't have a strictly defined home directory the way some other operating systems like Unix and Mac OS X do. By default, Emacs assumes that the C:\ folder is your home directory. You can put your .emacs file there, but you can also modify your home directory using the Windows environment variable called HOME. To change this environment variable on Windows XP, select System from the Control Panel. A System Properties window displays. Choose the Advanced tab, then choose Environment Variables. HOME is probably not listed; click on New, then type HOME and the path to your desired home directory. Emacs will now look for the .emacs file in this directory.

Because of naming compatibility issues, older Windows versions of Emacs used the _emacs file rather than the .emacs file for customization and configuration. This file is still a valid option. However, if both _emacs and .emacs are found in the home directory, only .emacs is used.

13.3.3 Starting Emacs from the Command Line

The Emacs bin folder includes two related files, each sporting a Gnu icon: emacs.exe and runemacs.exe. Typically you'll use runemacs.exe; this runs Emacs graphically without opening a console window. The other file, emacs.exe, can be used to run Emacs from the command line as described next.

To run Emacs from the command line, cd to the directory where you installed Emacs and type emacs -nw (or whatever command-line argument you wanted to use; -nw runs Emacs in the console window). You can also do this by choosing Start Run, then selecting Browse to locate emacs.exe. Add any command-line arguments you wish, and then click OK to invoke Emacs using these arguments.

13.3.4 Making Emacs Act like Windows: CUA Mode

CUA stands for common user access, a standard originally developed by IBM. CUA mandates that certain keys should always perform certain functions. In Windows, for example, C-c copies and C-v pastes from one application to another. As you know, Emacs uses these key bindings for its own purposes.

That's where Kim Storm's CUA mode comes in. This mode was so popular that it is now part of Emacs.[8] It allows standard Windows key bindings, like C-x for cut and C-v for paste, to work properly within Emacs. It's quite clever these keys cut and paste only when an active selection exists. That leaves the normal functionality of multistroke commands like C-c C-f in fine shape.

[8] If you are running an older version of Emacs and want this functionality, visit http://www.cua.dk/emacs.html to download and install CUA mode.

To turn on CUA mode, select C-x/C-c/C-v cut-and-paste (CUA) from the Options menu. If you decide you want to use CUA mode for multiple sessions, select Save Options to have Custom (discussed in Chapter 10) automatically add it to your .emacs file.

As you can see from the option name, in this mode, C-x is used for cutting text, C-c is used for copying text, and C-v is used for pasting text. What is not so apparent is that C-z runs undo rather than minimizing the window (in CUA mode, you can minimize using C-x C-z).

What if you're used to confirming a region before you cut it using C-x C-x? You can type C-c C-x C-x in this case. This works in part because C-c cancels the active region. Remember that C-x would normally cut.

Strictly speaking, C-x C-x doesn't immediately cut text, if you type it fast enough. Cut is really bound to C-x <timeout>. In other words, Emacs is watching to see if you type something else really quickly. If you have a region highlighted and type C-x C-s to save the buffer, Emacs does the right thing. But if you pause after C-x, you'll cut text. This is true of C-c as well. If you immediately type another sequence after C-c, Emacs uses C-c as a prefix. If you pause, it copies the highlighted text.

CUA mode has a few other interesting behaviors. It has highly advanced rectangle support. (Rectangle editing is described in Chapter 7.) It also has the common behavior of replacing highlighted text. If you select a region and start typing, the highlighted text is replaced. Taking this one step further, you can do a quick and dirty search and replace in this way. Let's say that the text you typed over is just the first of several identical instances where you want to replace text. Typing M-v (for cua-repeat-replace-region) replaces the next instance. Repeat this command to continue making replacements. If there is no string to replace, M-v does nothing.

For example, let's take our classic Dickens passage and replace the word times with rhymes:

Highlight the word times.

The word times is highlighted.


Type: rhymes

Emacs replaces times with rhymes.


Type: M-v

Emacs replaces the next instance of times with rhymes.


You may love CUA mode or you may hate it; the only way to see if your fingers are ready for this option is to try it out. If you've used Emacs for years, you may find CUA mode keeps doing unexpected things. Your finger habits are set to Emacs's ways. On the other hand, it's hard to move back and forth between applications and change your finger habits all the time. If you have not yet gotten used to the Emacs key bindings, you may well love CUA mode, as many people do.

Table 13-1 lists CUA mode commands.

Table 13-1. CUA mode commands

Keystrokes

Command name

Action

C-c C-x C-x

cua-exchange-point-and-mark

Exchange location of cursor and mark.

C-c

copy-region-as-kill

Copy the region.

C-x or C-w or S-Delete

kill-region

Delete the region.

C-v or C-y or S-Insert

cua-paste

Paste most recently killed or copied text.

M-v

cua-repeat-replace-region

After highlighting and replacing a string, find the next string and replace it the same way.

PgUp

cua-scroll-up

Scroll up one page (or to the beginning of the buffer).

PgDown

cua-scroll-down

Scroll down one page (or to the end of the buffer).

M-y

cua-paste-pop

After C-v, pastes earlier deletion.

C-z or C-x u

cua-undo

Undoes the last change.

C-x C-z

iconify-frame

Minimize the current frame (what C-z does outside CUA mode).


13.3.5 Installing Ispell

Installing Ispell on Windows can be tricky. Emacs 20 and beyond includes features like Flyspell and earlier versions of Ispell won't handle that functionality. Many Windows users do not compile their own software, and even if they did, the very newest Ispell also doesn't work with Emacs.

We found the version we describe here in a post by Raymond Zeitler (http://lists.nongnu.org/archive/html/help-emacs-windows/2004-06/msg00023.html), and we thank him heartily for it. The only downside to this version is that it is designed for English speakers. It may well work with other languages, but you'd have to find the <language>.hash file appropriate for your language.

The first step is to download a Windows binary of Ispell 3.1.20.[9]

[9] This binary is also available from this book's web site, http://www.oreilly.com/catalog/gnu3.

Open a command window. On Windows XP, you open it using Start Run, then typing OK.

Create a temporary directory and move there (you can substitute another name for tmp).

C:\> mkdir tmp C:\> cd tmp

FTP to gatekeeper.dec.com.

C:\tmp> ftp gatekeeper.dec.com

Type anonymous as your username and your email address as your password.

Move to the /pub/GNU/windows/emacs/contrib directory.

C:\tmp> cd /pub/GNU/windows/emacs/contrib

Type bin to change to binary mode.

C:\tmp> bin

Download ispell.zip.

C:\tmp> get ispell.zip

Type bye to close your ftp session, then exit to close the MS-DOS window.

Unzip the archive with WinZip or Windows' own decompression utility. We need to move a few files around to make Ispell work properly with Emacs.

Move ispell.exe to Emacs' bin folder. For example, if you called the folder where you installed Emacs nqmacs, you would place the file in nqmacs\bin.

Move english.hash to your home directory (either C: or the one you defined earlier as the location for your .emacs file). Now copy english.hash to american.hash (both files must exist for Ispell to work properly). We suspect but cannot verify that this would not be necessary for users of systems expecting British English dictionaries.

There's a lot more to the world of Emacs in Windows. We encourage you to check out the frequently asked questions and documentation available online at http://www.gnu.org/software/emacs/windows/.



Learning GNU Emacs
Learning GNU Emacs, Third Edition
ISBN: 0596006489
EAN: 2147483647
Year: 2003
Pages: 161

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net