GNU Emacs FAQ


Next: , Previous: (dir), Up: (dir)

This is the GNU Emacs FAQ, last updated on 4 June 2007.

This FAQ is maintained as a part of GNU Emacs. If you find any errors, or have any suggestions, please use M-x report-emacs-bug to report them.


Next: , Previous: Top, Up: Top

1 FAQ notation

This chapter describes notation used in the GNU Emacs FAQ, as well as in the Emacs documentation. Consult this section if this is the first time you are reading the FAQ, or if you are confused by notation or terms used in the FAQ.


Next: , Previous: FAQ notation, Up: FAQ notation

1.1 What do these mean: C-h, C-M-a, <RET>, <ESC> a, etc.?

Key sequences longer than one key (and some single-key sequences) are written inside quotes or on lines by themselves, like this:

       M-x frobnicate-while-foo RET

Any real spaces in such a key sequence should be ignored; only <SPC> really means press the space key.

The ASCII code sent by C-x (except for C-?) is the value that would be sent by pressing just <x> minus 96 (or 64 for upper-case <X>) and will be from 0 to 31. On Unix and GNU/Linux terminals, the ASCII code sent by M-x is the sum of 128 and the ASCII code that would be sent by pressing just <x>. Essentially, <Control> turns off bits 5 and 6 and <Meta> turns on bit 71.

C-? (aka <DEL>) is ASCII code 127. It is a misnomer to call C-? a “control” key, since 127 has both bits 5 and 6 turned ON. Also, on very few keyboards does C-? generate ASCII code 127.

see Text Characters, and see Keys, for more information. (See On-line manual, for more information about Info.)


Next: , Previous: Basic keys, Up: FAQ notation

1.2 What does M-x command mean?

