: Learning GNU Emacs, 3rd Edition

· #1

Quite a few issues come up in discussions of GNU Emacs versus XEmacs, with character encoding schemes, user interface differences, and copyright issues among them. We're not interested in taking sides in the battles between these emacsen.

· #2

Typically we would not find the need to be quite so specific, but the user interface changed at Emacs 21.3.5; in particular you'll notice different toolbar icons if you have an earlier version.

· #3

FSF programs such as Emacs are often distributed with commercial systems. Even in these cases, the General Public License guarantees your right to use and give away their programs without restriction. Of course, the license does not apply to other proprietary software with which GNU tools have been shipped.

· #4

GPL-compatible is a critical distinction for many organizations. As our reviewer Mike Trent points out, many organizations release their software under a modified GPL because the GPL's license is actually "viral." That is, if one line of GPL'd code appears in a project, the entire project must be GPL'd. This means corporations interested in protecting their assets but still wanting to share code with the open source community cannot use the GPL without some modification.

· #5

How you start Emacs may vary by platform. Linux has no icon on the desktop by default; Windows and Mac OS X do (if you've installed Emacs on these platforms). Note that Mac OS X comes with a version of GNU Emacs installed in /usr/bin, and that is what runs by default when you start up Emacs using the Terminal application. You won't be able to use the mouse at all if you run Emacs in the Terminal application, and there are a number of other limitations as well. Better versions of GNU Emacs are available to you; see Chapter 13 for details.

· #6

Emacs works best with a three-button mouse (more buttons are okay, too).

· #7

The scrollbar's location depends on the platform and windowing system you're using. Linux puts scrollbars on the left while Mac OS X and Windows put them on the right by default. Note also that the order of the information in the mode line is different if you run Emacs in a terminal window.

· #8

In certain special editing modes, such as dired-mode for viewing and manipulating directories on your computer, the normal typing keys don't insert themselves. They are instead bound to special commands that do things like opening and renaming files. This flexibility in defining and changing keymaps, while it might seem somewhat arbitrary and overwhelming at first, is one of the great sources of power in Emacs.

· #9

One exception to this rule is the *scratch* buffer. It's a scratchpad and Emacs assumes you were doodling, not doing serious artwork, so to speak. If you do any serious work in the *scratch* buffer, you must save it explicitly.

· #10

Remember that (none) in the first column means that you type M-x followed by the command name in the second column, then press Enter to run the command. There are no default keystrokes. To use the refill-mode command, type M-x refill-mode Enter.

· #11

Most often, you'll use C-u as we've described here. However, it doesn't always work as a multiplier; sometimes C-u modifies the command's function. Later in this chapter, you'll see one such case. However, if you're doing something where a multiplier makes sense, C-u is almost certain to work.

· #12

You may be used to pressing C-v to paste in all applications if you are a Linux or Windows user. Emacs has options to change its default paste, cut, and copy commands to the familiar C-v, C-x, and C-c. See "Making Emacs Work the Way You Want" for details. Also, a quick warning to vi users who are learning Emacs: vi also uses the term yank, but its meaning is almost the exact opposite. Don't let this confuse you.

· #13

You can make this happen if you highlight the text and then press xxxMacSymxxx-C. Simply highlighting the text doesn't copy it to the clipboard.

· #14

xxxMacSymxxx-v pastes from the clipboard.

· #15

On a Mac keyboard, we found that the Help key, to the left of Home, toggles overwrite mode.

· #16

If you find that you repeat the undo command frequently, it's worth getting fluent with C-_. It's true that this requires holding down Ctrl and Shift at the same time, but once you've got that down, pressing _ repeatedly is much easier than typing C-x u again and again.

· #17

There is no real difference between undo and advertised-undo. They work the same way.

· #18

We should say that Emacs tries to do this. In some cases, Emacs can't, and there is really no guarantee. Power surges and OS crashes are examples of times where things happen so fast that Emacs may not be able to create an auto-save file. But we are surprised at how often it manages to do so.

· #19

You could use C-_ for undo instead and then you wouldn't need to read this section. We recommend that you read it anyway because you might find another annoying key mapping that you want to change and this section tells a bit about how to do so.

· #20

Your default dictionary might be called something else entirely, like .aspell.language.pws. If you run the command ispell-check-version, you'll see that although Ispell is supposedly running, it's really Aspell behind the scenes.

· #21

Once upon a time this use of word abbreviation mode was nontraditional; these days Flyspell, described earlier, automatically defines misspellings as abbreviations.

· #22

The exception to the rule that ** means changed and %% means read-only is the *scratch* buffer. Because Emacs doesn't warn you if you kill the *scratch* buffer, even if it is changed, it wants to give you some indication that there are unsaved changes. Instead of %%, the *scratch* buffer puts %* on the mode line.

· #23

It's true that you can't resize Emacs windows using the mouse. But if you resize an Emacs frame, it does impact the size of the windows, even eliminating windows at times if the frame cannot display all the windows. Of course, as always, eliminating a window doesn't impact the underlying buffer.

· #24

You can have more than two windows on the screen, but only two are compared: the one the cursor is in and the next window (remember that the next window is either to the right or down if there is no window to the right).

· #25

You do have choices under Windows as well, thanks to Cygwin (http://cygwin.com/). For example, if you wanted to run Cygwin's bash, you'll find helpful information on how to set that up on Ngai Kim Hoong's page on that topic at http://www.khngai.com/emacs/cygwin.php.

· #26

The one exception to this is running Emacs in the Mac OS X Terminal application, which has its own drag-and-drop behavior. In the terminaland thus in Emacs running in the terminal windowdragging and dropping a folder inserts the complete pathname of that folder rather than opening the folder in Dired.

· #27

What if it's a file that shouldn't be viewed in Emacs, like a JPG or a PDF? In this case, the variable dired-view-command-alist associates viewers with file extensions. The defaults for this command work on Linux, but require some tweaking on other platforms. See Chapter 10 for an example of using Custom to change this variable for Mac OS X and Windows.

· #28

Emacs understands only compress and gzip formats, not ZIP or other proprietary file compression algorithms. When you uncompress files, Emacs recognizes and correctly uncompresses files with the following suffixes: .z, .Z, or .gz. When you compress files, Emacs uses gzip, resulting in files that end in .gz.

· #29

And if all the Dired features aren't enough, there's Dired-x, an add-in module that includes other features such as omitting unimportant files from the listing, finding files mentioned in any buffer, and additional variables and means of marking files. For more details, see the Info text on this subject (type C-h i to get to the Info menu).

· #30

This feature works on Linux, but not on Windows. To make it work on Mac OS X, set shell-file-name to /bin/sh.

· #31

If you normally use another binding for the set-mark command or if you typically spell out that command, you'll run into a problem marking regions in the calendar. In the calendar, C-Space and C-@ run calendar-set-mark rather than set-mark, so that regions are marked by time rather than just across the screen. To mark regions correctly in the calendar (linearly by time rather than simply across the screen), you must type C-Space, C-@, or M-x calendar-set-mark to set the mark.

· #32

You could delete the third column of a table by marking it as a rectangle, as described in Chapter 7. But bear with us for the sake of making this point: when you find yourself doing repetitive work, macros are the tool to remember.

· #33

Mac OS X users may have bound F3 and F4, used in defining and executing macros, to another key. These users should press Option-F3 and Option-F4 to get the same functionality.

· #34

M-a's definition of a "sentence" is controlled by the variable sentence-end, which is a fairly complex regular expression. By default, a sentence ends with a period, question mark, or exclamation mark, optionally followed by a quotation mark or parenthesis (including brackets or braces), and followed by two or more spaces or a newline.

· #35

You can't change tab stops with this method, but you can change tab width. We'll cover this shortly.

· #36

Once upon a time, you had to enter indented text mode explicitly to get the behavior we describe here. Now it is on by default in text mode.

· #37

Of course, after the document is complete, you'll want to remove the asterisks. You can use a query-replace to change the asterisk-style headers into headers that are appropriate for your preferred formatting style. Find the lowest-level heading and do its replacement first. If you have third-level headings, replace all occurrences of *** with the mark-up for a third-level heading, then move on to second-level headings, and finally first-level headings. Be careful on first-level headings, though; there may well be asterisks in the file that are unrelated to headings; preface the asterisk with C-q C-j to ensure that you get an asterisk that starts on a new line. Another approach is to use Eric Pement's awk scripts. The script at http://www.student.northpark.edu/pemente/awk/outline_classic11.awk.txt converts an outline mode outline to a classic outline while the script at http://www.student.northpark.edu/pemente/awk/outline_numbered11.awk.txt converts to a numbered outline.

· #38

You can, however, store rectangles in registers, providing the effective equivalent of the kill ring. More on this shortly.

· #39

Like all Emacs delete commands, delete-rectangle doesn't store what you delete in the kill ring.

· #40

A number of online groups are dedicated to ASCII art. Of course, all such art requires that you use a monospace font for proper viewing. Newsgroups such as alt.ascii.art and web sites such as the Ascii Art Dictionary (http://www.ascii-art.de/) provide a good introduction.

· #41

Other commands can accomplish this task more quickly, but bear with us for the sake of a simple example. For example, this little exercise could be accomplished with a single mouse drag in artist mode. Picture mode also offers a quick command for drawing a rectangle, C-c C-r.

· #42

SGML stands for standardized general markup language. Both XML and HTML are descendants of SGML.

· #43

At this writing, there is no way to enter XHTML mode explicitly. If your file looks like an XHTML file, Emacs puts you in that mode automatically.

· #44

Pay no attention to the fact that this is called SGML versus HTML name entity mode. Since HTML mode is derived from SGML mode, many commands that work with HTML have sgml in their names. Also, note that the command is called sgml-name-8bit-mode, a clear discrepancy with the minibuffer message.

· #45

For some reason, perhaps the way SGML name entity mode is programmed, you can insert these entities only using key bindings. The mode fails to trap the equivalent commands and translate them into entities. For this reason, we focus on key bindings.

· #46

For instructions on making these bindings work properly, read this section carefully.

· #47

The version we downloaded in August 2004 marked this file as alpha code, so don't be surprised if you find bugs. Visit the file to see if its status has changed.

· #48

For this to work, you must invoke the command through the keyboard, either using its key binding or its command name. Using a menu option doesn't work.

· #49

If M-Tab is trapped by the operating system to switch between applications (it is on Red Hat Linux), type Esc Tab instead.

· #50

We'd like to thank Emacs guru Eric Pement for pointing out TEI Emacs to Deb.

· #51

We sincerely hope that this support will be extended to Mac OS X as well, providing developers and writers on that platform the benefits of this tool's capabilities. Meanwhile, Mac users may want to install nxml mode from http://thaiopensource.com/download/ and psgml mode from http://www.lysator.liu.se/projects/about_psgml.html.

· #52

A straightforward introduction to setting up a complete environment for psgml mode can be found at http://openacs.org/doc/openacs-5-0-0/psgml-mode.html.

· #53

TEI Emacs, mentioned earlier in this chapter, automatically sets up the environment for you and adds more features including Auctex, a complete authoring environment that supports many TEX variants as well as bibcite/bibtex for generating bibliographies. However, LaTeX mode under TEI Emacs appears to be a different beast from Emacs LaTeX mode, and we do not describe it here.

· #54

If you don't have your TEX environment set up properly (and it isn't by default on Mac OS X, for example), this command hangs or crashes Emacs (pressing C-g may help; in one author's case it did and in another's it didn't). Try the latex command at a shell prompt to see if the command exists before attempting to process a file using Emacs.

· #55

Using tex-buffer gives the resulting .dvi file a long and strange filename that includes your domain name. We recommend using C-c C-f (for tex-file) instead.

· #56

The -k option overrides make's default of stopping after a job returns an error. Instead, make continues on branches of the dependency tree that do not depend on the branch where the error occurred.

· #57

Unfortunately, Emacs won't understand error messages generated by make itself, such as those due to syntax errors in your Makefile.

· #58

If grep -n is run on only one file, it just prints line numbers; Emacs forces it to print the filename as well in this case by appending the dummy file /dev/null to the grep command.

· #59

Actually, there is a limit to how far back (in characters) Emacs searches for a matching open parenthesis: this is the value of the variable blink-matching-paren-distance, which defaults to 25,600. The duration of the "flash" is also configurable: it's the value (in seconds) of blink-matching-delay, whose default value is 1.

· #60

The key binding is mnemonic for Lisp programmers because comments in Lisp start with semicolons.

· #61

etags is also a platform-specific feature. The etags facility is available on Unix platforms, including Mac OS X.

· #62

We know! There is no M-x cc-mode. It can be confusing. Just try to remember that the modes are named directly after the language they support.

· #63

The function commands have "defun" in their names because they are actually adaptations of analogous commands in Lisp mode; a defun is a function definition in Lisp.

· #64

These emulate electric-c-mode in the old Gosling Emacs.

· #65

Before we take you through the installation process, we should mention two caveats. XEmacs has the JDEE built-in, though it is often out-of-date. TEI-Emacs, an add-on for Linux and Windows described in Chapter 8, also includes the JDEE.

· #66

For Mac OS X users, the classes normally found in tools.jar are already a permanent part of the standard classes.jar so they are always availableeven though tools.jar isn't in any of the library locations.

· #67

The indentation style is bound up in the Emacs Lisp code for Lisp mode. If you are an experienced Lisp hacker, you can examine the code for lisp-mode.el in the Emacs Lisp directory and determine how to customize indentation the way you wish. A good place to start looking is the function lisp-indent-line.

· #68

This key binding may not work on all platforms. If it is intercepted by the operating system (as it is on Red Hat Linux), type Esc Tab instead (remember to release Esc before you press Tab).

· #69

This Lisp mode command (run-lisp) was designed to run with the franz Lisp system on BSD Unix systems, though it should work with other Lisp interpreters.

· #70

You can use Meta in place of Esc, but the bindings are still stored in the esc-map.

· #71

There is a better way of dealing with this situation, which we will cover in the next chapter.

· #72

Lisp programmers will understand that there are other ways to add to auto-mode-alist, such as append.

· #73

We recommend Lisp by Patrick Henry Winston and Berthold Klaus Paul Horn (Addison Wesley).

· #74

Experienced Lisp programmers should note that Emacs Lisp most closely resembles MacLisp, with a few Common Lisp features added. More complete Common Lisp emulation can be had by loading the package cl (see Appendix B).

· #75

Integers are also allowed where characters are expected. The ASCII code is used on most machines. For example, the number 65 is interpreted as the character A on such a machine.

· #76

We hope that Lisp purists will forgive us for calling setq a function, for the sake of simplicity, rather than a form, which it technically is.

· #77

Statement blocks are actually optional; some programmers like to omit the final statement block, leaving the final "condition" as an "otherwise" clause to be executed if all of the preceding conditions evaluate to nil. If the statement block is omitted, the value returned by cond is simply the value of the condition.

· #78

Emacs uses ASCII codes (on most machines) to build ranges, but you shouldn't depend on this fact; it is better to stick to dependable things, like all-lowercase or all-uppercase alphabet subsets or [0-9] for digits, and avoid potentially nonportable items, like [A-z] and ranges involving punctuation characters.

· #79

The version presented in this example is simplified for reasons of space and clarity. The full version, which adds the ability to insert templates for function definitions and process arbitrary Emacs Lisp functions within template files, is also available for download.

· #80

Unfortunately, because such variables are defined before they are made local to the mode, there is still a problem with name clashes with global variables. Therefore, it is still important to use names that aren't already used for global variables. A good strategy for avoiding this is to use variable names that start with the name of the mode.

· #81

Experienced Lisp programmers should note that Emacs Lisp does not supply standard contractions like cadr, cdar, and so on.

· #82

APL programmers will recognize these as variations of that language's "scan" operators.

· #83

The second argument to re-search-forwardand other search functionsgives a bound to the search: if given an integer value n don't search past character position n. A value of nil, the default, means don't give the search a bound.

· #84

There is also the option "-f function-name" which causes Emacs to run the function function-name at startup, with no arguments.

· #85

You don't need to have registered a file from VC to use VC on it. VC works just fine on a preexisting tree of version-controlled files.

· #86

Minor tricky detail: your very first vc-next-action on a new work file normally takes you from "unregistered" through "registered, unlocked," and then to "locked, editable." Why make you do two commands for those two steps when one will cover the typical case? If you want to register a file but not check it out, use C-x v i (for vc-register). With the advent of CVS, this point becomes largely moot as you'll see in Figure 12-2.

· #87

This is a slight oversimplification. VC actually has its own script as a wrapper around SCCS's sccsdiff, in order to give it a calling sequence more like RCS's rcsdiff.

· #88

Depending on your system and its permissions, you may have to switch to the root user using su to install Emacs. In that case, you won't need to preface the final make command with sudo.

· #89

One of the authors was not able to see the splash screen, but the install worked fine nonetheless. We say forge ahead even if you don't see it.

· #90

We say "more or less" because at the time we went to press, you still needed to grab the source from a separate site. That difference should eventually disappear as well.

· #91

A donation to defray hosting costs would certainly be appreciated; the site includes a link for contributions.

· #92

You can still run this new Emacs as a plain Terminal app with the -nw command-line argument (type emacs -nw.)

· #93

We found this hint on John Schneider's web page called "Getting Mac OS X.3 to Behave Almost Like My Linux Boxes" (http://www.eecs.wsu.edu/~schneidj/mac-os-x-10.3.html).

· #94

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.

· #95

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.

· #96

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

· #97

These command names are case-sensitive. For example, completion won't find them if you type them with a lowercase i.

· #98

You can't just press Tab without typing the p because the current and parent directories, named . and .., respectively, are also file choices. Normally, Emacs runs dired when you visit a file that's a directory.

· #99

For example, if you make changes to your .emacs file regularly, you will appreciate that M-x eval-c is an acceptable prefix for M-x eval-current-buffer.

· #100

Emacs Lisp mode is also invoked for files named .emacs or _emacs. In the default configuration, Lisp Interaction mode is used by the initial *scratch* buffer.

· #101

See Chapter 8 for an extensive discussion of working with markup languages in Emacs.

· #102

Some of these will be useful on Windows only if you've installed a Unix compatibility package like Cygwin (see http://www.cygwin.com).

----


: 0.107. /Cache: 0 / 0