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.
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.
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.)
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.
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.
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.
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.
This chapter contains general questions having to do with Emacs, the Free Software Foundation, and related organizations.
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.
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.
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).
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.
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.
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.
For details on how to order items directly from the FSF, see the GNU Web site.
This chapter tells you how to get help with Emacs
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.
There are several methods for finding out how to do things in Emacs.
Info-goto-emacs-command-node) prompts
for the name of a command, and then attempts to find the section in the
Emacs manual where that command is described.
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.
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
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:
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:
info command and specify
the name of the Info file in the minibuffer. This goes to the node
named `Top' in that file. For example, to view a Info file named
info-file in your home directory, you can type this:
C-u C-h i ~/info-file <RET>
Alternatively, you can feed a file name to the Info-goto-node
command (invoked by pressing <g> in Info mode) by typing the name
of the file in parentheses, like this:
C-h i g (~/info-file) <RET>
Info-default-directory-list. For example, to use a private Info
directory which is a subdirectory of your home directory named Info,
you could put this in your .emacs file:
(setq Info-default-directory-list
(cons "~/Info" Info-default-directory-list))
You will need a top-level Info file named dir in this directory
which has everything the system dir file has in it, except it should
list only entries for Info files in that directory. You might not need
it if all files in this directory were referenced by other dir
files. The node lists from all dir files in
Info-default-directory-list are merged by the Info system.
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:
\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).
The `texi2dvi' script is part of the GNU Texinfo distribution (see Installing Texinfo documentation).
dvips program to print the DVI file on that
printer.
To get more general instructions, retrieve the latest Texinfo package (see Installing Texinfo documentation).
Yes. Here are some alternative programs:
info, a stand-alone version of the Info program, comes as part of
the Texinfo package. See Installing Texinfo documentation, for
details.
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).
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
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).
The Emacs FAQ is available in several ways:
?GNU Emacs Frequently Asked Questions?rc:m
In Gnus, you should type C-u C-x C-s from the *Summary* buffer or C-u <SPC> from the *Newsgroup* buffer to view all articles in a newsgroup.
If the FAQ articles have expired and have been deleted from your news spool, it might (or might not) do some good to complain to your news administrator, because the most recent FAQ should not expire for a while.
ftp://rtfm.mit.edu/pub/usenet/comp.emacs/ and
ftp://ftp.uni-paderborn.de/pub/doc/FAQ/comp/emacs/
If you do not have access to anonymous FTP, you can access the archives using the rtfm.mit.edu mail server. The Emacs FAQ can be retrieved by sending mail to mail-server@rtfm.mit.edu with a blank subject and containing
send usenet/news.answers/GNU-Emacs-FAQ/diffs
send usenet/news.answers/GNU-Emacs-FAQ/part1
send usenet/news.answers/GNU-Emacs-FAQ/part2
send usenet/news.answers/GNU-Emacs-FAQ/part3
send usenet/news.answers/GNU-Emacs-FAQ/part4
send usenet/news.answers/GNU-Emacs-FAQ/part5
For more information, send email to mail-server@rtfm.mit.edu with `help' and `index' in the body on separate lines.
This chapter gives you basic information about Emacs, including its latest version status.
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).
Emacs 22.1 is the current version as of this writing.
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.
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.
The following language environments have also been added: Belarusian, Bulgarian, Chinese-EUC-TW, Croatian, French, Georgian, Italian, Latin-6, Latin-7, Latvian, Lithuanian, Malayalam, Russian, Slovenian, Swedish, Tajik, Tamil, UTF-8, Ukrainian, Welsh, and Windows-1255.
Many other changes have been made in Emacs 22, use C-h n to get a full list.
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.
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.
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.
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.
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.
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")
(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.
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.
You can cause the region to be highlighted when the mark is active by including
(transient-mark-mode t)
in your .emacs file.
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>.
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)))
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>
Use C-q C-j. For more information, see see Special Input for Incremental Search.
Use M-y. see Isearch Yanking.
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.
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)
Use Ispell. See Ispell.
Use Ispell. Ispell can handle TeX and *roff documents. See Ispell.
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))
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.
Emacs must have executed the server-start function for
`emacsclient' to work. This can be done either by a command line
option:
emacs -f server-start
or by invoking server-start from .emacs:
(if (some conditions are met) (server-start))
When this is done, Emacs creates a Unix domain socket named
server in /tmp/emacsuserid. See
server-socket-dir.
To get your news reader, mail reader, etc., to invoke
`emacsclient', try setting the environment variable EDITOR
(or sometimes VISUAL) to the value `emacsclient'. You may
have to specify the full pathname of the `emacsclient' program
instead. Examples:
# csh commands:
setenv EDITOR emacsclient
# using full pathname
setenv EDITOR /usr/local/emacs/etc/emacsclient
# sh command:
EDITOR=emacsclient ; export EDITOR
When `emacsclient' is run, it connects to the socket and passes its
command line options to Emacs, which at the next opportunity will visit
the files specified. (Line numbers can be specified just like with
Emacs.) The user will have to switch to the Emacs window by hand. When
the user is done editing a file, the user can type C-x # (or
M-x server-edit) to indicate this. If there is another buffer
requested by emacsclient, Emacs will switch to it; otherwise
emacsclient will exit, signaling the calling program to continue.
There is an enhanced version of `emacsclient' called `gnuserv', written by Andy Norman (see Packages that do not come with Emacs). `gnuserv' uses Internet domain sockets, so it can work across most network connections.
The most recent `gnuserv' package is available at
Customize the compilation-error-regexp-alist variable.
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.
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:
0+-++--*/ (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.
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.
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.
turn-on-hscroll is useful in mode hooks as in:
(add-hook 'text-mode-hook 'turn-on-hscroll)
hscroll-margin controls how close the cursor can get to the
edge of the window.
hscroll-step-percent controls how far to jump once we decide to do so.
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.
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)
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
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.
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:
forward-sexp) and C-M-b (backward-sexp)
will skip over one set of balanced parentheses, so you can see which
parentheses match. (You can train it to skip over balanced brackets
and braces at the same time by modifying the syntax table.)
vi. In addition, if the cursor isn't over a
parenthesis, it simply inserts a % like normal.
;; By an unknown contributor
(global-set-key "%" 'match-paren)
(defun match-paren (arg)
"Go to the matching paren if on a paren; otherwise insert %."
(interactive "p")
(cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
((looking-at "\\s\)") (forward-char 1) (backward-list 1))
(t (self-insert-command (or arg 1)))))
#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.
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.)
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.
There are a number of ways to execute (evaluate, in Lisp lingo) an Emacs Lisp form:
emacs-lisp-mode, typing C-M-x evaluates a top-level form
before or around point.
load
instead.)
The functions load-library, eval-region,
eval-buffer, require, and autoload are also
useful; see Emacs Lisp documentation, if you want to learn more
about them.
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.
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).
Mark the region and then type M-x underline-region <RET>.
See also the variable track-eol and the command
set-goal-column bound to C-x C-n
(see Moving Point).
C-z iconifies Emacs when running under X and suspends Emacs otherwise. see Frame Commands.
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!