M-x command means type M-x, then type the name of the command, then type <RET>. (See Basic keys, if you're not sure what M-x and <RET> mean.)

M-x (by default) invokes the command execute-extended-command. This command allows you to run any Emacs command if you can remember the command's name. If you can't remember the command's name, you can type <TAB> and <SPC> for completion, <?> for a list of possibilities, and M-p and M-n (or up-arrow and down-arrow on terminals that have these editing keys) to see previous commands entered. An Emacs command is an interactive Emacs function.

Your system administrator may have bound other key sequences to invoke execute-extended-command. A function key labeled Do is a good candidate for this, on keyboards that have such a key.

If you need to run non-interactive Emacs functions, see Evaluating Emacs Lisp code.


Next: , Previous: Extended commands, Up: FAQ notation

1.3 How do I read topic XXX in the on-line manual?

When we refer you to some topic in the on-line manual, you can read this manual node inside Emacs (assuming nothing is broken) by typing C-h i m emacs <RET> m topic <RET>.

This invokes Info, the GNU hypertext documentation browser. If you don't already know how to use Info, type <?> from within Info.

If we refer to topic:subtopic, type C-h i m emacs <RET> m topic <RET> m subtopic <RET>.

If these commands don't work as expected, your system administrator may not have installed the Info files, or may have installed them improperly. In this case you should complain.

See Getting a printed manual, if you would like a paper copy of the Emacs manual.


Next: , Previous: On-line manual, Up: FAQ notation

1.4 What are etc/SERVICE, src/config.h, and lisp/default.el?

These are files that come with Emacs. The Emacs distribution is divided into subdirectories; the important ones are etc, lisp, and src.

If you use Emacs, but don't know where it is kept on your system, start Emacs, then type C-h v data-directory <RET>. The directory name displayed by this will be the full pathname of the installed etc directory. (This full path is recorded in the Emacs variable data-directory, and C-h v displays the value and the documentation of a variable.)

The location of your Info directory (i.e., where on-line documentation is stored) is kept in the variable Info-default-directory-list. Use C-h v Info-default-directory-list <RET> to see the value of this variable, which will be a list of directory names. The last directory in that list is probably where most Info files are stored. By default, Info documentation is placed in /usr/local/info.

Some of these files are available individually via FTP or e-mail; see Informational files for Emacs. They all are available in the source distribution. Many of the files in the etc directory are also available via the Emacs `Help' menu, or by typing C-h ? (M-x help-for-help).

Your system administrator may have removed the src directory and many files from the etc directory.


Previous: File-name conventions, Up: FAQ notation

1.5 What are FSF, LPF, OSF, GNU, RMS, FTP, and GPL?

FSF
Free Software Foundation
LPF
League for Programming Freedom
OSF
Open Software Foundation
GNU
GNU's Not Unix
RMS
Richard Matthew Stallman
FTP
File Transfer Protocol
GPL
GNU General Public License

Avoid confusing the FSF, the LPF, and the OSF. The LPF opposes look-and-feel copyrights and software patents. The FSF aims to make high quality free software available for everyone. The OSF is a consortium of computer vendors which develops commercial software for Unix systems.

The word “free” in the title of the Free Software Foundation refers to “freedom,” not “zero cost.” Anyone can charge any price for GPL-covered software that they want to. However, in practice, the freedom enforced by the GPL leads to low prices, because you can always get the software for less money from someone else, since everyone has the right to resell or give away GPL-covered software.


Next: , Previous: FAQ notation, Up: Top

2 General questions

This chapter contains general questions having to do with Emacs, the Free Software Foundation, and related organizations.


Next: , Previous: General questions, Up: General questions

2.1 What is the LPF?

The LPF opposes the expanding danger of software patents and look-and-feel copyrights. To get more information, feel free to contact the LPF via e-mail or otherwise. You may also contact Joe Wells; he will be happy to talk to you about the LPF.

You can find more information about the LPF in the file etc/LPF. More papers describing the LPF's views are available on the Internet and also from the LPF home page.


Next: , Previous: The LPF, Up: General questions

2.2 What is the real legal meaning of the GNU copyleft?

The real legal meaning of the GNU General Public License (copyleft) will only be known if and when a judge rules on its validity and scope. There has never been a copyright infringement case involving the GPL to set any precedents. Please take any discussion regarding this issue to the newsgroup news:gnu.misc.discuss, which was created to hold the extensive flame wars on the subject.

RMS writes:

The legal meaning of the GNU copyleft is less important than the spirit, which is that Emacs is a free software project and that work pertaining to Emacs should also be free software. “Free” means that all users have the freedom to study, share, change and improve Emacs. To make sure everyone has this freedom, pass along source code when you distribute any version of Emacs or a related program, and give the recipients the same freedom that you enjoyed.


Next: , Previous: Real meaning of copyleft, Up: General questions

2.3 What are appropriate messages for news:gnu.emacs.help, news:gnu.emacs.bug, news:comp.emacs, etc.?

The file etc/MAILINGLISTS describes the purpose of each GNU mailing list. (See Informational files for Emacs, if you want a copy of the file.) For those lists which are gatewayed with newsgroups, it lists both the newsgroup name and the mailing list address.

The newsgroup news:comp.emacs is for discussion of Emacs programs in general. This includes Emacs along with various other implementations, such as XEmacs, JOVE, MicroEmacs, Freemacs, MG, Unipress, CCA, and Epsilon.

Many people post Emacs questions to news:comp.emacs because they don't receive any of the gnu.* newsgroups. Arguments have been made both for and against posting GNU-Emacs-specific material to news:comp.emacs. You have to decide for yourself.

Messages advocating “non-free” software are considered unacceptable on any of the gnu.* newsgroups except for news:gnu.misc.discuss, which was created to hold the extensive flame-wars on the subject. “Non-free” software includes any software for which the end user can't freely modify the source code and exchange enhancements. Be careful to remove the gnu.* groups from the `Newsgroups:' line when posting a followup that recommends such software.

news:gnu.emacs.bug is a place where bug reports appear, but avoid posting bug reports to this newsgroup directly (see Reporting bugs).


Next: , Previous: Guidelines for newsgroup postings, Up: General questions

2.4 Where can I get old postings to news:gnu.emacs.help and other GNU groups?

The FSF has maintained archives of all of the GNU mailing lists for many years, although there may be some unintentional gaps in coverage. The archive is not particularly well organized or easy to retrieve individual postings from, but pretty much everything is there.

The archive is at ftp://lists.gnu.org/.

The archive can be browsed over the web at the GNU mail archive.

Web-based Usenet search services, such as Google, also archive the gnu.* groups.

You can read the archives of the gnu.* groups and post new messages at Gmane.


Next: , Previous: Newsgroup archives, Up: General questions

2.5 Where should I report bugs and other problems with Emacs?

The correct way to report Emacs bugs is to use the command M-x report-emacs-bug. It sets up a mail buffer with the essential information and the correct e-mail address which is bug-gnu-emacs@gnu.org for the released versions of Emacs. Anything sent to bug-gnu-emacs@gnu.org also appears in the newsgroup news:gnu.emacs.bug, but please use e-mail instead of news to submit the bug report. This ensures a reliable return address so you can be contacted for further details.

Be sure to read the “Bugs” section of the Emacs manual before reporting a bug! The manual describes in detail how to submit a useful bug report (see Reporting Bugs). (See On-line manual, if you don't know how to read the manual.)

RMS says:

Sending bug reports to help-gnu-emacs@gnu.org (which has the effect of posting on news:gnu.emacs.help) is undesirable because it takes the time of an unnecessarily large group of people, most of whom are just users and have no idea how to fix these problem. bug-gnu-emacs@gnu.org reaches a much smaller group of people who are more likely to know what to do and have expressed a wish to receive more messages about Emacs than the others.

RMS says it is sometimes fine to post to news:gnu.emacs.help:

If you have reported a bug and you don't hear about a possible fix, then after a suitable delay (such as a week) it is okay to post on gnu.emacs.help asking if anyone can help you.

If you are unsure whether you have found a bug, consider the following non-exhaustive list, courtesy of RMS:

If Emacs crashes, that is a bug. If Emacs gets compilation errors while building, that is a bug. If Emacs crashes while building, that is a bug. If Lisp code does not do what the documentation says it does, that is a bug.


Next: , Previous: Reporting bugs, Up: General questions

2.6 How do I unsubscribe from this mailing list?

If you are receiving a GNU mailing list named list, you might be able to unsubscribe from it by sending a request to the address list-request@gnu.org. However, this will not work if you are not listed on the main mailing list, but instead receive the mail from a distribution point. In that case, you will have to track down at which distribution point you are listed. Inspecting the `Received' headers on the mail messages may help, along with liberal use of the `EXPN' or `VRFY' sendmail commands through `telnet site-address smtp'. Ask your postmaster for help, if you cannot figure out these details.


Previous: Unsubscribing from Emacs lists, Up: General questions

2.7 What is the current address of the FSF?

E-mail
gnu@gnu.org
Telephone
+1-617-542-5942
Fax
+1-617-542-2652
World Wide Web
http://www.gnu.org/
Postal address
Free Software Foundation
51 Franklin Street, Fifth Floor
Boston, MA 02110-1301
USA

For details on how to order items directly from the FSF, see the GNU Web site.


Next: , Previous: General questions, Up: Top

3 Getting help

This chapter tells you how to get help with Emacs


Next: , Previous: Getting help, Up: Getting help

3.1 I'm just starting Emacs; how do I do basic editing?

Type C-h t to invoke the self-paced tutorial. Just typing C-h enters the help system. Starting with Emacs 22, the tutorial is available in many foreign languages such as French, German, Japanese, Russian, etc. Use M-x help-with-tutorial-spec-language <RET> to choose your language and start the tutorial.

Your system administrator may have changed C-h to act like <DEL> to deal with local keyboards. You can use M-x help-for-help instead to invoke help. To discover what key (if any) invokes help on your system, type M-x where-is <RET> help-for-help <RET>. This will print a comma-separated list of key sequences in the echo area. Ignore the last character in each key sequence listed. Each of the resulting key sequences invokes help.

Emacs help works best if it is invoked by a single key whose value should be stored in the variable help-char.


Next: , Previous: Basic editing, Up: Getting help

3.2 How do I find out how to do something in Emacs?

There are several methods for finding out how to do things in Emacs.


Next: , Previous: Learning how to do something, Up: Getting help

3.3 How do I get a printed copy of the Emacs manual?

You can order a printed copy of the Emacs manual from the FSF. For details see the GNU Web site.

The full Texinfo source for the manual also comes in the man directory of the Emacs distribution, if you're daring enough to try to print out this 620-page manual yourself (see Printing a Texinfo file).

If you absolutely have to print your own copy, and you don't have TeX, you can get a PostScript version from

http://www.gnu.org/software/emacs/manual/emacs.ps.gz

An HTML version of the manual is at

http://www.gnu.org/software/emacs/manual/emacs.html

The manual is available in other formats at

http://www.gnu.org/software/emacs/manual/

See Learning how to do something, for how to view the manual on-line.


Next: , Previous: Getting a printed manual, Up: Getting help

3.4 Where can I get documentation on Emacs Lisp?

Within Emacs, you can type C-h f to get the documentation for a function, C-h v for a variable.

For more information, the Emacs Lisp Reference Manual is available on-line, in Info format. See Emacs Lisp.

You can also order a hardcopy of the manual, details on ordering it from FSF are on the GNU Web site.

An HTML version of the Emacs Lisp Reference Manual is available at

http://www.gnu.org/software/emacs/elisp-manual/elisp.html


Next: , Previous: Emacs Lisp documentation, Up: Getting help

3.5 How do I install a piece of Texinfo documentation?

First, you must turn the Texinfo files into Info files. You may do this using the stand-alone makeinfo program, available as part of the latest Texinfo package at

ftp://ftp.gnu.org/pub/gnu/texinfo/texinfo-4.8.tar.gz

and all mirrors of `ftp.gnu.org' (for a list, see Current GNU distributions).

For information about the Texinfo format, read the Texinfo manual which comes with the Texinfo package. This manual also comes installed in Info format, so you can read it on-line; type C-h i m texinfo <RET>.

Alternatively, you could use the Emacs command M-x texinfo-format-buffer, after visiting the Texinfo source file of the manual you want to convert.

Neither texinfo-format-buffer nor makeinfo installs the resulting Info files in Emacs's Info tree. To install Info files, perform these steps:

  1. Move the files to the info directory in the installed Emacs distribution. See File-name conventions, if you don't know where that is.
  2. Run the install-info command, which is part of the Texinfo distribution, to update the main Info directory menu, like this:
               install-info --info-dir=dir-path dir-path/file
         

    where dir-path is the full path to the directory where you copied the produced Info file(s), and file is the name of the Info file you produced and want to install.

    If you don't have the install-info command installed, you can edit the file info/dir in the installed Emacs distribution, and add a line for the top level node in the Info package that you are installing. Follow the examples already in this file. The format is:

              * Topic: (relative-pathname).  Short description of topic.
         

If you want to install Info files and you don't have the necessary privileges, you have several options:


Next: , Previous: Installing Texinfo documentation, Up: Getting help

3.6 How do I print a Texinfo file?

You can't get nicely printed output from Info files; you must still have the original Texinfo source file for the manual you want to print.

Assuming you have TeX installed on your system, follow these steps:

  1. Make sure the first line of the Texinfo file looks like this:
              \input texinfo
         

    You may need to change `texinfo' to the full pathname of the texinfo.tex file, which comes with Emacs as man/texinfo.tex (or copy or link it into the current directory).

  2. Type texi2dvi texinfo-source, where texinfo-source is the name of the Texinfo source file for which you want to produce a printed copy.

    The `texi2dvi' script is part of the GNU Texinfo distribution (see Installing Texinfo documentation).

  3. Print the DVI file texinfo-source.dvi in the normal way for printing DVI files at your site. For example, if you have a PostScript printer, run the dvips program to print the DVI file on that printer.

To get more general instructions, retrieve the latest Texinfo package (see Installing Texinfo documentation).


Next: , Previous: Printing a Texinfo file, Up: Getting help

3.7 Can I view Info files without using Emacs?

Yes. Here are some alternative programs:


Next: , Previous: Viewing Info files outside of Emacs, Up: Getting help

3.8 What informational files are available for Emacs?

This isn't a frequently asked question, but it should be! A variety of informational files about Emacs and relevant aspects of the GNU project are available for you to read.

The following files are available in the etc directory of the Emacs distribution (see File-name conventions, if you're not sure where that is).

COPYING
GNU General Public License
DISTRIB
Emacs Availability Information, including the popular Free Software Foundation Order Form
FTP
How to get GNU Software by Internet FTP or by UUCP
GNU
The GNU Manifesto
INTERVIEW
Richard Stallman discusses his public-domain UNIX-compatible software system with BYTE editors
LPF
Why you should join the League for Programming Freedom
MACHINES
Status of Emacs on Various Machines and Systems
MAILINGLISTS
GNU Project Electronic Mailing Lists
NEWS
Emacs news, a history of recent user-visible changes
SERVICE
GNU Service Directory
SUN-SUPPORT
including “Using Emacstool with GNU Emacs”

More GNU information, including back issues of the GNU's Bulletin, are at

http://www.gnu.org/bulletins/bulletins.html and

http://www.cs.pdx.edu/~trent/gnu/gnu.html


Next: , Previous: Informational files for Emacs, Up: Getting help

3.9 Where can I get help in installing Emacs?

See Installing Emacs, for some basic installation hints, and see Problems building Emacs, or Linking with -lX11 fails, if you have problems with the installation.

The file etc/SERVICE (see File-name conventions, if you're not sure where that is) lists companies and individuals willing to sell you help in installing or using Emacs. An up-to-date version this file is available on `ftp.gnu.org' (see Informational files for Emacs).


Previous: Help installing Emacs, Up: Getting help

3.10 Where can I get the latest version of this FAQ?

The Emacs FAQ is available in several ways:


Next: , Previous: Getting help, Up: Top

4 Status of Emacs

This chapter gives you basic information about Emacs, including its latest version status.


Next: , Previous: Status of Emacs, Up: Status of Emacs

4.1 Where does the name “Emacs” come from?

Emacs originally was an acronym for Editor MACroS. RMS says he “picked the name Emacs because <E> was not in use as an abbreviation on ITS at the time.” The first Emacs was a set of macros written in 1976 at MIT by RMS for the editor TECO (Text Editor and COrrector, originally Tape Editor and COrrector) under ITS on a PDP-10. RMS had already extended TECO with a “real-time” full-screen mode with reprogrammable keys. Emacs was started by Guy Steele as a project to unify the many divergent TECO command sets and key bindings at MIT, and completed by RMS.

Many people have said that TECO code looks a lot like line noise; you can read more at news:alt.lang.teco. Someone has written a TECO implementation in Emacs Lisp (to find it, see Packages that do not come with Emacs); it would be an interesting project to run the original TECO Emacs inside of Emacs.

For some not-so-serious alternative reasons for Emacs to have that name, check out the file etc/JOKES (see File-name conventions).


Next: , Previous: Origin of the term Emacs, Up: Status of Emacs

4.2 What is the latest version of Emacs?

Emacs 22.1 is the current version as of this writing.


Next: , Previous: Latest version of Emacs, Up: Status of Emacs

4.3 What is different about Emacs 20?

To find out what has changed in recent versions, type C-h C-n (M-x view-emacs-news). The oldest changes are at the bottom of the file, so you might want to read it starting there, rather than at the top.

The differences between Emacs versions 18 and 19 was rather dramatic; the introduction of frames, faces, and colors on windowing systems was obvious to even the most casual user.

There are differences between Emacs versions 19 and 20 as well, but many are more subtle or harder to find. Among the changes are the inclusion of MULE code for languages that use non-Latin characters and for mixing several languages in the same document; the “Customize” facility for modifying variables without having to use Lisp; and automatic conversion of files from Macintosh, Microsoft, and Unix platforms.

A number of older Lisp packages, such as Gnus, Supercite and the calendar/diary, have been updated and enhanced to work with Emacs 20, and are now included with the standard distribution.


Next: , Previous: New in Emacs 20, Up: Status of Emacs

4.4 What is different about Emacs 21?

Emacs 21 features a thorough rewrite of the display engine. The new display engine supports variable-size fonts, images, and can play sounds on platforms which support that. As a result, the visual appearance of Emacs, when it runs on a windowed display, is much more reminiscent of modern GUI programs, and includes 3D widgets (used for the mode line and the scroll bars), a configurable and extensible toolbar, tooltips (a.k.a. balloon help), and other niceties.

In addition, Emacs 21 supports faces on text-only terminals. This means that you can now have colors when you run Emacs on a GNU/Linux console and on xterm with emacs -nw.


Previous: New in Emacs 21, Up: Status of Emacs

4.5 What is different about Emacs 22?

Many other changes have been made in Emacs 22, use C-h n to get a full list.


Next: , Previous: Status of Emacs, Up: Top

5 Common requests


Next: , Previous: Common requests, Up: Common requests

5.1 How do I set up a .emacs file properly?

see Init File.

In general, new Emacs users should not have .emacs files, because it causes confusing non-standard behavior. Then they send questions to help-gnu-emacs@gnu.org asking why Emacs isn't behaving as documented.

Beginning with version 20.1, Emacs includes the new Customize facility (see Using Customize). This allows users who are unfamiliar with Emacs Lisp to modify their .emacs files in a relatively straightforward way, using menus rather than Lisp code. Most packages support Customize as of this writing.

While Customize might indeed make it easier to configure Emacs, consider taking a bit of time to learn Emacs Lisp and modifying your .emacs directly. Simple configuration options are described rather completely in see Init File, for users interested in performing frequently requested, basic tasks.

Sometimes users are unsure as to where their .emacs file should be found. Visiting the file as ~/.emacs from Emacs will find the correct file.


Next: , Previous: Setting up a customization file, Up: Common requests

5.2 How do I start using Customize?

The main Customize entry point is M-x customize <RET>. This command takes you to a buffer listing all the available Customize groups. From there, you can access all customizable options and faces, change their values, and save your changes to your init file. see Easy Customization.

If you know the name of the group in advance (e.g. “shell”), use M-x customize-group <RET>.

If you wish to customize a single option, use M-x customize-option <RET>. This command prompts you for the name of the option to customize, with completion.


Next: , Previous: Using Customize, Up: Common requests

5.3 How do I get colors and syntax highlighting on a TTY?

In Emacs 21.1 and later, colors and faces are supported in non-windowed mode, i.e. on Unix and GNU/Linux text-only terminals and consoles, and when invoked as `emacs -nw' on X, MS-Windows, and Mac. (Colors and faces were supported in the MS-DOS port since Emacs 19.29.) Emacs automatically detects color support at startup and uses it if available. If you think that your terminal supports colors, but Emacs won't use them, check the termcap entry for your display type for color-related capabilities.

The command M-x list-colors-display pops up a window which exhibits all the colors Emacs knows about on the current display.

Syntax highlighting is on by default since version 22.1.


Next: , Previous: Colors on a TTY, Up: Common requests

5.4 How do I debug a .emacs file?

Start Emacs with the `-debug-init' command-line option. This enables the Emacs Lisp debugger before evaluating your .emacs file, and places you in the debugger if something goes wrong. The top line in the trace-back buffer will be the error message, and the second or third line of that buffer will display the Lisp code from your .emacs file that caused the problem.

You can also evaluate an individual function or argument to a function in your .emacs file by moving the cursor to the end of the function or argument and typing C-x C-e (M-x eval-last-sexp).

Use C-h v (M-x describe-variable) to check the value of variables which you are trying to set or use.


Next: , Previous: Debugging a customization file, Up: Common requests

5.5 How do I make Emacs display the current line (or column) number?

To have Emacs automatically display the current line number of the point in the mode line, do M-x line-number-mode. You can also put the form

     (setq line-number-mode t)

in your .emacs file to achieve this whenever you start Emacs. (Line number display is on by default, unless your site-specific initialization disables it.) Note that Emacs will not display the line number if the buffer's size in bytes is larger than the value of the variable line-number-display-limit.

You can similarly display the current column with M-x column-number-mode, or by putting the form

     (setq column-number-mode t)

in your .emacs file.

The "%c" format specifier in the variable mode-line-format will insert the current column's value into the mode line. See the documentation for mode-line-format (using C-h v mode-line-format <RET>) for more information on how to set and use this variable.

Users of all Emacs versions can display the current column using the `column' package written by Per Abrahamsen. See Packages that do not come with Emacs, for instructions on how to get it.

None of the vi emulation modes provide the “set number” capability of vi (as far as we know). The `setnu' package written by Kyle Jones provides this feature. So too does `wb-line-number', written by Naoki Nakamura.


Next: , Previous: Displaying the current line or column, Up: Common requests

5.6 How can I modify the titlebar to contain the current file name?

The contents of an Emacs frame's titlebar is controlled by the variable frame-title-format, which has the same structure as the variable mode-line-format. (Use C-h v or M-x describe-variable to get information about one or both of these variables.)

By default, the titlebar for a frame does contain the name of the buffer currently being visited, except if there is a single frame. In such a case, the titlebar contains Emacs invocation name and the name of the machine at which Emacs was invoked. This is done by setting frame-title-format to the default value of

     (multiple-frames "%b" ("" invocation-name "@" system-name))

To modify the behavior such that frame titlebars contain the buffer's name regardless of the number of existing frames, include the following in your .emacs:

     (setq frame-title-format "%b")


Next: , Previous: Displaying the current file name in the titlebar, Up: Common requests

5.7 How do I turn on abbrevs by default just in mode mymode?

Put this in your .emacs file:

     (condition-case ()
        (quietly-read-abbrev-file)
       (file-error nil))
     
     (add-hook 'mymode-mode-hook
               (lambda ()
                (setq abbrev-mode t)))

Starting with Emacs 22, the standard abbrevs file is read automatically at startup, so the first of these two forms becomes unnecessary.


Next: , Previous: Turning on abbrevs by default, Up: Common requests

5.8 How do I make Emacs use a certain major mode for certain files?

If you want to use a certain mode foo for all files whose names end with the extension .bar, this will do it for you:

     (setq auto-mode-alist (cons '("\\.bar\\'" . foo-mode) auto-mode-alist))

Otherwise put this somewhere in the first line of any file you want to edit in the mode foo (in the second line, if the first line begins with `#!'):

     -*- foo -*-

Beginning with Emacs 19, the variable interpreter-mode-alist specifies which mode to use when loading a shell script. (Emacs determines which interpreter you're using by examining the first line of the script.) This feature only applies when the file name doesn't indicate which mode to use. Use C-h v (or M-x describe-variable) on interpreter-mode-alist to learn more.


Next: , Previous: Associating modes with files, Up: Common requests

5.9 How can I highlight a region of text in Emacs?

You can cause the region to be highlighted when the mark is active by including

     (transient-mark-mode t)

in your .emacs file.


Next: , Previous: Highlighting a region, Up: Common requests

5.10 How can I replace highlighted text with what I type?

Use delete-selection-mode, which you can start automatically by placing the following Lisp form in your .emacs file:

     (delete-selection-mode 1)

According to the documentation string for delete-selection-mode (which you can read using M-x describe-function <RET> delete-selection-mode <RET>):

When ON, typed text replaces the selection if the selection is active. When OFF, typed text is just inserted at point.

This mode also allows you to delete (not kill) the highlighted region by pressing <DEL>.


Next: , Previous: Replacing highlighted text, Up: Common requests

5.11 How do I control Emacs's case-sensitivity when searching/replacing?

For searching, the value of the variable case-fold-search determines whether they are case sensitive:

     (setq case-fold-search nil) ; make searches case sensitive
     (setq case-fold-search t)   ; make searches case insensitive

Similarly, for replacing, the variable case-replace determines whether replacements preserve case.

You can also toggle case sensitivity at will in isearch with M-c.

To change the case sensitivity just for one major mode, use the major mode's hook. For example:

     (add-hook 'foo-mode-hook
               (lambda ()
                (setq case-fold-search nil)))


Next: , Previous: Controlling case sensitivity, Up: Common requests

5.12 How do I search for, delete, or replace unprintable (eight-bit or control) characters?

To search for a single character that appears in the buffer as, for example, `\237', you can type C-s C-q 2 3 7. (This assumes the value of search-quote-char is 17 (i.e., C-q).) Searching for all unprintable characters is best done with a regular expression (regexp) search. The easiest regexp to use for the unprintable chars is the complement of the regexp for the printable chars.

To type these special characters in an interactive argument to isearch-forward-regexp or re-search-forward, you need to use C-q. (`\t', `\n', `\r', and `\f' stand respectively for <TAB>, <LFD>, <RET>, and C-l.) So, to search for unprintable characters using re-search-forward:

M-x re-search-forward <RET> [^ <TAB> C-q <LFD> C-q <RET> C-q C-l <SPC> -~] <RET>

Using isearch-forward-regexp:

C-M-s [^ <TAB> <LFD> C-q <RET> C-q C-l <SPC> -~]

To delete all unprintable characters, simply use replace-regexp:

M-x replace-regexp <RET> [^ <TAB> C-q <LFD> C-q <RET> C-q C-l <SPC> -~] <RET> <RET>

Replacing is similar to the above. To replace all unprintable characters with a colon, use:

M-x replace-regexp <RET> [^ <TAB> C-q <LFD> C-q <RET> C-q C-l <SPC> -~] <RET> : <RET>


Next: , Previous: Working with unprintable characters, Up: Common requests

5.13 How do I input a newline character in isearch or query-replace?

Use C-q C-j. For more information, see see Special Input for Incremental Search.


Next: , Previous: Searching for/replacing newlines, Up: Common requests

5.14 How do I copy text from the kill ring into the search string?

Use M-y. see Isearch Yanking.


Next: , Previous: Yanking text in isearch, Up: Common requests

5.15 How do I make Emacs wrap words for me?

Use auto-fill-mode, activated by typing M-x auto-fill-mode. The default maximum line width is 70, determined by the variable fill-column. To learn how to turn this on automatically, see Turning on auto-fill by default.


Next: , Previous: Wrapping words automatically, Up: Common requests

5.16 How do I turn on auto-fill-mode by default?

To turn on auto-fill-mode just once for one buffer, use M-x auto-fill-mode.

To turn it on for every buffer in a certain mode, you must use the hook for that mode. For example, to turn on auto-fill mode for all text buffers, including the following in your .emacs file:

     (add-hook 'text-mode-hook 'turn-on-auto-fill)

If you want auto-fill mode on in all major modes, do this:

     (setq-default auto-fill-function 'do-auto-fill)


Next: , Previous: Turning on auto-fill by default, Up: Common requests

5.17 Where can I get a better spelling checker for Emacs?

Use Ispell. See Ispell.


Next: , Previous: Spell-checkers, Up: Common requests

5.18 How can I spell-check TeX or *roff documents?

Use Ispell. Ispell can handle TeX and *roff documents. See Ispell.


Next: , Previous: Checking TeX and *roff documents, Up: Common requests

5.19 How do I change load-path?

In general, you should only add to the load-path. You can add directory /dir/subdir to the load path like this:

     (setq load-path (cons "/dir/subdir/" load-path))

To do this relative to your home directory:

     (setq load-path (cons "~/mysubdir/" load-path))


Next: , Previous: Changing load-path, Up: Common requests

5.20 How do I use an already running Emacs from another window?

emacsclient, which comes with Emacs, is for editing a file using an already running Emacs rather than starting up a new Emacs. It does this by sending a request to the already running Emacs, which must be expecting the request.


Next: , Previous: Using an already running Emacs process, Up: Common requests

5.21 How do I make Emacs recognize my compiler's funny error messages?

Customize the compilation-error-regexp-alist variable.


Next: , Previous: Compiler error messages, Up: Common requests

5.22 How do I change the indentation for switch?

Many people want to indent their switch statements like this:

     f()
     {
       switch(x) {
         case A:
           x1;
           break;
         case B:
           x2;
           break;
         default:
           x3;
       }
     }

The solution at first appears to be: set c-indent-level to 4 and c-label-offset to -2. However, this will give you an indentation spacing of four instead of two.

The real solution is to use cc-mode (the default mode for C programming in Emacs 20 and later) and add the following line to your .emacs:

     (c-set-offset 'case-label '+)

There appears to be no way to do this with the old c-mode.


Next: , Previous: Indenting switch statements, Up: Common requests

5.23 How to customize indentation in C, C++, and Java buffers?

The Emacs cc-mode features an interactive procedure for customizing the indentation style, which is fully explained in the CC Mode manual that is part of the Emacs distribution, see Customization Indentation. Here's a short summary of the procedure:

  1. Go to the beginning of the first line where you don't like the indentation and type C-c C-o. Emacs will prompt you for the syntactic symbol; type <RET> to accept the default it suggests.
  2. Emacs now prompts for the offset of this syntactic symbol, showing the default (the current definition) inside parentheses. You can choose one of these:
    0
    No extra indentation.
    +
    Indent one basic offset.
    -
    Outdent one basic offset.
    ++
    Indent two basic offsets
    --
    Outdent two basic offsets.
    *
    Indent half basic offset.
    /
    Outdent half basic offset.
  3. After choosing one of these symbols, type C-c C-q to reindent the line or the block according to what you just specified.
  4. If you don't like the result, go back to step 1. Otherwise, add the following line to your .emacs:
              (c-set-offset 'syntactic-symbol offset)
         

    where syntactic-symbol is the name Emacs shows in the minibuffer when you type C-c C-o at the beginning of the line, and offset is one of the indentation symbols listed above (+, /, 0, etc.) that you've chosen during the interactive procedure.

  5. Go to the next line whose indentation is not to your liking and repeat the process there.

It is recommended to put all the resulting (c-set-offset ...) customizations inside a C mode hook, like this:

     (defun my-c-mode-hook ()
       (c-set-offset ...)
       (c-set-offset ...))
     (add-hook 'c-mode-hook 'my-c-mode-hook)

Using c-mode-hook avoids the need to put a (require 'cc-mode) into your .emacs file, because c-set-offset might be unavailable when cc-mode is not loaded.

Note that c-mode-hook runs for C source files only; use c++-mode-hook for C++ sources, java-mode-hook for Java sources, etc. If you want the same customizations to be in effect in all languages supported by cc-mode, use c-mode-common-hook.


Next: , Previous: Customizing C and C++ indentation, Up: Common requests

5.24 How can I make Emacs automatically scroll horizontally?

In Emacs 21 and later, this is on by default: if the variable truncate-lines is non-nil in the current buffer, Emacs automatically scrolls the display horizontally when point moves off the left or right edge of the window.

Note that this is overridden by the variable truncate-partial-width-windows if that variable is non-nil and the current buffer is not full-frame width.

In Emacs 20, use the hscroll-mode. Here is some information from the documentation, available by typing C-h f hscroll-mode <RET>:

Automatically scroll horizontally when the point moves off the left or right edge of the window.


Next: , Previous: Horizontal scrolling, Up: Common requests

5.25 How do I make Emacs “typeover” or “overwrite” instead of inserting?

M-x overwrite-mode (a minor mode). This toggles overwrite-mode on and off, so exiting from overwrite-mode is as easy as another M-x overwrite-mode.

On some systems, <Insert> toggles overwrite-mode on and off.


Next: , Previous: Overwrite mode, Up: Common requests

5.26 How do I stop Emacs from beeping on a terminal?

Martin R. Frank writes:

Tell Emacs to use the visible bell instead of the audible bell, and set the visible bell to nothing.

That is, put the following in your TERMCAP environment variable (assuming you have one):

     ... :vb=: ...

And evaluate the following Lisp form:

     (setq visible-bell t)


Next: , Previous: Turning off beeping, Up: Common requests

5.27 How do I turn down the bell volume in Emacs running under X?

On X Window system, you can adjust the bell volume and duration for all programs with the shell command xset.

Invoking xset without any arguments produces some basic information, including the following:

     usage:  xset [-display host:dpy] option ...
       To turn bell off:
           -b                b off               b 0
       To set bell volume, pitch and duration:
            b [vol [pitch [dur]]]          b on


Next: , Previous: Turning the volume down, Up: Common requests

5.28 How do I tell Emacs to automatically indent a new line to the indentation of the previous line?

Such behavior is automatic in Emacs 20 and later. From the etc/NEWS file for Emacs 20.2:

     ** In Text mode, now only blank lines separate paragraphs.  This makes
     it possible to get the full benefit of Adaptive Fill mode in Text mode,
     and other modes derived from it (such as Mail mode).  <TAB> in Text
     mode now runs the command indent-relative; this makes a practical
     difference only when you use indented paragraphs.
     
     As a result, the old Indented Text mode is now identical to Text mode,
     and is an alias for it.
     
     If you want spaces at the beginning of a line to start a paragraph, use
     the new mode, Paragraph Indent Text mode.

If you have auto-fill-mode turned on (see Turning on auto-fill by default), you can tell Emacs to prefix every line with a certain character sequence, the fill prefix. Type the prefix at the beginning of a line, position point after it, and then type C-x . (set-fill-prefix) to set the fill prefix. Thereafter, auto-filling will automatically put the fill prefix at the beginning of new lines, and M-q (fill-paragraph) will maintain any fill prefix when refilling the paragraph.

If you have paragraphs with different levels of indentation, you will have to set the fill prefix to the correct value each time you move to a new paragraph. There are many packages available to deal with this (see Packages that do not come with Emacs). Look for “fill” and “indent” keywords for guidance.


Next: , Previous: Automatic indentation, Up: Common requests

5.29 How do I show which parenthesis matches the one I'm looking at?

Call show-paren-mode in your .emacs file:

     (show-paren-mode 1)

You can also enable this mode by selecting the `Paren Match Highlighting' option from the `Options' menu of the Emacs menu bar at the top of any Emacs frame.

Alternatives to this mode include:


Next: , Previous: Matching parentheses, Up: Common requests

5.30 In C mode, can I show just the lines that will be left after #ifdef commands are handled by the compiler?

M-x hide-ifdef-mode. (This is a minor mode.) You might also want to investigate cpp.el, which is distributed with Emacs.


Next: , Previous: Hiding #ifdef lines, Up: Common requests

5.31 How do I repeat a command as many times as possible?

As of Emacs 20.3, there is indeed a repeat command (C-x z) that repeats the last command. If you preface it with a prefix argument, the prefix arg is applied to the command.

You can also type C-x <ESC> <ESC> (repeat-complex-command) to reinvoke commands that used the minibuffer to get arguments. In repeat-complex-command you can type M-p and M-n (and also up-arrow and down-arrow, if your keyboard has these keys) to scan through all the different complex commands you've typed.

To repeat a set of commands, use keyboard macros. Use C-x ( and C-x ) to make a keyboard macro that invokes the command and then type C-x e. (see Keyboard Macros.)

If you're really desperate for the . command in vi that redoes the last insertion/deletion, use VIPER, a vi emulation mode which comes with Emacs, and which appears to support it. (See VIPER.)


Next: , Previous: Repeating commands, Up: Common requests

5.32 What are the valid X resource settings (i.e., stuff in .Xdefaults)?

see X Resources.

You can also use a resource editor, such as editres (for X11R5 and onwards), to look at the resource names for the menu bar, assuming Emacs was compiled with the X toolkit.


Next: , Previous: Valid X resources, Up: Common requests

5.33 How do I execute (“evaluate”) a piece of Emacs Lisp code?

There are a number of ways to execute (evaluate, in Lisp lingo) an Emacs Lisp form:


Next: , Previous: Evaluating Emacs Lisp code, Up: Common requests

5.34 How do I change Emacs's idea of the <TAB> character's length?

Set the variable default-tab-width. For example, to set <TAB> stops every 10 characters, insert the following in your .emacs file:

     (setq default-tab-width 10)

Do not confuse variable tab-width with variable tab-stop-list. The former is used for the display of literal <TAB> characters. The latter controls what characters are inserted when you press the <TAB> character in certain modes.


Next: , Previous: Changing the length of a Tab, Up: Common requests

5.35 How do I insert <some text> at the beginning of every line?

To do this to an entire buffer, type M-< M-x replace-regexp <RET> ^ <RET> your text <RET>.

To do this to a region, use string-insert-rectangle. Set the mark (C-<SPC>) at the beginning of the first line you want to prefix, move the cursor to last line to be prefixed, and type M-x string-insert-rectangle <RET>. To do this for the whole buffer, type C-x h M-x string-insert-rectangle <RET>.

If you are trying to prefix a yanked mail message with `>', you might want to set the variable mail-yank-prefix. In Message buffers, you can even use M-; to cite yanked messages (M-; runs the function comment-region, it is a general-purpose mechanism to comment regions) (see Changing the included text prefix).


Next: , Previous: Inserting text at the beginning of each line, Up: Common requests

5.36 How do I insert `_^H' before each character in a region to get an underlined paragraph?

Mark the region and then type M-x underline-region <RET>.


Next: , Previous: Underlining paragraphs, Up: Common requests

5.37 How do I make Emacs behave like this: when I go up or down, the cursor should stay in the same column even if the line is too short?

Use M-x picture-mode.

See also the variable track-eol and the command set-goal-column bound to C-x C-n (see Moving Point).


Next: , Previous: Forcing the cursor to remain in the same column, Up: Common requests

5.38 How do I tell Emacs to iconify itself?

C-z iconifies Emacs when running under X and suspends Emacs otherwise. see Frame Commands.


Next: , Previous: Forcing Emacs to iconify itself, Up: Common requests

5.39 How do I use regexps (regular expressions) in Emacs?

see Regexp Backslash.

The or operator is `\|', not `|', and the grouping operators are `\(' and `\)'. Also, the string syntax for a backslash is `\\'. To specify a regular expression like `xxx\(foo\|bar\)' in a Lisp string, use `xxx\\(foo\\|bar\\)'.

Note the doubled backslashes!


Next: , Previous: Using regular expressions, Up: Common requests

5.40 How do I perform a replace operation across more than one file?