cc-mode.texi 271 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467
  1. \input texinfo
  2. @c Notes to self regarding line handling:
  3. @c
  4. @c Empty lines are often significant before @end directives; avoid them.
  5. @c
  6. @c Empty lines before and after @example directives are significant in
  7. @c info output but not in TeX. Empty lines inside @example directives
  8. @c are significant.
  9. @c Conventions for formatting examples:
  10. @c o If the example contains empty lines then put the surrounding empty
  11. @c lines inside the @example directives. Put them outside otherwise.
  12. @c o Use @group inside the example only if it shows indentation where
  13. @c the relation between lines inside is relevant.
  14. @c o Format line number columns like this:
  15. @c 1: foo
  16. @c 2: bar
  17. @c ^ one space
  18. @c ^^ two columns, right alignment
  19. @c o Check line lengths in TeX output; they can typically be no longer
  20. @c than 70 chars, 60 if the paragraph is indented.
  21. @comment TBD: Document the finer details of statement anchoring?
  22. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  23. @comment %**start of header (This is for running Texinfo on a region)
  24. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  25. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  26. @comment How to make the various output formats:
  27. @comment (Thanks to Robert Chassell for supplying this information.)
  28. @comment Note that Texinfo 4.7 (or later) is needed.
  29. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  30. @ignore
  31. In each of the following pairs of commands, the first generates a
  32. version with cross references pointing to the GNU Emacs manuals,
  33. the second with them pointing to the XEmacs manuals.
  34. ## Info output
  35. makeinfo cc-mode.texi
  36. makeinfo -DXEMACS cc-mode.texi
  37. ## DVI output
  38. ## You may need to set up the environment variable TEXINPUTS so
  39. ## that tex can find the file texinfo.tex - See the tex
  40. ## manpage.
  41. texi2dvi cc-mode.texi
  42. texi2dvi -t "@set XEMACS " cc-mode.texi
  43. ## HTML output. (The --no-split parameter is optional)
  44. makeinfo --html --no-split cc-mode.texi
  45. makeinfo --html --no-split -DXEMACS cc-mode.texi
  46. ## Plain text output
  47. makeinfo --fill-column=70 --no-split --paragraph-indent=0 \
  48. --no-headers --output=cc-mode.txt cc-mode.texi
  49. makeinfo --fill-column=70 --no-split --paragraph-indent=0 \
  50. --no-headers --output=cc-mode.txt -DXEMACS cc-mode.texi
  51. ## DocBook output
  52. makeinfo --docbook --no-split --paragraph-indent=0 \
  53. cc-mode.texi
  54. makeinfo --docbook --no-split --paragraph-indent=0 \
  55. -DXEMACS cc-mode.texi
  56. ## XML output
  57. makeinfo --xml --no-split --paragraph-indent=0 \
  58. cc-mode.texi
  59. makeinfo --xml --no-split --paragraph-indent=0 \
  60. -DXEMACS cc-mode.texi
  61. #### (You must be in the same directory as the viewed file.)
  62. ## View DVI output
  63. xdvi cc-mode.dvi &
  64. ## View HTML output
  65. mozilla cc-mode.html
  66. @end ignore
  67. @comment No overfull hbox marks in the dvi file.
  68. @finalout
  69. @setfilename ../../info/ccmode.info
  70. @settitle CC Mode Manual
  71. @include docstyle.texi
  72. @footnotestyle end
  73. @c The following four macros generate the filenames and titles of the
  74. @c main (X)Emacs manual and the Elisp/Lispref manual. Leave the
  75. @c Texinfo variable 'XEMACS' unset to generate a GNU Emacs version, set it
  76. @c to generate an XEmacs version, e.g., with
  77. @c "makeinfo -DXEMACS cc-mode.texi".
  78. @ifset XEMACS
  79. @macro emacsman
  80. xemacs
  81. @end macro
  82. @macro emacsmantitle
  83. XEmacs User's Manual
  84. @end macro
  85. @macro lispref
  86. lispref
  87. @end macro
  88. @macro lispreftitle
  89. XEmacs Lisp Reference Manual
  90. @end macro
  91. @end ifset
  92. @ifclear XEMACS
  93. @macro emacsman
  94. emacs
  95. @end macro
  96. @macro emacsmantitle
  97. GNU Emacs Manual
  98. @end macro
  99. @macro lispref
  100. elisp
  101. @end macro
  102. @macro lispreftitle
  103. GNU Emacs Lisp Reference Manual
  104. @end macro
  105. @end ifclear
  106. @macro ccmode
  107. CC Mode
  108. @end macro
  109. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  110. @comment @setchapternewpage odd !! we don't want blank pages !!
  111. @comment %**end of header (This is for running Texinfo on a region)
  112. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  113. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  114. @comment
  115. @comment Texinfo manual for CC Mode
  116. @comment Generated from the original README file by Krishna Padmasola
  117. @comment <krishna@earth-gw.njit.edu>
  118. @comment
  119. @comment Authors:
  120. @comment Barry A. Warsaw
  121. @comment Martin Stjernholm
  122. @comment Alan Mackenzie
  123. @comment
  124. @comment Maintained by Martin Stjernholm and Alan Mackenzie <bug-cc-mode@gnu.org>
  125. @comment
  126. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  127. @comment Define an index for syntactic symbols.
  128. @defindex ss
  129. @comment Combine key, syntactic symbol and concept indices into one.
  130. @syncodeindex ss cp
  131. @syncodeindex ky cp
  132. @copying
  133. This manual is for CC Mode in Emacs.
  134. Copyright @copyright{} 1995--2017 Free Software Foundation, Inc.
  135. @quotation
  136. Permission is granted to copy, distribute and/or modify this document
  137. under the terms of the GNU Free Documentation License, Version 1.3 or
  138. any later version published by the Free Software Foundation; with no
  139. Invariant Sections, with the Front-Cover Texts being ``A GNU Manual'',
  140. and with the Back-Cover Texts as in (a) below. A copy of the license
  141. is included in the section entitled ``GNU Free Documentation License''.
  142. (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
  143. modify this GNU manual.''
  144. @end quotation
  145. @end copying
  146. @comment Info directory entry for use by install-info. The indentation
  147. @comment here is by request from the FSF folks.
  148. @dircategory Emacs editing modes
  149. @direntry
  150. * CC Mode: (ccmode). Emacs mode for editing C, C++, Objective-C,
  151. Java, Pike, AWK, and CORBA IDL code.
  152. @end direntry
  153. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  154. @comment TeX title page
  155. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  156. @titlepage
  157. @sp 10
  158. @center @titlefont{CC Mode 5.32}
  159. @sp 2
  160. @center A GNU Emacs mode for editing C and C-like languages
  161. @sp 2
  162. @center Barry A. Warsaw, Martin Stjernholm, Alan Mackenzie
  163. @page
  164. @vskip 0pt plus 1filll
  165. @insertcopying
  166. This manual was generated from cc-mode.texi, which is distributed with Emacs,
  167. or can be downloaded from @url{http://savannah.gnu.org/projects/emacs/}.
  168. @end titlepage
  169. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  170. @comment The Top node contains the master menu for the Info file.
  171. @comment This appears only in the Info file, not the printed manual.
  172. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  173. @summarycontents
  174. @contents
  175. @node Top, Introduction, (dir), (dir)
  176. @comment node-name, next, previous, up
  177. @ifnottex
  178. @top @ccmode{}
  179. @ccmode{} is a GNU Emacs mode for editing files containing C, C++,
  180. Objective-C, Java, CORBA IDL (and the variants PSDL and CIDL), Pike
  181. and AWK code. It provides syntax-based indentation, font locking, and
  182. has several handy commands and some minor modes to make the editing
  183. easier. It does not provide tools to look up and navigate between
  184. functions, classes, etc.; there are other packages for that.
  185. @insertcopying
  186. @end ifnottex
  187. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  188. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  189. @menu
  190. * Introduction::
  191. * Overview::
  192. * Getting Started::
  193. * Commands::
  194. * Font Locking::
  195. * Config Basics::
  196. * Custom Filling and Breaking::
  197. * Custom Auto-newlines::
  198. * Clean-ups::
  199. * Indentation Engine Basics::
  200. * Customizing Indentation::
  201. * Custom Macros::
  202. * Odds and Ends::
  203. * Sample Init File::
  204. * Performance Issues::
  205. * Limitations and Known Bugs::
  206. * FAQ::
  207. * Updating CC Mode::
  208. * Mailing Lists and Bug Reports::
  209. * GNU Free Documentation License::
  210. * Command and Function Index::
  211. * Variable Index::
  212. * Concept and Key Index::
  213. @detailmenu
  214. --- The Detailed Node Listing ---
  215. Commands
  216. * Indentation Commands::
  217. * Comment Commands::
  218. * Movement Commands::
  219. * Filling and Breaking::
  220. * Minor Modes::
  221. * Electric Keys::
  222. * Auto-newlines::
  223. * Hungry WS Deletion::
  224. * Subword Movement::
  225. * Other Commands::
  226. Font Locking
  227. * Font Locking Preliminaries::
  228. * Faces::
  229. * Doc Comments::
  230. * Misc Font Locking::
  231. * AWK Mode Font Locking::
  232. Configuration Basics
  233. * CC Hooks::
  234. * Style Variables::
  235. * Styles::
  236. Styles
  237. * Built-in Styles::
  238. * Choosing a Style::
  239. * Adding Styles::
  240. * Guessing the Style::
  241. * File Styles::
  242. Customizing Auto-newlines
  243. * Hanging Braces::
  244. * Hanging Colons::
  245. * Hanging Semicolons and Commas::
  246. Hanging Braces
  247. * Custom Braces::
  248. Indentation Engine Basics
  249. * Syntactic Analysis::
  250. * Syntactic Symbols::
  251. * Indentation Calculation::
  252. Syntactic Symbols
  253. * Function Symbols::
  254. * Class Symbols::
  255. * Conditional Construct Symbols::
  256. * Switch Statement Symbols::
  257. * Brace List Symbols::
  258. * External Scope Symbols::
  259. * Paren List Symbols::
  260. * Literal Symbols::
  261. * Multiline Macro Symbols::
  262. * Objective-C Method Symbols::
  263. * Java Symbols::
  264. * Statement Block Symbols::
  265. * K&R Symbols::
  266. Customizing Indentation
  267. * c-offsets-alist::
  268. * Interactive Customization::
  269. * Line-Up Functions::
  270. * Custom Line-Up::
  271. * Other Indentation::
  272. Line-Up Functions
  273. * Brace/Paren Line-Up::
  274. * List Line-Up::
  275. * Operator Line-Up::
  276. * Comment Line-Up::
  277. * Misc Line-Up::
  278. Customizing Macros
  279. * Macro Backslashes::
  280. * Macros with ;::
  281. * Noise Macros::
  282. @end detailmenu
  283. @end menu
  284. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  285. @node Introduction, Overview, Top, Top
  286. @comment node-name, next, previous, up
  287. @chapter Introduction
  288. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  289. @cindex BOCM
  290. @cindex history
  291. @cindex awk-mode.el
  292. @cindex c-mode.el
  293. @cindex c++-mode.el
  294. Welcome to @ccmode{}, a GNU Emacs mode for editing files containing C,
  295. C++, Objective-C, Java, CORBA IDL (and the variants CORBA PSDL and
  296. CIDL), Pike and AWK code. This incarnation of the mode is descended
  297. from @file{c-mode.el} (also called ``Boring Old C Mode'' or BOCM
  298. @t{:-)}, @file{c++-mode.el} version 2, which Barry Warsaw had been
  299. maintaining since 1992, and @file{awk-mode.el}, a long neglected mode
  300. in the (X)Emacs base.
  301. Late in 1997, Martin Stjernholm joined Barry on the @ccmode{}
  302. Maintainers Team, and implemented the Pike support. In 2000 Martin
  303. took over as the sole maintainer. In 2001 Alan Mackenzie joined the
  304. team, implementing AWK support in version 5.30. @ccmode{} did not
  305. originally contain the font lock support for its languages; that
  306. was added in version 5.30.
  307. This manual describes @ccmode{}
  308. @comment The following line must appear on its own, so that the
  309. version 5.32.
  310. @comment Release.py script can update the version number automatically
  311. @ccmode{} supports the editing of C, C++, Objective-C,
  312. Java, CORBA's Interface Definition Language, Pike@footnote{A C-like
  313. scripting language with its roots in the LPC language used in some MUD
  314. engines. See @uref{http://pike.ida.liu.se/}.} and AWK files. In this
  315. way, you can easily set up consistent font locking and coding styles for
  316. use in editing all of these languages, although AWK is not yet as
  317. uniformly integrated as the other languages.
  318. @findex c-mode
  319. @findex c++-mode
  320. @findex objc-mode
  321. @findex java-mode
  322. @findex idl-mode
  323. @findex pike-mode
  324. @findex awk-mode
  325. Note that the name of this package is ``@ccmode{}'', but there is no top
  326. level @code{cc-mode} entry point. All of the variables, commands, and
  327. functions in @ccmode{} are prefixed with @code{c-@var{thing}}, and
  328. @code{c-mode}, @code{c++-mode}, @code{objc-mode}, @code{java-mode},
  329. @code{idl-mode}, @code{pike-mode}, and @code{awk-mode} entry points are
  330. provided. This package is intended to be a replacement for
  331. @file{c-mode.el}, @file{c++-mode.el} and @file{awk-mode.el}.
  332. A special word of thanks goes to Krishna Padmasola for his work in
  333. converting the original @file{README} file to Texinfo format. I'd
  334. also like to thank all the @ccmode{} victims who help enormously
  335. during the early beta stages of @ccmode{}'s development.
  336. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  337. @node Overview, Getting Started, Introduction, Top
  338. @comment node-name, next, previous, up@cindex organization of the manual
  339. @chapter Overview of the Manual
  340. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  341. @noindent
  342. The manual starts with several introductory chapters (including this
  343. one).
  344. @noindent
  345. The next chunk of the manual describes the day to day @emph{use} of
  346. @ccmode{} (as contrasted with how to customize it).
  347. @itemize @bullet
  348. @item
  349. The chapter ``Commands'' describes in detail how to use (nearly) all
  350. of @ccmode{}'s features. There are extensive cross-references from
  351. here to the corresponding sections later in the manual which tell you
  352. how to customize these features.
  353. @item
  354. ``Font Locking'' describes how ``syntax highlighting'' is applied to
  355. your buffers. It is mainly background information and can be skipped
  356. over at a first reading.
  357. @end itemize
  358. @noindent
  359. The next chunk of the manual describes how to @emph{customize}
  360. @ccmode{}. Typically, an overview of a topic is given at the chapter
  361. level, then the sections and subsections describe the material in
  362. increasing detail.
  363. @itemize @bullet
  364. @item
  365. The chapter ``Configuration Basics'' tells you @emph{how} to write
  366. customizations: whether in hooks, in styles, in both, or in neither,
  367. depending on your needs. It describes the @ccmode{} style system and
  368. lists the standard styles that @ccmode{} supplies.
  369. @item
  370. The next few chapters describe in detail how to customize the various
  371. features of @ccmode{}.
  372. @item
  373. Finally, there is a sample @file{.emacs} fragment, which might help you
  374. in creating your own customization.
  375. @end itemize
  376. @noindent
  377. The manual ends with ``this and that'', things that don't fit cleanly
  378. into any of the previous chunks.
  379. @itemize @bullet
  380. @item
  381. Two chapters discuss the performance of @ccmode{} and known
  382. bugs/limitations.
  383. @item
  384. The FAQ contains a list of common problems and questions.
  385. @item
  386. The next two chapters tell you how to get in touch with the @ccmode{}
  387. project: whether for updating @ccmode{} or submitting bug reports.
  388. @end itemize
  389. @noindent
  390. Finally, there are the customary indices.
  391. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  392. @node Getting Started, Commands, Overview, Top
  393. @comment node-name, next, previous, up
  394. @chapter Getting Started
  395. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  396. If you got this version of @ccmode{} with Emacs or XEmacs, it should
  397. work just fine right out of the box. Note however that you might not
  398. have the latest @ccmode{} release and might want to upgrade your copy
  399. (see below).
  400. You should probably start by skimming through the entire Commands chapter
  401. (@pxref{Commands}) to get an overview of @ccmode{}'s capabilities.
  402. After trying out some commands, you may dislike some aspects of
  403. @ccmode{}'s default configuration. Here is an outline of how to
  404. change some of the settings that newcomers to @ccmode{} most often
  405. want to change:
  406. @table @asis
  407. @item c-basic-offset
  408. This Lisp variable holds an integer, the number of columns @ccmode{}
  409. indents nested code. To set this value to 6, customize
  410. @code{c-basic-offset} or put this into your @file{.emacs}:
  411. @example
  412. (setq c-basic-offset 6)
  413. @end example
  414. @item The (indentation) style
  415. The basic ``shape'' of indentation created by @ccmode{}---by default,
  416. this is @code{gnu} style (except for Java and AWK buffers). A list of
  417. the available styles and their descriptions can be found in
  418. @ref{Built-in Styles}. A complete specification of the @ccmode{}
  419. style system, including how to create your own style, can be found in
  420. the chapter @ref{Styles}. To set your style to @code{linux}, either
  421. customize @code{c-default-style} or put this into your @file{.emacs}:
  422. @example
  423. (setq c-default-style '((java-mode . "java")
  424. (awk-mode . "awk")
  425. (other . "linux")))
  426. @end example
  427. @item Electric Indentation
  428. Normally, when you type ``punctuation'' characters such as @samp{;} or
  429. @samp{@{}, @ccmode{} instantly reindents the current line. This can
  430. be disconcerting until you get used to it. To disable @dfn{electric
  431. indentation} in the current buffer, type @kbd{C-c C-l}. Type the same
  432. thing to enable it again. To have electric indentation disabled by
  433. default, put the following into your @file{.emacs} file@footnote{There
  434. is no ``easy customization'' facility for making this change.}:
  435. @example
  436. (setq-default c-electric-flag nil)
  437. @end example
  438. @noindent
  439. Details of this and other similar ``Minor Modes'' appear in the
  440. section @ref{Minor Modes}.
  441. @item Making the @key{RET} key indent the new line
  442. The standard Emacs binding for @key{RET} just adds a new line. If you
  443. want it to reindent the new line as well, rebind the key. Note that
  444. the action of rebinding would fail if the pertinent keymap didn't yet
  445. exist---we thus need to delay the action until after @ccmode{} has
  446. been loaded. Put the following code into your @file{.emacs}:
  447. @example
  448. (defun my-make-CR-do-indent ()
  449. (define-key c-mode-base-map "\C-m" 'c-context-line-break))
  450. (add-hook 'c-initialization-hook 'my-make-CR-do-indent)
  451. @end example
  452. @noindent
  453. This example demonstrates the use of a very powerful @ccmode{} (and
  454. Emacs) facility, the hook. The use of @ccmode{}'s hooks is described
  455. in @ref{CC Hooks}.
  456. @end table
  457. All these settings should occur in your @file{.emacs} @emph{before}
  458. any @ccmode{} buffers get loaded---in particular, before any call of
  459. @code{desktop-read}.
  460. As you get to know the mode better, you may want to make more
  461. ambitious changes to your configuration. For this, you should start
  462. reading the chapter @ref{Config Basics}.
  463. If you are upgrading an existing @ccmode{} installation, please see
  464. the @file{README} file for installation details. In particular, if
  465. you are going to be editing AWK files, @file{README} describes how to
  466. configure your (X)Emacs so that @ccmode{} will supersede the obsolete
  467. @code{awk-mode.el} which might have been supplied with your (X)Emacs.
  468. @ccmode{} might not work with older versions of Emacs or XEmacs. See
  469. the @ccmode{} release notes at @uref{http://cc-mode.sourceforge.net}
  470. for the latest information on Emacs version and package compatibility
  471. (@pxref{Updating CC Mode}).
  472. @deffn Command c-version
  473. @findex version (c-)
  474. You can find out what version of @ccmode{} you are using by visiting a C
  475. file and entering @kbd{M-x c-version RET}. You should see this message in
  476. the echo area:
  477. @example
  478. Using CC Mode version 5.XX
  479. @end example
  480. @noindent
  481. where @samp{XX} is the minor release number.
  482. @end deffn
  483. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  484. @node Commands, Font Locking, Getting Started, Top
  485. @comment node-name, next, previous, up
  486. @chapter Commands
  487. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  488. This chapter specifies all of CC Mode's commands, and thus contains
  489. nearly everything you need to know to @emph{use} @ccmode{} (as
  490. contrasted with configuring it). @dfn{Commands} here means both
  491. control key sequences and @dfn{electric keys}, these being characters
  492. such as @samp{;} which, as well as inserting themselves into the
  493. buffer, also do other things.
  494. You might well want to review
  495. @ifset XEMACS
  496. @ref{Lists,,,@emacsman{}, @emacsmantitle{}},
  497. @end ifset
  498. @ifclear XEMACS
  499. @ref{Moving by Parens,,,@emacsman{}, @emacsmantitle{}},
  500. @end ifclear
  501. which describes commands for moving around brace and parenthesis
  502. structures.
  503. @menu
  504. * Indentation Commands::
  505. * Comment Commands::
  506. * Movement Commands::
  507. * Filling and Breaking::
  508. * Minor Modes::
  509. * Electric Keys::
  510. * Auto-newlines::
  511. * Hungry WS Deletion::
  512. * Subword Movement::
  513. * Other Commands::
  514. @end menu
  515. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  516. @node Indentation Commands, Comment Commands, Commands, Commands
  517. @comment node-name, next, previous,up
  518. @section Indentation Commands
  519. @cindex indentation
  520. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  521. The following commands reindent C constructs. Note that when you
  522. change your coding style, either interactively or through some other
  523. means, your file does @emph{not} automatically get reindented. You
  524. will need to execute one of the following commands to see the effects
  525. of your changes.
  526. @cindex GNU indent program
  527. Also, variables like @code{c-hanging-*} and @code{c-cleanup-list}
  528. (@pxref{Custom Auto-newlines}) only affect how on-the-fly code is
  529. formatted. Changing the ``hanginess'' of a brace and then
  530. reindenting, will not move the brace to a different line. For this,
  531. you're better off getting an external program like GNU @code{indent},
  532. which will rearrange brace location, amongst other things.
  533. Preprocessor directives are handled as syntactic whitespace from other
  534. code, i.e., they can be interspersed anywhere without affecting the
  535. indentation of the surrounding code, just like comments.
  536. The code inside macro definitions is, by default, still analyzed
  537. syntactically so that you get relative indentation there just as you'd
  538. get if the same code was outside a macro. However, since there is no
  539. hint about the syntactic context, i.e., whether the macro expands to an
  540. expression, to some statements, or perhaps to whole functions, the
  541. syntactic recognition can be wrong. @ccmode{} manages to figure it
  542. out correctly most of the time, though.
  543. Some macros, when invoked, ''have their own semicolon''. To get the
  544. next line indented correctly, rather than as a continuation line,
  545. @xref{Macros with ;}.
  546. Reindenting large sections of code can take a long time. When
  547. @ccmode{} reindents a region of code, it is essentially equivalent to
  548. hitting @key{TAB} on every line of the region.
  549. These commands indent code:
  550. @table @asis
  551. @item @kbd{@key{TAB}} (@code{c-indent-command})
  552. @kindex TAB
  553. @findex c-indent-command
  554. @findex indent-command (c-)
  555. This command indents the current line. That is all you need to know
  556. about it for normal use.
  557. @code{c-indent-command} does different things, depending on the
  558. setting of @code{c-syntactic-indentation} (@pxref{Indentation Engine
  559. Basics}):
  560. @itemize @bullet
  561. @item
  562. When it's non-@code{nil} (which it normally is), the command indents
  563. the line according to its syntactic context. With a prefix argument
  564. (@kbd{C-u @key{TAB}}), it will re-indent the entire
  565. expression@footnote{this is only useful for a line starting with a
  566. comment opener or an opening brace, parenthesis, or string quote.}
  567. that begins at the line's left margin.
  568. @item
  569. When it's @code{nil}, the command indents the line by an extra
  570. @code{c-basic-offset} columns. A prefix argument acts as a
  571. multiplier. A bare prefix (@kbd{C-u @key{TAB}}) is equivalent to -1,
  572. removing @code{c-basic-offset} columns from the indentation.
  573. @end itemize
  574. The precise behavior is modified by several variables: With
  575. @code{c-tab-always-indent}, you can make @key{TAB} insert whitespace
  576. in some circumstances---@code{c-insert-tab-function} then defines
  577. precisely what sort of ``whitespace'' this will be. Set the standard
  578. Emacs variable @code{indent-tabs-mode} to @code{t} if you want real
  579. @samp{tab} characters to be used in the indentation, to @code{nil} if
  580. you want only spaces. @xref{Just Spaces,,,@emacsman{},
  581. @emacsmantitle{}}.
  582. @defopt c-tab-always-indent
  583. @vindex tab-always-indent (c-)
  584. @cindex literal
  585. This variable modifies how @key{TAB} operates.
  586. @itemize @bullet
  587. @item
  588. When it is @code{t} (the default), @key{TAB} simply indents the
  589. current line.
  590. @item
  591. When it is @code{nil}, @key{TAB} (re)indents the line only if point is
  592. to the left of the first non-whitespace character on the line.
  593. Otherwise it inserts some whitespace (a tab or an equivalent number of
  594. spaces; see below) at point.
  595. @item
  596. With some other value, the line is reindented. Additionally, if point
  597. is within a string or comment, some whitespace is inserted.
  598. @end itemize
  599. @end defopt
  600. @defopt c-insert-tab-function
  601. @vindex insert-tab-function (c-)
  602. @findex tab-to-tab-stop
  603. When ``some whitespace'' is inserted as described above, what actually
  604. happens is that the function stored in @code{c-insert-tab-function} is
  605. called. Normally, this is @code{insert-tab}, which inserts a real tab
  606. character or the equivalent number of spaces (depending on
  607. @code{indent-tabs-mode}). Some people, however, set
  608. @code{c-insert-tab-function} to @code{tab-to-tab-stop} so as to get
  609. hard tab stops when indenting.
  610. @end defopt
  611. @end table
  612. @noindent
  613. The kind of indentation the next five commands do depends on the
  614. setting of @code{c-syntactic-indentation} (@pxref{Indentation Engine
  615. Basics}):
  616. @itemize @bullet
  617. @item
  618. when it is non-@code{nil} (the default), the commands indent lines
  619. according to their syntactic context;
  620. @item
  621. when it is @code{nil}, they just indent each line the same amount as
  622. the previous non-blank line. The commands that indent a region aren't
  623. very useful in this case.
  624. @end itemize
  625. @table @asis
  626. @item @kbd{C-M-q} (@code{c-indent-exp})
  627. @kindex C-M-q
  628. @findex c-indent-exp
  629. @findex indent-exp (c-)
  630. Indents an entire balanced brace or parenthesis expression. Note that
  631. point must be on the opening brace or parenthesis of the expression
  632. you want to indent.
  633. @item @kbd{C-c C-q} (@code{c-indent-defun})
  634. @kindex C-c C-q
  635. @findex c-indent-defun
  636. @findex indent-defun (c-)
  637. Indents the entire top-level function, class or macro definition
  638. encompassing point. It leaves point unchanged. This function can't be
  639. used to reindent a nested brace construct, such as a nested class or
  640. function, or a Java method. The top-level construct being reindented
  641. must be complete, i.e., it must have both a beginning brace and an ending
  642. brace.
  643. @item @kbd{C-M-\} (@code{indent-region})
  644. @kindex C-M-\
  645. @findex indent-region
  646. Indents an arbitrary region of code. This is a standard Emacs command,
  647. tailored for C code in a @ccmode{} buffer. Note, of course, that point
  648. and mark must delineate the region you want to indent.
  649. @item @kbd{C-M-h} (@code{c-mark-function})
  650. @kindex C-M-h
  651. @findex c-mark-function
  652. @findex mark-function (c-)
  653. While not strictly an indentation command, this is useful for marking
  654. the current top-level function or class definition as the current
  655. region. As with @code{c-indent-defun}, this command operates on
  656. top-level constructs, and can't be used to mark say, a Java method.
  657. @end table
  658. These variables are also useful when indenting code:
  659. @defopt indent-tabs-mode
  660. This is a standard Emacs variable that controls how line indentation
  661. is composed. When it's non-@code{nil}, tabs can be used in a line's
  662. indentation, otherwise only spaces are used.
  663. @end defopt
  664. @defopt c-progress-interval
  665. @vindex progress-interval (c-)
  666. When indenting large regions of code, this variable controls how often a
  667. progress message is displayed. Set this variable to @code{nil} to
  668. inhibit the progress messages, or set it to an integer which is how
  669. often (in seconds) progress messages are to be displayed.
  670. @end defopt
  671. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  672. @node Comment Commands, Movement Commands, Indentation Commands, Commands
  673. @comment node-name, next, previous, up
  674. @section Comment Commands
  675. @cindex comments (insertion of)
  676. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  677. When the commands in this section add comment delimiters, they use
  678. either line comments or block comments depending on the setting of the
  679. comment style (@pxref{Minor Modes}).
  680. @table @asis
  681. @item @kbd{C-c C-c} (@code{comment-region})
  682. @kindex C-c C-c
  683. @findex comment-region
  684. This command comments out the lines that start in the region. With a
  685. negative argument, it does the opposite: it deletes the comment
  686. delimiters from these lines. @xref{Multi-Line Comments,,, emacs, GNU
  687. Emacs Manual}, for fuller details. @code{comment-region} isn't
  688. actually part of @ccmode{}; it is given a @ccmode{} binding for
  689. convenience.
  690. @item @kbd{M-;} (@code{comment-dwim} or @code{indent-for-comment} @footnote{The name of this command varies between (X)Emacs versions.})
  691. @kindex M-;
  692. @findex comment-dwim
  693. @findex indent-for-comment
  694. Insert a comment at the end of the current line, if none is there
  695. already. Then reindent the comment according to @code{comment-column}
  696. @ifclear XEMACS
  697. (@pxref{Options for Comments,,, emacs, GNU Emacs Manual})
  698. @end ifclear
  699. @ifset XEMACS
  700. (@pxref{Comments,,, xemacs, XEmacs User's Manual})
  701. @end ifset
  702. and the variables below. Finally, position the point after the
  703. comment starter. @kbd{C-u M-;} kills any comment on the current line,
  704. together with any whitespace before it. This is a standard Emacs
  705. command, but @ccmode{} enhances it a bit with two variables:
  706. @defopt c-indent-comment-alist
  707. @vindex indent-comment-alist (c-)
  708. @vindex comment-column
  709. This style variable allows you to vary the column that @kbd{M-;} puts
  710. the comment at, depending on what sort of code is on the line, and
  711. possibly the indentation of any similar comment on the preceding line.
  712. It is an association list that maps different types of lines to
  713. actions describing how they should be handled. If a certain line type
  714. isn't present on the list then the line is indented to the column
  715. specified by @code{comment-column}.
  716. See the documentation string for a full description of this
  717. variable (use @kbd{C-h v c-indent-comment-alist}).
  718. @end defopt
  719. @defopt c-indent-comments-syntactically-p
  720. @vindex indent-comments-syntactically-p (c-)
  721. Normally, when this style variable is @code{nil}, @kbd{M-;} will
  722. indent comment-only lines according to @code{c-indent-comment-alist},
  723. just as it does with lines where other code precede the comments.
  724. However, if you want it to act just like @key{TAB} for comment-only
  725. lines you can get that by setting
  726. @code{c-indent-comments-syntactically-p} to non-@code{nil}.
  727. If @code{c-indent-comments-syntactically-p} is non-@code{nil} then
  728. @code{c-indent-comment-alist} won't be consulted at all for comment-only
  729. lines.
  730. @end defopt
  731. @end table
  732. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  733. @node Movement Commands, Filling and Breaking, Comment Commands, Commands
  734. @comment node-name, next, previous, up
  735. @section Movement Commands
  736. @cindex movement
  737. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  738. @ccmode{} contains some useful commands for moving around in C code.
  739. @table @asis
  740. @item @kbd{C-M-a} (@code{c-beginning-of-defun})
  741. @itemx @kbd{C-M-e} (@code{c-end-of-defun})
  742. @findex c-beginning-of-defun
  743. @findex c-end-of-defun
  744. @vindex c-defun-tactic
  745. @vindex defun-tactic (c-)
  746. Move to the beginning or end of the current or next function. Other
  747. constructs (such as a structs or classes) which have a brace block
  748. also count as ``functions'' here. To move over several functions, you
  749. can give these commands a repeat count.
  750. The start of a function is at its header. The end of the function is
  751. after its closing brace, or after the semicolon of a construct (such
  752. as a @code{struct}) which doesn't end at the brace. These two
  753. commands try to leave point at the beginning of a line near the actual
  754. start or end of the function. This occasionally causes point not to
  755. move at all.
  756. By default, these commands will recognize functions contained within a
  757. @dfn{declaration scope} such as a C++ @code{class} or @code{namespace}
  758. construct, should the point start inside it. If @ccmode fails to find
  759. function beginnings or ends inside the current declaration scope, it
  760. will search the enclosing scopes. If you want @ccmode to recognize
  761. functions only at the top level@footnote{this was @ccmode{}'s
  762. behavior prior to version 5.32.}, set @code{c-defun-tactic} to
  763. @code{t}.
  764. These functions are analogous to the Emacs built-in commands
  765. @code{beginning-of-defun} and @code{end-of-defun}, except they
  766. eliminate the constraint that the top-level opening brace of the defun
  767. must be in column zero. See @ref{Defuns,,,@emacsman{},
  768. @emacsmantitle{}}, for more information.
  769. @item @kbd{C-M-a} (AWK Mode) (@code{c-awk-beginning-of-defun})
  770. @itemx @kbd{C-M-e} (AWK Mode) (@code{c-awk-end-of-defun})
  771. @kindex C-M-a (AWK Mode)
  772. @kindex C-M-e (AWK Mode)
  773. @findex c-awk-beginning-of-defun
  774. @findex awk-beginning-of-defun (c-)
  775. @findex c-awk-end-of-defun
  776. @findex awk-end-of-defun (c-)
  777. Move to the beginning or end of the current or next AWK defun. These
  778. commands can take prefix-arguments, their functionality being entirely
  779. equivalent to @code{beginning-of-defun} and @code{end-of-defun}.
  780. AWK Mode @dfn{defuns} are either pattern/action pairs (either of which
  781. might be implicit) or user defined functions. Having the @samp{@{} and
  782. @samp{@}} (if there are any) in column zero, as is suggested for some
  783. modes, is neither necessary nor helpful in AWK mode.
  784. @item @kbd{M-a} (@code{c-beginning-of-statement})
  785. @itemx @kbd{M-e} (@code{c-end-of-statement})
  786. @kindex M-a
  787. @kindex M-e
  788. @findex c-beginning-of-statement
  789. @findex c-end-of-statement
  790. @findex beginning-of-statement (c-)
  791. @findex end-of-statement (c-)
  792. Move to the beginning or end of the innermost C statement. If point
  793. is already there, move to the next beginning or end of a statement,
  794. even if that means moving into a block. (Use @kbd{C-M-b} or
  795. @kbd{C-M-f} to move over a balanced block.) A prefix argument @var{n}
  796. means move over @var{n} statements.
  797. If point is within or next to a comment or a string which spans more
  798. than one line, these commands move by sentences instead of statements.
  799. When called from a program, these functions take three optional
  800. arguments: the repetition count, a buffer position limit which is the
  801. farthest back to search for the syntactic context, and a flag saying
  802. whether to do sentence motion in or near comments and multiline
  803. strings.
  804. @item @kbd{C-c C-u} (@code{c-up-conditional})
  805. @kindex C-c C-u
  806. @findex c-up-conditional
  807. @findex up-conditional (c-)
  808. Move back to the containing preprocessor conditional, leaving the mark
  809. behind. A prefix argument acts as a repeat count. With a negative
  810. argument, move forward to the end of the containing preprocessor
  811. conditional.
  812. @samp{#elif} is treated like @samp{#else} followed by @samp{#if}, so the
  813. function stops at them when going backward, but not when going
  814. forward.
  815. This key sequence is not bound in AWK Mode, which doesn't have
  816. preprocessor statements.
  817. @item @kbd{M-x c-up-conditional-with-else}
  818. @findex c-up-conditional-with-else
  819. @findex up-conditional-with-else (c-)
  820. A variety of @code{c-up-conditional} that also stops at @samp{#else}
  821. lines. Normally those lines are ignored.
  822. @item @kbd{M-x c-down-conditional}
  823. @findex c-down-conditional
  824. @findex down-conditional (c-)
  825. Move forward into the next nested preprocessor conditional, leaving
  826. the mark behind. A prefix argument acts as a repeat count. With a
  827. negative argument, move backward into the previous nested preprocessor
  828. conditional.
  829. @samp{#elif} is treated like @samp{#else} followed by @samp{#if}, so the
  830. function stops at them when going forward, but not when going backward.
  831. @item @kbd{M-x c-down-conditional-with-else}
  832. @findex c-down-conditional-with-else
  833. @findex down-conditional-with-else (c-)
  834. A variety of @code{c-down-conditional} that also stops at @samp{#else}
  835. lines. Normally those lines are ignored.
  836. @item @kbd{C-c C-p} (@code{c-backward-conditional})
  837. @itemx @kbd{C-c C-n} (@code{c-forward-conditional})
  838. @kindex C-c C-p
  839. @kindex C-c C-n
  840. @findex c-backward-conditional
  841. @findex c-forward-conditional
  842. @findex backward-conditional (c-)
  843. @findex forward-conditional (c-)
  844. Move backward or forward across a preprocessor conditional, leaving
  845. the mark behind. A prefix argument acts as a repeat count. With a
  846. negative argument, move in the opposite direction.
  847. These key sequences are not bound in AWK Mode, which doesn't have
  848. preprocessor statements.
  849. @item @kbd{M-x c-backward-into-nomenclature}
  850. @itemx @kbd{M-x c-forward-into-nomenclature}
  851. @findex c-backward-into-nomenclature
  852. @findex c-forward-into-nomenclature
  853. @findex backward-into-nomenclature (c-)
  854. @findex forward-into-nomenclature (c-)
  855. A popular programming style, especially for object-oriented languages
  856. such as C++ is to write symbols in a mixed case format, where the
  857. first letter of each word is capitalized, and not separated by
  858. underscores. E.g., @samp{SymbolsWithMixedCaseAndNoUnderlines}.
  859. These commands move backward or forward to the beginning of the next
  860. capitalized word. With prefix argument @var{n}, move @var{n} times.
  861. If @var{n} is negative, move in the opposite direction.
  862. Note that these two commands have been superseded by
  863. @code{subword-mode}, which you should use instead. @xref{Subword
  864. Movement}. They might be removed from a future release of @ccmode{}.
  865. @end table
  866. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  867. @node Filling and Breaking, Minor Modes, Movement Commands, Commands
  868. @comment node-name, next, previous, up
  869. @section Filling and Line Breaking Commands
  870. @cindex text filling
  871. @cindex line breaking
  872. @cindex comment handling
  873. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  874. Since there's a lot of normal text in comments and string literals,
  875. @ccmode{} provides features to edit these like in text mode. The goal
  876. is to do it seamlessly, i.e., you can use auto fill mode, sentence and
  877. paragraph movement, paragraph filling, adaptive filling etc.@: wherever
  878. there's a piece of normal text without having to think much about it.
  879. @ccmode{} keeps the indentation, fixes suitable comment line prefixes,
  880. and so on.
  881. You can configure the exact way comments get filled and broken, and
  882. where Emacs does auto-filling (see @pxref{Custom Filling and
  883. Breaking}). Typically, the style system (@pxref{Styles}) will have
  884. set this up for you, so you probably won't have to bother.
  885. @findex auto-fill-mode
  886. @cindex Auto Fill mode
  887. @cindex paragraph filling
  888. Line breaks are by default handled (almost) the same regardless of
  889. whether they are made by auto fill mode (@pxref{Auto
  890. Fill,,,@emacsman{}, @emacsmantitle{}}), by paragraph filling (e.g., with
  891. @kbd{M-q}), or explicitly with @kbd{M-j} or similar methods. In
  892. string literals, the new line gets the same indentation as the
  893. previous nonempty line.@footnote{You can change this default by
  894. setting the @code{string} syntactic symbol (@pxref{Syntactic Symbols}
  895. and @pxref{Customizing Indentation})}.
  896. @table @asis
  897. @item @kbd{M-q} (@code{c-fill-paragraph})
  898. @kindex M-q
  899. @findex c-fill-paragraph
  900. @findex fill-paragraph (c-)
  901. @cindex Javadoc markup
  902. @cindex Pike autodoc markup
  903. This command fills multiline string literals and both block
  904. and line style comments. In Java buffers, the Javadoc markup words
  905. are recognized as paragraph starters. The line oriented Pike autodoc
  906. markup words are recognized in the same way in Pike mode.
  907. The formatting of the starters (@code{/*}) and enders (@code{*/}) of
  908. block comments are kept as they were before the filling. I.e., if
  909. either the starter or ender were on a line of its own, then it stays
  910. on its own line; conversely, if the delimiter has comment text on its
  911. line, it keeps at least one word of that text with it on the line.
  912. This command is the replacement for @code{fill-paragraph} in @ccmode{}
  913. buffers.
  914. @item @kbd{M-j} (@code{c-indent-new-comment-line})
  915. @kindex M-j
  916. @findex c-indent-new-comment-line
  917. @findex indent-new-comment-line (c-)
  918. This breaks the current line at point and indents the new line. If
  919. point was in a comment, the new line gets the proper comment line
  920. prefix. If point was inside a macro, a backslash is inserted before
  921. the line break. It is the replacement for
  922. @code{indent-new-comment-line}.
  923. @item @kbd{M-x c-context-line-break}
  924. @findex c-context-line-break
  925. @findex context-line-break (c-)
  926. Insert a line break suitable to the context: If the point is inside a
  927. comment, the new line gets the suitable indentation and comment line
  928. prefix like @code{c-indent-new-comment-line}. In normal code it's
  929. indented like @code{newline-and-indent} would do. In macros it acts
  930. like @code{newline-and-indent} but additionally inserts and optionally
  931. aligns the line ending backslash so that the macro remains unbroken.
  932. @xref{Custom Macros}, for details about the backslash alignment. In a
  933. string, a backslash is inserted only if the string is within a
  934. macro@footnote{In GCC, unescaped line breaks within strings are
  935. valid.}.
  936. This function is not bound to a key by default, but it's intended to be
  937. used on the @kbd{RET} key. If you like the behavior of
  938. @code{newline-and-indent} on @kbd{RET}, you should consider switching to
  939. this function. @xref{Sample Init File}.
  940. @item @kbd{M-x c-context-open-line}
  941. @findex c-context-open-line
  942. @findex context-open-line (c-)
  943. This is to @kbd{C-o} (@kbd{M-x open-line}) as
  944. @code{c-context-line-break} is to @kbd{RET}. I.e., it works just like
  945. @code{c-context-line-break} but leaves the point before the inserted
  946. line break.
  947. @end table
  948. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  949. @node Minor Modes, Electric Keys, Filling and Breaking, Commands
  950. @comment node-name, next, previous, up
  951. @section Minor Modes
  952. @cindex Minor Modes
  953. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  954. @ccmode{} contains several minor-mode-like features that you might
  955. find useful while writing new code or editing old code:
  956. @table @asis
  957. @item comment style
  958. This specifies whether comment commands (such as @kbd{M-;}) insert
  959. block comments or line comments.
  960. @item electric mode
  961. When this is enabled, certain visible characters cause reformatting as
  962. they are typed. This is normally helpful, but can be a nuisance when
  963. editing chaotically formatted code. It can also be disconcerting,
  964. especially for users who are new to @ccmode{}.
  965. @item auto-newline mode
  966. This automatically inserts newlines where you'd probably want to type
  967. them yourself, e.g., after typing @samp{@}}s. Its action is suppressed
  968. when electric mode is disabled.
  969. @item hungry-delete mode
  970. This lets you delete a contiguous block of whitespace with a single
  971. key: for example, the newline and indentation just inserted by
  972. auto-newline when you want to back up and write a comment after the
  973. last statement.
  974. @item subword mode
  975. This mode makes basic word movement commands like @kbd{M-f}
  976. (@code{forward-word}) and @kbd{M-b} (@code{backward-word}) treat the
  977. parts of sillycapsed symbols as different words.
  978. E.g., @samp{NSGraphicsContext} is treated as three words @samp{NS},
  979. @samp{Graphics}, and @samp{Context}.
  980. @item syntactic-indentation mode
  981. When this is enabled (which it normally is), indentation commands such
  982. as @kbd{C-j} indent lines of code according to their syntactic
  983. structure. Otherwise, a line is simply indented to the same level as
  984. the previous one and @kbd{@key{TAB}} adjusts the indentation in steps
  985. of @code{c-basic-offset}.
  986. @end table
  987. Full details on how these minor modes work are at @ref{Electric Keys},
  988. @ref{Auto-newlines}, @ref{Hungry WS Deletion}, @ref{Subword Movement},
  989. and @ref{Indentation Engine Basics}.
  990. You can toggle each of these minor modes on and off, and you can
  991. configure @ccmode{} so that it starts up with your favorite
  992. combination of them (@pxref{Sample Init File}). By default, when
  993. you initialize a buffer, the comment style is set to the default for
  994. the major mode, electric mode and syntactic-indentation mode are
  995. enabled, but the other three modes are disabled.
  996. @ccmode{} displays the current state of the first five of these minor
  997. modes on the mode line by appending characters to the major mode's
  998. name: @samp{/} or @samp{*} to indicate the comment style (respectively
  999. line or block), and one letter for each of the other minor modes which
  1000. is enabled - @samp{l} for electric mode, @samp{a} for auto-newline
  1001. mode, @samp{h} for hungry delete mode, and @samp{w} for subword mode.
  1002. If the comment style was block and all the other modes were enabled,
  1003. you'd see @samp{C/*lahw}@footnote{The @samp{C} would be replaced with
  1004. the name of the language in question for the other languages @ccmode{}
  1005. supports.}.
  1006. Here are the commands to toggle these modes:
  1007. @table @asis
  1008. @item @kbd{C-c C-k} (@code{c-toggle-comment-style})
  1009. @kindex C-c C-k
  1010. @findex c-toggle-comment-style
  1011. @findex toggle-comment-style (c-)
  1012. Toggle the comment style between line style and block style. In modes
  1013. (such as AWK Mode) which only have one of these styles, this function
  1014. does nothing.
  1015. @item @kbd{C-c C-l} (@code{c-toggle-electric-state})
  1016. @kindex C-c C-l
  1017. @findex c-toggle-electric-state
  1018. @findex toggle-electric-state (c-)
  1019. Toggle electric minor mode. When the command turns the mode off, it
  1020. also suppresses auto-newline mode.
  1021. @item @kbd{C-c C-a} (@code{c-toggle-auto-newline})
  1022. @kindex C-c C-a
  1023. @findex c-toggle-auto-newline
  1024. @findex toggle-auto-newline (c-)
  1025. Toggle auto-newline minor mode. When the command turns the mode on,
  1026. it also enables electric minor mode.
  1027. @item @kbd{M-x c-toggle-hungry-state}@footnote{Prior to @ccmode{} 5.31, this command was bound to @kbd{C-c C-d}.}
  1028. @findex c-toggle-hungry-state
  1029. @findex toggle-hungry-state (c-)
  1030. Toggle hungry-delete minor mode.
  1031. @item @kbd{M-x c-toggle-auto-hungry-state}@footnote{Prior to @ccmode{} 5.31, this command was bound to @kbd{C-c C-t}.}
  1032. @findex c-toggle-auto-hungry-state
  1033. @findex toggle-auto-hungry-state (c-)
  1034. Toggle both auto-newline and hungry delete minor modes.
  1035. @item @kbd{C-c C-w} (@code{M-x subword-mode})
  1036. @kindex C-c C-w
  1037. @findex subword-mode
  1038. Toggle subword mode.
  1039. @item @kbd{M-x c-toggle-syntactic-indentation}
  1040. @findex c-toggle-syntactic-indentation
  1041. @findex toggle-syntactic-indentation (c-)
  1042. Toggle syntactic-indentation mode.
  1043. @end table
  1044. Common to all the toggle functions above is that if they are called
  1045. programmatically, they take an optional numerical argument. For
  1046. @code{c-toggle-comment style}, a positive value will select block
  1047. comments, a negative value will select line comments. For the other
  1048. functions, a positive value will turn on the minor mode (or both of
  1049. them in the case of @code{c-toggle-auto-hungry-state}) and a negative
  1050. value will turn it (or them) off.
  1051. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1052. @node Electric Keys, Auto-newlines, Minor Modes, Commands
  1053. @comment node-name, next, previous, up
  1054. @section Electric Keys and Keywords
  1055. @cindex electric characters
  1056. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1057. Most punctuation keys provide @dfn{electric} behavior: as well as
  1058. inserting themselves they perform some other action, such as
  1059. reindenting the line. This reindentation saves you from having to
  1060. reindent a line manually after typing, say, a @samp{@}}. A few
  1061. keywords, such as @code{else}, also trigger electric action.
  1062. You can inhibit the electric behavior described here by disabling
  1063. electric minor mode (@pxref{Minor Modes}).
  1064. Common to all these keys is that they only behave electrically when
  1065. used in normal code (as contrasted with getting typed in a string
  1066. literal or comment). Those which cause re-indentation do so only when
  1067. @code{c-syntactic-indentation} has a non-@code{nil} value (which it
  1068. does by default).
  1069. These keys and keywords are:
  1070. @c ACM, 2004/8/24: c-electric-pound doesn't check c-s-i: this is more
  1071. @c like a bug in the code than a bug in this document. It'll get
  1072. @c fixed in the code sometime.
  1073. @table @kbd
  1074. @item #
  1075. @kindex #
  1076. @findex c-electric-pound
  1077. @findex electric-pound (c-)
  1078. @vindex c-electric-pound-behavior
  1079. @vindex electric-pound-behavior (c-)
  1080. Pound (bound to @code{c-electric-pound}) is electric when typed as the
  1081. first non-whitespace character on a line and not within a macro
  1082. definition. In this case, the variable @code{c-electric-pound-behavior}
  1083. is consulted for the electric behavior. This variable takes a list
  1084. value, although the only element currently defined is @code{alignleft},
  1085. which tells this command to force the @samp{#} character into column
  1086. zero. This is useful for entering preprocessor macro definitions.
  1087. Pound is not electric in AWK buffers, where @samp{#} starts a comment,
  1088. and is bound to @code{self-insert-command} like any typical printable
  1089. character.
  1090. @c ACM, 2004/8/24: Change this (and the code) to do AWK comment
  1091. @c reindentation.
  1092. @item *
  1093. @kindex *
  1094. @itemx /
  1095. @kindex /
  1096. @findex c-electric-star
  1097. @findex electric-star (c-)
  1098. @findex c-electric-slash
  1099. @findex electric-slash (c-)
  1100. A star (bound to @code{c-electric-star}) or a slash
  1101. (@code{c-electric-slash}) causes reindentation when you type it as the
  1102. second component of a C style block comment opener (@samp{/*}) or a
  1103. C++ line comment opener (@samp{//}) respectively, but only if the
  1104. comment opener is the first thing on the line (i.e., there's only
  1105. whitespace before it).
  1106. Additionally, you can configure @ccmode{} so that typing a slash at
  1107. the start of a line within a block comment will terminate the
  1108. comment. You don't need to have electric minor mode enabled to get
  1109. this behavior. @xref{Clean-ups}.
  1110. In AWK mode, @samp{*} and @samp{/} do not delimit comments and are not
  1111. electric.
  1112. @item <
  1113. @kindex <
  1114. @itemx >
  1115. @kindex >
  1116. @findex c-electric-lt-gt
  1117. @findex electric-lt-gt (c-)
  1118. A less-than or greater-than sign (bound to @code{c-electric-lt-gt}) is
  1119. electric in two circumstances: when it is an angle bracket in a C++
  1120. @samp{template} declaration (and similar constructs in other
  1121. languages) and when it is the second of two @kbd{<} or @kbd{>}
  1122. characters in a C++ style stream operator. In either case, the line
  1123. is reindented. Angle brackets in C @samp{#include} directives are not
  1124. electric.
  1125. @item (
  1126. @kindex (
  1127. @itemx )
  1128. @kindex )
  1129. @findex c-electric-paren
  1130. @findex electric-paren (c-)
  1131. The normal parenthesis characters @samp{(} and @samp{)} (bound to
  1132. @code{c-electric-paren}) reindent the current line. This is useful
  1133. for getting the closing parenthesis of an argument list aligned
  1134. automatically.
  1135. You can also configure @ccmode{} to insert a space automatically
  1136. between a function name and the @samp{(} you've just typed, and to
  1137. remove it automatically after typing @samp{)}, should the argument
  1138. list be empty. You don't need to have electric minor mode enabled to
  1139. get these actions. @xref{Clean-ups}.
  1140. @item @{
  1141. @kindex @{
  1142. @itemx @}
  1143. @kindex @}
  1144. @findex c-electric-brace
  1145. @findex electric-brace (c-)
  1146. Typing a brace (bound to @code{c-electric-brace}) reindents the
  1147. current line. Also, one or more newlines might be inserted if
  1148. auto-newline minor mode is enabled. @xref{Auto-newlines}.
  1149. Additionally, you can configure @ccmode{} to compact excess whitespace
  1150. inserted by auto-newline mode in certain circumstances.
  1151. @xref{Clean-ups}.
  1152. @item :
  1153. @kindex :
  1154. @findex c-electric-colon
  1155. @findex electric-colon (c-)
  1156. Typing a colon (bound to @code{c-electric-colon}) reindents the
  1157. current line. Additionally, one or more newlines might be inserted if
  1158. auto-newline minor mode is enabled. @xref{Auto-newlines}. If you
  1159. type a second colon immediately after such an auto-newline, by default
  1160. the whitespace between the two colons is removed, leaving a C++ scope
  1161. operator. @xref{Clean-ups}.
  1162. If you prefer, you can insert @samp{::} in a single operation,
  1163. avoiding all these spurious reindentations, newlines, and clean-ups.
  1164. @xref{Other Commands}.
  1165. @item ;
  1166. @kindex ;
  1167. @itemx ,
  1168. @kindex ,
  1169. @findex c-electric-semi&comma
  1170. @findex electric-semi&comma (c-)
  1171. Typing a semicolon or comma (bound to @code{c-electric-semi&comma})
  1172. reindents the current line. Also, a newline might be inserted if
  1173. auto-newline minor mode is enabled. @xref{Auto-newlines}.
  1174. Additionally, you can configure @ccmode{} so that when auto-newline
  1175. has inserted whitespace after a @samp{@}}, it will be removed again
  1176. when you type a semicolon or comma just after it. @xref{Clean-ups}.
  1177. @end table
  1178. @deffn Command c-electric-continued-statement
  1179. @findex electric-continued-statement (c-)
  1180. Certain keywords are electric, causing reindentation when they are
  1181. preceded only by whitespace on the line. The keywords are those that
  1182. continue an earlier statement instead of starting a new one:
  1183. @code{else}, @code{while}, @code{catch} (only in C++ and Java) and
  1184. @code{finally} (only in Java).
  1185. An example:
  1186. @example
  1187. @group
  1188. for (i = 0; i < 17; i++)
  1189. if (a[i])
  1190. res += a[i]->offset;
  1191. else
  1192. @end group
  1193. @end example
  1194. Here, the @code{else} should be indented like the preceding @code{if},
  1195. since it continues that statement. @ccmode{} will automatically
  1196. reindent it after the @code{else} has been typed in full, since only
  1197. then is it possible to decide whether it's a new statement or a
  1198. continuation of the preceding @code{if}.
  1199. @vindex abbrev-mode
  1200. @findex abbrev-mode
  1201. @cindex Abbrev mode
  1202. @ccmode{} uses Abbrev mode (@pxref{Abbrevs,,,@emacsman{}, @emacsmantitle{}})
  1203. to accomplish this. It's therefore turned on by default in all language
  1204. modes except IDL mode, since CORBA IDL doesn't have any statements.
  1205. @end deffn
  1206. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1207. @node Auto-newlines, Hungry WS Deletion, Electric Keys, Commands
  1208. @comment node-name, next, previous, up
  1209. @section Auto-newline Insertion
  1210. @cindex auto-newline
  1211. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1212. When you have @dfn{Auto-newline minor mode} enabled (@pxref{Minor
  1213. Modes}), @ccmode{} inserts newlines for you automatically (in certain
  1214. syntactic contexts) when you type a left or right brace, a colon, a
  1215. semicolon, or a comma. Sometimes a newline appears before the
  1216. character you type, sometimes after it, sometimes both.
  1217. Auto-newline only triggers when the following conditions hold:
  1218. @itemize @bullet
  1219. @item
  1220. Auto-newline minor mode is enabled, as evidenced by the indicator
  1221. @samp{a} after the mode name on the modeline (e.g., @samp{C/a} or
  1222. @samp{C/la}).
  1223. @item
  1224. The character was typed at the end of a line, or with only whitespace
  1225. after it, and possibly a @samp{\} escaping the newline.
  1226. @item
  1227. The character is not on its own line already. (This applies only to
  1228. insertion of a newline @emph{before} the character.)
  1229. @item
  1230. @cindex literal
  1231. @cindex syntactic whitespace
  1232. The character was not typed inside of a literal @footnote{A
  1233. @dfn{literal} is defined as any comment, string, or preprocessor macro
  1234. definition. These constructs are also known as @dfn{syntactic
  1235. whitespace} since they are usually ignored when scanning C code.}.
  1236. @item
  1237. No numeric argument was supplied to the command (i.e., it was typed as
  1238. normal, with no @kbd{C-u} prefix).
  1239. @end itemize
  1240. You can configure the precise circumstances in which newlines get
  1241. inserted (see @pxref{Custom Auto-newlines}). Typically, the style
  1242. system (@pxref{Styles}) will have set this up for you, so you probably
  1243. won't have to bother.
  1244. Sometimes @ccmode{} inserts an auto-newline where you don't want one,
  1245. such as after a @samp{@}} when you're about to type a @samp{;}.
  1246. Hungry deletion can help here (@pxref{Hungry WS Deletion}), or you can
  1247. activate an appropriate @dfn{clean-up}, which will remove the excess
  1248. whitespace after you've typed the @samp{;}. See @ref{Clean-ups} for a
  1249. full description. See also @ref{Electric Keys} for a summary of
  1250. clean-ups listed by key.
  1251. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1252. @node Hungry WS Deletion, Subword Movement, Auto-newlines, Commands
  1253. @comment node-name, next, previous, up
  1254. @section Hungry Deletion of Whitespace
  1255. @cindex hungry-deletion
  1256. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1257. If you want to delete an entire block of whitespace at point, you can
  1258. use @dfn{hungry deletion}. This deletes all the contiguous whitespace
  1259. either before point or after point in a single operation.
  1260. ``Whitespace'' here includes tabs and newlines, but not comments or
  1261. preprocessor commands. Hungry deletion can markedly cut down on the
  1262. number of times you have to hit deletion keys when, for example,
  1263. you've made a mistake on the preceding line and have already pressed
  1264. @kbd{C-j}.
  1265. Hungry deletion is a simple feature that some people find extremely
  1266. useful. In fact, you might find yourself wanting it in @strong{all}
  1267. your editing modes!
  1268. Loosely speaking, in what follows, @dfn{@key{DEL}} means ``the
  1269. backspace key'' and @dfn{@key{DELETE}} means ``the forward delete
  1270. key''. This is discussed in more detail below.
  1271. There are two different ways you can use hungry deletion:
  1272. @table @asis
  1273. @item Using @dfn{Hungry Delete Mode} with @kbd{@key{DEL}} and @kbd{C-d}
  1274. Here you toggle Hungry Delete minor mode with @kbd{M-x
  1275. c-toggle-hungry-state}@footnote{Prior to @ccmode{} 5.31, this command
  1276. was bound to @kbd{C-c C-d}. @kbd{C-c C-d} is now the default binding
  1277. for @code{c-hungry-delete-forward}.} (@pxref{Minor Modes}.) This
  1278. makes @kbd{@key{DEL}} and @kbd{C-d} do backwards and forward hungry
  1279. deletion.
  1280. @table @asis
  1281. @item @kbd{@key{DEL}} (@code{c-electric-backspace})
  1282. @kindex DEL
  1283. @findex c-electric-backspace
  1284. @findex electric-backspace (c-)
  1285. This command is run by default when you hit the @kbd{DEL} key. When
  1286. hungry delete mode is enabled, it deletes any amount of whitespace in
  1287. the backwards direction. Otherwise, or when used with a prefix
  1288. argument or in a literal (@pxref{Auto-newlines}), the command just
  1289. deletes backwards in the usual way. (More precisely, it calls the
  1290. function contained in the variable @code{c-backspace-function},
  1291. passing it the prefix argument, if any.)
  1292. @item @code{c-backspace-function}
  1293. @vindex c-backspace-function
  1294. @vindex backspace-function (c-)
  1295. @findex backward-delete-char-untabify
  1296. Hook that gets called by @code{c-electric-backspace} when it doesn't
  1297. do an ``electric'' deletion of the preceding whitespace. The default
  1298. value is @code{backward-delete-char-untabify}
  1299. (@pxref{Deletion,,,@lispref{}, @lispreftitle{}}, the function which
  1300. deletes a single character.
  1301. @item @kbd{C-d} (@code{c-electric-delete-forward})
  1302. @kindex C-d
  1303. @findex c-electric-delete-forward
  1304. @findex electric-delete-forward (c-)
  1305. This function, which is bound to @kbd{C-d} by default, works just like
  1306. @code{c-electric-backspace} but in the forward direction. When it
  1307. doesn't do an ``electric'' deletion of the following whitespace, it
  1308. just does @code{delete-char}, more or less. (Strictly speaking, it
  1309. calls the function in @code{c-delete-function} with the prefix
  1310. argument.)
  1311. @item @code{c-delete-function}
  1312. @vindex c-delete-function
  1313. @vindex delete-function (c-)
  1314. @findex delete-char
  1315. Hook that gets called by @code{c-electric-delete-forward} when it
  1316. doesn't do an ``electric'' deletion of the following whitespace. The
  1317. default value is @code{delete-char}.
  1318. @end table
  1319. @item Using Distinct Bindings
  1320. The other (newer and recommended) way to use hungry deletion is to
  1321. perform @code{c-hungry-delete-backwards} and
  1322. @code{c-hungry-delete-forward} directly through their key sequences
  1323. rather than using the minor mode toggling.
  1324. @table @asis
  1325. @item @kbd{C-c C-@key{DEL}}, or @kbd{C-c @key{DEL}} (@code{c-hungry-delete-backwards})@footnote{This command was formerly known as @code{c-hungry-backspace}.}
  1326. @kindex C-c C-<backspace>
  1327. @kindex C-c <backspace>
  1328. @kindex C-c C-DEL
  1329. @kindex C-c DEL
  1330. @findex c-hungry-delete-backwards
  1331. @findex hungry-delete-backwards (c-)
  1332. Delete any amount of whitespace in the backwards direction (regardless
  1333. whether hungry-delete mode is enabled or not). This command is bound
  1334. to both @kbd{C-c C-@key{DEL}} and @kbd{C-c @key{DEL}}, since the more
  1335. natural one, @kbd{C-c C-@key{DEL}}, is sometimes difficult to type at
  1336. a character terminal.
  1337. @item @kbd{C-c C-d}, @kbd{C-c C-@key{DELETE}}, or @kbd{C-c @key{DELETE}} (@code{c-hungry-delete-forward})
  1338. @kindex C-c C-d
  1339. @kindex C-c C-<DELETE>
  1340. @kindex C-c <DELETE>
  1341. @findex c-hungry-delete-forward
  1342. @findex hungry-delete-forward (c-)
  1343. Delete any amount of whitespace in the forward direction (regardless
  1344. whether hungry-delete mode is enabled or not). This command is bound
  1345. to both @kbd{C-c C-@key{DELETE}} and @kbd{C-c @key{DELETE}} for the
  1346. same reason as for @key{DEL} above.
  1347. @end table
  1348. @end table
  1349. @kindex <delete>
  1350. @kindex <backspace>
  1351. When we talk about @kbd{@key{DEL}}, and @kbd{@key{DELETE}} above, we
  1352. actually do so without connecting them to the physical keys commonly
  1353. known as @key{Backspace} and @key{Delete}. The default bindings to
  1354. those two keys depends on the flavor of (X)Emacs you are using.
  1355. @findex c-electric-delete
  1356. @findex electric-delete (c-)
  1357. @findex c-hungry-delete
  1358. @findex hungry-delete (c-)
  1359. @vindex delete-key-deletes-forward
  1360. In XEmacs 20.3 and beyond, the @key{Backspace} key is bound to
  1361. @code{c-electric-backspace} and the @key{Delete} key is bound to
  1362. @code{c-electric-delete}. You control the direction it deletes in by
  1363. setting the variable @code{delete-key-deletes-forward}, a standard
  1364. XEmacs variable.
  1365. @c This variable is encapsulated by XEmacs's (defsubst delete-forward-p ...).
  1366. When this variable is non-@code{nil}, @code{c-electric-delete} will do
  1367. forward deletion with @code{c-electric-delete-forward}, otherwise it
  1368. does backward deletion with @code{c-electric-backspace}. Similarly,
  1369. @kbd{C-c @key{Delete}} and @kbd{C-c C-@key{Delete}} are bound to
  1370. @code{c-hungry-delete} which is controlled in the same way by
  1371. @code{delete-key-deletes-forward}.
  1372. @findex normal-erase-is-backspace-mode
  1373. Emacs 21 and later automatically binds @key{Backspace} and
  1374. @key{Delete} to @kbd{DEL} and @kbd{C-d} according to your environment,
  1375. and @ccmode{} extends those bindings to @kbd{C-c C-@key{Backspace}}
  1376. etc. If you need to change the bindings through
  1377. @code{normal-erase-is-backspace-mode} then @ccmode{} will also adapt
  1378. its extended bindings accordingly.
  1379. In earlier (X)Emacs versions, @ccmode{} doesn't bind either
  1380. @key{Backspace} or @key{Delete} directly. Only the key codes
  1381. @kbd{DEL} and @kbd{C-d} are bound, and it's up to the default bindings
  1382. to map the physical keys to them. You might need to modify this
  1383. yourself if the defaults are unsuitable.
  1384. Getting your @key{Backspace} and @key{Delete} keys properly set up can
  1385. sometimes be tricky. The information in @ref{DEL Does Not
  1386. Delete,,,emacs, GNU Emacs Manual}, might be helpful if you're having
  1387. trouble with this in GNU Emacs.
  1388. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1389. @node Subword Movement, Other Commands, Hungry WS Deletion, Commands
  1390. @comment node-name, next, previous, up
  1391. @section Subword Movement and Editing
  1392. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1393. @cindex nomenclature
  1394. @cindex subword
  1395. In spite of the GNU Coding Standards, it is popular to name a symbol
  1396. by mixing uppercase and lowercase letters, e.g., @samp{GtkWidget},
  1397. @samp{EmacsFrameClass}, or @samp{NSGraphicsContext}. Here we call
  1398. these mixed case symbols @dfn{nomenclatures}. Also, each capitalized
  1399. (or completely uppercase) part of a nomenclature is called a
  1400. @dfn{subword}. Here are some examples:
  1401. @multitable {@samp{NSGraphicsContext}} {@samp{NS}, @samp{Graphics}, and @samp{Context}}
  1402. @c This could be converted to @headitem when we require Texinfo 4.7
  1403. @iftex
  1404. @item @b{Nomenclature}
  1405. @tab @b{Subwords}
  1406. @end iftex
  1407. @ifnottex
  1408. @item Nomenclature
  1409. @tab Subwords
  1410. @item ---------------------------------------------------------
  1411. @end ifnottex
  1412. @item @samp{GtkWindow}
  1413. @tab @samp{Gtk} and @samp{Window}
  1414. @item @samp{EmacsFrameClass}
  1415. @tab @samp{Emacs}, @samp{Frame}, and @samp{Class}
  1416. @item @samp{NSGraphicsContext}
  1417. @tab @samp{NS}, @samp{Graphics}, and @samp{Context}
  1418. @end multitable
  1419. The subword minor mode replaces the basic word oriented movement and
  1420. editing commands with variants that recognize subwords in a
  1421. nomenclature and treat them as separate words:
  1422. @findex c-forward-subword
  1423. @findex forward-subword (c-)
  1424. @findex c-backward-subword
  1425. @findex backward-subword (c-)
  1426. @findex c-mark-subword
  1427. @findex mark-subword (c-)
  1428. @findex c-kill-subword
  1429. @findex kill-subword (c-)
  1430. @findex c-backward-kill-subword
  1431. @findex backward-kill-subword (c-)
  1432. @findex c-transpose-subwords
  1433. @findex transpose-subwords (c-)
  1434. @findex c-capitalize-subword
  1435. @findex capitalize-subword (c-)
  1436. @findex c-upcase-subword
  1437. @findex upcase-subword (c-)
  1438. @findex c-downcase-subword
  1439. @findex downcase-subword (c-)
  1440. @multitable @columnfractions .20 .40 .40
  1441. @c This could be converted to @headitem when we require Texinfo 4.7
  1442. @iftex
  1443. @item @b{Key} @tab @b{Word oriented command} @tab @b{Subword oriented command}
  1444. @end iftex
  1445. @ifnottex
  1446. @item Key @tab Word oriented command @tab Subword oriented command
  1447. @item ----------------------------------------------------------------------------
  1448. @end ifnottex
  1449. @item @kbd{M-f} @tab @code{forward-word} @tab @code{c-forward-subword}
  1450. @item @kbd{M-b} @tab @code{backward-word} @tab @code{c-backward-subword}
  1451. @item @kbd{M-@@} @tab @code{mark-word} @tab @code{c-mark-subword}
  1452. @item @kbd{M-d} @tab @code{kill-word} @tab @code{c-kill-subword}
  1453. @item @kbd{M-DEL} @tab @code{backward-kill-word} @tab @code{c-backward-kill-subword}
  1454. @item @kbd{M-t} @tab @code{transpose-words} @tab @code{c-transpose-subwords}
  1455. @item @kbd{M-c} @tab @code{capitalize-word} @tab @code{c-capitalize-subword}
  1456. @item @kbd{M-u} @tab @code{upcase-word} @tab @code{c-upcase-subword}
  1457. @item @kbd{M-l} @tab @code{downcase-word} @tab @code{c-downcase-subword}
  1458. @end multitable
  1459. Note that if you have changed the key bindings for the word oriented
  1460. commands in your @file{.emacs} or a similar place, the keys you have
  1461. configured are also used for the corresponding subword oriented
  1462. commands.
  1463. Type @kbd{C-c C-w} to toggle subword mode on and off. To make the
  1464. mode turn on automatically, put the following code in your
  1465. @file{.emacs}:
  1466. @example
  1467. (add-hook 'c-mode-common-hook
  1468. (lambda () (subword-mode 1)))
  1469. @end example
  1470. As a bonus, you can also use @code{subword-mode} in non-@ccmode{}
  1471. buffers by typing @kbd{M-x subword-mode}.
  1472. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1473. @node Other Commands, , Subword Movement, Commands
  1474. @comment node-name, next, previous, up
  1475. @section Other Commands
  1476. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1477. Here are the various other commands that didn't fit anywhere else:
  1478. @table @asis
  1479. @item @kbd{C-c .} (@code{c-set-style})
  1480. @kindex C-c .
  1481. @findex c-set-style
  1482. @findex set-style (c-)
  1483. Switch to the specified style in the current buffer. Use like this:
  1484. @example
  1485. @kbd{C-c . @var{style-name} @key{RET}}
  1486. @end example
  1487. You can use the @key{TAB} in the normal way to do completion on the
  1488. style name. Note that all style names are case insensitive, even the
  1489. ones you define yourself.
  1490. Setting a style in this way does @emph{not} automatically reindent your
  1491. file. For commands that you can use to view the effect of your changes,
  1492. see @ref{Indentation Commands} and @ref{Filling and Breaking}.
  1493. For details of the @ccmode{} style system, see @ref{Styles}.
  1494. @item @kbd{C-c :} (@code{c-scope-operator})
  1495. @kindex C-c :
  1496. @findex c-scope-operator
  1497. @findex scope-operator (c-)
  1498. In C++, it is also sometimes desirable to insert the double-colon scope
  1499. operator without performing the electric behavior of colon insertion.
  1500. @kbd{C-c :} does just this.
  1501. @item @kbd{C-c C-\} (@code{c-backslash-region})
  1502. @kindex C-c C-\
  1503. @findex c-backslash-region
  1504. @findex backslash-region (c-)
  1505. This function inserts and aligns or deletes end-of-line backslashes in
  1506. the current region. These are typically used in multi-line macros.
  1507. With no prefix argument, it inserts any missing backslashes and aligns
  1508. them according to the @code{c-backslash-column} and
  1509. @code{c-backslash-max-column} variables. With a prefix argument, it
  1510. deletes any backslashes.
  1511. The function does not modify blank lines at the start of the region. If
  1512. the region ends at the start of a line, it always deletes the backslash
  1513. (if any) at the end of the previous line.
  1514. To customize the precise workings of this command, @ref{Custom Macros}.
  1515. @end table
  1516. @noindent
  1517. The recommended line breaking function, @code{c-context-line-break}
  1518. (@pxref{Filling and Breaking}), is especially nice if you edit
  1519. multiline macros frequently. When used inside a macro, it
  1520. automatically inserts and adjusts the mandatory backslash at the end
  1521. of the line to keep the macro together, and it leaves the point at the
  1522. right indentation column for the code. Thus you can write code inside
  1523. macros almost exactly as you can elsewhere, without having to bother
  1524. with the trailing backslashes.
  1525. @table @asis
  1526. @item @kbd{C-c C-e} (@code{c-macro-expand})
  1527. @kindex C-c C-e
  1528. @findex c-macro-expand
  1529. @findex macro-expand (c-)
  1530. This command expands C, C++, Objective C or Pike macros in the region,
  1531. using an appropriate external preprocessor program. Normally it
  1532. displays its output in a temporary buffer, but if you give it a prefix
  1533. arg (with @kbd{C-u C-c C-e}) it will overwrite the original region
  1534. with the expansion.
  1535. The command does not work in any of the other modes, and the key
  1536. sequence is not bound in these other modes.
  1537. @code{c-macro-expand} isn't actually part of @ccmode{}, even though it
  1538. is bound to a @ccmode{} key sequence. If you need help setting it up
  1539. or have other problems with it, you can either read its source code or
  1540. ask for help in the standard (X)Emacs forums.
  1541. @end table
  1542. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1543. @node Font Locking, Config Basics, Commands, Top
  1544. @comment node-name, next, previous, up
  1545. @chapter Font Locking
  1546. @cindex font locking
  1547. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1548. @cindex Font Lock mode
  1549. @ccmode{} provides font locking for its supported languages by
  1550. supplying patterns for use with Font Lock mode. This means that you
  1551. get distinct faces on the various syntactic parts such as comments,
  1552. strings, keywords and types, which is very helpful in telling them
  1553. apart at a glance and discovering syntactic errors. @xref{Font
  1554. Lock,,, emacs, GNU Emacs Manual}, for ways to enable font locking in
  1555. @ccmode{} buffers.
  1556. @strong{Please note:} The font locking in AWK mode is currently not
  1557. integrated with the rest of @ccmode{}. Only the last section of this
  1558. chapter, @ref{AWK Mode Font Locking}, applies to AWK@. The other
  1559. sections apply to the other languages.
  1560. @menu
  1561. * Font Locking Preliminaries::
  1562. * Faces::
  1563. * Doc Comments::
  1564. * Misc Font Locking::
  1565. * AWK Mode Font Locking::
  1566. @end menu
  1567. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1568. @node Font Locking Preliminaries, Faces, Font Locking, Font Locking
  1569. @comment node-name, next, previous, up
  1570. @section Font Locking Preliminaries
  1571. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1572. The font locking for most of the @ccmode{} languages were provided
  1573. directly by the Font Lock package prior to version 5.30 of @ccmode{}.
  1574. In the transition to @ccmode{} the patterns have been reworked
  1575. completely and are applied uniformly across all the languages except AWK
  1576. mode, just like the indentation rules (although each language still has
  1577. some peculiarities of its own, of course). Since the languages
  1578. previously had completely separate font locking patterns, this means
  1579. that it's a bit different in most languages now.
  1580. The main goal for the font locking in @ccmode{} is accuracy, to provide
  1581. a dependable aid in recognizing the various constructs. Some, like
  1582. strings and comments, are easy to recognize while others, like
  1583. declarations and types, can be very tricky. @ccmode{} can go to great
  1584. lengths to recognize declarations and casts correctly, especially when
  1585. the types aren't recognized by standard patterns. This is a fairly
  1586. demanding analysis which can be slow on older hardware, and it can
  1587. therefore be disabled by choosing a lower decoration level with the
  1588. variable @code{font-lock-maximum-decoration} (@pxref{Font Lock,,,
  1589. emacs, GNU Emacs Manual}).
  1590. @vindex font-lock-maximum-decoration
  1591. The decoration levels are used as follows:
  1592. @enumerate
  1593. @comment 1
  1594. @item
  1595. Minimal font locking: Fontify only comments, strings and preprocessor
  1596. directives (in the languages that use cpp).
  1597. @comment 2
  1598. @item
  1599. Fast font locking: In addition to level 1, fontify keywords, simple
  1600. types and declarations that are easy to recognize. The variables
  1601. @code{*-font-lock-extra-types} (where @samp{*} is the name of the
  1602. language) are used to recognize types (see below). Documentation
  1603. comments like Javadoc are fontified according to
  1604. @code{c-doc-comment-style} (@pxref{Doc Comments}).
  1605. Use this if you think the font locking is too slow. It's the closest
  1606. corresponding level to level 3 in the old font lock patterns.
  1607. @comment 3
  1608. @item
  1609. Accurate font locking: Like level 2 but uses a different approach that
  1610. can recognize types and declarations much more accurately. The
  1611. @code{*-font-lock-extra-types} variables are still used, but user
  1612. defined types are recognized correctly anyway in most cases. Therefore
  1613. those variables should be fairly restrictive and not contain patterns
  1614. that are uncertain.
  1615. @cindex Lazy Lock mode
  1616. @cindex Just-in-time Lock mode
  1617. This level is designed for fairly modern hardware and a font lock
  1618. support mode like Lazy Lock or Just-in-time Lock mode that only
  1619. fontifies the parts that are actually shown. Fontifying the whole
  1620. buffer at once can easily get bothersomely slow even on contemporary
  1621. hardware. @xref{Font Lock,,,@emacsman{}, @emacsmantitle{}}.
  1622. @end enumerate
  1623. @cindex user defined types
  1624. @cindex types, user defined
  1625. Since user defined types are hard to recognize you can provide
  1626. additional regexps to match those you use:
  1627. @defopt c-font-lock-extra-types
  1628. @defoptx c++-font-lock-extra-types
  1629. @defoptx objc-font-lock-extra-types
  1630. @defoptx java-font-lock-extra-types
  1631. @defoptx idl-font-lock-extra-types
  1632. @defoptx pike-font-lock-extra-types
  1633. For each language there's a variable @code{*-font-lock-extra-types},
  1634. where @samp{*} stands for the language in question. It contains a list
  1635. of regexps that matches identifiers that should be recognized as types,
  1636. e.g., @samp{\\sw+_t} to recognize all identifiers ending with @samp{_t}
  1637. as is customary in C code. Each regexp should not match more than a
  1638. single identifier.
  1639. The default values contain regexps for many types in standard runtime
  1640. libraries that are otherwise difficult to recognize, and patterns for
  1641. standard type naming conventions like the @samp{_t} suffix in C and C++.
  1642. Java, Objective-C and Pike have as a convention to start class names
  1643. with capitals, so there are patterns for that in those languages.
  1644. Despite the names of these variables, they are not only used for
  1645. fontification but in other places as well where @ccmode{} needs to
  1646. recognize types.
  1647. @end defopt
  1648. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1649. @node Faces, Doc Comments, Font Locking Preliminaries, Font Locking
  1650. @comment node-name, next, previous, up
  1651. @section Faces
  1652. @cindex faces
  1653. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1654. @ccmode{} attempts to use the standard faces for programming languages
  1655. in accordance with their intended purposes as far as possible. No extra
  1656. faces are currently provided, with the exception of a replacement face
  1657. @code{c-invalid-face} for emacsen that don't provide
  1658. @code{font-lock-warning-face}.
  1659. @itemize @bullet
  1660. @item
  1661. @vindex font-lock-comment-face
  1662. Normal comments are fontified in @code{font-lock-comment-face}.
  1663. @item
  1664. @vindex font-lock-doc-face
  1665. @vindex font-lock-doc-string-face
  1666. @vindex font-lock-comment-face
  1667. Comments that are recognized as documentation (@pxref{Doc Comments})
  1668. get @code{font-lock-doc-face} (Emacs) or
  1669. @code{font-lock-doc-string-face} (XEmacs) if those faces exist. If
  1670. they don't then @code{font-lock-comment-face} is used.
  1671. @item
  1672. @vindex font-lock-string-face
  1673. String and character literals are fontified in
  1674. @code{font-lock-string-face}.
  1675. @item
  1676. @vindex font-lock-keyword-face
  1677. Keywords are fontified with @code{font-lock-keyword-face}.
  1678. @item
  1679. @vindex font-lock-function-name-face
  1680. @code{font-lock-function-name-face} is used for function names in
  1681. declarations and definitions, and classes in those contexts. It's also
  1682. used for preprocessor defines with arguments.
  1683. @item
  1684. @vindex font-lock-variable-name-face
  1685. Variables in declarations and definitions, and other identifiers in such
  1686. variable contexts, get @code{font-lock-variable-name-face}. It's also
  1687. used for preprocessor defines without arguments.
  1688. @item
  1689. @vindex font-lock-constant-face
  1690. @vindex font-lock-reference-face
  1691. Builtin constants are fontified in @code{font-lock-constant-face} if it
  1692. exists, @code{font-lock-reference-face} otherwise. As opposed to the
  1693. preceding two faces, this is used on the names in expressions, and it's
  1694. not used in declarations, even if there happen to be a @samp{const} in
  1695. them somewhere.
  1696. @item
  1697. @vindex font-lock-type-face
  1698. @code{font-lock-type-face} is put on types (both predefined and user
  1699. defined) and classes in type contexts.
  1700. @item
  1701. @vindex font-lock-constant-face
  1702. @vindex font-lock-reference-face
  1703. Label identifiers get @code{font-lock-constant-face} if it exists,
  1704. @code{font-lock-reference-face} otherwise.
  1705. @item
  1706. Name qualifiers and identifiers for scope constructs are fontified like
  1707. labels.
  1708. @item
  1709. Special markup inside documentation comments are also fontified like
  1710. labels.
  1711. @item
  1712. @vindex font-lock-preprocessor-face
  1713. @vindex font-lock-builtin-face
  1714. @vindex font-lock-reference-face
  1715. Preprocessor directives get @code{font-lock-preprocessor-face} if it
  1716. exists (i.e., XEmacs). In Emacs they get @code{font-lock-builtin-face}
  1717. or @code{font-lock-reference-face}, for lack of a closer equivalent.
  1718. @item
  1719. @vindex font-lock-warning-face
  1720. @vindex c-invalid-face
  1721. @vindex invalid-face (c-)
  1722. Some kinds of syntactic errors are fontified with
  1723. @code{font-lock-warning-face} in Emacs. In older XEmacs versions
  1724. there's no corresponding standard face, so there a special
  1725. @code{c-invalid-face} is used, which is defined to stand out sharply by
  1726. default.
  1727. Note that it's not used for @samp{#error} or @samp{#warning} directives,
  1728. since those aren't syntactic errors in themselves.
  1729. @end itemize
  1730. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1731. @node Doc Comments, Misc Font Locking, Faces, Font Locking
  1732. @comment node-name, next, previous, up
  1733. @section Documentation Comments
  1734. @cindex documentation comments
  1735. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1736. There are various tools to supply documentation in the source as
  1737. specially structured comments, e.g., the standard Javadoc tool in Java.
  1738. @ccmode{} provides an extensible mechanism to fontify such comments and
  1739. the special markup inside them.
  1740. @defopt c-doc-comment-style
  1741. @vindex doc-comment-style (c-)
  1742. This is a style variable that specifies which documentation comment
  1743. style to recognize, e.g., @code{javadoc} for Javadoc comments.
  1744. The value may also be a list of styles, in which case all of them are
  1745. recognized simultaneously (presumably with markup cues that don't
  1746. conflict).
  1747. The value may also be an association list to specify different comment
  1748. styles for different languages. The symbol for the major mode is then
  1749. looked up in the alist, and the value of that element is interpreted as
  1750. above if found. If it isn't found then the symbol @code{other} is looked up
  1751. and its value is used instead.
  1752. The default value for @code{c-doc-comment-style} is
  1753. @w{@code{((java-mode . javadoc) (pike-mode . autodoc) (c-mode . gtkdoc))}}.
  1754. Note that @ccmode{} uses this variable to set other variables that
  1755. handle fontification etc. That's done at mode initialization or when
  1756. you switch to a style which sets this variable. Thus, if you change it
  1757. in some other way, e.g., interactively in a CC Mode buffer, you will need
  1758. to do @kbd{M-x java-mode} (or whatever mode you're currently using) to
  1759. reinitialize.
  1760. @findex c-setup-doc-comment-style
  1761. @findex setup-doc-comment-style (c-)
  1762. Note also that when @ccmode{} starts up, the other variables are
  1763. modified before the mode hooks are run. If you change this variable in
  1764. a mode hook, you'll have to call @code{c-setup-doc-comment-style}
  1765. afterwards to redo that work.
  1766. @end defopt
  1767. @ccmode{} currently provides handing of the following doc comment
  1768. styles:
  1769. @table @code
  1770. @item javadoc
  1771. @cindex Javadoc markup
  1772. Javadoc comments, the standard tool in Java.
  1773. @item autodoc
  1774. @cindex Pike autodoc markup
  1775. For Pike autodoc markup, the standard in Pike.
  1776. @item gtkdoc
  1777. @cindex GtkDoc markup
  1778. For GtkDoc markup, widely used in the Gnome community.
  1779. @end table
  1780. The above is by no means complete. If you'd like to see support for
  1781. other doc comment styles, please let us know (@pxref{Mailing Lists and
  1782. Bug Reports}).
  1783. You can also write your own doc comment fontification support to use
  1784. with @code{c-doc-comment-style}: Supply a variable or function
  1785. @code{*-font-lock-keywords} where @samp{*} is the name you want to use
  1786. in @code{c-doc-comment-style}. If it's a variable, it's prepended to
  1787. @code{font-lock-keywords}. If it's a function, it's called at mode
  1788. initialization and the result is prepended. For an example, see
  1789. @code{javadoc-font-lock-keywords} in @file{cc-fonts.el}.
  1790. If you add support for another doc comment style, please consider
  1791. contributing it: send a note to @email{bug-cc-mode@@gnu.org}.
  1792. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1793. @node Misc Font Locking, AWK Mode Font Locking, Doc Comments, Font Locking
  1794. @comment node-name, next, previous, up
  1795. @section Miscellaneous Font Locking
  1796. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1797. In some languages, particularly in C++, there are constructs which are
  1798. syntactically ambiguous---they could be either declarations or
  1799. expressions, and @ccmode{} cannot tell for sure which. Often such a
  1800. construct is one of the operators @samp{*} or @samp{&} surrounded by
  1801. two identifiers.
  1802. Experience shows that very often when such a construct is a
  1803. declaration it will be written with the operator touching exactly one
  1804. of the identifiers, like:
  1805. @example
  1806. foo *bar
  1807. @end example
  1808. or
  1809. @example
  1810. foo& bar
  1811. @end example
  1812. . Whether such code is fontified depends on the setting of
  1813. @code{c-asymmetry-fontification-flag}.
  1814. @defvar c-asymmetry-fontification-flag
  1815. @vindex asymmetry-fontification-flag (c-)
  1816. When @code{c-asymmetry-fontification-flag} is non-nil (which it is by
  1817. default), code like the above, with white space either before or after
  1818. the operator, but not both, is fontified as a declaration. When the
  1819. variable is nil, such a construct gets the default face.
  1820. @end defvar
  1821. When the construct is an expression there will often be white space
  1822. both before and after the operator or there will be no white space
  1823. around it at all, like:
  1824. @example
  1825. foo * bar
  1826. @end example
  1827. or
  1828. @example
  1829. foo&bar
  1830. @end example
  1831. .
  1832. Such code is not fontified as a declaration. (Typically, the
  1833. identifiers don't get a non-default face.)
  1834. For clarity's sake, we emphasize that the ``asymmetry'' rule in this
  1835. section only applies when CC Mode cannot disambiguate a construct in
  1836. any other way.
  1837. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1838. @node AWK Mode Font Locking, , Misc Font Locking, Font Locking
  1839. @comment node-name, next, previous, up
  1840. @section AWK Mode Font Locking
  1841. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1842. The general appearance of font-locking in AWK mode is much like in any
  1843. other programming mode. @xref{Faces for Font Lock,,,elisp, GNU Emacs
  1844. Lisp Reference Manual}.
  1845. The following faces are, however, used in a non-standard fashion in
  1846. AWK mode:
  1847. @table @asis
  1848. @item @code{font-lock-variable-name-face}
  1849. This face was intended for variable declarations. Since variables are
  1850. not declared in AWK, this face is used instead for AWK system
  1851. variables (such as @code{NF}) and ``Special File Names'' (such as
  1852. @code{"/dev/stderr"}).
  1853. @item @code{font-lock-builtin-face} (Emacs)/@code{font-lock-preprocessor-face} (XEmacs)
  1854. This face is normally used for preprocessor directives in @ccmode{}.
  1855. There are no such things in AWK, so this face is used instead for
  1856. standard functions (such as @code{match}).
  1857. @item @code{font-lock-string-face}
  1858. As well as being used for strings, including localizable strings,
  1859. (delimited by @samp{"} and @samp{_"}), this face is also used for AWK
  1860. regular expressions (delimited by @samp{/}).
  1861. @item @code{font-lock-warning-face} (Emacs)/@code{c-invalid-face} (XEmacs)
  1862. This face highlights the following syntactically invalid AWK
  1863. constructs:
  1864. @itemize @bullet
  1865. @item
  1866. An unterminated string or regular expression. Here the opening
  1867. delimiter (@samp{"} or @samp{/} or @samp{_"}) is displayed in
  1868. @code{font-lock-warning-face}. This is most noticeable when typing in a
  1869. new string/regular expression into a buffer, when the warning-face
  1870. serves as a continual reminder to terminate the construct.
  1871. AWK mode fontifies unterminated strings/regular expressions
  1872. differently from other modes: Only the text up to the end of the line
  1873. is fontified as a string (escaped newlines being handled correctly),
  1874. rather than the text up to the next string quote.
  1875. @item
  1876. A space between the function name and opening parenthesis when calling
  1877. a user function. The last character of the function name and the
  1878. opening parenthesis are highlighted. This font-locking rule will
  1879. spuriously highlight a valid concatenation expression where an
  1880. identifier precedes a parenthesized expression. Unfortunately.
  1881. @item
  1882. Whitespace following the @samp{\} in what otherwise looks like an
  1883. escaped newline. The @samp{\} is highlighted.
  1884. @end itemize
  1885. @end table
  1886. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1887. @node Config Basics, Custom Filling and Breaking, Font Locking, Top
  1888. @comment node-name, next, previous, up
  1889. @chapter Configuration Basics
  1890. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1891. @cindex Emacs Initialization File
  1892. @cindex Configuration
  1893. You configure @ccmode{} by setting Lisp variables and calling (and
  1894. perhaps writing) Lisp functions@footnote{DON'T PANIC!!! This isn't
  1895. difficult.}, which is usually done by adding code to an Emacs
  1896. initialization file. This file might be @file{site-start.el} or
  1897. @file{.emacs} or @file{init.el} or @file{default.el} or perhaps some
  1898. other file. @xref{Init File,,,@emacsman{}, @emacsmantitle{}}. For
  1899. the sake of conciseness, we just call this file ``your @file{.emacs}''
  1900. throughout the rest of the manual.
  1901. Several of these variables (currently 16), are known collectively as
  1902. @dfn{style variables}. @ccmode{} provides a special mechanism, known
  1903. as @dfn{styles} to make it easier to set these variables as a group,
  1904. to ``inherit'' settings from one style into another, and so on. Style
  1905. variables remain ordinary Lisp variables, whose values can be read and
  1906. changed independently of the style system. @xref{Style Variables}.
  1907. There are several ways you can write the code, depending on the
  1908. precise effect you want---they are described further down on this page.
  1909. If you are new to @ccmode{}, we suggest you begin with the simplest
  1910. method, ``Top-level commands or the customization interface''.
  1911. If you make conflicting settings in several of these ways, the way
  1912. that takes precedence is the one that appears latest in this list:
  1913. @itemize @w{}
  1914. @item
  1915. @table @asis
  1916. @item Style
  1917. @itemx File Style@footnote{In earlier versions of @ccmode{}, a File Style setting took precedence over any other setting apart from a File Local Variable setting.}
  1918. @itemx Top-level command or ``customization interface''
  1919. @itemx Hook
  1920. @itemx File Local Variable setting
  1921. @end table
  1922. @end itemize
  1923. Here is a summary of the different ways of writing your configuration
  1924. settings:
  1925. @table @asis
  1926. @item Top-level commands or the ``customization interface''
  1927. Most simply, you can write @code{setq} and similar commands at the top
  1928. level of your @file{.emacs} file. When you load a @ccmode{} buffer,
  1929. it initializes its configuration from these global values (at least,
  1930. for those settings you have given values to), so it makes sense to
  1931. have these @code{setq} commands run @emph{before} @ccmode{} is first
  1932. initialized---in particular, before any call to @code{desktop-read}
  1933. (@pxref{Saving Emacs Sessions,,, emacs, GNU Emacs Manual}). For
  1934. example, you might set c-basic-offset thus:
  1935. @example
  1936. (setq c-basic-offset 4)
  1937. @end example
  1938. You can use the more user friendly Customization interface instead,
  1939. but this manual does not cover in detail how that works. To do this,
  1940. start by typing @kbd{M-x customize-group @key{RET} c @key{RET}}.
  1941. @xref{Easy Customization,,,@emacsman{}, @emacsmantitle{}}.
  1942. @c The following note really belongs in the Emacs manual.
  1943. Emacs normally writes the customizations at the end of your
  1944. @file{.emacs} file. If you use @code{desktop-read}, you should edit
  1945. your @file{.emacs} to place the call to @code{desktop-read} @emph{after}
  1946. the customizations.
  1947. The first initialization of @ccmode{} puts a snapshot of the
  1948. configuration settings into the special style @code{user}.
  1949. @xref{Built-in Styles}.
  1950. For basic use of Emacs, either of these ways of configuring is
  1951. adequate. However, the settings are then the same in all @ccmode{}
  1952. buffers and it can be clumsy to communicate them between programmers.
  1953. For more flexibility, you'll want to use one (or both) of @ccmode{}'s
  1954. more sophisticated facilities, hooks and styles.
  1955. @item Hooks
  1956. An Emacs @dfn{hook} is a place to put Lisp functions that you want
  1957. Emacs to execute later in specific circumstances.
  1958. @xref{Hooks,,,@lispref{}, @lispreftitle{}}. @ccmode{} supplies a main
  1959. hook and a language-specific hook for each language it supports; any
  1960. functions you put onto these hooks get executed as the last part of a
  1961. buffer's initialization. Typically you put most of your customization
  1962. within the main hook, and use the language-specific hooks to vary the
  1963. customization settings between language modes. For example, if you
  1964. wanted different (non-standard) values of @code{c-basic-offset} in C
  1965. Mode and Java Mode buffers, you could do it like this:
  1966. @example
  1967. @group
  1968. (defun my-c-mode-hook ()
  1969. (setq c-basic-offset 3))
  1970. (add-hook 'c-mode-hook 'my-c-mode-hook)
  1971. (defun my-java-mode-hook ()
  1972. (setq c-basic-offset 6))
  1973. (add-hook 'java-mode-hook 'my-java-mode-hook)
  1974. @end group
  1975. @end example
  1976. See @ref{CC Hooks} for more details on the use of @ccmode{} hooks.
  1977. @item Styles
  1978. A @ccmode{} @dfn{style} is a coherent collection of customizations
  1979. with a name. At any time, exactly one style is active in each
  1980. @ccmode{} buffer, either the one you have selected or a default.
  1981. @ccmode{} is delivered with several existing styles. Additionally,
  1982. you can create your own styles, possibly based on these existing
  1983. styles. If you worked in a programming team called the ``Free
  1984. Group'', which had its own coding standards, you might well have this
  1985. in your @file{.emacs} file:
  1986. @example
  1987. (setq c-default-style '((java-mode . "java")
  1988. (awk-mode . "awk")
  1989. (other . "free-group-style")))
  1990. @end example
  1991. See @ref{Styles} for fuller details on using @ccmode{} styles and how
  1992. to create them.
  1993. @item File Local Variable setting
  1994. A @dfn{file local variable setting} is a setting which applies to an
  1995. individual source file. You put this in a @dfn{local variables list},
  1996. a special block at the end of the source file (@pxref{Specifying File
  1997. Variables,,,@emacsman{}}).
  1998. @item File Styles
  1999. A @dfn{file style} is a rarely used variant of the ``style'' mechanism
  2000. described above, which applies to an individual source file.
  2001. @xref{File Styles}. You use this by setting certain special variables
  2002. in a local variables list (@pxref{Specifying File
  2003. Variables,,,@emacsman{}}).
  2004. @item Hooks with Styles
  2005. For ultimate flexibility, you can use hooks and styles together. For
  2006. example, if your team were developing a product which required a
  2007. Linux driver, you'd probably want to use the ``linux'' style for the
  2008. driver, and your own team's style for the rest of the code. You
  2009. could achieve this with code like this in your @file{.emacs}:
  2010. @example
  2011. @group
  2012. (defun my-c-mode-hook ()
  2013. (c-set-style
  2014. (if (and (buffer-file-name)
  2015. (string-match "/usr/src/linux" (buffer-file-name)))
  2016. "linux"
  2017. "free-group-style")))
  2018. (add-hook 'c-mode-hook 'my-c-mode-hook)
  2019. @end group
  2020. @end example
  2021. In a programming team, a hook is a also a good place for each member
  2022. to put his own personal preferences. For example, you might be the
  2023. only person in your team who likes Auto-newline minor mode. You could
  2024. have it enabled by default by placing the following in your
  2025. @file{.emacs}:
  2026. @example
  2027. @group
  2028. (defun my-turn-on-auto-newline ()
  2029. (c-toggle-auto-newline 1))
  2030. (add-hook 'c-mode-common-hook 'my-turn-on-auto-newline)
  2031. @end group
  2032. @end example
  2033. @end table
  2034. @menu
  2035. * CC Hooks::
  2036. * Style Variables::
  2037. * Styles::
  2038. @end menu
  2039. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2040. @node CC Hooks, Style Variables, Config Basics, Config Basics
  2041. @comment node-name, next, previous, up
  2042. @section Hooks
  2043. @cindex mode hooks
  2044. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2045. @c The node name is "CC Hooks" rather than "Hooks" because of a bug in
  2046. @c some older versions of Info, e.g., the info.el in GNU Emacs 21.3.
  2047. @c If you go to "Config Basics" and hit <CR> on the xref to "CC
  2048. @c Hooks" the function Info-follow-reference searches for "*Note: CC
  2049. @c Hooks" from the beginning of the page. If this node were instead
  2050. @c named "Hooks", that search would spuriously find "*Note:
  2051. @c Hooks(elisp)" and go to the wrong node.
  2052. @ccmode{} provides several hooks that you can use to customize the
  2053. mode for your coding style. The main hook is
  2054. @code{c-mode-common-hook}; typically, you'll put the bulk of your
  2055. customizations here. In addition, each language mode has its own
  2056. hook, allowing you to fine tune your settings individually for the
  2057. different @ccmode{} languages, and there is a package initialization
  2058. hook. Finally, there is @code{c-special-indent-hook}, which enables
  2059. you to solve anomalous indentation problems. It is described in
  2060. @ref{Other Indentation}, not here. All these hooks adhere to the
  2061. standard Emacs conventions.
  2062. When you open a buffer, @ccmode{} first initializes it with the
  2063. currently active style (@pxref{Styles}). Then it calls
  2064. @code{c-mode-common-hook}, and finally it calls the language-specific
  2065. hook. Thus, any style settings done in these hooks will override
  2066. those set by @code{c-default-style}.
  2067. @defvar c-initialization-hook
  2068. @vindex initialization-hook (c-)
  2069. Hook run only once per Emacs session, when @ccmode{} is initialized.
  2070. This is a good place to change key bindings (or add new ones) in any
  2071. of the @ccmode{} key maps. @xref{Sample Init File}.
  2072. @end defvar
  2073. @defvar c-mode-common-hook
  2074. @vindex mode-common-hook (c-)
  2075. Common hook across all languages. It's run immediately before the
  2076. language specific hook.
  2077. @end defvar
  2078. @defvar c-mode-hook
  2079. @defvarx c++-mode-hook
  2080. @defvarx objc-mode-hook
  2081. @defvarx java-mode-hook
  2082. @defvarx idl-mode-hook
  2083. @defvarx pike-mode-hook
  2084. @defvarx awk-mode-hook
  2085. The language specific mode hooks. The appropriate one is run as the
  2086. last thing when you enter that language mode.
  2087. @end defvar
  2088. Although these hooks are variables defined in @ccmode{}, you can give
  2089. them values before @ccmode{}'s code is loaded---indeed, this is the
  2090. only way to use @code{c-initialization-hook}. Their values aren't
  2091. overwritten when @ccmode{} gets loaded.
  2092. Here's a simplified example of what you can add to your @file{.emacs}
  2093. file to do things whenever any @ccmode{} language is edited. See the
  2094. Emacs manuals for more information on customizing Emacs via hooks.
  2095. @xref{Sample Init File}, for a more complete sample @file{.emacs}
  2096. file.
  2097. @example
  2098. (defun my-c-mode-common-hook ()
  2099. ;; my customizations for all of c-mode and related modes
  2100. (no-case-fold-search)
  2101. )
  2102. (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
  2103. @end example
  2104. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2105. @node Style Variables, Styles, CC Hooks, Config Basics
  2106. @comment node-name, next, previous, up
  2107. @section Style Variables
  2108. @cindex styles
  2109. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2110. @cindex style variables
  2111. The variables that @ccmode{}'s style system control are called
  2112. @dfn{style variables}. Note that style variables are ordinary Lisp
  2113. variables, which the style system initializes; you can change their
  2114. values at any time (e.g., in a hook function). The style system can
  2115. also set other variables, to some extent. @xref{Styles}.
  2116. @dfn{Style variables} are handled specially in several ways:
  2117. @itemize @bullet
  2118. @item
  2119. Style variables are by default buffer-local variables. However, they
  2120. can instead be made global by setting
  2121. @code{c-style-variables-are-local-p} to @code{nil} before @ccmode{} is
  2122. initialized.
  2123. @item
  2124. @vindex c-old-style-variable-behavior
  2125. @vindex old-style-variable-behavior (c-)
  2126. The default global binding of any style variable (with two exceptions
  2127. - see below) is the special symbol @code{set-from-style}. When the
  2128. style system initializes a buffer-local copy of a style variable for a
  2129. @ccmode{} buffer, if its global binding is still that symbol then it
  2130. will be set from the current style. Otherwise it will retain its
  2131. global default@footnote{This is a big change from versions of
  2132. @ccmode{} earlier than 5.26, where such settings would get overridden
  2133. by the style system unless special precautions were taken. That was
  2134. changed since it was counterintuitive and confusing, especially to
  2135. novice users. If your configuration depends on the old overriding
  2136. behavior, you can set the variable
  2137. @code{c-old-style-variable-behavior} to non-@code{nil}.}. This
  2138. ``otherwise'' happens, for example, when you've set the variable with
  2139. @code{setq} at the top level of your @file{.emacs} (@pxref{Config
  2140. Basics}).
  2141. @item
  2142. The style variable @code{c-offsets-alist} (@pxref{c-offsets-alist}) is
  2143. an association list with an element for each syntactic symbol. It's
  2144. handled a little differently from the other style variables. It's
  2145. default global binding is the empty list @code{nil}, rather than
  2146. @code{set-from-style}. Before the style system is initialized, you
  2147. can add individual elements to @code{c-offsets-alist} by calling
  2148. @code{c-set-offset} (@pxref{c-offsets-alist}) just like you would set
  2149. other style variables with @code{setq}. Those elements will then
  2150. prevail when the style system later initializes a buffer-local copy of
  2151. @code{c-offsets-alist}.
  2152. @item
  2153. The style variable @code{c-special-indent-hook} is also handled in a
  2154. special way. Styles can only add functions to this hook, not remove
  2155. them, so any global settings you put on it are always
  2156. preserved@footnote{This did not change in version 5.26.}. The value
  2157. you give this variable in a style definition can be either a function
  2158. or a list of functions.
  2159. @item
  2160. The global bindings of the style variables get captured in the special
  2161. @code{user} style when the style system is first initialized.
  2162. @xref{Built-in Styles}, for details.
  2163. @end itemize
  2164. The style variables are:@*
  2165. @code{c-indent-comment-alist},
  2166. @code{c-indent-comments-syntactically-p} (@pxref{Indentation
  2167. Commands});@*
  2168. @code{c-doc-comment-style} (@pxref{Doc Comments});@*
  2169. @code{c-block-comment-prefix}, @code{c-comment-prefix-regexp}
  2170. (@pxref{Custom Filling and Breaking});@*
  2171. @code{c-hanging-braces-alist} (@pxref{Hanging Braces});@*
  2172. @code{c-hanging-colons-alist} (@pxref{Hanging Colons});@*
  2173. @code{c-hanging-semi&comma-criteria} (@pxref{Hanging Semicolons and
  2174. Commas});@*
  2175. @code{c-cleanup-list} (@pxref{Clean-ups});@*
  2176. @code{c-basic-offset} (@pxref{Customizing Indentation});@*
  2177. @code{c-offsets-alist} (@pxref{c-offsets-alist});@*
  2178. @code{c-comment-only-line-offset} (@pxref{Comment Line-Up});@*
  2179. @code{c-special-indent-hook}, @code{c-label-minimum-indentation}
  2180. (@pxref{Other Indentation});@*
  2181. @code{c-backslash-column}, @code{c-backslash-max-column}
  2182. (@pxref{Custom Macros}).
  2183. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2184. @node Styles, , Style Variables, Config Basics
  2185. @comment node-name, next, previous, up
  2186. @section Styles
  2187. @cindex styles
  2188. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2189. By @dfn{style} we mean the layout of the code---things like how many
  2190. columns to indent a block of code, whether an opening brace gets
  2191. indented to the level of the code it encloses, or of the construct
  2192. that introduces it, or ``hangs'' at the end of a line.
  2193. Most people only need to edit code formatted in just a few well-defined
  2194. and consistent styles. For example, their organization might impose a
  2195. ``blessed'' style that all its programmers must conform to. Similarly,
  2196. people who work on GNU software will have to use the GNU coding style.
  2197. Some shops are more lenient, allowing a variety of coding styles, and as
  2198. programmers come and go, there could be a number of styles in use. For
  2199. this reason, @ccmode{} makes it convenient for you to set up logical
  2200. groupings of customizations called @dfn{styles}, associate a single name
  2201. for any particular style, and pretty easily start editing new or
  2202. existing code using these styles.
  2203. As an alternative to writing a style definition yourself, you can have
  2204. @ccmode{} @dfn{guess} (at least part of) your style by looking at an
  2205. already formatted piece of your code, @ref{Guessing the Style}.
  2206. @menu
  2207. * Built-in Styles::
  2208. * Choosing a Style::
  2209. * Adding Styles::
  2210. * Guessing the Style::
  2211. * File Styles::
  2212. @end menu
  2213. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2214. @node Built-in Styles, Choosing a Style, Styles, Styles
  2215. @comment node-name, next, previous, up
  2216. @subsection Built-in Styles
  2217. @cindex styles, built-in
  2218. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2219. If you're lucky, one of @ccmode{}'s built-in styles might be just
  2220. what you're looking for. These are:
  2221. @table @code
  2222. @item gnu
  2223. @cindex GNU style
  2224. Coding style blessed by the Free Software Foundation
  2225. for C code in GNU programs.
  2226. @item k&r
  2227. @cindex K&R style
  2228. The classic Kernighan and Ritchie style for C code. If you're looking
  2229. for the style used in the 2nd edition of their book ``The C
  2230. Programming Language'', then check out the @code{stroustrup} style.
  2231. @item bsd
  2232. @cindex BSD style
  2233. Also known as ``Allman style'' after Eric Allman.
  2234. @item whitesmith
  2235. @cindex Whitesmith style
  2236. Popularized by the examples that came with Whitesmiths C, an early
  2237. commercial C compiler.
  2238. @item stroustrup
  2239. @cindex Stroustrup style
  2240. The classic Stroustrup style for C++ code.
  2241. @item ellemtel
  2242. @cindex Ellemtel style
  2243. Popular C++ coding standards as defined by ``Programming in C++, Rules
  2244. and Recommendations,'' Erik Nyquist and Mats Henricson,
  2245. Ellemtel@footnote{This document is available at
  2246. @uref{http://www.doc.ic.ac.uk/lab/cplus/c++.rules/} among other
  2247. places.}.
  2248. @c N.B. This URL was still valid at 2005/8/28 (ACM).
  2249. @item linux
  2250. @cindex Linux style
  2251. C coding standard for Linux (the kernel).
  2252. @item python
  2253. @cindex Python style
  2254. C coding standard for Python extension modules@footnote{Python is a
  2255. high level scripting language with a C/C++ foreign function interface.
  2256. For more information, see @uref{http://www.python.org/}.}.
  2257. @item java
  2258. @cindex Java style
  2259. The style for editing Java code. Note that the default
  2260. value for @code{c-default-style} installs this style when you enter
  2261. @code{java-mode}.
  2262. @item awk
  2263. @cindex AWK style
  2264. The style for editing AWK code. Note that the default value for
  2265. @code{c-default-style} installs this style when you enter
  2266. @code{awk-mode}.
  2267. @item user
  2268. @cindex User style
  2269. This is a special style created by you. It consists of the factory
  2270. defaults for all the style variables as modified by the customizations
  2271. you do either with the Customization interface or by writing
  2272. @code{setq}s and @code{c-set-offset}s at the top level of your
  2273. @file{.emacs} file (@pxref{Config Basics}). The style system creates
  2274. this style as part of its initialization and doesn't modify it
  2275. afterwards.
  2276. @end table
  2277. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2278. @node Choosing a Style, Adding Styles, Built-in Styles, Styles
  2279. @comment node-name, next, previous, up
  2280. @subsection Choosing a Style
  2281. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2282. When you create a new buffer, its style will be set from
  2283. @code{c-default-style}. The factory default is the style @code{gnu},
  2284. except in Java and AWK modes where it's @code{java} and @code{awk}.
  2285. Remember that if you set a style variable with the Customization
  2286. interface or at the top level of your @file{.emacs} file before the
  2287. style system is initialized (@pxref{Config Basics}), this setting will
  2288. override the one that the style system would have given the variable.
  2289. To set a buffer's style interactively, use the command @kbd{C-c .}
  2290. (@pxref{Other Commands}). To set it from a file's local variable
  2291. list, @ref{File Styles}.
  2292. @defopt c-default-style
  2293. @vindex default-style (c-)
  2294. This variable specifies which style to install by default in new
  2295. buffers. It takes either a style name string, or an association list
  2296. of major mode symbols to style names:
  2297. @enumerate
  2298. @item
  2299. When @code{c-default-style} is a string, it must be an existing style
  2300. name. This style is then used for all modes.
  2301. @item
  2302. When @code{c-default-style} is an association list, the mode language
  2303. is looked up to find a style name string.
  2304. @item
  2305. If @code{c-default-style} is an association list where the mode
  2306. language mode isn't found then the special symbol @samp{other} is
  2307. looked up. If it's found then the associated style is used.
  2308. @item
  2309. If @samp{other} is not found then the @samp{gnu} style is used.
  2310. @end enumerate
  2311. In all cases, the style described in @code{c-default-style} is installed
  2312. @emph{before} the language hooks are run, so you can always override
  2313. this setting by including an explicit call to @code{c-set-style} in your
  2314. language mode hook, or in @code{c-mode-common-hook}.
  2315. The standard value of @code{c-default-style} is @w{@code{((java-mode
  2316. . "java") (awk-mode . "awk") (other . "gnu"))}}.
  2317. @end defopt
  2318. @defvar c-indentation-style
  2319. @vindex indentation-style (c-)
  2320. This variable always contains the buffer's current style name, as a
  2321. string.
  2322. @end defvar
  2323. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2324. @node Adding Styles, Guessing the Style, Choosing a Style, Styles
  2325. @comment node-name, next, previous, up
  2326. @subsection Adding and Amending Styles
  2327. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2328. If none of the built-in styles is appropriate, you'll probably want to
  2329. create a new @dfn{style definition}, possibly based on an existing
  2330. style. To do this, put the new style's settings into a list with the
  2331. following format; the list can then be passed as an argument to the
  2332. function @code{c-add-style}. You can see an example of a style
  2333. definition in @ref{Sample Init File}.
  2334. @cindex style definition
  2335. @c @defvr {List} style definition
  2336. @table @asis
  2337. @item Structure of a Style Definition List
  2338. ([@var{base-style}] [(@var{variable} . @var{value}) @dots{}])
  2339. Optional @var{base-style}, if present, must be a string which is the
  2340. name of the @dfn{base style} from which this style inherits. At most
  2341. one @var{base-style} is allowed in a style definition. If
  2342. @var{base-style} is not specified, the style inherits from the table
  2343. of factory default values@footnote{This table is stored internally in
  2344. the variable c-fallback-style.} instead. All styles eventually
  2345. inherit from this internal table. Style loops generate errors. The
  2346. list of pre-existing styles can be seen in @ref{Built-in Styles}.
  2347. The dotted pairs (@var{variable} . @var{value}) each consist of a
  2348. variable and the value it is to be set to when the style is later
  2349. activated.@footnote{Note that if the variable has been given a value
  2350. by the Customization interface or a @code{setq} at the top level of
  2351. your @file{.emacs}, this value will override the one the style system
  2352. tries to give it. @xref{Config Basics}.} The variable can be either a
  2353. @ccmode{} style variable or an arbitrary Emacs variable. In the
  2354. latter case, it is @emph{not} made buffer-local by the @ccmode{} style
  2355. system.
  2356. @c @end defvr
  2357. Two variables are treated specially in the dotted pair list:
  2358. @table @code
  2359. @item c-offsets-alist
  2360. The value is in turn a list of dotted pairs of the form
  2361. @example
  2362. (@r{@var{syntactic-symbol}} . @r{@var{offset}})
  2363. @end example
  2364. as described in @ref{c-offsets-alist}. These are passed to
  2365. @code{c-set-offset} so there is no need to set every syntactic symbol
  2366. in your style, only those that are different from the inherited style.
  2367. @item c-special-indent-hook
  2368. The value is added to @code{c-special-indent-hook} using
  2369. @code{add-hook}, so any functions already on it are kept. If the value
  2370. is a list, each element of the list is added with @code{add-hook}.
  2371. @end table
  2372. @end table
  2373. Styles are kept in the @code{c-style-alist} variable, but you
  2374. should never modify this variable directly. Instead, @ccmode{}
  2375. provides the function @code{c-add-style} for this purpose.
  2376. @defun c-add-style stylename description &optional set-p
  2377. @findex add-style (c-)
  2378. Add or update a style called @var{stylename}, a string.
  2379. @var{description} is the new style definition in the form described
  2380. above. If @var{stylename} already exists in @code{c-style-alist} then
  2381. it is replaced by @var{description}. (Note, this replacement is
  2382. total. The old style is @emph{not} merged into the new one.)
  2383. Otherwise, a new style is added.
  2384. If the optional @var{set-p} is non-@code{nil} then the new style is
  2385. applied to the current buffer as well. The use of this facility is
  2386. deprecated and it might be removed from @ccmode{} in a future release.
  2387. You should use @code{c-set-style} instead.
  2388. The sample @file{.emacs} file provides a concrete example of how a new
  2389. style can be added and automatically set. @xref{Sample Init File}.
  2390. @end defun
  2391. @defvar c-style-alist
  2392. @vindex style-alist (c-)
  2393. This is the variable that holds the definitions for the styles. It
  2394. should not be changed directly; use @code{c-add-style} instead.
  2395. @end defvar
  2396. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2397. @node Guessing the Style, File Styles, Adding Styles, Styles
  2398. @comment node-name, next, previous, up
  2399. @subsection Guessing the Style
  2400. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2401. Instead of specifying a style, you can get @ccmode{} to @dfn{guess}
  2402. your style by examining an already formatted code buffer. @ccmode{}
  2403. then determines the ''most frequent'' offset (@pxref{c-offsets-alist})
  2404. for each of the syntactic symbols (@pxref{Indentation Engine Basics})
  2405. encountered in the buffer, and the ''most frequent'' value of
  2406. c-basic-offset (@pxref{Customizing Indentation}), then merges the
  2407. current style with these ''guesses'' to form a new style. This
  2408. combined style is known as the @dfn{guessed style}.
  2409. To do this, call @code{c-guess} (or one of the other 5 guessing
  2410. commands) on your sample buffer. The analysis of your code may take
  2411. some time.
  2412. You can then set the guessed style in any @ccmode{} buffer with
  2413. @code{c-guess-install}. You can display the style with
  2414. @code{c-guess-view}, and preserve it by copying it into your
  2415. @file{.emacs} for future use, preferably after editing it.
  2416. @table @asis
  2417. @item @kbd{M-x c-guess-no-install}
  2418. @itemx @kbd{M-x c-guess-buffer-no-install}
  2419. @itemx @kbd{M-x c-guess-region-no-install}
  2420. @findex c-guess-no-install
  2421. @findex c-guess-buffer-no-install
  2422. @findex c-guess-region-no-install
  2423. @findex guess-no-install (c-)
  2424. @findex guess-buffer-no-install (c-)
  2425. @findex guess-region-no-install (c-)
  2426. These commands analyze a part of the current buffer and guess the
  2427. style from it.
  2428. The part of the buffer examined is either the region
  2429. (@code{c-guess-region-no-install}), the entire buffer
  2430. (@code{c-guess-buffer-no-install}), or the first
  2431. @code{c-guess-region-max} bytes (@code{c-guess-no-install}).
  2432. Each of these commands can be given an optional prefix argument. This
  2433. instructs @ccmode{} to combine the new guesses with the current
  2434. guesses before forming the guessed style.
  2435. @end table
  2436. @table @asis
  2437. @item @kbd{M-x c-guess}
  2438. @itemx @kbd{M-x c-guess-buffer}
  2439. @itemx @kbd{M-x c-guess-region}
  2440. @findex c-guess
  2441. @findex c-guess-buffer
  2442. @findex c-guess-region
  2443. @findex guess (c-)
  2444. @findex guess-buffer (c-)
  2445. @findex guess-region (c-)
  2446. These commands analyze a part of the current buffer, guess the style
  2447. from it, then install the guessed style on the buffer. The guessed
  2448. style is given a name based on the buffer's absolute file name, and
  2449. you can then set this style on any @ccmode{} buffer with @kbd{C-c .}.
  2450. The part of the buffer examined is either the region
  2451. (@code{c-guess-region}), the entire buffer (@code{c-guess-buffer}), or
  2452. the first @code{c-guess-region-max} bytes (@code{c-guess}).
  2453. Each of these commands can be given an optional prefix argument. This
  2454. instructs @ccmode{} to combine the new guesses with the current
  2455. guesses before forming the guessed style.
  2456. @end table
  2457. @defopt c-guess-region-max
  2458. @vindex guess-region-max (c-)
  2459. This variable, default 50000, is the size in bytes of the buffer
  2460. portion examined by c-guess and c-guess-no-install. If set to
  2461. @code{nil}, the entire buffer is examined.
  2462. @end defopt
  2463. @defopt c-guess-offset-threshold
  2464. @vindex guess-offset-threshold (c-)
  2465. This variable, default 10, is the maximum offset, either outwards or
  2466. inwards, which will be taken into account by the analysis process.
  2467. Any offset bigger than this will be ignored. For no limit, set this
  2468. variable to a large number.
  2469. @end defopt
  2470. @table @asis
  2471. @item @kbd{M-x c-guess-install}
  2472. @findex c-guess-install
  2473. @findex guess-install (c-)
  2474. Set the current buffer's style to the guessed style. This prompts you
  2475. to enter an optional new style name to give to the guessed style. By
  2476. default, this name is based on the buffer's absolute file name. You
  2477. can then use this style like any other.
  2478. @item @kbd{M-x c-guess-view}
  2479. @findex c-guess-view
  2480. @findex guess-view (c-)
  2481. Display the most recently guessed style in a temporary buffer. This
  2482. display is in the form of a @code{c-add-style} form (@pxref{Adding
  2483. Styles}) which can be easily copied to your @file{.emacs}. You will
  2484. probably want to edit it first.
  2485. The display of the guessed style contains these elements:
  2486. @table @asis
  2487. @item Placeholder Name
  2488. You should replace this with a style name of your own.
  2489. @item Parent Style
  2490. The style current when the guessing began, from which the guessed
  2491. style inherits (@pxref{Config Basics}) the settings which weren't
  2492. guessed.
  2493. @item Guessed Offsets
  2494. These are the core result of the guessing process. Each of them is
  2495. marked by a comment.
  2496. @item Inherited Offsets
  2497. These are syntactic offsets which have been taken over from the parent
  2498. style. To avoid possible future conflicts, you should remove either
  2499. these offsets or the parent style name.
  2500. @end table
  2501. @end table
  2502. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2503. @node File Styles, , Guessing the Style, Styles
  2504. @comment node-name, next, previous, up
  2505. @subsection File Styles
  2506. @cindex styles, file local
  2507. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2508. @cindex file local variables
  2509. The Emacs manual describes how you can customize certain variables on a
  2510. per-file basis by including a @dfn{file local variable} block at the end
  2511. of the file (@pxref{File Variables,, Local Variables in Files,@emacsman{},
  2512. @emacsmantitle{}}).
  2513. So far, you've only seen a functional interface for setting styles in
  2514. @ccmode{}, and this can't be used here. @ccmode{} fills the gap by
  2515. providing two variables for use in a file's local variable list.
  2516. Don't use them anywhere else! These allow you to customize the style
  2517. on a per-file basis:
  2518. @defvar c-file-style
  2519. @vindex file-style (c-)
  2520. Set this variable to a style name string in the Local Variables list.
  2521. From now on, when you visit the file, @ccmode{} will automatically set
  2522. the file's style to this one using @code{c-set-style}.
  2523. @end defvar
  2524. @defvar c-file-offsets
  2525. @vindex file-offsets (c-)
  2526. Set this variable (in the Local Variables list) to an association list
  2527. of the same format as @code{c-offsets-alist}. From now on, when you
  2528. visit the file, @ccmode{} will automatically institute these offsets
  2529. using @code{c-set-offset}.
  2530. @end defvar
  2531. Note that file style settings (i.e., @code{c-file-style}) are applied
  2532. before file offset settings
  2533. (i.e., @code{c-file-offsets})@footnote{Also, if either of these are set
  2534. in a file's local variable section, all the style variable values are
  2535. made local to that buffer, even if
  2536. @code{c-style-variables-are-local-p} is @code{nil}. Since this
  2537. variable is virtually always non-@code{nil} anyhow, you're unlikely to
  2538. notice this effect.}.
  2539. If you set any variable by the file local variables mechanism, that
  2540. setting takes priority over all other settings, even those in your
  2541. mode hooks (@pxref{CC Hooks}). Any individual setting of a variable
  2542. will override one made through @code{c-file-style} or
  2543. @code{c-file-offsets}.
  2544. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2545. @node Custom Filling and Breaking, Custom Auto-newlines, Config Basics, Top
  2546. @comment node-name, next, previous, up
  2547. @chapter Customizing Filling and Line Breaking
  2548. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2549. Since there's a lot of normal text in comments and string literals,
  2550. @ccmode{} provides features to edit these like in text mode. It does
  2551. this by hooking in on the different line breaking functions and tuning
  2552. relevant variables as necessary.
  2553. @vindex c-comment-prefix-regexp
  2554. @vindex comment-prefix-regexp (c-)
  2555. @cindex comment line prefix
  2556. @vindex comment-start
  2557. @vindex comment-end
  2558. @vindex comment-start-skip
  2559. @vindex paragraph-start
  2560. @vindex paragraph-separate
  2561. @vindex paragraph-ignore-fill-prefix
  2562. @vindex adaptive-fill-mode
  2563. @vindex adaptive-fill-regexp
  2564. @vindex adaptive-fill-first-line-regexp
  2565. To make Emacs recognize comments and treat text in them as normal
  2566. paragraphs, @ccmode{} makes several standard
  2567. variables@footnote{@code{comment-start}, @code{comment-end},
  2568. @code{comment-start-skip}, @code{paragraph-start},
  2569. @code{paragraph-separate}, @code{paragraph-ignore-fill-prefix},
  2570. @code{adaptive-fill-mode}, @code{adaptive-fill-regexp}, and
  2571. @code{adaptive-fill-first-line-regexp}.} buffer-local and modifies them
  2572. according to the language syntax and the comment line prefix.
  2573. @defopt c-comment-prefix-regexp
  2574. @vindex comment-prefix-regexp (c-)
  2575. This style variable contains the regexp used to recognize the
  2576. @dfn{comment line prefix}, which is the line decoration that starts
  2577. every line in a comment. The variable is either the comment line
  2578. prefix itself, or (more usually) an association list with different
  2579. values for different languages. The symbol for the major mode is
  2580. looked up in the alist to get the regexp for the language, and if it
  2581. isn't found then the special symbol @samp{other} is looked up instead.
  2582. When a comment line gets divided by @kbd{M-j} or the like, @ccmode{}
  2583. inserts the comment line prefix from a neighboring line at the start
  2584. of the new line. The default value of c-comment-prefix-regexp is
  2585. @samp{//+\\|\\**}, which matches C++ style line comments like
  2586. @example
  2587. // blah blah
  2588. @end example
  2589. @noindent
  2590. with two or more slashes in front of them, and the second and
  2591. subsequent lines of C style block comments like
  2592. @example
  2593. @group
  2594. /*
  2595. * blah blah
  2596. */
  2597. @end group
  2598. @end example
  2599. @noindent
  2600. with zero or more stars at the beginning of every line. If you change
  2601. this variable, please make sure it still matches the comment starter
  2602. (i.e., @code{//}) of line comments @emph{and} the line prefix inside
  2603. block comments.
  2604. @findex c-setup-paragraph-variables
  2605. @findex setup-paragraph-variables (c-)
  2606. Also note that since @ccmode{} uses the value of
  2607. @code{c-comment-prefix-regexp} to set up several other variables at
  2608. mode initialization, there won't be any effect if you just change it
  2609. inside a @ccmode{} buffer. You need to call the command
  2610. @code{c-setup-paragraph-variables} too, to update those other
  2611. variables. That's also the case if you modify
  2612. @code{c-comment-prefix-regexp} in a mode hook, since @ccmode{} will
  2613. already have set up these variables before calling the hook.
  2614. @end defopt
  2615. In comments, @ccmode{} uses @code{c-comment-prefix-regexp} to adapt
  2616. the line prefix from the other lines in the comment.
  2617. @vindex adaptive-fill-mode
  2618. @cindex Adaptive Fill mode
  2619. @ccmode{} uses adaptive fill mode (@pxref{Adaptive Fill,,, emacs, GNU
  2620. Emacs Manual}) to make Emacs correctly keep the line prefix when
  2621. filling paragraphs. That also makes Emacs preserve the text
  2622. indentation @emph{inside} the comment line prefix. E.g., in the
  2623. following comment, both paragraphs will be filled with the left
  2624. margins of the texts kept intact:
  2625. @example
  2626. @group
  2627. /* Make a balanced b-tree of the nodes in the incoming
  2628. * stream. But, to quote the famous words of Donald E.
  2629. * Knuth,
  2630. *
  2631. * Beware of bugs in the above code; I have only
  2632. * proved it correct, not tried it.
  2633. */
  2634. @end group
  2635. @end example
  2636. @findex c-setup-filladapt
  2637. @findex setup-filladapt (c-)
  2638. @findex filladapt-mode
  2639. @vindex filladapt-mode
  2640. @cindex Filladapt mode
  2641. It's also possible to use other adaptive filling packages, notably Kyle
  2642. E. Jones' Filladapt package@footnote{It's available from
  2643. @uref{http://www.wonderworks.com/}. As of version 2.12, it does however
  2644. lack a feature that makes it work suboptimally when
  2645. @code{c-comment-prefix-regexp} matches the empty string (which it does
  2646. by default). A patch for that is available from
  2647. @uref{http://cc-mode.sourceforge.net/,, the CC Mode web site}.},
  2648. @c 2005/11/22: The above is still believed to be the case.
  2649. which handles things like bulleted lists nicely. There's a convenience
  2650. function @code{c-setup-filladapt} that tunes the relevant variables in
  2651. Filladapt for use in @ccmode{}. Call it from a mode hook, e.g., with
  2652. something like this in your @file{.emacs}:
  2653. @example
  2654. (defun my-c-mode-common-hook ()
  2655. (c-setup-filladapt)
  2656. (filladapt-mode 1))
  2657. (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
  2658. @end example
  2659. @defopt c-block-comment-prefix
  2660. @vindex block-comment-prefix (c-)
  2661. @vindex c-comment-continuation-stars
  2662. @vindex comment-continuation-stars (c-)
  2663. Normally the comment line prefix inserted for a new line inside a
  2664. comment is deduced from other lines in it. However there's one
  2665. situation when there's no hint about what the prefix should look like,
  2666. namely when a block comment is broken for the first time. This style
  2667. variable@footnote{In versions before 5.26, this variable was called
  2668. @code{c-comment-continuation-stars}. As a compatibility measure,
  2669. @ccmode{} still uses the value on that variable if it's set.} is used
  2670. then as the comment prefix. It defaults to @samp{*
  2671. }@footnote{Actually, this default setting of
  2672. @code{c-block-comment-prefix} typically gets overridden by the default
  2673. style @code{gnu}, which sets it to blank. You can see the line
  2674. splitting effect described here by setting a different style,
  2675. e.g., @code{k&r} @xref{Choosing a Style}.}, which makes a comment
  2676. @example
  2677. /* Got O(n^2) here, which is a Bad Thing. */
  2678. @end example
  2679. @noindent
  2680. break into
  2681. @example
  2682. @group
  2683. /* Got O(n^2) here, which
  2684. * is a Bad Thing. */
  2685. @end group
  2686. @end example
  2687. Note that it won't work to adjust the indentation by putting leading
  2688. spaces in @code{c-block-comment-prefix}, since @ccmode{} still uses the
  2689. normal indentation engine to indent the line. Thus, the right way to
  2690. fix the indentation is by customizing the @code{c} syntactic symbol. It
  2691. defaults to @code{c-lineup-C-comments}, which handles the indentation of
  2692. most common comment styles, see @ref{Line-Up Functions}.
  2693. @end defopt
  2694. @defopt c-ignore-auto-fill
  2695. @vindex ignore-auto-fill (c-)
  2696. When auto fill mode is enabled, @ccmode{} can selectively ignore it
  2697. depending on the context the line break would occur in, e.g., to never
  2698. break a line automatically inside a string literal. This variable
  2699. takes a list of symbols for the different contexts where auto-filling
  2700. never should occur:
  2701. @table @code
  2702. @item string
  2703. Inside a string or character literal.
  2704. @item c
  2705. Inside a C style block comment.
  2706. @item c++
  2707. Inside a C++ style line comment.
  2708. @item cpp
  2709. Inside a preprocessor directive.
  2710. @item code
  2711. Anywhere else, i.e., in normal code.
  2712. @end table
  2713. By default, @code{c-ignore-auto-fill} is set to @code{(string cpp
  2714. code)}, which means that when auto-fill mode is activated,
  2715. auto-filling only occurs in comments. In literals, it's often
  2716. desirable to have explicit control over newlines. In preprocessor
  2717. directives, the necessary @samp{\} escape character before the newline
  2718. is not automatically inserted, so an automatic line break would
  2719. produce invalid code. In normal code, line breaks are normally
  2720. dictated by some logical structure in the code rather than the last
  2721. whitespace character, so automatic line breaks there will produce poor
  2722. results in the current implementation.
  2723. @end defopt
  2724. @vindex comment-multi-line
  2725. If inside a comment and @code{comment-multi-line} (@pxref{Auto
  2726. Fill,,,@emacsman{}, @emacsmantitle{}} is non-@code{nil}, the
  2727. indentation and
  2728. line prefix are preserved. If inside a comment and
  2729. @code{comment-multi-line} is @code{nil}, a new comment of the same
  2730. type is started on the next line and indented as appropriate for
  2731. comments.
  2732. Note that @ccmode{} sets @code{comment-multi-line} to @code{t} at
  2733. startup. The reason is that @kbd{M-j} could otherwise produce sequences
  2734. of single line block comments for texts that should logically be treated
  2735. as one comment, and the rest of the paragraph handling code
  2736. (e.g., @kbd{M-q} and @kbd{M-a}) can't cope with that, which would lead to
  2737. inconsistent behavior.
  2738. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2739. @node Custom Auto-newlines, Clean-ups, Custom Filling and Breaking, Top
  2740. @comment node-name, next, previous, up
  2741. @chapter Customizing Auto-newlines
  2742. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2743. @ccmode{} determines whether to insert auto-newlines in two basically
  2744. different ways, depending on the character just typed:
  2745. @table @asis
  2746. @item Braces and Colons
  2747. @ccmode{} first determines the syntactic context of the brace or colon
  2748. (@pxref{Syntactic Symbols}), then looks for a corresponding element in
  2749. an alist. This element specifies where to put newlines: this is any
  2750. combination of before and after the brace or colon. If no alist
  2751. element is found, newlines are inserted both before and after a brace,
  2752. but none are inserted around a colon. See @ref{Hanging Braces} and
  2753. @ref{Hanging Colons}.
  2754. @item Semicolons and Commas
  2755. The variable @code{c-hanging-semi&comma-criteria} contains a list of
  2756. functions which determine whether to insert a newline after a newly
  2757. typed semicolon or comma. @xref{Hanging Semicolons and Commas}.
  2758. @end table
  2759. The names of these configuration variables contain @samp{hanging}
  2760. because they let you @dfn{hang} the pertinent characters. A character
  2761. which introduces a C construct is said to @dfn{hang on the right} when
  2762. it appears at the end of a line after other code, being separated by a
  2763. line break from the construct it introduces, like the opening brace in:
  2764. @example
  2765. @group
  2766. while (i < MAX) @{
  2767. total += entry[i];
  2768. entry [i++] = 0;
  2769. @}
  2770. @end group
  2771. @end example
  2772. @noindent
  2773. A character @dfn{hangs on the left} when it appears at the start of
  2774. the line after the construct it closes off, like the above closing
  2775. brace.
  2776. The next chapter, ``Clean-ups'', describes how to configure @ccmode{}
  2777. to remove these automatically added newlines in certain specific
  2778. circumstances. @xref{Clean-ups}.
  2779. @menu
  2780. * Hanging Braces::
  2781. * Hanging Colons::
  2782. * Hanging Semicolons and Commas::
  2783. @end menu
  2784. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2785. @node Hanging Braces, Hanging Colons, Custom Auto-newlines, Custom Auto-newlines
  2786. @comment node-name, next, previous, up
  2787. @section Hanging Braces
  2788. @cindex hanging braces
  2789. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2790. To specify which kinds of braces you want auto-newlines put around,
  2791. you set the style variable @code{c-hanging-braces-alist}. Its
  2792. structure and semantics are described in this section. Details of how
  2793. to set it up, and its relationship to CC Mode's style system are given
  2794. in @ref{Style Variables}.
  2795. Say you wanted an auto-newline after (but not before) the following
  2796. @samp{@{}:
  2797. @example
  2798. if (foo < 17) @{
  2799. @end example
  2800. @noindent
  2801. First you need to find the @dfn{syntactic context} of the brace---type
  2802. a @key{RET} before the brace to get it on a line of its
  2803. own@footnote{Also insert a @samp{\} at the end of the previous line if
  2804. you're in AWK Mode.}, then type @kbd{C-c C-s}. That will tell you
  2805. something like:
  2806. @example
  2807. ((substatement-open 1061))
  2808. @end example
  2809. @noindent
  2810. So here you need to put the entry @code{(substatement-open . (after))}
  2811. into @code{c-hanging-braces-alist}.
  2812. If you don't want any auto-newlines for a particular syntactic symbol,
  2813. put this into @code{c-hanging-braces-alist}:
  2814. @example
  2815. (brace-entry-open)
  2816. @end example
  2817. If some brace syntactic symbol is not in @code{c-hanging-brace-alist},
  2818. its entry is taken by default as @code{(before after)}---insert a
  2819. newline both before and after the brace. In place of a
  2820. ``before/after'' list you can specify a function in this alist---this
  2821. is useful when the auto newlines depend on the code around the brace.
  2822. @defopt c-hanging-braces-alist
  2823. @vindex hanging-braces-alist (c-)
  2824. This variable is an association list which maps syntactic symbols to
  2825. lists of places to insert a newline. @xref{Association
  2826. Lists,,,@lispref{}, @lispreftitle{}}. The key of each element is the
  2827. syntactic symbol, the associated value is either @code{nil}, a list,
  2828. or a function.
  2829. @table @asis
  2830. @item The Key: the syntactic symbol
  2831. The syntactic symbols that are useful as keys in this list are
  2832. @code{brace-list-intro}, @code{statement-cont},
  2833. @code{inexpr-class-open}, @code{inexpr-class-close}, and all the
  2834. @code{*-open} and @code{*-close} symbols. @xref{Syntactic Symbols},
  2835. for a more detailed description of these syntactic symbols, except for
  2836. @code{inexpr-class-open} and @code{inexpr-class-close}, which aren't
  2837. actual syntactic symbols. Elements with any other value as a key get
  2838. ignored.
  2839. The braces of anonymous inner classes in Java are given the special
  2840. symbols @code{inexpr-class-open} and @code{inexpr-class-close}, so that
  2841. they can be distinguished from the braces of normal classes@footnote{The
  2842. braces of anonymous classes produce a combination of
  2843. @code{inexpr-class}, and @code{class-open} or @code{class-close} in
  2844. normal indentation analysis.}.
  2845. Note that the aggregate constructs in Pike mode, @samp{(@{}, @samp{@})},
  2846. @samp{([}, @samp{])}, and @samp{(<}, @samp{>)}, do not count as brace
  2847. lists in this regard, even though they do for normal indentation
  2848. purposes. It's currently not possible to set automatic newlines on
  2849. these constructs.
  2850. @item The associated value: the ``ACTION'' list or function
  2851. The value associated with each syntactic symbol in this association
  2852. list is called an @var{action}, which can be either a list or a
  2853. function which returns a list. @xref{Custom Braces}, for how to use
  2854. a function as a brace hanging @var{action}.
  2855. The list @var{action} (or the list returned by @var{action} when it's
  2856. a function) contains some combination of the symbols @code{before} and
  2857. @code{after}, directing @ccmode{} where to put newlines in
  2858. relationship to the brace being inserted. Thus, if the list contains
  2859. only the symbol @code{after}, then the brace hangs on the right side
  2860. of the line, as in:
  2861. @example
  2862. // here, open braces always 'hang'
  2863. void spam( int i ) @{
  2864. if( i == 7 ) @{
  2865. dosomething(i);
  2866. @}
  2867. @}
  2868. @end example
  2869. When the list contains both @code{after} and @code{before}, the braces
  2870. will appear on a line by themselves, as shown by the close braces in
  2871. the above example. The list can also be empty, in which case newlines
  2872. are added neither before nor after the brace.
  2873. @end table
  2874. If a syntactic symbol is missing entirely from
  2875. @code{c-hanging-braces-alist}, it's treated in the same way as an
  2876. @var{action} with a list containing @code{before} and @code{after}, so
  2877. that braces by default end up on their own line.
  2878. For example, the default value of @code{c-hanging-braces-alist} is:
  2879. @example
  2880. ((brace-list-open)
  2881. (brace-entry-open)
  2882. (statement-cont)
  2883. (substatement-open after)
  2884. (block-close . c-snug-do-while)
  2885. (extern-lang-open after)
  2886. (namespace-open after)
  2887. (module-open after)
  2888. (composition-open after)
  2889. (inexpr-class-open after)
  2890. (inexpr-class-close before))
  2891. @end example
  2892. @noindent which says that @code{brace-list-open},
  2893. @code{brace-entry-open} and @code{statement-cont}@footnote{Brace lists
  2894. inside statements, such as initializers for static array variables
  2895. inside functions in C, are recognized as @code{statement-cont}. All
  2896. normal substatement blocks are recognized with other symbols.} braces
  2897. should both hang on the right side and allow subsequent text to follow
  2898. on the same line as the brace. Also, @code{substatement-open},
  2899. @code{extern-lang-open}, and @code{inexpr-class-open} braces should hang
  2900. on the right side, but subsequent text should follow on the next line.
  2901. The opposite holds for @code{inexpr-class-close} braces; they won't
  2902. hang, but the following text continues on the same line. Here, in the
  2903. @code{block-close} entry, you also see an example of using a function as
  2904. an @var{action}. In all other cases, braces are put on a line by
  2905. themselves.
  2906. @end defopt
  2907. @menu
  2908. * Custom Braces::
  2909. @end menu
  2910. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2911. @node Custom Braces, , Hanging Braces, Hanging Braces
  2912. @comment node-name, next, previous, up
  2913. @subsection Custom Brace Hanging
  2914. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2915. @vindex c-hanging-braces-alist
  2916. @vindex hanging-braces-alist (c-)
  2917. @cindex action functions
  2918. Syntactic symbols aren't the only place where you can customize
  2919. @ccmode{} with the lisp equivalent of callback functions. Remember
  2920. that @var{action}s are usually a list containing some combination of
  2921. the symbols @code{before} and @code{after} (@pxref{Hanging Braces}).
  2922. For more flexibility, you can instead specify brace ``hanginess'' by
  2923. giving a syntactic symbol an @dfn{action function} in
  2924. @code{c-hanging-braces-alist}; this function determines the
  2925. ``hanginess'' of a brace, usually by looking at the code near it.
  2926. @cindex customization, brace hanging
  2927. An action function is called with two arguments: the syntactic symbol
  2928. for the brace (e.g., @code{substatement-open}), and the buffer position
  2929. where the brace has been inserted. Point is undefined on entry to an
  2930. action function, but the function must preserve it (e.g., by using
  2931. @code{save-excursion}). The return value should be a list containing
  2932. some combination of @code{before} and @code{after}, including neither
  2933. of them (i.e., @code{nil}).
  2934. @defvar c-syntactic-context
  2935. @vindex syntactic-context (c-)
  2936. During the call to the indentation or brace hanging @var{action}
  2937. function, this variable is bound to the full syntactic analysis list.
  2938. This might be, for example, @samp{((block-close 73))}. Don't ever
  2939. give @code{c-syntactic-context} a value yourself---this would disrupt
  2940. the proper functioning of @ccmode{}.
  2941. This variable is also bound in three other circumstances:
  2942. (i)@w{ }when calling a c-hanging-semi&comma-criteria function
  2943. (@pxref{Hanging Semicolons and Commas}); (ii)@w{ }when calling a
  2944. line-up function (@pxref{Custom Line-Up}); (iii)@w{ }when calling a
  2945. c-special-indent-hook function (@pxref{Other Indentation}).
  2946. @end defvar
  2947. As an example, @ccmode{} itself uses this feature to dynamically
  2948. determine the hanginess of braces which close ``do-while''
  2949. constructs:
  2950. @example
  2951. void do_list( int count, char** atleast_one_string )
  2952. @{
  2953. int i=0;
  2954. do @{
  2955. handle_string( atleast_one_string[i] );
  2956. i++;
  2957. @} while( i < count );
  2958. @}
  2959. @end example
  2960. @ccmode{} assigns the @code{block-close} syntactic symbol to the
  2961. brace that closes the @code{do} construct, and normally we'd like the
  2962. line that follows a @code{block-close} brace to begin on a separate
  2963. line. However, with ``do-while'' constructs, we want the
  2964. @code{while} clause to follow the closing brace. To do this, we
  2965. associate the @code{block-close} symbol with the @var{action} function
  2966. @code{c-snug-do-while}:
  2967. @example
  2968. (defun c-snug-do-while (syntax pos)
  2969. "Dynamically calculate brace hanginess for do-while statements."
  2970. (save-excursion
  2971. (let (langelem)
  2972. (if (and (eq syntax 'block-close)
  2973. (setq langelem (assq 'block-close c-syntactic-context))
  2974. (progn (goto-char (cdr langelem))
  2975. (if (= (following-char) ?@{)
  2976. (forward-sexp -1))
  2977. (looking-at "\\<do\\>[^_]")))
  2978. '(before)
  2979. '(before after)))))
  2980. @end example
  2981. @findex c-snug-do-while
  2982. @findex snug-do-while (c-)
  2983. This function simply looks to see if the brace closes a ``do-while''
  2984. clause and if so, returns the list @samp{(before)} indicating
  2985. that a newline should be inserted before the brace, but not after it.
  2986. In all other cases, it returns the list @samp{(before after)} so
  2987. that the brace appears on a line by itself.
  2988. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2989. @node Hanging Colons, Hanging Semicolons and Commas, Hanging Braces, Custom Auto-newlines
  2990. @comment node-name, next, previous, up
  2991. @section Hanging Colons
  2992. @cindex hanging colons
  2993. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2994. @cindex customization, colon hanging
  2995. @vindex c-hanging-colons-alist
  2996. @vindex hanging-colons-alist (c-)
  2997. Using a mechanism similar to brace hanging (@pxref{Hanging Braces}),
  2998. colons can also be made to hang using the style variable
  2999. @code{c-hanging-colons-alist}: when a colon is typed, @ccmode
  3000. determines its syntactic context, looks this up in the alist
  3001. @code{c-changing-colons-alist} and inserts up to two newlines
  3002. accordingly. Here, however, If @ccmode fails to find an entry for a
  3003. syntactic symbol in the alist, no newlines are inserted around the
  3004. newly typed colon.
  3005. @defopt c-hanging-colons-alist
  3006. @vindex hanging-colons-alist (c-)
  3007. @table @asis
  3008. @item The Key: the syntactic symbol
  3009. The syntactic symbols appropriate as keys in this association list
  3010. are: @code{case-label}, @code{label}, @code{access-label},
  3011. @code{member-init-intro}, and @code{inher-intro}. @xref{Syntactic
  3012. Symbols}. Elements with any other value as a key get ignored.
  3013. @item The associated value: the ``ACTION'' list
  3014. The @var{action} here is simply a list containing a combination of the
  3015. symbols @code{before} and @code{after}. Unlike in
  3016. @code{c-hanging-braces-alist}, functions as @var{actions} are not
  3017. supported; there doesn't seem to be any need for them.
  3018. @end table
  3019. @end defopt
  3020. In C++, double-colons are used as a scope operator but because these
  3021. colons always appear right next to each other, newlines before and after
  3022. them are controlled by a different mechanism, called @dfn{clean-ups} in
  3023. @ccmode{}. @xref{Clean-ups}, for details.
  3024. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3025. @node Hanging Semicolons and Commas, , Hanging Colons, Custom Auto-newlines
  3026. @comment node-name, next, previous, up
  3027. @section Hanging Semicolons and Commas
  3028. @cindex hanging semicolons
  3029. @cindex hanging commas
  3030. @cindex customization, semicolon newlines
  3031. @cindex customization, comma newlines
  3032. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3033. @defopt c-hanging-semi&comma-criteria
  3034. @vindex hanging-semi&comma-criteria (c-)
  3035. This style variable takes a list of functions; these get called when
  3036. you type a semicolon or comma. The functions are called in order
  3037. without arguments. When these functions are entered, point is just
  3038. after the newly inserted @samp{;} or @samp{,} and they must preserve
  3039. point (e.g., by using @code{save-excursion}). During the call, the
  3040. variable @code{c-syntactic-context} is bound to the syntactic context
  3041. of the current line@footnote{This was first introduced in @ccmode{}
  3042. 5.31.} @pxref{Custom Braces}. These functions don't insert newlines
  3043. themselves, rather they direct @ccmode{} whether or not to do so.
  3044. They should return one of the following values:
  3045. @table @code
  3046. @item t
  3047. A newline is to be inserted after the @samp{;} or @samp{,}, and no
  3048. more functions from the list are to be called.
  3049. @item stop
  3050. No more functions from the list are to be called, and no newline is to
  3051. be inserted.
  3052. @item nil
  3053. No determination has been made, and the next function in the list is
  3054. to be called.
  3055. @end table
  3056. Note that auto-newlines are never inserted @emph{before} a semicolon
  3057. or comma. If every function in the list is called without a
  3058. determination being made, then no newline is added.
  3059. In AWK mode, this variable is set by default to @code{nil}. In the
  3060. other modes, the default value is a list containing a single function,
  3061. @code{c-semi&comma-inside-parenlist}. This inserts newlines after all
  3062. semicolons, apart from those separating @code{for}-clause statements.
  3063. @end defopt
  3064. @defun c-semi&comma-no-newlines-before-nonblanks
  3065. @findex semi&comma-no-newlines-before-nonblanks (c-)
  3066. This is an example of a criteria function, provided by @ccmode{}. It
  3067. prevents newlines from being inserted after semicolons when there is a
  3068. non-blank following line. Otherwise, it makes no determination. To
  3069. use, add this function to the front of the
  3070. @code{c-hanging-semi&comma-criteria} list.
  3071. @example
  3072. (defun c-semi&comma-no-newlines-before-nonblanks ()
  3073. (save-excursion
  3074. (if (and (= (c-last-command-char) ?\;)
  3075. (zerop (forward-line 1))
  3076. (bolp) ; forward-line has funny behavior at eob.
  3077. (not (looking-at "^[ \t]*$")))
  3078. 'stop
  3079. nil)))
  3080. @end example
  3081. @end defun
  3082. @defun c-semi&comma-inside-parenlist
  3083. @findex semi&comma-inside-parenlist (c-)
  3084. @defunx c-semi&comma-no-newlines-for-oneline-inliners
  3085. @findex semi&comma-no-newlines-for-oneline-inliners (c-)
  3086. The function @code{c-semi&comma-inside-parenlist} is what prevents
  3087. newlines from being inserted inside the parenthesis list of @code{for}
  3088. statements. In addition to
  3089. @code{c-semi&comma-no-newlines-before-nonblanks} described above,
  3090. @ccmode{} also comes with the criteria function
  3091. @code{c-semi&comma-no-newlines-for-oneline-inliners}, which suppresses
  3092. newlines after semicolons inside one-line inline method definitions
  3093. (e.g., in C++ or Java).
  3094. @end defun
  3095. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3096. @node Clean-ups, Indentation Engine Basics, Custom Auto-newlines, Top
  3097. @comment node-name, next, previous, up
  3098. @chapter Clean-ups
  3099. @cindex clean-ups
  3100. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3101. @dfn{Clean-ups} are mechanisms which remove (or exceptionally, add)
  3102. whitespace in specific circumstances and are complementary to colon
  3103. and brace hanging. You enable a clean-up by adding its symbol into
  3104. @code{c-cleanup-list}, e.g., like this:
  3105. @example
  3106. (add-to-list 'c-cleanup-list 'space-before-funcall)
  3107. @end example
  3108. On the surface, it would seem that clean-ups overlap the functionality
  3109. provided by the @code{c-hanging-*-alist} variables. Clean-ups,
  3110. however, are used to adjust code ``after-the-fact'', i.e., to adjust
  3111. the whitespace in constructs later than when they were typed.
  3112. Most of the clean-ups remove automatically inserted newlines, and are
  3113. only active when auto-newline minor mode is turned on. Others will
  3114. work all the time. Note that clean-ups are only performed when there
  3115. is nothing but whitespace appearing between the individual components
  3116. of the construct, and (apart from @code{comment-close-slash}) when the
  3117. construct does not occur within a literal (@pxref{Auto-newlines}).
  3118. @defopt c-cleanup-list
  3119. @vindex cleanup-list (c-)
  3120. @cindex literal
  3121. You configure @ccmode{}'s clean-ups by setting the style variable
  3122. @code{c-cleanup-list}, which is a list of clean-up symbols. By
  3123. default, @ccmode{} cleans up only the @code{scope-operator} construct,
  3124. which is necessary for proper C++ support.
  3125. @end defopt
  3126. These are the clean-ups that are only active when electric and
  3127. auto-newline minor modes are enabled:
  3128. @c TBD: Would like to use some sort of @deffoo here; @table indents a
  3129. @c bit too much in dvi output.
  3130. @table @code
  3131. @item brace-else-brace
  3132. Clean up @samp{@} else @{} constructs by placing the entire construct on
  3133. a single line. Clean up occurs when the open brace after the
  3134. @samp{else} is typed. So for example, this:
  3135. @example
  3136. @group
  3137. void spam(int i)
  3138. @{
  3139. if( i==7 ) @{
  3140. dosomething();
  3141. @}
  3142. else
  3143. @{
  3144. @end group
  3145. @end example
  3146. @noindent
  3147. appears like this after the last open brace is typed:
  3148. @example
  3149. @group
  3150. void spam(int i)
  3151. @{
  3152. if( i==7 ) @{
  3153. dosomething();
  3154. @} else @{
  3155. @end group
  3156. @end example
  3157. @item brace-elseif-brace
  3158. Similar to the @code{brace-else-brace} clean-up, but this cleans up
  3159. @samp{@} else if (...) @{} constructs. For example:
  3160. @example
  3161. @group
  3162. void spam(int i)
  3163. @{
  3164. if( i==7 ) @{
  3165. dosomething();
  3166. @}
  3167. else if( i==3 )
  3168. @{
  3169. @end group
  3170. @end example
  3171. @noindent
  3172. appears like this after the last open parenthesis is typed:
  3173. @example
  3174. @group
  3175. void spam(int i)
  3176. @{
  3177. if( i==7 ) @{
  3178. dosomething();
  3179. @} else if(
  3180. @end group
  3181. @end example
  3182. @noindent
  3183. and like this after the last open brace is typed:
  3184. @example
  3185. @group
  3186. void spam(int i)
  3187. @{
  3188. if( i==7 ) @{
  3189. dosomething();
  3190. @} else if( i==3 ) @{
  3191. @end group
  3192. @end example
  3193. @item brace-catch-brace
  3194. Analogous to @code{brace-elseif-brace}, but cleans up @samp{@} catch
  3195. (...) @{} in C++ and Java mode.
  3196. @item empty-defun-braces
  3197. Clean up braces following a top-level function or class definition that
  3198. contains no body. Clean up occurs when the closing brace is typed.
  3199. Thus the following:
  3200. @example
  3201. @group
  3202. class Spam
  3203. @{
  3204. @}
  3205. @end group
  3206. @end example
  3207. @noindent
  3208. is transformed into this when the close brace is typed:
  3209. @example
  3210. @group
  3211. class Spam
  3212. @{@}
  3213. @end group
  3214. @end example
  3215. @item defun-close-semi
  3216. Clean up the terminating semicolon on top-level function or class
  3217. definitions when they follow a close brace. Clean up occurs when the
  3218. semicolon is typed. So for example, the following:
  3219. @example
  3220. @group
  3221. class Spam
  3222. @{
  3223. ...
  3224. @}
  3225. ;
  3226. @end group
  3227. @end example
  3228. @noindent
  3229. is transformed into this when the semicolon is typed:
  3230. @example
  3231. @group
  3232. class Spam
  3233. @{
  3234. ...
  3235. @};
  3236. @end group
  3237. @end example
  3238. @item list-close-comma
  3239. Clean up commas following braces in array and aggregate initializers.
  3240. Clean up occurs when the comma is typed. The space before the comma
  3241. is zapped just like the space before the semicolon in
  3242. @code{defun-close-semi}.
  3243. @item scope-operator
  3244. Clean up double colons which might designate a C++ scope operator split
  3245. across multiple lines@footnote{Certain C++ constructs introduce
  3246. ambiguous situations, so @code{scope-operator} clean-ups might not
  3247. always be correct. This usually only occurs when scoped identifiers
  3248. appear in switch label tags.}. Clean up occurs when the second colon is
  3249. typed. You will always want @code{scope-operator} in the
  3250. @code{c-cleanup-list} when you are editing C++ code.
  3251. @item one-liner-defun
  3252. Clean up a single line of code enclosed by defun braces by removing
  3253. the whitespace before and after the code. The clean-up happens when
  3254. the closing brace is typed. If the variable
  3255. @code{c-max-one-liner-length} is set, the cleanup is only done if the
  3256. resulting line would be no longer than the value of that variable.
  3257. For example, consider this AWK code:
  3258. @example
  3259. @group
  3260. BEGIN @{
  3261. FS = "\t" # use <TAB> as a field separator
  3262. @}
  3263. @end group
  3264. @end example
  3265. @noindent
  3266. It gets compacted to the following when the closing brace is typed:
  3267. @example
  3268. @group
  3269. BEGIN @{FS = "\t"@} # use <TAB> as a field separator
  3270. @end group
  3271. @end example
  3272. @defopt c-max-one-liner-length
  3273. @vindex max-one-liner-length (c-)
  3274. The maximum length of the resulting line for which the clean-up
  3275. @code{one-liner-defun} will be triggered. This length is that of the entire
  3276. line, including any leading whitespace and any trailing comment. Its
  3277. default value is 80. If the value is zero or @code{nil}, no limit
  3278. applies.
  3279. @end defopt
  3280. @end table
  3281. The following clean-ups are always active when they occur on
  3282. @code{c-cleanup-list}, regardless of whether Electric minor mode or
  3283. Auto-newline minor mode are enabled:
  3284. @table @code
  3285. @item space-before-funcall
  3286. Insert a space between the function name and the opening parenthesis
  3287. of a function call. This produces function calls in the style
  3288. mandated by the GNU coding standards, e.g., @samp{signal@w{ }(SIGINT,
  3289. SIG_IGN)} and @samp{abort@w{ }()}. Clean up occurs when the opening
  3290. parenthesis is typed. This clean-up should never be active in AWK
  3291. Mode, since such a space is syntactically invalid for user defined
  3292. functions.
  3293. @item compact-empty-funcall
  3294. Clean up any space between the function name and the opening parenthesis
  3295. of a function call that has no arguments. This is typically used
  3296. together with @code{space-before-funcall} if you prefer the GNU function
  3297. call style for functions with arguments but think it looks ugly when
  3298. it's only an empty parenthesis pair. I.e., you will get @samp{signal
  3299. (SIGINT, SIG_IGN)}, but @samp{abort()}. Clean up occurs when the
  3300. closing parenthesis is typed.
  3301. @item comment-close-slash
  3302. When inside a block comment, terminate the comment when you type a slash
  3303. at the beginning of a line (i.e., immediately after the comment prefix).
  3304. This clean-up removes whitespace preceding the slash and if needed,
  3305. inserts a star to complete the token @samp{*/}. Type @kbd{C-q /} in this
  3306. situation if you just want a literal @samp{/} inserted.
  3307. @end table
  3308. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3309. @node Indentation Engine Basics, Customizing Indentation, Clean-ups, Top
  3310. @comment node-name, next, previous, up
  3311. @chapter Indentation Engine Basics
  3312. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3313. This chapter will briefly cover how @ccmode{} indents lines of code.
  3314. It is helpful to understand the indentation model being used so that
  3315. you will know how to customize @ccmode{} for your personal coding
  3316. style. All the details are in @ref{Customizing Indentation}.
  3317. @ccmode{} has an indentation engine that provides a flexible and
  3318. general mechanism for customizing indentation. When @ccmode{} indents
  3319. a line of code, it separates its calculations into two steps:
  3320. @enumerate
  3321. @item
  3322. @cindex syntactic symbol
  3323. @cindex anchor position
  3324. It analyzes the line to determine its @dfn{syntactic symbol(s)} (the
  3325. kind of language construct it's looking at) and its @dfn{anchor
  3326. position} (the position earlier in the file that @ccmode{} will indent
  3327. the line relative to). The anchor position might be the location of
  3328. an opening brace in the previous line, for example. @xref{Syntactic
  3329. Analysis}.
  3330. @item
  3331. @cindex offsets
  3332. @cindex indentation offset specifications
  3333. It looks up the syntactic symbol(s) in the configuration to get the
  3334. corresponding @dfn{offset(s)}. The symbol @code{+}, which means
  3335. ``indent this line one more level'' is a typical offset. @ccmode{}
  3336. then applies these offset(s) to the anchor position, giving the
  3337. indentation for the line. The different sorts of offsets are
  3338. described in @ref{c-offsets-alist}.
  3339. @end enumerate
  3340. In exceptional circumstances, the syntax directed indentation
  3341. described here may be a nuisance rather than a help. You can disable
  3342. it by setting @code{c-syntactic-indentation} to @code{nil}. (To set
  3343. the variable interactively, @ref{Minor Modes}).
  3344. @defopt c-syntactic-indentation
  3345. @vindex syntactic-indentation (c-)
  3346. When this is non-@code{nil} (which it is by default), the indentation
  3347. of code is done according to its syntactic structure. When it's
  3348. @code{nil}, every line is just indented to the same level as the
  3349. previous one, and @kbd{TAB} (@code{c-indent-command}) adjusts the
  3350. indentation in steps of @code{c-basic-offset}. The current style
  3351. (@pxref{Config Basics}) then has no effect on indentation, nor do any
  3352. of the variables associated with indentation, not even
  3353. @code{c-special-indent-hook}.
  3354. @end defopt
  3355. @menu
  3356. * Syntactic Analysis::
  3357. * Syntactic Symbols::
  3358. * Indentation Calculation::
  3359. @end menu
  3360. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3361. @node Syntactic Analysis, Syntactic Symbols, Indentation Engine Basics, Indentation Engine Basics
  3362. @comment node-name, next, previous, up
  3363. @section Syntactic Analysis
  3364. @cindex syntactic analysis
  3365. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3366. @cindex syntactic element
  3367. @cindex syntactic context
  3368. The first thing @ccmode{} does when indenting a line of code, is to
  3369. analyze the line by calling @code{c-guess-basic-syntax}, determining
  3370. the syntactic context of the (first) construct on that line. Although
  3371. this function is mainly used internally, it can sometimes be useful in
  3372. Line-up functions (@pxref{Custom Line-Up}) or in functions on
  3373. @code{c-special-indent-hook} (@pxref{Other Indentation}).
  3374. @defun c-guess-basic-syntax
  3375. @findex guess-basic-syntax (c-)
  3376. Determine the syntactic context of the current line.
  3377. @end defun
  3378. The @dfn{syntactic context} is a list of @dfn{syntactic elements},
  3379. where each syntactic element in turn is a list@footnote{In
  3380. @ccmode 5.28 and earlier, a syntactic element was a dotted pair; the
  3381. cons was the syntactic symbol and the cdr was the anchor position.
  3382. For compatibility's sake, the parameter passed to a line-up function
  3383. still has this dotted pair form (@pxref{Custom Line-Up}).} Here is a
  3384. brief and typical example:
  3385. @example
  3386. ((defun-block-intro 1959))
  3387. @end example
  3388. @cindex syntactic symbol
  3389. @noindent
  3390. The first thing inside each syntactic element is always a
  3391. @dfn{syntactic symbol}. It describes the kind of construct that was
  3392. recognized, e.g., @code{statement}, @code{substatement},
  3393. @code{class-open}, @code{class-close}, etc. @xref{Syntactic Symbols},
  3394. for a complete list of currently recognized syntactic symbols and
  3395. their semantics. The remaining entries are various data associated
  3396. with the recognized construct; there might be zero or more.
  3397. @cindex anchor position
  3398. Conceptually, a line of code is always indented relative to some
  3399. position higher up in the buffer (typically the indentation of the
  3400. previous line). That position is the @dfn{anchor position} in the
  3401. syntactic element. If there is an entry after the syntactic symbol in
  3402. the syntactic element list then it's either @code{nil} or that anchor position.
  3403. Here is an example. Suppose we had the following code as the only thing
  3404. in a C++ buffer @footnote{The line numbers in this and future examples
  3405. don't actually appear in the buffer, of course!}:
  3406. @example
  3407. 1: void swap( int& a, int& b )
  3408. 2: @{
  3409. 3: int tmp = a;
  3410. 4: a = b;
  3411. 5: b = tmp;
  3412. 6: @}
  3413. @end example
  3414. @noindent
  3415. We can use @kbd{C-c C-s} (@code{c-show-syntactic-information}) to
  3416. report what the syntactic analysis is for the current line:
  3417. @table @asis
  3418. @item @kbd{C-c C-s} (@code{c-show-syntactic-information})
  3419. @kindex C-c C-s
  3420. @findex c-show-syntactic-information
  3421. @findex show-syntactic-information (c-)
  3422. This command calculates the syntactic analysis of the current line and
  3423. displays it in the minibuffer. The command also highlights the anchor
  3424. position(s).
  3425. @end table
  3426. Running this command on line 4 of this example, we'd see in the echo
  3427. area@footnote{With a universal argument (i.e., @kbd{C-u C-c C-s}) the
  3428. analysis is inserted into the buffer as a comment on the current
  3429. line.}:
  3430. @example
  3431. ((statement 35))
  3432. @end example
  3433. @noindent
  3434. and the @samp{i} of @code{int} on line 3 would be highlighted. This
  3435. tells us that the line is a statement and it is indented relative to
  3436. buffer position 35, the highlighted position. If you were to move
  3437. point to line 3 and hit @kbd{C-c C-s}, you would see:
  3438. @example
  3439. ((defun-block-intro 29))
  3440. @end example
  3441. @noindent
  3442. This indicates that the @samp{int} line is the first statement in a top
  3443. level function block, and is indented relative to buffer position 29,
  3444. which is the brace just after the function header.
  3445. Here's another example:
  3446. @example
  3447. 1: int add( int val, int incr, int doit )
  3448. 2: @{
  3449. 3: if( doit )
  3450. 4: @{
  3451. 5: return( val + incr );
  3452. 6: @}
  3453. 7: return( val );
  3454. 8: @}
  3455. @end example
  3456. @noindent
  3457. Hitting @kbd{C-c C-s} on line 4 gives us:
  3458. @example
  3459. ((substatement-open 46))
  3460. @end example
  3461. @cindex substatement
  3462. @cindex substatement block
  3463. @noindent
  3464. which tells us that this is a brace that @emph{opens} a substatement
  3465. block.@footnote{A @dfn{substatement} is the line after a
  3466. conditional statement, such as @code{if}, @code{else}, @code{while},
  3467. @code{do}, @code{switch}, etc. A @dfn{substatement
  3468. block} is a brace block following one of these conditional statements.}
  3469. @cindex comment-only line
  3470. Syntactic contexts can contain more than one element, and syntactic
  3471. elements need not have anchor positions. The most common example of
  3472. this is a @dfn{comment-only line}:
  3473. @example
  3474. 1: void draw_list( List<Drawables>& drawables )
  3475. 2: @{
  3476. 3: // call the virtual draw() method on each element in list
  3477. 4: for( int i=0; i < drawables.count(), ++i )
  3478. 5: @{
  3479. 6: drawables[i].draw();
  3480. 7: @}
  3481. 8: @}
  3482. @end example
  3483. @noindent
  3484. Hitting @kbd{C-c C-s} on line 3 of this example gives:
  3485. @example
  3486. ((comment-intro) (defun-block-intro 46))
  3487. @end example
  3488. @noindent
  3489. and you can see that the syntactic context contains two syntactic
  3490. elements. Notice that the first element, @samp{(comment-intro)}, has no
  3491. anchor position.
  3492. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3493. @node Syntactic Symbols, Indentation Calculation, Syntactic Analysis, Indentation Engine Basics
  3494. @comment node-name, next, previous, up
  3495. @section Syntactic Symbols
  3496. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3497. @cindex syntactic symbols, brief list
  3498. @vindex c-offsets-alist
  3499. @vindex offsets-alist (c-)
  3500. This section is a complete list of the syntactic symbols which appear
  3501. in the @code{c-offsets-alist} style variable, along with brief
  3502. descriptions. The previous section (@pxref{Syntactic Analysis})
  3503. states what syntactic symbols are and how the indentation engine uses
  3504. them.
  3505. More detailed descriptions of these symbols, together with snippets of
  3506. source code to which they apply, appear in the examples in the
  3507. subsections below. Note that, in the interests of brevity, the anchor
  3508. position associated with most syntactic symbols is @emph{not}
  3509. specified. In cases of doubt, type @kbd{C-c C-s} on a pertinent
  3510. line---this highlights the anchor position.
  3511. @ssindex -open symbols
  3512. @ssindex -close symbols
  3513. @ssindex -block-intro symbols
  3514. The syntactic symbols which indicate brace constructs follow a general
  3515. naming convention. When a line begins with an open or close brace,
  3516. its syntactic symbol will contain the suffix @code{-open} or
  3517. @code{-close} respectively. The first line within the brace block
  3518. construct will contain the suffix @code{-block-intro}.
  3519. @ssindex -intro symbols
  3520. @ssindex -cont symbols
  3521. In constructs which can span several lines, a distinction is usually
  3522. made between the first line that introduces the construct and the
  3523. lines that continue it. The syntactic symbols that indicate these
  3524. lines will contain the suffixes @code{-intro} or @code{-cont}
  3525. respectively.
  3526. The best way to understand how all this works is by looking at some
  3527. examples. Remember that you can see the syntax of any source code
  3528. line by using @kbd{C-c C-s}.
  3529. @table @code
  3530. @item string
  3531. Inside a multiline string. @ref{Literal Symbols}.
  3532. @item c
  3533. Inside a multiline C style block comment. @ref{Literal Symbols}.
  3534. @item defun-open
  3535. Brace that opens a top-level function definition. @ref{Function
  3536. Symbols}.
  3537. @item defun-close
  3538. Brace that closes a top-level function definition. @ref{Function
  3539. Symbols}.
  3540. @item defun-block-intro
  3541. The first line in a top-level defun. @ref{Function Symbols}.
  3542. @item class-open
  3543. Brace that opens a class definition. @ref{Class Symbols}.
  3544. @item class-close
  3545. Brace that closes a class definition. @ref{Class Symbols}.
  3546. @item inline-open
  3547. Brace that opens an in-class inline method. @ref{Class Symbols}.
  3548. @item inline-close
  3549. Brace that closes an in-class inline method. @ref{Class Symbols}.
  3550. @item func-decl-cont
  3551. The region between a function definition's argument list and the
  3552. function opening brace (excluding K&R argument declarations). In C,
  3553. you cannot put anything but whitespace and comments in this region,
  3554. however in C++ and Java, @code{throws} declarations and other things
  3555. can appear here. @ref{Literal Symbols}. @c @emph{FIXME!!! Can it not
  3556. @c go somewhere better?}
  3557. @item knr-argdecl-intro
  3558. First line of a K&R C argument declaration. @ref{K&R Symbols}.
  3559. @item knr-argdecl
  3560. Subsequent lines in a K&R C argument declaration. @ref{K&R Symbols}.
  3561. @item topmost-intro
  3562. The first line in a ``topmost'' definition. @ref{Function Symbols}.
  3563. @item topmost-intro-cont
  3564. Topmost definition continuation lines. This is only used in the parts
  3565. that aren't covered by other symbols such as @code{func-decl-cont} and
  3566. @code{knr-argdecl}. @ref{Function Symbols}.
  3567. @item annotation-top-cont
  3568. Topmost definition continuation lines where all previous items are
  3569. annotations. @ref{Java Symbols}.
  3570. @item member-init-intro
  3571. First line in a member initialization list. @ref{Class Symbols}.
  3572. @item member-init-cont
  3573. Subsequent member initialization list lines. @ref{Class Symbols}.
  3574. @item inher-intro
  3575. First line of a multiple inheritance list. @ref{Class Symbols}.
  3576. @item inher-cont
  3577. Subsequent multiple inheritance lines. @ref{Class Symbols}.
  3578. @item block-open
  3579. Statement block open brace. @ref{Literal Symbols}.
  3580. @item block-close
  3581. Statement block close brace. @ref{Conditional Construct Symbols}.
  3582. @item brace-list-open
  3583. Open brace of an enum or static array list. @ref{Brace List Symbols}.
  3584. @item brace-list-close
  3585. Close brace of an enum or static array list. @ref{Brace List Symbols}.
  3586. @item brace-list-intro
  3587. First line after the opening @samp{@{} in an enum or static array
  3588. list. @ref{Brace List Symbols}.
  3589. @item brace-list-entry
  3590. Subsequent lines in an enum or static array list. @ref{Brace List
  3591. Symbols}.
  3592. @item brace-entry-open
  3593. Subsequent lines in an enum or static array list where the line begins
  3594. with an open brace. @ref{Brace List Symbols}.
  3595. @item statement
  3596. A statement. @ref{Function Symbols}.
  3597. @item statement-cont
  3598. A continuation of a statement. @ref{Function Symbols}.
  3599. @item annotation-var-cont
  3600. A continuation of a statement where all previous items are
  3601. annotations. @ref{Java Symbols}.
  3602. @item statement-block-intro
  3603. The first line in a new statement block. @ref{Conditional Construct
  3604. Symbols}.
  3605. @item statement-case-intro
  3606. The first line in a case block. @ref{Switch Statement Symbols}.
  3607. @item statement-case-open
  3608. The first line in a case block that starts with a brace. @ref{Switch
  3609. Statement Symbols}.
  3610. @item substatement
  3611. The first line after a conditional or loop construct.
  3612. @ref{Conditional Construct Symbols}.
  3613. @item substatement-open
  3614. The brace that opens a substatement block. @ref{Conditional Construct
  3615. Symbols}.
  3616. @item substatement-label
  3617. The first line after a conditional or loop construct if it's a label.
  3618. @ref{Conditional Construct Symbols}.
  3619. @item case-label
  3620. A label in a @code{switch} block. @ref{Switch Statement Symbols}.
  3621. @item access-label
  3622. C++ access control label. @ref{Class Symbols}.
  3623. @item label
  3624. Any other label. @ref{Literal Symbols}.
  3625. @item do-while-closure
  3626. The @code{while} line that ends a @code{do}-@code{while} construct.
  3627. @ref{Conditional Construct Symbols}.
  3628. @item else-clause
  3629. The @code{else} line of an @code{if}-@code{else} construct.
  3630. @ref{Conditional Construct Symbols}.
  3631. @item catch-clause
  3632. The @code{catch} or @code{finally} (in Java) line of a
  3633. @code{try}-@code{catch} construct. @ref{Conditional Construct
  3634. Symbols}.
  3635. @item comment-intro
  3636. A line containing only a comment introduction. @ref{Literal Symbols}.
  3637. @item arglist-intro
  3638. The first line in an argument list. @ref{Paren List Symbols}.
  3639. @item arglist-cont
  3640. Subsequent argument list lines when no arguments follow on the same
  3641. line as the arglist opening paren. @ref{Paren List Symbols}.
  3642. @item arglist-cont-nonempty
  3643. Subsequent argument list lines when at least one argument follows on
  3644. the same line as the arglist opening paren. @ref{Paren List Symbols}.
  3645. @item arglist-close
  3646. The solo close paren of an argument list. @ref{Paren List Symbols}.
  3647. @item stream-op
  3648. Lines continuing a stream operator (C++ only). @ref{Literal
  3649. Symbols}. @c @emph{FIXME!!! Can this not be moved somewhere better?}
  3650. @item inclass
  3651. The line is nested inside a class definition. @ref{Class Symbols}.
  3652. @item cpp-macro
  3653. The start of a preprocessor macro definition. @ref{Literal Symbols}.
  3654. @item cpp-define-intro
  3655. The first line inside a multiline preprocessor macro if
  3656. @code{c-syntactic-indentation-in-macros} is set. @ref{Multiline Macro
  3657. Symbols}.
  3658. @item cpp-macro-cont
  3659. All lines inside multiline preprocessor macros if
  3660. @code{c-syntactic-indentation-in-macros} is @code{nil}.
  3661. @ref{Multiline Macro Symbols}.
  3662. @item friend
  3663. A C++ friend declaration. @ref{Class Symbols}.
  3664. @item objc-method-intro
  3665. The first line of an Objective-C method definition. @ref{Objective-C
  3666. Method Symbols}.
  3667. @item objc-method-args-cont
  3668. Lines continuing an Objective-C method definition. @ref{Objective-C
  3669. Method Symbols}.
  3670. @item objc-method-call-cont
  3671. Lines continuing an Objective-C method call. @ref{Objective-C Method
  3672. Symbols}.
  3673. @item extern-lang-open
  3674. Brace that opens an @code{extern} block (e.g., @code{extern "C"
  3675. @{...@}}). @ref{External Scope Symbols}.
  3676. @item extern-lang-close
  3677. Brace that closes an @code{extern} block. @ref{External Scope
  3678. Symbols}.
  3679. @item inextern-lang
  3680. Analogous to @code{inclass} syntactic symbol, but used inside
  3681. @code{extern} blocks. @ref{External Scope Symbols}.
  3682. @item namespace-open
  3683. @itemx namespace-close
  3684. @itemx innamespace
  3685. These are analogous to the three @code{extern-lang} symbols above, but
  3686. are returned for C++ namespace blocks. @ref{External Scope Symbols}.
  3687. @item module-open
  3688. @itemx module-close
  3689. @itemx inmodule
  3690. Analogous to the above, but for CORBA IDL @code{module} blocks.
  3691. @ref{External Scope Symbols}.
  3692. @item composition-open
  3693. @itemx composition-close
  3694. @itemx incomposition
  3695. Analogous to the above, but for CORBA CIDL @code{composition} blocks.
  3696. @ref{External Scope Symbols}.
  3697. @item template-args-cont
  3698. C++ template argument list continuations. @ref{Class Symbols}.
  3699. @item inlambda
  3700. Analogous to @code{inclass} syntactic symbol, but used inside lambda
  3701. (i.e., anonymous) functions. Used in C++ and Pike modes.
  3702. @ref{Statement Block Symbols}.
  3703. @item lambda-intro-cont
  3704. Lines continuing the header of a lambda function, i.e., between the
  3705. @code{lambda} keyword and the function body. Only used in Pike mode.
  3706. @ref{Statement Block Symbols}.
  3707. @item inexpr-statement
  3708. A statement block inside an expression. The gcc C and C++ extension
  3709. for this is recognized. It's also used for the special functions that
  3710. take a statement block as an argument in Pike. @ref{Statement Block
  3711. Symbols}.
  3712. @item inexpr-class
  3713. A class definition inside an expression. This is used for anonymous
  3714. classes in Java. It's also used for anonymous array initializers in
  3715. Java. @ref{Java Symbols}.
  3716. @end table
  3717. @menu
  3718. * Function Symbols::
  3719. * Class Symbols::
  3720. * Conditional Construct Symbols::
  3721. * Switch Statement Symbols::
  3722. * Brace List Symbols::
  3723. * External Scope Symbols::
  3724. * Paren List Symbols::
  3725. * Literal Symbols::
  3726. * Multiline Macro Symbols::
  3727. * Objective-C Method Symbols::
  3728. * Java Symbols::
  3729. * Statement Block Symbols::
  3730. * K&R Symbols::
  3731. @end menu
  3732. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3733. @node Function Symbols, Class Symbols, Syntactic Symbols, Syntactic Symbols
  3734. @comment node-name, next, previous, up
  3735. @subsection Function Symbols
  3736. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3737. This example shows a typical function declaration.
  3738. @example
  3739. 1: void
  3740. 2: swap( int& a, int& b )
  3741. 3: @{
  3742. 4: int tmp = a;
  3743. 5: a = b;
  3744. 6: b = tmp;
  3745. 7: int ignored =
  3746. 8: a + b;
  3747. 9: @}
  3748. @end example
  3749. @ssindex topmost-intro
  3750. @ssindex topmost-intro-cont
  3751. @ssindex defun-open
  3752. @ssindex defun-close
  3753. @ssindex defun-block-intro
  3754. Line 1 shows a @code{topmost-intro} since it is the first line that
  3755. introduces a top-level construct. Line 2 is a continuation of the
  3756. top-level construct introduction so it has the syntax
  3757. @code{topmost-intro-cont}. Line 3 shows a @code{defun-open} since it is
  3758. the brace that opens a top-level function definition. Line 9 is the
  3759. corresponding
  3760. @code{defun-close} since it contains the brace that closes the top-level
  3761. function definition. Line 4 is a @code{defun-block-intro}, i.e., it is
  3762. the first line of a brace-block, enclosed in a
  3763. top-level function definition.
  3764. @ssindex statement
  3765. @ssindex statement-cont
  3766. Lines 5, 6, and 7 are all given @code{statement} syntax since there
  3767. isn't much special about them. Note however that line 8 is given
  3768. @code{statement-cont} syntax since it continues the statement begun
  3769. on the previous line.
  3770. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3771. @node Class Symbols, Conditional Construct Symbols, Function Symbols, Syntactic Symbols
  3772. @comment node-name, next, previous, up
  3773. @subsection Class related Symbols
  3774. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3775. Here's an example which illustrates some C++ class syntactic symbols:
  3776. @example
  3777. 1: class Bass
  3778. 2: : public Guitar,
  3779. 3: public Amplifiable
  3780. 4: @{
  3781. 5: public:
  3782. 6: Bass()
  3783. 7: : eString( new BassString( 0.105 )),
  3784. 8: aString( new BassString( 0.085 )),
  3785. 9: dString( new BassString( 0.065 )),
  3786. 10: gString( new BassString( 0.045 ))
  3787. 11: @{
  3788. 12: eString.tune( 'E' );
  3789. 13: aString.tune( 'A' );
  3790. 14: dString.tune( 'D' );
  3791. 15: gString.tune( 'G' );
  3792. 16: @}
  3793. 17: friend class Luthier;
  3794. 18: @};
  3795. @end example
  3796. @ssindex class-open
  3797. @ssindex class-close
  3798. As in the previous example, line 1 has the @code{topmost-intro} syntax.
  3799. Here however, the brace that opens a C++ class definition on line 4 is
  3800. assigned the @code{class-open} syntax. Note that in C++, classes,
  3801. structs, and unions are essentially equivalent syntactically (and are
  3802. very similar semantically), so replacing the @code{class} keyword in the
  3803. example above with @code{struct} or @code{union} would still result in a
  3804. syntax of @code{class-open} for line 4 @footnote{This is the case even
  3805. for C and Objective-C@. For consistency, structs in all supported
  3806. languages are syntactically equivalent to classes. Note however that
  3807. the keyword @code{class} is meaningless in C and Objective-C.}.
  3808. Similarly, line 18 is assigned @code{class-close} syntax.
  3809. @ssindex inher-intro
  3810. @ssindex inher-cont
  3811. Line 2 introduces the inheritance list for the class so it is assigned
  3812. the @code{inher-intro} syntax, and line 3, which continues the
  3813. inheritance list is given @code{inher-cont} syntax.
  3814. @ssindex access-label
  3815. @ssindex inclass
  3816. Hitting @kbd{C-c C-s} on line 5 shows the following analysis:
  3817. @example
  3818. ((inclass 58) (access-label 58))
  3819. @end example
  3820. @noindent
  3821. The primary syntactic symbol for this line is @code{access-label} as
  3822. this is a label keyword that specifies access protection in C++. However,
  3823. because this line is also a top-level construct inside a class
  3824. definition, the analysis actually shows two syntactic symbols. The
  3825. other syntactic symbol assigned to this line is @code{inclass}.
  3826. Similarly, line 6 is given both @code{inclass} and @code{topmost-intro}
  3827. syntax:
  3828. @example
  3829. ((inclass 58) (topmost-intro 60))
  3830. @end example
  3831. @ssindex member-init-intro
  3832. @ssindex member-init-cont
  3833. Line 7 introduces a C++ member initialization list and as such is given
  3834. @code{member-init-intro} syntax. Note that in this case it is
  3835. @emph{not} assigned @code{inclass} since this is not considered a
  3836. top-level construct. Lines 8 through 10 are all assigned
  3837. @code{member-init-cont} since they continue the member initialization
  3838. list started on line 7.
  3839. @cindex in-class inline methods
  3840. @ssindex inline-open
  3841. @ssindex inline-close
  3842. Line 11's analysis is a bit more complicated:
  3843. @example
  3844. ((inclass 58) (inline-open))
  3845. @end example
  3846. This line is assigned a syntax of both @code{inline-open} and
  3847. @code{inclass} because it opens an @dfn{in-class} C++ inline method
  3848. definition. This is distinct from, but related to, the C++ notion of an
  3849. inline function in that its definition occurs inside an enclosing class
  3850. definition, which in C++ implies that the function should be inlined.
  3851. However, if the definition of the @code{Bass} constructor appeared
  3852. outside the class definition, the construct would be given the
  3853. @code{defun-open} syntax, even if the keyword @code{inline} appeared
  3854. before the method name, as in:
  3855. @example
  3856. 1: class Bass
  3857. 2: : public Guitar,
  3858. 3: public Amplifiable
  3859. 4: @{
  3860. 5: public:
  3861. 6: Bass();
  3862. 7: @};
  3863. 8:
  3864. 9: inline
  3865. 10: Bass::Bass()
  3866. 11: : eString( new BassString( 0.105 )),
  3867. 12: aString( new BassString( 0.085 )),
  3868. 13: dString( new BassString( 0.065 )),
  3869. 14: gString( new BassString( 0.045 ))
  3870. 15: @{
  3871. 16: eString.tune( 'E' );
  3872. 17: aString.tune( 'A' );
  3873. 18: dString.tune( 'D' );
  3874. 19: gString.tune( 'G' );
  3875. 20: @}
  3876. @end example
  3877. @ssindex friend
  3878. Returning to the previous example, line 16 is given @code{inline-close}
  3879. syntax, while line 12 is given @code{defun-block-open} syntax, and lines
  3880. 13 through 15 are all given @code{statement} syntax. Line 17 is
  3881. interesting in that its syntactic analysis list contains three
  3882. elements:
  3883. @example
  3884. ((inclass 58) (topmost-intro 380) (friend))
  3885. @end example
  3886. The @code{friend} and @code{inline-open} syntactic symbols are
  3887. modifiers that do not have anchor positions.
  3888. @ssindex template-args-cont
  3889. Template definitions introduce yet another syntactic symbol:
  3890. @example
  3891. 1: ThingManager <int,
  3892. 2: Framework::Callback *,
  3893. 3: Mutex> framework_callbacks;
  3894. @end example
  3895. Here, line 1 is analyzed as a @code{topmost-intro}, but lines 2 and 3
  3896. are both analyzed as @code{template-args-cont} lines.
  3897. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3898. @node Conditional Construct Symbols, Switch Statement Symbols, Class Symbols, Syntactic Symbols
  3899. @comment node-name, next, previous, up
  3900. @subsection Conditional Construct Symbols
  3901. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3902. Here is a (totally contrived) example which illustrates how syntax is
  3903. assigned to various conditional constructs:
  3904. @example
  3905. 1: void spam( int index )
  3906. 2: @{
  3907. 3: for( int i=0; i<index; i++ )
  3908. 4: @{
  3909. 5: if( i == 10 )
  3910. 6: do_something_special();
  3911. 7: else
  3912. 8: silly_label:
  3913. 9: do_something( i );
  3914. 10: @}
  3915. 11: do @{
  3916. 12: another_thing( i-- );
  3917. 13: @}
  3918. 14: while( i > 0 );
  3919. 15: @}
  3920. @end example
  3921. Only the lines that illustrate new syntactic symbols will be discussed.
  3922. @ssindex substatement-open
  3923. @ssindex statement-block-intro
  3924. @ssindex block-close
  3925. Line 4 has a brace which opens a conditional's substatement block. It
  3926. is thus assigned @code{substatement-open} syntax, and since line 5 is
  3927. the first line in the substatement block, it is assigned
  3928. @code{statement-block-intro} syntax. Line 10 contains the brace
  3929. that closes the inner substatement block, and is therefore given the
  3930. syntax @code{block-close}@footnote{@code{block-open} is used only for
  3931. ``free-standing'' blocks, and is somewhat rare (@pxref{Literal
  3932. Symbols} for an example.)}. Line 13 is treated the same way.
  3933. @ssindex substatement
  3934. Lines 6 and 9 are also substatements of conditionals, but since they
  3935. don't start blocks they are given @code{substatement} syntax
  3936. instead of @code{substatement-open}.
  3937. @ssindex substatement-label
  3938. Line 8 contains a label, which is normally given @code{label} syntax.
  3939. This one is however a bit special since it's between a conditional and
  3940. its substatement. It's analyzed as @code{substatement-label} to let you
  3941. handle this rather odd case differently from normal labels.
  3942. @ssindex else-clause
  3943. @ssindex catch-clause
  3944. Line 7 start with an @code{else} that matches the @code{if} statement on
  3945. line 5. It is therefore given the @code{else-clause} syntax and is
  3946. anchored on the matching @code{if}. The @code{try}-@code{catch}
  3947. constructs in C++ and Java are treated this way too, except that
  3948. @code{catch} and (in Java) @code{finally}, are marked with
  3949. @code{catch-clause}.
  3950. @ssindex do-while-closure
  3951. The @code{while} construct on line 14 that closes a @code{do}
  3952. conditional is given the special syntax @code{do-while-closure} if it
  3953. appears on a line by itself. Note that if the @code{while} appeared on
  3954. the same line as the preceding close brace, that line would still have
  3955. @code{block-close} syntax.
  3956. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3957. @node Switch Statement Symbols, Brace List Symbols, Conditional Construct Symbols, Syntactic Symbols
  3958. @comment node-name, next, previous, up
  3959. @subsection Switch Statement Symbols
  3960. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3961. Switch statements have their own set of syntactic symbols. Here's an
  3962. example:
  3963. @example
  3964. 1: void spam( enum Ingredient i )
  3965. 2: @{
  3966. 3: switch( i ) @{
  3967. 4: case Ham:
  3968. 5: be_a_pig();
  3969. 6: break;
  3970. 7: case Salt:
  3971. 8: drink_some_water();
  3972. 9: break;
  3973. 10: default:
  3974. 11: @{
  3975. 12: what_is_it();
  3976. 13: break;
  3977. 14: @}
  3978. 15: @}
  3979. 14: @}
  3980. @end example
  3981. @ssindex case-label
  3982. @ssindex statement-case-intro
  3983. @ssindex statement-case-open
  3984. Here, lines 4, 7, and 10 are all assigned @code{case-label} syntax,
  3985. while lines 5 and 8 are assigned @code{statement-case-intro}. Line 11
  3986. is treated slightly differently since it contains a brace that opens a
  3987. block; it is given @code{statement-case-open} syntax.
  3988. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3989. @node Brace List Symbols, External Scope Symbols, Switch Statement Symbols, Syntactic Symbols
  3990. @comment node-name, next, previous, up
  3991. @subsection Brace List Symbols
  3992. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3993. @cindex brace lists
  3994. There are a set of syntactic symbols that are used to recognize
  3995. constructs inside of brace lists. A brace list is defined as an
  3996. @code{enum} or aggregate initializer list, such as might statically
  3997. initialize an array of structs. The three special aggregate constructs
  3998. in Pike, @code{(@{ @})}, @code{([ ])} and @code{(< >)}, are treated as
  3999. brace lists too. An example:
  4000. @example
  4001. 1: static char* ingredients[] =
  4002. 2: @{
  4003. 3: "Ham",
  4004. 4: "Salt",
  4005. 5: NULL
  4006. 6: @};
  4007. @end example
  4008. @ssindex brace-list-open
  4009. @ssindex brace-list-intro
  4010. @ssindex brace-list-close
  4011. @ssindex brace-list-entry
  4012. Following convention, line 2 in this example is assigned
  4013. @code{brace-list-open} syntax, and line 3 is assigned
  4014. @code{brace-list-intro} syntax. Likewise, line 6 is assigned
  4015. @code{brace-list-close} syntax. Lines 4 and 5 however, are assigned
  4016. @code{brace-list-entry} syntax, as would all subsequent lines in this
  4017. initializer list.
  4018. @ssindex brace-entry-open
  4019. Your static initializer might be initializing nested structures, for
  4020. example:
  4021. @example
  4022. 1: struct intpairs[] =
  4023. 2: @{
  4024. 3: @{ 1, 2 @},
  4025. 4: @{
  4026. 5: 3,
  4027. 6: 4
  4028. 7: @}
  4029. 8: @{ 1,
  4030. 9: 2 @},
  4031. 10: @{ 3, 4 @}
  4032. 11: @};
  4033. @end example
  4034. Here, you've already seen the analysis of lines 1, 2, 3, and 11. On
  4035. line 4, things get interesting; this line is assigned
  4036. @code{brace-entry-open} syntactic symbol because it's a bracelist
  4037. entry line that starts with an open brace. Lines 5 and 6 are pretty
  4038. standard, and line 7 is a @code{brace-list-close} as you'd expect.
  4039. Once again, line 8 is assigned as @code{brace-entry-open} as is line
  4040. 10. Line 9 is assigned two syntactic elements, @code{brace-list-intro}
  4041. with anchor point at the @samp{@{} of line 8@footnote{This extra
  4042. syntactic element was introduced in @ccmode{} 5.33.1 to allow extra
  4043. flexibility in indenting the second line of such a construct. You can
  4044. preserve the behaviour resulting from the former syntactic analysis by
  4045. giving @code{brace-list-entry} an offset of
  4046. @code{c-lineup-under-anchor} (@pxref{Misc Line-Up}).}, and
  4047. @code{brace-list-entry} anchored on the @samp{1} of line 8.
  4048. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4049. @node External Scope Symbols, Paren List Symbols, Brace List Symbols, Syntactic Symbols
  4050. @comment node-name, next, previous, up
  4051. @subsection External Scope Symbols
  4052. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4053. External language definition blocks also have their own syntactic
  4054. symbols. In this example:
  4055. @example
  4056. 1: extern "C"
  4057. 2: @{
  4058. 3: int thing_one( int );
  4059. 4: int thing_two( double );
  4060. 5: @}
  4061. @end example
  4062. @ssindex extern-lang-open
  4063. @ssindex extern-lang-close
  4064. @ssindex inextern-lang
  4065. @ssindex inclass
  4066. @noindent
  4067. line 2 is given the @code{extern-lang-open} syntax, while line 5 is given
  4068. the @code{extern-lang-close} syntax. The analysis for line 3 yields:
  4069. @example
  4070. ((inextern-lang) (topmost-intro 14))
  4071. @end example
  4072. @noindent
  4073. where @code{inextern-lang} is a modifier similar in purpose to
  4074. @code{inclass}.
  4075. There are various other top level blocks like @code{extern}, and they
  4076. are all treated in the same way except that the symbols are named after
  4077. the keyword that introduces the block. E.g., C++ namespace blocks get
  4078. the three symbols @code{namespace-open}, @code{namespace-close} and
  4079. @code{innamespace}. The currently recognized top level blocks are:
  4080. @table @asis
  4081. @item @code{extern-lang-open}, @code{extern-lang-close}, @code{inextern-lang}
  4082. @code{extern} blocks in C and C++.@footnote{These should logically be
  4083. named @code{extern-open}, @code{extern-close} and @code{inextern}, but
  4084. that isn't the case for historical reasons.}
  4085. @item @code{namespace-open}, @code{namespace-close}, @code{innamespace}
  4086. @ssindex namespace-open
  4087. @ssindex namespace-close
  4088. @ssindex innamespace
  4089. @code{namespace} blocks in C++.
  4090. @item @code{module-open}, @code{module-close}, @code{inmodule}
  4091. @ssindex module-open
  4092. @ssindex module-close
  4093. @ssindex inmodule
  4094. @code{module} blocks in CORBA IDL.
  4095. @item @code{composition-open}, @code{composition-close}, @code{incomposition}
  4096. @ssindex composition-open
  4097. @ssindex composition-close
  4098. @ssindex incomposition
  4099. @code{composition} blocks in CORBA CIDL.
  4100. @end table
  4101. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4102. @node Paren List Symbols, Literal Symbols, External Scope Symbols, Syntactic Symbols
  4103. @comment node-name, next, previous, up
  4104. @subsection Parenthesis (Argument) List Symbols
  4105. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4106. A number of syntactic symbols are associated with parenthesis lists,
  4107. a.k.a argument lists, as found in function declarations and function
  4108. calls. This example illustrates these:
  4109. @example
  4110. 1: void a_function( int line1,
  4111. 2: int line2 );
  4112. 3:
  4113. 4: void a_longer_function(
  4114. 5: int line1,
  4115. 6: int line2
  4116. 7: );
  4117. 8:
  4118. 9: void call_them( int line1, int line2 )
  4119. 10: @{
  4120. 11: a_function(
  4121. 12: line1,
  4122. 13: line2
  4123. 14: );
  4124. 15:
  4125. 16: a_longer_function( line1,
  4126. 17: line2 );
  4127. 18: @}
  4128. @end example
  4129. @ssindex arglist-intro
  4130. @ssindex arglist-close
  4131. Lines 5 and 12 are assigned @code{arglist-intro} syntax since they are
  4132. the first line following the open parenthesis, and lines 7 and 14 are
  4133. assigned @code{arglist-close} syntax since they contain the parenthesis
  4134. that closes the argument list.
  4135. @ssindex arglist-cont-nonempty
  4136. @ssindex arglist-cont
  4137. Lines that continue argument lists can be assigned one of two syntactic
  4138. symbols. For example, Lines 2 and 17
  4139. are assigned @code{arglist-cont-nonempty} syntax. What this means
  4140. is that they continue an argument list, but that the line containing the
  4141. parenthesis that opens the list is @emph{not empty} following the open
  4142. parenthesis. Contrast this against lines 6 and 13 which are assigned
  4143. @code{arglist-cont} syntax. This is because the parenthesis that opens
  4144. their argument lists is the last character on that line.
  4145. Syntactic elements with @code{arglist-intro},
  4146. @code{arglist-cont-nonempty}, and @code{arglist-close} contain two
  4147. buffer positions: the anchor position (the beginning of the
  4148. declaration or statement) and the position of the open parenthesis.
  4149. The latter position can be used in a line-up function (@pxref{Line-Up
  4150. Functions}).
  4151. Note that there is no @code{arglist-open} syntax. This is because any
  4152. parenthesis that opens an argument list, appearing on a separate line,
  4153. is assigned the @code{statement-cont} syntax instead.
  4154. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4155. @node Literal Symbols, Multiline Macro Symbols, Paren List Symbols, Syntactic Symbols
  4156. @comment node-name, next, previous, up
  4157. @subsection Comment String Label and Macro Symbols
  4158. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4159. A few miscellaneous syntactic symbols that haven't been previously
  4160. covered are illustrated by this C++ example:
  4161. @example
  4162. 1: void Bass::play( int volume )
  4163. 2: const
  4164. 3: @{
  4165. 4: /* this line starts a multiline
  4166. 5: * comment. This line should get 'c' syntax */
  4167. 6:
  4168. 7: char* a_multiline_string = "This line starts a multiline \
  4169. 8: string. This line should get 'string' syntax.";
  4170. 9:
  4171. 10: note:
  4172. 11: @{
  4173. 12: #ifdef LOCK
  4174. 13: Lock acquire();
  4175. 14: #endif // LOCK
  4176. 15: slap_pop();
  4177. 16: cout << "I played "
  4178. 17: << "a note\n";
  4179. 18: @}
  4180. 19: @}
  4181. @end example
  4182. The lines to note in this example include:
  4183. @itemize @bullet
  4184. @item
  4185. @ssindex func-decl-cont
  4186. Line 2 is assigned the @code{func-decl-cont} syntax.
  4187. @item
  4188. @ssindex comment-intro
  4189. Line 4 is assigned both @code{defun-block-intro} @emph{and}
  4190. @code{comment-intro} syntax. A syntactic element with
  4191. @code{comment-intro} has no anchor point. It is always accompanied
  4192. by another syntactic element which does have one.
  4193. @item
  4194. @ssindex c
  4195. Line 5 is assigned @code{c} syntax.
  4196. @item
  4197. @cindex syntactic whitespace
  4198. Line 6 which, even though it contains nothing but whitespace, is
  4199. assigned @code{defun-block-intro}. Note that the appearance of the
  4200. comment on lines 4 and 5 do not cause line 6 to be assigned
  4201. @code{statement} syntax because comments are considered to be
  4202. @dfn{syntactic whitespace}, which are ignored when analyzing
  4203. code.
  4204. @item
  4205. @ssindex string
  4206. Line 8 is assigned @code{string} syntax.
  4207. @item
  4208. @ssindex label
  4209. Line 10 is assigned @code{label} syntax.
  4210. @item
  4211. @ssindex block-open
  4212. Line 11 is assigned @code{block-open} as well as @code{statement}
  4213. syntax. A @code{block-open} syntactic element doesn't have an anchor
  4214. position, since it always appears with another syntactic element which
  4215. does have one.
  4216. @item
  4217. @ssindex cpp-macro
  4218. Lines 12 and 14 are assigned @code{cpp-macro} syntax in addition to the
  4219. normal syntactic symbols (@code{statement-block-intro} and
  4220. @code{statement}, respectively). Normally @code{cpp-macro} is
  4221. configured to cancel out the normal syntactic context to make all
  4222. preprocessor directives stick to the first column, but that's easily
  4223. changed if you want preprocessor directives to be indented like the rest
  4224. of the code. Like @code{comment-intro}, a syntactic element with
  4225. @code{cpp-macro} doesn't contain an anchor position.
  4226. @item
  4227. @ssindex stream-op
  4228. Line 17 is assigned @code{stream-op} syntax.
  4229. @end itemize
  4230. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4231. @node Multiline Macro Symbols, Objective-C Method Symbols, Literal Symbols, Syntactic Symbols
  4232. @comment node-name, next, previous, up
  4233. @subsection Multiline Macro Symbols
  4234. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4235. @cindex multiline macros
  4236. @cindex syntactic whitespace
  4237. @ssindex cpp-define-intro
  4238. @ssindex cpp-macro-cont
  4239. Multiline preprocessor macro definitions are normally handled just like
  4240. other code, i.e., the lines inside them are indented according to the
  4241. syntactic analysis of the preceding lines inside the macro. The first
  4242. line inside a macro definition (i.e., the line after the starting line of
  4243. the cpp directive itself) gets @code{cpp-define-intro}. In this example:
  4244. @example
  4245. 1: #define LIST_LOOP(cons, listp) \
  4246. 2: for (cons = listp; !NILP (cons); cons = XCDR (cons)) \
  4247. 3: if (!CONSP (cons)) \
  4248. 4: signal_error ("Invalid list format", listp); \
  4249. 5: else
  4250. @end example
  4251. @noindent
  4252. line 1 is given the syntactic symbol @code{cpp-macro}. The first line
  4253. of a cpp directive is always given that symbol. Line 2 is given
  4254. @code{cpp-define-intro}, so that you can give the macro body as a whole
  4255. some extra indentation. Lines 3 through 5 are then analyzed as normal
  4256. code, i.e., @code{substatement} on lines 3 and 4, and @code{else-clause}
  4257. on line 5.
  4258. The syntactic analysis inside macros can be turned off with
  4259. @code{c-syntactic-indentation-in-macros} (@pxref{Custom Macros}). In
  4260. that case, lines 2 through 5 would all be given @code{cpp-macro-cont}
  4261. with an anchor position pointing to the @code{#} which starts the cpp
  4262. directive@footnote{This is how @ccmode{} 5.28 and earlier analyzed
  4263. macros.}.
  4264. @xref{Custom Macros}, for more info about the treatment of macros.
  4265. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4266. @node Objective-C Method Symbols, Java Symbols, Multiline Macro Symbols, Syntactic Symbols
  4267. @comment node-name, next, previous, up
  4268. @subsection Objective-C Method Symbols
  4269. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4270. In Objective-C buffers, there are three additional syntactic symbols
  4271. assigned to various message calling constructs. Here's an example
  4272. illustrating these:
  4273. @example
  4274. 1: - (void)setDelegate:anObject
  4275. 2: withStuff:stuff
  4276. 3: @{
  4277. 4: [delegate masterWillRebind:self
  4278. 5: toDelegate:anObject
  4279. 6: withExtraStuff:stuff];
  4280. 7: @}
  4281. @end example
  4282. @ssindex objc-method-intro
  4283. @ssindex objc-method-args-cont
  4284. @ssindex objc-method-call-cont
  4285. Here, line 1 is assigned @code{objc-method-intro} syntax, and line 2 is
  4286. assigned @code{objc-method-args-cont} syntax. Lines 5 and 6 are both
  4287. assigned @code{objc-method-call-cont} syntax.
  4288. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4289. @node Java Symbols, Statement Block Symbols, Objective-C Method Symbols, Syntactic Symbols
  4290. @comment node-name, next, previous, up
  4291. @subsection Java Symbols
  4292. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4293. Java has a concept of anonymous classes which can look something like
  4294. this:
  4295. @example
  4296. 1: @@Test
  4297. 2: public void watch(Observable o) @{
  4298. 3: @@NonNull
  4299. 4: Observer obs = new Observer() @{
  4300. 5: public void update(Observable o, Object arg) @{
  4301. 6: history.addElement(arg);
  4302. 7: @}
  4303. 8: @};
  4304. 9: o.addObserver(obs);
  4305. 10: @}
  4306. @end example
  4307. @ssindex inexpr-class
  4308. The brace following the @code{new} operator opens the anonymous class.
  4309. Lines 5 and 8 are assigned the @code{inexpr-class} syntax, besides the
  4310. @code{inclass} symbol used in normal classes. Thus, the class will be
  4311. indented just like a normal class, with the added indentation given to
  4312. @code{inexpr-class}. An @code{inexpr-class} syntactic element doesn't
  4313. have an anchor position.
  4314. @ssindex annotation-top-cont
  4315. @ssindex annotation-var-cont
  4316. Line 2 is assigned the @code{annotation-top-cont} syntax, due to it being a
  4317. continuation of a topmost introduction with an annotation symbol preceding
  4318. the current line. Similarly, line 4 is assigned the @code{annotation-var-cont}
  4319. syntax due to it being a continuation of a variable declaration where preceding
  4320. the declaration is an annotation.
  4321. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4322. @node Statement Block Symbols, K&R Symbols, Java Symbols, Syntactic Symbols
  4323. @comment node-name, next, previous, up
  4324. @subsection Statement Block Symbols
  4325. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4326. There are a few occasions where a statement block might be used inside
  4327. an expression. One is in C or C++ code using the gcc extension for
  4328. this, e.g.:
  4329. @example
  4330. 1: int res = (@{
  4331. 2: int y = foo (); int z;
  4332. 3: if (y > 0) z = y; else z = - y;
  4333. 4: z;
  4334. 5: @});
  4335. @end example
  4336. @ssindex inexpr-statement
  4337. Lines 2 and 5 get the @code{inexpr-statement} syntax, besides the
  4338. symbols they'd get in a normal block. Therefore, the indentation put on
  4339. @code{inexpr-statement} is added to the normal statement block
  4340. indentation. An @code{inexpr-statement} syntactic element doesn't
  4341. contain an anchor position.
  4342. C++11's lambda expressions involve a block inside a statement. For
  4343. example:
  4344. @example
  4345. 1: std::for_each(someList.begin(), someList.end(), [&total](int x) @{
  4346. 2: total += x;
  4347. 3: @});
  4348. @end example
  4349. Here a lambda expressions begins at the open bracket on line 1 and
  4350. ends at the closing brace on line 3. Line 2, in addition to the
  4351. familiar @code{defun-block-intro} syntactic element, is also prefixed
  4352. by an @code{inlambda} element, which is typically used to indent the
  4353. entire lambda expression to under the opening bracket.
  4354. In Pike code, there are a few other situations where blocks occur inside
  4355. statements, as illustrated here:
  4356. @example
  4357. 1: array itgob()
  4358. 2: @{
  4359. 3: string s = map (backtrace()[-2][3..],
  4360. 4: lambda
  4361. 5: (mixed arg)
  4362. 6: @{
  4363. 7: return sprintf ("%t", arg);
  4364. 8: @}) * ", " + "\n";
  4365. 9: return catch @{
  4366. 10: write (s + "\n");
  4367. 11: @};
  4368. 12: @}
  4369. @end example
  4370. @ssindex inlambda
  4371. @ssindex lambda-intro-cont
  4372. Lines 4 through 8 contain a lambda function, which @ccmode{} recognizes
  4373. by the @code{lambda} keyword. If the function argument list is put
  4374. on a line of its own, as in line 5, it gets the @code{lambda-intro-cont}
  4375. syntax. The function body is handled as an inline method body, with the
  4376. addition of the @code{inlambda} syntactic symbol. This means that line
  4377. 6 gets @code{inlambda} and @code{inline-open}, and line 8 gets
  4378. @code{inline-close}@footnote{You might wonder why it doesn't get
  4379. @code{inlambda} too. It's because the closing brace is relative to the
  4380. opening brace, which stands on its own line in this example. If the
  4381. opening brace was hanging on the previous line, then the closing brace
  4382. would get the @code{inlambda} syntax too to be indented correctly.}.
  4383. @ssindex inexpr-statement
  4384. On line 9, @code{catch} is a special function taking a statement block
  4385. as its argument. The block is handled as an in-expression statement
  4386. with the @code{inexpr-statement} syntax, just like the gcc extended C
  4387. example above. The other similar special function, @code{gauge}, is
  4388. handled like this too.
  4389. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4390. @node K&R Symbols, , Statement Block Symbols, Syntactic Symbols
  4391. @comment node-name, next, previous, up
  4392. @subsection K&R Symbols
  4393. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4394. @ssindex knr-argdecl-intro
  4395. @ssindex knr-argdecl
  4396. Two other syntactic symbols can appear in old style, non-prototyped C
  4397. code @footnote{a.k.a.@: K&R C, or Kernighan & Ritchie C}:
  4398. @example
  4399. 1: int add_three_integers(a, b, c)
  4400. 2: int a;
  4401. 3: int b;
  4402. 4: int c;
  4403. 5: @{
  4404. 6: return a + b + c;
  4405. 7: @}
  4406. @end example
  4407. Here, line 2 is the first line in an argument declaration list and so is
  4408. given the @code{knr-argdecl-intro} syntactic symbol. Subsequent lines
  4409. (i.e., lines 3 and 4 in this example), are given @code{knr-argdecl}
  4410. syntax.
  4411. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4412. @node Indentation Calculation, , Syntactic Symbols, Indentation Engine Basics
  4413. @comment node-name, next, previous, up
  4414. @section Indentation Calculation
  4415. @cindex indentation
  4416. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4417. Indentation for a line is calculated from the syntactic context
  4418. (@pxref{Syntactic Analysis}).
  4419. First, a buffer position is found whose column will be the base for the
  4420. indentation calculation. It's the anchor position in the first
  4421. syntactic element that provides one that is used. If no syntactic
  4422. element has an anchor position then column zero is used.
  4423. Second, the syntactic symbols in each syntactic element are looked up
  4424. in the @code{c-offsets-alist} style variable
  4425. (@pxref{c-offsets-alist}), which is an association list of syntactic
  4426. symbols and the offsets to apply for those symbols. These offsets are
  4427. added together with the base column to produce the new indentation
  4428. column.
  4429. Let's use our two code examples above to see how this works. Here is
  4430. our first example again:
  4431. @example
  4432. 1: void swap( int& a, int& b )
  4433. 2: @{
  4434. 3: int tmp = a;
  4435. 4: a = b;
  4436. 5: b = tmp;
  4437. 6: @}
  4438. @end example
  4439. Let's say point is on line 3 and we hit the @key{TAB} key to reindent
  4440. the line. The syntactic context for that line is:
  4441. @example
  4442. ((defun-block-intro 29))
  4443. @end example
  4444. @noindent
  4445. Since buffer position 29 is the first and only anchor position in the
  4446. list, @ccmode{} goes there and asks for the current column. This brace
  4447. is in column zero, so @ccmode{} uses @samp{0} as the base column.
  4448. Next, @ccmode{} looks up @code{defun-block-intro} in the
  4449. @code{c-offsets-alist} style variable. Let's say it finds the value
  4450. @samp{4}; it adds this to the base column @samp{0}, yielding a running
  4451. total indentation of 4 spaces.
  4452. Since there is only one syntactic element on the list for this line,
  4453. indentation calculation is complete, and the total indentation for the
  4454. line is 4 spaces.
  4455. Here's another example:
  4456. @example
  4457. 1: int add( int val, int incr, int doit )
  4458. 2: @{
  4459. 3: if( doit )
  4460. 4: @{
  4461. 5: return( val + incr );
  4462. 6: @}
  4463. 7: return( val );
  4464. 8: @}
  4465. @end example
  4466. If we were to hit @kbd{TAB} on line 4 in the above example, the same
  4467. basic process is performed, despite the differences in the syntactic
  4468. context. The context for this line is:
  4469. @example
  4470. ((substatement-open 46))
  4471. @end example
  4472. Here, @ccmode{} goes to buffer position 46, which is the @samp{i} in
  4473. @code{if} on line 3. This character is in the fourth column on that
  4474. line so the base column is @samp{4}. Then @ccmode{} looks up the
  4475. @code{substatement-open} symbol in @code{c-offsets-alist}. Let's say it
  4476. finds the value @samp{4}. It's added with the base column and yields an
  4477. indentation for the line of 8 spaces.
  4478. Simple, huh?
  4479. Actually, it's a bit more complicated than that since the entries on
  4480. @code{c-offsets-alist} can be much more than plain offsets.
  4481. @xref{c-offsets-alist}, for the full story.
  4482. Anyway, the mode usually just does The Right Thing without you having to
  4483. think about it in this much detail. But when customizing indentation,
  4484. it's helpful to understand the general indentation model being used.
  4485. As you configure @ccmode{}, you might want to set the variable
  4486. @code{c-echo-syntactic-information-p} to non-@code{nil} so that the
  4487. syntactic context and calculated offset always is echoed in the
  4488. minibuffer when you hit @kbd{TAB}.
  4489. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4490. @node Customizing Indentation, Custom Macros, Indentation Engine Basics, Top
  4491. @comment node-name, next, previous, up
  4492. @chapter Customizing Indentation
  4493. @cindex customization, indentation
  4494. @cindex indentation
  4495. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4496. The principal variable for customizing indentation is the style
  4497. variable @code{c-offsets-alist}, which gives an @dfn{offset} (an
  4498. indentation rule) for each syntactic symbol. Its structure and
  4499. semantics are completely described in @ref{c-offsets-alist}. The
  4500. various ways you can set the variable, including the use of the
  4501. @ccmode{} style system, are described in @ref{Config Basics} and its
  4502. sections, in particular @ref{Style Variables}.
  4503. The simplest and most used kind of ``offset'' setting in
  4504. @code{c-offsets-alist} is in terms of multiples of
  4505. @code{c-basic-offset}:
  4506. @defopt c-basic-offset
  4507. @vindex basic-offset (c-)
  4508. This style variable holds the basic offset between indentation levels.
  4509. It's factory default is 4, but all the built-in styles set it
  4510. themselves, to some value between 2 (for @code{gnu} style) and 8 (for
  4511. @code{bsd}, @code{linux}, and @code{python} styles).
  4512. @end defopt
  4513. The most flexible ``offset'' setting you can make in
  4514. @code{c-offsets-alist} is a line-up function (or even a list of them),
  4515. either one supplied by @ccmode{} (@pxref{Line-Up Functions}) or one
  4516. you write yourself (@pxref{Custom Line-Up}).
  4517. Finally, in @ref{Other Indentation} you'll find the tool of last
  4518. resort: a hook which is called after a line has been indented. You
  4519. can install functions here to make ad-hoc adjustments to any line's
  4520. indentation.
  4521. @menu
  4522. * c-offsets-alist::
  4523. * Interactive Customization::
  4524. * Line-Up Functions::
  4525. * Custom Line-Up::
  4526. * Other Indentation::
  4527. @end menu
  4528. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4529. @node c-offsets-alist, Interactive Customization, Customizing Indentation, Customizing Indentation
  4530. @comment node-name, next, previous, up
  4531. @section c-offsets-alist
  4532. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4533. This section explains the structure and semantics of the style
  4534. variable @code{c-offsets-alist}, the principal variable for configuring
  4535. indentation. Details of how to set it up, and its relationship to
  4536. @ccmode{}'s style system are given in @ref{Style Variables}.
  4537. @defopt c-offsets-alist
  4538. @vindex offsets-alist (c-)
  4539. This is an alist which associates an offset with each syntactic
  4540. symbol. This @dfn{offset} is a rule specifying how to indent a line
  4541. whose syntactic context matches the symbol. @xref{Syntactic
  4542. Analysis}.
  4543. Note that the buffer-local binding of this alist in a @ccmode{} buffer
  4544. contains an entry for @emph{every} syntactic symbol. Its global
  4545. binding and its settings within style specifications usually contain
  4546. only a few entries. @xref{Style Variables}.
  4547. The offset specification associated with any particular syntactic
  4548. symbol can be an integer, a variable name, a vector, a function or
  4549. lambda expression, a list, or one of the following special symbols:
  4550. @code{+}, @code{-}, @code{++}, @code{--}, @code{*}, or @code{/}. The
  4551. meanings of these values are described in detail below.
  4552. Here is an example fragment of a @code{c-offsets-alist}, showing some
  4553. of these kinds of offsets:
  4554. @example
  4555. ((statement . 0)
  4556. (substatement . +)
  4557. (cpp-macro . [0])
  4558. (topmost-intro-cont . c-lineup-topmost-intro-cont)
  4559. (statement-block-intro . (add c-lineup-whitesmith-in-block
  4560. c-indent-multi-line-block))
  4561. @dots{}
  4562. @*)
  4563. @end example
  4564. @end defopt
  4565. @deffn Command c-set-offset (@kbd{C-c C-o})
  4566. @findex set-offset (c-)
  4567. @kindex C-c C-o
  4568. This command changes the entry for a syntactic symbol in the current
  4569. binding of @code{c-offsets-alist}, or it inserts a new entry if there
  4570. isn't already one for that syntactic symbol.
  4571. You can use @code{c-set-offset} interactively within a @ccmode{}
  4572. buffer to make experimental changes to your indentation settings.
  4573. @kbd{C-c C-o} prompts you for the syntactic symbol to change
  4574. (defaulting to that of the current line) and the new offset
  4575. (defaulting to the current offset).
  4576. @code{c-set-offset} takes two arguments when used programmatically:
  4577. @var{symbol}, the syntactic element symbol to change and @var{offset},
  4578. the new offset for that syntactic element. You can call the command
  4579. in your @file{.emacs} to change the global binding of
  4580. @code{c-offsets-alist} (@pxref{Style Variables}); you can use it in a
  4581. hook function to make changes from the current style. @ccmode{}
  4582. itself uses this function when initializing styles.
  4583. @end deffn
  4584. @cindex offset specification
  4585. The ``offset specifications'' in @code{c-offsets-alist} can be any of
  4586. the following:
  4587. @table @asis
  4588. @item An integer
  4589. The integer specifies a relative offset. All relative
  4590. offsets@footnote{The syntactic context @code{@w{((defun-block-intro
  4591. 2724) (comment-intro))}} would likely have two relative offsets.} will
  4592. be added together and used to calculate the indentation relative to an
  4593. anchor position earlier in the buffer. @xref{Indentation
  4594. Calculation}, for details. Most of the time, it's probably better to
  4595. use one of the special symbols like @code{+} than an integer (apart
  4596. from zero).
  4597. @item One of the symbols @code{+}, @code{-}, @code{++}, @code{--}, @code{*}, or @code{/}
  4598. These special symbols describe a relative offset in multiples of
  4599. @code{c-basic-offset}:
  4600. By defining a style's indentation in terms of @code{c-basic-offset},
  4601. you can change the amount of whitespace given to an indentation level
  4602. while maintaining the same basic shape of your code. Here are the
  4603. values that the special symbols correspond to:
  4604. @table @code
  4605. @item +
  4606. @code{c-basic-offset} times 1
  4607. @item -
  4608. @code{c-basic-offset} times @minus{}1
  4609. @item ++
  4610. @code{c-basic-offset} times 2
  4611. @item --
  4612. @code{c-basic-offset} times @minus{}2
  4613. @item *
  4614. @code{c-basic-offset} times 0.5
  4615. @item /
  4616. @code{c-basic-offset} times @minus{}0.5
  4617. @end table
  4618. @item A vector
  4619. The first element of the vector, an integer, sets the absolute
  4620. indentation column. This will override any previously calculated
  4621. indentation, but won't override relative indentation calculated from
  4622. syntactic elements later on in the syntactic context of the line being
  4623. indented. @xref{Indentation Calculation}. Any elements in the vector
  4624. beyond the first will be ignored.
  4625. @item A function or lambda expression
  4626. The function will be called and its return value will in turn be
  4627. evaluated as an offset specification. Functions are useful when more
  4628. context than just the syntactic symbol is needed to get the desired
  4629. indentation. @xref{Line-Up Functions}, and @ref{Custom Line-Up}, for
  4630. details about them.
  4631. @item A symbol with a variable binding
  4632. If the symbol also has a function binding, the function takes
  4633. precedence over the variable. Otherwise the value of the variable is
  4634. used. It must be an integer (which is used as relative offset) or a
  4635. vector (an absolute offset).
  4636. @item A list
  4637. The offset can also be a list containing several offset
  4638. specifications; these are evaluated recursively and combined. A list
  4639. is typically only useful when some of the offsets are line-up
  4640. functions. A common strategy is calling a sequence of functions in
  4641. turn until one of them recognizes that it is appropriate for the
  4642. source line and returns a non-@code{nil} value.
  4643. @code{nil} values are always ignored when the offsets are combined.
  4644. The first element of the list specifies the method of combining the
  4645. non-@code{nil} offsets from the remaining elements:
  4646. @table @code
  4647. @item first
  4648. Use the first offset that doesn't evaluate to @code{nil}. Subsequent
  4649. elements of the list don't get evaluated.
  4650. @item min
  4651. Use the minimum of all the offsets. All must be either relative or
  4652. absolute; they can't be mixed.
  4653. @item max
  4654. Use the maximum of all the offsets. All must be either relative or
  4655. absolute; they can't be mixed.
  4656. @item add
  4657. Add all the evaluated offsets together. Exactly one of them may be
  4658. absolute, in which case the result is absolute. Any relative offsets
  4659. that preceded the absolute one in the list will be ignored in that case.
  4660. @end table
  4661. As a compatibility measure, if the first element is none of the above
  4662. then it too will be taken as an offset specification and the whole list
  4663. will be combined according to the method @code{first}.
  4664. @end table
  4665. @vindex c-strict-syntax-p
  4666. @vindex strict-syntax-p (c-)
  4667. If an offset specification evaluates to @code{nil}, then a relative
  4668. offset of 0 (zero) is used@footnote{There is however a variable
  4669. @code{c-strict-syntax-p} that when set to non-@code{nil} will cause an
  4670. error to be signaled in that case. It's now considered obsolete since
  4671. it doesn't work well with some of the alignment functions that return
  4672. @code{nil} instead of zero. You should therefore leave
  4673. @code{c-strict-syntax-p} set to @code{nil}.}.
  4674. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4675. @node Interactive Customization, Line-Up Functions, c-offsets-alist, Customizing Indentation
  4676. @comment node-name, next, previous, up
  4677. @section Interactive Customization
  4678. @cindex customization, interactive
  4679. @cindex interactive customization
  4680. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4681. As an example of how to customize indentation, let's change the
  4682. style of this example@footnote{In this and subsequent examples, the
  4683. original code is formatted using the @samp{gnu} style unless otherwise
  4684. indicated. @xref{Styles}.}:
  4685. @example
  4686. @group
  4687. 1: int add( int val, int incr, int doit )
  4688. 2: @{
  4689. 3: if( doit )
  4690. 4: @{
  4691. 5: return( val + incr );
  4692. 6: @}
  4693. 7: return( val );
  4694. 8: @}
  4695. @end group
  4696. @end example
  4697. @noindent
  4698. to:
  4699. @example
  4700. @group
  4701. 1: int add( int val, int incr, int doit )
  4702. 2: @{
  4703. 3: if( doit )
  4704. 4: @{
  4705. 5: return( val + incr );
  4706. 6: @}
  4707. 7: return( val );
  4708. 8: @}
  4709. @end group
  4710. @end example
  4711. In other words, we want to change the indentation of braces that open a
  4712. block following a condition so that the braces line up under the
  4713. conditional, instead of being indented. Notice that the construct we
  4714. want to change starts on line 4. To change the indentation of a line,
  4715. we need to see which syntactic symbols affect the offset calculations
  4716. for that line. Hitting @kbd{C-c C-s} on line 4 yields:
  4717. @example
  4718. ((substatement-open 44))
  4719. @end example
  4720. @noindent
  4721. so we know that to change the offset of the open brace, we need to
  4722. change the indentation for the @code{substatement-open} syntactic
  4723. symbol.
  4724. To do this interactively, just hit @kbd{C-c C-o}. This prompts
  4725. you for the syntactic symbol to change, providing a reasonable default.
  4726. In this case, the default is @code{substatement-open}, which is just the
  4727. syntactic symbol we want to change!
  4728. After you hit return, @ccmode{} will then prompt you for the new
  4729. offset value, with the old value as the default. The default in this
  4730. case is @samp{+}, but we want no extra indentation so enter
  4731. @samp{0} and @kbd{RET}. This will associate the offset 0 with the
  4732. syntactic symbol @code{substatement-open}.
  4733. To check your changes quickly, just hit @kbd{C-c C-q}
  4734. (@code{c-indent-defun}) to reindent the entire function. The example
  4735. should now look like:
  4736. @example
  4737. @group
  4738. 1: int add( int val, int incr, int doit )
  4739. 2: @{
  4740. 3: if( doit )
  4741. 4: @{
  4742. 5: return( val + incr );
  4743. 6: @}
  4744. 7: return( val );
  4745. 8: @}
  4746. @end group
  4747. @end example
  4748. Notice how just changing the open brace offset on line 4 is all we
  4749. needed to do. Since the other affected lines are indented relative to
  4750. line 4, they are automatically indented the way you'd expect. For more
  4751. complicated examples, this might not always work. The general approach
  4752. to take is to always start adjusting offsets for lines higher up in the
  4753. file, then reindent and see if any following lines need further
  4754. adjustments.
  4755. @c Move this bit to "Styles" (2005/10/7)
  4756. @deffn Command c-set-offset symbol offset
  4757. @findex set-offset (c-)
  4758. @kindex C-c C-o
  4759. This is the command bound to @kbd{C-c C-o}. It provides a convenient
  4760. way to set offsets on @code{c-offsets-alist} both interactively (see
  4761. the example above) and from your mode hook.
  4762. It takes two arguments when used programmatically: @var{symbol} is the
  4763. syntactic element symbol to change and @var{offset} is the new offset
  4764. for that syntactic element.
  4765. @end deffn
  4766. @c End of MOVE THIS BIT.
  4767. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4768. @node Line-Up Functions, Custom Line-Up, Interactive Customization, Customizing Indentation
  4769. @comment node-name, next, previous, up
  4770. @section Line-Up Functions
  4771. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4772. @cindex line-up function
  4773. @cindex indentation function
  4774. Often there are cases when a simple offset setting on a syntactic
  4775. symbol isn't enough to get the desired indentation---for example, you
  4776. might want to line up a closing parenthesis with the matching opening
  4777. one rather than indenting relative to its ``anchor point''. @ccmode{}
  4778. provides this flexibility with @dfn{line-up functions}.
  4779. The way you associate a line-up function with a syntactic symbol is
  4780. described in @ref{c-offsets-alist}. @ccmode{} comes with many
  4781. predefined line-up functions for common situations. If none of these
  4782. does what you want, you can write your own. @xref{Custom Line-Up}.
  4783. Sometimes, it is easier to tweak the standard indentation by adding a
  4784. function to @code{c-special-indent-hook} (@pxref{Other Indentation}).
  4785. The line-up functions haven't been adapted for AWK buffers or tested
  4786. with them. Some of them might work serendipitously. There shouldn't be
  4787. any problems writing custom line-up functions for AWK mode.
  4788. The calling convention for line-up functions is described fully in
  4789. @ref{Custom Line-Up}. Roughly speaking, the return value is either an
  4790. offset itself (such as @code{+} or @code{[0]}) or it's @code{nil},
  4791. meaning ``this function is inappropriate in this case; try a
  4792. different one''. @xref{c-offsets-alist}.
  4793. The subsections below describe all the standard line-up functions,
  4794. categorized by the sort of token the lining-up centers around. For
  4795. each of these functions there is a ``works with'' list that indicates
  4796. which syntactic symbols the function is intended to be used with.
  4797. @macro workswith
  4798. @emph{Works with:@ }
  4799. @end macro
  4800. @ifinfo
  4801. @unmacro workswith
  4802. @macro workswith
  4803. Works with:
  4804. @end macro
  4805. @end ifinfo
  4806. @macro sssTBasicOffset
  4807. <--> @i{c-basic-offset}@c
  4808. @end macro
  4809. @macro sssTsssTBasicOffset
  4810. <--><--> @i{c-basic-offset}@c
  4811. @end macro
  4812. @macro hereFn{func}
  4813. <- @i{\func\}@c
  4814. @end macro
  4815. @c The TeX backend seems to insert extra spaces around the argument. :P
  4816. @iftex
  4817. @unmacro hereFn
  4818. @macro hereFn{func}
  4819. <-@i{\func\}@c
  4820. @end macro
  4821. @end iftex
  4822. @menu
  4823. * Brace/Paren Line-Up::
  4824. * List Line-Up::
  4825. * Operator Line-Up::
  4826. * Comment Line-Up::
  4827. * Misc Line-Up::
  4828. @end menu
  4829. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4830. @node Brace/Paren Line-Up, List Line-Up, Line-Up Functions, Line-Up Functions
  4831. @comment node-name, next, previous, up
  4832. @subsection Brace and Parenthesis Line-Up Functions
  4833. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4834. The line-up functions here calculate the indentation for braces,
  4835. parentheses and statements within brace blocks.
  4836. @defun c-lineup-close-paren
  4837. @findex lineup-close-paren (c-)
  4838. Line up the closing paren under its corresponding open paren if the
  4839. open paren is followed by code. If the open paren ends its line, no
  4840. indentation is added. E.g.:
  4841. @example
  4842. @group
  4843. main (int,
  4844. char **
  4845. ) @hereFn{c-lineup-close-paren}
  4846. @end group
  4847. @end example
  4848. @noindent
  4849. and
  4850. @example
  4851. @group
  4852. main (
  4853. int, char **
  4854. ) @hereFn{c-lineup-close-paren}
  4855. @end group
  4856. @end example
  4857. As a special case, if a brace block is opened at the same line as the
  4858. open parenthesis of the argument list, the indentation is
  4859. @code{c-basic-offset} instead of the open paren column. See
  4860. @code{c-lineup-arglist} for further discussion of this ``DWIM'' measure.
  4861. @workswith All @code{*-close} symbols.
  4862. @end defun
  4863. @comment ------------------------------------------------------------
  4864. @anchor{c-lineup-arglist-close-under-paren}
  4865. @defun c-lineup-arglist-close-under-paren
  4866. @findex lineup-arglist-close-under-paren (c-)
  4867. Set your @code{arglist-close} syntactic symbol to this line-up function
  4868. so that parentheses that close argument lists will line up under the
  4869. parenthesis that opened the argument list. It can also be used with
  4870. @code{arglist-cont} and @code{arglist-cont-nonempty} to line up all
  4871. lines inside a parenthesis under the open paren.
  4872. As a special case, if a brace block is opened at the same line as the
  4873. open parenthesis of the argument list, the indentation is
  4874. @code{c-basic-offset} only. See @code{c-lineup-arglist} for further
  4875. discussion of this ``DWIM'' measure.
  4876. @workswith Almost all symbols, but are typically most useful on
  4877. @code{arglist-close}, @code{brace-list-close}, @code{arglist-cont} and
  4878. @code{arglist-cont-nonempty}.
  4879. @end defun
  4880. @comment ------------------------------------------------------------
  4881. @defun c-indent-one-line-block
  4882. @findex indent-one-line-block (c-)
  4883. Indent a one line block @code{c-basic-offset} extra. E.g.:
  4884. @example
  4885. @group
  4886. if (n > 0)
  4887. @{m+=n; n=0;@} @hereFn{c-indent-one-line-block}
  4888. @sssTBasicOffset{}
  4889. @end group
  4890. @end example
  4891. @noindent
  4892. and
  4893. @example
  4894. @group
  4895. if (n > 0)
  4896. @{ @hereFn{c-indent-one-line-block}
  4897. m+=n; n=0;
  4898. @}
  4899. @end group
  4900. @end example
  4901. The block may be surrounded by any kind of parenthesis characters.
  4902. @code{nil} is returned if the line doesn't start with a one line block,
  4903. which makes the function usable in list expressions.
  4904. @workswith Almost all syntactic symbols, but most useful on the
  4905. @code{-open} symbols.
  4906. @end defun
  4907. @comment ------------------------------------------------------------
  4908. @defun c-indent-multi-line-block
  4909. @findex indent-multi-line-block (c-)
  4910. Indent a multiline block @code{c-basic-offset} extra. E.g.:
  4911. @example
  4912. @group
  4913. int *foo[] = @{
  4914. NULL,
  4915. @{17@}, @hereFn{c-indent-multi-line-block}
  4916. @end group
  4917. @end example
  4918. @noindent
  4919. and
  4920. @example
  4921. @group
  4922. int *foo[] = @{
  4923. NULL,
  4924. @{ @hereFn{c-indent-multi-line-block}
  4925. 17
  4926. @},
  4927. @sssTBasicOffset{}
  4928. @end group
  4929. @end example
  4930. The block may be surrounded by any kind of parenthesis characters.
  4931. @code{nil} is returned if the line doesn't start with a multiline
  4932. block, which makes the function usable in list expressions.
  4933. @workswith Almost all syntactic symbols, but most useful on the
  4934. @code{-open} symbols.
  4935. @end defun
  4936. @comment ------------------------------------------------------------
  4937. @defun c-lineup-runin-statements
  4938. @findex lineup-runin-statements (c-)
  4939. Line up statements for coding standards which place the first statement
  4940. in a block on the same line as the block opening brace@footnote{Run-in
  4941. style doesn't really work too well. You might need to write your own
  4942. custom line-up functions to better support this style.}. E.g.:
  4943. @example
  4944. @group
  4945. int main()
  4946. @{ puts ("Hello!");
  4947. return 0; @hereFn{c-lineup-runin-statements}
  4948. @}
  4949. @end group
  4950. @end example
  4951. If there is no statement after the opening brace to align with,
  4952. @code{nil} is returned. This makes the function usable in list
  4953. expressions.
  4954. @workswith The @code{statement} syntactic symbol.
  4955. @end defun
  4956. @comment ------------------------------------------------------------
  4957. @defun c-lineup-inexpr-block
  4958. @findex lineup-inexpr-block (c-)
  4959. This can be used with the in-expression block symbols to indent the
  4960. whole block to the column where the construct is started. E.g., for Java
  4961. anonymous classes, this lines up the class under the @samp{new} keyword,
  4962. and in Pike it lines up the lambda function body under the @samp{lambda}
  4963. keyword. Returns @code{nil} if the block isn't part of such a
  4964. construct.
  4965. @workswith @code{inlambda}, @code{inexpr-statement},
  4966. @code{inexpr-class}.
  4967. @end defun
  4968. @comment ------------------------------------------------------------
  4969. @defun c-lineup-after-whitesmith-blocks
  4970. @findex lineup-after-whitesmith-blocks (c-)
  4971. Compensate for Whitesmith style indentation of blocks. Due to the way
  4972. @ccmode{} calculates anchor positions for normal lines inside blocks,
  4973. this function is necessary for those lines to get correct Whitesmith
  4974. style indentation. Consider the following examples:
  4975. @example
  4976. @group
  4977. int foo()
  4978. @{
  4979. a;
  4980. x; @hereFn{c-lineup-after-whitesmith-blocks}
  4981. @end group
  4982. @end example
  4983. @example
  4984. @group
  4985. int foo()
  4986. @{
  4987. @{
  4988. a;
  4989. @}
  4990. x; @hereFn{c-lineup-after-whitesmith-blocks}
  4991. @end group
  4992. @end example
  4993. The fact that the line with @code{x} is preceded by a Whitesmith style
  4994. indented block in the latter case and not the first should not affect
  4995. its indentation. But since CC Mode in cases like this uses the
  4996. indentation of the preceding statement as anchor position, the @code{x}
  4997. would in the second case be indented too much if the offset for
  4998. @code{statement} was set simply to zero.
  4999. This lineup function corrects for this situation by detecting if the
  5000. anchor position is at an open paren character. In that case, it instead
  5001. indents relative to the surrounding block just like
  5002. @code{c-lineup-whitesmith-in-block}.
  5003. @workswith @code{brace-list-entry}, @code{brace-entry-open},
  5004. @code{statement}, @code{arglist-cont}.
  5005. @end defun
  5006. @comment ------------------------------------------------------------
  5007. @defun c-lineup-whitesmith-in-block
  5008. @findex lineup-whitesmith-in-block (c-)
  5009. Line up lines inside a block in Whitesmith style. It's done in a way
  5010. that works both when the opening brace hangs and when it doesn't. E.g.:
  5011. @example
  5012. @group
  5013. something
  5014. @{
  5015. foo; @hereFn{c-lineup-whitesmith-in-block}
  5016. @}
  5017. @end group
  5018. @end example
  5019. @noindent
  5020. and
  5021. @example
  5022. @group
  5023. something @{
  5024. foo; @hereFn{c-lineup-whitesmith-in-block}
  5025. @}
  5026. @sssTBasicOffset{}
  5027. @end group
  5028. @end example
  5029. In the first case the indentation is kept unchanged, in the second
  5030. @code{c-basic-offset} is added.
  5031. @workswith @code{defun-close}, @code{defun-block-intro},
  5032. @code{inline-close}, @code{block-close}, @code{brace-list-close},
  5033. @code{brace-list-intro}, @code{statement-block-intro},
  5034. @code{arglist-intro}, @code{arglist-cont-nonempty},
  5035. @code{arglist-close}, and all @code{in*} symbols, e.g., @code{inclass}
  5036. and @code{inextern-lang}.
  5037. @end defun
  5038. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5039. @node List Line-Up, Operator Line-Up, Brace/Paren Line-Up, Line-Up Functions
  5040. @comment node-name, next, previous, up
  5041. @subsection List Line-Up Functions
  5042. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5043. The line-up functions here calculate the indentation for lines which
  5044. form lists of items, usually separated by commas.
  5045. The function @ref{c-lineup-arglist-close-under-paren}, which is mainly
  5046. for indenting a close parenthesis, is also useful for the lines
  5047. contained within parentheses.
  5048. @defun c-lineup-arglist
  5049. @findex lineup-arglist (c-)
  5050. Line up the current argument line under the first argument.
  5051. As a special case, if an argument on the same line as the open
  5052. parenthesis starts with a brace block opener, the indentation is
  5053. @code{c-basic-offset} only. This is intended as a ``DWIM'' measure in
  5054. cases like macros that contain statement blocks, e.g.:
  5055. @example
  5056. @group
  5057. A_VERY_LONG_MACRO_NAME (@{
  5058. some (code, with + long, lines * in[it]);
  5059. @});
  5060. @sssTBasicOffset{}
  5061. @end group
  5062. @end example
  5063. This is motivated partly because it's more in line with how code
  5064. blocks are handled, and partly since it approximates the behavior of
  5065. earlier CC Mode versions, which due to inaccurate analysis tended to
  5066. indent such cases this way.
  5067. @workswith @code{arglist-cont-nonempty}, @code{arglist-close}.
  5068. @end defun
  5069. @comment ------------------------------------------------------------
  5070. @defun c-lineup-arglist-intro-after-paren
  5071. @findex lineup-arglist-intro-after-paren (c-)
  5072. Line up a line to just after the open paren of the surrounding paren or
  5073. brace block.
  5074. @workswith @code{defun-block-intro}, @code{brace-list-intro},
  5075. @code{statement-block-intro}, @code{statement-case-intro},
  5076. @code{arglist-intro}.
  5077. @end defun
  5078. @comment ------------------------------------------------------------
  5079. @defun c-lineup-multi-inher
  5080. @findex lineup-multi-inher (c-)
  5081. Line up the classes in C++ multiple inheritance clauses and member
  5082. initializers under each other. E.g.:
  5083. @example
  5084. @group
  5085. Foo::Foo (int a, int b):
  5086. Cyphr (a),
  5087. Bar (b) @hereFn{c-lineup-multi-inher}
  5088. @end group
  5089. @end example
  5090. @noindent
  5091. and
  5092. @example
  5093. @group
  5094. class Foo
  5095. : public Cyphr,
  5096. public Bar @hereFn{c-lineup-multi-inher}
  5097. @end group
  5098. @end example
  5099. @noindent
  5100. and
  5101. @example
  5102. @group
  5103. Foo::Foo (int a, int b)
  5104. : Cyphr (a)
  5105. , Bar (b) @hereFn{c-lineup-multi-inher}
  5106. @end group
  5107. @end example
  5108. @workswith @code{inher-cont}, @code{member-init-cont}.
  5109. @end defun
  5110. @comment ------------------------------------------------------------
  5111. @defun c-lineup-java-inher
  5112. @findex lineup-java-inher (c-)
  5113. Line up Java implements and extends declarations. If class names
  5114. follow on the same line as the @samp{implements}/@samp{extends}
  5115. keyword, they are lined up under each other. Otherwise, they are
  5116. indented by adding @code{c-basic-offset} to the column of the keyword.
  5117. E.g.:
  5118. @example
  5119. @group
  5120. class Foo
  5121. extends
  5122. Bar @hereFn{c-lineup-java-inher}
  5123. @sssTBasicOffset{}
  5124. @end group
  5125. @end example
  5126. @noindent
  5127. and
  5128. @example
  5129. @group
  5130. class Foo
  5131. extends Cyphr,
  5132. Bar @hereFn{c-lineup-java-inher}
  5133. @end group
  5134. @end example
  5135. @workswith @code{inher-cont}.
  5136. @end defun
  5137. @comment ------------------------------------------------------------
  5138. @defun c-lineup-java-throws
  5139. @findex lineup-java-throws (c-)
  5140. Line up Java throws declarations. If exception names follow on the
  5141. same line as the throws keyword, they are lined up under each other.
  5142. Otherwise, they are indented by adding @code{c-basic-offset} to the
  5143. column of the @samp{throws} keyword. The @samp{throws} keyword itself
  5144. is also indented by @code{c-basic-offset} from the function declaration
  5145. start if it doesn't hang. E.g.:
  5146. @example
  5147. @group
  5148. int foo()
  5149. throws @hereFn{c-lineup-java-throws}
  5150. Bar @hereFn{c-lineup-java-throws}
  5151. @sssTsssTBasicOffset{}
  5152. @end group
  5153. @end example
  5154. @noindent
  5155. and
  5156. @example
  5157. @group
  5158. int foo() throws Cyphr,
  5159. Bar, @hereFn{c-lineup-java-throws}
  5160. Vlod @hereFn{c-lineup-java-throws}
  5161. @end group
  5162. @end example
  5163. @workswith @code{func-decl-cont}.
  5164. @end defun
  5165. @comment ------------------------------------------------------------
  5166. @defun c-lineup-template-args
  5167. @findex lineup-template-args (c-)
  5168. Line up the arguments of a template argument list under each other, but
  5169. only in the case where the first argument is on the same line as the
  5170. opening @samp{<}.
  5171. To allow this function to be used in a list expression, @code{nil} is
  5172. returned if there's no template argument on the first line.
  5173. @workswith @code{template-args-cont}.
  5174. @end defun
  5175. @comment ------------------------------------------------------------
  5176. @defun c-lineup-ObjC-method-call
  5177. @findex lineup-ObjC-method-call (c-)
  5178. For Objective-C code, line up selector args as Emacs Lisp mode does
  5179. with function args: go to the position right after the message receiver,
  5180. and if you are at the end of the line, indent the current line
  5181. c-basic-offset columns from the opening bracket; otherwise you are
  5182. looking at the first character of the first method call argument, so
  5183. lineup the current line with it.
  5184. @workswith @code{objc-method-call-cont}.
  5185. @end defun
  5186. @comment ------------------------------------------------------------
  5187. @defun c-lineup-ObjC-method-args
  5188. @findex lineup-ObjC-method-args (c-)
  5189. For Objective-C code, line up the colons that separate args. The colon
  5190. on the current line is aligned with the one on the first line.
  5191. @workswith @code{objc-method-args-cont}.
  5192. @end defun
  5193. @comment ------------------------------------------------------------
  5194. @defun c-lineup-ObjC-method-args-2
  5195. @findex lineup-ObjC-method-args-2 (c-)
  5196. Similar to @code{c-lineup-ObjC-method-args} but lines up the colon on
  5197. the current line with the colon on the previous line.
  5198. @workswith @code{objc-method-args-cont}.
  5199. @end defun
  5200. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5201. @node Operator Line-Up, Comment Line-Up, List Line-Up, Line-Up Functions
  5202. @comment node-name, next, previous, up
  5203. @subsection Operator Line-Up Functions
  5204. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5205. The line-up functions here calculate the indentation for lines which
  5206. start with an operator, by lining it up with something on the previous
  5207. line.
  5208. @defun c-lineup-argcont
  5209. @findex lineup-argcont (c-)
  5210. Line up a continued argument. E.g.:
  5211. @example
  5212. @group
  5213. foo (xyz, aaa + bbb + ccc
  5214. + ddd + eee + fff); @hereFn{c-lineup-argcont}
  5215. @end group
  5216. @end example
  5217. Only continuation lines like this are touched, @code{nil} is returned on
  5218. lines which are the start of an argument.
  5219. Within a gcc @code{asm} block, @code{:} is recognized as an argument
  5220. separator, but of course only between operand specifications, not in the
  5221. expressions for the operands.
  5222. @workswith @code{arglist-cont}, @code{arglist-cont-nonempty}.
  5223. @end defun
  5224. @comment ------------------------------------------------------------
  5225. @defun c-lineup-arglist-operators
  5226. @findex lineup-arglist-operators (c-)
  5227. Line up lines starting with an infix operator under the open paren.
  5228. Return @code{nil} on lines that don't start with an operator, to leave
  5229. those cases to other line-up functions. Example:
  5230. @example
  5231. @group
  5232. if ( x < 10
  5233. || at_limit (x, @hereFn{c-lineup-arglist-operators}
  5234. list) @hereFn{c-lineup-arglist-operators@r{ returns nil}}
  5235. )
  5236. @end group
  5237. @end example
  5238. Since this function doesn't do anything for lines without an infix
  5239. operator you typically want to use it together with some other lineup
  5240. settings, e.g., as follows (the @code{arglist-close} setting is just a
  5241. suggestion to get a consistent style):
  5242. @example
  5243. (c-set-offset 'arglist-cont
  5244. '(c-lineup-arglist-operators 0))
  5245. (c-set-offset 'arglist-cont-nonempty
  5246. '(c-lineup-arglist-operators c-lineup-arglist))
  5247. (c-set-offset 'arglist-close
  5248. '(c-lineup-arglist-close-under-paren))
  5249. @end example
  5250. @workswith @code{arglist-cont}, @code{arglist-cont-nonempty}.
  5251. @end defun
  5252. @comment ------------------------------------------------------------
  5253. @defun c-lineup-assignments
  5254. @findex lineup-assignments (c-)
  5255. Line up the current line after the assignment operator on the first line
  5256. in the statement. If there isn't any, return @code{nil} to allow stacking with
  5257. other line-up functions. If the current line contains an assignment
  5258. operator too, try to align it with the first one.
  5259. @workswith @code{topmost-intro-cont}, @code{statement-cont},
  5260. @code{arglist-cont}, @code{arglist-cont-nonempty}.
  5261. @end defun
  5262. @comment ------------------------------------------------------------
  5263. @defun c-lineup-math
  5264. @findex lineup-math (c-)
  5265. Like @code{c-lineup-assignments} but indent with @code{c-basic-offset}
  5266. if no assignment operator was found on the first line. I.e., this
  5267. function is the same as specifying a list @code{(c-lineup-assignments
  5268. +)}. It's provided for compatibility with old configurations.
  5269. @workswith @code{topmost-intro-cont}, @code{statement-cont},
  5270. @code{arglist-cont}, @code{arglist-cont-nonempty}.
  5271. @end defun
  5272. @comment ------------------------------------------------------------
  5273. @defun c-lineup-cascaded-calls
  5274. @findex lineup-cascaded-calls (c-)
  5275. Line up ``cascaded calls'' under each other. If the line begins with
  5276. @code{->} or @code{.} and the preceding line ends with one or more
  5277. function calls preceded by the same token, then the arrow is lined up
  5278. with the first of those tokens. E.g.:
  5279. @example
  5280. @group
  5281. r = proc->add(17)->add(18)
  5282. ->add(19) + @hereFn{c-lineup-cascaded-calls}
  5283. offset; @hereFn{c-lineup-cascaded-calls@r{ (inactive)}}
  5284. @end group
  5285. @end example
  5286. In any other situation @code{nil} is returned to allow use in list
  5287. expressions.
  5288. @workswith @code{topmost-intro-cont}, @code{statement-cont},
  5289. @code{arglist-cont}, @code{arglist-cont-nonempty}.
  5290. @end defun
  5291. @comment ------------------------------------------------------------
  5292. @defun c-lineup-streamop
  5293. @findex lineup-streamop (c-)
  5294. Line up C++ stream operators (i.e., @samp{<<} and @samp{>>}).
  5295. @workswith @code{stream-op}.
  5296. @end defun
  5297. @comment ------------------------------------------------------------
  5298. @defun c-lineup-string-cont
  5299. @findex lineup-string-cont (c-)
  5300. Line up a continued string under the one it continues. A continued
  5301. string in this sense is where a string literal follows directly after
  5302. another one. E.g.:
  5303. @example
  5304. @group
  5305. result = prefix + "A message "
  5306. "string."; @hereFn{c-lineup-string-cont}
  5307. @end group
  5308. @end example
  5309. @code{nil} is returned in other situations, to allow stacking with other
  5310. lineup functions.
  5311. @workswith @code{topmost-intro-cont}, @code{statement-cont},
  5312. @code{arglist-cont}, @code{arglist-cont-nonempty}.
  5313. @end defun
  5314. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5315. @node Comment Line-Up, Misc Line-Up, Operator Line-Up, Line-Up Functions
  5316. @comment node-name, next, previous, up
  5317. @subsection Comment Line-Up Functions
  5318. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5319. The lineup functions here calculate the indentation for several types
  5320. of comment structure.
  5321. @defun c-lineup-C-comments
  5322. @findex lineup-C-comments (c-)
  5323. Line up C block comment continuation lines. Various heuristics are used
  5324. to handle most of the common comment styles. Some examples:
  5325. @example
  5326. @group
  5327. /* /** /*
  5328. * text * text text
  5329. */ */ */
  5330. @end group
  5331. @end example
  5332. @example
  5333. @group
  5334. /* text /* /**
  5335. text ** text ** text
  5336. */ */ */
  5337. @end group
  5338. @end example
  5339. @example
  5340. @group
  5341. /**************************************************
  5342. * text
  5343. *************************************************/
  5344. @end group
  5345. @end example
  5346. @vindex comment-start-skip
  5347. @example
  5348. @group
  5349. /**************************************************
  5350. Free form text comments:
  5351. In comments with a long delimiter line at the
  5352. start, the indentation is kept unchanged for lines
  5353. that start with an empty comment line prefix. The
  5354. delimiter line is whatever matches the
  5355. @code{comment-start-skip} regexp.
  5356. **************************************************/
  5357. @end group
  5358. @end example
  5359. The style variable @code{c-comment-prefix-regexp} is used to recognize
  5360. the comment line prefix, e.g., the @samp{*} that usually starts every
  5361. line inside a comment.
  5362. @workswith The @code{c} syntactic symbol.
  5363. @end defun
  5364. @comment ------------------------------------------------------------
  5365. @defun c-lineup-comment
  5366. @findex lineup-comment (c-)
  5367. Line up a comment-only line according to the style variable
  5368. @code{c-comment-only-line-offset}. If the comment is lined up with a
  5369. comment starter on the previous line, that alignment is preserved.
  5370. @defopt c-comment-only-line-offset
  5371. @vindex comment-only-line-offset (c-)
  5372. This style variable specifies the extra offset for the line. It can
  5373. contain an integer or a cons cell of the form
  5374. @example
  5375. (@r{@var{non-anchored-offset}} . @r{@var{anchored-offset}})
  5376. @end example
  5377. @noindent
  5378. where @var{non-anchored-offset} is the amount of offset given to
  5379. non-column-zero anchored lines, and @var{anchored-offset} is the amount
  5380. of offset to give column-zero anchored lines. Just an integer as value
  5381. is equivalent to @code{(@r{@var{value}} . -1000)}.
  5382. @end defopt
  5383. @workswith @code{comment-intro}.
  5384. @end defun
  5385. @comment ------------------------------------------------------------
  5386. @defun c-lineup-knr-region-comment
  5387. @findex lineup-knr-region-comment (c-)
  5388. Line up a comment in the ``K&R region'' with the declaration. That is
  5389. the region between the function or class header and the beginning of the
  5390. block. E.g.:
  5391. @example
  5392. @group
  5393. int main()
  5394. /* Called at startup. */ @hereFn{c-lineup-knr-region-comment}
  5395. @{
  5396. return 0;
  5397. @}
  5398. @end group
  5399. @end example
  5400. Return @code{nil} if called in any other situation, to be useful in list
  5401. expressions.
  5402. @workswith @code{comment-intro}.
  5403. @end defun
  5404. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5405. @node Misc Line-Up, , Comment Line-Up, Line-Up Functions
  5406. @comment node-name, next, previous, up
  5407. @subsection Miscellaneous Line-Up Functions
  5408. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5409. The line-up functions here are the odds and ends which didn't fit into
  5410. any earlier category.
  5411. @defun c-lineup-dont-change
  5412. @findex lineup-dont-change (c-)
  5413. This lineup function makes the line stay at whatever indentation it
  5414. already has; think of it as an identity function for lineups.
  5415. @workswith Any syntactic symbol.
  5416. @end defun
  5417. @comment ------------------------------------------------------------
  5418. @defun c-lineup-under-anchor
  5419. Line up a line directly underneath its anchor point. This is like
  5420. @samp{0}, except any previously calculated offset contributions are
  5421. disregarded.
  5422. @workswith Any syntactic symbol which has an anchor point.
  5423. @end defun
  5424. @comment ------------------------------------------------------------
  5425. @defun c-lineup-cpp-define
  5426. @findex lineup-cpp-define (c-)
  5427. Line up macro continuation lines according to the indentation of the
  5428. construct preceding the macro. E.g.:
  5429. @example
  5430. @group
  5431. const char msg[] = @hereFn{@r{The beginning of the preceding construct.}}
  5432. \"Some text.\";
  5433. #define X(A, B) \
  5434. do @{ \ @hereFn{c-lineup-cpp-define}
  5435. printf (A, B); \
  5436. @} while (0)
  5437. @end group
  5438. @end example
  5439. @noindent
  5440. and:
  5441. @example
  5442. @group
  5443. int dribble() @{
  5444. if (!running) @hereFn{@r{The beginning of the preceding construct.}}
  5445. error(\"Not running!\");
  5446. #define X(A, B) \
  5447. do @{ \ @hereFn{c-lineup-cpp-define}
  5448. printf (A, B); \
  5449. @} while (0)
  5450. @end group
  5451. @end example
  5452. If @code{c-syntactic-indentation-in-macros} is non-@code{nil}, the
  5453. function returns the relative indentation to the macro start line to
  5454. allow accumulation with other offsets. E.g., in the following cases,
  5455. @code{cpp-define-intro} is combined with the
  5456. @code{statement-block-intro} that comes from the @samp{do @{} that hangs
  5457. on the @samp{#define} line:
  5458. @example
  5459. @group
  5460. const char msg[] =
  5461. \"Some text.\";
  5462. #define X(A, B) do @{ \
  5463. printf (A, B); \ @hereFn{c-lineup-cpp-define}
  5464. this->refs++; \
  5465. @} while (0) @hereFn{c-lineup-cpp-define}
  5466. @end group
  5467. @end example
  5468. @noindent
  5469. and:
  5470. @example
  5471. @group
  5472. int dribble() @{
  5473. if (!running)
  5474. error(\"Not running!\");
  5475. #define X(A, B) do @{ \
  5476. printf (A, B); \ @hereFn{c-lineup-cpp-define}
  5477. this->refs++; \
  5478. @} while (0) @hereFn{c-lineup-cpp-define}
  5479. @end group
  5480. @end example
  5481. The relative indentation returned by @code{c-lineup-cpp-define} is zero
  5482. and two, respectively, on the two lines in each of these examples. They
  5483. are then added to the two column indentation that
  5484. @code{statement-block-intro} gives in both cases here.
  5485. If the relative indentation is zero, then @code{nil} is returned
  5486. instead. That is useful in a list expression to specify the default
  5487. indentation on the top level.
  5488. If @code{c-syntactic-indentation-in-macros} is @code{nil} then this
  5489. function keeps the current indentation, except for empty lines (ignoring
  5490. the ending backslash) where it takes the indentation from the closest
  5491. preceding nonempty line in the macro. If there's no such line in the
  5492. macro then the indentation is taken from the construct preceding it, as
  5493. described above.
  5494. @workswith @code{cpp-define-intro}.
  5495. @end defun
  5496. @comment ------------------------------------------------------------
  5497. @defun c-lineup-gcc-asm-reg
  5498. @findex lineup-gcc-asm-reg (c-)
  5499. Line up a gcc asm register under one on a previous line.
  5500. @example
  5501. @group
  5502. asm ("foo %1, %0\n"
  5503. "bar %0, %1"
  5504. : "=r" (w),
  5505. "=r" (x)
  5506. : "0" (y),
  5507. "1" (z));
  5508. @end group
  5509. @end example
  5510. The @samp{x} line is aligned to the text after the @samp{:} on the
  5511. @samp{w} line, and similarly @samp{z} under @samp{y}.
  5512. This is done only in an @samp{asm} or @samp{__asm__} block, and only to
  5513. those lines mentioned. Anywhere else @code{nil} is returned. The usual
  5514. arrangement is to have this routine as an extra feature at the start of
  5515. arglist lineups, e.g.:
  5516. @example
  5517. (c-lineup-gcc-asm-reg c-lineup-arglist)
  5518. @end example
  5519. @workswith @code{arglist-cont}, @code{arglist-cont-nonempty}.
  5520. @end defun
  5521. @comment ------------------------------------------------------------
  5522. @defun c-lineup-topmost-intro-cont
  5523. @findex lineup-topmost-intro-cont (c-)
  5524. Line up declaration continuation lines zero or one indentation
  5525. step@footnote{This function is mainly provided to mimic the behavior of
  5526. CC Mode 5.28 and earlier where this case wasn't handled consistently so
  5527. that those lines could be analyzed as either topmost-intro-cont or
  5528. statement-cont. It's used for @code{topmost-intro-cont} by default, but
  5529. you might consider using @code{+} instead.}. For lines preceding a
  5530. definition, zero is used. For other lines, @code{c-basic-offset} is
  5531. added to the indentation. E.g.:
  5532. @example
  5533. @group
  5534. int
  5535. neg (int i) @hereFn{c-lineup-topmost-intro-cont}
  5536. @{
  5537. return -i;
  5538. @}
  5539. @end group
  5540. @end example
  5541. @noindent
  5542. and
  5543. @example
  5544. @group
  5545. struct
  5546. larch @hereFn{c-lineup-topmost-intro-cont}
  5547. @{
  5548. double height;
  5549. @}
  5550. the_larch, @hereFn{c-lineup-topmost-intro-cont}
  5551. another_larch; @hereFn{c-lineup-topmost-intro-cont}
  5552. @sssTBasicOffset{}
  5553. @end group
  5554. @end example
  5555. @noindent
  5556. and
  5557. @example
  5558. @group
  5559. struct larch
  5560. the_larch, @hereFn{c-lineup-topmost-intro-cont}
  5561. another_larch; @hereFn{c-lineup-topmost-intro-cont}
  5562. @end group
  5563. @end example
  5564. @workswith @code{topmost-intro-cont}.
  5565. @end defun
  5566. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5567. @node Custom Line-Up, Other Indentation, Line-Up Functions, Customizing Indentation
  5568. @comment node-name, next, previous, up
  5569. @section Custom Line-Up Functions
  5570. @cindex customization, indentation functions
  5571. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5572. The most flexible way to customize indentation is by writing custom
  5573. line-up functions, and associating them with specific syntactic
  5574. symbols (@pxref{c-offsets-alist}). Depending on the effect you want,
  5575. it might be better to write a @code{c-special-indent-hook} function
  5576. rather than a line-up function (@pxref{Other Indentation}).
  5577. @ccmode{} comes with an extensive set of predefined line-up functions,
  5578. not all of which are used by the default styles. So there's a good
  5579. chance the function you want already exists. @xref{Line-Up
  5580. Functions}, for a list of them. If you write your own line-up
  5581. function, it's probably a good idea to start working from one of these
  5582. predefined functions, which can be found in the file
  5583. @file{cc-align.el}. If you have written a line-up function that you
  5584. think is generally useful, you're very welcome to contribute it;
  5585. please contact @email{bug-cc-mode@@gnu.org}.
  5586. Line-up functions are passed a single argument, the syntactic
  5587. element (see below). At the time of the call, point will be somewhere
  5588. on the line being indented. The return value is a
  5589. @code{c-offsets-alist} offset specification: for example, an integer,
  5590. a symbol such as @code{+}, a vector, @code{nil}@footnote{Returning
  5591. @code{nil} is useful when the offset specification for a syntactic
  5592. element is a list containing the line-up function
  5593. (@pxref{c-offsets-alist}).}, or even another line-up function. Full
  5594. details of these are in @ref{c-offsets-alist}.
  5595. Line-up functions must not move point or change the content of the
  5596. buffer (except temporarily). They are however allowed to do
  5597. @dfn{hidden buffer changes}, i.e., setting text properties for caching
  5598. purposes etc. Buffer undo recording is disabled while they run.
  5599. The syntactic element passed as the parameter to a line-up function is
  5600. a cons cell of the form
  5601. @example
  5602. (@r{@var{syntactic-symbol}} . @r{@var{anchor-position}})
  5603. @end example
  5604. @noindent
  5605. @c FIXME!!! The following sentence might be better omitted, since the
  5606. @c information is in the cross reference "Syntactic Analysis". 2005/10/2.
  5607. where @var{syntactic-symbol} is the symbol that the function was
  5608. called for, and @var{anchor-position} is the anchor position (if any)
  5609. for the construct that triggered the syntactic symbol
  5610. (@pxref{Syntactic Analysis}). This cons cell is how the syntactic
  5611. element of a line used to be represented in @ccmode{} 5.28 and
  5612. earlier. Line-up functions are still passed this cons cell, so as to
  5613. preserve compatibility with older configurations. In the future, we
  5614. may decide to convert to using the full list format---you can prepare
  5615. your setup for this by using the access functions
  5616. (@code{c-langelem-sym}, etc.)@: described below.
  5617. @vindex c-syntactic-element
  5618. @vindex syntactic-element (c-)
  5619. @vindex c-syntactic-context
  5620. @vindex syntactic-context (c-)
  5621. Some syntactic symbols, e.g., @code{arglist-cont-nonempty}, have more
  5622. info in the syntactic element: typically other positions that can be
  5623. interesting besides the anchor position. That info can't be accessed
  5624. through the passed argument, which is a cons cell. Instead, you can
  5625. get this information from the variable @code{c-syntactic-element},
  5626. which is dynamically bound to the complete syntactic element. The
  5627. variable @code{c-syntactic-context} might also be useful: it gets
  5628. dynamically bound to the complete syntactic context. @xref{Custom
  5629. Braces}.
  5630. @ccmode{} provides a few functions to access parts of syntactic
  5631. elements in a more abstract way. Besides making the code easier to
  5632. read, they also hide the difference between the old cons cell form
  5633. used in the line-up function argument and the new list form used in
  5634. @code{c-syntactic-element} and everywhere else. The functions are:
  5635. @defun c-langelem-sym langelem
  5636. @findex langelem-sym (c-)
  5637. Return the syntactic symbol in @var{langelem}.
  5638. @end defun
  5639. @defun c-langelem-pos langelem
  5640. @findex langelem-pos (c-)
  5641. Return the anchor position in @var{langelem}, or @code{nil} if there is none.
  5642. @end defun
  5643. @defun c-langelem-col langelem &optional preserve-point
  5644. @findex langelem-col (c-)
  5645. Return the column of the anchor position in @var{langelem}. Also move
  5646. the point to that position unless @var{preserve-point} is
  5647. non-@code{nil}.
  5648. @end defun
  5649. @defun c-langelem-2nd-pos langelem
  5650. @findex langelem-2nd-pos (c-)
  5651. Return the secondary position in @var{langelem}, or @code{nil} if there
  5652. is none.
  5653. Note that the return value of this function is always @code{nil} if
  5654. @var{langelem} is in the old cons cell form. Thus this function is
  5655. only meaningful when used on syntactic elements taken from
  5656. @code{c-syntactic-element} or @code{c-syntactic-context}.
  5657. @end defun
  5658. Sometimes you may need to use the syntactic context of a line other
  5659. than the one being indented. You can determine this by (temporarily)
  5660. moving point onto this line and calling @code{c-guess-basic-syntax}
  5661. (@pxref{Syntactic Analysis}).
  5662. Custom line-up functions can be as simple or as complex as you like, and
  5663. any syntactic symbol that appears in @code{c-offsets-alist} can have a
  5664. custom line-up function associated with it.
  5665. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5666. @node Other Indentation, , Custom Line-Up, Customizing Indentation
  5667. @comment node-name, next, previous, up
  5668. @section Other Special Indentations
  5669. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5670. To configure macros which you invoke without a terminating @samp{;},
  5671. see @xref{Macros with ;}.
  5672. Here are the remaining odds and ends regarding indentation:
  5673. @defopt c-label-minimum-indentation
  5674. @vindex label-minimum-indentation (c-)
  5675. In @samp{gnu} style (@pxref{Built-in Styles}), a minimum indentation is
  5676. imposed on lines inside code blocks. This minimum indentation is
  5677. controlled by this style variable. The default value is 1.
  5678. @findex c-gnu-impose-minimum
  5679. @findex gnu-impose-minimum (c-)
  5680. It's the function @code{c-gnu-impose-minimum} that enforces this minimum
  5681. indentation. It must be present on @code{c-special-indent-hook} to
  5682. work.
  5683. @end defopt
  5684. @defopt c-special-indent-hook
  5685. @vindex special-indent-hook (c-)
  5686. This style variable is a standard hook variable that is called after
  5687. every line is indented by @ccmode{}. It is called only if
  5688. @code{c-syntactic-indentation} is non-@code{nil} (which it is by
  5689. default (@pxref{Indentation Engine Basics})). You can put a function
  5690. on this hook to do any special indentation or ad hoc line adjustments
  5691. your style dictates, such as adding extra indentation to constructors
  5692. or destructor declarations in a class definition, etc. Sometimes it
  5693. is better to write a custom Line-up Function instead (@pxref{Custom
  5694. Line-Up}).
  5695. When the indentation engine calls this hook, the variable
  5696. @code{c-syntactic-context} is bound to the current syntactic context
  5697. (i.e., what you would get by typing @kbd{C-c C-s} on the source line.
  5698. @xref{Custom Braces}.). Note that you should not change point or mark
  5699. inside a @code{c-special-indent-hook} function, i.e., you'll probably
  5700. want to wrap your function in a @code{save-excursion}@footnote{The
  5701. numerical value returned by @code{point} will change if you change the
  5702. indentation of the line within a @code{save-excursion} form, but point
  5703. itself will still be over the same piece of text.}.
  5704. Setting @code{c-special-indent-hook} in style definitions is handled
  5705. slightly differently from other variables---A style can only add
  5706. functions to this hook, not remove them. @xref{Style Variables}.
  5707. @end defopt
  5708. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5709. @node Custom Macros, Odds and Ends, Customizing Indentation, Top
  5710. @comment node-name, next, previous, up
  5711. @chapter Customizing Macros
  5712. @cindex macros
  5713. @cindex preprocessor directives
  5714. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5715. Preprocessor macros in C, C++, and Objective C (introduced by
  5716. @code{#define}) have a syntax different from the main language---for
  5717. example, a macro declaration is not terminated by a semicolon, and if
  5718. it is more than a line long, line breaks in it must be escaped with
  5719. backslashes. @ccmode{} has some commands to manipulate these, see
  5720. @ref{Macro Backslashes}.
  5721. Normally, the lines in a multi-line macro are indented relative to
  5722. each other as though they were code. You can suppress this behavior
  5723. by setting the following user option:
  5724. @defopt c-syntactic-indentation-in-macros
  5725. @vindex syntactic-indentation-in-macros (c-)
  5726. Enable syntactic analysis inside macros, which is the default. If this
  5727. is @code{nil}, all lines inside macro definitions are analyzed as
  5728. @code{cpp-macro-cont}.
  5729. @end defopt
  5730. Because a macro can expand into anything at all, near where one is
  5731. invoked @ccmode{} can only indent and fontify code heuristically.
  5732. Sometimes it gets it wrong. Usually you should try to design your
  5733. macros so that they ''look like ordinary code'' when you invoke them.
  5734. However, two situations are so common that @ccmode{} handles them
  5735. specially: that is when certain macros needn't (or mustn't) be
  5736. followed by a @samp{;}, and when certain macros (or compiler
  5737. directives) expand to nothing. You need to configure @ccmode{} to
  5738. handle these macros properly, see @ref{Macros with ;} and @ref{Noise
  5739. Macros}.
  5740. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5741. @menu
  5742. * Macro Backslashes::
  5743. * Macros with ;::
  5744. * Noise Macros::
  5745. @end menu
  5746. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5747. @node Macro Backslashes, Macros with ;, Custom Macros, Custom Macros
  5748. @comment node-name, next, previous, up
  5749. @section Customizing Macro Backslashes
  5750. @cindex @code{#define}
  5751. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5752. @ccmode{} provides some tools to help keep the line continuation
  5753. backslashes in macros neat and tidy. Their precise action is
  5754. customized with these variables:
  5755. @defopt c-backslash-column
  5756. @vindex backslash-column (c-)
  5757. @defoptx c-backslash-max-column
  5758. @vindex backslash-max-column (c-)
  5759. These variables control the alignment columns for line continuation
  5760. backslashes in multiline macros. They are used by the functions that
  5761. automatically insert or align such backslashes,
  5762. e.g., @code{c-backslash-region} and @code{c-context-line-break}.
  5763. @code{c-backslash-column} specifies the minimum column for the
  5764. backslashes. If any line in the macro goes past this column, then the
  5765. next tab stop (i.e., next multiple of @code{tab-width}) in that line is
  5766. used as the alignment column for all the backslashes, so that they
  5767. remain in a single column. However, if any lines go past
  5768. @code{c-backslash-max-column} then the backslashes in the rest of the
  5769. macro will be kept at that column, so that the lines which are too
  5770. long ``stick out'' instead.
  5771. Don't ever set these variables to @code{nil}. If you want to disable
  5772. the automatic alignment of backslashes, use
  5773. @code{c-auto-align-backslashes}.
  5774. @end defopt
  5775. @defopt c-auto-align-backslashes
  5776. @vindex auto-align-backslashes (c-)
  5777. Align automatically inserted line continuation backslashes if
  5778. non-@code{nil}. When line continuation backslashes are inserted
  5779. automatically for line breaks in multiline macros, e.g., by
  5780. @code{c-context-line-break}, they are aligned with the other
  5781. backslashes in the same macro if this flag is set.
  5782. If @code{c-auto-align-backslashes} is @code{nil}, automatically
  5783. inserted backslashes are preceded by a single space, and backslashes
  5784. get aligned only when you explicitly invoke the command
  5785. @code{c-backslash-region} (@kbd{C-c C-\}).
  5786. @end defopt
  5787. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5788. @node Macros with ;, Noise Macros, Macro Backslashes, Custom Macros
  5789. @comment node-name, next, previous, up
  5790. @section Macros with semicolons
  5791. @cindex macros with semicolons
  5792. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5793. Macros which needn't (or mustn't) be followed by a semicolon when you
  5794. invoke them, @dfn{macros with semicolons}, are very common. These can
  5795. cause @ccmode{} to parse the next line wrongly as a
  5796. @code{statement-cont} (@pxref{Function Symbols}) and thus mis-indent
  5797. it. At the top level, a macro invocation before a defun start can
  5798. cause, for example, @code{c-beginning-of-defun} (@kbd{C-M-a}) not to
  5799. find the correct start of the current function.
  5800. You can prevent these by specifying which macros have semicolons. It
  5801. doesn't matter whether or not such a macro has a parameter list:
  5802. @defopt c-macro-names-with-semicolon
  5803. @vindex macro-names-with-semicolon (c-)
  5804. This buffer-local variable specifies which macros have semicolons.
  5805. After setting its value, you need to call
  5806. @code{c-make-macro-with-semi-re} for it to take effect. It should be
  5807. set to one of these values:
  5808. @table @asis
  5809. @item nil
  5810. There are no macros with semicolons.
  5811. @item a list of strings
  5812. Each string is the name of a macro with a semicolon. Only valid
  5813. @code{#define} names are allowed here. For example, to set the
  5814. default value, you could write the following into your @file{.emacs}:
  5815. @example
  5816. (setq c-macro-names-with-semicolon
  5817. '("Q_OBJECT" "Q_PROPERTY" "Q_DECLARE" "Q_ENUMS"))
  5818. @end example
  5819. @item a regular expression
  5820. This matches each symbol which is a macro with a semicolon. It must
  5821. not match any string which isn't a valid @code{#define} name. For
  5822. example:
  5823. @example
  5824. (setq c-macro-names-with-semicolon
  5825. "\\<\\(CLEAN_UP_AND_RETURN\\|Q_[[:upper:]]+\\)\\>")
  5826. @end example
  5827. @end table
  5828. @end defopt
  5829. @defun c-make-macro-with-semi-re
  5830. @findex make-macro-with-semi-re (c-)
  5831. Call this (non-interactive) function, which sets internal variables,
  5832. each time you change the value of @code{c-macro-names-with-semicolon}
  5833. after the major mode function has run. It takes no arguments, and its
  5834. return value has no meaning. This function is called by @ccmode{}'s
  5835. initialization code, after the mode hooks have run.
  5836. @end defun
  5837. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5838. @node Noise Macros, , Macros with ;, Custom Macros
  5839. @comment node-name, next, previous, up
  5840. @section Noise Macros
  5841. @cindex noise macros
  5842. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5843. In @ccmode{}, @dfn{noise macros} are macros which expand to nothing,
  5844. or compiler directives (such as GCC's @code{__attribute__}) which play
  5845. no part in the syntax of the C (etc.) language. Some noise macros are
  5846. followed by arguments in parentheses (possibly optionally), others
  5847. are not.
  5848. Noise macros can easily confuse @ccmode{}'s analysis of function
  5849. headers, causing them to be mis-fontified, or even mis-indented. You
  5850. can prevent this confusion by specifying the identifiers which
  5851. constitute noise macros.
  5852. @defopt c-noise-macro-names
  5853. @vindex noise-macro-names (c-)
  5854. This variable is a list of names of noise macros which never have
  5855. parenthesized arguments. Each element is a string, and must be a
  5856. valid identifier. An element in @code{c-noise-macro-names} must not
  5857. also be in @code{c-noise-macro-with-parens-names}. Such an element is
  5858. treated as whitespace by @ccmode{}.
  5859. @end defopt
  5860. @defopt c-noise-macro-with-parens-names
  5861. @vindex noise-macro-with-parens-names (c-)
  5862. This variable is a list of names of noise macros which optionally have
  5863. arguments in parentheses. Each element of the list is a string, and
  5864. must be a valid identifier. An element in
  5865. @code{c-noise-macro-with-parens-names} must not also be in
  5866. @code{c-noise-macro-names}. For performance reasons, such an element,
  5867. together with the optional parenthesized arguments, is specially
  5868. handled, but it is only handled when used in declaration
  5869. contexts@footnote{If this restriction causes your project
  5870. difficulties, please get in touch with @email{bug-cc-mode@@gnu.org}.}.
  5871. The two compiler directives @code{__attribute__} and @code{__declspec}
  5872. have traditionally been handled specially in @ccmode{}; for example
  5873. they are fontified with font-lock-keyword-face. You don't need to
  5874. include these directives in @code{c-noise-macro-with-parens-names},
  5875. but doing so is OK.
  5876. @end defopt
  5877. @defun c-make-noise-macro-regexps
  5878. @findex make-noise-macro-regexps (c-)
  5879. Call this (non-interactive) function, which sets internal variables,
  5880. on changing the value of @code{c-noise-macro-names} or
  5881. @code{c-noise-macro-with-parens-names} after the major mode's function
  5882. has run. This function is called by @ccmode{}'s initialization code,
  5883. after the mode hooks have run.
  5884. @end defun
  5885. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5886. @node Odds and Ends, Sample Init File, Custom Macros, Top
  5887. @comment node-name, next, previous, up
  5888. @chapter Odds and Ends
  5889. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5890. The stuff that didn't fit in anywhere else is documented here.
  5891. @defopt c-require-final-newline
  5892. @vindex require-final-newline (c-)
  5893. Controls whether a final newline is enforced when the file is saved.
  5894. The value is an association list that for each language mode specifies
  5895. the value to give to @code{require-final-newline} (@pxref{Saving
  5896. Buffers,,,@lispref{}, @lispreftitle{}}) at mode initialization. If a
  5897. language isn't present on the association list, CC Mode won't touch
  5898. @code{require-final-newline} in buffers for that language.
  5899. The default is to set @code{require-final-newline} to @code{t} in the
  5900. languages that mandate that source files should end with newlines.
  5901. These are C, C++ and Objective-C.
  5902. @end defopt
  5903. @defopt c-echo-syntactic-information-p
  5904. @vindex echo-syntactic-information-p (c-)
  5905. If non-@code{nil}, the syntactic analysis for the current line is shown
  5906. in the echo area when it's indented (unless
  5907. @code{c-syntactic-indentation} is @code{nil}). That's useful when
  5908. finding out which syntactic symbols to modify to get the indentation you
  5909. want.
  5910. @end defopt
  5911. @defopt c-report-syntactic-errors
  5912. @vindex report-syntactic-errors (c-)
  5913. If non-@code{nil}, certain syntactic errors are reported with a ding and
  5914. a message, for example when an @code{else} is indented for which there
  5915. is no corresponding @code{if}.
  5916. Note however that @ccmode{} doesn't make any special effort to check for
  5917. syntactic errors; that's the job of the compiler. The reason it can
  5918. report cases like the one above is that it can't find the correct
  5919. anchoring position to indent the line in that case.
  5920. @end defopt
  5921. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5922. @node Sample Init File, Performance Issues, Odds and Ends, Top
  5923. @comment node-name, next, previous, up
  5924. @appendix Sample Init File
  5925. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5926. Here's a sample .emacs file fragment that might help you along the way.
  5927. Just copy this region and paste it into your .emacs file. You might want
  5928. to change some of the actual values.
  5929. @verbatim
  5930. ;; Make a non-standard key binding. We can put this in
  5931. ;; c-mode-base-map because c-mode-map, c++-mode-map, and so on,
  5932. ;; inherit from it.
  5933. (defun my-c-initialization-hook ()
  5934. (define-key c-mode-base-map "\C-m" 'c-context-line-break))
  5935. (add-hook 'c-initialization-hook 'my-c-initialization-hook)
  5936. ;; offset customizations not in my-c-style
  5937. ;; This will take precedence over any setting of the syntactic symbol
  5938. ;; made by a style.
  5939. (setq c-offsets-alist '((member-init-intro . ++)))
  5940. ;; Create my personal style.
  5941. (defconst my-c-style
  5942. '((c-tab-always-indent . t)
  5943. (c-comment-only-line-offset . 4)
  5944. (c-hanging-braces-alist . ((substatement-open after)
  5945. (brace-list-open)))
  5946. (c-hanging-colons-alist . ((member-init-intro before)
  5947. (inher-intro)
  5948. (case-label after)
  5949. (label after)
  5950. (access-label after)))
  5951. (c-cleanup-list . (scope-operator
  5952. empty-defun-braces
  5953. defun-close-semi))
  5954. (c-offsets-alist . ((arglist-close . c-lineup-arglist)
  5955. (substatement-open . 0)
  5956. (case-label . 4)
  5957. (block-open . 0)
  5958. (knr-argdecl-intro . -)))
  5959. (c-echo-syntactic-information-p . t))
  5960. "My C Programming Style")
  5961. (c-add-style "PERSONAL" my-c-style)
  5962. ;; Customizations for all modes in CC Mode.
  5963. (defun my-c-mode-common-hook ()
  5964. ;; set my personal style for the current buffer
  5965. (c-set-style "PERSONAL")
  5966. ;; other customizations
  5967. (setq tab-width 8
  5968. ;; this will make sure spaces are used instead of tabs
  5969. indent-tabs-mode nil)
  5970. ;; we like auto-newline, but not hungry-delete
  5971. (c-toggle-auto-newline 1))
  5972. (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
  5973. @end verbatim
  5974. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5975. @node Performance Issues, Limitations and Known Bugs, Sample Init File, Top
  5976. @comment node-name, next, previous, up
  5977. @appendix Performance Issues
  5978. @cindex performance
  5979. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5980. @comment FIXME: (ACM, 2003/5/24). Check whether AWK needs mentioning here.
  5981. C and its derivative languages are highly complex creatures. Often,
  5982. ambiguous code situations arise that require @ccmode{} to scan large
  5983. portions of the buffer to determine syntactic context. Such
  5984. pathological code can cause @ccmode{} to perform fairly badly. This
  5985. section gives some insight in how @ccmode{} operates, how that interacts
  5986. with some coding styles, and what you can use to improve performance.
  5987. The overall goal is that @ccmode{} shouldn't be overly slow (i.e., take
  5988. more than a fraction of a second) in any interactive operation.
  5989. I.e., it's tuned to limit the maximum response time in single operations,
  5990. which is sometimes at the expense of batch-like operations like
  5991. reindenting whole blocks. If you find that @ccmode{} gradually gets
  5992. slower and slower in certain situations, perhaps as the file grows in
  5993. size or as the macro or comment you're editing gets bigger, then chances
  5994. are that something isn't working right. You should consider reporting
  5995. it, unless it's something that's mentioned in this section.
  5996. Because @ccmode{} has to scan the buffer backwards from the current
  5997. insertion point, and because C's syntax is fairly difficult to parse in
  5998. the backwards direction, @ccmode{} often tries to find the nearest
  5999. position higher up in the buffer from which to begin a forward scan
  6000. (it's typically an opening or closing parenthesis of some kind). The
  6001. farther this position is from the current insertion point, the slower it
  6002. gets.
  6003. @findex beginning-of-defun
  6004. In earlier versions of @ccmode{}, we used to recommend putting the
  6005. opening brace of a top-level construct@footnote{E.g., a function in C,
  6006. or outermost class definition in C++ or Java.} into the leftmost
  6007. column. Earlier still, this used to be a rigid Emacs constraint, as
  6008. embodied in the @code{beginning-of-defun} function. @ccmode now
  6009. caches syntactic information much better, so that the delay caused by
  6010. searching for such a brace when it's not in column 0 is minimal,
  6011. except perhaps when you've just moved a long way inside the file.
  6012. @findex defun-prompt-regexp
  6013. @vindex c-Java-defun-prompt-regexp
  6014. @vindex Java-defun-prompt-regexp (c-)
  6015. A special note about @code{defun-prompt-regexp} in Java mode: The common
  6016. style is to hang the opening braces of functions and classes on the
  6017. right side of the line, and that doesn't work well with the Emacs
  6018. approach. @ccmode{} comes with a constant
  6019. @code{c-Java-defun-prompt-regexp} which tries to define a regular
  6020. expression usable for this style, but there are problems with it. In
  6021. some cases it can cause @code{beginning-of-defun} to hang@footnote{This
  6022. has been observed in Emacs 19.34 and XEmacs 19.15.}. For this reason,
  6023. it is not used by default, but if you feel adventurous, you can set
  6024. @code{defun-prompt-regexp} to it in your mode hook. In any event,
  6025. setting and relying on @code{defun-prompt-regexp} will definitely slow
  6026. things down because (X)Emacs will be doing regular expression searches a
  6027. lot, so you'll probably be taking a hit either way!
  6028. @ccmode{} maintains a cache of the opening parentheses of the blocks
  6029. surrounding the point, and it adapts that cache as the point is moved
  6030. around. That means that in bad cases it can take noticeable time to
  6031. indent a line in a new surrounding, but after that it gets fast as long
  6032. as the point isn't moved far off. The farther the point is moved, the
  6033. less useful is the cache. Since editing typically is done in ``chunks''
  6034. rather than on single lines far apart from each other, the cache
  6035. typically gives good performance even when the code doesn't fit the
  6036. Emacs approach to finding the defun starts.
  6037. @vindex c-enable-xemacs-performance-kludge-p
  6038. @vindex enable-xemacs-performance-kludge-p (c-)
  6039. XEmacs users can set the variable
  6040. @code{c-enable-xemacs-performance-kludge-p} to non-@code{nil}. This
  6041. tells @ccmode{} to use XEmacs-specific built-in functions which, in some
  6042. circumstances, can locate the top-most opening brace much more quickly than
  6043. @code{beginning-of-defun}. Preliminary testing has shown that for
  6044. styles where these braces are hung (e.g., most JDK-derived Java styles),
  6045. this hack can improve performance of the core syntax parsing routines
  6046. from 3 to 60 times. However, for styles which @emph{do} conform to
  6047. Emacs's recommended style of putting top-level braces in column zero,
  6048. this hack can degrade performance by about as much. Thus this variable
  6049. is set to @code{nil} by default, since the Emacs-friendly styles should
  6050. be more common (and encouraged!). Note that this variable has no effect
  6051. in Emacs since the necessary built-in functions don't exist (in Emacs
  6052. 22.1 as of this writing in February 2007).
  6053. Text properties are used to speed up skipping over syntactic whitespace,
  6054. i.e., comments and preprocessor directives. Indenting a line after a
  6055. huge macro definition can be slow the first time, but after that the
  6056. text properties are in place and it should be fast (even after you've
  6057. edited other parts of the file and then moved back).
  6058. Font locking can be a CPU hog, especially the font locking done on
  6059. decoration level 3 which tries to be very accurate. Note that that
  6060. level is designed to be used with a font lock support mode that only
  6061. fontifies the text that's actually shown, i.e., Lazy Lock or Just-in-time
  6062. Lock mode, so make sure you use one of them. Fontification of a whole
  6063. buffer with some thousand lines can often take over a minute. That is
  6064. a known weakness; the idea is that it never should happen.
  6065. The most effective way to speed up font locking is to reduce the
  6066. decoration level to 2 by setting @code{font-lock-maximum-decoration}
  6067. appropriately. That level is designed to be as pretty as possible
  6068. without sacrificing performance. @xref{Font Locking Preliminaries}, for
  6069. more info.
  6070. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  6071. @node Limitations and Known Bugs, FAQ, Performance Issues, Top
  6072. @comment node-name, next, previous, up
  6073. @appendix Limitations and Known Bugs
  6074. @cindex limitations
  6075. @cindex bugs
  6076. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  6077. @itemize @bullet
  6078. @item
  6079. @ccmode{} doesn't support trigraphs. (These are character sequences
  6080. such as @samp{??(}, which represents @samp{[}. They date from a time
  6081. when some character sets didn't have all the characters that C needs,
  6082. and are now utterly obsolete.)
  6083. @item
  6084. There is no way to apply auto newline settings (@pxref{Auto-newlines})
  6085. on already typed lines. That's only a feature to ease interactive
  6086. editing.
  6087. To generalize this issue a bit: @ccmode{} is not intended to be used as
  6088. a reformatter for old code in some more or less batch-like way. With
  6089. the exception of some functions like @code{c-indent-region}, it's only
  6090. geared to be used interactively to edit new code. There's currently no
  6091. intention to change this goal.
  6092. If you want to reformat old code, you're probably better off using some
  6093. other tool instead, e.g., @ref{Top, , GNU indent, indent, The `indent'
  6094. Manual}, which has more powerful reformatting capabilities than
  6095. @ccmode{}.
  6096. @item
  6097. The support for C++ templates (in angle brackets) is not yet complete.
  6098. When a non-nested template is used in a declaration, @ccmode{} indents
  6099. it and font-locks it OK@. Templates used in expressions, and nested
  6100. templates do not fare so well. Sometimes a workaround is to refontify
  6101. the expression after typing the closing @samp{>}.
  6102. @item
  6103. In a @dfn{k&r region} (the part of an old-fashioned C function
  6104. declaration which specifies the types of its parameters, coming
  6105. between the parameter list and the opening brace), there should be at
  6106. most 20 top-level parenthesis and bracket pairs. This limit has been
  6107. imposed for performance reasons. If it is violated, the source file
  6108. might be incorrectly indented or fontified.
  6109. @item
  6110. On loading @ccmode{}, sometimes this error message appears:
  6111. @example
  6112. File mode specification error: (void-variable c-font-lock-keywords-3)
  6113. @end example
  6114. This is due to a bug in the function @code{eval-after-load} in some
  6115. versions of (X)Emacs. It can manifest itself when there is a symbolic
  6116. link in the path of the directory which contains (X)Emacs. As a
  6117. workaround, put the following into your @file{.emacs} file, fairly
  6118. early on:
  6119. @example
  6120. (defun my-load-cc-fonts ()
  6121. (require "cc-fonts"))
  6122. (add-hook 'c-initialization-hook 'my-load-cc-fonts)
  6123. @end example
  6124. @end itemize
  6125. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  6126. @node FAQ, Updating CC Mode, Limitations and Known Bugs, Top
  6127. @comment node-name, next, previous, up
  6128. @appendix Frequently Asked Questions
  6129. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  6130. @itemize @bullet
  6131. @item
  6132. @emph{How can I change the indent level from 4 spaces to 2 spaces?}
  6133. Set the variable @code{c-basic-offset}. @xref{Getting Started}.
  6134. @item
  6135. @kindex RET
  6136. @kindex C-j
  6137. @emph{Why does/doesn't the @kbd{RET} key indent the new line?}
  6138. Emacs's convention used to be that @kbd{RET} just adds a newline, and that
  6139. @kbd{C-j} adds a newline and indents it. In Emacs-24.4, this convention was
  6140. reversed.
  6141. If you use an older Emacs and you want @kbd{RET} do this
  6142. too, add this to your @code{c-initialization-hook}:
  6143. @example
  6144. (define-key c-mode-base-map "\C-m" 'c-context-line-break)
  6145. @end example
  6146. @xref{Getting Started}. This was a very common question.
  6147. @item
  6148. @emph{How do I get block comments in my C++ files?}
  6149. Interactively, change the comment style with @kbd{C-c C-k}.
  6150. @xref{Minor Modes}.
  6151. To configure this setting, say, for files within the gdb project, you
  6152. could amend your C++ Mode hook like this:
  6153. @example
  6154. (defun my-c++-mode-hook ()
  6155. (if (string-match "/gdb/" (buffer-file-name))
  6156. (c-toggle-comment-style 1)))
  6157. (add-hook 'c++-mode-hook 'my-c++-mode-hook)
  6158. @end example
  6159. @item
  6160. @emph{How do I stop my C++ lambda expressions being indented way over
  6161. to the right?}
  6162. Change the offset associated with @code{inlambda} from its default,
  6163. the function @code{c-lineup-inexpr-block}, to 0. For example, if you
  6164. are setting offsets in a hook function you might include the following
  6165. line:
  6166. @example
  6167. (c-set-offset 'inlambda 0)
  6168. @end example
  6169. For details of the different ways you can make this setting,
  6170. @ref{Config Basics}.
  6171. @item
  6172. @emph{How do I stop my code jumping all over the place when I type?}
  6173. Deactivate ``electric minor mode'' with @kbd{C-c C-l}. @xref{Getting
  6174. Started}.
  6175. @item
  6176. @kindex C-x h
  6177. @kindex C-M-\
  6178. @emph{How do I reindent the whole file?}
  6179. Visit the file and hit @kbd{C-x h} to mark the whole buffer. Then hit
  6180. @kbd{C-M-\}. @xref{Indentation Commands}.
  6181. @item
  6182. @kindex C-M-q
  6183. @kindex C-M-u
  6184. @emph{How do I reindent the current block?}
  6185. First move to the brace which opens the block with @kbd{C-M-u}, then
  6186. reindent that expression with @kbd{C-M-q}. @xref{Indentation
  6187. Commands}.
  6188. @item
  6189. @emph{I put @code{(c-set-offset 'substatement-open 0)} in my
  6190. @file{.emacs} file but I get an error saying that @code{c-set-offset}'s
  6191. function definition is void. What's wrong?}
  6192. This means that @ccmode{} hasn't yet been loaded into your Emacs
  6193. session by the time the @code{c-set-offset} call is reached, most
  6194. likely because @ccmode{} is being autoloaded. Instead of putting the
  6195. @code{c-set-offset} line in your top-level @file{.emacs} file, put it
  6196. in your @code{c-initialization-hook} (@pxref{CC Hooks}), or simply
  6197. modify @code{c-offsets-alist} directly:
  6198. @example
  6199. (setq c-offsets-alist '((substatement-open . 0)))
  6200. @end example
  6201. @item
  6202. @cindex open paren in column zero
  6203. @emph{I have an open paren character at column zero inside a comment or
  6204. multiline string literal, and it causes the fontification and/or
  6205. indentation to go haywire. What gives?}
  6206. It's due to the ad-hoc rule in (X)Emacs that such open parens always
  6207. start defuns (which translates to functions, classes, namespaces or any
  6208. other top-level block constructs in the @ccmode{} languages).
  6209. @ifset XEMACS
  6210. @xref{Defuns,,, xemacs, XEmacs User's Manual}, for details.
  6211. @end ifset
  6212. @ifclear XEMACS
  6213. @xref{Left Margin Paren,,, emacs, GNU Emacs Manual}, for details
  6214. (@xref{Defuns,,, emacs, GNU Emacs Manual}, in the Emacs 20 manual).
  6215. @end ifclear
  6216. This heuristic is built into the core syntax analysis routines in
  6217. (X)Emacs, so it's not really a @ccmode{} issue. However, in Emacs
  6218. 21.1 it became possible to turn it off@footnote{Using the variable
  6219. @code{open-paren-in-column-0-is-defun-start}.} and @ccmode{} does so
  6220. there since it's got its own system to keep track of blocks.
  6221. @end itemize
  6222. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  6223. @node Updating CC Mode, Mailing Lists and Bug Reports, FAQ, Top
  6224. @comment node-name, next, previous, up
  6225. @appendix Getting the Latest CC Mode Release
  6226. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  6227. @ccmode{} has been standard with all versions of Emacs since 19.34 and
  6228. of XEmacs since 19.16.
  6229. @cindex web site
  6230. Due to release schedule skew, it is likely that all of these Emacsen
  6231. have old versions of @ccmode{} and so should be upgraded. Access to the
  6232. @ccmode{} source code, as well as more detailed information on Emacsen
  6233. compatibility, etc.@: are all available on the web site:
  6234. @quotation
  6235. @uref{http://cc-mode.sourceforge.net/}
  6236. @end quotation
  6237. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  6238. @node Mailing Lists and Bug Reports, GNU Free Documentation License, Updating CC Mode, Top
  6239. @comment node-name, next, previous, up
  6240. @appendix Mailing Lists and Submitting Bug Reports
  6241. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  6242. @kindex C-c C-b
  6243. @findex c-submit-bug-report
  6244. @findex submit-bug-report (c-)
  6245. To report bugs, use the @kbd{C-c C-b} (bound to
  6246. @code{c-submit-bug-report}) command. This provides vital information
  6247. we need to reproduce your problem. Make sure you include a concise,
  6248. but complete code example. Please try to boil your example down to
  6249. just the essential code needed to reproduce the problem, and include
  6250. an exact recipe of steps needed to expose the bug. Be especially sure
  6251. to include any code that appears @emph{before} your bug example, if
  6252. you think it might affect our ability to reproduce it.
  6253. Please try to produce the problem in an Emacs instance without any
  6254. customizations loaded (i.e., start it with the @samp{-q --no-site-file}
  6255. arguments). If it works correctly there, the problem might be caused
  6256. by faulty customizations in either your own or your site
  6257. configuration. In that case, we'd appreciate it if you isolate the
  6258. Emacs Lisp code that triggers the bug and include it in your report.
  6259. @cindex bug report mailing list
  6260. Reporting a bug using @code{c-submit-bug-report} files it in
  6261. the GNU Bug Tracker at @url{http://debbugs.gnu.org}, then sends it on
  6262. to @email{bug-cc-mode@@gnu.org}. You can also send reports, other
  6263. questions, and suggestions (kudos?@: @t{;-)} to that address. It's a
  6264. mailing list which you can join or browse an archive of; see the web site at
  6265. @uref{http://cc-mode.sourceforge.net/} for further details.
  6266. @cindex announcement mailing list
  6267. If you want to get announcements of new @ccmode{} releases, send the
  6268. word @emph{subscribe} in the body of a message to
  6269. @email{cc-mode-announce-request@@lists.sourceforge.net}. It's possible
  6270. to subscribe from the web site too. Announcements will also be posted
  6271. to the Usenet newsgroups @code{gnu.emacs.sources}, @code{comp.emacs},
  6272. @code{comp.emacs.xemacs}, @code{comp.lang.c}, @code{comp.lang.c++},
  6273. @code{comp.lang.objective-c}, @code{comp.lang.java.softwaretools},
  6274. @code{comp.lang.idl}, and @code{comp.lang.awk}.
  6275. @c There is no newsgroup for Pike. :-(
  6276. @node GNU Free Documentation License, Command and Function Index, Mailing Lists and Bug Reports, Top
  6277. @appendix GNU Free Documentation License
  6278. @include doclicense.texi
  6279. @c Removed the tentative node "Mode Initialization" from here, 2005/8/27.
  6280. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  6281. @node Command and Function Index, Variable Index, GNU Free Documentation License, Top
  6282. @comment node-name, next, previous, up
  6283. @unnumbered Command and Function Index
  6284. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  6285. Since most @ccmode{} commands are prepended with the string
  6286. @samp{c-}, each appears under its @code{c-@var{thing}} name and its
  6287. @code{@var{thing} (c-)} name.
  6288. @iftex
  6289. @sp 2
  6290. @end iftex
  6291. @printindex fn
  6292. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  6293. @node Variable Index, Concept and Key Index, Command and Function Index, Top
  6294. @comment node-name, next, previous, up
  6295. @unnumbered Variable Index
  6296. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  6297. Since most @ccmode{} variables are prepended with the string
  6298. @samp{c-}, each appears under its @code{c-@var{thing}} name and its
  6299. @code{@var{thing} (c-)} name.
  6300. @iftex
  6301. @sp 2
  6302. @end iftex
  6303. @printindex vr
  6304. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  6305. @node Concept and Key Index, , Variable Index, Top
  6306. @comment node-name, next, previous, up
  6307. @unnumbered Concept and Key Index
  6308. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  6309. @printindex cp
  6310. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  6311. @comment Epilogue.
  6312. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  6313. @bye