cc-mode.texi 161 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635
  1. \input texinfo
  2. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3. @comment %**start of header (This is for running Texinfo on a region)
  4. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5. @comment No overfull hbox marks in the dvi file.
  6. @finalout
  7. @setfilename ../info/ccmode
  8. @settitle CC Mode Manual
  9. @footnotestyle end
  10. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  11. @comment @setchapternewpage odd !! we don't want blank pages !!
  12. @comment %**end of header (This is for running Texinfo on a region)
  13. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  14. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  15. @comment
  16. @comment Texinfo manual for CC Mode
  17. @comment Generated from the original README file by Krishna Padmasola
  18. @comment <krishna@earth-gw.njit.edu>
  19. @comment
  20. @comment Authors:
  21. @comment Barry A. Warsaw
  22. @comment Martin Stjernholm
  23. @comment
  24. @comment Maintained by Martin Stjernholm <bug-cc-mode@gnu.org>
  25. @comment
  26. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  27. @macro copyrightblurb
  28. Copyright @copyright{} 1995, 96, 97, 98, 99, 2000, 01 Free Software Foundation, Inc.
  29. @end macro
  30. @comment Info directory entry for use by install-info. The indentation
  31. @comment here is by request from the FSF folks.
  32. @dircategory Emacs
  33. @direntry
  34. * CC Mode: (ccmode). Emacs mode for editing C, C++, Objective-C,
  35. Java, Pike, and IDL code.
  36. @end direntry
  37. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  38. @comment The following lines inserts the copyright notice
  39. @comment into the Info file.
  40. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  41. @ifnottex
  42. Copyright @copyright{} 1995, 96, 97, 98, 99, 2000, 2001 Free Software Foundation, Inc.
  43. Permission is granted to copy, distribute and/or modify this document
  44. under the terms of the GNU Free Documentation License, Version 1.1 or
  45. any later version published by the Free Software Foundation; with the
  46. Invariant Sections being ``The GNU Manifesto'', ``Distribution'' and
  47. ``GNU GENERAL PUBLIC LICENSE'', with the Front-Cover texts being ``A GNU
  48. Manual'', and with the Back-Cover Texts as in (a) below. A copy of the
  49. license is included in the section entitled ``GNU Free Documentation
  50. License'' in the Emacs manual.
  51. (a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
  52. this GNU Manual, like GNU software. Copies published by the Free
  53. Software Foundation raise funds for GNU development.''
  54. This document is part of a collection distributed under the GNU Free
  55. Documentation License. If you want to distribute this document
  56. separately from the collection, you can do so by adding a copy of the
  57. license to the document, as described in section 6 of the license.
  58. @end ifnottex
  59. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  60. @comment TeX title page
  61. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  62. @titlepage
  63. @sp 10
  64. @center @titlefont{CC Mode 5.28}
  65. @sp 2
  66. @center @subtitlefont{A GNU Emacs mode for editing C and C-like languages}
  67. @sp 2
  68. @center Barry A. Warsaw, Martin Stjernholm
  69. @page
  70. @vskip 0pt plus 1filll
  71. Copyright @copyright{} 1995, 96, 97, 98, 99, 2000, 2001 Free Software Foundation, Inc.
  72. @sp 1
  73. Permission is granted to copy, distribute and/or modify this document
  74. under the terms of the GNU Free Documentation License, Version 1.1 or
  75. any later version published by the Free Software Foundation; with the
  76. Invariant Sections being ``The GNU Manifesto'', ``Distribution'' and
  77. ``GNU GENERAL PUBLIC LICENSE'', with the Front-Cover texts being ``A GNU
  78. Manual'', and with the Back-Cover Texts as in (a) below. A copy of the
  79. license is included in the section entitled ``GNU Free Documentation
  80. License'' in the Emacs manual.
  81. (a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
  82. this GNU Manual, like GNU software. Copies published by the Free
  83. Software Foundation raise funds for GNU development.''
  84. This document is part of a collection distributed under the GNU Free
  85. Documentation License. If you want to distribute this document
  86. separately from the collection, you can do so by adding a copy of the
  87. license to the document, as described in section 6 of the license.
  88. @end titlepage
  89. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  90. @comment The Top node contains the master menu for the Info file.
  91. @comment This appears only in the Info file, not the printed manual.
  92. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  93. @node Top, Introduction, (dir), (dir)
  94. @comment node-name, next, previous, up
  95. @macro ccmode
  96. CC Mode
  97. @end macro
  98. @ifinfo
  99. @top @ccmode{}
  100. @ccmode{} is a GNU Emacs mode for editing files containing C, C++,
  101. Objective-C, Java, CORBA IDL, and Pike code. It provides syntax-based
  102. indentation and has several handy commands and some minor modes to make
  103. the editing easier. Note that @ccmode{} does @emph{not} provide
  104. font-locking; there are other Emacs packages for that.
  105. @end ifinfo
  106. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  107. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  108. @menu
  109. * Introduction::
  110. * Getting Connected::
  111. * New Indentation Engine::
  112. * Minor Modes::
  113. * Text Filling and Line Breaking::
  114. * Commands::
  115. * Customizing Indentation::
  116. * Syntactic Symbols::
  117. * Indentation Functions::
  118. * Performance Issues::
  119. * Limitations and Known Bugs::
  120. * Frequently Asked Questions::
  121. * Getting the Latest CC Mode Release::
  122. * Mailing Lists and Submitting Bug Reports::
  123. * Sample .emacs File::
  124. --- Indices ---
  125. * Concept Index::
  126. * Command Index::
  127. * Key Index::
  128. * Variable Index::
  129. --- The Detailed Node Listing ---
  130. New Indentation Engine
  131. * Syntactic Analysis::
  132. * Indentation Calculation::
  133. Minor Modes
  134. * Auto-newline Insertion::
  135. * Hungry-deletion of Whitespace::
  136. Auto-newline Insertion
  137. * Hanging Braces::
  138. * Hanging Colons::
  139. * Hanging Semi-colons and Commas::
  140. * Other Electric Commands::
  141. * Clean-ups::
  142. Commands
  143. * Indentation Commands::
  144. * Movement Commands::
  145. * Other Commands::
  146. Customizing Indentation
  147. * Interactive Customization::
  148. * Permanent Customization::
  149. * Hooks::
  150. * Styles::
  151. * Advanced Customizations::
  152. Styles
  153. * Built-in Styles::
  154. * Adding Styles::
  155. * File Styles::
  156. Advanced Customizations
  157. * Custom Indentation Functions::
  158. * Custom Brace and Colon Hanging::
  159. * Customizing Semi-colons and Commas::
  160. * Other Special Indentations::
  161. @end menu
  162. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  163. @node Introduction, Getting Connected, Top, Top
  164. @comment node-name, next, previous, up
  165. @chapter Introduction
  166. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  167. @cindex BOCM
  168. Welcome to @ccmode{}, a GNU Emacs mode for editing files containing C,
  169. C++, Objective-C, Java, CORBA IDL, and Pike code. This incarnation of
  170. the mode is descendant from @file{c-mode.el} (also called "Boring Old C
  171. Mode" or BOCM @t{:-)}, and @file{c++-mode.el} version 2, which Barry has
  172. been maintaining since 1992. @ccmode{} represents a significant
  173. milestone in the mode's life. It has been fully merged back with Emacs
  174. 19's @file{c-mode.el}. Also a new, more intuitive and flexible mechanism
  175. for controlling indentation has been developed. Late in 1997, Martin
  176. joined the @ccmode{} Maintainers Team, and implemented the Pike support.
  177. As of 2000 Martin has taken over as the sole maintainer.
  178. This manual describes @ccmode{}
  179. @comment The following line must appear on its own, so that the automated
  180. version 5.28.
  181. @comment Release.py script can update the version number automatically
  182. @ccmode{} supports the editing of K&R and ANSI C, @dfn{ARM}
  183. @footnote{@cite{The Annotated C++ Reference Manual}, by Ellis and
  184. Stroustrup.} C++, Objective-C, Java, CORBA's Interface Definition
  185. Language, and Pike@footnote{A C-like scripting language with its roots
  186. in the LPC language used in some MUD engines. See
  187. @uref{http://pike.idonex.se/}.} files. In this way, you can easily set
  188. up consistent coding styles for use in editing all of these languages.
  189. @ccmode{} does @emph{not} handle font-locking (a.k.a. syntax coloring,
  190. keyword highlighting) or anything of that nature, for any of these
  191. modes. Font-locking is handled by other Emacs packages.
  192. This manual will describe the following:
  193. @itemize @bullet
  194. @item
  195. How to get started using @ccmode{}.
  196. @item
  197. How the new indentation engine works.
  198. @item
  199. How to customize the new indentation engine.
  200. @end itemize
  201. @findex c-mode
  202. @findex c++-mode
  203. @findex objc-mode
  204. @findex java-mode
  205. @findex idl-mode
  206. @findex pike-mode
  207. Note that the name of this package is ``@ccmode{},'' but there is no top
  208. level @code{cc-mode} entry point. All of the variables, commands, and
  209. functions in @ccmode{} are prefixed with @code{c-@var{<thing>}}, and
  210. @code{c-mode}, @code{c++-mode}, @code{objc-mode}, @code{java-mode},
  211. @code{idl-mode}, and @code{pike-mode} entry points are provided. This
  212. package is intended to be a replacement for @file{c-mode.el} and
  213. @file{c++-mode.el}.
  214. @cindex @file{cc-compat.el} file
  215. This distribution also contains a file
  216. called @file{cc-compat.el} which should ease your transition from BOCM
  217. to @ccmode{}. If you have a BOCM configuration you are really happy
  218. with, and want to postpone learning how to configure @ccmode{}, take a
  219. look at that file. It maps BOCM configuration variables to @ccmode{}'s
  220. new indentation model. It is not actively supported so for the long
  221. run, you should learn how to customize @ccmode{} to support your coding
  222. style.
  223. A special word of thanks goes to Krishna Padmasola for his work in
  224. converting the original @file{README} file to Texinfo format. I'd also
  225. like to thank all the @ccmode{} victims who help enormously during the
  226. early beta stages of @ccmode{}'s development.
  227. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  228. @node Getting Connected, New Indentation Engine, Introduction, Top
  229. @comment node-name, next, previous, up
  230. @chapter Getting Connected
  231. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  232. If you got this version of @ccmode{} with Emacs or XEmacs, it should
  233. work just fine right out of the box. Note however that you may not have
  234. the latest @ccmode{} release and may want to upgrade your copy.
  235. If you are upgrading an existing @ccmode{} installation, please see the
  236. @file{README} file for installation details. @ccmode{} may not work
  237. with older versions of Emacs or XEmacs. See the @ccmode{} release notes
  238. Web pages for the latest information on Emacs version and package
  239. compatibility (@pxref{Getting the Latest CC Mode Release}).
  240. @cindex @file{cc-mode-18.el} file
  241. @emph{Note that @ccmode{} no longer
  242. works with Emacs 18!}, so if you haven't upgraded from Emacs 18 by now,
  243. you are out of luck.
  244. @findex c-version
  245. @findex version (c-)
  246. You can find out what version of @ccmode{} you are using by visiting a C
  247. file and entering @kbd{M-x c-version RET}. You should see this message in
  248. the echo area:
  249. @example
  250. Using CC Mode version 5.XX
  251. @end example
  252. @noindent
  253. where @samp{XX} is the minor release number.
  254. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  255. @node New Indentation Engine, Minor Modes, Getting Connected, Top
  256. @comment node-name, next, previous, up
  257. @chapter New Indentation Engine
  258. @cindex indentation engine
  259. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  260. @ccmode{} has a new indentation engine, providing a simplified, yet
  261. flexible and general mechanism for customizing indentation. It separates
  262. indentation calculation into two steps: first, @ccmode{} analyzes the
  263. line of code being indented to determine the kind of language construct
  264. it's looking at, then it applies user defined offsets to the current
  265. line based on this analysis.
  266. This section will briefly cover how indentation is calculated in
  267. @ccmode{}. It is important to understand the indentation model
  268. being used so that you will know how to customize @ccmode{} for
  269. your personal coding style.
  270. @menu
  271. * Syntactic Analysis::
  272. * Indentation Calculation::
  273. @end menu
  274. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  275. @node Syntactic Analysis, Indentation Calculation, , New Indentation Engine
  276. @comment node-name, next, previous, up
  277. @section Syntactic Analysis
  278. @cindex syntactic analysis
  279. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  280. @cindex relative buffer position
  281. @cindex syntactic symbol
  282. @cindex syntactic component
  283. @cindex syntactic component list
  284. The first thing @ccmode{} does when indenting a line of code, is to
  285. analyze the line, determining the @dfn{syntactic component list} of the
  286. construct on that line. A syntactic component consists of a pair of
  287. information (in lisp parlance, a @emph{cons cell}), where the first part
  288. is a @dfn{syntactic symbol}, and the second part is a @dfn{relative
  289. buffer position}. Syntactic symbols describe elements of C code
  290. @footnote{Unless otherwise noted, the term ``C code'' to refers to all
  291. the C-like languages.}, e.g. @code{statement}, @code{substatement},
  292. @code{class-open}, @code{class-close}, etc. @xref{Syntactic Symbols},
  293. for a complete list of currently recognized syntactic symbols and their
  294. semantics. The style variable @code{c-offsets-alist} also contains the
  295. list of currently supported syntactic symbols.
  296. Conceptually, a line of C code is always indented relative to the
  297. indentation of some line higher up in the buffer. This is represented
  298. by the relative buffer position in the syntactic component.
  299. Here is an example. Suppose we had the following code as the only thing
  300. in a C++ buffer @footnote{The line numbers in this and future examples
  301. don't actually appear in the buffer, of course!}:
  302. @example
  303. @group
  304. 1: void swap( int& a, int& b )
  305. 2: @{
  306. 3: int tmp = a;
  307. 4: a = b;
  308. 5: b = tmp;
  309. 6: @}
  310. @end group
  311. @end example
  312. @kindex C-c C-s
  313. @findex c-show-syntactic-information
  314. @findex show-syntactic-information (c-)
  315. We can use the command @kbd{C-c C-s}
  316. (@code{c-show-syntactic-information}) to simply report what the
  317. syntactic analysis is for the current line. Running this command on
  318. line 4 of this example, we'd see in the echo area@footnote{With a universal
  319. argument (i.e. @kbd{C-u C-c C-s}) the analysis is inserted into the
  320. buffer as a comment
  321. on the current line.}:
  322. @example
  323. ((statement . 35))
  324. @end example
  325. This tells us that the line is a statement and it is indented relative
  326. to buffer position 35, which happens to be the @samp{i} in @code{int} on
  327. line 3. If you were to move point to line 3 and hit @kbd{C-c C-s}, you
  328. would see:
  329. @example
  330. ((defun-block-intro . 29))
  331. @end example
  332. This indicates that the @samp{int} line is the first statement in a top
  333. level function block, and is indented relative to buffer position 29,
  334. which is the brace just after the function header.
  335. Here's another example:
  336. @example
  337. @group
  338. 1: int add( int val, int incr, int doit )
  339. 2: @{
  340. 3: if( doit )
  341. 4: @{
  342. 5: return( val + incr );
  343. 6: @}
  344. 7: return( val );
  345. 8: @}
  346. @end group
  347. @end example
  348. @noindent
  349. Hitting @kbd{C-c C-s} on line 4 gives us:
  350. @example
  351. ((substatement-open . 46))
  352. @end example
  353. @cindex substatement
  354. @cindex substatement block
  355. @noindent
  356. which tells us that this is a brace that @emph{opens} a substatement
  357. block. @footnote{A @dfn{substatement} is the line after a
  358. conditional statement, such as @code{if}, @code{else}, @code{while},
  359. @code{do}, @code{switch}, etc. A @dfn{substatement
  360. block} is a brace block following one of these conditional statements.}
  361. @cindex comment-only line
  362. Syntactic component lists can contain more than one component, and
  363. individual syntactic components need not have relative buffer positions.
  364. The most common example of this is a line that contains a @dfn{comment
  365. only line}.
  366. @example
  367. @group
  368. 1: void draw_list( List<Drawables>& drawables )
  369. 2: @{
  370. 3: // call the virtual draw() method on each element in list
  371. 4: for( int i=0; i < drawables.count(), ++i )
  372. 5: @{
  373. 6: drawables[i].draw();
  374. 7: @}
  375. 8: @}
  376. @end group
  377. @end example
  378. @noindent
  379. Hitting @kbd{C-c C-s} on line 3 of this example gives:
  380. @example
  381. ((comment-intro) (defun-block-intro . 46))
  382. @end example
  383. @noindent
  384. and you can see that the syntactic component list contains two syntactic
  385. components. Also notice that the first component,
  386. @samp{(comment-intro)} has no relative buffer position.
  387. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  388. @node Indentation Calculation, , Syntactic Analysis, New Indentation Engine
  389. @comment node-name, next, previous, up
  390. @section Indentation Calculation
  391. @cindex indentation calculation
  392. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  393. Indentation for a line is calculated using the syntactic
  394. component list derived in step 1 above (@pxref{Syntactic Analysis}).
  395. Each component contributes to the final total indentation of the line in
  396. two ways.
  397. First, the syntactic symbols are looked up in the @code{c-offsets-alist}
  398. style variable, which is an association list of syntactic symbols and
  399. the offsets to apply for those symbols. These offsets are added to a
  400. running total.
  401. Second, if the component has a relative buffer position, @ccmode{}
  402. adds the column number of that position to the running total. By adding
  403. up the offsets and columns for every syntactic component on the list,
  404. the final total indentation for the current line is computed.
  405. Let's use our two code examples above to see how this works. Here is
  406. our first example again:
  407. @example
  408. @group
  409. 1: void swap( int& a, int& b )
  410. 2: @{
  411. 3: int tmp = a;
  412. 4: a = b;
  413. 5: b = tmp;
  414. 6: @}
  415. @end group
  416. @end example
  417. Let's say point is on line 3 and we hit the @kbd{TAB} key to re-indent
  418. the line. Remember that the syntactic component list for that
  419. line is:
  420. @example
  421. ((defun-block-intro . 29))
  422. @end example
  423. @noindent
  424. @ccmode{} looks up @code{defun-block-intro} in the
  425. @code{c-offsets-alist} style variable. Let's say it finds the value
  426. @samp{4}; it adds this to the running total (initialized to zero),
  427. yielding a running total indentation of 4 spaces.
  428. Next @ccmode{} goes to buffer position 29 and asks for the current
  429. column. This brace is in column zero, so @ccmode{}
  430. adds @samp{0} to the running total. Since there is only one syntactic
  431. component on the list for this line, indentation calculation is
  432. complete, and the total indentation for the line
  433. is 4 spaces.
  434. Here's another example:
  435. @example
  436. @group
  437. 1: int add( int val, int incr, int doit )
  438. 2: @{
  439. 3: if( doit )
  440. 4: @{
  441. 5: return( val + incr );
  442. 6: @}
  443. 7: return( val );
  444. 8: @}
  445. @end group
  446. @end example
  447. If we were to hit @kbd{TAB} on line 4 in the above example, the same
  448. basic process is performed, despite the differences in the syntactic
  449. component list. Remember that the list for this line is:
  450. @example
  451. ((substatement-open . 46))
  452. @end example
  453. Here, @ccmode{} first looks up the @code{substatement-open} symbol
  454. in @code{c-offsets-alist}. Let's say it finds the value @samp{4}. This
  455. yields a running total of 4. @ccmode{} then goes to
  456. buffer position 46, which is the @samp{i} in @code{if} on line 3. This
  457. character is in the fourth column on that line so adding this to the
  458. running total yields an indentation for the line of 8 spaces.
  459. Simple, huh?
  460. Actually, the mode usually just does The Right Thing without you having
  461. to think about it in this much detail. But when customizing
  462. indentation, it's helpful to understand the general indentation model
  463. being used.
  464. @vindex c-echo-syntactic-information-p
  465. @vindex echo-syntactic-information-p (c-)
  466. As you configure @ccmode{}, you might want to set the variable
  467. @code{c-echo-syntactic-information-p} to non-@code{nil} so that the
  468. syntactic component list and calculated offset will always be echoed in
  469. the minibuffer when you hit @kbd{TAB}.
  470. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  471. @node Minor Modes, Text Filling and Line Breaking, New Indentation Engine, Top
  472. @comment node-name, next, previous, up
  473. @chapter Minor Modes
  474. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  475. @ccmode{} contains two minor-mode-like features that you should
  476. find useful while you enter new C code. The first is called
  477. @dfn{auto-newline} mode, and the second is called @dfn{hungry-delete}
  478. mode. These minor modes can be toggled on and off independently, and
  479. @ccmode{} can be configured so that it starts up with any
  480. combination of these minor modes. By default, both of these minor modes
  481. are turned off.
  482. The state of the minor modes is always reflected in the minor mode list
  483. on the modeline of the @ccmode{} buffer. When auto-newline mode is
  484. enabled, you will see @samp{C/a} on the mode line @footnote{The @samp{C}
  485. would be replaced with @samp{C++}, @samp{ObjC}, @samp{Java}, @samp{IDL},
  486. or @samp{Pike} for the respective languages.}. When hungry delete mode
  487. is enabled you would see @samp{C/h} and when both modes are enabled,
  488. you'd see @samp{C/ah}.
  489. @kindex C-c C-a
  490. @kindex C-c C-d
  491. @kindex C-c C-t
  492. @findex c-toggle-hungry-state
  493. @findex c-toggle-auto-state
  494. @findex c-toggle-auto-hungry-state
  495. @findex toggle-hungry-state (c-)
  496. @findex toggle-auto-state (c-)
  497. @findex toggle-auto-hungry-state (c-)
  498. @ccmode{} provides key bindings which allow you to toggle the minor
  499. modes on the fly while editing code. To toggle just the auto-newline
  500. state, hit @kbd{C-c C-a} (@code{c-toggle-auto-state}). When you do
  501. this, you should see the @samp{a} indicator either appear or disappear
  502. on the modeline. Similarly, to toggle just the hungry-delete state, use
  503. @kbd{C-c C-d} (@code{c-toggle-hungry-state}), and to toggle both states,
  504. use @kbd{C-c C-t} (@code{c-toggle-auto-hungry-state}).
  505. To set up the auto-newline and hungry-delete states to your preferred
  506. values, you would need to add some lisp to your @file{.emacs} file that
  507. called one of the @code{c-toggle-*-state} functions directly. When
  508. called programmatically, each function takes a numeric value, where
  509. a positive number enables the minor mode, a negative number disables the
  510. mode, and zero toggles the current state of the mode.
  511. So for example, if you wanted to enable both auto-newline and
  512. hungry-delete for all your C file editing, you could add the following
  513. to your @file{.emacs} file:
  514. @example
  515. (add-hook 'c-mode-common-hook
  516. (lambda () (c-toggle-auto-hungry-state 1)))
  517. @end example
  518. @cindex electric characters
  519. @menu
  520. * Auto-newline Insertion::
  521. * Hungry-deletion of Whitespace::
  522. @end menu
  523. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  524. @node Auto-newline Insertion, Hungry-deletion of Whitespace, , Minor Modes
  525. @comment node-name, next, previous, up
  526. @section Auto-newline Insertion
  527. @cindex auto-newline insertion
  528. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  529. @cindex electric commands
  530. Auto-newline minor mode works by enabling certain @dfn{electric
  531. commands}. Electric commands are typically bound to special characters
  532. such as the left and right braces, colons, semi-colons, etc., which when
  533. typed, perform some magic formatting in addition to inserting the typed
  534. character. As a general rule, electric commands are only electric when
  535. the following conditions apply:
  536. @itemize @bullet
  537. @item
  538. Auto-newline minor mode is enabled, as evidenced by a @samp{C/a} or
  539. @samp{C/ah} indicator on the modeline.
  540. @cindex literal
  541. @cindex syntactic whitespace
  542. @item
  543. The character was not typed inside of a literal @footnote{A
  544. @dfn{literal} is defined as any comment, string, or C preprocessor macro
  545. definition. These constructs are also known as @dfn{syntactic
  546. whitespace} since they are usually ignored when scanning C code.}.
  547. @item
  548. @kindex C-u
  549. No numeric argument was supplied to the command (i.e. it was typed as
  550. normal, with no @kbd{C-u} prefix).
  551. @end itemize
  552. @menu
  553. * Hanging Braces::
  554. * Hanging Colons::
  555. * Hanging Semi-colons and Commas::
  556. * Other Electric Commands::
  557. * Clean-ups::
  558. @end menu
  559. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  560. @node Hanging Braces, Hanging Colons, , Auto-newline Insertion
  561. @comment node-name, next, previous, up
  562. @subsection Hanging Braces
  563. @cindex hanging braces
  564. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  565. @findex c-electric-brace
  566. @findex electric-brace (c-)
  567. @vindex c-hanging-braces-alist
  568. @vindex hanging-braces-alist (c-)
  569. When you type either an open or close brace (i.e. @kbd{@{} or @kbd{@}}),
  570. the electric command @code{c-electric-brace} gets run. This command has
  571. two electric formatting behaviors. First, it will perform some
  572. re-indentation of the line the brace was typed on, and second, it will
  573. add various newlines before and/or after the typed brace.
  574. Re-indentation occurs automatically whenever the electric behavior is
  575. enabled. If the brace ends up on a line other than the one it was typed
  576. on, then that line is also re-indented.
  577. @cindex class-open syntactic symbol
  578. @cindex class-close syntactic symbol
  579. @cindex defun-open syntactic symbol
  580. @cindex defun-close syntactic symbol
  581. @cindex inline-open syntactic symbol
  582. @cindex inline-close syntactic symbol
  583. @cindex brace-list-open syntactic symbol
  584. @cindex brace-list-close syntactic symbol
  585. @cindex brace-list-intro syntactic symbol
  586. @cindex brace-entry-open syntactic symbol
  587. @cindex block-open syntactic symbol
  588. @cindex block-close syntactic symbol
  589. @cindex substatement-open syntactic symbol
  590. @cindex statement-case-open syntactic symbol
  591. @cindex extern-lang-open syntactic symbol
  592. @cindex extern-lang-close syntactic symbol
  593. @cindex namespace-open syntactic symbol
  594. @cindex namespace-close syntactic symbol
  595. @cindex inexpr-class-open symbol
  596. @cindex inexpr-class-close symbol
  597. The default in auto-newline mode is to insert newlines both before and
  598. after a brace, but that can be controlled by the
  599. @code{c-hanging-braces-alist} style variable. This variable contains a
  600. mapping between syntactic symbols related to braces, and a list of
  601. places to insert a newline. The syntactic symbols that are useful for
  602. this list are: @code{class-open}, @code{class-close}, @code{defun-open},
  603. @code{defun-close}, @code{inline-open}, @code{inline-close},
  604. @code{brace-list-open}, @code{brace-list-close},
  605. @code{brace-list-intro}, @code{brace-entry-open}, @code{block-open},
  606. @code{block-close}, @code{substatement-open},
  607. @code{statement-case-open}, @code{extern-lang-open},
  608. @code{extern-lang-close}, @code{namespace-open}, @code{namespace-close},
  609. @code{inexpr-class-open}, and @code{inexpr-class-close}@footnote{Note
  610. that the aggregate constructs in Pike mode, @samp{(@{}, @samp{@})},
  611. @samp{([}, @samp{])}, and @samp{(<}, @samp{>)}, do not count as brace
  612. lists in this regard, even though they do for normal indentation
  613. purposes. It's currently not possible to set automatic newlines on
  614. these constructs.}. @xref{Syntactic Symbols}, for a more detailed
  615. description of these syntactic symbols, except for
  616. @code{inexpr-class-open} and @code{inexpr-class-close}, which aren't
  617. actual syntactic symbols.
  618. The braces of anonymous inner classes in Java are given the special
  619. symbols @code{inexpr-class-open} and @code{inexpr-class-close}, so that
  620. they can be distinguished from the braces of normal classes@footnote{The
  621. braces of anonymous classes produces a combination of
  622. @code{inexpr-class}, and @code{class-open} or @code{class-close} in
  623. normal indentation analysis.}.
  624. The value associated with each syntactic symbol in this association list
  625. is called an @var{ACTION} which can be either a function or a list.
  626. @xref{Custom Brace and Colon Hanging}, for a more detailed discussion of
  627. using a function as a brace hanging @var{ACTION}.
  628. When the @var{ACTION} is a list, it can contain any combination of the
  629. symbols @code{before} and @code{after}, directing @ccmode{} where to
  630. put newlines in relationship to the brace being inserted. Thus, if the
  631. list contains only the symbol @code{after}, then the brace is said to
  632. @dfn{hang} on the right side of the line, as in:
  633. @example
  634. @group
  635. // here, open braces always `hang'
  636. void spam( int i ) @{
  637. if( i == 7 ) @{
  638. dosomething(i);
  639. @}
  640. @}
  641. @end group
  642. @end example
  643. When the list contains both @code{after} and @code{before}, the braces
  644. will appear on a line by themselves, as shown by the close braces in the
  645. above example. The list can also be empty, in which case no newlines
  646. are added either before or after the brace.
  647. If a syntactic symbol is missing entirely from
  648. @code{c-hanging-braces-alist}, it's treated in the same way as an
  649. @var{ACTION} with a list containing @code{before} and @code{after}, so
  650. that braces by default end up on their own line.
  651. For example, the default value of @code{c-hanging-braces-alist} is:
  652. @example
  653. @group
  654. ((brace-list-open)
  655. (brace-entry-open)
  656. (substatement-open after)
  657. (block-close . c-snug-do-while)
  658. (extern-lang-open after)
  659. (inexpr-class-open after)
  660. (inexpr-class-close before))
  661. @end group
  662. @end example
  663. @noindent which says that @code{brace-list-open} and
  664. @code{brace-entry-open} braces should both hang on the right side, and
  665. allow subsequent text to follow on the same line as the brace. Also,
  666. @code{substatement-open}, @code{extern-lang-open}, and
  667. @code{inexpr-class-open} braces should hang on the right side, but
  668. subsequent text should follow on the next line. The opposite holds for
  669. @code{inexpr-class-close} braces; they won't hang, but the following
  670. text continues on the same line. Here, in the @code{block-close} entry,
  671. you also see an example of using a function as an @var{ACTION}. In all
  672. other cases, braces are put on a line by themselves.
  673. A word of caution: it is not a good idea to hang top-level construct
  674. introducing braces, such as @code{class-open} or @code{defun-open}.
  675. Emacs makes an assumption that such braces will always appear in column
  676. zero, hanging them can introduce performance problems.
  677. @xref{Performance Issues}, for more information.
  678. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  679. @node Hanging Colons, Hanging Semi-colons and Commas, Hanging Braces, Auto-newline Insertion
  680. @comment node-name, next, previous, up
  681. @subsection Hanging Colons
  682. @cindex hanging colons
  683. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  684. @vindex hanging-colons-alist (c-)
  685. @vindex c-hanging-colons-alist
  686. Using a mechanism similar to brace hanging (@pxref{Hanging Braces}),
  687. colons can also be made to hang using the style variable
  688. @code{c-hanging-colons-alist}. The syntactic symbols appropriate for
  689. this association list are: @code{case-label}, @code{label},
  690. @code{access-label}, @code{member-init-intro}, and @code{inher-intro}.
  691. Note however that for @code{c-hanging-colons-alist}, @var{ACTION}s as
  692. functions are not supported. See also @ref{Custom Brace and Colon
  693. Hanging} for details.
  694. In C++, double-colons are used as a scope operator but because these
  695. colons always appear right next to each other, newlines before and after
  696. them are controlled by a different mechanism, called @dfn{clean-ups} in
  697. @ccmode{}. @xref{Clean-ups}, for details.
  698. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  699. @node Hanging Semi-colons and Commas, Other Electric Commands, Hanging Colons, Auto-newline Insertion
  700. @comment node-name, next, previous, up
  701. @subsection Hanging Semi-colons and Commas
  702. @cindex hanging semi-colons
  703. @cindex hanging commas
  704. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  705. Semicolons and commas are also electric in @ccmode{}, but since
  706. these characters do not correspond directly to syntactic symbols, a
  707. different mechanism is used to determine whether newlines should be
  708. automatically inserted after these characters. @xref{Customizing
  709. Semi-colons and Commas}, for details.
  710. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  711. @node Other Electric Commands, Clean-ups, Hanging Semi-colons and Commas, Auto-newline Insertion
  712. @comment node-name, next, previous, up
  713. @subsection Other Electric Commands
  714. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  715. @kindex #
  716. @findex c-electric-pound
  717. @vindex c-electric-pound-behavior
  718. @findex electric-pound (c-)
  719. @vindex electric-pound-behavior (c-)
  720. A few other keys also provide electric behavior. For example
  721. @kbd{#} (@code{c-electric-pound}) is electric when typed as
  722. the first non-whitespace character on a line. In this case, the
  723. variable @code{c-electric-pound-behavior} is consulted for the electric
  724. behavior. This variable takes a list value, although the only element
  725. currently defined is @code{alignleft}, which tells this command to force
  726. the @samp{#} character into column zero. This is useful for entering
  727. C preprocessor macro definitions.
  728. @findex c-electric-star
  729. @findex c-electric-slash
  730. @findex electric-star (c-)
  731. @findex electric-slash (c-)
  732. Stars and slashes (i.e. @kbd{*} and @kbd{/}, @code{c-electric-star} and
  733. @code{c-electric-slash} respectively) are also electric under
  734. certain circumstances. If a star is inserted as the second character of
  735. a C style block comment on a comment-only line, then the comment
  736. delimiter is indented as defined by @code{c-offsets-alist}. A
  737. comment-only line is defined as a line which contains only a comment, as
  738. in:
  739. @example
  740. @group
  741. void spam( int i )
  742. @{
  743. // this is a comment-only line...
  744. if( i == 7 ) // but this is not
  745. @{
  746. dosomething(i);
  747. @}
  748. @}
  749. @end group
  750. @end example
  751. Likewise, if a slash is inserted as the second slash in a C++ style line
  752. comment (also only on a comment-only line), then the line is indented as
  753. defined by @code{c-offsets-alist}.
  754. @findex c-electric-lt-gt
  755. @findex electric-lt-gt (c-)
  756. @kindex <
  757. @kindex >
  758. Less-than and greater-than signs (@code{c-electric-lt-gt}) are also
  759. electric, but only in C++ mode. Hitting the second of two @kbd{<} or
  760. @kbd{>} keys re-indents the line if it is a C++ style stream operator.
  761. @findex c-electric-paren
  762. @findex electric-paren (c-)
  763. @kindex (
  764. @kindex )
  765. The normal parenthesis characters @samp{(} and @samp{)} also reindent
  766. the current line if they are used in normal code. This is useful for
  767. getting the closing parenthesis of an argument list aligned
  768. automatically.
  769. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  770. @node Clean-ups, , Other Electric Commands, Auto-newline Insertion
  771. @comment node-name, next, previous, up
  772. @subsection Clean-ups
  773. @cindex clean-ups
  774. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  775. @dfn{Clean-ups} are mechanisms complementary to colon and brace hanging.
  776. On the surface, it would seem that clean-ups overlap the functionality
  777. provided by the @code{c-hanging-*-alist} variables. Clean-ups are
  778. however used to adjust code ``after-the-fact,'' i.e. to adjust the
  779. whitespace in constructs after they are typed.
  780. Most of the clean-ups are only applicable to counteract automatically
  781. inserted newlines, and will therefore only have any effect if the
  782. auto-newline minor mode is turned on. Others will work all the time.
  783. @vindex c-cleanup-list
  784. @vindex cleanup-list (c-)
  785. @cindex literal
  786. You can configure @ccmode{}'s clean-ups by setting the style variable
  787. @code{c-cleanup-list}, which is a list of clean-up symbols. By default,
  788. @ccmode{} cleans up only the @code{scope-operator} construct, which is
  789. necessary for proper C++ support. Note that clean-ups are only
  790. performed when the construct does not occur within a literal
  791. (@pxref{Auto-newline Insertion}), and when there is nothing but
  792. whitespace appearing between the individual components of the construct.
  793. These are the clean-ups that only are active in the auto-newline minor
  794. mode:
  795. @itemize @bullet
  796. @item
  797. @code{brace-else-brace} --- Clean up @samp{@} else @{} constructs by
  798. placing the entire construct on a single line. Clean-up occurs when the
  799. open brace after the @samp{else} is typed. So for example, this:
  800. @example
  801. @group
  802. void spam(int i)
  803. @{
  804. if( i==7 )
  805. @{
  806. dosomething();
  807. @}
  808. else
  809. @{
  810. @end group
  811. @end example
  812. @noindent
  813. appears like this after the open brace is typed:
  814. @example
  815. @group
  816. void spam(int i)
  817. @{
  818. if( i==7 ) @{
  819. dosomething();
  820. @} else @{
  821. @end group
  822. @end example
  823. @item
  824. @code{brace-elseif-brace} --- Similar to the @code{brace-else-brace}
  825. clean-up, but this cleans up @samp{@} else if (...) @{} constructs. For
  826. example:
  827. @example
  828. @group
  829. void spam(int i)
  830. @{
  831. if( i==7 )
  832. @{
  833. dosomething();
  834. @}
  835. else if( i==3 )
  836. @{
  837. @end group
  838. @end example
  839. @noindent
  840. appears like this after the open parenthesis is typed:
  841. @example
  842. @group
  843. void spam(int i)
  844. @{
  845. if( i==7 ) @{
  846. dosomething();
  847. @} else if( i==3 )
  848. @{
  849. @end group
  850. @end example
  851. @noindent
  852. and like this after the open brace is typed:
  853. @example
  854. @group
  855. void spam(int i)
  856. @{
  857. if( i==7 ) @{
  858. dosomething();
  859. @} else if( i==3 ) @{
  860. @end group
  861. @end example
  862. @item
  863. @code{brace-catch-brace} --- Analogous to @code{brace-elseif-brace}, but
  864. cleans up @samp{@} catch (...) @{} in C++ and Java mode.
  865. @item
  866. @code{empty-defun-braces} --- Clean up braces following a top-level
  867. function or class definition that contains no body. Clean up occurs
  868. when the closing brace is typed. Thus the following:
  869. @example
  870. @group
  871. class Spam
  872. @{
  873. @}
  874. @end group
  875. @end example
  876. @noindent
  877. is transformed into this when the close brace is typed:
  878. @example
  879. @group
  880. class Spam
  881. @{@}
  882. @end group
  883. @end example
  884. @item
  885. @code{defun-close-semi} --- Clean up the terminating semi-colon on
  886. top-level function or class definitions when they follow a close
  887. brace. Clean up occurs when the semi-colon is typed.
  888. So for example, the following:
  889. @example
  890. @group
  891. class Spam
  892. @{
  893. @}
  894. ;
  895. @end group
  896. @end example
  897. @noindent
  898. is transformed into this when the semi-colon is typed:
  899. @example
  900. @group
  901. class Spam
  902. @{
  903. @};
  904. @end group
  905. @end example
  906. @item
  907. @code{list-close-comma} --- Clean up commas following braces in array
  908. and aggregate initializers. Clean up occurs when the comma is typed.
  909. @item
  910. @code{scope-operator} --- Clean up double colons which may designate a
  911. C++ scope operator split across multiple lines@footnote{Certain C++
  912. constructs introduce ambiguous situations, so @code{scope-operator}
  913. clean-ups may not always be correct. This usually only occurs when
  914. scoped identifiers appear in switch label tags.}. Clean up occurs when
  915. the second colon is typed. You will always want @code{scope-operator}
  916. in the @code{c-cleanup-list} when you are editing C++ code.
  917. @end itemize
  918. The following clean-ups are always active when they occur on
  919. @code{c-cleanup-list}, and are thus not affected by the auto-newline
  920. minor mode:
  921. @itemize @bullet
  922. @item
  923. @code{space-before-funcall} --- Insert a space between the function name
  924. and the opening parenthesis of a function call. This produces function
  925. calls in the style mandated by the GNU coding standards,
  926. e.g. @samp{signal (SIGINT, SIG_IGN)} and @samp{abort ()}. Clean up
  927. occurs when the opening parenthesis is typed.
  928. @item
  929. @code{compact-empty-funcall} --- Clean up any space between the function
  930. name and the opening parenthesis of a function call that have no
  931. arguments. This is typically used together with
  932. @code{space-before-funcall} if you prefer the GNU function call style
  933. for functions with arguments but think it looks ugly when it's only an
  934. empty parenthesis pair. I.e. you will get @samp{signal (SIGINT,
  935. SIG_IGN)}, but @samp{abort()}. Clean up occurs when the closing
  936. parenthesis is typed.
  937. @end itemize
  938. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  939. @node Hungry-deletion of Whitespace, , Auto-newline Insertion, Minor Modes
  940. @comment node-name, next, previous, up
  941. @section Hungry-deletion of Whitespace
  942. @cindex hungry-deletion of whitespace
  943. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  944. Hungry deletion of whitespace, or as it more commonly called,
  945. @dfn{hungry-delete mode}, is a simple feature that some people find
  946. extremely useful. In fact, you might find yourself wanting
  947. hungry-delete in @strong{all} your editing modes!
  948. @kindex DEL
  949. @kindex Backspace
  950. In a nutshell, when hungry-delete mode is enabled, hitting the
  951. @key{Backspace} key@footnote{I say ``hit the @key{Backspace} key'' but
  952. what I really mean is ``when Emacs receives the @code{BackSpace} key
  953. event.'' The difference usually isn't significant to most users, but
  954. advanced users will realize that under window systems such as X, any
  955. physical key (keycap) on the keyboard can be configured to generate any
  956. keysym, and thus any Emacs key event. Also, the use of Emacs on TTYs
  957. will affect which keycap generates which key event. From a pedantic
  958. point of view, here we are only concerned with the key event that
  959. Emacs receives.} will consume all preceding whitespace, including
  960. newlines and tabs. This can really cut down on the number of
  961. @key{Backspace}'s you have to type if, for example you made a mistake on
  962. the preceding line.
  963. @findex c-electric-backspace
  964. @findex electric-backspace (c-)
  965. @vindex c-backspace-function
  966. @vindex backspace-function (c-)
  967. @findex c-electric-delete
  968. @findex electric-delete (c-)
  969. @vindex c-delete-function
  970. @vindex delete-function (c-)
  971. @cindex literal
  972. @findex backward-delete-char-untabify
  973. By default, when you hit the @key{Backspace} key @ccmode{} runs the
  974. command @code{c-electric-backspace}, which deletes text in the backwards
  975. direction. When deleting a single character, or when @key{Backspace} is
  976. hit in a literal (@pxref{Auto-newline Insertion}), or when hungry-delete
  977. mode is disabled, the function contained in the
  978. @code{c-backspace-function} variable is called with one argument (the
  979. number of characters to delete). This variable is set to
  980. @code{backward-delete-char-untabify} by default.
  981. @vindex delete-key-deletes-forward
  982. @findex delete-char
  983. The default behavior of the @key{Delete} key depends on the flavor of
  984. Emacs you are using. By default in XEmacs 20.3 and beyond, the
  985. @key{Delete} key is bound to @code{c-electric-delete}. You control the
  986. direction that the @key{Delete} key deletes by setting the variable
  987. @code{delete-key-deletes-forward}, a standard XEmacs variable. When
  988. this variable is non-@code{nil} and hungry-delete mode is enabled,
  989. @code{c-electric-delete} will consume all whitespace @emph{following}
  990. point. When @code{delete-key-deletes-forward} is @code{nil}, it deletes
  991. all whitespace @emph{preceding} point@footnote{i.e. it literally calls
  992. @code{c-electric-backspace}.} When deleting a single character, or if
  993. @key{Delete} is hit in a literal, or hungry-delete mode is disabled, the
  994. function contained in @code{c-delete-function} is called with one
  995. argument: the number of characters to delete. This variable is set to
  996. @code{delete-char} by default.
  997. In Emacs 19 or Emacs 20, both the @key{Delete} and @key{Backspace} keys
  998. are bound to @code{c-electric-backspace}, however you can change this by
  999. explicitly binding @code{[delete]}@footnote{E.g. to
  1000. @code{c-electric-delete} in your @file{.emacs} file. Note however, that
  1001. Emacs 20 does not have a standard variable such as
  1002. @code{delete-key-deletes-forward}.}.
  1003. XEmacsen older than 20.3 behave similar to Emacs 19 and Emacs 20.
  1004. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1005. @node Text Filling and Line Breaking, Commands, Minor Modes, Top
  1006. @comment node-name, next, previous, up
  1007. @chapter Text Filling and Line Breaking
  1008. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1009. Since there's a lot of normal text in comments and string literals,
  1010. @ccmode{} provides features to edit these like in text mode. The goal
  1011. is to do it as seamlessly as possible, i.e. you can use auto fill mode,
  1012. sentence and paragraph movement, paragraph filling, adaptive filling etc
  1013. wherever there's a piece of normal text without having to think much
  1014. about it. @ccmode{} should keep the indentation, fix the comment line
  1015. decorations, and so on, for you. It does that by hooking in on the
  1016. different line breaking functions and tuning relevant variables as
  1017. necessary.
  1018. @vindex c-comment-prefix-regexp
  1019. @vindex comment-prefix-regexp (c-)
  1020. @cindex comment line prefix
  1021. @vindex comment-start
  1022. @vindex comment-end
  1023. @vindex comment-start-skip
  1024. @vindex paragraph-start
  1025. @vindex paragraph-separate
  1026. @vindex paragraph-ignore-fill-prefix
  1027. @vindex adaptive-fill-mode
  1028. @vindex adaptive-fill-regexp
  1029. @vindex adaptive-fill-first-line-regexp
  1030. To make Emacs recognize comments and treat text in them as normal
  1031. paragraphs, @ccmode{} makes several standard
  1032. variables@footnote{@code{comment-start}, @code{comment-end},
  1033. @code{comment-start-skip}, @code{paragraph-start},
  1034. @code{paragraph-separate}, @code{paragraph-ignore-fill-prefix},
  1035. @code{adaptive-fill-mode}, @code{adaptive-fill-regexp}, and
  1036. @code{adaptive-fill-first-line-regexp}.} buffer local and modifies them
  1037. according to the language syntax and the style of line decoration that
  1038. starts every line in a comment. The style variable
  1039. @code{c-comment-prefix-regexp} contains the regexp used to recognize
  1040. this @dfn{comment line prefix}. The default is @samp{//+\\|\\**}, which
  1041. matches C++ style line comments like
  1042. @example
  1043. // blah blah
  1044. @end example
  1045. @noindent
  1046. with two or more slashes in front of them, and C style block comments
  1047. like
  1048. @example
  1049. @group
  1050. /*
  1051. * blah blah
  1052. */
  1053. @end group
  1054. @end example
  1055. @noindent
  1056. with zero or more stars at the beginning of every line. If you change
  1057. that variable, please make sure it still matches the comment starter
  1058. (i.e. @code{//}) of line comments @emph{and} the line prefix inside
  1059. block comments. Also note that since @ccmode{} uses the value of
  1060. @code{c-comment-prefix-regexp} to set up several other variables at mode
  1061. initialization, you need to reinitialize the program mode if you change
  1062. it inside a @ccmode{} buffer.
  1063. @findex auto-fill-mode
  1064. @cindex auto fill mode
  1065. @cindex paragraph fill
  1066. Line breaks are by default handled (almost) the same regardless whether
  1067. they are made by auto fill mode (@pxref{Auto Fill,,, emacs, The Emacs
  1068. Editor}), paragraph filling (e.g. with @kbd{M-q}), or explicitly with
  1069. @kbd{M-j} or similar methods. In string literals, the new line gets the
  1070. same indentation as the previous nonempty line (may be changed with the
  1071. @code{string} syntactic symbol). In comments, @ccmode{} uses
  1072. @code{c-comment-prefix-regexp} to adapt the line prefix from the other
  1073. lines in the comment.
  1074. @vindex adaptive-fill-mode
  1075. @cindex adaptive fill mode
  1076. @ccmode{} uses adaptive fill mode (@pxref{Adaptive Fill,,, emacs, The
  1077. Emacs Editor}) to make Emacs correctly keep the line prefix when filling
  1078. paragraphs. That also makes Emacs preserve the text indentation
  1079. @emph{inside} the comment line prefix. E.g. in the following comment,
  1080. both paragraphs will be filled with the left margins kept intact:
  1081. @example
  1082. @group
  1083. /* Make a balanced b-tree of the nodes in the incoming
  1084. * stream. But, to quote the famous words of Donald E.
  1085. * Knuth,
  1086. *
  1087. * Beware of bugs in the above code; I have only
  1088. * proved it correct, not tried it.
  1089. */
  1090. @end group
  1091. @end example
  1092. @findex c-setup-filladapt
  1093. @findex setup-filladapt (c-)
  1094. @findex filladapt-mode
  1095. @vindex filladapt-mode
  1096. @cindex Filladapt mode
  1097. It's also possible to use other adaptive filling packages, notably Kyle
  1098. E. Jones' Filladapt package@footnote{It's available from
  1099. @uref{http://www.wonderworks.com/}. As of version 2.12, it does however
  1100. lack a feature that makes it work suboptimally when
  1101. @code{c-comment-prefix-regexp} matches the empty string (which it does
  1102. by default). A patch for that is available from
  1103. @uref{http://cc-mode.sourceforge.net/,, the CC Mode site}.},
  1104. which handles things like bulleted lists nicely. There's a convenience
  1105. function @code{c-setup-filladapt} that tunes the relevant variables in
  1106. Filladapt for use in @ccmode{}. Call it from a mode hook, e.g. with
  1107. something like this in your @file{.emacs}:
  1108. @example
  1109. @group
  1110. (defun my-c-mode-common-hook ()
  1111. (c-setup-filladapt)
  1112. (filladapt-mode 1))
  1113. (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
  1114. @end group
  1115. @end example
  1116. @vindex c-block-comment-prefix
  1117. @vindex block-comment-prefix (c-)
  1118. @vindex c-comment-continuation-stars
  1119. @vindex comment-continuation-stars (c-)
  1120. Normally the comment line prefix inserted for a new line inside a
  1121. comment is deduced from other lines in it. However there's one
  1122. situation when there's no clue about how the prefix should look, namely
  1123. when a block comment is broken for the first time. The string in the
  1124. style variable @code{c-block-comment-prefix}@footnote{In versions before
  1125. 5.26, this variable was called @code{c-comment-continuation-stars}. As
  1126. a compatibility measure, @ccmode{} still uses the value on that variable
  1127. if it's set.} is used in that case. It defaults to @samp{* }, which
  1128. makes a comment
  1129. @example
  1130. /* Got O(n^2) here, which is a Bad Thing. */
  1131. @end example
  1132. @noindent
  1133. break into
  1134. @example
  1135. @group
  1136. /* Got O(n^2) here,
  1137. * which is a Bad Thing. */
  1138. @end group
  1139. @end example
  1140. Note that it won't work to justify the indentation by putting leading
  1141. spaces in the @code{c-block-comment-prefix} string, since @ccmode{}
  1142. still uses the normal indentation engine to indent the line. Thus, the
  1143. right way to fix the indentation is by setting the @code{c} syntactic
  1144. symbol. It defaults to @code{c-lineup-C-comments}, which handles the
  1145. indentation of most common comment styles, see @ref{Indentation
  1146. Functions}.
  1147. @vindex c-ignore-auto-fill
  1148. @vindex ignore-auto-fill (c-)
  1149. When auto fill mode is enabled, @ccmode{} can selectively ignore it
  1150. depending on the context the line break would occur in, e.g. to never
  1151. break a line automatically inside a string literal. This behavior can
  1152. be controlled with the @code{c-ignore-auto-fill} variable. It takes a
  1153. list of symbols for the different contexts where auto-filling never
  1154. should occur:
  1155. @itemize @bullet
  1156. @item @code{string} --- Inside a string or character literal.
  1157. @item @code{c} --- Inside a C style block comment.
  1158. @item @code{c++} --- Inside a C++ style line comment.
  1159. @item @code{cpp} --- Inside a preprocessor directive.
  1160. @item @code{code} --- Anywhere else, i.e. in normal code.
  1161. @end itemize
  1162. By default, @code{c-ignore-auto-fill} is set to @code{'(string cpp
  1163. code)}, which means that auto-filling only occurs in comments when
  1164. auto-fill mode is activated. In literals, it's often desirable to have
  1165. explicit control over newlines. In preprocessor directives, the
  1166. necessary @samp{\} escape character before the newline is not
  1167. automatically inserted, so an automatic line break would produce invalid
  1168. code. In normal code, line breaks are normally dictated by some logical
  1169. structure in the code rather than the last whitespace character, so
  1170. automatic line breaks there will produce poor results in the current
  1171. implementation.
  1172. The commands that does the actual work follows.
  1173. @table @asis
  1174. @kindex M-q
  1175. @findex c-fill-paragraph
  1176. @findex fill-paragraph (c-)
  1177. @cindex Javadoc markup
  1178. @cindex Pike autodoc markup
  1179. @item @kbd{M-q} (@code{c-fill-paragraph})
  1180. This is the replacement for @code{fill-paragraph} in @ccmode{}
  1181. buffers. It's used to fill multiline string literals and both block and
  1182. line style comments. In Java buffers, the Javadoc markup words are
  1183. recognized as paragraph starters. The line oriented Pike autodoc markup
  1184. words are recognized in the same way in Pike mode.
  1185. The function keeps the comment starters and enders of block comments as
  1186. they were before the filling. This means that a comment ender on the
  1187. same line as the paragraph being filled will be filled with the
  1188. paragraph, and one on a line by itself will stay as it is. The comment
  1189. starter is handled similarly@footnote{This means that the variables
  1190. @code{c-hanging-comment-starter-p} and @code{c-hanging-comment-ender-p},
  1191. which controlled this behavior in earlier versions of @ccmode{}, are now
  1192. obsolete.}.
  1193. @kindex M-j
  1194. @findex c-indent-new-comment-line
  1195. @findex indent-new-comment-line (c-)
  1196. @item @kbd{M-j} (@code{c-indent-new-comment-line})
  1197. This is the replacement for @code{indent-new-comment-line}. It breaks
  1198. the line at point and indents the new line like the current one.
  1199. @vindex comment-multi-line
  1200. If inside a comment and @code{comment-multi-line} is non-@code{nil}, the
  1201. indentation and line prefix are preserved. If inside a comment and
  1202. @code{comment-multi-line} is @code{nil}, a new comment of the same type
  1203. is started on the next line and indented as appropriate for comments.
  1204. @findex c-context-line-break
  1205. @findex context-line-break (c-)
  1206. @item @kbd{M-x c-context-line-break}
  1207. This is a function that works like @code{indent-new-comment-line} in
  1208. comments and @code{newline-and-indent} elsewhere, thus combining those
  1209. two in a way that uses each one in the context it's best suited for.
  1210. I.e. in comments the comment line prefix and indentation is kept for the
  1211. new line, and in normal code it's indented according to context by the
  1212. indentation engine.
  1213. It's not bound to a key by default, but it's intended to be used on the
  1214. @kbd{RET} key. If you like the behavior of @code{newline-and-indent} on
  1215. @kbd{RET}, you might consider switching to this function.
  1216. @end table
  1217. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1218. @node Commands, Customizing Indentation, Text Filling and Line Breaking, Top
  1219. @comment node-name, next, previous, up
  1220. @chapter Commands
  1221. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1222. @menu
  1223. * Indentation Commands::
  1224. * Movement Commands::
  1225. * Other Commands::
  1226. @end menu
  1227. See also @ref{Text Filling and Line Breaking}, for commands concerning
  1228. that bit.
  1229. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1230. @node Indentation Commands, Movement Commands, , Commands
  1231. @comment node-name, next, previous,up
  1232. @section Indentation Commands
  1233. @cindex indentation commands
  1234. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1235. The following list of commands re-indent C constructs. Note that when
  1236. you change your coding style, either interactively or through some other
  1237. means, your file does @emph{not} automatically get re-indented. You
  1238. will need to execute one of the following commands to see the effects of
  1239. your changes.
  1240. @cindex GNU indent program
  1241. Also, variables like @code{c-hanging-*} and @code{c-cleanup-list}
  1242. only affect how on-the-fly code is formatted. Changing the
  1243. ``hanginess'' of a brace and then re-indenting, will not move the brace
  1244. to a different line. For this, you're better off getting an external
  1245. program like GNU @code{indent}, which will re-arrange brace location,
  1246. among other things.
  1247. Re-indenting large sections of code can take a long time. When
  1248. @ccmode{} reindents a region of code, it is essentially equivalent to
  1249. hitting @kbd{TAB} on every line of the region. Especially vulnerable is
  1250. code generator output@footnote{In particular, I have had people
  1251. complain about the speed with which @code{lex(1)} output is re-indented.
  1252. Lex, yacc, and other code generators usually output some pretty
  1253. perversely formatted code. Re-indenting such code will be slow.}.
  1254. These commands are useful when indenting code:
  1255. @table @asis
  1256. @kindex TAB
  1257. @findex c-indent-command
  1258. @findex indent-command (c-)
  1259. @item @kbd{TAB} (@code{c-indent-command})
  1260. Indents the current line. The actual behavior is controlled by several
  1261. variables, described below. See @code{c-tab-always-indent},
  1262. @code{c-insert-tab-function}, and @code{indent-tabs-mode}. With a
  1263. numeric argument, this command rigidly indents the region, preserving
  1264. the relative indentation among the lines.
  1265. @kindex C-M-q
  1266. @findex c-indent-exp
  1267. @findex indent-exp (c-)
  1268. @item @kbd{C-M-q} (@code{c-indent-exp})
  1269. Indent an entire balanced brace or parenthesis expression. Note that
  1270. point must be on the opening brace or parenthesis of the expression you
  1271. want to indent.
  1272. @kindex C-c C-q
  1273. @findex c-indent-defun
  1274. @findex indent-defun (c-)
  1275. @item @kbd{C-c C-q} (@code{c-indent-defun})
  1276. Indents the entire top-level function or class definition encompassing
  1277. point. It leaves point unchanged. This function can't be used to
  1278. re-indent a nested brace construct, such as a nested class or function,
  1279. or a Java method. The top-level construct being re-indented must be
  1280. complete, i.e. it must have both a beginning brace and an ending brace.
  1281. @kindex C-M-\
  1282. @findex indent-region
  1283. @item @kbd{C-M-\} (@code{indent-region})
  1284. Indents an arbitrary region of code. This is a standard Emacs command,
  1285. tailored for C code in a @ccmode{} buffer. Note that of course, point
  1286. and mark must delineate the region you want to indent.
  1287. @kindex C-M-h
  1288. @findex c-mark-function
  1289. @findex mark-function (c-)
  1290. @item @kbd{C-M-h} (@code{c-mark-function})
  1291. While not strictly an indentation command, this is useful for marking
  1292. the current top-level function or class definition as the current
  1293. region. As with @code{c-indent-defun}, this command operates on
  1294. top-level constructs, and can't be used to mark say, a Java method.
  1295. @end table
  1296. These variables are also useful when indenting code:
  1297. @table @code
  1298. @vindex c-tab-always-indent
  1299. @vindex tab-always-indent (c-)
  1300. @kindex TAB
  1301. @cindex literal
  1302. @item c-tab-always-indent
  1303. This variable controls how @kbd{TAB} @code{c-indent-command} operates.
  1304. When this variable is @code{t}, @kbd{TAB} always just indents the
  1305. current line. When it is @code{nil}, the line is indented only if point
  1306. is at the left margin, or on or before the first non-whitespace
  1307. character on the line, otherwise some whitespace is inserted. If this
  1308. variable is the symbol @code{other}, then some whitespace is inserted
  1309. only within strings and comments (literals), an inside preprocessor
  1310. directives, but the line is always reindented.
  1311. @vindex c-insert-tab-function
  1312. @vindex insert-tab-function (c-)
  1313. @findex tab-to-tab-stop
  1314. @item c-insert-tab-function
  1315. When ``some whitespace'' is inserted as described above, what actually
  1316. happens is that the function stored in @code{c-insert-tab-function} is
  1317. called. Normally, this just inserts a real tab character, or the
  1318. equivalent number of spaces, depending on @code{indent-tabs-mode}.
  1319. Some people, however, set @code{c-insert-tab-function} to
  1320. @code{tab-to-tab-stop} so as to get hard tab stops when indenting.
  1321. @vindex indent-tabs-mode
  1322. @item indent-tabs-mode
  1323. This is a standard Emacs variable that controls how line indentation is
  1324. composed. When this variable is non-@code{nil}, then tabs can be used
  1325. in a line's indentation, otherwise only spaces can be used.
  1326. @vindex c-progress-interval
  1327. @vindex progress-interval (c-)
  1328. @item c-progress-interval
  1329. When indenting large regions of code, this variable controls how often a
  1330. progress message is displayed. Set this variable to @code{nil} to
  1331. inhibit the progress messages, or set it to an integer which is the
  1332. interval in seconds that progress messages are displayed.
  1333. @end table
  1334. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1335. @node Movement Commands, Other Commands, Indentation Commands, Commands
  1336. @comment node-name, next, previous, up
  1337. @section Movement Commands
  1338. @cindex movement commands
  1339. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1340. @ccmode{} contains some useful command for moving around in C
  1341. code.
  1342. @table @asis
  1343. @findex c-beginning-of-defun
  1344. @findex beginning-of-defun (c-)
  1345. @findex beginning-of-defun
  1346. @item @kbd{M-x c-beginning-of-defun}
  1347. Moves point back to the least-enclosing brace. This function is
  1348. analogous to the Emacs built-in command @code{beginning-of-defun},
  1349. except it eliminates the constraint that the top-level opening brace
  1350. must be in column zero. See @code{beginning-of-defun} for more
  1351. information.
  1352. Depending on the coding style being used, you might prefer
  1353. @code{c-beginning-of-defun} to @code{beginning-of-defun}. If so,
  1354. consider binding @kbd{C-M-a} to the former instead. For backwards
  1355. compatibility reasons, the default binding remains in effect.
  1356. @findex c-end-of-defun
  1357. @findex end-of-defun (c-)
  1358. @findex end-of-defun
  1359. @item @kbd{M-x c-end-of-defun}
  1360. Moves point to the end of the current top-level definition. This
  1361. function is analogous to the Emacs built-in command @code{end-of-defun},
  1362. except it eliminates the constraint that the top-level opening brace of
  1363. the defun must be in column zero. See @code{beginning-of-defun} for more
  1364. information.
  1365. Depending on the coding style being used, you might prefer
  1366. @code{c-end-of-defun} to @code{end-of-defun}. If so,
  1367. consider binding @kbd{C-M-e} to the former instead. For backwards
  1368. compatibility reasons, the default binding remains in effect.
  1369. @kindex C-c C-u
  1370. @findex c-up-conditional
  1371. @findex up-conditional (c-)
  1372. @item @kbd{C-c C-u} (@code{c-up-conditional})
  1373. Move point back to the containing preprocessor conditional, leaving the
  1374. mark behind. A prefix argument acts as a repeat count. With a negative
  1375. argument, move point forward to the end of the containing
  1376. preprocessor conditional.
  1377. @samp{#elif} is treated like @samp{#else} followed by @samp{#if}, so the
  1378. function stops at them when going backward, but not when going forward.
  1379. @findex c-up-conditional-with-else
  1380. @findex up-conditional-with-else (c-)
  1381. @item @kbd{M-x c-up-conditional-with-else}
  1382. A variety of @code{c-up-conditional} that also stops at @samp{#else}
  1383. lines. Normally those lines are ignored.
  1384. @findex c-down-conditional
  1385. @findex down-conditional (c-)
  1386. @item @kbd{M-x c-down-conditional}
  1387. Move point forward into the next nested preprocessor conditional,
  1388. leaving the mark behind. A prefix argument acts as a repeat count.
  1389. With a negative argument, move point backward into the previous
  1390. nested preprocessor conditional.
  1391. @samp{#elif} is treated like @samp{#else} followed by @samp{#if}, so the
  1392. function stops at them when going forward, but not when going backward.
  1393. @findex c-down-conditional-with-else
  1394. @findex down-conditional-with-else (c-)
  1395. @item @kbd{M-x c-down-conditional-with-else}
  1396. A variety of @code{c-down-conditional} that also stops at @samp{#else}
  1397. lines. Normally those lines are ignored.
  1398. @kindex C-c C-p
  1399. @findex c-backward-conditional
  1400. @findex backward-conditional (c-)
  1401. @item @kbd{C-c C-p} (@code{c-backward-conditional})
  1402. Move point back over a preprocessor conditional, leaving the mark
  1403. behind. A prefix argument acts as a repeat count. With a negative
  1404. argument, move forward.
  1405. @kindex C-c C-n
  1406. @findex c-forward-conditional
  1407. @findex forward-conditional (c-)
  1408. @item @kbd{C-c C-n} (@code{c-forward-conditional})
  1409. Move point forward across a preprocessor conditional, leaving the mark
  1410. behind. A prefix argument acts as a repeat count. With a negative
  1411. argument, move backward.
  1412. @kindex M-a
  1413. @findex c-beginning-of-statement
  1414. @findex beginning-of-statement (c-)
  1415. @item @kbd{M-a} (@code{c-beginning-of-statement})
  1416. Move point to the beginning of the innermost C statement. If point is
  1417. already at the beginning of a statement, move to the beginning of the
  1418. closest preceding statement, even if that means moving into a block (you
  1419. can use @kbd{C-M-b} to move over a balanced block). With prefix
  1420. argument @var{n}, move back @var{n} @minus{} 1 statements.
  1421. If point is within or next to a comment or a string which spans more
  1422. than one line, this command moves by sentences instead of statements.
  1423. When called from a program, this function takes three optional
  1424. arguments: the repetition count, a buffer position limit which is the
  1425. farthest back to search for the syntactic context, and a flag saying
  1426. whether to do sentence motion in or near comments and multiline strings.
  1427. @kindex M-e
  1428. @findex c-end-of-statement
  1429. @findex end-of-statement (c-)
  1430. @item @kbd{M-e} (@code{c-end-of-statement})
  1431. Move point to the end of the innermost C statement. If point is at the
  1432. end of a statement, move to the end of the next statement, even if it's
  1433. inside a nested block (use @kbd{C-M-f} to move to the other side of the
  1434. block). With prefix argument @var{n}, move forward @var{n} @minus{} 1
  1435. statements.
  1436. If point is within or next to a comment or a string which spans more
  1437. than one line, this command moves by sentences instead of statements.
  1438. When called from a program, this function takes three optional
  1439. arguments: the repetition count, a buffer position limit which is the
  1440. farthest back to search for the syntactic context, and a flag saying
  1441. whether to do sentence motion in or near comments and multiline strings.
  1442. @findex c-forward-into-nomenclature
  1443. @findex forward-into-nomenclature (c-)
  1444. @item @kbd{M-x c-forward-into-nomenclature}
  1445. A popular programming style, especially for object-oriented languages
  1446. such as C++ is to write symbols in a mixed case format, where the first
  1447. letter of each word is capitalized, and not separated by underscores.
  1448. E.g. @samp{SymbolsWithMixedCaseAndNoUnderlines}.
  1449. This command moves point forward to next capitalized word. With prefix
  1450. argument @var{n}, move @var{n} times.
  1451. @findex c-backward-into-nomenclature
  1452. @findex backward-into-nomenclature (c-)
  1453. @item @kbd{M-x c-backward-into-nomenclature}
  1454. Move point backward to beginning of the next capitalized
  1455. word. With prefix argument @var{n}, move @var{n} times. If
  1456. @var{n} is negative, move forward.
  1457. @end table
  1458. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1459. @node Other Commands, , Movement Commands, Commands
  1460. @comment node-name, next, previous, up
  1461. @section Other Commands
  1462. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1463. @ccmode{} contains a few other useful commands:
  1464. @table @asis
  1465. @kindex C-c :
  1466. @findex c-scope-operator
  1467. @findex scope-operator (c-)
  1468. @item @kbd{C-c :} (@code{c-scope-operator})
  1469. In C++, it is also sometimes desirable to insert the double-colon scope
  1470. operator without performing the electric behavior of colon insertion.
  1471. @kbd{C-c :} does just this.
  1472. @kindex C-c C-\
  1473. @findex c-backslash-region
  1474. @findex backslash-region (c-)
  1475. @item @kbd{C-c C-\} (@code{c-backslash-region})
  1476. This function is handy when editing macros split over several lines by
  1477. ending each line with a backslash. It inserts and aligns, or deletes
  1478. these end-of-line backslashes in the current region.
  1479. @vindex c-backslash-column
  1480. @vindex backslash-column (c-)
  1481. With no prefix argument, it inserts any missing backslashes and aligns
  1482. them to the column specified by the @code{c-backslash-column} style
  1483. variable. With a prefix argument, it deletes any backslashes.
  1484. The function does not modify blank lines at the start of the region. If
  1485. the region ends at the start of a line, it always deletes the backslash
  1486. (if any) at the end of the previous line.
  1487. @end table
  1488. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1489. @node Customizing Indentation, Syntactic Symbols, Commands, Top
  1490. @comment node-name, next, previous, up
  1491. @chapter Customizing Indentation
  1492. @cindex customizing indentation
  1493. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1494. @vindex c-offsets-alist
  1495. @vindex offsets-alist (c-)
  1496. The style variable @code{c-offsets-alist} contains the mappings between
  1497. syntactic symbols and the offsets to apply for those symbols. It's set
  1498. at mode initialization from a @emph{style} you may specify. Styles are
  1499. groupings of syntactic symbol offsets and other style variable values.
  1500. Most likely, you'll find that one of the pre-defined styles will suit
  1501. your needs. @xref{Styles}, for an explanation of how to set up named
  1502. styles.
  1503. Only syntactic symbols not already bound on @code{c-offsets-alist} will
  1504. be set from styles. This means that any association you set on it, be
  1505. it before or after mode initialization, will not be changed. The
  1506. @code{c-offsets-alist} variable may therefore be used from e.g. the
  1507. Customization interface@footnote{Available in Emacs 20 and later, and
  1508. XEmacs 19.15 and later.} to easily change indentation offsets without
  1509. having to bother about styles. Initially @code{c-offsets-alist} is
  1510. empty, so that all syntactic symbols are set by the style system.
  1511. @kindex C-c C-o
  1512. @findex c-set-offset
  1513. @findex set-offset (c-)
  1514. You can use the command @kbd{C-c C-o} (@code{c-set-offset}) as the way
  1515. to set offsets, both interactively and from your mode
  1516. hook@footnote{Obviously, you use the key binding interactively, and the
  1517. function call programmatically!}.
  1518. @vindex c-basic-offset
  1519. @vindex basic-offset (c-)
  1520. The offset associated with any particular syntactic symbol can be any of
  1521. an integer, a function or lambda expression, a variable name, a vector,
  1522. a list, or one of the following symbols: @code{+}, @code{-}, @code{++},
  1523. @code{--}, @code{*}, or @code{/}.
  1524. Those last special symbols describe an offset in multiples of the value
  1525. of the style variable @code{c-basic-offset}. By defining a style's
  1526. indentation in terms of this fundamental variable, you can change the
  1527. amount of whitespace given to an indentation level while maintaining the
  1528. same basic shape of your code. Here are the values that the special
  1529. symbols correspond to:
  1530. @table @code
  1531. @item +
  1532. @code{c-basic-offset} times 1
  1533. @item -
  1534. @code{c-basic-offset} times -1
  1535. @item ++
  1536. @code{c-basic-offset} times 2
  1537. @item --
  1538. @code{c-basic-offset} times -2
  1539. @item *
  1540. @code{c-basic-offset} times 0.5
  1541. @item /
  1542. @code{c-basic-offset} times -0.5
  1543. @end table
  1544. @cindex indentation functions
  1545. When a function is used as offset, it's called an @dfn{indentation
  1546. function}. Such functions are useful when more context than just the
  1547. syntactic symbol is needed to get the desired indentation.
  1548. @xref{Indentation Functions}, and @ref{Custom Indentation Functions},
  1549. for details about them.
  1550. If the offset is a vector, its first element sets the absolute
  1551. indentation column, which will override any relative indentation.
  1552. @vindex c-strict-syntax-p
  1553. @vindex strict-syntax-p (c-)
  1554. The offset can also be a list, in which case it is evaluated recursively
  1555. using the semantics described above. The first element of the list that
  1556. returns a non-@code{nil} value succeeds and the evaluation stops. If
  1557. none of the list elements return a non-@code{nil} value, then an offset
  1558. of 0 (zero) is used@footnote{There is however a variable
  1559. @code{c-strict-syntax-p} that, when set to non-@code{nil}, will cause an
  1560. error to be signalled in that case. It's now considered obsolete since
  1561. it doesn't work well with some of the alignment functions that now
  1562. returns @code{nil} instead of zero to be more usable in lists. You
  1563. should therefore leave @code{c-strict-syntax-p} set to @code{nil}.}.
  1564. So, for example, because most of the default offsets are defined in
  1565. terms of @code{+}, @code{-}, and @code{0}, if you like the general
  1566. indentation style, but you use 4 spaces instead of 2 spaces per level,
  1567. you can probably achieve your style just by changing
  1568. @code{c-basic-offset} like so@footnote{You can try this interactively in
  1569. a C buffer by typing the text that appears in italics.}:
  1570. @example
  1571. @emph{M-x set-variable RET}
  1572. Set variable: @emph{c-basic-offset RET}
  1573. Set c-basic-offset to value: @emph{4 RET}
  1574. @end example
  1575. @noindent
  1576. This would change
  1577. @example
  1578. @group
  1579. int add( int val, int incr, int doit )
  1580. @{
  1581. if( doit )
  1582. @{
  1583. return( val + incr );
  1584. @}
  1585. return( val );
  1586. @}
  1587. @end group
  1588. @end example
  1589. @noindent
  1590. to
  1591. @example
  1592. @group
  1593. int add( int val, int incr, int doit )
  1594. @{
  1595. if( doit )
  1596. @{
  1597. return( val + incr );
  1598. @}
  1599. return( val );
  1600. @}
  1601. @end group
  1602. @end example
  1603. To change indentation styles more radically, you will want to change the
  1604. offsets associated with other syntactic symbols. First, I'll show you
  1605. how to do that interactively, then I'll describe how to make changes to
  1606. your @file{.emacs} file so that your changes are more permanent.
  1607. @menu
  1608. * Interactive Customization::
  1609. * Permanent Customization::
  1610. * Hooks::
  1611. * Styles::
  1612. * Advanced Customizations::
  1613. @end menu
  1614. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1615. @node Interactive Customization, Permanent Customization, , Customizing Indentation
  1616. @comment node-name, next, previous, up
  1617. @section Interactive Customization
  1618. @cindex interactive customization
  1619. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1620. As an example of how to customize indentation, let's change the
  1621. style of this example@footnote{In this an subsequent examples, the
  1622. original code is formatted using the @samp{gnu} style unless otherwise
  1623. indicated. @xref{Styles}.}:
  1624. @example
  1625. @group
  1626. 1: int add( int val, int incr, int doit )
  1627. 2: @{
  1628. 3: if( doit )
  1629. 4: @{
  1630. 5: return( val + incr );
  1631. 6: @}
  1632. 7: return( val );
  1633. 8: @}
  1634. @end group
  1635. @end example
  1636. @noindent
  1637. to:
  1638. @example
  1639. @group
  1640. 1: int add( int val, int incr, int doit )
  1641. 2: @{
  1642. 3: if( doit )
  1643. 4: @{
  1644. 5: return( val + incr );
  1645. 6: @}
  1646. 7: return( val );
  1647. 8: @}
  1648. @end group
  1649. @end example
  1650. In other words, we want to change the indentation of braces that open a
  1651. block following a condition so that the braces line up under the
  1652. conditional, instead of being indented. Notice that the construct we
  1653. want to change starts on line 4. To change the indentation of a line,
  1654. we need to see which syntactic components affect the offset calculations
  1655. for that line. Hitting @kbd{C-c C-s} on line 4 yields:
  1656. @example
  1657. ((substatement-open . 44))
  1658. @end example
  1659. @noindent
  1660. so we know that to change the offset of the open brace, we need to
  1661. change the indentation for the @code{substatement-open} syntactic
  1662. symbol. To do this interactively, just hit @kbd{C-c C-o}. This prompts
  1663. you for the syntactic symbol to change, providing a reasonable default.
  1664. In this case, the default is @code{substatement-open}, which is just the
  1665. syntactic symbol we want to change!
  1666. After you hit return, @ccmode{} will then prompt you for the new
  1667. offset value, with the old value as the default. The default in this
  1668. case is @samp{+}, but we want no extra indentation so enter
  1669. @samp{0} and @kbd{RET}. This will associate the offset 0 with the
  1670. syntactic symbol @code{substatement-open}.
  1671. To check your changes quickly, just hit @kbd{C-c C-q}
  1672. (@code{c-indent-defun}) to reindent the entire function. The example
  1673. should now look like:
  1674. @example
  1675. @group
  1676. 1: int add( int val, int incr, int doit )
  1677. 2: @{
  1678. 3: if( doit )
  1679. 4: @{
  1680. 5: return( val + incr );
  1681. 6: @}
  1682. 7: return( val );
  1683. 8: @}
  1684. @end group
  1685. @end example
  1686. Notice how just changing the open brace offset on line 4 is all we
  1687. needed to do. Since the other affected lines are indented relative to
  1688. line 4, they are automatically indented the way you'd expect. For more
  1689. complicated examples, this may not always work. The general approach to
  1690. take is to always start adjusting offsets for lines higher up in the
  1691. file, then re-indent and see if any following lines need further
  1692. adjustments.
  1693. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1694. @node Permanent Customization, Hooks, Interactive Customization, Customizing Indentation
  1695. @comment node-name, next, previous, up
  1696. @section Permanent Customization
  1697. @cindex permanent customization
  1698. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1699. To make your changes permanent, you need to add some lisp code to your
  1700. @file{.emacs} file. @ccmode{} supports many different ways to be
  1701. configured, from the straightforward way by setting variables globally
  1702. in @file{.emacs} or in the Customization interface, to the complex and
  1703. precisely controlled way by using styles and hook functions.
  1704. The simplest way of customizing @ccmode{} permanently is to set the
  1705. variables in your @file{.emacs} with @code{setq} and similar commands.
  1706. So to make the setting of @code{substatement-open} permanent, add this
  1707. to the @file{.emacs} file:
  1708. @example
  1709. @group
  1710. (require 'cc-mode)
  1711. (c-set-offset 'substatement-open 0)
  1712. @end group
  1713. @end example
  1714. The @code{require} line is only needed once in the beginning to make
  1715. sure @ccmode{} is loaded so that the @code{c-set-offset} function is
  1716. defined.
  1717. You can also use the more user friendly Customization interface, but
  1718. this manual does not cover how that works.
  1719. Variables set like this at the top level in @file{.emacs} take effect in
  1720. all @ccmode{} buffers, regardless of language. The indentation style
  1721. related variables, e.g. @code{c-basic-offset}, that you don't set this
  1722. way get their value from the style system (@pxref{Styles}), and they
  1723. therefore depend on the setting of @code{c-default-style}. Note that if
  1724. you use Customize, this means that the greyed-out default values
  1725. presented there might not be the ones you actually get, since the actual
  1726. values depend on the style, which may very well be different for
  1727. different languages.
  1728. If you want to make more advanced configurations, e.g. language-specific
  1729. customization, global variable settings isn't enough. For that you can
  1730. use the language hooks, see @ref{Hooks}, and/or the style system, see
  1731. @ref{Styles}.
  1732. @vindex c-style-variables-are-local-p
  1733. @vindex style-variables-are-local-p (c-)
  1734. By default, all style variables are global, so that every buffer will
  1735. share the same style settings. This is fine if you primarily edit one
  1736. style of code, but if you edit several languages and want to use
  1737. different styles for them, you need finer control by making the style
  1738. variables buffer local. The recommended way to do this is to set the
  1739. variable @code{c-style-variables-are-local-p} to @code{t}. The
  1740. variables will be made buffer local when @ccmode{} is activated in a
  1741. buffer for the first time in the Emacs session. Note that once the
  1742. style variables are made buffer local, they cannot be made global again,
  1743. without restarting Emacs.
  1744. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1745. @node Hooks, Styles, Permanent Customization, Customizing Indentation
  1746. @comment node-name, next, previous, up
  1747. @section Hooks
  1748. @cindex hooks
  1749. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1750. @vindex c-mode-common-hook
  1751. @vindex mode-common-hook (c-)
  1752. @vindex c-mode-hook
  1753. @vindex c++-mode-hook
  1754. @vindex objc-mode-hook
  1755. @vindex java-mode-hook
  1756. @vindex idl-mode-hook
  1757. @vindex pike-mode-hook
  1758. @vindex c-initialization-hook
  1759. @vindex initialization-hook (c-)
  1760. @ccmode{} provides several hooks that you can use to customize the mode
  1761. according to your coding style. Each language mode has its own hook,
  1762. adhering to standard Emacs major mode conventions. There is also one
  1763. general hook and one package initialization hook:
  1764. @itemize @bullet
  1765. @item
  1766. @code{c-mode-hook} --- For C buffers only.
  1767. @item
  1768. @code{c++-mode-hook} --- For C++ buffers only.
  1769. @item
  1770. @code{objc-mode-hook} --- For Objective-C buffers only.
  1771. @item
  1772. @code{java-mode-hook} --- For Java buffers only.
  1773. @item
  1774. @code{idl-mode-hook} --- For CORBA IDL buffers only.
  1775. @item
  1776. @code{pike-mode-hook} --- For Pike buffers only.
  1777. @item
  1778. @code{c-mode-common-hook} --- Common across all languages.
  1779. @item
  1780. @code{c-initialization-hook} --- Hook run only once per Emacs session,
  1781. when @ccmode{} is initialized.
  1782. @end itemize
  1783. The language hooks get run as the last thing when you enter that
  1784. language mode. The @code{c-mode-common-hook} is run by all supported
  1785. modes @emph{before} the language specific hook, and thus can contain
  1786. customizations that are common across all languages. Most of the
  1787. examples in this section will assume you are using the common hook.
  1788. Note that all the language-specific mode setup that CC Mode does is done
  1789. prior to both @code{c-mode-common-hook} and the language specific hook.
  1790. That includes installing the indentation style, which can be mode
  1791. specific (and also is by default for Java mode). Thus, any style
  1792. settings done in @code{c-mode-common-hook} will override whatever
  1793. language-specific style is chosen by @code{c-default-style}.
  1794. Here's a simplified example of what you can add to your @file{.emacs}
  1795. file to do things whenever any @ccmode{} language is edited. See the
  1796. Emacs manuals for more information on customizing Emacs via hooks.
  1797. @xref{Sample .emacs File}, for a more complete sample @file{.emacs}
  1798. file.
  1799. @example
  1800. @group
  1801. (defun my-c-mode-common-hook ()
  1802. ;; my customizations for all of c-mode and related modes
  1803. (no-case-fold-search)
  1804. )
  1805. (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
  1806. @end group
  1807. @end example
  1808. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1809. @node Styles, Advanced Customizations, Hooks, Customizing Indentation
  1810. @comment node-name, next, previous, up
  1811. @section Styles
  1812. @cindex styles
  1813. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1814. Most people only need to edit code formatted in just a few well-defined
  1815. and consistent styles. For example, their organization might impose a
  1816. ``blessed'' style that all its programmers must conform to. Similarly,
  1817. people who work on GNU software will have to use the GNU coding style.
  1818. Some shops are more lenient, allowing a variety of coding styles, and as
  1819. programmers come and go, there could be a number of styles in use. For
  1820. this reason, @ccmode{} makes it convenient for you to set up logical
  1821. groupings of customizations called @dfn{styles}, associate a single name
  1822. for any particular style, and pretty easily start editing new or
  1823. existing code using these styles.
  1824. @cindex style variables
  1825. The variables that the style system affect are called @dfn{style
  1826. variables}. They are handled specially in several ways:
  1827. @itemize @bullet
  1828. @item
  1829. Style variables are by default global variables, i.e. they have the same
  1830. value in all Emacs buffers. However, they can instead be made always
  1831. buffer local by setting @code{c-style-variables-are-local-p} to
  1832. non-@code{nil} before @ccmode{} is initialized.
  1833. @vindex c-old-style-variable-behavior
  1834. @vindex old-style-variable-behavior (c-)
  1835. @item
  1836. The default value of any style variable (with two exceptions --- see
  1837. below) is the special symbol @code{set-from-style}. Variables that are
  1838. still set to that symbol when a @ccmode{} buffer is initialized will be
  1839. set according to the current style, otherwise they will keep their
  1840. current value@footnote{This is a big change from versions of @ccmode{}
  1841. earlier than 5.26, where such settings would get overridden by the style
  1842. system unless special precautions were taken. That was changed since it
  1843. was counterintuitive and confusing, especially to novice users. If your
  1844. configuration depends on the old overriding behavior, you can set the
  1845. variable @code{c-old-style-variable-behavior} to non-@code{nil}.}.
  1846. Note that when we talk about the ``default value'' for a style variable,
  1847. we don't mean the @code{set-from-style} symbol that all style variables
  1848. are set to initially, but instead the value it will get at mode
  1849. initialization when neither a style nor a global setting has set its
  1850. value.
  1851. The style variable @code{c-offsets-alist} is handled a little
  1852. differently from the other style variables. It's an association list,
  1853. and is thus by default set to the empty list, @code{nil}. When the
  1854. style system is initialized, any syntactic symbols already on it are
  1855. kept --- only the missing ones are filled in from the chosen style.
  1856. The style variable @code{c-special-indent-hook} is also handled in a
  1857. special way. Styles may only add more functions on this hook, so the
  1858. global settings on it are always preserved@footnote{This did not change
  1859. in version 5.26.}.
  1860. @item
  1861. The global settings of style variables get captured in the special
  1862. @code{user} style, which is used as the base for all the other styles.
  1863. @xref{Built-in Styles}, for details.
  1864. @end itemize
  1865. The style variables are:
  1866. @code{c-basic-offset},
  1867. @code{c-comment-only-line-offset},
  1868. @code{c-block-comment-prefix},
  1869. @code{c-comment-prefix-regexp},
  1870. @code{c-cleanup-list},
  1871. @code{c-hanging-braces-alist},
  1872. @code{c-hanging-colons-alist},
  1873. @code{c-hanging-semi&comma-criteria},
  1874. @code{c-backslash-column},
  1875. @code{c-special-indent-hook},
  1876. @code{c-label-minimum-indentation}, and
  1877. @code{c-offsets-alist}.
  1878. @menu
  1879. * Built-in Styles::
  1880. * Adding Styles::
  1881. * File Styles::
  1882. @end menu
  1883. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1884. @node Built-in Styles, Adding Styles, , Styles
  1885. @comment node-name, next, previous, up
  1886. @subsection Built-in Styles
  1887. @cindex built-in styles
  1888. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1889. If you're lucky, one of @ccmode{}'s built-in styles might be just
  1890. what you're looking for. These include:
  1891. @itemize @bullet
  1892. @cindex GNU style
  1893. @item
  1894. @code{gnu} --- Coding style blessed by the Free Software Foundation
  1895. for C code in GNU programs.
  1896. @cindex K&R style
  1897. @item
  1898. @code{k&r} --- The classic Kernighan and Ritchie style for C code.
  1899. @cindex BSD style
  1900. @item
  1901. @code{bsd} --- Also known as ``Allman style'' after Eric Allman.
  1902. @cindex Whitesmith style
  1903. @item
  1904. @code{whitesmith} --- Popularized by the examples that came with
  1905. Whitesmiths C, an early commercial C compiler.
  1906. @cindex Stroustrup style
  1907. @item
  1908. @code{stroustrup} --- The classic Stroustrup style for C++ code.
  1909. @cindex Ellemtel style
  1910. @item
  1911. @code{ellemtel} --- Popular C++ coding standards as defined by
  1912. ``Programming in C++, Rules and Recommendations,'' Erik Nyquist and Mats
  1913. Henricson, Ellemtel@footnote{This document is available at
  1914. @uref{http://www.doc.ic.ac.uk/lab/cplus/c++.rules/} among other
  1915. places.}.
  1916. @cindex Linux style
  1917. @item
  1918. @code{linux} --- C coding standard for Linux (the kernel).
  1919. @cindex Python style
  1920. @item
  1921. @code{python} --- C coding standard for Python extension
  1922. modules@footnote{Python is a high level scripting language with a C/C++
  1923. foreign function interface. For more information, see
  1924. @uref{http://www.python.org/}.}.
  1925. @cindex Java style
  1926. @findex java-mode
  1927. @item
  1928. @code{java} --- The style for editing Java code. Note that the default
  1929. value for @code{c-default-style} installs this style when you enter
  1930. @code{java-mode}.
  1931. @cindex User style
  1932. @item
  1933. @code{user} --- This is a special style for several reasons. First, the
  1934. @ccmode{} customizations you do by using either the Customization
  1935. interface, or by writing @code{setq}'s at the top level of your
  1936. @file{.emacs} file, will be captured in the @code{user} style. Also,
  1937. all other styles implicitly inherit their settings from @code{user}
  1938. style. This means that for any styles you add via @code{c-add-style}
  1939. (@pxref{Adding Styles}) you need only define the differences between
  1940. your new style and @code{user} style.
  1941. @end itemize
  1942. @vindex c-default-style
  1943. @vindex default-style (c-)
  1944. The default style in all newly created buffers is @code{gnu}, but you
  1945. can change this by setting variable @code{c-default-style}. Although
  1946. the @code{user} style is not the default style, any style variable
  1947. settings you do with the Customization interface or on the top level in
  1948. your @file{.emacs} file will by default override the style system, so
  1949. you don't need to set @code{c-default-style} to @code{user} to see the
  1950. effect of these settings.
  1951. @code{c-default-style} takes either a style name string, or an
  1952. association list of major mode symbols to style names. Thus you can
  1953. control exactly which default style is used for which @ccmode{} language
  1954. mode. Here are the rules:
  1955. @vindex c-style-alist
  1956. @vindex style-alist (c-)
  1957. @vindex c-mode-common-hook
  1958. @vindex mode-common-hook (c-)
  1959. @enumerate
  1960. @item
  1961. When @code{c-default-style} is a string, it must be an existing style
  1962. name as found in @code{c-style-alist}. This style is then used for all
  1963. modes.
  1964. @item
  1965. When @code{c-default-style} is an association list, the current major
  1966. mode is looked up to find a style name string. In this case, this style
  1967. is always used exactly as specified and an error will occur if the named
  1968. style does not exist.
  1969. @item
  1970. If @code{c-default-style} is an association list, but the current major
  1971. mode isn't found, then the special symbol @samp{other} is looked up. If
  1972. this value is found, the associated style is used.
  1973. @item
  1974. If @samp{other} is not found, then the @samp{gnu} style is used.
  1975. @item
  1976. In all cases, the style described in @code{c-default-style} is installed
  1977. @emph{before} the language hooks are run, so you can always override
  1978. this setting by including an explicit call to @code{c-set-style} in your
  1979. language mode hook, or in @code{c-mode-common-hook}.
  1980. @end enumerate
  1981. @findex c-set-style
  1982. @findex set-style (c-)
  1983. @kindex C-c .
  1984. If you'd like to experiment with these built-in styles you can simply
  1985. type the following in a @ccmode{} buffer:
  1986. @example
  1987. @group
  1988. @kbd{C-c . @var{STYLE-NAME} RET}
  1989. @end group
  1990. @end example
  1991. @noindent
  1992. @kbd{C-c .} runs the command @code{c-set-style}. Note that all style
  1993. names are case insensitive, even the ones you define.
  1994. Setting a style in this way does @emph{not} automatically re-indent your
  1995. file. For commands that you can use to view the effect of your changes,
  1996. see @ref{Commands}.
  1997. @vindex c-indentation-style
  1998. @vindex indentation-style (c-)
  1999. Note that for BOCM compatibility, @samp{gnu} is the default style, and
  2000. any non-style based customizations you make (i.e. in
  2001. @code{c-mode-common-hook} in your @file{.emacs} file) will be based on
  2002. @samp{gnu} style unless you set @code{c-default-style} or do a
  2003. @code{c-set-style} as the first thing in your hook. The variable
  2004. @code{c-indentation-style} always contains the buffer's current style
  2005. name, as a string.
  2006. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2007. @node Adding Styles, File Styles, Built-in Styles, Styles
  2008. @comment node-name, next, previous, up
  2009. @subsection Adding Styles
  2010. @cindex adding styles
  2011. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2012. @vindex c-style-alist
  2013. @vindex style-alist (c-)
  2014. @findex c-add-style
  2015. @findex add-style (c-)
  2016. If none of the built-in styles is appropriate, you'll probably want to
  2017. add a new @dfn{style definition}. Styles are kept in the
  2018. @code{c-style-alist} variable, but you should never modify this variable
  2019. directly. Instead, @ccmode{} provides the function
  2020. @code{c-add-style} that you can use to easily add new styles or change
  2021. existing styles. This function takes two arguments, a @var{stylename}
  2022. string, and an association list @var{description} of style
  2023. customizations. If @var{stylename} is not already in
  2024. @code{c-style-alist}, the new style is added, otherwise the style is
  2025. changed to the new @var{description}.
  2026. This function also takes an optional third argument, which if
  2027. non-@code{nil}, automatically applies the new style to the current
  2028. buffer.
  2029. @comment TBD: The next paragraph is bogus. I really need to better
  2030. @comment document adding styles, including setting up inherited styles.
  2031. The sample @file{.emacs} file provides a concrete example of how a new
  2032. style can be added and automatically set. @xref{Sample .emacs File}.
  2033. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2034. @node File Styles, , Adding Styles, Styles
  2035. @comment node-name, next, previous, up
  2036. @subsection File Styles
  2037. @cindex file styles
  2038. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2039. @cindex local variables
  2040. The Emacs manual describes how you can customize certain variables on a
  2041. per-file basis by including a @dfn{Local Variable} block at the end of
  2042. the file. So far, you've only seen a functional interface to @ccmode{}
  2043. customization, which is highly inconvenient for use in a Local Variable
  2044. block. @ccmode{} provides two variables that make it easier for you to
  2045. customize your style on a per-file basis.
  2046. @vindex c-file-style
  2047. @vindex file-style (c-)
  2048. @vindex c-file-offsets
  2049. @vindex file-offsets (c-)
  2050. The variable @code{c-file-style} can be set to a style name string.
  2051. When the file is visited, @ccmode{} will automatically set the
  2052. file's style to this style using @code{c-set-style}.
  2053. Another variable, @code{c-file-offsets}, takes an association list
  2054. similar to what is allowed in @code{c-offsets-alist}. When the file is
  2055. visited, @ccmode{} will automatically institute these offsets using
  2056. @code{c-set-offset}.
  2057. Note that file style settings (i.e. @code{c-file-style}) are applied
  2058. before file offset settings (i.e. @code{c-file-offsets}). Also, if
  2059. either of these are set in a file's local variable section, all the
  2060. style variable values are made local to that buffer.
  2061. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2062. @node Advanced Customizations, , Styles, Customizing Indentation
  2063. @comment node-name, next, previous, up
  2064. @section Advanced Customizations
  2065. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2066. @vindex c-style-alist
  2067. @vindex style-alist (c-)
  2068. For most users, @ccmode{} will support their coding styles with
  2069. very little need for more advanced customizations. Usually, one of the
  2070. standard styles defined in @code{c-style-alist} will do the trick. At
  2071. most, perhaps one of the syntactic symbol offsets will need to be
  2072. tweaked slightly, or maybe @code{c-basic-offset} will need to be
  2073. changed. However, some styles require a more flexible framework for
  2074. customization, and one of the real strengths of @ccmode{} is that
  2075. the syntactic analysis model provides just such a framework. This allows
  2076. you to implement custom indentation calculations for situations not
  2077. handled by the mode directly.
  2078. @menu
  2079. * Custom Indentation Functions::
  2080. * Custom Brace and Colon Hanging::
  2081. * Customizing Semi-colons and Commas::
  2082. * Other Special Indentations::
  2083. @end menu
  2084. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2085. @node Custom Indentation Functions, Custom Brace and Colon Hanging, , Advanced Customizations
  2086. @comment node-name, next, previous, up
  2087. @subsection Custom Indentation Functions
  2088. @cindex custom indentation functions
  2089. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2090. The most flexible way to customize @ccmode{} is by writing custom
  2091. indentation functions, and associating them with specific syntactic
  2092. symbols (@pxref{Syntactic Symbols}). @ccmode{} itself uses indentation
  2093. functions to provide more sophisticated indentation, for example when
  2094. lining up C++ stream operator blocks:
  2095. @example
  2096. @group
  2097. 1: void main(int argc, char**)
  2098. 2: @{
  2099. 3: cout << "There were "
  2100. 4: << argc
  2101. 5: << "arguments passed to the program"
  2102. 6: << endl;
  2103. 7: @}
  2104. @end group
  2105. @end example
  2106. In this example, lines 4 through 6 are assigned the @code{stream-op}
  2107. syntactic symbol. Here, @code{stream-op} has an offset of @code{+}, and
  2108. with a @code{c-basic-offset} of 2, you can see that lines 4 through 6
  2109. are simply indented two spaces to the right of line 3. But perhaps we'd
  2110. like @ccmode{} to be a little more intelligent so that it aligns
  2111. all the @samp{<<} symbols in lines 3 through 6. To do this, we have
  2112. to write a custom indentation function which finds the column of first
  2113. stream operator on the first line of the statement. Here is sample
  2114. lisp code implementing this:
  2115. @example
  2116. @group
  2117. (defun c-lineup-streamop (langelem)
  2118. ;; lineup stream operators
  2119. (save-excursion
  2120. (let* ((relpos (cdr langelem))
  2121. (curcol (progn (goto-char relpos)
  2122. (current-column))))
  2123. (re-search-forward "<<\\|>>" (c-point 'eol) 'move)
  2124. (goto-char (match-beginning 0))
  2125. (- (current-column) curcol))))
  2126. @end group
  2127. @end example
  2128. @noindent
  2129. Indentation functions take a single argument, which is a syntactic
  2130. component cons cell (@pxref{Syntactic Analysis}). The function returns
  2131. an integer offset value that will be added to the running total
  2132. indentation for the line. Note that what actually gets returned is the
  2133. difference between the column that the first stream operator is on, and
  2134. the column of the buffer relative position passed in the function's
  2135. argument. Remember that @ccmode{} automatically adds in the column of
  2136. the component's relative buffer position and we don't the column offset
  2137. added in twice.
  2138. The function should return @code{nil} if it's used in a situation where
  2139. it doesn't want to do any decision. If the function is used in a list
  2140. expression (@pxref{Customizing Indentation}), that will cause @ccmode{}
  2141. to go on and check the next entry in the list.
  2142. @cindex stream-op syntactic symbol
  2143. @findex c-lineup-streamop
  2144. @findex lineup-streamop (c-)
  2145. Now, to associate the function @code{c-lineup-streamop} with the
  2146. @code{stream-op} syntactic symbol, we can add something like the
  2147. following to our @code{c++-mode-hook}@footnote{It probably makes more
  2148. sense to add this to @code{c++-mode-hook} than @code{c-mode-common-hook}
  2149. since stream operators are only relevant for C++.}:
  2150. @example
  2151. (c-set-offset 'stream-op 'c-lineup-streamop)
  2152. @end example
  2153. Now the function looks like this after re-indenting (using @kbd{C-c
  2154. C-q}):
  2155. @example
  2156. @group
  2157. 1: void main(int argc, char**)
  2158. 2: @{
  2159. 3: cout << "There were "
  2160. 4: << argc
  2161. 5: << " arguments passed to the program"
  2162. 6: << endl;
  2163. 7: @}
  2164. @end group
  2165. @end example
  2166. Custom indentation functions can be as simple or as complex as you like,
  2167. and any syntactic symbol that appears in @code{c-offsets-alist} can have
  2168. a custom indentation function associated with it.
  2169. @ccmode{} comes with an extensive set of predefined indentation
  2170. functions, not all of which are used by the default styles. So there's
  2171. a good chance the function you want already exists. @xref{Indentation
  2172. Functions}, for a list of them. If you have written an indentation
  2173. function that you think is generally useful, you're very welcome to
  2174. contribute it; please contact @email{bug-cc-mode@@gnu.org}.
  2175. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2176. @node Custom Brace and Colon Hanging, Customizing Semi-colons and Commas, Custom Indentation Functions, Advanced Customizations
  2177. @comment node-name, next, previous, up
  2178. @subsection Custom Brace and Colon Hanging
  2179. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2180. @vindex c-hanging-braces-alist
  2181. @vindex hanging-braces-alist (c-)
  2182. Syntactic symbols aren't the only place where you can customize
  2183. @ccmode{} with the lisp equivalent of callback functions. Brace
  2184. ``hanginess'' can also be determined by custom functions associated with
  2185. syntactic symbols on the @code{c-hanging-braces-alist} style variable.
  2186. Remember that @var{ACTION}'s are typically a list containing some
  2187. combination of the symbols @code{before} and @code{after}
  2188. (@pxref{Hanging Braces}). However, an @var{ACTION} can also be a
  2189. function which gets called when a brace matching that syntactic symbol
  2190. is entered.
  2191. @cindex customizing brace hanging
  2192. These @var{ACTION} functions are called with two arguments: the
  2193. syntactic symbol for the brace, and the buffer position at which the
  2194. brace was inserted. The @var{ACTION} function is expected to return a
  2195. list containing some combination of @code{before} and @code{after},
  2196. including neither of them (i.e. @code{nil}). This return value has the
  2197. normal brace hanging semantics.
  2198. As an example, @ccmode{} itself uses this feature to dynamically
  2199. determine the hanginess of braces which close ``do-while''
  2200. constructs:
  2201. @example
  2202. @group
  2203. void do_list( int count, char** atleast_one_string )
  2204. @{
  2205. int i=0;
  2206. do @{
  2207. handle_string( atleast_one_string[i] );
  2208. i++;
  2209. @} while( i < count );
  2210. @}
  2211. @end group
  2212. @end example
  2213. @findex c-snug-do-while
  2214. @findex snug-do-while (c-)
  2215. @ccmode{} assigns the @code{block-close} syntactic symbol to the
  2216. brace that closes the @code{do} construct, and normally we'd like the
  2217. line that follows a @code{block-close} brace to begin on a separate
  2218. line. However, with ``do-while'' constructs, we want the
  2219. @code{while} clause to follow the closing brace. To do this, we
  2220. associate the @code{block-close} symbol with the @var{ACTION} function
  2221. @code{c-snug-do-while}:
  2222. @example
  2223. (defun c-snug-do-while (syntax pos)
  2224. "Dynamically calculate brace hanginess for do-while statements.
  2225. Using this function, `while' clauses that end a `do-while' block will
  2226. remain on the same line as the brace that closes that block.
  2227. See `c-hanging-braces-alist' for how to utilize this function as an
  2228. ACTION associated with `block-close' syntax."
  2229. (save-excursion
  2230. (let (langelem)
  2231. (if (and (eq syntax 'block-close)
  2232. (setq langelem (assq 'block-close c-syntactic-context))
  2233. (progn (goto-char (cdr langelem))
  2234. (if (= (following-char) ?@{)
  2235. (forward-sexp -1))
  2236. (looking-at "\\<do\\>[^_]")))
  2237. '(before)
  2238. '(before after)))))
  2239. @end example
  2240. This function simply looks to see if the brace closes a ``do-while''
  2241. clause and if so, returns the list @samp{(before)} indicating
  2242. that a newline should be inserted before the brace, but not after it.
  2243. In all other cases, it returns the list @samp{(before after)} so
  2244. that the brace appears on a line by itself.
  2245. @vindex c-syntactic-context
  2246. @vindex syntactic-context (c-)
  2247. During the call to the brace hanging @var{ACTION} function, the variable
  2248. @code{c-syntactic-context} is bound to the full syntactic analysis list.
  2249. @cindex customizing colon hanging
  2250. @vindex c-hanging-colon-alist
  2251. @vindex hanging-colon-alist (c-)
  2252. Note that for symmetry, colon hanginess should be customizable by
  2253. allowing function symbols as @var{ACTION}s on the
  2254. @code{c-hanging-colon-alist} style variable. Since no use has actually
  2255. been found for this feature, it isn't currently implemented!
  2256. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2257. @node Customizing Semi-colons and Commas, Other Special Indentations, Custom Brace and Colon Hanging, Advanced Customizations
  2258. @comment node-name, next, previous, up
  2259. @subsection Customizing Semi-colons and Commas
  2260. @cindex customizing semi-colons and commas
  2261. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2262. @vindex c-hanging-semi&comma-criteria
  2263. @vindex hanging-semi&comma-criteria (c-)
  2264. You can also customize the insertion of newlines after semi-colons and
  2265. commas, when the auto-newline minor mode is enabled (@pxref{Minor
  2266. Modes}). This is controlled by the style variable
  2267. @code{c-hanging-semi&comma-criteria}, which contains a list of functions
  2268. that are called in the order they appear. Each function is called with
  2269. zero arguments, and is expected to return one of the following values:
  2270. @itemize @bullet
  2271. @item
  2272. non-@code{nil} --- A newline is inserted, and no more functions from the
  2273. list are called.
  2274. @item
  2275. @code{stop} --- No more functions from the list are called, but no
  2276. newline is inserted.
  2277. @item
  2278. @code{nil} --- No determination is made, and the next function in the
  2279. list is called.
  2280. @end itemize
  2281. If every function in the list is called without a determination being
  2282. made, then no newline is added. The default value for this variable is a
  2283. list containing a single function which inserts newlines only after
  2284. semi-colons which do not appear inside parenthesis lists (i.e. those
  2285. that separate @code{for}-clause statements).
  2286. @findex c-semi&comma-no-newlines-before-nonblanks
  2287. @findex semi&comma-no-newlines-before-nonblanks (c-)
  2288. Here's an example of a criteria function, provided by @ccmode{}, that
  2289. will prevent newlines from being inserted after semicolons when there is
  2290. a non-blank following line. Otherwise, it makes no determination. To
  2291. use, add this to the front of the @code{c-hanging-semi&comma-criteria}
  2292. list.
  2293. @example
  2294. @group
  2295. (defun c-semi&comma-no-newlines-before-nonblanks ()
  2296. (save-excursion
  2297. (if (and (eq last-command-char ?\;)
  2298. (zerop (forward-line 1))
  2299. (not (looking-at "^[ \t]*$")))
  2300. 'stop
  2301. nil)))
  2302. @end group
  2303. @end example
  2304. @findex c-semi&comma-inside-parenlist
  2305. @findex c-semi&comma-no-newlines-for-oneline-inliners
  2306. @findex semi&comma-inside-parenlist (c-)
  2307. @findex semi&comma-no-newlines-for-oneline-inliners (c-)
  2308. The function @code{c-semi&comma-inside-parenlist} is what prevents
  2309. newlines from being inserted inside the parenthesis list of @code{for}
  2310. statements. In addition to
  2311. @code{c-semi&comma-no-newlines-before-nonblanks} described above,
  2312. @ccmode{} also comes with the criteria function
  2313. @code{c-semi&comma-no-newlines-for-oneline-inliners}, which suppresses
  2314. newlines after semicolons inside one-line inline method definitions
  2315. (i.e. in C++ or Java).
  2316. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2317. @node Other Special Indentations, , Customizing Semi-colons and Commas, Advanced Customizations
  2318. @comment node-name, next, previous, up
  2319. @subsection Other Special Indentations
  2320. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2321. @vindex c-label-minimum-indentation
  2322. @vindex label-minimum-indentation (c-)
  2323. In @samp{gnu} style (@pxref{Built-in Styles}), a minimum indentation
  2324. is imposed on lines inside top-level constructs. This minimum
  2325. indentation is controlled by the style variable
  2326. @code{c-label-minimum-indentation}. The default value for this variable
  2327. is 1.
  2328. @vindex c-special-indent-hook
  2329. @vindex special-indent-hook (c-)
  2330. One other customization variable is available in @ccmode{}: The style
  2331. variable @code{c-special-indent-hook}. This is a standard hook variable
  2332. that is called after every line is indented by @ccmode{}. You can use
  2333. it to do any special indentation or line adjustments your style
  2334. dictates, such as adding extra indentation to constructors or destructor
  2335. declarations in a class definition, etc. Note however, that you should
  2336. not change point or mark inside your @code{c-special-indent-hook}
  2337. functions (i.e. you'll probably want to wrap your function in a
  2338. @code{save-excursion}).
  2339. Setting @code{c-special-indent-hook} in your style definition is handled
  2340. slightly differently than other variables. In your style definition,
  2341. you should set the value for
  2342. @code{c-special-indent-hook} to a function or list of functions, which
  2343. will be appended to @code{c-special-indent-hook} using @code{add-hook}.
  2344. That way, the current setting for the buffer local value of
  2345. @code{c-special-indent-hook} won't be overridden.
  2346. @kindex M-;
  2347. @findex indent-for-comment
  2348. @vindex c-indent-comments-syntactically-p
  2349. @vindex indent-comments-syntactically-p (c-)
  2350. @vindex comment-column
  2351. Normally, the standard Emacs command @kbd{M-;}
  2352. (@code{indent-for-comment}) will indent comment only lines to
  2353. @code{comment-column}. Some users however, prefer that @kbd{M-;} act
  2354. just like @kbd{TAB} for purposes of indenting comment-only lines;
  2355. i.e. they want the comments to always indent as they would for normal
  2356. code, regardless of whether @kbd{TAB} or @kbd{M-;} were used. This
  2357. behavior is controlled by the variable
  2358. @code{c-indent-comments-syntactically-p}. When @code{nil} (the
  2359. default), @kbd{M-;} indents comment-only lines to @code{comment-column},
  2360. otherwise, they are indented just as they would be if @kbd{TAB} were
  2361. typed.
  2362. Note that this has no effect for comment lines that are inserted with
  2363. @kbd{M-;} at the end of regular code lines. These comments will always
  2364. start at @code{comment-column}.
  2365. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2366. @node Syntactic Symbols, Indentation Functions, Customizing Indentation, Top
  2367. @comment node-name, next, previous, up
  2368. @chapter Syntactic Symbols
  2369. @cindex syntactic symbols
  2370. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2371. @vindex c-offsets-alist
  2372. @vindex offsets-alist (c-)
  2373. Here is a complete list of the recognized syntactic symbols as described
  2374. in the @code{c-offsets-alist} style variable, along with a brief
  2375. description. More detailed descriptions follow.
  2376. @table @code
  2377. @item string
  2378. Inside a multi-line string.
  2379. @item c
  2380. Inside a multi-line C style block comment.
  2381. @item defun-open
  2382. Brace that opens a top-level function definition.
  2383. @item defun-close
  2384. Brace that closes a top-level function definition.
  2385. @item defun-block-intro
  2386. The first line in a top-level defun.
  2387. @item class-open
  2388. Brace that opens a class definition.
  2389. @item class-close
  2390. Brace that closes a class definition.
  2391. @item inline-open
  2392. Brace that opens an in-class inline method.
  2393. @item inline-close
  2394. Brace that closes an in-class inline method.
  2395. @item func-decl-cont
  2396. The region between a function definition's argument list and the
  2397. function opening brace (excluding K&R argument declarations). In C, you
  2398. cannot put anything but whitespace and comments in this region, however
  2399. in C++ and Java, @code{throws} declarations and other things can appear
  2400. here.
  2401. @item knr-argdecl-intro
  2402. First line of a K&R C argument declaration.
  2403. @item knr-argdecl
  2404. Subsequent lines in a K&R C argument declaration.
  2405. @item topmost-intro
  2406. The first line in a ``topmost'' definition.
  2407. @item topmost-intro-cont
  2408. Topmost definition continuation lines.
  2409. @item member-init-intro
  2410. First line in a member initialization list.
  2411. @item member-init-cont
  2412. Subsequent member initialization list lines.
  2413. @item inher-intro
  2414. First line of a multiple inheritance list.
  2415. @item inher-cont
  2416. Subsequent multiple inheritance lines.
  2417. @item block-open
  2418. Statement block open brace.
  2419. @item block-close
  2420. Statement block close brace.
  2421. @item brace-list-open
  2422. Open brace of an enum or static array list.
  2423. @item brace-list-close
  2424. Close brace of an enum or static array list.
  2425. @item brace-list-intro
  2426. First line in an enum or static array list.
  2427. @item brace-list-entry
  2428. Subsequent lines in an enum or static array list.
  2429. @item brace-entry-open
  2430. Subsequent lines in an enum or static array list where the line begins
  2431. with an open brace.
  2432. @item statement
  2433. A statement.
  2434. @item statement-cont
  2435. A continuation of a statement.
  2436. @item statement-block-intro
  2437. The first line in a new statement block.
  2438. @item statement-case-intro
  2439. The first line in a case block.
  2440. @item statement-case-open
  2441. The first line in a case block that starts with a brace.
  2442. @item substatement
  2443. The first line after a conditional or loop construct.
  2444. @item substatement-open
  2445. The brace that opens a substatement block.
  2446. @item case-label
  2447. A @code{case} or @code{default} label.
  2448. @item access-label
  2449. C++ access control label.
  2450. @item label
  2451. Any non-special C label.
  2452. @item do-while-closure
  2453. The @code{while} line that ends a @code{do}-@code{while} construct.
  2454. @item else-clause
  2455. The @code{else} line of an @code{if}-@code{else} construct.
  2456. @item catch-clause
  2457. The @code{catch} or @code{finally} (in Java) line of a
  2458. @code{try}-@code{catch} construct.
  2459. @item comment-intro
  2460. A line containing only a comment introduction.
  2461. @item arglist-intro
  2462. The first line in an argument list.
  2463. @item arglist-cont
  2464. Subsequent argument list lines when no arguments follow on the same line
  2465. as the arglist opening paren.
  2466. @item arglist-cont-nonempty
  2467. Subsequent argument list lines when at least one argument follows on the
  2468. same line as the arglist opening paren.
  2469. @item arglist-close
  2470. The solo close paren of an argument list.
  2471. @item stream-op
  2472. Lines continuing a stream operator (C++ only).
  2473. @item inclass
  2474. The line is nested inside a class definition.
  2475. @item cpp-macro
  2476. The start of a C preprocessor macro definition.
  2477. @item cpp-macro-cont
  2478. Subsequent lines of a multi-line C preprocessor macro definition.
  2479. @item friend
  2480. A C++ friend declaration.
  2481. @item objc-method-intro
  2482. The first line of an Objective-C method. definition.
  2483. @item objc-method-args-cont
  2484. Lines continuing an Objective-C method. definition
  2485. @item objc-method-call-cont
  2486. Lines continuing an Objective-C method call.
  2487. @item extern-lang-open
  2488. Brace that opens an external language block.
  2489. @item extern-lang-close
  2490. Brace that closes an external language block.
  2491. @item inextern-lang
  2492. Analogous to @code{inclass} syntactic symbol, but used inside external
  2493. language blocks (e.g. @code{extern "C" @{}).
  2494. @item namespace-open
  2495. Brace that opens a C++ namespace block.
  2496. @item namespace-close
  2497. Brace that closes a C++ namespace block.
  2498. @item innamespace
  2499. Analogous to @code{inextern-lang} syntactic symbol, but used inside C++
  2500. namespace blocks.
  2501. @item template-args-cont
  2502. C++ template argument list continuations.
  2503. @item inlambda
  2504. Analogous to @code{inclass} syntactic symbol, but used inside lambda
  2505. (i.e. anonymous) functions. Only used in Pike mode.
  2506. @item lambda-intro-cont
  2507. Lines continuing the header of a lambda function, i.e. between the
  2508. @code{lambda} keyword and the function body. Only used in Pike mode.
  2509. @item inexpr-statement
  2510. A statement block inside an expression. The gcc C extension of this is
  2511. recognized. It's also used for the special functions that takes a
  2512. statement block as an argument in Pike.
  2513. @item inexpr-class
  2514. A class definition inside an expression. This is used for anonymous
  2515. classes in Java. It's also used for anonymous array initializers in
  2516. Java.
  2517. @end table
  2518. @cindex -open syntactic symbols
  2519. @cindex -close syntactic symbols
  2520. Most syntactic symbol names follow a general naming convention. When a
  2521. line begins with an open or close brace, the syntactic symbol will
  2522. contain the suffix @code{-open} or @code{-close} respectively.
  2523. @cindex -intro syntactic symbols
  2524. @cindex -cont syntactic symbols
  2525. @cindex -block-intro syntactic symbols
  2526. Usually, a distinction is made between the first line that introduces a
  2527. construct and lines that continue a construct, and the syntactic symbols
  2528. that represent these lines will contain the suffix @code{-intro} or
  2529. @code{-cont} respectively. As a sub-classification of this scheme, a
  2530. line which is the first of a particular brace block construct will
  2531. contain the suffix @code{-block-intro}.
  2532. Let's look at some examples to understand how this works. Remember that
  2533. you can check the syntax of any line by using @kbd{C-c C-s}.
  2534. @example
  2535. @group
  2536. 1: void
  2537. 2: swap( int& a, int& b )
  2538. 3: @{
  2539. 4: int tmp = a;
  2540. 5: a = b;
  2541. 6: b = tmp;
  2542. 7: int ignored =
  2543. 8: a + b;
  2544. 9: @}
  2545. @end group
  2546. @end example
  2547. @cindex topmost-intro syntactic symbol
  2548. @cindex topmost-intro-cont syntactic symbol
  2549. @cindex defun-open syntactic symbol
  2550. @cindex defun-close syntactic symbol
  2551. @cindex defun-block-intro syntactic symbol
  2552. Line 1 shows a @code{topmost-intro} since it is the first line that
  2553. introduces a top-level construct. Line 2 is a continuation of the
  2554. top-level construct introduction so it has the syntax
  2555. @code{topmost-intro-cont}. Line 3 shows a @code{defun-open} since it is
  2556. the brace that opens a top-level function definition. Line 9 is the
  2557. corresponding
  2558. @code{defun-close} since it contains the brace that closes the top-level
  2559. function definition. Line 4 is a @code{defun-block-intro}, i.e. it is
  2560. the first line of a brace-block, enclosed in a
  2561. top-level function definition.
  2562. @cindex statement syntactic symbol
  2563. @cindex statement-cont syntactic symbol
  2564. Lines 5, 6, and 7 are all given @code{statement} syntax since there
  2565. isn't much special about them. Note however that line 8 is given
  2566. @code{statement-cont} syntax since it continues the statement begun
  2567. on the previous line.
  2568. Here's another example, which illustrates some C++ class syntactic
  2569. symbols:
  2570. @example
  2571. @group
  2572. 1: class Bass
  2573. 2: : public Guitar,
  2574. 3: public Amplifiable
  2575. 4: @{
  2576. 5: public:
  2577. 6: Bass()
  2578. 7: : eString( new BassString( 0.105 )),
  2579. 8: aString( new BassString( 0.085 )),
  2580. 9: dString( new BassString( 0.065 )),
  2581. 10: gString( new BassString( 0.045 ))
  2582. 11: @{
  2583. 12: eString.tune( 'E' );
  2584. 13: aString.tune( 'A' );
  2585. 14: dString.tune( 'D' );
  2586. 15: gString.tune( 'G' );
  2587. 16: @}
  2588. 17: friend class Luthier;
  2589. 18: @}
  2590. @end group
  2591. @end example
  2592. @cindex class-open syntactic symbol
  2593. @cindex class-close syntactic symbol
  2594. As in the previous example, line 1 has the @code{topmost-intro} syntax.
  2595. Here however, the brace that opens a C++ class definition on line 4 is
  2596. assigned the @code{class-open} syntax. Note that in C++, classes,
  2597. structs, and unions are essentially equivalent syntactically (and are
  2598. very similar semantically), so replacing the @code{class} keyword in the
  2599. example above with @code{struct} or @code{union} would still result in a
  2600. syntax of @code{class-open} for line 4 @footnote{This is the case even
  2601. for C and Objective-C. For consistency, structs in all supported
  2602. languages are syntactically equivalent to classes. Note however that
  2603. the keyword @code{class} is meaningless in C and Objective-C.}.
  2604. Similarly, line 18 is assigned @code{class-close} syntax.
  2605. @cindex inher-intro syntactic symbol
  2606. @cindex inher-cont syntactic symbol
  2607. Line 2 introduces the inheritance list for the class so it is assigned
  2608. the @code{inher-intro} syntax, and line 3, which continues the
  2609. inheritance list is given @code{inher-cont} syntax.
  2610. @cindex access-label syntactic symbol
  2611. @cindex inclass syntactic symbol
  2612. Hitting @kbd{C-c C-s} on line 5 shows the following analysis:
  2613. @example
  2614. @group
  2615. @code{((inclass . 58) (access-label . 67))}
  2616. @end group
  2617. @end example
  2618. @noindent
  2619. The primary syntactic symbol for this line is @code{access-label} as
  2620. this a label keyword that specifies access protection in C++. However,
  2621. because this line is also a top-level construct inside a class
  2622. definition, the analysis actually shows two syntactic symbols. The
  2623. other syntactic symbol assigned to this line is @code{inclass}.
  2624. Similarly, line 6 is given both @code{inclass} and @code{topmost-intro}
  2625. syntax:
  2626. @example
  2627. @group
  2628. @code{((inclass . 58) (topmost-intro . 60))}
  2629. @end group
  2630. @end example
  2631. @cindex member-init-intro syntactic symbol
  2632. @cindex member-init-cont syntactic symbol
  2633. Line 7 introduces a C++ member initialization list and as such is given
  2634. @code{member-init-intro} syntax. Note that in this case it is
  2635. @emph{not} assigned @code{inclass} since this is not considered a
  2636. top-level construct. Lines 8 through 10 are all assigned
  2637. @code{member-init-cont} since they continue the member initialization
  2638. list started on line 7.
  2639. @cindex in-class inline methods
  2640. @cindex inline-open syntactic symbol
  2641. @cindex inline-close syntactic symbol
  2642. Line 11's analysis is a bit more complicated:
  2643. @example
  2644. @group
  2645. @code{((inclass . 58) (inline-open))}
  2646. @end group
  2647. @end example
  2648. This line is assigned a syntax of both @code{inline-open} and
  2649. @code{inclass} because it opens an @dfn{in-class} C++ inline method
  2650. definition. This is distinct from, but related to, the C++ notion of an
  2651. inline function in that its definition occurs inside an enclosing class
  2652. definition, which in C++ implies that the function should be inlined.
  2653. If though, the definition of the @code{Bass} constructor appeared
  2654. outside the class definition, the construct would be given the
  2655. @code{defun-open} syntax, even if the keyword @code{inline} appeared
  2656. before the method name, as in:
  2657. @example
  2658. @group
  2659. class Bass
  2660. : public Guitar,
  2661. public Amplifiable
  2662. @{
  2663. public:
  2664. Bass();
  2665. @}
  2666. inline
  2667. Bass::Bass()
  2668. : eString( new BassString( 0.105 )),
  2669. aString( new BassString( 0.085 )),
  2670. dString( new BassString( 0.065 )),
  2671. gString( new BassString( 0.045 ))
  2672. @{
  2673. eString.tune( 'E' );
  2674. aString.tune( 'A' );
  2675. dString.tune( 'D' );
  2676. gString.tune( 'G' );
  2677. @}
  2678. @end group
  2679. @end example
  2680. @cindex friend syntactic symbol
  2681. Returning to the previous example, line 16 is given @code{inline-close}
  2682. syntax, while line 12 is given @code{defun-block-open} syntax, and lines
  2683. 13 through 15 are all given @code{statement} syntax. Line 17 is
  2684. interesting in that its syntactic analysis list contains three
  2685. elements:
  2686. @example
  2687. @code{((friend) (inclass . 58) (topmost-intro . 380))}
  2688. @end example
  2689. The @code{friend} syntactic symbol is a modifier that typically does not
  2690. have a relative buffer position.
  2691. Template definitions introduce yet another syntactic symbol:
  2692. @example
  2693. @group
  2694. 1: ThingManager <int,
  2695. 2: Framework::Callback *,
  2696. 3: Mutex> framework_callbacks;
  2697. @end group
  2698. @end example
  2699. Here, line 1 is analyzed as a @code{topmost-intro}, but lines 2 and 3
  2700. are both analyzed as @code{template-args-cont} lines.
  2701. Here is another (totally contrived) example which illustrates how syntax
  2702. is assigned to various conditional constructs:
  2703. @example
  2704. @group
  2705. 1: void spam( int index )
  2706. 2: @{
  2707. 3: for( int i=0; i<index; i++ )
  2708. 4: @{
  2709. 5: if( i == 10 )
  2710. 6: @{
  2711. 7: do_something_special();
  2712. 8: @}
  2713. 9: else
  2714. 10: do_something( i );
  2715. 11: @}
  2716. 12: do @{
  2717. 13: another_thing( i-- );
  2718. 14: @}
  2719. 15: while( i > 0 );
  2720. 16: @}
  2721. @end group
  2722. @end example
  2723. @noindent
  2724. Only the lines that illustrate new syntactic symbols will be discussed.
  2725. @cindex substatement-open syntactic symbol
  2726. @cindex substatement-block-intro syntactic symbol
  2727. @cindex block-close syntactic symbol
  2728. Line 4 has a brace which opens a conditional's substatement block. It
  2729. is thus assigned @code{substatement-open} syntax, and since line 5 is
  2730. the first line in the substatement block, it is assigned
  2731. @code{substatement-block-intro} syntax. Lines 6 and 7 are assigned
  2732. similar syntax. Line 8 contains the brace that closes the inner
  2733. substatement block. It is given the syntax @code{block-close},
  2734. as are lines 11 and 14.
  2735. @cindex else-clause syntactic symbol
  2736. @cindex catch-clause syntactic symbol
  2737. Line 9 is a little different --- since it contains the keyword
  2738. @code{else} matching the @code{if} statement introduced on line 5, it is
  2739. given the @code{else-clause} syntax. The @code{try}-@code{catch}
  2740. constructs in C++ and Java are treated this way too, with the only
  2741. difference that the @code{catch}, and in Java also @code{finally}, is
  2742. marked with @code{catch-clause}.
  2743. @cindex substatement syntactic symbol
  2744. Line 10 is also slightly different. Because @code{else} is considered a
  2745. conditional introducing keyword @footnote{The list of conditional
  2746. keywords are (in C, C++, Objective-C, Java, and Pike): @code{for},
  2747. @code{if}, @code{do}, @code{else}, @code{while}, and @code{switch}. C++
  2748. and Java have two additional conditional keywords: @code{try} and
  2749. @code{catch}. Java also has the @code{finally} and @code{synchronized}
  2750. keywords.}, and because the following substatement is not a brace block,
  2751. line 10 is assigned the @code{substatement} syntax.
  2752. @cindex do-while-closure syntactic symbol
  2753. One other difference is seen on line 15. The @code{while} construct
  2754. that closes a @code{do} conditional is given the special syntax
  2755. @code{do-while-closure} if it appears on a line by itself. Note that if
  2756. the @code{while} appeared on the same line as the preceding close brace,
  2757. that line would have been assigned @code{block-close} syntax instead.
  2758. Switch statements have their own set of syntactic symbols. Here's an
  2759. example:
  2760. @example
  2761. @group
  2762. 1: void spam( enum Ingredient i )
  2763. 2: @{
  2764. 3: switch( i ) @{
  2765. 4: case Ham:
  2766. 5: be_a_pig();
  2767. 6: break;
  2768. 7: case Salt:
  2769. 8: drink_some_water();
  2770. 9: break;
  2771. 10: default:
  2772. 11: @{
  2773. 12: what_is_it();
  2774. 13: break;
  2775. 14: @}
  2776. 15: @}
  2777. 14: @}
  2778. @end group
  2779. @end example
  2780. @cindex case-label syntactic symbol
  2781. @cindex statement-case-intro syntactic symbol
  2782. @cindex statement-case-open syntactic symbol
  2783. Here, lines 4, 7, and 10 are all assigned @code{case-label} syntax,
  2784. while lines 5 and 8 are assigned @code{statement-case-intro}. Line 11
  2785. is treated slightly differently since it contains a brace that opens a
  2786. block --- it is given @code{statement-case-open} syntax.
  2787. @cindex brace lists
  2788. There are a set of syntactic symbols that are used to recognize
  2789. constructs inside of brace lists. A brace list is defined as an
  2790. @code{enum} or aggregate initializer list, such as might statically
  2791. initialize an array of structs. The three special aggregate constructs
  2792. in Pike, @code{(@{ @})}, @code{([ ])} and @code{(< >)}, are treated as
  2793. brace lists too. An example:
  2794. @example
  2795. @group
  2796. 1: static char* ingredients[] =
  2797. 2: @{
  2798. 3: "Ham",
  2799. 4: "Salt",
  2800. 5: NULL
  2801. 6: @}
  2802. @end group
  2803. @end example
  2804. @cindex brace-list-open syntactic symbol
  2805. @cindex brace-list-intro syntactic symbol
  2806. @cindex brace-list-close syntactic symbol
  2807. @cindex brace-list-entry syntactic symbol
  2808. Following convention, line 2 in this example is assigned
  2809. @code{brace-list-open} syntax, and line 3 is assigned
  2810. @code{brace-list-intro} syntax. Likewise, line 6 is assigned
  2811. @code{brace-list-close} syntax. Lines 4 and 5 however, are assigned
  2812. @code{brace-list-entry} syntax, as would all subsequent lines in this
  2813. initializer list.
  2814. @cindex brace-entry-open syntactic symbol
  2815. Your static initializer might be initializing nested structures, for
  2816. example:
  2817. @example
  2818. @group
  2819. 1: struct intpairs[] =
  2820. 2: @{
  2821. 3: @{ 1, 2 @},
  2822. 4: @{
  2823. 5: 3,
  2824. 6: 4
  2825. 7: @}
  2826. 8: @{ 1,
  2827. 9: 2 @},
  2828. 10: @{ 3, 4 @}
  2829. 11: @}
  2830. @end group
  2831. @end example
  2832. Here, you've already seen the analysis of lines 1, 2, 3, and 11. On
  2833. line 4, things get interesting; this line is assigned
  2834. @code{brace-entry-open} syntactic symbol because it's a bracelist entry
  2835. line that starts with an open brace. Lines 5 and 6 (and line 9) are
  2836. pretty standard, and line 7 is a @code{brace-list-close} as you'd
  2837. expect. Once again, line 8 is assigned as @code{brace-entry-open} as is
  2838. line 10.
  2839. External language definition blocks also have their own syntactic
  2840. symbols. In this example:
  2841. @example
  2842. @group
  2843. 1: extern "C"
  2844. 2: @{
  2845. 3: int thing_one( int );
  2846. 4: int thing_two( double );
  2847. 5: @}
  2848. @end group
  2849. @end example
  2850. @cindex extern-lang-open syntactic symbol
  2851. @cindex extern-lang-close syntactic symbol
  2852. @cindex inextern-lang syntactic symbol
  2853. @cindex inclass syntactic symbol
  2854. @noindent
  2855. line 2 is given the @code{extern-lang-open} syntax, while line 5 is given
  2856. the @code{extern-lang-close} syntax. The analysis for line 3 yields:
  2857. @code{((inextern-lang) (topmost-intro . 14))}, where
  2858. @code{inextern-lang} is a modifier similar in purpose to @code{inclass}.
  2859. Similarly, C++ namespace constructs have their own associated syntactic
  2860. symbols. In this example:
  2861. @example
  2862. @group
  2863. 1: namespace foo
  2864. 2: @{
  2865. 3: void xxx() @{@}
  2866. 4: @}
  2867. @end group
  2868. @end example
  2869. @cindex namespace-open syntactic symbol
  2870. @cindex namespace-close syntactic symbol
  2871. @cindex innamespace syntactic symbol
  2872. @noindent
  2873. line 2 is given the @code{namespace-open} syntax, while line 4 is given
  2874. the @code{namespace-close} syntax. The analysis for line 3 yields:
  2875. @code{((innamespace) (topmost-intro . 17))}, where @code{innamespace} is
  2876. a modifier similar in purpose to @code{inextern-lang} and @code{inclass}.
  2877. A number of syntactic symbols are associated with parenthesis lists,
  2878. a.k.a argument lists, as found in function declarations and function
  2879. calls. This example illustrates these:
  2880. @example
  2881. @group
  2882. 1: void a_function( int line1,
  2883. 2: int line2 );
  2884. 3:
  2885. 4: void a_longer_function(
  2886. 5: int line1,
  2887. 6: int line2
  2888. 7: );
  2889. 8:
  2890. 9: void call_them( int line1, int line2 )
  2891. 10: @{
  2892. 11: a_function(
  2893. 12: line1,
  2894. 13: line2
  2895. 14: );
  2896. 15:
  2897. 16: a_longer_function( line1,
  2898. 17: line2 );
  2899. 18: @}
  2900. @end group
  2901. @end example
  2902. @cindex arglist-intro syntactic symbol
  2903. @cindex arglist-close syntactic symbol
  2904. Lines 5 and 12 are assigned @code{arglist-intro} syntax since they are
  2905. the first line following the open parenthesis, and lines 7 and 14 are
  2906. assigned @code{arglist-close} syntax since they contain the parenthesis
  2907. that closes the argument list.
  2908. @cindex arglist-cont-nonempty syntactic symbol
  2909. @cindex arglist-cont syntactic symbol
  2910. Lines that continue argument lists can be assigned one of two syntactic
  2911. symbols. For example, Lines 2 and 17
  2912. are assigned @code{arglist-cont-nonempty} syntax. What this means
  2913. is that they continue an argument list, but that the line containing the
  2914. parenthesis that opens the list is @emph{not empty} following the open
  2915. parenthesis. Contrast this against lines 6 and 13 which are assigned
  2916. @code{arglist-cont} syntax. This is because the parenthesis that opens
  2917. their argument lists is the last character on that line.
  2918. Note that there is no @code{arglist-open} syntax. This is because any
  2919. parenthesis that opens an argument list, appearing on a separate line,
  2920. is assigned the @code{statement-cont} syntax instead.
  2921. A few miscellaneous syntactic symbols that haven't been previously
  2922. covered are illustrated by this C++ example:
  2923. @example
  2924. @group
  2925. 1: void Bass::play( int volume )
  2926. 2: const
  2927. 3: @{
  2928. 4: /* this line starts a multi-line
  2929. 5: * comment. This line should get `c' syntax */
  2930. 6:
  2931. 7: char* a_multiline_string = "This line starts a multi-line \
  2932. 8: string. This line should get `string' syntax.";
  2933. 9:
  2934. 10: note:
  2935. 11: @{
  2936. 12: #ifdef LOCK
  2937. 13: Lock acquire();
  2938. 14: #endif // LOCK
  2939. 15: slap_pop();
  2940. 16: cout << "I played "
  2941. 17: << "a note\n";
  2942. 18: @}
  2943. 19: @}
  2944. @end group
  2945. @end example
  2946. The lines to note in this example include:
  2947. @itemize @bullet
  2948. @cindex func-decl-cont syntactic symbol
  2949. @item
  2950. Line 2 is assigned the @code{func-decl-cont} syntax.
  2951. @cindex comment-intro syntactic symbol
  2952. @item
  2953. Line 4 is assigned both @code{defun-block-intro} @emph{and}
  2954. @code{comment-intro} syntax.
  2955. @cindex c syntactic symbol
  2956. @item
  2957. Line 5 is assigned @code{c} syntax.
  2958. @item
  2959. @cindex syntactic whitespace
  2960. Line 6 which, even though it contains nothing but whitespace, is
  2961. assigned @code{defun-block-intro}. Note that the appearance of the
  2962. comment on lines 4 and 5 do not cause line 6 to be assigned
  2963. @code{statement} syntax because comments are considered to be
  2964. @dfn{syntactic whitespace}, which are ignored when analyzing
  2965. code.
  2966. @cindex string syntactic symbol
  2967. @item
  2968. Line 8 is assigned @code{string} syntax.
  2969. @cindex label syntactic symbol
  2970. @item
  2971. Line 10 is assigned @code{label} syntax.
  2972. @cindex block-open syntactic symbol
  2973. @item
  2974. Line 11 is assigned @code{block-open} syntax.
  2975. @cindex cpp-macro syntactic symbol
  2976. @cindex cpp-macro-cont syntactic symbol
  2977. @item
  2978. Lines 12 and 14 are assigned @code{cpp-macro} syntax in addition to the
  2979. normal syntactic symbols (@code{statement-block-intro} and
  2980. @code{statement}, respectively). Normally @code{cpp-macro} is
  2981. configured to cancel out the normal syntactic context to make all
  2982. preprocessor directives stick to the first column, but that's easily
  2983. changed if you want preprocessor directives to be indented like the rest
  2984. of the code.
  2985. @cindex stream-op syntactic symbol
  2986. @item
  2987. Line 17 is assigned @code{stream-op} syntax.
  2988. @end itemize
  2989. @cindex multi-line macros
  2990. @cindex syntactic whitespace
  2991. Multi-line C preprocessor macros are now (somewhat) supported. At least
  2992. @ccmode{} now recognizes the fact that it is inside a multi-line macro,
  2993. and it properly skips such macros as syntactic whitespace. In this
  2994. example:
  2995. @example
  2996. @group
  2997. 1: #define LIST_LOOP(cons, listp) \
  2998. 2: for (cons = listp; !NILP (cons); cons = XCDR (cons)) \
  2999. 3: if (!CONSP (cons)) \
  3000. 4: signal_error ("Invalid list format", listp); \
  3001. 5: else
  3002. @end group
  3003. @end example
  3004. @noindent
  3005. line 1 is given the syntactic symbol @code{cpp-macro}. This first line
  3006. of a macro is always given this symbol. The second and subsequent lines
  3007. (e.g. lines 2 through 5) are given the @code{cpp-macro-cont} syntactic
  3008. symbol, with a relative buffer position pointing to the @code{#} which
  3009. starts the macro definition.
  3010. In Objective-C buffers, there are three additional syntactic symbols
  3011. assigned to various message calling constructs. Here's an example
  3012. illustrating these:
  3013. @example
  3014. @group
  3015. 1: - (void)setDelegate:anObject
  3016. 2: withStuff:stuff
  3017. 3: @{
  3018. 4: [delegate masterWillRebind:self
  3019. 5: toDelegate:anObject
  3020. 6: withExtraStuff:stuff];
  3021. 7: @}
  3022. @end group
  3023. @end example
  3024. @cindex objc-method-intro syntactic symbol
  3025. @cindex objc-method-args-cont syntactic symbol
  3026. @cindex objc-method-call-cont syntactic symbol
  3027. Here, line 1 is assigned @code{objc-method-intro} syntax, and line 2 is
  3028. assigned @code{objc-method-args-cont} syntax. Lines 5 and 6 are both
  3029. assigned @code{objc-method-call-cont} syntax.
  3030. Java has a concept of anonymous classes, which may look something like
  3031. this:
  3032. @example
  3033. @group
  3034. 1: public void watch(Observable o) @{
  3035. 2: o.addObserver(new Observer() @{
  3036. 3: public void update(Observable o, Object arg) @{
  3037. 4: history.addElement(arg);
  3038. 5: @}
  3039. 6: @});
  3040. 7: @}
  3041. @end group
  3042. @end example
  3043. @cindex inexpr-class syntactic symbol
  3044. The brace following the @code{new} operator opens the anonymous class.
  3045. Lines 3 and 6 are assigned the @code{inexpr-class} syntax, besides the
  3046. @code{inclass} symbol used in normal classes. Thus, the class will be
  3047. indented just like a normal class, with the added indentation given to
  3048. @code{inexpr-class}.
  3049. There are a few occasions where a statement block may be used inside an
  3050. expression. One is in C code using the gcc extension for this, e.g:
  3051. @example
  3052. @group
  3053. 1: int res = (@{
  3054. 2: int y = foo (); int z;
  3055. 3: if (y > 0) z = y; else z = - y;
  3056. 4: z;
  3057. 5: @});
  3058. @end group
  3059. @end example
  3060. @cindex inexpr-statement syntactic symbol
  3061. Lines 2 and 5 get the @code{inexpr-statement} syntax, besides the
  3062. symbols they'd get in a normal block. Therefore, the indentation put on
  3063. @code{inexpr-statement} is added to the normal statement block
  3064. indentation.
  3065. In Pike code, there are a few other situations where blocks occur inside
  3066. statements, as illustrated here:
  3067. @example
  3068. @group
  3069. 1: array itgob()
  3070. 2: @{
  3071. 3: string s = map (backtrace()[-2][3..],
  3072. 4: lambda
  3073. 5: (mixed arg)
  3074. 6: @{
  3075. 7: return sprintf ("%t", arg);
  3076. 8: @}) * ", " + "\n";
  3077. 9: return catch @{
  3078. 10: write (s + "\n");
  3079. 11: @};
  3080. 12: @}
  3081. @end group
  3082. @end example
  3083. @cindex inlambda syntactic symbol
  3084. @cindex lambda-intro-cont syntactic symbol
  3085. Lines 4 through 8 contain a lambda function, which @ccmode{} recognizes
  3086. by the @code{lambda} keyword. If the function argument list is put
  3087. on a line of its own, as in line 5, it gets the @code{lambda-intro-cont}
  3088. syntax. The function body is handled as an inline method body, with the
  3089. addition of the @code{inlambda} syntactic symbol. This means that line
  3090. 6 gets @code{inlambda} and @code{inline-open}, and line 8 gets
  3091. @code{inline-close}@footnote{You might wonder why it doesn't get
  3092. @code{inlambda} too. It's because the closing brace is relative to the
  3093. opening brace, which stands on its own line in this example. If the
  3094. opening brace was hanging on the previous line, then the closing brace
  3095. would get the @code{inlambda} syntax too to be indented correctly.}.
  3096. @cindex inexpr-statement syntactic symbol
  3097. On line 9, @code{catch} is a special function taking a statement block
  3098. as its argument. The block is handled as an in-expression statement
  3099. with the @code{inexpr-statement} syntax, just like the gcc extended C
  3100. example above. The other similar special function, @code{gauge}, is
  3101. handled like this too.
  3102. @cindex knr-argdecl-intro syntactic symbol
  3103. @cindex knr-argdecl syntactic symbol
  3104. Two other syntactic symbols can appear in old style, non-prototyped C
  3105. code @footnote{a.k.a. K&R C, or Kernighan & Ritchie C}:
  3106. @example
  3107. @group
  3108. 1: int add_three_integers(a, b, c)
  3109. 2: int a;
  3110. 3: int b;
  3111. 4: int c;
  3112. 5: @{
  3113. 6: return a + b + c;
  3114. 7: @}
  3115. @end group
  3116. @end example
  3117. Here, line 2 is the first line in an argument declaration list and so is
  3118. given the @code{knr-argdecl-intro} syntactic symbol. Subsequent lines
  3119. (i.e. lines 3 and 4 in this example), are given @code{knr-argdecl}
  3120. syntax.
  3121. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3122. @node Indentation Functions, Performance Issues, Syntactic Symbols, Top
  3123. @comment node-name, next, previous, up
  3124. @chapter Indentation Functions
  3125. @cindex indentation functions
  3126. @cindex line-up functions
  3127. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3128. Often there are cases when a simple offset setting on a syntactic symbol
  3129. isn't enough to get the desired indentation. Therefore, it's also
  3130. possible to use a @dfn{indentation function} (a.k.a. line-up function)
  3131. for a syntactic symbol.
  3132. @ccmode{} comes with many predefined indentation functions for common
  3133. situations. If none of these does what you want, you can write your
  3134. own, see @ref{Custom Indentation Functions}. If you do, it's probably a
  3135. good idea to start working from one of these predefined functions, they
  3136. can be found in the file @file{cc-align.el}.
  3137. For every function below there is a ``works with'' list that indicates
  3138. which syntactic symbols the function is intended to be used with.
  3139. @macro workswith
  3140. @emph{Works with:@ }
  3141. @end macro
  3142. @ifinfo
  3143. @unmacro workswith
  3144. @macro workswith
  3145. Works with:
  3146. @end macro
  3147. @end ifinfo
  3148. @table @code
  3149. @findex c-lineup-arglist
  3150. @findex lineup-arglist (c-)
  3151. @item c-lineup-arglist
  3152. Line up the current argument line under the first argument.
  3153. @workswith @code{arglist-cont-nonempty}.
  3154. @findex c-lineup-arglist-intro-after-paren
  3155. @findex lineup-arglist-intro-after-paren (c-)
  3156. @item c-lineup-arglist-intro-after-paren
  3157. Line up a line just after the open paren of the surrounding paren or
  3158. brace block.
  3159. @workswith @code{defun-block-intro}, @code{brace-list-intro},
  3160. @code{statement-block-intro}, @code{statement-case-intro},
  3161. @code{arglist-intro}.
  3162. @findex c-lineup-arglist-close-under-paren
  3163. @findex lineup-arglist-close-under-paren (c-)
  3164. @item c-lineup-arglist-close-under-paren
  3165. Set e.g. your @code{arglist-close} syntactic symbol to this line-up
  3166. function so that parentheses that close argument lists will line up
  3167. under the parenthesis that opened the argument list.
  3168. @workswith @code{defun-close}, @code{class-close}, @code{inline-close},
  3169. @code{block-close}, @code{brace-list-close}, @code{arglist-close},
  3170. @code{extern-lang-close}, @code{namespace-close} (for most of these, a
  3171. zero offset will normally produce the same result, though).
  3172. @findex c-lineup-close-paren
  3173. @findex lineup-close-paren (c-)
  3174. @item c-lineup-close-paren
  3175. Line up the closing paren under its corresponding open paren if the
  3176. open paren is followed by code. If the open paren ends its line, no
  3177. indentation is added. E.g:
  3178. @example
  3179. @group
  3180. main (int,
  3181. char **
  3182. ) // c-lineup-close-paren
  3183. @end group
  3184. @end example
  3185. @noindent
  3186. and
  3187. @example
  3188. @group
  3189. main (
  3190. int, char **
  3191. ) // c-lineup-close-paren
  3192. @end group
  3193. @end example
  3194. @workswith @code{defun-close}, @code{class-close}, @code{inline-close},
  3195. @code{block-close}, @code{brace-list-close}, @code{arglist-close},
  3196. @code{extern-lang-close}, @code{namespace-close}.
  3197. @findex c-lineup-streamop
  3198. @findex lineup-streamop (c-)
  3199. @item c-lineup-streamop
  3200. Line up C++ stream operators (i.e. @samp{<<} and @samp{>>}).
  3201. @workswith @code{stream-op}.
  3202. @findex c-lineup-multi-inher
  3203. @findex lineup-multi-inher (c-)
  3204. @item c-lineup-multi-inher
  3205. Line up the classes in C++ multiple inheritance clauses and member
  3206. initializers under each other. E.g:
  3207. @example
  3208. @group
  3209. Foo::Foo (int a, int b):
  3210. Cyphr (a),
  3211. Bar (b) // c-lineup-multi-inher
  3212. @end group
  3213. @end example
  3214. @noindent
  3215. and
  3216. @example
  3217. @group
  3218. class Foo
  3219. : public Cyphr,
  3220. public Bar // c-lineup-multi-inher
  3221. @end group
  3222. @end example
  3223. @noindent
  3224. and
  3225. @example
  3226. @group
  3227. Foo::Foo (int a, int b)
  3228. : Cyphr (a)
  3229. , Bar (b) // c-lineup-multi-inher
  3230. @end group
  3231. @end example
  3232. @workswith @code{inher-cont}, @code{member-init-cont}.
  3233. @findex c-lineup-java-inher
  3234. @findex lineup-java-inher (c-)
  3235. @item c-lineup-java-inher
  3236. Line up Java implements and extends declarations. If class names
  3237. follows on the same line as the @samp{implements}/@samp{extends}
  3238. keyword, they are lined up under each other. Otherwise, they are
  3239. indented by adding @code{c-basic-offset} to the column of the keyword.
  3240. E.g:
  3241. @example
  3242. @group
  3243. class Foo
  3244. extends
  3245. Bar // c-lineup-java-inher
  3246. <--> c-basic-offset
  3247. @end group
  3248. @end example
  3249. @noindent
  3250. and
  3251. @example
  3252. @group
  3253. class Foo
  3254. extends Cyphr,
  3255. Bar // c-lineup-java-inher
  3256. @end group
  3257. @end example
  3258. @workswith @code{inher-cont}.
  3259. @findex c-lineup-java-throws
  3260. @findex lineup-java-throws (c-)
  3261. @item c-lineup-java-throws
  3262. Line up Java throws declarations. If exception names follows on the
  3263. same line as the throws keyword, they are lined up under each other.
  3264. Otherwise, they are indented by adding @code{c-basic-offset} to the
  3265. column of the @samp{throws} keyword. The @samp{throws} keyword itself
  3266. is also indented by @code{c-basic-offset} from the function declaration
  3267. start if it doesn't hang. E.g:
  3268. @example
  3269. @group
  3270. int foo()
  3271. throws // c-lineup-java-throws
  3272. Bar // c-lineup-java-throws
  3273. <--><--> c-basic-offset
  3274. @end group
  3275. @end example
  3276. @noindent
  3277. and
  3278. @example
  3279. @group
  3280. int foo() throws Cyphr,
  3281. Bar, // c-lineup-java-throws
  3282. Vlod // c-lineup-java-throws
  3283. @end group
  3284. @end example
  3285. @workswith @code{func-decl-cont}.
  3286. @findex c-indent-one-line-block
  3287. @findex indent-one-line-block (c-)
  3288. @item c-indent-one-line-block
  3289. Indent a one line block @code{c-basic-offset} extra. E.g:
  3290. @example
  3291. @group
  3292. if (n > 0)
  3293. @{m+=n; n=0;@} // c-indent-one-line-block
  3294. <--> c-basic-offset
  3295. @end group
  3296. @end example
  3297. @noindent
  3298. and
  3299. @example
  3300. @group
  3301. if (n > 0)
  3302. @{ // c-indent-one-line-block
  3303. m+=n; n=0;
  3304. @}
  3305. @end group
  3306. @end example
  3307. The block may be surrounded by any kind of parenthesis characters.
  3308. @code{nil} is returned if the line doesn't start with a one line block,
  3309. which makes the function usable in list expressions.
  3310. @workswith Almost all syntactic symbols, but most useful on the
  3311. @code{-open} symbols.
  3312. @findex c-indent-multi-line-block
  3313. @findex indent-multi-line-block (c-)
  3314. @item c-indent-multi-line-block
  3315. Indent a multi line block @code{c-basic-offset} extra. E.g:
  3316. @example
  3317. @group
  3318. int *foo[] = @{
  3319. NULL,
  3320. @{17@}, // c-indent-multi-line-block
  3321. @end group
  3322. @end example
  3323. @noindent
  3324. and
  3325. @example
  3326. @group
  3327. int *foo[] = @{
  3328. NULL,
  3329. @{ // c-indent-multi-line-block
  3330. 17
  3331. @},
  3332. <--> c-basic-offset
  3333. @end group
  3334. @end example
  3335. The block may be surrounded by any kind of parenthesis characters.
  3336. @code{nil} is returned if the line doesn't start with a multi line
  3337. block, which makes the function usable in list expressions.
  3338. @workswith Almost all syntactic symbols, but most useful on the
  3339. @code{-open} symbols.
  3340. @findex c-lineup-C-comments
  3341. @findex lineup-C-comments (c-)
  3342. @item c-lineup-C-comments
  3343. Line up C block comment continuation lines. Various heuristics are used
  3344. to handle most of the common comment styles. Some examples:
  3345. @example
  3346. @group
  3347. /* /** /*
  3348. * text * text text
  3349. */ */ */
  3350. @end group
  3351. @group
  3352. /* text /* /**
  3353. text ** text ** text
  3354. */ */ */
  3355. @end group
  3356. @group
  3357. /**************************************************
  3358. * text
  3359. *************************************************/
  3360. @end group
  3361. @vindex comment-start-skip
  3362. @group
  3363. /**************************************************
  3364. Free form text comments:
  3365. In comments with a long delimiter line at the
  3366. start, the indentation is kept unchanged for lines
  3367. that start with an empty comment line prefix. The
  3368. delimiter line is whatever matches the
  3369. @code{comment-start-skip} regexp.
  3370. **************************************************/
  3371. @end group
  3372. @end example
  3373. The style variable @code{c-comment-prefix-regexp} is used to recognize
  3374. the comment line prefix, e.g. the @samp{*} that usually starts every
  3375. line inside a comment.
  3376. @workswith The @code{c} syntactic symbol.
  3377. @findex c-lineup-comment
  3378. @findex lineup-comment (c-)
  3379. @item c-lineup-comment
  3380. Line up a comment-only line according to the style variable
  3381. @code{c-comment-only-line-offset}. If the comment is lined up with a
  3382. comment starter on the previous line, that alignment is preserved.
  3383. @vindex c-comment-only-line-offset
  3384. @vindex comment-only-line-offset (c-)
  3385. @code{c-comment-only-line-offset} specifies the extra offset for the
  3386. line. It can contain an integer or a cons cell of the form
  3387. @example
  3388. (@r{<non-anchored-offset>} . @r{<anchored-offset>})
  3389. @end example
  3390. @noindent
  3391. where @var{non-anchored-offset} is the amount of offset given to
  3392. non-column-zero anchored lines, and @var{anchored-offset} is the amount
  3393. of offset to give column-zero anchored lines. Just an integer as value
  3394. is equivalent to @code{(@r{<value>} . -1000)}.
  3395. @workswith @code{comment-intro}.
  3396. @findex c-lineup-runin-statements
  3397. @findex lineup-runin-statements (c-)
  3398. @item c-lineup-runin-statements
  3399. Line up statements for coding standards which place the first statement
  3400. in a block on the same line as the block opening brace@footnote{Run-in
  3401. style doesn't really work too well. You might need to write your own
  3402. custom indentation functions to better support this style.}. E.g:
  3403. @example
  3404. @group
  3405. int main()
  3406. @{ puts (\"Hello world!\");
  3407. return 0; // c-lineup-runin-statements
  3408. @}
  3409. @end group
  3410. @end example
  3411. If there is no statement after the opening brace to align with,
  3412. @code{nil} is returned. This makes the function usable in list
  3413. expressions.
  3414. @workswith The @code{statement} syntactic symbol.
  3415. @findex c-lineup-math
  3416. @findex lineup-math (c-)
  3417. @item c-lineup-math
  3418. Line up the current line after the equal sign on the first line in the
  3419. statement. If there isn't any, indent with @code{c-basic-offset}. If
  3420. the current line contains an equal sign too, try to align it with the
  3421. first one.
  3422. @workswith @code{statement-cont}.
  3423. @findex c-lineup-template-args
  3424. @findex lineup-template-args (c-)
  3425. @item c-lineup-template-args
  3426. Line up the arguments of a template argument list under each other, but
  3427. only in the case where the first argument is on the same line as the
  3428. opening @samp{<}.
  3429. To allow this function to be used in a list expression, @code{nil} is
  3430. returned if there's no template argument on the first line.
  3431. @workswith @code{template-args-cont}.
  3432. @findex c-lineup-ObjC-method-call
  3433. @findex lineup-ObjC-method-call (c-)
  3434. @item c-lineup-ObjC-method-call
  3435. For Objective-C code, line up selector args as @code{elisp-mode} does
  3436. with function args: go to the position right after the message receiver,
  3437. and if you are at the end of the line, indent the current line
  3438. c-basic-offset columns from the opening bracket; otherwise you are
  3439. looking at the first character of the first method call argument, so
  3440. lineup the current line with it.
  3441. @workswith @code{objc-method-call-cont}.
  3442. @findex c-lineup-ObjC-method-args
  3443. @findex lineup-ObjC-method-args (c-)
  3444. @item c-lineup-ObjC-method-args
  3445. For Objective-C code, line up the colons that separate args. The colon
  3446. on the current line is aligned with the one on the first line.
  3447. @workswith @code{objc-method-args-cont}.
  3448. @findex c-lineup-ObjC-method-args-2
  3449. @findex lineup-ObjC-method-args-2 (c-)
  3450. @item c-lineup-ObjC-method-args-2
  3451. Similar to @code{c-lineup-ObjC-method-args} but lines up the colon on
  3452. the current line with the colon on the previous line.
  3453. @workswith @code{objc-method-args-cont}.
  3454. @findex c-lineup-inexpr-block
  3455. @findex lineup-inexpr-block (c-)
  3456. @item c-lineup-inexpr-block
  3457. This can be used with the in-expression block symbols to indent the
  3458. whole block to the column where the construct is started. E.g. for Java
  3459. anonymous classes, this lines up the class under the @samp{new} keyword,
  3460. and in Pike it lines up the lambda function body under the @samp{lambda}
  3461. keyword. Returns @code{nil} if the block isn't part of such a
  3462. construct.
  3463. @workswith @code{inlambda}, @code{inexpr-statement},
  3464. @code{inexpr-class}.
  3465. @findex c-lineup-whitesmith-in-block
  3466. @findex lineup-whitesmith-in-block (c-)
  3467. @item c-lineup-whitesmith-in-block
  3468. Line up lines inside a block in Whitesmith style. It's done in a way
  3469. that works both when the opening brace hangs and when it doesn't. E.g:
  3470. @example
  3471. @group
  3472. something
  3473. @{
  3474. foo; // c-lineup-whitesmith-in-block
  3475. @}
  3476. @end group
  3477. @end example
  3478. @noindent
  3479. and
  3480. @example
  3481. @group
  3482. something @{
  3483. foo; // c-lineup-whitesmith-in-block
  3484. @}
  3485. <--> c-basic-offset
  3486. @end group
  3487. @end example
  3488. In the first case the indentation is kept unchanged, in the second
  3489. @code{c-basic-offset} is added.
  3490. @workswith @code{defun-close}, @code{defun-block-intro},
  3491. @code{block-close}, @code{brace-list-close}, @code{brace-list-intro},
  3492. @code{statement-block-intro}, @code{inclass}, @code{inextern-lang},
  3493. @code{innamespace}.
  3494. @findex c-lineup-dont-change
  3495. @findex lineup-dont-change (c-)
  3496. @item c-lineup-dont-change
  3497. This lineup function makes the line stay at whatever indentation it
  3498. already has; think of it as an identity function for lineups. It is
  3499. used for @code{cpp-macro-cont} lines.
  3500. @workswith Any syntactic symbol.
  3501. @end table
  3502. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3503. @node Performance Issues, Limitations and Known Bugs, Indentation Functions, Top
  3504. @comment node-name, next, previous, up
  3505. @chapter Performance Issues
  3506. @cindex performance issues
  3507. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3508. C and its derivative languages are highly complex creatures. Often,
  3509. ambiguous code situations arise that require @ccmode{} to scan
  3510. large portions of the buffer to determine syntactic context. Such
  3511. pathological code@footnote{such as the output of @code{lex(1)}!}
  3512. can cause @ccmode{} to perform fairly badly.
  3513. This section identifies some of the coding styles to watch out for, and
  3514. suggests some workarounds that you can use to improve performance.
  3515. Because @ccmode{} has to scan the buffer backwards from the current
  3516. insertion point, and because C's syntax is fairly difficult to parse in
  3517. the backwards direction, @ccmode{} often tries to find the nearest
  3518. position higher up in the buffer from which to begin a forward scan.
  3519. The farther this position is from the current insertion point, the
  3520. slower the mode gets. Some coding styles can even force @ccmode{}
  3521. to scan from the beginning of the buffer for every line of code!
  3522. @findex beginning-of-defun
  3523. @findex defun-prompt-regexp
  3524. One of the simplest things you can do to reduce scan time, is make sure
  3525. any brace that opens a top-level construct@footnote{E.g. a function in
  3526. C, or outermost class definition in C++ or Java.} always appears in the
  3527. leftmost column. This is actually an Emacs constraint, as embodied in
  3528. the @code{beginning-of-defun} function which @ccmode{} uses heavily. If
  3529. you insist on hanging top-level open braces on the right side of the
  3530. line, then you might want to set the variable @code{defun-prompt-regexp}
  3531. to something reasonable, however that ``something reasonable'' is
  3532. difficult to define, so @ccmode{} doesn't do it for you.
  3533. @vindex c-Java-defun-prompt-regexp
  3534. @vindex Java-defun-prompt-regexp (c-)
  3535. A special note about @code{defun-prompt-regexp} in Java mode: while much
  3536. of the early sample Java code seems to encourage a style where the brace
  3537. that opens a class is hung on the right side of the line, this is not a
  3538. good style to pursue in Emacs. @ccmode{} comes with a variable
  3539. @code{c-Java-defun-prompt-regexp} which tries to define a regular
  3540. expression usable for this style, but there are problems with it. In
  3541. some cases it can cause @code{beginning-of-defun} to hang@footnote{This
  3542. has been observed in Emacs 19.34 and XEmacs 19.15.}. For this reason,
  3543. it is not used by default, but if you feel adventurous, you can set
  3544. @code{defun-prompt-regexp} to it in your mode hook. In any event,
  3545. setting and rely on @code{defun-prompt-regexp} will definitely slow
  3546. things down anyway because you'll be doing regular expression searches
  3547. for every line you indent, so you're probably screwed either way!
  3548. @vindex c-enable-xemacs-performance-kludge-p
  3549. @vindex enable-xemacs-performance-kludge-p (c-)
  3550. Another alternative for XEmacs users, is to set the variable
  3551. @code{c-enable-xemacs-performance-kludge-p} to non-@code{nil}. This
  3552. tells @ccmode{} to use XEmacs-specific built-in functions which, in some
  3553. circumstances, can locate the top-most opening brace much quicker than
  3554. @code{beginning-of-defun}. Preliminary testing has shown that for
  3555. styles where these braces are hung (e.g. most JDK-derived Java styles),
  3556. this hack can improve performance of the core syntax parsing routines
  3557. from 3 to 60 times. However, for styles which @emph{do} conform to
  3558. Emacs' recommended style of putting top-level braces in column zero,
  3559. this hack can degrade performance by about as much. Thus this variable
  3560. is set to @code{nil} by default, since the Emacs-friendly styles
  3561. should be more common (and
  3562. encouraged!). Note that this variable has no effect in Emacs since the
  3563. necessary built-in functions don't exist (in Emacs 20.2 or 20.3 as of
  3564. this writing 27-Apr-1998).
  3565. You will probably notice pathological behavior from @ccmode{} when
  3566. working in files containing large amounts of C preprocessor macros.
  3567. This is because Emacs cannot skip backwards over these lines as quickly
  3568. as it can comments.
  3569. @vindex c-recognize-knr-p
  3570. @vindex recognize-knr-p (c-)
  3571. Previous versions of @ccmode{} had potential performance problems
  3572. when recognizing K&R style function argument declarations. This was
  3573. because there are ambiguities in the C syntax when K&R style argument
  3574. lists are used@footnote{It is hard to distinguish them from top-level
  3575. declarations.}. @ccmode{} has adopted BOCM's convention for
  3576. limiting the search: it assumes that argdecls are indented at least one
  3577. space, and that the function headers are not indented at all. With
  3578. current versions of @ccmode{}, user customization of
  3579. @code{c-recognize-knr-p} is deprecated. Just don't put argdecls in
  3580. column zero!
  3581. @cindex @file{cc-lobotomy.el} file
  3582. @vindex cc-lobotomy-pith-list
  3583. You might want to investigate the speed-ups contained in the
  3584. file @file{cc-lobotomy.el}, which comes as part of the @ccmode{}
  3585. distribution, but is completely unsupported.
  3586. As mentioned previous, @ccmode{} always trades speed for accuracy,
  3587. however it is recognized that sometimes you need speed and can sacrifice
  3588. some accuracy in indentation. The file @file{cc-lobotomy.el} contains
  3589. hacks that will ``dumb down'' @ccmode{} in some specific ways, making
  3590. that trade-off of accurancy for speed. I won't go into details of its
  3591. use here; you should read the comments at the top of the file, and look
  3592. at the variable @code{cc-lobotomy-pith-list} for details.
  3593. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3594. @node Limitations and Known Bugs, Frequently Asked Questions, Performance Issues, Top
  3595. @comment node-name, next, previous, up
  3596. @chapter Limitations and Known Bugs
  3597. @cindex limitations
  3598. @cindex bugs
  3599. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3600. @itemize @bullet
  3601. @item
  3602. Re-indenting large regions or expressions can be slow.
  3603. @findex c-indent-exp
  3604. @findex indent-exp (c-)
  3605. @item
  3606. @code{c-indent-exp} has not been fully optimized. It essentially
  3607. equivalent to hitting @kbd{TAB} (@code{c-indent-command}) on every
  3608. line. Some information is cached from line to line, but such caching
  3609. invariable causes inaccuracies in analysis in some bizarre situations.
  3610. @vindex signal-error-on-buffer-boundary
  3611. @item
  3612. XEmacs versions from 19.15 until (as of this writing 12-Mar-1998) 20.4
  3613. contain a variable called @code{signal-error-on-buffer-boundary}. This
  3614. was intended as a solution to user interface problems associated with
  3615. buffer movement and the @code{zmacs-region} deactivation on errors.
  3616. However, setting this variable to a non-default value had the
  3617. deleterious side effect of breaking many built-in primitive functions.
  3618. Most users will not be affected since they never change the value of
  3619. this variable. @strong{Do not set this variable to @code{nil}}; you
  3620. will cause serious problems in @ccmode{} and probably other XEmacs
  3621. packages! As of at least XEmacs 20.4, the effects this variable tried
  3622. to correct have been fixed in other, better ways.
  3623. @end itemize
  3624. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3625. @node Frequently Asked Questions, Getting the Latest CC Mode Release, Limitations and Known Bugs, Top
  3626. @comment node-name, next, previous, up
  3627. @appendix Frequently Asked Questions
  3628. @cindex frequently asked questions
  3629. @cindex FAQ
  3630. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3631. @kindex C-x h
  3632. @kindex C-M-\
  3633. @kindex C-M-x
  3634. @kindex C-M-q
  3635. @kindex C-M-u
  3636. @kindex RET
  3637. @kindex C-j
  3638. @quotation
  3639. @strong{Q.} @emph{How do I re-indent the whole file?}
  3640. @strong{A.} Visit the file and hit @kbd{C-x h} to mark the whole
  3641. buffer. Then hit @kbd{C-M-\}.
  3642. @sp 1
  3643. @strong{Q.} @emph{How do I re-indent the entire function?
  3644. @kbd{C-M-x} doesn't work.}
  3645. @strong{A.} @kbd{C-M-x} is reserved for future Emacs use.
  3646. To re-indent the entire function hit @kbd{C-c C-q}.
  3647. @sp 1
  3648. @strong{Q.} @emph{How do I re-indent the current block?}
  3649. @strong{A.} First move to the brace which opens the block with
  3650. @kbd{C-M-u}, then re-indent that expression with
  3651. @kbd{C-M-q}.
  3652. @sp 1
  3653. @strong{Q.} @emph{Why doesn't the @kbd{RET} key indent the new line?}
  3654. @strong{A.} Emacs' convention is that @kbd{RET} just adds a newline,
  3655. and that @kbd{C-j} adds a newline and indents it. You can make
  3656. @kbd{RET} do this too by adding this to your
  3657. @code{c-mode-common-hook}:
  3658. @example
  3659. (define-key c-mode-base-map "\C-m" 'c-context-line-break)
  3660. @end example
  3661. This is a very common question. If you want this to be the default
  3662. behavior, don't lobby me, lobby RMS! @t{:-)}
  3663. @sp 1
  3664. @strong{Q.} @emph{I put @code{(c-set-offset 'substatement-open 0)}
  3665. in my @file{.emacs} file but I get an error saying that
  3666. @code{c-set-offset}'s function definition is void.}
  3667. @strong{A.} This means that @ccmode{} wasn't loaded into your
  3668. Emacs session by the time the @code{c-set-offset} call was reached,
  3669. most likely because @ccmode{} is being autoloaded. Instead
  3670. of putting the @code{c-set-offset} line in your top-level
  3671. @file{.emacs} file, put it in your @code{c-mode-common-hook}, or
  3672. simply modify @code{c-offsets-alist} directly:
  3673. @example
  3674. (setq c-offsets-alist '((substatement-open . 0)))
  3675. @end example
  3676. @sp 1
  3677. @strong{Q.} @emph{How do I make strings, comments, keywords, and other
  3678. constructs appear in different colors, or in bold face, etc.?}
  3679. @strong{A.} ``Syntax Colorization'' is a standard Emacs feature,
  3680. controlled by @code{font-lock-mode}. @ccmode{} does not contain
  3681. font-lock definitions for any of its supported languages.
  3682. @sp 1
  3683. @strong{Q.} @emph{@kbd{M-a} and @kbd{M-e} used to move over entire
  3684. balanced brace lists, but now they move into blocks. How do I get the
  3685. old behavior back?}
  3686. @strong{A.} Use @kbd{C-M-f} and @kbd{C-M-b} to move over balanced brace
  3687. blocks. Use @kbd{M-a} and @kbd{M-e} to move by statements, which will
  3688. also move into blocks.
  3689. @sp 1
  3690. @strong{Q.} @emph{Whenever I try to indent a line or type an
  3691. ``electric'' key such as @kbd{;}, @kbd{@{}, or @kbd{@}}, I get an error
  3692. that look like this: @code{Invalid function: (macro . #[...}. What
  3693. gives?}
  3694. @strong{A.} This is a common error when @ccmode{} hasn't been compiled
  3695. correctly, especially under Emacs 19.34@footnote{Technically, it's
  3696. because some macros wasn't defined during the compilation, so the byte
  3697. compiler put in function calls instead of the macro expansions. Later,
  3698. when the interpreter tries to call the macros as functions, it shows
  3699. this (somewhat cryptic) error message.}. If you are using the standalone
  3700. @ccmode{} distribution, try recompiling it according to the instructions
  3701. in the @file{README} file.
  3702. @end quotation
  3703. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3704. @node Getting the Latest CC Mode Release, Mailing Lists and Submitting Bug Reports, Frequently Asked Questions, Top
  3705. @comment node-name, next, previous, up
  3706. @appendix Getting the Latest CC Mode Release
  3707. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3708. @ccmode{} is standard with all versions of Emacs since 19.34 and of
  3709. XEmacs since 19.16.
  3710. Due to release schedule skew, it is likely that all of these Emacsen
  3711. have old versions of @ccmode{} and so should be upgraded. Access to the
  3712. @ccmode{} source code, as well as more detailed information on Emacsen
  3713. compatibility, etc. are all available via the Web at:
  3714. @example
  3715. @group
  3716. @uref{http://cc-mode.sourceforge.net/}
  3717. @end group
  3718. @end example
  3719. @emph{Old URLs, including the FTP URLs, should no longer be used.}
  3720. There are many files under these directories; you can pick up the entire
  3721. distribution (named @code{cc-mode.tar.gz}; a gzip'd tar file), or any of
  3722. the individual files, including PostScript documentation.
  3723. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3724. @node Mailing Lists and Submitting Bug Reports, Sample .emacs File, Getting the Latest CC Mode Release, Top
  3725. @comment node-name, next, previous, up
  3726. @appendix Mailing Lists and Submitting Bug Reports
  3727. @cindex mailing lists
  3728. @cindex reporting bugs
  3729. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3730. @kindex C-c C-b
  3731. @findex c-submit-bug-report
  3732. @findex submit-bug-report (c-)
  3733. To report bugs, use the @kbd{C-c C-b} (@code{c-submit-bug-report})
  3734. command. This provides vital information we need to reproduce your
  3735. problem. Make sure you include a concise, but complete code example.
  3736. Please try to boil your example down to just the essential code needed
  3737. to reproduce the problem, and include an exact recipe of steps needed to
  3738. expose the bug. Be especially sure to include any code that appears
  3739. @emph{before} your bug example, if you think it might affect our ability
  3740. to reproduce it.
  3741. Please try to produce the problem in an Emacs instance without any
  3742. customizations loaded (i.e. start it with the @code{-q -no-site-file}
  3743. arguments). If it works correctly there, the problem might be caused by
  3744. faulty customizations in either your own or your site configuration. In
  3745. that case, we'd appreciate if you isolate the Emacs Lisp code that trigs
  3746. the bug and include it in your report.
  3747. @cindex bug report mailing list
  3748. Bug reports are now sent to the following email addresses:
  3749. @email{bug-cc-mode@@gnu.org} and @email{bug-gnu-emacs@@gnu.org}; the
  3750. latter is mirrored on the Usenet newsgroup @code{gnu.emacs.bug}. You
  3751. can send other questions and suggestions (kudos? @t{;-)} to
  3752. @email{bug-cc-mode@@gnu.org}.
  3753. @cindex announcement mailing list
  3754. If you want to get announcements of new @ccmode{} releases, send the
  3755. word @emph{subscribe} in the body of a message to
  3756. @email{cc-mode-announce-request@@lists.sourceforge.net}. Announcements
  3757. will also be posted to the Usenet newsgroups @code{gnu.emacs.sources},
  3758. @code{comp.emacs} and @code{comp.emacs.xemacs}.
  3759. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3760. @node Sample .emacs File, Concept Index, Mailing Lists and Submitting Bug Reports, Top
  3761. @comment node-name, next, previous, up
  3762. @appendix Sample .emacs file
  3763. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3764. @example
  3765. ;; Here's a sample .emacs file that might help you along the way. Just
  3766. ;; copy this region and paste it into your .emacs file. You may want to
  3767. ;; change some of the actual values.
  3768. (defconst my-c-style
  3769. '((c-tab-always-indent . t)
  3770. (c-comment-only-line-offset . 4)
  3771. (c-hanging-braces-alist . ((substatement-open after)
  3772. (brace-list-open)))
  3773. (c-hanging-colons-alist . ((member-init-intro before)
  3774. (inher-intro)
  3775. (case-label after)
  3776. (label after)
  3777. (access-label after)))
  3778. (c-cleanup-list . (scope-operator
  3779. empty-defun-braces
  3780. defun-close-semi))
  3781. (c-offsets-alist . ((arglist-close . c-lineup-arglist)
  3782. (substatement-open . 0)
  3783. (case-label . 4)
  3784. (block-open . 0)
  3785. (knr-argdecl-intro . -)))
  3786. (c-echo-syntactic-information-p . t)
  3787. )
  3788. "My C Programming Style")
  3789. ;; offset customizations not in my-c-style
  3790. (setq c-offsets-alist '((member-init-intro . ++)))
  3791. ;; Customizations for all modes in CC Mode.
  3792. (defun my-c-mode-common-hook ()
  3793. ;; add my personal style and set it for the current buffer
  3794. (c-add-style "PERSONAL" my-c-style t)
  3795. ;; other customizations
  3796. (setq tab-width 8
  3797. ;; this will make sure spaces are used instead of tabs
  3798. indent-tabs-mode nil)
  3799. ;; we like auto-newline and hungry-delete
  3800. (c-toggle-auto-hungry-state 1)
  3801. ;; key bindings for all supported languages. We can put these in
  3802. ;; c-mode-base-map because c-mode-map, c++-mode-map, objc-mode-map,
  3803. ;; java-mode-map, idl-mode-map, and pike-mode-map inherit from it.
  3804. (define-key c-mode-base-map "\C-m" 'c-context-line-break)
  3805. )
  3806. (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
  3807. @end example
  3808. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3809. @node Concept Index, Command Index, Sample .emacs File, Top
  3810. @comment node-name, next, previous, up
  3811. @unnumbered Concept Index
  3812. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3813. @printindex cp
  3814. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3815. @node Command Index, Key Index, Concept Index, Top
  3816. @comment node-name, next, previous, up
  3817. @unnumbered Command Index
  3818. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3819. Since most @ccmode{} commands are prepended with the string
  3820. @samp{c-}, each appears under its @code{c-@var{<thing>}} name and its
  3821. @code{@var{<thing>} (c-)} name.
  3822. @iftex
  3823. @sp 2
  3824. @end iftex
  3825. @printindex fn
  3826. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3827. @node Key Index, Variable Index, Command Index, Top
  3828. @comment node-name, next, previous, up
  3829. @unnumbered Key Index
  3830. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3831. @printindex ky
  3832. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3833. @node Variable Index, , Key Index, Top
  3834. @comment node-name, next, previous, up
  3835. @unnumbered Variable Index
  3836. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3837. Since most @ccmode{} variables are prepended with the string
  3838. @samp{c-}, each appears under its @code{c-@var{<thing>}} name and its
  3839. @code{@var{<thing>} (c-)} name.
  3840. @iftex
  3841. @sp 2
  3842. @end iftex
  3843. @printindex vr
  3844. @iftex
  3845. @page
  3846. @summarycontents
  3847. @contents
  3848. @end iftex
  3849. @bye