(finder-mode-map): Add n and p bindings.
[emacs.git] / man / emacs-xtra.texi
blob7f7574d05e5fac5535c1ea91dc8624b1dc45b9e2
1 \input texinfo    @c -*-texinfo-*-
2 @comment %**start of header
3 @setfilename ../info/emacs-xtra
4 @settitle Specialized Emacs Features
5 @syncodeindex fn cp
6 @syncodeindex vr cp
7 @syncodeindex ky cp
8 @comment %**end of header
10 @copying
11 This manual describes specialized features of Emacs.
13 Copyright @copyright{} 2004, 2005, 2006 Free Software Foundation, Inc.
15 @quotation
16 Permission is granted to copy, distribute and/or modify this document
17 under the terms of the GNU Free Documentation License, Version 1.2 or
18 any later version published by the Free Software Foundation; with no
19 Invariant Sections, with the Front-Cover texts being ``A GNU
20 Manual'', and with the Back-Cover Texts as in (a) below.  A copy of the
21 license is included in the section entitled ``GNU Free Documentation
22 License'' in the Emacs manual.
24 (a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
25 this GNU Manual, like GNU software.  Copies published by the Free
26 Software Foundation raise funds for GNU development.''
28 This document is part of a collection distributed under the GNU Free
29 Documentation License.  If you want to distribute this document
30 separately from the collection, you can do so by adding a copy of the
31 license to the document, as described in section 6 of the license.
32 @end quotation
33 @end copying
35 @dircategory Emacs
36 @direntry
37 * Emacs-Xtra: (emacs-xtra).    Specialized Emacs features.
38 @end direntry
40 @titlepage
41 @title Specialized Emacs Features
42 @page
43 @vskip 0pt plus 1filll
44 @insertcopying
45 @end titlepage
47 @contents
49 @ifnottex
50 @node Top
51 @top Specialized Emacs Features
53 @insertcopying
55 @end ifnottex
57 @menu
58 * Introduction::                  What documentation belongs here?
59 * Autorevert::                    Auto Reverting non-file buffers.
60 * Subdir switches::               Subdirectory switches in Dired.
61 * Advanced Calendar/Diary Usage:: Advanced Calendar/Diary customization.
62 * Emerge::                        A convenient way of merging two versions
63                                     of a program.
64 * Picture Mode::                  Editing pictures made up of characters
65                                     using the quarter-plane screen model.
66 * Fortran::                       Fortran mode and its special features.
67 * MS-DOG::                        
68 * Index::
69 @end menu
71 @node Introduction
72 @unnumbered Introduction
74 This manual contains detailed information about various features that
75 are too specialized to be included in the Emacs manual.  It is
76 intended to be readable by anyone having a basic knowledge of Emacs.
77 However, certain sections may be intended for a more specialized
78 audience, such as Elisp authors.  This should be clearly pointed out
79 at the beginning of these sections.
81 This manual is intended as a complement, rather than an alternative,
82 to other ways to gain a more detailed knowledge of Emacs than the
83 Emacs manual can provide, such as browsing packages using @kbd{C-h p},
84 accessing mode documentation using @kbd{C-h m} and browsing user
85 options using Custom.  Also, certain packages, or collections of
86 related features, have their own manuals.  The present manual is
87 mainly intended to be a collection of smaller specialized features,
88 too small to get their own manual.
90 Sections intended specifically for Elisp programmers can follow the
91 style of the Elisp manual.  Other sections should follow the style of
92 the Emacs manual.
94 @node Autorevert
95 @chapter Auto Reverting non-file Buffers
97 Normally Global Auto Revert Mode only reverts file buffers.  There are
98 two ways to auto-revert certain non-file buffers: enabling Auto Revert
99 Mode in those buffers (using @kbd{M-x auto-revert-mode}) and setting
100 @code{global-auto-revert-non-file-buffers} to @code{t}.  The latter
101 enables Auto Reverting for all types of buffers for which it is
102 implemented, that is, for the types of buffers listed in the menu
103 below.
105 Like file buffers, non-file buffers should normally not revert while
106 you are working on them, or while they contain information that might
107 get lost after reverting.  Therefore, they do not revert if they are
108 ``modified''.  This can get tricky, because deciding when a non-file
109 buffer should be marked modified is usually more difficult than for
110 file buffers.
112 Another tricky detail is that, for efficiency reasons, Auto Revert
113 often does not try to detect all possible changes in the buffer, only
114 changes that are ``major'' or easy to detect.  Hence, enabling
115 auto-reverting for a non-file buffer does not always guarantee that
116 all information in the buffer is up to date and does not necessarily
117 make manual reverts useless.
119 At the other extreme, certain buffers automatically auto-revert every
120 @code{auto-revert-interval} seconds.  (This currently only applies to
121 the Buffer Menu.)  In this case, Auto Revert does not print any
122 messages while reverting, even when @code{auto-revert-verbose} is
123 non-@code{nil}.
125 The details depend on the particular types of buffers and are
126 explained in the corresponding sections.
128 @menu
129 * Auto Reverting the Buffer Menu::
130 * Auto Reverting Dired::
131 * Supporting additional buffers::
132 @end menu
134 @node Auto Reverting the Buffer Menu
135 @section Auto Reverting the Buffer Menu
137 If auto-reverting of non-file buffers is enabled, the Buffer Menu
138 automatically reverts every @code{auto-revert-interval} seconds,
139 whether there is a need for it or not.  (It would probably take longer
140 to check whether there is a need than to actually revert.)
142 If the Buffer Menu inappropriately gets marked modified, just revert
143 it manually using @kbd{g} and auto-reverting will resume.  However, if
144 you marked certain buffers to get deleted or to be displayed, you have
145 to be careful, because reverting erases all marks.  The fact that
146 adding marks sets the buffer's modified flag prevents Auto Revert from
147 automatically erasing the marks.
149 @node Auto Reverting Dired
150 @section Auto Reverting Dired buffers
152 Auto-reverting Dired buffers currently works on GNU or Unix style
153 operating systems.  It may not work satisfactorily on some other
154 systems.
156 Dired buffers only auto-revert when the file list of the buffer's main
157 directory changes.  They do not auto-revert when information about a
158 particular file changes or when inserted subdirectories change.  To be
159 sure that @emph{all} listed information is up to date, you have to
160 manually revert using @kbd{g}, @emph{even} if auto-reverting is
161 enabled in the Dired buffer.  Sometimes, you might get the impression
162 that modifying or saving files listed in the main directory actually
163 does cause auto-reverting.  This is because making changes to a file,
164 or saving it, very often causes changes in the directory itself, for
165 instance, through backup files or auto-save files.  However, this is
166 not guaranteed.
168 If the Dired buffer is marked modified and there are no changes you
169 want to protect, then most of the time you can make auto-reverting
170 resume by manually reverting the buffer using @kbd{g}.  There is one
171 exception.  If you flag or mark files, you can safely revert the
172 buffer.  This will not erase the flags or marks (unless the marked
173 file has been deleted, of course).  However, the buffer will stay
174 modified, even after reverting, and auto-reverting will not resume.
175 This is because, if you flag or mark files, you may be working on the
176 buffer and you might not want the buffer to change without warning.
177 If you want auto-reverting to resume in the presence of marks and
178 flags, mark the buffer non-modified using @kbd{M-~}.  However, adding,
179 deleting or changing marks or flags will mark it modified again.
181 Remote Dired buffers are not auto-reverted.  Neither are Dired buffers
182 for which you used shell wildcards or file arguments to list only some
183 of the files.  @samp{*Find*} and @samp{*Locate*} buffers do not
184 auto-revert either.
186 @node Supporting additional buffers
187 @section Adding Support for Auto-Reverting additional Buffers.
189 This section is intended for Elisp programmers who would like to add
190 support for auto-reverting new types of buffers.
192 To support auto-reverting the buffer must first of all have a
193 @code{revert-buffer-function}.  @xref{Definition of
194 revert-buffer-function,, Reverting, elisp, the Emacs Lisp Reference Manual}.
196 In addition, it @emph{must} have a @code{buffer-stale-function}.
198 @defvar buffer-stale-function
199 The value of this variable is a function to check whether a non-file
200 buffer needs reverting.  This should be a function with one optional
201 argument @var{noconfirm}.  The function should return non-@code{nil}
202 if the buffer should be reverted.  The buffer is current when this
203 function is called.
205 While this function is mainly intended for use in auto-reverting, it
206 could be used for other purposes as well.  For instance, if
207 auto-reverting is not enabled, it could be used to warn the user that
208 the buffer needs reverting.  The idea behind the @var{noconfirm}
209 argument is that it should be @code{t} if the buffer is going to be
210 reverted without asking the user and @code{nil} if the function is
211 just going to be used to warn the user that the buffer is out of date.
212 In particular, for use in auto-reverting, @var{noconfirm} is @code{t}.
213 If the function is only going to be used for auto-reverting, you can
214 ignore the @var{noconfirm} argument.
216 If you just want to automatically auto-revert every
217 @code{auto-revert-interval} seconds, use:
219 @example
220 (set (make-local-variable 'buffer-stale-function)
221      #'(lambda (&optional noconfirm) 'fast))
222 @end example
224 @noindent
225 in the buffer's mode function.
227 The special return value @samp{fast} tells the caller that the need
228 for reverting was not checked, but that reverting the buffer is fast.
229 It also tells Auto Revert not to print any revert messages, even if
230 @code{auto-revert-verbose} is non-@code{nil}.  This is important, as
231 getting revert messages every @code{auto-revert-interval} seconds can
232 be very annoying.  The information provided by this return value could
233 also be useful if the function is consulted for purposes other than
234 auto-reverting.
235 @end defvar
237 Once the buffer has a @code{revert-buffer-function} and a
238 @code{buffer-stale-function}, several problems usually remain.
240 The buffer will only auto-revert if it is marked unmodified.  Hence,
241 you will have to make sure that various functions mark the buffer
242 modified if and only if either the buffer contains information that
243 might be lost by reverting or there is reason to believe that the user
244 might be inconvenienced by auto-reverting, because he is actively
245 working on the buffer.  The user can always override this by manually
246 adjusting the modified status of the buffer.  To support this, calling
247 the @code{revert-buffer-function} on a buffer that is marked
248 unmodified should always keep the buffer marked unmodified.
250 It is important to assure that point does not continuously jump around
251 as a consequence of auto-reverting.  Of course, moving point might be
252 inevitable if the buffer radically changes.
254 You should make sure that the @code{revert-buffer-function} does not
255 print messages that unnecessarily duplicate Auto Revert's own messages
256 if @code{auto-revert-verbose} is @code{t} and effectively override a
257 @code{nil} value for @code{auto-revert-verbose}.  Hence, adapting a
258 mode for auto-reverting often involves getting rid of such messages.
259 This is especially important for buffers that automatically
260 auto-revert every @code{auto-revert-interval} seconds.
262 Also, you may want to update the documentation string of
263 @code{global-auto-revert-non-file-buffers}.
265 @ifinfo
266 Finally, you should add a node to this chapter's menu.  This node
267 @end ifinfo
268 @ifnotinfo
269 Finally, you should add a section to this chapter.  This section
270 @end ifnotinfo
271 should at the very least make clear whether enabling auto-reverting
272 for the buffer reliably assures that all information in the buffer is
273 completely up to date (or will be after @code{auto-revert-interval}
274 seconds).
276 @node Subdir switches
277 @chapter Subdirectory Switches in Dired
279 You can insert subdirectories with specified @code{ls} switches in
280 Dired buffers, using @kbd{C-u i}.  You can change the @code{ls}
281 switches of an already inserted subdirectory using @kbd{C-u l}.
283 In Emacs versions 22.1 and later, Dired remembers the switches, so
284 that reverting the buffer will not change them back to the main
285 directory's switches.  Deleting a subdirectory forgets about its
286 switches.
288 Using @code{dired-undo} (usually bound to @kbd{C-_} and @kbd{C-x u})
289 to reinsert or delete subdirectories, that were inserted with explicit
290 switches, can bypass Dired's machinery for remembering (or forgetting)
291 switches.  Deleting a subdirectory using @code{dired-undo} does not
292 forget its switches.  When later reinserted using @kbd{i}, it will be
293 reinserted using its old switches.  Using @code{dired-undo} to
294 reinsert a subdirectory that was deleted using the regular
295 Dired commands (not @code{dired-undo}) will originally insert it with
296 its old switches.  However, reverting the buffer will relist it using
297 the buffer's default switches.  If any of this yields problems, you
298 can easily correct the situation using @kbd{C-u i} or @kbd{C-u l}.
300 Dired does not remember the @code{R} switch.  Inserting a subdirectory
301 with switches that include the @code{R} switch is equivalent with
302 inserting each of its subdirectories using all remaining switches.
303 For instance, updating or killing a subdirectory that was inserted
304 with the @code{R} switch will not update or kill its subdirectories.
306 The buffer's default switches do not affect subdirectories that were
307 inserted using explicitly specified switches.  In particular,
308 commands such as @kbd{s}, that change the buffer's switches do not
309 affect such subdirectories.  (They do affect subdirectories without
310 explicitly assigned switches, however.)
312 You can make Dired forget about all subdirectory switches and relist
313 all subdirectories with the buffer's default switches using
314 @kbd{M-x dired-reset-subdir-switches}.  This also reverts the Dired buffer.
317 @c Moved here from the Emacs Lisp Reference Manual, 2005-03-26.
318 @node Advanced Calendar/Diary Usage
319 @chapter Customizing the Calendar and Diary
321   There are many customizations that you can use to make the calendar and
322 diary suit your personal tastes.
324 @menu
325 * Calendar Customizing::   Defaults you can set.
326 * Holiday Customizing::    Defining your own holidays.
327 * Date Display Format::    Changing the format.
328 * Time Display Format::    Changing the format.
329 * Daylight Savings::       Changing the default.
330 * Diary Customizing::      Defaults you can set.
331 * Hebrew/Islamic Entries:: How to obtain them.
332 * Fancy Diary Display::    Enhancing the diary display, sorting entries,
333                              using included diary files.
334 * Sexp Diary Entries::     Fancy things you can do.
335 @end menu
337 @node Calendar Customizing
338 @section Customizing the Calendar
339 @vindex calendar-holiday-marker
340 @vindex diary-entry-marker
341   The variable @code{calendar-holiday-marker} specifies how to mark a
342 date as being a holiday.  Its value may be a single-character string
343 to insert next to the date, or a face name to use for displaying the
344 date.  Likewise, the variable @code{diary-entry-marker} specifies how
345 to mark a date that has diary entries.  The calendar creates faces
346 named @code{holiday-face} and @code{diary-face} for these purposes;
347 those symbols are the default values of these variables.
349 @vindex calendar-load-hook
350   The variable @code{calendar-load-hook} is a normal hook run when the
351 calendar package is first loaded (before actually starting to display
352 the calendar).
354 @vindex initial-calendar-window-hook
355   Starting the calendar runs the normal hook
356 @code{initial-calendar-window-hook}.  Recomputation of the calendar
357 display does not run this hook.  But if you leave the calendar with the
358 @kbd{q} command and reenter it, the hook runs again.@refill
360 @vindex today-visible-calendar-hook
361   The variable @code{today-visible-calendar-hook} is a normal hook run
362 after the calendar buffer has been prepared with the calendar when the
363 current date is visible in the window.  One use of this hook is to
364 replace today's date with asterisks; to do that, use the hook function
365 @code{calendar-star-date}.
367 @findex calendar-star-date
368 @example
369 (add-hook 'today-visible-calendar-hook 'calendar-star-date)
370 @end example
372 @noindent
373 Another standard hook function marks the current date, either by
374 changing its face or by adding an asterisk.  Here's how to use it:
376 @findex calendar-mark-today
377 @example
378 (add-hook 'today-visible-calendar-hook 'calendar-mark-today)
379 @end example
381 @noindent
382 @vindex calendar-today-marker
383 The variable @code{calendar-today-marker} specifies how to mark
384 today's date.  Its value should be a single-character string to insert
385 next to the date or a face name to use for displaying the date.  A
386 face named @code{calendar-today-face} is provided for this purpose;
387 that symbol is the default for this variable.
389 @vindex today-invisible-calendar-hook
390 @noindent
391   A similar normal hook, @code{today-invisible-calendar-hook} is run if
392 the current date is @emph{not} visible in the window.
394 @vindex calendar-move-hook
395   Each of the calendar cursor motion commands runs the hook
396 @code{calendar-move-hook} after it moves the cursor.
398 @node Holiday Customizing
399 @section Customizing the Holidays
401 @vindex calendar-holidays
402 @vindex christian-holidays
403 @vindex hebrew-holidays
404 @vindex islamic-holidays
405   Emacs knows about holidays defined by entries on one of several lists.
406 You can customize these lists of holidays to your own needs, adding or
407 deleting holidays.  The lists of holidays that Emacs uses are for
408 general holidays (@code{general-holidays}), local holidays
409 (@code{local-holidays}), Christian holidays (@code{christian-holidays}),
410 Hebrew (Jewish) holidays (@code{hebrew-holidays}), Islamic (Muslim)
411 holidays (@code{islamic-holidays}), and other holidays
412 (@code{other-holidays}).
414 @vindex general-holidays
415   The general holidays are, by default, holidays common throughout the
416 United States.  To eliminate these holidays, set @code{general-holidays}
417 to @code{nil}.
419 @vindex local-holidays
420   There are no default local holidays (but sites may supply some).  You
421 can set the variable @code{local-holidays} to any list of holidays, as
422 described below.
424 @vindex all-christian-calendar-holidays
425 @vindex all-hebrew-calendar-holidays
426 @vindex all-islamic-calendar-holidays
427   By default, Emacs does not include all the holidays of the religions
428 that it knows, only those commonly found in secular calendars.  For a
429 more extensive collection of religious holidays, you can set any (or
430 all) of the variables @code{all-christian-calendar-holidays},
431 @code{all-hebrew-calendar-holidays}, or
432 @code{all-islamic-calendar-holidays} to @code{t}.  If you want to
433 eliminate the religious holidays, set any or all of the corresponding
434 variables @code{christian-holidays}, @code{hebrew-holidays}, and
435 @code{islamic-holidays} to @code{nil}.@refill
437 @vindex other-holidays
438   You can set the variable @code{other-holidays} to any list of
439 holidays.  This list, normally empty, is intended for individual use.
441 @cindex holiday forms
442   Each of the lists (@code{general-holidays}, @code{local-holidays},
443 @code{christian-holidays}, @code{hebrew-holidays},
444 @code{islamic-holidays}, and @code{other-holidays}) is a list of
445 @dfn{holiday forms}, each holiday form describing a holiday (or
446 sometimes a list of holidays).
448   Here is a table of the possible kinds of holiday form.  Day numbers
449 and month numbers count starting from 1, but ``dayname'' numbers
450 count Sunday as 0.  The element @var{string} is always the
451 name of the holiday, as a string.
453 @table @code
454 @item (holiday-fixed @var{month} @var{day} @var{string})
455 A fixed date on the Gregorian calendar.
457 @item (holiday-float @var{month} @var{dayname} @var{k} @var{string})
458 The @var{k}th @var{dayname} in @var{month} on the Gregorian calendar
459 (@var{dayname}=0 for Sunday, and so on); negative @var{k} means count back
460 from the end of the month.
462 @item (holiday-hebrew @var{month} @var{day} @var{string})
463 A fixed date on the Hebrew calendar.
465 @item (holiday-islamic @var{month} @var{day} @var{string})
466 A fixed date on the Islamic calendar.
468 @item (holiday-julian @var{month} @var{day} @var{string})
469 A fixed date on the Julian calendar.
471 @item (holiday-sexp @var{sexp} @var{string})
472 A date calculated by the Lisp expression @var{sexp}.  The expression
473 should use the variable @code{year} to compute and return the date of a
474 holiday, or @code{nil} if the holiday doesn't happen this year.  The
475 value of @var{sexp} must represent the date as a list of the form
476 @code{(@var{month} @var{day} @var{year})}.
478 @item (if @var{condition} @var{holiday-form})
479 A holiday that happens only if @var{condition} is true.
481 @item (@var{function} @r{[}@var{args}@r{]})
482 A list of dates calculated by the function @var{function}, called with
483 arguments @var{args}.
484 @end table
486   For example, suppose you want to add Bastille Day, celebrated in
487 France on July 14.  You can do this as follows:
489 @smallexample
490 (setq other-holidays '((holiday-fixed 7 14 "Bastille Day")))
491 @end smallexample
493 @noindent
494 The holiday form @code{(holiday-fixed 7 14 "Bastille Day")} specifies the
495 fourteenth day of the seventh month (July).
497   Many holidays occur on a specific day of the week, at a specific time
498 of month.  Here is a holiday form describing Hurricane Supplication Day,
499 celebrated in the Virgin Islands on the fourth Monday in August:
501 @smallexample
502 (holiday-float 8 1 4 "Hurricane Supplication Day")
503 @end smallexample
505 @noindent
506 Here the 8 specifies August, the 1 specifies Monday (Sunday is 0,
507 Tuesday is 2, and so on), and the 4 specifies the fourth occurrence in
508 the month (1 specifies the first occurrence, 2 the second occurrence,
509 @minus{}1 the last occurrence, @minus{}2 the second-to-last occurrence, and
510 so on).
512   You can specify holidays that occur on fixed days of the Hebrew,
513 Islamic, and Julian calendars too.  For example,
515 @smallexample
516 (setq other-holidays
517       '((holiday-hebrew 10 2 "Last day of Hanukkah")
518         (holiday-islamic 3 12 "Mohammed's Birthday")
519         (holiday-julian 4 2 "Jefferson's Birthday")))
520 @end smallexample
522 @noindent
523 adds the last day of Hanukkah (since the Hebrew months are numbered with
524 1 starting from Nisan), the Islamic feast celebrating Mohammed's
525 birthday (since the Islamic months are numbered from 1 starting with
526 Muharram), and Thomas Jefferson's birthday, which is 2 April 1743 on the
527 Julian calendar.
529   To include a holiday conditionally, use either Emacs Lisp's @code{if} or the
530 @code{holiday-sexp} form.  For example, American presidential elections
531 occur on the first Tuesday after the first Monday in November of years
532 divisible by 4:
534 @smallexample
535 (holiday-sexp '(if (= 0 (% year 4))
536                    (calendar-gregorian-from-absolute
537                     (1+ (calendar-dayname-on-or-before
538                           1 (+ 6 (calendar-absolute-from-gregorian
539                                   (list 11 1 year)))))))
540               "US Presidential Election")
541 @end smallexample
543 @noindent
546 @smallexample
547 (if (= 0 (% displayed-year 4))
548     (fixed 11
549            (extract-calendar-day
550              (calendar-gregorian-from-absolute
551                (1+ (calendar-dayname-on-or-before
552                      1 (+ 6 (calendar-absolute-from-gregorian
553                               (list 11 1 displayed-year)))))))
554            "US Presidential Election"))
555 @end smallexample
557   Some holidays just don't fit into any of these forms because special
558 calculations are involved in their determination.  In such cases you
559 must write a Lisp function to do the calculation.  To include eclipses,
560 for example, add @code{(eclipses)} to @code{other-holidays}
561 and write an Emacs Lisp function @code{eclipses} that returns a
562 (possibly empty) list of the relevant Gregorian dates among the range
563 visible in the calendar window, with descriptive strings, like this:
565 @smallexample
566 (((6 27 1991) "Lunar Eclipse") ((7 11 1991) "Solar Eclipse") ... )
567 @end smallexample
569 @node Date Display Format
570 @section Date Display Format
571 @vindex calendar-date-display-form
573   You can customize the manner of displaying dates in the diary, in mode
574 lines, and in messages by setting @code{calendar-date-display-form}.
575 This variable holds a list of expressions that can involve the variables
576 @code{month}, @code{day}, and @code{year}, which are all numbers in
577 string form, and @code{monthname} and @code{dayname}, which are both
578 alphabetic strings.  In the American style, the default value of this
579 list is as follows:
581 @smallexample
582 ((if dayname (concat dayname ", ")) monthname " " day ", " year)
583 @end smallexample
585 @noindent
586 while in the European style this value is the default:
588 @smallexample
589 ((if dayname (concat dayname ", ")) day " " monthname " " year)
590 @end smallexample
592 @noindent
593 The ISO standard date representation is this:
595 @smallexample
596 (year "-" month "-" day)
597 @end smallexample
599 @noindent
600 This specifies a typical American format:
602 @smallexample
603 (month "/" day "/" (substring year -2))
604 @end smallexample
606 @node Time Display Format
607 @section Time Display Format
608 @vindex calendar-time-display-form
610   The calendar and diary by default display times of day in the
611 conventional American style with the hours from 1 through 12, minutes,
612 and either @samp{am} or @samp{pm}.  If you prefer the European style,
613 also known in the US as military, in which the hours go from 00 to 23,
614 you can alter the variable @code{calendar-time-display-form}.  This
615 variable is a list of expressions that can involve the variables
616 @code{12-hours}, @code{24-hours}, and @code{minutes}, which are all
617 numbers in string form, and @code{am-pm} and @code{time-zone}, which are
618 both alphabetic strings.  The default value of
619 @code{calendar-time-display-form} is as follows:
621 @smallexample
622 (12-hours ":" minutes am-pm
623           (if time-zone " (") time-zone (if time-zone ")"))
624 @end smallexample
626 @noindent
627 Here is a value that provides European style times:
629 @smallexample
630 (24-hours ":" minutes
631           (if time-zone " (") time-zone (if time-zone ")"))
632 @end smallexample
634 @node Daylight Savings
635 @section Daylight Savings Time
636 @cindex daylight savings time
638   Emacs understands the difference between standard time and daylight
639 savings time---the times given for sunrise, sunset, solstices,
640 equinoxes, and the phases of the moon take that into account.  The rules
641 for daylight savings time vary from place to place and have also varied
642 historically from year to year.  To do the job properly, Emacs needs to
643 know which rules to use.
645   Some operating systems keep track of the rules that apply to the place
646 where you are; on these systems, Emacs gets the information it needs
647 from the system automatically.  If some or all of this information is
648 missing, Emacs fills in the gaps with the rules currently used in
649 Cambridge, Massachusetts, which is the center of GNU's world.
652 @vindex calendar-daylight-savings-starts
653 @vindex calendar-daylight-savings-ends
654   If the default choice of rules is not appropriate for your location,
655 you can tell Emacs the rules to use by setting the variables
656 @code{calendar-daylight-savings-starts} and
657 @code{calendar-daylight-savings-ends}.  Their values should be Lisp
658 expressions that refer to the variable @code{year}, and evaluate to the
659 Gregorian date on which daylight savings time starts or (respectively)
660 ends, in the form of a list @code{(@var{month} @var{day} @var{year})}.
661 The values should be @code{nil} if your area does not use daylight
662 savings time.
664   Emacs uses these expressions to determine the start and end dates of
665 daylight savings time as holidays and for correcting times of day in the
666 solar and lunar calculations.
668   The values for Cambridge, Massachusetts are as follows:
670 @example
671 @group
672 (calendar-nth-named-day 1 0 4 year)
673 (calendar-nth-named-day -1 0 10 year)
674 @end group
675 @end example
677 @noindent
678 i.e., the first 0th day (Sunday) of the fourth month (April) in
679 the year specified by @code{year}, and the last Sunday of the tenth month
680 (October) of that year.  If daylight savings time were
681 changed to start on October 1, you would set
682 @code{calendar-daylight-savings-starts} to this:
684 @example
685 (list 10 1 year)
686 @end example
688   For a more complex example, suppose daylight savings time begins on
689 the first of Nisan on the Hebrew calendar.  You should set
690 @code{calendar-daylight-savings-starts} to this value:
692 @example
693 (calendar-gregorian-from-absolute
694   (calendar-absolute-from-hebrew
695     (list 1 1 (+ year 3760))))
696 @end example
698 @noindent
699 because Nisan is the first month in the Hebrew calendar and the Hebrew
700 year differs from the Gregorian year by 3760 at Nisan.
702   If there is no daylight savings time at your location, or if you want
703 all times in standard time, set @code{calendar-daylight-savings-starts}
704 and @code{calendar-daylight-savings-ends} to @code{nil}.
706 @vindex calendar-daylight-time-offset
707   The variable @code{calendar-daylight-time-offset} specifies the
708 difference between daylight savings time and standard time, measured in
709 minutes.  The value for Cambridge is 60.
711 @vindex calendar-daylight-savings-starts-time
712 @vindex calendar-daylight-savings-ends-time
713   The variable @code{calendar-daylight-savings-starts-time} and the
714 variable @code{calendar-daylight-savings-ends-time} specify the number
715 of minutes after midnight local time when the transition to and from
716 daylight savings time should occur.  For Cambridge, both variables'
717 values are 120.
719 @node Diary Customizing
720 @section Customizing the Diary
722 @vindex holidays-in-diary-buffer
723   Ordinarily, the mode line of the diary buffer window indicates any
724 holidays that fall on the date of the diary entries.  The process of
725 checking for holidays can take several seconds, so including holiday
726 information delays the display of the diary buffer noticeably.  If you'd
727 prefer to have a faster display of the diary buffer but without the
728 holiday information, set the variable @code{holidays-in-diary-buffer} to
729 @code{nil}.@refill
731 @vindex number-of-diary-entries
732   The variable @code{number-of-diary-entries} controls the number of
733 days of diary entries to be displayed at one time.  It affects the
734 initial display when @code{view-diary-entries-initially} is @code{t}, as
735 well as the command @kbd{M-x diary}.  For example, the default value is
736 1, which says to display only the current day's diary entries.  If the
737 value is 2, both the current day's and the next day's entries are
738 displayed.  The value can also be a vector of seven elements: for
739 example, if the value is @code{[0 2 2 2 2 4 1]} then no diary entries
740 appear on Sunday, the current date's and the next day's diary entries
741 appear Monday through Thursday, Friday through Monday's entries appear
742 on Friday, while on Saturday only that day's entries appear.
744 @vindex print-diary-entries-hook
745 @findex print-diary-entries
746   The variable @code{print-diary-entries-hook} is a normal hook run
747 after preparation of a temporary buffer containing just the diary
748 entries currently visible in the diary buffer.  (The other, irrelevant
749 diary entries are really absent from the temporary buffer; in the diary
750 buffer, they are merely hidden.)  The default value of this hook does
751 the printing with the command @code{lpr-buffer}.  If you want to use a
752 different command to do the printing, just change the value of this
753 hook.  Other uses might include, for example, rearranging the lines into
754 order by day and time.
756 @vindex diary-date-forms
757   You can customize the form of dates in your diary file, if neither the
758 standard American nor European styles suits your needs, by setting the
759 variable @code{diary-date-forms}.  This variable is a list of patterns
760 for recognizing a date.  Each date pattern is a list whose elements may
761 be regular expressions (@pxref{Regular Expressions,,, elisp, the Emacs
762 Lisp Reference Manual}) or the symbols @code{month}, @code{day},
763 @code{year}, @code{monthname}, and @code{dayname}.  All these elements
764 serve as patterns that match certain kinds of text in the diary file.
765 In order for the date pattern, as a whole, to match, all of its elements
766 must match consecutively.
768   A regular expression in a date pattern matches in its usual fashion,
769 using the standard syntax table altered so that @samp{*} is a word
770 constituent.
772   The symbols @code{month}, @code{day}, @code{year}, @code{monthname},
773 and @code{dayname} match the month number, day number, year number,
774 month name, and day name of the date being considered.  The symbols that
775 match numbers allow leading zeros; those that match names allow
776 three-letter abbreviations and capitalization.  All the symbols can
777 match @samp{*}; since @samp{*} in a diary entry means ``any day'', ``any
778 month'', and so on, it should match regardless of the date being
779 considered.
781   The default value of @code{diary-date-forms} in the American style is
782 this:
784 @example
785 ((month "/" day "[^/0-9]")
786  (month "/" day "/" year "[^0-9]")
787  (monthname " *" day "[^,0-9]")
788  (monthname " *" day ", *" year "[^0-9]")
789  (dayname "\\W"))
790 @end example
792   The date patterns in the list must be @emph{mutually exclusive} and
793 must not match any portion of the diary entry itself, just the date and
794 one character of whitespace.  If, to be mutually exclusive, the pattern
795 must match a portion of the diary entry text---beyond the whitespace
796 that ends the date---then the first element of the date pattern
797 @emph{must} be @code{backup}.  This causes the date recognizer to back
798 up to the beginning of the current word of the diary entry, after
799 finishing the match.  Even if you use @code{backup}, the date pattern
800 must absolutely not match more than a portion of the first word of the
801 diary entry.  The default value of @code{diary-date-forms} in the
802 European style is this list:
804 @example
805 ((day "/" month "[^/0-9]")
806  (day "/" month "/" year "[^0-9]")
807  (backup day " *" monthname "\\W+\\<[^*0-9]")
808  (day " *" monthname " *" year "[^0-9]")
809  (dayname "\\W"))
810 @end example
812 @noindent
813 Notice the use of @code{backup} in the third pattern, because it needs
814 to match part of a word beyond the date itself to distinguish it from
815 the fourth pattern.
817 @node Hebrew/Islamic Entries
818 @section Hebrew- and Islamic-Date Diary Entries
820   Your diary file can have entries based on Hebrew or Islamic dates, as
821 well as entries based on the world-standard Gregorian calendar.
822 However, because recognition of such entries is time-consuming and most
823 people don't use them, you must explicitly enable their use.  If you
824 want the diary to recognize Hebrew-date diary entries, for example,
825 you must do this:
827 @vindex nongregorian-diary-listing-hook
828 @vindex nongregorian-diary-marking-hook
829 @findex list-hebrew-diary-entries
830 @findex mark-hebrew-diary-entries
831 @smallexample
832 (add-hook 'nongregorian-diary-listing-hook 'list-hebrew-diary-entries)
833 (add-hook 'nongregorian-diary-marking-hook 'mark-hebrew-diary-entries)
834 @end smallexample
836 @noindent
837 If you want Islamic-date entries, do this:
839 @findex list-islamic-diary-entries
840 @findex mark-islamic-diary-entries
841 @smallexample
842 (add-hook 'nongregorian-diary-listing-hook 'list-islamic-diary-entries)
843 (add-hook 'nongregorian-diary-marking-hook 'mark-islamic-diary-entries)
844 @end smallexample
846   Hebrew- and Islamic-date diary entries have the same formats as
847 Gregorian-date diary entries, except that @samp{H} precedes a Hebrew
848 date and @samp{I} precedes an Islamic date.  Moreover, because the
849 Hebrew and Islamic month names are not uniquely specified by the first
850 three letters, you may not abbreviate them.  For example, a diary entry
851 for the Hebrew date Heshvan 25 could look like this:
853 @smallexample
854 HHeshvan 25 Happy Hebrew birthday!
855 @end smallexample
857 @noindent
858 and would appear in the diary for any date that corresponds to Heshvan 25
859 on the Hebrew calendar.  And here is an Islamic-date diary entry that matches
860 Dhu al-Qada 25:
862 @smallexample
863 IDhu al-Qada 25 Happy Islamic birthday!
864 @end smallexample
866   As with Gregorian-date diary entries, Hebrew- and Islamic-date entries
867 are nonmarking if they are preceded with an ampersand (@samp{&}).
869   Here is a table of commands used in the calendar to create diary entries
870 that match the selected date and other dates that are similar in the Hebrew
871 or Islamic calendar:
873 @table @kbd
874 @item i h d
875 Add a diary entry for the Hebrew date corresponding to the selected date
876 (@code{insert-hebrew-diary-entry}).
877 @item i h m
878 Add a diary entry for the day of the Hebrew month corresponding to the
879 selected date (@code{insert-monthly-hebrew-diary-entry}).  This diary
880 entry matches any date that has the same Hebrew day-within-month as the
881 selected date.
882 @item i h y
883 Add a diary entry for the day of the Hebrew year corresponding to the
884 selected date (@code{insert-yearly-hebrew-diary-entry}).  This diary
885 entry matches any date which has the same Hebrew month and day-within-month
886 as the selected date.
887 @item i i d
888 Add a diary entry for the Islamic date corresponding to the selected date
889 (@code{insert-islamic-diary-entry}).
890 @item i i m
891 Add a diary entry for the day of the Islamic month corresponding to the
892 selected date (@code{insert-monthly-islamic-diary-entry}).
893 @item i i y
894 Add a diary entry for the day of the Islamic year corresponding to the
895 selected date (@code{insert-yearly-islamic-diary-entry}).
896 @end table
898 @findex insert-hebrew-diary-entry
899 @findex insert-monthly-hebrew-diary-entry
900 @findex insert-yearly-hebrew-diary-entry
901 @findex insert-islamic-diary-entry
902 @findex insert-monthly-islamic-diary-entry
903 @findex insert-yearly-islamic-diary-entry
904   These commands work much like the corresponding commands for ordinary
905 diary entries: they apply to the date that point is on in the calendar
906 window, and what they do is insert just the date portion of a diary entry
907 at the end of your diary file.  You must then insert the rest of the
908 diary entry.
910 @node Fancy Diary Display
911 @section Fancy Diary Display
912 @vindex diary-display-hook
913 @findex simple-diary-display
915   Diary display works by preparing the diary buffer and then running the
916 hook @code{diary-display-hook}.  The default value of this hook
917 (@code{simple-diary-display}) hides the irrelevant diary entries and
918 then displays the buffer.  However, if you specify the hook as follows,
920 @cindex diary buffer
921 @findex fancy-diary-display
922 @example
923 (add-hook 'diary-display-hook 'fancy-diary-display)
924 @end example
926 @noindent
927 this enables fancy diary display.  It displays diary entries and
928 holidays by copying them into a special buffer that exists only for the
929 sake of display.  Copying to a separate buffer provides an opportunity
930 to change the displayed text to make it prettier---for example, to sort
931 the entries by the dates they apply to.
933   As with simple diary display, you can print a hard copy of the buffer
934 with @code{print-diary-entries}.  To print a hard copy of a day-by-day
935 diary for a week, position point on Sunday of that week, type
936 @kbd{7 d}, and then do @kbd{M-x print-diary-entries}.  As usual, the
937 inclusion of the holidays slows down the display slightly; you can speed
938 things up by setting the variable @code{holidays-in-diary-buffer} to
939 @code{nil}.
941 @vindex diary-list-include-blanks
942   Ordinarily, the fancy diary buffer does not show days for which there are
943 no diary entries, even if that day is a holiday.  If you want such days to be
944 shown in the fancy diary buffer, set the variable
945 @code{diary-list-include-blanks} to @code{t}.@refill
947 @cindex sorting diary entries
948   If you use the fancy diary display, you can use the normal hook
949 @code{list-diary-entries-hook} to sort each day's diary entries by their
950 time of day.  Here's how:
952 @findex sort-diary-entries
953 @example
954 (add-hook 'list-diary-entries-hook 'sort-diary-entries t)
955 @end example
957 @noindent
958 For each day, this sorts diary entries that begin with a recognizable
959 time of day according to their times.  Diary entries without times come
960 first within each day.
962   Fancy diary display also has the ability to process included diary
963 files.  This permits a group of people to share a diary file for events
964 that apply to all of them.  Lines in the diary file of this form:
966 @smallexample
967 #include "@var{filename}"
968 @end smallexample
970 @noindent
971 includes the diary entries from the file @var{filename} in the fancy
972 diary buffer.  The include mechanism is recursive, so that included files
973 can include other files, and so on; you must be careful not to have a
974 cycle of inclusions, of course.  Here is how to enable the include
975 facility:
977 @vindex list-diary-entries-hook
978 @vindex mark-diary-entries-hook
979 @findex include-other-diary-files
980 @findex mark-included-diary-files
981 @smallexample
982 (add-hook 'list-diary-entries-hook 'include-other-diary-files)
983 (add-hook 'mark-diary-entries-hook 'mark-included-diary-files)
984 @end smallexample
986 The include mechanism works only with the fancy diary display, because
987 ordinary diary display shows the entries directly from your diary file.
989 @node Sexp Diary Entries
990 @section Sexp Entries and the Fancy Diary Display
991 @cindex sexp diary entries
993   Sexp diary entries allow you to do more than just have complicated
994 conditions under which a diary entry applies.  If you use the fancy
995 diary display, sexp entries can generate the text of the entry depending
996 on the date itself.  For example, an anniversary diary entry can insert
997 the number of years since the anniversary date into the text of the
998 diary entry.  Thus the @samp{%d} in this dairy entry:
1000 @findex diary-anniversary
1001 @smallexample
1002 %%(diary-anniversary 10 31 1948) Arthur's birthday (%d years old)
1003 @end smallexample
1005 @noindent
1006 gets replaced by the age, so on October 31, 1990 the entry appears in
1007 the fancy diary buffer like this:
1009 @smallexample
1010 Arthur's birthday (42 years old)
1011 @end smallexample
1013 @noindent
1014 If the diary file instead contains this entry:
1016 @smallexample
1017 %%(diary-anniversary 10 31 1948) Arthur's %d%s birthday
1018 @end smallexample
1020 @noindent
1021 the entry in the fancy diary buffer for October 31, 1990 appears like this:
1023 @smallexample
1024 Arthur's 42nd birthday
1025 @end smallexample
1027   Similarly, cyclic diary entries can interpolate the number of repetitions
1028 that have occurred:
1030 @findex diary-cyclic
1031 @smallexample
1032 %%(diary-cyclic 50 1 1 1990) Renew medication (%d%s time)
1033 @end smallexample
1035 @noindent
1036 looks like this:
1038 @smallexample
1039 Renew medication (5th time)
1040 @end smallexample
1042 @noindent
1043 in the fancy diary display on September 8, 1990.
1045   There is an early reminder diary sexp that includes its entry in the
1046 diary not only on the date of occurrence, but also on earlier dates.
1047 For example, if you want a reminder a week before your anniversary, you
1048 can use
1050 @findex diary-remind
1051 @smallexample
1052 %%(diary-remind '(diary-anniversary 12 22 1968) 7) Ed's anniversary
1053 @end smallexample
1055 @noindent
1056 and the fancy diary will show
1057 @smallexample
1058 Ed's anniversary
1059 @end smallexample
1060 @noindent
1061 both on December 15 and on December 22.
1063 @findex diary-date
1064   The function @code{diary-date} applies to dates described by a month,
1065 day, year combination, each of which can be an integer, a list of
1066 integers, or @code{t}. The value @code{t} means all values.  For
1067 example,
1069 @smallexample
1070 %%(diary-date '(10 11 12) 22 t) Rake leaves
1071 @end smallexample
1073 @noindent
1074 causes the fancy diary to show
1076 @smallexample
1077 Rake leaves
1078 @end smallexample
1080 @noindent
1081 on October 22, November 22, and December 22 of every year.
1083 @findex diary-float
1084   The function @code{diary-float} allows you to describe diary entries
1085 that apply to dates like the third Friday of November, or the last
1086 Tuesday in April.  The parameters are the @var{month}, @var{dayname},
1087 and an index @var{n}. The entry appears on the @var{n}th @var{dayname}
1088 of @var{month}, where @var{dayname}=0 means Sunday, 1 means Monday, and
1089 so on.  If @var{n} is negative it counts backward from the end of
1090 @var{month}.  The value of @var{month} can be a list of months, a single
1091 month, or @code{t} to specify all months.  You can also use an optional
1092 parameter @var{day} to specify the @var{n}th @var{dayname} of
1093 @var{month} on or after/before @var{day}; the value of @var{day} defaults
1094 to 1 if @var{n} is positive and to the last day of @var{month} if
1095 @var{n} is negative.  For example,
1097 @smallexample
1098 %%(diary-float t 1 -1) Pay rent
1099 @end smallexample
1101 @noindent
1102 causes the fancy diary to show
1104 @smallexample
1105 Pay rent
1106 @end smallexample
1108 @noindent
1109 on the last Monday of every month.
1111   The generality of sexp diary entries lets you specify any diary
1112 entry that you can describe algorithmically.  A sexp diary entry
1113 contains an expression that computes whether the entry applies to any
1114 given date.  If its value is non-@code{nil}, the entry applies to that
1115 date; otherwise, it does not.  The expression can use the variable
1116 @code{date} to find the date being considered; its value is a list
1117 (@var{month} @var{day} @var{year}) that refers to the Gregorian
1118 calendar.
1120   The sexp diary entry applies to a date when the expression's value
1121 is non-@code{nil}, but some values have more specific meanings.  If
1122 the value is a string, that string is a description of the event which
1123 occurs on that date.  The value can also have the form
1124 @code{(@var{mark} . @var{string})}; then @var{mark} specifies how to
1125 mark the date in the calendar, and @var{string} is the description of
1126 the event.  If @var{mark} is a single-character string, that character
1127 appears next to the date in the calendar.  If @var{mark} is a face
1128 name, the date is displayed in that face.  If @var{mark} is
1129 @code{nil}, that specifies no particular highlighting for the date.
1131   Suppose you get paid on the 21st of the month if it is a weekday, and
1132 on the Friday before if the 21st is on a weekend.  Here is how to write
1133 a sexp diary entry that matches those dates:
1135 @smallexample
1136 &%%(let ((dayname (calendar-day-of-week date))
1137          (day (car (cdr date))))
1138       (or (and (= day 21) (memq dayname '(1 2 3 4 5)))
1139           (and (memq day '(19 20)) (= dayname 5)))
1140          ) Pay check deposited
1141 @end smallexample
1143   The following sexp diary entries take advantage of the ability (in the fancy
1144 diary display) to concoct diary entries whose text varies based on the date:
1146 @findex diary-sunrise-sunset
1147 @findex diary-phases-of-moon
1148 @findex diary-day-of-year
1149 @findex diary-iso-date
1150 @findex diary-julian-date
1151 @findex diary-astro-day-number
1152 @findex diary-hebrew-date
1153 @findex diary-islamic-date
1154 @findex diary-french-date
1155 @findex diary-mayan-date
1156 @table @code
1157 @item %%(diary-sunrise-sunset)
1158 Make a diary entry for the local times of today's sunrise and sunset.
1159 @item %%(diary-phases-of-moon)
1160 Make a diary entry for the phases (quarters) of the moon.
1161 @item %%(diary-day-of-year)
1162 Make a diary entry with today's day number in the current year and the number
1163 of days remaining in the current year.
1164 @item %%(diary-iso-date)
1165 Make a diary entry with today's equivalent ISO commercial date.
1166 @item %%(diary-julian-date)
1167 Make a diary entry with today's equivalent date on the Julian calendar.
1168 @item %%(diary-astro-day-number)
1169 Make a diary entry with today's equivalent astronomical (Julian) day number.
1170 @item %%(diary-hebrew-date)
1171 Make a diary entry with today's equivalent date on the Hebrew calendar.
1172 @item %%(diary-islamic-date)
1173 Make a diary entry with today's equivalent date on the Islamic calendar.
1174 @item %%(diary-french-date)
1175 Make a diary entry with today's equivalent date on the French Revolutionary
1176 calendar.
1177 @item %%(diary-mayan-date)
1178 Make a diary entry with today's equivalent date on the Mayan calendar.
1179 @end table
1181 @noindent
1182 Thus including the diary entry
1184 @example
1185 &%%(diary-hebrew-date)
1186 @end example
1188 @noindent
1189 causes every day's diary display to contain the equivalent date on the
1190 Hebrew calendar, if you are using the fancy diary display.  (With simple
1191 diary display, the line @samp{&%%(diary-hebrew-date)} appears in the
1192 diary for any date, but does nothing particularly useful.)
1194   These functions can be used to construct sexp diary entries based on
1195 the Hebrew calendar in certain standard ways:
1197 @cindex rosh hodesh
1198 @findex diary-rosh-hodesh
1199 @cindex parasha, weekly
1200 @findex diary-parasha
1201 @cindex candle lighting times
1202 @findex diary-sabbath-candles
1203 @cindex omer count
1204 @findex diary-omer
1205 @cindex yahrzeits
1206 @findex diary-yahrzeit
1207 @table @code
1208 @item %%(diary-rosh-hodesh)
1209 Make a diary entry that tells the occurrence and ritual announcement of each
1210 new Hebrew month.
1211 @item %%(diary-parasha)
1212 Make a Saturday diary entry that tells the weekly synagogue scripture reading.
1213 @item %%(diary-sabbath-candles)
1214 Make a Friday diary entry that tells the @emph{local time} of Sabbath
1215 candle lighting.
1216 @item %%(diary-omer)
1217 Make a diary entry that gives the omer count, when appropriate.
1218 @item %%(diary-yahrzeit @var{month} @var{day} @var{year}) @var{name}
1219 Make a diary entry marking the anniversary of a date of death.  The date
1220 is the @emph{Gregorian} (civil) date of death.  The diary entry appears
1221 on the proper Hebrew calendar anniversary and on the day before.  (In
1222 the European style, the order of the parameters is changed to @var{day},
1223 @var{month}, @var{year}.)
1224 @end table
1226   All the functions documented above take an optional argument
1227 @var{mark} which specifies how to mark the date in the calendar display.
1228 If one of these functions decides that it applies to a certain date,
1229 it returns a value that contains @var{mark}.
1231 @node Emerge
1232 @chapter Merging Files with Emerge
1233 @cindex Emerge
1234 @cindex merging files
1236   It's not unusual for programmers to get their signals crossed and
1237 modify the same program in two different directions.  To recover from
1238 this confusion, you need to merge the two versions.  Emerge makes this
1239 easier.  For other ways to compare files, see @ref{Comparing Files,,,
1240 emacs, the Emacs Manual} and @ref{Top, Ediff,, ediff, The Ediff
1241 Manual}.
1243 @menu
1244 * Overview of Emerge::  How to start Emerge.  Basic concepts.
1245 * Submodes of Emerge::  Fast mode vs. Edit mode.
1246                           Skip Prefers mode and Auto Advance mode.
1247 * State of Difference:: You do the merge by specifying state A or B
1248                           for each difference.
1249 * Merge Commands::      Commands for selecting a difference,
1250                           changing states of differences, etc.
1251 * Exiting Emerge::      What to do when you've finished the merge.
1252 * Combining in Emerge::     How to keep both alternatives for a difference.
1253 * Fine Points of Emerge::   Misc.
1254 @end menu
1256 @node Overview of Emerge
1257 @section Overview of Emerge
1259   To start Emerge, run one of these four commands:
1261 @table @kbd
1262 @item M-x emerge-files
1263 @findex emerge-files
1264 Merge two specified files.
1266 @item M-x emerge-files-with-ancestor
1267 @findex emerge-files-with-ancestor
1268 Merge two specified files, with reference to a common ancestor.
1270 @item M-x emerge-buffers
1271 @findex emerge-buffers
1272 Merge two buffers.
1274 @item M-x emerge-buffers-with-ancestor
1275 @findex emerge-buffers-with-ancestor
1276 Merge two buffers with reference to a common ancestor in a third
1277 buffer.
1278 @end table
1280 @cindex merge buffer (Emerge)
1281 @cindex A and B buffers (Emerge)
1282   The Emerge commands compare two files or buffers, and display the
1283 comparison in three buffers: one for each input text (the @dfn{A buffer}
1284 and the @dfn{B buffer}), and one (the @dfn{merge buffer}) where merging
1285 takes place.  The merge buffer shows the full merged text, not just the
1286 differences.  Wherever the two input texts differ, you can choose which
1287 one of them to include in the merge buffer.
1289   The Emerge commands that take input from existing buffers use only
1290 the accessible portions of those buffers, if they are narrowed.
1291 @xref{Narrowing,,, emacs, the Emacs Manual}.
1294   If a common ancestor version is available, from which the two texts to
1295 be merged were both derived, Emerge can use it to guess which
1296 alternative is right.  Wherever one current version agrees with the
1297 ancestor, Emerge presumes that the other current version is a deliberate
1298 change which should be kept in the merged version.  Use the
1299 @samp{with-ancestor} commands if you want to specify a common ancestor
1300 text.  These commands read three file or buffer names---variant A,
1301 variant B, and the common ancestor.
1303   After the comparison is done and the buffers are prepared, the
1304 interactive merging starts.  You control the merging by typing special
1305 @dfn{merge commands} in the merge buffer (@pxref{Merge Commands}).
1306 For each run of differences between the input texts, you can choose
1307 which one of them to keep, or edit them both together.
1309   The merge buffer uses a special major mode, Emerge mode, with commands
1310 for making these choices.  But you can also edit the buffer with
1311 ordinary Emacs commands.
1313   At any given time, the attention of Emerge is focused on one
1314 particular difference, called the @dfn{selected} difference.  This
1315 difference is marked off in the three buffers like this:
1317 @example
1318 vvvvvvvvvvvvvvvvvvvv
1319 @var{text that differs}
1320 ^^^^^^^^^^^^^^^^^^^^
1321 @end example
1323 @noindent
1324 Emerge numbers all the differences sequentially and the mode
1325 line always shows the number of the selected difference.
1327   Normally, the merge buffer starts out with the A version of the text.
1328 But when the A version of a difference agrees with the common ancestor,
1329 then the B version is initially preferred for that difference.
1331   Emerge leaves the merged text in the merge buffer when you exit.  At
1332 that point, you can save it in a file with @kbd{C-x C-w}.  If you give a
1333 numeric argument to @code{emerge-files} or
1334 @code{emerge-files-with-ancestor}, it reads the name of the output file
1335 using the minibuffer.  (This is the last file name those commands read.)
1336 Then exiting from Emerge saves the merged text in the output file.
1338   Normally, Emerge commands save the output buffer in its file when you
1339 exit.  If you abort Emerge with @kbd{C-]}, the Emerge command does not
1340 save the output buffer, but you can save it yourself if you wish.
1342 @node Submodes of Emerge
1343 @section Submodes of Emerge
1345   You can choose between two modes for giving merge commands: Fast mode
1346 and Edit mode.  In Fast mode, basic merge commands are single
1347 characters, but ordinary Emacs commands are disabled.  This is
1348 convenient if you use only merge commands.  In Edit mode, all merge
1349 commands start with the prefix key @kbd{C-c C-c}, and the normal Emacs
1350 commands are also available.  This allows editing the merge buffer, but
1351 slows down Emerge operations.
1353   Use @kbd{e} to switch to Edit mode, and @kbd{C-c C-c f} to switch to
1354 Fast mode.  The mode line indicates Edit and Fast modes with @samp{E}
1355 and @samp{F}.
1357   Emerge has two additional submodes that affect how particular merge
1358 commands work: Auto Advance mode and Skip Prefers mode.
1360   If Auto Advance mode is in effect, the @kbd{a} and @kbd{b} commands
1361 advance to the next difference.  This lets you go through the merge
1362 faster as long as you simply choose one of the alternatives from the
1363 input.  The mode line indicates Auto Advance mode with @samp{A}.
1365   If Skip Prefers mode is in effect, the @kbd{n} and @kbd{p} commands
1366 skip over differences in states prefer-A and prefer-B (@pxref{State of
1367 Difference}).  Thus you see only differences for which neither version
1368 is presumed ``correct.''  The mode line indicates Skip Prefers mode with
1369 @samp{S}.
1371 @findex emerge-auto-advance-mode
1372 @findex emerge-skip-prefers-mode
1373   Use the command @kbd{s a} (@code{emerge-auto-advance-mode}) to set or
1374 clear Auto Advance mode.  Use @kbd{s s}
1375 (@code{emerge-skip-prefers-mode}) to set or clear Skip Prefers mode.
1376 These commands turn on the mode with a positive argument, turns it off
1377 with a negative or zero argument, and toggle the mode with no argument.
1379 @node State of Difference
1380 @section State of a Difference
1382   In the merge buffer, a difference is marked with lines of @samp{v} and
1383 @samp{^} characters.  Each difference has one of these seven states:
1385 @table @asis
1386 @item A
1387 The difference is showing the A version.  The @kbd{a} command always
1388 produces this state; the mode line indicates it with @samp{A}.
1390 @item B
1391 The difference is showing the B version.  The @kbd{b} command always
1392 produces this state; the mode line indicates it with @samp{B}.
1394 @item default-A
1395 @itemx default-B
1396 The difference is showing the A or the B state by default, because you
1397 haven't made a choice.  All differences start in the default-A state
1398 (and thus the merge buffer is a copy of the A buffer), except those for
1399 which one alternative is ``preferred'' (see below).
1401 When you select a difference, its state changes from default-A or
1402 default-B to plain A or B.  Thus, the selected difference never has
1403 state default-A or default-B, and these states are never displayed in
1404 the mode line.
1406 The command @kbd{d a} chooses default-A as the default state, and @kbd{d
1407 b} chooses default-B.  This chosen default applies to all differences
1408 which you haven't ever selected and for which no alternative is preferred.
1409 If you are moving through the merge sequentially, the differences you
1410 haven't selected are those following the selected one.  Thus, while
1411 moving sequentially, you can effectively make the A version the default
1412 for some sections of the merge buffer and the B version the default for
1413 others by using @kbd{d a} and @kbd{d b} between sections.
1415 @item prefer-A
1416 @itemx prefer-B
1417 The difference is showing the A or B state because it is
1418 @dfn{preferred}.  This means that you haven't made an explicit choice,
1419 but one alternative seems likely to be right because the other
1420 alternative agrees with the common ancestor.  Thus, where the A buffer
1421 agrees with the common ancestor, the B version is preferred, because
1422 chances are it is the one that was actually changed.
1424 These two states are displayed in the mode line as @samp{A*} and @samp{B*}.
1426 @item combined
1427 The difference is showing a combination of the A and B states, as a
1428 result of the @kbd{x c} or @kbd{x C} commands.
1430 Once a difference is in this state, the @kbd{a} and @kbd{b} commands
1431 don't do anything to it unless you give them a numeric argument.
1433 The mode line displays this state as @samp{comb}.
1434 @end table
1436 @node Merge Commands
1437 @section Merge Commands
1439   Here are the Merge commands for Fast mode; in Edit mode, precede them
1440 with @kbd{C-c C-c}:
1442 @table @kbd
1443 @item p
1444 Select the previous difference.
1446 @item n
1447 Select the next difference.
1449 @item a
1450 Choose the A version of this difference.
1452 @item b
1453 Choose the B version of this difference.
1455 @item C-u @var{n} j
1456 Select difference number @var{n}.
1458 @item .
1459 Select the difference containing point.  You can use this command in the
1460 merge buffer or in the A or B buffer.
1462 @item q
1463 Quit---finish the merge.
1465 @item C-]
1466 Abort---exit merging and do not save the output.
1468 @item f
1469 Go into Fast mode.  (In Edit mode, this is actually @kbd{C-c C-c f}.)
1471 @item e
1472 Go into Edit mode.
1474 @item l
1475 Recenter (like @kbd{C-l}) all three windows.
1477 @item -
1478 Specify part of a prefix numeric argument.
1480 @item @var{digit}
1481 Also specify part of a prefix numeric argument.
1483 @item d a
1484 Choose the A version as the default from here down in
1485 the merge buffer.
1487 @item d b
1488 Choose the B version as the default from here down in
1489 the merge buffer.
1491 @item c a
1492 Copy the A version of this difference into the kill ring.
1494 @item c b
1495 Copy the B version of this difference into the kill ring.
1497 @item i a
1498 Insert the A version of this difference at point.
1500 @item i b
1501 Insert the B version of this difference at point.
1503 @item m
1504 Put point and mark around the difference.
1506 @item ^
1507 Scroll all three windows down (like @kbd{M-v}).
1509 @item v
1510 Scroll all three windows up (like @kbd{C-v}).
1512 @item <
1513 Scroll all three windows left (like @kbd{C-x <}).
1515 @item >
1516 Scroll all three windows right (like @kbd{C-x >}).
1518 @item |
1519 Reset horizontal scroll on all three windows.
1521 @item x 1
1522 Shrink the merge window to one line.  (Use @kbd{C-u l} to restore it
1523 to full size.)
1525 @item x c
1526 Combine the two versions of this difference (@pxref{Combining in
1527 Emerge}).
1529 @item x f
1530 Show the names of the files/buffers Emerge is operating on, in a Help
1531 window.  (Use @kbd{C-u l} to restore windows.)
1533 @item x j
1534 Join this difference with the following one.
1535 (@kbd{C-u x j} joins this difference with the previous one.)
1537 @item x s
1538 Split this difference into two differences.  Before you use this
1539 command, position point in each of the three buffers at the place where
1540 you want to split the difference.
1542 @item x t
1543 Trim identical lines off the top and bottom of the difference.
1544 Such lines occur when the A and B versions are
1545 identical but differ from the ancestor version.
1546 @end table
1548 @node Exiting Emerge
1549 @section Exiting Emerge
1551   The @kbd{q} command (@code{emerge-quit}) finishes the merge, storing
1552 the results into the output file if you specified one.  It restores the
1553 A and B buffers to their proper contents, or kills them if they were
1554 created by Emerge and you haven't changed them.  It also disables the
1555 Emerge commands in the merge buffer, since executing them later could
1556 damage the contents of the various buffers.
1558   @kbd{C-]} aborts the merge.  This means exiting without writing the
1559 output file.  If you didn't specify an output file, then there is no
1560 real difference between aborting and finishing the merge.
1562   If the Emerge command was called from another Lisp program, then its
1563 return value is @code{t} for successful completion, or @code{nil} if you
1564 abort.
1566 @node Combining in Emerge
1567 @section Combining the Two Versions
1569   Sometimes you want to keep @emph{both} alternatives for a particular
1570 difference.  To do this, use @kbd{x c}, which edits the merge buffer
1571 like this:
1573 @example
1574 @group
1575 #ifdef NEW
1576 @var{version from A buffer}
1577 #else /* not NEW */
1578 @var{version from B buffer}
1579 #endif /* not NEW */
1580 @end group
1581 @end example
1583 @noindent
1584 @vindex emerge-combine-versions-template
1585 While this example shows C preprocessor conditionals delimiting the two
1586 alternative versions, you can specify the strings to use by setting
1587 the variable @code{emerge-combine-versions-template} to a string of your
1588 choice.  In the string, @samp{%a} says where to put version A, and
1589 @samp{%b} says where to put version B.  The default setting, which
1590 produces the results shown above, looks like this:
1592 @example
1593 @group
1594 "#ifdef NEW\n%a#else /* not NEW */\n%b#endif /* not NEW */\n"
1595 @end group
1596 @end example
1598 @node Fine Points of Emerge
1599 @section Fine Points of Emerge
1601   During the merge, you mustn't try to edit the A and B buffers yourself.
1602 Emerge modifies them temporarily, but ultimately puts them back the way
1603 they were.
1605   You can have any number of merges going at once---just don't use any one
1606 buffer as input to more than one merge at once, since the temporary
1607 changes made in these buffers would get in each other's way.
1609   Starting Emerge can take a long time because it needs to compare the
1610 files fully.  Emacs can't do anything else until @code{diff} finishes.
1611 Perhaps in the future someone will change Emerge to do the comparison in
1612 the background when the input files are large---then you could keep on
1613 doing other things with Emacs until Emerge is ready to accept
1614 commands.
1616 @vindex emerge-startup-hook
1617   After setting up the merge, Emerge runs the hook
1618 @code{emerge-startup-hook}.  @xref{Hooks,,, emacs, the Emacs Manual}.
1620 @node Picture Mode
1621 @chapter Editing Pictures
1622 @cindex pictures
1623 @cindex making pictures out of text characters
1624 @findex edit-picture
1626   To edit a picture made out of text characters (for example, a picture
1627 of the division of a register into fields, as a comment in a program),
1628 use the command @kbd{M-x edit-picture} to enter Picture mode.
1630   In Picture mode, editing is based on the @dfn{quarter-plane} model of
1631 text, according to which the text characters lie studded on an area that
1632 stretches infinitely far to the right and downward.  The concept of the end
1633 of a line does not exist in this model; the most you can say is where the
1634 last nonblank character on the line is found.
1636   Of course, Emacs really always considers text as a sequence of
1637 characters, and lines really do have ends.  But Picture mode replaces
1638 the most frequently-used commands with variants that simulate the
1639 quarter-plane model of text.  They do this by inserting spaces or by
1640 converting tabs to spaces.
1642   Most of the basic editing commands of Emacs are redefined by Picture mode
1643 to do essentially the same thing but in a quarter-plane way.  In addition,
1644 Picture mode defines various keys starting with the @kbd{C-c} prefix to
1645 run special picture editing commands.
1647   One of these keys, @kbd{C-c C-c}, is particularly important.  Often a
1648 picture is part of a larger file that is usually edited in some other
1649 major mode.  @kbd{M-x edit-picture} records the name of the previous
1650 major mode so you can use the @kbd{C-c C-c} command
1651 (@code{picture-mode-exit}) later to go back to that mode.  @kbd{C-c C-c}
1652 also deletes spaces from the ends of lines, unless given a numeric
1653 argument.
1655   The special commands of Picture mode all work in other modes (provided
1656 the @file{picture} library is loaded), but are not bound to keys except
1657 in Picture mode.  The descriptions below talk of moving ``one column''
1658 and so on, but all the picture mode commands handle numeric arguments as
1659 their normal equivalents do.
1661 @vindex picture-mode-hook
1662   Turning on Picture mode runs the hook @code{picture-mode-hook}.
1663 Additional extensions to Picture mode can be found in
1664 @file{artist.el}.
1666 @menu
1667 * Basic Picture::         Basic concepts and simple commands of Picture Mode.
1668 * Insert in Picture::     Controlling direction of cursor motion
1669                             after "self-inserting" characters.
1670 * Tabs in Picture::       Various features for tab stops and indentation.
1671 * Rectangles in Picture:: Clearing and superimposing rectangles.
1672 @end menu
1674 @node Basic Picture
1675 @section Basic Editing in Picture Mode
1677 @findex picture-forward-column
1678 @findex picture-backward-column
1679 @findex picture-move-down
1680 @findex picture-move-up
1681 @cindex editing in Picture mode
1683   Most keys do the same thing in Picture mode that they usually do, but
1684 do it in a quarter-plane style.  For example, @kbd{C-f} is rebound to
1685 run @code{picture-forward-column}, a command which moves point one
1686 column to the right, inserting a space if necessary so that the actual
1687 end of the line makes no difference.  @kbd{C-b} is rebound to run
1688 @code{picture-backward-column}, which always moves point left one
1689 column, converting a tab to multiple spaces if necessary.  @kbd{C-n} and
1690 @kbd{C-p} are rebound to run @code{picture-move-down} and
1691 @code{picture-move-up}, which can either insert spaces or convert tabs
1692 as necessary to make sure that point stays in exactly the same column.
1693 @kbd{C-e} runs @code{picture-end-of-line}, which moves to after the last
1694 nonblank character on the line.  There is no need to change @kbd{C-a},
1695 as the choice of screen model does not affect beginnings of
1696 lines.
1698 @findex picture-newline
1699   Insertion of text is adapted to the quarter-plane screen model
1700 through the use of Overwrite mode (@pxref{Minor Modes,,, emacs, the
1701 Emacs Manual}.)  Self-inserting characters replace existing text,
1702 column by column, rather than pushing existing text to the right.
1703 @key{RET} runs @code{picture-newline}, which just moves to the
1704 beginning of the following line so that new text will replace that
1705 line.
1707 @findex picture-backward-clear-column
1708 @findex picture-clear-column
1709 @findex picture-clear-line
1710   In Picture mode, the commands that normally delete or kill text,
1711 instead erase text (replacing it with spaces).  @key{DEL}
1712 (@code{picture-backward-clear-column}) replaces the preceding
1713 character with a space rather than removing it; this moves point
1714 backwards.  @kbd{C-d} (@code{picture-clear-column}) replaces the next
1715 character or characters with spaces, but does not move point.  (If you
1716 want to clear characters to spaces and move forward over them, use
1717 @key{SPC}.)  @kbd{C-k} (@code{picture-clear-line}) really kills the
1718 contents of lines, but does not delete the newlines from the buffer.
1720 @findex picture-open-line
1721   To do actual insertion, you must use special commands.  @kbd{C-o}
1722 (@code{picture-open-line}) creates a blank line after the current
1723 line; it never splits a line.  @kbd{C-M-o} (@code{split-line}) makes
1724 sense in Picture mode, so it is not changed.  @kbd{C-j}
1725 (@code{picture-duplicate-line}) inserts another line with the same
1726 contents below the current line.
1728 @kindex C-c C-d @r{(Picture mode)}
1729    To do actual deletion in Picture mode, use @kbd{C-w}, @kbd{C-c C-d}
1730 (which is defined as @code{delete-char}, as @kbd{C-d} is in other
1731 modes), or one of the picture rectangle commands (@pxref{Rectangles in
1732 Picture}).
1734 @node Insert in Picture
1735 @section Controlling Motion after Insert
1737 @findex picture-movement-up
1738 @findex picture-movement-down
1739 @findex picture-movement-left
1740 @findex picture-movement-right
1741 @findex picture-movement-nw
1742 @findex picture-movement-ne
1743 @findex picture-movement-sw
1744 @findex picture-movement-se
1745 @kindex C-c < @r{(Picture mode)}
1746 @kindex C-c > @r{(Picture mode)}
1747 @kindex C-c ^ @r{(Picture mode)}
1748 @kindex C-c . @r{(Picture mode)}
1749 @kindex C-c ` @r{(Picture mode)}
1750 @kindex C-c ' @r{(Picture mode)}
1751 @kindex C-c / @r{(Picture mode)}
1752 @kindex C-c \ @r{(Picture mode)}
1753   Since ``self-inserting'' characters in Picture mode overwrite and move
1754 point, there is no essential restriction on how point should be moved.
1755 Normally point moves right, but you can specify any of the eight
1756 orthogonal or diagonal directions for motion after a ``self-inserting''
1757 character.  This is useful for drawing lines in the buffer.
1759 @table @kbd
1760 @item C-c <
1761 @itemx C-c @key{LEFT}
1762 Move left after insertion (@code{picture-movement-left}).
1763 @item C-c >
1764 @itemx C-c @key{RIGHT}
1765 Move right after insertion (@code{picture-movement-right}).
1766 @item C-c ^
1767 @itemx C-c @key{UP}
1768 Move up after insertion (@code{picture-movement-up}).
1769 @item C-c .
1770 @itemx C-c @key{DOWN}
1771 Move down after insertion (@code{picture-movement-down}).
1772 @item C-c `
1773 @itemx C-c @key{HOME}
1774 Move up and left (``northwest'') after insertion (@code{picture-movement-nw}).
1775 @item C-c '
1776 @itemx C-c @key{PAGEUP}
1777 Move up and right (``northeast'') after insertion
1778 (@code{picture-movement-ne}).
1779 @item C-c /
1780 @itemx C-c @key{END}
1781 Move down and left (``southwest'') after insertion
1782 @*(@code{picture-movement-sw}).
1783 @item C-c \
1784 @itemx C-c @key{PAGEDOWN}
1785 Move down and right (``southeast'') after insertion
1786 @*(@code{picture-movement-se}).
1787 @end table
1789 @kindex C-c C-f @r{(Picture mode)}
1790 @kindex C-c C-b @r{(Picture mode)}
1791 @findex picture-motion
1792 @findex picture-motion-reverse
1793   Two motion commands move based on the current Picture insertion
1794 direction.  The command @kbd{C-c C-f} (@code{picture-motion}) moves in the
1795 same direction as motion after ``insertion'' currently does, while @kbd{C-c
1796 C-b} (@code{picture-motion-reverse}) moves in the opposite direction.
1798 @node Tabs in Picture
1799 @section Picture Mode Tabs
1801 @kindex M-TAB @r{(Picture mode)}
1802 @findex picture-tab-search
1803 @vindex picture-tab-chars
1804   Two kinds of tab-like action are provided in Picture mode.  Use
1805 @kbd{M-@key{TAB}} (@code{picture-tab-search}) for context-based tabbing.
1806 With no argument, it moves to a point underneath the next
1807 ``interesting'' character that follows whitespace in the previous
1808 nonblank line.  ``Next'' here means ``appearing at a horizontal position
1809 greater than the one point starts out at.''  With an argument, as in
1810 @kbd{C-u M-@key{TAB}}, this command moves to the next such interesting
1811 character in the current line.  @kbd{M-@key{TAB}} does not change the
1812 text; it only moves point.  ``Interesting'' characters are defined by
1813 the variable @code{picture-tab-chars}, which should define a set of
1814 characters.  The syntax for this variable is like the syntax used inside
1815 of @samp{[@dots{}]} in a regular expression---but without the @samp{[}
1816 and the @samp{]}.  Its default value is @code{"!-~"}.
1818 @findex picture-tab
1819   @key{TAB} itself runs @code{picture-tab}, which operates based on the
1820 current tab stop settings; it is the Picture mode equivalent of
1821 @code{tab-to-tab-stop}.  Normally it just moves point, but with a numeric
1822 argument it clears the text that it moves over.
1824 @kindex C-c TAB @r{(Picture mode)}
1825 @findex picture-set-tab-stops
1826   The context-based and tab-stop-based forms of tabbing are brought
1827 together by the command @kbd{C-c @key{TAB}} (@code{picture-set-tab-stops}).
1828 This command sets the tab stops to the positions which @kbd{M-@key{TAB}}
1829 would consider significant in the current line.  The use of this command,
1830 together with @key{TAB}, can get the effect of context-based tabbing.  But
1831 @kbd{M-@key{TAB}} is more convenient in the cases where it is sufficient.
1833   It may be convenient to prevent use of actual tab characters in
1834 pictures.  For example, this prevents @kbd{C-x @key{TAB}} from messing
1835 up the picture.  You can do this by setting the variable
1836 @code{indent-tabs-mode} to @code{nil}.
1838 @node Rectangles in Picture
1839 @section Picture Mode Rectangle Commands
1840 @cindex rectangles and Picture mode
1841 @cindex Picture mode and rectangles
1843   Picture mode defines commands for working on rectangular pieces of
1844 the text in ways that fit with the quarter-plane model.  The standard
1845 rectangle commands may also be useful.  @xref{Rectangles,,, emacs, the
1846 Emacs Manual}.
1848 @table @kbd
1849 @item C-c C-k
1850 Clear out the region-rectangle with spaces
1851 (@code{picture-clear-rectangle}).  With argument, delete the text.
1852 @item C-c C-w @var{r}
1853 Similar, but save rectangle contents in register @var{r} first
1854 (@code{picture-clear-rectangle-to-register}).
1855 @item C-c C-y
1856 Copy last killed rectangle into the buffer by overwriting, with upper
1857 left corner at point (@code{picture-yank-rectangle}).  With argument,
1858 insert instead.
1859 @item C-c C-x @var{r}
1860 Similar, but use the rectangle in register @var{r}
1861 (@code{picture-yank-rectangle-from-register}).
1862 @end table
1864 @kindex C-c C-k @r{(Picture mode)}
1865 @kindex C-c C-w @r{(Picture mode)}
1866 @findex picture-clear-rectangle
1867 @findex picture-clear-rectangle-to-register
1868   The picture rectangle commands @kbd{C-c C-k}
1869 (@code{picture-clear-rectangle}) and @kbd{C-c C-w}
1870 (@code{picture-clear-rectangle-to-register}) differ from the standard
1871 rectangle commands in that they normally clear the rectangle instead of
1872 deleting it; this is analogous with the way @kbd{C-d} is changed in Picture
1873 mode.
1875   However, deletion of rectangles can be useful in Picture mode, so
1876 these commands delete the rectangle if given a numeric argument.
1877 @kbd{C-c C-k} either with or without a numeric argument saves the
1878 rectangle for @kbd{C-c C-y}.
1880 @kindex C-c C-y @r{(Picture mode)}
1881 @kindex C-c C-x @r{(Picture mode)}
1882 @findex picture-yank-rectangle
1883 @findex picture-yank-rectangle-from-register
1884   The Picture mode commands for yanking rectangles differ from the
1885 standard ones in that they overwrite instead of inserting.  This is
1886 the same way that Picture mode insertion of other text differs from
1887 other modes.  @kbd{C-c C-y} (@code{picture-yank-rectangle}) inserts
1888 (by overwriting) the rectangle that was most recently killed, while
1889 @kbd{C-c C-x} (@code{picture-yank-rectangle-from-register}) does
1890 likewise for the rectangle found in a specified register.
1892 @node Fortran
1893 @chapter Fortran Mode
1894 @cindex Fortran mode
1895 @cindex mode, Fortran
1897   Fortran mode provides special motion commands for Fortran statements
1898 and subprograms, and indentation commands that understand Fortran
1899 conventions of nesting, line numbers and continuation statements.
1900 Fortran mode has support for Auto Fill mode that breaks long lines into
1901 proper Fortran continuation lines.
1903   Special commands for comments are provided because Fortran comments
1904 are unlike those of other languages.  Built-in abbrevs optionally save
1905 typing when you insert Fortran keywords.
1907   Use @kbd{M-x fortran-mode} to switch to this major mode.  This
1908 command runs the hook @code{fortran-mode-hook}.  @xref{Hooks,,, emacs,
1909 the Emacs Manual}.
1911 @cindex Fortran77 and Fortran90
1912 @findex f90-mode
1913 @findex fortran-mode
1914   Fortran mode is meant for editing Fortran77 ``fixed format'' (and also
1915 ``tab format'') source code.  For editing the modern Fortran90 or
1916 Fortran95 ``free format'' source code, use F90 mode (@code{f90-mode}).
1917 Emacs normally uses Fortran mode for files with extension @samp{.f},
1918 @samp{.F} or @samp{.for}, and F90 mode for the extension @samp{.f90} and
1919 @samp{.f95}.  GNU Fortran supports both kinds of format.
1921 @menu
1922 * Motion: Fortran Motion.        Moving point by statements or subprograms.
1923 * Indent: Fortran Indent.        Indentation commands for Fortran.
1924 * Comments: Fortran Comments.    Inserting and aligning comments.
1925 * Autofill: Fortran Autofill.    Auto fill support for Fortran.
1926 * Columns: Fortran Columns.      Measuring columns for valid Fortran.
1927 * Abbrev: Fortran Abbrev.        Built-in abbrevs for Fortran keywords.
1928 @end menu
1930 @node Fortran Motion
1931 @section Motion Commands
1933   In addition to the normal commands for moving by and operating on
1934 ``defuns'' (Fortran subprograms---functions and subroutines, as well as
1935 modules for F90 mode), Fortran mode provides special commands to move by
1936 statements and other program units.
1938 @table @kbd
1939 @kindex C-c C-n @r{(Fortran mode)}
1940 @findex fortran-next-statement
1941 @findex f90-next-statement
1942 @item C-c C-n
1943 Move to the beginning of the next statement
1944 (@code{fortran-next-statement}/@code{f90-next-statement}).
1946 @kindex C-c C-p @r{(Fortran mode)}
1947 @findex fortran-previous-statement
1948 @findex f90-previous-statement
1949 @item C-c C-p
1950 Move to the beginning of the previous statement
1951 (@code{fortran-previous-statement}/@code{f90-previous-statement}).
1952 If there is no previous statement (i.e. if called from the first
1953 statement in the buffer), move to the start of the buffer.
1955 @kindex C-c C-e @r{(F90 mode)}
1956 @findex f90-next-block
1957 @item C-c C-e
1958 Move point forward to the start of the next code block
1959 (@code{f90-next-block}).  A code block is a subroutine,
1960 @code{if}--@code{endif} statement, and so forth.  This command exists
1961 for F90 mode only, not Fortran mode.  With a numeric argument, this
1962 moves forward that many blocks.
1964 @kindex C-c C-a @r{(F90 mode)}
1965 @findex f90-previous-block
1966 @item C-c C-a
1967 Move point backward to the previous code block
1968 (@code{f90-previous-block}).  This is like @code{f90-next-block}, but
1969 moves backwards.
1971 @kindex C-M-n @r{(Fortran mode)}
1972 @findex fortran-end-of-block
1973 @findex f90-end-of-block
1974 @item C-M-n
1975 Move to the end of the current code block
1976 (@code{fortran-end-of-block}/@code{f90-end-of-block}).  With a numeric
1977 agument, move forward that number of blocks.  The mark is set before
1978 moving point.  The F90 mode version of this command checks for
1979 consistency of block types and labels (if present), but it does not
1980 check the outermost block since that may be incomplete.
1982 @kindex C-M-p @r{(Fortran mode)}
1983 @findex fortran-beginning-of-block
1984 @findex f90-beginning-of-block
1985 @item C-M-p
1986 Move to the start of the current code block
1987 (@code{fortran-beginning-of-block}/@code{f90-beginning-of-block}). This
1988 is like @code{fortran-end-of-block}, but moves backwards.
1989 @end table
1991 @node Fortran Indent
1992 @section Fortran Indentation
1994   Special commands and features are needed for indenting Fortran code in
1995 order to make sure various syntactic entities (line numbers, comment line
1996 indicators and continuation line flags) appear in the columns that are
1997 required for standard, fixed (or tab) format Fortran.
1999 @menu
2000 * Commands: ForIndent Commands.  Commands for indenting and filling Fortran.
2001 * Contline: ForIndent Cont.      How continuation lines indent.
2002 * Numbers:  ForIndent Num.       How line numbers auto-indent.
2003 * Conv:     ForIndent Conv.      Conventions you must obey to avoid trouble.
2004 * Vars:     ForIndent Vars.      Variables controlling Fortran indent style.
2005 @end menu
2007 @node ForIndent Commands
2008 @subsection Fortran Indentation and Filling Commands
2010 @table @kbd
2011 @item C-M-j
2012 Break the current line at point and set up a continuation line
2013 (@code{fortran-split-line}).
2014 @item M-^
2015 Join this line to the previous line (@code{fortran-join-line}).
2016 @item C-M-q
2017 Indent all the lines of the subprogram point is in
2018 (@code{fortran-indent-subprogram}).
2019 @item M-q
2020 Fill a comment block or statement.
2021 @end table
2023 @kindex C-M-q @r{(Fortran mode)}
2024 @findex fortran-indent-subprogram
2025   The key @kbd{C-M-q} runs @code{fortran-indent-subprogram}, a command
2026 to reindent all the lines of the Fortran subprogram (function or
2027 subroutine) containing point.
2029 @kindex C-M-j @r{(Fortran mode)}
2030 @findex fortran-split-line
2031   The key @kbd{C-M-j} runs @code{fortran-split-line}, which splits
2032 a line in the appropriate fashion for Fortran.  In a non-comment line,
2033 the second half becomes a continuation line and is indented
2034 accordingly.  In a comment line, both halves become separate comment
2035 lines.
2037 @kindex M-^ @r{(Fortran mode)}
2038 @kindex C-c C-d @r{(Fortran mode)}
2039 @findex fortran-join-line
2040   @kbd{M-^} or @kbd{C-c C-d} runs the command @code{fortran-join-line},
2041 which joins a continuation line back to the previous line, roughly as
2042 the inverse of @code{fortran-split-line}.  The point must be on a
2043 continuation line when this command is invoked.
2045 @kindex M-q @r{(Fortran mode)}
2046 @kbd{M-q} in Fortran mode fills the comment block or statement that
2047 point is in.  This removes any excess statement continuations.
2049 @node ForIndent Cont
2050 @subsection Continuation Lines
2051 @cindex Fortran continuation lines
2053 @vindex fortran-continuation-string
2054   Most Fortran77 compilers allow two ways of writing continuation lines.
2055 If the first non-space character on a line is in column 5, then that
2056 line is a continuation of the previous line.  We call this @dfn{fixed
2057 format}.  (In GNU Emacs we always count columns from 0; but note that
2058 the Fortran standard counts from 1.)  The variable
2059 @code{fortran-continuation-string} specifies what character to put in
2060 column 5.  A line that starts with a tab character followed by any digit
2061 except @samp{0} is also a continuation line.  We call this style of
2062 continuation @dfn{tab format}.  (Fortran90 introduced ``free format'',
2063 with another style of continuation lines).
2065 @vindex indent-tabs-mode @r{(Fortran mode)}
2066 @vindex fortran-analyze-depth
2067 @vindex fortran-tab-mode-default
2068   Fortran mode can use either style of continuation line.  When you
2069 enter Fortran mode, it tries to deduce the proper continuation style
2070 automatically from the buffer contents.  It does this by scanning up to
2071 @code{fortran-analyze-depth} (default 100) lines from the start of the
2072 buffer.  The first line that begins with either a tab character or six
2073 spaces determines the choice.  If the scan fails (for example, if the
2074 buffer is new and therefore empty), the value of
2075 @code{fortran-tab-mode-default} (@code{nil} for fixed format, and
2076 non-@code{nil} for tab format) is used.  @samp{/t} in the mode line
2077 indicates tab format is selected.  Fortran mode sets the value of
2078 @code{indent-tabs-mode} accordingly.
2080   If the text on a line starts with the Fortran continuation marker
2081 @samp{$}, or if it begins with any non-whitespace character in column
2082 5, Fortran mode treats it as a continuation line.  When you indent a
2083 continuation line with @key{TAB}, it converts the line to the current
2084 continuation style.  When you split a Fortran statement with
2085 @kbd{C-M-j}, the continuation marker on the newline is created according
2086 to the continuation style.
2088   The setting of continuation style affects several other aspects of
2089 editing in Fortran mode.  In fixed format mode, the minimum column
2090 number for the body of a statement is 6.  Lines inside of Fortran
2091 blocks that are indented to larger column numbers always use only the
2092 space character for whitespace.  In tab format mode, the minimum
2093 column number for the statement body is 8, and the whitespace before
2094 column 8 must always consist of one tab character.
2096 @node ForIndent Num
2097 @subsection Line Numbers
2099   If a number is the first non-whitespace in the line, Fortran
2100 indentation assumes it is a line number and moves it to columns 0
2101 through 4.  (Columns always count from 0 in GNU Emacs.)
2103 @vindex fortran-line-number-indent
2104   Line numbers of four digits or less are normally indented one space.
2105 The variable @code{fortran-line-number-indent} controls this; it
2106 specifies the maximum indentation a line number can have.  The default
2107 value of the variable is 1.  Fortran mode tries to prevent line number
2108 digits passing column 4, reducing the indentation below the specified
2109 maximum if necessary.  If @code{fortran-line-number-indent} has the
2110 value 5, line numbers are right-justified to end in column 4.
2112 @vindex fortran-electric-line-number
2113   Simply inserting a line number is enough to indent it according to
2114 these rules.  As each digit is inserted, the indentation is recomputed.
2115 To turn off this feature, set the variable
2116 @code{fortran-electric-line-number} to @code{nil}.
2119 @node ForIndent Conv
2120 @subsection Syntactic Conventions
2122   Fortran mode assumes that you follow certain conventions that simplify
2123 the task of understanding a Fortran program well enough to indent it
2124 properly:
2126 @itemize @bullet
2127 @item
2128 Two nested @samp{do} loops never share a @samp{continue} statement.
2130 @item
2131 Fortran keywords such as @samp{if}, @samp{else}, @samp{then}, @samp{do}
2132 and others are written without embedded whitespace or line breaks.
2134 Fortran compilers generally ignore whitespace outside of string
2135 constants, but Fortran mode does not recognize these keywords if they
2136 are not contiguous.  Constructs such as @samp{else if} or @samp{end do}
2137 are acceptable, but the second word should be on the same line as the
2138 first and not on a continuation line.
2139 @end itemize
2141 @noindent
2142 If you fail to follow these conventions, the indentation commands may
2143 indent some lines unaesthetically.  However, a correct Fortran program
2144 retains its meaning when reindented even if the conventions are not
2145 followed.
2147 @node ForIndent Vars
2148 @subsection Variables for Fortran Indentation
2150 @vindex fortran-do-indent
2151 @vindex fortran-if-indent
2152 @vindex fortran-structure-indent
2153 @vindex fortran-continuation-indent
2154 @vindex fortran-check-all-num@dots{}
2155 @vindex fortran-minimum-statement-indent@dots{}
2156   Several additional variables control how Fortran indentation works:
2158 @table @code
2159 @item fortran-do-indent
2160 Extra indentation within each level of @samp{do} statement (default 3).
2162 @item fortran-if-indent
2163 Extra indentation within each level of @samp{if}, @samp{select case}, or
2164 @samp{where} statements (default 3).
2166 @item fortran-structure-indent
2167 Extra indentation within each level of @samp{structure}, @samp{union},
2168 @samp{map}, or @samp{interface} statements (default 3).
2170 @item fortran-continuation-indent
2171 Extra indentation for bodies of continuation lines (default 5).
2173 @item fortran-check-all-num-for-matching-do
2174 In Fortran77, a numbered @samp{do} statement is ended by any statement
2175 with a matching line number.  It is common (but not compulsory) to use a
2176 @samp{continue} statement for this purpose.  If this variable has a
2177 non-@code{nil} value, indenting any numbered statement must check for a
2178 @samp{do} that ends there.  If you always end @samp{do} statements with
2179 a @samp{continue} line (or if you use the more modern @samp{enddo}),
2180 then you can speed up indentation by setting this variable to
2181 @code{nil}.  The default is @code{nil}.
2183 @item fortran-blink-matching-if
2184 If this is @code{t}, indenting an @samp{endif} (or @samp{enddo}
2185 statement moves the cursor momentarily to the matching @samp{if} (or
2186 @samp{do}) statement to show where it is.  The default is @code{nil}.
2188 @item fortran-minimum-statement-indent-fixed
2189 Minimum indentation for Fortran statements when using fixed format
2190 continuation line style.  Statement bodies are never indented less than
2191 this much.  The default is 6.
2193 @item fortran-minimum-statement-indent-tab
2194 Minimum indentation for Fortran statements for tab format continuation line
2195 style.  Statement bodies are never indented less than this much.  The
2196 default is 8.
2197 @end table
2199 The variables controlling the indentation of comments are described in
2200 the following section.
2202 @node Fortran Comments
2203 @section Fortran Comments
2205   The usual Emacs comment commands assume that a comment can follow a
2206 line of code.  In Fortran77, the standard comment syntax requires an
2207 entire line to be just a comment.  Therefore, Fortran mode replaces the
2208 standard Emacs comment commands and defines some new variables.
2210 @vindex fortran-comment-line-start
2211   Fortran mode can also handle the Fortran90 comment syntax where comments
2212 start with @samp{!} and can follow other text.  Because only some Fortran77
2213 compilers accept this syntax, Fortran mode will not insert such comments
2214 unless you have said in advance to do so.  To do this, set the variable
2215 @code{fortran-comment-line-start} to @samp{"!"}.
2217 @table @kbd
2218 @item M-;
2219 Align comment or insert new comment (@code{fortran-indent-comment}).
2221 @item C-x ;
2222 Applies to nonstandard @samp{!} comments only.
2224 @item C-c ;
2225 Turn all lines of the region into comments, or (with argument) turn them back
2226 into real code (@code{fortran-comment-region}).
2227 @end table
2229 @findex fortran-indent-comment
2230   @kbd{M-;} in Fortran mode is redefined as the command
2231 @code{fortran-indent-comment}.  Like the usual @kbd{M-;} command, this
2232 recognizes any kind of existing comment and aligns its text appropriately;
2233 if there is no existing comment, a comment is inserted and aligned.  But
2234 inserting and aligning comments are not the same in Fortran mode as in
2235 other modes.
2237   When a new comment must be inserted, if the current line is blank, a
2238 full-line comment is inserted.  On a non-blank line, a nonstandard @samp{!}
2239 comment is inserted if you have said you want to use them.  Otherwise a
2240 full-line comment is inserted on a new line before the current line.
2242   Nonstandard @samp{!} comments are aligned like comments in other
2243 languages, but full-line comments are different.  In a standard full-line
2244 comment, the comment delimiter itself must always appear in column zero.
2245 What can be aligned is the text within the comment.  You can choose from
2246 three styles of alignment by setting the variable
2247 @code{fortran-comment-indent-style} to one of these values:
2249 @vindex fortran-comment-indent-style
2250 @vindex fortran-comment-line-extra-indent
2251 @table @code
2252 @item fixed
2253 Align the text at a fixed column, which is the sum of
2254 @code{fortran-comment-line-extra-indent} and the minimum statement
2255 indentation.  This is the default.
2257 The minimum statement indentation is
2258 @code{fortran-minimum-statement-indent-fixed} for fixed format
2259 continuation line style and @code{fortran-minimum-statement-indent-tab}
2260 for tab format style.
2262 @item relative
2263 Align the text as if it were a line of code, but with an additional
2264 @code{fortran-comment-line-extra-indent} columns of indentation.
2266 @item nil
2267 Don't move text in full-line comments automatically.
2268 @end table
2270 @vindex fortran-comment-indent-char
2271   In addition, you can specify the character to be used to indent within
2272 full-line comments by setting the variable
2273 @code{fortran-comment-indent-char} to the single-character string you want
2274 to use.
2276 @vindex fortran-directive-re
2277   Compiler directive lines, or preprocessor lines, have much the same
2278 appearance as comment lines.  It is important, though, that such lines
2279 never be indented at all, no matter what the value of
2280 @code{fortran-comment-indent-style}.  The variable
2281 @code{fortran-directive-re} is a regular expression that specifies which
2282 lines are directives.  Matching lines are never indented, and receive
2283 distinctive font-locking.
2285   The normal Emacs comment command @kbd{C-x ;} has not been redefined.  If
2286 you use @samp{!} comments, this command can be used with them.  Otherwise
2287 it is useless in Fortran mode.
2289 @kindex C-c ; @r{(Fortran mode)}
2290 @findex fortran-comment-region
2291 @vindex fortran-comment-region
2292   The command @kbd{C-c ;} (@code{fortran-comment-region}) turns all the
2293 lines of the region into comments by inserting the string @samp{C$$$} at
2294 the front of each one.  With a numeric argument, it turns the region
2295 back into live code by deleting @samp{C$$$} from the front of each line
2296 in it.  The string used for these comments can be controlled by setting
2297 the variable @code{fortran-comment-region}.  Note that here we have an
2298 example of a command and a variable with the same name; these two uses
2299 of the name never conflict because in Lisp and in Emacs it is always
2300 clear from the context which one is meant.
2302 @node Fortran Autofill
2303 @section Auto Fill in Fortran Mode
2305   Fortran mode has specialized support for Auto Fill mode, which is a
2306 minor mode that automatically splits statements as you insert them
2307 when they become too wide.  Splitting a statement involves making
2308 continuation lines using @code{fortran-continuation-string}
2309 (@pxref{ForIndent Cont}).  This splitting happens when you type
2310 @key{SPC}, @key{RET}, or @key{TAB}, and also in the Fortran
2311 indentation commands.  You activate Auto Fill in Fortran mode in the
2312 normal way.  @xref{Auto Fill,,, emacs, the Emacs Manual}.
2314 @vindex fortran-break-before-delimiters
2315    Auto Fill breaks lines at spaces or delimiters when the lines get
2316 longer than the desired width (the value of @code{fill-column}).  The
2317 delimiters (besides whitespace) that Auto Fill can break at are
2318 @samp{+}, @samp{-}, @samp{/}, @samp{*}, @samp{=}, @samp{<}, @samp{>},
2319 and @samp{,}.  The line break comes after the delimiter if the
2320 variable @code{fortran-break-before-delimiters} is @code{nil}.
2321 Otherwise (and by default), the break comes before the delimiter.
2323   To enable Auto Fill in all Fortran buffers, add
2324 @code{turn-on-auto-fill} to @code{fortran-mode-hook}.  @xref{Hooks,,,
2325 emacs, the Emacs Manual}.
2327 @node Fortran Columns
2328 @section Checking Columns in Fortran
2330 @table @kbd
2331 @item C-c C-r
2332 Display a ``column ruler'' momentarily above the current line
2333 (@code{fortran-column-ruler}).
2334 @item C-c C-w
2335 Split the current window horizontally temporarily so that it is 72
2336 columns wide (@code{fortran-window-create-momentarily}).  This may
2337 help you avoid making lines longer than the 72-character limit that
2338 some Fortran compilers impose.
2339 @item C-u C-c C-w
2340 Split the current window horizontally so that it is 72 columns wide
2341 (@code{fortran-window-create}).  You can then continue editing.
2342 @item M-x fortran-strip-sequence-nos
2343 Delete all text in column 72 and beyond.
2344 @end table
2346 @kindex C-c C-r @r{(Fortran mode)}
2347 @findex fortran-column-ruler
2348   The command @kbd{C-c C-r} (@code{fortran-column-ruler}) shows a column
2349 ruler momentarily above the current line.  The comment ruler is two lines
2350 of text that show you the locations of columns with special significance in
2351 Fortran programs.  Square brackets show the limits of the columns for line
2352 numbers, and curly brackets show the limits of the columns for the
2353 statement body.  Column numbers appear above them.
2355   Note that the column numbers count from zero, as always in GNU Emacs.
2356 As a result, the numbers may be one less than those you are familiar
2357 with; but the positions they indicate in the line are standard for
2358 Fortran.
2360 @vindex fortran-column-ruler-fixed
2361 @vindex fortran-column-ruler-tabs
2362   The text used to display the column ruler depends on the value of the
2363 variable @code{indent-tabs-mode}.  If @code{indent-tabs-mode} is
2364 @code{nil}, then the value of the variable
2365 @code{fortran-column-ruler-fixed} is used as the column ruler.
2366 Otherwise, the value of the variable @code{fortran-column-ruler-tab} is
2367 displayed.  By changing these variables, you can change the column ruler
2368 display.
2370 @kindex C-c C-w @r{(Fortran mode)}
2371 @findex fortran-window-create-momentarily
2372   @kbd{C-c C-w} (@code{fortran-window-create-momentarily}) temporarily
2373 splits the current window horizontally, making a window 72 columns
2374 wide, so you can see any lines that are too long.  Type a space to
2375 restore the normal width.
2377 @kindex C-u C-c C-w @r{(Fortran mode)}
2378 @findex fortran-window-create
2379   You can also split the window horizontally and continue editing with
2380 the split in place.  To do this, use @kbd{C-u C-c C-w} (@code{M-x
2381 fortran-window-create}).  By editing in this window you can
2382 immediately see when you make a line too wide to be correct Fortran.
2384 @findex fortran-strip-sequence-nos
2385   The command @kbd{M-x fortran-strip-sequence-nos} deletes all text in
2386 column 72 and beyond, on all lines in the current buffer.  This is the
2387 easiest way to get rid of old sequence numbers.
2389 @node Fortran Abbrev
2390 @section Fortran Keyword Abbrevs
2392   Fortran mode provides many built-in abbrevs for common keywords and
2393 declarations.  These are the same sort of abbrev that you can define
2394 yourself.  To use them, you must turn on Abbrev mode.
2395 @xref{Abbrevs,,, emacs, the Emacs Manual}.
2397   The built-in abbrevs are unusual in one way: they all start with a
2398 semicolon.  You cannot normally use semicolon in an abbrev, but Fortran
2399 mode makes this possible by changing the syntax of semicolon to ``word
2400 constituent.''
2402   For example, one built-in Fortran abbrev is @samp{;c} for
2403 @samp{continue}.  If you insert @samp{;c} and then insert a punctuation
2404 character such as a space or a newline, the @samp{;c} expands automatically
2405 to @samp{continue}, provided Abbrev mode is enabled.@refill
2407   Type @samp{;?} or @samp{;C-h} to display a list of all the built-in
2408 Fortran abbrevs and what they stand for.
2411 @node MS-DOG
2412 @chapter Emacs and MS-DOS
2413 @cindex MS-DOG
2414 @cindex MS-DOS peculiarities
2416   This section briefly describes the peculiarities of using Emacs on
2417 the MS-DOS ``operating system'' (also known as ``MS-DOG'').
2418 Information about Emacs and Microsoft's current operating system
2419 Windows (also known as ``Losedows) is in the main Emacs manual
2420 (@pxref{Emacs and Microsoft Systems,,, emacs, the Emacs Manual}).
2422   If you build Emacs for MS-DOS, the binary will also run on Windows
2423 3.X, Windows NT, Windows 9X/ME, Windows 2000, or OS/2 as a DOS
2424 application; all of this chapter applies for all of those systems, if
2425 you use an Emacs that was built for MS-DOS.
2427   @xref{Text and Binary,,,emacs, the Emacs Manual}, for information
2428 about Emacs' special handling of text files under MS-DOS (and
2429 Windows).
2431 @menu
2432 * Keyboard: MS-DOS Keyboard.   Keyboard conventions on MS-DOS.
2433 * Mouse: MS-DOS Mouse.         Mouse conventions on MS-DOS.
2434 * Display: MS-DOS Display.     Fonts, frames and display size on MS-DOS.
2435 * Files: MS-DOS File Names.    File name conventions on MS-DOS.
2436 * Printing: MS-DOS Printing.   How to specify the printer on MS-DOS.
2437 * I18N: MS-DOS and MULE.       Support for internationalization on MS-DOS.
2438 * Processes: MS-DOS Processes. Running subprocesses on MS-DOS.
2439 @end menu
2441 @node MS-DOS Keyboard
2442 @section Keyboard Usage on MS-DOS
2444 @kindex DEL @r{(MS-DOS)}
2445 @kindex BS @r{(MS-DOS)}
2446   The key that is called @key{DEL} in Emacs (because that's how it is
2447 designated on most workstations) is known as @key{BS} (backspace) on a
2448 PC.  That is why the PC-specific terminal initialization remaps the
2449 @key{BS} key to act as @key{DEL}; the @key{DELETE} key is remapped to act
2450 as @kbd{C-d} for the same reasons.
2452 @kindex C-g @r{(MS-DOS)}
2453 @kindex C-BREAK @r{(MS-DOS)}
2454 @cindex quitting on MS-DOS
2455   Emacs built for MS-DOS recognizes @kbd{C-@key{BREAK}} as a quit
2456 character, just like @kbd{C-g}.  This is because Emacs cannot detect
2457 that you have typed @kbd{C-g} until it is ready for more input.  As a
2458 consequence, you cannot use @kbd{C-g} to stop a running command
2459 (@pxref{Quitting,,,emacs, the Emacs Manual}).  By contrast,
2460 @kbd{C-@key{BREAK}} @emph{is} detected as soon as you type it (as
2461 @kbd{C-g} is on other systems), so it can be used to stop a running
2462 command and for emergency escape (@pxref{Emergency Escape,,,emacs, the
2463 Emacs Manual}).
2465 @cindex Meta (under MS-DOS)
2466 @cindex Hyper (under MS-DOS)
2467 @cindex Super (under MS-DOS)
2468 @vindex dos-super-key
2469 @vindex dos-hyper-key
2470   The PC keyboard maps use the left @key{ALT} key as the @key{META} key.
2471 You have two choices for emulating the @key{SUPER} and @key{HYPER} keys:
2472 choose either the right @key{CTRL} key or the right @key{ALT} key by
2473 setting the variables @code{dos-hyper-key} and @code{dos-super-key} to 1
2474 or 2 respectively.  If neither @code{dos-super-key} nor
2475 @code{dos-hyper-key} is 1, then by default the right @key{ALT} key is
2476 also mapped to the @key{META} key.  However, if the MS-DOS international
2477 keyboard support program @file{KEYB.COM} is installed, Emacs will
2478 @emph{not} map the right @key{ALT} to @key{META}, since it is used for
2479 accessing characters like @kbd{~} and @kbd{@@} on non-US keyboard
2480 layouts; in this case, you may only use the left @key{ALT} as @key{META}
2481 key.
2483 @kindex C-j @r{(MS-DOS)}
2484 @vindex dos-keypad-mode
2485   The variable @code{dos-keypad-mode} is a flag variable that controls
2486 what key codes are returned by keys in the numeric keypad.  You can also
2487 define the keypad @key{ENTER} key to act like @kbd{C-j}, by putting the
2488 following line into your @file{_emacs} file:
2490 @smallexample
2491 ;; @r{Make the @key{ENTER} key from the numeric keypad act as @kbd{C-j}.}
2492 (define-key function-key-map [kp-enter] [?\C-j])
2493 @end smallexample
2495 @node MS-DOS Mouse
2496 @section Mouse Usage on MS-DOS
2498 @cindex mouse support under MS-DOS
2499   Emacs on MS-DOS supports a mouse (on the default terminal only).
2500 The mouse commands work as documented, including those that use menus
2501 and the menu bar (@pxref{Menu Bar,,,emacs, the Emacs Manual}).  Scroll
2502 bars don't work in MS-DOS Emacs.  PC mice usually have only two
2503 buttons; these act as @kbd{Mouse-1} and @kbd{Mouse-2}, but if you
2504 press both of them together, that has the effect of @kbd{Mouse-3}.  If
2505 the mouse does have 3 buttons, Emacs detects that at startup, and all
2506 the 3 buttons function normally, as on X.
2508   Help strings for menu-bar and pop-up menus are displayed in the echo
2509 area when the mouse pointer moves across the menu items.  Highlighting
2510 of mouse-sensitive text (@pxref{Mouse References,,,emacs, the Emacs
2511 Manual}) is also supported.
2513 @cindex mouse, set number of buttons
2514 @findex msdos-set-mouse-buttons
2515   Some versions of mouse drivers don't report the number of mouse
2516 buttons correctly.  For example, mice with a wheel report that they
2517 have 3 buttons, but only 2 of them are passed to Emacs; the clicks on
2518 the wheel, which serves as the middle button, are not passed.  In
2519 these cases, you can use the @kbd{M-x msdos-set-mouse-buttons} command
2520 to tell Emacs how many mouse buttons to expect.  You could make such a
2521 setting permanent by adding this fragment to your @file{_emacs} init
2522 file:
2524 @example
2525 ;; @r{Treat the mouse like a 2-button mouse.}
2526 (msdos-set-mouse-buttons 2)
2527 @end example
2529 @cindex Windows clipboard support
2530   Emacs built for MS-DOS supports clipboard operations when it runs on
2531 Windows.  Commands that put text on the kill ring, or yank text from
2532 the ring, check the Windows clipboard first, just as Emacs does on the
2533 X Window System (@pxref{Mouse Commands,,,emacs, the Emacs Manual}).
2534 Only the primary selection and the cut buffer are supported by MS-DOS
2535 Emacs on Windows; the secondary selection always appears as empty.
2537   Due to the way clipboard access is implemented by Windows, the
2538 length of text you can put into the clipboard is limited by the amount
2539 of free DOS memory that is available to Emacs.  Usually, up to 620KB of
2540 text can be put into the clipboard, but this limit depends on the system
2541 configuration and is lower if you run Emacs as a subprocess of
2542 another program.  If the killed text does not fit, Emacs outputs a
2543 message saying so, and does not put the text into the clipboard.
2545   Null characters also cannot be put into the Windows clipboard.  If the
2546 killed text includes null characters, Emacs does not put such text into
2547 the clipboard, and displays in the echo area a message to that effect.
2549 @vindex dos-display-scancodes
2550   The variable @code{dos-display-scancodes}, when non-@code{nil},
2551 directs Emacs to display the @acronym{ASCII} value and the keyboard scan code of
2552 each keystroke; this feature serves as a complement to the
2553 @code{view-lossage} command, for debugging.
2555 @node MS-DOS Display
2556 @section Display on MS-DOS
2557 @cindex faces under MS-DOS
2558 @cindex fonts, emulating under MS-DOS
2560   Display on MS-DOS cannot use font variants, like bold or italic, but
2561 it does support multiple faces, each of which can specify a foreground
2562 and a background color.  Therefore, you can get the full functionality
2563 of Emacs packages that use fonts (such as @code{font-lock}, Enriched
2564 Text mode, and others) by defining the relevant faces to use different
2565 colors.  Use the @code{list-colors-display} command (@pxref{Frame
2566 Parameters,,,emacs, the Emacs Manual}) and the
2567 @code{list-faces-display} command (@pxref{Faces,,,emacs, the Emacs
2568 Manual}) to see what colors and faces are available and what they look
2569 like.
2571   @xref{MS-DOS and MULE}, later in this chapter, for information on
2572 how Emacs displays glyphs and characters that aren't supported by the
2573 native font built into the DOS display.
2575 @cindex cursor shape on MS-DOS
2576   When Emacs starts, it changes the cursor shape to a solid box.  This
2577 is for compatibility with other systems, where the box cursor is the
2578 default in Emacs.  This default shape can be changed to a bar by
2579 specifying the @code{cursor-type} parameter in the variable
2580 @code{default-frame-alist} (@pxref{Creating Frames,,,emacs, the Emacs
2581 Manual}).  The MS-DOS terminal doesn't support a vertical-bar cursor,
2582 so the bar cursor is horizontal, and the @code{@var{width}} parameter,
2583 if specified by the frame parameters, actually determines its height.
2584 For this reason, the @code{bar} and @code{hbar} cursor types produce
2585 the same effect on MS-DOS.  As an extension, the bar cursor
2586 specification can include the starting scan line of the cursor as well
2587 as its width, like this:
2589 @example
2590  '(cursor-type bar @var{width} . @var{start})
2591 @end example
2593 @noindent
2594 In addition, if the @var{width} parameter is negative, the cursor bar
2595 begins at the top of the character cell.
2597 @cindex frames on MS-DOS
2598   The MS-DOS terminal can only display a single frame at a time.  The
2599 Emacs frame facilities work on MS-DOS much as they do on text-only
2600 terminals (@pxref{Frames,,,emacs, the Emacs Manual}).  When you run
2601 Emacs from a DOS window on MS-Windows, you can make the visible frame
2602 smaller than the full screen, but Emacs still cannot display more than
2603 a single frame at a time.
2605 @cindex frame size under MS-DOS
2606 @findex mode4350
2607 @findex mode25
2608   The @code{mode4350} command switches the display to 43 or 50
2609 lines, depending on your hardware; the @code{mode25} command switches
2610 to the default 80x25 screen size.
2612   By default, Emacs only knows how to set screen sizes of 80 columns by
2613 25, 28, 35, 40, 43 or 50 rows.  However, if your video adapter has
2614 special video modes that will switch the display to other sizes, you can
2615 have Emacs support those too.  When you ask Emacs to switch the frame to
2616 @var{n} rows by @var{m} columns dimensions, it checks if there is a
2617 variable called @code{screen-dimensions-@var{n}x@var{m}}, and if so,
2618 uses its value (which must be an integer) as the video mode to switch
2619 to.  (Emacs switches to that video mode by calling the BIOS @code{Set
2620 Video Mode} function with the value of
2621 @code{screen-dimensions-@var{n}x@var{m}} in the @code{AL} register.)
2622 For example, suppose your adapter will switch to 66x80 dimensions when
2623 put into video mode 85.  Then you can make Emacs support this screen
2624 size by putting the following into your @file{_emacs} file:
2626 @example
2627 (setq screen-dimensions-66x80 85)
2628 @end example
2630   Since Emacs on MS-DOS can only set the frame size to specific
2631 supported dimensions, it cannot honor every possible frame resizing
2632 request.  When an unsupported size is requested, Emacs chooses the next
2633 larger supported size beyond the specified size.  For example, if you
2634 ask for 36x80 frame, you will get 40x80 instead.
2636   The variables @code{screen-dimensions-@var{n}x@var{m}} are used only
2637 when they exactly match the specified size; the search for the next
2638 larger supported size ignores them.  In the above example, even if your
2639 VGA supports 38x80 dimensions and you define a variable
2640 @code{screen-dimensions-38x80} with a suitable value, you will still get
2641 40x80 screen when you ask for a 36x80 frame.  If you want to get the
2642 38x80 size in this case, you can do it by setting the variable named
2643 @code{screen-dimensions-36x80} with the same video mode value as
2644 @code{screen-dimensions-38x80}.
2646   Changing frame dimensions on MS-DOS has the effect of changing all the
2647 other frames to the new dimensions.
2649 @node MS-DOS File Names
2650 @section File Names on MS-DOS
2651 @cindex file names under MS-DOS
2652 @cindex init file, default name under MS-DOS
2654   MS-DOS normally uses a backslash, @samp{\}, to separate name units
2655 within a file name, instead of the slash used on other systems.  Emacs
2656 on MS-DOS permits use of either slash or backslash, and also knows
2657 about drive letters in file names.
2659   On MS-DOS, file names are case-insensitive and limited to eight
2660 characters, plus optionally a period and three more characters.  Emacs
2661 knows enough about these limitations to handle file names that were
2662 meant for other operating systems.  For instance, leading dots
2663 @samp{.}  in file names are invalid in MS-DOS, so Emacs transparently
2664 converts them to underscores @samp{_}; thus your default init file
2665 (@pxref{Init File,,,emacs, the Emacs Manual}) is called @file{_emacs}
2666 on MS-DOS.  Excess characters before or after the period are generally
2667 ignored by MS-DOS itself; thus, if you visit the file
2668 @file{LongFileName.EvenLongerExtension}, you will silently get
2669 @file{longfile.eve}, but Emacs will still display the long file name
2670 on the mode line.  Other than that, it's up to you to specify file
2671 names which are valid under MS-DOS; the transparent conversion as
2672 described above only works on file names built into Emacs.
2674 @cindex backup file names on MS-DOS
2675   The above restrictions on the file names on MS-DOS make it almost
2676 impossible to construct the name of a backup file (@pxref{Backup
2677 Names,,,emacs, the Emacs Manual}) without losing some of the original
2678 file name characters.  For example, the name of a backup file for
2679 @file{docs.txt} is @file{docs.tx~} even if single backup is used.
2681 @cindex file names under Windows 95/NT
2682 @cindex long file names in DOS box under Windows 95/NT
2683   If you run Emacs as a DOS application under Windows 9X, Windows ME, or
2684 Windows 2000, you can turn on support for long file names.  If you do
2685 that, Emacs doesn't truncate file names or convert them to lower case;
2686 instead, it uses the file names that you specify, verbatim.  To enable
2687 long file name support, set the environment variable @env{LFN} to
2688 @samp{y} before starting Emacs.  Unfortunately, Windows NT doesn't allow
2689 DOS programs to access long file names, so Emacs built for MS-DOS will
2690 only see their short 8+3 aliases.
2692 @cindex @env{HOME} directory under MS-DOS
2693   MS-DOS has no notion of home directory, so Emacs on MS-DOS pretends
2694 that the directory where it is installed is the value of the @env{HOME}
2695 environment variable.  That is, if your Emacs binary,
2696 @file{emacs.exe}, is in the directory @file{c:/utils/emacs/bin}, then
2697 Emacs acts as if @env{HOME} were set to @samp{c:/utils/emacs}.  In
2698 particular, that is where Emacs looks for the init file @file{_emacs}.
2699 With this in mind, you can use @samp{~} in file names as an alias for
2700 the home directory, as you would on GNU or Unix.  You can also set
2701 @env{HOME} variable in the environment before starting Emacs; its
2702 value will then override the above default behavior.
2704   Emacs on MS-DOS handles the directory name @file{/dev} specially,
2705 because of a feature in the emulator libraries of DJGPP that pretends
2706 I/O devices have names in that directory.  We recommend that you avoid
2707 using an actual directory named @file{/dev} on any disk.
2709 @node MS-DOS Printing
2710 @section Printing and MS-DOS
2712   Printing commands, such as @code{lpr-buffer}
2713 (@pxref{Printing,,,emacs, the Emacs Manual }) and
2714 @code{ps-print-buffer} (@pxref{PostScript,,,emacs, the Emacs Manual})
2715 can work in MS-DOS and MS-Windows by sending the output to one of the
2716 printer ports, if a Posix-style @code{lpr} program is unavailable.
2717 The same Emacs variables control printing on all systems, but in some
2718 cases they have different default values on MS-DOS and MS-Windows.
2720 @vindex printer-name @r{(MS-DOS)}
2721   If you want to use your local printer, printing on it in the usual DOS
2722 manner, then set the Lisp variable @code{lpr-command} to @code{""} (its
2723 default value) and @code{printer-name} to the name of the printer
2724 port---for example, @code{"PRN"}, the usual local printer port (that's
2725 the default), or @code{"LPT2"}, or @code{"COM1"} for a serial printer.
2726 You can also set @code{printer-name} to a file name, in which case
2727 ``printed'' output is actually appended to that file.  If you set
2728 @code{printer-name} to @code{"NUL"}, printed output is silently
2729 discarded (sent to the system null device).
2731   On MS-Windows, when the Windows network software is installed, you can
2732 also use a printer shared by another machine by setting
2733 @code{printer-name} to the UNC share name for that printer---for example,
2734 @code{"//joes_pc/hp4si"}.  (It doesn't matter whether you use forward
2735 slashes or backslashes here.)  To find out the names of shared printers,
2736 run the command @samp{net view} at a DOS command prompt to obtain a list
2737 of servers, and @samp{net view @var{server-name}} to see the names of printers
2738 (and directories) shared by that server.  Alternatively, click the
2739 @samp{Network Neighborhood} icon on your desktop, and look for machines
2740 which share their printers via the network.
2742 @cindex @samp{net use}, and printing on MS-Windows
2743 @cindex networked printers (MS-Windows)
2744   If the printer doesn't appear in the output of @samp{net view}, or
2745 if setting @code{printer-name} to the UNC share name doesn't produce a
2746 hardcopy on that printer, you can use the @samp{net use} command to
2747 connect a local print port such as @code{"LPT2"} to the networked
2748 printer.  For example, typing @kbd{net use LPT2:
2749 \\joes_pc\hp4si}@footnote{
2750 Note that the @samp{net use} command requires the UNC share name to be
2751 typed with the Windows-style backslashes, while the value of
2752 @code{printer-name} can be set with either forward- or backslashes.}
2753 causes Windows to @dfn{capture} the LPT2 port and redirect the printed
2754 material to the printer connected to the machine @code{joes_pc}.
2755 After this command, setting @code{printer-name} to @code{"LPT2"}
2756 should produce the hardcopy on the networked printer.
2758   With some varieties of Windows network software, you can instruct
2759 Windows to capture a specific printer port such as @code{"LPT2"}, and
2760 redirect it to a networked printer via the @w{@code{Control
2761 Panel->Printers}} applet instead of @samp{net use}.
2763   Some printers expect DOS codepage encoding of non-@acronym{ASCII} text, even
2764 though they are connected to a Windows machine which uses a different
2765 encoding for the same locale.  For example, in the Latin-1 locale, DOS
2766 uses codepage 850 whereas Windows uses codepage 1252.  @xref{MS-DOS and
2767 MULE}.  When you print to such printers from Windows, you can use the
2768 @kbd{C-x RET c} (@code{universal-coding-system-argument}) command before
2769 @kbd{M-x lpr-buffer}; Emacs will then convert the text to the DOS
2770 codepage that you specify.  For example, @kbd{C-x RET c cp850-dos RET
2771 M-x lpr-region RET} will print the region while converting it to the
2772 codepage 850 encoding.  You may need to create the @code{cp@var{nnn}}
2773 coding system with @kbd{M-x codepage-setup}.
2775   If you set @code{printer-name} to a file name, it's best to use an
2776 absolute file name.  Emacs changes the working directory according to
2777 the default directory of the current buffer, so if the file name in
2778 @code{printer-name} is relative, you will end up with several such
2779 files, each one in the directory of the buffer from which the printing
2780 was done.
2782 @findex print-buffer @r{(MS-DOS)}
2783 @findex print-region @r{(MS-DOS)}
2784 @vindex lpr-headers-switches @r{(MS-DOS)}
2785   The commands @code{print-buffer} and @code{print-region} call the
2786 @code{pr} program, or use special switches to the @code{lpr} program, to
2787 produce headers on each printed page.  MS-DOS and MS-Windows don't
2788 normally have these programs, so by default, the variable
2789 @code{lpr-headers-switches} is set so that the requests to print page
2790 headers are silently ignored.  Thus, @code{print-buffer} and
2791 @code{print-region} produce the same output as @code{lpr-buffer} and
2792 @code{lpr-region}, respectively.  If you do have a suitable @code{pr}
2793 program (for example, from GNU Textutils), set
2794 @code{lpr-headers-switches} to @code{nil}; Emacs will then call
2795 @code{pr} to produce the page headers, and print the resulting output as
2796 specified by @code{printer-name}.
2798 @vindex print-region-function @r{(MS-DOS)}
2799 @cindex lpr usage under MS-DOS
2800 @vindex lpr-command @r{(MS-DOS)}
2801 @vindex lpr-switches @r{(MS-DOS)}
2802   Finally, if you do have an @code{lpr} work-alike, you can set the
2803 variable @code{lpr-command} to @code{"lpr"}.  Then Emacs will use
2804 @code{lpr} for printing, as on other systems.  (If the name of the
2805 program isn't @code{lpr}, set @code{lpr-command} to specify where to
2806 find it.)  The variable @code{lpr-switches} has its standard meaning
2807 when @code{lpr-command} is not @code{""}.  If the variable
2808 @code{printer-name} has a string value, it is used as the value for the
2809 @code{-P} option to @code{lpr}, as on Unix.
2811 @findex ps-print-buffer @r{(MS-DOS)}
2812 @findex ps-spool-buffer @r{(MS-DOS)}
2813 @vindex ps-printer-name @r{(MS-DOS)}
2814 @vindex ps-lpr-command @r{(MS-DOS)}
2815 @vindex ps-lpr-switches @r{(MS-DOS)}
2816   A parallel set of variables, @code{ps-lpr-command},
2817 @code{ps-lpr-switches}, and @code{ps-printer-name} (@pxref{PostScript
2818 Variables,,,emacs, the Emacs Manual}), defines how PostScript files
2819 should be printed.  These variables are used in the same way as the
2820 corresponding variables described above for non-PostScript printing.
2821 Thus, the value of @code{ps-printer-name} is used as the name of the
2822 device (or file) to which PostScript output is sent, just as
2823 @code{printer-name} is used for non-PostScript printing.  (There are
2824 two distinct sets of variables in case you have two printers attached
2825 to two different ports, and only one of them is a PostScript printer.)
2827   The default value of the variable @code{ps-lpr-command} is @code{""},
2828 which causes PostScript output to be sent to the printer port specified
2829 by @code{ps-printer-name}, but @code{ps-lpr-command} can also be set to
2830 the name of a program which will accept PostScript files.  Thus, if you
2831 have a non-PostScript printer, you can set this variable to the name of
2832 a PostScript interpreter program (such as Ghostscript).  Any switches
2833 that need to be passed to the interpreter program are specified using
2834 @code{ps-lpr-switches}.  (If the value of @code{ps-printer-name} is a
2835 string, it will be added to the list of switches as the value for the
2836 @code{-P} option.  This is probably only useful if you are using
2837 @code{lpr}, so when using an interpreter typically you would set
2838 @code{ps-printer-name} to something other than a string so it is
2839 ignored.)
2841   For example, to use Ghostscript for printing on an Epson printer
2842 connected to the @samp{LPT2} port, put this in your @file{_emacs} file:
2844 @example
2845 (setq ps-printer-name t)  ; Ghostscript doesn't understand -P
2846 (setq ps-lpr-command "c:/gs/gs386")
2847 (setq ps-lpr-switches '("-q" "-dNOPAUSE"
2848                         "-sDEVICE=epson"
2849                         "-r240x72"
2850                         "-sOutputFile=LPT2"
2851                         "-Ic:/gs"))
2852 @end example
2854 @noindent
2855 (This assumes that Ghostscript is installed in the @file{"c:/gs"}
2856 directory.)
2858 @vindex dos-printer
2859 @vindex dos-ps-printer
2860   For backwards compatibility, the value of @code{dos-printer}
2861 (@code{dos-ps-printer}), if it has a value, overrides the value of
2862 @code{printer-name} (@code{ps-printer-name}), on MS-DOS and MS-Windows
2863 only.
2866 @node MS-DOS and MULE
2867 @section International Support on MS-DOS
2868 @cindex international support @r{(MS-DOS)}
2870   Emacs on MS-DOS supports the same international character sets as it
2871 does on GNU, Unix and other platforms (@pxref{International,,,emacs,
2872 the Emacs Manual}), including coding systems for converting between
2873 the different character sets.  However, due to incompatibilities
2874 between MS-DOS/MS-Windows and other systems, there are several
2875 DOS-specific aspects of this support that you should be aware of.
2876 This section describes these aspects.
2878   The description below is largely specific to the MS-DOS port of
2879 Emacs, especially where it talks about practical implications for
2880 Emacs users.  For other operating systems, see the @file{code-pages.el}
2881 package, which implements support for MS-DOS- and MS-Windows-specific
2882 encodings for all platforms other than MS-DOS.
2884 @table @kbd
2885 @item M-x dos-codepage-setup
2886 Set up Emacs display and coding systems as appropriate for the current
2887 DOS codepage.
2889 @item M-x codepage-setup
2890 Create a coding system for a certain DOS codepage.
2891 @end table
2893 @cindex codepage, MS-DOS
2894 @cindex DOS codepages
2895   MS-DOS is designed to support one character set of 256 characters at
2896 any given time, but gives you a variety of character sets to choose
2897 from.  The alternative character sets are known as @dfn{DOS codepages}.
2898 Each codepage includes all 128 @acronym{ASCII} characters, but the other 128
2899 characters (codes 128 through 255) vary from one codepage to another.
2900 Each DOS codepage is identified by a 3-digit number, such as 850, 862,
2901 etc.
2903   In contrast to X, which lets you use several fonts at the same time,
2904 MS-DOS normally doesn't allow use of several codepages in a single
2905 session.  MS-DOS was designed to load a single codepage at system
2906 startup, and require you to reboot in order to change
2907 it@footnote{Normally, one particular codepage is burnt into the
2908 display memory, while other codepages can be installed by modifying
2909 system configuration files, such as @file{CONFIG.SYS}, and rebooting.
2910 While there is third-party software that allows changing the codepage
2911 without rebooting, we describe here how a stock MS-DOS system
2912 behaves.}.  Much the same limitation applies when you run DOS
2913 executables on other systems such as MS-Windows.
2915 @cindex unibyte operation @r{(MS-DOS)}
2916   If you invoke Emacs on MS-DOS with the @samp{--unibyte} option
2917 (@pxref{Initial Options,,,emacs, the Emacs Manual}), Emacs does not
2918 perform any conversion of non-@acronym{ASCII} characters.  Instead, it
2919 reads and writes any non-@acronym{ASCII} characters verbatim, and
2920 sends their 8-bit codes to the display verbatim.  Thus, unibyte Emacs
2921 on MS-DOS supports the current codepage, whatever it may be, but
2922 cannot even represent any other characters.
2924 @vindex dos-codepage
2925   For multibyte operation on MS-DOS, Emacs needs to know which
2926 characters the chosen DOS codepage can display.  So it queries the
2927 system shortly after startup to get the chosen codepage number, and
2928 stores the number in the variable @code{dos-codepage}.  Some systems
2929 return the default value 437 for the current codepage, even though the
2930 actual codepage is different.  (This typically happens when you use the
2931 codepage built into the display hardware.)  You can specify a different
2932 codepage for Emacs to use by setting the variable @code{dos-codepage} in
2933 your init file.
2935 @cindex language environment, automatic selection on @r{MS-DOS}
2936   Multibyte Emacs supports only certain DOS codepages: those which can
2937 display Far-Eastern scripts, like the Japanese codepage 932, and those
2938 that encode a single ISO 8859 character set.
2940   The Far-Eastern codepages can directly display one of the MULE
2941 character sets for these countries, so Emacs simply sets up to use the
2942 appropriate terminal coding system that is supported by the codepage.
2943 The special features described in the rest of this section mostly
2944 pertain to codepages that encode ISO 8859 character sets.
2946   For the codepages which correspond to one of the ISO character sets,
2947 Emacs knows the character set name based on the codepage number.  Emacs
2948 automatically creates a coding system to support reading and writing
2949 files that use the current codepage, and uses this coding system by
2950 default.  The name of this coding system is @code{cp@var{nnn}}, where
2951 @var{nnn} is the codepage number.@footnote{The standard Emacs coding
2952 systems for ISO 8859 are not quite right for the purpose, because
2953 typically the DOS codepage does not match the standard ISO character
2954 codes.  For example, the letter @samp{@,{c}} (@samp{c} with cedilla) has
2955 code 231 in the standard Latin-1 character set, but the corresponding
2956 DOS codepage 850 uses code 135 for this glyph.}
2958 @cindex mode line @r{(MS-DOS)}
2959   All the @code{cp@var{nnn}} coding systems use the letter @samp{D}
2960 (for ``DOS'') as their mode-line mnemonic.  Since both the terminal
2961 coding system and the default coding system for file I/O are set to
2962 the proper @code{cp@var{nnn}} coding system at startup, it is normal
2963 for the mode line on MS-DOS to begin with @samp{-DD\-}.  @xref{Mode
2964 Line,,,emacs, the Emacs Manual}.  Far-Eastern DOS terminals do not use
2965 the @code{cp@var{nnn}} coding systems, and thus their initial mode
2966 line looks like the Emacs default.
2968   Since the codepage number also indicates which script you are using,
2969 Emacs automatically runs @code{set-language-environment} to select the
2970 language environment for that script (@pxref{Language
2971 Environments,,,emacs, the Emacs Manual}).
2973   If a buffer contains a character belonging to some other ISO 8859
2974 character set, not the one that the chosen DOS codepage supports, Emacs
2975 displays it using a sequence of @acronym{ASCII} characters.  For example, if the
2976 current codepage doesn't have a glyph for the letter @samp{@`o} (small
2977 @samp{o} with a grave accent), it is displayed as @samp{@{`o@}}, where
2978 the braces serve as a visual indication that this is a single character.
2979 (This may look awkward for some non-Latin characters, such as those from
2980 Greek or Hebrew alphabets, but it is still readable by a person who
2981 knows the language.)  Even though the character may occupy several
2982 columns on the screen, it is really still just a single character, and
2983 all Emacs commands treat it as one.
2985 @cindex IBM graphics characters (MS-DOS)
2986 @cindex box-drawing characters (MS-DOS)
2987 @cindex line-drawing characters (MS-DOS)
2988   Not all characters in DOS codepages correspond to ISO 8859
2989 characters---some are used for other purposes, such as box-drawing
2990 characters and other graphics.  Emacs maps these characters to two
2991 special character sets called @code{eight-bit-control} and
2992 @code{eight-bit-graphic}, and displays them as their IBM glyphs.
2993 However, you should be aware that other systems might display these
2994 characters differently, so you should avoid them in text that might be
2995 copied to a different operating system, or even to another DOS machine
2996 that uses a different codepage.
2998 @vindex dos-unsupported-character-glyph
2999   Emacs supports many other characters sets aside from ISO 8859, but it
3000 cannot display them on MS-DOS.  So if one of these multibyte characters
3001 appears in a buffer, Emacs on MS-DOS displays them as specified by the
3002 @code{dos-unsupported-character-glyph} variable; by default, this glyph
3003 is an empty triangle.  Use the @kbd{C-u C-x =} command to display the
3004 actual code and character set of such characters.  @xref{Position
3005 Info,,,emacs, the Emacs Manual}.
3007 @findex codepage-setup
3008   By default, Emacs defines a coding system to support the current
3009 codepage.  To define a coding system for some other codepage (e.g., to
3010 visit a file written on a DOS machine in another country), use the
3011 @kbd{M-x codepage-setup} command.  It prompts for the 3-digit code of
3012 the codepage, with completion, then creates the coding system for the
3013 specified codepage.  You can then use the new coding system to read and
3014 write files, but you must specify it explicitly for the file command
3015 when you want to use it (@pxref{Text Coding,,,emacs, the Emacs Manual}).
3017   These coding systems are also useful for visiting a file encoded using
3018 a DOS codepage, using Emacs running on some other operating system.
3020 @cindex MS-Windows codepages
3021   MS-Windows provides its own codepages, which are different from the
3022 DOS codepages for the same locale.  For example, DOS codepage 850
3023 supports the same character set as Windows codepage 1252; DOS codepage
3024 855 supports the same character set as Windows codepage 1251, etc.
3025 The MS-Windows version of Emacs uses the current codepage for display
3026 when invoked with the @samp{-nw} option.  Support for codepages in the
3027 Windows port of Emacs is part of the @file{code-pages.el} package.
3029 @node MS-DOS Processes
3030 @section Subprocesses on MS-DOS
3032 @cindex compilation under MS-DOS
3033 @cindex inferior processes under MS-DOS
3034 @findex compile @r{(MS-DOS)}
3035 @findex grep @r{(MS-DOS)}
3036   Because MS-DOS is a single-process ``operating system,''
3037 asynchronous subprocesses are not available.  In particular, Shell
3038 mode and its variants do not work.  Most Emacs features that use
3039 asynchronous subprocesses also don't work on MS-DOS, including
3040 Shell mode and GUD.  When in doubt, try and see; commands that
3041 don't work output an error message saying that asynchronous processes
3042 aren't supported.
3044   Compilation under Emacs with @kbd{M-x compile}, searching files with
3045 @kbd{M-x grep} and displaying differences between files with @kbd{M-x
3046 diff} do work, by running the inferior processes synchronously.  This
3047 means you cannot do any more editing until the inferior process
3048 finishes.
3050   Spell checking also works, by means of special support for synchronous
3051 invocation of the @code{ispell} program.  This is slower than the
3052 asynchronous invocation on other platforms
3054   Instead of the Shell mode, which doesn't work on MS-DOS, you can use
3055 the @kbd{M-x eshell} command.  This invokes the Eshell package that
3056 implements a Posix-like shell entirely in Emacs Lisp.
3058   By contrast, Emacs compiled as a native Windows application
3059 @strong{does} support asynchronous subprocesses.  @xref{Windows
3060 Processes,,,emacs, the Emacs Manual}.
3062 @cindex printing under MS-DOS
3063   Printing commands, such as @code{lpr-buffer}
3064 (@pxref{Printing,,,emacs, the Emacs Manual}) and
3065 @code{ps-print-buffer} (@pxref{PostScript,,,emacs, the Emacs Manual}),
3066 work in MS-DOS by sending the output to one of the printer ports.
3067 @xref{MS-DOS Printing,,,emacs, the Emacs Manual}.
3069   When you run a subprocess synchronously on MS-DOS, make sure the
3070 program terminates and does not try to read keyboard input.  If the
3071 program does not terminate on its own, you will be unable to terminate
3072 it, because MS-DOS provides no general way to terminate a process.
3073 Pressing @kbd{C-c} or @kbd{C-@key{BREAK}} might sometimes help in these
3074 cases.
3076   Accessing files on other machines is not supported on MS-DOS.  Other
3077 network-oriented commands such as sending mail, Web browsing, remote
3078 login, etc., don't work either, unless network access is built into
3079 MS-DOS with some network redirector.
3081 @cindex directory listing on MS-DOS
3082 @vindex dired-listing-switches @r{(MS-DOS)}
3083   Dired on MS-DOS uses the @code{ls-lisp} package where other
3084 platforms use the system @code{ls} command.  Therefore, Dired on
3085 MS-DOS supports only some of the possible options you can mention in
3086 the @code{dired-listing-switches} variable.  The options that work are
3087 @samp{-A}, @samp{-a}, @samp{-c}, @samp{-i}, @samp{-r}, @samp{-S},
3088 @samp{-s}, @samp{-t}, and @samp{-u}.
3091 @node Index
3092 @unnumbered Index
3094 @printindex cp
3096 @bye
3098 @ignore
3099    arch-tag: 75c33f13-32c6-41b6-9537-847a312e2e49
3100 @end ignore