Warning
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, cdto the directory where you installed Emacs and type emacs -nw(or whatever command-line argument you wanted to use; -nwruns 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 OKto 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-ccopies and C-vpastes 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. [95]It allows standard Windows key bindings, like C-xfor cut and C-vfor 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-fin fine shape.
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-xis used for cutting text, C-cis used for copying text, and C-vis used for pasting text. What is not so apparent is that C-zruns 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-xin this case. This works in part because C-ccancels the active region. Remember that C-xwould normally cut.
Strictly speaking, C-x C-xdoesn't immediately cut text, if you type it fast enough. Cut is really bound to C-x . 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-sto save the buffer, Emacs does the right thing. But if you pause after C-x, you'll cut text. This is true of C-cas well. If you immediately type another sequence after C-c, Emacs uses C-cas 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-vdoes 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-1lists 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-zdoes outside CUA mode). |
Читать дальше