This is the thirteenth edition of the `GNU Emacs Manual', updated for
Emacs version 20.7.
Published by the Free Software Foundation 59 Temple Place, Suite 330
Boston, MA 02111-1307 USA
Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998,
1999 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided also
that the sections entitled "The GNU Manifesto", "Distribution" and "GNU
General Public License" are included exactly as in the original, and
provided that the entire resulting derived work is distributed under the
terms of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions, except that the sections entitled "The GNU Manifesto",
"Distribution" and "GNU General Public License" may be included in a
translation approved by the Free Software Foundation instead of in the
original English.
The Emacs Editor
****************
Emacs is the extensible, customizable, self-documenting real-time
display editor. This Info file describes how to edit with Emacs and
some of how to customize it; it corresponds to GNU Emacs version 20.7.
For information on extending Emacs, see *Note Emacs Lisp: (elisp).
Distribution
************
GNU Emacs is "free software"; this means that everyone is free to
use it and free to redistribute it on certain conditions. GNU Emacs is
not in the public domain; it is copyrighted and there are restrictions
on its distribution, but these restrictions are designed to permit
everything that a good cooperating citizen would want to do. What is
not allowed is to try to prevent others from further sharing any version
of GNU Emacs that they might get from you. The precise conditions are
found in the GNU General Public License that comes with Emacs and also
appears following this section.
One way to get a copy of GNU Emacs is from someone else who has it.
You need not ask for our permission to do so, or tell any one else; just
copy it. If you have access to the Internet, you can get the latest
distribution version of GNU Emacs by anonymous FTP; see the file
`etc/FTP' in the Emacs distribution for more information.
You may also receive GNU Emacs when you buy a computer. Computer
manufacturers are free to distribute copies on the same terms that
apply to everyone else. These terms require them to give you the full
sources, including whatever changes they may have made, and to permit
you to redistribute the GNU Emacs received from them under the usual
terms of the General Public License. In other words, the program must
be free for you when you get it, not just free for the manufacturer.
You can also order copies of GNU Emacs from the Free Software
Foundation on CD-ROM. This is a convenient and reliable way to get a
copy; it is also a good way to help fund our work. (The Foundation has
always received most of its funds in this way.) An order form is
included in the file `etc/ORDERS' in the Emacs distribution, and on our
web site in `http://www.gnu.org/order/order.html'. For further
information, write to
Free Software Foundation
59 Temple Place, Suite 330
Boston, MA 02111-1307 USA
USA
The income from distribution fees goes to support the foundation's
purpose: the development of new free software, and improvements to our
existing programs including GNU Emacs.
If you find GNU Emacs useful, please *send a donation* to the Free
Software Foundation to support our work. Donations to the Free
Software Foundation are tax deductible in the US. If you use GNU Emacs
at your workplace, please suggest that the company make a donation. If
company policy is unsympathetic to the idea of donating to charity, you
might instead suggest ordering a CD-ROM from the Foundation
occasionally, or subscribing to periodic updates.
GNU GENERAL PUBLIC LICENSE
**************************
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
========
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it in
new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software,
and (2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains a
notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program",
below, refers to any such program or work, and a "work based on
the Program" means either the Program or any derivative work under
copyright law: that is to say, a work containing the Program or a
portion of it, either verbatim or with modifications and/or
translated into another language. (Hereinafter, translation is
included without limitation in the term "modification".) Each
licensee is addressed as "you".
Activities other than copying, distribution and modification are
not covered by this License; they are outside its scope. The act
of running the Program is not restricted, and the output from the
Program is covered only if its contents constitute a work based on
the Program (independent of having been made by running the
Program). Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any
warranty; and give any other recipients of the Program a copy of
this License along with the Program.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange
for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a. You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b. You must cause any work that you distribute or publish, that
in whole or in part contains or is derived from the Program
or any part thereof, to be licensed as a whole at no charge
to all third parties under the terms of this License.
c. If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display
an announcement including an appropriate copyright notice and
a notice that there is no warranty (or else, saying that you
provide a warranty) and that users may redistribute the
program under these conditions, and telling the user how to
view a copy of this License. (Exception: if the Program
itself is interactive but does not normally print such an
announcement, your work based on the Program is not required
to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the
Program, and can be reasonably considered independent and separate
works in themselves, then this License, and its terms, do not
apply to those sections when you distribute them as separate
works. But when you distribute the same sections as part of a
whole which is a work based on the Program, the distribution of
the whole must be on the terms of this License, whose permissions
for other licensees extend to the entire whole, and thus to each
and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or
contest your rights to work written entirely by you; rather, the
intent is to exercise the right to control the distribution of
derivative or collective works based on the Program.
In addition, mere aggregation of another work not based on the
Program with the Program (or with a work based on the Program) on
a volume of a storage or distribution medium does not bring the
other work under the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms
of Sections 1 and 2 above provided that you also do one of the
following:
a. Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of
Sections 1 and 2 above on a medium customarily used for
software interchange; or,
b. Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange; or,
c. Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with
such an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete
source code means all the source code for all modules it contains,
plus any associated interface definition files, plus the scripts
used to control compilation and installation of the executable.
However, as a special exception, the source code distributed need
not include anything that is normally distributed (in either
source or binary form) with the major components (compiler,
kernel, and so on) of the operating system on which the executable
runs, unless that component itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this
License. However, parties who have received copies, or rights,
from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify
or distribute the Program or its derivative works. These actions
are prohibited by law if you do not accept this License.
Therefore, by modifying or distributing the Program (or any work
based on the Program), you indicate your acceptance of this
License to do so, and all its terms and conditions for copying,
distributing or modifying the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program
subject to these terms and conditions. You may not impose any
further restrictions on the recipients' exercise of the rights
granted herein. You are not responsible for enforcing compliance
by third parties to this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent
issues), conditions are imposed on you (whether by court order,
agreement or otherwise) that contradict the conditions of this
License, they do not excuse you from the conditions of this
License. If you cannot distribute so as to satisfy simultaneously
your obligations under this License and any other pertinent
obligations, then as a consequence you may not distribute the
Program at all. For example, if a patent license would not permit
royalty-free redistribution of the Program by all those who
receive copies directly or indirectly through you, then the only
way you could satisfy both it and this License would be to refrain
entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable
under any particular circumstance, the balance of the section is
intended to apply and the section as a whole is intended to apply
in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of
any such claims; this section has the sole purpose of protecting
the integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is
willing to distribute software through any other system and a
licensee cannot impose that choice.
This section is intended to make thoroughly clear what is believed
to be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces,
the original copyright holder who places the Program under this
License may add an explicit geographical distribution limitation
excluding those countries, so that distribution is permitted only
in or among countries not thus excluded. In such case, this
License incorporates the limitation as if written in the body of
this License.
9. The Free Software Foundation may publish revised and/or new
versions of the General Public License from time to time. Such
new versions will be similar in spirit to the present version, but
may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies a version number of this License which applies
to it and "any later version", you have the option of following
the terms and conditions either of that version or of any later
version published by the Free Software Foundation. If the Program
does not specify a version number of this License, you may choose
any version ever published by the Free Software Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the
author to ask for permission. For software which is copyrighted
by the Free Software Foundation, write to the Free Software
Foundation; we sometimes make exceptions for this. Our decision
will be guided by the two goals of preserving the free status of
all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE
LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE
QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
SERVICING, REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY
MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU
OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY
OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
=============================================
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these
terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
ONE LINE TO GIVE THE PROGRAM'S NAME AND AN IDEA OF WHAT IT DOES.
Copyright (C) 19YY NAME OF AUTHOR
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
Also add information on how to contact you by electronic and paper
mail.
If the program is interactive, make it output a short notice like
this when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19YY NAME OF AUTHOR
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
type `show w'. This is free software, and you are welcome
to redistribute it under certain conditions; type `show c'
for details.
The hypothetical commands `show w' and `show c' should show the
appropriate parts of the General Public License. Of course, the
commands you use may be called something other than `show w' and `show
c'; they could even be mouse-clicks or menu items--whatever suits your
program.
You should also get your employer (if you work as a programmer) or
your school, if any, to sign a "copyright disclaimer" for the program,
if necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright
interest in the program `Gnomovision'
(which makes passes at compilers) written
by James Hacker.
SIGNATURE OF TY COON, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your
program into proprietary programs. If your program is a subroutine
library, you may consider it more useful to permit linking proprietary
applications with the library. If this is what you want to do, use the
GNU Library General Public License instead of this License.
Introduction
************
You are reading about GNU Emacs, the GNU incarnation of the advanced,
self-documenting, customizable, extensible real-time display editor
Emacs. (The `G' in `GNU' is not silent.)
We say that Emacs is a "display" editor because normally the text
being edited is visible on the screen and is updated automatically as
you type your commands. *Note Display: Screen.
We call it a "real-time" editor because the display is updated very
frequently, usually after each character or pair of characters you
type. This minimizes the amount of information you must keep in your
head as you edit. *Note Real-time: Basic.
We call Emacs advanced because it provides facilities that go beyond
simple insertion and deletion: controlling subprocesses; automatic
indentation of programs; viewing two or more files at once; editing
formatted text; and dealing in terms of characters, words, lines,
sentences, paragraphs, and pages, as well as expressions and comments in
several different programming languages.
"Self-documenting" means that at any time you can type a special
character, `Control-h', to find out what your options are. You can
also use it to find out what any command does, or to find all the
commands that pertain to a topic. *Note Help::.
"Customizable" means that you can change the definitions of Emacs
commands in little ways. For example, if you use a programming
language in which comments start with `', you can
tell the Emacs comment manipulation commands to use those strings
(*note Comments::.). Another sort of customization is rearrangement of
the command set. For example, if you prefer the four basic cursor
motion commands (up, down, left and right) on keys in a diamond pattern
on the keyboard, you can rebind the keys that way. *Note
Customization::.
"Extensible" means that you can go beyond simple customization and
write entirely new commands, programs in the Lisp language to be run by
Emacs's own Lisp interpreter. Emacs is an "on-line extensible" system,
which means that it is divided into many functions that call each
other, any of which can be redefined in the middle of an editing
session. Almost any part of Emacs can be replaced without making a
separate copy of all of Emacs. Most of the editing commands of Emacs
are written in Lisp already; the few exceptions could have been written
in Lisp but are written in C for efficiency. Although only a programmer
can write an extension, anybody can use it afterward. If you want to
learn Emacs Lisp programming, we recommend the `Introduction to Emacs
Lisp' by Robert J. Chassell, also published by the Free Software
Foundation.
When run under the X Window System, Emacs provides its own menus and
convenient bindings to mouse buttons. But Emacs can provide many of the
benefits of a window system on a text-only terminal. For instance, you
can look at or edit several files at once, move text between files, and
edit files while running shell commands.
The Organization of the Screen
******************************
On a text-only terminal, the Emacs display occupies the whole screen.
On the X Window System, Emacs creates its own X windows to use. We use
the term "frame" to mean an entire text-only screen or an entire X
window used by Emacs. Emacs uses both kinds of frames in the same way
to display your editing. Emacs normally starts out with just one frame,
but you can create additional frames if you wish. *Note Frames::.
When you start Emacs, the entire frame except for the first and last
lines is devoted to the text you are editing. This area is called the
"window". The first line is a "menu bar", and the last line is a
special "echo area" or "minibuffer window" where prompts appear and
where you can enter responses. See below for more information about
these special lines.
You can subdivide the large text window horizontally or vertically
into multiple text windows, each of which can be used for a different
file (*note Windows::.). In this manual, the word "window" always
refers to the subdivisions of a frame within Emacs.
The window that the cursor is in is the "selected window", in which
editing takes place. Most Emacs commands implicitly apply to the text
in the selected window (though mouse commands generally operate on
whatever window you click them in, whether selected or not). The other
windows display text for reference only, unless/until you select them.
If you use multiple frames under the X Window System, then giving the
input focus to a particular frame selects a window in that frame.
Each window's last line is a "mode line", which describes what is
going on in that window. It appears in inverse video, if the terminal
supports that, and its contents begin with `--:-- *scratch*' when
Emacs starts. The mode line displays status information such as what
buffer is being displayed above it in the window, what major and minor
modes are in use, and whether the buffer contains unsaved changes.
Point
=====
Within Emacs, the terminal's cursor shows the location at which
editing commands will take effect. This location is called "point".
Many Emacs commands move point through the text, so that you can edit at
different places in it. You can also place point by clicking mouse
button 1.
While the cursor appears to point *at* a character, you should think
of point as *between* two characters; it points *before* the character
that appears under the cursor. For example, if your text looks like
`frob' with the cursor over the `b', then point is between the `o' and
the `b'. If you insert the character `!' at that position, the result
is `fro!b', with point between the `!' and the `b'. Thus, the cursor
remains over the `b', as before.
Sometimes people speak of "the cursor" when they mean "point," or
speak of commands that move point as "cursor motion" commands.
Terminals have only one cursor, and when output is in progress it
must appear where the typing is being done. This does not mean that
point is moving. It is only that Emacs has no way to show you the
location of point except when the terminal is idle.
If you are editing several files in Emacs, each in its own buffer,
each buffer has its own point location. A buffer that is not currently
displayed remembers where point is in case you display it again later.
When there are multiple windows in a frame, each window has its own
point location. The cursor shows the location of point in the selected
window. This also is how you can tell which window is selected. If the
same buffer appears in more than one window, each window has its own
position for point in that buffer.
When there are multiple frames, each frame can display one cursor.
The cursor in the selected frame is solid; the cursor in other frames is
a hollow box, and appears in the window that would be selected if you
give the input focus to that frame.
The term `point' comes from the character `.', which was the command
in TECO (the language in which the original Emacs was written) for
accessing the value now called `point'.
The Echo Area
=============
The line at the bottom of the frame (below the mode line) is the
"echo area". It is used to display small amounts of text for several
purposes.
"Echoing" means displaying the characters that you type. Outside
Emacs, the operating system normally echoes all your input. Emacs
handles echoing differently.
Single-character commands do not echo in Emacs, and multi-character
commands echo only if you pause while typing them. As soon as you pause
for more than a second in the middle of a command, Emacs echoes all the
characters of the command so far. This is to "prompt" you for the rest
of the command. Once echoing has started, the rest of the command
echoes immediately as you type it. This behavior is designed to give
confident users fast response, while giving hesitant users maximum
feedback. You can change this behavior by setting a variable (*note
Display Vars::.).
If a command cannot be executed, it may print an "error message" in
the echo area. Error messages are accompanied by a beep or by flashing
the screen. Also, any input you have typed ahead is thrown away when
an error happens.
Some commands print informative messages in the echo area. These
messages look much like error messages, but they are not announced with
a beep and do not throw away input. Sometimes the message tells you
what the command has done, when this is not obvious from looking at the
text being edited. Sometimes the sole purpose of a command is to print
a message giving you specific information--for example, `C-x =' prints
a message describing the character position of point in the text and
its current column in the window. Commands that take a long time often
display messages ending in `...' while they are working, and add `done'
at the end when they are finished.
Echo-area informative messages are saved in an editor buffer named
`*Messages*'. (We have not explained buffers yet; see *Note Buffers::,
for more information about them.) If you miss a message that appears
briefly on the screen, you can switch to the `*Messages*' buffer to see
it again. (Successive progress messages are often collapsed into one
in that buffer.)
The size of `*Messages*' is limited to a certain number of lines.
The variable `message-log-max' specifies how many lines. Once the
buffer has that many lines, each line added at the end deletes one line
from the beginning. *Note Variables::, for how to set variables such as
`message-log-max'.
The echo area is also used to display the "minibuffer", a window that
is used for reading arguments to commands, such as the name of a file
to be edited. When the minibuffer is in use, the echo area begins with
a prompt string that usually ends with a colon; also, the cursor
appears in that line because it is the selected window. You can always
get out of the minibuffer by typing `C-g'. *Note Minibuffer::.
The Mode Line
=============
Each text window's last line is a "mode line", which describes what
is going on in that window. When there is only one text window, the
mode line appears right above the echo area; it is the next-to-last line
on the frame. The mode line is in inverse video if the terminal
supports that, and it starts and ends with dashes.
Normally, the mode line looks like this:
-CS:CH BUF (MAJOR MINOR)--LINE--POS------
This gives information about the buffer being displayed in the window:
the buffer's name, what major and minor modes are in use, whether the
buffer's text has been changed, and how far down the buffer you are
currently looking.
CH contains two stars `**' if the text in the buffer has been edited
(the buffer is "modified"), or `--' if the buffer has not been edited.
For a read-only buffer, it is `%*' if the buffer is modified, and `%%'
otherwise.
BUF is the name of the window's "buffer". In most cases this is the
same as the name of a file you are editing. *Note Buffers::.
The buffer displayed in the selected window (the window that the
cursor is in) is also Emacs's selected buffer, the one that editing
takes place in. When we speak of what some command does to "the
buffer," we are talking about the currently selected buffer.
LINE is `L' followed by the current line number of point. This is
present when Line Number mode is enabled (which it normally is). You
can optionally display the current column number too, by turning on
Column Number mode (which is not enabled by default because it is
somewhat slower). *Note Optional Mode Line::.
POS tells you whether there is additional text above the top of the
window, or below the bottom. If your buffer is small and it is all
visible in the window, POS is `All'. Otherwise, it is `Top' if you are
looking at the beginning of the buffer, `Bot' if you are looking at the
end of the buffer, or `NN%', where NN is the percentage of the buffer
above the top of the window.
MAJOR is the name of the "major mode" in effect in the buffer. At
any time, each buffer is in one and only one of the possible major
modes. The major modes available include Fundamental mode (the least
specialized), Text mode, Lisp mode, C mode, Texinfo mode, and many
others. *Note Major Modes::, for details of how the modes differ and
how to select one.
Some major modes display additional information after the major mode
name. For example, Rmail buffers display the current message number and
the total number of messages. Compilation buffers and Shell buffers
display the status of the subprocess.
MINOR is a list of some of the "minor modes" that are turned on at
the moment in the window's chosen buffer. For example, `Fill' means
that Auto Fill mode is on. `Abbrev' means that Word Abbrev mode is on.
`Ovwrt' means that Overwrite mode is on. *Note Minor Modes::, for
more information. `Narrow' means that the buffer being displayed has
editing restricted to only a portion of its text. This is not really a
minor mode, but is like one. *Note Narrowing::. `Def' means that a
keyboard macro is being defined. *Note Keyboard Macros::.
In addition, if Emacs is currently inside a recursive editing level,
square brackets (`[...]') appear around the parentheses that surround
the modes. If Emacs is in one recursive editing level within another,
double square brackets appear, and so on. Since recursive editing
levels affect Emacs globally, not just one buffer, the square brackets
appear in every window's mode line or not in any of them. *Note
Recursive Edit::.
Non-windowing terminals can only show a single Emacs frame at a time
(*note Frames::.). On such terminals, the mode line displays the name
of the selected frame, after CH. The initial frame's name is `F1'.
CS states the coding system used for the file you are editing. A
dash indicates the default state of affairs: no code conversion, except
for end-of-line translation if the file contents call for that. `='
means no conversion whatsoever. Nontrivial code conversions are
represented by various letters--for example, `1' refers to ISO Latin-1.
*Note Coding Systems::, for more information. If you are using an
input method, a string of the form `I>' is added to the beginning of
CS; I identifies the input method. (Some input methods show `+' or `@'
instead of `>'.) *Note Input Methods::.
When you are using a character-only terminal (not a window system),
CS uses three characters to describe, respectively, the coding system
for keyboard input, the coding system for terminal output, and the
coding system used for the file you are editing.
When multibyte characters are not enabled, CS does not appear at
all. *Note Enabling Multibyte::.
The colon after CS can change to another string in certain
circumstances. Emacs uses newline to separate lines in the buffer.
Some files use different conventions for separating lines: either
carriage-return linefeed (the MS-DOS convention) or just carriage-return
(the Macintosh convention). If the buffer's file uses carriage-return
linefeed, the colon changes to either a backslash (`\') or `(DOS)',
depending on the operating system. If the file uses just
carriage-return, the colon indicator changes to either a forward slash
(`/') or `(Mac)'. On some systems, Emacs displays `(Unix)' instead of
the colon even for files that use newline to separate lines.
You can customize the mode line display for each of the end-of-line
formats by setting each of the variables `eol-mnemonic-unix',
`eol-mnemonic-dos', `eol-mnemonic-mac', and `eol-mnemonic-undecided' to
any string you find appropriate. *Note Variables::, for an explanation
how to set variables.
*Note Optional Mode Line::, for features that add other handy
information to the mode line, such as the current column number of
point, the current time, and whether new mail for you has arrived.
The Menu Bar
============
Each Emacs frame normally has a "menu bar" at the top which you can
use to perform certain common operations. There's no need to list them
here, as you can more easily see for yourself.
When you are using a window system, you can use the mouse to choose a
command from the menu bar. An arrow pointing right, after the menu
item, indicates that the item leads to a subsidiary menu; `...' at the
end means that the command will read arguments from the keyboard before
it actually does anything.
To view the full command name and documentation for a menu item, type
`C-h k', and then select the menu bar with the mouse in the usual way
(*note Key Help::.).
On text-only terminals with no mouse, you can use the menu bar by
typing `M-`' or (these run the command `tmm-menubar'). This
command enters a mode in which you can select a menu item from the
keyboard. A provisional choice appears in the echo area. You can use
the left and right arrow keys to move through the menu to different
choices. When you have found the choice you want, type to select
it.
Each menu item also has an assigned letter or digit which designates
that item; it is usually the initial of some word in the item's name.
This letter or digit is separated from the item name by `=>'. You can
type the item's letter or digit to select the item.
Some of the commands in the menu bar have ordinary key bindings as
well; if so, the menu lists one equivalent key binding in parentheses
after the item itself.
Kinds of User Input
===================
GNU Emacs uses an extension of the ASCII character set for keyboard
input; it also accepts non-character input events including function
keys and mouse button actions.
ASCII consists of 128 character codes. Some of these codes are
assigned graphic symbols such as `a' and `='; the rest are control
characters, such as `Control-a' (usually written `C-a' for short).
`C-a' gets its name from the fact that you type it by holding down the
key while pressing `a'.
Some ASCII control characters have special names, and most terminals
have special keys you can type them with: for example, , ,
and . The space character is usually referred to below as
, even though strictly speaking it is a graphic character whose
graphic happens to be blank. Some keyboards have a key labeled
"linefeed" which is an alias for `C-j'.
Emacs extends the ASCII character set with thousands more printing
characters (*note International::.), additional control characters, and
a few more modifiers that can be combined with any character.
On ASCII terminals, there are only 32 possible control characters.
These are the control variants of letters and `@[]\^_'. In addition,
the shift key is meaningless with control characters: `C-a' and `C-A'
are the same character, and Emacs cannot distinguish them.
But the Emacs character set has room for control variants of all
printing characters, and for distinguishing between `C-a' and `C-A'. X
Windows makes it possible to enter all these characters. For example,
`C--' (that's Control-Minus) and `C-5' are meaningful Emacs commands
under X.
Another Emacs character-set extension is additional modifier bits.
Only one modifier bit is commonly used; it is called Meta. Every
character has a Meta variant; examples include `Meta-a' (normally
written `M-a', for short), `M-A' (not the same character as `M-a', but
those two characters normally have the same meaning in Emacs),
`M-', and `M-C-a'. For reasons of tradition, we usually write
`C-M-a' rather than `M-C-a'; logically speaking, the order in which the
modifier keys and are mentioned does not matter.
Some terminals have a key, and allow you to type Meta
characters by holding this key down. Thus, `Meta-a' is typed by
holding down and pressing `a'. The key works much like
the key. Such a key is not always labeled , however, as
this function is often a special option for a key with some other
primary purpose.
If there is no key, you can still type Meta characters using
two-character sequences starting with . Thus, to enter `M-a', you
could type ` a'. To enter `C-M-a', you would type ` C-a'.
is allowed on terminals with keys, too, in case you have
formed a habit of using it.
X Windows provides several other modifier keys that can be applied to
any input character. These are called , and . We
write `s-', `H-' and `A-' to say that a character uses these modifiers.
Thus, `s-H-C-x' is short for `Super-Hyper-Control-x'. Not all X
terminals actually provide keys for these modifier flags--in fact, many
terminals have a key labeled which is really a key. The
standard key bindings of Emacs do not include any characters with these
modifiers. But you can assign them meanings of your own by customizing
Emacs.
Keyboard input includes keyboard keys that are not characters at all:
for example function keys and arrow keys. Mouse buttons are also
outside the gamut of characters. You can modify these events with the
modifier keys , , , and , just like
keyboard characters.
Input characters and non-character inputs are collectively called
"input events". *Note Input Events: (elisp)Input Events, for more
information. If you are not doing Lisp programming, but simply want to
redefine the meaning of some characters or non-character events, see
*Note Customization::.
ASCII terminals cannot really send anything to the computer except
ASCII characters. These terminals use a sequence of characters to
represent each function key. But that is invisible to the Emacs user,
because the keyboard input routines recognize these special sequences
and convert them to function key events before any other part of Emacs
gets to see them.
Keys
====
A "key sequence" ("key", for short) is a sequence of input events
that are meaningful as a unit--as "a single command." Some Emacs
command sequences are just one character or one event; for example,
just `C-f' is enough to move forward one character. But Emacs also has
commands that take two or more events to invoke.
If a sequence of events is enough to invoke a command, it is a
"complete key". Examples of complete keys include `C-a', `X', ,
(a function key), (an arrow key), `C-x C-f', and `C-x 4
C-f'. If it isn't long enough to be complete, we call it a "prefix
key". The above examples show that `C-x' and `C-x 4' are prefix keys.
Every key sequence is either a complete key or a prefix key.
Most single characters constitute complete keys in the standard Emacs
command bindings. A few of them are prefix keys. A prefix key combines
with the following input event to make a longer key sequence, which may
itself be complete or a prefix. For example, `C-x' is a prefix key, so
`C-x' and the next input event combine to make a two-character key
sequence. Most of these key sequences are complete keys, including
`C-x C-f' and `C-x b'. A few, such as `C-x 4' and `C-x r', are
themselves prefix keys that lead to three-character key sequences.
There's no limit to the length of a key sequence, but in practice
people rarely use sequences longer than four events.
By contrast, you can't add more events onto a complete key. For
example, the two-character sequence `C-f C-k' is not a key, because the
`C-f' is a complete key in itself. It's impossible to give `C-f C-k'
an independent meaning as a command. `C-f C-k' is two key sequences,
not one.
All told, the prefix keys in Emacs are `C-c', `C-h', `C-x', `C-x
', `C-x @', `C-x a', `C-x n', `C-x r', `C-x v', `C-x 4', `C-x 5',
`C-x 6', , `M-g' and `M-j'. But this list is not cast in
concrete; it is just a matter of Emacs's standard key bindings. If you
customize Emacs, you can make new prefix keys, or eliminate these.
*Note Key Bindings::.
If you do make or eliminate prefix keys, that changes the set of
possible key sequences. For example, if you redefine `C-f' as a
prefix, `C-f C-k' automatically becomes a key (complete, unless you
define it too as a prefix). Conversely, if you remove the prefix
definition of `C-x 4', then `C-x 4 f' (or `C-x 4 ANYTHING') is no
longer a key.
Typing the help character (`C-h' or ) after a prefix character
displays a list of the commands starting with that prefix. There are a
few prefix characters for which `C-h' does not work--for historical
reasons, they have other meanings for `C-h' which are not easy to
change. But should work for all prefix characters.
Keys and Commands
=================
This manual is full of passages that tell you what particular keys
do. But Emacs does not assign meanings to keys directly. Instead,
Emacs assigns meanings to named "commands", and then gives keys their
meanings by "binding" them to commands.
Every command has a name chosen by a programmer. The name is usually
made of a few English words separated by dashes; for example,
`next-line' or `forward-word'. A command also has a "function
definition" which is a Lisp program; this is what makes the command do
what it does. In Emacs Lisp, a command is actually a special kind of
Lisp function; one which specifies how to read arguments for it and
call it interactively. For more information on commands and functions,
see *Note What Is a Function: (elisp)What Is a Function. (The
definition we use in this manual is simplified slightly.)
The bindings between keys and commands are recorded in various tables
called "keymaps". *Note Keymaps::.
When we say that "`C-n' moves down vertically one line" we are
glossing over a distinction that is irrelevant in ordinary use but is
vital in understanding how to customize Emacs. It is the command
`next-line' that is programmed to move down vertically. `C-n' has this
effect *because* it is bound to that command. If you rebind `C-n' to
the command `forward-word' then `C-n' will move forward by words
instead. Rebinding keys is a common method of customization.
In the rest of this manual, we usually ignore this subtlety to keep
things simple. To give the information needed for customization, we
state the name of the command which really does the work in parentheses
after mentioning the key that runs it. For example, we will say that
"The command `C-n' (`next-line') moves point vertically down," meaning
that `next-line' is a command that moves vertically down and `C-n' is a
key that is standardly bound to it.
While we are on the subject of information for customization only,
it's a good time to tell you about "variables". Often the description
of a command will say, "To change this, set the variable `mumble-foo'."
A variable is a name used to remember a value. Most of the variables
documented in this manual exist just to facilitate customization: some
command or other part of Emacs examines the variable and behaves
differently according to the value that you set. Until you are
interested in customizing, you can ignore the information about
variables. When you are ready to be interested, read the basic
information on variables, and then the information on individual
variables will make sense. *Note Variables::.
Character Set for Text
======================
Text in Emacs buffers is a sequence of 8-bit bytes. Each byte can
hold a single ASCII character. Both ASCII control characters (octal
codes 000 through 037, and 0177) and ASCII printing characters (codes
040 through 0176) are allowed; however, non-ASCII control characters
cannot appear in a buffer. The other modifier flags used in keyboard
input, such as Meta, are not allowed in buffers either.
Some ASCII control characters serve special purposes in text, and
have special names. For example, the newline character (octal code
012) is used in the buffer to end a line, and the tab character (octal
code 011) is used for indenting to the next tab stop column (normally
every 8 columns). *Note Text Display::.
Non-ASCII printing characters can also appear in buffers. When
multibyte characters are enabled, you can use any of the non-ASCII
printing characters that Emacs supports. They have character codes
starting at 256, octal 0400, and each one is represented as a sequence
of two or more bytes. *Note International::.
If you disable multibyte characters, then you can use only one
alphabet of non-ASCII characters, but they all fit in one byte. They
use codes 0200 through 0377. *Note Single-Byte European Support::.
Entering and Exiting Emacs
**************************
The usual way to invoke Emacs is with the shell command `emacs'.
Emacs clears the screen and then displays an initial help message and
copyright notice. Some operating systems discard all type-ahead when
Emacs starts up; they give Emacs no way to prevent this. Therefore, it
is advisable to wait until Emacs clears the screen before typing your
first editing command.
If you run Emacs from a shell window under the X Window System, run
it in the background with `emacs&'. This way, Emacs does not tie up
the shell window, so you can use that to run other shell commands while
Emacs operates its own X windows. You can begin typing Emacs commands
as soon as you direct your keyboard input to the Emacs frame.
When Emacs starts up, it makes a buffer named `*scratch*'. That's
the buffer you start out in. The `*scratch*' buffer uses Lisp
Interaction mode; you can use it to type Lisp expressions and evaluate
them, or you can ignore that capability and simply doodle. (You can
specify a different major mode for this buffer by setting the variable
`initial-major-mode' in your init file. *Note Init File::.)
It is possible to specify files to be visited, Lisp files to be
loaded, and functions to be called, by giving Emacs arguments in the
shell command line. *Note Command Arguments::. But we don't recommend
doing this. The feature exists mainly for compatibility with other
editors.
Many other editors are designed to be started afresh each time you
want to edit. You edit one file and then exit the editor. The next
time you want to edit either another file or the same one, you must run
the editor again. With these editors, it makes sense to use a
command-line argument to say which file to edit.
But starting a new Emacs each time you want to edit a different file
does not make sense. For one thing, this would be annoyingly slow. For
another, this would fail to take advantage of Emacs's ability to visit
more than one file in a single editing session. And it would lose the
other accumulated context, such as registers, undo history, and the mark
ring.
The recommended way to use GNU Emacs is to start it only once, just
after you log in, and do all your editing in the same Emacs session.
Each time you want to edit a different file, you visit it with the
existing Emacs, which eventually comes to have many files in it ready
for editing. Usually you do not kill the Emacs until you are about to
log out. *Note Files::, for more information on visiting more than one
file.
Exiting Emacs
=============
There are two commands for exiting Emacs because there are two kinds
of exiting: "suspending" Emacs and "killing" Emacs.
"Suspending" means stopping Emacs temporarily and returning control
to its parent process (usually a shell), allowing you to resume editing
later in the same Emacs job, with the same buffers, same kill ring,
same undo history, and so on. This is the usual way to exit.
"Killing" Emacs means destroying the Emacs job. You can run Emacs
again later, but you will get a fresh Emacs; there is no way to resume
the same editing session after it has been killed.
`C-z'
Suspend Emacs (`suspend-emacs') or iconify a frame
(`iconify-or-deiconify-frame').
`C-x C-c'
Kill Emacs (`save-buffers-kill-emacs').
To suspend Emacs, type `C-z' (`suspend-emacs'). This takes you back
to the shell from which you invoked Emacs. You can resume Emacs with
the shell command `%emacs' in most common shells.
On systems that do not support suspending programs, `C-z' starts an
inferior shell that communicates directly with the terminal. Emacs
waits until you exit the subshell. (The way to do that is probably
with `C-d' or `exit', but it depends on which shell you use.) The only
way on these systems to get back to the shell from which Emacs was run
(to log out, for example) is to kill Emacs.
Suspending also fails if you run Emacs under a shell that doesn't
support suspending programs, even if the system itself does support it.
In such a case, you can set the variable `cannot-suspend' to a
non-`nil' value to force `C-z' to start an inferior shell. (One might
also describe Emacs's parent shell as "inferior" for failing to support
job control properly, but that is a matter of taste.)
When Emacs communicates directly with an X server and creates its own
dedicated X windows, `C-z' has a different meaning. Suspending an
applications that uses its own X windows is not meaningful or useful.
Instead, `C-z' runs the command `iconify-or-deiconify-frame', which
temporarily closes up the selected Emacs frame (*note Frames::.). The
way to get back to a shell window is with the window manager.
To kill Emacs, type `C-x C-c' (`save-buffers-kill-emacs'). A
two-character key is used for this to make it harder to type. This
command first offers to save any modified file-visiting buffers. If you
do not save them all, it asks for reconfirmation with `yes' before
killing Emacs, since any changes not saved will be lost forever. Also,
if any subprocesses are still running, `C-x C-c' asks for confirmation
about them, since killing Emacs will kill the subprocesses immediately.
There is no way to restart an Emacs session once you have killed it.
You can, however, arrange for Emacs to record certain session
information, such as which files are visited, when you kill it, so that
the next time you restart Emacs it will try to visit the same files and
so on. *Note Saving Emacs Sessions::.
The operating system usually listens for certain special characters
whose meaning is to kill or suspend the program you are running. This
operating system feature is turned off while you are in Emacs. The
meanings of `C-z' and `C-x C-c' as keys in Emacs were inspired by the
use of `C-z' and `C-c' on several operating systems as the characters
for stopping or killing a program, but that is their only relationship
with the operating system. You can customize these keys to run any
commands of your choice (*note Keymaps::.).
Basic Editing Commands
**********************
We now give the basics of how to enter text, make corrections, and
save the text in a file. If this material is new to you, you might
learn it more easily by running the Emacs learn-by-doing tutorial. To
use the tutorial, run Emacs and type `Control-h t'
(`help-with-tutorial').
To clear the screen and redisplay, type `C-l' (`recenter').
Inserting Text
==============
To insert printing characters into the text you are editing, just
type them. This inserts the characters you type into the buffer at the
cursor (that is, at "point"; *note Point::.). The cursor moves
forward, and any text after the cursor moves forward too. If the text
in the buffer is `FOOBAR', with the cursor before the `B', then if you
type `XX', you get `FOOXXBAR', with the cursor still before the `B'.
To "delete" text you have just inserted, use . deletes
the character *before* the cursor (not the one that the cursor is on
top of or under; that is the character AFTER the cursor). The cursor
and all characters after it move backwards. Therefore, if you type a
printing character and then type , they cancel out.
To end a line and start typing a new one, type . This inserts
a newline character in the buffer. If point is in the middle of a
line, splits the line. Typing when the cursor is at the
beginning of a line deletes the preceding newline, thus joining the
line with the preceding line.
Emacs can split lines automatically when they become too long, if you
turn on a special minor mode called "Auto Fill" mode. *Note Filling::,
for how to use Auto Fill mode.
If you prefer to have text characters replace (overwrite) existing
text rather than shove it to the right, you can enable Overwrite mode,
a minor mode. *Note Minor Modes::.
Direct insertion works for printing characters and , but other
characters act as editing commands and do not insert themselves. If you
need to insert a control character or a character whose code is above
200 octal, you must "quote" it by typing the character `Control-q'
(`quoted-insert') first. (This character's name is normally written
`C-q' for short.) There are two ways to use `C-q':
* `C-q' followed by any non-graphic character (even `C-g') inserts
that character.
* `C-q' followed by a sequence of octal digits inserts the character
with the specified octal character code. You can use any number of
octal digits; any non-digit terminates the sequence. If the
terminating character is , it serves only to terminate the
sequence; any other non-digit is itself used as input after
terminating the sequence. (The use of octal sequences is disabled
in ordinary non-binary Overwrite mode, to give you a convenient
way to insert a digit instead of overwriting with it.)
When multibyte characters are enabled, octal codes 0200 through 0377 are
not valid as characters; if you specify a code in this range, `C-q'
assumes that you intend to use some ISO Latin-N character set, and
converts the specified code to the corresponding Emacs character code.
*Note Enabling Multibyte::. You select *which* ISO Latin character set
though your choice of language environment (*note Language
Environments::.).
To use decimal or hexadecimal instead of octal, set the variable
`read-quoted-char-radix' to 10 or 16. If the radix is greater than 10,
some letters starting with `a' serve as part of a character code, just
like digits.
A numeric argument to `C-q' specifies how many copies of the quoted
character should be inserted (*note Arguments::.).
Customization information: in most modes runs the command
`delete-backward-char'; runs the command `newline', and
self-inserting printing characters run the command `self-insert', which
inserts whatever character was typed to invoke it. Some major modes
rebind to other commands.
Changing the Location of Point
==============================
To do more than insert characters, you have to know how to move point
(*note Point::.). The simplest way to do this is with arrow keys, or by
clicking the left mouse button where you want to move to.
There are also control and meta characters for cursor motion. Some
are equivalent to the arrow keys (these date back to the days before
terminals had arrow keys, and are usable on terminals which don't have
them). Others do more sophisticated things.
`C-a'
Move to the beginning of the line (`beginning-of-line').
`C-e'
Move to the end of the line (`end-of-line').
`C-f'
Move forward one character (`forward-char').
`C-b'
Move backward one character (`backward-char').
`M-f'
Move forward one word (`forward-word').
`M-b'
Move backward one word (`backward-word').
`C-n'
Move down one line, vertically (`next-line'). This command
attempts to keep the horizontal position unchanged, so if you
start in the middle of one line, you end in the middle of the
next. When on the last line of text, `C-n' creates a new line and
moves onto it.
`C-p'
Move up one line, vertically (`previous-line').
`M-r'
Move point to left margin, vertically centered in the window
(`move-to-window-line'). Text does not move on the screen.
A numeric argument says which screen line to place point on. It
counts screen lines down from the top of the window (zero for the
top line). A negative argument counts lines from the bottom (-1
for the bottom line).
`M-'
Move to the end of the buffer (`end-of-buffer').
`M-x goto-char'
Read a number N and move point to buffer position N. Position 1
is the beginning of the buffer.
`M-x goto-line'
Read a number N and move point to line number N. Line 1 is the
beginning of the buffer.
`C-x C-n'
Use the current column of point as the "semipermanent goal column"
for `C-n' and `C-p' (`set-goal-column'). Henceforth, those
commands always move to this column in each line moved into, or as
close as possible given the contents of the line. This goal
column remains in effect until canceled.
`C-u C-x C-n'
Cancel the goal column. Henceforth, `C-n' and `C-p' once again
try to stick to a fixed horizontal position, as usual.
If you set the variable `track-eol' to a non-`nil' value, then `C-n'
and `C-p' when at the end of the starting line move to the end of
another line. Normally, `track-eol' is `nil'. *Note Variables::, for
how to set variables such as `track-eol'.
Normally, `C-n' on the last line of a buffer appends a newline to
it. If the variable `next-line-add-newlines' is `nil', then `C-n' gets
an error instead (like `C-p' on the first line).
Erasing Text
============
`'
Delete the character before point (`delete-backward-char').
`C-d'
Delete the character after point (`delete-char').
`C-k'
Kill to the end of the line (`kill-line').
`M-d'
Kill forward to the end of the next word (`kill-word').
`M-'
Kill back to the beginning of the previous word
(`backward-kill-word').
You already know about the key which deletes the character
before point (that is, before the cursor). Another key, `Control-d'
(`C-d' for short), deletes the character after point (that is, the
character that the cursor is on). This shifts the rest of the text on
the line to the left. If you type `C-d' at the end of a line, it joins
together that line and the next line.
To erase a larger amount of text, use the `C-k' key, which kills a
line at a time. If you type `C-k' at the beginning or middle of a
line, it kills all the text up to the end of the line. If you type
`C-k' at the end of a line, it joins that line and the next line.
*Note Killing::, for more flexible ways of killing text.
Undoing Changes
===============
You can undo all the recent changes in the buffer text, up to a
certain point. Each buffer records changes individually, and the undo
command always applies to the current buffer. Usually each editing
command makes a separate entry in the undo records, but some commands
such as `query-replace' make many entries, and very simple commands
such as self-inserting characters are often grouped to make undoing less
tedious.
`C-x u'
Undo one batch of changes--usually, one command worth (`undo').
`C-_'
The same.
`C-u C-x u'
Undo one batch of changes in the region.
The command `C-x u' or `C-_' is how you undo. The first time you
give this command, it undoes the last change. Point moves back to
where it was before the command that made the change.
Consecutive repetitions of `C-_' or `C-x u' undo earlier and earlier
changes, back to the limit of the undo information available. If all
recorded changes have already been undone, the undo command prints an
error message and does nothing.
Any command other than an undo command breaks the sequence of undo
commands. Starting from that moment, the previous undo commands become
ordinary changes that you can undo. Thus, to redo changes you have
undone, type `C-f' or any other command that will harmlessly break the
sequence of undoing, then type more undo commands.
Ordinary undo applies to all changes made in the current buffer. You
can also perform "selective undo", limited to the current region. To
do this, specify the region you want, then run the `undo' command with
a prefix argument (the value does not matter): `C-u C-x u' or `C-u
C-_'. This undoes the most recent change in the region. To undo
further changes in the same region, repeat the `undo' command (no
prefix argument is needed). In Transient Mark mode, any use of `undo'
when there is an active region performs selective undo; you do not need
a prefix argument.
If you notice that a buffer has been modified accidentally, the
easiest way to recover is to type `C-_' repeatedly until the stars
disappear from the front of the mode line. At this time, all the
modifications you made have been canceled. Whenever an undo command
makes the stars disappear from the mode line, it means that the buffer
contents are the same as they were when the file was last read in or
saved.
If you do not remember whether you changed the buffer deliberately,
type `C-_' once. When you see the last change you made undone, you
will see whether it was an intentional change. If it was an accident,
leave it undone. If it was deliberate, redo the change as described
above.
Not all buffers record undo information. Buffers whose names start
with spaces don't; these buffers are used internally by Emacs and its
extensions to hold text that users don't normally look at or edit.
You cannot undo mere cursor motion; only changes in the buffer
contents save undo information. However, some cursor motion commands
set the mark, so if you use these commands from time to time, you can
move back to the neighborhoods you have moved through by popping the
mark ring (*note Mark Ring::.).
When the undo information for a buffer becomes too large, Emacs
discards the oldest undo information from time to time (during garbage
collection). You can specify how much undo information to keep by
setting two variables: `undo-limit' and `undo-strong-limit'. Their
values are expressed in units of bytes of space.
The variable `undo-limit' sets a soft limit: Emacs keeps undo data
for enough commands to reach this size, and perhaps exceed it, but does
not keep data for any earlier commands beyond that. Its default value
is 20000. The variable `undo-strong-limit' sets a stricter limit: the
command which pushes the size past this amount is itself forgotten.
Its default value is 30000.
Regardless of the values of those variables, the most recent change
is never discarded, so there is no danger that garbage collection
occurring right after an unintentional large change might prevent you
from undoing it.
The reason the `undo' command has two keys, `C-x u' and `C-_', set
up to run it is that it is worthy of a single-character key, but on
some keyboards it is not obvious how to type `C-_'. `C-x u' is an
alternative you can type straightforwardly on any terminal.
Files
=====
The commands described above are sufficient for creating and altering
text in an Emacs buffer; the more advanced Emacs commands just make
things easier. But to keep any text permanently you must put it in a
"file". Files are named units of text which are stored by the
operating system for you to retrieve later by name. To look at or use
the contents of a file in any way, including editing the file with
Emacs, you must specify the file name.
Consider a file named `/usr/rms/foo.c'. In Emacs, to begin editing
this file, type
C-x C-f /usr/rms/foo.c
Here the file name is given as an "argument" to the command `C-x C-f'
(`find-file'). That command uses the "minibuffer" to read the
argument, and you type to terminate the argument (*note
Minibuffer::.).
Emacs obeys the command by "visiting" the file: creating a buffer,
copying the contents of the file into the buffer, and then displaying
the buffer for you to edit. If you alter the text, you can "save" the
new text in the file by typing `C-x C-s' (`save-buffer'). This makes
the changes permanent by copying the altered buffer contents back into
the file `/usr/rms/foo.c'. Until you save, the changes exist only
inside Emacs, and the file `foo.c' is unaltered.
To create a file, just visit the file with `C-x C-f' as if it
already existed. This creates an empty buffer in which you can insert
the text you want to put in the file. The file is actually created when
you save this buffer with `C-x C-s'.
Of course, there is a lot more to learn about using files. *Note
Files::.
Help
====
If you forget what a key does, you can find out with the Help
character, which is `C-h' (or , which is an alias for `C-h'). Type
`C-h k' followed by the key you want to know about; for example, `C-h k
C-n' tells you all about what `C-n' does. `C-h' is a prefix key; `C-h
k' is just one of its subcommands (the command `describe-key'). The
other subcommands of `C-h' provide different kinds of help. Type `C-h'
twice to get a description of all the help facilities. *Note Help::.
Blank Lines
===========
Here are special commands and techniques for putting in and taking
out blank lines.
`C-o'
Insert one or more blank lines after the cursor (`open-line').
`C-x C-o'
Delete all but one of many consecutive blank lines
(`delete-blank-lines').
When you want to insert a new line of text before an existing line,
you can do it by typing the new line of text, followed by .
However, it may be easier to see what you are doing if you first make a
blank line and then insert the desired text into it. This is easy to do
using the key `C-o' (`open-line'), which inserts a newline after point
but leaves point in front of the newline. After `C-o', type the text
for the new line. `C-o F O O' has the same effect as `F O O ',
except for the final location of point.
You can make several blank lines by typing `C-o' several times, or
by giving it a numeric argument to tell it how many blank lines to make.
*Note Arguments::, for how. If you have a fill prefix, then `C-o'
command inserts the fill prefix on the new line, when you use it at the
beginning of a line. *Note Fill Prefix::.
The easy way to get rid of extra blank lines is with the command
`C-x C-o' (`delete-blank-lines'). `C-x C-o' in a run of several blank
lines deletes all but one of them. `C-x C-o' on a solitary blank line
deletes that blank line. When point is on a nonblank line, `C-x C-o'
deletes any blank lines following that nonblank line.
Continuation Lines
==================
If you add too many characters to one line without breaking it with
, the line will grow to occupy two (or more) lines on the screen,
with a `\' at the extreme right margin of all but the last of them.
The `\' says that the following screen line is not really a distinct
line in the text, but just the "continuation" of a line too long to fit
the screen. Continuation is also called "line wrapping".
Sometimes it is nice to have Emacs insert newlines automatically when
a line gets too long. Continuation on the screen does not do that. Use
Auto Fill mode (*note Filling::.) if that's what you want.
As an alternative to continuation, Emacs can display long lines by
"truncation". This means that all the characters that do not fit in
the width of the screen or window do not appear at all. They remain in
the buffer, temporarily invisible. `$' is used in the last column
instead of `\' to inform you that truncation is in effect.
Truncation instead of continuation happens whenever horizontal
scrolling is in use, and optionally in all side-by-side windows (*note
Windows::.). You can enable truncation for a particular buffer by
setting the variable `truncate-lines' to non-`nil' in that buffer.
(*Note Variables::.) Altering the value of `truncate-lines' makes it
local to the current buffer; until that time, the default value is in
effect. The default is initially `nil'. *Note Locals::.
*Note Display Vars::, for additional variables that affect how text
is displayed.
Cursor Position Information
===========================
Here are commands to get information about the size and position of
parts of the buffer, and to count lines.
`M-x what-page'
Print page number of point, and line number within page.
`M-x what-line'
Print line number of point in the buffer.
`M-x line-number-mode'
Toggle automatic display of current line number.
`M-='
Print number of lines in the current region (`count-lines-region').
*Note Mark::, for information about the region.
`C-x ='
Print character code of character after point, character position
of point, and column of point (`what-cursor-position').
There are two commands for working with line numbers. `M-x
what-line' computes the current line number and displays it in the echo
area. To go to a given line by number, use `M-x goto-line'; it prompts
you for the number. These line numbers count from one at the beginning
of the buffer.
You can also see the current line number in the mode line; *Note
Mode Line::. If you narrow the buffer, then the line number in the
mode line is relative to the accessible portion (*note Narrowing::.).
By contrast, `what-line' shows both the line number relative to the
narrowed region and the line number relative to the whole buffer.
By contrast, `M-x what-page' counts pages from the beginning of the
file, and counts lines within the page, printing both numbers. *Note
Pages::.
While on this subject, we might as well mention `M-='
(`count-lines-region'), which prints the number of lines in the region
(*note Mark::.). *Note Pages::, for the command `C-x l' which counts
the lines in the current page.
The command `C-x =' (`what-cursor-position') can be used to find out
the column that the cursor is in, and other miscellaneous information
about point. It prints a line in the echo area that looks like this:
Char: c (0143, 99, 0x63) point=21044 of 26883(78%) column 53
(In fact, this is the output produced when point is before the `column'
in the example.)
The four values after `Char:' describe the character that follows
point, first by showing it and then by giving its character code in
octal, decimal and hex. For a non-ASCII multibyte character, these are
followed by `ext' and the character's representation, in hex, in the
buffer's coding system, if that coding system encodes the character
safely and with a single byte (*note Coding Systems::.). If the
character's encoding is longer than one byte, Emacs shows `ext ...'.
`point=' is followed by the position of point expressed as a
character count. The front of the buffer counts as position 1, one
character later as 2, and so on. The next, larger, number is the total
number of characters in the buffer. Afterward in parentheses comes the
position expressed as a percentage of the total size.
`column' is followed by the horizontal position of point, in columns
from the left edge of the window.
If the buffer has been narrowed, making some of the text at the
beginning and the end temporarily inaccessible, `C-x =' prints
additional text describing the currently accessible range. For
example, it might display this:
Char: C (0103, 67, 0x43) point=252 of 889(28%) <231 - 599> column 0
where the two extra numbers give the smallest and largest character
position that point is allowed to assume. The characters between those
two positions are the accessible ones. *Note Narrowing::.
If point is at the end of the buffer (or the end of the accessible
part), the `C-x =' output does not describe a character after point.
The output might look like this:
point=26957 of 26956(100%) column 0
`C-u C-x =' displays additional information about a character, in
place of the buffer coordinates and column: the character set name and
the codes that identify the character within that character set; ASCII
characters are identified as belonging to the `ASCII' character set.
In addition, the full character encoding, even if it takes more than a
single byte, is shown after `ext'. Here's an example for a Latin-1
character A with a grave accent in a buffer whose coding system is
iso-2022-7bit(1):
Char: `A (04300, 2240, 0x8c0, ext ESC , A @) (latin-iso8859-1 64)
---------- Footnotes ----------
(1) On terminals that support Latin-1 characters, the character
shown after `Char:' is displayed as the actual glyph of A with grave
accent.
Numeric Arguments
=================
In mathematics and computer usage, the word "argument" means "data
provided to a function or operation." You can give any Emacs command a
"numeric argument" (also called a "prefix argument"). Some commands
interpret the argument as a repetition count. For example, `C-f' with
an argument of ten moves forward ten characters instead of one. With
these commands, no argument is equivalent to an argument of one.
Negative arguments tell most such commands to move or act in the
opposite direction.
If your terminal keyboard has a key, the easiest way to
specify a numeric argument is to type digits and/or a minus sign while
holding down the key. For example,
M-5 C-n
would move down five lines. The characters `Meta-1', `Meta-2', and so
on, as well as `Meta--', do this because they are keys bound to
commands (`digit-argument' and `negative-argument') that are defined to
contribute to an argument for the next command. Digits and `-'
modified with Control, or Control and Meta, also specify numeric
arguments.
Another way of specifying an argument is to use the `C-u'
(`universal-argument') command followed by the digits of the argument.
With `C-u', you can type the argument digits without holding down
modifier keys; `C-u' works on all terminals. To type a negative
argument, type a minus sign after `C-u'. Just a minus sign without
digits normally means -1.
`C-u' followed by a character which is neither a digit nor a minus
sign has the special meaning of "multiply by four." It multiplies the
argument for the next command by four. `C-u' twice multiplies it by
sixteen. Thus, `C-u C-u C-f' moves forward sixteen characters. This
is a good way to move forward "fast," since it moves about 1/5 of a line
in the usual size screen. Other useful combinations are `C-u C-n',
`C-u C-u C-n' (move down a good fraction of a screen), `C-u C-u C-o'
(make "a lot" of blank lines), and `C-u C-k' (kill four lines).
Some commands care only about whether there is an argument, and not
about its value. For example, the command `M-q' (`fill-paragraph') with
no argument fills text; with an argument, it justifies the text as well.
(*Note Filling::, for more information on `M-q'.) Plain `C-u' is a
handy way of providing an argument for such commands.
Some commands use the value of the argument as a repeat count, but do
something peculiar when there is no argument. For example, the command
`C-k' (`kill-line') with argument N kills N lines, including their
terminating newlines. But `C-k' with no argument is special: it kills
the text up to the next newline, or, if point is right at the end of
the line, it kills the newline itself. Thus, two `C-k' commands with
no arguments can kill a nonblank line, just like `C-k' with an argument
of one. (*Note Killing::, for more information on `C-k'.)
A few commands treat a plain `C-u' differently from an ordinary
argument. A few others may treat an argument of just a minus sign
differently from an argument of -1. These unusual cases are described
when they come up; they are always for reasons of convenience of use of
the individual command.
You can use a numeric argument to insert multiple copies of a
character. This is straightforward unless the character is a digit; for
example, `C-u 6 4 a' inserts 64 copies of the character `a'. But this
does not work for inserting digits; `C-u 6 4 1' specifies an argument
of 641, rather than inserting anything. To separate the digit to
insert from the argument, type another `C-u'; for example, `C-u 6 4 C-u
1' does insert 64 copies of the character `1'.
We use the term "prefix argument" as well as "numeric argument" to
emphasize that you type the argument before the command, and to
distinguish these arguments from minibuffer arguments that come after
the command.
Repeating a Command
===================
The command `C-x z' (`repeat') provides another way to repeat an
Emacs command many times. This command repeats the previous Emacs
command, whatever that was. Repeating a command uses the same arguments
that were used before; it does not read new arguments each time.
To repeat the command more than once, type additional `z''s: each
`z' repeats the command one more time. Repetition ends when you type a
character other than `z', or press a mouse button.
For example, suppose you type `C-u 2 0 C-d' to delete 20 characters.
You can repeat that command (including its argument) three additional
times, to delete a total of 80 characters, by typing `C-x z z z'. The
first `C-x z' repeats the command once, and each subsequent `z' repeats
it once again.
The Minibuffer
**************
The "minibuffer" is the facility used by Emacs commands to read
arguments more complicated than a single number. Minibuffer arguments
can be file names, buffer names, Lisp function names, Emacs command
names, Lisp expressions, and many other things, depending on the command
reading the argument. You can use the usual Emacs editing commands in
the minibuffer to edit the argument text.
When the minibuffer is in use, it appears in the echo area, and the
terminal's cursor moves there. The beginning of the minibuffer line
displays a "prompt" which says what kind of input you should supply and
how it will be used. Often this prompt is derived from the name of the
command that the argument is for. The prompt normally ends with a
colon.
Sometimes a "default argument" appears in parentheses after the
colon; it too is part of the prompt. The default will be used as the
argument value if you enter an empty argument (for example, just type
). For example, commands that read buffer names always show a
default, which is the name of the buffer that will be used if you type
just .
The simplest way to enter a minibuffer argument is to type the text
you want, terminated by which exits the minibuffer. You can
cancel the command that wants the argument, and get out of the
minibuffer, by typing `C-g'.
Since the minibuffer uses the screen space of the echo area, it can
conflict with other ways Emacs customarily uses the echo area. Here is
how Emacs handles such conflicts:
* If a command gets an error while you are in the minibuffer, this
does not cancel the minibuffer. However, the echo area is needed
for the error message and therefore the minibuffer itself is
hidden for a while. It comes back after a few seconds, or as soon
as you type anything.
* If in the minibuffer you use a command whose purpose is to print a
message in the echo area, such as `C-x =', the message is printed
normally, and the minibuffer is hidden for a while. It comes back
after a few seconds, or as soon as you type anything.
* Echoing of keystrokes does not take place while the minibuffer is
in use.
Minibuffers for File Names
==========================
Sometimes the minibuffer starts out with text in it. For example,
when you are supposed to give a file name, the minibuffer starts out
containing the "default directory", which ends with a slash. This is
to inform you which directory the file will be found in if you do not
specify a directory.
For example, the minibuffer might start out with these contents:
Find File: /u2/emacs/src/
where `Find File: ' is the prompt. Typing `buffer.c' specifies the
file `/u2/emacs/src/buffer.c'. To find files in nearby directories,
use `..'; thus, if you type `../lisp/simple.el', you will get the file
named `/u2/emacs/lisp/simple.el'. Alternatively, you can kill with
`M-' the directory names you don't want (*note Words::.).
If you don't want any of the default, you can kill it with `C-a
C-k'. But you don't need to kill the default; you can simply ignore it.
Insert an absolute file name, one starting with a slash or a tilde,
after the default directory. For example, to specify the file
`/etc/termcap', just insert that name, giving these minibuffer contents:
Find File: /u2/emacs/src//etc/termcap
GNU Emacs gives a special meaning to a double slash (which is not
normally a useful thing to write): it means, "ignore everything before
the second slash in the pair." Thus, `/u2/emacs/src/' is ignored in
the example above, and you get the file `/etc/termcap'.
If you set `insert-default-directory' to `nil', the default
directory is not inserted in the minibuffer. This way, the minibuffer
starts out empty. But the name you type, if relative, is still
interpreted with respect to the same default directory.
Editing in the Minibuffer
=========================
The minibuffer is an Emacs buffer (albeit a peculiar one), and the
usual Emacs commands are available for editing the text of an argument
you are entering.
Since in the minibuffer is defined to exit the minibuffer, you
can't use it to insert a newline in the minibuffer. To do that, type
`C-o' or `C-q C-j'. (Recall that a newline is really the character
control-J.)
The minibuffer has its own window which always has space on the
screen but acts as if it were not there when the minibuffer is not in
use. When the minibuffer is in use, its window is just like the
others; you can switch to another window with `C-x o', edit text in
other windows and perhaps even visit more files, before returning to
the minibuffer to submit the argument. You can kill text in another
window, return to the minibuffer window, and then yank the text to use
it in the argument. *Note Windows::.
There are some restrictions on the use of the minibuffer window,
however. You cannot switch buffers in it--the minibuffer and its
window are permanently attached. Also, you cannot split or kill the
minibuffer window. But you can make it taller in the normal fashion
with `C-x ^'. If you enable Resize-Minibuffer mode, then the
minibuffer window expands vertically as necessary to hold the text that
you put in the minibuffer. Use `M-x resize-minibuffer-mode' to enable
or disable this minor mode (*note Minor Modes::.).
Scrolling works specially in the minibuffer window. When the
minibuffer is just one line high, and it contains a long line of text
that won't fit on the screen, scrolling automatically maintains an
overlap of a certain number of characters from one continuation line to
the next. The variable `minibuffer-scroll-overlap' specifies how many
characters of overlap; the default is 20.
If while in the minibuffer you issue a command that displays help
text of any sort in another window, you can use the `C-M-v' command
while in the minibuffer to scroll the help text. This lasts until you
exit the minibuffer. This feature is especially useful if a completing
minibuffer gives you a list of possible completions. *Note Other
Window::.
Emacs normally disallows most commands that use the minibuffer while
the minibuffer is active. This rule is to prevent recursive minibuffers
from confusing novice users. If you want to be able to use such
commands in the minibuffer, set the variable
`enable-recursive-minibuffers' to a non-`nil' value.
Completion
==========
For certain kinds of arguments, you can use "completion" to enter
the argument value. Completion means that you type part of the
argument, then Emacs visibly fills in the rest, or as much as can be
determined from the part you have typed.
When completion is available, certain keys--, , and
--are rebound to complete the text present in the minibuffer into
a longer string that it stands for, by matching it against a set of
"completion alternatives" provided by the command reading the argument.
`?' is defined to display a list of possible completions of what you
have inserted.
For example, when `M-x' uses the minibuffer to read the name of a
command, it provides a list of all available Emacs command names to
complete against. The completion keys match the text in the minibuffer
against all the command names, find any additional name characters
implied by the ones already present in the minibuffer, and add those
characters to the ones you have given. This is what makes it possible
to type `M-x ins b ' instead of `M-x insert-buffer '
(for example).
Case is normally significant in completion, because it is significant
in most of the names that you can complete (buffer names, file names and
command names). Thus, `fo' does not complete to `Foo'. Completion
does ignore case distinctions for certain arguments in which case does
not matter.
Completion Example
------------------
A concrete example may help here. If you type `M-x au ', the
looks for alternatives (in this case, command names) that start
with `au'. There are several, including `auto-fill-mode' and
`auto-save-mode'--but they are all the same as far as `auto-', so the
`au' in the minibuffer changes to `auto-'.
If you type again immediately, there are multiple
possibilities for the very next character--it could be any of
`cfilrs'--so no more characters are added; instead, displays a
list of all possible completions in another window.
If you go on to type `f ', this sees `auto-f'. The only
command name starting this way is `auto-fill-mode', so completion fills
in the rest of that. You now have `auto-fill-mode' in the minibuffer
after typing just `au f '. Note that has this effect
because in the minibuffer it is bound to the command
`minibuffer-complete' when completion is available.
Completion Commands
-------------------
Here is a list of the completion commands defined in the minibuffer
when completion is available.
`'
Complete the text in the minibuffer as much as possible
(`minibuffer-complete').
`'
Complete the minibuffer text, but don't go beyond one word
(`minibuffer-complete-word').
`'
Submit the text in the minibuffer as the argument, possibly
completing first as described below
(`minibuffer-complete-and-exit').
`?'
Print a list of all possible completions of the text in the
minibuffer (`minibuffer-list-completions').
completes much like , but never goes beyond the next
hyphen or space. If you have `auto-f' in the minibuffer and type
, it finds that the completion is `auto-fill-mode', but it stops
completing after `fill-'. This gives `auto-fill-'. Another at
this point completes all the way to `auto-fill-mode'. in the
minibuffer when completion is available runs the command
`minibuffer-complete-word'.
Here are some commands you can use to choose a completion from a
window that displays a list of completions:
`Mouse-2'
Clicking mouse button 2 on a completion in the list of possible
completions chooses that completion (`mouse-choose-completion').
You normally use this command while point is in the minibuffer;
but you must click in the list of completions, not in the
minibuffer itself.
`'
`M-v'
Typing or , or `M-v', while in the minibuffer,
selects the window showing the completion list buffer
(`switch-to-completions'). This paves the way for using the
commands below. (Selecting that window in the usual ways has the
same effect, but this way is more convenient.)
`'
Typing *in the completion list buffer* chooses the
completion that point is in or next to (`choose-completion'). To
use this command, you must first switch windows to the window that
shows the list of completions.
`'
Typing the right-arrow key *in the completion list buffer*
moves point to the following completion (`next-completion').
`'
Typing the left-arrow key *in the completion list buffer*
moves point toward the beginning of the buffer, to the previous
completion (`previous-completion').
Strict Completion
-----------------
There are three different ways that can work in completing
minibuffers, depending on how the argument will be used.
* "Strict" completion is used when it is meaningless to give any
argument except one of the known alternatives. For example, when
`C-x k' reads the name of a buffer to kill, it is meaningless to
give anything but the name of an existing buffer. In strict
completion, refuses to exit if the text in the minibuffer
does not complete to an exact match.
* "Cautious" completion is similar to strict completion, except that
exits only if the text was an exact match already, not
needing completion. If the text is not an exact match, does
not exit, but it does complete the text. If it completes to an
exact match, a second will exit.
Cautious completion is used for reading file names for files that
must already exist.
* "Permissive" completion is used when any string whatever is
meaningful, and the list of completion alternatives is just a
guide. For example, when `C-x C-f' reads the name of a file to
visit, any file name is allowed, in case you want to create a
file. In permissive completion, takes the text in the
minibuffer exactly as given, without completing it.
The completion commands display a list of all possible completions in
a window whenever there is more than one possibility for the very next
character. Also, typing `?' explicitly requests such a list. If the
list of completions is long, you can scroll it with `C-M-v' (*note
Other Window::.).
Completion Options
------------------
When completion is done on file names, certain file names are usually
ignored. The variable `completion-ignored-extensions' contains a list
of strings; a file whose name ends in any of those strings is ignored
as a possible completion. The standard value of this variable has
several elements including `".o"', `".elc"', `".dvi"' and `"~"'. The
effect is that, for example, `foo' can complete to `foo.c' even though
`foo.o' exists as well. However, if *all* the possible completions end
in "ignored" strings, then they are not ignored. Ignored extensions do
not apply to lists of completions--those always mention all possible
completions.
Normally, a completion command that finds the next character is
undetermined automatically displays a list of all possible completions.
If the variable `completion-auto-help' is set to `nil', this does not
happen, and you must type `?' to display the possible completions.
The `complete' library implements a more powerful kind of completion
that can complete multiple words at a time. For example, it can
complete the command name abbreviation `p-b' into `print-buffer',
because no other command starts with two words whose initials are `p'
and `b'. To use this library, put `(load "complete")' in your
`~/.emacs' file (*note Init File::.).
Icomplete mode presents a constantly-updated display that tells you
what completions are available for the text you've entered so far. The
command to enable or disable this minor mode is `M-x icomplete-mode'.
Minibuffer History
==================
Every argument that you enter with the minibuffer is saved on a
"minibuffer history list" so that you can use it again later in another
argument. Special commands load the text of an earlier argument in the
minibuffer. They discard the old minibuffer contents, so you can think
of them as moving through the history of previous arguments.
`'
`M-p'
Move to the next earlier argument string saved in the minibuffer
history (`previous-history-element').
`'
`M-n'
Move to the next later argument string saved in the minibuffer
history (`next-history-element').
`M-r REGEXP '
Move to an earlier saved argument in the minibuffer history that
has a match for REGEXP (`previous-matching-history-element').
`M-s REGEXP '
Move to a later saved argument in the minibuffer history that has a
match for REGEXP (`next-matching-history-element').
The simplest way to reuse the saved arguments in the history list is
to move through the history list one element at a time. While in the
minibuffer, use `M-p' or up-arrow (`previous-history-element') to "move
to" the next earlier minibuffer input, and use `M-n' or down-arrow
(`next-history-element') to "move to" the next later input.
The previous input that you fetch from the history entirely replaces
the contents of the minibuffer. To use it as the argument, exit the
minibuffer as usual with . You can also edit the text before you
reuse it; this does not change the history element that you "moved" to,
but your new argument does go at the end of the history list in its own
right.
For many minibuffer arguments there is a "default" value. In some
cases, the minibuffer history commands know the default value. Then you
can insert the default value into the minibuffer as text by using `M-n'
to move "into the future" in the history. Eventually we hope to make
this feature available whenever the minibuffer has a default value.
There are also commands to search forward or backward through the
history; they search for history elements that match a regular
expression that you specify with the minibuffer. `M-r'
(`previous-matching-history-element') searches older elements in the
history, while `M-s' (`next-matching-history-element') searches newer
elements. By special dispensation, these commands can use the
minibuffer to read their arguments even though you are already in the
minibuffer when you issue them. As with incremental searching, an
uppercase letter in the regular expression makes the search
case-sensitive (*note Search Case::.).
All uses of the minibuffer record your input on a history list, but
there are separate history lists for different kinds of arguments. For
example, there is a list for file names, used by all the commands that
read file names. (As a special feature, this history list records the
absolute file name, no more and no less, even if that is not how you
entered the file name.)
There are several other very specific history lists, including one
for command names read by `M-x', one for buffer names, one for arguments
of commands like `query-replace', and one for compilation commands read
by `compile'. Finally, there is one "miscellaneous" history list that
most minibuffer arguments use.
The variable `history-length' specifies the maximum length of a
minibuffer history list; once a list gets that long, the oldest element
is deleted each time an element is added. If the value of
`history-length' is `t', though, there is no maximum length and
elements are never deleted.
Repeating Minibuffer Commands
=============================
Every command that uses the minibuffer at least once is recorded on a
special history list, together with the values of its arguments, so that
you can repeat the entire command. In particular, every use of `M-x'
is recorded there, since `M-x' uses the minibuffer to read the command
name.
`C-x '
Re-execute a recent minibuffer command (`repeat-complex-command').
`M-x list-command-history'
Display the entire command history, showing all the commands `C-x
' can repeat, most recent first.
`C-x ' is used to re-execute a recent minibuffer-using
command. With no argument, it repeats the last such command. A
numeric argument specifies which command to repeat; one means the last
one, and larger numbers specify earlier ones.
`C-x ' works by turning the previous command into a Lisp
expression and then entering a minibuffer initialized with the text for
that expression. If you type just , the command is repeated as
before. You can also change the command by editing the Lisp
expression. Whatever expression you finally submit is what will be
executed. The repeated command is added to the front of the command
history unless it is identical to the most recently executed command
already there.
Even if you don't understand Lisp syntax, it will probably be obvious
which command is displayed for repetition. If you do not change the
text, it will repeat exactly as before.
Once inside the minibuffer for `C-x ', you can use the
minibuffer history commands (`M-p', `M-n', `M-r', `M-s'; *note
Minibuffer History::.) to move through the history list of saved entire
commands. After finding the desired previous command, you can edit its
expression as usual and then resubmit it by typing as usual.
The list of previous minibuffer-using commands is stored as a Lisp
list in the variable `command-history'. Each element is a Lisp
expression which describes one command and its arguments. Lisp programs
can re-execute a command by calling `eval' with the `command-history'
element.
Running Commands by Name
************************
The Emacs commands that are used often or that must be quick to type
are bound to keys--short sequences of characters--for convenient use.
Other Emacs commands that do not need to be brief are not bound to
keys; to run them, you must refer to them by name.
A command name is, by convention, made up of one or more words,
separated by hyphens; for example, `auto-fill-mode' or `manual-entry'.
The use of English words makes the command name easier to remember than
a key made up of obscure characters, even though it is more characters
to type.
The way to run a command by name is to start with `M-x', type the
command name, and finish it with . `M-x' uses the minibuffer to
read the command name. exits the minibuffer and runs the
command. The string `M-x' appears at the beginning of the minibuffer
as a "prompt" to remind you to enter the name of a command to be run.
*Note Minibuffer::, for full information on the features of the
minibuffer.
You can use completion to enter the command name. For example, the
command `forward-char' can be invoked by name by typing
M-x forward-char
or
M-x forw c
Note that `forward-char' is the same command that you invoke with the
key `C-f'. You can run any Emacs command by name using `M-x', whether
or not any keys are bound to it.
If you type `C-g' while the command name is being read, you cancel
the `M-x' command and get out of the minibuffer, ending up at top level.
To pass a numeric argument to the command you are invoking with
`M-x', specify the numeric argument before the `M-x'. `M-x' passes the
argument along to the command it runs. The argument value appears in
the prompt while the command name is being read.
If the command you type has a key binding of its own, Emacs mentions
this in the echo area, two seconds after the command finishes (if you
don't type anything else first). For example, if you type `M-x
forward-word', the message says that you can run the same command more
easily by typing `M-f'. You can turn off these messages by setting
`suggest-key-bindings' to `nil'.
Normally, when describing in this manual a command that is run by
name, we omit the that is needed to terminate the name. Thus we
might speak of `M-x auto-fill-mode' rather than `M-x auto-fill-mode
'. We mention the only when there is a need to emphasize
its presence, such as when we show the command together with following
arguments.
`M-x' works by running the command `execute-extended-command', which
is responsible for reading the name of another command and invoking it.
Help
****
Emacs provides extensive help features accessible through a single
character, `C-h'. `C-h' is a prefix key that is used only for
documentation-printing commands. The characters that you can type after
`C-h' are called "help options". One help option is `C-h'; that is how
you ask for help about using `C-h'. To cancel, type `C-g'. The
function key is equivalent to `C-h'.
`C-h C-h' (`help-for-help') displays a list of the possible help
options, each with a brief description. Before you type a help option,
you can use or to scroll through the list.
`C-h' or means "help" in various other contexts as well. For
example, in the middle of `query-replace', it describes the options
available for how to operate on the current match. After a prefix key,
it displays a list of the alternatives that can follow the prefix key.
(A few prefix keys don't support `C-h', because they define other
meanings for it, but they all support .)
Most help buffers use a special major mode, Help mode, which lets you
scroll conveniently with and .
Help Summary
============
Here is a summary of the defined help commands.
`C-h a REGEXP '
Display a list of commands whose names match REGEXP
(`apropos-command').
`C-h b'
Display a table of all key bindings in effect now, in this order:
minor mode bindings, major mode bindings, and global bindings
(`describe-bindings').
`C-h c KEY'
Print the name of the command that KEY runs
(`describe-key-briefly'). Here `c' stands for `character'. For
more extensive information on KEY, use `C-h k'.
`C-h f FUNCTION '
Display documentation on the Lisp function named FUNCTION
(`describe-function'). Since commands are Lisp functions, a
command name may be used.
`C-h h'
Display the `hello' file, which shows examples of various character
sets.
`C-h i'
Run Info, the program for browsing documentation files (`info').
The complete Emacs manual is available on-line in Info.
`C-h k KEY'
Display the name and documentation of the command that KEY runs
(`describe-key').
`C-h l'
Display a description of the last 100 characters you typed
(`view-lossage').
`C-h m'
Display documentation of the current major mode (`describe-mode').
`C-h n'
Display documentation of Emacs changes, most recent first
(`view-emacs-news').
`C-h p'
Find packages by topic keyword (`finder-by-keyword').
`C-h s'
Display current contents of the syntax table, plus an explanation
of what they mean (`describe-syntax'). *Note Syntax::.
`C-h t'
Enter the Emacs interactive tutorial (`help-with-tutorial').
`C-h v VAR '
Display the documentation of the Lisp variable VAR
(`describe-variable').
`C-h w COMMAND '
Print which keys run the command named COMMAND (`where-is').
`C-h C CODING '
Describe coding system CODING (`describe-coding-system').
`C-h C '
Describe the coding systems currently in use.
`C-h I METHOD '
Describe an input method (`describe-input-method').
`C-h L LANGUAGE-ENV '
Describe information on the character sets, coding systems and
input methods used for language environment LANGUAGE-ENV
(`describe-language-environment').
`C-h C-c'
Display the copying conditions for GNU Emacs.
`C-h C-d'
Display information about getting new versions of GNU Emacs.
`C-h C-f FUNCTION '
Enter Info and go to the node documenting the Emacs function
FUNCTION (`Info-goto-emacs-command-node').
`C-h C-k KEY'
Enter Info and go to the node where the key sequence KEY is
documented (`Info-goto-emacs-key-command-node').
`C-h C-p'
Display information about the GNU Project.
`C-h SYMBOL '
Display the Info documentation on symbol SYMBOL according to the
programming language you are editing (`info-lookup-symbol').
Documentation for a Key
=======================
The most basic `C-h' options are `C-h c' (`describe-key-briefly')
and `C-h k' (`describe-key'). `C-h c KEY' prints in the echo area the
name of the command that KEY is bound to. For example, `C-h c C-f'
prints `forward-char'. Since command names are chosen to describe what
the commands do, this is a good way to get a very brief description of
what KEY does.
`C-h k KEY' is similar but gives more information: it displays the
documentation string of the command as well as its name. This is too
big for the echo area, so a window is used for the display.
`C-h c' and `C-h k' work for any sort of key sequences, including
function keys and mouse events.
Help by Command or Variable Name
================================
`C-h f' (`describe-function') reads the name of a Lisp function
using the minibuffer, then displays that function's documentation string
in a window. Since commands are Lisp functions, you can use this to get
the documentation of a command that you know by name. For example,
C-h f auto-fill-mode
displays the documentation of `auto-fill-mode'. This is the only way
to get the documentation of a command that is not bound to any key (one
which you would normally run using `M-x').
`C-h f' is also useful for Lisp functions that you are planning to
use in a Lisp program. For example, if you have just written the
expression `(make-vector len)' and want to check that you are using
`make-vector' properly, type `C-h f make-vector '. Because `C-h
f' allows all function names, not just command names, you may find that
some of your favorite abbreviations that work in `M-x' don't work in
`C-h f'. An abbreviation may be unique among command names yet fail to
be unique when other function names are allowed.
The function name for `C-h f' to describe has a default which is
used if you type leaving the minibuffer empty. The default is
the function called by the innermost Lisp expression in the buffer
around point, *provided* that is a valid, defined Lisp function name.
For example, if point is located following the text `(make-vector (car
x)', the innermost list containing point is the one that starts with
`(make-vector', so the default is to describe the function
`make-vector'.
`C-h f' is often useful just to verify that you have the right
spelling for the function name. If `C-h f' mentions a name from the
buffer as the default, that name must be defined as a Lisp function. If
that is all you want to know, just type `C-g' to cancel the `C-h f'
command, then go on editing.
`C-h w COMMAND ' tells you what keys are bound to COMMAND. It
prints a list of the keys in the echo area. If it says the command is
not on any key, you must use `M-x' to run it. `C-h w' runs the command
`where-is'.
`C-h v' (`describe-variable') is like `C-h f' but describes Lisp
variables instead of Lisp functions. Its default is the Lisp symbol
around or before point, but only if that is the name of a known Lisp
variable. *Note Variables::.
Apropos
=======
A more sophisticated sort of question to ask is, "What are the
commands for working with files?" To ask this question, type `C-h a
file ', which displays a list of all command names that contain
`file', including `copy-file', `find-file', and so on. With each
command name appears a brief description of how to use the command, and
what keys you can currently invoke it with. For example, it would say
that you can invoke `find-file' by typing `C-x C-f'. The `a' in `C-h
a' stands for `Apropos'; `C-h a' runs the command `apropos-command'.
This command normally checks only commands (interactive functions); if
you specify a prefix argument, it checks noninteractive functions as
well.
Because `C-h a' looks only for functions whose names contain the
string you specify, you must use ingenuity in choosing the string. If
you are looking for commands for killing backwards and `C-h a
kill-backwards ' doesn't reveal any, don't give up. Try just
`kill', or just `backwards', or just `back'. Be persistent. Also note
that you can use a regular expression as the argument, for more
flexibility (*note Regexps::.).
Here is a set of arguments to give to `C-h a' that covers many
classes of Emacs commands, since there are strong conventions for naming
the standard Emacs commands. By giving you a feel for the naming
conventions, this set should also serve to aid you in developing a
technique for picking `apropos' strings.
char, line, word, sentence, paragraph, region, page, sexp, list,
defun, rect, buffer, frame, window, face, file, dir, register,
mode, beginning, end, forward, backward, next, previous, up, down,
search, goto, kill, delete, mark, insert, yank, fill, indent,
case, change, set, what, list, find, view, describe, default.
To list all user variables that match a regexp, use the command `M-x
apropos-variable'. This command shows only user variables and
customization options by default; if you specify a prefix argument, it
checks all variables.
To list all Lisp symbols that contain a match for a regexp, not just
the ones that are defined as commands, use the command `M-x apropos'
instead of `C-h a'. This command does not check key bindings by
default; specify a numeric argument if you want it to check them.
The `apropos-documentation' command is like `apropos' except that it
searches documentation strings as well as symbol names for matches for
the specified regular expression.
The `apropos-value' command is like `apropos' except that it
searches symbols' values for matches for the specified regular
expression. This command does not check function definitions or
property lists by default; specify a numeric argument if you want it to
check them.
If the variable `apropos-do-all' is non-`nil', the commands above
all behave as if they had been given a prefix argument.
If you want more information about a function definition, variable or
symbol property listed in the Apropos buffer, you can click on it with
`Mouse-2' or move there and type .
Keyword Search for Lisp Libraries
=================================
The `C-h p' command lets you search the standard Emacs Lisp
libraries by topic keywords. Here is a partial list of keywords you can
use:
abbrev --- abbreviation handling, typing shortcuts, macros.
bib --- support for the bibliography processor `bib'.
c --- C and C++ language support.
calendar --- calendar and time management support.
comm --- communications, networking, remote access to files.
data --- support for editing files of data.
docs --- support for Emacs documentation.
emulations --- emulations of other editors.
extensions --- Emacs Lisp language extensions.
faces --- support for using faces (fonts and colors; *note Faces::.).
frames --- support for Emacs frames and window systems.
games --- games, jokes and amusements.
hardware --- support for interfacing with exotic hardware.
help --- support for on-line help systems.
hypermedia --- support for links within text, or other media types.
i18n --- internationalization and alternate character-set support.
internal --- code for Emacs internals, build process, defaults.
languages --- specialized modes for editing programming languages.
lisp --- support for using Lisp (including Emacs Lisp).
local --- libraries local to your site.
maint --- maintenance aids for the Emacs development group.
mail --- modes for electronic-mail handling.
matching --- searching and matching.
news --- support for netnews reading and posting.
non-text --- support for editing files that are not ordinary text.
oop --- support for object-oriented programming.
outlines --- hierarchical outlining.
processes --- process, subshell, compilation, and job control support.
terminals --- support for terminal types.
tex --- support for the TeX formatter.
tools --- programming tools.
unix --- front-ends/assistants for, or emulators of, Unix features.
vms --- support code for VMS.
wp --- word processing.
Help for International Language Support
=======================================
You can use the command `C-h L' (`describe-language-environment') to
find out the support for a specific language environment. *Note
Language Environments::. This tells you which languages this language
environment is useful for, and lists the character sets, coding
systems, and input methods that go with it. It also shows some sample
text to illustrate scripts.
The command `C-h h' (`view-hello-file') displays the file
`etc/HELLO', which shows how to say "hello" in many languages.
The command `C-h I' (`describe-input-method') describes information
about input methods--either a specified input method, or by default the
input method in use. *Note Input Methods::.
The command `C-h C' (`describe-coding-system') describes information
about coding systems--either a specified coding system, or the ones
currently in use. *Note Coding Systems::.
Help Mode Commands
==================
Help buffers provide the commands of View mode (*note Misc File
Ops::.), plus a few special commands of their own.
`'
Scroll forward.
`'
Scroll backward.
`'
Follow a cross reference at point.
`'
Move point forward to the next cross reference.
`S-'
Move point back to the previous cross reference.
`Mouse-2'
Follow a cross reference that you click on.
When a command name (*note Running Commands by Name: M-x.) or
variable name (*note Variables::.) appears in the documentation, it
normally appears inside paired single-quotes. You can click on the name
with `Mouse-2', or move point there and type , to view the
documentation of that command or variable. Use `C-c C-b' to retrace
your steps.
There are convenient commands for moving point to cross references in
the help text. (`help-next-ref') moves point down to the next
cross reference. Use `S-' to move point up to the previous cross
reference (`help-previous-ref').
Other Help Commands
===================
`C-h i' (`info') runs the Info program, which is used for browsing
through structured documentation files. The entire Emacs manual is
available within Info. Eventually all the documentation of the GNU
system will be available. Type `h' after entering Info to run a
tutorial on using Info.
If you specify a numeric argument, `C-h i' prompts for the name of a
documentation file. This way, you can browse a file which doesn't have
an entry in the top-level Info menu. It is also handy when you need to
get to the documentation quickly, and you know the exact name of the
file.
There are two special help commands for accessing Emacs documentation
through Info. `C-h C-f FUNCTION ' enters Info and goes straight
to the documentation of the Emacs function FUNCTION. `C-h C-k KEY'
enters Info and goes straight to the documentation of the key KEY.
These two keys run the commands `Info-goto-emacs-command-node' and
`Info-goto-emacs-key-command-node'.
When editing a program, if you have an Info version of the manual for
the programming language, you can use the command `C-h C-i' to refer to
the manual documentation for a symbol (keyword, function or variable).
The details of how this command works depend on the major mode.
If something surprising happens, and you are not sure what commands
you typed, use `C-h l' (`view-lossage'). `C-h l' prints the last 100
command characters you typed in. If you see commands that you don't
know, you can use `C-h c' to find out what they do.
Emacs has numerous major modes, each of which redefines a few keys
and makes a few other changes in how editing works. `C-h m'
(`describe-mode') prints documentation on the current major mode, which
normally describes all the commands that are changed in this mode.
`C-h b' (`describe-bindings') and `C-h s' (`describe-syntax')
present other information about the current Emacs mode. `C-h b'
displays a list of all the key bindings now in effect; the local
bindings defined by the current minor modes first, then the local
bindings defined by the current major mode, and finally the global
bindings (*note Key Bindings::.). `C-h s' displays the contents of the
syntax table, with explanations of each character's syntax (*note
Syntax::.).
You can get a similar list for a particular prefix key by typing
`C-h' after the prefix key. (There are a few prefix keys for which
this does not work--those that provide their own bindings for `C-h'.
One of these is , because ` C-h' is actually `C-M-h', which
marks a defun.)
The other `C-h' options display various files of useful information.
`C-h C-w' displays the full details on the complete absence of
warranty for GNU Emacs. `C-h n' (`view-emacs-news') displays the file
`emacs/etc/NEWS', which contains documentation on Emacs changes
arranged chronologically. `C-h F' (`view-emacs-FAQ') displays the
Emacs frequently-answered-questions list. `C-h t'
(`help-with-tutorial') displays the learn-by-doing Emacs tutorial.
`C-h C-c' (`describe-copying') displays the file `emacs/etc/COPYING',
which tells you the conditions you must obey in distributing copies of
Emacs. `C-h C-d' (`describe-distribution') displays the file
`emacs/etc/DISTRIB', which tells you how you can order a copy of the
latest version of Emacs. `C-h C-p' (`describe-project') displays
general information about the GNU Project.
The Mark and the Region
***********************
Many Emacs commands operate on an arbitrary contiguous part of the
current buffer. To specify the text for such a command to operate on,
you set "the mark" at one end of it, and move point to the other end.
The text between point and the mark is called "the region". Emacs
highlights the region whenever there is one, if you enable Transient
Mark mode (*note Transient Mark::.).
You can move point or the mark to adjust the boundaries of the
region. It doesn't matter which one is set first chronologically, or
which one comes earlier in the text. Once the mark has been set, it
remains where you put it until you set it again at another place. Each
Emacs buffer has its own mark, so that when you return to a buffer that
had been selected previously, it has the same mark it had before.
Many commands that insert text, such as `C-y' (`yank') and `M-x
insert-buffer', position point and the mark at opposite ends of the
inserted text, so that the region contains the text just inserted.
Aside from delimiting the region, the mark is also useful for
remembering a spot that you may want to go back to. To make this
feature more useful, each buffer remembers 16 previous locations of the
mark in the "mark ring".
Setting the Mark
================
Here are some commands for setting the mark:
`C-'
Set the mark where point is (`set-mark-command').
`C-@'
The same.
`C-x C-x'
Interchange mark and point (`exchange-point-and-mark').
`Drag-Mouse-1'
Set point and the mark around the text you drag across.
`Mouse-3'
Set the mark where point is, then move point to where you click
(`mouse-save-then-kill').
For example, suppose you wish to convert part of the buffer to upper
case, using the `C-x C-u' (`upcase-region') command, which operates on
the text in the region. You can first go to the beginning of the text
to be capitalized, type `C-' to put the mark there, move to the
end, and then type `C-x C-u'. Or, you can set the mark at the end of
the text, move to the beginning, and then type `C-x C-u'.
The most common way to set the mark is with the `C-' command
(`set-mark-command'). This sets the mark where point is. Then you can
move point away, leaving the mark behind.
There are two ways to set the mark with the mouse. You can drag
mouse button one across a range of text; that puts point where you
release the mouse button, and sets the mark at the other end of that
range. Or you can click mouse button three, which sets the mark at
point (like `C-') and then moves point (like `Mouse-1'). Both of
these methods copy the region into the kill ring in addition to setting
the mark; that gives behavior consistent with other window-driven
applications, but if you don't want to modify the kill ring, you must
use keyboard commands to set the mark. *Note Mouse Commands::.
Ordinary terminals have only one cursor, so there is no way for Emacs
to show you where the mark is located. You have to remember. The usual
solution to this problem is to set the mark and then use it soon, before
you forget where it is. Alternatively, you can see where the mark is
with the command `C-x C-x' (`exchange-point-and-mark') which puts the
mark where point was and point where the mark was. The extent of the
region is unchanged, but the cursor and point are now at the previous
position of the mark. In Transient Mark mode, this command reactivates
the mark.
`C-x C-x' is also useful when you are satisfied with the position of
point but want to move the other end of the region (where the mark is);
do `C-x C-x' to put point at that end of the region, and then move it.
A second use of `C-x C-x', if necessary, puts the mark at the new
position with point back at its original position.
There is no such character as `C-' in ASCII; when you type
while holding down , what you get on most ordinary
terminals is the character `C-@'. This key is actually bound to
`set-mark-command'. But unless you are unlucky enough to have a
terminal where typing `C-' does not produce `C-@', you might as
well think of this character as `C-'. Under X, `C-' is
actually a distinct character, but its binding is still
`set-mark-command'.
Transient Mark Mode
===================
Emacs can highlight the current region, using X Windows. But
normally it does not. Why not?
Highlighting the region doesn't work well ordinarily in Emacs,
because once you have set a mark, there is *always* a region (in that
buffer). And highlighting the region all the time would be a nuisance.
You can turn on region highlighting by enabling Transient Mark mode.
This is a more rigid mode of operation in which the region "lasts" only
temporarily, so you must set up a region for each command that uses
one. In Transient Mark mode, most of the time there is no region;
therefore, highlighting the region when it exists is convenient.
To enable Transient Mark mode, type `M-x transient-mark-mode'. This
command toggles the mode, so you can repeat the command to turn off the
mode.
Here are the details of Transient Mark mode:
* To set the mark, type `C-' (`set-mark-command'). This makes
the mark active; as you move point, you will see the region
highlighting grow and shrink.
* The mouse commands for specifying the mark also make it active.
So do keyboard commands whose purpose is to specify a region,
including `M-@', `C-M-@', `M-h', `C-M-h', `C-x C-p', and `C-x h'.
* When the mark is active, you can execute commands that operate on
the region, such as killing, indenting, or writing to a file.
* Any change to the buffer, such as inserting or deleting a
character, deactivates the mark. This means any subsequent
command that operates on a region will get an error and refuse to
operate. You can make the region active again by typing `C-x C-x'.
* Commands like `M->' and `C-s' that "leave the mark behind" in
addition to some other primary purpose do not activate the new
mark. You can activate the new region by executing `C-x C-x'
(`exchange-point-and-mark').
* `C-s' when the mark is active does not alter the mark.
* Quitting with `C-g' deactivates the mark.
Highlighting of the region uses the `region' face; you can customize
how the region is highlighted by changing this face. *Note Face
Customization::.
When multiple windows show the same buffer, they can have different
regions, because they can have different values of point (though they
all share one common mark position). Ordinarily, only the selected
window highlights its region (*note Windows::.). However, if the
variable `highlight-nonselected-windows' is non-`nil', then each window
highlights its own region (provided that Transient Mark mode is enabled
and the window's buffer's mark is active).
When Transient Mark mode is not enabled, every command that sets the
mark also activates it, and nothing ever deactivates it.
If the variable `mark-even-if-inactive' is non-`nil' in Transient
Mark mode, then commands can use the mark and the region even when it
is inactive. Region highlighting appears and disappears just as it
normally does in Transient Mark mode, but the mark doesn't really go
away when the highlighting disappears.
Transient Mark mode is also sometimes known as "Zmacs mode" because
the Zmacs editor on the MIT Lisp Machine handled the mark in a similar
way.
Operating on the Region
=======================
Once you have a region and the mark is active, here are some of the
ways you can operate on the region:
* Kill it with `C-w' (*note Killing::.).
* Save it in a register with `C-x r s' (*note Registers::.).
* Save it in a buffer or a file (*note Accumulating Text::.).
* Convert case with `C-x C-l' or `C-x C-u' (*note Case::.).
* Indent it with `C-x ' or `C-M-\' (*note Indentation::.).
* Fill it as text with `M-x fill-region' (*note Filling::.).
* Print hardcopy with `M-x print-region' (*note Hardcopy::.).
* Evaluate it as Lisp code with `M-x eval-region' (*note Lisp
Eval::.).
Most commands that operate on the text in the region have the word
`region' in their names.
Commands to Mark Textual Objects
================================
Here are the commands for placing point and the mark around a textual
object such as a word, list, paragraph or page.
`M-@'
Set mark after end of next word (`mark-word'). This command and
the following one do not move point.
`C-M-@'
Set mark after end of next Lisp expression (`mark-sexp').
`M-h'
Put region around current paragraph (`mark-paragraph').
`C-M-h'
Put region around current Lisp defun (`mark-defun').
`C-x h'
Put region around entire buffer (`mark-whole-buffer').
`C-x C-p'
Put region around current page (`mark-page').
`M-@' (`mark-word') puts the mark at the end of the next word, while
`C-M-@' (`mark-sexp') puts it at the end of the next Lisp expression.
These commands handle arguments just like `M-f' and `C-M-f'.
Other commands set both point and mark, to delimit an object in the
buffer. For example, `M-h' (`mark-paragraph') moves point to the
beginning of the paragraph that surrounds or follows point, and puts
the mark at the end of that paragraph (*note Paragraphs::.). It
prepares the region so you can indent, case-convert, or kill a whole
paragraph.
`C-M-h' (`mark-defun') similarly puts point before and the mark
after the current or following defun (*note Defuns::.). `C-x C-p'
(`mark-page') puts point before the current page, and mark at the end
(*note Pages::.). The mark goes after the terminating page delimiter
(to include it), while point goes after the preceding page delimiter
(to exclude it). A numeric argument specifies a later page (if
positive) or an earlier page (if negative) instead of the current page.
Finally, `C-x h' (`mark-whole-buffer') sets up the entire buffer as
the region, by putting point at the beginning and the mark at the end.
In Transient Mark mode, all of these commands activate the mark.
The Mark Ring
=============
Aside from delimiting the region, the mark is also useful for
remembering a spot that you may want to go back to. To make this
feature more useful, each buffer remembers 16 previous locations of the
mark, in the "mark ring". Commands that set the mark also push the old
mark onto this ring. To return to a marked location, use `C-u C-'
(or `C-u C-@'); this is the command `set-mark-command' given a numeric
argument. It moves point to where the mark was, and restores the mark
from the ring of former marks. Thus, repeated use of this command
moves point to all of the old marks on the ring, one by one. The mark
positions you move through in this way are not lost; they go to the end
of the ring.
Each buffer has its own mark ring. All editing commands use the
current buffer's mark ring. In particular, `C-u C-' always stays
in the same buffer.
Many commands that can move long distances, such as `M-' cycles through the positions currently in the ring.
The variable `mark-ring' holds the mark ring itself, as a list of
marker objects, with the most recent first. This variable is local in
every buffer.
The Global Mark Ring
====================
In addition to the ordinary mark ring that belongs to each buffer,
Emacs has a single "global mark ring". It records a sequence of
buffers in which you have recently set the mark, so you can go back to
those buffers.
Setting the mark always makes an entry on the current buffer's mark
ring. If you have switched buffers since the previous mark setting, the
new mark position makes an entry on the global mark ring also. The
result is that the global mark ring records a sequence of buffers that
you have been in, and, for each buffer, a place where you set the mark.
The command `C-x C-' (`pop-global-mark') jumps to the buffer
and position of the latest entry in the global ring. It also rotates
the ring, so that successive uses of `C-x C-' take you to earlier
and earlier buffers.
Deletion and Killing
====================
Most commands which erase text from the buffer save it in the kill
ring so that you can move or copy it to other parts of the buffer.
These commands are known as "kill" commands. The rest of the commands
that erase text do not save it in the kill ring; they are known as
"delete" commands. (This distinction is made only for erasure of text
in the buffer.) If you do a kill or delete command by mistake, you can
use the `C-x u' (`undo') command to undo it (*note Undo::.).
The delete commands include `C-d' (`delete-char') and
(`delete-backward-char'), which delete only one character at a time,
and those commands that delete only spaces or newlines. Commands that
can destroy significant amounts of nontrivial data generally kill. The
commands' names and individual descriptions use the words `kill' and
`delete' to say which they do.
Deletion
--------
`C-d'
Delete next character (`delete-char').
`'
Delete previous character (`delete-backward-char').
`M-\'
Delete spaces and tabs around point (`delete-horizontal-space').
`M-'
Delete spaces and tabs around point, leaving one space
(`just-one-space').
`C-x C-o'
Delete blank lines around the current line (`delete-blank-lines').
`M-^'
Join two lines by deleting the intervening newline, along with any
indentation following it (`delete-indentation').
The most basic delete commands are `C-d' (`delete-char') and
(`delete-backward-char'). `C-d' deletes the character after point, the
one the cursor is "on top of." This doesn't move point. deletes
the character before the cursor, and moves point back. You can delete
newlines like any other characters in the buffer; deleting a newline
joins two lines. Actually, `C-d' and aren't always delete
commands; when given arguments, they kill instead, since they can erase
more than one character this way.
The other delete commands are those which delete only whitespace
characters: spaces, tabs and newlines. `M-\'
(`delete-horizontal-space') deletes all the spaces and tab characters
before and after point. `M-' (`just-one-space') does likewise but
leaves a single space after point, regardless of the number of spaces
that existed previously (even zero).
`C-x C-o' (`delete-blank-lines') deletes all blank lines after the
current line. If the current line is blank, it deletes all blank lines
preceding the current line as well (leaving one blank line, the current
line).
`M-^' (`delete-indentation') joins the current line and the previous
line, by deleting a newline and all surrounding spaces, usually leaving
a single space. *Note M-^: Indentation.
Killing by Lines
----------------
`C-k'
Kill rest of line or one or more lines (`kill-line').
The simplest kill command is `C-k'. If given at the beginning of a
line, it kills all the text on the line, leaving it blank. When used
on a blank line, it kills the whole line including its newline. To kill
an entire non-blank line, go to the beginning and type `C-k' twice.
More generally, `C-k' kills from point up to the end of the line,
unless it is at the end of a line. In that case it kills the newline
following point, thus merging the next line into the current one.
Spaces and tabs that you can't see at the end of the line are ignored
when deciding which case applies, so if point appears to be at the end
of the line, you can be sure `C-k' will kill the newline.
When `C-k' is given a positive argument, it kills that many lines
and the newlines that follow them (however, text on the current line
before point is spared). With a negative argument -N, it kills N lines
preceding the current line (together with the text on the current line
before point). Thus, `C-u - 2 C-k' at the front of a line kills the
two previous lines.
`C-k' with an argument of zero kills the text before point on the
current line.
If the variable `kill-whole-line' is non-`nil', `C-k' at the very
beginning of a line kills the entire line including the following
newline. This variable is normally `nil'.
Other Kill Commands
-------------------
`C-w'
Kill region (from point to the mark) (`kill-region').
`M-d'
Kill word (`kill-word'). *Note Words::.
`M-'
Kill word backwards (`backward-kill-word').
`C-x '
Kill back to beginning of sentence (`backward-kill-sentence').
*Note Sentences::.
`M-k'
Kill to end of sentence (`kill-sentence').
`C-M-k'
Kill sexp (`kill-sexp'). *Note Lists::.
`M-z CHAR'
Kill through the next occurrence of CHAR (`zap-to-char').
A kill command which is very general is `C-w' (`kill-region'), which
kills everything between point and the mark. With this command, you
can kill any contiguous sequence of characters, if you first set the
region around them.
A convenient way of killing is combined with searching: `M-z'
(`zap-to-char') reads a character and kills from point up to (and
including) the next occurrence of that character in the buffer. A
numeric argument acts as a repeat count. A negative argument means to
search backward and kill text before point.
Other syntactic units can be killed: words, with `M-' and `M-d'
(*note Words::.); sexps, with `C-M-k' (*note Lists::.); and sentences,
with `C-x ' and `M-k' (*note Sentences::.).
You can use kill commands in read-only buffers. They don't actually
change the buffer, and they beep to warn you of that, but they do copy
the text you tried to kill into the kill ring, so you can yank it into
other buffers. Most of the kill commands move point across the text
they copy in this way, so that successive kill commands build up a
single kill ring entry as usual.
Yanking
=======
"Yanking" means reinserting text previously killed. This is what
some systems call "pasting." The usual way to move or copy text is to
kill it and then yank it elsewhere one or more times.
`C-y'
Yank last killed text (`yank').
`M-y'
Replace text just yanked with an earlier batch of killed text
(`yank-pop').
`M-w'
Save region as last killed text without actually killing it
(`kill-ring-save').
`C-M-w'
Append next kill to last batch of killed text (`append-next-kill').
The Kill Ring
-------------
All killed text is recorded in the "kill ring", a list of blocks of
text that have been killed. There is only one kill ring, shared by all
buffers, so you can kill text in one buffer and yank it in another
buffer. This is the usual way to move text from one file to another.
(*Note Accumulating Text::, for some other ways.)
The command `C-y' (`yank') reinserts the text of the most recent
kill. It leaves the cursor at the end of the text. It sets the mark at
the beginning of the text. *Note Mark::.
`C-u C-y' leaves the cursor in front of the text, and sets the mark
after it. This happens only if the argument is specified with just a
`C-u', precisely. Any other sort of argument, including `C-u' and
digits, specifies an earlier kill to yank (*note Earlier Kills::.).
To copy a block of text, you can use `M-w' (`kill-ring-save'), which
copies the region into the kill ring without removing it from the
buffer. This is approximately equivalent to `C-w' followed by `C-x u',
except that `M-w' does not alter the undo history and does not
temporarily change the screen.
Appending Kills
---------------
Normally, each kill command pushes a new entry onto the kill ring.
However, two or more kill commands in a row combine their text into a
single entry, so that a single `C-y' yanks all the text as a unit, just
as it was before it was killed.
Thus, if you want to yank text as a unit, you need not kill all of it
with one command; you can keep killing line after line, or word after
word, until you have killed it all, and you can still get it all back at
once.
Commands that kill forward from point add onto the end of the
previous killed text. Commands that kill backward from point add text
onto the beginning. This way, any sequence of mixed forward and
backward kill commands puts all the killed text into one entry without
rearrangement. Numeric arguments do not break the sequence of
appending kills. For example, suppose the buffer contains this text:
This is a line -!-of sample text.
with point shown by -!-. If you type `M-d M- M-d M-',
killing alternately forward and backward, you end up with `a line of
sample' as one entry in the kill ring, and `This is text.' in the
buffer. (Note the double space, which you can clean up with `M-'
or `M-q'.)
Another way to kill the same text is to move back two words with
`M-b M-b', then kill all four words forward with `C-u M-d'. This
produces exactly the same results in the buffer and in the kill ring.
`M-f M-f C-u M-' kills the same text, all going backward; once
again, the result is the same. The text in the kill ring entry always
has the same order that it had in the buffer before you killed it.
If a kill command is separated from the last kill command by other
commands (not just numeric arguments), it starts a new entry on the kill
ring. But you can force it to append by first typing the command
`C-M-w' (`append-next-kill') right before it. The `C-M-w' tells the
following command, if it is a kill command, to append the text it kills
to the last killed text, instead of starting a new entry. With
`C-M-w', you can kill several separated pieces of text and accumulate
them to be yanked back in one place.
A kill command following `M-w' does not append to the text that
`M-w' copied into the kill ring.
Yanking Earlier Kills
---------------------
To recover killed text that is no longer the most recent kill, use
the `M-y' command (`yank-pop'). It takes the text previously yanked
and replaces it with the text from an earlier kill. So, to recover the
text of the next-to-the-last kill, first use `C-y' to yank the last
kill, and then use `M-y' to replace it with the previous kill. `M-y'
is allowed only after a `C-y' or another `M-y'.
You can understand `M-y' in terms of a "last yank" pointer which
points at an entry in the kill ring. Each time you kill, the "last
yank" pointer moves to the newly made entry at the front of the ring.
`C-y' yanks the entry which the "last yank" pointer points to. `M-y'
moves the "last yank" pointer to a different entry, and the text in the
buffer changes to match. Enough `M-y' commands can move the pointer to
any entry in the ring, so you can get any entry into the buffer.
Eventually the pointer reaches the end of the ring; the next `M-y'
moves it to the first entry again.
`M-y' moves the "last yank" pointer around the ring, but it does not
change the order of the entries in the ring, which always runs from the
most recent kill at the front to the oldest one still remembered.
`M-y' can take a numeric argument, which tells it how many entries
to advance the "last yank" pointer by. A negative argument moves the
pointer toward the front of the ring; from the front of the ring, it
moves "around" to the last entry and continues forward from there.
Once the text you are looking for is brought into the buffer, you can
stop doing `M-y' commands and it will stay there. It's just a copy of
the kill ring entry, so editing it in the buffer does not change what's
in the ring. As long as no new killing is done, the "last yank"
pointer remains at the same place in the kill ring, so repeating `C-y'
will yank another copy of the same previous kill.
If you know how many `M-y' commands it would take to find the text
you want, you can yank that text in one step using `C-y' with a numeric
argument. `C-y' with an argument restores the text the specified
number of entries back in the kill ring. Thus, `C-u 2 C-y' gets the
next-to-the-last block of killed text. It is equivalent to `C-y M-y'.
`C-y' with a numeric argument starts counting from the "last yank"
pointer, and sets the "last yank" pointer to the entry that it yanks.
The length of the kill ring is controlled by the variable
`kill-ring-max'; no more than that many blocks of killed text are saved.
The actual contents of the kill ring are stored in a variable named
`kill-ring'; you can view the entire contents of the kill ring with the
command `C-h v kill-ring'.
Accumulating Text
=================
Usually we copy or move text by killing it and yanking it, but there
are other methods convenient for copying one block of text in many
places, or for copying many scattered blocks of text into one place. To
copy one block to many places, store it in a register (*note
Registers::.). Here we describe the commands to accumulate scattered
pieces of text into a buffer or into a file.
`M-x append-to-buffer'
Append region to contents of specified buffer.
`M-x prepend-to-buffer'
Prepend region to contents of specified buffer.
`M-x copy-to-buffer'
Copy region into specified buffer, deleting that buffer's old
contents.
`M-x insert-buffer'
Insert contents of specified buffer into current buffer at point.
`M-x append-to-file'
Append region to contents of specified file, at the end.
To accumulate text into a buffer, use `M-x append-to-buffer'. This
reads a buffer name, then inserts a copy of the region into the buffer
specified. If you specify a nonexistent buffer, `append-to-buffer'
creates the buffer. The text is inserted wherever point is in that
buffer. If you have been using the buffer for editing, the copied text
goes into the middle of the text of the buffer, wherever point happens
to be in it.
Point in that buffer is left at the end of the copied text, so
successive uses of `append-to-buffer' accumulate the text in the
specified buffer in the same order as they were copied. Strictly
speaking, `append-to-buffer' does not always append to the text already
in the buffer--it appends only if point in that buffer is at the end.
However, if `append-to-buffer' is the only command you use to alter a
buffer, then point is always at the end.
`M-x prepend-to-buffer' is just like `append-to-buffer' except that
point in the other buffer is left before the copied text, so successive
prependings add text in reverse order. `M-x copy-to-buffer' is similar
except that any existing text in the other buffer is deleted, so the
buffer is left containing just the text newly copied into it.
To retrieve the accumulated text from another buffer, use the command
`M-x insert-buffer'; this too takes BUFFERNAME as an argument. It
inserts a copy of the text in buffer BUFFERNAME into the selected
buffer. You can alternatively select the other buffer for editing,
then optionally move text from it by killing. *Note Buffers::, for
background information on buffers.
Instead of accumulating text within Emacs, in a buffer, you can
append text directly into a file with `M-x append-to-file', which takes
FILENAME as an argument. It adds the text of the region to the end of
the specified file. The file is changed immediately on disk.
You should use `append-to-file' only with files that are *not* being
visited in Emacs. Using it on a file that you are editing in Emacs
would change the file behind Emacs's back, which can lead to losing
some of your editing.
Rectangles
==========
The rectangle commands operate on rectangular areas of the text: all
the characters between a certain pair of columns, in a certain range of
lines. Commands are provided to kill rectangles, yank killed
rectangles, clear them out, fill them with blanks or text, or delete
them. Rectangle commands are useful with text in multicolumn formats,
and for changing text into or out of such formats.
When you must specify a rectangle for a command to work on, you do it
by putting the mark at one corner and point at the opposite corner. The
rectangle thus specified is called the "region-rectangle" because you
control it in about the same way the region is controlled. But
remember that a given combination of point and mark values can be
interpreted either as a region or as a rectangle, depending on the
command that uses them.
If point and the mark are in the same column, the rectangle they
delimit is empty. If they are in the same line, the rectangle is one
line high. This asymmetry between lines and columns comes about
because point (and likewise the mark) is between two columns, but within
a line.
`C-x r k'
Kill the text of the region-rectangle, saving its contents as the
"last killed rectangle" (`kill-rectangle').
`C-x r d'
Delete the text of the region-rectangle (`delete-rectangle').
`C-x r y'
Yank the last killed rectangle with its upper left corner at point
(`yank-rectangle').
`C-x r o'
Insert blank space to fill the space of the region-rectangle
(`open-rectangle'). This pushes the previous contents of the
region-rectangle rightward.
`M-x clear-rectangle'
Clear the region-rectangle by replacing its contents with spaces.
`M-x delete-whitespace-rectangle'
Delete whitespace in each of the lines on the specified rectangle,
starting from the left edge column of the rectangle.
`C-x r t STRING '
Insert STRING on each line of the region-rectangle
(`string-rectangle').
The rectangle operations fall into two classes: commands deleting and
inserting rectangles, and commands for blank rectangles.
There are two ways to get rid of the text in a rectangle: you can
discard the text (delete it) or save it as the "last killed" rectangle.
The commands for these two ways are `C-x r d' (`delete-rectangle') and
`C-x r k' (`kill-rectangle'). In either case, the portion of each line
that falls inside the rectangle's boundaries is deleted, causing
following text (if any) on the line to move left into the gap.
Note that "killing" a rectangle is not killing in the usual sense;
the rectangle is not stored in the kill ring, but in a special place
that can only record the most recent rectangle killed. This is because
yanking a rectangle is so different from yanking linear text that
different yank commands have to be used and yank-popping is hard to
make sense of.
To yank the last killed rectangle, type `C-x r y'
(`yank-rectangle'). Yanking a rectangle is the opposite of killing
one. Point specifies where to put the rectangle's upper left corner.
The rectangle's first line is inserted there, the rectangle's second
line is inserted at a position one line vertically down, and so on. The
number of lines affected is determined by the height of the saved
rectangle.
You can convert single-column lists into double-column lists using
rectangle killing and yanking; kill the second half of the list as a
rectangle and then yank it beside the first line of the list. *Note
Two-Column::, for another way to edit multi-column text.
You can also copy rectangles into and out of registers with `C-x r r
R' and `C-x r i R'. *Note Rectangle Registers: RegRect.
There are two commands you can use for making blank rectangles: `M-x
clear-rectangle' which blanks out existing text, and `C-x r o'
(`open-rectangle') which inserts a blank rectangle. Clearing a
rectangle is equivalent to deleting it and then inserting a blank
rectangle of the same size.
The command `M-x delete-whitespace-rectangle' deletes horizontal
whitespace starting from a particular column. This applies to each of
the lines in the rectangle, and the column is specified by the left
edge of the rectangle. The right edge of the rectangle does not make
any difference to this command.
The command `C-x r t' (`M-x string-rectangle') replaces the
rectangle with a specified string (inserted once on each line). The
string's width need not be the same as the width of the rectangle. If
the string's width is less, the text after the rectangle shifts left; if
the string is wider than the rectangle, the text after the rectangle
shifts right.
Registers
*********
Emacs "registers" are places you can save text or positions for
later use. Once you save text or a rectangle in a register, you can
copy it into the buffer once or many times; you can move point to a
position saved in a register once or many times.
Each register has a name which is a single character. A register can
store a piece of text, a rectangle, a position, a window configuration,
or a file name, but only one thing at any given time. Whatever you
store in a register remains there until you store something else in that
register. To see what a register R contains, use `M-x view-register'.
`M-x view-register R'
Display a description of what register R contains.
Saving Positions in Registers
=============================
Saving a position records a place in a buffer so that you can move
back there later. Moving to a saved position switches to that buffer
and moves point to that place in it.
`C-x r R'
Save position of point in register R (`point-to-register').
`C-x r j R'
Jump to the position saved in register R (`jump-to-register').
To save the current position of point in a register, choose a name R
and type `C-x r R'. The register R retains the position thus
saved until you store something else in that register.
The command `C-x r j R' moves point to the position recorded in
register R. The register is not affected; it continues to record the
same position. You can jump to the saved position any number of times.
If you use `C-x r j' to go to a saved position, but the buffer it
was saved from has been killed, `C-x r j' tries to create the buffer
again by visiting the same file. Of course, this works only for buffers
that were visiting files.
Saving Text in Registers
========================
When you want to insert a copy of the same piece of text several
times, it may be inconvenient to yank it from the kill ring, since each
subsequent kill moves that entry further down the ring. An alternative
is to store the text in a register and later retrieve it.
`C-x r s R'
Copy region into register R (`copy-to-register').
`C-x r i R'
Insert text from register R (`insert-register').
`C-x r s R' stores a copy of the text of the region into the
register named R. Given a numeric argument, `C-x r s R' deletes the
text from the buffer as well.
`C-x r i R' inserts in the buffer the text from register R.
Normally it leaves point before the text and places the mark after, but
with a numeric argument (`C-u') it puts point after the text and the
mark before.
Saving Rectangles in Registers
==============================
A register can contain a rectangle instead of linear text. The
rectangle is represented as a list of strings. *Note Rectangles::, for
basic information on how to specify a rectangle in the buffer.
`C-x r r R'
Copy the region-rectangle into register R
(`copy-rectangle-to-register'). With numeric argument, delete it
as well.
`C-x r i R'
Insert the rectangle stored in register R (if it contains a
rectangle) (`insert-register').
The `C-x r i R' command inserts a text string if the register
contains one, and inserts a rectangle if the register contains one.
See also the command `sort-columns', which you can think of as
sorting a rectangle. *Note Sorting::.
Saving Window Configurations in Registers
=========================================
You can save the window configuration of the selected frame in a
register, or even the configuration of all windows in all frames, and
restore the configuration later.
`C-x r w R'
Save the state of the selected frame's windows in register R
(`window-configuration-to-register').
`C-x r f R'
Save the state of all frames, including all their windows, in
register R (`frame-configuration-to-register').
Use `C-x r j R' to restore a window or frame configuration. This is
the same command used to restore a cursor position. When you restore a
frame configuration, any existing frames not included in the
configuration become invisible. If you wish to delete these frames
instead, use `C-u C-x r j R'.
Keeping Numbers in Registers
============================
There are commands to store a number in a register, to insert the
number in the buffer in decimal, and to increment it. These commands
can be useful in keyboard macros (*note Keyboard Macros::.).
`C-u NUMBER C-x r n REG'
Store NUMBER into register REG (`number-to-register').
`C-u NUMBER C-x r + REG'
Increment the number in register REG by NUMBER
(`increment-register').
`C-x r g REG'
Insert the number from register REG into the buffer.
`C-x r g' is the same command used to insert any other sort of
register contents into the buffer.
Keeping File Names in Registers
===============================
If you visit certain file names frequently, you can visit them more
conveniently if you put their names in registers. Here's the Lisp code
used to put a file name in a register:
(set-register ?R '(file . NAME))
For example,
(set-register ?z '(file . "/gd/gnu/emacs/19.0/src/ChangeLog"))
puts the file name shown in register `z'.
To visit the file whose name is in register R, type `C-x r j R'.
(This is the same command used to jump to a position or restore a frame
configuration.)
Bookmarks
=========
"Bookmarks" are somewhat like registers in that they record
positions you can jump to. Unlike registers, they have long names, and
they persist automatically from one Emacs session to the next. The
prototypical use of bookmarks is to record "where you were reading" in
various files.
`C-x r m '
Set the bookmark for the visited file, at point.
`C-x r m BOOKMARK '
Set the bookmark named BOOKMARK at point (`bookmark-set').
`C-x r b BOOKMARK '
Jump to the bookmark named BOOKMARK (`bookmark-jump').
`C-x r l'
List all bookmarks (`list-bookmarks').
`M-x bookmark-save'
Save all the current bookmark values in the default bookmark file.
The prototypical use for bookmarks is to record one current position
in each of several files. So the command `C-x r m', which sets a
bookmark, uses the visited file name as the default for the bookmark
name. If you name each bookmark after the file it points to, then you
can conveniently revisit any of those files with `C-x r b', and move to
the position of the bookmark at the same time.
To display a list of all your bookmarks in a separate buffer, type
`C-x r l' (`list-bookmarks'). If you switch to that buffer, you can
use it to edit your bookmark definitions or annotate the bookmarks.
Type `C-h m' in that buffer for more information about its special
editing commands.
When you kill Emacs, Emacs offers to save your bookmark values in
your default bookmark file, `~/.emacs.bmk', if you have changed any
bookmark values. You can also save the bookmarks at any time with the
`M-x bookmark-save' command. The bookmark commands load your default
bookmark file automatically. This saving and loading is how bookmarks
persist from one Emacs session to the next.
If you set the variable `bookmark-save-flag' to 1, then each command
that sets a bookmark will also save your bookmarks; this way, you don't
lose any bookmark values even if Emacs crashes. (The value, if a
number, says how many bookmark modifications should go by between
saving.)
Bookmark position values are saved with surrounding context, so that
`bookmark-jump' can find the proper position even if the file is
modified slightly. The variable `bookmark-search-size' says how many
characters of context to record, on each side of the bookmark's
position.
Here are some additional commands for working with bookmarks:
`M-x bookmark-load FILENAME '
Load a file named FILENAME that contains a list of bookmark
values. You can use this command, as well as `bookmark-write', to
work with other files of bookmark values in addition to your
default bookmark file.
`M-x bookmark-write FILENAME '
Save all the current bookmark values in the file FILENAME.
`M-x bookmark-delete BOOKMARK '
Delete the bookmark named BOOKMARK.
`M-x bookmark-insert-location BOOKMARK '
Insert in the buffer the name of the file that bookmark BOOKMARK
points to.
`M-x bookmark-insert BOOKMARK '
Insert in the buffer the *contents* of the file that bookmark
BOOKMARK points to.
Controlling the Display
***********************
Since only part of a large buffer fits in the window, Emacs tries to
show a part that is likely to be interesting. Display-control commands
allow you to specify which part of the text you want to see, and how to
display it.
Scrolling
=========
If a buffer contains text that is too large to fit entirely within a
window that is displaying the buffer, Emacs shows a contiguous portion
of the text. The portion shown always contains point.
"Scrolling" means moving text up or down in the window so that
different parts of the text are visible. Scrolling forward means that
text moves up, and new text appears at the bottom. Scrolling backward
moves text down and new text appears at the top.
Scrolling happens automatically if you move point past the bottom or
top of the window. You can also explicitly request scrolling with the
commands in this section.
`C-l'
Clear screen and redisplay, scrolling the selected window to center
point vertically within it (`recenter').
`C-v'
Scroll forward (a windowful or a specified number of lines)
(`scroll-up').
`'
Likewise, scroll forward.
`M-v'
Scroll backward (`scroll-down').
`'
Likewise, scroll backward.
`ARG C-l'
Scroll so point is on line ARG (`recenter').
`C-M-l'
Scroll heuristically to bring useful information onto the screen
(`reposition-window').
The most basic scrolling command is `C-l' (`recenter') with no
argument. It clears the entire screen and redisplays all windows. In
addition, it scrolls the selected window so that point is halfway down
from the top of the window.
The scrolling commands `C-v' and `M-v' let you move all the text in
the window up or down a few lines. `C-v' (`scroll-up') with an
argument shows you that many more lines at the bottom of the window,
moving the text and point up together as `C-l' might. `C-v' with a
negative argument shows you more lines at the top of the window. `M-v'
(`scroll-down') is like `C-v', but moves in the opposite direction.
The function keys and are equivalent to `C-v' and `M-v'.
The names of scroll commands are based on the direction that the text
moves in the window. Thus, the command to scroll forward is called
`scroll-up' because it moves the text upward on the screen.
To read the buffer a windowful at a time, use `C-v' with no argument.
It takes the last two lines at the bottom of the window and puts them at
the top, followed by nearly a whole windowful of lines not previously
visible. If point was in the text scrolled off the top, it moves to the
new top of the window. `M-v' with no argument moves backward with
overlap similarly. The number of lines of overlap across a `C-v' or
`M-v' is controlled by the variable `next-screen-context-lines'; by
default, it is 2.
Some users like the full-screen scroll commands to keep point at the
same screen line. To enable this behavior, set the variable
`scroll-preserve-screen-position' to a non-`nil' value. This mode is
convenient for browsing through a file by scrolling by screenfuls; if
you come back to the screen where you started, point goes back to the
line where it started. However, this mode is inconvenient when you
move to the next screen in order to move point to the text there.
Another way to do scrolling is with `C-l' with a numeric argument.
`C-l' does not clear the screen when given an argument; it only scrolls
the selected window. With a positive argument N, it repositions text
to put point N lines down from the top. An argument of zero puts point
on the very top line. Point does not move with respect to the text;
rather, the text and point move rigidly on the screen. `C-l' with a
negative argument puts point that many lines from the bottom of the
window. For example, `C-u - 1 C-l' puts point on the bottom line, and
`C-u - 5 C-l' puts it five lines from the bottom. Just `C-u' as
argument, as in `C-u C-l', scrolls point to the center of the selected
window.
The `C-M-l' command (`reposition-window') scrolls the current window
heuristically in a way designed to get useful information onto the
screen. For example, in a Lisp file, this command tries to get the
entire current defun onto the screen if possible.
Scrolling happens automatically if point has moved out of the visible
portion of the text when it is time to display. Normally, automatic
scrolling centers point vertically within the window. However, if you
set `scroll-conservatively' to a small number N, then if you move point
just a little off the screen--less than N lines--then Emacs scrolls the
text just far enough to bring point back on screen. By default,
`scroll-conservatively' is 0.
The variable `scroll-margin' restricts how close point can come to
the top or bottom of a window. Its value is a number of screen lines;
if point comes within that many lines of the top or bottom of the
window, Emacs recenters the window. By default, `scroll-margin' is 0.
Horizontal Scrolling
====================
"Horizontal scrolling" means shifting all the lines sideways within
a window--so that some of the text near the left margin is not
displayed at all.
`C-x '
Scroll to the right (`scroll-right').
When a window has been scrolled horizontally, text lines are
truncated rather than continued (*note Continuation Lines::.), with a
`$' appearing in the first column when there is text truncated to the
left, and in the last column when there is text truncated to the right.
The command `C-x ' (`scroll-right') scrolls similarly to the right. The window
cannot be scrolled any farther to the right once it is displayed
normally (with each line starting at the window's left margin);
attempting to do so has no effect. This means that you don't have to
calculate the argument precisely for `C-x >'; any sufficiently large
argument will restore the normal display.
You can request automatic horizontal scrolling by enabling Hscroll
mode. When this mode is enabled, Emacs scrolls a window horizontally
whenever that is necessary to keep point visible and not too far from
the left or right edge. The command to enable or disable this mode is
`M-x hscroll-mode'.
Follow Mode
===========
"Follow mode" is a minor mode that makes two windows showing the
same buffer scroll as one tall "virtual window." To use Follow mode,
go to a frame with just one window, split it into two side-by-side
windows using `C-x 3', and then type `M-x follow-mode'. From then on,
you can edit the buffer in either of the two windows, or scroll either
one; the other window follows it.
To turn off Follow mode, type `M-x follow-mode' a second time.
Selective Display
=================
Emacs has the ability to hide lines indented more than a certain
number of columns (you specify how many columns). You can use this to
get an overview of a part of a program.
To hide lines, type `C-x $' (`set-selective-display') with a numeric
argument N. Then lines with at least N columns of indentation
disappear from the screen. The only indication of their presence is
that three dots (`...') appear at the end of each visible line that is
followed by one or more hidden ones.
The commands `C-n' and `C-p' move across the hidden lines as if they
were not there.
The hidden lines are still present in the buffer, and most editing
commands see them as usual, so you may find point in the middle of the
hidden text. When this happens, the cursor appears at the end of the
previous line, after the three dots. If point is at the end of the
visible line, before the newline that ends it, the cursor appears before
the three dots.
To make all lines visible again, type `C-x $' with no argument.
If you set the variable `selective-display-ellipses' to `nil', the
three dots do not appear at the end of a line that precedes hidden
lines. Then there is no visible indication of the hidden lines. This
variable becomes local automatically when set.
Optional Mode Line Features
===========================
The current line number of point appears in the mode line when Line
Number mode is enabled. Use the command `M-x line-number-mode' to turn
this mode on and off; normally it is on. The line number appears
before the buffer percentage POS, with the letter `L' to indicate what
it is. *Note Minor Modes::, for more information about minor modes and
about how to use this command.
If the buffer is very large (larger than the value of
`line-number-display-limit'), then the line number doesn't appear.
Emacs doesn't compute the line number when the buffer is large, because
that would be too slow. If you have narrowed the buffer (*note
Narrowing::.), the displayed line number is relative to the accessible
portion of the buffer.
You can also display the current column number by turning on Column
Number mode. It displays the current column number preceded by the
letter `C'. Type `M-x column-number-mode' to toggle this mode.
Emacs can optionally display the time and system load in all mode
lines. To enable this feature, type `M-x display-time'. The
information added to the mode line usually appears after the buffer
name, before the mode names and their parentheses. It looks like this:
HH:MMpm L.LL
Here HH and MM are the hour and minute, followed always by `am' or
`pm'. L.LL is the average number of running processes in the whole
system recently. (Some fields may be missing if your operating system
cannot support them.) If you prefer time display in 24-hour format,
set the variable `display-time-24hr-format' to `t'.
The word `Mail' appears after the load level if there is mail for
you that you have not read yet.
How Text Is Displayed
=====================
ASCII printing characters (octal codes 040 through 0176) in Emacs
buffers are displayed with their graphics. So are non-ASCII multibyte
printing characters (octal codes above 0400).
Some ASCII control characters are displayed in special ways. The
newline character (octal code 012) is displayed by starting a new line.
The tab character (octal code 011) is displayed by moving to the next
tab stop column (normally every 8 columns).
Other ASCII control characters are normally displayed as a caret
(`^') followed by the non-control version of the character; thus,
control-A is displayed as `^A'.
Non-ASCII characters 0200 through 0377 are displayed with octal
escape sequences; thus, character code 0243 (octal) is displayed as
`\243'. However, if you enable European display, most of these
characters become non-ASCII printing characters, and are displayed using
their graphics (assuming your terminal supports them). *Note
Single-Byte European Support::.
Variables Controlling Display
=============================
This section contains information for customization only. Beginning
users should skip it.
The variable `mode-line-inverse-video' controls whether the mode
line is displayed in inverse video (assuming the terminal supports it);
`nil' means don't do so. *Note Mode Line::. If you specify the
foreground color for the `modeline' face, and `mode-line-inverse-video'
is non-`nil', then the default background color for that face is the
usual foreground color. *Note Faces::.
If the variable `inverse-video' is non-`nil', Emacs attempts to
invert all the lines of the display from what they normally are.
If the variable `visible-bell' is non-`nil', Emacs attempts to make
the whole screen blink when it would normally make an audible bell
sound. This variable has no effect if your terminal does not have a way
to make the screen blink.
When you reenter Emacs after suspending, Emacs normally clears the
screen and redraws the entire display. On some terminals with more than
one page of memory, it is possible to arrange the termcap entry so that
the `ti' and `te' strings (output to the terminal when Emacs is entered
and exited, respectively) switch between pages of memory so as to use
one page for Emacs and another page for other output. Then you might
want to set the variable `no-redraw-on-reenter' non-`nil'; this tells
Emacs to assume, when resumed, that the screen page it is using still
contains what Emacs last wrote there.
The variable `echo-keystrokes' controls the echoing of
multi-character keys; its value is the number of seconds of pause
required to cause echoing to start, or zero meaning don't echo at all.
*Note Echo Area::.
If the variable `ctl-arrow' is `nil', control characters in the
buffer are displayed with octal escape sequences, except for newline
and tab. Altering the value of `ctl-arrow' makes it local to the
current buffer; until that time, the default value is in effect. The
default is initially `t'. *Note Display Tables: (elisp)Display Tables.
Normally, a tab character in the buffer is displayed as whitespace
which extends to the next display tab stop position, and display tab
stops come at intervals equal to eight spaces. The number of spaces
per tab is controlled by the variable `tab-width', which is made local
by changing it, just like `ctl-arrow'. Note that how the tab character
in the buffer is displayed has nothing to do with the definition of
as a command. The variable `tab-width' must have an integer
value between 1 and 1000, inclusive.
If the variable `truncate-lines' is non-`nil', then each line of
text gets just one screen line for display; if the text line is too
long, display shows only the part that fits. If `truncate-lines' is
`nil', then long text lines display as more than one screen line,
enough to show the whole text of the line. *Note Continuation Lines::.
Altering the value of `truncate-lines' makes it local to the current
buffer; until that time, the default value is in effect. The default
is initially `nil'.
If the variable `truncate-partial-width-windows' is non-`nil', it
forces truncation rather than continuation in any window less than the
full width of the screen or frame, regardless of the value of
`truncate-lines'. For information about side-by-side windows, see
*Note Split Window::. See also *Note Display: (elisp)Display.
The variable `baud-rate' holds the output speed of the terminal, as
far as Emacs knows. Setting this variable does not change the speed of
actual data transmission, but the value is used for calculations such
as padding. It also affects decisions about whether to scroll part of
the screen or redraw it instead--even when using a window system. (We
designed it this way, despite the fact that a window system has no true
"output speed," to give you a way to tune these decisions.)
You can customize the way any particular character code is displayed
by means of a display table. *Note Display Tables: (elisp)Display
Tables.
Searching and Replacement
*************************
Like other editors, Emacs has commands for searching for occurrences
of a string. The principal search command is unusual in that it is
"incremental"; it begins to search before you have finished typing the
search string. There are also nonincremental search commands more like
those of other editors.
Besides the usual `replace-string' command that finds all
occurrences of one string and replaces them with another, Emacs has a
fancy replacement command called `query-replace' which asks
interactively which occurrences to replace.
Incremental Search
==================
An incremental search begins searching as soon as you type the first
character of the search string. As you type in the search string, Emacs
shows you where the string (as you have typed it so far) would be
found. When you have typed enough characters to identify the place you
want, you can stop. Depending on what you plan to do next, you may or
may not need to terminate the search explicitly with .
`C-s'
Incremental search forward (`isearch-forward').
`C-r'
Incremental search backward (`isearch-backward').
`C-s' starts an incremental search. `C-s' reads characters from the
keyboard and positions the cursor at the first occurrence of the
characters that you have typed. If you type `C-s' and then `F', the
cursor moves right after the first `F'. Type an `O', and see the
cursor move to after the first `FO'. After another `O', the cursor is
after the first `FOO' after the place where you started the search. At
each step, the buffer text that matches the search string is
highlighted, if the terminal can do that; at each step, the current
search string is updated in the echo area.
If you make a mistake in typing the search string, you can cancel
characters with . Each cancels the last character of search
string. This does not happen until Emacs is ready to read another
input character; first it must either find, or fail to find, the
character you want to erase. If you do not want to wait for this to
happen, use `C-g' as described below.
When you are satisfied with the place you have reached, you can type
, which stops searching, leaving the cursor where the search
brought it. Also, any command not specially meaningful in searches
stops the searching and is then executed. Thus, typing `C-a' would
exit the search and then move to the beginning of the line. is
necessary only if the next command you want to type is a printing
character, , , or another control character that is special
within searches (`C-q', `C-w', `C-r', `C-s', `C-y', `M-y', `M-r', or
`M-s').
Sometimes you search for `FOO' and find it, but not the one you
expected to find. There was a second `FOO' that you forgot about,
before the one you were aiming for. In this event, type another `C-s'
to move to the next occurrence of the search string. This can be done
any number of times. If you overshoot, you can cancel some `C-s'
characters with .
After you exit a search, you can search for the same string again by
typing just `C-s C-s': the first `C-s' is the key that invokes
incremental search, and the second `C-s' means "search again."
To reuse earlier search strings, use the "search ring". The
commands `M-p' and `M-n' move through the ring to pick a search string
to reuse. These commands leave the selected search ring element in the
minibuffer, where you can edit it. Type `C-s' or `C-r' to terminate
editing the string and search for it.
If your string is not found at all, the echo area says `Failing
I-Search'. The cursor is after the place where Emacs found as much of
your string as it could. Thus, if you search for `FOOT', and there is
no `FOOT', you might see the cursor after the `FOO' in `FOOL'. At this
point there are several things you can do. If your string was
mistyped, you can rub some of it out and correct it. If you like the
place you have found, you can type or some other Emacs command to
"accept what the search offered." Or you can type `C-g', which removes
from the search string the characters that could not be found (the `T'
in `FOOT'), leaving those that were found (the `FOO' in `FOOT'). A
second `C-g' at that point cancels the search entirely, returning point
to where it was when the search started.
An upper-case letter in the search string makes the search
case-sensitive. If you delete the upper-case character from the search
string, it ceases to have this effect. *Note Search Case::.
If a search is failing and you ask to repeat it by typing another
`C-s', it starts again from the beginning of the buffer. Repeating a
failing reverse search with `C-r' starts again from the end. This is
called "wrapping around". `Wrapped' appears in the search prompt once
this has happened. If you keep on going past the original starting
point of the search, it changes to `Overwrapped', which means that you
are revisiting matches that you have already seen.
The `C-g' "quit" character does special things during searches; just
what it does depends on the status of the search. If the search has
found what you specified and is waiting for input, `C-g' cancels the
entire search. The cursor moves back to where you started the search.
If `C-g' is typed when there are characters in the search string that
have not been found--because Emacs is still searching for them, or
because it has failed to find them--then the search string characters
which have not been found are discarded from the search string. With
them gone, the search is now successful and waiting for more input, so
a second `C-g' will cancel the entire search.
To search for a newline, type `C-j'. To search for another control
character, such as control-S or carriage return, you must quote it by
typing `C-q' first. This function of `C-q' is analogous to its use for
insertion (*note Inserting Text::.): it causes the following character
to be treated the way any "ordinary" character is treated in the same
context. You can also specify a character by its octal code: enter
`C-q' followed by a sequence of octal digits.
You can change to searching backwards with `C-r'. If a search fails
because the place you started was too late in the file, you should do
this. Repeated `C-r' keeps looking for more occurrences backwards. A
`C-s' starts going forwards again. `C-r' in a search can be canceled
with .
If you know initially that you want to search backwards, you can use
`C-r' instead of `C-s' to start the search, because `C-r' as a key runs
a command (`isearch-backward') to search backward. A backward search
finds matches that are entirely before the starting point, just as a
forward search finds matches that begin after it.
The characters `C-y' and `C-w' can be used in incremental search to
grab text from the buffer into the search string. This makes it
convenient to search for another occurrence of text at point. `C-w'
copies the word after point as part of the search string, advancing
point over that word. Another `C-s' to repeat the search will then
search for a string including that word. `C-y' is similar to `C-w' but
copies all the rest of the current line into the search string. Both
`C-y' and `C-w' convert the text they copy to lower case if the search
is currently not case-sensitive; this is so the search remains
case-insensitive.
The character `M-y' copies text from the kill ring into the search
string. It uses the same text that `C-y' as a command would yank.
*Note Yanking::.
When you exit the incremental search, it sets the mark to where point
*was*, before the search. That is convenient for moving back there.
In Transient Mark mode, incremental search sets the mark without
activating it, and does so only if the mark is not already active.
To customize the special characters that incremental search
understands, alter their bindings in the keymap `isearch-mode-map'.
For a list of bindings, look at the documentation of `isearch-mode' with
`C-h f isearch-mode '.
Slow Terminal Incremental Search
--------------------------------
Incremental search on a slow terminal uses a modified style of
display that is designed to take less time. Instead of redisplaying
the buffer at each place the search gets to, it creates a new
single-line window and uses that to display the line that the search
has found. The single-line window comes into play as soon as point
gets outside of the text that is already on the screen.
When you terminate the search, the single-line window is removed.
Then Emacs redisplays the window in which the search was done, to show
its new position of point.
The slow terminal style of display is used when the terminal baud
rate is less than or equal to the value of the variable
`search-slow-speed', initially 1200.
The number of lines to use in slow terminal search display is
controlled by the variable `search-slow-window-lines'. Its normal
value is 1.
Nonincremental Search
=====================
Emacs also has conventional nonincremental search commands, which
require you to type the entire search string before searching begins.
`C-s STRING '
Search for STRING.
`C-r STRING '
Search backward for STRING.
To do a nonincremental search, first type `C-s '. This enters
the minibuffer to read the search string; terminate the string with
, and then the search takes place. If the string is not found,
the search command gets an error.
The way `C-s ' works is that the `C-s' invokes incremental
search, which is specially programmed to invoke nonincremental search
if the argument you give it is empty. (Such an empty argument would
otherwise be useless.) `C-r ' also works this way.
However, nonincremental searches performed using `C-s ' do not
call `search-forward' right away. The first thing done is to see if
the next character is `C-w', which requests a word search. *Note Word
Search::.
Forward and backward nonincremental searches are implemented by the
commands `search-forward' and `search-backward'. These commands may be
bound to keys in the usual manner. The feature that you can get to
them via the incremental search commands exists for historical reasons,
and to avoid the need to find suitable key sequences for them.
Word Search
===========
Word search searches for a sequence of words without regard to how
the words are separated. More precisely, you type a string of many
words, using single spaces to separate them, and the string can be
found even if there are multiple spaces, newlines or other punctuation
between the words.
Word search is useful for editing a printed document made with a text
formatter. If you edit while looking at the printed, formatted version,
you can't tell where the line breaks are in the source file. With word
search, you can search without having to know them.
`C-s C-w WORDS '
Search for WORDS, ignoring details of punctuation.
`C-r C-w WORDS '
Search backward for WORDS, ignoring details of punctuation.
Word search is a special case of nonincremental search and is invoked
with `C-s C-w'. This is followed by the search string, which
must always be terminated with . Being nonincremental, this
search does not start until the argument is terminated. It works by
constructing a regular expression and searching for that; see *Note
Regexp Search::.
Use `C-r C-w' to do backward word search.
Forward and backward word searches are implemented by the commands
`word-search-forward' and `word-search-backward'. These commands may
be bound to keys in the usual manner. The feature that you can get to
them via the incremental search commands exists for historical reasons,
and to avoid the need to find suitable key sequences for them.
Regular Expression Search
=========================
A "regular expression" ("regexp", for short) is a pattern that
denotes a class of alternative strings to match, possibly infinitely
many. In GNU Emacs, you can search for the next match for a regexp
either incrementally or not.
Incremental search for a regexp is done by typing `C-M-s'
(`isearch-forward-regexp'). This command reads a search string
incrementally just like `C-s', but it treats the search string as a
regexp rather than looking for an exact match against the text in the
buffer. Each time you add text to the search string, you make the
regexp longer, and the new regexp is searched for. Invoking `C-s' with
a prefix argument (its value does not matter) is another way to do a
forward incremental regexp search. To search backward for a regexp,
use `C-M-r' (`isearch-backward-regexp'), or `C-r' with a prefix
argument.
All of the control characters that do special things within an
ordinary incremental search have the same function in incremental regexp
search. Typing `C-s' or `C-r' immediately after starting the search
retrieves the last incremental search regexp used; that is to say,
incremental regexp and non-regexp searches have independent defaults.
They also have separate search rings that you can access with `M-p' and
`M-n'.
If you type in incremental regexp search, it matches any
sequence of whitespace characters, including newlines. If you want to
match just a space, type `C-q '.
Note that adding characters to the regexp in an incremental regexp
search can make the cursor move back and start again. For example, if
you have searched for `foo' and you add `\|bar', the cursor backs up in
case the first `bar' precedes the first `foo'.
Nonincremental search for a regexp is done by the functions
`re-search-forward' and `re-search-backward'. You can invoke these
with `M-x', or bind them to keys, or invoke them by way of incremental
regexp search with `C-M-s ' and `C-M-r '.
If you use the incremental regexp search commands with a prefix
argument, they perform ordinary string search, like `isearch-forward'
and `isearch-backward'. *Note Incremental Search::.
Syntax of Regular Expressions
=============================
Regular expressions have a syntax in which a few characters are
special constructs and the rest are "ordinary". An ordinary character
is a simple regular expression which matches that same character and
nothing else. The special characters are `$', `^', `.', `*', `+', `?',
`[', `]' and `\'. Any other character appearing in a regular
expression is ordinary, unless a `\' precedes it.
For example, `f' is not a special character, so it is ordinary, and
therefore `f' is a regular expression that matches the string `f' and
no other string. (It does *not* match the string `ff'.) Likewise, `o'
is a regular expression that matches only `o'. (When case distinctions
are being ignored, these regexps also match `F' and `O', but we
consider this a generalization of "the same string," rather than an
exception.)
Any two regular expressions A and B can be concatenated. The result
is a regular expression which matches a string if A matches some amount
of the beginning of that string and B matches the rest of the string.
As a simple example, we can concatenate the regular expressions `f'
and `o' to get the regular expression `fo', which matches only the
string `fo'. Still trivial. To do something nontrivial, you need to
use one of the special characters. Here is a list of them.
`. (Period)'
is a special character that matches any single character except a
newline. Using concatenation, we can make regular expressions
like `a.b', which matches any three-character string that begins
with `a' and ends with `b'.
`*'
is not a construct by itself; it is a postfix operator that means
to match the preceding regular expression repetitively as many
times as possible. Thus, `o*' matches any number of `o's
(including no `o's).
`*' always applies to the *smallest* possible preceding
expression. Thus, `fo*' has a repeating `o', not a repeating
`fo'. It matches `f', `fo', `foo', and so on.
The matcher processes a `*' construct by matching, immediately, as
many repetitions as can be found. Then it continues with the rest
of the pattern. If that fails, backtracking occurs, discarding
some of the matches of the `*'-modified construct in case that
makes it possible to match the rest of the pattern. For example,
in matching `ca*ar' against the string `caaar', the `a*' first
tries to match all three `a's; but the rest of the pattern is `ar'
and there is only `r' left to match, so this try fails. The next
alternative is for `a*' to match only two `a's. With this choice,
the rest of the regexp matches successfully.
`+'
is a postfix operator, similar to `*' except that it must match
the preceding expression at least once. So, for example, `ca+r'
matches the strings `car' and `caaaar' but not the string `cr',
whereas `ca*r' matches all three strings.
`?'
is a postfix operator, similar to `*' except that it can match the
preceding expression either once or not at all. For example,
`ca?r' matches `car' or `cr'; nothing else.
`[ ... ]'
is a "character set", which begins with `[' and is terminated by
`]'. In the simplest case, the characters between the two
brackets are what this set can match.
Thus, `[ad]' matches either one `a' or one `d', and `[ad]*'
matches any string composed of just `a's and `d's (including the
empty string), from which it follows that `c[ad]*r' matches `cr',
`car', `cdr', `caddaar', etc.
You can also include character ranges in a character set, by
writing the starting and ending characters with a `-' between
them. Thus, `[a-z]' matches any lower-case ASCII letter. Ranges
may be intermixed freely with individual characters, as in
`[a-z$%.]', which matches any lower-case ASCII letter or `$', `%'
or period.
Note that the usual regexp special characters are not special
inside a character set. A completely different set of special
characters exists inside character sets: `]', `-' and `^'.
To include a `]' in a character set, you must make it the first
character. For example, `[]a]' matches `]' or `a'. To include a
`-', write `-' as the first or last character of the set, or put
it after a range. Thus, `[]-]' matches both `]' and `-'.
To include `^' in a set, put it anywhere but at the beginning of
the set.
When you use a range in case-insensitive search, you should write
both ends of the range in upper case, or both in lower case, or
both should be non-letters. The behavior of a mixed-case range
such as `A-z' is somewhat ill-defined, and it may change in future
Emacs versions.
`[^ ... ]'
`[^' begins a "complemented character set", which matches any
character except the ones specified. Thus, `[^a-z0-9A-Z]' matches
all characters *except* letters and digits.
`^' is not special in a character set unless it is the first
character. The character following the `^' is treated as if it
were first (in other words, `-' and `]' are not special there).
A complemented character set can match a newline, unless newline is
mentioned as one of the characters not to match. This is in
contrast to the handling of regexps in programs such as `grep'.
`^'
is a special character that matches the empty string, but only at
the beginning of a line in the text being matched. Otherwise it
fails to match anything. Thus, `^foo' matches a `foo' that occurs
at the beginning of a line.
`$'
is similar to `^' but matches only at the end of a line. Thus,
`x+$' matches a string of one `x' or more at the end of a line.
`\'
has two functions: it quotes the special characters (including
`\'), and it introduces additional special constructs.
Because `\' quotes special characters, `\$' is a regular
expression that matches only `$', and `\[' is a regular expression
that matches only `[', and so on.
Note: for historical compatibility, special characters are treated as
ordinary ones if they are in contexts where their special meanings make
no sense. For example, `*foo' treats `*' as ordinary since there is no
preceding expression on which the `*' can act. It is poor practice to
depend on this behavior; it is better to quote the special character
anyway, regardless of where it appears.
For the most part, `\' followed by any character matches only that
character. However, there are several exceptions: two-character
sequences starting with `\' that have special meanings. The second
character in the sequence is always an ordinary character when used on
its own. Here is a table of `\' constructs.
`\|'
specifies an alternative. Two regular expressions A and B with
`\|' in between form an expression that matches some text if
either A matches it or B matches it. It works by trying to match
A, and if that fails, by trying to match B.
Thus, `foo\|bar' matches either `foo' or `bar' but no other string.
`\|' applies to the largest possible surrounding expressions.
Only a surrounding `\( ... \)' grouping can limit the grouping
power of `\|'.
Full backtracking capability exists to handle multiple uses of
`\|'.
`\( ... \)'
is a grouping construct that serves three purposes:
1. To enclose a set of `\|' alternatives for other operations.
Thus, `\(foo\|bar\)x' matches either `foox' or `barx'.
2. To enclose a complicated expression for the postfix operators
`*', `+' and `?' to operate on. Thus, `ba\(na\)*' matches
`bananana', etc., with any (zero or more) number of `na'
strings.
3. To record a matched substring for future reference.
This last application is not a consequence of the idea of a
parenthetical grouping; it is a separate feature that is assigned
as a second meaning to the same `\( ... \)' construct. In practice
there is no conflict between the two meanings.
`\D'
matches the same text that matched the Dth occurrence of a `\( ...
\)' construct.
After the end of a `\( ... \)' construct, the matcher remembers
the beginning and end of the text matched by that construct. Then,
later on in the regular expression, you can use `\' followed by the
digit D to mean "match the same text matched the Dth time by the
`\( ... \)' construct."
The strings matching the first nine `\( ... \)' constructs
appearing in a regular expression are assigned numbers 1 through 9
in the order that the open-parentheses appear in the regular
expression. So you can use `\1' through `\9' to refer to the text
matched by the corresponding `\( ... \)' constructs.
For example, `\(.*\)\1' matches any newline-free string that is
composed of two identical halves. The `\(.*\)' matches the first
half, which may be anything, but the `\1' that follows must match
the same exact text.
If a particular `\( ... \)' construct matches more than once
(which can easily happen if it is followed by `*'), only the last
match is recorded.
`\`'
matches the empty string, but only at the beginning of the buffer
or string being matched against.
`\''
matches the empty string, but only at the end of the buffer or
string being matched against.
`\='
matches the empty string, but only at point.
`\b'
matches the empty string, but only at the beginning or end of a
word. Thus, `\bfoo\b' matches any occurrence of `foo' as a
separate word. `\bballs?\b' matches `ball' or `balls' as a
separate word.
`\b' matches at the beginning or end of the buffer regardless of
what text appears next to it.
`\B'
matches the empty string, but *not* at the beginning or end of a
word.
`\'
matches the empty string, but only at the end of a word. `\>'
matches at the end of the buffer only if the contents end with a
word-constituent character.
`\w'
matches any word-constituent character. The syntax table
determines which characters these are. *Note Syntax::.
`\W'
matches any character that is not a word-constituent.
`\sC'
matches any character whose syntax is C. Here C is a character
that represents a syntax code: thus, `w' for word constituent, `-'
for whitespace, `(' for open parenthesis, etc. Represent a
character of whitespace (which can be a newline) by either `-' or
a space character.
`\SC'
matches any character whose syntax is not C.
The constructs that pertain to words and syntax are controlled by the
setting of the syntax table (*note Syntax::.).
Here is a complicated regexp, used by Emacs to recognize the end of a
sentence together with any whitespace that follows. It is given in Lisp
syntax to enable you to distinguish the spaces from the tab characters.
In Lisp syntax, the string constant begins and ends with a
double-quote. `\"' stands for a double-quote as part of the regexp,
`\\' for a backslash as part of the regexp, `\t' for a tab and `\n' for
a newline.
"[.?!][]\"')]*\\($\\|\t\\| \\)[ \t\n]*"
This contains four parts in succession: a character set matching period,
`?', or `!'; a character set matching close-brackets, quotes, or
parentheses, repeated any number of times; an alternative in
backslash-parentheses that matches end-of-line, a tab, or two spaces;
and a character set matching whitespace characters, repeated any number
of times.
To enter the same regexp interactively, you would type to
enter a tab, and `C-j' to enter a newline. You would also type single
backslashes as themselves, instead of doubling them for Lisp syntax.
Searching and Case
==================
Incremental searches in Emacs normally ignore the case of the text
they are searching through, if you specify the text in lower case.
Thus, if you specify searching for `foo', then `Foo' and `foo' are also
considered a match. Regexps, and in particular character sets, are
included: `[ab]' would match `a' or `A' or `b' or `B'.
An upper-case letter anywhere in the incremental search string makes
the search case-sensitive. Thus, searching for `Foo' does not find
`foo' or `FOO'. This applies to regular expression search as well as
to string search. The effect ceases if you delete the upper-case
letter from the search string.
If you set the variable `case-fold-search' to `nil', then all
letters must match exactly, including case. This is a per-buffer
variable; altering the variable affects only the current buffer, but
there is a default value which you can change as well. *Note Locals::.
This variable applies to nonincremental searches also, including those
performed by the replace commands (*note Replace::.) and the minibuffer
history matching commands (*note Minibuffer History::.).
Replacement Commands
====================
Global search-and-replace operations are not needed as often in Emacs
as they are in other editors(1), but they are available. In addition
to the simple `M-x replace-string' command which is like that found in
most editors, there is a `M-x query-replace' command which asks you, for
each occurrence of the pattern, whether to replace it.
The replace commands normally operate on the text from point to the
end of the buffer; however, in Transient Mark mode, when the mark is
active, they operate on the region. The replace commands all replace
one string (or regexp) with one replacement string. It is possible to
perform several replacements in parallel using the command
`expand-region-abbrevs' (*note Expanding Abbrevs::.).
---------- Footnotes ----------
(1) In some editors, search-and-replace operations are the only
convenient way to make a single change in the text.
Unconditional Replacement
-------------------------
`M-x replace-string STRING NEWSTRING '
Replace every occurrence of STRING with NEWSTRING.
`M-x replace-regexp REGEXP NEWSTRING '
Replace every match for REGEXP with NEWSTRING.
To replace every instance of `foo' after point with `bar', use the
command `M-x replace-string' with the two arguments `foo' and `bar'.
Replacement happens only in the text after point, so if you want to
cover the whole buffer you must go to the beginning first. All
occurrences up to the end of the buffer are replaced; to limit
replacement to part of the buffer, narrow to that part of the buffer
before doing the replacement (*note Narrowing::.). In Transient Mark
mode, when the region is active, replacement is limited to the region
(*note Transient Mark::.).
When `replace-string' exits, it leaves point at the last occurrence
replaced. It sets the mark to the prior position of point (where the
`replace-string' command was issued); use `C-u C-' to move back
there.
A numeric argument restricts replacement to matches that are
surrounded by word boundaries. The argument's value doesn't matter.
Regexp Replacement
------------------
The `M-x replace-string' command replaces exact matches for a single
string. The similar command `M-x replace-regexp' replaces any match
for a specified pattern.
In `replace-regexp', the NEWSTRING need not be constant: it can
refer to all or part of what is matched by the REGEXP. `\&' in
NEWSTRING stands for the entire match being replaced. `\D' in
NEWSTRING, where D is a digit, stands for whatever matched the Dth
parenthesized grouping in REGEXP. To include a `\' in the text to
replace with, you must enter `\\'. For example,
M-x replace-regexp c[ad]+r \&-safe
replaces (for example) `cadr' with `cadr-safe' and `cddr' with
`cddr-safe'.
M-x replace-regexp \(c[ad]+r\)-safe \1
performs the inverse transformation.
Replace Commands and Case
-------------------------
If the first argument of a replace command is all lower case, the
commands ignores case while searching for occurrences to
replace--provided `case-fold-search' is non-`nil'. If
`case-fold-search' is set to `nil', case is always significant in all
searches.
In addition, when the NEWSTRING argument is all or partly lower
case, replacement commands try to preserve the case pattern of each
occurrence. Thus, the command
M-x replace-string foo bar