This is ../info/emacs, produced by makeinfo version 4.11 from
emacs.texi.

This is the Sixteenth edition of the `GNU Emacs Manual',
updated for Emacs version 22.3.

   Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998,
1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free
Software Foundation, Inc.

     Permission is granted to copy, distribute and/or modify this
     document under the terms of the GNU Free Documentation License,
     Version 1.2 or any later version published by the Free Software
     Foundation; with the Invariant Sections being "The GNU Manifesto,"
     "Distribution" and "GNU GENERAL PUBLIC LICENSE," with the
     Front-Cover texts being "A GNU Manual," and with the Back-Cover
     Texts as in (a) below.  A copy of the license is included in the
     section entitled "GNU Free Documentation License."

     (a) The FSF's Back-Cover Text is: "You are free to copy and modify
     this GNU Manual. Buying copies from GNU Press supports the FSF in
     developing GNU and promoting software freedom."

INFO-DIR-SECTION Emacs
START-INFO-DIR-ENTRY
* Emacs: (emacs).	The extensible self-documenting text editor.
END-INFO-DIR-ENTRY


File: emacs,  Node: From Other Calendar,  Next: Mayan Calendar,  Prev: To Other Calendar,  Up: Other Calendars

39.9.3 Converting From Other Calendars
--------------------------------------

You can use the other supported calendars to specify a date to move to.
This section describes the commands for doing this using calendars
other than Mayan; for the Mayan calendar, see the following section.

`g c'
     Move to a date specified in the ISO commercial calendar
     (`calendar-goto-iso-date').

`g w'
     Move to a week specified in the ISO commercial calendar
     (`calendar-goto-iso-week').

`g j'
     Move to a date specified in the Julian calendar
     (`calendar-goto-julian-date').

`g a'
     Move to a date specified with an astronomical (Julian) day number
     (`calendar-goto-astro-day-number').

`g h'
     Move to a date specified in the Hebrew calendar
     (`calendar-goto-hebrew-date').

`g i'
     Move to a date specified in the Islamic calendar
     (`calendar-goto-islamic-date').

`g f'
     Move to a date specified in the French Revolutionary calendar
     (`calendar-goto-french-date').

`g C'
     Move to a date specified in the Chinese calendar
     (`calendar-goto-chinese-date').

`g p'
     Move to a date specified in the Persian calendar
     (`calendar-goto-persian-date').

`g k'
     Move to a date specified in the Coptic calendar
     (`calendar-goto-coptic-date').

`g e'
     Move to a date specified in the Ethiopic calendar
     (`calendar-goto-ethiopic-date').

   These commands ask you for a date on the other calendar, move point
to the Gregorian calendar date equivalent to that date, and display the
other calendar's date in the echo area.  Emacs uses strict completion
(*note Completion::) whenever it asks you to type a month name, so you
don't have to worry about the spelling of Hebrew, Islamic, or French
names.

   One common question concerning the Hebrew calendar is the computation
of the anniversary of a date of death, called a "yahrzeit."  The Emacs
calendar includes a facility for such calculations.  If you are in the
calendar, the command `M-x list-yahrzeit-dates' asks you for a range of
years and then displays a list of the yahrzeit dates for those years
for the date given by point.  If you are not in the calendar, this
command first asks you for the date of death and the range of years,
and then displays the list of yahrzeit dates.


File: emacs,  Node: Mayan Calendar,  Prev: From Other Calendar,  Up: Other Calendars

39.9.4 Converting from the Mayan Calendar
-----------------------------------------

Here are the commands to select dates based on the Mayan calendar:

`g m l'
     Move to a date specified by the long count calendar
     (`calendar-goto-mayan-long-count-date').

`g m n t'
     Move to the next occurrence of a place in the tzolkin calendar
     (`calendar-next-tzolkin-date').

`g m p t'
     Move to the previous occurrence of a place in the tzolkin calendar
     (`calendar-previous-tzolkin-date').

`g m n h'
     Move to the next occurrence of a place in the haab calendar
     (`calendar-next-haab-date').

`g m p h'
     Move to the previous occurrence of a place in the haab calendar
     (`calendar-previous-haab-date').

`g m n c'
     Move to the next occurrence of a place in the calendar round
     (`calendar-next-calendar-round-date').

`g m p c'
     Move to the previous occurrence of a place in the calendar round
     (`calendar-previous-calendar-round-date').

   To understand these commands, you need to understand the Mayan
calendars.  The "long count" is a counting of days with these units:

     1 kin = 1 day   1 uinal = 20 kin   1 tun = 18 uinal
     1 katun = 20 tun   1 baktun = 20 katun

Thus, the long count date 12.16.11.16.6 means 12 baktun, 16 katun, 11
tun, 16 uinal, and 6 kin.  The Emacs calendar can handle Mayan long
count dates as early as 7.17.18.13.3, but no earlier.  When you use the
`g m l' command, type the Mayan long count date with the baktun, katun,
tun, uinal, and kin separated by periods.

   The Mayan tzolkin calendar is a cycle of 260 days formed by a pair of
independent cycles of 13 and 20 days.  Since this cycle repeats
endlessly, Emacs provides commands to move backward and forward to the
previous or next point in the cycle.  Type `g m p t' to go to the
previous tzolkin date; Emacs asks you for a tzolkin date and moves point
to the previous occurrence of that date.  Similarly, type `g m n t' to
go to the next occurrence of a tzolkin date.

   The Mayan haab calendar is a cycle of 365 days arranged as 18 months
of 20 days each, followed a 5-day monthless period.  Like the tzolkin
cycle, this cycle repeats endlessly, and there are commands to move
backward and forward to the previous or next point in the cycle.  Type
`g m p h' to go to the previous haab date; Emacs asks you for a haab
date and moves point to the previous occurrence of that date.
Similarly, type `g m n h' to go to the next occurrence of a haab date.

   The Maya also used the combination of the tzolkin date and the haab
date.  This combination is a cycle of about 52 years called a _calendar
round_.  If you type `g m p c', Emacs asks you for both a haab and a
tzolkin date and then moves point to the previous occurrence of that
combination.  Use `g m n c' to move point to the next occurrence of a
combination.  These commands signal an error if the haab/tzolkin date
combination you have typed is impossible.

   Emacs uses strict completion (*note Strict Completion::) whenever it
asks you to type a Mayan name, so you don't have to worry about
spelling.


File: emacs,  Node: Diary,  Next: Appointments,  Prev: Other Calendars,  Up: Calendar/Diary

39.10 The Diary
===============

The Emacs diary keeps track of appointments or other events on a daily
basis, in conjunction with the calendar.  To use the diary feature, you
must first create a "diary file" containing a list of events and their
dates.  Then Emacs can automatically pick out and display the events
for today, for the immediate future, or for any specified date.

   The name of the diary file is specified by the variable
`diary-file'; `~/diary' is the default.  Here's an example showing what
that file looks like:

     12/22/1988  Twentieth wedding anniversary!!
     &1/1.       Happy New Year!
     10/22       Ruth's birthday.
     * 21, *:    Payday
     Tuesday--weekly meeting with grad students at 10am
              Supowit, Shen, Bitner, and Kapoor to attend.
     1/13/89     Friday the thirteenth!!
     &thu 4pm    squash game with Lloyd.
     mar 16      Dad's birthday
     April 15, 1989 Income tax due.
     &* 15       time cards due.

This format is essentially the same as the one used by the system's
`calendar' utility.  This example uses extra spaces to align the event
descriptions of most of the entries.  Such formatting is purely a
matter of taste.

   Although you probably will start by creating a diary manually, Emacs
provides a number of commands to let you view, add, and change diary
entries.

* Menu:

* Displaying the Diary::   Viewing diary entries and associated calendar dates.
* Format of Diary File::   Entering events in your diary.
* Date Formats::	   Various ways you can specify dates.
* Adding to Diary::	   Commands to create diary entries.
* Special Diary Entries::  Anniversaries, blocks of dates, cyclic entries, etc.


File: emacs,  Node: Displaying the Diary,  Next: Format of Diary File,  Up: Diary

39.10.1 Displaying the Diary
----------------------------

Once you have created a diary file, you can use the calendar to view
it.  You can also view today's events outside of Calendar mode.

`d'
     Display all diary entries for the selected date
     (`diary-view-entries').

`Mouse-2 Diary'
     Display all diary entries for the date you click on.

`s'
     Display the entire diary file (`diary-show-all-entries').

`m'
     Mark all visible dates that have diary entries
     (`mark-diary-entries').

`u'
     Unmark the calendar window (`calendar-unmark').

`M-x print-diary-entries'
     Print hard copy of the diary display as it appears.

`M-x diary'
     Display all diary entries for today's date.

`M-x diary-mail-entries'
     Mail yourself email reminders about upcoming diary entries.

   Displaying the diary entries with `d' shows in a separate window the
diary entries for the selected date in the calendar.  The mode line of
the new window shows the date of the diary entries and any holidays
that fall on that date.  If you specify a numeric argument with `d', it
shows all the diary entries for that many successive days.  Thus, `2 d'
displays all the entries for the selected date and for the following
day.

   Another way to display the diary entries for a date is to click
`Mouse-2' on the date, and then choose `Diary entries' from the menu
that appears.  If the variable `view-diary-entries-initially' is
non-`nil', creating the calendar lists the diary entries for the
current date (provided the current date is visible).

   To get a broader view of which days are mentioned in the diary, use
the `m' command.  This displays the dates that have diary entries in a
different face (or places a `+' after these dates, if display with
multiple faces is not available).  *Note diary-entry-marker: Calendar
Customizing.    The command applies both to the currently visible
months and to other months that subsequently become visible by
scrolling.  To turn marking off and erase the current marks, type `u',
which also turns off holiday marks (*note Holidays::).  If the variable
`mark-diary-entries-in-calendar' is non-`nil', creating or updating the
calendar marks diary dates automatically.

   To see the full diary file, rather than just some of the entries, use
the `s' command.

   Display of selected diary entries uses the selective display feature
to hide entries that don't apply.  The diary buffer as you see it is an
illusion, so simply printing the buffer does not print what you see on
your screen.  There is a special command to print hard copy of the
diary buffer _as it appears_; this command is `M-x
print-diary-entries'.  It sends the data directly to the printer.  You
can customize it like `lpr-region' (*note Printing::).

   The command `M-x diary' displays the diary entries for the current
date, independently of the calendar display, and optionally for the next
few days as well; the variable `number-of-diary-entries' specifies how
many days to include.  *Note number-of-diary-entries: Diary Customizing.

   If you put `(diary)' in your `.emacs' file, this automatically
displays a window with the day's diary entries, when you enter Emacs.
The mode line of the displayed window shows the date and any holidays
that fall on that date.

   Many users like to receive notice of events in their diary as email.
To send such mail to yourself, use the command `M-x
diary-mail-entries'.  A prefix argument specifies how many days
(starting with today) to check; otherwise, the variable
`diary-mail-days' says how many days.


File: emacs,  Node: Format of Diary File,  Next: Date Formats,  Prev: Displaying the Diary,  Up: Diary

39.10.2 The Diary File
----------------------

Your "diary file" is a file that records events associated with
particular dates.  The name of the diary file is specified by the
variable `diary-file'; `~/diary' is the default.  The `calendar'
utility program supports a subset of the format allowed by the Emacs
diary facilities, so you can use that utility to view the diary file,
with reasonable results aside from the entries it cannot understand.

   Each entry in the diary file describes one event and consists of one
or more lines.  An entry always begins with a date specification at the
left margin.  The rest of the entry is simply text to describe the
event.  If the entry has more than one line, then the lines after the
first must begin with whitespace to indicate they continue a previous
entry.  Lines that do not begin with valid dates and do not continue a
preceding entry are ignored.

   You can inhibit the marking of certain diary entries in the calendar
window; to do this, insert an ampersand (`&') at the beginning of the
entry, before the date.  This has no effect on display of the entry in
the diary window; it affects only marks on dates in the calendar
window.  Nonmarking entries are especially useful for generic entries
that would otherwise mark many different dates.

   If the first line of a diary entry consists only of the date or day
name with no following blanks or punctuation, then the diary window
display doesn't include that line; only the continuation lines appear.
For example, this entry:

     02/11/1989
           Bill B. visits Princeton today
           2pm Cognitive Studies Committee meeting
           2:30-5:30 Liz at Lawrenceville
           4:00pm Dentist appt
           7:30pm Dinner at George's
           8:00-10:00pm concert

appears in the diary window without the date line at the beginning.
This style of entry looks neater when you display just a single day's
entries, but can cause confusion if you ask for more than one day's
entries.

   You can edit the diary entries as they appear in the window, but it
is important to remember that the buffer displayed contains the _entire_
diary file, with portions of it concealed from view.  This means, for
instance, that the `C-f' (`forward-char') command can put point at what
appears to be the end of the line, but what is in reality the middle of
some concealed line.

   _Be careful when editing the diary entries!_  Inserting additional
lines or adding/deleting characters in the middle of a visible line
cannot cause problems, but editing at the end of a line may not do what
you expect.  Deleting a line may delete other invisible entries that
follow it.  Before editing the diary, it is best to display the entire
file with `s' (`diary-show-all-entries').


File: emacs,  Node: Date Formats,  Next: Adding to Diary,  Prev: Format of Diary File,  Up: Diary

39.10.3 Date Formats
--------------------

Here are some sample diary entries, illustrating different ways of
formatting a date.  The examples all show dates in American order
(month, day, year), but Calendar mode supports European order (day,
month, year) as an option.

     4/20/93  Switch-over to new tabulation system
     apr. 25  Start tabulating annual results
     4/30  Results for April are due
     */25  Monthly cycle finishes
     Friday  Don't leave without backing up files

   The first entry appears only once, on April 20, 1993.  The second and
third appear every year on the specified dates, and the fourth uses a
wildcard (asterisk) for the month, so it appears on the 25th of every
month.  The final entry appears every week on Friday.

   You can use just numbers to express a date, as in `MONTH/DAY' or
`MONTH/DAY/YEAR'.  This must be followed by a nondigit.  In the date
itself, MONTH and DAY are numbers of one or two digits.  The optional
YEAR is also a number, and may be abbreviated to the last two digits;
that is, you can use `11/12/1989' or `11/12/89'.

   Dates can also have the form `MONTHNAME DAY' or `MONTHNAME DAY,
YEAR', where the month's name can be spelled in full or abbreviated
(with or without a period).  The preferred abbreviations can be
controlled using the variables `calendar-abbrev-length',
`calendar-month-abbrev-array', and `calendar-day-abbrev-array'.  The
default is to use the first three letters of a name as its
abbreviation.  Case is not significant.

   A date may be "generic"; that is, partially unspecified.  Then the
entry applies to all dates that match the specification.  If the date
does not contain a year, it is generic and applies to any year.
Alternatively, MONTH, DAY, or YEAR can be a `*'; this matches any
month, day, or year, respectively.  Thus, a diary entry `3/*/*' matches
any day in March of any year; so does `march *'.

   If you prefer the European style of writing dates--in which the day
comes before the month--type `M-x european-calendar' while in the
calendar, or set the variable `european-calendar-style' to `t' with
`M-x customize', or _before_ using any calendar or diary command.  This
mode interprets all dates in the diary in the European manner, and also
uses European style for displaying diary dates.  (Note that there is no
comma after the MONTHNAME in the European style.)  To go back to the
(default) American style of writing dates, type `M-x american-calendar'.

   You can use the name of a day of the week as a generic date which
applies to any date falling on that day of the week.  You can abbreviate
the day of the week to three letters (with or without a period) or spell
it in full; case is not significant.


File: emacs,  Node: Adding to Diary,  Next: Special Diary Entries,  Prev: Date Formats,  Up: Diary

39.10.4 Commands to Add to the Diary
------------------------------------

While in the calendar, there are several commands to create diary
entries:

`i d'
     Add a diary entry for the selected date (`insert-diary-entry').

`i w'
     Add a diary entry for the selected day of the week
     (`insert-weekly-diary-entry').

`i m'
     Add a diary entry for the selected day of the month
     (`insert-monthly-diary-entry').

`i y'
     Add a diary entry for the selected day of the year
     (`insert-yearly-diary-entry').

   You can make a diary entry for a specific date by selecting that date
in the calendar window and typing the `i d' command.  This command
displays the end of your diary file in another window and inserts the
date; you can then type the rest of the diary entry.

   If you want to make a diary entry that applies to a specific day of
the week, select that day of the week (any occurrence will do) and type
`i w'.  This inserts the day-of-week as a generic date; you can then
type the rest of the diary entry.  You can make a monthly diary entry in
the same fashion: select the day of the month, use the `i m' command,
and type the rest of the entry.  Similarly, you can insert a yearly
diary entry with the `i y' command.

   All of the above commands make marking diary entries by default.  To
make a nonmarking diary entry, give a numeric argument to the command.
For example, `C-u i w' makes a nonmarking weekly diary entry.

   When you modify the diary file, be sure to save the file before
exiting Emacs.  Saving the diary file after using any of the above
insertion commands will automatically update the diary marks in the
calendar window, if appropriate.  You can use the command
`redraw-calendar' to force an update at any time.


File: emacs,  Node: Special Diary Entries,  Prev: Adding to Diary,  Up: Diary

39.10.5 Special Diary Entries
-----------------------------

In addition to entries based on calendar dates, the diary file can
contain "sexp entries" for regular events such as anniversaries.  These
entries are based on Lisp expressions (sexps) that Emacs evaluates as
it scans the diary file.  Instead of a date, a sexp entry contains `%%'
followed by a Lisp expression which must begin and end with
parentheses.  The Lisp expression determines which dates the entry
applies to.

   Calendar mode provides commands to insert certain commonly used sexp
entries:

`i a'
     Add an anniversary diary entry for the selected date
     (`insert-anniversary-diary-entry').

`i b'
     Add a block diary entry for the current region
     (`insert-block-diary-entry').

`i c'
     Add a cyclic diary entry starting at the date
     (`insert-cyclic-diary-entry').

   If you want to make a diary entry that applies to the anniversary of
a specific date, move point to that date and use the `i a' command.
This displays the end of your diary file in another window and inserts
the anniversary description; you can then type the rest of the diary
entry.  The entry looks like this:

     %%(diary-anniversary 10 31 1948) Arthur's birthday

This entry applies to October 31 in any year after 1948; `10 31 1948'
specifies the date.  (If you are using the European calendar style, the
month and day are interchanged.)  The reason this expression requires a
beginning year is that advanced diary functions can use it to calculate
the number of elapsed years.

   A "block" diary entry applies to a specified range of consecutive
dates.  Here is a block diary entry that applies to all dates from June
24, 1990 through July 10, 1990:

     %%(diary-block 6 24 1990 7 10 1990) Vacation

The `6 24 1990' indicates the starting date and the `7 10 1990'
indicates the stopping date.  (Again, if you are using the European
calendar style, the month and day are interchanged.)

   To insert a block entry, place point and the mark on the two dates
that begin and end the range, and type `i b'.  This command displays
the end of your diary file in another window and inserts the block
description; you can then type the diary entry.

   "Cyclic" diary entries repeat after a fixed interval of days.  To
create one, select the starting date and use the `i c' command.  The
command prompts for the length of interval, then inserts the entry,
which looks like this:

     %%(diary-cyclic 50 3 1 1990) Renew medication

This entry applies to March 1, 1990 and every 50th day following; `3 1
1990' specifies the starting date.  (If you are using the European
calendar style, the month and day are interchanged.)

   All three of these commands make marking diary entries.  To insert a
nonmarking entry, give a numeric argument to the command.  For example,
`C-u i a' makes a nonmarking anniversary diary entry.

   Marking sexp diary entries in the calendar is _extremely_
time-consuming, since every date visible in the calendar window must be
individually checked.  So it's a good idea to make sexp diary entries
nonmarking (with `&') when possible.

   Another sophisticated kind of sexp entry, a "floating" diary entry,
specifies a regularly occurring event by offsets specified in days,
weeks, and months.  It is comparable to a crontab entry interpreted by
the `cron' utility.  Here is a nonmarking, floating diary entry that
applies to the fourth Thursday in November:

     &%%(diary-float 11 4 4) American Thanksgiving

The 11 specifies November (the eleventh month), the 4 specifies Thursday
(the fourth day of the week, where Sunday is numbered zero), and the
second 4 specifies the fourth Thursday (1 would mean "first," 2 would
mean "second," -2 would mean "second-to-last," and so on).  The month
can be a single month or a list of months.  Thus you could change the
11 above to `'(1 2 3)' and have the entry apply to the last Thursday of
January, February, and March.  If the month is `t', the entry applies
to all months of the year.

   Each of the standard sexp diary entries takes an optional parameter
specifying the name of a face or a single-character string to use when
marking the entry in the calendar.  Most generally, sexp diary entries
can perform arbitrary computations to determine when they apply.  *note
()Sexp Diary Entries::.


File: emacs,  Node: Appointments,  Next: Importing Diary,  Prev: Diary,  Up: Calendar/Diary

39.11 Appointments
==================

If you have a diary entry for an appointment, and that diary entry
begins with a recognizable time of day, Emacs can warn you several
minutes beforehand that that appointment is pending.  Emacs alerts you
to the appointment by displaying a message in your chosen format, as
specified by the variable `appt-display-format'.  If the value of
`appt-audible' is non-`nil', the warning includes an audible reminder.
In addition, if `appt-display-mode-line' is non-`nil', Emacs displays
the number of minutes to the appointment on the mode line.

   If `appt-display-format' has the value `window', then the variable
`appt-display-duration' controls how long the reminder window is
visible for; and the variables `appt-disp-window-function' and
`appt-delete-window-function' give the names of functions used to
create and destroy the window, respectively.

   To enable appointment notification, use the command `M-x
appt-activate'.  With a positive argument, it enables notification;
with a negative argument, it disables notification; with no argument,
it toggles.  Enabling notification also sets up an appointment list for
today from the diary file, giving all diary entries found with
recognizable times of day, and reminds you just before each of them.

   For example, suppose the diary file contains these lines:

     Monday
       9:30am Coffee break
      12:00pm Lunch

Then on Mondays, you will be reminded at around 9:20am about your
coffee break and at around 11:50am about lunch.  The variable
`appt-message-warning-time' specifies how many minutes in advance to
warn you; its default value is 12 (12 minutes).

   You can write times in am/pm style (with `12:00am' standing for
midnight and `12:00pm' standing for noon), or 24-hour European/military
style.  You need not be consistent; your diary file can have a mixture
of the two styles.  Times must be at the beginning of lines if they are
to be recognized.

   Emacs updates the appointments list from the diary file
automatically just after midnight.  You can force an update at any time
by re-enabling appointment notification.  Both these actions also
display the day's diary buffer, unless you set `appt-display-diary' to
`nil'.  The appointments list is also updated whenever the diary file
is saved.

   You can also use the appointment notification facility like an alarm
clock.  The command `M-x appt-add' adds entries to the appointment list
without affecting your diary file.  You delete entries from the
appointment list with `M-x appt-delete'.


File: emacs,  Node: Importing Diary,  Next: Daylight Saving,  Prev: Appointments,  Up: Calendar/Diary

39.12 Importing and Exporting Diary Entries
===========================================

You can transfer diary entries between Emacs diary files and a variety
of other formats.

   You can import diary entries from Outlook-generated appointment
messages.  While viewing such a message in Rmail or Gnus, do `M-x
diary-from-outlook' to import the entry.  You can make this command
recognize additional appointment message formats by customizing the
variable `diary-outlook-formats'.

   The icalendar package allows you to transfer data between your Emacs
diary file and iCalendar files, which are defined in "RFC
2445--Internet Calendaring and Scheduling Core Object Specification
(iCalendar)" (as well as the earlier vCalendar format).

   Importing works for "ordinary" (i.e. non-recurring) events, but (at
present) may not work correctly (if at all) for recurring events.
Exporting of diary files into iCalendar files should work correctly for
most diary entries.  This feature is a work in progress, so the
commands may evolve in future.

   The command `icalendar-import-buffer' extracts iCalendar data from
the current buffer and adds it to your (default) diary file.  This
function is also suitable for automatic extraction of iCalendar data;
for example with the Rmail mail client one could use:

     (add-hook 'rmail-show-message-hook 'icalendar-import-buffer)

   The command `icalendar-import-file' imports an iCalendar file and
adds the results to an Emacs diary file.  For example:

     (icalendar-import-file "/here/is/calendar.ics"
                            "/there/goes/ical-diary")

You can use an `#include' directive to add the import file contents to
the main diary file, if these are different files.  *Note Fancy Diary
Display::.

   Use `icalendar-export-file' to interactively export an entire Emacs
diary file to iCalendar format.  To export only a part of a diary file,
mark the relevant area, and call `icalendar-export-region'.  In both
cases the result is appended to the target file.


File: emacs,  Node: Daylight Saving,  Next: Time Intervals,  Prev: Importing Diary,  Up: Calendar/Diary

39.13 Daylight Saving Time
==========================

Emacs understands the difference between standard time and daylight
saving time--the times given for sunrise, sunset, solstices, equinoxes,
and the phases of the moon take that into account.  The rules for
daylight saving time vary from place to place and have also varied
historically from year to year.  To do the job properly, Emacs needs to
know which rules to use.

   Some operating systems keep track of the rules that apply to the
place where you are; on these systems, Emacs gets the information it
needs from the system automatically.  If some or all of this
information is missing, Emacs fills in the gaps with the rules
currently used in Cambridge, Massachusetts.  If the resulting rules are
not what you want, you can tell Emacs the rules to use by setting
certain variables: `calendar-daylight-savings-starts' and
`calendar-daylight-savings-ends'.

   These values should be Lisp expressions that refer to the variable
`year', and evaluate to the Gregorian date on which daylight saving
time starts or (respectively) ends, in the form of a list `(MONTH DAY
YEAR)'.  The values should be `nil' if your area does not use daylight
saving time.

   Emacs uses these expressions to determine the starting date of
daylight saving time for the holiday list and for correcting times of
day in the solar and lunar calculations.

   The values for Cambridge, Massachusetts are as follows:

     (calendar-nth-named-day 2 0 3 year)
     (calendar-nth-named-day 1 0 11 year)

That is, the second 0th day (Sunday) of the third month (March) in the
year specified by `year', and the first Sunday of the eleventh month
(November) of that year.  If daylight saving time were changed to start
on October 1, you would set `calendar-daylight-savings-starts' to this:

     (list 10 1 year)

   If there is no daylight saving time at your location, or if you want
all times in standard time, set `calendar-daylight-savings-starts' and
`calendar-daylight-savings-ends' to `nil'.

   The variable `calendar-daylight-time-offset' specifies the
difference between daylight saving time and standard time, measured in
minutes.  The value for Cambridge, Massachusetts is 60.

   Finally, the two variables `calendar-daylight-savings-starts-time'
and `calendar-daylight-savings-ends-time' specify the number of minutes
after midnight local time when the transition to and from daylight
saving time should occur.  For Cambridge, Massachusetts both variables'
values are 120.


File: emacs,  Node: Time Intervals,  Next: Advanced Calendar/Diary Usage,  Prev: Daylight Saving,  Up: Calendar/Diary

39.14 Summing Time Intervals
============================

The timeclock feature adds up time intervals, so you can (for instance)
keep track of how much time you spend working on particular projects.

   Use the `M-x timeclock-in' command when you start working on a
project, and `M-x timeclock-out' command when you're done.  Each time
you do this, it adds one time interval to the record of the project.
You can change to working on a different project with `M-x
timeclock-change'.

   Once you've collected data from a number of time intervals, you can
use `M-x timeclock-workday-remaining' to see how much time is left to
work today (assuming a typical average of 8 hours a day), and `M-x
timeclock-when-to-leave' which will calculate when you're "done."

   If you want Emacs to display the amount of time "left" of your
workday in the mode line, either customize the
`timeclock-modeline-display' variable and set its value to `t', or
invoke the `M-x timeclock-modeline-display' command.

   Terminating the current Emacs session might or might not mean that
you have stopped working on the project and, by default, Emacs asks
you.  You can, however, set the value of the variable
`timeclock-ask-before-exiting' to `nil' (via `M-x customize') to avoid
the question; then, only an explicit `M-x timeclock-out' or `M-x
timeclock-change' will tell Emacs that the current interval is over.

   The timeclock functions work by accumulating the data in a file
called `.timelog' in your home directory.  You can specify a different
name for this file by customizing the variable `timeclock-file'.  If
you edit the timeclock file manually, or if you change the value of any
of timeclock's customizable variables, you should run the command `M-x
timeclock-reread-log' to update the data in Emacs from the file.


File: emacs,  Node: Advanced Calendar/Diary Usage,  Prev: Time Intervals,  Up: Calendar/Diary

39.15 Customizing the Calendar and Diary
========================================

There are many customizations that you can use to make the calendar and
diary suit your personal tastes.

* Menu:

* Calendar Customizing::   Defaults you can set.
* Holiday Customizing::    Defining your own holidays.
* Date Display Format::    Changing the format.
* Time Display Format::    Changing the format.
* Diary Customizing::      Defaults you can set.
* Hebrew/Islamic Entries:: How to obtain them.
* Fancy Diary Display::    Enhancing the diary display, sorting entries,
                             using included diary files.
* Sexp Diary Entries::     Fancy things you can do.


File: emacs,  Node: Calendar Customizing,  Next: Holiday Customizing,  Up: Advanced Calendar/Diary Usage

39.15.1 Customizing the Calendar
--------------------------------

The variable `calendar-holiday-marker' specifies how to mark a date as
being a holiday.  Its value may be a single-character string to insert
next to the date, or a face name to use for displaying the date.
Likewise, the variable `diary-entry-marker' specifies how to mark a
date that has diary entries.  The calendar creates faces named
`holiday-face' and `diary-face' for these purposes; those symbols are
the default values of these variables.

   The variable `calendar-load-hook' is a normal hook run when the
calendar package is first loaded (before actually starting to display
the calendar).

   Starting the calendar runs the normal hook
`initial-calendar-window-hook'.  Recomputation of the calendar display
does not run this hook.  But if you leave the calendar with the `q'
command and reenter it, the hook runs again.

   The variable `today-visible-calendar-hook' is a normal hook run
after the calendar buffer has been prepared with the calendar when the
current date is visible in the window.  One use of this hook is to
replace today's date with asterisks; to do that, use the hook function
`calendar-star-date'.

     (add-hook 'today-visible-calendar-hook 'calendar-star-date)

Another standard hook function marks the current date, either by
changing its face or by adding an asterisk.  Here's how to use it:

     (add-hook 'today-visible-calendar-hook 'calendar-mark-today)

The variable `calendar-today-marker' specifies how to mark today's
date.  Its value should be a single-character string to insert next to
the date or a face name to use for displaying the date.  A face named
`calendar-today-face' is provided for this purpose; that symbol is the
default for this variable.

A similar normal hook, `today-invisible-calendar-hook' is run if the
current date is _not_ visible in the window.

   Each of the calendar cursor motion commands runs the hook
`calendar-move-hook' after it moves the cursor.


File: emacs,  Node: Holiday Customizing,  Next: Date Display Format,  Prev: Calendar Customizing,  Up: Advanced Calendar/Diary Usage

39.15.2 Customizing the Holidays
--------------------------------

Emacs knows about holidays defined by entries on one of several lists.
You can customize these lists of holidays to your own needs, adding or
deleting holidays.  The lists of holidays that Emacs uses are for
general holidays (`general-holidays'), local holidays
(`local-holidays'), Christian holidays (`christian-holidays'), Hebrew
(Jewish) holidays (`hebrew-holidays'), Islamic (Muslim) holidays
(`islamic-holidays'), and other holidays (`other-holidays').

   The general holidays are, by default, holidays common throughout the
United States.  To eliminate these holidays, set `general-holidays' to
`nil'.

   There are no default local holidays (but sites may supply some).  You
can set the variable `local-holidays' to any list of holidays, as
described below.

   By default, Emacs does not include all the holidays of the religions
that it knows, only those commonly found in secular calendars.  For a
more extensive collection of religious holidays, you can set any (or
all) of the variables `all-christian-calendar-holidays',
`all-hebrew-calendar-holidays', or `all-islamic-calendar-holidays' to
`t'.  If you want to eliminate the religious holidays, set any or all
of the corresponding variables `christian-holidays', `hebrew-holidays',
and `islamic-holidays' to `nil'.

   You can set the variable `other-holidays' to any list of holidays.
This list, normally empty, is intended for individual use.

   Each of the lists (`general-holidays', `local-holidays',
`christian-holidays', `hebrew-holidays', `islamic-holidays', and
`other-holidays') is a list of "holiday forms", each holiday form
describing a holiday (or sometimes a list of holidays).

   Here is a table of the possible kinds of holiday form.  Day numbers
and month numbers count starting from 1, but "dayname" numbers count
Sunday as 0.  The element STRING is always the name of the holiday, as
a string.

`(holiday-fixed MONTH DAY STRING)'
     A fixed date on the Gregorian calendar.

`(holiday-float MONTH DAYNAME K STRING)'
     The Kth DAYNAME in MONTH on the Gregorian calendar (DAYNAME=0 for
     Sunday, and so on); negative K means count back from the end of
     the month.

`(holiday-hebrew MONTH DAY STRING)'
     A fixed date on the Hebrew calendar.

`(holiday-islamic MONTH DAY STRING)'
     A fixed date on the Islamic calendar.

`(holiday-julian MONTH DAY STRING)'
     A fixed date on the Julian calendar.

`(holiday-sexp SEXP STRING)'
     A date calculated by the Lisp expression SEXP.  The expression
     should use the variable `year' to compute and return the date of a
     holiday, or `nil' if the holiday doesn't happen this year.  The
     value of SEXP must represent the date as a list of the form
     `(MONTH DAY YEAR)'.

`(if CONDITION HOLIDAY-FORM)'
     A holiday that happens only if CONDITION is true.

`(FUNCTION [ARGS])'
     A list of dates calculated by the function FUNCTION, called with
     arguments ARGS.

   For example, suppose you want to add Bastille Day, celebrated in
France on July 14.  You can do this as follows:

     (setq other-holidays '((holiday-fixed 7 14 "Bastille Day")))

The holiday form `(holiday-fixed 7 14 "Bastille Day")' specifies the
fourteenth day of the seventh month (July).

   Many holidays occur on a specific day of the week, at a specific time
of month.  Here is a holiday form describing Hurricane Supplication Day,
celebrated in the Virgin Islands on the fourth Monday in August:

     (holiday-float 8 1 4 "Hurricane Supplication Day")

Here the 8 specifies August, the 1 specifies Monday (Sunday is 0,
Tuesday is 2, and so on), and the 4 specifies the fourth occurrence in
the month (1 specifies the first occurrence, 2 the second occurrence,
-1 the last occurrence, -2 the second-to-last occurrence, and so on).

   You can specify holidays that occur on fixed days of the Hebrew,
Islamic, and Julian calendars too.  For example,

     (setq other-holidays
           '((holiday-hebrew 10 2 "Last day of Hanukkah")
             (holiday-islamic 3 12 "Mohammed's Birthday")
             (holiday-julian 4 2 "Jefferson's Birthday")))

adds the last day of Hanukkah (since the Hebrew months are numbered with
1 starting from Nisan), the Islamic feast celebrating Mohammed's
birthday (since the Islamic months are numbered from 1 starting with
Muharram), and Thomas Jefferson's birthday, which is 2 April 1743 on the
Julian calendar.

   To include a holiday conditionally, use either Emacs Lisp's `if' or
the `holiday-sexp' form.  For example, American presidential elections
occur on the first Tuesday after the first Monday in November of years
divisible by 4:

     (holiday-sexp '(if (= 0 (% year 4))
                        (calendar-gregorian-from-absolute
                         (1+ (calendar-dayname-on-or-before
                               1 (+ 6 (calendar-absolute-from-gregorian
                                       (list 11 1 year)))))))
                   "US Presidential Election")

or

     (if (= 0 (% displayed-year 4))
         (fixed 11
                (extract-calendar-day
                  (calendar-gregorian-from-absolute
                    (1+ (calendar-dayname-on-or-before
                          1 (+ 6 (calendar-absolute-from-gregorian
                                   (list 11 1 displayed-year)))))))
                "US Presidential Election"))

   Some holidays just don't fit into any of these forms because special
calculations are involved in their determination.  In such cases you
must write a Lisp function to do the calculation.  To include eclipses,
for example, add `(eclipses)' to `other-holidays' and write an Emacs
Lisp function `eclipses' that returns a (possibly empty) list of the
relevant Gregorian dates among the range visible in the calendar
window, with descriptive strings, like this:

     (((6 27 1991) "Lunar Eclipse") ((7 11 1991) "Solar Eclipse") ... )


File: emacs,  Node: Date Display Format,  Next: Time Display Format,  Prev: Holiday Customizing,  Up: Advanced Calendar/Diary Usage

39.15.3 Date Display Format
---------------------------

You can customize the manner of displaying dates in the diary, in mode
lines, and in messages by setting `calendar-date-display-form'.  This
variable holds a list of expressions that can involve the variables
`month', `day', and `year', which are all numbers in string form, and
`monthname' and `dayname', which are both alphabetic strings.  In the
American style, the default value of this list is as follows:

     ((if dayname (concat dayname ", ")) monthname " " day ", " year)

while in the European style this value is the default:

     ((if dayname (concat dayname ", ")) day " " monthname " " year)

The ISO standard date representation is this:

     (year "-" month "-" day)

This specifies a typical American format:

     (month "/" day "/" (substring year -2))


File: emacs,  Node: Time Display Format,  Next: Diary Customizing,  Prev: Date Display Format,  Up: Advanced Calendar/Diary Usage

39.15.4 Time Display Format
---------------------------

The calendar and diary by default display times of day in the
conventional American style with the hours from 1 through 12, minutes,
and either `am' or `pm'.  If you prefer the European style, also known
in the US as military, in which the hours go from 00 to 23, you can
alter the variable `calendar-time-display-form'.  This variable is a
list of expressions that can involve the variables `12-hours',
`24-hours', and `minutes', which are all numbers in string form, and
`am-pm' and `time-zone', which are both alphabetic strings.  The
default value of `calendar-time-display-form' is as follows:

     (12-hours ":" minutes am-pm
               (if time-zone " (") time-zone (if time-zone ")"))

Here is a value that provides European style times:

     (24-hours ":" minutes
               (if time-zone " (") time-zone (if time-zone ")"))


File: emacs,  Node: Diary Customizing,  Next: Hebrew/Islamic Entries,  Prev: Time Display Format,  Up: Advanced Calendar/Diary Usage

39.15.5 Customizing the Diary
-----------------------------

Ordinarily, the mode line of the diary buffer window indicates any
holidays that fall on the date of the diary entries.  The process of
checking for holidays can take several seconds, so including holiday
information delays the display of the diary buffer noticeably.  If you'd
prefer to have a faster display of the diary buffer but without the
holiday information, set the variable `holidays-in-diary-buffer' to
`nil'.

   The variable `number-of-diary-entries' controls the number of days
of diary entries to be displayed at one time.  It affects the initial
display when `view-diary-entries-initially' is `t', as well as the
command `M-x diary'.  For example, the default value is 1, which says
to display only the current day's diary entries.  If the value is 2,
both the current day's and the next day's entries are displayed.  The
value can also be a vector of seven elements: for example, if the value
is `[0 2 2 2 2 4 1]' then no diary entries appear on Sunday, the
current date's and the next day's diary entries appear Monday through
Thursday, Friday through Monday's entries appear on Friday, while on
Saturday only that day's entries appear.

   The variable `print-diary-entries-hook' is a normal hook run after
preparation of a temporary buffer containing just the diary entries
currently visible in the diary buffer.  (The other, irrelevant diary
entries are really absent from the temporary buffer; in the diary
buffer, they are merely hidden.)  The default value of this hook does
the printing with the command `lpr-buffer'.  If you want to use a
different command to do the printing, just change the value of this
hook.  Other uses might include, for example, rearranging the lines into
order by day and time.

   You can customize the form of dates in your diary file, if neither
the standard American nor European styles suits your needs, by setting
the variable `diary-date-forms'.  This variable is a list of patterns
for recognizing a date.  Each date pattern is a list whose elements may
be regular expressions (*note Regular Expressions: (elisp)Regular
Expressions.) or the symbols `month', `day', `year', `monthname', and
`dayname'.  All these elements serve as patterns that match certain
kinds of text in the diary file.  In order for the date pattern, as a
whole, to match, all of its elements must match consecutively.

   A regular expression in a date pattern matches in its usual fashion,
using the standard syntax table altered so that `*' is a word
constituent.

   The symbols `month', `day', `year', `monthname', and `dayname' match
the month number, day number, year number, month name, and day name of
the date being considered.  The symbols that match numbers allow
leading zeros; those that match names allow three-letter abbreviations
and capitalization.  All the symbols can match `*'; since `*' in a
diary entry means "any day", "any month", and so on, it should match
regardless of the date being considered.

   The default value of `diary-date-forms' in the American style is
this:

     ((month "/" day "[^/0-9]")
      (month "/" day "/" year "[^0-9]")
      (monthname " *" day "[^,0-9]")
      (monthname " *" day ", *" year "[^0-9]")
      (dayname "\\W"))

   The date patterns in the list must be _mutually exclusive_ and must
not match any portion of the diary entry itself, just the date and one
character of whitespace.  If, to be mutually exclusive, the pattern
must match a portion of the diary entry text--beyond the whitespace
that ends the date--then the first element of the date pattern _must_
be `backup'.  This causes the date recognizer to back up to the
beginning of the current word of the diary entry, after finishing the
match.  Even if you use `backup', the date pattern must absolutely not
match more than a portion of the first word of the diary entry.  The
default value of `diary-date-forms' in the European style is this list:

     ((day "/" month "[^/0-9]")
      (day "/" month "/" year "[^0-9]")
      (backup day " *" monthname "\\W+\\<[^*0-9]")
      (day " *" monthname " *" year "[^0-9]")
      (dayname "\\W"))

Notice the use of `backup' in the third pattern, because it needs to
match part of a word beyond the date itself to distinguish it from the
fourth pattern.


File: emacs,  Node: Hebrew/Islamic Entries,  Next: Fancy Diary Display,  Prev: Diary Customizing,  Up: Advanced Calendar/Diary Usage

39.15.6 Hebrew- and Islamic-Date Diary Entries
----------------------------------------------

Your diary file can have entries based on Hebrew or Islamic dates, as
well as entries based on the world-standard Gregorian calendar.
However, because recognition of such entries is time-consuming and most
people don't use them, you must explicitly enable their use.  If you
want the diary to recognize Hebrew-date diary entries, for example, you
must do this:

     (add-hook 'nongregorian-diary-listing-hook 'list-hebrew-diary-entries)
     (add-hook 'nongregorian-diary-marking-hook 'mark-hebrew-diary-entries)

If you want Islamic-date entries, do this:

     (add-hook 'nongregorian-diary-listing-hook 'list-islamic-diary-entries)
     (add-hook 'nongregorian-diary-marking-hook 'mark-islamic-diary-entries)

   Hebrew- and Islamic-date diary entries have the same formats as
Gregorian-date diary entries, except that `H' precedes a Hebrew date
and `I' precedes an Islamic date.  Moreover, because the Hebrew and
Islamic month names are not uniquely specified by the first three
letters, you may not abbreviate them.  For example, a diary entry for
the Hebrew date Heshvan 25 could look like this:

     HHeshvan 25 Happy Hebrew birthday!

and would appear in the diary for any date that corresponds to Heshvan
25 on the Hebrew calendar.  And here is an Islamic-date diary entry
that matches Dhu al-Qada 25:

     IDhu al-Qada 25 Happy Islamic birthday!

   As with Gregorian-date diary entries, Hebrew- and Islamic-date
entries are nonmarking if they are preceded with an ampersand (`&').

   Here is a table of commands used in the calendar to create diary
entries that match the selected date and other dates that are similar
in the Hebrew or Islamic calendar:

`i h d'
     Add a diary entry for the Hebrew date corresponding to the
     selected date (`insert-hebrew-diary-entry').

`i h m'
     Add a diary entry for the day of the Hebrew month corresponding to
     the selected date (`insert-monthly-hebrew-diary-entry').  This
     diary entry matches any date that has the same Hebrew
     day-within-month as the selected date.

`i h y'
     Add a diary entry for the day of the Hebrew year corresponding to
     the selected date (`insert-yearly-hebrew-diary-entry').  This diary
     entry matches any date which has the same Hebrew month and
     day-within-month as the selected date.

`i i d'
     Add a diary entry for the Islamic date corresponding to the
     selected date (`insert-islamic-diary-entry').

`i i m'
     Add a diary entry for the day of the Islamic month corresponding
     to the selected date (`insert-monthly-islamic-diary-entry').

`i i y'
     Add a diary entry for the day of the Islamic year corresponding to
     the selected date (`insert-yearly-islamic-diary-entry').

   These commands work much like the corresponding commands for ordinary
diary entries: they apply to the date that point is on in the calendar
window, and what they do is insert just the date portion of a diary
entry at the end of your diary file.  You must then insert the rest of
the diary entry.


File: emacs,  Node: Fancy Diary Display,  Next: Sexp Diary Entries,  Prev: Hebrew/Islamic Entries,  Up: Advanced Calendar/Diary Usage

39.15.7 Fancy Diary Display
---------------------------

Diary display works by preparing the diary buffer and then running the
hook `diary-display-hook'.  The default value of this hook
(`simple-diary-display') hides the irrelevant diary entries and then
displays the buffer.  However, if you specify the hook as follows,

     (add-hook 'diary-display-hook 'fancy-diary-display)

this enables fancy diary display.  It displays diary entries and
holidays by copying them into a special buffer that exists only for the
sake of display.  Copying to a separate buffer provides an opportunity
to change the displayed text to make it prettier--for example, to sort
the entries by the dates they apply to.

   As with simple diary display, you can print a hard copy of the buffer
with `print-diary-entries'.  To print a hard copy of a day-by-day diary
for a week, position point on Sunday of that week, type `7 d', and then
do `M-x print-diary-entries'.  As usual, the inclusion of the holidays
slows down the display slightly; you can speed things up by setting the
variable `holidays-in-diary-buffer' to `nil'.

   Ordinarily, the fancy diary buffer does not show days for which
there are no diary entries, even if that day is a holiday.  If you want
such days to be shown in the fancy diary buffer, set the variable
`diary-list-include-blanks' to `t'.

   If you use the fancy diary display, you can use the normal hook
`list-diary-entries-hook' to sort each day's diary entries by their
time of day.  Here's how:

     (add-hook 'list-diary-entries-hook 'sort-diary-entries t)

For each day, this sorts diary entries that begin with a recognizable
time of day according to their times.  Diary entries without times come
first within each day.

   Fancy diary display also has the ability to process included diary
files.  This permits a group of people to share a diary file for events
that apply to all of them.  Lines in the diary file of this form:

     #include "FILENAME"

includes the diary entries from the file FILENAME in the fancy diary
buffer.  The include mechanism is recursive, so that included files can
include other files, and so on; you must be careful not to have a cycle
of inclusions, of course.  Here is how to enable the include facility:

     (add-hook 'list-diary-entries-hook 'include-other-diary-files)
     (add-hook 'mark-diary-entries-hook 'mark-included-diary-files)

   The include mechanism works only with the fancy diary display,
because ordinary diary display shows the entries directly from your
diary file.


File: emacs,  Node: Sexp Diary Entries,  Prev: Fancy Diary Display,  Up: Advanced Calendar/Diary Usage

39.15.8 Sexp Entries and the Fancy Diary Display
------------------------------------------------

Sexp diary entries allow you to do more than just have complicated
conditions under which a diary entry applies.  If you use the fancy
diary display, sexp entries can generate the text of the entry depending
on the date itself.  For example, an anniversary diary entry can insert
the number of years since the anniversary date into the text of the
diary entry.  Thus the `%d' in this diary entry:

     %%(diary-anniversary 10 31 1948) Arthur's birthday (%d years old)

gets replaced by the age, so on October 31, 1990 the entry appears in
the fancy diary buffer like this:

     Arthur's birthday (42 years old)

If the diary file instead contains this entry:

     %%(diary-anniversary 10 31 1948) Arthur's %d%s birthday

the entry in the fancy diary buffer for October 31, 1990 appears like
this:

     Arthur's 42nd birthday

   Similarly, cyclic diary entries can interpolate the number of
repetitions that have occurred:

     %%(diary-cyclic 50 1 1 1990) Renew medication (%d%s time)

looks like this:

     Renew medication (5th time)

in the fancy diary display on September 8, 1990.

   There is an early reminder diary sexp that includes its entry in the
diary not only on the date of occurrence, but also on earlier dates.
For example, if you want a reminder a week before your anniversary, you
can use

     %%(diary-remind '(diary-anniversary 12 22 1968) 7) Ed's anniversary

and the fancy diary will show
     Ed's anniversary
   both on December 15 and on December 22.

   The function `diary-date' applies to dates described by a month,
day, year combination, each of which can be an integer, a list of
integers, or `t'. The value `t' means all values.  For example,

     %%(diary-date '(10 11 12) 22 t) Rake leaves

causes the fancy diary to show

     Rake leaves

on October 22, November 22, and December 22 of every year.

   The function `diary-float' allows you to describe diary entries that
apply to dates like the third Friday of November, or the last Tuesday
in April.  The parameters are the MONTH, DAYNAME, and an index N. The
entry appears on the Nth DAYNAME of MONTH, where DAYNAME=0 means
Sunday, 1 means Monday, and so on.  If N is negative it counts backward
from the end of MONTH.  The value of MONTH can be a list of months, a
single month, or `t' to specify all months.  You can also use an
optional parameter DAY to specify the Nth DAYNAME of MONTH on or
after/before DAY; the value of DAY defaults to 1 if N is positive and
to the last day of MONTH if N is negative.  For example,

     %%(diary-float t 1 -1) Pay rent

causes the fancy diary to show

     Pay rent

on the last Monday of every month.

   The generality of sexp diary entries lets you specify any diary
entry that you can describe algorithmically.  A sexp diary entry
contains an expression that computes whether the entry applies to any
given date.  If its value is non-`nil', the entry applies to that date;
otherwise, it does not.  The expression can use the variable `date' to
find the date being considered; its value is a list (MONTH DAY YEAR)
that refers to the Gregorian calendar.

   The sexp diary entry applies to a date when the expression's value
is non-`nil', but some values have more specific meanings.  If the
value is a string, that string is a description of the event which
occurs on that date.  The value can also have the form `(MARK .
STRING)'; then MARK specifies how to mark the date in the calendar, and
STRING is the description of the event.  If MARK is a single-character
string, that character appears next to the date in the calendar.  If
MARK is a face name, the date is displayed in that face.  If MARK is
`nil', that specifies no particular highlighting for the date.

   Suppose you get paid on the 21st of the month if it is a weekday, and
on the Friday before if the 21st is on a weekend.  Here is how to write
a sexp diary entry that matches those dates:

     &%%(let ((dayname (calendar-day-of-week date))
              (day (car (cdr date))))
           (or (and (= day 21) (memq dayname '(1 2 3 4 5)))
               (and (memq day '(19 20)) (= dayname 5)))
              ) Pay check deposited

   The following sexp diary entries take advantage of the ability (in
the fancy diary display) to concoct diary entries whose text varies
based on the date:

`%%(diary-sunrise-sunset)'
     Make a diary entry for the local times of today's sunrise and
     sunset.

`%%(diary-phases-of-moon)'
     Make a diary entry for the phases (quarters) of the moon.

`%%(diary-day-of-year)'
     Make a diary entry with today's day number in the current year and
     the number of days remaining in the current year.

`%%(diary-iso-date)'
     Make a diary entry with today's equivalent ISO commercial date.

`%%(diary-julian-date)'
     Make a diary entry with today's equivalent date on the Julian
     calendar.

`%%(diary-astro-day-number)'
     Make a diary entry with today's equivalent astronomical (Julian)
     day number.

`%%(diary-hebrew-date)'
     Make a diary entry with today's equivalent date on the Hebrew
     calendar.

`%%(diary-islamic-date)'
     Make a diary entry with today's equivalent date on the Islamic
     calendar.

`%%(diary-french-date)'
     Make a diary entry with today's equivalent date on the French
     Revolutionary calendar.

`%%(diary-mayan-date)'
     Make a diary entry with today's equivalent date on the Mayan
     calendar.

Thus including the diary entry

     &%%(diary-hebrew-date)

causes every day's diary display to contain the equivalent date on the
Hebrew calendar, if you are using the fancy diary display.  (With simple
diary display, the line `&%%(diary-hebrew-date)' appears in the diary
for any date, but does nothing particularly useful.)

   These functions can be used to construct sexp diary entries based on
the Hebrew calendar in certain standard ways:

`%%(diary-rosh-hodesh)'
     Make a diary entry that tells the occurrence and ritual
     announcement of each new Hebrew month.

`%%(diary-parasha)'
     Make a Saturday diary entry that tells the weekly synagogue
     scripture reading.

`%%(diary-sabbath-candles)'
     Make a Friday diary entry that tells the _local time_ of Sabbath
     candle lighting.

`%%(diary-omer)'
     Make a diary entry that gives the omer count, when appropriate.

`%%(diary-yahrzeit MONTH DAY YEAR) NAME'
     Make a diary entry marking the anniversary of a date of death.
     The date is the _Gregorian_ (civil) date of death.  The diary
     entry appears on the proper Hebrew calendar anniversary and on the
     day before.  (In the European style, the order of the parameters
     is changed to DAY, MONTH, YEAR.)

   All the functions documented above take an optional argument MARK
which specifies how to mark the date in the calendar display.  If one
of these functions decides that it applies to a certain date, it
returns a value that contains MARK.


File: emacs,  Node: Gnus,  Next: Shell,  Prev: Calendar/Diary,  Up: Top

40 Gnus
*******

Gnus is an Emacs package primarily designed for reading and posting
Usenet news.  It can also be used to read and respond to messages from a
number of other sources--mail, remote directories, digests, and so on.

   Here we introduce Gnus and describe several basic features.  For
full details, see *note Gnus: (gnus)Top.

   To start Gnus, type `M-x gnus <RET>'.

* Menu:

* Buffers of Gnus::	The group, summary, and article buffers.
* Gnus Startup::	What you should know about starting Gnus.
* Summary of Gnus::	A short description of the basic Gnus commands.


File: emacs,  Node: Buffers of Gnus,  Next: Gnus Startup,  Up: Gnus

40.1 Gnus Buffers
=================

Unlike most Emacs packages, Gnus uses several buffers to display
information and to receive commands.  The three Gnus buffers users use
most are the "group buffer", the "summary buffer" and the "article
buffer".

   The "group buffer" contains a list of newsgroups.  This is the first
buffer Gnus displays when it starts up.  It normally displays only the
groups to which you subscribe and that contain unread articles.  Use
this buffer to select a specific group.

   The "summary buffer" lists one line for each article in a single
group.  By default, the author, the subject and the line number are
displayed for each article, but this is customizable, like most aspects
of Gnus display.  The summary buffer is created when you select a group
in the group buffer, and is killed when you exit the group.  Use this
buffer to select an article.

   The "article buffer" displays the article.  In normal Gnus usage,
you see this buffer but you don't select it--all useful
article-oriented commands work in the summary buffer.  But you can
select the article buffer, and execute all Gnus commands from that
buffer, if you want to.


File: emacs,  Node: Gnus Startup,  Next: Summary of Gnus,  Prev: Buffers of Gnus,  Up: Gnus

40.2 When Gnus Starts Up
========================

At startup, Gnus reads your `.newsrc' news initialization file and
attempts to communicate with the local news server, which is a
repository of news articles.  The news server need not be the same
computer you are logged in on.

   If you start Gnus and connect to the server, but do not see any
newsgroups listed in the group buffer, type `L' or `A k' to get a
listing of all the groups.  Then type `u' to toggle subscription to
groups.

   The first time you start Gnus, Gnus subscribes you to a few selected
groups.  All other groups start out as "killed groups" for you; you can
list them with `A k'.  All new groups that subsequently come to exist
at the news server become "zombie groups" for you; type `A z' to list
them.  You can subscribe to a group shown in these lists using the `u'
command.

   When you quit Gnus with `q', it automatically records in your
`.newsrc' and `.newsrc.eld' initialization files the subscribed or
unsubscribed status of all groups.  You should normally not edit these
files manually, but you may if you know how.


File: emacs,  Node: Summary of Gnus,  Prev: Gnus Startup,  Up: Gnus

40.3 Summary of Gnus Commands
=============================

Reading news is a two-step process:

  1. Choose a group in the group buffer.

  2. Select articles from the summary buffer.  Each article selected is
     displayed in the article buffer in a large window, below the
     summary buffer in its small window.

   Each Gnus buffer has its own special commands; the meanings of any
given key in the various Gnus buffers are usually analogous, even if
not identical.  Here are commands for the group and summary buffers:

`q'
     In the group buffer, update your `.newsrc' initialization file and
     quit Gnus.

     In the summary buffer, exit the current group and return to the
     group buffer.  Thus, typing `q' twice quits Gnus.

`L'
     In the group buffer, list all the groups available on your news
     server (except those you have killed).  This may be a long list!

`l'
     In the group buffer, list only the groups to which you subscribe
     and which contain unread articles.

`u'
     In the group buffer, unsubscribe from (or subscribe to) the group
     listed in the line that point is on.  When you quit Gnus by typing
     `q', Gnus lists in your `.newsrc' file which groups you have
     subscribed to.  The next time you start Gnus, you won't see this
     group, because Gnus normally displays only subscribed-to groups.

`C-k'
     In the group buffer, "kill" the current line's group--don't even
     list it in `.newsrc' from now on.  This affects future Gnus
     sessions as well as the present session.

     When you quit Gnus by typing `q', Gnus writes information in the
     file `.newsrc' describing all newsgroups except those you have
     "killed."

`<SPC>'
     In the group buffer, select the group on the line under the cursor
     and display the first unread article in that group.

     In the summary buffer,

        * Select the article on the line under the cursor if none is
          selected.

        * Scroll the text of the selected article (if there is one).

        * Select the next unread article if at the end of the current
          article.

     Thus, you can move through all the articles by repeatedly typing
     <SPC>.

`<DEL>'
     In the group buffer, move point to the previous group containing
     unread articles.

     In the summary buffer, scroll the text of the article backwards.

`n'
     Move point to the next unread group, or select the next unread
     article.

`p'
     Move point to the previous unread group, or select the previous
     unread article.

`C-n'
`C-p'
     Move point to the next or previous item, even if it is marked as
     read.  This does not select the article or group on that line.

`s'
     In the summary buffer, do an incremental search of the current
     text in the article buffer, just as if you switched to the article
     buffer and typed `C-s'.

`M-s REGEXP <RET>'
     In the summary buffer, search forward for articles containing a
     match for REGEXP.



File: emacs,  Node: Shell,  Next: Emacs Server,  Prev: Gnus,  Up: Top

41 Running Shell Commands from Emacs
************************************

Emacs has commands for passing single command lines to inferior shell
processes; it can also run a shell interactively with input and output
to an Emacs buffer named `*shell*' or run a shell inside a terminal
emulator window.

`M-! CMD <RET>'
     Run the shell command line CMD and display the output
     (`shell-command').

`M-| CMD <RET>'
     Run the shell command line CMD with region contents as input;
     optionally replace the region with the output
     (`shell-command-on-region').

`M-x shell'
     Run a subshell with input and output through an Emacs buffer.  You
     can then give commands interactively.

`M-x term'
     Run a subshell with input and output through an Emacs buffer.  You
     can then give commands interactively.  Full terminal emulation is
     available.

   `M-x eshell' invokes a shell implemented entirely in Emacs.  It is
documented in a separate manual.  *Note Eshell: (eshell)Top.

* Menu:

* Single Shell::           How to run one shell command and return.
* Interactive Shell::      Permanent shell taking input via Emacs.
* Shell Mode::             Special Emacs commands used with permanent shell.
* Shell Prompts::          Two ways to recognize shell prompts.
* History: Shell History.  Repeating previous commands in a shell buffer.
* Directory Tracking::     Keeping track when the subshell changes directory.
* Options: Shell Options.  Options for customizing Shell mode.
* Terminal emulator::      An Emacs window as a terminal emulator.
* Term Mode::              Special Emacs commands used in Term mode.
* Paging in Term::         Paging in the terminal emulator.
* Remote Host::            Connecting to another computer.


File: emacs,  Node: Single Shell,  Next: Interactive Shell,  Up: Shell

41.1 Single Shell Commands
==========================

`M-!' (`shell-command') reads a line of text using the minibuffer and
executes it as a shell command in a subshell made just for that
command.  Standard input for the command comes from the null device.
If the shell command produces any output, the output appears either in
the echo area (if it is short), or in an Emacs buffer named `*Shell
Command Output*', which is displayed in another window but not selected
(if the output is long).

   For instance, one way to decompress a file `foo.gz' from Emacs is to
type `M-! gunzip foo.gz <RET>'.  That shell command normally creates
the file `foo' and produces no terminal output.

   A numeric argument, as in `M-1 M-!', says to insert terminal output
into the current buffer instead of a separate buffer.  It puts point
before the output, and sets the mark after the output.  For instance,
`M-1 M-! gunzip < foo.gz <RET>' would insert the uncompressed
equivalent of `foo.gz' into the current buffer.

   If the shell command line ends in `&', it runs asynchronously.  For
a synchronous shell command, `shell-command' returns the command's exit
status (0 means success), when it is called from a Lisp program.  You
do not get any status information for an asynchronous command, since it
hasn't finished yet when `shell-command' returns.

   `M-|' (`shell-command-on-region') is like `M-!' but passes the
contents of the region as the standard input to the shell command,
instead of no input.  With a numeric argument, meaning insert the
output in the current buffer, it deletes the old region and the output
replaces it as the contents of the region.  It returns the command's
exit status, like `M-!'.

   One use for `M-|' is to run `gpg' to see what keys are in the
buffer.  For instance, if the buffer contains a GPG key, type `C-x h
M-| gpg <RET>' to feed the entire buffer contents to the `gpg' program.
That program will ignore everything except the encoded keys, and will
output a list of the keys the buffer contains.

   Both `M-!' and `M-|' use `shell-file-name' to specify the shell to
use.  This variable is initialized based on your `SHELL' environment
variable when Emacs is started.  If the file name is relative, Emacs
searches the directories in the list `exec-path'; this list is
initialized based on the environment variable `PATH' when Emacs is
started.  Your `.emacs' file can override either or both of these
default initializations.

   Both `M-!' and `M-|' wait for the shell command to complete, unless
you end the command with `&' to make it asynchronous.  To stop waiting,
type `C-g' to quit; that terminates the shell command with the signal
`SIGINT'--the same signal that `C-c' normally generates in the shell.
Emacs then waits until the command actually terminates.  If the shell
command doesn't stop (because it ignores the `SIGINT' signal), type
`C-g' again; this sends the command a `SIGKILL' signal which is
impossible to ignore.

   Asynchronous commands ending in `&' feed their output into the
buffer `*Async Shell Command*'.  Output arrives in that buffer
regardless of whether it is visible in a window.

   To specify a coding system for `M-!' or `M-|', use the command `C-x
<RET> c' immediately beforehand.  *Note Communication Coding::.

   Error output from these commands is normally intermixed with the
regular output.  But if the variable
`shell-command-default-error-buffer' has a string as value, and it's
the name of a buffer, `M-!' and `M-|' insert error output before point
in that buffer.


File: emacs,  Node: Interactive Shell,  Next: Shell Mode,  Prev: Single Shell,  Up: Shell

41.2 Interactive Inferior Shell
===============================

To run a subshell interactively, putting its typescript in an Emacs
buffer, use `M-x shell'.  This creates (or reuses) a buffer named
`*shell*' and runs a subshell with input coming from and output going
to that buffer.  That is to say, any "terminal output" from the subshell
goes into the buffer, advancing point, and any "terminal input" for the
subshell comes from text in the buffer.  To give input to the subshell,
go to the end of the buffer and type the input, terminated by <RET>.

   Emacs does not wait for the subshell to do anything.  You can switch
windows or buffers and edit them while the shell is waiting, or while
it is running a command.  Output from the subshell waits until Emacs
has time to process it; this happens whenever Emacs is waiting for
keyboard input or for time to elapse.

   Input lines, once you submit them, are displayed using the face
`comint-highlight-input', and prompts are displayed using the face
`comint-highlight-prompt'.  This makes it easier to see previous input
lines in the buffer.  *Note Faces::.

   To make multiple subshells, you can invoke `M-x shell' with a prefix
argument (e.g. `C-u M-x shell'), which will read a buffer name and
create (or reuse) a subshell in that buffer.  You can also rename the
`*shell*' buffer using `M-x rename-uniquely', then create a new
`*shell*' buffer using plain `M-x shell'.  Subshells in different
buffers run independently and in parallel.

   The file name used to load the subshell is the value of the variable
`explicit-shell-file-name', if that is non-`nil'.  Otherwise, the
environment variable `ESHELL' is used, or the environment variable
`SHELL' if there is no `ESHELL'.  If the file name specified is
relative, the directories in the list `exec-path' are searched; this
list is initialized based on the environment variable `PATH' when Emacs
is started.  Your `.emacs' file can override either or both of these
default initializations.

   Emacs sends the new shell the contents of the file
`~/.emacs_SHELLNAME' as input, if it exists, where SHELLNAME is the
name of the file that the shell was loaded from.  For example, if you
use bash, the file sent to it is `~/.emacs_bash'.  If this file is not
found, Emacs tries to fallback on `~/.emacs.d/init_SHELLNAME.sh'.

   To specify a coding system for the shell, you can use the command
`C-x <RET> c' immediately before `M-x shell'.  You can also change the
coding system for a running subshell by typing `C-x <RET> p' in the
shell buffer.  *Note Communication Coding::.

   Emacs sets the environment variable `INSIDE_EMACS' in the subshell
to a comma-separated list including the Emacs version.  Programs can
check this variable to determine whether they are running inside an
Emacs subshell.

   Emacs also sets the `EMACS' environment variable (to `t') if it is
not already defined.  *Warning:* This environment variable is
deprecated.  Programs that check this variable should be changed to
check `INSIDE_EMACS' instead.


File: emacs,  Node: Shell Mode,  Next: Shell Prompts,  Prev: Interactive Shell,  Up: Shell

41.3 Shell Mode
===============

Shell buffers use Shell mode, which defines several special keys
attached to the `C-c' prefix.  They are chosen to resemble the usual
editing and job control characters present in shells that are not under
Emacs, except that you must type `C-c' first.  Here is a complete list
of the special key bindings of Shell mode:

`<RET>'
     At end of buffer send line as input; otherwise, copy current line
     to end of buffer and send it (`comint-send-input').  Copying a line
     in this way omits any prompt at the beginning of the line (text
     output by programs preceding your input).  *Note Shell Prompts::,
     for how Shell mode recognizes prompts.

`<TAB>'
     Complete the command name or file name before point in the shell
     buffer (`comint-dynamic-complete').  <TAB> also completes history
     references (*note History References::) and environment variable
     names.

     The variable `shell-completion-fignore' specifies a list of file
     name extensions to ignore in Shell mode completion.  The default
     setting is `nil', but some users prefer `("~" "#" "%")' to ignore
     file names ending in `~', `#' or `%'.  Other related Comint modes
     use the variable `comint-completion-fignore' instead.

`M-?'
     Display temporarily a list of the possible completions of the file
     name before point in the shell buffer
     (`comint-dynamic-list-filename-completions').

`C-d'
     Either delete a character or send EOF
     (`comint-delchar-or-maybe-eof').  Typed at the end of the shell
     buffer, `C-d' sends EOF to the subshell.  Typed at any other
     position in the buffer, `C-d' deletes a character as usual.

`C-c C-a'
     Move to the beginning of the line, but after the prompt if any
     (`comint-bol-or-process-mark').  If you repeat this command twice
     in a row, the second time it moves back to the process mark, which
     is the beginning of the input that you have not yet sent to the
     subshell.  (Normally that is the same place--the end of the prompt
     on this line--but after `C-c <SPC>' the process mark may be in a
     previous line.)

`C-c <SPC>'
     Accumulate multiple lines of input, then send them together.  This
     command inserts a newline before point, but does not send the
     preceding text as input to the subshell--at least, not yet.  Both
     lines, the one before this newline and the one after, will be sent
     together (along with the newline that separates them), when you
     type <RET>.

`C-c C-u'
     Kill all text pending at end of buffer to be sent as input
     (`comint-kill-input').  If point is not at end of buffer, this
     only kills the part of this text that precedes point.

`C-c C-w'
     Kill a word before point (`backward-kill-word').

`C-c C-c'
     Interrupt the shell or its current subjob if any
     (`comint-interrupt-subjob').  This command also kills any shell
     input pending in the shell buffer and not yet sent.

`C-c C-z'
     Stop the shell or its current subjob if any (`comint-stop-subjob').
     This command also kills any shell input pending in the shell
     buffer and not yet sent.

`C-c C-\'
     Send quit signal to the shell or its current subjob if any
     (`comint-quit-subjob').  This command also kills any shell input
     pending in the shell buffer and not yet sent.

`C-c C-o'
     Delete the last batch of output from a shell command
     (`comint-delete-output').  This is useful if a shell command spews
     out lots of output that just gets in the way.  This command used
     to be called `comint-kill-output'.

`C-c C-s'
     Write the last batch of output from a shell command to a file
     (`comint-write-output').  With a prefix argument, the file is
     appended to instead.  Any prompt at the end of the output is not
     written.

`C-c C-r'
`C-M-l'
     Scroll to display the beginning of the last batch of output at the
     top of the window; also move the cursor there
     (`comint-show-output').

`C-c C-e'
     Scroll to put the end of the buffer at the bottom of the window
     (`comint-show-maximum-output').

`C-c C-f'
     Move forward across one shell command, but not beyond the current
     line (`shell-forward-command').  The variable
     `shell-command-regexp' specifies how to recognize the end of a
     command.

`C-c C-b'
     Move backward across one shell command, but not beyond the current
     line (`shell-backward-command').

`M-x dirs'
     Ask the shell what its current directory is, so that Emacs can
     agree with the shell.

`M-x send-invisible <RET> TEXT <RET>'
     Send TEXT as input to the shell, after reading it without echoing.
     This is useful when a shell command runs a program that asks for a
     password.

     Please note that Emacs will not echo passwords by default.  If you
     really want them to be echoed, evaluate the following Lisp
     expression:

          (remove-hook 'comint-output-filter-functions
                       'comint-watch-for-password-prompt)

`M-x comint-continue-subjob'
     Continue the shell process.  This is useful if you accidentally
     suspend the shell process.(1)

`M-x comint-strip-ctrl-m'
     Discard all control-M characters from the current group of shell
     output.  The most convenient way to use this command is to make it
     run automatically when you get output from the subshell.  To do
     that, evaluate this Lisp expression:

          (add-hook 'comint-output-filter-functions
                    'comint-strip-ctrl-m)

`M-x comint-truncate-buffer'
     This command truncates the shell buffer to a certain maximum
     number of lines, specified by the variable
     `comint-buffer-maximum-size'.  Here's how to do this automatically
     each time you get output from the subshell:

          (add-hook 'comint-output-filter-functions
                    'comint-truncate-buffer)

   Shell mode is a derivative of Comint mode, a general-purpose mode for
communicating with interactive subprocesses.  Most of the features of
Shell mode actually come from Comint mode, as you can see from the
command names listed above.  The special features of Shell mode include
the directory tracking feature, and a few user commands.

   Other Emacs features that use variants of Comint mode include GUD
(*note Debuggers::) and `M-x run-lisp' (*note External Lisp::).

   You can use `M-x comint-run' to execute any program of your choice
in a subprocess using unmodified Comint mode--without the
specializations of Shell mode.

   ---------- Footnotes ----------

   (1) You should not suspend the shell process.  Suspending a subjob
of the shell is a completely different matter--that is normal practice,
but you must use the shell to continue the subjob; this command won't
do it.


File: emacs,  Node: Shell Prompts,  Next: Shell History,  Prev: Shell Mode,  Up: Shell

41.4 Shell Prompts
==================

A prompt is text output by a program to show that it is ready to accept
new user input.  Normally, Comint mode (and thus Shell mode) considers
the prompt to be any text output by a program at the beginning of an
input line.  However, if the variable `comint-use-prompt-regexp' is
non-`nil', then Comint mode uses a regular expression to recognize
prompts.  In Shell mode, `shell-prompt-pattern' specifies the regular
expression.

   The value of `comint-use-prompt-regexp' also affects many motion and
paragraph commands.  If the value is non-`nil', the general Emacs
motion commands behave as they normally do in buffers without special
text properties.  However, if the value is `nil', the default, then
Comint mode divides the buffer into two types of "fields" (ranges of
consecutive characters having the same `field' text property): input
and output.  Prompts are part of the output.  Most Emacs motion
commands do not cross field boundaries, unless they move over multiple
lines.  For instance, when point is in input on the same line as a
prompt, `C-a' puts point at the beginning of the input if
`comint-use-prompt-regexp' is `nil' and at the beginning of the line
otherwise.

   In Shell mode, only shell prompts start new paragraphs.  Thus, a
paragraph consists of a prompt and the input and output that follow it.
However, if `comint-use-prompt-regexp' is `nil', the default, most
paragraph commands do not cross field boundaries.  This means that
prompts, ranges of input, and ranges of non-prompt output behave mostly
like separate paragraphs; with this setting, numeric arguments to most
paragraph commands yield essentially undefined behavior.  For the
purpose of finding paragraph boundaries, Shell mode uses
`shell-prompt-pattern', regardless of `comint-use-prompt-regexp'.


File: emacs,  Node: Shell History,  Next: Directory Tracking,  Prev: Shell Prompts,  Up: Shell

41.5 Shell Command History
==========================

Shell buffers support three ways of repeating earlier commands.  You
can use keys like those used for the minibuffer history; these work
much as they do in the minibuffer, inserting text from prior commands
while point remains always at the end of the buffer.  You can move
through the buffer to previous inputs in their original place, then
resubmit them or copy them to the end.  Or you can use a `!'-style
history reference.

* Menu:

* Ring: Shell Ring.             Fetching commands from the history list.
* Copy: Shell History Copying.  Moving to a command and then copying it.
* History References::          Expanding `!'-style history references.


File: emacs,  Node: Shell Ring,  Next: Shell History Copying,  Up: Shell History

41.5.1 Shell History Ring
-------------------------

`M-p'
`C-<UP>'
     Fetch the next earlier old shell command.

`M-n'
`C-<DOWN>'
     Fetch the next later old shell command.

`M-r REGEXP <RET>'
`M-s REGEXP <RET>'
     Search backwards or forwards for old shell commands that match
     REGEXP.

`C-c C-x'
     Fetch the next subsequent command from the history.

`C-c .'
     Fetch one argument from an old shell command.

`C-c C-l'
     Display the buffer's history of shell commands in another window
     (`comint-dynamic-list-input-ring').

   Shell buffers provide a history of previously entered shell
commands.  To reuse shell commands from the history, use the editing
commands `M-p', `M-n', `M-r' and `M-s'.  These work just like the
minibuffer history commands except that they operate on the text at the
end of the shell buffer, where you would normally insert text to send
to the shell.

   `M-p' fetches an earlier shell command to the end of the shell
buffer.  Successive use of `M-p' fetches successively earlier shell
commands, each replacing any text that was already present as potential
shell input.  `M-n' does likewise except that it finds successively
more recent shell commands from the buffer.  `C-<UP>' works like `M-p',
and `C-<DOWN>' like `M-n'.

   The history search commands `M-r' and `M-s' read a regular
expression and search through the history for a matching command.  Aside
from the choice of which command to fetch, they work just like `M-p'
and `M-n'.  If you enter an empty regexp, these commands reuse the same
regexp used last time.

   When you find the previous input you want, you can resubmit it by
typing <RET>, or you can edit it first and then resubmit it if you
wish.  Any partial input you were composing before navigating the
history list is restored when you go to the beginning or end of the
history ring.

   Often it is useful to reexecute several successive shell commands
that were previously executed in sequence.  To do this, first find and
reexecute the first command of the sequence.  Then type `C-c C-x'; that
will fetch the following command--the one that follows the command you
just repeated.  Then type <RET> to reexecute this command.  You can
reexecute several successive commands by typing `C-c C-x <RET>' over
and over.

   The command `C-c .' (`comint-input-previous-argument') copies an
individual argument from a previous command, like `ESC .' in Bash.  The
simplest use copies the last argument from the previous shell command.
With a prefix argument N, it copies the Nth argument instead.
Repeating `C-c .' copies from an earlier shell command instead, always
using the same value of N (don't give a prefix argument when you repeat
the `C-c .' command).

   These commands get the text of previous shell commands from a special
history list, not from the shell buffer itself.  Thus, editing the shell
buffer, or even killing large parts of it, does not affect the history
that these commands access.

   Some shells store their command histories in files so that you can
refer to commands from previous shell sessions.  Emacs reads the
command history file for your chosen shell, to initialize its own
command history.  The file name is `~/.bash_history' for bash,
`~/.sh_history' for ksh, and `~/.history' for other shells.


File: emacs,  Node: Shell History Copying,  Next: History References,  Prev: Shell Ring,  Up: Shell History

41.5.2 Shell History Copying
----------------------------

`C-c C-p'
     Move point to the previous prompt (`comint-previous-prompt').

`C-c C-n'
     Move point to the following prompt (`comint-next-prompt').

`C-c <RET>'
     Copy the input command which point is in, inserting the copy at
     the end of the buffer (`comint-copy-old-input').  This is useful
     if you move point back to a previous command.  After you copy the
     command, you can submit the copy as input with <RET>.  If you
     wish, you can edit the copy before resubmitting it.  If you use
     this command on an output line, it copies that line to the end of
     the buffer.

`Mouse-2'
     If `comint-use-prompt-regexp' is `nil' (the default), copy the old
     input command that you click on, inserting the copy at the end of
     the buffer (`comint-insert-input').  If `comint-use-prompt-regexp'
     is non-`nil', or if the click is not over old input, just yank as
     usual.

   Moving to a previous input and then copying it with `C-c <RET>' or
`Mouse-2' produces the same results--the same buffer contents--that you
would get by using `M-p' enough times to fetch that previous input from
the history list.  However, `C-c <RET>' copies the text from the
buffer, which can be different from what is in the history list if you
edit the input text in the buffer after it has been sent.


File: emacs,  Node: History References,  Prev: Shell History Copying,  Up: Shell History

41.5.3 Shell History References
-------------------------------

Various shells including csh and bash support "history references" that
begin with `!' and `^'.  Shell mode recognizes these constructs, and
can perform the history substitution for you.

   If you insert a history reference and type <TAB>, this searches the
input history for a matching command, performs substitution if
necessary, and places the result in the buffer in place of the history
reference.  For example, you can fetch the most recent command
beginning with `mv' with `! m v <TAB>'.  You can edit the command if
you wish, and then resubmit the command to the shell by typing <RET>.

   Shell mode can optionally expand history references in the buffer
when you send them to the shell.  To request this, set the variable
`comint-input-autoexpand' to `input'.  You can make <SPC> perform
history expansion by binding <SPC> to the command `comint-magic-space'.

   Shell mode recognizes history references when they follow a prompt.
*Note Shell Prompts::, for how Shell mode recognizes prompts.


File: emacs,  Node: Directory Tracking,  Next: Shell Options,  Prev: Shell History,  Up: Shell

41.6 Directory Tracking
=======================

Shell mode keeps track of `cd', `pushd' and `popd' commands given to
the inferior shell, so it can keep the `*shell*' buffer's default
directory the same as the shell's working directory.  It recognizes
these commands syntactically, by examining lines of input that are sent.

   If you use aliases for these commands, you can tell Emacs to
recognize them also.  For example, if the value of the variable
`shell-pushd-regexp' matches the beginning of a shell command line,
that line is regarded as a `pushd' command.  Change this variable when
you add aliases for `pushd'.  Likewise, `shell-popd-regexp' and
`shell-cd-regexp' are used to recognize commands with the meaning of
`popd' and `cd'.  These commands are recognized only at the beginning
of a shell command line.

   If Emacs gets confused about changes in the current directory of the
subshell, use the command `M-x dirs' to ask the shell what its current
directory is.  This command works for shells that support the most
common command syntax; it may not work for unusual shells.

   You can also use `M-x dirtrack-mode' to enable (or disable) an
alternative and more aggressive method of tracking changes in the
current directory.


File: emacs,  Node: Shell Options,  Next: Terminal emulator,  Prev: Directory Tracking,  Up: Shell

41.7 Shell Mode Options
=======================

If the variable `comint-scroll-to-bottom-on-input' is non-`nil',
insertion and yank commands scroll the selected window to the bottom
before inserting.  The default is `nil'.

   If `comint-scroll-show-maximum-output' is non-`nil', then arrival of
output when point is at the end tries to scroll the last line of text
to the bottom line of the window, showing as much useful text as
possible.  (This mimics the scrolling behavior of most terminals.)  The
default is `t'.

   By setting `comint-move-point-for-output', you can opt for having
point jump to the end of the buffer whenever output arrives--no matter
where in the buffer point was before.  If the value is `this', point
jumps in the selected window.  If the value is `all', point jumps in
each window that shows the Comint buffer.  If the value is `other',
point jumps in all nonselected windows that show the current buffer.
The default value is `nil', which means point does not jump to the end.

   If you set `comint-prompt-read-only', the prompts in the Comint
buffer are read-only.

   The variable `comint-input-ignoredups' controls whether successive
identical inputs are stored in the input history.  A non-`nil' value
means to omit an input that is the same as the previous input.  The
default is `nil', which means to store each input even if it is equal
to the previous input.

   Three variables customize file name completion.  The variable
`comint-completion-addsuffix' controls whether completion inserts a
space or a slash to indicate a fully completed file or directory name
(non-`nil' means do insert a space or slash).
`comint-completion-recexact', if non-`nil', directs <TAB> to choose the
shortest possible completion if the usual Emacs completion algorithm
cannot add even a single character.  `comint-completion-autolist', if
non-`nil', says to list all the possible completions whenever
completion is not exact.

   Command completion normally considers only executable files.  If you
set `shell-completion-execonly' to `nil', it considers nonexecutable
files as well.

   You can configure the behavior of `pushd'.  Variables control
whether `pushd' behaves like `cd' if no argument is given
(`shell-pushd-tohome'), pop rather than rotate with a numeric argument
(`shell-pushd-dextract'), and only add directories to the directory
stack if they are not already on it (`shell-pushd-dunique').  The
values you choose should match the underlying shell, of course.

   If you want Shell mode to handle color output from shell commands,
you can enable ANSI Color mode.  Here is how to do this:

     (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)


File: emacs,  Node: Terminal emulator,  Next: Term Mode,  Prev: Shell Options,  Up: Shell

41.8 Emacs Terminal Emulator
============================

To run a subshell in a terminal emulator, putting its typescript in an
Emacs buffer, use `M-x term'.  This creates (or reuses) a buffer named
`*terminal*', and runs a subshell with input coming from your keyboard,
and output going to that buffer.

   The terminal emulator uses Term mode, which has two input modes.  In
line mode, Term basically acts like Shell mode; see *note Shell Mode::.

   In char mode, each character is sent directly to the inferior
subshell, as "terminal input."  Any "echoing" of your input is the
responsibility of the subshell.  The sole exception is the terminal
escape character, which by default is `C-c' (*note Term Mode::).  Any
"terminal output" from the subshell goes into the buffer, advancing
point.

   Some programs (such as Emacs itself) need to control the appearance
on the terminal screen in detail.  They do this by sending special
control codes.  The exact control codes needed vary from terminal to
terminal, but nowadays most terminals and terminal emulators (including
`xterm') understand the ANSI-standard (VT100-style) escape sequences.
Term mode recognizes these escape sequences, and handles each one
appropriately, changing the buffer so that the appearance of the window
matches what it would be on a real terminal.  You can actually run
Emacs inside an Emacs Term window.

   The file name used to load the subshell is determined the same way
as for Shell mode.  To make multiple terminal emulators, rename the
buffer `*terminal*' to something different using `M-x rename-uniquely',
just as with Shell mode.

   Unlike Shell mode, Term mode does not track the current directory by
examining your input.  But some shells can tell Term what the current
directory is.  This is done automatically by `bash' version 1.15 and
later.


File: emacs,  Node: Term Mode,  Next: Paging in Term,  Prev: Terminal emulator,  Up: Shell

41.9 Term Mode
==============

The terminal emulator uses Term mode, which has two input modes.  In
line mode, Term basically acts like Shell mode; see *note Shell Mode::.
In char mode, each character is sent directly to the inferior subshell,
except for the Term escape character, normally `C-c'.

   To switch between line and char mode, use these commands:

`C-c C-j'
     Switch to line mode.  Do nothing if already in line mode.

`C-c C-k'
     Switch to char mode.  Do nothing if already in char mode.

   The following commands are only available in char mode:

`C-c C-c'
     Send a literal <C-c> to the sub-shell.

`C-c CHAR'
     This is equivalent to `C-x CHAR' in normal Emacs.  For example,
     `C-c o' invokes the global binding of `C-x o', which is normally
     `other-window'.


File: emacs,  Node: Paging in Term,  Next: Remote Host,  Prev: Term Mode,  Up: Shell

41.10 Page-At-A-Time Output
===========================

Term mode has a page-at-a-time feature.  When enabled it makes output
pause at the end of each screenful.

`C-c C-q'
     Toggle the page-at-a-time feature.  This command works in both line
     and char modes.  When page-at-a-time is enabled, the mode-line
     displays the word `page'.

   With page-at-a-time enabled, whenever Term receives more than a
screenful of output since your last input, it pauses, displaying
`**MORE**' in the mode-line.  Type <SPC> to display the next screenful
of output.  Type `?' to see your other options.  The interface is
similar to the `more' program.


File: emacs,  Node: Remote Host,  Prev: Paging in Term,  Up: Shell

41.11 Remote Host Shell
=======================

You can login to a remote computer, using whatever commands you would
from a regular terminal (e.g. using the `telnet' or `rlogin' commands),
from a Term window.

   A program that asks you for a password will normally suppress
echoing of the password, so the password will not show up in the
buffer.  This will happen just as if you were using a real terminal, if
the buffer is in char mode.  If it is in line mode, the password is
temporarily visible, but will be erased when you hit return.  (This
happens automatically; there is no special password processing.)

   When you log in to a different machine, you need to specify the type
of terminal you're using, by setting the `TERM' environment variable in
the environment for the remote login command.  (If you use bash, you do
that by writing the variable assignment before the remote login
command, without separating comma.)  Terminal types `ansi' or `vt100'
will work on most systems.


File: emacs,  Node: Emacs Server,  Next: Printing,  Prev: Shell,  Up: Top

42 Using Emacs as a Server
**************************

Various programs such as `mail' can invoke your choice of editor to
edit a particular piece of text, such as a message that you are
sending.  By convention, most of these programs use the environment
variable `EDITOR' to specify which editor to run.  If you set `EDITOR'
to `emacs', they invoke Emacs--but in an inconvenient fashion, by
starting a new, separate Emacs process.  This is inconvenient because
it takes time and because the new Emacs process doesn't share the
buffers with any existing Emacs process.

   You can arrange to use your existing Emacs process as the editor for
programs like `mail' by using the Emacs client program and the server
that is part of Emacs.  Here is how.

   First, the preparations.  Within Emacs, call the function
`server-start'.  (Your `.emacs' init file can do this automatically if
you add the expression `(server-start)' to it, see *note Init File::.)
Then, outside Emacs, set the `EDITOR' environment variable to
`emacsclient'.  (Note that some programs use a different environment
variable; for example, to make TeX use `emacsclient', you should set
the `TEXEDIT' environment variable to `emacsclient +%d %s'.)

   As an alternative to using `emacsclient', the file `etc/emacs.bash'
defines a Bash command `edit' which will communicate with a running
Emacs session, or start one if none exist.

   Now, whenever any program invokes your specified `EDITOR' program,
the effect is to send a message to your principal Emacs telling it to
visit a file.  (That's what the program `emacsclient' does.)  Emacs
displays the buffer immediately and you can immediately begin editing
it in the already running Emacs session.

   When you've finished editing that buffer, type `C-x #'
(`server-edit').  This saves the file and sends a message back to the
`emacsclient' program telling it to exit.  The programs that use
`EDITOR' wait for the "editor" (actually, `emacsclient') to exit.  `C-x
#' also checks for other pending external requests to edit various
files, and selects the next such file.

   You can switch to a server buffer manually if you wish; you don't
have to arrive at it with `C-x #'.  But `C-x #' is the way to say that
you are finished with one.

   Finishing with a server buffer also kills the buffer, unless it
already existed in the Emacs session before the server asked to create
it.  However, if you set `server-kill-new-buffers' to `nil', then a
different criterion is used: finishing with a server buffer kills it if
the file name matches the regular expression `server-temp-file-regexp'.
This is set up to distinguish certain "temporary" files.

   If you set the variable `server-window' to a window or a frame, `C-x
#' displays the server buffer in that window or in that frame.

   You can run multiple Emacs servers on the same machine by giving
each one a unique "server name", using the variable `server-name'.  For
example, `M-x set-variable <RET> server-name <RET> foo <RET>' sets the
server name to `foo'.  The `emacsclient' program can specify a server by
name using the `-s' option.  *Note Invoking emacsclient::.

   While `mail' or another application is waiting for `emacsclient' to
finish, `emacsclient' does not read terminal input.  So the terminal
that `mail' was using is effectively blocked for the duration.  In
order to edit with your principal Emacs, you need to be able to use it
without using that terminal.  There are three ways to do this:

   * Using a window system, run `mail' and the principal Emacs in two
     separate windows.  While `mail' is waiting for `emacsclient', the
     window where it was running is blocked, but you can use Emacs by
     switching windows.

   * Using virtual terminals, run `mail' in one virtual terminal and
     run Emacs in another.

   * Use Shell mode or Term mode in Emacs to run the other program such
     as `mail'; then, `emacsclient' blocks only the subshell under
     Emacs, and you can still use Emacs to edit the file.

   If you run `emacsclient' with the option `--no-wait', it returns
immediately without waiting for you to "finish" the buffer in Emacs.
Note that server buffers created in this way are not killed
automatically when you finish with them.

* Menu:

* Invoking emacsclient:: Emacs client startup options.


File: emacs,  Node: Invoking emacsclient,  Prev: Emacs Server,  Up: Emacs Server

42.1 Invoking `emacsclient'
===========================

To run the `emacsclient' program, specify file names as arguments, and
optionally line numbers as well, like this:

     emacsclient {[+LINE[COLUMN]] FILENAME}...

This tells Emacs to visit each of the specified files; if you specify a
line number for a certain file, Emacs moves to that line in the file.
If you specify a column number as well, Emacs puts point on that column
in the line.

   Ordinarily, `emacsclient' does not return until you use the `C-x #'
command on each of these buffers.  When that happens, Emacs sends a
message to the `emacsclient' program telling it to return.

   If you invoke `emacsclient' for more than one file, the additional
client buffers are buried at the bottom of the buffer list (*note
Buffers::).  If you call `C-x #' after you are done editing a client
buffer, the next client buffer is automatically selected.

   But if you use the option `-n' or `--no-wait' when running
`emacsclient', then it returns immediately.  (You can take as long as
you like to edit the files in Emacs.)

   The option `-a COMMAND' or `--alternate-editor=COMMAND' specifies a
command to run if `emacsclient' fails to contact Emacs.  This is useful
when running `emacsclient' in a script.  For example, the following
setting for the `EDITOR' environment variable will always give you an
editor, even if no Emacs server is running:

     EDITOR="emacsclient --alternate-editor emacs +%d %s"

The environment variable `ALTERNATE_EDITOR' has the same effect, with
the value of the `--alternate-editor' option taking precedence.

   If you use several displays, you can tell Emacs on which display to
open the given files with the `-d DISPLAY' or `--display=DISPLAY'
option to `emacsclient'.  This is handy when connecting from home to an
Emacs session running on your machine at your workplace.

   If there is more than one Emacs server running, you can specify a
server name with the `-s NAME' or `--socket-name=NAME' option to
`emacsclient'.  (This option is not supported on MS-Windows.)

   You can also use `emacsclient' to execute any piece of Emacs Lisp
code, using the `-e' or `--eval' option.  When this option is given,
the rest of the arguments is interpreted as a list of expressions to
evaluate, not a list of files to visit.

   When you start the Emacs server (by calling `server-start'), Emacs
creates a file with information about TCP connection to the server: the
host where Emacs is running, the port where it is listening, and an
authentication string.  `emacsclient' uses this information if it needs
to connect to the server via TCP.  By default, the file goes in the
`~/.emacs.d/server/' directory(1).  You can specify the file name to
use with the `-f FILE' or `--server-file=FILE' options, or by setting
`EMACS_SERVER_FILE' environment variable to the file name.

   ---------- Footnotes ----------

   (1) On MS-Windows, if `HOME' is not set or the TCP configuration file
cannot be found there, Emacs also looks for the file in the
`.emacs.d/server/' subdirectory of the directory pointed to by the
`APPDATA' environment variable.


File: emacs,  Node: Printing,  Next: Sorting,  Prev: Emacs Server,  Up: Top

43 Printing Hard Copies
***********************

Emacs provides commands for printing hard copies of either an entire
buffer or just part of one, with or without page headers.  You can
invoke the printing commands directly, as detailed in the following
section, or using the `File' menu on the menu bar.  See also the
hardcopy commands of Dired (*note Misc File Ops::) and the diary (*note
Displaying the Diary::).

`M-x print-buffer'
     Print hardcopy of current buffer with page headings containing the
     file name and page number.

`M-x lpr-buffer'
     Print hardcopy of current buffer without page headings.

`M-x print-region'
     Like `print-buffer' but print only the current region.

`M-x lpr-region'
     Like `lpr-buffer' but print only the current region.

   The hardcopy commands (aside from the PostScript commands) pass extra
switches to the `lpr' program based on the value of the variable
`lpr-switches'.  Its value should be a list of strings, each string an
option starting with `-'.  For example, to specify a line width of 80
columns for all the printing you do in Emacs, set `lpr-switches' like
this:

     (setq lpr-switches '("-w80"))

   You can specify the printer to use by setting the variable
`printer-name'.

   The variable `lpr-command' specifies the name of the printer program
to run; the default value depends on your operating system type.  On
most systems, the default is `"lpr"'.  The variable
`lpr-headers-switches' similarly specifies the extra switches to use to
make page headers.  The variable `lpr-add-switches' controls whether to
supply `-T' and `-J' options (suitable for `lpr') to the printer
program: `nil' means don't add them.  `lpr-add-switches' should be
`nil' if your printer program is not compatible with `lpr'.

* Menu:

* PostScript::	         Printing buffers or regions as PostScript.
* PostScript Variables:: Customizing the PostScript printing commands.
* Printing Package::     An optional advanced printing interface.


File: emacs,  Node: PostScript,  Next: PostScript Variables,  Up: Printing

44 PostScript Hardcopy
**********************

These commands convert buffer contents to PostScript, either printing
it or leaving it in another Emacs buffer.

`M-x ps-print-buffer'
     Print hardcopy of the current buffer in PostScript form.

`M-x ps-print-region'
     Print hardcopy of the current region in PostScript form.

`M-x ps-print-buffer-with-faces'
     Print hardcopy of the current buffer in PostScript form, showing
     the faces used in the text by means of PostScript features.

`M-x ps-print-region-with-faces'
     Print hardcopy of the current region in PostScript form, showing
     the faces used in the text.

`M-x ps-spool-buffer'
     Generate PostScript for the current buffer text.

`M-x ps-spool-region'
     Generate PostScript for the current region.

`M-x ps-spool-buffer-with-faces'
     Generate PostScript for the current buffer, showing the faces used.

`M-x ps-spool-region-with-faces'
     Generate PostScript for the current region, showing the faces used.

`M-x handwrite'
     Generates/prints PostScript for the current buffer as if
     handwritten.

   The PostScript commands, `ps-print-buffer' and `ps-print-region',
print buffer contents in PostScript form.  One command prints the
entire buffer; the other, just the region.  The corresponding
`-with-faces' commands, `ps-print-buffer-with-faces' and
`ps-print-region-with-faces', use PostScript features to show the faces
(fonts and colors) in the text properties of the text being printed.

   If you are using a color display, you can print a buffer of program
code with color highlighting by turning on Font-Lock mode in that
buffer, and using `ps-print-buffer-with-faces'.

   The commands whose names have `spool' instead of `print' generate
the PostScript output in an Emacs buffer instead of sending it to the
printer.

   `M-x handwrite' is more frivolous.  It generates a PostScript
rendition of the current buffer as a cursive handwritten document.  It
can be customized in group `handwrite'.  This function only supports
ISO 8859-1 characters.

   The following section describes variables for customizing these
commands.


File: emacs,  Node: PostScript Variables,  Next: Printing Package,  Prev: PostScript,  Up: Printing

45 Variables for PostScript Hardcopy
************************************

All the PostScript hardcopy commands use the variables `ps-lpr-command'
and `ps-lpr-switches' to specify how to print the output.
`ps-lpr-command' specifies the command name to run, `ps-lpr-switches'
specifies command line options to use, and `ps-printer-name' specifies
the printer.  If you don't set the first two variables yourself, they
take their initial values from `lpr-command' and `lpr-switches'.  If
`ps-printer-name' is `nil', `printer-name' is used.

   The variable `ps-print-header' controls whether these commands add
header lines to each page--set it to `nil' to turn headers off.

   If your printer doesn't support colors, you should turn off color
processing by setting `ps-print-color-p' to `nil'.  By default, if the
display supports colors, Emacs produces hardcopy output with color
information; on black-and-white printers, colors are emulated with
shades of gray.  This might produce illegible output, even if your
screen colors only use shades of gray.

   By default, PostScript printing ignores the background colors of the
faces, unless the variable `ps-use-face-background' is non-`nil'.  This
is to avoid unwanted interference with the zebra stripes and background
image/text.

   The variable `ps-paper-type' specifies which size of paper to format
for; legitimate values include `a4', `a3', `a4small', `b4', `b5',
`executive', `ledger', `legal', `letter', `letter-small', `statement',
`tabloid'.  The default is `letter'.  You can define additional paper
sizes by changing the variable `ps-page-dimensions-database'.

   The variable `ps-landscape-mode' specifies the orientation of
printing on the page.  The default is `nil', which stands for
"portrait" mode.  Any non-`nil' value specifies "landscape" mode.

   The variable `ps-number-of-columns' specifies the number of columns;
it takes effect in both landscape and portrait mode.  The default is 1.

   The variable `ps-font-family' specifies which font family to use for
printing ordinary text.  Legitimate values include `Courier',
`Helvetica', `NewCenturySchlbk', `Palatino' and `Times'.  The variable
`ps-font-size' specifies the size of the font for ordinary text.  It
defaults to 8.5 points.

   Emacs supports more scripts and characters than a typical PostScript
printer.  Thus, some of the characters in your buffer might not be
printable using the fonts built into your printer.  You can augment the
fonts supplied with the printer with those from the GNU Intlfonts
package, or you can instruct Emacs to use Intlfonts exclusively.  The
variable `ps-multibyte-buffer' controls this: the default value, `nil',
is appropriate for printing ASCII and Latin-1 characters; a value of
`non-latin-printer' is for printers which have the fonts for ASCII,
Latin-1, Japanese, and Korean characters built into them.  A value of
`bdf-font' arranges for the BDF fonts from the Intlfonts package to be
used for _all_ characters.  Finally, a value of `bdf-font-except-latin'
instructs the printer to use built-in fonts for ASCII and Latin-1
characters, and Intlfonts BDF fonts for the rest.

   To be able to use the BDF fonts, Emacs needs to know where to find
them.  The variable `bdf-directory-list' holds the list of directories
where Emacs should look for the fonts; the default value includes a
single directory `/usr/local/share/emacs/fonts/bdf'.

   Many other customization variables for these commands are defined and
described in the Lisp files `ps-print.el' and `ps-mule.el'.


File: emacs,  Node: Printing Package,  Prev: PostScript Variables,  Up: Printing

46 Printing Package
*******************

The basic Emacs facilities for printing hardcopy can be extended using
the Printing package.  This provides an easy-to-use interface for
choosing what to print, previewing PostScript files before printing,
and setting various printing options such as print headers, landscape
or portrait modes, duplex modes, and so forth.  On GNU/Linux or Unix
systems, the Printing package relies on the `gs' and `gv' utilities,
which are distributed as part of the GhostScript program.  On
MS-Windows, the `gstools' port of Ghostscript can be used.

   To use the Printing package, add `(require 'printing)' to your init
file (*note Init File::), followed by `(pr-update-menus)'.  This
function replaces the usual printing commands in the menu bar with a
`Printing' submenu that contains various printing options.  You can
also type `M-x pr-interface RET'; this creates a `*Printing Interface*'
buffer, similar to a customization buffer, where you can set the
printing options.  After selecting what and how to print, you start the
print job using the `Print' button (click `mouse-2' on it, or move
point over it and type `RET').  For further information on the various
options, use the `Interface Help' button.


File: emacs,  Node: Sorting,  Next: Narrowing,  Prev: Printing,  Up: Top

47 Sorting Text
***************

Emacs provides several commands for sorting text in the buffer.  All
operate on the contents of the region.  They divide the text of the
region into many "sort records", identify a "sort key" for each record,
and then reorder the records into the order determined by the sort
keys.  The records are ordered so that their keys are in alphabetical
order, or, for numeric sorting, in numeric order.  In alphabetic
sorting, all upper-case letters `A' through `Z' come before lower-case
`a', in accord with the ASCII character sequence.

   The various sort commands differ in how they divide the text into
sort records and in which part of each record is used as the sort key.
Most of the commands make each line a separate sort record, but some
commands use paragraphs or pages as sort records.  Most of the sort
commands use each entire sort record as its own sort key, but some use
only a portion of the record as the sort key.

`M-x sort-lines'
     Divide the region into lines, and sort by comparing the entire
     text of a line.  A numeric argument means sort into descending
     order.

`M-x sort-paragraphs'
     Divide the region into paragraphs, and sort by comparing the entire
     text of a paragraph (except for leading blank lines).  A numeric
     argument means sort into descending order.

`M-x sort-pages'
     Divide the region into pages, and sort by comparing the entire
     text of a page (except for leading blank lines).  A numeric
     argument means sort into descending order.

`M-x sort-fields'
     Divide the region into lines, and sort by comparing the contents of
     one field in each line.  Fields are defined as separated by
     whitespace, so the first run of consecutive non-whitespace
     characters in a line constitutes field 1, the second such run
     constitutes field 2, etc.

     Specify which field to sort by with a numeric argument: 1 to sort
     by field 1, etc.  A negative argument means count fields from the
     right instead of from the left; thus, minus 1 means sort by the
     last field.  If several lines have identical contents in the field
     being sorted, they keep the same relative order that they had in
     the original buffer.

`M-x sort-numeric-fields'
     Like `M-x sort-fields' except the specified field is converted to
     an integer for each line, and the numbers are compared.  `10'
     comes before `2' when considered as text, but after it when
     considered as a number.  By default, numbers are interpreted
     according to `sort-numeric-base', but numbers beginning with `0x'
     or `0' are interpreted as hexadecimal and octal, respectively.

`M-x sort-columns'
     Like `M-x sort-fields' except that the text within each line used
     for comparison comes from a fixed range of columns.  See below for
     an explanation.

`M-x reverse-region'
     Reverse the order of the lines in the region.  This is useful for
     sorting into descending order by fields or columns, since those
     sort commands do not have a feature for doing that.

   For example, if the buffer contains this:

     On systems where clash detection (locking of files being edited) is
     implemented, Emacs also checks the first time you modify a buffer
     whether the file has changed on disk since it was last visited or
     saved.  If it has, you are asked to confirm that you want to change
     the buffer.

applying `M-x sort-lines' to the entire buffer produces this:

     On systems where clash detection (locking of files being edited) is
     implemented, Emacs also checks the first time you modify a buffer
     saved.  If it has, you are asked to confirm that you want to change
     the buffer.
     whether the file has changed on disk since it was last visited or

where the upper-case `O' sorts before all lower-case letters.  If you
use `C-u 2 M-x sort-fields' instead, you get this:

     implemented, Emacs also checks the first time you modify a buffer
     saved.  If it has, you are asked to confirm that you want to change
     the buffer.
     On systems where clash detection (locking of files being edited) is
     whether the file has changed on disk since it was last visited or

where the sort keys were `Emacs', `If', `buffer', `systems' and `the'.

   `M-x sort-columns' requires more explanation.  You specify the
columns by putting point at one of the columns and the mark at the other
column.  Because this means you cannot put point or the mark at the
beginning of the first line of the text you want to sort, this command
uses an unusual definition of "region": all of the line point is in is
considered part of the region, and so is all of the line the mark is in,
as well as all the lines in between.

   For example, to sort a table by information found in columns 10 to
15, you could put the mark on column 10 in the first line of the table,
and point on column 15 in the last line of the table, and then run
`sort-columns'.  Equivalently, you could run it with the mark on column
15 in the first line and point on column 10 in the last line.

   This can be thought of as sorting the rectangle specified by point
and the mark, except that the text on each line to the left or right of
the rectangle moves along with the text inside the rectangle.  *Note
Rectangles::.

   Many of the sort commands ignore case differences when comparing, if
`sort-fold-case' is non-`nil'.


File: emacs,  Node: Narrowing,  Next: Two-Column,  Prev: Sorting,  Up: Top

48 Narrowing
************

"Narrowing" means focusing in on some portion of the buffer, making the
rest temporarily inaccessible.  The portion which you can still get to
is called the "accessible portion".  Canceling the narrowing, which
makes the entire buffer once again accessible, is called "widening".
The bounds of narrowing in effect in a buffer are called the buffer's
"restriction".

   Narrowing can make it easier to concentrate on a single subroutine or
paragraph by eliminating clutter.  It can also be used to limit the
range of operation of a replace command or repeating keyboard macro.

`C-x n n'
     Narrow down to between point and mark (`narrow-to-region').

`C-x n w'
     Widen to make the entire buffer accessible again (`widen').

`C-x n p'
     Narrow down to the current page (`narrow-to-page').

`C-x n d'
     Narrow down to the current defun (`narrow-to-defun').

   When you have narrowed down to a part of the buffer, that part
appears to be all there is.  You can't see the rest, you can't move
into it (motion commands won't go outside the accessible part), you
can't change it in any way.  However, it is not gone, and if you save
the file all the inaccessible text will be saved.  The word `Narrow'
appears in the mode line whenever narrowing is in effect.

   The primary narrowing command is `C-x n n' (`narrow-to-region').  It
sets the current buffer's restrictions so that the text in the current
region remains accessible, but all text before the region or after the
region is inaccessible.  Point and mark do not change.

   Alternatively, use `C-x n p' (`narrow-to-page') to narrow down to
the current page.  *Note Pages::, for the definition of a page.  `C-x n
d' (`narrow-to-defun') narrows down to the defun containing point
(*note Defuns::).

   The way to cancel narrowing is to widen with `C-x n w' (`widen').
This makes all text in the buffer accessible again.

   You can get information on what part of the buffer you are narrowed
down to using the `C-x =' command.  *Note Position Info::.

   Because narrowing can easily confuse users who do not understand it,
`narrow-to-region' is normally a disabled command.  Attempting to use
this command asks for confirmation and gives you the option of enabling
it; if you enable the command, confirmation will no longer be required
for it.  *Note Disabling::.


File: emacs,  Node: Two-Column,  Next: Editing Binary Files,  Prev: Narrowing,  Up: Top

49 Two-Column Editing
*********************

Two-column mode lets you conveniently edit two side-by-side columns of
text.  It uses two side-by-side windows, each showing its own buffer.

   There are three ways to enter two-column mode:

`<F2> 2' or `C-x 6 2'
     Enter two-column mode with the current buffer on the left, and on
     the right, a buffer whose name is based on the current buffer's
     name (`2C-two-columns').  If the right-hand buffer doesn't already
     exist, it starts out empty; the current buffer's contents are not
     changed.

     This command is appropriate when the current buffer is empty or
     contains just one column and you want to add another column.

`<F2> s' or `C-x 6 s'
     Split the current buffer, which contains two-column text, into two
     buffers, and display them side by side (`2C-split').  The current
     buffer becomes the left-hand buffer, but the text in the right-hand
     column is moved into the right-hand buffer.  The current column
     specifies the split point.  Splitting starts with the current line
     and continues to the end of the buffer.

     This command is appropriate when you have a buffer that already
     contains two-column text, and you wish to separate the columns
     temporarily.

`<F2> b BUFFER <RET>'
`C-x 6 b BUFFER <RET>'
     Enter two-column mode using the current buffer as the left-hand
     buffer, and using buffer BUFFER as the right-hand buffer
     (`2C-associate-buffer').

   `<F2> s' or `C-x 6 s' looks for a column separator, which is a
string that appears on each line between the two columns.  You can
specify the width of the separator with a numeric argument to `<F2> s';
that many characters, before point, constitute the separator string.
By default, the width is 1, so the column separator is the character
before point.

   When a line has the separator at the proper place, `<F2> s' puts the
text after the separator into the right-hand buffer, and deletes the
separator.  Lines that don't have the column separator at the proper
place remain unsplit; they stay in the left-hand buffer, and the
right-hand buffer gets an empty line to correspond.  (This is the way
to write a line that "spans both columns while in two-column mode":
write it in the left-hand buffer, and put an empty line in the
right-hand buffer.)

   The command `C-x 6 <RET>' or `<F2> <RET>' (`2C-newline') inserts a
newline in each of the two buffers at corresponding positions.  This is
the easiest way to add a new line to the two-column text while editing
it in split buffers.

   When you have edited both buffers as you wish, merge them with `<F2>
1' or `C-x 6 1' (`2C-merge').  This copies the text from the right-hand
buffer as a second column in the other buffer.  To go back to
two-column editing, use `<F2> s'.

   Use `<F2> d' or `C-x 6 d' to dissociate the two buffers, leaving
each as it stands (`2C-dissociate').  If the other buffer, the one not
current when you type `<F2> d', is empty, `<F2> d' kills it.


File: emacs,  Node: Editing Binary Files,  Next: Saving Emacs Sessions,  Prev: Two-Column,  Up: Top

50 Editing Binary Files
***********************

There is a special major mode for editing binary files: Hexl mode.  To
use it, use `M-x hexl-find-file' instead of `C-x C-f' to visit the
file.  This command converts the file's contents to hexadecimal and
lets you edit the translation.  When you save the file, it is converted
automatically back to binary.

   You can also use `M-x hexl-mode' to translate an existing buffer
into hex.  This is useful if you visit a file normally and then discover
it is a binary file.

   Ordinary text characters overwrite in Hexl mode.  This is to reduce
the risk of accidentally spoiling the alignment of data in the file.
There are special commands for insertion.  Here is a list of the
commands of Hexl mode:

`C-M-d'
     Insert a byte with a code typed in decimal.

`C-M-o'
     Insert a byte with a code typed in octal.

`C-M-x'
     Insert a byte with a code typed in hex.

`C-x ['
     Move to the beginning of a 1k-byte "page."

`C-x ]'
     Move to the end of a 1k-byte "page."

`M-g'
     Move to an address specified in hex.

`M-j'
     Move to an address specified in decimal.

`C-c C-c'
     Leave Hexl mode, going back to the major mode this buffer had
     before you invoked `hexl-mode'.

Other Hexl commands let you insert strings (sequences) of binary bytes,
move by `short's or `int's, etc.; type `C-h a hexl-<RET>' for details.


File: emacs,  Node: Saving Emacs Sessions,  Next: Recursive Edit,  Prev: Editing Binary Files,  Up: Top

51 Saving Emacs Sessions
************************

Use the desktop library to save the state of Emacs from one session to
another.  Once you save the Emacs "desktop"--the buffers, their file
names, major modes, buffer positions, and so on--then subsequent Emacs
sessions reload the saved desktop.

   You can save the desktop manually with the command `M-x
desktop-save'.  You can also enable automatic saving of the desktop
when you exit Emacs, and automatic restoration of the last saved
desktop when Emacs starts: use the Customization buffer (*note Easy
Customization::) to set `desktop-save-mode' to `t' for future sessions,
or add this line in your `~/.emacs' file:

     (desktop-save-mode 1)

   If you turn on `desktop-save-mode' in your `~/.emacs', then when
Emacs starts, it looks for a saved desktop in the current directory.
Thus, you can have separate saved desktops in different directories,
and the starting directory determines which one Emacs reloads.  You can
save the current desktop and reload one saved in another directory by
typing `M-x desktop-change-dir'.  Typing `M-x desktop-revert' reverts
to the desktop previously reloaded.

   Specify the option `--no-desktop' on the command line when you don't
want it to reload any saved desktop.  This turns off
`desktop-save-mode' for the current session.  Starting Emacs with the
`--no-init-file' option also disables desktop reloading, since it
bypasses the `.emacs' init file, where `desktop-save-mode' is usually
turned on.

   By default, all the buffers in the desktop are restored at one go.
However, this may be slow if there are a lot of buffers in the desktop.
You can specify the maximum number of buffers to restore immediately
with the variable `desktop-restore-eager'; the remaining buffers are
restored "lazily," when Emacs is idle.

   Type `M-x desktop-clear' to empty the Emacs desktop.  This kills all
buffers except for internal ones, and clears the global variables
listed in `desktop-globals-to-clear'.  If you want this to preserve
certain buffers, customize the variable
`desktop-clear-preserve-buffers-regexp', whose value is a regular
expression matching the names of buffers not to kill.

   If you want to save minibuffer history from one session to another,
use the `savehist' library.


File: emacs,  Node: Recursive Edit,  Next: Emulation,  Prev: Saving Emacs Sessions,  Up: Top

52 Recursive Editing Levels
***************************

A "recursive edit" is a situation in which you are using Emacs commands
to perform arbitrary editing while in the middle of another Emacs
command.  For example, when you type `C-r' inside of a `query-replace',
you enter a recursive edit in which you can change the current buffer.
On exiting from the recursive edit, you go back to the `query-replace'.

   "Exiting" the recursive edit means returning to the unfinished
command, which continues execution.  The command to exit is `C-M-c'
(`exit-recursive-edit').

   You can also "abort" the recursive edit.  This is like exiting, but
also quits the unfinished command immediately.  Use the command `C-]'
(`abort-recursive-edit') to do this.  *Note Quitting::.

   The mode line shows you when you are in a recursive edit by
displaying square brackets around the parentheses that always surround
the major and minor mode names.  Every window's mode line shows this in
the same way, since being in a recursive edit is true of Emacs as a
whole rather than any particular window or buffer.

   It is possible to be in recursive edits within recursive edits.  For
example, after typing `C-r' in a `query-replace', you may type a
command that enters the debugger.  This begins a recursive editing level
for the debugger, within the recursive editing level for `C-r'.  Mode
lines display a pair of square brackets for each recursive editing
level currently in progress.

   Exiting the inner recursive edit (such as with the debugger `c'
command) resumes the command running in the next level up.  When that
command finishes, you can then use `C-M-c' to exit another recursive
editing level, and so on.  Exiting applies to the innermost level only.
Aborting also gets out of only one level of recursive edit; it returns
immediately to the command level of the previous recursive edit.  If you
wish, you can then abort the next recursive editing level.

   Alternatively, the command `M-x top-level' aborts all levels of
recursive edits, returning immediately to the top-level command reader.

   The text being edited inside the recursive edit need not be the same
text that you were editing at top level.  It depends on what the
recursive edit is for.  If the command that invokes the recursive edit
selects a different buffer first, that is the buffer you will edit
recursively.  In any case, you can switch buffers within the recursive
edit in the normal manner (as long as the buffer-switching keys have
not been rebound).  You could probably do all the rest of your editing
inside the recursive edit, visiting files and all.  But this could have
surprising effects (such as stack overflow) from time to time.  So
remember to exit or abort the recursive edit when you no longer need it.

   In general, we try to minimize the use of recursive editing levels in
GNU Emacs.  This is because they constrain you to "go back" in a
particular order--from the innermost level toward the top level.  When
possible, we present different activities in separate buffers so that
you can switch between them as you please.  Some commands switch to a
new major mode which provides a command to switch back.  These
approaches give you more flexibility to go back to unfinished tasks in
the order you choose.


File: emacs,  Node: Emulation,  Next: Hyperlinking,  Prev: Recursive Edit,  Up: Top

53 Emulation
************

GNU Emacs can be programmed to emulate (more or less) most other
editors.  Standard facilities can emulate these:

CRiSP/Brief (PC editor)
     You can turn on key bindings to emulate the CRiSP/Brief editor with
     `M-x crisp-mode'.  Note that this rebinds `M-x' to exit Emacs
     unless you set the variable `crisp-override-meta-x'.  You can also
     use the command `M-x scroll-all-mode' or set the variable
     `crisp-load-scroll-all' to emulate CRiSP's scroll-all feature
     (scrolling all windows together).

EDT (DEC VMS editor)
     Turn on EDT emulation with the command `M-x edt-emulation-on',
     while `M-x edt-emulation-off' restores normal Emacs command
     bindings.

     Most of the EDT emulation commands are keypad keys, and most
     standard Emacs key bindings are still available.  The EDT
     emulation rebindings are done in the global keymap, so there is no
     problem switching buffers or major modes while in EDT emulation.

TPU (DEC VMS editor)
     `M-x tpu-edt-on' turns on emulation of the TPU editor emulating
     EDT.

vi (Berkeley editor)
     Viper is the newest emulator for vi.  It implements several levels
     of emulation; level 1 is closest to vi itself, while level 5
     departs somewhat from strict emulation to take advantage of the
     capabilities of Emacs.  To invoke Viper, type `M-x viper-mode'; it
     will guide you the rest of the way and ask for the emulation
     level.  *note Viper: (viper)Top.

vi (another emulator)
     `M-x vi-mode' enters a major mode that replaces the previously
     established major mode.  All of the vi commands that, in real vi,
     enter "input" mode are programmed instead to return to the
     previous major mode.  Thus, ordinary Emacs serves as vi's "input"
     mode.

     Because vi emulation works through major modes, it does not work
     to switch buffers during emulation.  Return to normal Emacs first.

     If you plan to use vi emulation much, you probably want to bind a
     key to the `vi-mode' command.

vi (alternate emulator)
     `M-x vip-mode' invokes another vi emulator, said to resemble real
     vi more thoroughly than `M-x vi-mode'.  "Input" mode in this
     emulator is changed from ordinary Emacs so you can use <ESC> to go
     back to emulated vi command mode.  To get from emulated vi command
     mode back to ordinary Emacs, type `C-z'.

     This emulation does not work through major modes, and it is
     possible to switch buffers in various ways within the emulator.
     It is not so necessary to assign a key to the command `vip-mode' as
     it is with `vi-mode' because terminating insert mode does not use
     it.

     *note VIP: (vip)Top, for full information.

WordStar (old wordprocessor)
     `M-x wordstar-mode' provides a major mode with WordStar-like key
     bindings.


File: emacs,  Node: Hyperlinking,  Next: Dissociated Press,  Prev: Emulation,  Up: Top

54 Hyperlinking and Navigation Features
***************************************

Various modes documented elsewhere have hypertext features so that you
can follow links, usually by clicking `Mouse-2' on the link or typing
<RET> while point is on the link.  Clicking `Mouse-1' quickly on the
link also follows it.  (Hold `Mouse-1' for longer if you want to set
point instead.)

   Info mode, Help mode and the Dired-like modes are examples of modes
that have links in the buffer.  The Tags facility links between uses
and definitions in source files, see *note Tags::.  Imenu provides
navigation amongst items indexed in the current buffer, see *note
Imenu::.  Info-lookup provides mode-specific lookup of definitions in
Info indexes, see *note Documentation::.  Speedbar maintains a frame in
which links to files, and locations in files are displayed, see *note
Speedbar::.

   Other non-mode-specific facilities described in this section enable
following links from the current buffer in a context-sensitive fashion.

* Menu:

* Browse-URL::                  Following URLs.
* Goto-address::                Activating URLs.
* FFAP::                        Finding files etc. at point.


File: emacs,  Node: Browse-URL,  Next: Goto-address,  Up: Hyperlinking

54.1 Following URLs
===================

`M-x browse-url <RET> URL <RET>'
     Load a URL into a Web browser.

   The Browse-URL package provides facilities for following URLs
specifying links on the World Wide Web.  Usually this works by invoking
a web browser, but you can, for instance, arrange to invoke
`compose-mail' from `mailto:' URLs.

   The general way to use this feature is to type `M-x browse-url',
which displays a specified URL.  If point is located near a plausible
URL, that URL is used as the default.  Other commands are available
which you might like to bind to keys, such as `browse-url-at-point' and
`browse-url-at-mouse'.

   You can customize Browse-URL's behavior via various options in the
`browse-url' Customize group, particularly
`browse-url-browser-function'.  You can invoke actions dependent on the
type of URL by defining `browse-url-browser-function' as an association
list.  The package's commentary available via `C-h p' under the
`hypermedia' keyword provides more information.  Packages with
facilities for following URLs should always go through Browse-URL, so
that the customization options for Browse-URL will affect all browsing
in Emacs.


File: emacs,  Node: Goto-address,  Next: FFAP,  Prev: Browse-URL,  Up: Hyperlinking

54.2 Activating URLs
====================

`M-x goto-address'
     Activate URLs and e-mail addresses in the current buffer.

   You can make URLs in the current buffer active with `M-x
goto-address'.  This finds all the URLs in the buffer, and establishes
bindings for `Mouse-2' and `C-c <RET>' on them.  After activation, if
you click on a URL with `Mouse-2', or move to a URL and type `C-c
<RET>', that will display the web page that the URL specifies.  For a
`mailto' URL, it sends mail instead, using your selected
mail-composition method (*note Mail Methods::).

   It can be useful to add `goto-address' to mode hooks and the hooks
used to display an incoming message.  `rmail-show-message-hook' is the
appropriate hook for Rmail, and `mh-show-mode-hook' for MH-E.  This is
not needed for Gnus, which has a similar feature of its own.


File: emacs,  Node: FFAP,  Prev: Goto-address,  Up: Hyperlinking

54.3 Finding Files and URLs at Point
====================================

FFAP mode replaces certain key bindings for finding files, including
`C-x C-f', with commands that provide more sensitive defaults.  These
commands behave like the ordinary ones when given a prefix argument.
Otherwise, they get the default file name or URL from the text around
point.  If what is found in the buffer has the form of a URL rather
than a file name, the commands use `browse-url' to view it.

   This feature is useful for following references in mail or news
buffers, `README' files, `MANIFEST' files, and so on.  The `ffap'
package's commentary available via `C-h p' under the `files' keyword
and the `ffap' Custom group provide details.

   You can turn on FFAP minor mode by calling `ffap-bindings' to make
the following key bindings and to install hooks for using `ffap' in
Rmail, Gnus and VM article buffers.

`C-x C-f FILENAME <RET>'
     Find FILENAME, guessing a default from text around point
     (`find-file-at-point').

`C-x C-r'
     `ffap-read-only', analogous to `find-file-read-only'.

`C-x C-v'
     `ffap-alternate-file', analogous to `find-alternate-file'.

`C-x d DIRECTORY <RET>'
     Start Dired on DIRECTORY, defaulting to the directory name at
     point (`dired-at-point').

`C-x C-d'
     `ffap-list-directory', analogous to `list-directory'.

`C-x 4 f'
     `ffap-other-window', analogous to `find-file-other-window'.

`C-x 4 r'
     `ffap-read-only-other-window', analogous to
     `find-file-read-only-other-window'.

`C-x 4 d'
     `ffap-dired-other-window', analogous to `dired-other-window'.

`C-x 5 f'
     `ffap-other-frame', analogous to `find-file-other-frame'.

`C-x 5 r'
     `ffap-read-only-other-frame', analogous to
     `find-file-read-only-other-frame'.

`C-x 5 d'
     `ffap-dired-other-frame', analogous to `dired-other-frame'.

`M-x ffap-next'
     Search buffer for next file name or URL, then find that file or
     URL.

`S-Mouse-3'
     `ffap-at-mouse' finds the file guessed from text around the
     position of a mouse click.

`C-S-Mouse-3'
     Display a menu of files and URLs mentioned in current buffer, then
     find the one you select (`ffap-menu').


File: emacs,  Node: Dissociated Press,  Next: Amusements,  Prev: Hyperlinking,  Up: Top

55 Dissociated Press
********************

`M-x dissociated-press' is a command for scrambling a file of text
either word by word or character by character.  Starting from a buffer
of straight English, it produces extremely amusing output.  The input
comes from the current Emacs buffer.  Dissociated Press writes its
output in a buffer named `*Dissociation*', and redisplays that buffer
after every couple of lines (approximately) so you can read the output
as it comes out.

   Dissociated Press asks every so often whether to continue generating
output.  Answer `n' to stop it.  You can also stop at any time by
typing `C-g'.  The dissociation output remains in the `*Dissociation*'
buffer for you to copy elsewhere if you wish.

   Dissociated Press operates by jumping at random from one point in the
buffer to another.  In order to produce plausible output rather than
gibberish, it insists on a certain amount of overlap between the end of
one run of consecutive words or characters and the start of the next.
That is, if it has just output `president' and then decides to jump to
a different point in the file, it might spot the `ent' in `pentagon'
and continue from there, producing `presidentagon'.(1)  Long sample
texts produce the best results.

   A positive argument to `M-x dissociated-press' tells it to operate
character by character, and specifies the number of overlap characters.
A negative argument tells it to operate word by word, and specifies the
number of overlap words.  In this mode, whole words are treated as the
elements to be permuted, rather than characters.  No argument is
equivalent to an argument of two.  For your againformation, the output
goes only into the buffer `*Dissociation*'.  The buffer you start with
is not changed.

   Dissociated Press produces results fairly like those of a Markov
chain based on a frequency table constructed from the sample text.  It
is, however, an independent, ignoriginal invention.  Dissociated Press
techniquitously copies several consecutive characters from the sample
between random choices, whereas a Markov chain would choose randomly
for each word or character.  This makes for more plausible sounding
results, and runs faster.

   It is a mustatement that too much use of Dissociated Press can be a
developediment to your real work, sometimes to the point of outragedy.
And keep dissociwords out of your documentation, if you want it to be
well userenced and properbose.  Have fun.  Your buggestions are welcome.

   ---------- Footnotes ----------

   (1) This dissociword actually appeared during the Vietnam War, when
it was very appropriate.  Bush has made it appropriate again.


File: emacs,  Node: Amusements,  Next: Customization,  Prev: Dissociated Press,  Up: Top

56 Other Amusements
*******************

If you are a little bit bored, you can try `M-x hanoi'.  If you are
considerably bored, give it a numeric argument.  If you are very, very
bored, try an argument of 9.  Sit back and watch.

   If you want a little more personal involvement, try `M-x gomoku',
which plays the game Go Moku with you.

   `M-x blackbox', `M-x mpuz' and `M-x 5x5' are puzzles.  `blackbox'
challenges you to determine the location of objects inside a box by
tomography.  `mpuz' displays a multiplication puzzle with letters
standing for digits in a code that you must guess--to guess a value,
type a letter and then the digit you think it stands for.  The aim of
`5x5' is to fill in all the squares.

   `M-x decipher' helps you to cryptanalyze a buffer which is encrypted
in a simple monoalphabetic substitution cipher.

   `M-x dunnet' runs an adventure-style exploration game, which is a
bigger sort of puzzle.

   `M-x lm' runs a relatively non-participatory game in which a robot
attempts to maneuver towards a tree at the center of the window based on
unique olfactory cues from each of the four directions.

   `M-x life' runs Conway's "Life" cellular automaton.

   `M-x morse-region' converts text in a region to Morse code and `M-x
unmorse-region' converts it back.  No cause for remorse.

   `M-x pong' plays a Pong-like game, bouncing the ball off opposing
bats.

   `M-x solitaire' plays a game of solitaire in which you jump pegs
across other pegs.

   `M-x studlify-region' studlify-cases the region, producing text like
this:

     M-x stUdlIfY-RegioN stUdlIfY-CaSeS thE region.

   `M-x tetris' runs an implementation of the well-known Tetris game.
Likewise, `M-x snake' provides an implementation of Snake.

   When you are frustrated, try the famous Eliza program.  Just do `M-x
doctor'.  End each input by typing <RET> twice.

   When you are feeling strange, type `M-x yow'.

   The command `M-x zone' plays games with the display when Emacs is
idle.


File: emacs,  Node: Customization,  Next: Quitting,  Prev: Amusements,  Up: Top

57 Customization
****************

This chapter talks about various topics relevant to adapting the
behavior of Emacs in ways we have anticipated.  *Note Emacs Lisp:
(elisp)Top, for how to make more far-reaching and open-ended changes.
*Note X Resources::, for information on using X resources to customize
Emacs.

   Customization that you do within Emacs normally affects only the
particular Emacs session that you do it in--it does not persist between
sessions unless you save the customization in a file such as your init
file (`.emacs') that will affect future sessions.  (*Note Init File::.)
When you tell the customization buffer to save customizations for
future sessions, this actually works by editing `.emacs' for you.

   Another means of customization is the keyboard macro, which is a
sequence of keystrokes to be replayed with a single command.  *Note
Keyboard Macros::, for full instruction how to record, manage, and
replay sequences of keys.

* Menu:

* Minor Modes::		Each minor mode is one feature you can turn on
			  independently of any others.
* Easy Customization::  Convenient way to browse and change settings.
* Variables::		Many Emacs commands examine Emacs variables
			  to decide what to do; by setting variables,
			  you can control their functioning.
* Key Bindings::	The keymaps say what command each key runs.
			  By changing them, you can "redefine keys".
* Syntax::		The syntax table controls how words and
			  expressions are parsed.
* Init File::		How to write common customizations in the
			  `.emacs' file.


File: emacs,  Node: Minor Modes,  Next: Easy Customization,  Up: Customization

57.1 Minor Modes
================

Minor modes are optional features which you can turn on or off.  For
example, Auto Fill mode is a minor mode in which <SPC> breaks lines
between words as you type.  All the minor modes are independent of each
other and of the selected major mode.  Most minor modes say in the mode
line when they are enabled; for example, `Fill' in the mode line means
that Auto Fill mode is enabled.

   You should append `-mode' to the name of a minor mode to produce the
name of the command that turns the mode on or off.  Thus, the command
to enable or disable Auto Fill mode is called `auto-fill-mode'.  These
commands are usually invoked with `M-x', but you can bind keys to them
if you wish.

   With no argument, the minor mode function turns the mode on if it
was off, and off if it was on.  This is known as "toggling".  A
positive argument always turns the mode on, and an explicit zero
argument or a negative argument always turns it off.

   Some minor modes are global: while enabled, they affect everything
you do in the Emacs session, in all buffers.  Other minor modes are
buffer-local; they apply only to the current buffer, so you can enable
the mode in certain buffers and not others.

   For most minor modes, the command name is also the name of a
variable.  The variable's value is non-`nil' if the mode is enabled and
`nil' if it is disabled.  Some minor-mode commands work by just setting
the variable.  For example, the command `abbrev-mode' works by setting
the value of `abbrev-mode' as a variable; it is this variable that
directly turns Abbrev mode on and off.  You can directly set the
variable's value instead of calling the mode function.  For other minor
modes, you need to either set the variable through the Customize
interface or call the mode function to correctly enable or disable the
mode.  To check which of these two possibilities applies to a given
minor mode, use `C-h v' to ask for documentation on the variable name.

   For minor mode commands that work by just setting the minor mode
variable, that variable provides a good way for Lisp programs to turn
minor modes on and off; it is also useful in a file's local variables
list (*note File Variables::).  But please think twice before setting
minor modes with a local variables list, because most minor modes are a
matter of user preference--other users editing the same file might not
want the same minor modes you prefer.

   The most useful buffer-local minor modes include Abbrev mode, Auto
Fill mode, Auto Save mode, Font-Lock mode, Glasses mode, Outline minor
mode, Overwrite mode, and Binary Overwrite mode.

   Abbrev mode allows you to define abbreviations that automatically
expand as you type them.  For example, `amd' might expand to `abbrev
mode'.  *Note Abbrevs::, for full information.

   Auto Fill mode allows you to enter filled text without breaking lines
explicitly.  Emacs inserts newlines as necessary to prevent lines from
becoming too long.  *Note Filling::.

   Auto Save mode saves the buffer contents periodically to reduce the
amount of work you can lose in case of a crash.  *Note Auto Save::.

   Enriched mode enables editing and saving of formatted text.  *Note
Formatted Text::.

   Flyspell mode automatically highlights misspelled words.  *Note
Spelling::.

   Font-Lock mode automatically highlights certain textual units found
in programs, such as comments, strings, and function names being
defined.  This requires a display that can show multiple fonts or
colors.  *Note Faces::.

   Outline minor mode provides the same facilities as the major mode
called Outline mode; but since it is a minor mode instead, you can
combine it with any major mode.  *Note Outline Mode::.

   Overwrite mode causes ordinary printing characters to replace
existing text instead of shoving it to the right.  For example, if
point is in front of the `B' in `FOOBAR', then in Overwrite mode typing
a `G' changes it to `FOOGAR', instead of producing `FOOGBAR' as usual.
In Overwrite mode, the command `C-q' inserts the next character
whatever it may be, even if it is a digit--this gives you a way to
insert a character instead of replacing an existing character.

   The command `overwrite-mode' is an exception to the rule that
commands which toggle minor modes are normally not bound to keys: it is
bound to the <INSERT> function key.  This is because many other
programs bind <INSERT> to similar functions.

   Binary Overwrite mode is a variant of Overwrite mode for editing
binary files; it treats newlines and tabs like other characters, so that
they overwrite other characters and can be overwritten by them.  In
Binary Overwrite mode, digits after `C-q' specify an octal character
code, as usual.

   Here are some useful minor modes that normally apply to all buffers
at once.  Since Line Number mode and Transient Mark mode can be enabled
or disabled just by setting the value of the minor mode variable, you
_can_ set them differently for particular buffers, by explicitly making
the corresponding variable local in those buffers.  *Note Locals::.

   Icomplete mode displays an indication of available completions when
you are in the minibuffer and completion is active.  *Note Completion
Options::.

   Line Number mode enables continuous display in the mode line of the
line number of point, and Column Number mode enables display of the
column number.  *Note Mode Line::.

   Scroll Bar mode gives each window a scroll bar (*note Scroll Bars::).
Menu Bar mode gives each frame a menu bar (*note Menu Bars::).  Both of
these modes are enabled by default when you use the X Window System.

   In Transient Mark mode, every change in the buffer contents
"deactivates" the mark, so that commands that operate on the region
will get an error.  This means you must either set the mark, or
explicitly "reactivate" it, before each command that uses the region.
The advantage of Transient Mark mode is that Emacs can display the
region highlighted.  *Note Mark::.


File: emacs,  Node: Easy Customization,  Next: Variables,  Prev: Minor Modes,  Up: Customization

57.2 Easy Customization Interface
=================================

Emacs has many "settings" which have values that you can specify in
order to customize various commands.  Many are documented in this
manual.  Most settings are "user options"--that is to say, Lisp
variables (*note Variables::)--so their names appear in the Variable
Index (*note Variable Index::).  The other settings are faces and their
attributes (*note Faces::).

   You can browse interactively through settings and change them using
`M-x customize'.  This command creates a "customization buffer", which
offers commands to navigate through a logically organized structure of
the Emacs settings; you can also use it to edit and set their values,
and to save settings permanently in your `~/.emacs' file (*note Init
File::).

   The appearance of the example buffers in this section is typically
different under a graphical display, since faces are then used to
indicate buttons, links and editable fields.

* Menu:

* Groups: Customization Groups.   How settings are classified in a structure.
* Browsing: Browsing Custom.   Browsing and searching for settings.
* Changing a Variable::      How to edit an option's value and set the option.
* Saving Customizations::    Specifying the file for saving customizations.
* Face Customization::       How to edit the attributes of a face.
* Specific Customization::   Making a customization buffer for specific
                                variables, faces, or groups.
* Custom Themes::            How to define collections of customized options
                                that can be loaded and unloaded together.


File: emacs,  Node: Customization Groups,  Next: Browsing Custom,  Up: Easy Customization

57.2.1 Customization Groups
---------------------------

For customization purposes, settings are organized into "groups" to
help you find them.  Groups are collected into bigger groups, all the
way up to a master group called `Emacs'.

   `M-x customize' creates a customization buffer that shows the
top-level `Emacs' group and the second-level groups immediately under
it.  It looks like this, in part:

     /- Emacs group: ---------------------------------------------------\
           [State]: visible group members are all at standard values.
        Customization of the One True Editor.
        See also [Manual].

     Editing group: [Go to Group]
     Basic text editing facilities.

     External group: [Go to Group]
     Interfacing to external utilities.

     MORE SECOND-LEVEL GROUPS

     \- Emacs group end ------------------------------------------------/

This says that the buffer displays the contents of the `Emacs' group.
The other groups are listed because they are its contents.  But they
are listed differently, without indentation and dashes, because _their_
contents are not included.  Each group has a single-line documentation
string; the `Emacs' group also has a `[State]' line.

   Most of the text in the customization buffer is read-only, but it
typically includes some "editable fields" that you can edit.  There are
also "buttons" and "links", which do something when you "invoke" them.
To invoke a button or a link, either click on it with `Mouse-1', or
move point to it and type <RET>.

   For example, the phrase `[State]' that appears in a second-level
group is a button.  It operates on the same customization buffer.  The
phrase `[Go to Group]' is a kind of hypertext link to another group.
Invoking it creates a new customization buffer, which shows that group
and its contents.

   The `Emacs' group includes a few settings, but mainly it contains
other groups, which contain more groups, which contain the settings.
By browsing the hierarchy of groups, you will eventually find the
feature you are interested in customizing.  Then you can use the
customization buffer to set that feature's settings.  You can also go
straight to a particular group by name, using the command `M-x
customize-group'.


File: emacs,  Node: Browsing Custom,  Next: Changing a Variable,  Prev: Customization Groups,  Up: Easy Customization

57.2.2 Browsing and Searching for Options and Faces
---------------------------------------------------

`M-x customize-browse' is another way to browse the available settings.
This command creates a special customization buffer which shows only
the names of groups and settings, and puts them in a structure.

   In this buffer, you can show the contents of a group by invoking the
`[+]' button.  When the group contents are visible, this button changes
to `[-]'; invoking that hides the group contents again.

   Each group or setting in this buffer has a link which says
`[Group]', `[Option]' or `[Face]'.  Invoking this link creates an
ordinary customization buffer showing just that group and its contents,
just that user option, or just that face.  This is the way to change
settings that you find with `M-x customize-browse'.

   If you can guess part of the name of the settings you are interested
in, `M-x customize-apropos' is another way to search for settings.
However, unlike `customize' and `customize-browse', `customize-apropos'
can only find groups and settings that are loaded in the current Emacs
session.  *Note Customizing Specific Items: Specific Customization.


File: emacs,  Node: Changing a Variable,  Next: Saving Customizations,  Prev: Browsing Custom,  Up: Easy Customization

57.2.3 Changing a Variable
--------------------------

Here is an example of what a variable (a user option) looks like in the
customization buffer:

     Kill Ring Max: [Hide Value] 60
        [State]: STANDARD.
     Maximum length of kill ring before oldest elements are thrown away.

   The text following `[Hide Value]', `60' in this case, indicates the
current value of the variable.  If you see `[Show Value]' instead of
`[Hide Value]', it means that the value is hidden; the customization
buffer initially hides values that take up several lines.  Invoke
`[Show Value]' to show the value.

   The line after the variable name indicates the "customization state"
of the variable: in the example above, it says you have not changed the
option yet.  The `[State]' button at the beginning of this line gives
you a menu of various operations for customizing the variable.

   The line after the `[State]' line displays the beginning of the
variable's documentation string.  If there are more lines of
documentation, this line ends with a `[More]' button; invoke that to
show the full documentation string.

   To enter a new value for `Kill Ring Max', move point to the value
and edit it textually.  For example, you can type `M-d', then insert
another number.  As you begin to alter the text, you will see the
`[State]' line change to say that you have edited the value:

     [State]: EDITED, shown value does not take effect until you set or ...
                                                                save it.

   Editing the value does not actually set the variable.  To do that,
you must "set" the variable.  To do this, invoke the `[State]' button
and choose `Set for Current Session'.

   The state of the variable changes visibly when you set it:

     [State]: SET for current session only.

   You don't have to worry about specifying a value that is not valid;
the `Set for Current Session' operation checks for validity and will
not install an unacceptable value.

   While editing a field that is a file name, directory name, command
name, or anything else for which completion is defined, you can type
`M-<TAB>' (`widget-complete') to do completion.  (`<ESC> <TAB>' and
`C-M-i' do the same thing.)

   Some variables have a small fixed set of possible legitimate values.
These variables don't let you edit the value textually.  Instead, a
`[Value Menu]' button appears before the value; invoke this button to
change the value.  For a boolean "on or off" value, the button says
`[Toggle]', and it changes to the other value.  `[Value Menu]' and
`[Toggle]' simply edit the buffer; the changes take real effect when
you use the `Set for Current Session' operation.

   Some variables have values with complex structure.  For example, the
value of `file-coding-system-alist' is an association list.  Here is
how it appears in the customization buffer:

     File Coding System Alist: [Hide Value]
     [INS] [DEL] File regexp: \.elc\'
                 Choice: [Value Menu] Encoding/decoding pair:
                 Decoding: emacs-mule
                 Encoding: emacs-mule
     [INS] [DEL] File regexp: \(\`\|/\)loaddefs.el\'
                 Choice: [Value Menu] Encoding/decoding pair:
                 Decoding: raw-text
                 Encoding: raw-text-unix
     [INS] [DEL] File regexp: \.tar\'
                 Choice: [Value Menu] Encoding/decoding pair:
                 Decoding: no-conversion
                 Encoding: no-conversion
     [INS] [DEL] File regexp:
                 Choice: [Value Menu] Encoding/decoding pair:
                 Decoding: undecided
                 Encoding: nil
     [INS]
        [State]: STANDARD.
     Alist to decide a coding system to use for a file I/O ...
                                     operation. [Hide Rest]
     The format is ((PATTERN . VAL) ...),
     where PATTERN is a regular expression matching a file name,
     [...more lines of documentation...]

Each association in the list appears on four lines, with several
editable fields and/or buttons.  You can edit the regexps and coding
systems using ordinary editing commands.  You can also invoke `[Value
Menu]' to switch to a different kind of value--for instance, to specify
a function instead of a pair of coding systems.

   To delete an association from the list, invoke the `[DEL]' button
for that item.  To add an association, invoke `[INS]' at the position
where you want to add it.  There is an `[INS]' button between each pair
of associations, another at the beginning and another at the end, so
you can add a new association at any position in the list.

   Two special commands, <TAB> and `S-<TAB>', are useful for moving
through the customization buffer.  <TAB> (`widget-forward') moves
forward to the next button or editable field; `S-<TAB>'
(`widget-backward') moves backward to the previous button or editable
field.

   Typing <RET> on an editable field also moves forward, just like
<TAB>.  We set it up this way because people often type <RET> when they
are finished editing a field.  To insert a newline within an editable
field, use `C-o' or `C-q C-j'.

   Setting the variable changes its value in the current Emacs session;
"saving" the value changes it for future sessions as well.  To save the
variable, invoke `[State]' and select the `Save for Future Sessions'
operation.  This works by writing code so as to set the variable again,
each time you start Emacs (*note Saving Customizations::).

   You can also restore the variable to its standard value by invoking
`[State]' and selecting the `Erase Customization' operation.  There are
actually four reset operations:

`Undo Edits'
     If you have made some modifications and not yet set the variable,
     this restores the text in the customization buffer to match the
     actual value.

`Reset to Saved'
     This restores the value of the variable to the last saved value,
     and updates the text accordingly.

`Erase Customization'
     This sets the variable to its standard value, and updates the text
     accordingly.  This also eliminates any saved value for the
     variable, so that you will get the standard value in future Emacs
     sessions.

`Set to Backup Value'
     This sets the variable to a previous value that was set in the
     customization buffer in this session.  If you customize a variable
     and then reset it, which discards the customized value, you can
     get the discarded value back again with this operation.

   Sometimes it is useful to record a comment about a specific
customization.  Use the `Add Comment' item from the `[State]' menu to
create a field for entering the comment.  The comment you enter will be
saved, and displayed again if you again view the same variable in a
customization buffer, even in another session.

   The state of a group indicates whether anything in that group has
been edited, set or saved.

   Near the top of the customization buffer there are two lines of
buttons:

      [Set for Current Session] [Save for Future Sessions]
      [Undo Edits] [Reset to Saved] [Erase Customization]   [Finish]

Invoking `[Finish]' either buries or kills this customization buffer
according to the setting of the option `custom-buffer-done-kill'; the
default is to bury the buffer.  Each of the other buttons performs an
operation--set, save or reset--on each of the settings in the buffer
that could meaningfully be set, saved or reset.  They do not operate on
settings whose values are hidden, nor on subgroups which are hidden or
not visible in the buffer.


File: emacs,  Node: Saving Customizations,  Next: Face Customization,  Prev: Changing a Variable,  Up: Easy Customization

57.2.4 Saving Customizations
----------------------------

Saving customizations from the customization buffer works by writing
code that future sessions will read, code to set up those
customizations again.

   Normally this saves customizations in your init file, `~/.emacs'.
If you wish, you can save customizations in another file instead.  To
make this work, your `~/.emacs' should set `custom-file' to the name of
that file.  Then you should load the file by calling `load'.  For
example:

     (setq custom-file "~/.emacs-custom.el")
     (load custom-file)

   You can use `custom-file' to specify different customization files
for different Emacs versions, like this:

     (cond ((< emacs-major-version 21)
            ;; Emacs 20 customization.
            (setq custom-file "~/.custom-20.el"))
           ((and (= emacs-major-version 21) (< emacs-minor-version 4))
            ;; Emacs 21 customization, before version 21.4.
            (setq custom-file "~/.custom-21.el"))
           ((< emacs-major-version 22)
            ;; Emacs version 21.4 or later.
            (setq custom-file "~/.custom-21.4.el"))
           (t
            ;; Emacs version 22.1 or later.
            (setq custom-file "~/.custom-22.el")))

     (load custom-file)

   If Emacs was invoked with the `-q' or `--no-init-file' options
(*note Initial Options::), it will not let you save your customizations
in your `~/.emacs' init file.  This is because saving customizations
from such a session would wipe out all the other customizations you
might have on your init file.


File: emacs,  Node: Face Customization,  Next: Specific Customization,  Prev: Saving Customizations,  Up: Easy Customization

57.2.5 Customizing Faces
------------------------

In addition to variables, some customization groups also include faces.
When you show the contents of a group, both the variables and the faces
in the group appear in the customization buffer.  Here is an example of
how a face looks:

     Custom Changed Face:(sample) [Hide Face]
        [State]: STANDARD.
     Face used when the customize item has been changed.
     Parent groups: [Custom Magic Faces]
     Attributes: [ ] Font Family: *
                 [ ] Width: *
                 [ ] Height: *
                 [ ] Weight: *
                 [ ] Slant: *
                 [ ] Underline: *
                 [ ] Overline: *
                 [ ] Strike-through: *
                 [ ] Box around text: *
                 [ ] Inverse-video: *
                 [X] Foreground: white       (sample)
                 [X] Background: blue        (sample)
                 [ ] Stipple: *
                 [ ] Inherit: *

   Each face attribute has its own line.  The `[X]' button before the
attribute name indicates whether the attribute is "enabled"; `[X]'
means that it's enabled, and `[ ]' means that it's disabled.  You can
enable or disable the attribute by clicking that button.  When the
attribute is enabled, you can change the attribute value in the usual
ways.

   For the colors, you can specify a color name (use `M-x
list-colors-display' for a list of them) or a hexadecimal color
specification of the form `#RRGGBB'.  (`#000000' is black, `#ff0000' is
red, `#00ff00' is green, `#0000ff' is blue, and `#ffffff' is white.)
On a black-and-white display, the colors you can use for the background
are `black', `white', `gray', `gray1', and `gray3'.  Emacs supports
these shades of gray by using background stipple patterns instead of a
color.

   Setting, saving and resetting a face work like the same operations
for variables (*note Changing a Variable::).

   A face can specify different appearances for different types of
display.  For example, a face can make text red on a color display, but
use a bold font on a monochrome display.  To specify multiple
appearances for a face, select `For All Kinds of Displays' in the menu
you get from invoking `[State]'.

   Another more basic way to set the attributes of a specific face is
with `M-x modify-face'.  This command reads the name of a face, then
reads the attributes one by one.  For the color and stipple attributes,
the attribute's current value is the default--type just <RET> if you
don't want to change that attribute.  Type `none' if you want to clear
out the attribute.


File: emacs,  Node: Specific Customization,  Next: Custom Themes,  Prev: Face Customization,  Up: Easy Customization

57.2.6 Customizing Specific Items
---------------------------------

Instead of finding the setting you want to change by navigating the
structure of groups, here are other ways to specify the settings that
you want to customize.

`M-x customize-option <RET> OPTION <RET>'
     Set up a customization buffer with just one user option variable,
     OPTION.

`M-x customize-face <RET> FACE <RET>'
     Set up a customization buffer with just one face, FACE.

`M-x customize-group <RET> GROUP <RET>'
     Set up a customization buffer with just one group, GROUP.

`M-x customize-apropos <RET> REGEXP <RET>'
     Set up a customization buffer with all the settings and groups that
     match REGEXP.

`M-x customize-changed <RET> VERSION <RET>'
     Set up a customization buffer with all the settings and groups
     whose meaning has changed since Emacs version VERSION.

`M-x customize-saved'
     Set up a customization buffer containing all settings that you
     have saved with customization buffers.

`M-x customize-unsaved'
     Set up a customization buffer containing all settings that you have
     set but not saved.

   If you want to alter a particular user option with the customization
buffer, and you know its name, you can use the command `M-x
customize-option' and specify the user option (variable) name.  This
sets up the customization buffer with just one user option--the one
that you asked for.  Editing, setting and saving the value work as
described above, but only for the specified user option.  Minibuffer
completion is handy if you only know part of the name.  However, this
command can only see options that have been loaded in the current Emacs
session.

   Likewise, you can modify a specific face, chosen by name, using `M-x
customize-face'.  By default it operates on the face used on the
character after point.

   You can also set up the customization buffer with a specific group,
using `M-x customize-group'.  The immediate contents of the chosen
group, including settings (user options and faces), and other groups,
all appear as well (even if not already loaded).  However, the
subgroups' own contents are not included.

   For a more general way of controlling what to customize, you can use
`M-x customize-apropos'.  You specify a regular expression as argument;
then all _loaded_ settings and groups whose names match this regular
expression are set up in the customization buffer.  If you specify an
empty regular expression, this includes _all_ loaded groups and
settings--which takes a long time to set up.

   When you upgrade to a new Emacs version, you might want to consider
customizing new settings, and settings whose meanings or default values
have changed.  To do this, use `M-x customize-changed' and specify a
previous Emacs version number using the minibuffer.  It creates a
customization buffer which shows all the settings and groups whose
definitions have been changed since the specified version, loading them
if necessary.

   If you change settings and then decide the change was a mistake, you
can use two special commands to revisit your previous changes.  Use
`M-x customize-saved' to look at the settings that you have saved.  Use
`M-x customize-unsaved' to look at the settings that you have set but
not saved.


File: emacs,  Node: Custom Themes,  Prev: Specific Customization,  Up: Easy Customization

57.2.7 Customization Themes
---------------------------

"Custom themes" are collections of settings that can be enabled or
disabled as a unit.  You can use Custom themes to switch quickly and
easily between various collections of settings, and to transfer such
collections from one computer to another.

   To define a Custom theme, use `M-x customize-create-theme', which
brings up a buffer named `*New Custom Theme*'.  At the top of the
buffer is an editable field where you can specify the name of the
theme.  Click on the button labelled `Insert Variable' to add a
variable to the theme, and click on `Insert Face' to add a face.  You
can edit these values in the `*New Custom Theme*' buffer like in an
ordinary Customize buffer.  To remove an option from the theme, click
on its `State' button and select `Delete'.

   After adding the desired options, click on `Save Theme' to save the
Custom theme.  This writes the theme definition to a file
`FOO-theme.el' (where FOO is the theme name you supplied), in the
directory `~/.emacs.d/'.  You can specify the directory by setting
`custom-theme-directory'.

   You can view and edit the settings of a previously-defined theme by
clicking on `Visit Theme' and specifying the theme name.  You can also
import the variables and faces that you have set using Customize by
visiting the "special" theme named `user'.  This theme, which records
all the options that you set in the ordinary customization buffer, is
always enabled, and always takes precedence over all other enabled
Custom themes.  Additionally, the `user' theme is recorded with code in
your `.emacs' file, rather than a `user-theme.el' file.

   Once you have defined a Custom theme, you can use it by customizing
the variable `custom-enabled-themes'.  This is a list of Custom themes
that are "enabled", or put into effect.  If you set
`custom-enabled-themes' using the Customize interface, the theme
definitions are automatically loaded from the theme files, if they
aren't already.  If you save the value of `custom-enabled-themes' for
future Emacs sessions, those Custom themes will be enabled whenever
Emacs is started up.

   If two enabled themes specify different values for an option, the
theme occurring earlier in `custom-enabled-themes' takes effect.

   You can temporarily enable a Custom theme with `M-x enable-theme'.
This prompts for a theme name in the minibuffer, loads the theme from
the theme file if necessary, and enables the theme.  You can "disable"
any enabled theme with the command `M-x disable-theme'; this returns
the options specified in the theme to their original values.  To
re-enable the theme, type `M-x enable-theme' again.  If a theme file is
changed during your Emacs session, you can reload it by typing `M-x
load-theme'.  (This also enables the theme.)


File: emacs,  Node: Variables,  Next: Key Bindings,  Prev: Easy Customization,  Up: Customization

57.3 Variables
==============

A "variable" is a Lisp symbol which has a value.  The symbol's name is
also called the name of the variable.  A variable name can contain any
characters that can appear in a file, but conventionally variable names
consist of words separated by hyphens.  A variable can have a
documentation string which describes what kind of value it should have
and how the value will be used.

   Emacs Lisp allows any variable (with a few exceptions) to have any
kind of value, but most variables that Emacs uses expect a value of a
certain type.  Often the value should always be a string, or should
always be a number.  Sometimes we say that a certain feature is turned
on if a variable is "non-`nil'," meaning that if the variable's value
is `nil', the feature is off, but the feature is on for _any_ other
value.  The conventional value to use to turn on the feature--since you
have to pick one particular value when you set the variable--is `t'.

   Emacs uses many Lisp variables for internal record keeping, but the
most interesting variables for a non-programmer user are those meant
for users to change--these are called "user options".

   Each user option that you can set with the customization buffer is
in fact a Lisp variable.  Emacs does not (usually) change the values of
these variables on its own; instead, you set the values in order to
control the behavior of certain Emacs commands.  Use of the
customization buffer is explained above (*note Easy Customization::);
here we describe other aspects of Emacs variables.

* Menu:

* Examining::	        Examining or setting one variable's value.
* Hooks::	        Hook variables let you specify programs for parts
		          of Emacs to run on particular occasions.
* Locals::	        Per-buffer values of variables.
* File Variables::      How files can specify variable values.


File: emacs,  Node: Examining,  Next: Hooks,  Up: Variables

57.3.1 Examining and Setting Variables
--------------------------------------

`C-h v VAR <RET>'
     Display the value and documentation of variable VAR
     (`describe-variable').

`M-x set-variable <RET> VAR <RET> VALUE <RET>'
     Change the value of variable VAR to VALUE.

   To examine the value of a single variable, use `C-h v'
(`describe-variable'), which reads a variable name using the
minibuffer, with completion.  It displays both the value and the
documentation of the variable.  For example,

     C-h v fill-column <RET>

displays something like this:

     fill-column is a variable defined in `C source code'.
     fill-column's value is 70
     Local in buffer custom.texi; global value is 70
     Automatically becomes buffer-local when set in any fashion.

     This variable is safe to use as a file local variable only if its value
     satisfies the predicate `integerp'.

     Documentation:
     *Column beyond which automatic line-wrapping should happen.
     Interactively, you can set the buffer local value using C-x f.

     You can customize this variable.

The line that says you can customize the variable indicates that this
variable is a user option.  (The star also indicates this, but it is an
obsolete indicator that may eventually disappear.)  `C-h v' is not
restricted to user options; it allows any variable name.

   The most convenient way to set a specific user option variable is
with `M-x set-variable'.  This reads the variable name with the
minibuffer (with completion), and then reads a Lisp expression for the
new value using the minibuffer a second time (you can insert the old
value into the minibuffer for editing via `M-n').  For example,

     M-x set-variable <RET> fill-column <RET> 75 <RET>

sets `fill-column' to 75.

   `M-x set-variable' is limited to user option variables, but you can
set any variable with a Lisp expression, using the function `setq'.
Here is a `setq' expression to set `fill-column':

     (setq fill-column 75)

   To execute an expression like this one, go to the `*scratch*'
buffer, type in the expression, and then type `C-j'.  *Note Lisp
Interaction::.

   Setting variables, like all means of customizing Emacs except where
otherwise stated, affects only the current Emacs session.  The only way
to alter the variable in future sessions is to put something in the
`~/.emacs' file to set it those sessions (*note Init File::).


File: emacs,  Node: Hooks,  Next: Locals,  Prev: Examining,  Up: Variables

57.3.2 Hooks
------------

"Hooks" are an important mechanism for customization of Emacs.  A hook
is a Lisp variable which holds a list of functions, to be called on
some well-defined occasion.  (This is called "running the hook".)  The
individual functions in the list are called the "hook functions" of the
hook.  With rare exceptions, hooks in Emacs are empty when Emacs starts
up, so the only hook functions in any given hook are the ones you
explicitly put there as customization.

   Most major modes run one or more "mode hooks" as the last step of
initialization.  This makes it easy for you to customize the behavior of
the mode, by setting up a hook function to override the local variable
assignments already made by the mode.  But hooks are also used in other
contexts.  For example, the hook `suspend-hook' runs just before Emacs
suspends itself (*note Exiting::).

   Most Emacs hooks are "normal hooks".  This means that running the
hook operates by calling all the hook functions, unconditionally, with
no arguments.  We have made an effort to keep most hooks normal so that
you can use them in a uniform way.  Every variable in Emacs whose name
ends in `-hook' is a normal hook.

   There are also a few "abnormal hooks".  These variables' names end
in `-hooks' or `-functions', instead of `-hook'.  What makes these
hooks abnormal is that there is something peculiar about the way its
functions are called--perhaps they are given arguments, or perhaps the
values they return are used in some way.  For example,
`find-file-not-found-functions' (*note Visiting::) is abnormal because
as soon as one hook function returns a non-`nil' value, the rest are
not called at all.  The documentation of each abnormal hook variable
explains in detail what is peculiar about it.

   You can set a hook variable with `setq' like any other Lisp
variable, but the recommended way to add a hook function to a hook
(either normal or abnormal) is by calling `add-hook'.  *Note Hooks:
(elisp)Hooks.

   For example, here's how to set up a hook to turn on Auto Fill mode
when entering Text mode and other modes based on Text mode:

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

   The next example shows how to use a hook to customize the indentation
of C code.  (People often have strong personal preferences for one
format compared to another.)  Here the hook function is an anonymous
lambda expression.

     (setq my-c-style
       '((c-comment-only-line-offset . 4)
         (c-cleanup-list . (scope-operator
     		       empty-defun-braces
     		       defun-close-semi))
         (c-offsets-alist . ((arglist-close . c-lineup-arglist)
     			(substatement-open . 0)))))

     (add-hook 'c-mode-common-hook
       '(lambda ()
          (c-add-style "my-style" my-c-style t)))

   It is best to design your hook functions so that the order in which
they are executed does not matter.  Any dependence on the order is
"asking for trouble."  However, the order is predictable: the most
recently added hook functions are executed first.

   If you play with adding various different versions of a hook
function by calling `add-hook' over and over, remember that all the
versions you added will remain in the hook variable together.  You can
clear out individual functions by calling `remove-hook', or do `(setq
HOOK-VARIABLE nil)' to remove everything.


File: emacs,  Node: Locals,  Next: File Variables,  Prev: Hooks,  Up: Variables

57.3.3 Local Variables
----------------------

`M-x make-local-variable <RET> VAR <RET>'
     Make variable VAR have a local value in the current buffer.

`M-x kill-local-variable <RET> VAR <RET>'
     Make variable VAR use its global value in the current buffer.

`M-x make-variable-buffer-local <RET> VAR <RET>'
     Mark variable VAR so that setting it will make it local to the
     buffer that is current at that time.

   Almost any variable can be made "local" to a specific Emacs buffer.
This means that its value in that buffer is independent of its value in
other buffers.  A few variables are always local in every buffer.
Every other Emacs variable has a "global" value which is in effect in
all buffers that have not made the variable local.

   `M-x make-local-variable' reads the name of a variable and makes it
local to the current buffer.  Changing its value subsequently in this
buffer will not affect others, and changes in its global value will not
affect this buffer.

   `M-x make-variable-buffer-local' marks a variable so it will become
local automatically whenever it is set.  More precisely, once a
variable has been marked in this way, the usual ways of setting the
variable automatically do `make-local-variable' first.  We call such
variables "per-buffer" variables.  Many variables in Emacs are normally
per-buffer; the variable's document string tells you when this is so.
A per-buffer variable's global value is normally never effective in any
buffer, but it still has a meaning: it is the initial value of the
variable for each new buffer.

   Major modes (*note Major Modes::) always make variables local to the
buffer before setting the variables.  This is why changing major modes
in one buffer has no effect on other buffers.  Minor modes also work by
setting variables--normally, each minor mode has one controlling
variable which is non-`nil' when the mode is enabled (*note Minor
Modes::).  For many minor modes, the controlling variable is per
buffer, and thus always buffer-local.  Otherwise, you can make it local
in a specific buffer like any other variable.

   A few variables cannot be local to a buffer because they are always
local to each display instead (*note Multiple Displays::).  If you try
to make one of these variables buffer-local, you'll get an error
message.

   `M-x kill-local-variable' makes a specified variable cease to be
local to the current buffer.  The global value of the variable
henceforth is in effect in this buffer.  Setting the major mode kills
all the local variables of the buffer except for a few variables
specially marked as "permanent locals".

   To set the global value of a variable, regardless of whether the
variable has a local value in the current buffer, you can use the Lisp
construct `setq-default'.  This construct is used just like `setq', but
it sets variables' global values instead of their local values (if
any).  When the current buffer does have a local value, the new global
value may not be visible until you switch to another buffer.  Here is
an example:

     (setq-default fill-column 75)

`setq-default' is the only way to set the global value of a variable
that has been marked with `make-variable-buffer-local'.

   Lisp programs can use `default-value' to look at a variable's
default value.  This function takes a symbol as argument and returns its
default value.  The argument is evaluated; usually you must quote it
explicitly.  For example, here's how to obtain the default value of
`fill-column':

     (default-value 'fill-column)


File: emacs,  Node: File Variables,  Prev: Locals,  Up: Variables

57.3.4 Local Variables in Files
-------------------------------

A file can specify local variable values for use when you edit the file
with Emacs.  Visiting the file checks for local variable
specifications; it automatically makes these variables local to the
buffer, and sets them to the values specified in the file.

* Menu:

* Specifying File Variables:: Specifying file local variables.
* Safe File Variables::       Making sure file local variables are safe.


File: emacs,  Node: Specifying File Variables,  Next: Safe File Variables,  Up: File Variables

57.3.4.1 Specifying File Variables
..................................

There are two ways to specify file local variable values: in the first
line, or with a local variables list.  Here's how to specify them in the
first line:

     -*- mode: MODENAME; VAR: VALUE; ... -*-

You can specify any number of variables/value pairs in this way, each
pair with a colon and semicolon as shown above.  `mode: MODENAME;'
specifies the major mode; this should come first in the line.  The
VALUEs are not evaluated; they are used literally.  Here is an example
that specifies Lisp mode and sets two variables with numeric values:

     ;; -*- mode: Lisp; fill-column: 75; comment-column: 50; -*-

   You can also specify the coding system for a file in this way: just
specify a value for the "variable" named `coding'.  The "value" must be
a coding system name that Emacs recognizes.  *Note Coding Systems::.
`unibyte: t' specifies unibyte loading for a particular Lisp file.
*Note Enabling Multibyte::.

   The `eval' pseudo-variable, described below, can be specified in the
first line as well.

   In shell scripts, the first line is used to identify the script
interpreter, so you cannot put any local variables there.  To
accommodate this, Emacs looks for local variable specifications in the
_second_ line when the first line specifies an interpreter.

   A "local variables list" goes near the end of the file, in the last
page.  (It is often best to put it on a page by itself.)  The local
variables list starts with a line containing the string `Local
Variables:', and ends with a line containing the string `End:'.  In
between come the variable names and values, one set per line, as
`VARIABLE: VALUE'.  The VALUEs are not evaluated; they are used
literally.  If a file has both a local variables list and a `-*-' line,
Emacs processes _everything_ in the `-*-' line first, and _everything_
in the local variables list afterward.

   Here is an example of a local variables list:

     ;; Local Variables: **
     ;; mode:lisp **
     ;; comment-column:0 **
     ;; comment-start: ";; "  **
     ;; comment-end:"**" **
     ;; End: **

   Each line starts with the prefix `;; ' and each line ends with the
suffix ` **'.  Emacs recognizes these as the prefix and suffix based on
the first line of the list, by finding them surrounding the magic
string `Local Variables:'; then it automatically discards them from the
other lines of the list.

   The usual reason for using a prefix and/or suffix is to embed the
local variables list in a comment, so it won't confuse other programs
that the file is intended as input for.  The example above is for a
language where comment lines start with `;; ' and end with `**'; the
local values for `comment-start' and `comment-end' customize the rest
of Emacs for this unusual syntax.  Don't use a prefix (or a suffix) if
you don't need one.

   If you write a multi-line string value, you should put the prefix
and suffix on each line, even lines that start or end within the
string.  They will be stripped off for processing the list.  If you
want to split a long string across multiple lines of the file, you can
use backslash-newline, which is ignored in Lisp string constants.
Here's an example of doing this:

     # Local Variables:
     # compile-command: "cc foo.c -Dfoo=bar -Dhack=whatever \
     #   -Dmumble=blaah"
     # End:

   Some "variable names" have special meanings in a local variables
list.  Specifying the "variable" `mode' really sets the major mode,
while any value specified for the "variable" `eval' is simply evaluated
as an expression (its value is ignored).  A value for `coding'
specifies the coding system for character code conversion of this file,
and a value of `t' for `unibyte' says to visit the file in a unibyte
buffer.  These four "variables" are not really variables; setting them
in any other context has no special meaning.

   _If `mode' is used to set a major mode, it should be the first
"variable" in the list._  Otherwise, the entries that precede it will
usually be ignored, since most modes kill all local variables as part
of their initialization.

   You can use the `mode' "variable" to set minor modes as well as the
major modes; in fact, you can use it more than once, first to set the
major mode and then to set minor modes which are specific to particular
buffers.  But most minor modes should not be specified in the file at
all, because they represent user preferences.

   For example, you may be tempted to try to turn on Auto Fill mode with
a local variable list.  That is a mistake.  The choice of Auto Fill mode
or not is a matter of individual taste, not a matter of the contents of
particular files.  If you want to use Auto Fill, set up major mode hooks
with your `.emacs' file to turn it on (when appropriate) for you alone
(*note Init File::).  Don't use a local variable list to impose your
taste on everyone.

   The start of the local variables list must be no more than 3000
characters from the end of the file, and must be in the last page if the
file is divided into pages.  Otherwise, Emacs will not notice it is
there.  The purpose of this rule is so that a stray `Local Variables:'
not in the last page does not confuse Emacs, and so that visiting a
long file that is all one page and has no local variables list need not
take the time to search the whole file.

   Use the command `normal-mode' to reset the local variables and major
mode of a buffer according to the file name and contents, including the
local variables list if any.  *Note Choosing Modes::.


File: emacs,  Node: Safe File Variables,  Prev: Specifying File Variables,  Up: File Variables

57.3.4.2 Safety of File Variables
.................................

File-local variables can be dangerous; when you visit someone else's
file, there's no telling what its local variables list could do to your
Emacs.  Improper values of the `eval' "variable," and other variables
such as `load-path', could execute Lisp code you didn't intend to run.

   Therefore, whenever Emacs encounters file local variable values that
are not known to be safe, it displays the file's entire local variables
list, and asks you for confirmation before setting them.  You can type
`y' or <SPC> to put the local variables list into effect, or `n' to
ignore it.  When Emacs is run in batch mode (*note Initial Options::),
it can't really ask you, so it assumes the answer `n'.

   Emacs normally recognizes certain variables/value pairs as safe.
For instance, it is safe to give `comment-column' or `fill-column' any
integer value.  If a file specifies only known-safe variable/value
pairs, Emacs does not ask for confirmation before setting them.
Otherwise, you can tell Emacs to record all the variable/value pairs in
this file as safe, by typing `!' at the confirmation prompt.  When
Emacs encounters these variable/value pairs subsequently, in the same
file or others, it will assume they are safe.

   Some variables, such as `load-path', are considered particularly
"risky": there is seldom any reason to specify them as local variables,
and changing them can be dangerous.  If a file contains only risky
local variables, Emacs neither offers nor accepts `!' as input at the
confirmation prompt.  If some of the local variables in a file are
risky, and some are only potentially unsafe, you can enter `!' at the
prompt.  It applies all the variables, but only marks the non-risky
ones as safe for the future.  If you really want to record safe values
for risky variables, do it directly by customizing
`safe-local-variable-values' (*note Easy Customization::).

   The variable `enable-local-variables' allows you to change the way
Emacs processes local variables.  Its default value is `t', which
specifies the behavior described above.  If it is `nil', Emacs simply
ignores all file local variables.  `:safe' means use only the safe
values and ignore the rest.  Any other value says to query you about
each file that has local variables, without trying to determine whether
the values are known to be safe.

   The variable `enable-local-eval' controls whether Emacs processes
`eval' variables.  The three possibilities for the variable's value are
`t', `nil', and anything else, just as for `enable-local-variables'.
The default is `maybe', which is neither `t' nor `nil', so normally
Emacs does ask for confirmation about processing `eval' variables.

   But there is an exception.  The `safe-local-eval-forms' is a
customizable list of eval forms which are safe.  Emacs does not ask for
confirmation when it finds these forms for the `eval' variable.


File: emacs,  Node: Key Bindings,  Next: Syntax,  Prev: Variables,  Up: Customization

57.4 Customizing Key Bindings
=============================

This section describes "key bindings", which map keys to commands, and
"keymaps", which record key bindings.  It also explains how to
customize key bindings.

   Recall that a command is a Lisp function whose definition provides
for interactive use.  Like every Lisp function, a command has a function
name, which usually consists of lower-case letters and hyphens.

* Menu:

* Keymaps::             Generalities.  The global keymap.
* Prefix Keymaps::      Keymaps for prefix keys.
* Local Keymaps::       Major and minor modes have their own keymaps.
* Minibuffer Maps::     The minibuffer uses its own local keymaps.
* Rebinding::           How to redefine one key's meaning conveniently.
* Init Rebinding::      Rebinding keys with your init file, `.emacs'.
* Function Keys::       Rebinding terminal function keys.
* Named ASCII Chars::   Distinguishing <TAB> from C-i, and so on.
* Mouse Buttons::       Rebinding mouse buttons in Emacs.
* Disabling::           Disabling a command means confirmation is required
                          before it can be executed.  This is done to protect
                          beginners from surprises.


File: emacs,  Node: Keymaps,  Next: Prefix Keymaps,  Up: Key Bindings

57.4.1 Keymaps
--------------

The bindings between key sequences and command functions are recorded
in data structures called "keymaps".  Emacs has many of these, each
used on particular occasions.

   Recall that a "key sequence" ("key", for short) is a sequence of
"input events" that have a meaning as a unit.  Input events include
characters, function keys and mouse buttons--all the inputs that you
can send to the computer with your terminal.  A key sequence gets its
meaning from its "binding", which says what command it runs.  The
function of keymaps is to record these bindings.

   The "global" keymap is the most important keymap because it is
always in effect.  The global keymap defines keys for Fundamental mode;
most of these definitions are common to most or all major modes.  Each
major or minor mode can have its own keymap which overrides the global
definitions of some keys.

   For example, a self-inserting character such as `g' is
self-inserting because the global keymap binds it to the command
`self-insert-command'.  The standard Emacs editing characters such as
`C-a' also get their standard meanings from the global keymap.
Commands to rebind keys, such as `M-x global-set-key', actually work by
storing the new binding in the proper place in the global map.  *Note
Rebinding::.

   Meta characters work differently; Emacs translates each Meta
character into a pair of characters starting with <ESC>.  When you type
the character `M-a' in a key sequence, Emacs replaces it with `<ESC>
a'.  A meta key comes in as a single input event, but becomes two
events for purposes of key bindings.  The reason for this is
historical, and we might change it someday.

   Most modern keyboards have function keys as well as character keys.
Function keys send input events just as character keys do, and keymaps
can have bindings for them.

   On text terminals, typing a function key actually sends the computer
a sequence of characters; the precise details of the sequence depends on
which function key and on the model of terminal you are using.  (Often
the sequence starts with `<ESC> ['.)  If Emacs understands your
terminal type properly, it recognizes the character sequences forming
function keys wherever they occur in a key sequence (not just at the
beginning).  Thus, for most purposes, you can pretend the function keys
reach Emacs directly and ignore their encoding as character sequences.

   Mouse buttons also produce input events.  These events come with
other data--the window and position where you pressed or released the
button, and a time stamp.  But only the choice of button matters for key
bindings; the other data matters only if a command looks at it.
(Commands designed for mouse invocation usually do look at the other
data.)

   A keymap records definitions for single events.  Interpreting a key
sequence of multiple events involves a chain of keymaps.  The first
keymap gives a definition for the first event; this definition is
another keymap, which is used to look up the second event in the
sequence, and so on.

   Key sequences can mix function keys and characters.  For example,
`C-x <SELECT>' is meaningful.  If you make <SELECT> a prefix key, then
`<SELECT> C-n' makes sense.  You can even mix mouse events with
keyboard events, but we recommend against it, because such key
sequences are inconvenient to use.

   As a user, you can redefine any key; but it is usually best to stick
to key sequences that consist of `C-c' followed by a letter (upper or
lower case).  These keys are "reserved for users," so they won't
conflict with any properly designed Emacs extension.  The function keys
<F5> through <F9> are also reserved for users.  If you redefine some
other key, your definition may be overridden by certain extensions or
major modes which redefine the same key.


File: emacs,  Node: Prefix Keymaps,  Next: Local Keymaps,  Prev: Keymaps,  Up: Key Bindings

57.4.2 Prefix Keymaps
---------------------

A prefix key such as `C-x' or <ESC> has its own keymap, which holds the
definition for the event that immediately follows that prefix.

   The definition of a prefix key is usually the keymap to use for
looking up the following event.  The definition can also be a Lisp
symbol whose function definition is the following keymap; the effect is
the same, but it provides a command name for the prefix key that can be
used as a description of what the prefix key is for.  Thus, the binding
of `C-x' is the symbol `Control-X-prefix', whose function definition is
the keymap for `C-x' commands.  The definitions of `C-c', `C-x', `C-h'
and <ESC> as prefix keys appear in the global map, so these prefix keys
are always available.

   Aside from ordinary prefix keys, there is a fictitious "prefix key"
which represents the menu bar; see *note Menu Bar: (elisp)Menu Bar, for
special information about menu bar key bindings.  Mouse button events
that invoke pop-up menus are also prefix keys; see *note Menu Keymaps:
(elisp)Menu Keymaps, for more details.

   Some prefix keymaps are stored in variables with names:

   * `ctl-x-map' is the variable name for the map used for characters
     that follow `C-x'.

   * `help-map' is for characters that follow `C-h'.

   * `esc-map' is for characters that follow <ESC>.  Thus, all Meta
     characters are actually defined by this map.

   * `ctl-x-4-map' is for characters that follow `C-x 4'.

   * `mode-specific-map' is for characters that follow `C-c'.


File: emacs,  Node: Local Keymaps,  Next: Minibuffer Maps,  Prev: Prefix Keymaps,  Up: Key Bindings

57.4.3 Local Keymaps
--------------------

So far we have explained the ins and outs of the global map.  Major
modes customize Emacs by providing their own key bindings in "local
keymaps".  For example, C mode overrides <TAB> to make it indent the
current line for C code.  Portions of text in the buffer can specify
their own keymaps to substitute for the keymap of the buffer's major
mode.

   Minor modes can also have local keymaps.  Whenever a minor mode is
in effect, the definitions in its keymap override both the major mode's
local keymap and the global keymap.

   A local keymap can locally redefine a key as a prefix key by defining
it as a prefix keymap.  If the key is also defined globally as a prefix,
then its local and global definitions (both keymaps) effectively
combine: both of them are used to look up the event that follows the
prefix key.  Thus, if the mode's local keymap defines `C-c' as another
keymap, and that keymap defines `C-z' as a command, this provides a
local meaning for `C-c C-z'.  This does not affect other sequences that
start with `C-c'; if those sequences don't have their own local
bindings, their global bindings remain in effect.

   Another way to think of this is that Emacs handles a multi-event key
sequence by looking in several keymaps, one by one, for a binding of the
whole key sequence.  First it checks the minor mode keymaps for minor
modes that are enabled, then it checks the major mode's keymap, and then
it checks the global keymap.  This is not precisely how key lookup
works, but it's good enough for understanding the results in ordinary
circumstances.

   Most major modes construct their keymaps when the mode is used for
the first time in a session.  If you wish to change one of these
keymaps, you must use the major mode's "mode hook" (*note Hooks::).

   For example, the command `texinfo-mode' to select Texinfo mode runs
the hook `texinfo-mode-hook'.  Here's how you can use the hook to add
local bindings (not very useful, we admit) for `C-c n' and `C-c p' in
Texinfo mode:

     (add-hook 'texinfo-mode-hook
               '(lambda ()
                  (define-key texinfo-mode-map "\C-cp"
                              'backward-paragraph)
                  (define-key texinfo-mode-map "\C-cn"
                              'forward-paragraph)))


File: emacs,  Node: Minibuffer Maps,  Next: Rebinding,  Prev: Local Keymaps,  Up: Key Bindings

57.4.4 Minibuffer Keymaps
-------------------------

The minibuffer has its own set of local keymaps; they contain various
completion and exit commands.

   * `minibuffer-local-map' is used for ordinary input (no completion).

   * `minibuffer-local-ns-map' is similar, except that <SPC> exits just
     like <RET>.  This is used mainly for Mocklisp compatibility.

   * `minibuffer-local-completion-map' is for permissive completion.

   * `minibuffer-local-must-match-map' is for strict completion and for
     cautious completion.

   * Finally, `minibuffer-local-filename-completion-map' and
     `minibuffer-local-must-match-filename-map' are like the two
     previous ones, but they are specifically for file name completion.
     They do not bind <SPC>.


File: emacs,  Node: Rebinding,  Next: Init Rebinding,  Prev: Minibuffer Maps,  Up: Key Bindings

57.4.5 Changing Key Bindings Interactively
------------------------------------------

The way to redefine an Emacs key is to change its entry in a keymap.
You can change the global keymap, in which case the change is effective
in all major modes (except those that have their own overriding local
definitions for the same key).  Or you can change the current buffer's
local map, which affects all buffers using the same major mode.

`M-x global-set-key <RET> KEY CMD <RET>'
     Define KEY globally to run CMD.

`M-x local-set-key <RET> KEY CMD <RET>'
     Define KEY locally (in the major mode now in effect) to run CMD.

`M-x global-unset-key <RET> KEY'
     Make KEY undefined in the global map.

`M-x local-unset-key <RET> KEY'
     Make KEY undefined locally (in the major mode now in effect).

   For example, suppose you like to execute commands in a subshell
within an Emacs buffer, instead of suspending Emacs and executing
commands in your login shell.  Normally, `C-z' is bound to the function
`suspend-emacs' (when not using the X Window System), but you can
change `C-z' to invoke an interactive subshell within Emacs, by binding
it to `shell' as follows:

     M-x global-set-key <RET> C-z shell <RET>

`global-set-key' reads the command name after the key.   After you
press the key, a message like this appears so that you can confirm that
you are binding the key you want:

     Set key C-z to command:

   You can redefine function keys and mouse events in the same way; just
type the function key or click the mouse when it's time to specify the
key to rebind.

   You can rebind a key that contains more than one event in the same
way.  Emacs keeps reading the key to rebind until it is a complete key
(that is, not a prefix key).  Thus, if you type `C-f' for KEY, that's
the end; it enters the minibuffer immediately to read CMD.  But if you
type `C-x', since that's a prefix, it reads another character; if that
is `4', another prefix character, it reads one more character, and so
on.  For example,

     M-x global-set-key <RET> C-x 4 $ spell-other-window <RET>

redefines `C-x 4 $' to run the (fictitious) command
`spell-other-window'.

   The two-character keys consisting of `C-c' followed by a letter are
reserved for user customizations.  Lisp programs are not supposed to
define these keys, so the bindings you make for them will be available
in all major modes and will never get in the way of anything.

   You can remove the global definition of a key with
`global-unset-key'.  This makes the key "undefined"; if you type it,
Emacs will just beep.  Similarly, `local-unset-key' makes a key
undefined in the current major mode keymap, which makes the global
definition (or lack of one) come back into effect in that major mode.

   If you have redefined (or undefined) a key and you subsequently wish
to retract the change, undefining the key will not do the job--you need
to redefine the key with its standard definition.  To find the name of
the standard definition of a key, go to a Fundamental mode buffer in a
fresh Emacs and use `C-h c'.  The documentation of keys in this manual
also lists their command names.

   If you want to prevent yourself from invoking a command by mistake,
it is better to disable the command than to undefine the key.  A
disabled command is less work to invoke when you really want to.  *Note
Disabling::.


File: emacs,  Node: Init Rebinding,  Next: Function Keys,  Prev: Rebinding,  Up: Key Bindings

57.4.6 Rebinding Keys in Your Init File
---------------------------------------

If you have a set of key bindings that you like to use all the time,
you can specify them in your `.emacs' file by using their Lisp syntax.
(*Note Init File::.)

   The simplest method for doing this works for ASCII characters and
Meta-modified ASCII characters only.  This method uses a string to
represent the key sequence you want to rebind.  For example, here's how
to bind `C-z' to `shell':

     (global-set-key "\C-z" 'shell)

This example uses a string constant containing one character, `C-z'.
(`\C-' is string syntax for a control character.)  The single-quote
before the command name, `shell', marks it as a constant symbol rather
than a variable.  If you omit the quote, Emacs would try to evaluate
`shell' immediately as a variable.  This probably causes an error; it
certainly isn't what you want.

   Here is another example that binds the key sequence `C-x M-l':

     (global-set-key "\C-x\M-l" 'make-symbolic-link)

   To put <TAB>, <RET>, <ESC>, or <DEL> in the string, you can use the
Emacs Lisp escape sequences, `\t', `\r', `\e', and `\d'.  Here is an
example which binds `C-x <TAB>':

     (global-set-key "\C-x\t" 'indent-rigidly)

   These examples show how to write some other special ASCII characters
in strings for key bindings:

     (global-set-key "\r" 'newline)               ;; <RET>
     (global-set-key "\d" 'delete-backward-char)  ;; <DEL>
     (global-set-key "\C-x\e\e" 'repeat-complex-command)  ;; <ESC>

   When the key sequence includes function keys or mouse button events,
or non-ASCII characters such as `C-=' or `H-a', you must use the more
general method of rebinding, which uses a vector to specify the key
sequence.

   The way to write a vector in Emacs Lisp is with square brackets
around the vector elements.  Use spaces to separate the elements.  If an
element is a symbol, simply write the symbol's name--no other
delimiters or punctuation are needed.  If a vector element is a
character, write it as a Lisp character constant: `?' followed by the
character as it would appear in a string.

   Here are examples of using vectors to rebind `C-=' (a control
character not in ASCII), `C-M-=' (not in ASCII because `C-=' is not),
`H-a' (a Hyper character; ASCII doesn't have Hyper at all), <F7> (a
function key), and `C-Mouse-1' (a keyboard-modified mouse button):

     (global-set-key [?\C-=] 'make-symbolic-link)
     (global-set-key [?\M-\C-=] 'make-symbolic-link)
     (global-set-key [?\H-a] 'make-symbolic-link)
     (global-set-key [f7] 'make-symbolic-link)
     (global-set-key [C-mouse-1] 'make-symbolic-link)

   You can use a vector for the simple cases too.  Here's how to
rewrite the first six examples above to use vectors:

     (global-set-key [?\C-z] 'shell)
     (global-set-key [?\C-x ?l] 'make-symbolic-link)
     (global-set-key [?\C-x ?\t] 'indent-rigidly)
     (global-set-key [?\r] 'newline)
     (global-set-key [?\d] 'delete-backward-char)
     (global-set-key [?\C-x ?\e ?\e] 'repeat-complex-command)

As you see, you represent a multi-character key sequence with a vector
by listing all of the characters, in order, within the square brackets
that delimit the vector.

   Language and coding systems can cause problems with key bindings for
non-ASCII characters.  *Note Init Non-ASCII::.


File: emacs,  Node: Function Keys,  Next: Named ASCII Chars,  Prev: Init Rebinding,  Up: Key Bindings

57.4.7 Rebinding Function Keys
------------------------------

Key sequences can contain function keys as well as ordinary characters.
Just as Lisp characters (actually integers) represent keyboard
characters, Lisp symbols represent function keys.  If the function key
has a word as its label, then that word is also the name of the
corresponding Lisp symbol.  Here are the conventional Lisp names for
common function keys:

`left', `up', `right', `down'
     Cursor arrow keys.

`begin', `end', `home', `next', `prior'
     Other cursor repositioning keys.

`select', `print', `execute', `backtab'
`insert', `undo', `redo', `clearline'
`insertline', `deleteline', `insertchar', `deletechar'
     Miscellaneous function keys.

`f1', `f2', ... `f35'
     Numbered function keys (across the top of the keyboard).

`kp-add', `kp-subtract', `kp-multiply', `kp-divide'
`kp-backtab', `kp-space', `kp-tab', `kp-enter'
`kp-separator', `kp-decimal', `kp-equal'
     Keypad keys (to the right of the regular keyboard), with names or
     punctuation.

`kp-0', `kp-1', ... `kp-9'
     Keypad keys with digits.

`kp-f1', `kp-f2', `kp-f3', `kp-f4'
     Keypad PF keys.

   These names are conventional, but some systems (especially when using
X) may use different names.  To make certain what symbol is used for a
given function key on your terminal, type `C-h c' followed by that key.

   A key sequence which contains function key symbols (or anything but
ASCII characters) must be a vector rather than a string.  Thus, to bind
function key `f1' to the command `rmail', write the following:

     (global-set-key [f1] 'rmail)

To bind the right-arrow key to the command `forward-char', you can use
this expression:

     (global-set-key [right] 'forward-char)

This uses the Lisp syntax for a vector containing the symbol `right'.
(This binding is present in Emacs by default.)

   *Note Init Rebinding::, for more information about using vectors for
rebinding.

   You can mix function keys and characters in a key sequence.  This
example binds `C-x <NEXT>' to the command `forward-page'.

     (global-set-key [?\C-x next] 'forward-page)

where `?\C-x' is the Lisp character constant for the character `C-x'.
The vector element `next' is a symbol and therefore does not take a
question mark.

   You can use the modifier keys <CTRL>, <META>, <HYPER>, <SUPER>,
<ALT> and <SHIFT> with function keys.  To represent these modifiers,
add the strings `C-', `M-', `H-', `s-', `A-' and `S-' at the front of
the symbol name.  Thus, here is how to make `Hyper-Meta-<RIGHT>' move
forward a word:

     (global-set-key [H-M-right] 'forward-word)

   Many keyboards have a "numeric keypad" on the right hand side.  The
numeric keys in the keypad double up as cursor motion keys, toggled by
a key labeled `Num Lock'.  By default, Emacs translates these keys to
the corresponding keys in the main keyboard.  For example, when `Num
Lock' is on, the key labeled `8' on the numeric keypad produces `kp-8',
which is translated to `8'; when `Num Lock' is off, the same key
produces `kp-up', which is translated to <UP>.  If you rebind a key
such as `8' or <UP>, it affects the equivalent keypad key too.
However, if you rebind a `kp-' key directly, that won't affect its
non-keypad equivalent.

   Emacs provides a convenient method for binding the numeric keypad
keys, using the variables `keypad-setup', `keypad-numlock-setup',
`keypad-shifted-setup', and `keypad-numlock-shifted-setup'.  These can
be found in the `keyboard' customization group (*note Easy
Customization::).  You can rebind the keys to perform other tasks, such
as issuing numeric prefix arguments.


File: emacs,  Node: Named ASCII Chars,  Next: Mouse Buttons,  Prev: Function Keys,  Up: Key Bindings

57.4.8 Named ASCII Control Characters
-------------------------------------

<TAB>, <RET>, <BS>, <LFD>, <ESC> and <DEL> started out as names for
certain ASCII control characters, used so often that they have special
keys of their own.  For instance, <TAB> was another name for `C-i'.
Later, users found it convenient to distinguish in Emacs between these
keys and the "same" control characters typed with the <CTRL> key.
Therefore, on most modern terminals, they are no longer the same, and
<TAB> is distinguishable from `C-i'.

   Emacs can distinguish these two kinds of input if the keyboard does.
It treats the "special" keys as function keys named `tab', `return',
`backspace', `linefeed', `escape', and `delete'.  These function keys
translate automatically into the corresponding ASCII characters _if_
they have no bindings of their own.  As a result, neither users nor
Lisp programs need to pay attention to the distinction unless they care
to.

   If you do not want to distinguish between (for example) <TAB> and
`C-i', make just one binding, for the ASCII character <TAB> (octal code
011).  If you do want to distinguish, make one binding for this ASCII
character, and another for the "function key" `tab'.

   With an ordinary ASCII terminal, there is no way to distinguish
between <TAB> and `C-i' (and likewise for other such pairs), because
the terminal sends the same character in both cases.


File: emacs,  Node: Mouse Buttons,  Next: Disabling,  Prev: Named ASCII Chars,  Up: Key Bindings

57.4.9 Rebinding Mouse Buttons
------------------------------

Emacs uses Lisp symbols to designate mouse buttons, too.  The ordinary
mouse events in Emacs are "click" events; these happen when you press a
button and release it without moving the mouse.  You can also get
"drag" events, when you move the mouse while holding the button down.
Drag events happen when you finally let go of the button.

   The symbols for basic click events are `mouse-1' for the leftmost
button, `mouse-2' for the next, and so on.  Here is how you can
redefine the second mouse button to split the current window:

     (global-set-key [mouse-2] 'split-window-vertically)

   The symbols for drag events are similar, but have the prefix `drag-'
before the word `mouse'.  For example, dragging the first button
generates a `drag-mouse-1' event.

   You can also define bindings for events that occur when a mouse
button is pressed down.  These events start with `down-' instead of
`drag-'.  Such events are generated only if they have key bindings.
When you get a button-down event, a corresponding click or drag event
will always follow.

   If you wish, you can distinguish single, double, and triple clicks.
A double click means clicking a mouse button twice in approximately the
same place.  The first click generates an ordinary click event.  The
second click, if it comes soon enough, generates a double-click event
instead.  The event type for a double-click event starts with
`double-': for example, `double-mouse-3'.

   This means that you can give a special meaning to the second click at
the same place, but it must act on the assumption that the ordinary
single click definition has run when the first click was received.

   This constrains what you can do with double clicks, but user
interface designers say that this constraint ought to be followed in
any case.  A double click should do something similar to the single
click, only "more so."  The command for the double-click event should
perform the extra work for the double click.

   If a double-click event has no binding, it changes to the
corresponding single-click event.  Thus, if you don't define a
particular double click specially, it executes the single-click command
twice.

   Emacs also supports triple-click events whose names start with
`triple-'.  Emacs does not distinguish quadruple clicks as event types;
clicks beyond the third generate additional triple-click events.
However, the full number of clicks is recorded in the event list, so if
you know Emacs Lisp you can distinguish if you really want to (*note
Click Events: (elisp)Click Events.).  We don't recommend distinct
meanings for more than three clicks, but sometimes it is useful for
subsequent clicks to cycle through the same set of three meanings, so
that four clicks are equivalent to one click, five are equivalent to
two, and six are equivalent to three.

   Emacs also records multiple presses in drag and button-down events.
For example, when you press a button twice, then move the mouse while
holding the button, Emacs gets a `double-drag-' event.  And at the
moment when you press it down for the second time, Emacs gets a
`double-down-' event (which is ignored, like all button-down events, if
it has no binding).

   The variable `double-click-time' specifies how much time can elapse
between clicks and still allow them to be grouped as a multiple click.
Its value is in units of milliseconds.  If the value is `nil', double
clicks are not detected at all.  If the value is `t', then there is no
time limit.  The default is 500.

   The variable `double-click-fuzz' specifies how much the mouse can
move between clicks and still allow them to be grouped as a multiple
click.  Its value is in units of pixels on windowed displays and in
units of 1/8 of a character cell on text-mode terminals; the default is
3.

   The symbols for mouse events also indicate the status of the modifier
keys, with the usual prefixes `C-', `M-', `H-', `s-', `A-' and `S-'.
These always precede `double-' or `triple-', which always precede
`drag-' or `down-'.

   A frame includes areas that don't show text from the buffer, such as
the mode line and the scroll bar.  You can tell whether a mouse button
comes from a special area of the screen by means of dummy "prefix
keys."  For example, if you click the mouse in the mode line, you get
the prefix key `mode-line' before the ordinary mouse-button symbol.
Thus, here is how to define the command for clicking the first button in
a mode line to run `scroll-up':

     (global-set-key [mode-line mouse-1] 'scroll-up)

   Here is the complete list of these dummy prefix keys and their
meanings:

`mode-line'
     The mouse was in the mode line of a window.

`vertical-line'
     The mouse was in the vertical line separating side-by-side
     windows.  (If you use scroll bars, they appear in place of these
     vertical lines.)

`vertical-scroll-bar'
     The mouse was in a vertical scroll bar.  (This is the only kind of
     scroll bar Emacs currently supports.)

`menu-bar'
     The mouse was in the menu bar.

`header-line'
     The mouse was in a header line.

   You can put more than one mouse button in a key sequence, but it
isn't usual to do so.


File: emacs,  Node: Disabling,  Prev: Mouse Buttons,  Up: Key Bindings

57.4.10 Disabling Commands
--------------------------

Disabling a command means that invoking it interactively asks for
confirmation from the user.  The purpose of disabling a command is to
prevent users from executing it by accident; we do this for commands
that might be confusing to the uninitiated.

   Attempting to invoke a disabled command interactively in Emacs
displays a window containing the command's name, its documentation, and
some instructions on what to do immediately; then Emacs asks for input
saying whether to execute the command as requested, enable it and
execute it, or cancel.  If you decide to enable the command, you must
then answer another question--whether to do this permanently, or just
for the current session.  (Enabling permanently works by automatically
editing your `.emacs' file.)  You can also type `!' to enable _all_
commands, for the current session only.

   The direct mechanism for disabling a command is to put a non-`nil'
`disabled' property on the Lisp symbol for the command.  Here is the
Lisp program to do this:

     (put 'delete-region 'disabled t)

   If the value of the `disabled' property is a string, that string is
included in the message displayed when the command is used:

     (put 'delete-region 'disabled
          "It's better to use `kill-region' instead.\n")

   You can make a command disabled either by editing the `.emacs' file
directly, or with the command `M-x disable-command', which edits the
`.emacs' file for you.  Likewise, `M-x enable-command' edits `.emacs'
to enable a command permanently.  *Note Init File::.

   If Emacs was invoked with the `-q' or `--no-init-file' options
(*note Initial Options::), it will not edit your `~/.emacs' init file.
Doing so could lose information because Emacs has not read your init
file.

   Whether a command is disabled is independent of what key is used to
invoke it; disabling also applies if the command is invoked using
`M-x'.  However, disabling a command has no effect on calling it as a
function from Lisp programs.


File: emacs,  Node: Syntax,  Next: Init File,  Prev: Key Bindings,  Up: Customization

57.5 The Syntax Table
=====================

All the Emacs commands which parse words or balance parentheses are
controlled by the "syntax table".  The syntax table says which
characters are opening delimiters, which are parts of words, which are
string quotes, and so on.  It does this by assigning each character to
one of fifteen-odd "syntax classes".  In some cases it specifies some
additional information also.

   Each major mode has its own syntax table (though related major modes
sometimes share one syntax table), which it installs in each buffer
that uses the mode.  The syntax table installed in the current buffer
is the one that all commands use, so we call it "the" syntax table.

   To display a description of the contents of the current syntax
table, type `C-h s' (`describe-syntax').  The description of each
character includes the string you would have to give to
`modify-syntax-entry' to set up that character's current syntax,
starting with the character which designates its syntax class, plus
some English text to explain its meaning.

   A syntax table is actually a Lisp object, a char-table, whose
elements are cons cells.  For full information on the syntax table, see
*note Syntax Tables: (elisp)Syntax Tables.


File: emacs,  Node: Init File,  Prev: Syntax,  Up: Customization

57.6 The Init File, `~/.emacs'
==============================

When Emacs is started, it normally loads a Lisp program from the file
`.emacs' or `.emacs.el' in your home directory (*note Find Init::).  We
call this file your "init file" because it specifies how to initialize
Emacs for you.  You can use the command line switch `-q' to prevent
loading your init file, and `-u' (or `--user') to specify a different
user's init file (*note Initial Options::).

   You can also use `~/.emacs.d/init.el' as the init file.  Emacs tries
this if it cannot find `~/.emacs' or `~/.emacs.el'.

   There can also be a "default init file", which is the library named
`default.el', found via the standard search path for libraries.  The
Emacs distribution contains no such library; your site may create one
for local customizations.  If this library exists, it is loaded
whenever you start Emacs (except when you specify `-q').  But your init
file, if any, is loaded first; if it sets `inhibit-default-init'
non-`nil', then `default' is not loaded.

   Your site may also have a "site startup file"; this is named
`site-start.el', if it exists.  Like `default.el', Emacs finds this
file via the standard search path for Lisp libraries.  Emacs loads this
library before it loads your init file.  To inhibit loading of this
library, use the option `--no-site-file'.  *Note Initial Options::.  We
recommend against using `site-start.el' for changes that some users may
not like.  It is better to put them in `default.el', so that users can
more easily override them.

   You can place `default.el' and `site-start.el' in any of the
directories which Emacs searches for Lisp libraries.  The variable
`load-path' (*note Lisp Libraries::) specifies these directories.  Many
sites put these files in the `site-lisp' subdirectory of the Emacs
installation directory, typically `/usr/local/share/emacs/site-lisp'.

   If you have a large amount of code in your `.emacs' file, you should
rename it to `~/.emacs.el', and byte-compile it.  *Note Byte
Compilation: (elisp)Byte Compilation, for more information about
compiling Emacs Lisp programs.

   If you are going to write actual Emacs Lisp programs that go beyond
minor customization, you should read the `Emacs Lisp Reference Manual'.
*Note Emacs Lisp: (elisp)Top.

* Menu:

* Init Syntax::	        Syntax of constants in Emacs Lisp.
* Init Examples::       How to do some things with an init file.
* Terminal Init::       Each terminal type can have an init file.
* Find Init::	        How Emacs finds the init file.
* Init Non-ASCII::      Using non-ASCII characters in an init file.


File: emacs,  Node: Init Syntax,  Next: Init Examples,  Up: Init File

57.6.1 Init File Syntax
-----------------------

The `.emacs' file contains one or more Lisp function call expressions.
Each of these consists of a function name followed by arguments, all
surrounded by parentheses.  For example, `(setq fill-column 60)' calls
the function `setq' to set the variable `fill-column' (*note Filling::)
to 60.

   You can set any Lisp variable with `setq', but with certain
variables `setq' won't do what you probably want in the `.emacs' file.
Some variables automatically become buffer-local when set with `setq';
what you want in `.emacs' is to set the default value, using
`setq-default'.  Some customizable minor mode variables do special
things to enable the mode when you set them with Customize, but
ordinary `setq' won't do that; to enable the mode in your `.emacs'
file, call the minor mode command.  The following section has examples
of both of these methods.

   The second argument to `setq' is an expression for the new value of
the variable.  This can be a constant, a variable, or a function call
expression.  In `.emacs', constants are used most of the time.  They
can be:

Numbers:
     Numbers are written in decimal, with an optional initial minus
     sign.

Strings:
     Lisp string syntax is the same as C string syntax with a few extra
     features.  Use a double-quote character to begin and end a string
     constant.

     In a string, you can include newlines and special characters
     literally.  But often it is cleaner to use backslash sequences for
     them: `\n' for newline, `\b' for backspace, `\r' for carriage
     return, `\t' for tab, `\f' for formfeed (control-L), `\e' for
     escape, `\\' for a backslash, `\"' for a double-quote, or `\OOO'
     for the character whose octal code is OOO.  Backslash and
     double-quote are the only characters for which backslash sequences
     are mandatory.

     `\C-' can be used as a prefix for a control character, as in
     `\C-s' for ASCII control-S, and `\M-' can be used as a prefix for
     a Meta character, as in `\M-a' for `Meta-A' or `\M-\C-a' for
     `Control-Meta-A'.

     *Note Init Non-ASCII::, for information about including non-ASCII
     in your init file.

Characters:
     Lisp character constant syntax consists of a `?' followed by
     either a character or an escape sequence starting with `\'.
     Examples: `?x', `?\n', `?\"', `?\)'.  Note that strings and
     characters are not interchangeable in Lisp; some contexts require
     one and some contexts require the other.

     *Note Init Non-ASCII::, for information about binding commands to
     keys which send non-ASCII characters.

True:
     `t' stands for `true'.

False:
     `nil' stands for `false'.

Other Lisp objects:
     Write a single-quote (`'') followed by the Lisp object you want.


File: emacs,  Node: Init Examples,  Next: Terminal Init,  Prev: Init Syntax,  Up: Init File

57.6.2 Init File Examples
-------------------------

Here are some examples of doing certain commonly desired things with
Lisp expressions:

   * Make <TAB> in C mode just insert a tab if point is in the middle
     of a line.

          (setq c-tab-always-indent nil)

     Here we have a variable whose value is normally `t' for `true' and
     the alternative is `nil' for `false'.

   * Make searches case sensitive by default (in all buffers that do not
     override this).

          (setq-default case-fold-search nil)

     This sets the default value, which is effective in all buffers
     that do not have local values for the variable.  Setting
     `case-fold-search' with `setq' affects only the current buffer's
     local value, which is not what you probably want to do in an init
     file.

   * Specify your own email address, if Emacs can't figure it out
     correctly.

          (setq user-mail-address "rumsfeld@torture.gov")

     Various Emacs packages that need your own email address use the
     value of `user-mail-address'.

   * Make Text mode the default mode for new buffers.

          (setq default-major-mode 'text-mode)

     Note that `text-mode' is used because it is the command for
     entering Text mode.  The single-quote before it makes the symbol a
     constant; otherwise, `text-mode' would be treated as a variable
     name.

   * Set up defaults for the Latin-1 character set which supports most
     of the languages of Western Europe.

          (set-language-environment "Latin-1")

   * Turn off Line Number mode, a global minor mode.

          (line-number-mode 0)

   * Turn on Auto Fill mode automatically in Text mode and related
     modes.

          (add-hook 'text-mode-hook
            '(lambda () (auto-fill-mode 1)))

     This shows how to add a hook function to a normal hook variable
     (*note Hooks::).  The function we supply is a list starting with
     `lambda', with a single-quote in front of it to make it a list
     constant rather than an expression.

     It's beyond the scope of this manual to explain Lisp functions,
     but for this example it is enough to know that the effect is to
     execute `(auto-fill-mode 1)' when Text mode is entered.  You can
     replace that with any other expression that you like, or with
     several expressions in a row.

     Emacs comes with a function named `turn-on-auto-fill' whose
     definition is `(lambda () (auto-fill-mode 1))'.  Thus, a simpler
     way to write the above example is as follows:

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

   * Load the installed Lisp library named `foo' (actually a file
     `foo.elc' or `foo.el' in a standard Emacs directory).

          (load "foo")

     When the argument to `load' is a relative file name, not starting
     with `/' or `~', `load' searches the directories in `load-path'
     (*note Lisp Libraries::).

   * Load the compiled Lisp file `foo.elc' from your home directory.

          (load "~/foo.elc")

     Here an absolute file name is used, so no searching is done.

   * Tell Emacs to find the definition for the function `myfunction' by
     loading a Lisp library named `mypackage' (i.e. a file
     `mypackage.elc' or `mypackage.el'):

          (autoload 'myfunction "mypackage" "Do what I say." t)

     Here the string `"Do what I say."' is the function's documentation
     string.  You specify it in the `autoload' definition so it will be
     available for help commands even when the package is not loaded.
     The last argument, `t', indicates that this function is
     interactive; that is, it can be invoked interactively by typing
     `M-x myfunction <RET>' or by binding it to a key.  If the function
     is not interactive, omit the `t' or use `nil'.

   * Rebind the key `C-x l' to run the function `make-symbolic-link'
     (*note Init Rebinding::).

          (global-set-key "\C-xl" 'make-symbolic-link)

     or

          (define-key global-map "\C-xl" 'make-symbolic-link)

     Note once again the single-quote used to refer to the symbol
     `make-symbolic-link' instead of its value as a variable.

   * Do the same thing for Lisp mode only.

          (define-key lisp-mode-map "\C-xl" 'make-symbolic-link)

   * Redefine all keys which now run `next-line' in Fundamental mode so
     that they run `forward-line' instead.

          (substitute-key-definition 'next-line 'forward-line
                                     global-map)

   * Make `C-x C-v' undefined.

          (global-unset-key "\C-x\C-v")

     One reason to undefine a key is so that you can make it a prefix.
     Simply defining `C-x C-v ANYTHING' will make `C-x C-v' a prefix,
     but `C-x C-v' must first be freed of its usual non-prefix
     definition.

   * Make `$' have the syntax of punctuation in Text mode.  Note the
     use of a character constant for `$'.

          (modify-syntax-entry ?\$ "." text-mode-syntax-table)

   * Enable the use of the command `narrow-to-region' without
     confirmation.

          (put 'narrow-to-region 'disabled nil)

   * Adjusting the configuration to various platforms and Emacs
     versions.

     Users typically want Emacs to behave the same on all systems, so
     the same init file is right for all platforms.  However, sometimes
     it happens that a function you use for customizing Emacs is not
     available on some platforms or in older Emacs versions.  To deal
     with that situation, put the customization inside a conditional
     that tests whether the function or facility is available, like
     this:

          (if (fboundp 'blink-cursor-mode)
              (blink-cursor-mode 0))

          (if (boundp 'coding-category-utf-8)
              (set-coding-priority '(coding-category-utf-8)))

     You can also simply disregard the errors that occur if the
     function is not defined.

          (condition case ()
              (set-face-background 'region "grey75")
            (error nil))

     A `setq' on a variable which does not exist is generally harmless,
     so those do not need a conditional.


File: emacs,  Node: Terminal Init,  Next: Find Init,  Prev: Init Examples,  Up: Init File

57.6.3 Terminal-specific Initialization
---------------------------------------

Each terminal type can have a Lisp library to be loaded into Emacs when
it is run on that type of terminal.  For a terminal type named
TERMTYPE, the library is called `term/TERMTYPE' and it is found by
searching the directories `load-path' as usual and trying the suffixes
`.elc' and `.el'.  Normally it appears in the subdirectory `term' of
the directory where most Emacs libraries are kept.

   The usual purpose of the terminal-specific library is to map the
escape sequences used by the terminal's function keys onto more
meaningful names, using `function-key-map'.  See the file
`term/lk201.el' for an example of how this is done.  Many function keys
are mapped automatically according to the information in the Termcap
data base; the terminal-specific library needs to map only the function
keys that Termcap does not specify.

   When the terminal type contains a hyphen, only the part of the name
before the first hyphen is significant in choosing the library name.
Thus, terminal types `aaa-48' and `aaa-30-rv' both use the library
`term/aaa'.  The code in the library can use `(getenv "TERM")' to find
the full terminal type name.

   The library's name is constructed by concatenating the value of the
variable `term-file-prefix' and the terminal type.  Your `.emacs' file
can prevent the loading of the terminal-specific library by setting
`term-file-prefix' to `nil'.

   Emacs runs the hook `term-setup-hook' at the end of initialization,
after both your `.emacs' file and any terminal-specific library have
been read in.  Add hook functions to this hook if you wish to override
part of any of the terminal-specific libraries and to define
initializations for terminals that do not have a library.  *Note
Hooks::.


File: emacs,  Node: Find Init,  Next: Init Non-ASCII,  Prev: Terminal Init,  Up: Init File

57.6.4 How Emacs Finds Your Init File
-------------------------------------

Normally Emacs uses the environment variable `HOME' (*note HOME:
General Variables.) to find `.emacs'; that's what `~' means in a file
name.  If `.emacs' is not found inside `~/' (nor `.emacs.el'), Emacs
looks for `~/.emacs.d/init.el' (which, like `~/.emacs.el', can be
byte-compiled).

   However, if you run Emacs from a shell started by `su', Emacs tries
to find your own `.emacs', not that of the user you are currently
pretending to be.  The idea is that you should get your own editor
customizations even if you are running as the super user.

   More precisely, Emacs first determines which user's init file to use.
It gets your user name from the environment variables `LOGNAME' and
`USER'; if neither of those exists, it uses effective user-ID.  If that
user name matches the real user-ID, then Emacs uses `HOME'; otherwise,
it looks up the home directory corresponding to that user name in the
system's data base of users.


File: emacs,  Node: Init Non-ASCII,  Prev: Find Init,  Up: Init File

57.6.5 Non-ASCII Characters in Init Files
-----------------------------------------

Language and coding systems may cause problems if your init file
contains non-ASCII characters, such as accented letters, in strings or
key bindings.

   If you want to use non-ASCII characters in your init file, you
should put a `-*-coding: CODING-SYSTEM-*-' tag on the first line of the
init file, and specify a coding system that supports the character(s)
in question.  *Note Recognize Coding::.  This is because the defaults
for decoding non-ASCII text might not yet be set up by the time Emacs
reads those parts of your init file which use such strings, possibly
leading Emacs to decode those strings incorrectly.  You should then
avoid adding Emacs Lisp code that modifies the coding system in other
ways, such as calls to `set-language-environment'.

   To bind non-ASCII keys, you must use a vector (*note Init
Rebinding::).  The string syntax cannot be used, since the non-ASCII
characters will be interpreted as meta keys.  For instance:

     (global-set-key [?CHAR] 'some-function)

Type `C-q', followed by the key you want to bind, to insert CHAR.

   *Warning:* if you change the keyboard encoding, or change between
multibyte and unibyte mode, or anything that would alter which code
`C-q' would insert for that character, this key binding may stop
working.  It is therefore advisable to use one and only one coding
system, for your init file as well as the files you edit.  For example,
don't mix the `latin-1' and `latin-9' coding systems.


File: emacs,  Node: Quitting,  Next: Lossage,  Prev: Customization,  Up: Top

58 Quitting and Aborting
************************

`C-g'
`C-<BREAK> (MS-DOS only)'
     Quit: cancel running or partially typed command.

`C-]'
     Abort innermost recursive editing level and cancel the command
     which invoked it (`abort-recursive-edit').

`<ESC> <ESC> <ESC>'
     Either quit or abort, whichever makes sense
     (`keyboard-escape-quit').

`M-x top-level'
     Abort all recursive editing levels that are currently executing.

`C-x u'
     Cancel a previously made change in the buffer contents (`undo').

   There are two ways of canceling a command before it has finished:
"quitting" with `C-g', and "aborting" with `C-]' or `M-x top-level'.
Quitting cancels a partially typed command, or one which is still
running.  Aborting exits a recursive editing level and cancels the
command that invoked the recursive edit.  (*Note Recursive Edit::.)

   Quitting with `C-g' is the way to get rid of a partially typed
command, or a numeric argument that you don't want.  It also stops a
running command in the middle in a relatively safe way, so you can use
it if you accidentally give a command which takes a long time.  In
particular, it is safe to quit out of a kill command; either your text
will _all_ still be in the buffer, or it will _all_ be in the kill
ring, or maybe both.  Quitting an incremental search does special
things, documented under searching; it may take two successive `C-g'
characters to get out of a search (*note Incremental Search::).

   On MS-DOS, the character `C-<BREAK>' serves as a quit character like
`C-g'.  The reason is that it is not feasible, on MS-DOS, to recognize
`C-g' while a command is running, between interactions with the user.
By contrast, it _is_ feasible to recognize `C-<BREAK>' at all times.
*Note MS-DOS Keyboard::.

   `C-g' works by setting the variable `quit-flag' to `t' the instant
`C-g' is typed; Emacs Lisp checks this variable frequently, and quits
if it is non-`nil'.  `C-g' is only actually executed as a command if
you type it while Emacs is waiting for input.  In that case, the
command it runs is `keyboard-quit'.

   On a text terminal, if you quit with `C-g' a second time before the
first `C-g' is recognized, you activate the "emergency escape" feature
and return to the shell.  *Note Emergency Escape::.

   There are some situations where you cannot quit.  When Emacs is
waiting for the operating system to do something, quitting is
impossible unless special pains are taken for the particular system
call within Emacs where the waiting occurs.  We have done this for the
system calls that users are likely to want to quit from, but it's
possible you will encounter a case not handled.  In one very common
case--waiting for file input or output using NFS--Emacs itself knows
how to quit, but many NFS implementations simply do not allow user
programs to stop waiting for NFS when the NFS server is hung.

   Aborting with `C-]' (`abort-recursive-edit') is used to get out of a
recursive editing level and cancel the command which invoked it.
Quitting with `C-g' does not do this, and could not do this, because it
is used to cancel a partially typed command _within_ the recursive
editing level.  Both operations are useful.  For example, if you are in
a recursive edit and type `C-u 8' to enter a numeric argument, you can
cancel that argument with `C-g' and remain in the recursive edit.

   The sequence `<ESC> <ESC> <ESC>' (`keyboard-escape-quit') can either
quit or abort.  (We defined it this way because <ESC> means "get out"
in many PC programs.)  It can cancel a prefix argument, clear a
selected region, or get out of a Query Replace, like `C-g'.  It can get
out of the minibuffer or a recursive edit, like `C-]'.  It can also get
out of splitting the frame into multiple windows, as with `C-x 1'.  One
thing it cannot do, however, is stop a command that is running.  That's
because it executes as an ordinary command, and Emacs doesn't notice it
until it is ready for the next command.

   The command `M-x top-level' is equivalent to "enough" `C-]' commands
to get you out of all the levels of recursive edits that you are in.
`C-]' gets you out one level at a time, but `M-x top-level' goes out
all levels at once.  Both `C-]' and `M-x top-level' are like all other
commands, and unlike `C-g', in that they take effect only when Emacs is
ready for a command.  `C-]' is an ordinary key and has its meaning only
because of its binding in the keymap.  *Note Recursive Edit::.

   `C-x u' (`undo') is not strictly speaking a way of canceling a
command, but you can think of it as canceling a command that already
finished executing.  *Note Undo::, for more information about the undo
facility.


File: emacs,  Node: Lossage,  Next: Bugs,  Prev: Quitting,  Up: Top

59 Dealing with Emacs Trouble
*****************************

This section describes various conditions in which Emacs fails to work
normally, and how to recognize them and correct them.  For a list of
additional problems you might encounter, see *note Bugs and problems:
(efaq)Bugs and problems, and the file `etc/PROBLEMS' in the Emacs
distribution.  Type `C-h C-f' to read the FAQ; type `C-h C-e' to read
the `PROBLEMS' file.

* Menu:

* DEL Does Not Delete::   What to do if <DEL> doesn't delete.
* Stuck Recursive::       `[...]' in mode line around the parentheses.
* Screen Garbled::        Garbage on the screen.
* Text Garbled::          Garbage in the text.
* Memory Full::           How to cope when you run out of memory.
* After a Crash::         Recovering editing in an Emacs session that crashed.
* Emergency Escape::      Emergency escape---
                            What to do if Emacs stops responding.
* Total Frustration::     When you are at your wits' end.


File: emacs,  Node: DEL Does Not Delete,  Next: Stuck Recursive,  Up: Lossage

59.1 If <DEL> Fails to Delete
=============================

Every keyboard has a large key, a little ways above the <RET> or
<ENTER> key, which you normally use outside Emacs to erase the last
character that you typed.  We call this key "the usual erasure key".
In Emacs, it is supposed to be equivalent to <DEL>, and when Emacs is
properly configured for your terminal, it translates that key into the
character <DEL>.

   When Emacs starts up on a graphical display, it determines
automatically which key should be <DEL>.  In some unusual cases Emacs
gets the wrong information from the system.  If the usual erasure key
deletes forwards instead of backwards, that is probably what
happened--Emacs ought to be treating the <DELETE> key as <DEL>, but it
isn't.

   On a graphical display, if the usual erasure key is labeled
<BACKSPACE> and there is a <DELETE> key elsewhere, but the <DELETE> key
deletes backward instead of forward, that too suggests Emacs got the
wrong information--but in the opposite sense.  It ought to be treating
the <BACKSPACE> key as <DEL>, and treating <DELETE> differently, but it
isn't.

   On a text-only terminal, if you find the usual erasure key prompts
for a Help command, like `Control-h', instead of deleting a character,
it means that key is actually sending the <BS> character.  Emacs ought
to be treating <BS> as <DEL>, but it isn't.

   In all of those cases, the immediate remedy is the same: use the
command `M-x normal-erase-is-backspace-mode'.  This toggles between the
two modes that Emacs supports for handling <DEL>, so if Emacs starts in
the wrong mode, this should switch to the right mode.  On a text-only
terminal, if you want to ask for help when <BS> is treated as <DEL>,
use <F1>; `C-?' may also work, if it sends character code 127.

   To fix the problem automatically for every Emacs session, you can
put one of the following lines into your `.emacs' file (*note Init
File::).  For the first case above, where <DELETE> deletes forwards
instead of backwards, use this line to make <DELETE> act as <DEL>
(resulting in behavior compatible with Emacs 20 and previous versions):

     (normal-erase-is-backspace-mode 0)

For the other two cases, where <BACKSPACE> ought to act as <DEL>, use
this line:

     (normal-erase-is-backspace-mode 1)

   Another way to fix the problem for every Emacs session is to
customize the variable `normal-erase-is-backspace': the value `t'
specifies the mode where <BS> or <BACKSPACE> is <DEL>, and `nil'
specifies the other mode.  *Note Easy Customization::.

   On a graphical display, it can also happen that the usual erasure key
is labeled <BACKSPACE>, there is a <DELETE> key elsewhere, and both
keys delete forward.  This probably means that someone has redefined
your <BACKSPACE> key as a <DELETE> key.  With X, this is typically done
with a command to the `xmodmap' program when you start the server or
log in.  The most likely motive for this customization was to support
old versions of Emacs, so we recommend you simply remove it now.


File: emacs,  Node: Stuck Recursive,  Next: Screen Garbled,  Prev: DEL Does Not Delete,  Up: Lossage

59.2 Recursive Editing Levels
=============================

Recursive editing levels are important and useful features of Emacs, but
they can seem like malfunctions if you do not understand them.

   If the mode line has square brackets `[...]' around the parentheses
that contain the names of the major and minor modes, you have entered a
recursive editing level.  If you did not do this on purpose, or if you
don't understand what that means, you should just get out of the
recursive editing level.  To do so, type `M-x top-level'.  This is
called getting back to top level.  *Note Recursive Edit::.


File: emacs,  Node: Screen Garbled,  Next: Text Garbled,  Prev: Stuck Recursive,  Up: Lossage

59.3 Garbage on the Screen
==========================

If the text on a text terminal looks wrong, the first thing to do is
see whether it is wrong in the buffer.  Type `C-l' to redisplay the
entire screen.  If the screen appears correct after this, the problem
was entirely in the previous screen update.  (Otherwise, see the
following section.)

   Display updating problems often result from an incorrect terminfo
entry for the terminal you are using.  The file `etc/TERMS' in the
Emacs distribution gives the fixes for known problems of this sort.
`INSTALL' contains general advice for these problems in one of its
sections.  To investigate the possibility that you have this sort of
problem, try Emacs on another terminal made by a different
manufacturer.  If problems happen frequently on one kind of terminal
but not another kind, it is likely to be a bad terminfo entry, though
it could also be due to a bug in Emacs that appears for terminals that
have or that lack specific features.


File: emacs,  Node: Text Garbled,  Next: Memory Full,  Prev: Screen Garbled,  Up: Lossage

59.4 Garbage in the Text
========================

If `C-l' shows that the text is wrong, first type `C-h l' to see what
commands you typed to produce the observed results.  Then try undoing
the changes step by step using `C-x u', until it gets back to a state
you consider correct.

   If a large portion of text appears to be missing at the beginning or
end of the buffer, check for the word `Narrow' in the mode line.  If it
appears, the text you don't see is probably still present, but
temporarily off-limits.  To make it accessible again, type `C-x n w'.
*Note Narrowing::.


File: emacs,  Node: Memory Full,  Next: After a Crash,  Prev: Text Garbled,  Up: Lossage

59.5 Running out of Memory
==========================

If you get the error message `Virtual memory exceeded', save your
modified buffers with `C-x s'.  This method of saving them has the
smallest need for additional memory.  Emacs keeps a reserve of memory
which it makes available when this error happens; that should be enough
to enable `C-x s' to complete its work.  When the reserve has been
used, `!MEM FULL!' appears at the beginning of the mode line,
indicating there is no more reserve.

   Once you have saved your modified buffers, you can exit this Emacs
session and start another, or you can use `M-x kill-some-buffers' to
free space in the current Emacs job.  If this frees up sufficient
space, Emacs will refill its memory reserve, and `!MEM FULL!' will
disappear from the mode line.  That means you can safely go on editing
in the same Emacs session.

   Do not use `M-x buffer-menu' to save or kill buffers when you run
out of memory, because the buffer menu needs a fair amount of memory
itself, and the reserve supply may not be enough.


File: emacs,  Node: After a Crash,  Next: Emergency Escape,  Prev: Memory Full,  Up: Lossage

59.6 Recovery After a Crash
===========================

If Emacs or the computer crashes, you can recover the files you were
editing at the time of the crash from their auto-save files.  To do
this, start Emacs again and type the command `M-x recover-session'.

   This command initially displays a buffer which lists interrupted
session files, each with its date.  You must choose which session to
recover from.  Typically the one you want is the most recent one.  Move
point to the one you choose, and type `C-c C-c'.

   Then `recover-session' considers each of the files that you were
editing during that session; for each such file, it asks whether to
recover that file.  If you answer `y' for a file, it shows the dates of
that file and its auto-save file, then asks once again whether to
recover that file.  For the second question, you must confirm with
`yes'.  If you do, Emacs visits the file but gets the text from the
auto-save file.

   When `recover-session' is done, the files you've chosen to recover
are present in Emacs buffers.  You should then save them.  Only
this--saving them--updates the files themselves.

   As a last resort, if you had buffers with content which were not
associated with any files, or if the autosave was not recent enough to
have recorded important changes, you can use the `etc/emacs-buffer.gdb'
script with GDB (the GNU Debugger) to retrieve them from a core
dump-provided that a core dump was saved, and that the Emacs executable
was not stripped of its debugging symbols.

   As soon as you get the core dump, rename it to another name such as
`core.emacs', so that another crash won't overwrite it.

   To use this script, run `gdb' with the file name of your Emacs
executable and the file name of the core dump, e.g. `gdb /usr/bin/emacs
core.emacs'.  At the `(gdb)' prompt, load the recovery script: `source
/usr/src/emacs/etc/emacs-buffer.gdb'.  Then type the command
`ybuffer-list' to see which buffers are available.  For each buffer, it
lists a buffer number.  To save a buffer, use `ysave-buffer'; you
specify the buffer number, and the file name to write that buffer into.
You should use a file name which does not already exist; if the file
does exist, the script does not make a backup of its old contents.


File: emacs,  Node: Emergency Escape,  Next: Total Frustration,  Prev: After a Crash,  Up: Lossage

59.7 Emergency Escape
=====================

On text-only terminals, the "emergency escape" feature suspends Emacs
immediately if you type `C-g' a second time before Emacs can actually
respond to the first one by quitting.  This is so you can always get
out of GNU Emacs no matter how badly it might be hung.  When things are
working properly, Emacs recognizes and handles the first `C-g' so fast
that the second one won't trigger emergency escape.  However, if some
problem prevents Emacs from handling the first `C-g' properly, then the
second one will get you back to the shell.

   When you resume Emacs after a suspension caused by emergency escape,
it asks two questions before going back to what it had been doing:

     Auto-save? (y or n)
     Abort (and dump core)? (y or n)

Answer each one with `y' or `n' followed by <RET>.

   Saying `y' to `Auto-save?' causes immediate auto-saving of all
modified buffers in which auto-saving is enabled.  Saying `n' skips
this.

   Saying `y' to `Abort (and dump core)?' causes Emacs to crash,
dumping core.  This is to enable a wizard to figure out why Emacs was
failing to quit in the first place.  Execution does not continue after
a core dump.

   If you answer this question `n', Emacs execution resumes.  With
luck, Emacs will ultimately do the requested quit.  If not, each
subsequent `C-g' invokes emergency escape again.

   If Emacs is not really hung, just slow, you may invoke the double
`C-g' feature without really meaning to.  Then just resume and answer
`n' to both questions, and you will get back to the former state.  The
quit you requested will happen by and by.

   Emergency escape is active only for text terminals.  On graphical
displays, you can use the mouse to kill Emacs or switch to another
program.

   On MS-DOS, you must type `C-<BREAK>' (twice) to cause emergency
escape--but there are cases where it won't work, when system call hangs
or when Emacs is stuck in a tight loop in C code.


File: emacs,  Node: Total Frustration,  Prev: Emergency Escape,  Up: Lossage

59.8 Help for Total Frustration
===============================

If using Emacs (or something else) becomes terribly frustrating and none
of the techniques described above solve the problem, Emacs can still
help you.

   First, if the Emacs you are using is not responding to commands, type
`C-g C-g' to get out of it and then start a new one.

   Second, type `M-x doctor <RET>'.

   The Emacs psychotherapist will help you feel better.  Each time you
say something to the psychotherapist, you must end it by typing <RET>
<RET>.  This indicates you are finished typing.


File: emacs,  Node: Bugs,  Next: Contributing,  Prev: Lossage,  Up: Top

60 Reporting Bugs
*****************

Sometimes you will encounter a bug in Emacs.  Although we cannot
promise we can or will fix the bug, and we might not even agree that it
is a bug, we want to hear about problems you encounter.  Often we agree
they are bugs and want to fix them.

   To make it possible for us to fix a bug, you must report it.  In
order to do so effectively, you must know when and how to do it.

   Before reporting a bug, it is a good idea to see if it is already
known.  You can find the list of known problems in the file
`etc/PROBLEMS' in the Emacs distribution; type `C-h C-e' to read it.
Some additional user-level problems can be found in *note Bugs and
problems: (efaq)Bugs and problems.  Looking up your problem in these
two documents might provide you with a solution or a work-around, or
give you additional information about related issues.

* Menu:

* Criteria:  Bug Criteria.	 Have you really found a bug?
* Understanding Bug Reporting::	 How to report a bug effectively.
* Checklist::			 Steps to follow for a good bug report.
* Sending Patches::		 How to send a patch for GNU Emacs.


File: emacs,  Node: Bug Criteria,  Next: Understanding Bug Reporting,  Up: Bugs

60.1 When Is There a Bug
========================

If Emacs accesses an invalid memory location ("segmentation fault"), or
exits with an operating system error message that indicates a problem
in the program (as opposed to something like "disk full"), then it is
certainly a bug.

   If Emacs updates the display in a way that does not correspond to
what is in the buffer, then it is certainly a bug.  If a command seems
to do the wrong thing but the problem corrects itself if you type
`C-l', it is a case of incorrect display updating.

   Taking forever to complete a command can be a bug, but you must make
certain that it was really Emacs's fault.  Some commands simply take a
long time.  Type `C-g' (`C-<BREAK>' on MS-DOS) and then `C-h l' to see
whether the input Emacs received was what you intended to type; if the
input was such that you _know_ it should have been processed quickly,
report a bug.  If you don't know whether the command should take a long
time, find out by looking in the manual or by asking for assistance.

   If a command you are familiar with causes an Emacs error message in a
case where its usual definition ought to be reasonable, it is probably a
bug.

   If a command does the wrong thing, that is a bug.  But be sure you
know for certain what it ought to have done.  If you aren't familiar
with the command, or don't know for certain how the command is supposed
to work, then it might actually be working right.  Rather than jumping
to conclusions, show the problem to someone who knows for certain.

   Finally, a command's intended definition may not be the best
possible definition for editing with.  This is a very important sort of
problem, but it is also a matter of judgment.  Also, it is easy to come
to such a conclusion out of ignorance of some of the existing features.
It is probably best not to complain about such a problem until you have
checked the documentation in the usual ways, feel confident that you
understand it, and know for certain that what you want is not
available.  Ask other Emacs users, too.  If you are not sure what the
command is supposed to do after a careful reading of the manual, check
the index and glossary for any terms that may be unclear.

   If after careful rereading of the manual you still do not understand
what the command should do, that indicates a bug in the manual, which
you should report.  The manual's job is to make everything clear to
people who are not Emacs experts--including you.  It is just as
important to report documentation bugs as program bugs.

   If the on-line documentation string of a function or variable
disagrees with the manual, one of them must be wrong; that is a bug.


File: emacs,  Node: Understanding Bug Reporting,  Next: Checklist,  Prev: Bug Criteria,  Up: Bugs

60.2 Understanding Bug Reporting
================================

When you decide that there is a bug, it is important to report it and to
report it in a way which is useful.  What is most useful is an exact
description of what commands you type, starting with the shell command
to run Emacs, until the problem happens.

   The most important principle in reporting a bug is to report
_facts_.  Hypotheses and verbal descriptions are no substitute for the
detailed raw data.  Reporting the facts is straightforward, but many
people strain to posit explanations and report them instead of the
facts.  If the explanations are based on guesses about how Emacs is
implemented, they will be useless; meanwhile, lacking the facts, we will
have no real information about the bug.

   For example, suppose that you type `C-x C-f /glorp/baz.ugh <RET>',
visiting a file which (you know) happens to be rather large, and Emacs
displays `I feel pretty today'.  The best way to report the bug is with
a sentence like the preceding one, because it gives all the facts.

   A bad way would be to assume that the problem is due to the size of
the file and say, "I visited a large file, and Emacs displayed `I feel
pretty today'."  This is what we mean by "guessing explanations."  The
problem is just as likely to be due to the fact that there is a `z' in
the file name.  If this is so, then when we got your report, we would
try out the problem with some "large file," probably with no `z' in its
name, and not see any problem.  There is no way in the world that we
could guess that we should try visiting a file with a `z' in its name.

   Alternatively, the problem might be due to the fact that the file
starts with exactly 25 spaces.  For this reason, you should make sure
that you inform us of the exact contents of any file that is needed to
reproduce the bug.  What if the problem only occurs when you have typed
the `C-x C-a' command previously?  This is why we ask you to give the
exact sequence of characters you typed since starting the Emacs session.

   You should not even say "visit a file" instead of `C-x C-f' unless
you _know_ that it makes no difference which visiting command is used.
Similarly, rather than saying "if I have three characters on the line,"
say "after I type `<RET> A B C <RET> C-p'," if that is the way you
entered the text.

   So please don't guess any explanations when you report a bug.  If you
want to actually _debug_ the problem, and report explanations that are
more than guesses, that is useful--but please include the facts as well.


File: emacs,  Node: Checklist,  Next: Sending Patches,  Prev: Understanding Bug Reporting,  Up: Bugs

60.3 Checklist for Bug Reports
==============================

The best way to send a bug report is to mail it electronically to the
Emacs maintainers at <bug-gnu-emacs@gnu.org>, or to
<emacs-pretest-bug@gnu.org> if you are pretesting an Emacs beta
release.  (If you want to suggest a change as an improvement, use the
same address.)

   If you'd like to read the bug reports, you can find them on the
newsgroup `gnu.emacs.bug'; keep in mind, however, that as a spectator
you should not criticize anything about what you see there.  The
purpose of bug reports is to give information to the Emacs maintainers.
Spectators are welcome only as long as they do not interfere with this.
In particular, some bug reports contain fairly large amounts of data;
spectators should not complain about this.

   Please do not post bug reports using netnews; mail is more reliable
than netnews about reporting your correct address, which we may need in
order to ask you for more information.  If your data is more than
500,000 bytes, please don't include it directly in the bug report;
instead, offer to send it on request, or make it available by ftp and
say where.

   A convenient way to send a bug report for Emacs is to use the command
`M-x report-emacs-bug'.  This sets up a mail buffer (*note Sending
Mail::) and automatically inserts _some_ of the essential information.
However, it cannot supply all the necessary information; you should
still read and follow the guidelines below, so you can enter the other
crucial information by hand before you send the message.

   To enable maintainers to investigate a bug, your report should
include all these things:

   * The version number of Emacs.  Without this, we won't know whether
     there is any point in looking for the bug in the current version
     of GNU Emacs.

     You can get the version number by typing `M-x emacs-version
     <RET>'.  If that command does not work, you probably have something
     other than GNU Emacs, so you will have to report the bug somewhere
     else.

   * The type of machine you are using, and the operating system name
     and version number.  `M-x emacs-version <RET>' provides this
     information too.  Copy its output from the `*Messages*' buffer, so
     that you get it all and get it accurately.

   * The operands given to the `configure' command when Emacs was
     installed.

   * A complete list of any modifications you have made to the Emacs
     source.  (We may not have time to investigate the bug unless it
     happens in an unmodified Emacs.  But if you've made modifications
     and you don't tell us, you are sending us on a wild goose chase.)

     Be precise about these changes.  A description in English is not
     enough--send a context diff for them.

     Adding files of your own, or porting to another machine, is a
     modification of the source.

   * Details of any other deviations from the standard procedure for
     installing GNU Emacs.

   * The complete text of any files needed to reproduce the bug.

     If you can tell us a way to cause the problem without visiting any
     files, please do so.  This makes it much easier to debug.  If you
     do need files, make sure you arrange for us to see their exact
     contents.  For example, it can matter whether there are spaces at
     the ends of lines, or a newline after the last line in the buffer
     (nothing ought to care whether the last line is terminated, but
     try telling the bugs that).

   * The precise commands we need to type to reproduce the bug.

     The easy way to record the input to Emacs precisely is to write a
     dribble file.  To start the file, execute the Lisp expression

          (open-dribble-file "~/dribble")

     using `M-:' or from the `*scratch*' buffer just after starting
     Emacs.  From then on, Emacs copies all your input to the specified
     dribble file until the Emacs process is killed.

   * For possible display bugs, the terminal type (the value of
     environment variable `TERM'), the complete termcap entry for the
     terminal from `/etc/termcap' (since that file is not identical on
     all machines), and the output that Emacs actually sent to the
     terminal.

     The way to collect the terminal output is to execute the Lisp
     expression

          (open-termscript "~/termscript")

     using `M-:' or from the `*scratch*' buffer just after starting
     Emacs.  From then on, Emacs copies all terminal output to the
     specified termscript file as well, until the Emacs process is
     killed.  If the problem happens when Emacs starts up, put this
     expression into your `.emacs' file so that the termscript file
     will be open when Emacs displays the screen for the first time.

     Be warned: it is often difficult, and sometimes impossible, to fix
     a terminal-dependent bug without access to a terminal of the type
     that stimulates the bug.

   * If non-ASCII text or internationalization is relevant, the locale
     that was current when you started Emacs.  On GNU/Linux and Unix
     systems, or if you use a Posix-style shell such as Bash, you can
     use this shell command to view the relevant values:

          echo LC_ALL=$LC_ALL LC_COLLATE=$LC_COLLATE LC_CTYPE=$LC_CTYPE \
            LC_MESSAGES=$LC_MESSAGES LC_TIME=$LC_TIME LANG=$LANG

     Alternatively, use the `locale' command, if your system has it, to
     display your locale settings.

     You can use the `M-!' command to execute these commands from
     Emacs, and then copy the output from the `*Messages*' buffer into
     the bug report.  Alternatively, `M-x getenv <RET> LC_ALL <RET>'
     will display the value of `LC_ALL' in the echo area, and you can
     copy its output from the `*Messages*' buffer.

   * A description of what behavior you observe that you believe is
     incorrect.  For example, "The Emacs process gets a fatal signal,"
     or, "The resulting text is as follows, which I think is wrong."

     Of course, if the bug is that Emacs gets a fatal signal, then one
     can't miss it.  But if the bug is incorrect text, the maintainer
     might fail to notice what is wrong.  Why leave it to chance?

     Even if the problem you experience is a fatal signal, you should
     still say so explicitly.  Suppose something strange is going on,
     such as, your copy of the source is out of sync, or you have
     encountered a bug in the C library on your system.  (This has
     happened!)  Your copy might crash and the copy here might not.  If
     you _said_ to expect a crash, then when Emacs here fails to crash,
     we would know that the bug was not happening.  If you don't say to
     expect a crash, then we would not know whether the bug was
     happening--we would not be able to draw any conclusion from our
     observations.

   * If the bug is that the Emacs Manual or the Emacs Lisp Reference
     Manual fails to describe the actual behavior of Emacs, or that the
     text is confusing, copy in the text from the online manual which
     you think is at fault.  If the section is small, just the section
     name is enough.

   * If the manifestation of the bug is an Emacs error message, it is
     important to report the precise text of the error message, and a
     backtrace showing how the Lisp program in Emacs arrived at the
     error.

     To get the error message text accurately, copy it from the
     `*Messages*' buffer into the bug report.  Copy all of it, not just
     part.

     To make a backtrace for the error, use `M-x toggle-debug-on-error'
     before the error happens (that is to say, you must give that
     command and then make the bug happen).  This causes the error to
     start the Lisp debugger, which shows you a backtrace.  Copy the
     text of the debugger's backtrace into the bug report.  *Note The
     Lisp Debugger: (elisp)Debugger, for information on debugging Emacs
     Lisp programs with the Edebug package.

     This use of the debugger is possible only if you know how to make
     the bug happen again.  If you can't make it happen again, at least
     copy the whole error message.

   * Check whether any programs you have loaded into the Lisp world,
     including your `.emacs' file, set any variables that may affect the
     functioning of Emacs.  Also, see whether the problem happens in a
     freshly started Emacs without loading your `.emacs' file (start
     Emacs with the `-q' switch to prevent loading the init file).  If
     the problem does _not_ occur then, you must report the precise
     contents of any programs that you must load into the Lisp world in
     order to cause the problem to occur.

   * If the problem does depend on an init file or other Lisp programs
     that are not part of the standard Emacs system, then you should
     make sure it is not a bug in those programs by complaining to
     their maintainers first.  After they verify that they are using
     Emacs in a way that is supposed to work, they should report the
     bug.

   * If you wish to mention something in the GNU Emacs source, show the
     line of code with a few lines of context.  Don't just give a line
     number.

     The line numbers in the development sources don't match those in
     your sources.  It would take extra work for the maintainers to
     determine what code is in your version at a given line number, and
     we could not be certain.

   * Additional information from a C debugger such as GDB might enable
     someone to find a problem on a machine which he does not have
     available.  If you don't know how to use GDB, please read the GDB
     manual--it is not very long, and using GDB is easy.  You can find
     the GDB distribution, including the GDB manual in online form, in
     most of the same places you can find the Emacs distribution.  To
     run Emacs under GDB, you should switch to the `src' subdirectory
     in which Emacs was compiled, then do `gdb emacs'.  It is important
     for the directory `src' to be current so that GDB will read the
     `.gdbinit' file in this directory.

     However, you need to think when you collect the additional
     information if you want it to show what causes the bug.

     For example, many people send just a backtrace, but that is not
     very useful by itself.  A simple backtrace with arguments often
     conveys little about what is happening inside GNU Emacs, because
     most of the arguments listed in the backtrace are pointers to Lisp
     objects.  The numeric values of these pointers have no
     significance whatever; all that matters is the contents of the
     objects they point to (and most of the contents are themselves
     pointers).

     To provide useful information, you need to show the values of Lisp
     objects in Lisp notation.  Do this for each variable which is a
     Lisp object, in several stack frames near the bottom of the stack.
     Look at the source to see which variables are Lisp objects,
     because the debugger thinks of them as integers.

     To show a variable's value in Lisp syntax, first print its value,
     then use the user-defined GDB command `pr' to print the Lisp
     object in Lisp syntax.  (If you must use another debugger, call
     the function `debug_print' with the object as an argument.)  The
     `pr' command is defined by the file `.gdbinit', and it works only
     if you are debugging a running process (not with a core dump).

     To make Lisp errors stop Emacs and return to GDB, put a breakpoint
     at `Fsignal'.

     For a short listing of Lisp functions running, type the GDB
     command `xbacktrace'.

     The file `.gdbinit' defines several other commands that are useful
     for examining the data types and contents of Lisp objects.  Their
     names begin with `x'.  These commands work at a lower level than
     `pr', and are less convenient, but they may work even when `pr'
     does not, such as when debugging a core dump or when Emacs has had
     a fatal signal.

     More detailed advice and other useful techniques for debugging
     Emacs are available in the file `etc/DEBUG' in the Emacs
     distribution.  That file also includes instructions for
     investigating problems whereby Emacs stops responding (many people
     assume that Emacs is "hung," whereas in fact it might be in an
     infinite loop).

     To find the file `etc/DEBUG' in your Emacs installation, use the
     directory name stored in the variable `data-directory'.

   Here are some things that are not necessary in a bug report:

   * A description of the envelope of the bug--this is not necessary
     for a reproducible bug.

     Often people who encounter a bug spend a lot of time investigating
     which changes to the input file will make the bug go away and which
     changes will not affect it.

     This is often time-consuming and not very useful, because the way
     we will find the bug is by running a single example under the
     debugger with breakpoints, not by pure deduction from a series of
     examples.  You might as well save time by not searching for
     additional examples.  It is better to send the bug report right
     away, go back to editing, and find another bug to report.

     Of course, if you can find a simpler example to report _instead_ of
     the original one, that is a convenience.  Errors in the output
     will be easier to spot, running under the debugger will take less
     time, etc.

     However, simplification is not vital; if you can't do this or
     don't have time to try, please report the bug with your original
     test case.

   * A core dump file.

     Debugging the core dump might be useful, but it can only be done on
     your machine, with your Emacs executable.  Therefore, sending the
     core dump file to the Emacs maintainers won't be useful.  Above
     all, don't include the core file in an email bug report!  Such a
     large message can be extremely inconvenient.

   * A system-call trace of Emacs execution.

     System-call traces are very useful for certain special kinds of
     debugging, but in most cases they give little useful information.
     It is therefore strange that many people seem to think that _the_
     way to report information about a crash is to send a system-call
     trace.  Perhaps this is a habit formed from experience debugging
     programs that don't have source code or debugging symbols.

     In most programs, a backtrace is normally far, far more
     informative than a system-call trace.  Even in Emacs, a simple
     backtrace is generally more informative, though to give full
     information you should supplement the backtrace by displaying
     variable values and printing them as Lisp objects with `pr' (see
     above).

   * A patch for the bug.

     A patch for the bug is useful if it is a good one.  But don't omit
     the other information that a bug report needs, such as the test
     case, on the assumption that a patch is sufficient.  We might see
     problems with your patch and decide to fix the problem another
     way, or we might not understand it at all.  And if we can't
     understand what bug you are trying to fix, or why your patch
     should be an improvement, we mustn't install it.

     *Note Sending Patches::, for guidelines on how to make it easy for
     us to understand and install your patches.

   * A guess about what the bug is or what it depends on.

     Such guesses are usually wrong.  Even experts can't guess right
     about such things without first using the debugger to find the
     facts.


File: emacs,  Node: Sending Patches,  Prev: Checklist,  Up: Bugs

60.4 Sending Patches for GNU Emacs
==================================

If you would like to write bug fixes or improvements for GNU Emacs,
that is very helpful.  When you send your changes, please follow these
guidelines to make it easy for the maintainers to use them.  If you
don't follow these guidelines, your information might still be useful,
but using it will take extra work.  Maintaining GNU Emacs is a lot of
work in the best of circumstances, and we can't keep up unless you do
your best to help.

   * Send an explanation with your changes of what problem they fix or
     what improvement they bring about.  For a bug fix, just include a
     copy of the bug report, and explain why the change fixes the bug.

     (Referring to a bug report is not as good as including it, because
     then we will have to look it up, and we have probably already
     deleted it if we've already fixed the bug.)

   * Always include a proper bug report for the problem you think you
     have fixed.  We need to convince ourselves that the change is
     right before installing it.  Even if it is correct, we might have
     trouble understanding it if we don't have a way to reproduce the
     problem.

   * Include all the comments that are appropriate to help people
     reading the source in the future understand why this change was
     needed.

   * Don't mix together changes made for different reasons.  Send them
     _individually_.

     If you make two changes for separate reasons, then we might not
     want to install them both.  We might want to install just one.  If
     you send them all jumbled together in a single set of diffs, we
     have to do extra work to disentangle them--to figure out which
     parts of the change serve which purpose.  If we don't have time
     for this, we might have to ignore your changes entirely.

     If you send each change as soon as you have written it, with its
     own explanation, then two changes never get tangled up, and we can
     consider each one properly without any extra work to disentangle
     them.

   * Send each change as soon as that change is finished.  Sometimes
     people think they are helping us by accumulating many changes to
     send them all together.  As explained above, this is absolutely
     the worst thing you could do.

     Since you should send each change separately, you might as well
     send it right away.  That gives us the option of installing it
     immediately if it is important.

   * Use `diff -c' to make your diffs.  Diffs without context are hard
     to install reliably.  More than that, they are hard to study; we
     must always study a patch to decide whether we want to install it.
     Unidiff format is better than contextless diffs, but not as easy
     to read as `-c' format.

     If you have GNU diff, use `diff -c -F'^[_a-zA-Z0-9$]+ *('' when
     making diffs of C code.  This shows the name of the function that
     each change occurs in.

   * Avoid any ambiguity as to which is the old version and which is
     the new.  Please make the old version the first argument to diff,
     and the new version the second argument.  And please give one
     version or the other a name that indicates whether it is the old
     version or your new changed one.

   * Write the change log entries for your changes.  This is both to
     save us the extra work of writing them, and to help explain your
     changes so we can understand them.

     The purpose of the change log is to show people where to find what
     was changed.  So you need to be specific about what functions you
     changed; in large functions, it's often helpful to indicate where
     within the function the change was.

     On the other hand, once you have shown people where to find the
     change, you need not explain its purpose in the change log.  Thus,
     if you add a new function, all you need to say about it is that it
     is new.  If you feel that the purpose needs explaining, it
     probably does--but put the explanation in comments in the code.
     It will be more useful there.

     Please read the `ChangeLog' files in the `src' and `lisp'
     directories to see what sorts of information to put in, and to
     learn the style that we use.  *Note Change Log::.

   * When you write the fix, keep in mind that we can't install a
     change that would break other systems.  Please think about what
     effect your change will have if compiled on another type of system.

     Sometimes people send fixes that _might_ be an improvement in
     general--but it is hard to be sure of this.  It's hard to install
     such changes because we have to study them very carefully.  Of
     course, a good explanation of the reasoning by which you concluded
     the change was correct can help convince us.

     The safest changes are changes to the configuration files for a
     particular machine.  These are safe because they can't create new
     bugs on other machines.

     Please help us keep up with the workload by designing the patch in
     a form that is clearly safe to install.


File: emacs,  Node: Contributing,  Next: Service,  Prev: Bugs,  Up: Top

61 Contributing to Emacs Development
************************************

If you would like to help pretest Emacs releases to assure they work
well, or if you would like to work on improving Emacs, please contact
the maintainers at <emacs-devel@gnu.org>.  A pretester should be
prepared to investigate bugs as well as report them.  If you'd like to
work on improving Emacs, please ask for suggested projects or suggest
your own ideas.

   If you have already written an improvement, please tell us about it.
If you have not yet started work, it is useful to contact
<emacs-devel@gnu.org> before you start; it might be possible to suggest
ways to make your extension fit in better with the rest of Emacs.

   The development version of Emacs can be downloaded from the CVS
repository where it is actively maintained by a group of developers.
See the Emacs project page `http://savannah.gnu.org/projects/emacs/'
for details.


File: emacs,  Node: Service,  Next: Copying,  Prev: Contributing,  Up: Top

62 How To Get Help with GNU Emacs
*********************************

If you need help installing, using or changing GNU Emacs, there are two
ways to find it:

   * Send a message to the mailing list <help-gnu-emacs@gnu.org>, or
     post your request on newsgroup `gnu.emacs.help'.  (This mailing
     list and newsgroup interconnect, so it does not matter which one
     you use.)

   * Look in the service directory for someone who might help you for a
     fee.  The service directory is found in the file named
     `etc/SERVICE' in the Emacs distribution.

