programs.texi 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313
  1. @c This is part of the Emacs manual.
  2. @c Copyright (C) 1985,86,87,93,94,95,97,99,00,2001 Free Software Foundation, Inc.
  3. @c See file emacs.texi for copying conditions.
  4. @node Programs, Building, Text, Top
  5. @chapter Editing Programs
  6. @cindex Lisp editing
  7. @cindex C editing
  8. @cindex program editing
  9. Emacs provides many features to facilitate editing programs. Some
  10. of these features can
  11. @itemize @bullet
  12. @item
  13. Find or move over top-level definitions (@pxref{Defuns}).
  14. @item
  15. Apply the usual indentation conventions of the language
  16. (@pxref{Program Indent}).
  17. @item
  18. Insert, kill or align comments (@pxref{Comments}).
  19. @item
  20. Balance parentheses (@pxref{Parentheses}).
  21. @item
  22. Highlight program syntax (@pxref{Font Lock}).
  23. @end itemize
  24. This chapter describes these features and many more.
  25. @menu
  26. * Program Modes:: Major modes for editing programs.
  27. * Defuns:: Commands to operate on major top-level parts
  28. of a program.
  29. * Program Indent:: Adjusting indentation to show the nesting.
  30. * Comments:: Inserting, killing, and aligning comments.
  31. * Parentheses:: Commands that operate on parentheses.
  32. * Documentation:: Getting documentation of functions you plan to call.
  33. * Hideshow:: Displaying blocks selectively.
  34. * Symbol Completion:: Completion on symbol names of your program or language.
  35. * Glasses:: Making identifiersLikeThis more readable.
  36. * Misc for Programs:: Other Emacs features useful for editing programs.
  37. * C Modes:: Special commands of C, C++, Objective-C,
  38. Java, and Pike modes.
  39. * Fortran:: Fortran mode and its special features.
  40. * Asm Mode:: Asm mode and its special features.
  41. @end menu
  42. @node Program Modes
  43. @section Major Modes for Programming Languages
  44. @cindex modes for programming languages
  45. Emacs has specialized major modes for various programming languages.
  46. @xref{Major Modes}. A programming language major mode typically
  47. specifies the syntax of expressions, the customary rules for
  48. indentation, how to do syntax highlighting for the language, and how
  49. to find the beginning of a function definition. It often customizes
  50. or provides facilities for compiling and debugging programs as well.
  51. Ideally, Emacs should provide a major mode for each programming
  52. language that you might want to edit; if it doesn't have a mode for
  53. your favorite language, you can contribute one. But often the mode
  54. for one language can serve for other syntactically similar languages.
  55. The major mode for language @var{l} is called @code{@var{l}-mode},
  56. and you can select it by typing @kbd{M-x @var{l}-mode @key{RET}}.
  57. @xref{Choosing Modes}.
  58. @cindex Perl mode
  59. @cindex Icon mode
  60. @cindex Awk mode
  61. @cindex Makefile mode
  62. @cindex Tcl mode
  63. @cindex CPerl mode
  64. @cindex DSSSL mode
  65. @cindex Octave mode
  66. @cindex Metafont mode
  67. @cindex Modula2 mode
  68. @cindex Prolog mode
  69. @cindex Simula mode
  70. @cindex VHDL mode
  71. @cindex M4 mode
  72. @cindex Shell-script mode
  73. @cindex Delphi mode
  74. @cindex PostScript mode
  75. The existing programming language major modes include Lisp, Scheme (a
  76. variant of Lisp) and the Scheme-based DSSSL expression language, Ada,
  77. Awk, C, C++, Delphi (Object Pascal), Fortran (free format and fixed
  78. format), Icon, IDL (CORBA), IDLWAVE, Java, Metafont (@TeX{}'s
  79. companion for font creation), Modula2, Objective-C, Octave, Pascal,
  80. Perl, Pike, PostScript, Prolog, Simula, Tcl, and VHDL. There is
  81. also a major mode for makefiles, called Makefile mode. An alternative
  82. mode for Perl is called CPerl mode. Modes are available for the
  83. scripting languages of the common GNU and Unix shells, VMS DCL, and
  84. MS-DOS/MS-Windows @samp{BAT} files. There are also major modes for
  85. editing various sorts of configuration files.
  86. @kindex DEL @r{(programming modes)}
  87. @findex c-electric-backspace
  88. In most programming languages, indentation should vary from line to
  89. line to illustrate the structure of the program. So the major modes
  90. for programming languages arrange for @key{TAB} to update the
  91. indentation of the current line. They also rebind @key{DEL} to treat
  92. a tab as if it were the equivalent number of spaces; this lets you
  93. delete one column of indentation without worrying whether the
  94. whitespace consists of spaces or tabs. Use @kbd{C-b C-d} to delete a
  95. tab character before point, in these modes.
  96. Separate manuals are available for the modes for Ada (@pxref{Top, , Ada
  97. Mode, ada-mode, Ada Mode}), C/C++/Objective C/Java/Corba IDL
  98. (@pxref{Top, , CC Mode, ccmode, CC Mode}) and the IDLWAVE modes
  99. (@pxref{Top, , IDLWAVE, idlwave, IDLWAVE User Manual}).
  100. @cindex mode hook
  101. @vindex c-mode-hook
  102. @vindex lisp-mode-hook
  103. @vindex emacs-lisp-mode-hook
  104. @vindex lisp-interaction-mode-hook
  105. @vindex scheme-mode-hook
  106. Turning on a major mode runs a normal hook called the @dfn{mode
  107. hook}, which is the value of a Lisp variable. Each major mode has a
  108. mode hook, and the hook's name is always made from the mode command's
  109. name by adding @samp{-hook}. For example, turning on C mode runs the
  110. hook @code{c-mode-hook}, while turning on Lisp mode runs the hook
  111. @code{lisp-mode-hook}. The purpose of the mode hook is to give you a
  112. place to set up customizations for that major mode. @xref{Hooks}.
  113. @node Defuns
  114. @section Top-Level Definitions, or Defuns
  115. In Emacs, a major definition at the top level in the buffer is
  116. called a @dfn{defun}. The name comes from Lisp, but in Emacs we use
  117. it for all languages.
  118. In most programming language modes, Emacs assumes that a defun is
  119. any pair of parentheses (or braces, if the language uses braces this
  120. way) that starts at the left margin. For example, in C, the body of a
  121. function definition is normally a defun, because the open-brace that
  122. begins it is normally at the left margin. A variable's initializer
  123. can also count as a defun, if the open-brace that begins the
  124. initializer is at the left margin.
  125. However, some language modes provide their own code for recognizing
  126. defuns in a way that suits the language syntax and conventions better.
  127. @menu
  128. * Left Margin Paren:: An open-paren or similar opening delimiter
  129. starts a defun if it is at the left margin.
  130. * Moving by Defuns:: Commands to move over or mark a major definition.
  131. * Imenu:: Making buffer indexes as menus.
  132. * Which Function:: Which Function mode shows which function you are in.
  133. @end menu
  134. @node Left Margin Paren
  135. @subsection Left Margin Convention
  136. @cindex open-parenthesis in leftmost column
  137. @cindex ( in leftmost column
  138. In most major modes, Emacs assumes that any opening delimiter found
  139. at the left margin is the start of a top-level definition, or defun.
  140. Therefore, @strong{never put an opening delimiter at the left margin
  141. unless it should have that significance.} For instance, never put an
  142. open-parenthesis at the left margin in a Lisp file unless it is the
  143. start of a top-level list. Never put an open-brace or other opening
  144. delimiter at the beginning of a line of C code unless it is at top
  145. level.
  146. If you don't follow this convention, not only will you have trouble
  147. when you explicitly use the commands for motion by defuns; other
  148. features that use them will also give you trouble. This includes
  149. the indentation commands (@pxref{Program Indent}) and Font Lock
  150. mode (@pxref{Font Lock}).
  151. The most likely problem case is when you want an opening delimiter
  152. at the start of a line inside a string. To avoid trouble, put an
  153. escape character (@samp{\}, in C and Emacs Lisp, @samp{/} in some
  154. other Lisp dialects) before the opening delimiter. This will not
  155. affect the contents of the string, but will prevent that opening
  156. delimiter from starting a defun. Here's an example:
  157. @example
  158. (insert "Foo:
  159. \(bar)
  160. ")
  161. @end example
  162. In the earliest days, the original Emacs found defuns by moving
  163. upward a level of parentheses or braces until there were no more
  164. levels to go up. This always required scanning all the way back to
  165. the beginning of the buffer, even for a small function. To speed up
  166. the operation, we changed Emacs to assume that any opening delimiter
  167. at the left margin is the start of a defun. This heuristic is nearly
  168. always right, and avoids the need to scan back to the beginning of the
  169. buffer. However, it mandates following the convention described
  170. above.
  171. @node Moving by Defuns
  172. @subsection Moving by Defuns
  173. @cindex defuns
  174. These commands move point or set up the region based on top-level
  175. major definitions, also called @dfn{defuns}.
  176. @table @kbd
  177. @item C-M-a
  178. Move to beginning of current or preceding defun
  179. (@code{beginning-of-defun}).
  180. @item C-M-e
  181. Move to end of current or following defun (@code{end-of-defun}).
  182. @item C-M-h
  183. Put region around whole current or following defun (@code{mark-defun}).
  184. @end table
  185. @cindex move to beginning or end of function
  186. @cindex function, move to beginning or end
  187. @kindex C-M-a
  188. @kindex C-M-e
  189. @kindex C-M-h
  190. @findex beginning-of-defun
  191. @findex end-of-defun
  192. @findex mark-defun
  193. The commands to move to the beginning and end of the current defun
  194. are @kbd{C-M-a} (@code{beginning-of-defun}) and @kbd{C-M-e}
  195. (@code{end-of-defun}). If you repeat one of these commands, or use a
  196. positive numeric argument, each repetition moves to the next defun in
  197. the direction of motion.
  198. @kbd{C-M-a} with a negative argument @minus{}@var{n} moves forward
  199. @var{n} times to the next beginning of a defun. This is not exactly
  200. the same place that @kbd{C-M-e} with argument @var{n} would move to;
  201. the end of this defun is not usually exactly the same place as the
  202. beginning of the following defun. (Whitespace, comments, and perhaps
  203. declarations can separate them.) Likewise, @kbd{C-M-e} with a
  204. negative argument moves back to an end of a defun, which is not quite
  205. the same as @kbd{C-M-a} with a positive argument.
  206. @kindex C-M-h @r{(C mode)}
  207. @findex c-mark-function
  208. To operate on the current defun, use @kbd{C-M-h} (@code{mark-defun})
  209. which puts point at the beginning and mark at the end of the current
  210. defun. This is the easiest way to get ready to kill the defun in
  211. order to move it to a different place in the file. If you use the
  212. command while point is between defuns, it uses the following defun.
  213. In C mode, @kbd{C-M-h} runs the function @code{c-mark-function},
  214. which is almost the same as @code{mark-defun}; the difference is that
  215. it backs up over the argument declarations, function name and returned
  216. data type so that the entire C function is inside the region. This is
  217. an example of how major modes adjust the standard key bindings so that
  218. they do their standard jobs in a way better fitting a particular
  219. language. Other major modes may replace any or all of these key
  220. bindings for that purpose.
  221. @node Imenu
  222. @subsection Imenu
  223. @cindex index of buffer definitions
  224. @cindex buffer definitions index
  225. @cindex tags
  226. The Imenu facility offers a way to find the major definitions in
  227. a file by name. It is also useful in text formatter major modes,
  228. where it treats each chapter, section, etc., as a definition.
  229. (@xref{Tags}, for a more powerful feature that handles multiple files
  230. together.)
  231. @findex imenu
  232. If you type @kbd{M-x imenu}, it reads the name of a definition using
  233. the minibuffer, then moves point to that definition. You can use
  234. completion to specify the name; the command always displays the whole
  235. list of valid names.
  236. @findex imenu-add-menubar-index
  237. Alternatively, you can bind the command @code{imenu} to a mouse
  238. click. Then it displays mouse menus for you to select a definition
  239. name. You can also add the buffer's index to the menu bar by calling
  240. @code{imenu-add-menubar-index}. If you want to have this menu bar
  241. item available for all buffers in a certain major mode, you can do
  242. this by adding @code{imenu-add-menubar-index} to its mode hook. But
  243. if you have done that, you will have to wait each time you visit a
  244. file in that mode, while Emacs finds all the definitions in that
  245. buffer.
  246. @vindex imenu-auto-rescan
  247. When you change the contents of a buffer, if you add or delete
  248. definitions, you can update the buffer's index based on the
  249. new contents by invoking the @samp{*Rescan*} item in the menu.
  250. Rescanning happens automatically if you set @code{imenu-auto-rescan} to
  251. a non-@code{nil} value. There is no need to rescan because of small
  252. changes in the text.
  253. @vindex imenu-sort-function
  254. You can customize the way the menus are sorted by setting the
  255. variable @code{imenu-sort-function}. By default, names are ordered as
  256. they occur in the buffer; if you want alphabetic sorting, use the
  257. symbol @code{imenu--sort-by-name} as the value. You can also
  258. define your own comparison function by writing Lisp code.
  259. Imenu provides the information to guide Which Function mode
  260. @ifnottex
  261. (@pxref{Which Function}).
  262. @end ifnottex
  263. @iftex
  264. (see below).
  265. @end iftex
  266. The Speedbar can also use it (@pxref{Speedbar}).
  267. @node Which Function
  268. @subsection Which Function Mode
  269. @cindex current function name in mode line
  270. Which Function mode is a minor mode that displays the current
  271. function name in the mode line, updating it as you move around in a
  272. buffer.
  273. @findex which-function-mode
  274. @vindex which-func-modes
  275. To enable (or disable) Which Function mode, use the command @kbd{M-x
  276. which-function-mode}. This command is global; it applies to all
  277. buffers, both existing ones and those yet to be created. However,
  278. it only takes effect in certain major modes, those listed in the value of
  279. @code{which-func-modes}. If the value is @code{t}, then Which
  280. Function mode applies to all major modes that know how to support
  281. it---in other words, all the major modes that support Imenu.
  282. @node Program Indent
  283. @section Indentation for Programs
  284. @cindex indentation for programs
  285. The best way to keep a program properly indented is to use Emacs to
  286. reindent it as you change it. Emacs has commands to indent properly
  287. either a single line, a specified number of lines, or all of the lines
  288. inside a single parenthetical grouping.
  289. @menu
  290. * Basic Indent:: Indenting a single line.
  291. * Multi-line Indent:: Commands to reindent many lines at once.
  292. * Lisp Indent:: Specifying how each Lisp function should be indented.
  293. * C Indent:: Extra features for indenting C and related modes.
  294. * Custom C Indent:: Controlling indentation style for C and related modes.
  295. @end menu
  296. @cindex pretty-printer
  297. Emacs also provides a Lisp pretty-printer in the library @code{pp}.
  298. This program reformats a Lisp object with indentation chosen to look nice.
  299. @node Basic Indent
  300. @subsection Basic Program Indentation Commands
  301. The basic indentation commands indent a single line according to the
  302. usual conventions of the language you are editing.
  303. @table @kbd
  304. @item @key{TAB}
  305. Adjust indentation of current line.
  306. @item C-j
  307. Equivalent to @key{RET} followed by @key{TAB} (@code{newline-and-indent}).
  308. @item @key{LINEFEED}
  309. This key, if the keyboard has it, is another way to enter @kbd{C-j}.
  310. @end table
  311. @kindex TAB @r{(programming modes)}
  312. @findex c-indent-command
  313. @findex indent-line-function
  314. @findex indent-for-tab-command
  315. The basic indentation command is @key{TAB}, which gives the current line
  316. the correct indentation as determined from the previous lines. The
  317. function that @key{TAB} runs depends on the major mode; it is
  318. @code{indent-for-tab-command}
  319. in Lisp mode, @code{c-indent-command} in C mode, etc. These functions
  320. understand the syntax and conventions of different languages, but they all do
  321. conceptually the same job: @key{TAB} in any programming-language major mode
  322. inserts or deletes whitespace at the beginning of the current line,
  323. independent of where point is in the line. If point was inside the
  324. whitespace at the beginning of the line, @key{TAB} puts it at the end of
  325. that whitespace; otherwise, @key{TAB} keeps point fixed with respect to
  326. the characters around it.
  327. Use @kbd{C-q @key{TAB}} to insert a tab at point.
  328. @kindex C-j
  329. @findex newline-and-indent
  330. When entering lines of new code, use @kbd{C-j}
  331. (@code{newline-and-indent}), which is equivalent to a @key{RET}
  332. followed by a @key{TAB}. @kbd{C-j} at the end of a line creates a
  333. blank line and then gives it the appropriate indentation.
  334. @key{TAB} indents lines that start within a parenthetical grouping
  335. each under the preceding line (or the text after the parenthesis).
  336. Therefore, if you manually give one of these lines a nonstandard
  337. indentation, the lines below will tend to follow it. This behavior is
  338. convenient in cases where you have overridden the standard result of
  339. @key{TAB} because you find it unaesthetic for a particular line.
  340. Remember that an open-parenthesis, open-brace or other opening delimiter
  341. at the left margin is assumed by Emacs (including the indentation routines)
  342. to be the start of a function. Therefore, you must never have an opening
  343. delimiter in column zero that is not the beginning of a function, not even
  344. inside a string. This restriction is vital for making the indentation
  345. commands fast; you must simply accept it. @xref{Left Margin Paren},
  346. for more information on this.
  347. Normally, lines are indented with tabs and spaces. If you want Emacs
  348. to use spaces only, see @ref{Just Spaces}.
  349. @node Multi-line Indent
  350. @subsection Indenting Several Lines
  351. When you wish to reindent several lines of code which have been
  352. altered or moved to a different level in the parenthesis structure,
  353. you have several commands available.
  354. @table @kbd
  355. @item C-M-q
  356. Reindent all the lines within one parenthetical grouping(@code{indent-sexp}).
  357. @item C-M-\
  358. Reindent all lines in the region (@code{indent-region}).
  359. @item C-u @key{TAB}
  360. Shift an entire parenthetical grouping rigidly sideways so that its
  361. first line is properly indented.
  362. @item M-x indent-code-rigidly
  363. Shift all the lines in the region rigidly sideways, but do not alter
  364. lines that start inside comments and strings.
  365. @end table
  366. @kindex C-M-q
  367. @findex indent-sexp
  368. You can reindent the contents of a single parenthetical grouping by
  369. positioning point before the beginning of it and typing @kbd{C-M-q}
  370. (@code{indent-sexp} in Lisp mode, @code{c-indent-exp} in C mode; also
  371. bound to other suitable commands in other modes). The indentation of
  372. the line where the grouping starts is not changed; therefore, this
  373. changes only the relative indentation within the grouping, not its
  374. overall indentation. To correct that as well, type @key{TAB} first.
  375. Another way to specify the range to be reindented is with the
  376. region. The command @kbd{C-M-\} (@code{indent-region}) applies
  377. @key{TAB} to every line whose first character is between point and
  378. mark.
  379. @kindex C-u TAB
  380. If you like the relative indentation within a grouping, but not the
  381. indentation of its first line, you can type @kbd{C-u @key{TAB}} to
  382. reindent the whole grouping as a rigid unit. (This works in Lisp
  383. modes and C and related modes.) @key{TAB} with a numeric argument
  384. reindents the current line as usual, then reindents by the same amount
  385. all the lines in the parenthetical grouping starting on the current
  386. line. It is clever, though, and does not alter lines that start
  387. inside strings, or C preprocessor lines when in C mode.
  388. @findex indent-code-rigidly
  389. You can also perform this operation on the region, using the command
  390. @kbd{M-x indent-code-rigidly}. It rigidly shifts all the lines in the
  391. region sideways, like @code{indent-rigidly} does (@pxref{Indentation
  392. Commands}). It doesn't alter the indentation of lines that start
  393. inside a comment or a string, unless the region starts inside that
  394. comment or string.
  395. @node Lisp Indent
  396. @subsection Customizing Lisp Indentation
  397. @cindex customizing Lisp indentation
  398. The indentation pattern for a Lisp expression can depend on the function
  399. called by the expression. For each Lisp function, you can choose among
  400. several predefined patterns of indentation, or define an arbitrary one with
  401. a Lisp program.
  402. The standard pattern of indentation is as follows: the second line of the
  403. expression is indented under the first argument, if that is on the same
  404. line as the beginning of the expression; otherwise, the second line is
  405. indented underneath the function name. Each following line is indented
  406. under the previous line whose nesting depth is the same.
  407. @vindex lisp-indent-offset
  408. If the variable @code{lisp-indent-offset} is non-@code{nil}, it overrides
  409. the usual indentation pattern for the second line of an expression, so that
  410. such lines are always indented @code{lisp-indent-offset} more columns than
  411. the containing list.
  412. @vindex lisp-body-indent
  413. Certain functions override the standard pattern. Functions whose
  414. names start with @code{def} treat the second lines as the start of
  415. a @dfn{body}, by indenting the second line @code{lisp-body-indent}
  416. additional columns beyond the open-parenthesis that starts the
  417. expression.
  418. @cindex @code{lisp-indent-function} property
  419. You can override the standard pattern in various ways for individual
  420. functions, according to the @code{lisp-indent-function} property of the
  421. function name. There are four possibilities for this property:
  422. @table @asis
  423. @item @code{nil}
  424. This is the same as no property---use the standard indentation pattern.
  425. @item @code{defun}
  426. Handle this function like a @samp{def} construct: treat the second
  427. line as the start of a @dfn{body}.
  428. @item a number, @var{number}
  429. The first @var{number} arguments of the function are
  430. @dfn{distinguished} arguments; the rest are considered the body
  431. of the expression. A line in the expression is indented according to
  432. whether the first argument on it is distinguished or not. If the
  433. argument is part of the body, the line is indented @code{lisp-body-indent}
  434. more columns than the open-parenthesis starting the containing
  435. expression. If the argument is distinguished and is either the first
  436. or second argument, it is indented @emph{twice} that many extra columns.
  437. If the argument is distinguished and not the first or second argument,
  438. the line uses the standard pattern.
  439. @item a symbol, @var{symbol}
  440. @var{symbol} should be a function name; that function is called to
  441. calculate the indentation of a line within this expression. The
  442. function receives two arguments:
  443. @table @asis
  444. @item @var{state}
  445. The value returned by @code{parse-partial-sexp} (a Lisp primitive for
  446. indentation and nesting computation) when it parses up to the
  447. beginning of this line.
  448. @item @var{pos}
  449. The position at which the line being indented begins.
  450. @end table
  451. @noindent
  452. It should return either a number, which is the number of columns of
  453. indentation for that line, or a list whose car is such a number. The
  454. difference between returning a number and returning a list is that a
  455. number says that all following lines at the same nesting level should
  456. be indented just like this one; a list says that following lines might
  457. call for different indentations. This makes a difference when the
  458. indentation is being computed by @kbd{C-M-q}; if the value is a
  459. number, @kbd{C-M-q} need not recalculate indentation for the following
  460. lines until the end of the list.
  461. @end table
  462. @node C Indent
  463. @subsection Commands for C Indentation
  464. Here are special features for indentation in C mode and related modes:
  465. @table @code
  466. @item C-c C-q
  467. @kindex C-c C-q @r{(C mode)}
  468. @findex c-indent-defun
  469. Reindent the current top-level function definition or aggregate type
  470. declaration (@code{c-indent-defun}).
  471. @item C-M-q
  472. @kindex C-M-q @r{(C mode)}
  473. @findex c-indent-exp
  474. Reindent each line in the balanced expression that follows point
  475. (@code{c-indent-exp}). A prefix argument inhibits error checking and
  476. warning messages about invalid syntax.
  477. @item @key{TAB}
  478. @findex c-indent-command
  479. Reindent the current line, and/or in some cases insert a tab character
  480. (@code{c-indent-command}).
  481. If @code{c-tab-always-indent} is @code{t}, this command always reindents
  482. the current line and does nothing else. This is the default.
  483. If that variable is @code{nil}, this command reindents the current line
  484. only if point is at the left margin or in the line's indentation;
  485. otherwise, it inserts a tab (or the equivalent number of spaces,
  486. if @code{indent-tabs-mode} is @code{nil}).
  487. Any other value (not @code{nil} or @code{t}) means always reindent the
  488. line, and also insert a tab if within a comment, a string, or a
  489. preprocessor directive.
  490. @end table
  491. To reindent the whole current buffer, type @kbd{C-x h C-M-\}. This
  492. first selects the whole buffer as the region, then reindents that
  493. region.
  494. To reindent the current block, use @kbd{C-M-u C-M-q}. This moves
  495. to the front of the block and then reindents it all.
  496. @node Custom C Indent
  497. @subsection Customizing C Indentation
  498. @cindex style (for indentation)
  499. C mode and related modes use a simple yet flexible mechanism for
  500. customizing indentation. The mechanism works in two steps: first it
  501. classifies the line syntactically according to its contents and context;
  502. second, it associates each kind of syntactic construct with an
  503. indentation offset based on your selected @dfn{style}.
  504. @table @kbd
  505. @item M-x c-set-style @key{RET} @var{style} @key{RET}
  506. Select predefined indentation style @var{style}.
  507. @end table
  508. A style is a named collection of indentation customizations that can
  509. be used in C mode and the related modes. Emacs comes with several
  510. predefined styles, including @code{gnu}, @code{k&r}, @code{bsd},
  511. @code{stroustrup}, @code{linux}, @code{python}, @code{java},
  512. @code{whitesmith}, @code{ellemtel}, @code{cc-mode}, and @code{user}.
  513. Some of these styles are primarily intended for one language, but any
  514. of them can be used with any of the languages supported by these
  515. modes. To find out what a style looks like, select it and reindent
  516. some code, e.g., by typing @key{C-M-q} at the start of a function
  517. definition.
  518. @findex c-set-style
  519. To choose a style for the current buffer, use the command @kbd{M-x
  520. c-set-style}. Specify a style name as an argument (case is not
  521. significant). This command affects the current buffer only, and it
  522. affects only future invocations of the indentation commands; it does
  523. not reindent the code in the buffer. To reindent the whole buffer in
  524. the new style, you can type @kbd{C-x h C-M-\}.
  525. @vindex c-default-style
  526. You can also set the variable @code{c-default-style} to specify the
  527. default style for various major modes. Its value should be an alist,
  528. in which each element specifies one major mode and which indentation
  529. style to use for it. For example,
  530. @example
  531. (setq c-default-style
  532. '((java-mode . "java") (other . "gnu")))
  533. @end example
  534. @noindent
  535. specifies an explicit choice for Java mode, and the default @samp{gnu}
  536. style for the other C-like modes. This variable takes effect when you
  537. select one of the C-like major modes; thus, if you specify a new
  538. default style for Java mode, you can make it take effect in an
  539. existing Java mode buffer by typing @kbd{M-x java-mode} there.
  540. The @code{gnu} style specifies the formatting recommended by the GNU
  541. Project for C; it is the default, so as to encourage use of our
  542. recommended style.
  543. @xref{Customizing Indentation,,, ccmode, the CC Mode Manual}, for
  544. more information on customizing indentation for C and related modes,
  545. including how to override parts of an existing style and how to define
  546. your own styles.
  547. @node Parentheses
  548. @section Commands for Editing with Parentheses
  549. @findex check-parens
  550. @cindex unbalanced parentheses and quotes
  551. This section describes the commands and features that take advantage
  552. of the parenthesis structure in a program, or help you keep it
  553. balanced.
  554. When talking about these facilities, the term ``parenthesis'' also
  555. includes braces, brackets, or whatever delimiters are defined to match
  556. in pairs. The major mode controls which delimiters are significant,
  557. through the syntax table (@pxref{Syntax}). In Lisp, only parentheses
  558. count; in C, these commands apply to braces and brackets too.
  559. You can use @kbd{M-x check-parens} to find any unbalanced
  560. parentheses and unbalanced string quotes in the buffer.
  561. @menu
  562. * Expressions:: Expressions with balanced parentheses.
  563. * Moving by Parens:: Commands for moving up, down and across
  564. in the structure of parentheses.
  565. * Matching:: Insertion of a close-delimiter flashes matching open.
  566. @end menu
  567. @node Expressions
  568. @subsection Expressions with Balanced Parentheses
  569. @cindex sexp
  570. @cindex expression
  571. @cindex balanced expression
  572. These commands deal with balanced expressions, also called
  573. @dfn{sexps}@footnote{The word ``sexp'' is used to refer to an
  574. expression in Lisp.}.
  575. @table @kbd
  576. @item C-M-f
  577. Move forward over a balanced expression (@code{forward-sexp}).
  578. @item C-M-b
  579. Move backward over a balanced expression(@code{backward-sexp}).
  580. @item C-M-k
  581. Kill balanced expression forward (@code{kill-sexp}).
  582. @item C-M-@key{DEL}
  583. Kill balanced expression backward (@code{backward-kill-sexp}).
  584. @item C-M-t
  585. Transpose expressions (@code{transpose-sexps}).
  586. @item C-M-@@
  587. Put mark after following expression (@code{mark-sexp}).
  588. @end table
  589. Each programming language major mode customizes the definition of
  590. balanced expressions to suit that language. Balanced expressions
  591. typically include symbols, numbers, and string constants, as well as
  592. any pair of matching delimiters and their contents. Some languages
  593. have obscure forms of expression syntax that nobody has bothered to
  594. implement in Emacs.
  595. @cindex Control-Meta
  596. By convention, the keys for these commands are all Control-Meta
  597. characters. They usually act on expressions just as the corresponding
  598. Meta characters act on words. For instance, the command @kbd{C-M-b}
  599. moves backward over a balanced expression, just as @kbd{M-b} moves
  600. back over a word.
  601. @kindex C-M-f
  602. @kindex C-M-b
  603. @findex forward-sexp
  604. @findex backward-sexp
  605. To move forward over a balanced expression, use @kbd{C-M-f}
  606. (@code{forward-sexp}). If the first significant character after point
  607. is an opening delimiter (@samp{(} in Lisp; @samp{(}, @samp{[} or
  608. @samp{@{} in C), @kbd{C-M-f} moves past the matching closing
  609. delimiter. If the character begins a symbol, string, or number,
  610. @kbd{C-M-f} moves over that.
  611. The command @kbd{C-M-b} (@code{backward-sexp}) moves backward over a
  612. balanced expression. The detailed rules are like those above for
  613. @kbd{C-M-f}, but with directions reversed. If there are prefix
  614. characters (single-quote, backquote and comma, in Lisp) preceding the
  615. expression, @kbd{C-M-b} moves back over them as well. The balanced
  616. expression commands move across comments as if they were whitespace,
  617. in most modes.
  618. @kbd{C-M-f} or @kbd{C-M-b} with an argument repeats that operation the
  619. specified number of times; with a negative argument, it moves in the
  620. opposite direction.
  621. @cindex killing expressions
  622. @kindex C-M-k
  623. @findex kill-sexp
  624. @kindex C-M-DEL
  625. @findex backward-kill-sexp
  626. Killing a whole balanced expression can be done with @kbd{C-M-k}
  627. (@code{kill-sexp}) or @kbd{C-M-@key{DEL}} (@code{backward-kill-sexp}).
  628. @kbd{C-M-k} kills the characters that @kbd{C-M-f} would move over, and
  629. @kbd{C-M-@key{DEL}} kills the characters that @kbd{C-M-b} would move
  630. over. On some machines, @kbd{C-M-@key{DEL}} typed on the console is a
  631. command to reboot; when that is so, you cannot use it as an Emacs
  632. command. This conflict is rare, though: usually the @key{DEL} key for
  633. Emacs is really @key{BACKSPACE}, and the reboot command is
  634. @kbd{C-M-@key{DELETE}}, so there is no conflict.
  635. @cindex transposition of expressions
  636. @kindex C-M-t
  637. @findex transpose-sexps
  638. A somewhat random-sounding command which is nevertheless handy is
  639. @kbd{C-M-t} (@code{transpose-sexps}), which drags the previous
  640. balanced expression across the next one. An argument serves as a
  641. repeat count, and a negative argument drags the previous balanced
  642. expression backwards across those before it (thus canceling out the
  643. effect of @kbd{C-M-t} with a positive argument). An argument of zero,
  644. rather than doing nothing, transposes the balanced expressions ending
  645. at or after point and the mark.
  646. @kindex C-M-@@
  647. @findex mark-sexp
  648. To set the region around the next balanced expression in the buffer,
  649. use @kbd{C-M-@@} (@code{mark-sexp}), which sets mark at the same place
  650. that @kbd{C-M-f} would move to. @kbd{C-M-@@} takes arguments like
  651. @kbd{C-M-f}. In particular, a negative argument is useful for putting
  652. the mark at the beginning of the previous balanced expression.
  653. In languages that use infix operators, such as C, it is not possible
  654. to recognize all balanced expressions as such because there can be
  655. multiple possibilities at a given position. For example, C mode does
  656. not treat @samp{foo + bar} as a single expression, even though it
  657. @emph{is} one C expression; instead, it recognizes @samp{foo} as one
  658. expression and @samp{bar} as another, with the @samp{+} as punctuation
  659. between them. Both @samp{foo + bar} and @samp{foo} are legitimate
  660. choices for ``the expression following point'' when point is at the
  661. @samp{f}, so the expression commands must perforce choose one or the
  662. other to operate on. Note that @samp{(foo + bar)} is recognized as a
  663. single expression in C mode, because of the parentheses.
  664. @node Moving by Parens
  665. @subsection Moving in the Parenthesis Structure
  666. @cindex parenthetical groupings
  667. @cindex parentheses, moving across
  668. @cindex matching parenthesis and braces, moving to
  669. @cindex braces, moving across
  670. @cindex list commands
  671. The Emacs commands for handling parenthetical groupings see nothing
  672. except parentheses (or whatever characters must balance in the
  673. language you are working with), and the escape characters that might
  674. be used to quote those. They are mainly intended for editing
  675. programs, but can be useful for editing any text that has parentheses.
  676. They are sometimes called ``list'' commands because in Lisp these
  677. groupings are lists.
  678. @table @kbd
  679. @item C-M-n
  680. Move forward over a parenthetical group (@code{forward-list}).
  681. @item C-M-p
  682. Move backward over a parenthetical group(@code{backward-list}).
  683. @item C-M-u
  684. Move up in parenthesis structure (@code{backward-up-list}).
  685. @item C-M-d
  686. Move down in parenthesis structure (@code{down-list}).
  687. @end table
  688. @kindex C-M-n
  689. @kindex C-M-p
  690. @findex forward-list
  691. @findex backward-list
  692. The ``list'' commands @kbd{C-M-n} (@code{forward-list}) and
  693. @kbd{C-M-p} (@code{backward-list}) move over one (or @var{n})
  694. parenthetical groupings, skipping blithely over any amount of text
  695. that doesn't include meaningful parentheses (symbols, strings, etc.).
  696. @kindex C-M-u
  697. @kindex C-M-d
  698. @findex backward-up-list
  699. @findex down-list
  700. @kbd{C-M-n} and @kbd{C-M-p} try to stay at the same level in the
  701. parenthesis structure. To move @emph{up} one (or @var{n}) levels, use
  702. @kbd{C-M-u} (@code{backward-up-list}). @kbd{C-M-u} moves backward up
  703. past one unmatched opening delimiter. A positive argument serves as a
  704. repeat count; a negative argument reverses the direction of motion, so
  705. that the command moves forward and up one or more levels.
  706. To move @emph{down} in the parenthesis structure, use @kbd{C-M-d}
  707. (@code{down-list}). In Lisp mode, where @samp{(} is the only opening
  708. delimiter, this is nearly the same as searching for a @samp{(}. An
  709. argument specifies the number of levels to go down.
  710. @node Matching
  711. @subsection Automatic Display Of Matching Parentheses
  712. @cindex matching parentheses
  713. @cindex parentheses, displaying matches
  714. The Emacs parenthesis-matching feature is designed to show
  715. automatically how parentheses (and other matching delimiters) match in
  716. the text. Whenever you type a self-inserting character that is a
  717. closing delimiter, the cursor moves momentarily to the location of the
  718. matching opening delimiter, provided that is on the screen. If it is
  719. not on the screen, Emacs displays some of the text near it in the echo
  720. area. Either way, you can tell which grouping you are closing off.
  721. If the opening delimiter and closing delimiter are mismatched---such
  722. as in @samp{[x)}---a warning message is displayed in the echo area.
  723. @vindex blink-matching-paren
  724. @vindex blink-matching-paren-distance
  725. @vindex blink-matching-delay
  726. Three variables control parenthesis match display.
  727. @code{blink-matching-paren} turns the feature on or off: @code{nil}
  728. disables it, but the default is @code{t} to enable match display.
  729. @code{blink-matching-delay} says how many seconds to leave the
  730. cursor on the matching opening delimiter, before bringing it back to
  731. the real location of point; the default is 1, but on some systems it
  732. is useful to specify a fraction of a second.
  733. @code{blink-matching-paren-distance} specifies how many characters
  734. back to search to find the matching opening delimiter. If the match
  735. is not found in that distance, scanning stops, and nothing is displayed.
  736. This is to prevent the scan for the matching delimiter from wasting
  737. lots of time when there is no match. The default is 25600.
  738. @cindex Show Paren mode
  739. @cindex highlighting matching parentheses
  740. @findex show-paren-mode
  741. Show Paren mode provides a more powerful kind of automatic matching.
  742. Whenever point is after a closing delimiter, that delimiter and its
  743. matching opening delimiter are both highlighted; otherwise, if point
  744. is before an opening delimiter, the matching closing delimiter is
  745. highlighted. (There is no need to highlight the opening delimiter in
  746. that case, because the cursor appears on top of that character.) Use
  747. the command @kbd{M-x show-paren-mode} to enable or disable this mode.
  748. By default, @code{show-paren-mode} uses colors to highlight the
  749. parentheses. However, if your display doesn't support colors, you can
  750. customize the faces @code{show-paren-match-face} and
  751. @code{show-paren-mismatch-face} to use other attributes, such as bold or
  752. underline. @xref{Face Customization}.
  753. @node Comments
  754. @section Manipulating Comments
  755. @cindex comments
  756. Because comments are such an important part of programming, Emacs
  757. provides special commands for editing and inserting comments.
  758. @menu
  759. * Comment Commands:: Inserting, killing, and indenting comments.
  760. * Multi-Line Comments:: Commands for adding and editing multi-line comments.
  761. * Options for Comments::Customizing the comment features.
  762. @end menu
  763. @node Comment Commands
  764. @subsection Comment Commands
  765. @cindex indentation for comments
  766. The comment commands in this table insert, kill and align comments.
  767. They are described in this section and following sections.
  768. @table @kbd
  769. @item M-;
  770. Insert or realign comment on current line; alternatively, comment or
  771. uncomment the region (@code{comment-dwim}).
  772. @item C-u M-;
  773. Kill comment on current line (@code{comment-kill}).
  774. @item C-x ;
  775. Set comment column (@code{comment-set-column}).
  776. @item C-M-j
  777. Like @key{RET} followed by inserting and aligning a comment
  778. (@code{comment-indent-new-line}).
  779. @item M-x comment-region
  780. Add or remove comment delimiters on all the lines in the region.
  781. @end table
  782. @kindex M-;
  783. @findex comment-dwim
  784. The command to create or align a comment is @kbd{M-;}
  785. (@code{comment-dwim}). The word ``dwim'' is an acronym for ``Do What
  786. I Mean''; it indicates that this command can be used for many
  787. different jobs relating to comments, depending on the situation where
  788. you use it.
  789. If there is no comment already on the line, @kbd{M-;} inserts a new
  790. comment, aligned at a specific column called the @dfn{comment column}.
  791. The new comment begins with the string Emacs thinks comments should
  792. start with (the value of @code{comment-start}; see below). Point is
  793. after that string, so you can insert the text of the comment right
  794. away. If the major mode has specified a string to terminate comments,
  795. @kbd{M-;} inserts that too, to keep the syntax valid.
  796. If the text of the line extends past the comment column, then the
  797. comment start string is indented to a suitable boundary (usually, at
  798. least one space is inserted).
  799. You can also use @kbd{M-;} to align an existing comment. If a line
  800. already contains the comment-start string, @kbd{M-;} reindents it to
  801. the conventional alignment and moves point after it. (Exception:
  802. comments starting in column 0 are not moved.) Even when an existing
  803. comment is properly aligned, @kbd{M-;} is still useful for moving
  804. directly to the start of the text inside the comment.
  805. @findex comment-kill
  806. @kindex C-u M-;
  807. @kbd{C-u M-;} kills any comment on the current line, along with the
  808. whitespace before it. To reinsert the comment on another line, move
  809. to the end of that line, do @kbd{C-y}, and then do @kbd{M-;} to
  810. realign it.
  811. Note that @kbd{C-u M-;} is not a distinct key; it is @kbd{M-;}
  812. (@code{comment-dwim}) with a prefix argument. That command is
  813. programmed so that when it receives a prefix argument it calls
  814. @code{comment-kill}. However, @code{comment-kill} is a valid command
  815. in its own right, and you can bind it directly to a key if you wish.
  816. @kbd{M-;} does two other jobs when used with an active region in
  817. Transient Mark mode (@pxref{Transient Mark}). Then it either adds or
  818. removes comment delimiters on each line of the region. (If every line
  819. is a comment, it removes comment delimiters from each; otherwise, it
  820. adds comment delimiters to each.) If you are not using Transient Mark
  821. mode, then you should use the commands @code{comment-region} and
  822. @code{uncomment-region} to do these jobs (@pxref{Multi-Line Comments}).
  823. A prefix argument used in these circumstances specifies how many
  824. comment delimiters to add or how many to delete.
  825. Some major modes have special rules for indenting certain kinds of
  826. comments in certain contexts. For example, in Lisp code, comments which
  827. start with two semicolons are indented as if they were lines of code,
  828. instead of at the comment column. Comments which start with three
  829. semicolons are supposed to start at the left margin. Emacs understands
  830. these conventions by indenting a double-semicolon comment using @key{TAB},
  831. and by not changing the indentation of a triple-semicolon comment at all.
  832. @example
  833. ;; This function is just an example
  834. ;;; Here either two or three semicolons are appropriate.
  835. (defun foo (x)
  836. ;;; And now, the first part of the function:
  837. ;; The following line adds one.
  838. (1+ x)) ; This line adds one.
  839. @end example
  840. In C code, a comment preceded on its line by nothing but whitespace
  841. is indented like a line of code.
  842. @node Multi-Line Comments
  843. @subsection Multiple Lines of Comments
  844. @kindex C-M-j
  845. @cindex blank lines in programs
  846. @findex comment-indent-new-line
  847. If you are typing a comment and wish to continue it on another line,
  848. you can use the command @kbd{C-M-j} (@code{comment-indent-new-line}).
  849. This terminates the comment you are typing, creates a new blank line
  850. afterward, and begins a new comment indented under the old one. When
  851. Auto Fill mode is on, going past the fill column while typing a comment
  852. causes the comment to be continued in just this fashion. If point is
  853. not at the end of the line when @kbd{C-M-j} is typed, the text on
  854. the rest of the line becomes part of the new comment line.
  855. @findex comment-region
  856. To turn existing lines into comment lines, use the @kbd{M-x
  857. comment-region} command. It adds comment delimiters to the lines that start
  858. in the region, thus commenting them out. With a negative argument, it
  859. does the opposite---it deletes comment delimiters from the lines in the
  860. region.
  861. With a positive argument, @code{comment-region} duplicates the last
  862. character of the comment start sequence it adds; the argument specifies
  863. how many copies of the character to insert. Thus, in Lisp mode,
  864. @kbd{C-u 2 M-x comment-region} adds @samp{;;} to each line. Duplicating
  865. the comment delimiter is a way of calling attention to the comment. It
  866. can also affect how the comment is indented. In Lisp, for proper
  867. indentation, you should use an argument of two or three, if between defuns;
  868. if within a defun, it must be three.
  869. @node Options for Comments
  870. @subsection Options Controlling Comments
  871. @vindex comment-column
  872. @kindex C-x ;
  873. @findex comment-set-column
  874. The comment column is stored in the variable @code{comment-column}. You
  875. can set it to a number explicitly. Alternatively, the command @kbd{C-x ;}
  876. (@code{comment-set-column}) sets the comment column to the column point is
  877. at. @kbd{C-u C-x ;} sets the comment column to match the last comment
  878. before point in the buffer, and then does a @kbd{M-;} to align the
  879. current line's comment under the previous one.
  880. The variable @code{comment-column} is per-buffer: setting the variable
  881. in the normal fashion affects only the current buffer, but there is a
  882. default value which you can change with @code{setq-default}.
  883. @xref{Locals}. Many major modes initialize this variable for the
  884. current buffer.
  885. @vindex comment-start-skip
  886. The comment commands recognize comments based on the regular
  887. expression that is the value of the variable @code{comment-start-skip}.
  888. Make sure this regexp does not match the null string. It may match more
  889. than the comment starting delimiter in the strictest sense of the word;
  890. for example, in C mode the value of the variable is
  891. @c This stops M-q from breaking the line inside that @code.
  892. @code{@w{"/\\*+ *\\|//+ *""}}, which matches extra stars and spaces
  893. after the @samp{/*} itself, and accepts C++ style comments also.
  894. (Note that @samp{\\} is needed in Lisp syntax to include a @samp{\} in
  895. the string, which is needed to deny the first star its special meaning
  896. in regexp syntax. @xref{Regexps}.)
  897. @vindex comment-start
  898. @vindex comment-end
  899. When a comment command makes a new comment, it inserts the value of
  900. @code{comment-start} to begin it. The value of @code{comment-end} is
  901. inserted after point, so that it will follow the text that you will insert
  902. into the comment. In C mode, @code{comment-start} has the value
  903. @w{@code{"/* "}} and @code{comment-end} has the value @w{@code{" */"}}.
  904. @vindex comment-padding
  905. The variable @code{comment-padding} specifies how many spaces
  906. @code{comment-region} should insert on each line between the
  907. comment delimiter and the line's original text. The default is 1,
  908. to insert one space.
  909. @vindex comment-multi-line
  910. The variable @code{comment-multi-line} controls how @kbd{C-M-j}
  911. (@code{indent-new-comment-line}) behaves when used inside a comment. If
  912. @code{comment-multi-line} is @code{nil}, as it normally is, then the
  913. comment on the starting line is terminated and a new comment is started
  914. on the new following line. If @code{comment-multi-line} is not
  915. @code{nil}, then the new following line is set up as part of the same
  916. comment that was found on the starting line. This is done by not
  917. inserting a terminator on the old line, and not inserting a starter on
  918. the new line. In languages where multi-line comments work, the choice
  919. of value for this variable is a matter of taste.
  920. @vindex comment-indent-function
  921. The variable @code{comment-indent-function} should contain a function
  922. that will be called to compute the indentation for a newly inserted
  923. comment or for aligning an existing comment. It is set differently by
  924. various major modes. The function is called with no arguments, but with
  925. point at the beginning of the comment, or at the end of a line if a new
  926. comment is to be inserted. It should return the column in which the
  927. comment ought to start. For example, in Lisp mode, the indent hook
  928. function bases its decision on how many semicolons begin an existing
  929. comment, and on the code in the preceding lines.
  930. @node Documentation
  931. @section Documentation Lookup
  932. Emacs provides several features you can use to look up the
  933. documentation of functions, variables and commands that you plan to
  934. use in your program.
  935. @menu
  936. * Info Lookup:: Looking up library functions and commands
  937. in Info files.
  938. * Man Page:: Looking up man pages of library functions and commands.
  939. * Lisp Doc:: Looking up Emacs Lisp functions, etc.
  940. @end menu
  941. @node Info Lookup
  942. @subsection Info Documentation Lookup
  943. @findex info-lookup-symbol
  944. @findex info-lookup-file
  945. @kindex C-h C-i
  946. For C, Lisp, and other languages that have documentation in Info,
  947. you can use @kbd{C-h C-i} (@code{info-lookup-symbol}) to view the Info
  948. documentation for a symbol. You specify the symbol with the
  949. minibuffer; the default is the symbol appearing in the buffer at
  950. point.
  951. The major mode determines where to look for documentation for the
  952. symbol---which Info files to look in, and which indices to search.
  953. You can also use @kbd{M-x info-lookup-file} to look for documentation
  954. for a file name.
  955. This feature currently supports the modes Awk, Autoconf, Bison, C,
  956. Emacs Lisp, LaTeX, M4, Makefile, Octave, Perl, Scheme, and Texinfo,
  957. provided you have installed the relevant Info files, which are
  958. typically available with the appropriate GNU package.
  959. @node Man Page
  960. @subsection Man Page Lookup
  961. @cindex manual page
  962. On Unix, the main form of on-line documentation was the @dfn{manual
  963. page} or @dfn{man page}. In the GNU operating system, we hope to
  964. replace man pages with better-organized manuals that you can browse
  965. with Info (@pxref{Misc Help}). This process is not finished, so it is
  966. still useful to read manual pages.
  967. @findex manual-entry
  968. You can read the man page for an operating system command, library
  969. function, or system call, with the @kbd{M-x manual-entry} command. It
  970. runs the @code{man} program to format the man page; if the system
  971. permits, it runs @code{man} asynchronously, so that you can keep on
  972. editing while the page is being formatted. (On MS-DOS and MS-Windows
  973. 3, you cannot edit while Emacs waits for @code{man} to finish.) The
  974. result goes in a buffer named @samp{*Man @var{topic}*}. These buffers
  975. use a special major mode, Man mode, that facilitates scrolling and
  976. jumping to other manual pages. For details, type @kbd{C-h m} while in
  977. a man page buffer.
  978. @cindex sections of manual pages
  979. Each man page belongs to one of ten or more @dfn{sections}, each
  980. named by a digit or by a digit and a letter. Sometimes there are
  981. multiple man pages with the same name in different sections. To read
  982. a man page from a specific section, type
  983. @samp{@var{topic}(@var{section})} or @samp{@var{section} @var{topic}}
  984. when @kbd{M-x manual-entry} prompts for the topic. For example, to
  985. read the man page for the C library function @code{chmod} (as opposed
  986. to a command of the same name), type @kbd{M-x manual-entry @key{RET}
  987. chmod(2) @key{RET}} (@code{chmod} is a system call, so it is in
  988. section @samp{2}).
  989. @vindex Man-switches
  990. If you do not specify a section, the results depend on how the
  991. @code{man} program works on your system. Some of them display only
  992. the first man page they find. Others display all man pages that have
  993. the specified name, so you can move between them with the @kbd{M-n}
  994. and @kbd{M-p} keys@footnote{On some systems, the @code{man} program
  995. accepts a @samp{-a} command-line option which tells it to display all
  996. the man pages for the specified topic. If you want this behavior, you
  997. can add this option to the value of the variable @code{Man-switches}.}.
  998. The mode line shows how many manual pages are present in the Man buffer.
  999. @vindex Man-fontify-manpage-flag
  1000. By default, Emacs highlights the text in man pages. For a long man
  1001. page, highlighting can take substantial time. You can turn off
  1002. highlighting of man pages by setting the variable
  1003. @code{Man-fontify-manpage-flag} to @code{nil}.
  1004. @findex Man-fontify-manpage
  1005. If you insert the text of a man page into an Emacs buffer in some
  1006. other fashion, you can use the command @kbd{M-x Man-fontify-manpage} to
  1007. perform the same conversions that @kbd{M-x manual-entry} does.
  1008. @findex woman
  1009. @cindex manual pages, on MS-DOS/MS-Windows
  1010. An alternative way of reading manual pages is the @kbd{M-x woman}
  1011. command@footnote{The name of the command, @code{woman}, is an acronym
  1012. for ``w/o (without) man,'' since it doesn't use the @code{man}
  1013. program.}. Unlike @kbd{M-x man}, it does not run any external
  1014. programs to format and display the man pages; instead it does the job
  1015. in Emacs Lisp, so it works on systems such as MS-Windows, where the
  1016. @code{man} program (and the other programs it uses) are not generally
  1017. available.
  1018. @kbd{M-x woman} prompts for a name of a manual page, and provides
  1019. completion based on the list of manual pages that are installed on
  1020. your machine; the list of available manual pages is computed
  1021. automatically the first time you invoke @code{woman}. The word at
  1022. point in the current buffer is used to suggest the default for the
  1023. name the manual page.
  1024. With a numeric argument, @kbd{M-x woman} recomputes the list of the
  1025. manual pages used for completion. This is useful if you add or delete
  1026. manual pages.
  1027. If you type a name of a manual page and @kbd{M-x woman} finds that
  1028. several manual pages by the same name exist in different sections, it
  1029. pops up a window with possible candidates asking you to choose one of
  1030. them.
  1031. @vindex woman-manpath
  1032. By default, @kbd{M-x woman} looks for manual pages in the
  1033. directories specified in the @code{MANPATH} environment variable. (If
  1034. @code{MANPATH} is not set, @code{woman} uses a suitable default value,
  1035. which can be customized.) More precisely, @code{woman} looks for
  1036. subdirectories that match the shell wildcard pattern @file{man*} in each one
  1037. of these directories, and tries to find the manual pages in those
  1038. subdirectories. When first invoked, @kbd{M-x woman} converts the
  1039. value of @code{MANPATH} to a list of directory names and stores that
  1040. list in the @code{woman-manpath} variable. Changing the value of this
  1041. variable is another way to control the list of directories used.
  1042. @vindex woman-path
  1043. You can also augment the list of directories searched by
  1044. @code{woman} by setting the value of the @code{woman-path} variable.
  1045. This variable should hold a list of specific directories which
  1046. @code{woman} should search, in addition to those in
  1047. @code{woman-manpath}. Unlike @code{woman-manpath}, the directories in
  1048. @code{woman-path} are searched for the manual pages, not for
  1049. @file{man*} subdirectories.
  1050. @findex woman-find-file
  1051. Occasionally, you might need to display manual pages that are not in
  1052. any of the directories listed by @code{woman-manpath} and
  1053. @code{woman-path}. The @kbd{M-x woman-find-file} command prompts for a
  1054. name of a manual page file, with completion, and then formats and
  1055. displays that file like @kbd{M-x woman} does.
  1056. @vindex woman-dired-keys
  1057. The first time you invoke @kbd{M-x woman}, it defines the Dired
  1058. @kbd{W} key to run the @code{woman-find-file} command on the current
  1059. line's file. You can disable this by setting the variable
  1060. @code{woman-dired-keys} to @code{nil}. @xref{Dired}. In addition,
  1061. the Tar-mode @kbd{w} key is define to invoke @code{woman-find-file} on
  1062. the current line's archive member.
  1063. For more information about setting up and using @kbd{M-x woman}, see
  1064. @ref{Top, WoMan, Browse UN*X Manual Pages WithOut Man, woman, The WoMan
  1065. Manual}.
  1066. @node Lisp Doc
  1067. @subsection Emacs Lisp Documentation Lookup
  1068. As you edit Lisp code to be run in Emacs, you can use the commands
  1069. @kbd{C-h f} (@code{describe-function}) and @kbd{C-h v}
  1070. (@code{describe-variable}) to view documentation of functions and
  1071. variables that you want to use. These commands use the minibuffer to
  1072. read the name of a function or variable to document, and display the
  1073. documentation in a window. Their default arguments are based on the
  1074. code in the neighborhood of point. For @kbd{C-h f}, the default is
  1075. the function called in the innermost list containing point. @kbd{C-h
  1076. v} uses the symbol name around or adjacent to point as its default.
  1077. @cindex Eldoc mode
  1078. @findex eldoc-mode
  1079. A more automatic but less powerful method is Eldoc mode. This minor
  1080. mode constantly displays in the echo area the argument list for the
  1081. function being called at point. (In other words, it finds the
  1082. function call that point is contained in, and displays the argument
  1083. list of that function.) Eldoc mode applies in Emacs Lisp and Lisp
  1084. Interaction modes only. Use the command @kbd{M-x eldoc-mode} to
  1085. enable or disable this feature.
  1086. @node Hideshow
  1087. @section Hideshow minor mode
  1088. @findex hs-minor-mode
  1089. Hideshow minor mode provides selective display of portions of a
  1090. program, known as @dfn{blocks}. You can use @kbd{M-x hs-minor-mode}
  1091. to enable or disable this mode, or add @code{hs-minor-mode} to the
  1092. mode hook for certain major modes in order to enable it automatically
  1093. for those modes.
  1094. Just what constitutes a block depends on the major mode. In C mode
  1095. or C++ mode, they are delimited by braces, while in Lisp mode and
  1096. similar modes they are delimited by parentheses. Multi-line comments
  1097. also count as blocks.
  1098. @findex hs-hide-all
  1099. @findex hs-hide-block
  1100. @findex hs-show-all
  1101. @findex hs-show-block
  1102. @findex hs-show-region
  1103. @findex hs-hide-level
  1104. @findex hs-minor-mode
  1105. @kindex C-c @@ C-h
  1106. @kindex C-c @@ C-s
  1107. @kindex C-c @@ C-M-h
  1108. @kindex C-c @@ C-M-s
  1109. @kindex C-c @@ C-r
  1110. @kindex C-c @@ C-l
  1111. @kindex S-Mouse-2
  1112. @table @kbd
  1113. @item C-c @@ C-h
  1114. Hide the current block (@code{hs-hide-block}).
  1115. @item C-c @@ C-s
  1116. Show the current block (@code{hs-show-block}).
  1117. @item C-c @@ C-c
  1118. Either hide or show the current block (@code{hs-toggle-hiding})
  1119. @item S-Mouse-2
  1120. Either hide or show the block you click on (@code{hs-mouse-toggle-hiding})
  1121. @item C-c @@ C-M-h
  1122. Hide all top-level blocks (@code{hs-hide-all}).
  1123. @item C-c @@ C-M-s
  1124. Show everything in the buffer (@code{hs-show-all}).
  1125. @item C-c @@ C-l
  1126. Hide all blocks @var{n} levels below this block
  1127. (@code{hs-hide-level}).
  1128. @end table
  1129. @vindex hs-hide-comments-when-hiding-all
  1130. @vindex hs-isearch-open
  1131. @vindex hs-special-modes-alist
  1132. These user options exist for customizing Hideshow mode.
  1133. @table @code
  1134. @item hs-hide-comments-when-hiding-all
  1135. Non-@code{nil} says that @kbd{hs-hide-all} should hide comments too.
  1136. @item hs-isearch-open
  1137. Specifies what kind of hidden blocks to open in Isearch mode.
  1138. The value should be one of these four symbols.
  1139. @table @code
  1140. @item code
  1141. Open only code blocks.
  1142. @item comment
  1143. Open only comments.
  1144. @item t
  1145. Open both code blocks and comments.
  1146. @item nil
  1147. Open neither code blocks nor comments.
  1148. @end table
  1149. @item hs-special-modes-alist
  1150. A list of elements, each specifying how to initialize Hideshow
  1151. variables for one major mode. See the variable's documentation string
  1152. for more information.
  1153. @end table
  1154. @node Symbol Completion
  1155. @section Completion for Symbol Names
  1156. @cindex completion (symbol names)
  1157. In Emacs, completion is something you normally do in the minibuffer.
  1158. But one kind of completion is available in all buffers: completion for
  1159. symbol names.
  1160. @kindex M-TAB
  1161. The character @kbd{M-@key{TAB}} runs a command to complete the
  1162. partial symbol before point against the set of meaningful symbol
  1163. names. This command inserts at point any additional characters that
  1164. it can determine from the partial name.
  1165. If the partial name in the buffer has multiple possible completions
  1166. that differ in the very next character, so that it is impossible to
  1167. complete even one more character, @kbd{M-@key{TAB}} displays a list of
  1168. all possible completions in another window.
  1169. @cindex tags-based completion
  1170. @cindex Info index completion
  1171. @findex complete-symbol
  1172. In most programming language major modes, @kbd{M-@key{TAB}} runs the
  1173. command @code{complete-symbol}, which provides two kinds of completion.
  1174. Normally it does completion based on a tags table (@pxref{Tags}); with a
  1175. numeric argument (regardless of the value), it does completion based on
  1176. the names listed in the Info file indexes for your language. Thus, to
  1177. complete the name of a symbol defined in your own program, use
  1178. @kbd{M-@key{TAB}} with no argument; to complete the name of a standard
  1179. library function, use @kbd{C-u M-@key{TAB}}. Of course, Info-based
  1180. completion works only if there is an Info file for the standard library
  1181. functions of your language, and only if it is installed at your site.
  1182. @cindex Lisp symbol completion
  1183. @cindex completion (Lisp symbols)
  1184. @findex lisp-complete-symbol
  1185. In Emacs-Lisp mode, the name space for completion normally consists of
  1186. nontrivial symbols present in Emacs---those that have function
  1187. definitions, values or properties. However, if there is an
  1188. open-parenthesis immediately before the beginning of the partial symbol,
  1189. only symbols with function definitions are considered as completions.
  1190. The command which implements this is @code{lisp-complete-symbol}.
  1191. In Text mode and related modes, @kbd{M-@key{TAB}} completes words
  1192. based on the spell-checker's dictionary. @xref{Spelling}.
  1193. @node Glasses
  1194. @section Glasses minor mode
  1195. @cindex Glasses mode
  1196. @cindex identifiers, making long ones readable
  1197. @cindex StudlyCaps, making them readable
  1198. @findex glasses-mode
  1199. Glasses minor mode makes @samp{unreadableIdentifiersLikeThis}
  1200. readable by altering the way they display. It knows two different
  1201. ways to do this: by displaying underscores between a lower-case letter
  1202. and the following capital letter, and by emboldening the capital
  1203. letters. It does not alter the buffer text, only the way they
  1204. display, so you can use it even on read-only buffers. You can use the
  1205. command @kbd{M-x glasses-mode} to enable or disable the mode in the
  1206. current buffer; you can also add @code{glasses-mode} to the mode hook
  1207. of the programming language major modes in which you normally want
  1208. to use Glasses mode.
  1209. @node Misc for Programs
  1210. @section Other Features Useful for Editing Programs
  1211. A number of Emacs commands that aren't designed specifically for
  1212. editing programs are useful for that nonetheless.
  1213. The Emacs commands that operate on words, sentences and paragraphs
  1214. are useful for editing code. Most symbols names contain words
  1215. (@pxref{Words}); sentences can be found in strings and comments
  1216. (@pxref{Sentences}). Paragraphs in the strict sense can be found in
  1217. program code (in long comments), but the paragraph commands are useful
  1218. in other places too, because programming language major modes define
  1219. paragraphs to begin and end at blank lines (@pxref{Paragraphs}).
  1220. Judicious use of blank lines to make the program clearer will also
  1221. provide useful chunks of text for the paragraph commands to work on.
  1222. Auto Fill mode, if enabled in a programming language major mode,
  1223. indents the new lines which it creates.
  1224. The selective display feature is useful for looking at the overall
  1225. structure of a function (@pxref{Selective Display}). This feature
  1226. hides the lines that are indented more than a specified amount.
  1227. Programming modes often support Outline minor mode (@pxref{Outline
  1228. Mode}). The Foldout package provides folding-editor features
  1229. (@pxref{Foldout}).
  1230. The ``automatic typing'' features may be useful for writing programs.
  1231. @xref{Top,,Autotyping, autotype, Autotyping}.
  1232. @node C Modes
  1233. @section C and Related Modes
  1234. @cindex C mode
  1235. @cindex Java mode
  1236. @cindex Pike mode
  1237. @cindex IDL mode
  1238. @cindex CORBA IDL mode
  1239. @cindex Objective C mode
  1240. @cindex C++ mode
  1241. @cindex mode, Java
  1242. @cindex mode, C
  1243. @cindex mode, Objective C
  1244. @cindex mode, CORBA IDL
  1245. @cindex mode, Pike
  1246. This section gives a brief description of the special features
  1247. available in C, C++, Objective-C, Java, CORBA IDL, and Pike modes.
  1248. (These are called ``C mode and related modes.'') @xref{Top, CC Mode,
  1249. ccmode, , CC Mode}, for a more extensive description of these modes
  1250. and their special features.
  1251. @menu
  1252. * Motion in C:: Commands to move by C statements, etc.
  1253. * Electric C:: Colon and other chars can automatically reindent.
  1254. * Hungry Delete:: A more powerful DEL command.
  1255. * Other C Commands:: Filling comments, viewing expansion of macros,
  1256. and other neat features.
  1257. * Comments in C:: Options for customizing comment style.
  1258. @end menu
  1259. @node Motion in C
  1260. @subsection C Mode Motion Commands
  1261. This section describes commands for moving point, in C mode and
  1262. related modes.
  1263. @table @code
  1264. @item C-c C-u
  1265. @kindex C-c C-u @r{(C mode)}
  1266. @findex c-up-conditional
  1267. Move point back to the containing preprocessor conditional, leaving the
  1268. mark behind. A prefix argument acts as a repeat count. With a negative
  1269. argument, move point forward to the end of the containing
  1270. preprocessor conditional. When going backwards, @code{#elif} is treated
  1271. like @code{#else} followed by @code{#if}. When going forwards,
  1272. @code{#elif} is ignored.@refill
  1273. @item C-c C-p
  1274. @kindex C-c C-p @r{(C mode)}
  1275. @findex c-backward-conditional
  1276. Move point back over a preprocessor conditional, leaving the mark
  1277. behind. A prefix argument acts as a repeat count. With a negative
  1278. argument, move forward.
  1279. @item C-c C-n
  1280. @kindex C-c C-n @r{(C mode)}
  1281. @findex c-forward-conditional
  1282. Move point forward across a preprocessor conditional, leaving the mark
  1283. behind. A prefix argument acts as a repeat count. With a negative
  1284. argument, move backward.
  1285. @item M-a
  1286. @kindex ESC a
  1287. @findex c-beginning-of-statement
  1288. Move point to the beginning of the innermost C statement
  1289. (@code{c-beginning-of-statement}). If point is already at the beginning
  1290. of a statement, move to the beginning of the preceding statement. With
  1291. prefix argument @var{n}, move back @var{n} @minus{} 1 statements.
  1292. If point is within a string or comment, or next to a comment (only
  1293. whitespace between them), this command moves by sentences instead of
  1294. statements.
  1295. When called from a program, this function takes three optional
  1296. arguments: the numeric prefix argument, a buffer position limit
  1297. (don't move back before that place), and a flag that controls whether
  1298. to do sentence motion when inside of a comment.
  1299. @item M-e
  1300. @kindex ESC e
  1301. @findex c-end-of-statement
  1302. Move point to the end of the innermost C statement; like @kbd{M-a}
  1303. except that it moves in the other direction (@code{c-end-of-statement}).
  1304. @item M-x c-backward-into-nomenclature
  1305. @findex c-backward-into-nomenclature
  1306. Move point backward to beginning of a C++ nomenclature section or word.
  1307. With prefix argument @var{n}, move @var{n} times. If @var{n} is
  1308. negative, move forward. C++ nomenclature means a symbol name in the
  1309. style of NamingSymbolsWithMixedCaseAndNoUnderlines; each capital letter
  1310. begins a section or word.
  1311. In the GNU project, we recommend using underscores to separate words
  1312. within an identifier in C or C++, rather than using case distinctions.
  1313. @item M-x c-forward-into-nomenclature
  1314. @findex c-forward-into-nomenclature
  1315. Move point forward to end of a C++ nomenclature section or word.
  1316. With prefix argument @var{n}, move @var{n} times.
  1317. @end table
  1318. @node Electric C
  1319. @subsection Electric C Characters
  1320. In C mode and related modes, certain printing characters are
  1321. ``electric''---in addition to inserting themselves, they also reindent
  1322. the current line and may insert newlines. This feature is controlled by
  1323. the variable @code{c-auto-newline}. The ``electric'' characters are
  1324. @kbd{@{}, @kbd{@}}, @kbd{:}, @kbd{#}, @kbd{;}, @kbd{,}, @kbd{<},
  1325. @kbd{>}, @kbd{/}, @kbd{*}, @kbd{(}, and @kbd{)}.
  1326. Electric characters insert newlines only when the @dfn{auto-newline}
  1327. feature is enabled (indicated by @samp{/a} in the mode line after the
  1328. mode name). This feature is controlled by the variable
  1329. @code{c-auto-newline}. You can turn this feature on or off with the
  1330. command @kbd{C-c C-a}:
  1331. @table @kbd
  1332. @item C-c C-a
  1333. @kindex C-c C-a @r{(C mode)}
  1334. @findex c-toggle-auto-state
  1335. Toggle the auto-newline feature (@code{c-toggle-auto-state}). With a
  1336. prefix argument, this command turns the auto-newline feature on if the
  1337. argument is positive, and off if it is negative.
  1338. @end table
  1339. The colon character is electric because that is appropriate for a
  1340. single colon. But when you want to insert a double colon in C++, the
  1341. electric behavior of colon is inconvenient. You can insert a double
  1342. colon with no reindentation or newlines by typing @kbd{C-c :}:
  1343. @table @kbd
  1344. @item C-c :
  1345. @kindex C-c : @r{(C mode)}
  1346. @findex c-scope-operator
  1347. Insert a double colon scope operator at point, without reindenting the
  1348. line or adding any newlines (@code{c-scope-operator}).
  1349. @end table
  1350. The electric @kbd{#} key reindents the line if it appears to be the
  1351. beginning of a preprocessor directive. This happens when the value of
  1352. @code{c-electric-pound-behavior} is @code{(alignleft)}. You can turn
  1353. this feature off by setting @code{c-electric-pound-behavior} to
  1354. @code{nil}.
  1355. The variable @code{c-hanging-braces-alist} controls the insertion of
  1356. newlines before and after inserted braces. It is an association list
  1357. with elements of the following form: @code{(@var{syntactic-symbol}
  1358. . @var{nl-list})}. Most of the syntactic symbols that appear in
  1359. @code{c-offsets-alist} are meaningful here as well.
  1360. The list @var{nl-list} may contain either of the symbols
  1361. @code{before} or @code{after}, or both; or it may be @code{nil}. When a
  1362. brace is inserted, the syntactic context it defines is looked up in
  1363. @code{c-hanging-braces-alist}; if it is found, the @var{nl-list} is used
  1364. to determine where newlines are inserted: either before the brace,
  1365. after, or both. If not found, the default is to insert a newline both
  1366. before and after braces.
  1367. The variable @code{c-hanging-colons-alist} controls the insertion of
  1368. newlines before and after inserted colons. It is an association list
  1369. with elements of the following form: @code{(@var{syntactic-symbol}
  1370. . @var{nl-list})}. The list @var{nl-list} may contain either of the
  1371. symbols @code{before} or @code{after}, or both; or it may be @code{nil}.
  1372. When a colon is inserted, the syntactic symbol it defines is looked
  1373. up in this list, and if found, the @var{nl-list} is used to determine
  1374. where newlines are inserted: either before the brace, after, or both.
  1375. If the syntactic symbol is not found in this list, no newlines are
  1376. inserted.
  1377. Electric characters can also delete newlines automatically when the
  1378. auto-newline feature is enabled. This feature makes auto-newline more
  1379. acceptable, by deleting the newlines in the most common cases where you
  1380. do not want them. Emacs can recognize several cases in which deleting a
  1381. newline might be desirable; by setting the variable
  1382. @code{c-cleanup-list}, you can specify @emph{which} of these cases that
  1383. should happen. The variable's value is a list of symbols, each
  1384. describing one case for possible deletion of a newline. Here are the
  1385. meaningful symbols, and their meanings:
  1386. @table @code
  1387. @item brace-catch-brace
  1388. Clean up @samp{@} catch (@var{condition}) @{} constructs by placing the
  1389. entire construct on a single line. The clean-up occurs when you type
  1390. the @samp{@{}, if there is nothing between the braces aside from
  1391. @code{catch} and @var{condition}.
  1392. @item brace-else-brace
  1393. Clean up @samp{@} else @{} constructs by placing the entire construct on
  1394. a single line. The clean-up occurs when you type the @samp{@{} after
  1395. the @code{else}, but only if there is nothing but white space between
  1396. the braces and the @code{else}.
  1397. @item brace-elseif-brace
  1398. Clean up @samp{@} else if (@dots{}) @{} constructs by placing the entire
  1399. construct on a single line. The clean-up occurs when you type the
  1400. @samp{@{}, if there is nothing but white space between the @samp{@}} and
  1401. @samp{@{} aside from the keywords and the @code{if}-condition.
  1402. @item empty-defun-braces
  1403. Clean up empty defun braces by placing the braces on the same
  1404. line. Clean-up occurs when you type the closing brace.
  1405. @item defun-close-semi
  1406. Clean up the semicolon after a @code{struct} or similar type
  1407. declaration, by placing the semicolon on the same line as the closing
  1408. brace. Clean-up occurs when you type the semicolon.
  1409. @item list-close-comma
  1410. Clean up commas following braces in array and aggregate
  1411. initializers. Clean-up occurs when you type the comma.
  1412. @item scope-operator
  1413. Clean up double colons which may designate a C++ scope operator, by
  1414. placing the colons together. Clean-up occurs when you type the second
  1415. colon, but only when the two colons are separated by nothing but
  1416. whitespace.
  1417. @end table
  1418. @node Hungry Delete
  1419. @subsection Hungry Delete Feature in C
  1420. When the @dfn{hungry-delete} feature is enabled (indicated by
  1421. @samp{/h} or @samp{/ah} in the mode line after the mode name), a single
  1422. @key{DEL} command deletes all preceding whitespace, not just one space.
  1423. To turn this feature on or off, use @kbd{C-c C-d}:
  1424. @table @kbd
  1425. @item C-c C-d
  1426. @kindex C-c C-d @r{(C mode)}
  1427. @findex c-toggle-hungry-state
  1428. Toggle the hungry-delete feature (@code{c-toggle-hungry-state}). With a
  1429. prefix argument, this command turns the hungry-delete feature on if the
  1430. argument is positive, and off if it is negative.
  1431. @item C-c C-t
  1432. @kindex C-c C-t @r{(C mode)}
  1433. @findex c-toggle-auto-hungry-state
  1434. Toggle the auto-newline and hungry-delete features, both at once
  1435. (@code{c-toggle-auto-hungry-state}).
  1436. @end table
  1437. @vindex c-hungry-delete-key
  1438. The variable @code{c-hungry-delete-key} controls whether the
  1439. hungry-delete feature is enabled.
  1440. @node Other C Commands
  1441. @subsection Other Commands for C Mode
  1442. @table @kbd
  1443. @item C-M-h
  1444. Put mark at the end of a function definition, and put point at the
  1445. beginning (@code{c-mark-function}).
  1446. @item M-q
  1447. @kindex M-q @r{(C mode)}
  1448. @findex c-fill-paragraph
  1449. Fill a paragraph, handling C and C++ comments (@code{c-fill-paragraph}).
  1450. If any part of the current line is a comment or within a comment, this
  1451. command fills the comment or the paragraph of it that point is in,
  1452. preserving the comment indentation and comment delimiters.
  1453. @item C-c C-e
  1454. @cindex macro expansion in C
  1455. @cindex expansion of C macros
  1456. @findex c-macro-expand
  1457. @kindex C-c C-e @r{(C mode)}
  1458. Run the C preprocessor on the text in the region, and show the result,
  1459. which includes the expansion of all the macro calls
  1460. (@code{c-macro-expand}). The buffer text before the region is also
  1461. included in preprocessing, for the sake of macros defined there, but the
  1462. output from this part isn't shown.
  1463. When you are debugging C code that uses macros, sometimes it is hard to
  1464. figure out precisely how the macros expand. With this command, you
  1465. don't have to figure it out; you can see the expansions.
  1466. @item C-c C-\
  1467. @findex c-backslash-region
  1468. @kindex C-c C-\ @r{(C mode)}
  1469. Insert or align @samp{\} characters at the ends of the lines of the
  1470. region (@code{c-backslash-region}). This is useful after writing or
  1471. editing a C macro definition.
  1472. If a line already ends in @samp{\}, this command adjusts the amount of
  1473. whitespace before it. Otherwise, it inserts a new @samp{\}. However,
  1474. the last line in the region is treated specially; no @samp{\} is
  1475. inserted on that line, and any @samp{\} there is deleted.
  1476. @item M-x cpp-highlight-buffer
  1477. @cindex preprocessor highlighting
  1478. @findex cpp-highlight-buffer
  1479. Highlight parts of the text according to its preprocessor conditionals.
  1480. This command displays another buffer named @samp{*CPP Edit*}, which
  1481. serves as a graphic menu for selecting how to display particular kinds
  1482. of conditionals and their contents. After changing various settings,
  1483. click on @samp{[A]pply these settings} (or go to that buffer and type
  1484. @kbd{a}) to rehighlight the C mode buffer accordingly.
  1485. @item C-c C-s
  1486. @findex c-show-syntactic-information
  1487. @kindex C-c C-s @r{(C mode)}
  1488. Display the syntactic information about the current source line
  1489. (@code{c-show-syntactic-information}). This is the information that
  1490. directs how the line is indented.
  1491. @item M-x cwarn-mode
  1492. @itemx M-x global-cwarn-mode
  1493. @findex cwarn-mode
  1494. @findex global-cwarn-mode
  1495. @cindex CWarn mode
  1496. @cindex suspicious constructions in C, C++
  1497. CWarn minor mode highlights certain suspicious C and C++ constructions:
  1498. @itemize @bullet{}
  1499. @item
  1500. Assignments inside expressions.
  1501. @item
  1502. Semicolon following immediately after @samp{if}, @samp{for}, and @samp{while}
  1503. (except after a @samp{do @dots{} while} statement);
  1504. @item
  1505. C++ functions with reference parameters.
  1506. @end itemize
  1507. @noindent
  1508. You can enable the mode for one buffer with the command @kbd{M-x
  1509. cwarn-mode}, or for all suitable buffers with the command @kbd{M-x
  1510. global-cwarn-mode} or by customizing the variable
  1511. @code{global-cwarn-mode}. You must also enable Font Lock mode to make
  1512. it work.
  1513. @item M-x hide-ifdef-mode
  1514. @findex hide-ifdef-mode
  1515. @cindex Hide-ifdef mode
  1516. Hide-ifdef minor mode hides selected code within @samp{#if} and
  1517. @samp{#ifdef} preprocessor blocks. See the documentation string of
  1518. @code{hide-ifdef-mode} for more information.
  1519. @item M-x ff-find-related-file
  1520. @cindex related files
  1521. @findex ff-find-related-file
  1522. @vindex ff-related-file-alist
  1523. Find a file ``related'' in a special way to the file visited by the
  1524. current buffer. Typically this will be the header file corresponding
  1525. to a C/C++ source file, or vice versa. The variable
  1526. @code{ff-related-file-alist} specifies how to compute related file
  1527. names.
  1528. @end table
  1529. @node Comments in C
  1530. @subsection Comments in C Modes
  1531. C mode and related modes use a number of variables for controlling
  1532. comment format.
  1533. @table @code
  1534. @item c-comment-only-line-offset
  1535. @vindex c-comment-only-line-offset
  1536. Extra offset for line which contains only the start of a comment. It
  1537. can be either an integer or a cons cell of the form
  1538. @code{(@var{non-anchored-offset} . @var{anchored-offset})}, where
  1539. @var{non-anchored-offset} is the amount of offset given to
  1540. non-column-zero anchored comment-only lines, and @var{anchored-offset}
  1541. is the amount of offset to give column-zero anchored comment-only lines.
  1542. Just an integer as value is equivalent to @code{(@var{val} . 0)}.
  1543. @item c-comment-start-regexp
  1544. @vindex c-comment-start-regexp
  1545. This buffer-local variable specifies how to recognize the start of a comment.
  1546. @item c-hanging-comment-ender-p
  1547. @vindex c-hanging-comment-ender-p
  1548. If this variable is @code{nil}, @code{c-fill-paragraph} leaves the
  1549. comment terminator of a block comment on a line by itself. The default
  1550. value is @code{t}, which puts the comment-end delimiter @samp{*/} at the
  1551. end of the last line of the comment text.
  1552. @item c-hanging-comment-starter-p
  1553. @vindex c-hanging-comment-starter-p
  1554. If this variable is @code{nil}, @code{c-fill-paragraph} leaves the
  1555. starting delimiter of a block comment on a line by itself. The default
  1556. value is @code{t}, which puts the comment-start delimiter @samp{/*} at
  1557. the beginning of the first line of the comment text.
  1558. @end table
  1559. @node Fortran
  1560. @section Fortran Mode
  1561. @cindex Fortran mode
  1562. @cindex mode, Fortran
  1563. Fortran mode provides special motion commands for Fortran statements and
  1564. subprograms, and indentation commands that understand Fortran conventions
  1565. of nesting, line numbers and continuation statements. Fortran mode has
  1566. its own Auto Fill mode that breaks long lines into proper Fortran
  1567. continuation lines.
  1568. Special commands for comments are provided because Fortran comments
  1569. are unlike those of other languages. Built-in abbrevs optionally save
  1570. typing when you insert Fortran keywords.
  1571. Use @kbd{M-x fortran-mode} to switch to this major mode. This command
  1572. runs the hook @code{fortran-mode-hook} (@pxref{Hooks}).
  1573. @cindex Fortran77 and Fortran90
  1574. @findex f90-mode
  1575. @findex fortran-mode
  1576. Fortan mode is meant for editing Fortran77 ``fixed format'' source
  1577. code. For editing the modern Fortran90 ``free format'' source code,
  1578. use F90 mode (@code{f90-mode}). Emacs normally uses Fortran mode for
  1579. files with extension @samp{.f}, @samp{.F} or @samp{.for}, and F90 mode
  1580. for the extension @samp{.f90}. GNU Fortran supports both kinds of
  1581. format.
  1582. @menu
  1583. * Motion: Fortran Motion. Moving point by statements or subprograms.
  1584. * Indent: Fortran Indent. Indentation commands for Fortran.
  1585. * Comments: Fortran Comments. Inserting and aligning comments.
  1586. * Autofill: Fortran Autofill. Auto fill minor mode for Fortran.
  1587. * Columns: Fortran Columns. Measuring columns for valid Fortran.
  1588. * Abbrev: Fortran Abbrev. Built-in abbrevs for Fortran keywords.
  1589. @end menu
  1590. @node Fortran Motion
  1591. @subsection Motion Commands
  1592. In addition to the normal commands for moving by and operating on
  1593. ``defuns'' (Fortran subprograms---functions and subroutines), Fortran
  1594. mode provides special commands to move by statements.
  1595. @table @kbd
  1596. @kindex C-c C-n @r{(Fortran mode)}
  1597. @findex fortran-next-statement
  1598. @item C-c C-n
  1599. Move to beginning of current or next statement
  1600. (@code{fortran-next-statement}).
  1601. @kindex C-c C-p @r{(Fortran mode)}
  1602. @findex fortran-previous-statement
  1603. @item C-c C-p
  1604. Move to beginning of current or previous statement
  1605. (@code{fortran-previous-statement}).
  1606. @end table
  1607. @node Fortran Indent
  1608. @subsection Fortran Indentation
  1609. Special commands and features are needed for indenting Fortran code in
  1610. order to make sure various syntactic entities (line numbers, comment line
  1611. indicators and continuation line flags) appear in the columns that are
  1612. required for standard Fortran.
  1613. @menu
  1614. * Commands: ForIndent Commands. Commands for indenting and filling Fortran.
  1615. * Contline: ForIndent Cont. How continuation lines indent.
  1616. * Numbers: ForIndent Num. How line numbers auto-indent.
  1617. * Conv: ForIndent Conv. Conventions you must obey to avoid trouble.
  1618. * Vars: ForIndent Vars. Variables controlling Fortran indent style.
  1619. @end menu
  1620. @node ForIndent Commands
  1621. @subsubsection Fortran Indentation and Filling Commands
  1622. @table @kbd
  1623. @item C-M-j
  1624. Break the current line and set up a continuation line
  1625. (@code{fortran-split-line}).
  1626. @item M-^
  1627. Join this line to the previous line (@code{fortran-join-line}).
  1628. @item C-M-q
  1629. Indent all the lines of the subprogram point is in
  1630. (@code{fortran-indent-subprogram}).
  1631. @item M-q
  1632. Fill a comment block or statement.
  1633. @end table
  1634. @kindex C-M-q @r{(Fortran mode)}
  1635. @findex fortran-indent-subprogram
  1636. The key @kbd{C-M-q} runs @code{fortran-indent-subprogram}, a command
  1637. to reindent all the lines of the Fortran subprogram (function or
  1638. subroutine) containing point.
  1639. @kindex C-M-j @r{(Fortran mode)}
  1640. @findex fortran-split-line
  1641. The key @kbd{C-M-j} runs @code{fortran-split-line}, which splits
  1642. a line in the appropriate fashion for Fortran. In a non-comment line,
  1643. the second half becomes a continuation line and is indented
  1644. accordingly. In a comment line, both halves become separate comment
  1645. lines.
  1646. @kindex M-^ @r{(Fortran mode)}
  1647. @kindex C-c C-d @r{(Fortran mode)}
  1648. @findex fortran-join-line
  1649. @kbd{M-^} or @kbd{C-c C-d} runs the command @code{fortran-join-line},
  1650. which joins a continuation line back to the previous line, roughly as
  1651. the inverse of @code{fortran-split-line}. The point must be on a
  1652. continuation line when this command is invoked.
  1653. @kindex M-q @r{(Fortran mode)}
  1654. @kbd{M-q} in Fortran mode fills the comment block or statement that
  1655. point is in. This removes any excess statement continuations.
  1656. @node ForIndent Cont
  1657. @subsubsection Continuation Lines
  1658. @cindex Fortran continuation lines
  1659. @vindex fortran-continuation-string
  1660. Most modern Fortran compilers allow two ways of writing continuation
  1661. lines. If the first non-space character on a line is in column 5, then
  1662. that line is a continuation of the previous line. We call this
  1663. @dfn{fixed format}. (In GNU Emacs we always count columns from 0.) The
  1664. variable @code{fortran-continuation-string} specifies what character to
  1665. put on column 5. A line that starts with a tab character followed by
  1666. any digit except @samp{0} is also a continuation line. We call this
  1667. style of continuation @dfn{tab format}.
  1668. @vindex indent-tabs-mode @r{(Fortran mode)}
  1669. Fortran mode can make either style of continuation line, but you
  1670. must specify which one you prefer. The value of the variable
  1671. @code{indent-tabs-mode} controls the choice: @code{nil} for fixed
  1672. format, and non-@code{nil} for tab format. You can tell which style
  1673. is presently in effect by the presence or absence of the string
  1674. @samp{Tab} in the mode line.
  1675. If the text on a line starts with the conventional Fortran
  1676. continuation marker @samp{$}, or if it begins with any non-whitespace
  1677. character in column 5, Fortran mode treats it as a continuation line.
  1678. When you indent a continuation line with @key{TAB}, it converts the line
  1679. to the current continuation style. When you split a Fortran statement
  1680. with @kbd{C-M-j}, the continuation marker on the newline is created
  1681. according to the continuation style.
  1682. The setting of continuation style affects several other aspects of
  1683. editing in Fortran mode. In fixed format mode, the minimum column
  1684. number for the body of a statement is 6. Lines inside of Fortran
  1685. blocks that are indented to larger column numbers always use only the
  1686. space character for whitespace. In tab format mode, the minimum
  1687. column number for the statement body is 8, and the whitespace before
  1688. column 8 must always consist of one tab character.
  1689. @vindex fortran-tab-mode-default
  1690. @vindex fortran-analyze-depth
  1691. When you enter Fortran mode for an existing file, it tries to deduce the
  1692. proper continuation style automatically from the file contents. The first
  1693. line that begins with either a tab character or six spaces determines the
  1694. choice. The variable @code{fortran-analyze-depth} specifies how many lines
  1695. to consider (at the beginning of the file); if none of those lines
  1696. indicates a style, then the variable @code{fortran-tab-mode-default}
  1697. specifies the style. If it is @code{nil}, that specifies fixed format, and
  1698. non-@code{nil} specifies tab format.
  1699. @node ForIndent Num
  1700. @subsubsection Line Numbers
  1701. If a number is the first non-whitespace in the line, Fortran
  1702. indentation assumes it is a line number and moves it to columns 0
  1703. through 4. (Columns always count from 0 in GNU Emacs.)
  1704. @vindex fortran-line-number-indent
  1705. Line numbers of four digits or less are normally indented one space.
  1706. The variable @code{fortran-line-number-indent} controls this; it
  1707. specifies the maximum indentation a line number can have. Line numbers
  1708. are indented to right-justify them to end in column 4 unless that would
  1709. require more than this maximum indentation. The default value of the
  1710. variable is 1.
  1711. @vindex fortran-electric-line-number
  1712. Simply inserting a line number is enough to indent it according to
  1713. these rules. As each digit is inserted, the indentation is recomputed.
  1714. To turn off this feature, set the variable
  1715. @code{fortran-electric-line-number} to @code{nil}. Then inserting line
  1716. numbers is like inserting anything else.
  1717. @node ForIndent Conv
  1718. @subsubsection Syntactic Conventions
  1719. Fortran mode assumes that you follow certain conventions that simplify
  1720. the task of understanding a Fortran program well enough to indent it
  1721. properly:
  1722. @itemize @bullet
  1723. @item
  1724. Two nested @samp{do} loops never share a @samp{continue} statement.
  1725. @item
  1726. Fortran keywords such as @samp{if}, @samp{else}, @samp{then}, @samp{do}
  1727. and others are written without embedded whitespace or line breaks.
  1728. Fortran compilers generally ignore whitespace outside of string
  1729. constants, but Fortran mode does not recognize these keywords if they
  1730. are not contiguous. Constructs such as @samp{else if} or @samp{end do}
  1731. are acceptable, but the second word should be on the same line as the
  1732. first and not on a continuation line.
  1733. @end itemize
  1734. @noindent
  1735. If you fail to follow these conventions, the indentation commands may
  1736. indent some lines unaesthetically. However, a correct Fortran program
  1737. retains its meaning when reindented even if the conventions are not
  1738. followed.
  1739. @node ForIndent Vars
  1740. @subsubsection Variables for Fortran Indentation
  1741. @vindex fortran-do-indent
  1742. @vindex fortran-if-indent
  1743. @vindex fortran-structure-indent
  1744. @vindex fortran-continuation-indent
  1745. @vindex fortran-check-all-num@dots{}
  1746. @vindex fortran-minimum-statement-indent@dots{}
  1747. Several additional variables control how Fortran indentation works:
  1748. @table @code
  1749. @item fortran-do-indent
  1750. Extra indentation within each level of @samp{do} statement (default 3).
  1751. @item fortran-if-indent
  1752. Extra indentation within each level of @samp{if} statement (default 3).
  1753. This value is also used for extra indentation within each level of the
  1754. Fortran 90 @samp{where} statement.
  1755. @item fortran-structure-indent
  1756. Extra indentation within each level of @samp{structure}, @samp{union}, or
  1757. @samp{map} statements (default 3).
  1758. @item fortran-continuation-indent
  1759. Extra indentation for bodies of continuation lines (default 5).
  1760. @item fortran-check-all-num-for-matching-do
  1761. If this is @code{nil}, indentation assumes that each @samp{do} statement
  1762. ends on a @samp{continue} statement. Therefore, when computing
  1763. indentation for a statement other than @samp{continue}, it can save time
  1764. by not checking for a @samp{do} statement ending there. If this is
  1765. non-@code{nil}, indenting any numbered statement must check for a
  1766. @samp{do} that ends there. The default is @code{nil}.
  1767. @item fortran-blink-matching-if
  1768. If this is @code{t}, indenting an @samp{endif} statement moves the
  1769. cursor momentarily to the matching @samp{if} statement to show where it
  1770. is. The default is @code{nil}.
  1771. @item fortran-minimum-statement-indent-fixed
  1772. Minimum indentation for fortran statements when using fixed format
  1773. continuation line style. Statement bodies are never indented less than
  1774. this much. The default is 6.
  1775. @item fortran-minimum-statement-indent-tab
  1776. Minimum indentation for fortran statements for tab format continuation line
  1777. style. Statement bodies are never indented less than this much. The
  1778. default is 8.
  1779. @end table
  1780. @node Fortran Comments
  1781. @subsection Fortran Comments
  1782. The usual Emacs comment commands assume that a comment can follow a line
  1783. of code. In Fortran, the standard comment syntax requires an entire line
  1784. to be just a comment. Therefore, Fortran mode replaces the standard Emacs
  1785. comment commands and defines some new variables.
  1786. Fortran mode can also handle the Fortran90 comment syntax where comments
  1787. start with @samp{!} and can follow other text. Because only some Fortran77
  1788. compilers accept this syntax, Fortran mode will not insert such comments
  1789. unless you have said in advance to do so. To do this, set the variable
  1790. @code{comment-start} to @samp{"!"} (@pxref{Variables}).
  1791. @table @kbd
  1792. @item M-;
  1793. Align comment or insert new comment (@code{fortran-comment-indent}).
  1794. @item C-x ;
  1795. Applies to nonstandard @samp{!} comments only.
  1796. @item C-c ;
  1797. Turn all lines of the region into comments, or (with argument) turn them back
  1798. into real code (@code{fortran-comment-region}).
  1799. @end table
  1800. @kbd{M-;} in Fortran mode is redefined as the command
  1801. @code{fortran-comment-indent}. Like the usual @kbd{M-;} command, this
  1802. recognizes any kind of existing comment and aligns its text appropriately;
  1803. if there is no existing comment, a comment is inserted and aligned. But
  1804. inserting and aligning comments are not the same in Fortran mode as in
  1805. other modes.
  1806. When a new comment must be inserted, if the current line is blank, a
  1807. full-line comment is inserted. On a non-blank line, a nonstandard @samp{!}
  1808. comment is inserted if you have said you want to use them. Otherwise a
  1809. full-line comment is inserted on a new line before the current line.
  1810. Nonstandard @samp{!} comments are aligned like comments in other
  1811. languages, but full-line comments are different. In a standard full-line
  1812. comment, the comment delimiter itself must always appear in column zero.
  1813. What can be aligned is the text within the comment. You can choose from
  1814. three styles of alignment by setting the variable
  1815. @code{fortran-comment-indent-style} to one of these values:
  1816. @vindex fortran-comment-indent-style
  1817. @vindex fortran-comment-line-extra-indent
  1818. @table @code
  1819. @item fixed
  1820. Align the text at a fixed column, which is the sum of
  1821. @code{fortran-comment-line-extra-indent} and the minimum statement
  1822. indentation. This is the default.
  1823. The minimum statement indentation is
  1824. @code{fortran-minimum-statement-indent-fixed} for fixed format
  1825. continuation line style and @code{fortran-minimum-statement-indent-tab}
  1826. for tab format style.
  1827. @item relative
  1828. Align the text as if it were a line of code, but with an additional
  1829. @code{fortran-comment-line-extra-indent} columns of indentation.
  1830. @item nil
  1831. Don't move text in full-line comments automatically at all.
  1832. @end table
  1833. @vindex fortran-comment-indent-char
  1834. In addition, you can specify the character to be used to indent within
  1835. full-line comments by setting the variable
  1836. @code{fortran-comment-indent-char} to the single-character string you want
  1837. to use.
  1838. @vindex comment-line-start
  1839. @vindex comment-line-start-skip
  1840. Fortran mode introduces two variables @code{comment-line-start} and
  1841. @code{comment-line-start-skip}, which play for full-line comments the same
  1842. roles played by @code{comment-start} and @code{comment-start-skip} for
  1843. ordinary text-following comments. Normally these are set properly by
  1844. Fortran mode, so you do not need to change them.
  1845. The normal Emacs comment command @kbd{C-x ;} has not been redefined. If
  1846. you use @samp{!} comments, this command can be used with them. Otherwise
  1847. it is useless in Fortran mode.
  1848. @kindex C-c ; @r{(Fortran mode)}
  1849. @findex fortran-comment-region
  1850. @vindex fortran-comment-region
  1851. The command @kbd{C-c ;} (@code{fortran-comment-region}) turns all the
  1852. lines of the region into comments by inserting the string @samp{C$$$} at
  1853. the front of each one. With a numeric argument, it turns the region
  1854. back into live code by deleting @samp{C$$$} from the front of each line
  1855. in it. The string used for these comments can be controlled by setting
  1856. the variable @code{fortran-comment-region}. Note that here we have an
  1857. example of a command and a variable with the same name; these two uses
  1858. of the name never conflict because in Lisp and in Emacs it is always
  1859. clear from the context which one is meant.
  1860. @node Fortran Autofill
  1861. @subsection Fortran Auto Fill Mode
  1862. Fortran Auto Fill mode is a minor mode which automatically splits
  1863. Fortran statements as you insert them when they become too wide.
  1864. Splitting a statement involves making continuation lines using
  1865. @code{fortran-continuation-string} (@pxref{ForIndent Cont}). This
  1866. splitting happens when you type @key{SPC}, @key{RET}, or @key{TAB}, and
  1867. also in the Fortran indentation commands.
  1868. @findex fortran-auto-fill-mode
  1869. @kbd{M-x fortran-auto-fill-mode} turns Fortran Auto Fill mode on if it
  1870. was off, or off if it was on. This command works the same as @kbd{M-x
  1871. auto-fill-mode} does for normal Auto Fill mode (@pxref{Filling}). A
  1872. positive numeric argument turns Fortran Auto Fill mode on, and a
  1873. negative argument turns it off. You can see when Fortran Auto Fill mode
  1874. is in effect by the presence of the word @samp{Fill} in the mode line,
  1875. inside the parentheses. Fortran Auto Fill mode is a minor mode, turned
  1876. on or off for each buffer individually. @xref{Minor Modes}.
  1877. @vindex fortran-break-before-delimiters
  1878. Fortran Auto Fill mode breaks lines at spaces or delimiters when the
  1879. lines get longer than the desired width (the value of @code{fill-column}).
  1880. The delimiters that Fortran Auto Fill mode may break at are @samp{,},
  1881. @samp{'}, @samp{+}, @samp{-}, @samp{/}, @samp{*}, @samp{=}, and @samp{)}.
  1882. The line break comes after the delimiter if the variable
  1883. @code{fortran-break-before-delimiters} is @code{nil}. Otherwise (and by
  1884. default), the break comes before the delimiter.
  1885. By default, Fortran Auto Fill mode is not enabled. If you want this
  1886. feature turned on permanently, add a hook function to
  1887. @code{fortran-mode-hook} to execute @code{(fortran-auto-fill-mode 1)}.
  1888. @xref{Hooks}.
  1889. @node Fortran Columns
  1890. @subsection Checking Columns in Fortran
  1891. @table @kbd
  1892. @item C-c C-r
  1893. Display a ``column ruler'' momentarily above the current line
  1894. (@code{fortran-column-ruler}).
  1895. @item C-c C-w
  1896. Split the current window horizontally temporarily so that it is 72
  1897. columns wide (@code{fortran-window-create-momentarily}). This may
  1898. help you avoid making lines longer than the 72-character limit that
  1899. some Fortran compilers impose.
  1900. @item C-u C-c C-w
  1901. Split the current window horizontally so that it is 72 columns wide
  1902. (@code{fortran-window-create}). You can then continue editing.
  1903. @item M-x fortran-strip-sequence-nos
  1904. Delete all text in column 72 and beyond.
  1905. @end table
  1906. @kindex C-c C-r @r{(Fortran mode)}
  1907. @findex fortran-column-ruler
  1908. The command @kbd{C-c C-r} (@code{fortran-column-ruler}) shows a column
  1909. ruler momentarily above the current line. The comment ruler is two lines
  1910. of text that show you the locations of columns with special significance in
  1911. Fortran programs. Square brackets show the limits of the columns for line
  1912. numbers, and curly brackets show the limits of the columns for the
  1913. statement body. Column numbers appear above them.
  1914. Note that the column numbers count from zero, as always in GNU Emacs.
  1915. As a result, the numbers may be one less than those you are familiar
  1916. with; but the positions they indicate in the line are standard for
  1917. Fortran.
  1918. @vindex fortran-column-ruler-fixed
  1919. @vindex fortran-column-ruler-tabs
  1920. The text used to display the column ruler depends on the value of
  1921. the variable @code{indent-tabs-mode}. If @code{indent-tabs-mode} is
  1922. @code{nil}, then the value of the variable
  1923. @code{fortran-column-ruler-fixed} is used as the column ruler.
  1924. Otherwise, the variable @code{fortran-column-ruler-tab} is displayed.
  1925. By changing these variables, you can change the column ruler display.
  1926. @kindex C-c C-w @r{(Fortran mode)}
  1927. @findex fortran-window-create-momentarily
  1928. @kbd{C-c C-w} (@code{fortran-window-create-momentarily}) temporarily
  1929. splits the current window horizontally, making a window 72 columns
  1930. wide, so you can see which lines that is too long. Type a space to
  1931. restore the normal width.
  1932. @kindex C-u C-c C-w @r{(Fortran mode)}
  1933. @findex fortran-window-create
  1934. You can also split the window horizontally and continue editing with
  1935. the split in place. To do this, use @kbd{C-u C-c C-w} (@code{M-x
  1936. fortran-window-create}). By editing in this window you can
  1937. immediately see when you make a line too wide to be correct Fortran.
  1938. @findex fortran-strip-sequence-nos
  1939. The command @kbd{M-x fortran-strip-sequence-nos} deletes all text in
  1940. column 72 and beyond, on all lines in the current buffer. This is the
  1941. easiest way to get rid of old sequence numbers.
  1942. @node Fortran Abbrev
  1943. @subsection Fortran Keyword Abbrevs
  1944. Fortran mode provides many built-in abbrevs for common keywords and
  1945. declarations. These are the same sort of abbrev that you can define
  1946. yourself. To use them, you must turn on Abbrev mode. @xref{Abbrevs}.
  1947. The built-in abbrevs are unusual in one way: they all start with a
  1948. semicolon. You cannot normally use semicolon in an abbrev, but Fortran
  1949. mode makes this possible by changing the syntax of semicolon to ``word
  1950. constituent.''
  1951. For example, one built-in Fortran abbrev is @samp{;c} for
  1952. @samp{continue}. If you insert @samp{;c} and then insert a punctuation
  1953. character such as a space or a newline, the @samp{;c} expands automatically
  1954. to @samp{continue}, provided Abbrev mode is enabled.@refill
  1955. Type @samp{;?} or @samp{;C-h} to display a list of all the built-in
  1956. Fortran abbrevs and what they stand for.
  1957. @node Asm Mode
  1958. @section Asm Mode
  1959. @cindex Asm mode
  1960. @cindex assembler mode
  1961. Asm mode is a major mode for editing files of assembler code. It
  1962. defines these commands:
  1963. @table @kbd
  1964. @item @key{TAB}
  1965. @code{tab-to-tab-stop}.
  1966. @item C-j
  1967. Insert a newline and then indent using @code{tab-to-tab-stop}.
  1968. @item :
  1969. Insert a colon and then remove the indentation from before the label
  1970. preceding colon. Then do @code{tab-to-tab-stop}.
  1971. @item ;
  1972. Insert or align a comment.
  1973. @end table
  1974. The variable @code{asm-comment-char} specifies which character
  1975. starts comments in assembler syntax.