home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2 / Openstep-4.2-Intel-User.iso / usr / lib / emacs / info / emacs-8 (.txt) < prev    next >
GNU Info File  |  1992-10-30  |  51KB  |  900 lines

  1. This is Info file ../info/emacs, produced by Makeinfo-1.49 from the
  2. input file emacs.texi.
  3.    This file documents the GNU Emacs editor.
  4.    Copyright (C) 1985, 1986, 1988, 1992 Richard M. Stallman.
  5.    Permission is granted to make and distribute verbatim copies of this
  6. manual provided the copyright notice and this permission notice are
  7. preserved on all copies.
  8.    Permission is granted to copy and distribute modified versions of
  9. this manual under the conditions for verbatim copying, provided also
  10. that the sections entitled "The GNU Manifesto", "Distribution" and "GNU
  11. General Public License" are included exactly as in the original, and
  12. provided that the entire resulting derived work is distributed under the
  13. terms of a permission notice identical to this one.
  14.    Permission is granted to copy and distribute translations of this
  15. manual into another language, under the above conditions for modified
  16. versions, except that the sections entitled "The GNU Manifesto",
  17. "Distribution" and "GNU General Public License" may be included in a
  18. translation approved by the author instead of in the original English.
  19. File: emacs,  Node: Comments,  Next: Macro Expansion,  Prev: Matching,  Up: Programs
  20. Manipulating Comments
  21. =====================
  22.    The comment commands insert, kill and align comments.
  23. `M-;'
  24.      Insert or align comment (`indent-for-comment').
  25. `C-x ;'
  26.      Set comment column (`set-comment-column').
  27. `C-u - C-x ;'
  28.      Kill comment on current line (`kill-comment').
  29. `M-LFD'
  30.      Like RET followed by inserting and aligning a comment
  31.      (`indent-new-comment-line').
  32.    The command that creates a comment is `Meta-;'
  33. (`indent-for-comment'). If there is no comment already on the line, a
  34. new comment is created, aligned at a specific column called the
  35. "comment column".  The comment is created by inserting the string Emacs
  36. thinks comments should start with (the value of `comment-start'; see
  37. below).  Point is left after that string.  If the text of the line
  38. extends past the comment column, then the indentation is done to a
  39. suitable boundary (usually, at least one space is inserted).  If the
  40. major mode has specified a string to terminate comments, that is
  41. inserted after point, to keep the syntax valid.
  42.    `Meta-;' can also be used to align an existing comment.  If a line
  43. already contains the string that starts comments, then `M-;' just moves
  44. point after it and re-indents it to the conventional place.  Exception:
  45. comments starting in column 0 are not moved.
  46.    Some major modes have special rules for indenting certain kinds of
  47. comments in certain contexts.  For example, in Lisp code, comments which
  48. start with two semicolons are indented as if they were lines of code,
  49. instead of at the comment column.  Comments which start with three
  50. semicolons are supposed to start at the left margin.  Emacs understands
  51. these conventions by indenting a double-semicolon comment using TAB,
  52. and by not changing the indentation of a triple-semicolon comment at
  53.      ;; This function is just an example
  54.      ;;; Here either two or three semicolons are appropriate.
  55.      (defun foo (x)
  56.      ;;; And now, the first part of the function:
  57.        ;; The following line adds one.
  58.        (1+ x))           ; This line adds one.
  59.    In C code, a comment preceded on its line by nothing but whitespace
  60. is indented like a line of code.
  61.    Even when an existing comment is properly aligned, `M-;' is still
  62. useful for moving directly to the start of the comment.
  63.    `C-u - C-x ;' (`kill-comment') kills the comment on the current line,
  64. if there is one.  The indentation before the start of the comment is
  65. killed as well.  If there does not appear to be a comment in the line,
  66. nothing is done.  To reinsert the comment on another line, move to the
  67. end of that line, do `C-y', and then do `M-;' to realign it.  Note that
  68. `C-u - C-x ;' is not a distinct key; it is `C-x ;'
  69. (`set-comment-column') with a negative argument.  That command is
  70. programmed so that when it receives a negative argument it calls
  71. `kill-comment'.  However, `kill-comment' is a valid command which you
  72. could bind directly to a key if you wanted to.
  73. Multiple Lines of Comments
  74. --------------------------
  75.    If you are typing a comment and find that you wish to continue it on
  76. another line, you can use the command `Meta-LFD'
  77. (`indent-new-comment-line'), which terminates the comment you are
  78. typing, creates a new blank line afterward, and begins a new comment
  79. indented under the old one.  When Auto Fill mode is on, going past the
  80. fill column while typing a comment causes the comment to be continued
  81. in just this fashion.  If point is not at the end of the line when
  82. `M-LFD' is typed, the text on the rest of the line becomes part of the
  83. new comment line.
  84. Options Controlling Comments
  85. ----------------------------
  86.    The comment column is stored in the variable `comment-column'.  You
  87. can set it to a number explicitly.  Alternatively, the command `C-x ;'
  88. (`set-comment-column') sets the comment column to the column point is
  89. at.  `C-u C-x ;' sets the comment column to match the last comment
  90. before point in the buffer, and then does a `Meta-;' to align the
  91. current line's comment under the previous one.  Note that `C-u - C-x ;'
  92. runs the function `kill-comment' as described above.
  93.    `comment-column' is a per-buffer variable; altering the variable
  94. affects only the current buffer, but there is a default value which you
  95. can change as well.  *Note Locals::.  Many major modes initialize this
  96. variable for the current buffer.
  97.    The comment commands recognize comments based on the regular
  98. expression that is the value of the variable `comment-start-skip'. 
  99. This regexp should not match the null string.  It may match more than
  100. the comment starting delimiter in the strictest sense of the word; for
  101. example, in C mode the value of the variable is `"/\\*+ *"', which
  102. matches extra stars and spaces after the `/*' itself.  (Note that `\\'
  103. is needed in Lisp syntax to include a `\' in the string, which is needed
  104. to deny the first star its special meaning in regexp syntax.  *Note
  105. Regexps::.)
  106.    When a comment command makes a new comment, it inserts the value of
  107. `comment-start' to begin it.  The value of `comment-end' is inserted
  108. after point, so that it will follow the text that you will insert into
  109. the comment.  In C mode, `comment-start' has the value `"/* "' and
  110. `comment-end' has the value `" */"'.
  111.    `comment-multi-line' controls how `M-LFD' (`indent-new-comment-line')
  112. behaves when used inside a comment.  If `comment-multi-line' is `nil',
  113. as it normally is, then the comment on the starting line is terminated
  114. and a new comment is started on the new following line.  If
  115. `comment-multi-line' is not `nil', then the new following line is set
  116. up as part of the same comment that was found on the starting line.
  117. This is done by not inserting a terminator on the old line, and not
  118. inserting a starter on the new line.  In languages where multi-line
  119. comments work, the choice of value for this variable is a matter of
  120. taste.
  121.    The variable `comment-indent-hook' should contain a function that
  122. will be called to compute the indentation for a newly inserted comment
  123. or for aligning an existing comment.  It is set differently by various
  124. major modes.  The function is called with no arguments, but with point
  125. at the beginning of the comment, or at the end of a line if a new
  126. comment is to be inserted.  It should return the column in which the
  127. comment ought to start. For example, in Lisp mode, the indent hook
  128. function bases its decision on how many semicolons begin an existing
  129. comment, and on the code in the preceding lines.
  130. File: emacs,  Node: Macro Expansion,  Next: Balanced Editing,  Prev: Comments,  Up: Programs
  131. Viewing How C Macros Expand
  132. ===========================
  133.    When you are debugging C code that uses macros, sometimes it is hard
  134. to figure out precisely how the macros expand.  The command `M-x
  135. c-macro-expand'.  It runs the C preprocessor and shows you what
  136. expansion results from the region.  The portion of the buffer before the
  137. region is also included in preprocessing, for the sake of macros defined
  138. there, but the output from this part isn't shown.
  139. File: emacs,  Node: Balanced Editing,  Next: Lisp Completion,  Prev: Macro Expansion,  Up: Programs
  140. Editing Without Unbalanced Parentheses
  141. ======================================
  142. `M-('
  143.      Put parentheses around next sexp(s) (`insert-parentheses').
  144. `M-)'
  145.      Move past next close parenthesis and re-indent
  146.      (`move-over-close-and-reindent').
  147.    The two commands, `M-(' (`insert-parentheses') and `M-)'
  148. (`move-over-close-and-reindent'), are designed to facilitate a style of
  149. editing which keeps parentheses balanced at all times.  `M-(' inserts a
  150. pair of parentheses, either together as in `()', or, if given an
  151. argument, around the next several sexps, and leaves point after the open
  152. parenthesis.  Instead of typing `( F O O )', you can type `M-( F O O',
  153. which has the same effect except for leaving the cursor before the
  154. close parenthesis.  Then you would type `M-)', which moves past the
  155. close parenthesis, deleting any indentation preceding it (in this
  156. example there is none), and indenting with LFD after it.
  157. File: emacs,  Node: Lisp Completion,  Next: Documentation,  Prev: Balanced Editing,  Up: Programs
  158. Completion for Lisp Symbols
  159. ===========================
  160.    Usually completion happens in the minibuffer.  But one kind of
  161. completion is available in all buffers: completion for Lisp symbol
  162. names.
  163.    The command `M-TAB' (`lisp-complete-symbol') takes the partial Lisp
  164. symbol before point to be an abbreviation, and compares it against all
  165. nontrivial Lisp symbols currently known to Emacs.  Any additional
  166. characters that they all have in common are inserted at point.
  167. Nontrivial symbols are those that have function definitions, values or
  168. properties.
  169.    If there is an open-parenthesis immediately before the beginning of
  170. the partial symbol, only symbols with function definitions are
  171. considered as completions.
  172.    If the partial name in the buffer has more than one possible
  173. completion and they have no additional characters in common, a list of
  174. all possible completions is displayed in another window.
  175. File: emacs,  Node: Documentation,  Next: Change Log,  Prev: Lisp Completion,  Up: Programs
  176. Documentation Commands
  177. ======================
  178.    As you edit Lisp code to be run in Emacs, the commands `C-h f'
  179. (`describe-function') and `C-h v' (`describe-variable') can be used to
  180. print documentation of functions and variables that you want to call. 
  181. These commands use the minibuffer to read the name of a function or
  182. variable to document, and display the documentation in a window.
  183.    For extra convenience, these commands provide default arguments
  184. based on the code in the neighborhood of point.  `C-h f' sets the
  185. default to the function called in the innermost list containing point. 
  186. `C-h v' uses the symbol name around or adjacent to point as its default.
  187.    Documentation on Unix commands, system calls and libraries can be
  188. obtained with the `M-x manual-entry' command.  This reads a topic as an
  189. argument, and displays the text on that topic from the Unix manual.
  190. `manual-entry' always searches all 8 sections of the manual, and
  191. concatenates all the entries that are found.  For example, the topic
  192. `termcap' finds the description of the termcap library from section 3,
  193. followed by the description of the termcap data base from section 5.
  194. File: emacs,  Node: Change Log,  Next: Tags,  Prev: Documentation,  Up: Programs
  195. Change Logs
  196. ===========
  197.    The Emacs command `M-x add-change-log-entry' helps you keep a record
  198. of when and why you have changed a program.  It assumes that you have a
  199. file in which you write a chronological sequence of entries describing
  200. individual changes.  The default is to store the change entries in a
  201. file called `ChangeLog' in the same directory as the file you are
  202. editing. The same `ChangeLog' file therefore records changes for all
  203. the files in the directory.
  204.    A change log entry starts with a header line that contains your name
  205. and the current date.  Aside from these header lines, every line in the
  206. change log starts with a tab.  One entry can describe several changes;
  207. each change starts with a line starting with a tab and a star. `M-x
  208. add-change-log-entry' visits the change log file and creates a new
  209. entry unless the most recent entry is for today's date and your name. 
  210. In either case, it adds a new line to start the description of another
  211. change just after the header line of the entry.  When `M-x
  212. add-change-log-entry' is finished, all is prepared for you to edit in
  213. the description of what you changed and how.  You must then save the
  214. change log file yourself.
  215.    The change log file is always visited in Indented Text mode, which
  216. means that LFD and auto-filling indent each new line like the previous
  217. line.  This is convenient for entering the contents of an entry, which
  218. must all be indented.  *Note Text Mode::.
  219.    An alternative convenient command for starting a change log entry is
  220. `C-x 4 a' (`add-change-log-entry-other-window').  It resembles
  221. `add-change-log-entry' except that it visits the change log in another
  222. window, and always uses the file `./ChangeLog'--it does not ask you for
  223. the file name.
  224.    Here is an example of the formatting conventions used in the change
  225. log for Emacs:
  226.      Wed Jun 26 19:29:32 1985  Richard M. Stallman  (rms at mit-prep)
  227.      
  228.              * xdisp.c (try_window_id):
  229.              If C-k is done at end of next-to-last line,
  230.              this fn updates window_end_vpos and cannot leave
  231.              window_end_pos nonnegative (it is zero, in fact).
  232.              If display is preempted before lines are output,
  233.              this is inconsistent.  Fix by setting
  234.              blank_end_of_window to nonzero.
  235.      Tue Jun 25 05:25:33 1985  Richard M. Stallman  (rms at mit-prep)
  236.      
  237.              * cmds.c (Fnewline):
  238.              Call the auto fill hook if appropriate.
  239.      * xdisp.c (try_window_id):
  240.              If point is found by compute_motion after xp, record that
  241.              permanently.  If display_text_line sets point position wrong
  242.              (case where line is killed, point is at eob and that line is
  243.              not displayed), set it again in final compute_motion.
  244. File: emacs,  Node: Tags,  Next: Fortran,  Prev: Change Log,  Up: Programs
  245. Tag Tables
  246. ==========
  247.    A "tag table" is a description of how a multi-file program is broken
  248. up into files.  It lists the names of the component files and the names
  249. and positions of the functions in each file.  Grouping the related
  250. files makes it possible to search or replace through all the files with
  251. one command. Recording the function names and positions makes possible
  252. the `Meta-.' command which you can use to find the definition of a
  253. function without having to know which of the files it is in.
  254.    Tag tables are stored in files called "tag table files".  The
  255. conventional name for a tag table file is `TAGS'.
  256.    Each entry in the tag table records the name of one tag, the name of
  257. the file that the tag is defined in (implicitly), and the position in
  258. that file of the tag's definition.
  259.    Just what names from the described files are recorded in the tag
  260. table depends on the programming language of the described file.  They
  261. normally include all functions and subroutines, and may also include
  262. global variables, data types, and anything else convenient.  In any
  263. case, each name recorded is called a "tag".
  264. * Menu:
  265. * Tag Syntax::
  266. * Create Tag Table::
  267. * Select Tag Table::
  268. * Find Tag::
  269. * Tags Search::
  270. * Tags Stepping::
  271. * List Tags::
  272. File: emacs,  Node: Tag Syntax,  Next: Create Tag Table,  Prev: Tags,  Up: Tags
  273. Source File Tag Syntax
  274. ----------------------
  275.    In Lisp code, any function defined with `defun', any variable
  276. defined with `defvar' or `defconst', and in general the first argument
  277. of any expression that starts with `(def' in column zero, is a tag.
  278.    In C code, any C function is a tag, and so is any typedef if `-t' is
  279. specified when the tag table is constructed.
  280.    In Fortran code, functions and subroutines are tags.
  281.    In LaTeX text, the argument of any of the commands `\chapter',
  282. `\section', `\subsection', `\subsubsection', `\eqno', `\label', `\ref',
  283. `\cite', `\bibitem' and `\typeout' is a tag.
  284. File: emacs,  Node: Create Tag Table,  Next: Select Tag Table,  Prev: Tag Syntax,  Up: Tags
  285. Creating Tag Tables
  286. -------------------
  287.    The `etags' program is used to create a tag table file.  It knows
  288. the syntax of C, Fortran, LaTeX, Scheme and Emacs Lisp/Common Lisp.  To
  289. use `etags', type
  290.      etags INPUTFILES...
  291. as a shell command.  It reads the specified files and writes a tag table
  292. named `TAGS' in the current working directory.  `etags' recognizes the
  293. language used in an input file based on its file name and contents;
  294. there are no switches for specifying the language.  The `-t' switch
  295. tells `etags' to record typedefs in C code as tags.
  296.    If the tag table data become outdated due to changes in the files
  297. described in the table, the way to update the tag table is the same way
  298. it was made in the first place.  It is not necessary to do this often.
  299.    If the tag table fails to record a tag, or records it for the wrong
  300. file, then Emacs cannot possibly find its definition.  However, if the
  301. position recorded in the tag table becomes a little bit wrong (due to
  302. some editing in the file that the tag definition is in), the only
  303. consequence is to slow down finding the tag slightly.  Even if the
  304. stored position is very wrong, Emacs will still find the tag, but it
  305. must search the entire file for it.
  306.    So you should update a tag table when you define new tags that you
  307. want to have listed, or when you move tag definitions from one file to
  308. another, or when changes become substantial.  Normally there is no need
  309. to update the tag table after each edit, or even every day.
  310. File: emacs,  Node: Select Tag Table,  Next: Find Tag,  Prev: Create Tag Table,  Up: Tags
  311. Selecting a Tag Table
  312. ---------------------
  313.    Emacs has at any time one "selected" tag table, and all the commands
  314. for working with tag tables use the selected one.  To select a tag
  315. table, type `M-x visit-tags-table', which reads the tag table file name
  316. as an argument.  The name `TAGS' in the default directory is used as the
  317. default file name.
  318.    All this command does is store the file name in the variable
  319. `tags-file-name'.  Emacs does not actually read in the tag table
  320. contents until you try to use them.  Setting this variable yourself is
  321. just as good as using `visit-tags-table'.  The variable's initial value
  322. is `nil'; this value tells all the commands for working with tag tables
  323. that they must ask for a tag table file name to use.
  324. File: emacs,  Node: Find Tag,  Next: Tags Search,  Prev: Select Tag Table,  Up: Tags
  325. Finding a Tag
  326. -------------
  327.    The most important thing that a tag table enables you to do is to
  328. find the definition of a specific tag.
  329. `M-. TAG'
  330.      Find first definition of TAG (`find-tag').
  331. `C-u M-.'
  332.      Find next alternate definition of last tag specified.
  333. `C-x 4 . TAG'
  334.      Find first definition of TAG, but display it in another window
  335.      (`find-tag-other-window').
  336.    `M-.' (`find-tag') is the command to find the definition of a
  337. specified tag.  It searches through the tag table for that tag, as a
  338. string, and then uses the tag table info to determine the file that the
  339. definition is in and the approximate character position in the file of
  340. the definition.  Then `find-tag' visits that file, moves point to the
  341. approximate character position, and starts searching ever-increasing
  342. distances away for the the text that should appear at the beginning of
  343. the definition.
  344.    If an empty argument is given (just type RET), the sexp in the
  345. buffer before or around point is used as the name of the tag to find.
  346. *Note Lists::, for info on sexps.
  347.    The argument to `find-tag' need not be the whole tag name; it can be
  348. a substring of a tag name.  However, there can be many tag names
  349. containing the substring you specify.  Since `find-tag' works by
  350. searching the text of the tag table, it finds the first tag in the
  351. table that the specified substring appears in.
  352.    The way to find other tags that match the substring is to give
  353. `find-tag' a numeric argument, as in `C-u M-.'; this does not read a
  354. tag name, but continues searching the tag table's text for another tag
  355. containing the same substring last used.  If you have a real META key,
  356. `M-0 M-.' is an easier alternative to `C-u M-.'. (That is a zero in
  357. `M-0'.)
  358.    Like most commands that can switch buffers, `find-tag' has another
  359. similar command that displays the new buffer in another window.  `C-x 4
  360. .' invokes the function `find-tag-other-window'.  (This key sequence
  361. ends with a period.)
  362.    Emacs comes with a tag table file `TAGS', in the `src' subdirectory,
  363. which includes all the Lisp libraries and all the C sources of Emacs. 
  364. By specifying this file with `visit-tags-table' and then using `M-.'
  365. you can quickly look at the source of any Emacs function.
  366. File: emacs,  Node: Tags Search,  Next: Tags Stepping,  Prev: Find Tag,  Up: Tags
  367. Searching and Replacing with Tag Tables
  368. ---------------------------------------
  369.    The commands in this section visit and search all the files listed
  370. in the selected tag table, one by one.  For these commands, the tag
  371. table serves only to specify a sequence of files to search.  A related
  372. command is `M-x grep' (*note Compilation::.).
  373. `M-x tags-search'
  374.      Search for the specified regexp through the files in the selected
  375.      tag table.
  376. `M-x tags-query-replace'
  377.      Perform a `query-replace' on each file in the selected tag table.
  378. `M-,'
  379.      Restart one of the commands above, from the current location of
  380.      point (`tags-loop-continue').
  381.    `M-x tags-search' reads a regexp using the minibuffer, then visits
  382. the files of the selected tag table one by one, and searches through
  383. each one for that regexp.  It displays the name of the file being
  384. searched so you can follow its progress.  As soon as an occurrence is
  385. found, `tags-search' returns.
  386.    Having found one match, you probably want to find all the rest.  To
  387. find one more match, type `M-,' (`tags-loop-continue') to resume the
  388. `tags-search'.  This searches the rest of the current buffer, followed
  389. by the remaining files of the tag table.
  390.    `M-x tags-query-replace' performs a single `query-replace' through
  391. all the files in the tag table.  It reads a string to search for and a
  392. string to replace with, just like ordinary `M-x query-replace'. It
  393. searches much like `M-x tags-search' but repeatedly, processing matches
  394. according to your input.  *Note Replace::, for more information on
  395. `query-replace'.
  396.    It is possible to get through all the files in the tag table with a
  397. single invocation of `M-x tags-query-replace'.  But since any
  398. unrecognized character causes the command to exit, you may need to
  399. continue where you left off.  `M-,' can be used for this.  It resumes
  400. the last tags search or replace command that you did.
  401.    It may have struck you that `tags-search' is a lot like `grep'. You
  402. can also run `grep' itself as an inferior of Emacs and have Emacs show
  403. you the matching lines one by one.  This works mostly the same as
  404. running a compilation and having Emacs show you where the errors were.
  405. *Note Compilation::.
  406. File: emacs,  Node: Tags Stepping,  Next: List Tags,  Prev: Tags Search,  Up: Tags
  407. Stepping Through a Tag Table
  408. ----------------------------
  409.    If you wish to process all the files in the selected tag table, but
  410. `M-x tags-search' and `M-x tags-query-replace' in particular are not
  411. what you want, you can use `M-x next-file'.
  412. `C-u M-x next-file'
  413.      With a numeric argument, regardless of its value, visit the first
  414.      file in the tag table, and prepare to advance sequentially by
  415.      files.
  416. `M-x next-file'
  417.      Visit the next file in the selected tag table.
  418. File: emacs,  Node: List Tags,  Prev: Tags Stepping,  Up: Tags
  419. Tag Table Inquiries
  420. -------------------
  421. `M-x list-tags'
  422.      Display a list of the tags defined in a specific program file.
  423. `M-x tags-apropos'
  424.      Display a list of all tags matching a specified regexp.
  425.    `M-x list-tags' reads the name of one of the files described by the
  426. selected tag table, and displays a list of all the tags defined in that
  427. file.  The "file name" argument is really just a string to compare
  428. against the names recorded in the tag table; it is read as a string
  429. rather than as a file name.  Therefore, completion and defaulting are
  430. not available, and you must enter the string the same way it appears in
  431. the tag table.  Do not include a directory as part of the file name
  432. unless the file name recorded in the tag table includes a directory.
  433.    `M-x tags-apropos' is like `apropos' for tags.  It reads a regexp,
  434. then finds all the tags in the selected tag table whose entries match
  435. that regexp, and displays the tag names found.
  436. File: emacs,  Node: Fortran,  Prev: Tags,  Up: Programs
  437. Fortran Mode
  438. ============
  439.    Fortran mode provides special motion commands for Fortran statements
  440. and subprograms, and indentation commands that understand Fortran
  441. conventions of nesting, line numbers and continuation statements.
  442.    Special commands for comments are provided because Fortran comments
  443. are unlike those of other languages.
  444.    Built-in abbrevs optionally save typing when you insert Fortran
  445. keywords.
  446.    Use `M-x fortran-mode' to switch to this major mode.  Doing so calls
  447. the value of `fortran-mode-hook' as a function of no arguments if that
  448. variable has a value that is not `nil'.
  449. * Menu:
  450. * Motion: Fortran Motion.     Moving point by statements or subprograms.
  451. * Indent: Fortran Indent.     Indentation commands for Fortran.
  452. * Comments: Fortran Comments. Inserting and aligning comments.
  453. * Columns: Fortran Columns.   Measuring columns for valid Fortran.
  454. * Abbrev: Fortran Abbrev.     Built-in abbrevs for Fortran keywords.
  455.    Fortran mode was contributed by Michael Prange.
  456. File: emacs,  Node: Fortran Motion,  Next: Fortran Indent,  Prev: Fortran,  Up: Fortran
  457. Motion Commands
  458. ---------------
  459.    Fortran mode provides special commands to move by subprograms
  460. (functions and subroutines) and by statements.  There is also a command
  461. to put the region around one subprogram, convenient for killing it or
  462. moving it.
  463. `C-M-a'
  464.      Move to beginning of subprogram
  465.      (`beginning-of-fortran-subprogram').
  466. `C-M-e'
  467.      Move to end of subprogram (`end-of-fortran-subprogram').
  468. `C-M-h'
  469.      Put point at beginning of subprogram and mark at end
  470.      (`mark-fortran-subprogram').
  471. `C-c C-n'
  472.      Move to beginning of current or next statement
  473.      (`fortran-next-statement').
  474. `C-c C-p'
  475.      Move to beginning of current or previous statement
  476.      (`fortran-previous-statement').
  477. File: emacs,  Node: Fortran Indent,  Next: Fortran Comments,  Prev: Fortran Motion,  Up: Fortran
  478. Fortran Indentation
  479. -------------------
  480.    Special commands and features are needed for indenting Fortran code
  481. in order to make sure various syntactic entities (line numbers, comment
  482. line indicators and continuation line flags) appear in the columns that
  483. are required for standard Fortran.
  484. * Menu:
  485. * Commands: ForIndent Commands. Commands for indenting Fortran.
  486. * Numbers:  ForIndent Num.      How line numbers auto-indent.
  487. * Conv:     ForIndent Conv.     Conventions you must obey to avoid trouble.
  488. * Vars:     ForIndent Vars.     Variables controlling Fortran indent style.
  489. File: emacs,  Node: ForIndent Commands,  Next: ForIndent Num,  Prev: Fortran Indent,  Up: Fortran Indent
  490. Fortran Indentation Commands
  491. ............................
  492. `TAB'
  493.      Indent the current line (`fortran-indent-line').
  494. `M-LFD'
  495.      Break the current line and set up a continuation line.
  496. `C-M-q'
  497.      Indent all the lines of the subprogram point is in
  498.      (`fortran-indent-subprogram').
  499.    TAB is redefined by Fortran mode to reindent the current line for
  500. Fortran (`fortran-indent-line').  Line numbers and continuation markers
  501. are indented to their required columns, and the body of the statement
  502. is independently indented based on its nesting in the program.
  503.    The key `C-M-q' is redefined as `fortran-indent-subprogram', a
  504. command to reindent all the lines of the Fortran subprogram (function or
  505. subroutine) containing point.
  506.    The key `M-LFD' is redefined as `fortran-split-line', a command to
  507. split a line in the appropriate fashion for Fortran.  In a non-comment
  508. line, the second half becomes a continuation line and is indented
  509. accordingly.  In a comment line, both halves become separate comment
  510. lines.
  511. File: emacs,  Node: ForIndent Num,  Next: ForIndent Conv,  Prev: ForIndent Commands,  Up: Fortran Indent
  512. Line Numbers and Continuation
  513. .............................
  514.    If a number is the first non-whitespace in the line, it is assumed
  515. to be a line number and is moved to columns 0 through 4.  (Columns are
  516. always counted from 0 in GNU Emacs.)  If the text on the line starts
  517. with the conventional Fortran continuation marker `$', it is moved to
  518. column 5. If the text begins with any non whitespace character in
  519. column 5, it is assumed to be an unconventional continuation marker and
  520. remains in column 5.
  521.    Line numbers of four digits or less are normally indented one space.
  522. This amount is controlled by the variable `fortran-line-number-indent'
  523. which is the maximum indentation a line number can have.  Line numbers
  524. are indented to right-justify them to end in column 4 unless that would
  525. require more than this maximum indentation.  The default value of the
  526. variable is 1.
  527.    Simply inserting a line number is enough to indent it according to
  528. these rules.  As each digit is inserted, the indentation is recomputed.
  529.  To turn off this feature, set the variable
  530. `fortran-electric-line-number' to `nil'.  Then inserting line numbers
  531. is like inserting anything else.
  532. File: emacs,  Node: ForIndent Conv,  Next: ForIndent Vars,  Prev: ForIndent Num,  Up: Fortran Indent
  533. Syntactic Conventions
  534. .....................
  535.    Fortran mode assumes that you follow certain conventions that
  536. simplify the task of understanding a Fortran program well enough to
  537. indent it properly:
  538.    * Two nested `do' loops never share a `continue' statement.
  539.    * The same character appears in column 5 of all continuation lines,
  540.      and this character is the value of the variable
  541.      `fortran-continuation-char'. By default, this character is `$'.
  542. If you fail to follow these conventions, the indentation commands may
  543. indent some lines unaesthetically.  However, a correct Fortran program
  544. will retain its meaning when reindented even if the conventions are not
  545. followed.
  546. File: emacs,  Node: ForIndent Vars,  Prev: ForIndent Conv,  Up: Fortran Indent
  547. Variables for Fortran Indentation
  548. .................................
  549.    Several additional variables control how Fortran indentation works.
  550. `fortran-do-indent'
  551.      Extra indentation within each level of `do' statement
  552.      (default 3).
  553. `fortran-if-indent'
  554.      Extra indentation within each level of `if' statement
  555.      (default 3).
  556. `fortran-continuation-indent'
  557.      Extra indentation for bodies of continuation lines (default 5).
  558. `fortran-check-all-num-for-matching-do'
  559.      If this is `nil', indentation assumes that each `do' statement
  560.      ends on a `continue' statement.  Therefore, when computing
  561.      indentation for a statement other than `continue', it can save
  562.      time by not checking for a `do' statement ending there. If this is
  563.      non-`nil', indenting any numbered statement must check for a `do'
  564.      that ends there.  The default is `nil'.
  565. `fortran-minimum-statement-indent'
  566.      Minimum indentation for fortran statements.  For standard Fortran,
  567.      this is 6.  Statement bodies will never be indented less than this
  568.      much.
  569. File: emacs,  Node: Fortran Comments,  Next: Fortran Columns,  Prev: Fortran Indent,  Up: Fortran
  570. Comments
  571. --------
  572.    The usual Emacs comment commands assume that a comment can follow a
  573. line of code.  In Fortran, the standard comment syntax requires an
  574. entire line to be just a comment.  Therefore, Fortran mode replaces the
  575. standard Emacs comment commands and defines some new variables.
  576.    Fortran mode can also handle a nonstandard comment syntax where
  577. comments start with `!' and can follow other text.  Because only some
  578. Fortran compilers accept this syntax, Fortran mode will not insert such
  579. comments unless you have said in advance to do so.  To do this, set the
  580. variable `comment-start' to `"!"' (*note Variables::.).
  581. `M-;'
  582.      Align comment or insert new comment (`fortran-comment-indent').
  583. `C-x ;'
  584.      Applies to nonstandard `!' comments only.
  585. `C-c ;'
  586.      Turn all lines of the region into comments, or (with arg) turn
  587.      them back into real code (`fortran-comment-region').
  588.    `M-;' in Fortran mode is redefined as the command
  589. `fortran-comment-indent'.  Like the usual `M-;' command, this
  590. recognizes any kind of existing comment and aligns its text
  591. appropriately; if there is no existing comment, a comment is inserted
  592. and aligned.  But inserting and aligning comments are not the same in
  593. Fortran mode as in other modes.
  594.    When a new comment must be inserted, if the current line is blank, a
  595. full-line comment is inserted.  On a non-blank line, a nonstandard `!'
  596. comment is inserted if you have said you want to use them.  Otherwise a
  597. full-line comment is inserted on a new line before the current line.
  598.    Nonstandard `!' comments are aligned like comments in other
  599. languages, but full-line comments are different.  In a standard
  600. full-line comment, the comment delimiter itself must always appear in
  601. column zero. What can be aligned is the text within the comment.  You
  602. can choose from three styles of alignment by setting the variable
  603. `fortran-comment-indent-style' to one of these values:
  604. `fixed'
  605.      The text is aligned at a fixed column, which is the value of
  606.      `fortran-comment-line-column'.  This is the default.
  607. `relative'
  608.      The text is aligned as if it were a line of code, but with an
  609.      additional `fortran-comment-line-column' columns of indentation.
  610. `nil'
  611.      Text in full-line columns is not moved automatically.
  612.    In addition, you can specify the character to be used to indent
  613. within full-line comments by setting the variable
  614. `fortran-comment-indent-char' to the character you want to use.
  615.    Fortran mode introduces the two variables, `comment-line-start' and
  616. `comment-line-start-skip', which play for full-line comments the same
  617. roles played by `comment-start' and `comment-start-skip' for ordinary
  618. text-following comments.  Normally these are set properly by Fortran
  619. mode so you do not need to change them.
  620.    The normal Emacs comment command `C-x ;' has not been redefined. If
  621. you use `!' comments, this command can be used with them.  Otherwise it
  622. is useless in Fortran mode.
  623.    The command `C-c ;' (`fortran-comment-region') turns all the lines
  624. of the region into comments by inserting the string `C$$$' at the front
  625. of each one.  With a numeric arg, the region is turned back into live
  626. code by deleting `C$$$' from the front of each line in it.  The string
  627. used for these comments can be controlled by setting the variable
  628. `fortran-comment-region'.  Note that here we have an example of a
  629. command and a variable with the same name; these two uses of the name
  630. never conflict because in Lisp and in Emacs it is always clear from the
  631. context which one is meant.
  632. File: emacs,  Node: Fortran Columns,  Next: Fortran Abbrev,  Prev: Fortran Comments,  Up: Fortran
  633. Columns
  634. -------
  635. `C-c C-r'
  636.      Displays a "column ruler" momentarily above the current line
  637.      (`fortran-column-ruler').
  638. `C-c C-w'
  639.      Splits the current window horizontally so that it is 72 columns
  640.      wide. This may help you avoid going over that limit
  641.      (`fortran-window-create').
  642.    The command `C-c C-r' (`fortran-column-ruler') shows a column ruler
  643. momentarily above the current line.  The comment ruler is two lines of
  644. text that show you the locations of columns with special significance
  645. in Fortran programs.  Square brackets show the limits of the columns for
  646. line numbers, and curly brackets show the limits of the columns for the
  647. statement body.  Column numbers appear above them.
  648.    Note that the column numbers count from zero, as always in GNU
  649. Emacs.  As a result, the numbers may not be those you are familiar
  650. with; but the actual positions in the line are standard Fortran.
  651.    The text used to display the column ruler is the value of the
  652. variable `fortran-comment-ruler'.  By changing this variable, you can
  653. change the display.
  654.    For even more help, use `C-c C-w' (`fortran-window-create'), a
  655. command which splits the current window horizontally, making a window 72
  656. columns wide.  By editing in this window you can immediately see when
  657. you make a line too wide to be correct Fortran.
  658. File: emacs,  Node: Fortran Abbrev,  Prev: Fortran Columns,  Up: Fortran
  659. Fortran Keyword Abbrevs
  660. -----------------------
  661.    Fortran mode provides many built-in abbrevs for common keywords and
  662. declarations.  These are the same sort of abbrev that you can define
  663. yourself.  To use them, you must turn on Abbrev mode (*note Abbrevs::.).
  664.    The built-in abbrevs are unusual in one way: they all start with a
  665. semicolon.  You cannot normally use semicolons in an abbrev, but Fortran
  666. mode makes this possible by changing the syntax of semicolon to "word
  667. constituent".
  668.    For example, one built-in Fortran abbrev is `;c' for `continue'.  If
  669. you insert `;c' and then insert a punctuation character such as a space
  670. or a newline, the `;c' will change automatically to `continue',
  671. provided Abbrev mode is enabled.
  672.    Type `;?' or `;C-h' to display a list of all the built-in Fortran
  673. abbrevs and what they stand for.
  674. File: emacs,  Node: Compiling/Testing,  Next: Abbrevs,  Prev: Programs,  Up: Top
  675. Compiling and Testing Programs
  676. ******************************
  677.    The previous chapter discusses the Emacs commands that are useful for
  678. making changes in programs.  This chapter deals with commands that
  679. assist in the larger process of developing and maintaining programs.
  680. * Menu:
  681. * Compilation::        Compiling programs in languages other than Lisp
  682.                         (C, Pascal, etc.)
  683. * Modes: Lisp Modes.   Various modes for editing Lisp programs, with
  684.                        different facilities for running the Lisp programs.
  685. * Libraries: Lisp Libraries.      Creating Lisp programs to run in Emacs.
  686. * Interaction: Lisp Interaction.  Executing Lisp in an Emacs buffer.
  687. * Eval: Lisp Eval.     Executing a single Lisp expression in Emacs.
  688. * Debug: Lisp Debug.   Debugging Lisp programs running in Emacs.
  689. * External Lisp::      Communicating through Emacs with a separate Lisp.
  690. File: emacs,  Node: Compilation,  Next: Lisp Modes,  Prev: Compiling/Testing,  Up: Compiling/Testing
  691. Running `make', or Compilers Generally
  692. ======================================
  693.    Emacs can run compilers for noninteractive languages such as C and
  694. Fortran as inferior processes, feeding the error log into an Emacs
  695. buffer. It can also parse the error messages and visit the files in
  696. which errors are found, moving point right to the line where the error
  697. occurred.
  698. `M-x compile'
  699.      Run a compiler asynchronously under Emacs, with error messages to
  700.      `*compilation*' buffer.
  701. `M-x grep'
  702.      Run `grep' asynchronously under Emacs, with matching lines listed
  703.      in the buffer named `*compilation*'.
  704. `M-x kill-compilation'
  705. `M-x kill-grep'
  706.      Kill the running compilation or `grep' subprocess.
  707. `C-x `'
  708.      Visit the locus of the next compiler error message or `grep' match.
  709.    To run `make' or another compiler, do `M-x compile'.  This command
  710. reads a shell command line using the minibuffer, and then executes the
  711. specified command line in an inferior shell with output going to the
  712. buffer named `*compilation*'.  The current buffer's default directory
  713. is used as the working directory for the execution of the command;
  714. normally, therefore, the makefile comes from this directory.
  715.    When the shell command line is read, the minibuffer appears
  716. containing a default command line, which is the command you used the
  717. last time you did `M-x compile'.  If you type just RET, the same
  718. command line is used again.  The first `M-x compile' provides `make -k'
  719. as the default. The default is taken from the variable
  720. `compile-command'; if the appropriate compilation command for a file is
  721. something other than `make -k', it can be useful to have the file
  722. specify a local value for `compile-command' (*note File Variables::.).
  723.    Starting a compilation causes the buffer `*compilation*' to be
  724. displayed in another window but not selected.  Its mode line tells you
  725. whether compilation is finished, with the word `run' or `exit' inside
  726. the parentheses.  You do not have to keep this buffer visible;
  727. compilation continues in any case.
  728.    To kill the compilation process, do `M-x kill-compilation'.  You will
  729. see that the mode line of the `*compilation*' buffer changes to say
  730. `signal' instead of `run'.  Starting a new compilation also kills any
  731. running compilation, as only one can exist at any time.  However, this
  732. requires confirmation before actually killing a compilation that is
  733. running.
  734.    To parse the compiler error messages, type `C-x `' (`next-error'). 
  735. The character following the `C-x' is the grave accent, not the single
  736. quote.  This command displays the buffer `*compilation*' in one window
  737. and the buffer in which the next error occurred in another window. 
  738. Point in that buffer is moved to the line where the error was found. 
  739. The corresponding error message is scrolled to the top of the window in
  740. which `*compilation*' is displayed.
  741.    The first time `C-x `' is used after the start of a compilation, it
  742. parses all the error messages, visits all the files that have error
  743. messages, and makes markers pointing at the lines that the error
  744. messages refer to.  Then it moves to the first error message location. 
  745. Subsequent uses of `C-x `' advance down the data set up by the first
  746. use.  When the preparsed error messages are exhausted, the next `C-x `'
  747. checks for any more error messages that have come in; this is useful if
  748. you start editing the compiler errors while the compilation is still
  749. going on.  If no more error messages have come in, `C-x `' reports an
  750. error.
  751.    `C-u C-x `' discards the preparsed error message data and parses the
  752. `*compilation*' buffer over again, then displaying the first error.
  753. This way, you can process the same set of errors again.
  754.    Instead of running a compiler, you can run `grep' and see the lines
  755. on which matches were found.  To do this, type `M-x grep' with an
  756. argument line that contains the same arguments you would give `grep'
  757. when running it normally: a `grep'-style regexp (usually in
  758. singlequotes to quote the shell's special characters) followed by
  759. filenames which may use wildcards. The output from `grep' goes in the
  760. `*compilation*' buffer and the lines that matched can be found with
  761. `C-x `' as if they were compilation errors.
  762.    Note: a shell is used to run the compile command, but the shell is
  763. told that it should be noninteractive.  This means in particular that
  764. the shell starts up with no prompt.  If you find your usual shell
  765. prompt making an unsightly appearance in the `*compilation*' buffer, it
  766. means you have made a mistake in your shell's init file (`.cshrc' or
  767. `.shrc' or ...) by setting the prompt unconditionally.  The shell init
  768. file should set the prompt only if there already is a prompt.
  769.    Here is how to do it in `csh':
  770.      if ($?prompt) set prompt = ...
  771.    Here is how to do it in the Bourne-Again shell:
  772.      if [ ! "$PS1" ]; then
  773.         PS1=...
  774.      fi
  775. File: emacs,  Node: Lisp Modes,  Next: Lisp Libraries,  Prev: Compilation,  Up: Compiling/Testing
  776. Major Modes for Lisp
  777. ====================
  778.    Emacs has four different major modes for Lisp.  They are the same in
  779. terms of editing commands, but differ in the commands for executing Lisp
  780. expressions.
  781. Emacs-Lisp mode
  782.      The mode for editing source files of programs to run in Emacs Lisp.
  783.      This mode defines `C-M-x' to evaluate the current defun. *Note
  784.      Lisp Libraries::.
  785. Lisp Interaction mode
  786.      The mode for an interactive session with Emacs Lisp.  It defines
  787.      LFD to evaluate the sexp before point and insert its value in the
  788.      buffer.  *Note Lisp Interaction::.
  789. Lisp mode
  790.      The mode for editing source files of programs that run in Lisps
  791.      other than Emacs Lisp.  This mode defines `C-M-x' to send the
  792.      current defun to an inferior Lisp process.  *Note External Lisp::.
  793. Inferior Lisp mode
  794.      The mode for an interactive session with an inferior Lisp process.
  795.      This mode combines the special features of Lisp mode and Shell mode
  796.      (*note Shell Mode::.).
  797. Scheme mode
  798.      Like Lisp mode but for Scheme programs.
  799. Inferior Scheme mode
  800.      The mode for an interactive session with an inferior Scheme
  801.      process.
  802. File: emacs,  Node: Lisp Libraries,  Next: Lisp Eval,  Prev: Lisp Modes,  Up: Compiling/Testing
  803. Libraries of Lisp Code for Emacs
  804. ================================
  805.    Lisp code for Emacs editing commands is stored in files whose names
  806. conventionally end in `.el'.  This ending tells Emacs to edit them in
  807. Emacs-Lisp mode (*note Lisp Modes::.).
  808. * Menu:
  809. * Loading::        Loading libraries of Lisp code into Emacs for use.
  810. * Compiling Libraries:: Compiling a library makes it load and run faster.
  811. * Mocklisp::        Converting Mocklisp to Lisp so GNU Emacs can run it.
  812. File: emacs,  Node: Loading,  Next: Compiling Libraries,  Prev: Lisp Libraries,  Up: Lisp Libraries
  813. Loading Libraries
  814. -----------------
  815.    To execute a file of Emacs Lisp, use `M-x load-file'.  This command
  816. reads a file name using the minibuffer and then executes the contents of
  817. that file as Lisp code.  It is not necessary to visit the file first;
  818. in any case, this command reads the file as found on disk, not text in
  819. an Emacs buffer.
  820.    Once a file of Lisp code is installed in the Emacs Lisp library
  821. directories, users can load it using `M-x load-library'.  Programs can
  822. load it by calling `load-library', or with `load', a more primitive
  823. function that is similar but accepts some additional arguments.
  824.    `M-x load-library' differs from `M-x load-file' in that it searches
  825. a sequence of directories and tries three file names in each directory.
  826.  The three names are, first, the specified name with `.elc' appended;
  827. second, with `.el' appended; third, the specified name alone.  A `.elc'
  828. file would be the result of compiling the Lisp file into byte code; it
  829. is loaded if possible in preference to the Lisp file itself because the
  830. compiled file will load and run faster.
  831.    Because the argument to `load-library' is usually not in itself a
  832. valid file name, file name completion is not available.  Indeed, when
  833. using this command, you usually do not know exactly what file name will
  834. be used.
  835.    The sequence of directories searched by `M-x load-library' is
  836. specified by the variable `load-path', a list of strings that are
  837. directory names.  The default value of the list contains the directory
  838. where the Lisp code for Emacs itself is stored.  If you have libraries
  839. of your own, put them in a single directory and add that directory to
  840. `load-path'.  `nil' in this list stands for the current default
  841. directory, but it is probably not a good idea to put `nil' in the list.
  842.  If you find yourself wishing that `nil' were in the list, most likely
  843. what you really want to do is use `M-x load-file' this once.
  844.    Often you do not have to give any command to load a library, because
  845. the commands defined in the library are set up to "autoload" that
  846. library. Running any of those commands causes `load' to be called to
  847. load the library; this replaces the autoload definitions with the real
  848. ones from the library.
  849.    If autoloading a file does not finish, either because of an error or
  850. because of a `C-g' quit, all function definitions made by the file are
  851. undone automatically.  So are any calls to `provide'.  As a consequence,
  852. if you use one of the autoloadable commands again, the entire file will
  853. be loaded a second time.  This prevents problems where the command is no
  854. longer autoloading but it works wrong because not all the file was
  855. loaded. Function definitions are undone only for autoloading; explicit
  856. calls to `load' do not undo anything if loading is not completed.
  857. File: emacs,  Node: Compiling Libraries,  Next: Mocklisp,  Prev: Loading,  Up: Lisp Libraries
  858. Compiling Libraries
  859. -------------------
  860.    Emacs Lisp code can be compiled into byte-code which loads faster,
  861. takes up less space when loaded, and executes faster.
  862.    The way to make a byte-code compiled file from an Emacs-Lisp source
  863. file is with `M-x byte-compile-file'.  The default argument for this
  864. function is the file visited in the current buffer.  It reads the
  865. specified file, compiles it into byte code, and writes an output file
  866. whose name is made by appending `c' to the input file name.  Thus, the
  867. file `rmail.el' would be compiled into `rmail.elc'.
  868.    To recompile the changed Lisp files in a directory, use `M-x
  869. byte-recompile-directory'.  Specify just the directory name as an
  870. argument. Each `.el' file that has been byte-compiled before is
  871. byte-compiled again if it has changed since the previous compilation. 
  872. A numeric argument to this command tells it to offer to compile each
  873. `.el' file that has not already been compiled.  You must answer `y' or
  874. `n' to each offer.
  875.    Emacs can be invoked noninteractively from the shell to do byte
  876. compilation with the aid of the function `batch-byte-compile'.  In this
  877. case, the files to be compiled are specified with command-line
  878. arguments. Use a shell command of the form
  879.      emacs -batch -f batch-byte-compile FILES...
  880.    Directory names may also be given as arguments;
  881. `byte-recompile-directory' is invoked (in effect) on each such
  882. directory. `batch-byte-compile' uses all the remaining command-line
  883. arguments as file or directory names, then kills the Emacs process.
  884.    `M-x disassemble' explains the result of byte compilation.  Its
  885. argument is a function name.  It displays the byte-compiled code in a
  886. help window in symbolic form, one instruction per line.  If the
  887. instruction refers to a variable or constant, that is shown too.
  888. File: emacs,  Node: Mocklisp,  Prev: Compiling Libraries,  Up: Lisp Libraries
  889. Converting Mocklisp to Lisp
  890. ---------------------------
  891.    GNU Emacs can run Mocklisp files by converting them to Emacs Lisp
  892. first. To convert a Mocklisp file, visit it and then type `M-x
  893. convert-mocklisp-buffer'.  Then save the resulting buffer of Lisp file
  894. in a file whose name ends in `.el' and use the new file as a Lisp
  895. library.
  896.    It does not currently work to byte-compile converted Mocklisp code.
  897. This is because converted Mocklisp code uses some special Lisp features
  898. to deal with Mocklisp's incompatible ideas of how arguments are
  899. evaluated and which values signify "true" or "false".
  900.