cc-mode.texi 266 KB

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