org.el 511 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941
  1. ;;; org.el --- Outline-based notes management and organizer
  2. ;; Carstens outline-mode for keeping track of everything.
  3. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
  4. ;;
  5. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  6. ;; Keywords: outlines, hypermedia, calendar, wp
  7. ;; Homepage: http://orgmode.org
  8. ;; Version: 6.02b
  9. ;;
  10. ;; This file is part of GNU Emacs.
  11. ;;
  12. ;; GNU Emacs is free software: you can redistribute it and/or modify
  13. ;; it under the terms of the GNU General Public License as published by
  14. ;; the Free Software Foundation, either version 3 of the License, or
  15. ;; (at your option) any later version.
  16. ;; GNU Emacs is distributed in the hope that it will be useful,
  17. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. ;; GNU General Public License for more details.
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  22. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  23. ;;
  24. ;;; Commentary:
  25. ;;
  26. ;; Org-mode is a mode for keeping notes, maintaining ToDo lists, and doing
  27. ;; project planning with a fast and effective plain-text system.
  28. ;;
  29. ;; Org-mode develops organizational tasks around NOTES files that contain
  30. ;; information about projects as plain text. Org-mode is implemented on
  31. ;; top of outline-mode, which makes it possible to keep the content of
  32. ;; large files well structured. Visibility cycling and structure editing
  33. ;; help to work with the tree. Tables are easily created with a built-in
  34. ;; table editor. Org-mode supports ToDo items, deadlines, time stamps,
  35. ;; and scheduling. It dynamically compiles entries into an agenda that
  36. ;; utilizes and smoothly integrates much of the Emacs calendar and diary.
  37. ;; Plain text URL-like links connect to websites, emails, Usenet
  38. ;; messages, BBDB entries, and any files related to the projects. For
  39. ;; printing and sharing of notes, an Org-mode file can be exported as a
  40. ;; structured ASCII file, as HTML, or (todo and agenda items only) as an
  41. ;; iCalendar file. It can also serve as a publishing tool for a set of
  42. ;; linked webpages.
  43. ;;
  44. ;; Installation and Activation
  45. ;; ---------------------------
  46. ;; See the corresponding sections in the manual at
  47. ;;
  48. ;; http://orgmode.org/org.html#Installation
  49. ;;
  50. ;; Documentation
  51. ;; -------------
  52. ;; The documentation of Org-mode can be found in the TeXInfo file. The
  53. ;; distribution also contains a PDF version of it. At the homepage of
  54. ;; Org-mode, you can read the same text online as HTML. There is also an
  55. ;; excellent reference card made by Philip Rooke. This card can be found
  56. ;; in the etc/ directory of Emacs 22.
  57. ;;
  58. ;; A list of recent changes can be found at
  59. ;; http://orgmode.org/Changes.html
  60. ;;
  61. ;;; Code:
  62. (defvar org-inhibit-highlight-removal nil) ; dynamically scoped param
  63. (defvar org-table-formula-constants-local nil
  64. "Local version of `org-table-formula-constants'.")
  65. (make-variable-buffer-local 'org-table-formula-constants-local)
  66. ;;;; Require other packages
  67. (eval-when-compile
  68. (require 'cl)
  69. (require 'gnus-sum)
  70. (require 'calendar))
  71. ;; For XEmacs, noutline is not yet provided by outline.el, so arrange for
  72. ;; the file noutline.el being loaded.
  73. (if (featurep 'xemacs) (condition-case nil (require 'noutline)))
  74. ;; We require noutline, which might be provided in outline.el
  75. (require 'outline) (require 'noutline)
  76. ;; Other stuff we need.
  77. (require 'time-date)
  78. (unless (fboundp 'time-subtract) (defalias 'time-subtract 'subtract-time))
  79. (require 'easymenu)
  80. (require 'org-macs)
  81. (require 'org-compat)
  82. (require 'org-faces)
  83. ;;;; Customization variables
  84. ;;; Version
  85. (defconst org-version "6.02b"
  86. "The version number of the file org.el.")
  87. (defun org-version (&optional here)
  88. "Show the org-mode version in the echo area.
  89. With prefix arg HERE, insert it at point."
  90. (interactive "P")
  91. (let ((version (format "Org-mode version %s" org-version)))
  92. (message version)
  93. (if here
  94. (insert version))))
  95. ;;; Compatibility constants
  96. ;;; The custom variables
  97. (defgroup org nil
  98. "Outline-based notes management and organizer."
  99. :tag "Org"
  100. :group 'outlines
  101. :group 'hypermedia
  102. :group 'calendar)
  103. (defcustom org-load-hook nil
  104. "Hook that is run after org.el has been loaded."
  105. :group 'org
  106. :type 'hook)
  107. (defvar org-modules) ; defined below
  108. (defvar org-modules-loaded nil
  109. "Have the modules been loaded already?")
  110. (defun org-load-modules-maybe (&optional force)
  111. "Load all extensions listed in `org-default-extensions'."
  112. (when (or force (not org-modules-loaded))
  113. (mapc (lambda (ext)
  114. (condition-case nil (require ext)
  115. (error (message "Problems while trying to load feature `%s'" ext))))
  116. org-modules)
  117. (setq org-modules-loaded t)))
  118. (defun org-set-modules (var value)
  119. "Set VAR to VALUE and call `org-load-modules-maybe' with the force flag."
  120. (set var value)
  121. (when (featurep 'org)
  122. (org-load-modules-maybe 'force)))
  123. (when (org-bound-and-true-p org-modules)
  124. (let ((a (member 'org-infojs org-modules)))
  125. (and a (setcar a 'org-jsinfo))))
  126. (defcustom org-modules '(org-bbdb org-bibtex org-gnus org-info org-jsinfo org-irc org-mew org-mhe org-rmail org-vm org-wl)
  127. "Modules that should always be loaded together with org.el.
  128. If a description starts with <C>, the file is not part of emacs
  129. and loading it will require that you have downloaded and properly installed
  130. the org-mode distribution.
  131. You can also use this system to load external packages (i.e. neither Org
  132. core modules, not modules from the CONTRIB directory). Just add symbols
  133. to the end of the list. If the package is called org-xyz.e, then you need
  134. to add the symbol `xyz', and the package must have a call to
  135. (provide 'org-xyz)"
  136. :group 'org
  137. :set 'org-set-modules
  138. :type
  139. '(set :greedy t
  140. (const :tag " bbdb: Links to BBDB entries" org-bbdb)
  141. (const :tag " bibtex: Links to BibTeX entries" org-bibtex)
  142. (const :tag " gnus: Links to GNUS folders/messages" org-gnus)
  143. (const :tag " info: Links to Info nodes" org-info)
  144. (const :tag " jsinfo: Set up Sebastian Rose's JavaScript org-info.js" org-jsinfo)
  145. (const :tag " irc: Links to IRC/ERC chat sessions" org-irc)
  146. (const :tag " mac-message: Links to messages in Apple Mail" org-mac-message)
  147. (const :tag " mew Links to Mew folders/messages" org-mew)
  148. (const :tag " mhe: Links to MHE folders/messages" org-mhe)
  149. (const :tag " rmail: Links to RMAIL folders/messages" org-rmail)
  150. (const :tag " vm: Links to VM folders/messages" org-vm)
  151. (const :tag " wl: Links to Wanderlust folders/messages" org-wl)
  152. (const :tag " mouse: Additional mouse support" org-mouse)
  153. (const :tag "C annotate-file: Annotate a file with org syntax" org-annotate-file)
  154. (const :tag "C bookmark: Org links to bookmarks" org-bookmark)
  155. (const :tag "C depend: TODO dependencies for Org-mode" org-depend)
  156. (const :tag "C elisp-symbol: Org links to emacs-lisp symbols" org-elisp-symbol)
  157. (const :tag "C eval: Include command output as text" org-eval)
  158. (const :tag "C expiry: Expiry mechanism for Org entries" org-expiry)
  159. (const :tag "C id: Global id's for identifying entries" org-id)
  160. (const :tag "C interactive-query: Interactive modification of tags query" org-interactive-query)
  161. (const :tag "C mairix: Hook mairix search into Org for different MUAs" org-mairix)
  162. (const :tag "C man: Support for links to manpages in Org-mode" org-man)
  163. (const :tag "C panel: Simple routines for us with bad memory" org-panel)
  164. (const :tag "C registry: A registry for Org links" org-registry)
  165. (const :tag "C org2rem: Convert org appointments into reminders" org2rem)
  166. (const :tag "C screen: Visit screen sessions through Org-mode links" org-screen)
  167. (const :tag "C toc: Table of contents for Org-mode buffer" org-toc)
  168. (const :tag "C sqlinsert: Convert Org-mode tables to SQL insertions" orgtbl-sqlinsert)
  169. (repeat :tag "External packages" :inline t (symbol :tag "Package"))))
  170. (defgroup org-startup nil
  171. "Options concerning startup of Org-mode."
  172. :tag "Org Startup"
  173. :group 'org)
  174. (defcustom org-startup-folded t
  175. "Non-nil means, entering Org-mode will switch to OVERVIEW.
  176. This can also be configured on a per-file basis by adding one of
  177. the following lines anywhere in the buffer:
  178. #+STARTUP: fold
  179. #+STARTUP: nofold
  180. #+STARTUP: content"
  181. :group 'org-startup
  182. :type '(choice
  183. (const :tag "nofold: show all" nil)
  184. (const :tag "fold: overview" t)
  185. (const :tag "content: all headlines" content)))
  186. (defcustom org-startup-truncated t
  187. "Non-nil means, entering Org-mode will set `truncate-lines'.
  188. This is useful since some lines containing links can be very long and
  189. uninteresting. Also tables look terrible when wrapped."
  190. :group 'org-startup
  191. :type 'boolean)
  192. (defcustom org-startup-align-all-tables nil
  193. "Non-nil means, align all tables when visiting a file.
  194. This is useful when the column width in tables is forced with <N> cookies
  195. in table fields. Such tables will look correct only after the first re-align.
  196. This can also be configured on a per-file basis by adding one of
  197. the following lines anywhere in the buffer:
  198. #+STARTUP: align
  199. #+STARTUP: noalign"
  200. :group 'org-startup
  201. :type 'boolean)
  202. (defcustom org-insert-mode-line-in-empty-file nil
  203. "Non-nil means insert the first line setting Org-mode in empty files.
  204. When the function `org-mode' is called interactively in an empty file, this
  205. normally means that the file name does not automatically trigger Org-mode.
  206. To ensure that the file will always be in Org-mode in the future, a
  207. line enforcing Org-mode will be inserted into the buffer, if this option
  208. has been set."
  209. :group 'org-startup
  210. :type 'boolean)
  211. (defcustom org-replace-disputed-keys nil
  212. "Non-nil means use alternative key bindings for some keys.
  213. Org-mode uses S-<cursor> keys for changing timestamps and priorities.
  214. These keys are also used by other packages like `CUA-mode' or `windmove.el'.
  215. If you want to use Org-mode together with one of these other modes,
  216. or more generally if you would like to move some Org-mode commands to
  217. other keys, set this variable and configure the keys with the variable
  218. `org-disputed-keys'.
  219. This option is only relevant at load-time of Org-mode, and must be set
  220. *before* org.el is loaded. Changing it requires a restart of Emacs to
  221. become effective."
  222. :group 'org-startup
  223. :type 'boolean)
  224. (if (fboundp 'defvaralias)
  225. (defvaralias 'org-CUA-compatible 'org-replace-disputed-keys))
  226. (defcustom org-disputed-keys
  227. '(([(shift up)] . [(meta p)])
  228. ([(shift down)] . [(meta n)])
  229. ([(shift left)] . [(meta -)])
  230. ([(shift right)] . [(meta +)])
  231. ([(control shift right)] . [(meta shift +)])
  232. ([(control shift left)] . [(meta shift -)]))
  233. "Keys for which Org-mode and other modes compete.
  234. This is an alist, cars are the default keys, second element specifies
  235. the alternative to use when `org-replace-disputed-keys' is t.
  236. Keys can be specified in any syntax supported by `define-key'.
  237. The value of this option takes effect only at Org-mode's startup,
  238. therefore you'll have to restart Emacs to apply it after changing."
  239. :group 'org-startup
  240. :type 'alist)
  241. (defun org-key (key)
  242. "Select key according to `org-replace-disputed-keys' and `org-disputed-keys'.
  243. Or return the original if not disputed."
  244. (if org-replace-disputed-keys
  245. (let* ((nkey (key-description key))
  246. (x (org-find-if (lambda (x)
  247. (equal (key-description (car x)) nkey))
  248. org-disputed-keys)))
  249. (if x (cdr x) key))
  250. key))
  251. (defun org-find-if (predicate seq)
  252. (catch 'exit
  253. (while seq
  254. (if (funcall predicate (car seq))
  255. (throw 'exit (car seq))
  256. (pop seq)))))
  257. (defun org-defkey (keymap key def)
  258. "Define a key, possibly translated, as returned by `org-key'."
  259. (define-key keymap (org-key key) def))
  260. (defcustom org-ellipsis nil
  261. "The ellipsis to use in the Org-mode outline.
  262. When nil, just use the standard three dots. When a string, use that instead,
  263. When a face, use the standart 3 dots, but with the specified face.
  264. The change affects only Org-mode (which will then use its own display table).
  265. Changing this requires executing `M-x org-mode' in a buffer to become
  266. effective."
  267. :group 'org-startup
  268. :type '(choice (const :tag "Default" nil)
  269. (face :tag "Face" :value org-warning)
  270. (string :tag "String" :value "...#")))
  271. (defvar org-display-table nil
  272. "The display table for org-mode, in case `org-ellipsis' is non-nil.")
  273. (defgroup org-keywords nil
  274. "Keywords in Org-mode."
  275. :tag "Org Keywords"
  276. :group 'org)
  277. (defcustom org-deadline-string "DEADLINE:"
  278. "String to mark deadline entries.
  279. A deadline is this string, followed by a time stamp. Should be a word,
  280. terminated by a colon. You can insert a schedule keyword and
  281. a timestamp with \\[org-deadline].
  282. Changes become only effective after restarting Emacs."
  283. :group 'org-keywords
  284. :type 'string)
  285. (defcustom org-scheduled-string "SCHEDULED:"
  286. "String to mark scheduled TODO entries.
  287. A schedule is this string, followed by a time stamp. Should be a word,
  288. terminated by a colon. You can insert a schedule keyword and
  289. a timestamp with \\[org-schedule].
  290. Changes become only effective after restarting Emacs."
  291. :group 'org-keywords
  292. :type 'string)
  293. (defcustom org-closed-string "CLOSED:"
  294. "String used as the prefix for timestamps logging closing a TODO entry."
  295. :group 'org-keywords
  296. :type 'string)
  297. (defcustom org-clock-string "CLOCK:"
  298. "String used as prefix for timestamps clocking work hours on an item."
  299. :group 'org-keywords
  300. :type 'string)
  301. (defcustom org-comment-string "COMMENT"
  302. "Entries starting with this keyword will never be exported.
  303. An entry can be toggled between COMMENT and normal with
  304. \\[org-toggle-comment].
  305. Changes become only effective after restarting Emacs."
  306. :group 'org-keywords
  307. :type 'string)
  308. (defcustom org-quote-string "QUOTE"
  309. "Entries starting with this keyword will be exported in fixed-width font.
  310. Quoting applies only to the text in the entry following the headline, and does
  311. not extend beyond the next headline, even if that is lower level.
  312. An entry can be toggled between QUOTE and normal with
  313. \\[org-toggle-fixed-width-section]."
  314. :group 'org-keywords
  315. :type 'string)
  316. (defconst org-repeat-re
  317. "<[0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9] [^>\n]*\\([.+]?\\+[0-9]+[dwmy]\\)"
  318. "Regular expression for specifying repeated events.
  319. After a match, group 1 contains the repeat expression.")
  320. (defgroup org-structure nil
  321. "Options concerning the general structure of Org-mode files."
  322. :tag "Org Structure"
  323. :group 'org)
  324. (defgroup org-reveal-location nil
  325. "Options about how to make context of a location visible."
  326. :tag "Org Reveal Location"
  327. :group 'org-structure)
  328. (defconst org-context-choice
  329. '(choice
  330. (const :tag "Always" t)
  331. (const :tag "Never" nil)
  332. (repeat :greedy t :tag "Individual contexts"
  333. (cons
  334. (choice :tag "Context"
  335. (const agenda)
  336. (const org-goto)
  337. (const occur-tree)
  338. (const tags-tree)
  339. (const link-search)
  340. (const mark-goto)
  341. (const bookmark-jump)
  342. (const isearch)
  343. (const default))
  344. (boolean))))
  345. "Contexts for the reveal options.")
  346. (defcustom org-show-hierarchy-above '((default . t))
  347. "Non-nil means, show full hierarchy when revealing a location.
  348. Org-mode often shows locations in an org-mode file which might have
  349. been invisible before. When this is set, the hierarchy of headings
  350. above the exposed location is shown.
  351. Turning this off for example for sparse trees makes them very compact.
  352. Instead of t, this can also be an alist specifying this option for different
  353. contexts. Valid contexts are
  354. agenda when exposing an entry from the agenda
  355. org-goto when using the command `org-goto' on key C-c C-j
  356. occur-tree when using the command `org-occur' on key C-c /
  357. tags-tree when constructing a sparse tree based on tags matches
  358. link-search when exposing search matches associated with a link
  359. mark-goto when exposing the jump goal of a mark
  360. bookmark-jump when exposing a bookmark location
  361. isearch when exiting from an incremental search
  362. default default for all contexts not set explicitly"
  363. :group 'org-reveal-location
  364. :type org-context-choice)
  365. (defcustom org-show-following-heading '((default . nil))
  366. "Non-nil means, show following heading when revealing a location.
  367. Org-mode often shows locations in an org-mode file which might have
  368. been invisible before. When this is set, the heading following the
  369. match is shown.
  370. Turning this off for example for sparse trees makes them very compact,
  371. but makes it harder to edit the location of the match. In such a case,
  372. use the command \\[org-reveal] to show more context.
  373. Instead of t, this can also be an alist specifying this option for different
  374. contexts. See `org-show-hierarchy-above' for valid contexts."
  375. :group 'org-reveal-location
  376. :type org-context-choice)
  377. (defcustom org-show-siblings '((default . nil) (isearch t))
  378. "Non-nil means, show all sibling heading when revealing a location.
  379. Org-mode often shows locations in an org-mode file which might have
  380. been invisible before. When this is set, the sibling of the current entry
  381. heading are all made visible. If `org-show-hierarchy-above' is t,
  382. the same happens on each level of the hierarchy above the current entry.
  383. By default this is on for the isearch context, off for all other contexts.
  384. Turning this off for example for sparse trees makes them very compact,
  385. but makes it harder to edit the location of the match. In such a case,
  386. use the command \\[org-reveal] to show more context.
  387. Instead of t, this can also be an alist specifying this option for different
  388. contexts. See `org-show-hierarchy-above' for valid contexts."
  389. :group 'org-reveal-location
  390. :type org-context-choice)
  391. (defcustom org-show-entry-below '((default . nil))
  392. "Non-nil means, show the entry below a headline when revealing a location.
  393. Org-mode often shows locations in an org-mode file which might have
  394. been invisible before. When this is set, the text below the headline that is
  395. exposed is also shown.
  396. By default this is off for all contexts.
  397. Instead of t, this can also be an alist specifying this option for different
  398. contexts. See `org-show-hierarchy-above' for valid contexts."
  399. :group 'org-reveal-location
  400. :type org-context-choice)
  401. (defcustom org-indirect-buffer-display 'other-window
  402. "How should indirect tree buffers be displayed?
  403. This applies to indirect buffers created with the commands
  404. \\[org-tree-to-indirect-buffer] and \\[org-agenda-tree-to-indirect-buffer].
  405. Valid values are:
  406. current-window Display in the current window
  407. other-window Just display in another window.
  408. dedicated-frame Create one new frame, and re-use it each time.
  409. new-frame Make a new frame each time. Note that in this case
  410. previously-made indirect buffers are kept, and you need to
  411. kill these buffers yourself."
  412. :group 'org-structure
  413. :group 'org-agenda-windows
  414. :type '(choice
  415. (const :tag "In current window" current-window)
  416. (const :tag "In current frame, other window" other-window)
  417. (const :tag "Each time a new frame" new-frame)
  418. (const :tag "One dedicated frame" dedicated-frame)))
  419. (defgroup org-cycle nil
  420. "Options concerning visibility cycling in Org-mode."
  421. :tag "Org Cycle"
  422. :group 'org-structure)
  423. (defcustom org-drawers '("PROPERTIES" "CLOCK")
  424. "Names of drawers. Drawers are not opened by cycling on the headline above.
  425. Drawers only open with a TAB on the drawer line itself. A drawer looks like
  426. this:
  427. :DRAWERNAME:
  428. .....
  429. :END:
  430. The drawer \"PROPERTIES\" is special for capturing properties through
  431. the property API.
  432. Drawers can be defined on the per-file basis with a line like:
  433. #+DRAWERS: HIDDEN STATE PROPERTIES"
  434. :group 'org-structure
  435. :type '(repeat (string :tag "Drawer Name")))
  436. (defcustom org-cycle-global-at-bob nil
  437. "Cycle globally if cursor is at beginning of buffer and not at a headline.
  438. This makes it possible to do global cycling without having to use S-TAB or
  439. C-u TAB. For this special case to work, the first line of the buffer
  440. must not be a headline - it may be empty ot some other text. When used in
  441. this way, `org-cycle-hook' is disables temporarily, to make sure the
  442. cursor stays at the beginning of the buffer.
  443. When this option is nil, don't do anything special at the beginning
  444. of the buffer."
  445. :group 'org-cycle
  446. :type 'boolean)
  447. (defcustom org-cycle-emulate-tab t
  448. "Where should `org-cycle' emulate TAB.
  449. nil Never
  450. white Only in completely white lines
  451. whitestart Only at the beginning of lines, before the first non-white char
  452. t Everywhere except in headlines
  453. exc-hl-bol Everywhere except at the start of a headline
  454. If TAB is used in a place where it does not emulate TAB, the current subtree
  455. visibility is cycled."
  456. :group 'org-cycle
  457. :type '(choice (const :tag "Never" nil)
  458. (const :tag "Only in completely white lines" white)
  459. (const :tag "Before first char in a line" whitestart)
  460. (const :tag "Everywhere except in headlines" t)
  461. (const :tag "Everywhere except at bol in headlines" exc-hl-bol)
  462. ))
  463. (defcustom org-cycle-separator-lines 2
  464. "Number of empty lines needed to keep an empty line between collapsed trees.
  465. If you leave an empty line between the end of a subtree and the following
  466. headline, this empty line is hidden when the subtree is folded.
  467. Org-mode will leave (exactly) one empty line visible if the number of
  468. empty lines is equal or larger to the number given in this variable.
  469. So the default 2 means, at least 2 empty lines after the end of a subtree
  470. are needed to produce free space between a collapsed subtree and the
  471. following headline.
  472. Special case: when 0, never leave empty lines in collapsed view."
  473. :group 'org-cycle
  474. :type 'integer)
  475. (defcustom org-cycle-hook '(org-cycle-hide-archived-subtrees
  476. org-cycle-hide-drawers
  477. org-cycle-show-empty-lines
  478. org-optimize-window-after-visibility-change)
  479. "Hook that is run after `org-cycle' has changed the buffer visibility.
  480. The function(s) in this hook must accept a single argument which indicates
  481. the new state that was set by the most recent `org-cycle' command. The
  482. argument is a symbol. After a global state change, it can have the values
  483. `overview', `content', or `all'. After a local state change, it can have
  484. the values `folded', `children', or `subtree'."
  485. :group 'org-cycle
  486. :type 'hook)
  487. (defgroup org-edit-structure nil
  488. "Options concerning structure editing in Org-mode."
  489. :tag "Org Edit Structure"
  490. :group 'org-structure)
  491. (defcustom org-odd-levels-only nil
  492. "Non-nil means, skip even levels and only use odd levels for the outline.
  493. This has the effect that two stars are being added/taken away in
  494. promotion/demotion commands. It also influences how levels are
  495. handled by the exporters.
  496. Changing it requires restart of `font-lock-mode' to become effective
  497. for fontification also in regions already fontified.
  498. You may also set this on a per-file basis by adding one of the following
  499. lines to the buffer:
  500. #+STARTUP: odd
  501. #+STARTUP: oddeven"
  502. :group 'org-edit-structure
  503. :group 'org-font-lock
  504. :type 'boolean)
  505. (defcustom org-adapt-indentation t
  506. "Non-nil means, adapt indentation when promoting and demoting.
  507. When this is set and the *entire* text in an entry is indented, the
  508. indentation is increased by one space in a demotion command, and
  509. decreased by one in a promotion command. If any line in the entry
  510. body starts at column 0, indentation is not changed at all."
  511. :group 'org-edit-structure
  512. :type 'boolean)
  513. (defcustom org-special-ctrl-a/e nil
  514. "Non-nil means `C-a' and `C-e' behave specially in headlines and items.
  515. When t, `C-a' will bring back the cursor to the beginning of the
  516. headline text, i.e. after the stars and after a possible TODO keyword.
  517. In an item, this will be the position after the bullet.
  518. When the cursor is already at that position, another `C-a' will bring
  519. it to the beginning of the line.
  520. `C-e' will jump to the end of the headline, ignoring the presence of tags
  521. in the headline. A second `C-e' will then jump to the true end of the
  522. line, after any tags.
  523. When set to the symbol `reversed', the first `C-a' or `C-e' works normally,
  524. and only a directly following, identical keypress will bring the cursor
  525. to the special positions."
  526. :group 'org-edit-structure
  527. :type '(choice
  528. (const :tag "off" nil)
  529. (const :tag "after bullet first" t)
  530. (const :tag "border first" reversed)))
  531. (if (fboundp 'defvaralias)
  532. (defvaralias 'org-special-ctrl-a 'org-special-ctrl-a/e))
  533. (defcustom org-special-ctrl-k nil
  534. "Non-nil means `C-k' will behave specially in headlines.
  535. When nil, `C-k' will call the default `kill-line' command.
  536. When t, the following will happen while the cursor is in the headline:
  537. - When the cursor is at the beginning of a headline, kill the entire
  538. line and possible the folded subtree below the line.
  539. - When in the middle of the headline text, kill the headline up to the tags.
  540. - When after the headline text, kill the tags."
  541. :group 'org-edit-structure
  542. :type 'boolean)
  543. (defcustom org-M-RET-may-split-line '((default . t))
  544. "Non-nil means, M-RET will split the line at the cursor position.
  545. When nil, it will go to the end of the line before making a
  546. new line.
  547. You may also set this option in a different way for different
  548. contexts. Valid contexts are:
  549. headline when creating a new headline
  550. item when creating a new item
  551. table in a table field
  552. default the value to be used for all contexts not explicitly
  553. customized"
  554. :group 'org-structure
  555. :group 'org-table
  556. :type '(choice
  557. (const :tag "Always" t)
  558. (const :tag "Never" nil)
  559. (repeat :greedy t :tag "Individual contexts"
  560. (cons
  561. (choice :tag "Context"
  562. (const headline)
  563. (const item)
  564. (const table)
  565. (const default))
  566. (boolean)))))
  567. (defcustom org-blank-before-new-entry '((heading . nil)
  568. (plain-list-item . nil))
  569. "Should `org-insert-heading' leave a blank line before new heading/item?
  570. The value is an alist, with `heading' and `plain-list-item' as car,
  571. and a boolean flag as cdr."
  572. :group 'org-edit-structure
  573. :type '(list
  574. (cons (const heading) (boolean))
  575. (cons (const plain-list-item) (boolean))))
  576. (defcustom org-insert-heading-hook nil
  577. "Hook being run after inserting a new heading."
  578. :group 'org-edit-structure
  579. :type 'hook)
  580. (defcustom org-enable-fixed-width-editor t
  581. "Non-nil means, lines starting with \":\" are treated as fixed-width.
  582. This currently only means, they are never auto-wrapped.
  583. When nil, such lines will be treated like ordinary lines.
  584. See also the QUOTE keyword."
  585. :group 'org-edit-structure
  586. :type 'boolean)
  587. (defcustom org-goto-auto-isearch t
  588. "Non-nil means, typing characters in org-goto starts incremental search."
  589. :group 'org-edit-structure
  590. :type 'boolean)
  591. (defgroup org-sparse-trees nil
  592. "Options concerning sparse trees in Org-mode."
  593. :tag "Org Sparse Trees"
  594. :group 'org-structure)
  595. (defcustom org-highlight-sparse-tree-matches t
  596. "Non-nil means, highlight all matches that define a sparse tree.
  597. The highlights will automatically disappear the next time the buffer is
  598. changed by an edit command."
  599. :group 'org-sparse-trees
  600. :type 'boolean)
  601. (defcustom org-remove-highlights-with-change t
  602. "Non-nil means, any change to the buffer will remove temporary highlights.
  603. Such highlights are created by `org-occur' and `org-clock-display'.
  604. When nil, `C-c C-c needs to be used to get rid of the highlights.
  605. The highlights created by `org-preview-latex-fragment' always need
  606. `C-c C-c' to be removed."
  607. :group 'org-sparse-trees
  608. :group 'org-time
  609. :type 'boolean)
  610. (defcustom org-occur-hook '(org-first-headline-recenter)
  611. "Hook that is run after `org-occur' has constructed a sparse tree.
  612. This can be used to recenter the window to show as much of the structure
  613. as possible."
  614. :group 'org-sparse-trees
  615. :type 'hook)
  616. (defgroup org-plain-lists nil
  617. "Options concerning plain lists in Org-mode."
  618. :tag "Org Plain lists"
  619. :group 'org-structure)
  620. (defcustom org-cycle-include-plain-lists nil
  621. "Non-nil means, include plain lists into visibility cycling.
  622. This means that during cycling, plain list items will *temporarily* be
  623. interpreted as outline headlines with a level given by 1000+i where i is the
  624. indentation of the bullet. In all other operations, plain list items are
  625. not seen as headlines. For example, you cannot assign a TODO keyword to
  626. such an item."
  627. :group 'org-plain-lists
  628. :type 'boolean)
  629. (defcustom org-plain-list-ordered-item-terminator t
  630. "The character that makes a line with leading number an ordered list item.
  631. Valid values are ?. and ?\). To get both terminators, use t. While
  632. ?. may look nicer, it creates the danger that a line with leading
  633. number may be incorrectly interpreted as an item. ?\) therefore is
  634. the safe choice."
  635. :group 'org-plain-lists
  636. :type '(choice (const :tag "dot like in \"2.\"" ?.)
  637. (const :tag "paren like in \"2)\"" ?\))
  638. (const :tab "both" t)))
  639. (defcustom org-empty-line-terminates-plain-lists nil
  640. "Non-nil means, an empty line ends all plain list levels.
  641. When nil, empty lines are part of the preceeding item."
  642. :group 'org-plain-lists
  643. :type 'boolean)
  644. (defcustom org-auto-renumber-ordered-lists t
  645. "Non-nil means, automatically renumber ordered plain lists.
  646. Renumbering happens when the sequence have been changed with
  647. \\[org-shiftmetaup] or \\[org-shiftmetadown]. After other editing commands,
  648. use \\[org-ctrl-c-ctrl-c] to trigger renumbering."
  649. :group 'org-plain-lists
  650. :type 'boolean)
  651. (defcustom org-provide-checkbox-statistics t
  652. "Non-nil means, update checkbox statistics after insert and toggle.
  653. When this is set, checkbox statistics is updated each time you either insert
  654. a new checkbox with \\[org-insert-todo-heading] or toggle a checkbox
  655. with \\[org-ctrl-c-ctrl-c\\]."
  656. :group 'org-plain-lists
  657. :type 'boolean)
  658. (defgroup org-imenu-and-speedbar nil
  659. "Options concerning imenu and speedbar in Org-mode."
  660. :tag "Org Imenu and Speedbar"
  661. :group 'org-structure)
  662. (defcustom org-imenu-depth 2
  663. "The maximum level for Imenu access to Org-mode headlines.
  664. This also applied for speedbar access."
  665. :group 'org-imenu-and-speedbar
  666. :type 'number)
  667. (defgroup org-table nil
  668. "Options concerning tables in Org-mode."
  669. :tag "Org Table"
  670. :group 'org)
  671. (defcustom org-enable-table-editor 'optimized
  672. "Non-nil means, lines starting with \"|\" are handled by the table editor.
  673. When nil, such lines will be treated like ordinary lines.
  674. When equal to the symbol `optimized', the table editor will be optimized to
  675. do the following:
  676. - Automatic overwrite mode in front of whitespace in table fields.
  677. This makes the structure of the table stay in tact as long as the edited
  678. field does not exceed the column width.
  679. - Minimize the number of realigns. Normally, the table is aligned each time
  680. TAB or RET are pressed to move to another field. With optimization this
  681. happens only if changes to a field might have changed the column width.
  682. Optimization requires replacing the functions `self-insert-command',
  683. `delete-char', and `backward-delete-char' in Org-mode buffers, with a
  684. slight (in fact: unnoticeable) speed impact for normal typing. Org-mode is
  685. very good at guessing when a re-align will be necessary, but you can always
  686. force one with \\[org-ctrl-c-ctrl-c].
  687. If you would like to use the optimized version in Org-mode, but the
  688. un-optimized version in OrgTbl-mode, see the variable `orgtbl-optimized'.
  689. This variable can be used to turn on and off the table editor during a session,
  690. but in order to toggle optimization, a restart is required.
  691. See also the variable `org-table-auto-blank-field'."
  692. :group 'org-table
  693. :type '(choice
  694. (const :tag "off" nil)
  695. (const :tag "on" t)
  696. (const :tag "on, optimized" optimized)))
  697. (defcustom org-table-tab-recognizes-table.el t
  698. "Non-nil means, TAB will automatically notice a table.el table.
  699. When it sees such a table, it moves point into it and - if necessary -
  700. calls `table-recognize-table'."
  701. :group 'org-table-editing
  702. :type 'boolean)
  703. (defgroup org-link nil
  704. "Options concerning links in Org-mode."
  705. :tag "Org Link"
  706. :group 'org)
  707. (defvar org-link-abbrev-alist-local nil
  708. "Buffer-local version of `org-link-abbrev-alist', which see.
  709. The value of this is taken from the #+LINK lines.")
  710. (make-variable-buffer-local 'org-link-abbrev-alist-local)
  711. (defcustom org-link-abbrev-alist nil
  712. "Alist of link abbreviations.
  713. The car of each element is a string, to be replaced at the start of a link.
  714. The cdrs are replacement values, like (\"linkkey\" . REPLACE). Abbreviated
  715. links in Org-mode buffers can have an optional tag after a double colon, e.g.
  716. [[linkkey:tag][description]]
  717. If REPLACE is a string, the tag will simply be appended to create the link.
  718. If the string contains \"%s\", the tag will be inserted there.
  719. REPLACE may also be a function that will be called with the tag as the
  720. only argument to create the link, which should be returned as a string.
  721. See the manual for examples."
  722. :group 'org-link
  723. :type 'alist)
  724. (defcustom org-descriptive-links t
  725. "Non-nil means, hide link part and only show description of bracket links.
  726. Bracket links are like [[link][descritpion]]. This variable sets the initial
  727. state in new org-mode buffers. The setting can then be toggled on a
  728. per-buffer basis from the Org->Hyperlinks menu."
  729. :group 'org-link
  730. :type 'boolean)
  731. (defcustom org-link-file-path-type 'adaptive
  732. "How the path name in file links should be stored.
  733. Valid values are:
  734. relative Relative to the current directory, i.e. the directory of the file
  735. into which the link is being inserted.
  736. absolute Absolute path, if possible with ~ for home directory.
  737. noabbrev Absolute path, no abbreviation of home directory.
  738. adaptive Use relative path for files in the current directory and sub-
  739. directories of it. For other files, use an absolute path."
  740. :group 'org-link
  741. :type '(choice
  742. (const relative)
  743. (const absolute)
  744. (const noabbrev)
  745. (const adaptive)))
  746. (defcustom org-activate-links '(bracket angle plain radio tag date)
  747. "Types of links that should be activated in Org-mode files.
  748. This is a list of symbols, each leading to the activation of a certain link
  749. type. In principle, it does not hurt to turn on most link types - there may
  750. be a small gain when turning off unused link types. The types are:
  751. bracket The recommended [[link][description]] or [[link]] links with hiding.
  752. angular Links in angular brackes that may contain whitespace like
  753. <bbdb:Carsten Dominik>.
  754. plain Plain links in normal text, no whitespace, like http://google.com.
  755. radio Text that is matched by a radio target, see manual for details.
  756. tag Tag settings in a headline (link to tag search).
  757. date Time stamps (link to calendar).
  758. Changing this variable requires a restart of Emacs to become effective."
  759. :group 'org-link
  760. :type '(set (const :tag "Double bracket links (new style)" bracket)
  761. (const :tag "Angular bracket links (old style)" angular)
  762. (const :tag "Plain text links" plain)
  763. (const :tag "Radio target matches" radio)
  764. (const :tag "Tags" tag)
  765. (const :tag "Timestamps" date)))
  766. (defcustom org-make-link-description-function nil
  767. "Function to use to generate link descriptions from links. If
  768. nil the link location will be used. This function must take two
  769. parameters; the first is the link and the second the description
  770. org-insert-link has generated, and should return the description
  771. to use."
  772. :group 'org-link
  773. :type 'function)
  774. (defgroup org-link-store nil
  775. "Options concerning storing links in Org-mode."
  776. :tag "Org Store Link"
  777. :group 'org-link)
  778. (defcustom org-email-link-description-format "Email %c: %.30s"
  779. "Format of the description part of a link to an email or usenet message.
  780. The following %-excapes will be replaced by corresponding information:
  781. %F full \"From\" field
  782. %f name, taken from \"From\" field, address if no name
  783. %T full \"To\" field
  784. %t first name in \"To\" field, address if no name
  785. %c correspondent. Unually \"from NAME\", but if you sent it yourself, it
  786. will be \"to NAME\". See also the variable `org-from-is-user-regexp'.
  787. %s subject
  788. %m message-id.
  789. You may use normal field width specification between the % and the letter.
  790. This is for example useful to limit the length of the subject.
  791. Examples: \"%f on: %.30s\", \"Email from %f\", \"Email %c\""
  792. :group 'org-link-store
  793. :type 'string)
  794. (defcustom org-from-is-user-regexp
  795. (let (r1 r2)
  796. (when (and user-mail-address (not (string= user-mail-address "")))
  797. (setq r1 (concat "\\<" (regexp-quote user-mail-address) "\\>")))
  798. (when (and user-full-name (not (string= user-full-name "")))
  799. (setq r2 (concat "\\<" (regexp-quote user-full-name) "\\>")))
  800. (if (and r1 r2) (concat r1 "\\|" r2) (or r1 r2)))
  801. "Regexp mached against the \"From:\" header of an email or usenet message.
  802. It should match if the message is from the user him/herself."
  803. :group 'org-link-store
  804. :type 'regexp)
  805. (defcustom org-context-in-file-links t
  806. "Non-nil means, file links from `org-store-link' contain context.
  807. A search string will be added to the file name with :: as separator and
  808. used to find the context when the link is activated by the command
  809. `org-open-at-point'.
  810. Using a prefix arg to the command \\[org-store-link] (`org-store-link')
  811. negates this setting for the duration of the command."
  812. :group 'org-link-store
  813. :type 'boolean)
  814. (defcustom org-keep-stored-link-after-insertion nil
  815. "Non-nil means, keep link in list for entire session.
  816. The command `org-store-link' adds a link pointing to the current
  817. location to an internal list. These links accumulate during a session.
  818. The command `org-insert-link' can be used to insert links into any
  819. Org-mode file (offering completion for all stored links). When this
  820. option is nil, every link which has been inserted once using \\[org-insert-link]
  821. will be removed from the list, to make completing the unused links
  822. more efficient."
  823. :group 'org-link-store
  824. :type 'boolean)
  825. (defgroup org-link-follow nil
  826. "Options concerning following links in Org-mode."
  827. :tag "Org Follow Link"
  828. :group 'org-link)
  829. (defcustom org-follow-link-hook nil
  830. "Hook that is run after a link has been followed."
  831. :group 'org-link-follow
  832. :type 'hook)
  833. (defcustom org-tab-follows-link nil
  834. "Non-nil means, on links TAB will follow the link.
  835. Needs to be set before org.el is loaded."
  836. :group 'org-link-follow
  837. :type 'boolean)
  838. (defcustom org-return-follows-link nil
  839. "Non-nil means, on links RET will follow the link.
  840. Needs to be set before org.el is loaded."
  841. :group 'org-link-follow
  842. :type 'boolean)
  843. (defcustom org-mouse-1-follows-link
  844. (if (boundp 'mouse-1-click-follows-link) mouse-1-click-follows-link t)
  845. "Non-nil means, mouse-1 on a link will follow the link.
  846. A longer mouse click will still set point. Does not work on XEmacs.
  847. Needs to be set before org.el is loaded."
  848. :group 'org-link-follow
  849. :type 'boolean)
  850. (defcustom org-mark-ring-length 4
  851. "Number of different positions to be recorded in the ring
  852. Changing this requires a restart of Emacs to work correctly."
  853. :group 'org-link-follow
  854. :type 'interger)
  855. (defcustom org-link-frame-setup
  856. '((vm . vm-visit-folder-other-frame)
  857. (gnus . gnus-other-frame)
  858. (file . find-file-other-window))
  859. "Setup the frame configuration for following links.
  860. When following a link with Emacs, it may often be useful to display
  861. this link in another window or frame. This variable can be used to
  862. set this up for the different types of links.
  863. For VM, use any of
  864. `vm-visit-folder'
  865. `vm-visit-folder-other-frame'
  866. For Gnus, use any of
  867. `gnus'
  868. `gnus-other-frame'
  869. For FILE, use any of
  870. `find-file'
  871. `find-file-other-window'
  872. `find-file-other-frame'
  873. For the calendar, use the variable `calendar-setup'.
  874. For BBDB, it is currently only possible to display the matches in
  875. another window."
  876. :group 'org-link-follow
  877. :type '(list
  878. (cons (const vm)
  879. (choice
  880. (const vm-visit-folder)
  881. (const vm-visit-folder-other-window)
  882. (const vm-visit-folder-other-frame)))
  883. (cons (const gnus)
  884. (choice
  885. (const gnus)
  886. (const gnus-other-frame)))
  887. (cons (const file)
  888. (choice
  889. (const find-file)
  890. (const find-file-other-window)
  891. (const find-file-other-frame)))))
  892. (defcustom org-display-internal-link-with-indirect-buffer nil
  893. "Non-nil means, use indirect buffer to display infile links.
  894. Activating internal links (from one location in a file to another location
  895. in the same file) normally just jumps to the location. When the link is
  896. activated with a C-u prefix (or with mouse-3), the link is displayed in
  897. another window. When this option is set, the other window actually displays
  898. an indirect buffer clone of the current buffer, to avoid any visibility
  899. changes to the current buffer."
  900. :group 'org-link-follow
  901. :type 'boolean)
  902. (defcustom org-open-non-existing-files nil
  903. "Non-nil means, `org-open-file' will open non-existing files.
  904. When nil, an error will be generated."
  905. :group 'org-link-follow
  906. :type 'boolean)
  907. (defcustom org-link-mailto-program '(browse-url "mailto:%a?subject=%s")
  908. "Function and arguments to call for following mailto links.
  909. This is a list with the first element being a lisp function, and the
  910. remaining elements being arguments to the function. In string arguments,
  911. %a will be replaced by the address, and %s will be replaced by the subject
  912. if one was given like in <mailto:arthur@galaxy.org::this subject>."
  913. :group 'org-link-follow
  914. :type '(choice
  915. (const :tag "browse-url" (browse-url-mail "mailto:%a?subject=%s"))
  916. (const :tag "compose-mail" (compose-mail "%a" "%s"))
  917. (const :tag "message-mail" (message-mail "%a" "%s"))
  918. (cons :tag "other" (function) (repeat :tag "argument" sexp))))
  919. (defcustom org-confirm-shell-link-function 'yes-or-no-p
  920. "Non-nil means, ask for confirmation before executing shell links.
  921. Shell links can be dangerous: just think about a link
  922. [[shell:rm -rf ~/*][Google Search]]
  923. This link would show up in your Org-mode document as \"Google Search\",
  924. but really it would remove your entire home directory.
  925. Therefore we advise against setting this variable to nil.
  926. Just change it to `y-or-n-p' of you want to confirm with a
  927. single keystroke rather than having to type \"yes\"."
  928. :group 'org-link-follow
  929. :type '(choice
  930. (const :tag "with yes-or-no (safer)" yes-or-no-p)
  931. (const :tag "with y-or-n (faster)" y-or-n-p)
  932. (const :tag "no confirmation (dangerous)" nil)))
  933. (defcustom org-confirm-elisp-link-function 'yes-or-no-p
  934. "Non-nil means, ask for confirmation before executing Emacs Lisp links.
  935. Elisp links can be dangerous: just think about a link
  936. [[elisp:(shell-command \"rm -rf ~/*\")][Google Search]]
  937. This link would show up in your Org-mode document as \"Google Search\",
  938. but really it would remove your entire home directory.
  939. Therefore we advise against setting this variable to nil.
  940. Just change it to `y-or-n-p' of you want to confirm with a
  941. single keystroke rather than having to type \"yes\"."
  942. :group 'org-link-follow
  943. :type '(choice
  944. (const :tag "with yes-or-no (safer)" yes-or-no-p)
  945. (const :tag "with y-or-n (faster)" y-or-n-p)
  946. (const :tag "no confirmation (dangerous)" nil)))
  947. (defconst org-file-apps-defaults-gnu
  948. '((remote . emacs)
  949. (t . mailcap))
  950. "Default file applications on a UNIX or GNU/Linux system.
  951. See `org-file-apps'.")
  952. (defconst org-file-apps-defaults-macosx
  953. '((remote . emacs)
  954. (t . "open %s")
  955. ("ps" . "gv %s")
  956. ("ps.gz" . "gv %s")
  957. ("eps" . "gv %s")
  958. ("eps.gz" . "gv %s")
  959. ("dvi" . "xdvi %s")
  960. ("fig" . "xfig %s"))
  961. "Default file applications on a MacOS X system.
  962. The system \"open\" is known as a default, but we use X11 applications
  963. for some files for which the OS does not have a good default.
  964. See `org-file-apps'.")
  965. (defconst org-file-apps-defaults-windowsnt
  966. (list
  967. '(remote . emacs)
  968. (cons t
  969. (list (if (featurep 'xemacs)
  970. 'mswindows-shell-execute
  971. 'w32-shell-execute)
  972. "open" 'file)))
  973. "Default file applications on a Windows NT system.
  974. The system \"open\" is used for most files.
  975. See `org-file-apps'.")
  976. (defcustom org-file-apps
  977. '(
  978. ("txt" . emacs)
  979. ("tex" . emacs)
  980. ("ltx" . emacs)
  981. ("org" . emacs)
  982. ("el" . emacs)
  983. ("bib" . emacs)
  984. )
  985. "External applications for opening `file:path' items in a document.
  986. Org-mode uses system defaults for different file types, but
  987. you can use this variable to set the application for a given file
  988. extension. The entries in this list are cons cells where the car identifies
  989. files and the cdr the corresponding command. Possible values for the
  990. file identifier are
  991. \"ext\" A string identifying an extension
  992. `directory' Matches a directory
  993. `remote' Matches a remote file, accessible through tramp or efs.
  994. Remote files most likely should be visited through Emacs
  995. because external applications cannot handle such paths.
  996. t Default for all remaining files
  997. Possible values for the command are:
  998. `emacs' The file will be visited by the current Emacs process.
  999. `default' Use the default application for this file type.
  1000. string A command to be executed by a shell; %s will be replaced
  1001. by the path to the file.
  1002. sexp A Lisp form which will be evaluated. The file path will
  1003. be available in the Lisp variable `file'.
  1004. For more examples, see the system specific constants
  1005. `org-file-apps-defaults-macosx'
  1006. `org-file-apps-defaults-windowsnt'
  1007. `org-file-apps-defaults-gnu'."
  1008. :group 'org-link-follow
  1009. :type '(repeat
  1010. (cons (choice :value ""
  1011. (string :tag "Extension")
  1012. (const :tag "Default for unrecognized files" t)
  1013. (const :tag "Remote file" remote)
  1014. (const :tag "Links to a directory" directory))
  1015. (choice :value ""
  1016. (const :tag "Visit with Emacs" emacs)
  1017. (const :tag "Use system default" default)
  1018. (string :tag "Command")
  1019. (sexp :tag "Lisp form")))))
  1020. (defgroup org-refile nil
  1021. "Options concerning refiling entries in Org-mode."
  1022. :tag "Org Remember"
  1023. :group 'org)
  1024. (defcustom org-directory "~/org"
  1025. "Directory with org files.
  1026. This directory will be used as default to prompt for org files.
  1027. Used by the hooks for remember.el."
  1028. :group 'org-refile
  1029. :group 'org-remember
  1030. :type 'directory)
  1031. (defcustom org-default-notes-file "~/.notes"
  1032. "Default target for storing notes.
  1033. Used by the hooks for remember.el. This can be a string, or nil to mean
  1034. the value of `remember-data-file'.
  1035. You can set this on a per-template basis with the variable
  1036. `org-remember-templates'."
  1037. :group 'org-refile
  1038. :group 'org-remember
  1039. :type '(choice
  1040. (const :tag "Default from remember-data-file" nil)
  1041. file))
  1042. (defcustom org-goto-interface 'outline
  1043. "The default interface to be used for `org-goto'.
  1044. Allowed vaues are:
  1045. outline The interface shows an outline of the relevant file
  1046. and the correct heading is found by moving through
  1047. the outline or by searching with incremental search.
  1048. outline-path-completion Headlines in the current buffer are offered via
  1049. completion."
  1050. :group 'org-refile
  1051. :type '(choice
  1052. (const :tag "Outline" outline)
  1053. (const :tag "Outline-path-completion" outline-path-completion)))
  1054. (defcustom org-reverse-note-order nil
  1055. "Non-nil means, store new notes at the beginning of a file or entry.
  1056. When nil, new notes will be filed to the end of a file or entry.
  1057. This can also be a list with cons cells of regular expressions that
  1058. are matched against file names, and values."
  1059. :group 'org-remember
  1060. :type '(choice
  1061. (const :tag "Reverse always" t)
  1062. (const :tag "Reverse never" nil)
  1063. (repeat :tag "By file name regexp"
  1064. (cons regexp boolean))))
  1065. (defcustom org-refile-targets nil
  1066. "Targets for refiling entries with \\[org-refile].
  1067. This is list of cons cells. Each cell contains:
  1068. - a specification of the files to be considered, either a list of files,
  1069. or a symbol whose function or variable value will be used to retrieve
  1070. a file name or a list of file names. Nil means, refile to a different
  1071. heading in the current buffer.
  1072. - A specification of how to find candidate refile targets. This may be
  1073. any of
  1074. - a cons cell (:tag . \"TAG\") to identify refile targets by a tag.
  1075. This tag has to be present in all target headlines, inheritance will
  1076. not be considered.
  1077. - a cons cell (:todo . \"KEYWORD\") to identify refile targets by
  1078. todo keyword.
  1079. - a cons cell (:regexp . \"REGEXP\") with a regular expression matching
  1080. headlines that are refiling targets.
  1081. - a cons cell (:level . N). Any headline of level N is considered a target.
  1082. - a cons cell (:maxlevel . N). Any headline with level <= N is a target."
  1083. :group 'org-remember
  1084. :type '(repeat
  1085. (cons
  1086. (choice :value org-agenda-files
  1087. (const :tag "All agenda files" org-agenda-files)
  1088. (const :tag "Current buffer" nil)
  1089. (function) (variable) (file))
  1090. (choice :tag "Identify target headline by"
  1091. (cons :tag "Specific tag" (const :tag) (string))
  1092. (cons :tag "TODO keyword" (const :todo) (string))
  1093. (cons :tag "Regular expression" (const :regexp) (regexp))
  1094. (cons :tag "Level number" (const :level) (integer))
  1095. (cons :tag "Max Level number" (const :maxlevel) (integer))))))
  1096. (defcustom org-refile-use-outline-path nil
  1097. "Non-nil means, provide refile targets as paths.
  1098. So a level 3 headline will be available as level1/level2/level3.
  1099. When the value is `file', also include the file name (without directory)
  1100. into the path. When `full-file-path', include the full file path."
  1101. :group 'org-remember
  1102. :type '(choice
  1103. (const :tag "Not" nil)
  1104. (const :tag "Yes" t)
  1105. (const :tag "Start with file name" file)
  1106. (const :tag "Start with full file path" full-file-path)))
  1107. (defgroup org-todo nil
  1108. "Options concerning TODO items in Org-mode."
  1109. :tag "Org TODO"
  1110. :group 'org)
  1111. (defgroup org-progress nil
  1112. "Options concerning Progress logging in Org-mode."
  1113. :tag "Org Progress"
  1114. :group 'org-time)
  1115. (defcustom org-todo-keywords '((sequence "TODO" "DONE"))
  1116. "List of TODO entry keyword sequences and their interpretation.
  1117. \\<org-mode-map>This is a list of sequences.
  1118. Each sequence starts with a symbol, either `sequence' or `type',
  1119. indicating if the keywords should be interpreted as a sequence of
  1120. action steps, or as different types of TODO items. The first
  1121. keywords are states requiring action - these states will select a headline
  1122. for inclusion into the global TODO list Org-mode produces. If one of
  1123. the \"keywords\" is the vertical bat \"|\" the remaining keywords
  1124. signify that no further action is necessary. If \"|\" is not found,
  1125. the last keyword is treated as the only DONE state of the sequence.
  1126. The command \\[org-todo] cycles an entry through these states, and one
  1127. additional state where no keyword is present. For details about this
  1128. cycling, see the manual.
  1129. TODO keywords and interpretation can also be set on a per-file basis with
  1130. the special #+SEQ_TODO and #+TYP_TODO lines.
  1131. Each keyword can optionally specify a character for fast state selection
  1132. \(in combination with the variable `org-use-fast-todo-selection')
  1133. and specifiers for state change logging, using the same syntax
  1134. that is used in the \"#+TODO:\" lines. For example, \"WAIT(w)\" says
  1135. that the WAIT state can be selected with the \"w\" key. \"WAIT(w!)\"
  1136. indicates to record a time stamp each time this state is selected.
  1137. Each keyword may also specify if a timestamp or a note should be
  1138. recorded when entering or leaving the state, by adding additional
  1139. characters in the parenthesis after the keyword. This looks like this:
  1140. \"WAIT(w@/!)\". \"@\" means to add a note (with time), \"!\" means to
  1141. record only the time of the state change. With X and Y being either
  1142. \"@\" or \"!\", \"X/Y\" means use X when entering the state, and use
  1143. Y when leaving the state if and only if the *target* state does not
  1144. define X. You may omit any of the fast-selection key or X or /Y,
  1145. so WAIT(w@), WAIT(w/@) and WAIT(@/@) are all valid.
  1146. For backward compatibility, this variable may also be just a list
  1147. of keywords - in this case the interptetation (sequence or type) will be
  1148. taken from the (otherwise obsolete) variable `org-todo-interpretation'."
  1149. :group 'org-todo
  1150. :group 'org-keywords
  1151. :type '(choice
  1152. (repeat :tag "Old syntax, just keywords"
  1153. (string :tag "Keyword"))
  1154. (repeat :tag "New syntax"
  1155. (cons
  1156. (choice
  1157. :tag "Interpretation"
  1158. (const :tag "Sequence (cycling hits every state)" sequence)
  1159. (const :tag "Type (cycling directly to DONE)" type))
  1160. (repeat
  1161. (string :tag "Keyword"))))))
  1162. (defvar org-todo-keywords-1 nil
  1163. "All TODO and DONE keywords active in a buffer.")
  1164. (make-variable-buffer-local 'org-todo-keywords-1)
  1165. (defvar org-todo-keywords-for-agenda nil)
  1166. (defvar org-done-keywords-for-agenda nil)
  1167. (defvar org-agenda-contributing-files nil)
  1168. (defvar org-not-done-keywords nil)
  1169. (make-variable-buffer-local 'org-not-done-keywords)
  1170. (defvar org-done-keywords nil)
  1171. (make-variable-buffer-local 'org-done-keywords)
  1172. (defvar org-todo-heads nil)
  1173. (make-variable-buffer-local 'org-todo-heads)
  1174. (defvar org-todo-sets nil)
  1175. (make-variable-buffer-local 'org-todo-sets)
  1176. (defvar org-todo-log-states nil)
  1177. (make-variable-buffer-local 'org-todo-log-states)
  1178. (defvar org-todo-kwd-alist nil)
  1179. (make-variable-buffer-local 'org-todo-kwd-alist)
  1180. (defvar org-todo-key-alist nil)
  1181. (make-variable-buffer-local 'org-todo-key-alist)
  1182. (defvar org-todo-key-trigger nil)
  1183. (make-variable-buffer-local 'org-todo-key-trigger)
  1184. (defcustom org-todo-interpretation 'sequence
  1185. "Controls how TODO keywords are interpreted.
  1186. This variable is in principle obsolete and is only used for
  1187. backward compatibility, if the interpretation of todo keywords is
  1188. not given already in `org-todo-keywords'. See that variable for
  1189. more information."
  1190. :group 'org-todo
  1191. :group 'org-keywords
  1192. :type '(choice (const sequence)
  1193. (const type)))
  1194. (defcustom org-use-fast-todo-selection 'prefix
  1195. "Non-nil means, use the fast todo selection scheme with C-c C-t.
  1196. This variable describes if and under what circumstances the cycling
  1197. mechanism for TODO keywords will be replaced by a single-key, direct
  1198. selection scheme.
  1199. When nil, fast selection is never used.
  1200. When the symbol `prefix', it will be used when `org-todo' is called with
  1201. a prefix argument, i.e. `C-u C-c C-t' in an Org-mode buffer, and `C-u t'
  1202. in an agenda buffer.
  1203. When t, fast selection is used by default. In this case, the prefix
  1204. argument forces cycling instead.
  1205. In all cases, the special interface is only used if access keys have actually
  1206. been assigned by the user, i.e. if keywords in the configuration are followed
  1207. by a letter in parenthesis, like TODO(t)."
  1208. :group 'org-todo
  1209. :type '(choice
  1210. (const :tag "Never" nil)
  1211. (const :tag "By default" t)
  1212. (const :tag "Only with C-u C-c C-t" prefix)))
  1213. (defcustom org-after-todo-state-change-hook nil
  1214. "Hook which is run after the state of a TODO item was changed.
  1215. The new state (a string with a TODO keyword, or nil) is available in the
  1216. Lisp variable `state'."
  1217. :group 'org-todo
  1218. :type 'hook)
  1219. (defcustom org-log-done nil
  1220. "Non-nil means, record a CLOSED timestamp when moving an entry to DONE.
  1221. When equal to the list (done), also prompt for a closing note.
  1222. This can also be configured on a per-file basis by adding one of
  1223. the following lines anywhere in the buffer:
  1224. #+STARTUP: logdone
  1225. #+STARTUP: lognotedone
  1226. #+STARTUP: nologdone"
  1227. :group 'org-todo
  1228. :group 'org-progress
  1229. :type '(choice
  1230. (const :tag "No logging" nil)
  1231. (const :tag "Record CLOSED timestamp" time)
  1232. (const :tag "Record CLOSED timestamp with closing note." note)))
  1233. ;; Normalize old uses of org-log-done.
  1234. (cond
  1235. ((eq org-log-done t) (setq org-log-done 'time))
  1236. ((and (listp org-log-done) (memq 'done org-log-done))
  1237. (setq org-log-done 'note)))
  1238. (defcustom org-log-note-clock-out nil
  1239. "Non-nil means, recored a note when clocking out of an item.
  1240. This can also be configured on a per-file basis by adding one of
  1241. the following lines anywhere in the buffer:
  1242. #+STARTUP: lognoteclock-out
  1243. #+STARTUP: nolognoteclock-out"
  1244. :group 'org-todo
  1245. :group 'org-progress
  1246. :type 'boolean)
  1247. (defcustom org-log-done-with-time t
  1248. "Non-nil means, the CLOSED time stamp will contain date and time.
  1249. When nil, only the date will be recorded."
  1250. :group 'org-progress
  1251. :type 'boolean)
  1252. (defcustom org-log-note-headings
  1253. '((done . "CLOSING NOTE %t")
  1254. (state . "State %-12s %t")
  1255. (note . "Note taken on %t")
  1256. (clock-out . ""))
  1257. "Headings for notes added to entries.
  1258. The value is an alist, with the car being a symbol indicating the note
  1259. context, and the cdr is the heading to be used. The heading may also be the
  1260. empty string.
  1261. %t in the heading will be replaced by a time stamp.
  1262. %s will be replaced by the new TODO state, in double quotes.
  1263. %u will be replaced by the user name.
  1264. %U will be replaced by the full user name."
  1265. :group 'org-todo
  1266. :group 'org-progress
  1267. :type '(list :greedy t
  1268. (cons (const :tag "Heading when closing an item" done) string)
  1269. (cons (const :tag
  1270. "Heading when changing todo state (todo sequence only)"
  1271. state) string)
  1272. (cons (const :tag "Heading when just taking a note" note) string)
  1273. (cons (const :tag "Heading when clocking out" clock-out) string)))
  1274. (unless (assq 'note org-log-note-headings)
  1275. (push '(note . "%t") org-log-note-headings))
  1276. (defcustom org-log-states-order-reversed t
  1277. "Non-nil means, the latest state change note will be directly after heading.
  1278. When nil, the notes will be orderer according to time."
  1279. :group 'org-todo
  1280. :group 'org-progress
  1281. :type 'boolean)
  1282. (defcustom org-log-repeat 'time
  1283. "Non-nil means, record moving through the DONE state when triggering repeat.
  1284. An auto-repeating tasks is immediately switched back to TODO when marked
  1285. done. If you are not logging state changes (by adding \"@\" or \"!\" to
  1286. the TODO keyword definition, or recording a closing note by setting
  1287. `org-log-done', there will be no record of the task moving through DONE.
  1288. This variable forces taking a note anyway. Possible values are:
  1289. nil Don't force a record
  1290. time Record a time stamp
  1291. note Record a note
  1292. This option can also be set with on a per-file-basis with
  1293. #+STARTUP: logrepeat
  1294. #+STARTUP: lognoterepeat
  1295. #+STARTUP: nologrepeat
  1296. You can have local logging settings for a subtree by setting the LOGGING
  1297. property to one or more of these keywords."
  1298. :group 'org-todo
  1299. :group 'org-progress
  1300. :type '(choice
  1301. (const :tag "Don't force a record" nil)
  1302. (const :tag "Force recording the DONE state" time)
  1303. (const :tag "Force recording a note with the DONE state" note)))
  1304. (defgroup org-priorities nil
  1305. "Priorities in Org-mode."
  1306. :tag "Org Priorities"
  1307. :group 'org-todo)
  1308. (defcustom org-highest-priority ?A
  1309. "The highest priority of TODO items. A character like ?A, ?B etc.
  1310. Must have a smaller ASCII number than `org-lowest-priority'."
  1311. :group 'org-priorities
  1312. :type 'character)
  1313. (defcustom org-lowest-priority ?C
  1314. "The lowest priority of TODO items. A character like ?A, ?B etc.
  1315. Must have a larger ASCII number than `org-highest-priority'."
  1316. :group 'org-priorities
  1317. :type 'character)
  1318. (defcustom org-default-priority ?B
  1319. "The default priority of TODO items.
  1320. This is the priority an item get if no explicit priority is given."
  1321. :group 'org-priorities
  1322. :type 'character)
  1323. (defcustom org-priority-start-cycle-with-default t
  1324. "Non-nil means, start with default priority when starting to cycle.
  1325. When this is nil, the first step in the cycle will be (depending on the
  1326. command used) one higher or lower that the default priority."
  1327. :group 'org-priorities
  1328. :type 'boolean)
  1329. (defgroup org-time nil
  1330. "Options concerning time stamps and deadlines in Org-mode."
  1331. :tag "Org Time"
  1332. :group 'org)
  1333. (defcustom org-insert-labeled-timestamps-at-point nil
  1334. "Non-nil means, SCHEDULED and DEADLINE timestamps are inserted at point.
  1335. When nil, these labeled time stamps are forces into the second line of an
  1336. entry, just after the headline. When scheduling from the global TODO list,
  1337. the time stamp will always be forced into the second line."
  1338. :group 'org-time
  1339. :type 'boolean)
  1340. (defconst org-time-stamp-formats '("<%Y-%m-%d %a>" . "<%Y-%m-%d %a %H:%M>")
  1341. "Formats for `format-time-string' which are used for time stamps.
  1342. It is not recommended to change this constant.")
  1343. (defcustom org-time-stamp-rounding-minutes '(0 5)
  1344. "Number of minutes to round time stamps to.
  1345. These are two values, the first applies when first creating a time stamp.
  1346. The second applies when changing it with the commands `S-up' and `S-down'.
  1347. When changing the time stamp, this means that it will change in steps
  1348. of N minutes, as given by the second value.
  1349. When a setting is 0 or 1, insert the time unmodified. Useful rounding
  1350. numbers should be factors of 60, so for example 5, 10, 15.
  1351. When this is larger than 1, you can still force an exact time-stamp by using
  1352. a double prefix argument to a time-stamp command like `C-c .' or `C-c !',
  1353. and by using a prefix arg to `S-up/down' to specify the exact number
  1354. of minutes to shift."
  1355. :group 'org-time
  1356. :get '(lambda (var) ; Make sure all entries have 5 elements
  1357. (if (integerp (default-value var))
  1358. (list (default-value var) 5)
  1359. (default-value var)))
  1360. :type '(list
  1361. (integer :tag "when inserting times")
  1362. (integer :tag "when modifying times")))
  1363. ;; Normalize old customizations of this variable.
  1364. (when (integerp org-time-stamp-rounding-minutes)
  1365. (setq org-time-stamp-rounding-minutes
  1366. (list org-time-stamp-rounding-minutes
  1367. org-time-stamp-rounding-minutes)))
  1368. (defcustom org-display-custom-times nil
  1369. "Non-nil means, overlay custom formats over all time stamps.
  1370. The formats are defined through the variable `org-time-stamp-custom-formats'.
  1371. To turn this on on a per-file basis, insert anywhere in the file:
  1372. #+STARTUP: customtime"
  1373. :group 'org-time
  1374. :set 'set-default
  1375. :type 'sexp)
  1376. (make-variable-buffer-local 'org-display-custom-times)
  1377. (defcustom org-time-stamp-custom-formats
  1378. '("<%m/%d/%y %a>" . "<%m/%d/%y %a %H:%M>") ; american
  1379. "Custom formats for time stamps. See `format-time-string' for the syntax.
  1380. These are overlayed over the default ISO format if the variable
  1381. `org-display-custom-times' is set. Time like %H:%M should be at the
  1382. end of the second format."
  1383. :group 'org-time
  1384. :type 'sexp)
  1385. (defun org-time-stamp-format (&optional long inactive)
  1386. "Get the right format for a time string."
  1387. (let ((f (if long (cdr org-time-stamp-formats)
  1388. (car org-time-stamp-formats))))
  1389. (if inactive
  1390. (concat "[" (substring f 1 -1) "]")
  1391. f)))
  1392. (defcustom org-deadline-warning-days 14
  1393. "No. of days before expiration during which a deadline becomes active.
  1394. This variable governs the display in sparse trees and in the agenda.
  1395. When 0 or negative, it means use this number (the absolute value of it)
  1396. even if a deadline has a different individual lead time specified."
  1397. :group 'org-time
  1398. :group 'org-agenda-daily/weekly
  1399. :type 'number)
  1400. (defcustom org-read-date-prefer-future t
  1401. "Non-nil means, assume future for incomplete date input from user.
  1402. This affects the following situations:
  1403. 1. The user gives a day, but no month.
  1404. For example, if today is the 15th, and you enter \"3\", Org-mode will
  1405. read this as the third of *next* month. However, if you enter \"17\",
  1406. it will be considered as *this* month.
  1407. 2. The user gives a month but not a year.
  1408. For example, if it is april and you enter \"feb 2\", this will be read
  1409. as feb 2, *next* year. \"May 5\", however, will be this year.
  1410. Currently this does not work for ISO week specifications.
  1411. When this option is nil, the current month and year will always be used
  1412. as defaults."
  1413. :group 'org-time
  1414. :type 'boolean)
  1415. (defcustom org-read-date-display-live t
  1416. "Non-nil means, display current interpretation of date prompt live.
  1417. This display will be in an overlay, in the minibuffer."
  1418. :group 'org-time
  1419. :type 'boolean)
  1420. (defcustom org-read-date-popup-calendar t
  1421. "Non-nil means, pop up a calendar when prompting for a date.
  1422. In the calendar, the date can be selected with mouse-1. However, the
  1423. minibuffer will also be active, and you can simply enter the date as well.
  1424. When nil, only the minibuffer will be available."
  1425. :group 'org-time
  1426. :type 'boolean)
  1427. (if (fboundp 'defvaralias)
  1428. (defvaralias 'org-popup-calendar-for-date-prompt
  1429. 'org-read-date-popup-calendar))
  1430. (defcustom org-extend-today-until 0
  1431. "The hour when your day really ends.
  1432. This has influence for the following applications:
  1433. - When switching the agenda to \"today\". It it is still earlier than
  1434. the time given here, the day recognized as TODAY is actually yesterday.
  1435. - When a date is read from the user and it is still before the time given
  1436. here, the current date and time will be assumed to be yesterday, 23:59.
  1437. FIXME:
  1438. IMPORTANT: This is still a very experimental feature, it may disappear
  1439. again or it may be extended to mean more things."
  1440. :group 'org-time
  1441. :type 'number)
  1442. (defcustom org-edit-timestamp-down-means-later nil
  1443. "Non-nil means, S-down will increase the time in a time stamp.
  1444. When nil, S-up will increase."
  1445. :group 'org-time
  1446. :type 'boolean)
  1447. (defcustom org-calendar-follow-timestamp-change t
  1448. "Non-nil means, make the calendar window follow timestamp changes.
  1449. When a timestamp is modified and the calendar window is visible, it will be
  1450. moved to the new date."
  1451. :group 'org-time
  1452. :type 'boolean)
  1453. (defgroup org-tags nil
  1454. "Options concerning tags in Org-mode."
  1455. :tag "Org Tags"
  1456. :group 'org)
  1457. (defcustom org-tag-alist nil
  1458. "List of tags allowed in Org-mode files.
  1459. When this list is nil, Org-mode will base TAG input on what is already in the
  1460. buffer.
  1461. The value of this variable is an alist, the car of each entry must be a
  1462. keyword as a string, the cdr may be a character that is used to select
  1463. that tag through the fast-tag-selection interface.
  1464. See the manual for details."
  1465. :group 'org-tags
  1466. :type '(repeat
  1467. (choice
  1468. (cons (string :tag "Tag name")
  1469. (character :tag "Access char"))
  1470. (const :tag "Start radio group" (:startgroup))
  1471. (const :tag "End radio group" (:endgroup)))))
  1472. (defcustom org-use-fast-tag-selection 'auto
  1473. "Non-nil means, use fast tag selection scheme.
  1474. This is a special interface to select and deselect tags with single keys.
  1475. When nil, fast selection is never used.
  1476. When the symbol `auto', fast selection is used if and only if selection
  1477. characters for tags have been configured, either through the variable
  1478. `org-tag-alist' or through a #+TAGS line in the buffer.
  1479. When t, fast selection is always used and selection keys are assigned
  1480. automatically if necessary."
  1481. :group 'org-tags
  1482. :type '(choice
  1483. (const :tag "Always" t)
  1484. (const :tag "Never" nil)
  1485. (const :tag "When selection characters are configured" 'auto)))
  1486. (defcustom org-fast-tag-selection-single-key nil
  1487. "Non-nil means, fast tag selection exits after first change.
  1488. When nil, you have to press RET to exit it.
  1489. During fast tag selection, you can toggle this flag with `C-c'.
  1490. This variable can also have the value `expert'. In this case, the window
  1491. displaying the tags menu is not even shown, until you press C-c again."
  1492. :group 'org-tags
  1493. :type '(choice
  1494. (const :tag "No" nil)
  1495. (const :tag "Yes" t)
  1496. (const :tag "Expert" expert)))
  1497. (defvar org-fast-tag-selection-include-todo nil
  1498. "Non-nil means, fast tags selection interface will also offer TODO states.
  1499. This is an undocumented feature, you should not rely on it.")
  1500. (defcustom org-tags-column (if (featurep 'xemacs) -79 -80)
  1501. "The column to which tags should be indented in a headline.
  1502. If this number is positive, it specifies the column. If it is negative,
  1503. it means that the tags should be flushright to that column. For example,
  1504. -80 works well for a normal 80 character screen."
  1505. :group 'org-tags
  1506. :type 'integer)
  1507. (defcustom org-auto-align-tags t
  1508. "Non-nil means, realign tags after pro/demotion of TODO state change.
  1509. These operations change the length of a headline and therefore shift
  1510. the tags around. With this options turned on, after each such operation
  1511. the tags are again aligned to `org-tags-column'."
  1512. :group 'org-tags
  1513. :type 'boolean)
  1514. (defcustom org-use-tag-inheritance t
  1515. "Non-nil means, tags in levels apply also for sublevels.
  1516. When nil, only the tags directly given in a specific line apply there.
  1517. If you turn off this option, you very likely want to turn on the
  1518. companion option `org-tags-match-list-sublevels'.
  1519. This may also be a list of tags that should be inherited, or a regexp that
  1520. matches tags that should be inherited."
  1521. :group 'org-tags
  1522. :type '(choice
  1523. (const :tag "Not" nil)
  1524. (const :tag "Always" t)
  1525. (repeat :tag "Specific tags" (string :tag "Tag"))
  1526. (regexp :tag "Tags matched by regexp")))
  1527. (defun org-tag-inherit-p (tag)
  1528. "Check if TAG is one that should be inherited."
  1529. (cond
  1530. ((eq org-use-tag-inheritance t) t)
  1531. ((not org-use-tag-inheritance) nil)
  1532. ((stringp org-use-tag-inheritance)
  1533. (string-match org-use-tag-inheritance tag))
  1534. ((listp org-use-tag-inheritance)
  1535. (member tag org-use-tag-inheritance))
  1536. (t (error "Invalid setting of `org-use-tag-inheritance'"))))
  1537. (defcustom org-tags-match-list-sublevels nil
  1538. "Non-nil means list also sublevels of headlines matching tag search.
  1539. Because of tag inheritance (see variable `org-use-tag-inheritance'),
  1540. the sublevels of a headline matching a tag search often also match
  1541. the same search. Listing all of them can create very long lists.
  1542. Setting this variable to nil causes subtrees of a match to be skipped.
  1543. This option is off by default, because inheritance in on. If you turn
  1544. inheritance off, you very likely want to turn this option on.
  1545. As a special case, if the tag search is restricted to TODO items, the
  1546. value of this variable is ignored and sublevels are always checked, to
  1547. make sure all corresponding TODO items find their way into the list."
  1548. :group 'org-tags
  1549. :type 'boolean)
  1550. (defvar org-tags-history nil
  1551. "History of minibuffer reads for tags.")
  1552. (defvar org-last-tags-completion-table nil
  1553. "The last used completion table for tags.")
  1554. (defvar org-after-tags-change-hook nil
  1555. "Hook that is run after the tags in a line have changed.")
  1556. (defgroup org-properties nil
  1557. "Options concerning properties in Org-mode."
  1558. :tag "Org Properties"
  1559. :group 'org)
  1560. (defcustom org-property-format "%-10s %s"
  1561. "How property key/value pairs should be formatted by `indent-line'.
  1562. When `indent-line' hits a property definition, it will format the line
  1563. according to this format, mainly to make sure that the values are
  1564. lined-up with respect to each other."
  1565. :group 'org-properties
  1566. :type 'string)
  1567. (defcustom org-use-property-inheritance nil
  1568. "Non-nil means, properties apply also for sublevels.
  1569. This setting is chiefly used during property searches. Turning it on can
  1570. cause significant overhead when doing a search, which is why it is not
  1571. on by default.
  1572. When nil, only the properties directly given in the current entry count.
  1573. When t, every property is inherited. The value may also be a list of
  1574. properties that should have inheritance, or a regular expression matching
  1575. properties that should be inherited.
  1576. However, note that some special properties use inheritance under special
  1577. circumstances (not in searches). Examples are CATEGORY, ARCHIVE, COLUMNS,
  1578. and the properties ending in \"_ALL\" when they are used as descriptor
  1579. for valid values of a property.
  1580. Note for programmers:
  1581. When querying an entry with `org-entry-get', you can control if inheritance
  1582. should be used. By default, `org-entry-get' looks only at the local
  1583. properties. You can request inheritance by setting the inherit argument
  1584. to t (to force inheritance) or to `selective' (to respect the setting
  1585. in this variable)."
  1586. :group 'org-properties
  1587. :type '(choice
  1588. (const :tag "Not" nil)
  1589. (const :tag "Always" t)
  1590. (repeat :tag "Specific properties" (string :tag "Property"))
  1591. (regexp :tag "Properties matched by regexp")))
  1592. (defun org-property-inherit-p (property)
  1593. "Check if PROPERTY is one that should be inherited."
  1594. (cond
  1595. ((eq org-use-property-inheritance t) t)
  1596. ((not org-use-property-inheritance) nil)
  1597. ((stringp org-use-property-inheritance)
  1598. (string-match org-use-property-inheritance property))
  1599. ((listp org-use-property-inheritance)
  1600. (member property org-use-property-inheritance))
  1601. (t (error "Invalid setting of `org-use-property-inheritance'"))))
  1602. (defcustom org-columns-default-format "%25ITEM %TODO %3PRIORITY %TAGS"
  1603. "The default column format, if no other format has been defined.
  1604. This variable can be set on the per-file basis by inserting a line
  1605. #+COLUMNS: %25ITEM ....."
  1606. :group 'org-properties
  1607. :type 'string)
  1608. (defcustom org-effort-property "Effort"
  1609. "The property that is being used to keep track of effort estimates.
  1610. Effort estimates given in this property need to have the format H:MM."
  1611. :group 'org-properties
  1612. :group 'org-progress
  1613. :type '(string :tag "Property"))
  1614. (defconst org-global-properties-fixed
  1615. '(("VISIBILITY_ALL" . "folded children content all"))
  1616. "List of property/value pairs that can be inherited by any entry.
  1617. These are fixed values, for the preset properties.")
  1618. (defcustom org-global-properties nil
  1619. "List of property/value pairs that can be inherited by any entry.
  1620. You can set buffer-local values for this by adding lines like
  1621. #+PROPERTY: NAME VALUE"
  1622. :group 'org-properties
  1623. :type '(repeat
  1624. (cons (string :tag "Property")
  1625. (string :tag "Value"))))
  1626. (defvar org-local-properties nil
  1627. "List of property/value pairs that can be inherited by any entry.
  1628. Valid for the current buffer.
  1629. This variable is populated from #+PROPERTY lines.")
  1630. (defgroup org-agenda nil
  1631. "Options concerning agenda views in Org-mode."
  1632. :tag "Org Agenda"
  1633. :group 'org)
  1634. (defvar org-category nil
  1635. "Variable used by org files to set a category for agenda display.
  1636. Such files should use a file variable to set it, for example
  1637. # -*- mode: org; org-category: \"ELisp\"
  1638. or contain a special line
  1639. #+CATEGORY: ELisp
  1640. If the file does not specify a category, then file's base name
  1641. is used instead.")
  1642. (make-variable-buffer-local 'org-category)
  1643. (defcustom org-agenda-files nil
  1644. "The files to be used for agenda display.
  1645. Entries may be added to this list with \\[org-agenda-file-to-front] and removed with
  1646. \\[org-remove-file]. You can also use customize to edit the list.
  1647. If an entry is a directory, all files in that directory that are matched by
  1648. `org-agenda-file-regexp' will be part of the file list.
  1649. If the value of the variable is not a list but a single file name, then
  1650. the list of agenda files is actually stored and maintained in that file, one
  1651. agenda file per line."
  1652. :group 'org-agenda
  1653. :type '(choice
  1654. (repeat :tag "List of files and directories" file)
  1655. (file :tag "Store list in a file\n" :value "~/.agenda_files")))
  1656. (defcustom org-agenda-file-regexp "\\`[^.].*\\.org\\'"
  1657. "Regular expression to match files for `org-agenda-files'.
  1658. If any element in the list in that variable contains a directory instead
  1659. of a normal file, all files in that directory that are matched by this
  1660. regular expression will be included."
  1661. :group 'org-agenda
  1662. :type 'regexp)
  1663. (defcustom org-agenda-text-search-extra-files nil
  1664. "List of extra files to be searched by text search commands.
  1665. These files will be search in addition to the agenda files by the
  1666. commands `org-search-view' (`C-c a s') and `org-occur-in-agenda-files'.
  1667. Note that these files will only be searched for text search commands,
  1668. not for the other agenda views like todo lists, tag searches or the weekly
  1669. agenda. This variable is intended to list notes and possibly archive files
  1670. that should also be searched by these two commands.
  1671. In fact, if the first element in the list is the symbol `agenda-archives',
  1672. than all archive files of all agenda files will be added to the search
  1673. scope."
  1674. :group 'org-agenda
  1675. :type '(set :greedy t
  1676. (const :tag "Agenda Archives" agenda-archives)
  1677. (repeat :inline t (file))))
  1678. (if (fboundp 'defvaralias)
  1679. (defvaralias 'org-agenda-multi-occur-extra-files
  1680. 'org-agenda-text-search-extra-files))
  1681. (defcustom org-agenda-skip-unavailable-files nil
  1682. "t means to just skip non-reachable files in `org-agenda-files'.
  1683. Nil means to remove them, after a query, from the list."
  1684. :group 'org-agenda
  1685. :type 'boolean)
  1686. (defcustom org-calendar-to-agenda-key [?c]
  1687. "The key to be installed in `calendar-mode-map' for switching to the agenda.
  1688. The command `org-calendar-goto-agenda' will be bound to this key. The
  1689. default is the character `c' because then `c' can be used to switch back and
  1690. forth between agenda and calendar."
  1691. :group 'org-agenda
  1692. :type 'sexp)
  1693. (eval-after-load "calendar"
  1694. '(org-defkey calendar-mode-map org-calendar-to-agenda-key
  1695. 'org-calendar-goto-agenda))
  1696. (defgroup org-latex nil
  1697. "Options for embedding LaTeX code into Org-mode."
  1698. :tag "Org LaTeX"
  1699. :group 'org)
  1700. (defcustom org-format-latex-options
  1701. '(:foreground default :background default :scale 1.0
  1702. :html-foreground "Black" :html-background "Transparent" :html-scale 1.0
  1703. :matchers ("begin" "$" "$$" "\\(" "\\["))
  1704. "Options for creating images from LaTeX fragments.
  1705. This is a property list with the following properties:
  1706. :foreground the foreground color for images embedded in emacs, e.g. \"Black\".
  1707. `default' means use the forground of the default face.
  1708. :background the background color, or \"Transparent\".
  1709. `default' means use the background of the default face.
  1710. :scale a scaling factor for the size of the images
  1711. :html-foreground, :html-background, :html-scale
  1712. The same numbers for HTML export.
  1713. :matchers a list indicating which matchers should be used to
  1714. find LaTeX fragments. Valid members of this list are:
  1715. \"begin\" find environments
  1716. \"$\" find math expressions surrounded by $...$
  1717. \"$$\" find math expressions surrounded by $$....$$
  1718. \"\\(\" find math expressions surrounded by \\(...\\)
  1719. \"\\ [\" find math expressions surrounded by \\ [...\\]"
  1720. :group 'org-latex
  1721. :type 'plist)
  1722. (defcustom org-format-latex-header "\\documentclass{article}
  1723. \\usepackage{fullpage} % do not remove
  1724. \\usepackage{amssymb}
  1725. \\usepackage[usenames]{color}
  1726. \\usepackage{amsmath}
  1727. \\usepackage{latexsym}
  1728. \\usepackage[mathscr]{eucal}
  1729. \\pagestyle{empty} % do not remove"
  1730. "The document header used for processing LaTeX fragments."
  1731. :group 'org-latex
  1732. :type 'string)
  1733. (defgroup org-font-lock nil
  1734. "Font-lock settings for highlighting in Org-mode."
  1735. :tag "Org Font Lock"
  1736. :group 'org)
  1737. (defcustom org-level-color-stars-only nil
  1738. "Non-nil means fontify only the stars in each headline.
  1739. When nil, the entire headline is fontified.
  1740. Changing it requires restart of `font-lock-mode' to become effective
  1741. also in regions already fontified."
  1742. :group 'org-font-lock
  1743. :type 'boolean)
  1744. (defcustom org-hide-leading-stars nil
  1745. "Non-nil means, hide the first N-1 stars in a headline.
  1746. This works by using the face `org-hide' for these stars. This
  1747. face is white for a light background, and black for a dark
  1748. background. You may have to customize the face `org-hide' to
  1749. make this work.
  1750. Changing it requires restart of `font-lock-mode' to become effective
  1751. also in regions already fontified.
  1752. You may also set this on a per-file basis by adding one of the following
  1753. lines to the buffer:
  1754. #+STARTUP: hidestars
  1755. #+STARTUP: showstars"
  1756. :group 'org-font-lock
  1757. :type 'boolean)
  1758. (defcustom org-fontify-done-headline nil
  1759. "Non-nil means, change the face of a headline if it is marked DONE.
  1760. Normally, only the TODO/DONE keyword indicates the state of a headline.
  1761. When this is non-nil, the headline after the keyword is set to the
  1762. `org-headline-done' as an additional indication."
  1763. :group 'org-font-lock
  1764. :type 'boolean)
  1765. (defcustom org-fontify-emphasized-text t
  1766. "Non-nil means fontify *bold*, /italic/ and _underlined_ text.
  1767. Changing this variable requires a restart of Emacs to take effect."
  1768. :group 'org-font-lock
  1769. :type 'boolean)
  1770. (defcustom org-highlight-latex-fragments-and-specials nil
  1771. "Non-nil means, fontify what is treated specially by the exporters."
  1772. :group 'org-font-lock
  1773. :type 'boolean)
  1774. (defcustom org-hide-emphasis-markers nil
  1775. "Non-nil mean font-lock should hide the emphasis marker characters."
  1776. :group 'org-font-lock
  1777. :type 'boolean)
  1778. (defvar org-emph-re nil
  1779. "Regular expression for matching emphasis.")
  1780. (defvar org-verbatim-re nil
  1781. "Regular expression for matching verbatim text.")
  1782. (defvar org-emphasis-regexp-components) ; defined just below
  1783. (defvar org-emphasis-alist) ; defined just below
  1784. (defun org-set-emph-re (var val)
  1785. "Set variable and compute the emphasis regular expression."
  1786. (set var val)
  1787. (when (and (boundp 'org-emphasis-alist)
  1788. (boundp 'org-emphasis-regexp-components)
  1789. org-emphasis-alist org-emphasis-regexp-components)
  1790. (let* ((e org-emphasis-regexp-components)
  1791. (pre (car e))
  1792. (post (nth 1 e))
  1793. (border (nth 2 e))
  1794. (body (nth 3 e))
  1795. (nl (nth 4 e))
  1796. (stacked (and nil (nth 5 e))) ; stacked is no longer allowed, forced to nil
  1797. (body1 (concat body "*?"))
  1798. (markers (mapconcat 'car org-emphasis-alist ""))
  1799. (vmarkers (mapconcat
  1800. (lambda (x) (if (eq (nth 4 x) 'verbatim) (car x) ""))
  1801. org-emphasis-alist "")))
  1802. ;; make sure special characters appear at the right position in the class
  1803. (if (string-match "\\^" markers)
  1804. (setq markers (concat (replace-match "" t t markers) "^")))
  1805. (if (string-match "-" markers)
  1806. (setq markers (concat (replace-match "" t t markers) "-")))
  1807. (if (string-match "\\^" vmarkers)
  1808. (setq vmarkers (concat (replace-match "" t t vmarkers) "^")))
  1809. (if (string-match "-" vmarkers)
  1810. (setq vmarkers (concat (replace-match "" t t vmarkers) "-")))
  1811. (if (> nl 0)
  1812. (setq body1 (concat body1 "\\(?:\n" body "*?\\)\\{0,"
  1813. (int-to-string nl) "\\}")))
  1814. ;; Make the regexp
  1815. (setq org-emph-re
  1816. (concat "\\([" pre (if (and nil stacked) markers) "]\\|^\\)"
  1817. "\\("
  1818. "\\([" markers "]\\)"
  1819. "\\("
  1820. "[^" border "]\\|"
  1821. "[^" border (if (and nil stacked) markers) "]"
  1822. body1
  1823. "[^" border (if (and nil stacked) markers) "]"
  1824. "\\)"
  1825. "\\3\\)"
  1826. "\\([" post (if (and nil stacked) markers) "]\\|$\\)"))
  1827. (setq org-verbatim-re
  1828. (concat "\\([" pre "]\\|^\\)"
  1829. "\\("
  1830. "\\([" vmarkers "]\\)"
  1831. "\\("
  1832. "[^" border "]\\|"
  1833. "[^" border "]"
  1834. body1
  1835. "[^" border "]"
  1836. "\\)"
  1837. "\\3\\)"
  1838. "\\([" post "]\\|$\\)")))))
  1839. (defcustom org-emphasis-regexp-components
  1840. '(" \t('\"" "- \t.,:?;'\")" " \t\r\n,\"'" "." 1)
  1841. "Components used to build the regular expression for emphasis.
  1842. This is a list with 6 entries. Terminology: In an emphasis string
  1843. like \" *strong word* \", we call the initial space PREMATCH, the final
  1844. space POSTMATCH, the stars MARKERS, \"s\" and \"d\" are BORDER characters
  1845. and \"trong wor\" is the body. The different components in this variable
  1846. specify what is allowed/forbidden in each part:
  1847. pre Chars allowed as prematch. Beginning of line will be allowed too.
  1848. post Chars allowed as postmatch. End of line will be allowed too.
  1849. border The chars *forbidden* as border characters.
  1850. body-regexp A regexp like \".\" to match a body character. Don't use
  1851. non-shy groups here, and don't allow newline here.
  1852. newline The maximum number of newlines allowed in an emphasis exp.
  1853. Use customize to modify this, or restart Emacs after changing it."
  1854. :group 'org-font-lock
  1855. :set 'org-set-emph-re
  1856. :type '(list
  1857. (sexp :tag "Allowed chars in pre ")
  1858. (sexp :tag "Allowed chars in post ")
  1859. (sexp :tag "Forbidden chars in border ")
  1860. (sexp :tag "Regexp for body ")
  1861. (integer :tag "number of newlines allowed")
  1862. (option (boolean :tag "Stacking (DISABLED) "))))
  1863. (defcustom org-emphasis-alist
  1864. `(("*" bold "<b>" "</b>")
  1865. ("/" italic "<i>" "</i>")
  1866. ("_" underline "<u>" "</u>")
  1867. ("=" org-code "<code>" "</code>" verbatim)
  1868. ("~" org-verbatim "" "" verbatim)
  1869. ("+" ,(if (featurep 'xemacs) 'org-table '(:strike-through t))
  1870. "<del>" "</del>")
  1871. )
  1872. "Special syntax for emphasized text.
  1873. Text starting and ending with a special character will be emphasized, for
  1874. example *bold*, _underlined_ and /italic/. This variable sets the marker
  1875. characters, the face to be used by font-lock for highlighting in Org-mode
  1876. Emacs buffers, and the HTML tags to be used for this.
  1877. Use customize to modify this, or restart Emacs after changing it."
  1878. :group 'org-font-lock
  1879. :set 'org-set-emph-re
  1880. :type '(repeat
  1881. (list
  1882. (string :tag "Marker character")
  1883. (choice
  1884. (face :tag "Font-lock-face")
  1885. (plist :tag "Face property list"))
  1886. (string :tag "HTML start tag")
  1887. (string :tag "HTML end tag")
  1888. (option (const verbatim)))))
  1889. ;;; Miscellaneous options
  1890. (defgroup org-completion nil
  1891. "Completion in Org-mode."
  1892. :tag "Org Completion"
  1893. :group 'org)
  1894. (defcustom org-completion-fallback-command 'hippie-expand
  1895. "The expansion command called by \\[org-complete] in normal context.
  1896. Normal means, no org-mode-specific context."
  1897. :group 'org-completion
  1898. :type 'function)
  1899. ;;; Functions and variables from ther packages
  1900. ;; Declared here to avoid compiler warnings
  1901. ;; XEmacs only
  1902. (defvar outline-mode-menu-heading)
  1903. (defvar outline-mode-menu-show)
  1904. (defvar outline-mode-menu-hide)
  1905. (defvar zmacs-regions) ; XEmacs regions
  1906. ;; Emacs only
  1907. (defvar mark-active)
  1908. ;; Various packages
  1909. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  1910. (declare-function calendar-forward-day "cal-move" (arg))
  1911. (declare-function calendar-goto-date "cal-move" (date))
  1912. (declare-function calendar-goto-today "cal-move" ())
  1913. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  1914. (defvar calc-embedded-close-formula)
  1915. (defvar calc-embedded-open-formula)
  1916. (declare-function cdlatex-tab "ext:cdlatex" ())
  1917. (declare-function dired-get-filename "dired" (&optional localp no-error-if-not-filep))
  1918. (defvar font-lock-unfontify-region-function)
  1919. (declare-function iswitchb-mode "iswitchb" (&optional arg))
  1920. (declare-function iswitchb-read-buffer (prompt &optional default require-match start matches-set))
  1921. (defvar iswitchb-temp-buflist)
  1922. (declare-function org-gnus-follow-link "org-gnus" (&optional group article))
  1923. (declare-function org-agenda-skip "org-agenda" ())
  1924. (declare-function org-format-agenda-item "org-agenda"
  1925. (extra txt &optional category tags dotime noprefix remove-re))
  1926. (declare-function org-agenda-new-marker "org-agenda" (&optional pos))
  1927. (declare-function org-agenda-change-all-lines "org-agenda"
  1928. (newhead hdmarker &optional fixface))
  1929. (declare-function org-agenda-set-restriction-lock "org-agenda" (&optional type))
  1930. (declare-function org-agenda-maybe-redo "org-agenda" ())
  1931. (declare-function org-agenda-save-markers-for-cut-and-paste "org-agenda"
  1932. (beg end))
  1933. (declare-function parse-time-string "parse-time" (string))
  1934. (declare-function remember "remember" (&optional initial))
  1935. (declare-function remember-buffer-desc "remember" ())
  1936. (declare-function remember-finalize "remember" ())
  1937. (defvar remember-save-after-remembering)
  1938. (defvar remember-data-file)
  1939. (defvar remember-register)
  1940. (defvar remember-buffer)
  1941. (defvar remember-handler-functions)
  1942. (defvar remember-annotation-functions)
  1943. (defvar texmathp-why)
  1944. (declare-function speedbar-line-directory "speedbar" (&optional depth))
  1945. (declare-function table--at-cell-p "table" (position &optional object at-column))
  1946. (defvar w3m-current-url)
  1947. (defvar w3m-current-title)
  1948. (defvar org-latex-regexps)
  1949. ;;; Autoload and prepare some org modules
  1950. ;; Some table stuff that needs to be defined here, because it is used
  1951. ;; by the functions setting up org-mode or checking for table context.
  1952. (defconst org-table-any-line-regexp "^[ \t]*\\(|\\|\\+-[-+]\\)"
  1953. "Detects an org-type or table-type table.")
  1954. (defconst org-table-line-regexp "^[ \t]*|"
  1955. "Detects an org-type table line.")
  1956. (defconst org-table-dataline-regexp "^[ \t]*|[^-]"
  1957. "Detects an org-type table line.")
  1958. (defconst org-table-hline-regexp "^[ \t]*|-"
  1959. "Detects an org-type table hline.")
  1960. (defconst org-table1-hline-regexp "^[ \t]*\\+-[-+]"
  1961. "Detects a table-type table hline.")
  1962. (defconst org-table-any-border-regexp "^[ \t]*[^|+ \t]"
  1963. "Searching from within a table (any type) this finds the first line
  1964. outside the table.")
  1965. ;; Autoload the functions in org-table.el that are needed by functions here.
  1966. (eval-and-compile
  1967. (org-autoload "org-table"
  1968. '(org-table-align org-table-begin org-table-blank-field
  1969. org-table-convert org-table-convert-region org-table-copy-down
  1970. org-table-copy-region org-table-create
  1971. org-table-create-or-convert-from-region
  1972. org-table-create-with-table.el org-table-current-dline
  1973. org-table-cut-region org-table-delete-column org-table-edit-field
  1974. org-table-edit-formulas org-table-end org-table-eval-formula
  1975. org-table-export org-table-field-info
  1976. org-table-get-stored-formulas org-table-goto-column
  1977. org-table-hline-and-move org-table-import org-table-insert-column
  1978. org-table-insert-hline org-table-insert-row org-table-iterate
  1979. org-table-justify-field-maybe org-table-kill-row
  1980. org-table-maybe-eval-formula org-table-maybe-recalculate-line
  1981. org-table-move-column org-table-move-column-left
  1982. org-table-move-column-right org-table-move-row
  1983. org-table-move-row-down org-table-move-row-up
  1984. org-table-next-field org-table-next-row org-table-paste-rectangle
  1985. org-table-previous-field org-table-recalculate
  1986. org-table-rotate-recalc-marks org-table-sort-lines org-table-sum
  1987. org-table-toggle-coordinate-overlays
  1988. org-table-toggle-formula-debugger org-table-wrap-region
  1989. orgtbl-mode turn-on-orgtbl)))
  1990. (defun org-at-table-p (&optional table-type)
  1991. "Return t if the cursor is inside an org-type table.
  1992. If TABLE-TYPE is non-nil, also check for table.el-type tables."
  1993. (if org-enable-table-editor
  1994. (save-excursion
  1995. (beginning-of-line 1)
  1996. (looking-at (if table-type org-table-any-line-regexp
  1997. org-table-line-regexp)))
  1998. nil))
  1999. (defsubst org-table-p () (org-at-table-p))
  2000. (defun org-at-table.el-p ()
  2001. "Return t if and only if we are at a table.el table."
  2002. (and (org-at-table-p 'any)
  2003. (save-excursion
  2004. (goto-char (org-table-begin 'any))
  2005. (looking-at org-table1-hline-regexp))))
  2006. (defun org-table-recognize-table.el ()
  2007. "If there is a table.el table nearby, recognize it and move into it."
  2008. (if org-table-tab-recognizes-table.el
  2009. (if (org-at-table.el-p)
  2010. (progn
  2011. (beginning-of-line 1)
  2012. (if (looking-at org-table-dataline-regexp)
  2013. nil
  2014. (if (looking-at org-table1-hline-regexp)
  2015. (progn
  2016. (beginning-of-line 2)
  2017. (if (looking-at org-table-any-border-regexp)
  2018. (beginning-of-line -1)))))
  2019. (if (re-search-forward "|" (org-table-end t) t)
  2020. (progn
  2021. (require 'table)
  2022. (if (table--at-cell-p (point))
  2023. t
  2024. (message "recognizing table.el table...")
  2025. (table-recognize-table)
  2026. (message "recognizing table.el table...done")))
  2027. (error "This should not happen..."))
  2028. t)
  2029. nil)
  2030. nil))
  2031. (defun org-at-table-hline-p ()
  2032. "Return t if the cursor is inside a hline in a table."
  2033. (if org-enable-table-editor
  2034. (save-excursion
  2035. (beginning-of-line 1)
  2036. (looking-at org-table-hline-regexp))
  2037. nil))
  2038. (defvar org-table-clean-did-remove-column nil)
  2039. (defun org-table-map-tables (function)
  2040. "Apply FUNCTION to the start of all tables in the buffer."
  2041. (save-excursion
  2042. (save-restriction
  2043. (widen)
  2044. (goto-char (point-min))
  2045. (while (re-search-forward org-table-any-line-regexp nil t)
  2046. (message "Mapping tables: %d%%" (/ (* 100.0 (point)) (buffer-size)))
  2047. (beginning-of-line 1)
  2048. (if (looking-at org-table-line-regexp)
  2049. (save-excursion (funcall function)))
  2050. (re-search-forward org-table-any-border-regexp nil 1))))
  2051. (message "Mapping tables: done"))
  2052. ;; Declare and autoload functions from org-exp.el
  2053. (declare-function org-default-export-plist "org-exp")
  2054. (declare-function org-infile-export-plist "org-exp")
  2055. (declare-function org-get-current-options "org-exp")
  2056. (eval-and-compile
  2057. (org-autoload "org-exp"
  2058. '(org-export org-export-as-ascii org-export-visible
  2059. org-insert-export-options-template org-export-as-html-and-open
  2060. org-export-as-html-batch org-export-as-html-to-buffer
  2061. org-replace-region-by-html org-export-region-as-html
  2062. org-export-as-html org-export-icalendar-this-file
  2063. org-export-icalendar-all-agenda-files
  2064. org-export-icalendar-combine-agenda-files org-export-as-xoxo)))
  2065. ;; Declare and autoload functions from org-exp.el
  2066. (eval-and-compile
  2067. (org-autoload "org-exp"
  2068. '(org-agenda org-agenda-list org-search-view
  2069. org-todo-list org-tags-view org-agenda-list-stuck-projects
  2070. org-diary org-agenda-to-appt)))
  2071. ;; Autoload org-remember
  2072. (eval-and-compile
  2073. (org-autoload "org-remember"
  2074. '(org-remember-insinuate org-remember-annotation
  2075. org-remember-apply-template org-remember org-remember-handler)))
  2076. ;; Autoload org-clock.el
  2077. (declare-function org-clock-save-markers-for-cut-and-paste "org-clock"
  2078. (beg end))
  2079. (defvar org-clock-marker (make-marker)
  2080. "Marker recording the last clock-in.")
  2081. (eval-and-compile
  2082. (org-autoload
  2083. "org-clock"
  2084. '(org-clock-in org-clock-out org-clock-cancel
  2085. org-clock-goto org-clock-sum org-clock-display
  2086. org-remove-clock-overlays org-clock-report
  2087. org-clocktable-shift org-dblock-write:clocktable
  2088. org-get-clocktable)))
  2089. (defun org-clock-update-time-maybe ()
  2090. "If this is a CLOCK line, update it and return t.
  2091. Otherwise, return nil."
  2092. (interactive)
  2093. (save-excursion
  2094. (beginning-of-line 1)
  2095. (skip-chars-forward " \t")
  2096. (when (looking-at org-clock-string)
  2097. (let ((re (concat "[ \t]*" org-clock-string
  2098. " *[[<]\\([^]>]+\\)[]>]-+[[<]\\([^]>]+\\)[]>]"
  2099. "\\([ \t]*=>.*\\)?"))
  2100. ts te h m s)
  2101. (if (not (looking-at re))
  2102. nil
  2103. (and (match-end 3) (delete-region (match-beginning 3) (match-end 3)))
  2104. (end-of-line 1)
  2105. (setq ts (match-string 1)
  2106. te (match-string 2))
  2107. (setq s (- (time-to-seconds
  2108. (apply 'encode-time (org-parse-time-string te)))
  2109. (time-to-seconds
  2110. (apply 'encode-time (org-parse-time-string ts))))
  2111. h (floor (/ s 3600))
  2112. s (- s (* 3600 h))
  2113. m (floor (/ s 60))
  2114. s (- s (* 60 s)))
  2115. (insert " => " (format "%2d:%02d" h m))
  2116. t)))))
  2117. (defun org-check-running-clock ()
  2118. "Check if the current buffer contains the running clock.
  2119. If yes, offer to stop it and to save the buffer with the changes."
  2120. (when (and (equal (marker-buffer org-clock-marker) (current-buffer))
  2121. (y-or-n-p (format "Clock-out in buffer %s before killing it? "
  2122. (buffer-name))))
  2123. (org-clock-out)
  2124. (when (y-or-n-p "Save changed buffer?")
  2125. (save-buffer))))
  2126. (defun org-clocktable-try-shift (dir n)
  2127. "Check if this line starts a clock table, if yes, shift the time block."
  2128. (when (org-match-line "#\\+BEGIN: clocktable\\>")
  2129. (org-clocktable-shift dir n)))
  2130. ;; Autoload archiving code
  2131. ;; The stuff that is needed for cycling and tags has to be defined here.
  2132. (defgroup org-archive nil
  2133. "Options concerning archiving in Org-mode."
  2134. :tag "Org Archive"
  2135. :group 'org-structure)
  2136. (defcustom org-archive-location "%s_archive::"
  2137. "The location where subtrees should be archived.
  2138. Otherwise, the value of this variable is a string, consisting of two
  2139. parts, separated by a double-colon.
  2140. The first part is a file name - when omitted, archiving happens in the same
  2141. file. %s will be replaced by the current file name (without directory part).
  2142. Archiving to a different file is useful to keep archived entries from
  2143. contributing to the Org-mode Agenda.
  2144. The part after the double colon is a headline. The archived entries will be
  2145. filed under that headline. When omitted, the subtrees are simply filed away
  2146. at the end of the file, as top-level entries.
  2147. Here are a few examples:
  2148. \"%s_archive::\"
  2149. If the current file is Projects.org, archive in file
  2150. Projects.org_archive, as top-level trees. This is the default.
  2151. \"::* Archived Tasks\"
  2152. Archive in the current file, under the top-level headline
  2153. \"* Archived Tasks\".
  2154. \"~/org/archive.org::\"
  2155. Archive in file ~/org/archive.org (absolute path), as top-level trees.
  2156. \"basement::** Finished Tasks\"
  2157. Archive in file ./basement (relative path), as level 3 trees
  2158. below the level 2 heading \"** Finished Tasks\".
  2159. You may set this option on a per-file basis by adding to the buffer a
  2160. line like
  2161. #+ARCHIVE: basement::** Finished Tasks
  2162. You may also define it locally for a subtree by setting an ARCHIVE property
  2163. in the entry. If such a property is found in an entry, or anywhere up
  2164. the hierarchy, it will be used."
  2165. :group 'org-archive
  2166. :type 'string)
  2167. (defcustom org-archive-tag "ARCHIVE"
  2168. "The tag that marks a subtree as archived.
  2169. An archived subtree does not open during visibility cycling, and does
  2170. not contribute to the agenda listings.
  2171. After changing this, font-lock must be restarted in the relevant buffers to
  2172. get the proper fontification."
  2173. :group 'org-archive
  2174. :group 'org-keywords
  2175. :type 'string)
  2176. (defcustom org-agenda-skip-archived-trees t
  2177. "Non-nil means, the agenda will skip any items located in archived trees.
  2178. An archived tree is a tree marked with the tag ARCHIVE."
  2179. :group 'org-archive
  2180. :group 'org-agenda-skip
  2181. :type 'boolean)
  2182. (defcustom org-cycle-open-archived-trees nil
  2183. "Non-nil means, `org-cycle' will open archived trees.
  2184. An archived tree is a tree marked with the tag ARCHIVE.
  2185. When nil, archived trees will stay folded. You can still open them with
  2186. normal outline commands like `show-all', but not with the cycling commands."
  2187. :group 'org-archive
  2188. :group 'org-cycle
  2189. :type 'boolean)
  2190. (defcustom org-sparse-tree-open-archived-trees nil
  2191. "Non-nil means sparse tree construction shows matches in archived trees.
  2192. When nil, matches in these trees are highlighted, but the trees are kept in
  2193. collapsed state."
  2194. :group 'org-archive
  2195. :group 'org-sparse-trees
  2196. :type 'boolean)
  2197. (defun org-cycle-hide-archived-subtrees (state)
  2198. "Re-hide all archived subtrees after a visibility state change."
  2199. (when (and (not org-cycle-open-archived-trees)
  2200. (not (memq state '(overview folded))))
  2201. (save-excursion
  2202. (let* ((globalp (memq state '(contents all)))
  2203. (beg (if globalp (point-min) (point)))
  2204. (end (if globalp (point-max) (org-end-of-subtree t))))
  2205. (org-hide-archived-subtrees beg end)
  2206. (goto-char beg)
  2207. (if (looking-at (concat ".*:" org-archive-tag ":"))
  2208. (message "%s" (substitute-command-keys
  2209. "Subtree is archived and stays closed. Use \\[org-force-cycle-archived] to cycle it anyway.")))))))
  2210. (defun org-force-cycle-archived ()
  2211. "Cycle subtree even if it is archived."
  2212. (interactive)
  2213. (setq this-command 'org-cycle)
  2214. (let ((org-cycle-open-archived-trees t))
  2215. (call-interactively 'org-cycle)))
  2216. (defun org-hide-archived-subtrees (beg end)
  2217. "Re-hide all archived subtrees after a visibility state change."
  2218. (save-excursion
  2219. (let* ((re (concat ":" org-archive-tag ":")))
  2220. (goto-char beg)
  2221. (while (re-search-forward re end t)
  2222. (and (org-on-heading-p) (hide-subtree))
  2223. (org-end-of-subtree t)))))
  2224. (defalias 'org-advertized-archive-subtree 'org-archive-subtree)
  2225. (eval-and-compile
  2226. (org-autoload "org-archive"
  2227. '(org-add-archive-files org-archive-subtree
  2228. org-archive-to-archive-sibling org-toggle-archive-tag)))
  2229. ;; Autoload Column View Code
  2230. (declare-function org-columns-number-to-string "org-colview")
  2231. (declare-function org-columns-get-format-and-top-level "org-colview")
  2232. (declare-function org-columns-compute "org-colview")
  2233. (org-autoload (if (featurep 'xemacs) "org-colview-xemacs" "org-colview")
  2234. '(org-columns-number-to-string org-columns-get-format-and-top-level
  2235. org-columns-compute org-agenda-columns org-columns-remove-overlays
  2236. org-columns org-insert-columns-dblock))
  2237. ;;; Variables for pre-computed regular expressions, all buffer local
  2238. (defvar org-drawer-regexp nil
  2239. "Matches first line of a hidden block.")
  2240. (make-variable-buffer-local 'org-drawer-regexp)
  2241. (defvar org-todo-regexp nil
  2242. "Matches any of the TODO state keywords.")
  2243. (make-variable-buffer-local 'org-todo-regexp)
  2244. (defvar org-not-done-regexp nil
  2245. "Matches any of the TODO state keywords except the last one.")
  2246. (make-variable-buffer-local 'org-not-done-regexp)
  2247. (defvar org-todo-line-regexp nil
  2248. "Matches a headline and puts TODO state into group 2 if present.")
  2249. (make-variable-buffer-local 'org-todo-line-regexp)
  2250. (defvar org-complex-heading-regexp nil
  2251. "Matches a headline and puts everything into groups:
  2252. group 1: the stars
  2253. group 2: The todo keyword, maybe
  2254. group 3: Priority cookie
  2255. group 4: True headline
  2256. group 5: Tags")
  2257. (make-variable-buffer-local 'org-complex-heading-regexp)
  2258. (defvar org-todo-line-tags-regexp nil
  2259. "Matches a headline and puts TODO state into group 2 if present.
  2260. Also put tags into group 4 if tags are present.")
  2261. (make-variable-buffer-local 'org-todo-line-tags-regexp)
  2262. (defvar org-nl-done-regexp nil
  2263. "Matches newline followed by a headline with the DONE keyword.")
  2264. (make-variable-buffer-local 'org-nl-done-regexp)
  2265. (defvar org-looking-at-done-regexp nil
  2266. "Matches the DONE keyword a point.")
  2267. (make-variable-buffer-local 'org-looking-at-done-regexp)
  2268. (defvar org-ds-keyword-length 12
  2269. "Maximum length of the Deadline and SCHEDULED keywords.")
  2270. (make-variable-buffer-local 'org-ds-keyword-length)
  2271. (defvar org-deadline-regexp nil
  2272. "Matches the DEADLINE keyword.")
  2273. (make-variable-buffer-local 'org-deadline-regexp)
  2274. (defvar org-deadline-time-regexp nil
  2275. "Matches the DEADLINE keyword together with a time stamp.")
  2276. (make-variable-buffer-local 'org-deadline-time-regexp)
  2277. (defvar org-deadline-line-regexp nil
  2278. "Matches the DEADLINE keyword and the rest of the line.")
  2279. (make-variable-buffer-local 'org-deadline-line-regexp)
  2280. (defvar org-scheduled-regexp nil
  2281. "Matches the SCHEDULED keyword.")
  2282. (make-variable-buffer-local 'org-scheduled-regexp)
  2283. (defvar org-scheduled-time-regexp nil
  2284. "Matches the SCHEDULED keyword together with a time stamp.")
  2285. (make-variable-buffer-local 'org-scheduled-time-regexp)
  2286. (defvar org-closed-time-regexp nil
  2287. "Matches the CLOSED keyword together with a time stamp.")
  2288. (make-variable-buffer-local 'org-closed-time-regexp)
  2289. (defvar org-keyword-time-regexp nil
  2290. "Matches any of the 4 keywords, together with the time stamp.")
  2291. (make-variable-buffer-local 'org-keyword-time-regexp)
  2292. (defvar org-keyword-time-not-clock-regexp nil
  2293. "Matches any of the 3 keywords, together with the time stamp.")
  2294. (make-variable-buffer-local 'org-keyword-time-not-clock-regexp)
  2295. (defvar org-maybe-keyword-time-regexp nil
  2296. "Matches a timestamp, possibly preceeded by a keyword.")
  2297. (make-variable-buffer-local 'org-maybe-keyword-time-regexp)
  2298. (defvar org-planning-or-clock-line-re nil
  2299. "Matches a line with planning or clock info.")
  2300. (make-variable-buffer-local 'org-planning-or-clock-line-re)
  2301. (defconst org-plain-time-of-day-regexp
  2302. (concat
  2303. "\\(\\<[012]?[0-9]"
  2304. "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
  2305. "\\(--?"
  2306. "\\(\\<[012]?[0-9]"
  2307. "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
  2308. "\\)?")
  2309. "Regular expression to match a plain time or time range.
  2310. Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
  2311. groups carry important information:
  2312. 0 the full match
  2313. 1 the first time, range or not
  2314. 8 the second time, if it is a range.")
  2315. (defconst org-plain-time-extension-regexp
  2316. (concat
  2317. "\\(\\<[012]?[0-9]"
  2318. "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
  2319. "\\+\\([0-9]+\\)\\(:\\([0-5][0-9]\\)\\)?")
  2320. "Regular expression to match a time range like 13:30+2:10 = 13:30-15:40.
  2321. Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
  2322. groups carry important information:
  2323. 0 the full match
  2324. 7 hours of duration
  2325. 9 minutes of duration")
  2326. (defconst org-stamp-time-of-day-regexp
  2327. (concat
  2328. "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} +\\sw+ +\\)"
  2329. "\\([012][0-9]:[0-5][0-9]\\(-\\([012][0-9]:[0-5][0-9]\\)\\)?[^\n\r>]*?\\)>"
  2330. "\\(--?"
  2331. "<\\1\\([012][0-9]:[0-5][0-9]\\)>\\)?")
  2332. "Regular expression to match a timestamp time or time range.
  2333. After a match, the following groups carry important information:
  2334. 0 the full match
  2335. 1 date plus weekday, for backreferencing to make sure both times on same day
  2336. 2 the first time, range or not
  2337. 4 the second time, if it is a range.")
  2338. (defconst org-startup-options
  2339. '(("fold" org-startup-folded t)
  2340. ("overview" org-startup-folded t)
  2341. ("nofold" org-startup-folded nil)
  2342. ("showall" org-startup-folded nil)
  2343. ("content" org-startup-folded content)
  2344. ("hidestars" org-hide-leading-stars t)
  2345. ("showstars" org-hide-leading-stars nil)
  2346. ("odd" org-odd-levels-only t)
  2347. ("oddeven" org-odd-levels-only nil)
  2348. ("align" org-startup-align-all-tables t)
  2349. ("noalign" org-startup-align-all-tables nil)
  2350. ("customtime" org-display-custom-times t)
  2351. ("logdone" org-log-done time)
  2352. ("lognotedone" org-log-done note)
  2353. ("nologdone" org-log-done nil)
  2354. ("lognoteclock-out" org-log-note-clock-out t)
  2355. ("nolognoteclock-out" org-log-note-clock-out nil)
  2356. ("logrepeat" org-log-repeat state)
  2357. ("lognoterepeat" org-log-repeat note)
  2358. ("nologrepeat" org-log-repeat nil)
  2359. ("constcgs" constants-unit-system cgs)
  2360. ("constSI" constants-unit-system SI))
  2361. "Variable associated with STARTUP options for org-mode.
  2362. Each element is a list of three items: The startup options as written
  2363. in the #+STARTUP line, the corresponding variable, and the value to
  2364. set this variable to if the option is found. An optional forth element PUSH
  2365. means to push this value onto the list in the variable.")
  2366. (defun org-set-regexps-and-options ()
  2367. "Precompute regular expressions for current buffer."
  2368. (when (org-mode-p)
  2369. (org-set-local 'org-todo-kwd-alist nil)
  2370. (org-set-local 'org-todo-key-alist nil)
  2371. (org-set-local 'org-todo-key-trigger nil)
  2372. (org-set-local 'org-todo-keywords-1 nil)
  2373. (org-set-local 'org-done-keywords nil)
  2374. (org-set-local 'org-todo-heads nil)
  2375. (org-set-local 'org-todo-sets nil)
  2376. (org-set-local 'org-todo-log-states nil)
  2377. (let ((re (org-make-options-regexp
  2378. '("CATEGORY" "SEQ_TODO" "TYP_TODO" "TODO" "COLUMNS"
  2379. "STARTUP" "ARCHIVE" "TAGS" "LINK" "PRIORITIES"
  2380. "CONSTANTS" "PROPERTY" "DRAWERS" "SETUPFILE")))
  2381. (splitre "[ \t]+")
  2382. kwds kws0 kwsa key log value cat arch tags const links hw dws
  2383. tail sep kws1 prio props drawers
  2384. ext-setup-or-nil setup-contents (start 0))
  2385. (save-excursion
  2386. (save-restriction
  2387. (widen)
  2388. (goto-char (point-min))
  2389. (while (or (and ext-setup-or-nil
  2390. (string-match re ext-setup-or-nil start)
  2391. (setq start (match-end 0)))
  2392. (and (setq ext-setup-or-nil nil start 0)
  2393. (re-search-forward re nil t)))
  2394. (setq key (upcase (match-string 1 ext-setup-or-nil))
  2395. value (org-match-string-no-properties 2 ext-setup-or-nil))
  2396. (cond
  2397. ((equal key "CATEGORY")
  2398. (if (string-match "[ \t]+$" value)
  2399. (setq value (replace-match "" t t value)))
  2400. (setq cat value))
  2401. ((member key '("SEQ_TODO" "TODO"))
  2402. (push (cons 'sequence (org-split-string value splitre)) kwds))
  2403. ((equal key "TYP_TODO")
  2404. (push (cons 'type (org-split-string value splitre)) kwds))
  2405. ((equal key "TAGS")
  2406. (setq tags (append tags (org-split-string value splitre))))
  2407. ((equal key "COLUMNS")
  2408. (org-set-local 'org-columns-default-format value))
  2409. ((equal key "LINK")
  2410. (when (string-match "^\\(\\S-+\\)[ \t]+\\(.+\\)" value)
  2411. (push (cons (match-string 1 value)
  2412. (org-trim (match-string 2 value)))
  2413. links)))
  2414. ((equal key "PRIORITIES")
  2415. (setq prio (org-split-string value " +")))
  2416. ((equal key "PROPERTY")
  2417. (when (string-match "\\(\\S-+\\)\\s-+\\(.*\\)" value)
  2418. (push (cons (match-string 1 value) (match-string 2 value))
  2419. props)))
  2420. ((equal key "DRAWERS")
  2421. (setq drawers (org-split-string value splitre)))
  2422. ((equal key "CONSTANTS")
  2423. (setq const (append const (org-split-string value splitre))))
  2424. ((equal key "STARTUP")
  2425. (let ((opts (org-split-string value splitre))
  2426. l var val)
  2427. (while (setq l (pop opts))
  2428. (when (setq l (assoc l org-startup-options))
  2429. (setq var (nth 1 l) val (nth 2 l))
  2430. (if (not (nth 3 l))
  2431. (set (make-local-variable var) val)
  2432. (if (not (listp (symbol-value var)))
  2433. (set (make-local-variable var) nil))
  2434. (set (make-local-variable var) (symbol-value var))
  2435. (add-to-list var val))))))
  2436. ((equal key "ARCHIVE")
  2437. (string-match " *$" value)
  2438. (setq arch (replace-match "" t t value))
  2439. (remove-text-properties 0 (length arch)
  2440. '(face t fontified t) arch))
  2441. ((equal key "SETUPFILE")
  2442. (setq setup-contents (org-file-contents
  2443. (expand-file-name
  2444. (org-remove-double-quotes value))
  2445. 'noerror))
  2446. (if (not ext-setup-or-nil)
  2447. (setq ext-setup-or-nil setup-contents start 0)
  2448. (setq ext-setup-or-nil
  2449. (concat (substring ext-setup-or-nil 0 start)
  2450. "\n" setup-contents "\n"
  2451. (substring ext-setup-or-nil start)))))
  2452. ))))
  2453. (when cat
  2454. (org-set-local 'org-category (intern cat))
  2455. (push (cons "CATEGORY" cat) props))
  2456. (when prio
  2457. (if (< (length prio) 3) (setq prio '("A" "C" "B")))
  2458. (setq prio (mapcar 'string-to-char prio))
  2459. (org-set-local 'org-highest-priority (nth 0 prio))
  2460. (org-set-local 'org-lowest-priority (nth 1 prio))
  2461. (org-set-local 'org-default-priority (nth 2 prio)))
  2462. (and props (org-set-local 'org-local-properties (nreverse props)))
  2463. (and drawers (org-set-local 'org-drawers drawers))
  2464. (and arch (org-set-local 'org-archive-location arch))
  2465. (and links (setq org-link-abbrev-alist-local (nreverse links)))
  2466. ;; Process the TODO keywords
  2467. (unless kwds
  2468. ;; Use the global values as if they had been given locally.
  2469. (setq kwds (default-value 'org-todo-keywords))
  2470. (if (stringp (car kwds))
  2471. (setq kwds (list (cons org-todo-interpretation
  2472. (default-value 'org-todo-keywords)))))
  2473. (setq kwds (reverse kwds)))
  2474. (setq kwds (nreverse kwds))
  2475. (let (inter kws kw)
  2476. (while (setq kws (pop kwds))
  2477. (setq inter (pop kws) sep (member "|" kws)
  2478. kws0 (delete "|" (copy-sequence kws))
  2479. kwsa nil
  2480. kws1 (mapcar
  2481. (lambda (x)
  2482. ;; 1 2
  2483. (if (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?.*?)\\)?$" x)
  2484. (progn
  2485. (setq kw (match-string 1 x)
  2486. key (and (match-end 2) (match-string 2 x))
  2487. log (org-extract-log-state-settings x))
  2488. (push (cons kw (and key (string-to-char key))) kwsa)
  2489. (and log (push log org-todo-log-states))
  2490. kw)
  2491. (error "Invalid TODO keyword %s" x)))
  2492. kws0)
  2493. kwsa (if kwsa (append '((:startgroup))
  2494. (nreverse kwsa)
  2495. '((:endgroup))))
  2496. hw (car kws1)
  2497. dws (if sep (org-remove-keyword-keys (cdr sep)) (last kws1))
  2498. tail (list inter hw (car dws) (org-last dws)))
  2499. (add-to-list 'org-todo-heads hw 'append)
  2500. (push kws1 org-todo-sets)
  2501. (setq org-done-keywords (append org-done-keywords dws nil))
  2502. (setq org-todo-key-alist (append org-todo-key-alist kwsa))
  2503. (mapc (lambda (x) (push (cons x tail) org-todo-kwd-alist)) kws1)
  2504. (setq org-todo-keywords-1 (append org-todo-keywords-1 kws1 nil)))
  2505. (setq org-todo-sets (nreverse org-todo-sets)
  2506. org-todo-kwd-alist (nreverse org-todo-kwd-alist)
  2507. org-todo-key-trigger (delq nil (mapcar 'cdr org-todo-key-alist))
  2508. org-todo-key-alist (org-assign-fast-keys org-todo-key-alist)))
  2509. ;; Process the constants
  2510. (when const
  2511. (let (e cst)
  2512. (while (setq e (pop const))
  2513. (if (string-match "^\\([a-zA-Z0][_a-zA-Z0-9]*\\)=\\(.*\\)" e)
  2514. (push (cons (match-string 1 e) (match-string 2 e)) cst)))
  2515. (setq org-table-formula-constants-local cst)))
  2516. ;; Process the tags.
  2517. (when tags
  2518. (let (e tgs)
  2519. (while (setq e (pop tags))
  2520. (cond
  2521. ((equal e "{") (push '(:startgroup) tgs))
  2522. ((equal e "}") (push '(:endgroup) tgs))
  2523. ((string-match (org-re "^\\([[:alnum:]_@]+\\)(\\(.\\))$") e)
  2524. (push (cons (match-string 1 e)
  2525. (string-to-char (match-string 2 e)))
  2526. tgs))
  2527. (t (push (list e) tgs))))
  2528. (org-set-local 'org-tag-alist nil)
  2529. (while (setq e (pop tgs))
  2530. (or (and (stringp (car e))
  2531. (assoc (car e) org-tag-alist))
  2532. (push e org-tag-alist))))))
  2533. ;; Compute the regular expressions and other local variables
  2534. (if (not org-done-keywords)
  2535. (setq org-done-keywords (list (org-last org-todo-keywords-1))))
  2536. (setq org-ds-keyword-length (+ 2 (max (length org-deadline-string)
  2537. (length org-scheduled-string)
  2538. (length org-clock-string)
  2539. (length org-closed-string)))
  2540. org-drawer-regexp
  2541. (concat "^[ \t]*:\\("
  2542. (mapconcat 'regexp-quote org-drawers "\\|")
  2543. "\\):[ \t]*$")
  2544. org-not-done-keywords
  2545. (org-delete-all org-done-keywords (copy-sequence org-todo-keywords-1))
  2546. org-todo-regexp
  2547. (concat "\\<\\(" (mapconcat 'regexp-quote org-todo-keywords-1
  2548. "\\|") "\\)\\>")
  2549. org-not-done-regexp
  2550. (concat "\\<\\("
  2551. (mapconcat 'regexp-quote org-not-done-keywords "\\|")
  2552. "\\)\\>")
  2553. org-todo-line-regexp
  2554. (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
  2555. (mapconcat 'regexp-quote org-todo-keywords-1 "\\|")
  2556. "\\)\\>\\)?[ \t]*\\(.*\\)")
  2557. org-complex-heading-regexp
  2558. (concat "^\\(\\*+\\)\\(?:[ \t]+\\("
  2559. (mapconcat 'regexp-quote org-todo-keywords-1 "\\|")
  2560. "\\)\\>\\)?\\(?:[ \t]*\\(\\[#.\\]\\)\\)?[ \t]*\\(.*?\\)"
  2561. "\\(?:[ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
  2562. org-nl-done-regexp
  2563. (concat "\n\\*+[ \t]+"
  2564. "\\(?:" (mapconcat 'regexp-quote org-done-keywords "\\|")
  2565. "\\)" "\\>")
  2566. org-todo-line-tags-regexp
  2567. (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
  2568. (mapconcat 'regexp-quote org-todo-keywords-1 "\\|")
  2569. (org-re
  2570. "\\)\\>\\)? *\\(.*?\\([ \t]:[[:alnum:]:_@]+:[ \t]*\\)?$\\)"))
  2571. org-looking-at-done-regexp
  2572. (concat "^" "\\(?:"
  2573. (mapconcat 'regexp-quote org-done-keywords "\\|") "\\)"
  2574. "\\>")
  2575. org-deadline-regexp (concat "\\<" org-deadline-string)
  2576. org-deadline-time-regexp
  2577. (concat "\\<" org-deadline-string " *<\\([^>]+\\)>")
  2578. org-deadline-line-regexp
  2579. (concat "\\<\\(" org-deadline-string "\\).*")
  2580. org-scheduled-regexp
  2581. (concat "\\<" org-scheduled-string)
  2582. org-scheduled-time-regexp
  2583. (concat "\\<" org-scheduled-string " *<\\([^>]+\\)>")
  2584. org-closed-time-regexp
  2585. (concat "\\<" org-closed-string " *\\[\\([^]]+\\)\\]")
  2586. org-keyword-time-regexp
  2587. (concat "\\<\\(" org-scheduled-string
  2588. "\\|" org-deadline-string
  2589. "\\|" org-closed-string
  2590. "\\|" org-clock-string "\\)"
  2591. " *[[<]\\([^]>]+\\)[]>]")
  2592. org-keyword-time-not-clock-regexp
  2593. (concat "\\<\\(" org-scheduled-string
  2594. "\\|" org-deadline-string
  2595. "\\|" org-closed-string
  2596. "\\)"
  2597. " *[[<]\\([^]>]+\\)[]>]")
  2598. org-maybe-keyword-time-regexp
  2599. (concat "\\(\\<\\(" org-scheduled-string
  2600. "\\|" org-deadline-string
  2601. "\\|" org-closed-string
  2602. "\\|" org-clock-string "\\)\\)?"
  2603. " *\\([[<][0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^]\r\n>]*?[]>]\\|<%%([^\r\n>]*>\\)")
  2604. org-planning-or-clock-line-re
  2605. (concat "\\(?:^[ \t]*\\(" org-scheduled-string
  2606. "\\|" org-deadline-string
  2607. "\\|" org-closed-string "\\|" org-clock-string
  2608. "\\)\\>\\)")
  2609. )
  2610. (org-compute-latex-and-specials-regexp)
  2611. (org-set-font-lock-defaults)))
  2612. (defun org-file-contents (file &optional noerror)
  2613. "Return the contents of FILE, as a string."
  2614. (if (or (not file)
  2615. (not (file-readable-p file)))
  2616. (if noerror
  2617. (progn
  2618. (message "Cannot read file %s" file)
  2619. (ding) (sit-for 2)
  2620. "")
  2621. (error "Cannot read file %s" file))
  2622. (with-temp-buffer
  2623. (insert-file-contents file)
  2624. (buffer-string))))
  2625. (defun org-extract-log-state-settings (x)
  2626. "Extract the log state setting from a TODO keyword string.
  2627. This will extract info from a string like \"WAIT(w@/!)\"."
  2628. (let (kw key log1 log2)
  2629. (when (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?\\([!@]\\)?\\(?:/\\([!@]\\)\\)?)\\)?$" x)
  2630. (setq kw (match-string 1 x)
  2631. key (and (match-end 2) (match-string 2 x))
  2632. log1 (and (match-end 3) (match-string 3 x))
  2633. log2 (and (match-end 4) (match-string 4 x)))
  2634. (and (or log1 log2)
  2635. (list kw
  2636. (and log1 (if (equal log1 "!") 'time 'note))
  2637. (and log2 (if (equal log2 "!") 'time 'note)))))))
  2638. (defun org-remove-keyword-keys (list)
  2639. "Remove a pair of parenthesis at the end of each string in LIST."
  2640. (mapcar (lambda (x)
  2641. (if (string-match "(.*)$" x)
  2642. (substring x 0 (match-beginning 0))
  2643. x))
  2644. list))
  2645. ;; FIXME: this could be done much better, using second characters etc.
  2646. (defun org-assign-fast-keys (alist)
  2647. "Assign fast keys to a keyword-key alist.
  2648. Respect keys that are already there."
  2649. (let (new e k c c1 c2 (char ?a))
  2650. (while (setq e (pop alist))
  2651. (cond
  2652. ((equal e '(:startgroup)) (push e new))
  2653. ((equal e '(:endgroup)) (push e new))
  2654. (t
  2655. (setq k (car e) c2 nil)
  2656. (if (cdr e)
  2657. (setq c (cdr e))
  2658. ;; automatically assign a character.
  2659. (setq c1 (string-to-char
  2660. (downcase (substring
  2661. k (if (= (string-to-char k) ?@) 1 0)))))
  2662. (if (or (rassoc c1 new) (rassoc c1 alist))
  2663. (while (or (rassoc char new) (rassoc char alist))
  2664. (setq char (1+ char)))
  2665. (setq c2 c1))
  2666. (setq c (or c2 char)))
  2667. (push (cons k c) new))))
  2668. (nreverse new)))
  2669. ;;; Some variables used in various places
  2670. (defvar org-window-configuration nil
  2671. "Used in various places to store a window configuration.")
  2672. (defvar org-finish-function nil
  2673. "Function to be called when `C-c C-c' is used.
  2674. This is for getting out of special buffers like remember.")
  2675. ;; FIXME: Occasionally check by commenting these, to make sure
  2676. ;; no other functions uses these, forgetting to let-bind them.
  2677. (defvar entry)
  2678. (defvar state)
  2679. (defvar last-state)
  2680. (defvar date)
  2681. (defvar description)
  2682. ;; Defined somewhere in this file, but used before definition.
  2683. (defvar org-html-entities)
  2684. (defvar org-struct-menu)
  2685. (defvar org-org-menu)
  2686. (defvar org-tbl-menu)
  2687. (defvar org-agenda-keymap)
  2688. ;;;; Define the Org-mode
  2689. (if (and (not (keymapp outline-mode-map)) (featurep 'allout))
  2690. (error "Conflict with outdated version of allout.el. Load org.el before allout.el, or ugrade to newer allout, for example by switching to Emacs 22."))
  2691. ;; We use a before-change function to check if a table might need
  2692. ;; an update.
  2693. (defvar org-table-may-need-update t
  2694. "Indicates that a table might need an update.
  2695. This variable is set by `org-before-change-function'.
  2696. `org-table-align' sets it back to nil.")
  2697. (defun org-before-change-function (beg end)
  2698. "Every change indicates that a table might need an update."
  2699. (setq org-table-may-need-update t))
  2700. (defvar org-mode-map)
  2701. (defvar org-mode-hook nil)
  2702. (defvar org-inhibit-startup nil) ; Dynamically-scoped param.
  2703. (defvar org-agenda-keep-modes nil) ; Dynamically-scoped param.
  2704. (defvar org-table-buffer-is-an nil)
  2705. (defconst org-outline-regexp "\\*+ ")
  2706. ;;;###autoload
  2707. (define-derived-mode org-mode outline-mode "Org"
  2708. "Outline-based notes management and organizer, alias
  2709. \"Carsten's outline-mode for keeping track of everything.\"
  2710. Org-mode develops organizational tasks around a NOTES file which
  2711. contains information about projects as plain text. Org-mode is
  2712. implemented on top of outline-mode, which is ideal to keep the content
  2713. of large files well structured. It supports ToDo items, deadlines and
  2714. time stamps, which magically appear in the diary listing of the Emacs
  2715. calendar. Tables are easily created with a built-in table editor.
  2716. Plain text URL-like links connect to websites, emails (VM), Usenet
  2717. messages (Gnus), BBDB entries, and any files related to the project.
  2718. For printing and sharing of notes, an Org-mode file (or a part of it)
  2719. can be exported as a structured ASCII or HTML file.
  2720. The following commands are available:
  2721. \\{org-mode-map}"
  2722. ;; Get rid of Outline menus, they are not needed
  2723. ;; Need to do this here because define-derived-mode sets up
  2724. ;; the keymap so late. Still, it is a waste to call this each time
  2725. ;; we switch another buffer into org-mode.
  2726. (if (featurep 'xemacs)
  2727. (when (boundp 'outline-mode-menu-heading)
  2728. ;; Assume this is Greg's port, it used easymenu
  2729. (easy-menu-remove outline-mode-menu-heading)
  2730. (easy-menu-remove outline-mode-menu-show)
  2731. (easy-menu-remove outline-mode-menu-hide))
  2732. (define-key org-mode-map [menu-bar headings] 'undefined)
  2733. (define-key org-mode-map [menu-bar hide] 'undefined)
  2734. (define-key org-mode-map [menu-bar show] 'undefined))
  2735. (org-load-modules-maybe)
  2736. (easy-menu-add org-org-menu)
  2737. (easy-menu-add org-tbl-menu)
  2738. (org-install-agenda-files-menu)
  2739. (if org-descriptive-links (org-add-to-invisibility-spec '(org-link)))
  2740. (org-add-to-invisibility-spec '(org-cwidth))
  2741. (when (featurep 'xemacs)
  2742. (org-set-local 'line-move-ignore-invisible t))
  2743. (org-set-local 'outline-regexp org-outline-regexp)
  2744. (org-set-local 'outline-level 'org-outline-level)
  2745. (when (and org-ellipsis
  2746. (fboundp 'set-display-table-slot) (boundp 'buffer-display-table)
  2747. (fboundp 'make-glyph-code))
  2748. (unless org-display-table
  2749. (setq org-display-table (make-display-table)))
  2750. (set-display-table-slot
  2751. org-display-table 4
  2752. (vconcat (mapcar
  2753. (lambda (c) (make-glyph-code c (and (not (stringp org-ellipsis))
  2754. org-ellipsis)))
  2755. (if (stringp org-ellipsis) org-ellipsis "..."))))
  2756. (setq buffer-display-table org-display-table))
  2757. (org-set-regexps-and-options)
  2758. ;; Calc embedded
  2759. (org-set-local 'calc-embedded-open-mode "# ")
  2760. (modify-syntax-entry ?# "<")
  2761. (modify-syntax-entry ?@ "w")
  2762. (if org-startup-truncated (setq truncate-lines t))
  2763. (org-set-local 'font-lock-unfontify-region-function
  2764. 'org-unfontify-region)
  2765. ;; Activate before-change-function
  2766. (org-set-local 'org-table-may-need-update t)
  2767. (org-add-hook 'before-change-functions 'org-before-change-function nil
  2768. 'local)
  2769. ;; Check for running clock before killing a buffer
  2770. (org-add-hook 'kill-buffer-hook 'org-check-running-clock nil 'local)
  2771. ;; Paragraphs and auto-filling
  2772. (org-set-autofill-regexps)
  2773. (setq indent-line-function 'org-indent-line-function)
  2774. (org-update-radio-target-regexp)
  2775. ;; Comment characters
  2776. ; (org-set-local 'comment-start "#") ;; FIXME: this breaks wrapping
  2777. (org-set-local 'comment-padding " ")
  2778. ;; Align options lines
  2779. (org-set-local
  2780. 'align-mode-rules-list
  2781. '((org-in-buffer-settings
  2782. (regexp . "^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
  2783. (modes . '(org-mode)))))
  2784. ;; Imenu
  2785. (org-set-local 'imenu-create-index-function
  2786. 'org-imenu-get-tree)
  2787. ;; Make isearch reveal context
  2788. (if (or (featurep 'xemacs)
  2789. (not (boundp 'outline-isearch-open-invisible-function)))
  2790. ;; Emacs 21 and XEmacs make use of the hook
  2791. (org-add-hook 'isearch-mode-end-hook 'org-isearch-end 'append 'local)
  2792. ;; Emacs 22 deals with this through a special variable
  2793. (org-set-local 'outline-isearch-open-invisible-function
  2794. (lambda (&rest ignore) (org-show-context 'isearch))))
  2795. ;; If empty file that did not turn on org-mode automatically, make it to.
  2796. (if (and org-insert-mode-line-in-empty-file
  2797. (interactive-p)
  2798. (= (point-min) (point-max)))
  2799. (insert "# -*- mode: org -*-\n\n"))
  2800. (unless org-inhibit-startup
  2801. (when org-startup-align-all-tables
  2802. (let ((bmp (buffer-modified-p)))
  2803. (org-table-map-tables 'org-table-align)
  2804. (set-buffer-modified-p bmp)))
  2805. (org-set-startup-visibility)))
  2806. (put 'org-mode 'flyspell-mode-predicate 'org-mode-flyspell-verify)
  2807. (defun org-current-time ()
  2808. "Current time, possibly rounded to `org-time-stamp-rounding-minutes'."
  2809. (if (> (car org-time-stamp-rounding-minutes) 1)
  2810. (let ((r (car org-time-stamp-rounding-minutes))
  2811. (time (decode-time)))
  2812. (apply 'encode-time
  2813. (append (list 0 (* r (floor (+ .5 (/ (float (nth 1 time)) r)))))
  2814. (nthcdr 2 time))))
  2815. (current-time)))
  2816. ;;;; Font-Lock stuff, including the activators
  2817. (defvar org-mouse-map (make-sparse-keymap))
  2818. (org-defkey org-mouse-map
  2819. (if (featurep 'xemacs) [button2] [mouse-2]) 'org-open-at-mouse)
  2820. (org-defkey org-mouse-map
  2821. (if (featurep 'xemacs) [button3] [mouse-3]) 'org-find-file-at-mouse)
  2822. (when org-mouse-1-follows-link
  2823. (org-defkey org-mouse-map [follow-link] 'mouse-face))
  2824. (when org-tab-follows-link
  2825. (org-defkey org-mouse-map [(tab)] 'org-open-at-point)
  2826. (org-defkey org-mouse-map "\C-i" 'org-open-at-point))
  2827. (when org-return-follows-link
  2828. (org-defkey org-mouse-map [(return)] 'org-open-at-point)
  2829. (org-defkey org-mouse-map "\C-m" 'org-open-at-point))
  2830. (require 'font-lock)
  2831. (defconst org-non-link-chars "]\t\n\r<>")
  2832. (defvar org-link-types '("http" "https" "ftp" "mailto" "file" "news"
  2833. "shell" "elisp"))
  2834. (defvar org-link-types-re nil
  2835. "Matches a link that has a url-like prefix like \"http:\"")
  2836. (defvar org-link-re-with-space nil
  2837. "Matches a link with spaces, optional angular brackets around it.")
  2838. (defvar org-link-re-with-space2 nil
  2839. "Matches a link with spaces, optional angular brackets around it.")
  2840. (defvar org-angle-link-re nil
  2841. "Matches link with angular brackets, spaces are allowed.")
  2842. (defvar org-plain-link-re nil
  2843. "Matches plain link, without spaces.")
  2844. (defvar org-bracket-link-regexp nil
  2845. "Matches a link in double brackets.")
  2846. (defvar org-bracket-link-analytic-regexp nil
  2847. "Regular expression used to analyze links.
  2848. Here is what the match groups contain after a match:
  2849. 1: http:
  2850. 2: http
  2851. 3: path
  2852. 4: [desc]
  2853. 5: desc")
  2854. (defvar org-any-link-re nil
  2855. "Regular expression matching any link.")
  2856. (defun org-make-link-regexps ()
  2857. "Update the link regular expressions.
  2858. This should be called after the variable `org-link-types' has changed."
  2859. (setq org-link-types-re
  2860. (concat
  2861. "\\`\\(" (mapconcat 'identity org-link-types "\\|") "\\):")
  2862. org-link-re-with-space
  2863. (concat
  2864. "<?\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
  2865. "\\([^" org-non-link-chars " ]"
  2866. "[^" org-non-link-chars "]*"
  2867. "[^" org-non-link-chars " ]\\)>?")
  2868. org-link-re-with-space2
  2869. (concat
  2870. "<?\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
  2871. "\\([^" org-non-link-chars " ]"
  2872. "[^]\t\n\r]*"
  2873. "[^" org-non-link-chars " ]\\)>?")
  2874. org-angle-link-re
  2875. (concat
  2876. "<\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
  2877. "\\([^" org-non-link-chars " ]"
  2878. "[^" org-non-link-chars "]*"
  2879. "\\)>")
  2880. org-plain-link-re
  2881. (concat
  2882. "\\<\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
  2883. "\\([^]\t\n\r<>() ]+[^]\t\n\r<>,.;() ]\\)")
  2884. org-bracket-link-regexp
  2885. "\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]"
  2886. org-bracket-link-analytic-regexp
  2887. (concat
  2888. "\\[\\["
  2889. "\\(\\(" (mapconcat 'identity org-link-types "\\|") "\\):\\)?"
  2890. "\\([^]]+\\)"
  2891. "\\]"
  2892. "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
  2893. "\\]")
  2894. org-any-link-re
  2895. (concat "\\(" org-bracket-link-regexp "\\)\\|\\("
  2896. org-angle-link-re "\\)\\|\\("
  2897. org-plain-link-re "\\)")))
  2898. (org-make-link-regexps)
  2899. (defconst org-ts-regexp "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^\r\n>]*?\\)>"
  2900. "Regular expression for fast time stamp matching.")
  2901. (defconst org-ts-regexp-both "[[<]\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^\r\n>]*?\\)[]>]"
  2902. "Regular expression for fast time stamp matching.")
  2903. (defconst org-ts-regexp0 "\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) *\\([^]-+0-9>\r\n ]*\\)\\( \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
  2904. "Regular expression matching time strings for analysis.
  2905. This one does not require the space after the date, so it can be used
  2906. on a string that terminates immediately after the date.")
  2907. (defconst org-ts-regexp1 "\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) +\\([^]-+0-9>\r\n ]*\\)\\( \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
  2908. "Regular expression matching time strings for analysis.")
  2909. (defconst org-ts-regexp2 (concat "<" org-ts-regexp1 "[^>\n]\\{0,16\\}>")
  2910. "Regular expression matching time stamps, with groups.")
  2911. (defconst org-ts-regexp3 (concat "[[<]" org-ts-regexp1 "[^]>\n]\\{0,16\\}[]>]")
  2912. "Regular expression matching time stamps (also [..]), with groups.")
  2913. (defconst org-tr-regexp (concat org-ts-regexp "--?-?" org-ts-regexp)
  2914. "Regular expression matching a time stamp range.")
  2915. (defconst org-tr-regexp-both
  2916. (concat org-ts-regexp-both "--?-?" org-ts-regexp-both)
  2917. "Regular expression matching a time stamp range.")
  2918. (defconst org-tsr-regexp (concat org-ts-regexp "\\(--?-?"
  2919. org-ts-regexp "\\)?")
  2920. "Regular expression matching a time stamp or time stamp range.")
  2921. (defconst org-tsr-regexp-both (concat org-ts-regexp-both "\\(--?-?"
  2922. org-ts-regexp-both "\\)?")
  2923. "Regular expression matching a time stamp or time stamp range.
  2924. The time stamps may be either active or inactive.")
  2925. (defvar org-emph-face nil)
  2926. (defun org-do-emphasis-faces (limit)
  2927. "Run through the buffer and add overlays to links."
  2928. (let (rtn)
  2929. (while (and (not rtn) (re-search-forward org-emph-re limit t))
  2930. (if (not (= (char-after (match-beginning 3))
  2931. (char-after (match-beginning 4))))
  2932. (progn
  2933. (setq rtn t)
  2934. (font-lock-prepend-text-property (match-beginning 2) (match-end 2)
  2935. 'face
  2936. (nth 1 (assoc (match-string 3)
  2937. org-emphasis-alist)))
  2938. (add-text-properties (match-beginning 2) (match-end 2)
  2939. '(font-lock-multiline t))
  2940. (when org-hide-emphasis-markers
  2941. (add-text-properties (match-end 4) (match-beginning 5)
  2942. '(invisible org-link))
  2943. (add-text-properties (match-beginning 3) (match-end 3)
  2944. '(invisible org-link)))))
  2945. (backward-char 1))
  2946. rtn))
  2947. (defun org-emphasize (&optional char)
  2948. "Insert or change an emphasis, i.e. a font like bold or italic.
  2949. If there is an active region, change that region to a new emphasis.
  2950. If there is no region, just insert the marker characters and position
  2951. the cursor between them.
  2952. CHAR should be either the marker character, or the first character of the
  2953. HTML tag associated with that emphasis. If CHAR is a space, the means
  2954. to remove the emphasis of the selected region.
  2955. If char is not given (for example in an interactive call) it
  2956. will be prompted for."
  2957. (interactive)
  2958. (let ((eal org-emphasis-alist) e det
  2959. (erc org-emphasis-regexp-components)
  2960. (prompt "")
  2961. (string "") beg end move tag c s)
  2962. (if (org-region-active-p)
  2963. (setq beg (region-beginning) end (region-end)
  2964. string (buffer-substring beg end))
  2965. (setq move t))
  2966. (while (setq e (pop eal))
  2967. (setq tag (car (org-split-string (nth 2 e) "[ <>/]+"))
  2968. c (aref tag 0))
  2969. (push (cons c (string-to-char (car e))) det)
  2970. (setq prompt (concat prompt (format " [%s%c]%s" (car e) c
  2971. (substring tag 1)))))
  2972. (unless char
  2973. (message "%s" (concat "Emphasis marker or tag:" prompt))
  2974. (setq char (read-char-exclusive)))
  2975. (setq char (or (cdr (assoc char det)) char))
  2976. (if (equal char ?\ )
  2977. (setq s "" move nil)
  2978. (unless (assoc (char-to-string char) org-emphasis-alist)
  2979. (error "No such emphasis marker: \"%c\"" char))
  2980. (setq s (char-to-string char)))
  2981. (while (and (> (length string) 1)
  2982. (equal (substring string 0 1) (substring string -1))
  2983. (assoc (substring string 0 1) org-emphasis-alist))
  2984. (setq string (substring string 1 -1)))
  2985. (setq string (concat s string s))
  2986. (if beg (delete-region beg end))
  2987. (unless (or (bolp)
  2988. (string-match (concat "[" (nth 0 erc) "\n]")
  2989. (char-to-string (char-before (point)))))
  2990. (insert " "))
  2991. (unless (string-match (concat "[" (nth 1 erc) "\n]")
  2992. (char-to-string (char-after (point))))
  2993. (insert " ") (backward-char 1))
  2994. (insert string)
  2995. (and move (backward-char 1))))
  2996. (defconst org-nonsticky-props
  2997. '(mouse-face highlight keymap invisible intangible help-echo org-linked-text))
  2998. (defun org-activate-plain-links (limit)
  2999. "Run through the buffer and add overlays to links."
  3000. (catch 'exit
  3001. (let (f)
  3002. (while (re-search-forward org-plain-link-re limit t)
  3003. (setq f (get-text-property (match-beginning 0) 'face))
  3004. (if (or (eq f 'org-tag)
  3005. (and (listp f) (memq 'org-tag f)))
  3006. nil
  3007. (add-text-properties (match-beginning 0) (match-end 0)
  3008. (list 'mouse-face 'highlight
  3009. 'rear-nonsticky org-nonsticky-props
  3010. 'keymap org-mouse-map
  3011. ))
  3012. (throw 'exit t))))))
  3013. (defun org-activate-code (limit)
  3014. (if (re-search-forward "^[ \t]*\\(:.*\\)" limit t)
  3015. (unless (get-text-property (match-beginning 1) 'face)
  3016. (remove-text-properties (match-beginning 0) (match-end 0)
  3017. '(display t invisible t intangible t))
  3018. t)))
  3019. (defun org-activate-angle-links (limit)
  3020. "Run through the buffer and add overlays to links."
  3021. (if (re-search-forward org-angle-link-re limit t)
  3022. (progn
  3023. (add-text-properties (match-beginning 0) (match-end 0)
  3024. (list 'mouse-face 'highlight
  3025. 'rear-nonsticky org-nonsticky-props
  3026. 'keymap org-mouse-map
  3027. ))
  3028. t)))
  3029. (defun org-activate-bracket-links (limit)
  3030. "Run through the buffer and add overlays to bracketed links."
  3031. (if (re-search-forward org-bracket-link-regexp limit t)
  3032. (let* ((help (concat "LINK: "
  3033. (org-match-string-no-properties 1)))
  3034. ;; FIXME: above we should remove the escapes.
  3035. ;; but that requires another match, protecting match data,
  3036. ;; a lot of overhead for font-lock.
  3037. (ip (org-maybe-intangible
  3038. (list 'invisible 'org-link 'rear-nonsticky org-nonsticky-props
  3039. 'keymap org-mouse-map 'mouse-face 'highlight
  3040. 'font-lock-multiline t 'help-echo help)))
  3041. (vp (list 'rear-nonsticky org-nonsticky-props
  3042. 'keymap org-mouse-map 'mouse-face 'highlight
  3043. ' font-lock-multiline t 'help-echo help)))
  3044. ;; We need to remove the invisible property here. Table narrowing
  3045. ;; may have made some of this invisible.
  3046. (remove-text-properties (match-beginning 0) (match-end 0)
  3047. '(invisible nil))
  3048. (if (match-end 3)
  3049. (progn
  3050. (add-text-properties (match-beginning 0) (match-beginning 3) ip)
  3051. (add-text-properties (match-beginning 3) (match-end 3) vp)
  3052. (add-text-properties (match-end 3) (match-end 0) ip))
  3053. (add-text-properties (match-beginning 0) (match-beginning 1) ip)
  3054. (add-text-properties (match-beginning 1) (match-end 1) vp)
  3055. (add-text-properties (match-end 1) (match-end 0) ip))
  3056. t)))
  3057. (defun org-activate-dates (limit)
  3058. "Run through the buffer and add overlays to dates."
  3059. (if (re-search-forward org-tsr-regexp-both limit t)
  3060. (progn
  3061. (add-text-properties (match-beginning 0) (match-end 0)
  3062. (list 'mouse-face 'highlight
  3063. 'rear-nonsticky org-nonsticky-props
  3064. 'keymap org-mouse-map))
  3065. (when org-display-custom-times
  3066. (if (match-end 3)
  3067. (org-display-custom-time (match-beginning 3) (match-end 3)))
  3068. (org-display-custom-time (match-beginning 1) (match-end 1)))
  3069. t)))
  3070. (defvar org-target-link-regexp nil
  3071. "Regular expression matching radio targets in plain text.")
  3072. (defvar org-target-regexp "<<\\([^<>\n\r]+\\)>>"
  3073. "Regular expression matching a link target.")
  3074. (defvar org-radio-target-regexp "<<<\\([^<>\n\r]+\\)>>>"
  3075. "Regular expression matching a radio target.")
  3076. (defvar org-any-target-regexp "<<<?\\([^<>\n\r]+\\)>>>?" ; FIXME, not exact, would match <<<aaa>> as a radio target.
  3077. "Regular expression matching any target.")
  3078. (defun org-activate-target-links (limit)
  3079. "Run through the buffer and add overlays to target matches."
  3080. (when org-target-link-regexp
  3081. (let ((case-fold-search t))
  3082. (if (re-search-forward org-target-link-regexp limit t)
  3083. (progn
  3084. (add-text-properties (match-beginning 0) (match-end 0)
  3085. (list 'mouse-face 'highlight
  3086. 'rear-nonsticky org-nonsticky-props
  3087. 'keymap org-mouse-map
  3088. 'help-echo "Radio target link"
  3089. 'org-linked-text t))
  3090. t)))))
  3091. (defun org-update-radio-target-regexp ()
  3092. "Find all radio targets in this file and update the regular expression."
  3093. (interactive)
  3094. (when (memq 'radio org-activate-links)
  3095. (setq org-target-link-regexp
  3096. (org-make-target-link-regexp (org-all-targets 'radio)))
  3097. (org-restart-font-lock)))
  3098. (defun org-hide-wide-columns (limit)
  3099. (let (s e)
  3100. (setq s (text-property-any (point) (or limit (point-max))
  3101. 'org-cwidth t))
  3102. (when s
  3103. (setq e (next-single-property-change s 'org-cwidth))
  3104. (add-text-properties s e (org-maybe-intangible '(invisible org-cwidth)))
  3105. (goto-char e)
  3106. t)))
  3107. (defvar org-latex-and-specials-regexp nil
  3108. "Regular expression for highlighting export special stuff.")
  3109. (defvar org-match-substring-regexp)
  3110. (defvar org-match-substring-with-braces-regexp)
  3111. (defvar org-export-html-special-string-regexps)
  3112. (defun org-compute-latex-and-specials-regexp ()
  3113. "Compute regular expression for stuff treated specially by exporters."
  3114. (if (not org-highlight-latex-fragments-and-specials)
  3115. (org-set-local 'org-latex-and-specials-regexp nil)
  3116. (require 'org-exp)
  3117. (let*
  3118. ((matchers (plist-get org-format-latex-options :matchers))
  3119. (latexs (delq nil (mapcar (lambda (x) (if (member (car x) matchers) x))
  3120. org-latex-regexps)))
  3121. (options (org-combine-plists (org-default-export-plist)
  3122. (org-infile-export-plist)))
  3123. (org-export-with-sub-superscripts (plist-get options :sub-superscript))
  3124. (org-export-with-LaTeX-fragments (plist-get options :LaTeX-fragments))
  3125. (org-export-with-TeX-macros (plist-get options :TeX-macros))
  3126. (org-export-html-expand (plist-get options :expand-quoted-html))
  3127. (org-export-with-special-strings (plist-get options :special-strings))
  3128. (re-sub
  3129. (cond
  3130. ((equal org-export-with-sub-superscripts '{})
  3131. (list org-match-substring-with-braces-regexp))
  3132. (org-export-with-sub-superscripts
  3133. (list org-match-substring-regexp))
  3134. (t nil)))
  3135. (re-latex
  3136. (if org-export-with-LaTeX-fragments
  3137. (mapcar (lambda (x) (nth 1 x)) latexs)))
  3138. (re-macros
  3139. (if org-export-with-TeX-macros
  3140. (list (concat "\\\\"
  3141. (regexp-opt
  3142. (append (mapcar 'car org-html-entities)
  3143. (if (boundp 'org-latex-entities)
  3144. org-latex-entities nil))
  3145. 'words))) ; FIXME
  3146. ))
  3147. ;; (list "\\\\\\(?:[a-zA-Z]+\\)")))
  3148. (re-special (if org-export-with-special-strings
  3149. (mapcar (lambda (x) (car x))
  3150. org-export-html-special-string-regexps)))
  3151. (re-rest
  3152. (delq nil
  3153. (list
  3154. (if org-export-html-expand "@<[^>\n]+>")
  3155. ))))
  3156. (org-set-local
  3157. 'org-latex-and-specials-regexp
  3158. (mapconcat 'identity (append re-latex re-sub re-macros re-special
  3159. re-rest) "\\|")))))
  3160. (defun org-do-latex-and-special-faces (limit)
  3161. "Run through the buffer and add overlays to links."
  3162. (when org-latex-and-specials-regexp
  3163. (let (rtn d)
  3164. (while (and (not rtn) (re-search-forward org-latex-and-specials-regexp
  3165. limit t))
  3166. (if (not (memq (car-safe (get-text-property (1+ (match-beginning 0))
  3167. 'face))
  3168. '(org-code org-verbatim underline)))
  3169. (progn
  3170. (setq rtn t
  3171. d (cond ((member (char-after (1+ (match-beginning 0)))
  3172. '(?_ ?^)) 1)
  3173. (t 0)))
  3174. (font-lock-prepend-text-property
  3175. (+ d (match-beginning 0)) (match-end 0)
  3176. 'face 'org-latex-and-export-specials)
  3177. (add-text-properties (+ d (match-beginning 0)) (match-end 0)
  3178. '(font-lock-multiline t)))))
  3179. rtn)))
  3180. (defun org-restart-font-lock ()
  3181. "Restart font-lock-mode, to force refontification."
  3182. (when (and (boundp 'font-lock-mode) font-lock-mode)
  3183. (font-lock-mode -1)
  3184. (font-lock-mode 1)))
  3185. (defun org-all-targets (&optional radio)
  3186. "Return a list of all targets in this file.
  3187. With optional argument RADIO, only find radio targets."
  3188. (let ((re (if radio org-radio-target-regexp org-target-regexp))
  3189. rtn)
  3190. (save-excursion
  3191. (goto-char (point-min))
  3192. (while (re-search-forward re nil t)
  3193. (add-to-list 'rtn (downcase (org-match-string-no-properties 1))))
  3194. rtn)))
  3195. (defun org-make-target-link-regexp (targets)
  3196. "Make regular expression matching all strings in TARGETS.
  3197. The regular expression finds the targets also if there is a line break
  3198. between words."
  3199. (and targets
  3200. (concat
  3201. "\\<\\("
  3202. (mapconcat
  3203. (lambda (x)
  3204. (while (string-match " +" x)
  3205. (setq x (replace-match "\\s-+" t t x)))
  3206. x)
  3207. targets
  3208. "\\|")
  3209. "\\)\\>")))
  3210. (defun org-activate-tags (limit)
  3211. (if (re-search-forward (org-re "^\\*+.*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \r\n]") limit t)
  3212. (progn
  3213. (add-text-properties (match-beginning 1) (match-end 1)
  3214. (list 'mouse-face 'highlight
  3215. 'rear-nonsticky org-nonsticky-props
  3216. 'keymap org-mouse-map))
  3217. t)))
  3218. (defun org-outline-level ()
  3219. (save-excursion
  3220. (looking-at outline-regexp)
  3221. (if (match-beginning 1)
  3222. (+ (org-get-string-indentation (match-string 1)) 1000)
  3223. (1- (- (match-end 0) (match-beginning 0))))))
  3224. (defvar org-font-lock-keywords nil)
  3225. (defconst org-property-re (org-re "^[ \t]*\\(:\\([-[:alnum:]_]+\\):\\)[ \t]*\\([^ \t\r\n].*\\)")
  3226. "Regular expression matching a property line.")
  3227. (defvar org-font-lock-hook nil
  3228. "Functions to be called for special font loch stuff.")
  3229. (defun org-font-lock-hook (limit)
  3230. (run-hook-with-args 'org-font-lock-hook limit))
  3231. (defun org-set-font-lock-defaults ()
  3232. (let* ((em org-fontify-emphasized-text)
  3233. (lk org-activate-links)
  3234. (org-font-lock-extra-keywords
  3235. (list
  3236. ;; Call the hook
  3237. '(org-font-lock-hook)
  3238. ;; Headlines
  3239. '("^\\(\\**\\)\\(\\* \\)\\(.*\\)" (1 (org-get-level-face 1))
  3240. (2 (org-get-level-face 2)) (3 (org-get-level-face 3)))
  3241. ;; Table lines
  3242. '("^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)"
  3243. (1 'org-table t))
  3244. ;; Table internals
  3245. '("^[ \t]*|\\(?:.*?|\\)? *\\(:?=[^|\n]*\\)" (1 'org-formula t))
  3246. '("^[ \t]*| *\\([#*]\\) *|" (1 'org-formula t))
  3247. '("^[ \t]*|\\( *\\([$!_^/]\\) *|.*\\)|" (1 'org-formula t))
  3248. ;; Drawers
  3249. (list org-drawer-regexp '(0 'org-special-keyword t))
  3250. (list "^[ \t]*:END:" '(0 'org-special-keyword t))
  3251. ;; Properties
  3252. (list org-property-re
  3253. '(1 'org-special-keyword t)
  3254. '(3 'org-property-value t))
  3255. (if org-format-transports-properties-p
  3256. '("| *\\(<[0-9]+>\\) *" (1 'org-formula t)))
  3257. ;; Links
  3258. (if (memq 'tag lk) '(org-activate-tags (1 'org-tag prepend)))
  3259. (if (memq 'angle lk) '(org-activate-angle-links (0 'org-link t)))
  3260. (if (memq 'plain lk) '(org-activate-plain-links (0 'org-link t)))
  3261. (if (memq 'bracket lk) '(org-activate-bracket-links (0 'org-link t)))
  3262. (if (memq 'radio lk) '(org-activate-target-links (0 'org-link t)))
  3263. (if (memq 'date lk) '(org-activate-dates (0 'org-date t)))
  3264. '("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org-sexp-date t))
  3265. '(org-hide-wide-columns (0 nil append))
  3266. ;; TODO lines
  3267. (list (concat "^\\*+[ \t]+" org-todo-regexp)
  3268. '(1 (org-get-todo-face 1) t))
  3269. ;; DONE
  3270. (if org-fontify-done-headline
  3271. (list (concat "^[*]+ +\\<\\("
  3272. (mapconcat 'regexp-quote org-done-keywords "\\|")
  3273. "\\)\\(.*\\)")
  3274. '(2 'org-headline-done t))
  3275. nil)
  3276. ;; Priorities
  3277. (list (concat "\\[#[A-Z0-9]\\]") '(0 'org-special-keyword t))
  3278. ;; Special keywords
  3279. (list (concat "\\<" org-deadline-string) '(0 'org-special-keyword t))
  3280. (list (concat "\\<" org-scheduled-string) '(0 'org-special-keyword t))
  3281. (list (concat "\\<" org-closed-string) '(0 'org-special-keyword t))
  3282. (list (concat "\\<" org-clock-string) '(0 'org-special-keyword t))
  3283. ;; Emphasis
  3284. (if em
  3285. (if (featurep 'xemacs)
  3286. '(org-do-emphasis-faces (0 nil append))
  3287. '(org-do-emphasis-faces)))
  3288. ;; Checkboxes
  3289. '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(\\[[- X]\\]\\)"
  3290. 2 'bold prepend)
  3291. (if org-provide-checkbox-statistics
  3292. '("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
  3293. (0 (org-get-checkbox-statistics-face) t)))
  3294. ;; Description list items
  3295. '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(.*?\\) ::"
  3296. 2 'bold prepend)
  3297. (list (concat "^\\*+ \\(.*:" org-archive-tag ":.*\\)")
  3298. '(1 'org-archived prepend))
  3299. ;; Specials
  3300. '(org-do-latex-and-special-faces)
  3301. ;; Code
  3302. '(org-activate-code (1 'org-code t))
  3303. ;; COMMENT
  3304. (list (concat "^\\*+[ \t]+\\<\\(" org-comment-string
  3305. "\\|" org-quote-string "\\)\\>")
  3306. '(1 'org-special-keyword t))
  3307. '("^#.*" (0 'font-lock-comment-face t))
  3308. )))
  3309. (setq org-font-lock-extra-keywords (delq nil org-font-lock-extra-keywords))
  3310. ;; Now set the full font-lock-keywords
  3311. (org-set-local 'org-font-lock-keywords org-font-lock-extra-keywords)
  3312. (org-set-local 'font-lock-defaults
  3313. '(org-font-lock-keywords t nil nil backward-paragraph))
  3314. (kill-local-variable 'font-lock-keywords) nil))
  3315. (defvar org-m nil)
  3316. (defvar org-l nil)
  3317. (defvar org-f nil)
  3318. (defun org-get-level-face (n)
  3319. "Get the right face for match N in font-lock matching of healdines."
  3320. (setq org-l (- (match-end 2) (match-beginning 1) 1))
  3321. (if org-odd-levels-only (setq org-l (1+ (/ org-l 2))))
  3322. (setq org-f (nth (% (1- org-l) org-n-level-faces) org-level-faces))
  3323. (cond
  3324. ((eq n 1) (if org-hide-leading-stars 'org-hide org-f))
  3325. ((eq n 2) org-f)
  3326. (t (if org-level-color-stars-only nil org-f))))
  3327. (defun org-get-todo-face (kwd)
  3328. "Get the right face for a TODO keyword KWD.
  3329. If KWD is a number, get the corresponding match group."
  3330. (if (numberp kwd) (setq kwd (match-string kwd)))
  3331. (or (cdr (assoc kwd org-todo-keyword-faces))
  3332. (and (member kwd org-done-keywords) 'org-done)
  3333. 'org-todo))
  3334. (defun org-unfontify-region (beg end &optional maybe_loudly)
  3335. "Remove fontification and activation overlays from links."
  3336. (font-lock-default-unfontify-region beg end)
  3337. (let* ((buffer-undo-list t)
  3338. (inhibit-read-only t) (inhibit-point-motion-hooks t)
  3339. (inhibit-modification-hooks t)
  3340. deactivate-mark buffer-file-name buffer-file-truename)
  3341. (remove-text-properties beg end
  3342. '(mouse-face t keymap t org-linked-text t
  3343. invisible t intangible t))))
  3344. ;;;; Visibility cycling, including org-goto and indirect buffer
  3345. ;;; Cycling
  3346. (defvar org-cycle-global-status nil)
  3347. (make-variable-buffer-local 'org-cycle-global-status)
  3348. (defvar org-cycle-subtree-status nil)
  3349. (make-variable-buffer-local 'org-cycle-subtree-status)
  3350. ;;;###autoload
  3351. (defun org-cycle (&optional arg)
  3352. "Visibility cycling for Org-mode.
  3353. - When this function is called with a prefix argument, rotate the entire
  3354. buffer through 3 states (global cycling)
  3355. 1. OVERVIEW: Show only top-level headlines.
  3356. 2. CONTENTS: Show all headlines of all levels, but no body text.
  3357. 3. SHOW ALL: Show everything.
  3358. When called with two C-c C-u prefixes, switch to the startup visibility,
  3359. determined by the variable `org-startup-folded', and by any VISIBILITY
  3360. properties in the buffer.
  3361. - When point is at the beginning of a headline, rotate the subtree started
  3362. by this line through 3 different states (local cycling)
  3363. 1. FOLDED: Only the main headline is shown.
  3364. 2. CHILDREN: The main headline and the direct children are shown.
  3365. From this state, you can move to one of the children
  3366. and zoom in further.
  3367. 3. SUBTREE: Show the entire subtree, including body text.
  3368. - When there is a numeric prefix, go up to a heading with level ARG, do
  3369. a `show-subtree' and return to the previous cursor position. If ARG
  3370. is negative, go up that many levels.
  3371. - When point is not at the beginning of a headline, execute the global
  3372. binding for TAB, which is re-indenting the line. See the option
  3373. `org-cycle-emulate-tab' for details.
  3374. - Special case: if point is at the beginning of the buffer and there is
  3375. no headline in line 1, this function will act as if called with prefix arg.
  3376. But only if also the variable `org-cycle-global-at-bob' is t."
  3377. (interactive "P")
  3378. (org-load-modules-maybe)
  3379. (let* ((outline-regexp
  3380. (if (and (org-mode-p) org-cycle-include-plain-lists)
  3381. "\\(?:\\*+ \\|\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) \\)"
  3382. outline-regexp))
  3383. (bob-special (and org-cycle-global-at-bob (bobp)
  3384. (not (looking-at outline-regexp))))
  3385. (org-cycle-hook
  3386. (if bob-special
  3387. (delq 'org-optimize-window-after-visibility-change
  3388. (copy-sequence org-cycle-hook))
  3389. org-cycle-hook))
  3390. (pos (point)))
  3391. (if (or bob-special (equal arg '(4)))
  3392. ;; special case: use global cycling
  3393. (setq arg t))
  3394. (cond
  3395. ((equal arg '(16))
  3396. (org-set-startup-visibility)
  3397. (message "Startup visibility, plus VISIBILITY properties."))
  3398. ((org-at-table-p 'any)
  3399. ;; Enter the table or move to the next field in the table
  3400. (or (org-table-recognize-table.el)
  3401. (progn
  3402. (if arg (org-table-edit-field t)
  3403. (org-table-justify-field-maybe)
  3404. (call-interactively 'org-table-next-field)))))
  3405. ((eq arg t) ;; Global cycling
  3406. (cond
  3407. ((and (eq last-command this-command)
  3408. (eq org-cycle-global-status 'overview))
  3409. ;; We just created the overview - now do table of contents
  3410. ;; This can be slow in very large buffers, so indicate action
  3411. (message "CONTENTS...")
  3412. (org-content)
  3413. (message "CONTENTS...done")
  3414. (setq org-cycle-global-status 'contents)
  3415. (run-hook-with-args 'org-cycle-hook 'contents))
  3416. ((and (eq last-command this-command)
  3417. (eq org-cycle-global-status 'contents))
  3418. ;; We just showed the table of contents - now show everything
  3419. (show-all)
  3420. (message "SHOW ALL")
  3421. (setq org-cycle-global-status 'all)
  3422. (run-hook-with-args 'org-cycle-hook 'all))
  3423. (t
  3424. ;; Default action: go to overview
  3425. (org-overview)
  3426. (message "OVERVIEW")
  3427. (setq org-cycle-global-status 'overview)
  3428. (run-hook-with-args 'org-cycle-hook 'overview))))
  3429. ((and org-drawers org-drawer-regexp
  3430. (save-excursion
  3431. (beginning-of-line 1)
  3432. (looking-at org-drawer-regexp)))
  3433. ;; Toggle block visibility
  3434. (org-flag-drawer
  3435. (not (get-char-property (match-end 0) 'invisible))))
  3436. ((integerp arg)
  3437. ;; Show-subtree, ARG levels up from here.
  3438. (save-excursion
  3439. (org-back-to-heading)
  3440. (outline-up-heading (if (< arg 0) (- arg)
  3441. (- (funcall outline-level) arg)))
  3442. (org-show-subtree)))
  3443. ((and (save-excursion (beginning-of-line 1) (looking-at outline-regexp))
  3444. (or (bolp) (not (eq org-cycle-emulate-tab 'exc-hl-bol))))
  3445. ;; At a heading: rotate between three different views
  3446. (org-back-to-heading)
  3447. (let ((goal-column 0) eoh eol eos)
  3448. ;; First, some boundaries
  3449. (save-excursion
  3450. (org-back-to-heading)
  3451. (save-excursion
  3452. (beginning-of-line 2)
  3453. (while (and (not (eobp)) ;; this is like `next-line'
  3454. (get-char-property (1- (point)) 'invisible))
  3455. (beginning-of-line 2)) (setq eol (point)))
  3456. (outline-end-of-heading) (setq eoh (point))
  3457. (org-end-of-subtree t)
  3458. (unless (eobp)
  3459. (skip-chars-forward " \t\n")
  3460. (beginning-of-line 1) ; in case this is an item
  3461. )
  3462. (setq eos (1- (point))))
  3463. ;; Find out what to do next and set `this-command'
  3464. (cond
  3465. ((= eos eoh)
  3466. ;; Nothing is hidden behind this heading
  3467. (message "EMPTY ENTRY")
  3468. (setq org-cycle-subtree-status nil)
  3469. (save-excursion
  3470. (goto-char eos)
  3471. (outline-next-heading)
  3472. (if (org-invisible-p) (org-flag-heading nil))))
  3473. ((or (>= eol eos)
  3474. (not (string-match "\\S-" (buffer-substring eol eos))))
  3475. ;; Entire subtree is hidden in one line: open it
  3476. (org-show-entry)
  3477. (show-children)
  3478. (message "CHILDREN")
  3479. (save-excursion
  3480. (goto-char eos)
  3481. (outline-next-heading)
  3482. (if (org-invisible-p) (org-flag-heading nil)))
  3483. (setq org-cycle-subtree-status 'children)
  3484. (run-hook-with-args 'org-cycle-hook 'children))
  3485. ((and (eq last-command this-command)
  3486. (eq org-cycle-subtree-status 'children))
  3487. ;; We just showed the children, now show everything.
  3488. (org-show-subtree)
  3489. (message "SUBTREE")
  3490. (setq org-cycle-subtree-status 'subtree)
  3491. (run-hook-with-args 'org-cycle-hook 'subtree))
  3492. (t
  3493. ;; Default action: hide the subtree.
  3494. (hide-subtree)
  3495. (message "FOLDED")
  3496. (setq org-cycle-subtree-status 'folded)
  3497. (run-hook-with-args 'org-cycle-hook 'folded)))))
  3498. ;; TAB emulation
  3499. (buffer-read-only (org-back-to-heading))
  3500. ((org-try-cdlatex-tab))
  3501. ((and (eq org-cycle-emulate-tab 'exc-hl-bol)
  3502. (or (not (bolp))
  3503. (not (looking-at outline-regexp))))
  3504. (call-interactively (global-key-binding "\t")))
  3505. ((if (and (memq org-cycle-emulate-tab '(white whitestart))
  3506. (save-excursion (beginning-of-line 1) (looking-at "[ \t]*"))
  3507. (or (and (eq org-cycle-emulate-tab 'white)
  3508. (= (match-end 0) (point-at-eol)))
  3509. (and (eq org-cycle-emulate-tab 'whitestart)
  3510. (>= (match-end 0) pos))))
  3511. t
  3512. (eq org-cycle-emulate-tab t))
  3513. (call-interactively (global-key-binding "\t")))
  3514. (t (save-excursion
  3515. (org-back-to-heading)
  3516. (org-cycle))))))
  3517. ;;;###autoload
  3518. (defun org-global-cycle (&optional arg)
  3519. "Cycle the global visibility. For details see `org-cycle'.
  3520. With C-u prefix arg, switch to startup visibility.
  3521. With a numeric prefix, show all headlines up to that level."
  3522. (interactive "P")
  3523. (let ((org-cycle-include-plain-lists
  3524. (if (org-mode-p) org-cycle-include-plain-lists nil)))
  3525. (cond
  3526. ((integerp arg)
  3527. (show-all)
  3528. (hide-sublevels arg)
  3529. (setq org-cycle-global-status 'contents))
  3530. ((equal arg '(4))
  3531. (org-set-startup-visibility)
  3532. (message "Startup visibility, plus VISIBILITY properties."))
  3533. (t
  3534. (org-cycle '(4))))))
  3535. (defun org-set-startup-visibility ()
  3536. "Set the visibility required by startup options and properties."
  3537. (cond
  3538. ((eq org-startup-folded t)
  3539. (org-cycle '(4)))
  3540. ((eq org-startup-folded 'content)
  3541. (let ((this-command 'org-cycle) (last-command 'org-cycle))
  3542. (org-cycle '(4)) (org-cycle '(4)))))
  3543. (org-set-visibility-according-to-property 'no-cleanup)
  3544. (org-cycle-hide-archived-subtrees 'all)
  3545. (org-cycle-hide-drawers 'all)
  3546. (org-cycle-show-empty-lines 'all))
  3547. (defun org-set-visibility-according-to-property (&optional no-cleanup)
  3548. "Switch subtree visibilities according to :VISIBILITY: property."
  3549. (interactive)
  3550. (let (state)
  3551. (save-excursion
  3552. (goto-char (point-min))
  3553. (while (re-search-forward
  3554. "^[ \t]*:VISIBILITY:[ \t]+\\([a-z]+\\)"
  3555. nil t)
  3556. (setq state (match-string 1))
  3557. (save-excursion
  3558. (org-back-to-heading t)
  3559. (hide-subtree)
  3560. (org-reveal)
  3561. (cond
  3562. ((equal state '("fold" "folded"))
  3563. (hide-subtree))
  3564. ((equal state "children")
  3565. (org-show-hidden-entry)
  3566. (show-children))
  3567. ((equal state "content")
  3568. (save-excursion
  3569. (save-restriction
  3570. (org-narrow-to-subtree)
  3571. (org-content))))
  3572. ((member state '("all" "showall"))
  3573. (show-subtree)))))
  3574. (unless no-cleanup
  3575. (org-cycle-hide-archived-subtrees 'all)
  3576. (org-cycle-hide-drawers 'all)
  3577. (org-cycle-show-empty-lines 'all)))))
  3578. (defun org-overview ()
  3579. "Switch to overview mode, shoing only top-level headlines.
  3580. Really, this shows all headlines with level equal or greater than the level
  3581. of the first headline in the buffer. This is important, because if the
  3582. first headline is not level one, then (hide-sublevels 1) gives confusing
  3583. results."
  3584. (interactive)
  3585. (let ((level (save-excursion
  3586. (goto-char (point-min))
  3587. (if (re-search-forward (concat "^" outline-regexp) nil t)
  3588. (progn
  3589. (goto-char (match-beginning 0))
  3590. (funcall outline-level))))))
  3591. (and level (hide-sublevels level))))
  3592. (defun org-content (&optional arg)
  3593. "Show all headlines in the buffer, like a table of contents.
  3594. With numerical argument N, show content up to level N."
  3595. (interactive "P")
  3596. (save-excursion
  3597. ;; Visit all headings and show their offspring
  3598. (and (integerp arg) (org-overview))
  3599. (goto-char (point-max))
  3600. (catch 'exit
  3601. (while (and (progn (condition-case nil
  3602. (outline-previous-visible-heading 1)
  3603. (error (goto-char (point-min))))
  3604. t)
  3605. (looking-at outline-regexp))
  3606. (if (integerp arg)
  3607. (show-children (1- arg))
  3608. (show-branches))
  3609. (if (bobp) (throw 'exit nil))))))
  3610. (defun org-optimize-window-after-visibility-change (state)
  3611. "Adjust the window after a change in outline visibility.
  3612. This function is the default value of the hook `org-cycle-hook'."
  3613. (when (get-buffer-window (current-buffer))
  3614. (cond
  3615. ; ((eq state 'overview) (org-first-headline-recenter 1))
  3616. ; ((eq state 'overview) (org-beginning-of-line))
  3617. ((eq state 'content) nil)
  3618. ((eq state 'all) nil)
  3619. ((eq state 'folded) nil)
  3620. ((eq state 'children) (or (org-subtree-end-visible-p) (recenter 1)))
  3621. ((eq state 'subtree) (or (org-subtree-end-visible-p) (recenter 1))))))
  3622. (defun org-compact-display-after-subtree-move ()
  3623. (let (beg end)
  3624. (save-excursion
  3625. (if (org-up-heading-safe)
  3626. (progn
  3627. (hide-subtree)
  3628. (show-entry)
  3629. (show-children)
  3630. (org-cycle-show-empty-lines 'children)
  3631. (org-cycle-hide-drawers 'children))
  3632. (org-overview)))))
  3633. (defun org-cycle-show-empty-lines (state)
  3634. "Show empty lines above all visible headlines.
  3635. The region to be covered depends on STATE when called through
  3636. `org-cycle-hook'. Lisp program can use t for STATE to get the
  3637. entire buffer covered. Note that an empty line is only shown if there
  3638. are at least `org-cycle-separator-lines' empty lines before the headeline."
  3639. (when (> org-cycle-separator-lines 0)
  3640. (save-excursion
  3641. (let* ((n org-cycle-separator-lines)
  3642. (re (cond
  3643. ((= n 1) "\\(\n[ \t]*\n\\*+\\) ")
  3644. ((= n 2) "^[ \t]*\\(\n[ \t]*\n\\*+\\) ")
  3645. (t (let ((ns (number-to-string (- n 2))))
  3646. (concat "^\\(?:[ \t]*\n\\)\\{" ns "," ns "\\}"
  3647. "[ \t]*\\(\n[ \t]*\n\\*+\\) ")))))
  3648. beg end)
  3649. (cond
  3650. ((memq state '(overview contents t))
  3651. (setq beg (point-min) end (point-max)))
  3652. ((memq state '(children folded))
  3653. (setq beg (point) end (progn (org-end-of-subtree t t)
  3654. (beginning-of-line 2)
  3655. (point)))))
  3656. (when beg
  3657. (goto-char beg)
  3658. (while (re-search-forward re end t)
  3659. (if (not (get-char-property (match-end 1) 'invisible))
  3660. (outline-flag-region
  3661. (match-beginning 1) (match-end 1) nil)))))))
  3662. ;; Never hide empty lines at the end of the file.
  3663. (save-excursion
  3664. (goto-char (point-max))
  3665. (outline-previous-heading)
  3666. (outline-end-of-heading)
  3667. (if (and (looking-at "[ \t\n]+")
  3668. (= (match-end 0) (point-max)))
  3669. (outline-flag-region (point) (match-end 0) nil))))
  3670. (defun org-cycle-hide-drawers (state)
  3671. "Re-hide all drawers after a visibility state change."
  3672. (when (and (org-mode-p)
  3673. (not (memq state '(overview folded))))
  3674. (save-excursion
  3675. (let* ((globalp (memq state '(contents all)))
  3676. (beg (if globalp (point-min) (point)))
  3677. (end (if globalp (point-max) (org-end-of-subtree t))))
  3678. (goto-char beg)
  3679. (while (re-search-forward org-drawer-regexp end t)
  3680. (org-flag-drawer t))))))
  3681. (defun org-flag-drawer (flag)
  3682. (save-excursion
  3683. (beginning-of-line 1)
  3684. (when (looking-at "^[ \t]*:[a-zA-Z][a-zA-Z0-9]*:")
  3685. (let ((b (match-end 0))
  3686. (outline-regexp org-outline-regexp))
  3687. (if (re-search-forward
  3688. "^[ \t]*:END:"
  3689. (save-excursion (outline-next-heading) (point)) t)
  3690. (outline-flag-region b (point-at-eol) flag)
  3691. (error ":END: line missing"))))))
  3692. (defun org-subtree-end-visible-p ()
  3693. "Is the end of the current subtree visible?"
  3694. (pos-visible-in-window-p
  3695. (save-excursion (org-end-of-subtree t) (point))))
  3696. (defun org-first-headline-recenter (&optional N)
  3697. "Move cursor to the first headline and recenter the headline.
  3698. Optional argument N means, put the headline into the Nth line of the window."
  3699. (goto-char (point-min))
  3700. (when (re-search-forward (concat "^\\(" outline-regexp "\\)") nil t)
  3701. (beginning-of-line)
  3702. (recenter (prefix-numeric-value N))))
  3703. ;;; Org-goto
  3704. (defvar org-goto-window-configuration nil)
  3705. (defvar org-goto-marker nil)
  3706. (defvar org-goto-map
  3707. (let ((map (make-sparse-keymap)))
  3708. (let ((cmds '(isearch-forward isearch-backward kill-ring-save set-mark-command mouse-drag-region universal-argument org-occur)) cmd)
  3709. (while (setq cmd (pop cmds))
  3710. (substitute-key-definition cmd cmd map global-map)))
  3711. (suppress-keymap map)
  3712. (org-defkey map "\C-m" 'org-goto-ret)
  3713. (org-defkey map [(return)] 'org-goto-ret)
  3714. (org-defkey map [(left)] 'org-goto-left)
  3715. (org-defkey map [(right)] 'org-goto-right)
  3716. (org-defkey map [(control ?g)] 'org-goto-quit)
  3717. (org-defkey map "\C-i" 'org-cycle)
  3718. (org-defkey map [(tab)] 'org-cycle)
  3719. (org-defkey map [(down)] 'outline-next-visible-heading)
  3720. (org-defkey map [(up)] 'outline-previous-visible-heading)
  3721. (if org-goto-auto-isearch
  3722. (if (fboundp 'define-key-after)
  3723. (define-key-after map [t] 'org-goto-local-auto-isearch)
  3724. nil)
  3725. (org-defkey map "q" 'org-goto-quit)
  3726. (org-defkey map "n" 'outline-next-visible-heading)
  3727. (org-defkey map "p" 'outline-previous-visible-heading)
  3728. (org-defkey map "f" 'outline-forward-same-level)
  3729. (org-defkey map "b" 'outline-backward-same-level)
  3730. (org-defkey map "u" 'outline-up-heading))
  3731. (org-defkey map "/" 'org-occur)
  3732. (org-defkey map "\C-c\C-n" 'outline-next-visible-heading)
  3733. (org-defkey map "\C-c\C-p" 'outline-previous-visible-heading)
  3734. (org-defkey map "\C-c\C-f" 'outline-forward-same-level)
  3735. (org-defkey map "\C-c\C-b" 'outline-backward-same-level)
  3736. (org-defkey map "\C-c\C-u" 'outline-up-heading)
  3737. map))
  3738. (defconst org-goto-help
  3739. "Browse buffer copy, to find location or copy text. Just type for auto-isearch.
  3740. RET=jump to location [Q]uit and return to previous location
  3741. \[Up]/[Down]=next/prev headline TAB=cycle visibility [/] org-occur")
  3742. (defvar org-goto-start-pos) ; dynamically scoped parameter
  3743. (defun org-goto (&optional alternative-interface)
  3744. "Look up a different location in the current file, keeping current visibility.
  3745. When you want look-up or go to a different location in a document, the
  3746. fastest way is often to fold the entire buffer and then dive into the tree.
  3747. This method has the disadvantage, that the previous location will be folded,
  3748. which may not be what you want.
  3749. This command works around this by showing a copy of the current buffer
  3750. in an indirect buffer, in overview mode. You can dive into the tree in
  3751. that copy, use org-occur and incremental search to find a location.
  3752. When pressing RET or `Q', the command returns to the original buffer in
  3753. which the visibility is still unchanged. After RET is will also jump to
  3754. the location selected in the indirect buffer and expose the
  3755. the headline hierarchy above."
  3756. (interactive "P")
  3757. (let* ((org-refile-targets '((nil . (:maxlevel . 10))))
  3758. (org-refile-use-outline-path t)
  3759. (interface
  3760. (if (not alternative-interface)
  3761. org-goto-interface
  3762. (if (eq org-goto-interface 'outline)
  3763. 'outline-path-completion
  3764. 'outline)))
  3765. (org-goto-start-pos (point))
  3766. (selected-point
  3767. (if (eq interface 'outline)
  3768. (car (org-get-location (current-buffer) org-goto-help))
  3769. (nth 3 (org-refile-get-location "Goto: ")))))
  3770. (if selected-point
  3771. (progn
  3772. (org-mark-ring-push org-goto-start-pos)
  3773. (goto-char selected-point)
  3774. (if (or (org-invisible-p) (org-invisible-p2))
  3775. (org-show-context 'org-goto)))
  3776. (message "Quit"))))
  3777. (defvar org-goto-selected-point nil) ; dynamically scoped parameter
  3778. (defvar org-goto-exit-command nil) ; dynamically scoped parameter
  3779. (defvar org-goto-local-auto-isearch-map) ; defined below
  3780. (defun org-get-location (buf help)
  3781. "Let the user select a location in the Org-mode buffer BUF.
  3782. This function uses a recursive edit. It returns the selected position
  3783. or nil."
  3784. (let ((isearch-mode-map org-goto-local-auto-isearch-map)
  3785. (isearch-hide-immediately nil)
  3786. (isearch-search-fun-function
  3787. (lambda () 'org-goto-local-search-forward-headings))
  3788. (org-goto-selected-point org-goto-exit-command))
  3789. (save-excursion
  3790. (save-window-excursion
  3791. (delete-other-windows)
  3792. (and (get-buffer "*org-goto*") (kill-buffer "*org-goto*"))
  3793. (switch-to-buffer
  3794. (condition-case nil
  3795. (make-indirect-buffer (current-buffer) "*org-goto*")
  3796. (error (make-indirect-buffer (current-buffer) "*org-goto*"))))
  3797. (with-output-to-temp-buffer "*Help*"
  3798. (princ help))
  3799. (shrink-window-if-larger-than-buffer (get-buffer-window "*Help*"))
  3800. (setq buffer-read-only nil)
  3801. (let ((org-startup-truncated t)
  3802. (org-startup-folded nil)
  3803. (org-startup-align-all-tables nil))
  3804. (org-mode)
  3805. (org-overview))
  3806. (setq buffer-read-only t)
  3807. (if (and (boundp 'org-goto-start-pos)
  3808. (integer-or-marker-p org-goto-start-pos))
  3809. (let ((org-show-hierarchy-above t)
  3810. (org-show-siblings t)
  3811. (org-show-following-heading t))
  3812. (goto-char org-goto-start-pos)
  3813. (and (org-invisible-p) (org-show-context)))
  3814. (goto-char (point-min)))
  3815. (org-beginning-of-line)
  3816. (message "Select location and press RET")
  3817. (use-local-map org-goto-map)
  3818. (recursive-edit)
  3819. ))
  3820. (kill-buffer "*org-goto*")
  3821. (cons org-goto-selected-point org-goto-exit-command)))
  3822. (defvar org-goto-local-auto-isearch-map (make-sparse-keymap))
  3823. (set-keymap-parent org-goto-local-auto-isearch-map isearch-mode-map)
  3824. (define-key org-goto-local-auto-isearch-map "\C-i" 'isearch-other-control-char)
  3825. (define-key org-goto-local-auto-isearch-map "\C-m" 'isearch-other-control-char)
  3826. (defun org-goto-local-search-forward-headings (string bound noerror)
  3827. "Search and make sure that anu matches are in headlines."
  3828. (catch 'return
  3829. (while (search-forward string bound noerror)
  3830. (when (let ((context (mapcar 'car (save-match-data (org-context)))))
  3831. (and (member :headline context)
  3832. (not (member :tags context))))
  3833. (throw 'return (point))))))
  3834. (defun org-goto-local-auto-isearch ()
  3835. "Start isearch."
  3836. (interactive)
  3837. (goto-char (point-min))
  3838. (let ((keys (this-command-keys)))
  3839. (when (eq (lookup-key isearch-mode-map keys) 'isearch-printing-char)
  3840. (isearch-mode t)
  3841. (isearch-process-search-char (string-to-char keys)))))
  3842. (defun org-goto-ret (&optional arg)
  3843. "Finish `org-goto' by going to the new location."
  3844. (interactive "P")
  3845. (setq org-goto-selected-point (point)
  3846. org-goto-exit-command 'return)
  3847. (throw 'exit nil))
  3848. (defun org-goto-left ()
  3849. "Finish `org-goto' by going to the new location."
  3850. (interactive)
  3851. (if (org-on-heading-p)
  3852. (progn
  3853. (beginning-of-line 1)
  3854. (setq org-goto-selected-point (point)
  3855. org-goto-exit-command 'left)
  3856. (throw 'exit nil))
  3857. (error "Not on a heading")))
  3858. (defun org-goto-right ()
  3859. "Finish `org-goto' by going to the new location."
  3860. (interactive)
  3861. (if (org-on-heading-p)
  3862. (progn
  3863. (setq org-goto-selected-point (point)
  3864. org-goto-exit-command 'right)
  3865. (throw 'exit nil))
  3866. (error "Not on a heading")))
  3867. (defun org-goto-quit ()
  3868. "Finish `org-goto' without cursor motion."
  3869. (interactive)
  3870. (setq org-goto-selected-point nil)
  3871. (setq org-goto-exit-command 'quit)
  3872. (throw 'exit nil))
  3873. ;;; Indirect buffer display of subtrees
  3874. (defvar org-indirect-dedicated-frame nil
  3875. "This is the frame being used for indirect tree display.")
  3876. (defvar org-last-indirect-buffer nil)
  3877. (defun org-tree-to-indirect-buffer (&optional arg)
  3878. "Create indirect buffer and narrow it to current subtree.
  3879. With numerical prefix ARG, go up to this level and then take that tree.
  3880. If ARG is negative, go up that many levels.
  3881. If `org-indirect-buffer-display' is not `new-frame', the command removes the
  3882. indirect buffer previously made with this command, to avoid proliferation of
  3883. indirect buffers. However, when you call the command with a `C-u' prefix, or
  3884. when `org-indirect-buffer-display' is `new-frame', the last buffer
  3885. is kept so that you can work with several indirect buffers at the same time.
  3886. If `org-indirect-buffer-display' is `dedicated-frame', the C-u prefix also
  3887. requests that a new frame be made for the new buffer, so that the dedicated
  3888. frame is not changed."
  3889. (interactive "P")
  3890. (let ((cbuf (current-buffer))
  3891. (cwin (selected-window))
  3892. (pos (point))
  3893. beg end level heading ibuf)
  3894. (save-excursion
  3895. (org-back-to-heading t)
  3896. (when (numberp arg)
  3897. (setq level (org-outline-level))
  3898. (if (< arg 0) (setq arg (+ level arg)))
  3899. (while (> (setq level (org-outline-level)) arg)
  3900. (outline-up-heading 1 t)))
  3901. (setq beg (point)
  3902. heading (org-get-heading))
  3903. (org-end-of-subtree t) (setq end (point)))
  3904. (if (and (buffer-live-p org-last-indirect-buffer)
  3905. (not (eq org-indirect-buffer-display 'new-frame))
  3906. (not arg))
  3907. (kill-buffer org-last-indirect-buffer))
  3908. (setq ibuf (org-get-indirect-buffer cbuf)
  3909. org-last-indirect-buffer ibuf)
  3910. (cond
  3911. ((or (eq org-indirect-buffer-display 'new-frame)
  3912. (and arg (eq org-indirect-buffer-display 'dedicated-frame)))
  3913. (select-frame (make-frame))
  3914. (delete-other-windows)
  3915. (switch-to-buffer ibuf)
  3916. (org-set-frame-title heading))
  3917. ((eq org-indirect-buffer-display 'dedicated-frame)
  3918. (raise-frame
  3919. (select-frame (or (and org-indirect-dedicated-frame
  3920. (frame-live-p org-indirect-dedicated-frame)
  3921. org-indirect-dedicated-frame)
  3922. (setq org-indirect-dedicated-frame (make-frame)))))
  3923. (delete-other-windows)
  3924. (switch-to-buffer ibuf)
  3925. (org-set-frame-title (concat "Indirect: " heading)))
  3926. ((eq org-indirect-buffer-display 'current-window)
  3927. (switch-to-buffer ibuf))
  3928. ((eq org-indirect-buffer-display 'other-window)
  3929. (pop-to-buffer ibuf))
  3930. (t (error "Invalid value.")))
  3931. (if (featurep 'xemacs)
  3932. (save-excursion (org-mode) (turn-on-font-lock)))
  3933. (narrow-to-region beg end)
  3934. (show-all)
  3935. (goto-char pos)
  3936. (and (window-live-p cwin) (select-window cwin))))
  3937. (defun org-get-indirect-buffer (&optional buffer)
  3938. (setq buffer (or buffer (current-buffer)))
  3939. (let ((n 1) (base (buffer-name buffer)) bname)
  3940. (while (buffer-live-p
  3941. (get-buffer (setq bname (concat base "-" (number-to-string n)))))
  3942. (setq n (1+ n)))
  3943. (condition-case nil
  3944. (make-indirect-buffer buffer bname 'clone)
  3945. (error (make-indirect-buffer buffer bname)))))
  3946. (defun org-set-frame-title (title)
  3947. "Set the title of the current frame to the string TITLE."
  3948. ;; FIXME: how to name a single frame in XEmacs???
  3949. (unless (featurep 'xemacs)
  3950. (modify-frame-parameters (selected-frame) (list (cons 'name title)))))
  3951. ;;;; Structure editing
  3952. ;;; Inserting headlines
  3953. (defun org-insert-heading (&optional force-heading)
  3954. "Insert a new heading or item with same depth at point.
  3955. If point is in a plain list and FORCE-HEADING is nil, create a new list item.
  3956. If point is at the beginning of a headline, insert a sibling before the
  3957. current headline. If point is not at the beginning, do not split the line,
  3958. but create the new hedline after the current line."
  3959. (interactive "P")
  3960. (if (= (buffer-size) 0)
  3961. (insert "\n* ")
  3962. (when (or force-heading (not (org-insert-item)))
  3963. (let* ((head (save-excursion
  3964. (condition-case nil
  3965. (progn
  3966. (org-back-to-heading)
  3967. (match-string 0))
  3968. (error "*"))))
  3969. (blank (cdr (assq 'heading org-blank-before-new-entry)))
  3970. pos)
  3971. (cond
  3972. ((and (org-on-heading-p) (bolp)
  3973. (or (bobp)
  3974. (save-excursion (backward-char 1) (not (org-invisible-p)))))
  3975. ;; insert before the current line
  3976. (open-line (if blank 2 1)))
  3977. ((and (bolp)
  3978. (or (bobp)
  3979. (save-excursion
  3980. (backward-char 1) (not (org-invisible-p)))))
  3981. ;; insert right here
  3982. nil)
  3983. (t
  3984. ;; in the middle of the line
  3985. (org-show-entry)
  3986. (let ((split
  3987. (org-get-alist-option org-M-RET-may-split-line 'headline))
  3988. tags pos)
  3989. (if (org-on-heading-p)
  3990. (progn
  3991. (looking-at ".*?\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
  3992. (setq tags (and (match-end 2) (match-string 2)))
  3993. (and (match-end 1)
  3994. (delete-region (match-beginning 1) (match-end 1)))
  3995. (setq pos (point-at-bol))
  3996. (or split (end-of-line 1))
  3997. (delete-horizontal-space)
  3998. (newline (if blank 2 1))
  3999. (when tags
  4000. (save-excursion
  4001. (goto-char pos)
  4002. (end-of-line 1)
  4003. (insert " " tags)
  4004. (org-set-tags nil 'align))))
  4005. (or split (end-of-line 1))
  4006. (newline (if blank 2 1))))))
  4007. (insert head) (just-one-space)
  4008. (setq pos (point))
  4009. (end-of-line 1)
  4010. (unless (= (point) pos) (just-one-space) (backward-delete-char 1))
  4011. (run-hooks 'org-insert-heading-hook)))))
  4012. (defun org-get-heading (&optional no-tags)
  4013. "Return the heading of the current entry, without the stars."
  4014. (save-excursion
  4015. (org-back-to-heading t)
  4016. (if (looking-at
  4017. (if no-tags
  4018. (org-re "\\*+[ \t]+\\([^\n\r]*?\\)\\([ \t]+:[[:alnum:]:_@]+:[ \t]*\\)?$")
  4019. "\\*+[ \t]+\\([^\r\n]*\\)"))
  4020. (match-string 1) "")))
  4021. (defun org-insert-heading-after-current ()
  4022. "Insert a new heading with same level as current, after current subtree."
  4023. (interactive)
  4024. (org-back-to-heading)
  4025. (org-insert-heading)
  4026. (org-move-subtree-down)
  4027. (end-of-line 1))
  4028. (defun org-insert-todo-heading (arg)
  4029. "Insert a new heading with the same level and TODO state as current heading.
  4030. If the heading has no TODO state, or if the state is DONE, use the first
  4031. state (TODO by default). Also with prefix arg, force first state."
  4032. (interactive "P")
  4033. (when (not (org-insert-item 'checkbox))
  4034. (org-insert-heading)
  4035. (save-excursion
  4036. (org-back-to-heading)
  4037. (outline-previous-heading)
  4038. (looking-at org-todo-line-regexp))
  4039. (if (or arg
  4040. (not (match-beginning 2))
  4041. (member (match-string 2) org-done-keywords))
  4042. (insert (car org-todo-keywords-1) " ")
  4043. (insert (match-string 2) " "))))
  4044. (defun org-insert-subheading (arg)
  4045. "Insert a new subheading and demote it.
  4046. Works for outline headings and for plain lists alike."
  4047. (interactive "P")
  4048. (org-insert-heading arg)
  4049. (cond
  4050. ((org-on-heading-p) (org-do-demote))
  4051. ((org-at-item-p) (org-indent-item 1))))
  4052. (defun org-insert-todo-subheading (arg)
  4053. "Insert a new subheading with TODO keyword or checkbox and demote it.
  4054. Works for outline headings and for plain lists alike."
  4055. (interactive "P")
  4056. (org-insert-todo-heading arg)
  4057. (cond
  4058. ((org-on-heading-p) (org-do-demote))
  4059. ((org-at-item-p) (org-indent-item 1))))
  4060. ;;; Promotion and Demotion
  4061. (defun org-promote-subtree ()
  4062. "Promote the entire subtree.
  4063. See also `org-promote'."
  4064. (interactive)
  4065. (save-excursion
  4066. (org-map-tree 'org-promote))
  4067. (org-fix-position-after-promote))
  4068. (defun org-demote-subtree ()
  4069. "Demote the entire subtree. See `org-demote'.
  4070. See also `org-promote'."
  4071. (interactive)
  4072. (save-excursion
  4073. (org-map-tree 'org-demote))
  4074. (org-fix-position-after-promote))
  4075. (defun org-do-promote ()
  4076. "Promote the current heading higher up the tree.
  4077. If the region is active in `transient-mark-mode', promote all headings
  4078. in the region."
  4079. (interactive)
  4080. (save-excursion
  4081. (if (org-region-active-p)
  4082. (org-map-region 'org-promote (region-beginning) (region-end))
  4083. (org-promote)))
  4084. (org-fix-position-after-promote))
  4085. (defun org-do-demote ()
  4086. "Demote the current heading lower down the tree.
  4087. If the region is active in `transient-mark-mode', demote all headings
  4088. in the region."
  4089. (interactive)
  4090. (save-excursion
  4091. (if (org-region-active-p)
  4092. (org-map-region 'org-demote (region-beginning) (region-end))
  4093. (org-demote)))
  4094. (org-fix-position-after-promote))
  4095. (defun org-fix-position-after-promote ()
  4096. "Make sure that after pro/demotion cursor position is right."
  4097. (let ((pos (point)))
  4098. (when (save-excursion
  4099. (beginning-of-line 1)
  4100. (looking-at org-todo-line-regexp)
  4101. (or (equal pos (match-end 1)) (equal pos (match-end 2))))
  4102. (cond ((eobp) (insert " "))
  4103. ((eolp) (insert " "))
  4104. ((equal (char-after) ?\ ) (forward-char 1))))))
  4105. (defun org-reduced-level (l)
  4106. (if org-odd-levels-only (1+ (floor (/ l 2))) l))
  4107. (defun org-get-valid-level (level &optional change)
  4108. "Rectify a level change under the influence of `org-odd-levels-only'
  4109. LEVEL is a current level, CHANGE is by how much the level should be
  4110. modified. Even if CHANGE is nil, LEVEL may be returned modified because
  4111. even level numbers will become the next higher odd number."
  4112. (if org-odd-levels-only
  4113. (cond ((or (not change) (= 0 change)) (1+ (* 2 (/ level 2))))
  4114. ((> change 0) (1+ (* 2 (/ (+ level (* 2 change)) 2))))
  4115. ((< change 0) (max 1 (1+ (* 2 (/ (+ level (* 2 change)) 2))))))
  4116. (max 1 (+ level change))))
  4117. (if (boundp 'define-obsolete-function-alias)
  4118. (if (or (featurep 'xemacs) (< emacs-major-version 23))
  4119. (define-obsolete-function-alias 'org-get-legal-level
  4120. 'org-get-valid-level)
  4121. (define-obsolete-function-alias 'org-get-legal-level
  4122. 'org-get-valid-level "23.1")))
  4123. (defun org-promote ()
  4124. "Promote the current heading higher up the tree.
  4125. If the region is active in `transient-mark-mode', promote all headings
  4126. in the region."
  4127. (org-back-to-heading t)
  4128. (let* ((level (save-match-data (funcall outline-level)))
  4129. (up-head (concat (make-string (org-get-valid-level level -1) ?*) " "))
  4130. (diff (abs (- level (length up-head) -1))))
  4131. (if (= level 1) (error "Cannot promote to level 0. UNDO to recover if necessary"))
  4132. (replace-match up-head nil t)
  4133. ;; Fixup tag positioning
  4134. (and org-auto-align-tags (org-set-tags nil t))
  4135. (if org-adapt-indentation (org-fixup-indentation (- diff)))))
  4136. (defun org-demote ()
  4137. "Demote the current heading lower down the tree.
  4138. If the region is active in `transient-mark-mode', demote all headings
  4139. in the region."
  4140. (org-back-to-heading t)
  4141. (let* ((level (save-match-data (funcall outline-level)))
  4142. (down-head (concat (make-string (org-get-valid-level level 1) ?*) " "))
  4143. (diff (abs (- level (length down-head) -1))))
  4144. (replace-match down-head nil t)
  4145. ;; Fixup tag positioning
  4146. (and org-auto-align-tags (org-set-tags nil t))
  4147. (if org-adapt-indentation (org-fixup-indentation diff))))
  4148. (defun org-map-tree (fun)
  4149. "Call FUN for every heading underneath the current one."
  4150. (org-back-to-heading)
  4151. (let ((level (funcall outline-level)))
  4152. (save-excursion
  4153. (funcall fun)
  4154. (while (and (progn
  4155. (outline-next-heading)
  4156. (> (funcall outline-level) level))
  4157. (not (eobp)))
  4158. (funcall fun)))))
  4159. (defun org-map-region (fun beg end)
  4160. "Call FUN for every heading between BEG and END."
  4161. (let ((org-ignore-region t))
  4162. (save-excursion
  4163. (setq end (copy-marker end))
  4164. (goto-char beg)
  4165. (if (and (re-search-forward (concat "^" outline-regexp) nil t)
  4166. (< (point) end))
  4167. (funcall fun))
  4168. (while (and (progn
  4169. (outline-next-heading)
  4170. (< (point) end))
  4171. (not (eobp)))
  4172. (funcall fun)))))
  4173. (defun org-fixup-indentation (diff)
  4174. "Change the indentation in the current entry by DIFF
  4175. However, if any line in the current entry has no indentation, or if it
  4176. would end up with no indentation after the change, nothing at all is done."
  4177. (save-excursion
  4178. (let ((end (save-excursion (outline-next-heading)
  4179. (point-marker)))
  4180. (prohibit (if (> diff 0)
  4181. "^\\S-"
  4182. (concat "^ \\{0," (int-to-string (- diff)) "\\}\\S-")))
  4183. col)
  4184. (unless (save-excursion (end-of-line 1)
  4185. (re-search-forward prohibit end t))
  4186. (while (and (< (point) end)
  4187. (re-search-forward "^[ \t]+" end t))
  4188. (goto-char (match-end 0))
  4189. (setq col (current-column))
  4190. (if (< diff 0) (replace-match ""))
  4191. (indent-to (+ diff col))))
  4192. (move-marker end nil))))
  4193. (defun org-convert-to-odd-levels ()
  4194. "Convert an org-mode file with all levels allowed to one with odd levels.
  4195. This will leave level 1 alone, convert level 2 to level 3, level 3 to
  4196. level 5 etc."
  4197. (interactive)
  4198. (when (yes-or-no-p "Are you sure you want to globally change levels to odd? ")
  4199. (let ((org-odd-levels-only nil) n)
  4200. (save-excursion
  4201. (goto-char (point-min))
  4202. (while (re-search-forward "^\\*\\*+ " nil t)
  4203. (setq n (- (length (match-string 0)) 2))
  4204. (while (>= (setq n (1- n)) 0)
  4205. (org-demote))
  4206. (end-of-line 1))))))
  4207. (defun org-convert-to-oddeven-levels ()
  4208. "Convert an org-mode file with only odd levels to one with odd and even levels.
  4209. This promotes level 3 to level 2, level 5 to level 3 etc. If the file contains a
  4210. section with an even level, conversion would destroy the structure of the file. An error
  4211. is signaled in this case."
  4212. (interactive)
  4213. (goto-char (point-min))
  4214. ;; First check if there are no even levels
  4215. (when (re-search-forward "^\\(\\*\\*\\)+ " nil t)
  4216. (org-show-context t)
  4217. (error "Not all levels are odd in this file. Conversion not possible."))
  4218. (when (yes-or-no-p "Are you sure you want to globally change levels to odd-even? ")
  4219. (let ((org-odd-levels-only nil) n)
  4220. (save-excursion
  4221. (goto-char (point-min))
  4222. (while (re-search-forward "^\\*\\*+ " nil t)
  4223. (setq n (/ (1- (length (match-string 0))) 2))
  4224. (while (>= (setq n (1- n)) 0)
  4225. (org-promote))
  4226. (end-of-line 1))))))
  4227. (defun org-tr-level (n)
  4228. "Make N odd if required."
  4229. (if org-odd-levels-only (1+ (/ n 2)) n))
  4230. ;;; Vertical tree motion, cutting and pasting of subtrees
  4231. (defun org-move-subtree-up (&optional arg)
  4232. "Move the current subtree up past ARG headlines of the same level."
  4233. (interactive "p")
  4234. (org-move-subtree-down (- (prefix-numeric-value arg))))
  4235. (defun org-move-subtree-down (&optional arg)
  4236. "Move the current subtree down past ARG headlines of the same level."
  4237. (interactive "p")
  4238. (setq arg (prefix-numeric-value arg))
  4239. (let ((movfunc (if (> arg 0) 'outline-get-next-sibling
  4240. 'outline-get-last-sibling))
  4241. (ins-point (make-marker))
  4242. (cnt (abs arg))
  4243. beg beg0 end txt folded ne-beg ne-end ne-ins ins-end)
  4244. ;; Select the tree
  4245. (org-back-to-heading)
  4246. (setq beg0 (point))
  4247. (save-excursion
  4248. (setq ne-beg (org-back-over-empty-lines))
  4249. (setq beg (point)))
  4250. (save-match-data
  4251. (save-excursion (outline-end-of-heading)
  4252. (setq folded (org-invisible-p)))
  4253. (outline-end-of-subtree))
  4254. (outline-next-heading)
  4255. (setq ne-end (org-back-over-empty-lines))
  4256. (setq end (point))
  4257. (goto-char beg0)
  4258. (when (and (> arg 0) (org-first-sibling-p) (< ne-end ne-beg))
  4259. ;; include less whitespace
  4260. (save-excursion
  4261. (goto-char beg)
  4262. (forward-line (- ne-beg ne-end))
  4263. (setq beg (point))))
  4264. ;; Find insertion point, with error handling
  4265. (while (> cnt 0)
  4266. (or (and (funcall movfunc) (looking-at outline-regexp))
  4267. (progn (goto-char beg0)
  4268. (error "Cannot move past superior level or buffer limit")))
  4269. (setq cnt (1- cnt)))
  4270. (if (> arg 0)
  4271. ;; Moving forward - still need to move over subtree
  4272. (progn (org-end-of-subtree t t)
  4273. (save-excursion
  4274. (org-back-over-empty-lines)
  4275. (or (bolp) (newline)))))
  4276. (setq ne-ins (org-back-over-empty-lines))
  4277. (move-marker ins-point (point))
  4278. (setq txt (buffer-substring beg end))
  4279. (org-save-markers-in-region beg end)
  4280. (delete-region beg end)
  4281. (outline-flag-region (1- beg) beg nil)
  4282. (outline-flag-region (1- (point)) (point) nil)
  4283. (let ((bbb (point)))
  4284. (insert-before-markers txt)
  4285. (org-reinstall-markers-in-region bbb)
  4286. (move-marker ins-point bbb))
  4287. (or (bolp) (insert "\n"))
  4288. (setq ins-end (point))
  4289. (goto-char ins-point)
  4290. (org-skip-whitespace)
  4291. (when (and (< arg 0)
  4292. (org-first-sibling-p)
  4293. (> ne-ins ne-beg))
  4294. ;; Move whitespace back to beginning
  4295. (save-excursion
  4296. (goto-char ins-end)
  4297. (let ((kill-whole-line t))
  4298. (kill-line (- ne-ins ne-beg)) (point)))
  4299. (insert (make-string (- ne-ins ne-beg) ?\n)))
  4300. (move-marker ins-point nil)
  4301. (org-compact-display-after-subtree-move)
  4302. (unless folded
  4303. (org-show-entry)
  4304. (show-children)
  4305. (org-cycle-hide-drawers 'children))))
  4306. (defvar org-subtree-clip ""
  4307. "Clipboard for cut and paste of subtrees.
  4308. This is actually only a copy of the kill, because we use the normal kill
  4309. ring. We need it to check if the kill was created by `org-copy-subtree'.")
  4310. (defvar org-subtree-clip-folded nil
  4311. "Was the last copied subtree folded?
  4312. This is used to fold the tree back after pasting.")
  4313. (defun org-cut-subtree (&optional n)
  4314. "Cut the current subtree into the clipboard.
  4315. With prefix arg N, cut this many sequential subtrees.
  4316. This is a short-hand for marking the subtree and then cutting it."
  4317. (interactive "p")
  4318. (org-copy-subtree n 'cut))
  4319. (defun org-copy-subtree (&optional n cut force-store-markers)
  4320. "Cut the current subtree into the clipboard.
  4321. With prefix arg N, cut this many sequential subtrees.
  4322. This is a short-hand for marking the subtree and then copying it.
  4323. If CUT is non-nil, actually cut the subtree.
  4324. If FORCE-STORE-MARKERS is non-nil, store the relative locations
  4325. of some markers in the region, even if CUT is non-nil. This is
  4326. useful if the caller implements cut-and-paste as copy-then-paste-then-cut."
  4327. (interactive "p")
  4328. (let (beg end folded (beg0 (point)))
  4329. (if (interactive-p)
  4330. (org-back-to-heading nil) ; take what looks like a subtree
  4331. (org-back-to-heading t)) ; take what is really there
  4332. (org-back-over-empty-lines)
  4333. (setq beg (point))
  4334. (skip-chars-forward " \t\r\n")
  4335. (save-match-data
  4336. (save-excursion (outline-end-of-heading)
  4337. (setq folded (org-invisible-p)))
  4338. (condition-case nil
  4339. (outline-forward-same-level (1- n))
  4340. (error nil))
  4341. (org-end-of-subtree t t))
  4342. (org-back-over-empty-lines)
  4343. (setq end (point))
  4344. (goto-char beg0)
  4345. (when (> end beg)
  4346. (setq org-subtree-clip-folded folded)
  4347. (when (or cut force-store-markers)
  4348. (org-save-markers-in-region beg end))
  4349. (if cut (kill-region beg end) (copy-region-as-kill beg end))
  4350. (setq org-subtree-clip (current-kill 0))
  4351. (message "%s: Subtree(s) with %d characters"
  4352. (if cut "Cut" "Copied")
  4353. (length org-subtree-clip)))))
  4354. (defun org-paste-subtree (&optional level tree)
  4355. "Paste the clipboard as a subtree, with modification of headline level.
  4356. The entire subtree is promoted or demoted in order to match a new headline
  4357. level. By default, the new level is derived from the visible headings
  4358. before and after the insertion point, and taken to be the inferior headline
  4359. level of the two. So if the previous visible heading is level 3 and the
  4360. next is level 4 (or vice versa), level 4 will be used for insertion.
  4361. This makes sure that the subtree remains an independent subtree and does
  4362. not swallow low level entries.
  4363. You can also force a different level, either by using a numeric prefix
  4364. argument, or by inserting the heading marker by hand. For example, if the
  4365. cursor is after \"*****\", then the tree will be shifted to level 5.
  4366. If you want to insert the tree as is, just use \\[yank].
  4367. If optional TREE is given, use this text instead of the kill ring."
  4368. (interactive "P")
  4369. (unless (org-kill-is-subtree-p tree)
  4370. (error "%s"
  4371. (substitute-command-keys
  4372. "The kill is not a (set of) tree(s) - please use \\[yank] to yank anyway")))
  4373. (let* ((txt (or tree (and kill-ring (current-kill 0))))
  4374. (^re (concat "^\\(" outline-regexp "\\)"))
  4375. (re (concat "\\(" outline-regexp "\\)"))
  4376. (^re_ (concat "\\(\\*+\\)[ \t]*"))
  4377. (old-level (if (string-match ^re txt)
  4378. (- (match-end 0) (match-beginning 0) 1)
  4379. -1))
  4380. (force-level (cond (level (prefix-numeric-value level))
  4381. ((string-match
  4382. ^re_ (buffer-substring (point-at-bol) (point)))
  4383. (- (match-end 1) (match-beginning 1)))
  4384. (t nil)))
  4385. (previous-level (save-excursion
  4386. (condition-case nil
  4387. (progn
  4388. (outline-previous-visible-heading 1)
  4389. (if (looking-at re)
  4390. (- (match-end 0) (match-beginning 0) 1)
  4391. 1))
  4392. (error 1))))
  4393. (next-level (save-excursion
  4394. (condition-case nil
  4395. (progn
  4396. (or (looking-at outline-regexp)
  4397. (outline-next-visible-heading 1))
  4398. (if (looking-at re)
  4399. (- (match-end 0) (match-beginning 0) 1)
  4400. 1))
  4401. (error 1))))
  4402. (new-level (or force-level (max previous-level next-level)))
  4403. (shift (if (or (= old-level -1)
  4404. (= new-level -1)
  4405. (= old-level new-level))
  4406. 0
  4407. (- new-level old-level)))
  4408. (delta (if (> shift 0) -1 1))
  4409. (func (if (> shift 0) 'org-demote 'org-promote))
  4410. (org-odd-levels-only nil)
  4411. beg end)
  4412. ;; Remove the forced level indicator
  4413. (if force-level
  4414. (delete-region (point-at-bol) (point)))
  4415. ;; Paste
  4416. (beginning-of-line 1)
  4417. (org-back-over-empty-lines)
  4418. (setq beg (point))
  4419. (insert-before-markers txt)
  4420. (unless (string-match "\n\\'" txt) (insert "\n"))
  4421. (org-reinstall-markers-in-region beg)
  4422. (setq end (point))
  4423. (goto-char beg)
  4424. (skip-chars-forward " \t\n\r")
  4425. (setq beg (point))
  4426. ;; Shift if necessary
  4427. (unless (= shift 0)
  4428. (save-restriction
  4429. (narrow-to-region beg end)
  4430. (while (not (= shift 0))
  4431. (org-map-region func (point-min) (point-max))
  4432. (setq shift (+ delta shift)))
  4433. (goto-char (point-min))))
  4434. (when (interactive-p)
  4435. (message "Clipboard pasted as level %d subtree" new-level))
  4436. (if (and kill-ring
  4437. (eq org-subtree-clip (current-kill 0))
  4438. org-subtree-clip-folded)
  4439. ;; The tree was folded before it was killed/copied
  4440. (hide-subtree))))
  4441. (defun org-kill-is-subtree-p (&optional txt)
  4442. "Check if the current kill is an outline subtree, or a set of trees.
  4443. Returns nil if kill does not start with a headline, or if the first
  4444. headline level is not the largest headline level in the tree.
  4445. So this will actually accept several entries of equal levels as well,
  4446. which is OK for `org-paste-subtree'.
  4447. If optional TXT is given, check this string instead of the current kill."
  4448. (let* ((kill (or txt (and kill-ring (current-kill 0)) ""))
  4449. (start-level (and kill
  4450. (string-match (concat "\\`\\([ \t\n\r]*?\n\\)?\\("
  4451. org-outline-regexp "\\)")
  4452. kill)
  4453. (- (match-end 2) (match-beginning 2) 1)))
  4454. (re (concat "^" org-outline-regexp))
  4455. (start (1+ (match-beginning 2))))
  4456. (if (not start-level)
  4457. (progn
  4458. nil) ;; does not even start with a heading
  4459. (catch 'exit
  4460. (while (setq start (string-match re kill (1+ start)))
  4461. (when (< (- (match-end 0) (match-beginning 0) 1) start-level)
  4462. (throw 'exit nil)))
  4463. t))))
  4464. (defvar org-markers-to-move nil
  4465. "Markers that should be moved with a cut-and-paste operation.
  4466. Those markers are stored together with their positions relative to
  4467. the start of the region.")
  4468. (defun org-save-markers-in-region (beg end)
  4469. "Check markers in region.
  4470. If these markers are between BEG and END, record their position relative
  4471. to BEG, so that after moving the block of text, we can put the markers back
  4472. into place.
  4473. This function gets called just before an entry or tree gets cut from the
  4474. buffer. After re-insertion, `org-reinstall-markers-in-region' must be
  4475. called immediately, to move the markers with the entries."
  4476. (setq org-markers-to-move nil)
  4477. (when (featurep 'org-clock)
  4478. (org-clock-save-markers-for-cut-and-paste beg end))
  4479. (when (featurep 'org-agenda)
  4480. (org-agenda-save-markers-for-cut-and-paste beg end)))
  4481. (defun org-check-and-save-marker (marker beg end)
  4482. "Check if MARKER is between BEG and END.
  4483. If yes, remember the marker and the distance to BEG."
  4484. (when (and (marker-buffer marker)
  4485. (equal (marker-buffer marker) (current-buffer)))
  4486. (if (and (>= marker beg) (< marker end))
  4487. (push (cons marker (- marker beg)) org-markers-to-move))))
  4488. (defun org-reinstall-markers-in-region (beg)
  4489. "Move all remembered markers to their position relative to BEG."
  4490. (mapc (lambda (x)
  4491. (move-marker (car x) (+ beg (cdr x))))
  4492. org-markers-to-move)
  4493. (setq org-markers-to-move nil))
  4494. (defun org-narrow-to-subtree ()
  4495. "Narrow buffer to the current subtree."
  4496. (interactive)
  4497. (save-excursion
  4498. (save-match-data
  4499. (narrow-to-region
  4500. (progn (org-back-to-heading) (point))
  4501. (progn (org-end-of-subtree t t) (point))))))
  4502. ;;; Outline Sorting
  4503. (defun org-sort (with-case)
  4504. "Call `org-sort-entries-or-items' or `org-table-sort-lines'.
  4505. Optional argument WITH-CASE means sort case-sensitively."
  4506. (interactive "P")
  4507. (if (org-at-table-p)
  4508. (org-call-with-arg 'org-table-sort-lines with-case)
  4509. (org-call-with-arg 'org-sort-entries-or-items with-case)))
  4510. (defun org-sort-remove-invisible (s)
  4511. (remove-text-properties 0 (length s) org-rm-props s)
  4512. (while (string-match org-bracket-link-regexp s)
  4513. (setq s (replace-match (if (match-end 2)
  4514. (match-string 3 s)
  4515. (match-string 1 s)) t t s)))
  4516. s)
  4517. (defvar org-priority-regexp) ; defined later in the file
  4518. (defun org-sort-entries-or-items (&optional with-case sorting-type getkey-func property)
  4519. "Sort entries on a certain level of an outline tree.
  4520. If there is an active region, the entries in the region are sorted.
  4521. Else, if the cursor is before the first entry, sort the top-level items.
  4522. Else, the children of the entry at point are sorted.
  4523. Sorting can be alphabetically, numerically, and by date/time as given by
  4524. the first time stamp in the entry. The command prompts for the sorting
  4525. type unless it has been given to the function through the SORTING-TYPE
  4526. argument, which needs to a character, any of (?n ?N ?a ?A ?t ?T ?p ?P ?f ?F).
  4527. If the SORTING-TYPE is ?f or ?F, then GETKEY-FUNC specifies a function to be
  4528. called with point at the beginning of the record. It must return either
  4529. a string or a number that should serve as the sorting key for that record.
  4530. Comparing entries ignores case by default. However, with an optional argument
  4531. WITH-CASE, the sorting considers case as well."
  4532. (interactive "P")
  4533. (let ((case-func (if with-case 'identity 'downcase))
  4534. start beg end stars re re2
  4535. txt what tmp plain-list-p)
  4536. ;; Find beginning and end of region to sort
  4537. (cond
  4538. ((org-region-active-p)
  4539. ;; we will sort the region
  4540. (setq end (region-end)
  4541. what "region")
  4542. (goto-char (region-beginning))
  4543. (if (not (org-on-heading-p)) (outline-next-heading))
  4544. (setq start (point)))
  4545. ((org-at-item-p)
  4546. ;; we will sort this plain list
  4547. (org-beginning-of-item-list) (setq start (point))
  4548. (org-end-of-item-list) (setq end (point))
  4549. (goto-char start)
  4550. (setq plain-list-p t
  4551. what "plain list"))
  4552. ((or (org-on-heading-p)
  4553. (condition-case nil (progn (org-back-to-heading) t) (error nil)))
  4554. ;; we will sort the children of the current headline
  4555. (org-back-to-heading)
  4556. (setq start (point)
  4557. end (progn (org-end-of-subtree t t)
  4558. (org-back-over-empty-lines)
  4559. (point))
  4560. what "children")
  4561. (goto-char start)
  4562. (show-subtree)
  4563. (outline-next-heading))
  4564. (t
  4565. ;; we will sort the top-level entries in this file
  4566. (goto-char (point-min))
  4567. (or (org-on-heading-p) (outline-next-heading))
  4568. (setq start (point) end (point-max) what "top-level")
  4569. (goto-char start)
  4570. (show-all)))
  4571. (setq beg (point))
  4572. (if (>= beg end) (error "Nothing to sort"))
  4573. (unless plain-list-p
  4574. (looking-at "\\(\\*+\\)")
  4575. (setq stars (match-string 1)
  4576. re (concat "^" (regexp-quote stars) " +")
  4577. re2 (concat "^" (regexp-quote (substring stars 0 -1)) "[^*]")
  4578. txt (buffer-substring beg end))
  4579. (if (not (equal (substring txt -1) "\n")) (setq txt (concat txt "\n")))
  4580. (if (and (not (equal stars "*")) (string-match re2 txt))
  4581. (error "Region to sort contains a level above the first entry")))
  4582. (unless sorting-type
  4583. (message
  4584. (if plain-list-p
  4585. "Sort %s: [a]lpha [n]umeric [t]ime [f]unc A/N/T/F means reversed:"
  4586. "Sort %s: [a]lpha [n]umeric [t]ime [p]riority p[r]operty todo[o]rder [f]unc A/N/T/P/O/F means reversed:")
  4587. what)
  4588. (setq sorting-type (read-char-exclusive))
  4589. (and (= (downcase sorting-type) ?f)
  4590. (setq getkey-func
  4591. (completing-read "Sort using function: "
  4592. obarray 'fboundp t nil nil))
  4593. (setq getkey-func (intern getkey-func)))
  4594. (and (= (downcase sorting-type) ?r)
  4595. (setq property
  4596. (completing-read "Property: "
  4597. (mapcar 'list (org-buffer-property-keys t))
  4598. nil t))))
  4599. (message "Sorting entries...")
  4600. (save-restriction
  4601. (narrow-to-region start end)
  4602. (let ((dcst (downcase sorting-type))
  4603. (now (current-time)))
  4604. (sort-subr
  4605. (/= dcst sorting-type)
  4606. ;; This function moves to the beginning character of the "record" to
  4607. ;; be sorted.
  4608. (if plain-list-p
  4609. (lambda nil
  4610. (if (org-at-item-p) t (goto-char (point-max))))
  4611. (lambda nil
  4612. (if (re-search-forward re nil t)
  4613. (goto-char (match-beginning 0))
  4614. (goto-char (point-max)))))
  4615. ;; This function moves to the last character of the "record" being
  4616. ;; sorted.
  4617. (if plain-list-p
  4618. 'org-end-of-item
  4619. (lambda nil
  4620. (save-match-data
  4621. (condition-case nil
  4622. (outline-forward-same-level 1)
  4623. (error
  4624. (goto-char (point-max)))))))
  4625. ;; This function returns the value that gets sorted against.
  4626. (if plain-list-p
  4627. (lambda nil
  4628. (when (looking-at "[ \t]*[-+*0-9.)]+[ \t]+")
  4629. (cond
  4630. ((= dcst ?n)
  4631. (string-to-number (buffer-substring (match-end 0)
  4632. (point-at-eol))))
  4633. ((= dcst ?a)
  4634. (buffer-substring (match-end 0) (point-at-eol)))
  4635. ((= dcst ?t)
  4636. (if (re-search-forward org-ts-regexp
  4637. (point-at-eol) t)
  4638. (org-time-string-to-time (match-string 0))
  4639. now))
  4640. ((= dcst ?f)
  4641. (if getkey-func
  4642. (progn
  4643. (setq tmp (funcall getkey-func))
  4644. (if (stringp tmp) (setq tmp (funcall case-func tmp)))
  4645. tmp)
  4646. (error "Invalid key function `%s'" getkey-func)))
  4647. (t (error "Invalid sorting type `%c'" sorting-type)))))
  4648. (lambda nil
  4649. (cond
  4650. ((= dcst ?n)
  4651. (if (looking-at outline-regexp)
  4652. (string-to-number (buffer-substring (match-end 0)
  4653. (point-at-eol)))
  4654. nil))
  4655. ((= dcst ?a)
  4656. (funcall case-func (buffer-substring (point-at-bol)
  4657. (point-at-eol))))
  4658. ((= dcst ?t)
  4659. (if (re-search-forward org-ts-regexp
  4660. (save-excursion
  4661. (forward-line 2)
  4662. (point)) t)
  4663. (org-time-string-to-time (match-string 0))
  4664. now))
  4665. ((= dcst ?p)
  4666. (if (re-search-forward org-priority-regexp (point-at-eol) t)
  4667. (string-to-char (match-string 2))
  4668. org-default-priority))
  4669. ((= dcst ?r)
  4670. (or (org-entry-get nil property) ""))
  4671. ((= dcst ?o)
  4672. (if (looking-at org-complex-heading-regexp)
  4673. (- 9999 (length (member (match-string 2)
  4674. org-todo-keywords-1)))))
  4675. ((= dcst ?f)
  4676. (if getkey-func
  4677. (progn
  4678. (setq tmp (funcall getkey-func))
  4679. (if (stringp tmp) (setq tmp (funcall case-func tmp)))
  4680. tmp)
  4681. (error "Invalid key function `%s'" getkey-func)))
  4682. (t (error "Invalid sorting type `%c'" sorting-type)))))
  4683. nil
  4684. (cond
  4685. ((= dcst ?a) 'string<)
  4686. ((= dcst ?t) 'time-less-p)
  4687. (t nil)))))
  4688. (message "Sorting entries...done")))
  4689. (defun org-do-sort (table what &optional with-case sorting-type)
  4690. "Sort TABLE of WHAT according to SORTING-TYPE.
  4691. The user will be prompted for the SORTING-TYPE if the call to this
  4692. function does not specify it. WHAT is only for the prompt, to indicate
  4693. what is being sorted. The sorting key will be extracted from
  4694. the car of the elements of the table.
  4695. If WITH-CASE is non-nil, the sorting will be case-sensitive."
  4696. (unless sorting-type
  4697. (message
  4698. "Sort %s: [a]lphabetic. [n]umeric. [t]ime. A/N/T means reversed:"
  4699. what)
  4700. (setq sorting-type (read-char-exclusive)))
  4701. (let ((dcst (downcase sorting-type))
  4702. extractfun comparefun)
  4703. ;; Define the appropriate functions
  4704. (cond
  4705. ((= dcst ?n)
  4706. (setq extractfun 'string-to-number
  4707. comparefun (if (= dcst sorting-type) '< '>)))
  4708. ((= dcst ?a)
  4709. (setq extractfun (if with-case (lambda(x) (org-sort-remove-invisible x))
  4710. (lambda(x) (downcase (org-sort-remove-invisible x))))
  4711. comparefun (if (= dcst sorting-type)
  4712. 'string<
  4713. (lambda (a b) (and (not (string< a b))
  4714. (not (string= a b)))))))
  4715. ((= dcst ?t)
  4716. (setq extractfun
  4717. (lambda (x)
  4718. (if (string-match org-ts-regexp x)
  4719. (time-to-seconds
  4720. (org-time-string-to-time (match-string 0 x)))
  4721. 0))
  4722. comparefun (if (= dcst sorting-type) '< '>)))
  4723. (t (error "Invalid sorting type `%c'" sorting-type)))
  4724. (sort (mapcar (lambda (x) (cons (funcall extractfun (car x)) (cdr x)))
  4725. table)
  4726. (lambda (a b) (funcall comparefun (car a) (car b))))))
  4727. ;;;; Plain list items, including checkboxes
  4728. ;;; Plain list items
  4729. (defun org-at-item-p ()
  4730. "Is point in a line starting a hand-formatted item?"
  4731. (let ((llt org-plain-list-ordered-item-terminator))
  4732. (save-excursion
  4733. (goto-char (point-at-bol))
  4734. (looking-at
  4735. (cond
  4736. ((eq llt t) "\\([ \t]*\\([-+]\\|\\([0-9]+[.)]\\)\\)\\|[ \t]+\\*\\)\\( \\|$\\)")
  4737. ((= llt ?.) "\\([ \t]*\\([-+]\\|\\([0-9]+\\.\\)\\)\\|[ \t]+\\*\\)\\( \\|$\\)")
  4738. ((= llt ?\)) "\\([ \t]*\\([-+]\\|\\([0-9]+))\\)\\|[ \t]+\\*\\)\\( \\|$\\)")
  4739. (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))))))
  4740. (defun org-in-item-p ()
  4741. "It the cursor inside a plain list item.
  4742. Does not have to be the first line."
  4743. (save-excursion
  4744. (condition-case nil
  4745. (progn
  4746. (org-beginning-of-item)
  4747. (org-at-item-p)
  4748. t)
  4749. (error nil))))
  4750. (defun org-insert-item (&optional checkbox)
  4751. "Insert a new item at the current level.
  4752. Return t when things worked, nil when we are not in an item."
  4753. (when (save-excursion
  4754. (condition-case nil
  4755. (progn
  4756. (org-beginning-of-item)
  4757. (org-at-item-p)
  4758. (if (org-invisible-p) (error "Invisible item"))
  4759. t)
  4760. (error nil)))
  4761. (let* ((bul (match-string 0))
  4762. (eow (save-excursion (beginning-of-line 1) (looking-at "[ \t]*")
  4763. (match-end 0)))
  4764. (blank (cdr (assq 'plain-list-item org-blank-before-new-entry)))
  4765. pos)
  4766. (cond
  4767. ((and (org-at-item-p) (<= (point) eow))
  4768. ;; before the bullet
  4769. (beginning-of-line 1)
  4770. (open-line (if blank 2 1)))
  4771. ((<= (point) eow)
  4772. (beginning-of-line 1))
  4773. (t
  4774. (unless (org-get-alist-option org-M-RET-may-split-line 'item)
  4775. (end-of-line 1)
  4776. (delete-horizontal-space))
  4777. (newline (if blank 2 1))))
  4778. (insert bul (if checkbox "[ ]" ""))
  4779. (just-one-space)
  4780. (setq pos (point))
  4781. (end-of-line 1)
  4782. (unless (= (point) pos) (just-one-space) (backward-delete-char 1)))
  4783. (org-maybe-renumber-ordered-list)
  4784. (and checkbox (org-update-checkbox-count-maybe))
  4785. t))
  4786. ;;; Checkboxes
  4787. (defun org-at-item-checkbox-p ()
  4788. "Is point at a line starting a plain-list item with a checklet?"
  4789. (and (org-at-item-p)
  4790. (save-excursion
  4791. (goto-char (match-end 0))
  4792. (skip-chars-forward " \t")
  4793. (looking-at "\\[[- X]\\]"))))
  4794. (defun org-toggle-checkbox (&optional arg)
  4795. "Toggle the checkbox in the current line."
  4796. (interactive "P")
  4797. (catch 'exit
  4798. (let (beg end status (firstnew 'unknown))
  4799. (cond
  4800. ((org-region-active-p)
  4801. (setq beg (region-beginning) end (region-end)))
  4802. ((org-on-heading-p)
  4803. (setq beg (point) end (save-excursion (outline-next-heading) (point))))
  4804. ((org-at-item-checkbox-p)
  4805. (let ((pos (point)))
  4806. (replace-match
  4807. (cond (arg "[-]")
  4808. ((member (match-string 0) '("[ ]" "[-]")) "[X]")
  4809. (t "[ ]"))
  4810. t t)
  4811. (goto-char pos))
  4812. (throw 'exit t))
  4813. (t (error "Not at a checkbox or heading, and no active region")))
  4814. (save-excursion
  4815. (goto-char beg)
  4816. (while (< (point) end)
  4817. (when (org-at-item-checkbox-p)
  4818. (setq status (equal (match-string 0) "[X]"))
  4819. (when (eq firstnew 'unknown)
  4820. (setq firstnew (not status)))
  4821. (replace-match
  4822. (if (if arg (not status) firstnew) "[X]" "[ ]") t t))
  4823. (beginning-of-line 2)))))
  4824. (org-update-checkbox-count-maybe))
  4825. (defun org-update-checkbox-count-maybe ()
  4826. "Update checkbox statistics unless turned off by user."
  4827. (when org-provide-checkbox-statistics
  4828. (org-update-checkbox-count)))
  4829. (defun org-update-checkbox-count (&optional all)
  4830. "Update the checkbox statistics in the current section.
  4831. This will find all statistic cookies like [57%] and [6/12] and update them
  4832. with the current numbers. With optional prefix argument ALL, do this for
  4833. the whole buffer."
  4834. (interactive "P")
  4835. (save-excursion
  4836. (let* ((buffer-invisibility-spec (org-inhibit-invisibility)) ; Emacs 21
  4837. (beg (condition-case nil
  4838. (progn (outline-back-to-heading) (point))
  4839. (error (point-min))))
  4840. (end (move-marker (make-marker)
  4841. (progn (outline-next-heading) (point))))
  4842. (re "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)")
  4843. (re-box "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(\\[[- X]\\]\\)")
  4844. (re-find (concat re "\\|" re-box))
  4845. beg-cookie end-cookie is-percent c-on c-off lim
  4846. eline curr-ind next-ind continue-from startsearch
  4847. (cstat 0)
  4848. )
  4849. (when all
  4850. (goto-char (point-min))
  4851. (outline-next-heading)
  4852. (setq beg (point) end (point-max)))
  4853. (goto-char end)
  4854. ;; find each statistic cookie
  4855. (while (re-search-backward re-find beg t)
  4856. (setq beg-cookie (match-beginning 1)
  4857. end-cookie (match-end 1)
  4858. cstat (+ cstat (if end-cookie 1 0))
  4859. startsearch (point-at-eol)
  4860. continue-from (point-at-bol)
  4861. is-percent (match-beginning 2)
  4862. lim (cond
  4863. ((org-on-heading-p) (outline-next-heading) (point))
  4864. ((org-at-item-p) (org-end-of-item) (point))
  4865. (t nil))
  4866. c-on 0
  4867. c-off 0)
  4868. (when lim
  4869. ;; find first checkbox for this cookie and gather
  4870. ;; statistics from all that are at this indentation level
  4871. (goto-char startsearch)
  4872. (if (re-search-forward re-box lim t)
  4873. (progn
  4874. (org-beginning-of-item)
  4875. (setq curr-ind (org-get-indentation))
  4876. (setq next-ind curr-ind)
  4877. (while (and (bolp) (org-at-item-p) (= curr-ind next-ind))
  4878. (save-excursion (end-of-line) (setq eline (point)))
  4879. (if (re-search-forward re-box eline t)
  4880. (if (member (match-string 2) '("[ ]" "[-]"))
  4881. (setq c-off (1+ c-off))
  4882. (setq c-on (1+ c-on))
  4883. )
  4884. )
  4885. (org-end-of-item)
  4886. (setq next-ind (org-get-indentation))
  4887. )))
  4888. (goto-char continue-from)
  4889. ;; update cookie
  4890. (when end-cookie
  4891. (delete-region beg-cookie end-cookie)
  4892. (goto-char beg-cookie)
  4893. (insert
  4894. (if is-percent
  4895. (format "[%d%%]" (/ (* 100 c-on) (max 1 (+ c-on c-off))))
  4896. (format "[%d/%d]" c-on (+ c-on c-off)))))
  4897. ;; update items checkbox if it has one
  4898. (when (org-at-item-p)
  4899. (org-beginning-of-item)
  4900. (when (and (> (+ c-on c-off) 0)
  4901. (re-search-forward re-box (point-at-eol) t))
  4902. (setq beg-cookie (match-beginning 2)
  4903. end-cookie (match-end 2))
  4904. (delete-region beg-cookie end-cookie)
  4905. (goto-char beg-cookie)
  4906. (cond ((= c-off 0) (insert "[X]"))
  4907. ((= c-on 0) (insert "[ ]"))
  4908. (t (insert "[-]")))
  4909. )))
  4910. (goto-char continue-from))
  4911. (when (interactive-p)
  4912. (message "Checkbox satistics updated %s (%d places)"
  4913. (if all "in entire file" "in current outline entry") cstat)))))
  4914. (defun org-get-checkbox-statistics-face ()
  4915. "Select the face for checkbox statistics.
  4916. The face will be `org-done' when all relevant boxes are checked. Otherwise
  4917. it will be `org-todo'."
  4918. (if (match-end 1)
  4919. (if (equal (match-string 1) "100%") 'org-done 'org-todo)
  4920. (if (and (> (match-end 2) (match-beginning 2))
  4921. (equal (match-string 2) (match-string 3)))
  4922. 'org-done
  4923. 'org-todo)))
  4924. (defun org-get-indentation (&optional line)
  4925. "Get the indentation of the current line, interpreting tabs.
  4926. When LINE is given, assume it represents a line and compute its indentation."
  4927. (if line
  4928. (if (string-match "^ *" (org-remove-tabs line))
  4929. (match-end 0))
  4930. (save-excursion
  4931. (beginning-of-line 1)
  4932. (skip-chars-forward " \t")
  4933. (current-column))))
  4934. (defun org-remove-tabs (s &optional width)
  4935. "Replace tabulators in S with spaces.
  4936. Assumes that s is a single line, starting in column 0."
  4937. (setq width (or width tab-width))
  4938. (while (string-match "\t" s)
  4939. (setq s (replace-match
  4940. (make-string
  4941. (- (* width (/ (+ (match-beginning 0) width) width))
  4942. (match-beginning 0)) ?\ )
  4943. t t s)))
  4944. s)
  4945. (defun org-fix-indentation (line ind)
  4946. "Fix indentation in LINE.
  4947. IND is a cons cell with target and minimum indentation.
  4948. If the current indenation in LINE is smaller than the minimum,
  4949. leave it alone. If it is larger than ind, set it to the target."
  4950. (let* ((l (org-remove-tabs line))
  4951. (i (org-get-indentation l))
  4952. (i1 (car ind)) (i2 (cdr ind)))
  4953. (if (>= i i2) (setq l (substring line i2)))
  4954. (if (> i1 0)
  4955. (concat (make-string i1 ?\ ) l)
  4956. l)))
  4957. (defun org-beginning-of-item ()
  4958. "Go to the beginning of the current hand-formatted item.
  4959. If the cursor is not in an item, throw an error."
  4960. (interactive)
  4961. (let ((pos (point))
  4962. (limit (save-excursion
  4963. (condition-case nil
  4964. (progn
  4965. (org-back-to-heading)
  4966. (beginning-of-line 2) (point))
  4967. (error (point-min)))))
  4968. (ind-empty (if org-empty-line-terminates-plain-lists 0 10000))
  4969. ind ind1)
  4970. (if (org-at-item-p)
  4971. (beginning-of-line 1)
  4972. (beginning-of-line 1)
  4973. (skip-chars-forward " \t")
  4974. (setq ind (current-column))
  4975. (if (catch 'exit
  4976. (while t
  4977. (beginning-of-line 0)
  4978. (if (or (bobp) (< (point) limit)) (throw 'exit nil))
  4979. (if (looking-at "[ \t]*$")
  4980. (setq ind1 ind-empty)
  4981. (skip-chars-forward " \t")
  4982. (setq ind1 (current-column)))
  4983. (if (< ind1 ind)
  4984. (progn (beginning-of-line 1) (throw 'exit (org-at-item-p))))))
  4985. nil
  4986. (goto-char pos)
  4987. (error "Not in an item")))))
  4988. (defun org-end-of-item ()
  4989. "Go to the end of the current hand-formatted item.
  4990. If the cursor is not in an item, throw an error."
  4991. (interactive)
  4992. (let* ((pos (point))
  4993. ind1
  4994. (ind-empty (if org-empty-line-terminates-plain-lists 0 10000))
  4995. (limit (save-excursion (outline-next-heading) (point)))
  4996. (ind (save-excursion
  4997. (org-beginning-of-item)
  4998. (skip-chars-forward " \t")
  4999. (current-column)))
  5000. (end (catch 'exit
  5001. (while t
  5002. (beginning-of-line 2)
  5003. (if (eobp) (throw 'exit (point)))
  5004. (if (>= (point) limit) (throw 'exit (point-at-bol)))
  5005. (if (looking-at "[ \t]*$")
  5006. (setq ind1 ind-empty)
  5007. (skip-chars-forward " \t")
  5008. (setq ind1 (current-column)))
  5009. (if (<= ind1 ind)
  5010. (throw 'exit (point-at-bol)))))))
  5011. (if end
  5012. (goto-char end)
  5013. (goto-char pos)
  5014. (error "Not in an item"))))
  5015. (defun org-next-item ()
  5016. "Move to the beginning of the next item in the current plain list.
  5017. Error if not at a plain list, or if this is the last item in the list."
  5018. (interactive)
  5019. (let (ind ind1 (pos (point)))
  5020. (org-beginning-of-item)
  5021. (setq ind (org-get-indentation))
  5022. (org-end-of-item)
  5023. (setq ind1 (org-get-indentation))
  5024. (unless (and (org-at-item-p) (= ind ind1))
  5025. (goto-char pos)
  5026. (error "On last item"))))
  5027. (defun org-previous-item ()
  5028. "Move to the beginning of the previous item in the current plain list.
  5029. Error if not at a plain list, or if this is the first item in the list."
  5030. (interactive)
  5031. (let (beg ind ind1 (pos (point)))
  5032. (org-beginning-of-item)
  5033. (setq beg (point))
  5034. (setq ind (org-get-indentation))
  5035. (goto-char beg)
  5036. (catch 'exit
  5037. (while t
  5038. (beginning-of-line 0)
  5039. (if (looking-at "[ \t]*$")
  5040. nil
  5041. (if (<= (setq ind1 (org-get-indentation)) ind)
  5042. (throw 'exit t)))))
  5043. (condition-case nil
  5044. (if (or (not (org-at-item-p))
  5045. (< ind1 (1- ind)))
  5046. (error "")
  5047. (org-beginning-of-item))
  5048. (error (goto-char pos)
  5049. (error "On first item")))))
  5050. (defun org-first-list-item-p ()
  5051. "Is this heading the item in a plain list?"
  5052. (unless (org-at-item-p)
  5053. (error "Not at a plain list item"))
  5054. (org-beginning-of-item)
  5055. (= (point) (save-excursion (org-beginning-of-item-list))))
  5056. (defun org-move-item-down ()
  5057. "Move the plain list item at point down, i.e. swap with following item.
  5058. Subitems (items with larger indentation) are considered part of the item,
  5059. so this really moves item trees."
  5060. (interactive)
  5061. (let (beg beg0 end end0 ind ind1 (pos (point)) txt ne-end ne-beg)
  5062. (org-beginning-of-item)
  5063. (setq beg0 (point))
  5064. (save-excursion
  5065. (setq ne-beg (org-back-over-empty-lines))
  5066. (setq beg (point)))
  5067. (goto-char beg0)
  5068. (setq ind (org-get-indentation))
  5069. (org-end-of-item)
  5070. (setq end0 (point))
  5071. (setq ind1 (org-get-indentation))
  5072. (setq ne-end (org-back-over-empty-lines))
  5073. (setq end (point))
  5074. (goto-char beg0)
  5075. (when (and (org-first-list-item-p) (< ne-end ne-beg))
  5076. ;; include less whitespace
  5077. (save-excursion
  5078. (goto-char beg)
  5079. (forward-line (- ne-beg ne-end))
  5080. (setq beg (point))))
  5081. (goto-char end0)
  5082. (if (and (org-at-item-p) (= ind ind1))
  5083. (progn
  5084. (org-end-of-item)
  5085. (org-back-over-empty-lines)
  5086. (setq txt (buffer-substring beg end))
  5087. (save-excursion
  5088. (delete-region beg end))
  5089. (setq pos (point))
  5090. (insert txt)
  5091. (goto-char pos) (org-skip-whitespace)
  5092. (org-maybe-renumber-ordered-list))
  5093. (goto-char pos)
  5094. (error "Cannot move this item further down"))))
  5095. (defun org-move-item-up (arg)
  5096. "Move the plain list item at point up, i.e. swap with previous item.
  5097. Subitems (items with larger indentation) are considered part of the item,
  5098. so this really moves item trees."
  5099. (interactive "p")
  5100. (let (beg beg0 end ind ind1 (pos (point)) txt
  5101. ne-beg ne-ins ins-end)
  5102. (org-beginning-of-item)
  5103. (setq beg0 (point))
  5104. (setq ind (org-get-indentation))
  5105. (save-excursion
  5106. (setq ne-beg (org-back-over-empty-lines))
  5107. (setq beg (point)))
  5108. (goto-char beg0)
  5109. (org-end-of-item)
  5110. (setq end (point))
  5111. (goto-char beg0)
  5112. (catch 'exit
  5113. (while t
  5114. (beginning-of-line 0)
  5115. (if (looking-at "[ \t]*$")
  5116. (if org-empty-line-terminates-plain-lists
  5117. (progn
  5118. (goto-char pos)
  5119. (error "Cannot move this item further up"))
  5120. nil)
  5121. (if (<= (setq ind1 (org-get-indentation)) ind)
  5122. (throw 'exit t)))))
  5123. (condition-case nil
  5124. (org-beginning-of-item)
  5125. (error (goto-char beg)
  5126. (error "Cannot move this item further up")))
  5127. (setq ind1 (org-get-indentation))
  5128. (if (and (org-at-item-p) (= ind ind1))
  5129. (progn
  5130. (setq ne-ins (org-back-over-empty-lines))
  5131. (setq txt (buffer-substring beg end))
  5132. (save-excursion
  5133. (delete-region beg end))
  5134. (setq pos (point))
  5135. (insert txt)
  5136. (setq ins-end (point))
  5137. (goto-char pos) (org-skip-whitespace)
  5138. (when (and (org-first-list-item-p) (> ne-ins ne-beg))
  5139. ;; Move whitespace back to beginning
  5140. (save-excursion
  5141. (goto-char ins-end)
  5142. (let ((kill-whole-line t))
  5143. (kill-line (- ne-ins ne-beg)) (point)))
  5144. (insert (make-string (- ne-ins ne-beg) ?\n)))
  5145. (org-maybe-renumber-ordered-list))
  5146. (goto-char pos)
  5147. (error "Cannot move this item further up"))))
  5148. (defun org-maybe-renumber-ordered-list ()
  5149. "Renumber the ordered list at point if setup allows it.
  5150. This tests the user option `org-auto-renumber-ordered-lists' before
  5151. doing the renumbering."
  5152. (interactive)
  5153. (when (and org-auto-renumber-ordered-lists
  5154. (org-at-item-p))
  5155. (if (match-beginning 3)
  5156. (org-renumber-ordered-list 1)
  5157. (org-fix-bullet-type))))
  5158. (defun org-maybe-renumber-ordered-list-safe ()
  5159. (condition-case nil
  5160. (save-excursion
  5161. (org-maybe-renumber-ordered-list))
  5162. (error nil)))
  5163. (defun org-cycle-list-bullet (&optional which)
  5164. "Cycle through the different itemize/enumerate bullets.
  5165. This cycle the entire list level through the sequence:
  5166. `-' -> `+' -> `*' -> `1.' -> `1)'
  5167. If WHICH is a string, use that as the new bullet. If WHICH is an integer,
  5168. 0 meand `-', 1 means `+' etc."
  5169. (interactive "P")
  5170. (org-preserve-lc
  5171. (org-beginning-of-item-list)
  5172. (org-at-item-p)
  5173. (beginning-of-line 1)
  5174. (let ((current (match-string 0))
  5175. (prevp (eq which 'previous))
  5176. new)
  5177. (setq new (cond
  5178. ((and (numberp which)
  5179. (nth (1- which) '("-" "+" "*" "1." "1)"))))
  5180. ((string-match "-" current) (if prevp "1)" "+"))
  5181. ((string-match "\\+" current)
  5182. (if prevp "-" (if (looking-at "\\S-") "1." "*")))
  5183. ((string-match "\\*" current) (if prevp "+" "1."))
  5184. ((string-match "\\." current) (if prevp "*" "1)"))
  5185. ((string-match ")" current) (if prevp "1." "-"))
  5186. (t (error "This should not happen"))))
  5187. (and (looking-at "\\([ \t]*\\)\\S-+") (replace-match (concat "\\1" new)))
  5188. (org-fix-bullet-type)
  5189. (org-maybe-renumber-ordered-list))))
  5190. (defun org-get-string-indentation (s)
  5191. "What indentation has S due to SPACE and TAB at the beginning of the string?"
  5192. (let ((n -1) (i 0) (w tab-width) c)
  5193. (catch 'exit
  5194. (while (< (setq n (1+ n)) (length s))
  5195. (setq c (aref s n))
  5196. (cond ((= c ?\ ) (setq i (1+ i)))
  5197. ((= c ?\t) (setq i (* (/ (+ w i) w) w)))
  5198. (t (throw 'exit t)))))
  5199. i))
  5200. (defun org-renumber-ordered-list (arg)
  5201. "Renumber an ordered plain list.
  5202. Cursor needs to be in the first line of an item, the line that starts
  5203. with something like \"1.\" or \"2)\"."
  5204. (interactive "p")
  5205. (unless (and (org-at-item-p)
  5206. (match-beginning 3))
  5207. (error "This is not an ordered list"))
  5208. (let ((line (org-current-line))
  5209. (col (current-column))
  5210. (ind (org-get-string-indentation
  5211. (buffer-substring (point-at-bol) (match-beginning 3))))
  5212. ;; (term (substring (match-string 3) -1))
  5213. ind1 (n (1- arg))
  5214. fmt)
  5215. ;; find where this list begins
  5216. (org-beginning-of-item-list)
  5217. (looking-at "[ \t]*[0-9]+\\([.)]\\)")
  5218. (setq fmt (concat "%d" (match-string 1)))
  5219. (beginning-of-line 0)
  5220. ;; walk forward and replace these numbers
  5221. (catch 'exit
  5222. (while t
  5223. (catch 'next
  5224. (beginning-of-line 2)
  5225. (if (eobp) (throw 'exit nil))
  5226. (if (looking-at "[ \t]*$") (throw 'next nil))
  5227. (skip-chars-forward " \t") (setq ind1 (current-column))
  5228. (if (> ind1 ind) (throw 'next t))
  5229. (if (< ind1 ind) (throw 'exit t))
  5230. (if (not (org-at-item-p)) (throw 'exit nil))
  5231. (delete-region (match-beginning 2) (match-end 2))
  5232. (goto-char (match-beginning 2))
  5233. (insert (format fmt (setq n (1+ n)))))))
  5234. (goto-line line)
  5235. (org-move-to-column col)))
  5236. (defun org-fix-bullet-type ()
  5237. "Make sure all items in this list have the same bullet as the firsst item."
  5238. (interactive)
  5239. (unless (org-at-item-p) (error "This is not a list"))
  5240. (let ((line (org-current-line))
  5241. (col (current-column))
  5242. (ind (current-indentation))
  5243. ind1 bullet)
  5244. ;; find where this list begins
  5245. (org-beginning-of-item-list)
  5246. (beginning-of-line 1)
  5247. ;; find out what the bullet type is
  5248. (looking-at "[ \t]*\\(\\S-+\\)")
  5249. (setq bullet (match-string 1))
  5250. ;; walk forward and replace these numbers
  5251. (beginning-of-line 0)
  5252. (catch 'exit
  5253. (while t
  5254. (catch 'next
  5255. (beginning-of-line 2)
  5256. (if (eobp) (throw 'exit nil))
  5257. (if (looking-at "[ \t]*$") (throw 'next nil))
  5258. (skip-chars-forward " \t") (setq ind1 (current-column))
  5259. (if (> ind1 ind) (throw 'next t))
  5260. (if (< ind1 ind) (throw 'exit t))
  5261. (if (not (org-at-item-p)) (throw 'exit nil))
  5262. (skip-chars-forward " \t")
  5263. (looking-at "\\S-+")
  5264. (replace-match bullet))))
  5265. (goto-line line)
  5266. (org-move-to-column col)
  5267. (if (string-match "[0-9]" bullet)
  5268. (org-renumber-ordered-list 1))))
  5269. (defun org-beginning-of-item-list ()
  5270. "Go to the beginning of the current item list.
  5271. I.e. to the first item in this list."
  5272. (interactive)
  5273. (org-beginning-of-item)
  5274. (let ((pos (point-at-bol))
  5275. (ind (org-get-indentation))
  5276. ind1)
  5277. ;; find where this list begins
  5278. (catch 'exit
  5279. (while t
  5280. (catch 'next
  5281. (beginning-of-line 0)
  5282. (if (looking-at "[ \t]*$")
  5283. (throw (if (bobp) 'exit 'next) t))
  5284. (skip-chars-forward " \t") (setq ind1 (current-column))
  5285. (if (or (< ind1 ind)
  5286. (and (= ind1 ind)
  5287. (not (org-at-item-p)))
  5288. (bobp))
  5289. (throw 'exit t)
  5290. (when (org-at-item-p) (setq pos (point-at-bol)))))))
  5291. (goto-char pos)))
  5292. (defun org-end-of-item-list ()
  5293. "Go to the end of the current item list.
  5294. I.e. to the text after the last item."
  5295. (interactive)
  5296. (org-beginning-of-item)
  5297. (let ((pos (point-at-bol))
  5298. (ind (org-get-indentation))
  5299. ind1)
  5300. ;; find where this list begins
  5301. (catch 'exit
  5302. (while t
  5303. (catch 'next
  5304. (beginning-of-line 2)
  5305. (if (looking-at "[ \t]*$")
  5306. (throw (if (eobp) 'exit 'next) t))
  5307. (skip-chars-forward " \t") (setq ind1 (current-column))
  5308. (if (or (< ind1 ind)
  5309. (and (= ind1 ind)
  5310. (not (org-at-item-p)))
  5311. (eobp))
  5312. (progn
  5313. (setq pos (point-at-bol))
  5314. (throw 'exit t))))))
  5315. (goto-char pos)))
  5316. (defvar org-last-indent-begin-marker (make-marker))
  5317. (defvar org-last-indent-end-marker (make-marker))
  5318. (defun org-outdent-item (arg)
  5319. "Outdent a local list item."
  5320. (interactive "p")
  5321. (org-indent-item (- arg)))
  5322. (defun org-indent-item (arg)
  5323. "Indent a local list item."
  5324. (interactive "p")
  5325. (unless (org-at-item-p)
  5326. (error "Not on an item"))
  5327. (save-excursion
  5328. (let (beg end ind ind1 tmp delta ind-down ind-up)
  5329. (if (memq last-command '(org-shiftmetaright org-shiftmetaleft))
  5330. (setq beg org-last-indent-begin-marker
  5331. end org-last-indent-end-marker)
  5332. (org-beginning-of-item)
  5333. (setq beg (move-marker org-last-indent-begin-marker (point)))
  5334. (org-end-of-item)
  5335. (setq end (move-marker org-last-indent-end-marker (point))))
  5336. (goto-char beg)
  5337. (setq tmp (org-item-indent-positions)
  5338. ind (car tmp)
  5339. ind-down (nth 2 tmp)
  5340. ind-up (nth 1 tmp)
  5341. delta (if (> arg 0)
  5342. (if ind-down (- ind-down ind) 2)
  5343. (if ind-up (- ind-up ind) -2)))
  5344. (if (< (+ delta ind) 0) (error "Cannot outdent beyond margin"))
  5345. (while (< (point) end)
  5346. (beginning-of-line 1)
  5347. (skip-chars-forward " \t") (setq ind1 (current-column))
  5348. (delete-region (point-at-bol) (point))
  5349. (or (eolp) (org-indent-to-column (+ ind1 delta)))
  5350. (beginning-of-line 2))))
  5351. (org-fix-bullet-type)
  5352. (org-maybe-renumber-ordered-list-safe)
  5353. (save-excursion
  5354. (beginning-of-line 0)
  5355. (condition-case nil (org-beginning-of-item) (error nil))
  5356. (org-maybe-renumber-ordered-list-safe)))
  5357. (defun org-item-indent-positions ()
  5358. "Return indentation for plain list items.
  5359. This returns a list with three values: The current indentation, the
  5360. parent indentation and the indentation a child should habe.
  5361. Assumes cursor in item line."
  5362. (let* ((bolpos (point-at-bol))
  5363. (ind (org-get-indentation))
  5364. ind-down ind-up pos)
  5365. (save-excursion
  5366. (org-beginning-of-item-list)
  5367. (skip-chars-backward "\n\r \t")
  5368. (when (org-in-item-p)
  5369. (org-beginning-of-item)
  5370. (setq ind-up (org-get-indentation))))
  5371. (setq pos (point))
  5372. (save-excursion
  5373. (cond
  5374. ((and (condition-case nil (progn (org-previous-item) t)
  5375. (error nil))
  5376. (or (forward-char 1) t)
  5377. (re-search-forward "^\\([ \t]*\\([-+]\\|\\([0-9]+[.)]\\)\\)\\|[ \t]+\\*\\)\\( \\|$\\)" bolpos t))
  5378. (setq ind-down (org-get-indentation)))
  5379. ((and (goto-char pos)
  5380. (org-at-item-p))
  5381. (goto-char (match-end 0))
  5382. (skip-chars-forward " \t")
  5383. (setq ind-down (current-column)))))
  5384. (list ind ind-up ind-down)))
  5385. ;;; The orgstruct minor mode
  5386. ;; Define a minor mode which can be used in other modes in order to
  5387. ;; integrate the org-mode structure editing commands.
  5388. ;; This is really a hack, because the org-mode structure commands use
  5389. ;; keys which normally belong to the major mode. Here is how it
  5390. ;; works: The minor mode defines all the keys necessary to operate the
  5391. ;; structure commands, but wraps the commands into a function which
  5392. ;; tests if the cursor is currently at a headline or a plain list
  5393. ;; item. If that is the case, the structure command is used,
  5394. ;; temporarily setting many Org-mode variables like regular
  5395. ;; expressions for filling etc. However, when any of those keys is
  5396. ;; used at a different location, function uses `key-binding' to look
  5397. ;; up if the key has an associated command in another currently active
  5398. ;; keymap (minor modes, major mode, global), and executes that
  5399. ;; command. There might be problems if any of the keys is otherwise
  5400. ;; used as a prefix key.
  5401. ;; Another challenge is that the key binding for TAB can be tab or \C-i,
  5402. ;; likewise the binding for RET can be return or \C-m. Orgtbl-mode
  5403. ;; addresses this by checking explicitly for both bindings.
  5404. (defvar orgstruct-mode-map (make-sparse-keymap)
  5405. "Keymap for the minor `orgstruct-mode'.")
  5406. (defvar org-local-vars nil
  5407. "List of local variables, for use by `orgstruct-mode'")
  5408. ;;;###autoload
  5409. (define-minor-mode orgstruct-mode
  5410. "Toggle the minor more `orgstruct-mode'.
  5411. This mode is for using Org-mode structure commands in other modes.
  5412. The following key behave as if Org-mode was active, if the cursor
  5413. is on a headline, or on a plain list item (both in the definition
  5414. of Org-mode).
  5415. M-up Move entry/item up
  5416. M-down Move entry/item down
  5417. M-left Promote
  5418. M-right Demote
  5419. M-S-up Move entry/item up
  5420. M-S-down Move entry/item down
  5421. M-S-left Promote subtree
  5422. M-S-right Demote subtree
  5423. M-q Fill paragraph and items like in Org-mode
  5424. C-c ^ Sort entries
  5425. C-c - Cycle list bullet
  5426. TAB Cycle item visibility
  5427. M-RET Insert new heading/item
  5428. S-M-RET Insert new TODO heading / Chekbox item
  5429. C-c C-c Set tags / toggle checkbox"
  5430. nil " OrgStruct" nil
  5431. (org-load-modules-maybe)
  5432. (and (orgstruct-setup) (defun orgstruct-setup () nil)))
  5433. ;;;###autoload
  5434. (defun turn-on-orgstruct ()
  5435. "Unconditionally turn on `orgstruct-mode'."
  5436. (orgstruct-mode 1))
  5437. ;;;###autoload
  5438. (defun turn-on-orgstruct++ ()
  5439. "Unconditionally turn on `orgstruct-mode', and force org-mode indentations.
  5440. In addition to setting orgstruct-mode, this also exports all indentation and
  5441. autofilling variables from org-mode into the buffer. Note that turning
  5442. off orgstruct-mode will *not* remove these additional settings."
  5443. (orgstruct-mode 1)
  5444. (let (var val)
  5445. (mapc
  5446. (lambda (x)
  5447. (when (string-match
  5448. "^\\(paragraph-\\|auto-fill\\|fill-paragraph\\|adaptive-fill\\|indent-\\)"
  5449. (symbol-name (car x)))
  5450. (setq var (car x) val (nth 1 x))
  5451. (org-set-local var (if (eq (car-safe val) 'quote) (nth 1 val) val))))
  5452. org-local-vars)))
  5453. (defun orgstruct-error ()
  5454. "Error when there is no default binding for a structure key."
  5455. (interactive)
  5456. (error "This key has no function outside structure elements"))
  5457. (defun orgstruct-setup ()
  5458. "Setup orgstruct keymaps."
  5459. (let ((nfunc 0)
  5460. (bindings
  5461. (list
  5462. '([(meta up)] org-metaup)
  5463. '([(meta down)] org-metadown)
  5464. '([(meta left)] org-metaleft)
  5465. '([(meta right)] org-metaright)
  5466. '([(meta shift up)] org-shiftmetaup)
  5467. '([(meta shift down)] org-shiftmetadown)
  5468. '([(meta shift left)] org-shiftmetaleft)
  5469. '([(meta shift right)] org-shiftmetaright)
  5470. '([(shift up)] org-shiftup)
  5471. '([(shift down)] org-shiftdown)
  5472. '("\C-c\C-c" org-ctrl-c-ctrl-c)
  5473. '("\M-q" fill-paragraph)
  5474. '("\C-c^" org-sort)
  5475. '("\C-c-" org-cycle-list-bullet)))
  5476. elt key fun cmd)
  5477. (while (setq elt (pop bindings))
  5478. (setq nfunc (1+ nfunc))
  5479. (setq key (org-key (car elt))
  5480. fun (nth 1 elt)
  5481. cmd (orgstruct-make-binding fun nfunc key))
  5482. (org-defkey orgstruct-mode-map key cmd))
  5483. ;; Special treatment needed for TAB and RET
  5484. (org-defkey orgstruct-mode-map [(tab)]
  5485. (orgstruct-make-binding 'org-cycle 102 [(tab)] "\C-i"))
  5486. (org-defkey orgstruct-mode-map "\C-i"
  5487. (orgstruct-make-binding 'org-cycle 103 "\C-i" [(tab)]))
  5488. (org-defkey orgstruct-mode-map "\M-\C-m"
  5489. (orgstruct-make-binding 'org-insert-heading 105
  5490. "\M-\C-m" [(meta return)]))
  5491. (org-defkey orgstruct-mode-map [(meta return)]
  5492. (orgstruct-make-binding 'org-insert-heading 106
  5493. [(meta return)] "\M-\C-m"))
  5494. (org-defkey orgstruct-mode-map [(shift meta return)]
  5495. (orgstruct-make-binding 'org-insert-todo-heading 107
  5496. [(meta return)] "\M-\C-m"))
  5497. (unless org-local-vars
  5498. (setq org-local-vars (org-get-local-variables)))
  5499. t))
  5500. (defun orgstruct-make-binding (fun n &rest keys)
  5501. "Create a function for binding in the structure minor mode.
  5502. FUN is the command to call inside a table. N is used to create a unique
  5503. command name. KEYS are keys that should be checked in for a command
  5504. to execute outside of tables."
  5505. (eval
  5506. (list 'defun
  5507. (intern (concat "orgstruct-hijacker-command-" (int-to-string n)))
  5508. '(arg)
  5509. (concat "In Structure, run `" (symbol-name fun) "'.\n"
  5510. "Outside of structure, run the binding of `"
  5511. (mapconcat (lambda (x) (format "%s" x)) keys "' or `")
  5512. "'.")
  5513. '(interactive "p")
  5514. (list 'if
  5515. '(org-context-p 'headline 'item)
  5516. (list 'org-run-like-in-org-mode (list 'quote fun))
  5517. (list 'let '(orgstruct-mode)
  5518. (list 'call-interactively
  5519. (append '(or)
  5520. (mapcar (lambda (k)
  5521. (list 'key-binding k))
  5522. keys)
  5523. '('orgstruct-error))))))))
  5524. (defun org-context-p (&rest contexts)
  5525. "Check if local context is and of CONTEXTS.
  5526. Possible values in the list of contexts are `table', `headline', and `item'."
  5527. (let ((pos (point)))
  5528. (goto-char (point-at-bol))
  5529. (prog1 (or (and (memq 'table contexts)
  5530. (looking-at "[ \t]*|"))
  5531. (and (memq 'headline contexts)
  5532. (looking-at "\\*+"))
  5533. (and (memq 'item contexts)
  5534. (looking-at "[ \t]*\\([-+*] \\|[0-9]+[.)] \\)")))
  5535. (goto-char pos))))
  5536. (defun org-get-local-variables ()
  5537. "Return a list of all local variables in an org-mode buffer."
  5538. (let (varlist)
  5539. (with-current-buffer (get-buffer-create "*Org tmp*")
  5540. (erase-buffer)
  5541. (org-mode)
  5542. (setq varlist (buffer-local-variables)))
  5543. (kill-buffer "*Org tmp*")
  5544. (delq nil
  5545. (mapcar
  5546. (lambda (x)
  5547. (setq x
  5548. (if (symbolp x)
  5549. (list x)
  5550. (list (car x) (list 'quote (cdr x)))))
  5551. (if (string-match
  5552. "^\\(org-\\|orgtbl-\\|outline-\\|comment-\\|paragraph-\\|auto-fill\\|fill-paragraph\\|adaptive-fill\\|indent-\\)"
  5553. (symbol-name (car x)))
  5554. x nil))
  5555. varlist))))
  5556. ;;;###autoload
  5557. (defun org-run-like-in-org-mode (cmd)
  5558. (org-load-modules-maybe)
  5559. (unless org-local-vars
  5560. (setq org-local-vars (org-get-local-variables)))
  5561. (eval (list 'let org-local-vars
  5562. (list 'call-interactively (list 'quote cmd)))))
  5563. ;;;; Archiving
  5564. (defun org-get-category (&optional pos)
  5565. "Get the category applying to position POS."
  5566. (get-text-property (or pos (point)) 'org-category))
  5567. (defun org-refresh-category-properties ()
  5568. "Refresh category text properties in the buffer."
  5569. (let ((def-cat (cond
  5570. ((null org-category)
  5571. (if buffer-file-name
  5572. (file-name-sans-extension
  5573. (file-name-nondirectory buffer-file-name))
  5574. "???"))
  5575. ((symbolp org-category) (symbol-name org-category))
  5576. (t org-category)))
  5577. beg end cat pos optionp)
  5578. (org-unmodified
  5579. (save-excursion
  5580. (save-restriction
  5581. (widen)
  5582. (goto-char (point-min))
  5583. (put-text-property (point) (point-max) 'org-category def-cat)
  5584. (while (re-search-forward
  5585. "^\\(#\\+CATEGORY:\\|[ \t]*:CATEGORY:\\)\\(.*\\)" nil t)
  5586. (setq pos (match-end 0)
  5587. optionp (equal (char-after (match-beginning 0)) ?#)
  5588. cat (org-trim (match-string 2)))
  5589. (if optionp
  5590. (setq beg (point-at-bol) end (point-max))
  5591. (org-back-to-heading t)
  5592. (setq beg (point) end (org-end-of-subtree t t)))
  5593. (put-text-property beg end 'org-category cat)
  5594. (goto-char pos)))))))
  5595. ;;;; Link Stuff
  5596. ;;; Link abbreviations
  5597. (defun org-link-expand-abbrev (link)
  5598. "Apply replacements as defined in `org-link-abbrev-alist."
  5599. (if (string-match "^\\([a-zA-Z][-_a-zA-Z0-9]*\\)\\(::?\\(.*\\)\\)?$" link)
  5600. (let* ((key (match-string 1 link))
  5601. (as (or (assoc key org-link-abbrev-alist-local)
  5602. (assoc key org-link-abbrev-alist)))
  5603. (tag (and (match-end 2) (match-string 3 link)))
  5604. rpl)
  5605. (if (not as)
  5606. link
  5607. (setq rpl (cdr as))
  5608. (cond
  5609. ((symbolp rpl) (funcall rpl tag))
  5610. ((string-match "%s" rpl) (replace-match (or tag "") t t rpl))
  5611. (t (concat rpl tag)))))
  5612. link))
  5613. ;;; Storing and inserting links
  5614. (defvar org-insert-link-history nil
  5615. "Minibuffer history for links inserted with `org-insert-link'.")
  5616. (defvar org-stored-links nil
  5617. "Contains the links stored with `org-store-link'.")
  5618. (defvar org-store-link-plist nil
  5619. "Plist with info about the most recently link created with `org-store-link'.")
  5620. (defvar org-link-protocols nil
  5621. "Link protocols added to Org-mode using `org-add-link-type'.")
  5622. (defvar org-store-link-functions nil
  5623. "List of functions that are called to create and store a link.
  5624. Each function will be called in turn until one returns a non-nil
  5625. value. Each function should check if it is responsible for creating
  5626. this link (for example by looking at the major mode).
  5627. If not, it must exit and return nil.
  5628. If yes, it should return a non-nil value after a calling
  5629. `org-store-link-props' with a list of properties and values.
  5630. Special properties are:
  5631. :type The link prefix. like \"http\". This must be given.
  5632. :link The link, like \"http://www.astro.uva.nl/~dominik\".
  5633. This is obligatory as well.
  5634. :description Optional default description for the second pair
  5635. of brackets in an Org-mode link. The user can still change
  5636. this when inserting this link into an Org-mode buffer.
  5637. In addition to these, any additional properties can be specified
  5638. and then used in remember templates.")
  5639. (defun org-add-link-type (type &optional follow export)
  5640. "Add TYPE to the list of `org-link-types'.
  5641. Re-compute all regular expressions depending on `org-link-types'
  5642. FOLLOW and EXPORT are two functions.
  5643. FOLLOW should take the link path as the single argument and do whatever
  5644. is necessary to follow the link, for example find a file or display
  5645. a mail message.
  5646. EXPORT should format the link path for export to one of the export formats.
  5647. It should be a function accepting three arguments:
  5648. path the path of the link, the text after the prefix (like \"http:\")
  5649. desc the description of the link, if any, nil if there was no descripton
  5650. format the export format, a symbol like `html' or `latex'.
  5651. The function may use the FORMAT information to return different values
  5652. depending on the format. The return value will be put literally into
  5653. the exported file.
  5654. Org-mode has a built-in default for exporting links. If you are happy with
  5655. this default, there is no need to define an export function for the link
  5656. type. For a simple example of an export function, see `org-bbdb.el'."
  5657. (add-to-list 'org-link-types type t)
  5658. (org-make-link-regexps)
  5659. (if (assoc type org-link-protocols)
  5660. (setcdr (assoc type org-link-protocols) (list follow export))
  5661. (push (list type follow export) org-link-protocols)))
  5662. ;;;###autoload
  5663. (defun org-store-link (arg)
  5664. "\\<org-mode-map>Store an org-link to the current location.
  5665. This link is added to `org-stored-links' and can later be inserted
  5666. into an org-buffer with \\[org-insert-link].
  5667. For some link types, a prefix arg is interpreted:
  5668. For links to usenet articles, arg negates `org-usenet-links-prefer-google'.
  5669. For file links, arg negates `org-context-in-file-links'."
  5670. (interactive "P")
  5671. (org-load-modules-maybe)
  5672. (setq org-store-link-plist nil) ; reset
  5673. (let (link cpltxt desc description search txt)
  5674. (cond
  5675. ((run-hook-with-args-until-success 'org-store-link-functions)
  5676. (setq link (plist-get org-store-link-plist :link)
  5677. desc (or (plist-get org-store-link-plist :description) link)))
  5678. ((eq major-mode 'calendar-mode)
  5679. (let ((cd (calendar-cursor-to-date)))
  5680. (setq link
  5681. (format-time-string
  5682. (car org-time-stamp-formats)
  5683. (apply 'encode-time
  5684. (list 0 0 0 (nth 1 cd) (nth 0 cd) (nth 2 cd)
  5685. nil nil nil))))
  5686. (org-store-link-props :type "calendar" :date cd)))
  5687. ((eq major-mode 'w3-mode)
  5688. (setq cpltxt (url-view-url t)
  5689. link (org-make-link cpltxt))
  5690. (org-store-link-props :type "w3" :url (url-view-url t)))
  5691. ((eq major-mode 'w3m-mode)
  5692. (setq cpltxt (or w3m-current-title w3m-current-url)
  5693. link (org-make-link w3m-current-url))
  5694. (org-store-link-props :type "w3m" :url (url-view-url t)))
  5695. ((setq search (run-hook-with-args-until-success
  5696. 'org-create-file-search-functions))
  5697. (setq link (concat "file:" (abbreviate-file-name buffer-file-name)
  5698. "::" search))
  5699. (setq cpltxt (or description link)))
  5700. ((eq major-mode 'image-mode)
  5701. (setq cpltxt (concat "file:"
  5702. (abbreviate-file-name buffer-file-name))
  5703. link (org-make-link cpltxt))
  5704. (org-store-link-props :type "image" :file buffer-file-name))
  5705. ((eq major-mode 'dired-mode)
  5706. ;; link to the file in the current line
  5707. (setq cpltxt (concat "file:"
  5708. (abbreviate-file-name
  5709. (expand-file-name
  5710. (dired-get-filename nil t))))
  5711. link (org-make-link cpltxt)))
  5712. ((and buffer-file-name (org-mode-p))
  5713. ;; Just link to current headline
  5714. (setq cpltxt (concat "file:"
  5715. (abbreviate-file-name buffer-file-name)))
  5716. ;; Add a context search string
  5717. (when (org-xor org-context-in-file-links arg)
  5718. ;; Check if we are on a target
  5719. (if (org-in-regexp "<<\\(.*?\\)>>")
  5720. (setq cpltxt (concat cpltxt "::" (match-string 1)))
  5721. (setq txt (cond
  5722. ((org-on-heading-p) nil)
  5723. ((org-region-active-p)
  5724. (buffer-substring (region-beginning) (region-end)))
  5725. (t nil)))
  5726. (when (or (null txt) (string-match "\\S-" txt))
  5727. (setq cpltxt
  5728. (concat cpltxt "::"
  5729. (condition-case nil
  5730. (org-make-org-heading-search-string txt)
  5731. (error "")))
  5732. desc "NONE"))))
  5733. (if (string-match "::\\'" cpltxt)
  5734. (setq cpltxt (substring cpltxt 0 -2)))
  5735. (setq link (org-make-link cpltxt)))
  5736. ((buffer-file-name (buffer-base-buffer))
  5737. ;; Just link to this file here.
  5738. (setq cpltxt (concat "file:"
  5739. (abbreviate-file-name
  5740. (buffer-file-name (buffer-base-buffer)))))
  5741. ;; Add a context string
  5742. (when (org-xor org-context-in-file-links arg)
  5743. (setq txt (if (org-region-active-p)
  5744. (buffer-substring (region-beginning) (region-end))
  5745. (buffer-substring (point-at-bol) (point-at-eol))))
  5746. ;; Only use search option if there is some text.
  5747. (when (string-match "\\S-" txt)
  5748. (setq cpltxt
  5749. (concat cpltxt "::" (org-make-org-heading-search-string txt))
  5750. desc "NONE")))
  5751. (setq link (org-make-link cpltxt)))
  5752. ((interactive-p)
  5753. (error "Cannot link to a buffer which is not visiting a file"))
  5754. (t (setq link nil)))
  5755. (if (consp link) (setq cpltxt (car link) link (cdr link)))
  5756. (setq link (or link cpltxt)
  5757. desc (or desc cpltxt))
  5758. (if (equal desc "NONE") (setq desc nil))
  5759. (if (and (interactive-p) link)
  5760. (progn
  5761. (setq org-stored-links
  5762. (cons (list link desc) org-stored-links))
  5763. (message "Stored: %s" (or desc link)))
  5764. (and link (org-make-link-string link desc)))))
  5765. (defun org-store-link-props (&rest plist)
  5766. "Store link properties, extract names and addresses."
  5767. (let (x adr)
  5768. (when (setq x (plist-get plist :from))
  5769. (setq adr (mail-extract-address-components x))
  5770. (plist-put plist :fromname (car adr))
  5771. (plist-put plist :fromaddress (nth 1 adr)))
  5772. (when (setq x (plist-get plist :to))
  5773. (setq adr (mail-extract-address-components x))
  5774. (plist-put plist :toname (car adr))
  5775. (plist-put plist :toaddress (nth 1 adr))))
  5776. (let ((from (plist-get plist :from))
  5777. (to (plist-get plist :to)))
  5778. (when (and from to org-from-is-user-regexp)
  5779. (plist-put plist :fromto
  5780. (if (string-match org-from-is-user-regexp from)
  5781. (concat "to %t")
  5782. (concat "from %f")))))
  5783. (setq org-store-link-plist plist))
  5784. (defun org-add-link-props (&rest plist)
  5785. "Add these properties to the link property list."
  5786. (let (key value)
  5787. (while plist
  5788. (setq key (pop plist) value (pop plist))
  5789. (setq org-store-link-plist
  5790. (plist-put org-store-link-plist key value)))))
  5791. (defun org-email-link-description (&optional fmt)
  5792. "Return the description part of an email link.
  5793. This takes information from `org-store-link-plist' and formats it
  5794. according to FMT (default from `org-email-link-description-format')."
  5795. (setq fmt (or fmt org-email-link-description-format))
  5796. (let* ((p org-store-link-plist)
  5797. (to (plist-get p :toaddress))
  5798. (from (plist-get p :fromaddress))
  5799. (table
  5800. (list
  5801. (cons "%c" (plist-get p :fromto))
  5802. (cons "%F" (plist-get p :from))
  5803. (cons "%f" (or (plist-get p :fromname) (plist-get p :fromaddress) "?"))
  5804. (cons "%T" (plist-get p :to))
  5805. (cons "%t" (or (plist-get p :toname) (plist-get p :toaddress) "?"))
  5806. (cons "%s" (plist-get p :subject))
  5807. (cons "%m" (plist-get p :message-id)))))
  5808. (when (string-match "%c" fmt)
  5809. ;; Check if the user wrote this message
  5810. (if (and org-from-is-user-regexp from to
  5811. (save-match-data (string-match org-from-is-user-regexp from)))
  5812. (setq fmt (replace-match "to %t" t t fmt))
  5813. (setq fmt (replace-match "from %f" t t fmt))))
  5814. (org-replace-escapes fmt table)))
  5815. (defun org-make-org-heading-search-string (&optional string heading)
  5816. "Make search string for STRING or current headline."
  5817. (interactive)
  5818. (let ((s (or string (org-get-heading))))
  5819. (unless (and string (not heading))
  5820. ;; We are using a headline, clean up garbage in there.
  5821. (if (string-match org-todo-regexp s)
  5822. (setq s (replace-match "" t t s)))
  5823. (if (string-match (org-re ":[[:alnum:]_@:]+:[ \t]*$") s)
  5824. (setq s (replace-match "" t t s)))
  5825. (setq s (org-trim s))
  5826. (if (string-match (concat "^\\(" org-quote-string "\\|"
  5827. org-comment-string "\\)") s)
  5828. (setq s (replace-match "" t t s)))
  5829. (while (string-match org-ts-regexp s)
  5830. (setq s (replace-match "" t t s))))
  5831. (while (string-match "[^a-zA-Z_0-9 \t]+" s)
  5832. (setq s (replace-match " " t t s)))
  5833. (or string (setq s (concat "*" s))) ; Add * for headlines
  5834. (mapconcat 'identity (org-split-string s "[ \t]+") " ")))
  5835. (defun org-make-link (&rest strings)
  5836. "Concatenate STRINGS."
  5837. (apply 'concat strings))
  5838. (defun org-make-link-string (link &optional description)
  5839. "Make a link with brackets, consisting of LINK and DESCRIPTION."
  5840. (unless (string-match "\\S-" link)
  5841. (error "Empty link"))
  5842. (when (stringp description)
  5843. ;; Remove brackets from the description, they are fatal.
  5844. (while (string-match "\\[" description)
  5845. (setq description (replace-match "{" t t description)))
  5846. (while (string-match "\\]" description)
  5847. (setq description (replace-match "}" t t description))))
  5848. (when (equal (org-link-escape link) description)
  5849. ;; No description needed, it is identical
  5850. (setq description nil))
  5851. (when (and (not description)
  5852. (not (equal link (org-link-escape link))))
  5853. (setq description link))
  5854. (concat "[[" (org-link-escape link) "]"
  5855. (if description (concat "[" description "]") "")
  5856. "]"))
  5857. (defconst org-link-escape-chars
  5858. '((?\ . "%20")
  5859. (?\[ . "%5B")
  5860. (?\] . "%5D")
  5861. (?\340 . "%E0") ; `a
  5862. (?\342 . "%E2") ; ^a
  5863. (?\347 . "%E7") ; ,c
  5864. (?\350 . "%E8") ; `e
  5865. (?\351 . "%E9") ; 'e
  5866. (?\352 . "%EA") ; ^e
  5867. (?\356 . "%EE") ; ^i
  5868. (?\364 . "%F4") ; ^o
  5869. (?\371 . "%F9") ; `u
  5870. (?\373 . "%FB") ; ^u
  5871. (?\; . "%3B")
  5872. (?? . "%3F")
  5873. (?= . "%3D")
  5874. (?+ . "%2B")
  5875. )
  5876. "Association list of escapes for some characters problematic in links.
  5877. This is the list that is used for internal purposes.")
  5878. (defconst org-link-escape-chars-browser
  5879. '((?\ . "%20")) ; 32 for the SPC char
  5880. "Association list of escapes for some characters problematic in links.
  5881. This is the list that is used before handing over to the browser.")
  5882. (defun org-link-escape (text &optional table)
  5883. "Escape charaters in TEXT that are problematic for links."
  5884. (setq table (or table org-link-escape-chars))
  5885. (when text
  5886. (let ((re (mapconcat (lambda (x) (regexp-quote
  5887. (char-to-string (car x))))
  5888. table "\\|")))
  5889. (while (string-match re text)
  5890. (setq text
  5891. (replace-match
  5892. (cdr (assoc (string-to-char (match-string 0 text))
  5893. table))
  5894. t t text)))
  5895. text)))
  5896. (defun org-link-unescape (text &optional table)
  5897. "Reverse the action of `org-link-escape'."
  5898. (setq table (or table org-link-escape-chars))
  5899. (when text
  5900. (let ((re (mapconcat (lambda (x) (regexp-quote (cdr x)))
  5901. table "\\|")))
  5902. (while (string-match re text)
  5903. (setq text
  5904. (replace-match
  5905. (char-to-string (car (rassoc (match-string 0 text) table)))
  5906. t t text)))
  5907. text)))
  5908. (defun org-xor (a b)
  5909. "Exclusive or."
  5910. (if a (not b) b))
  5911. (defun org-get-header (header)
  5912. "Find a header field in the current buffer."
  5913. (save-excursion
  5914. (goto-char (point-min))
  5915. (let ((case-fold-search t) s)
  5916. (cond
  5917. ((eq header 'from)
  5918. (if (re-search-forward "^From:\\s-+\\(.*\\)" nil t)
  5919. (setq s (match-string 1)))
  5920. (while (string-match "\"" s)
  5921. (setq s (replace-match "" t t s)))
  5922. (if (string-match "[<(].*" s)
  5923. (setq s (replace-match "" t t s))))
  5924. ((eq header 'message-id)
  5925. (if (re-search-forward "^message-id:\\s-+\\(.*\\)" nil t)
  5926. (setq s (match-string 1))))
  5927. ((eq header 'subject)
  5928. (if (re-search-forward "^subject:\\s-+\\(.*\\)" nil t)
  5929. (setq s (match-string 1)))))
  5930. (if (string-match "\\`[ \t\]+" s) (setq s (replace-match "" t t s)))
  5931. (if (string-match "[ \t\]+\\'" s) (setq s (replace-match "" t t s)))
  5932. s)))
  5933. (defun org-fixup-message-id-for-http (s)
  5934. "Replace special characters in a message id, so it can be used in an http query."
  5935. (while (string-match "<" s)
  5936. (setq s (replace-match "%3C" t t s)))
  5937. (while (string-match ">" s)
  5938. (setq s (replace-match "%3E" t t s)))
  5939. (while (string-match "@" s)
  5940. (setq s (replace-match "%40" t t s)))
  5941. s)
  5942. ;;;###autoload
  5943. (defun org-insert-link-global ()
  5944. "Insert a link like Org-mode does.
  5945. This command can be called in any mode to insert a link in Org-mode syntax."
  5946. (interactive)
  5947. (org-load-modules-maybe)
  5948. (org-run-like-in-org-mode 'org-insert-link))
  5949. (defun org-insert-link (&optional complete-file link-location)
  5950. "Insert a link. At the prompt, enter the link.
  5951. Completion can be used to select a link previously stored with
  5952. `org-store-link'. When the empty string is entered (i.e. if you just
  5953. press RET at the prompt), the link defaults to the most recently
  5954. stored link. As SPC triggers completion in the minibuffer, you need to
  5955. use M-SPC or C-q SPC to force the insertion of a space character.
  5956. You will also be prompted for a description, and if one is given, it will
  5957. be displayed in the buffer instead of the link.
  5958. If there is already a link at point, this command will allow you to edit link
  5959. and description parts.
  5960. With a \\[universal-argument] prefix, prompts for a file to link to. The file name can
  5961. be selected using completion. The path to the file will be relative to the
  5962. current directory if the file is in the current directory or a subdirectory.
  5963. Otherwise, the link will be the absolute path as completed in the minibuffer
  5964. \(i.e. normally ~/path/to/file).
  5965. With two \\[universal-argument] prefixes, enforce an absolute path even if the file is in
  5966. the current directory or below. With three \\[universal-argument] prefixes, negate the meaning
  5967. of `org-keep-stored-link-after-insertion'.
  5968. If `org-make-link-description-function' is non-nil, this function will be
  5969. called with the link target, and the result will be the default
  5970. link description.
  5971. If the LINK-LOCATION parameter is non-nil, this value will be
  5972. used as the link location instead of reading one interactively."
  5973. (interactive "P")
  5974. (let* ((wcf (current-window-configuration))
  5975. (region (if (org-region-active-p)
  5976. (buffer-substring (region-beginning) (region-end))))
  5977. (remove (and region (list (region-beginning) (region-end))))
  5978. (desc region)
  5979. tmphist ; byte-compile incorrectly complains about this
  5980. (link link-location)
  5981. entry file)
  5982. (cond
  5983. (link-location) ; specified by arg, just use it.
  5984. ((org-in-regexp org-bracket-link-regexp 1)
  5985. ;; We do have a link at point, and we are going to edit it.
  5986. (setq remove (list (match-beginning 0) (match-end 0)))
  5987. (setq desc (if (match-end 3) (org-match-string-no-properties 3)))
  5988. (setq link (read-string "Link: "
  5989. (org-link-unescape
  5990. (org-match-string-no-properties 1)))))
  5991. ((or (org-in-regexp org-angle-link-re)
  5992. (org-in-regexp org-plain-link-re))
  5993. ;; Convert to bracket link
  5994. (setq remove (list (match-beginning 0) (match-end 0))
  5995. link (read-string "Link: "
  5996. (org-remove-angle-brackets (match-string 0)))))
  5997. ((equal complete-file '(4))
  5998. ;; Completing read for file names.
  5999. (setq file (read-file-name "File: "))
  6000. (let ((pwd (file-name-as-directory (expand-file-name ".")))
  6001. (pwd1 (file-name-as-directory (abbreviate-file-name
  6002. (expand-file-name ".")))))
  6003. (cond
  6004. ((equal complete-file '(16))
  6005. (setq link (org-make-link
  6006. "file:"
  6007. (abbreviate-file-name (expand-file-name file)))))
  6008. ((string-match (concat "^" (regexp-quote pwd1) "\\(.+\\)") file)
  6009. (setq link (org-make-link "file:" (match-string 1 file))))
  6010. ((string-match (concat "^" (regexp-quote pwd) "\\(.+\\)")
  6011. (expand-file-name file))
  6012. (setq link (org-make-link
  6013. "file:" (match-string 1 (expand-file-name file)))))
  6014. (t (setq link (org-make-link "file:" file))))))
  6015. (t
  6016. ;; Read link, with completion for stored links.
  6017. (with-output-to-temp-buffer "*Org Links*"
  6018. (princ "Insert a link. Use TAB to complete valid link prefixes.\n")
  6019. (when org-stored-links
  6020. (princ "\nStored links are available with <up>/<down> or M-p/n (most recent with RET):\n\n")
  6021. (princ (mapconcat
  6022. (lambda (x)
  6023. (if (nth 1 x) (concat (car x) " (" (nth 1 x) ")") (car x)))
  6024. (reverse org-stored-links) "\n"))))
  6025. (let ((cw (selected-window)))
  6026. (select-window (get-buffer-window "*Org Links*"))
  6027. (shrink-window-if-larger-than-buffer)
  6028. (setq truncate-lines t)
  6029. (select-window cw))
  6030. ;; Fake a link history, containing the stored links.
  6031. (setq tmphist (append (mapcar 'car org-stored-links)
  6032. org-insert-link-history))
  6033. (unwind-protect
  6034. (setq link (org-completing-read
  6035. "Link: "
  6036. (append
  6037. (mapcar (lambda (x) (list (concat (car x) ":")))
  6038. (append org-link-abbrev-alist-local org-link-abbrev-alist))
  6039. (mapcar (lambda (x) (list (concat x ":")))
  6040. org-link-types))
  6041. nil nil nil
  6042. 'tmphist
  6043. (or (car (car org-stored-links)))))
  6044. (set-window-configuration wcf)
  6045. (kill-buffer "*Org Links*"))
  6046. (setq entry (assoc link org-stored-links))
  6047. (or entry (push link org-insert-link-history))
  6048. (if (funcall (if (equal complete-file '(64)) 'not 'identity)
  6049. (not org-keep-stored-link-after-insertion))
  6050. (setq org-stored-links (delq (assoc link org-stored-links)
  6051. org-stored-links)))
  6052. (setq desc (or desc (nth 1 entry)))))
  6053. (if (string-match org-plain-link-re link)
  6054. ;; URL-like link, normalize the use of angular brackets.
  6055. (setq link (org-make-link (org-remove-angle-brackets link))))
  6056. ;; Check if we are linking to the current file with a search option
  6057. ;; If yes, simplify the link by using only the search option.
  6058. (when (and buffer-file-name
  6059. (string-match "\\<file:\\(.+?\\)::\\([^>]+\\)" link))
  6060. (let* ((path (match-string 1 link))
  6061. (case-fold-search nil)
  6062. (search (match-string 2 link)))
  6063. (save-match-data
  6064. (if (equal (file-truename buffer-file-name) (file-truename path))
  6065. ;; We are linking to this same file, with a search option
  6066. (setq link search)))))
  6067. ;; Check if we can/should use a relative path. If yes, simplify the link
  6068. (when (string-match "\\<file:\\(.*\\)" link)
  6069. (let* ((path (match-string 1 link))
  6070. (origpath path)
  6071. (case-fold-search nil))
  6072. (cond
  6073. ((eq org-link-file-path-type 'absolute)
  6074. (setq path (abbreviate-file-name (expand-file-name path))))
  6075. ((eq org-link-file-path-type 'noabbrev)
  6076. (setq path (expand-file-name path)))
  6077. ((eq org-link-file-path-type 'relative)
  6078. (setq path (file-relative-name path)))
  6079. (t
  6080. (save-match-data
  6081. (if (string-match (concat "^" (regexp-quote
  6082. (file-name-as-directory
  6083. (expand-file-name "."))))
  6084. (expand-file-name path))
  6085. ;; We are linking a file with relative path name.
  6086. (setq path (substring (expand-file-name path)
  6087. (match-end 0)))))))
  6088. (setq link (concat "file:" path))
  6089. (if (equal desc origpath)
  6090. (setq desc path))))
  6091. (if org-make-link-description-function
  6092. (setq desc (funcall org-make-link-description-function link desc)))
  6093. (setq desc (read-string "Description: " desc))
  6094. (unless (string-match "\\S-" desc) (setq desc nil))
  6095. (if remove (apply 'delete-region remove))
  6096. (insert (org-make-link-string link desc))))
  6097. (defun org-completing-read (&rest args)
  6098. (let ((minibuffer-local-completion-map
  6099. (copy-keymap minibuffer-local-completion-map)))
  6100. (org-defkey minibuffer-local-completion-map " " 'self-insert-command)
  6101. (apply 'completing-read args)))
  6102. ;;; Opening/following a link
  6103. (defvar org-link-search-failed nil)
  6104. (defun org-next-link ()
  6105. "Move forward to the next link.
  6106. If the link is in hidden text, expose it."
  6107. (interactive)
  6108. (when (and org-link-search-failed (eq this-command last-command))
  6109. (goto-char (point-min))
  6110. (message "Link search wrapped back to beginning of buffer"))
  6111. (setq org-link-search-failed nil)
  6112. (let* ((pos (point))
  6113. (ct (org-context))
  6114. (a (assoc :link ct)))
  6115. (if a (goto-char (nth 2 a)))
  6116. (if (re-search-forward org-any-link-re nil t)
  6117. (progn
  6118. (goto-char (match-beginning 0))
  6119. (if (org-invisible-p) (org-show-context)))
  6120. (goto-char pos)
  6121. (setq org-link-search-failed t)
  6122. (error "No further link found"))))
  6123. (defun org-previous-link ()
  6124. "Move backward to the previous link.
  6125. If the link is in hidden text, expose it."
  6126. (interactive)
  6127. (when (and org-link-search-failed (eq this-command last-command))
  6128. (goto-char (point-max))
  6129. (message "Link search wrapped back to end of buffer"))
  6130. (setq org-link-search-failed nil)
  6131. (let* ((pos (point))
  6132. (ct (org-context))
  6133. (a (assoc :link ct)))
  6134. (if a (goto-char (nth 1 a)))
  6135. (if (re-search-backward org-any-link-re nil t)
  6136. (progn
  6137. (goto-char (match-beginning 0))
  6138. (if (org-invisible-p) (org-show-context)))
  6139. (goto-char pos)
  6140. (setq org-link-search-failed t)
  6141. (error "No further link found"))))
  6142. (defun org-find-file-at-mouse (ev)
  6143. "Open file link or URL at mouse."
  6144. (interactive "e")
  6145. (mouse-set-point ev)
  6146. (org-open-at-point 'in-emacs))
  6147. (defun org-open-at-mouse (ev)
  6148. "Open file link or URL at mouse."
  6149. (interactive "e")
  6150. (mouse-set-point ev)
  6151. (org-open-at-point))
  6152. (defvar org-window-config-before-follow-link nil
  6153. "The window configuration before following a link.
  6154. This is saved in case the need arises to restore it.")
  6155. (defvar org-open-link-marker (make-marker)
  6156. "Marker pointing to the location where `org-open-at-point; was called.")
  6157. ;;;###autoload
  6158. (defun org-open-at-point-global ()
  6159. "Follow a link like Org-mode does.
  6160. This command can be called in any mode to follow a link that has
  6161. Org-mode syntax."
  6162. (interactive)
  6163. (org-run-like-in-org-mode 'org-open-at-point))
  6164. ;;;###autoload
  6165. (defun org-open-link-from-string (s &optional arg)
  6166. "Open a link in the string S, as if it was in Org-mode."
  6167. (interactive "sLink: \nP")
  6168. (with-temp-buffer
  6169. (let ((org-inhibit-startup t))
  6170. (org-mode)
  6171. (insert s)
  6172. (goto-char (point-min))
  6173. (org-open-at-point arg))))
  6174. (defun org-open-at-point (&optional in-emacs)
  6175. "Open link at or after point.
  6176. If there is no link at point, this function will search forward up to
  6177. the end of the current subtree.
  6178. Normally, files will be opened by an appropriate application. If the
  6179. optional argument IN-EMACS is non-nil, Emacs will visit the file."
  6180. (interactive "P")
  6181. (org-load-modules-maybe)
  6182. (move-marker org-open-link-marker (point))
  6183. (setq org-window-config-before-follow-link (current-window-configuration))
  6184. (org-remove-occur-highlights nil nil t)
  6185. (if (org-at-timestamp-p t)
  6186. (org-follow-timestamp-link)
  6187. (let (type path link line search (pos (point)))
  6188. (catch 'match
  6189. (save-excursion
  6190. (skip-chars-forward "^]\n\r")
  6191. (when (org-in-regexp org-bracket-link-regexp)
  6192. (setq link (org-link-unescape (org-match-string-no-properties 1)))
  6193. (while (string-match " *\n *" link)
  6194. (setq link (replace-match " " t t link)))
  6195. (setq link (org-link-expand-abbrev link))
  6196. (if (string-match org-link-re-with-space2 link)
  6197. (setq type (match-string 1 link) path (match-string 2 link))
  6198. (setq type "thisfile" path link))
  6199. (throw 'match t)))
  6200. (when (get-text-property (point) 'org-linked-text)
  6201. (setq type "thisfile"
  6202. pos (if (get-text-property (1+ (point)) 'org-linked-text)
  6203. (1+ (point)) (point))
  6204. path (buffer-substring
  6205. (previous-single-property-change pos 'org-linked-text)
  6206. (next-single-property-change pos 'org-linked-text)))
  6207. (throw 'match t))
  6208. (save-excursion
  6209. (when (or (org-in-regexp org-angle-link-re)
  6210. (org-in-regexp org-plain-link-re))
  6211. (setq type (match-string 1) path (match-string 2))
  6212. (throw 'match t)))
  6213. (when (org-in-regexp "\\<\\([^><\n]+\\)\\>")
  6214. (setq type "tree-match"
  6215. path (match-string 1))
  6216. (throw 'match t))
  6217. (save-excursion
  6218. (when (org-in-regexp (org-re "\\(:[[:alnum:]_@:]+\\):[ \t]*$"))
  6219. (setq type "tags"
  6220. path (match-string 1))
  6221. (while (string-match ":" path)
  6222. (setq path (replace-match "+" t t path)))
  6223. (throw 'match t))))
  6224. (unless path
  6225. (error "No link found"))
  6226. ;; Remove any trailing spaces in path
  6227. (if (string-match " +\\'" path)
  6228. (setq path (replace-match "" t t path)))
  6229. (cond
  6230. ((assoc type org-link-protocols)
  6231. (funcall (nth 1 (assoc type org-link-protocols)) path))
  6232. ((equal type "mailto")
  6233. (let ((cmd (car org-link-mailto-program))
  6234. (args (cdr org-link-mailto-program)) args1
  6235. (address path) (subject "") a)
  6236. (if (string-match "\\(.*\\)::\\(.*\\)" path)
  6237. (setq address (match-string 1 path)
  6238. subject (org-link-escape (match-string 2 path))))
  6239. (while args
  6240. (cond
  6241. ((not (stringp (car args))) (push (pop args) args1))
  6242. (t (setq a (pop args))
  6243. (if (string-match "%a" a)
  6244. (setq a (replace-match address t t a)))
  6245. (if (string-match "%s" a)
  6246. (setq a (replace-match subject t t a)))
  6247. (push a args1))))
  6248. (apply cmd (nreverse args1))))
  6249. ((member type '("http" "https" "ftp" "news"))
  6250. (browse-url (concat type ":" (org-link-escape
  6251. path org-link-escape-chars-browser))))
  6252. ((member type '("message"))
  6253. (browse-url (concat type ":" path)))
  6254. ((string= type "tags")
  6255. (org-tags-view in-emacs path))
  6256. ((string= type "thisfile")
  6257. (if in-emacs
  6258. (switch-to-buffer-other-window
  6259. (org-get-buffer-for-internal-link (current-buffer)))
  6260. (org-mark-ring-push))
  6261. (let ((cmd `(org-link-search
  6262. ,path
  6263. ,(cond ((equal in-emacs '(4)) 'occur)
  6264. ((equal in-emacs '(16)) 'org-occur)
  6265. (t nil))
  6266. ,pos)))
  6267. (condition-case nil (eval cmd)
  6268. (error (progn (widen) (eval cmd))))))
  6269. ((string= type "tree-match")
  6270. (org-occur (concat "\\[" (regexp-quote path) "\\]")))
  6271. ((string= type "file")
  6272. (if (string-match "::\\([0-9]+\\)\\'" path)
  6273. (setq line (string-to-number (match-string 1 path))
  6274. path (substring path 0 (match-beginning 0)))
  6275. (if (string-match "::\\(.+\\)\\'" path)
  6276. (setq search (match-string 1 path)
  6277. path (substring path 0 (match-beginning 0)))))
  6278. (if (string-match "[*?{]" (file-name-nondirectory path))
  6279. (dired path)
  6280. (org-open-file path in-emacs line search)))
  6281. ((string= type "news")
  6282. (require 'org-gnus)
  6283. (org-gnus-follow-link path))
  6284. ((string= type "shell")
  6285. (let ((cmd path))
  6286. (if (or (not org-confirm-shell-link-function)
  6287. (funcall org-confirm-shell-link-function
  6288. (format "Execute \"%s\" in shell? "
  6289. (org-add-props cmd nil
  6290. 'face 'org-warning))))
  6291. (progn
  6292. (message "Executing %s" cmd)
  6293. (shell-command cmd))
  6294. (error "Abort"))))
  6295. ((string= type "elisp")
  6296. (let ((cmd path))
  6297. (if (or (not org-confirm-elisp-link-function)
  6298. (funcall org-confirm-elisp-link-function
  6299. (format "Execute \"%s\" as elisp? "
  6300. (org-add-props cmd nil
  6301. 'face 'org-warning))))
  6302. (message "%s => %s" cmd (eval (read cmd)))
  6303. (error "Abort"))))
  6304. (t
  6305. (browse-url-at-point)))))
  6306. (move-marker org-open-link-marker nil)
  6307. (run-hook-with-args 'org-follow-link-hook))
  6308. ;;;; Time estimates
  6309. (defun org-get-effort (&optional pom)
  6310. "Get the effort estimate for the current entry."
  6311. (org-entry-get pom org-effort-property))
  6312. ;;; File search
  6313. (defvar org-create-file-search-functions nil
  6314. "List of functions to construct the right search string for a file link.
  6315. These functions are called in turn with point at the location to
  6316. which the link should point.
  6317. A function in the hook should first test if it would like to
  6318. handle this file type, for example by checking the major-mode or
  6319. the file extension. If it decides not to handle this file, it
  6320. should just return nil to give other functions a chance. If it
  6321. does handle the file, it must return the search string to be used
  6322. when following the link. The search string will be part of the
  6323. file link, given after a double colon, and `org-open-at-point'
  6324. will automatically search for it. If special measures must be
  6325. taken to make the search successful, another function should be
  6326. added to the companion hook `org-execute-file-search-functions',
  6327. which see.
  6328. A function in this hook may also use `setq' to set the variable
  6329. `description' to provide a suggestion for the descriptive text to
  6330. be used for this link when it gets inserted into an Org-mode
  6331. buffer with \\[org-insert-link].")
  6332. (defvar org-execute-file-search-functions nil
  6333. "List of functions to execute a file search triggered by a link.
  6334. Functions added to this hook must accept a single argument, the
  6335. search string that was part of the file link, the part after the
  6336. double colon. The function must first check if it would like to
  6337. handle this search, for example by checking the major-mode or the
  6338. file extension. If it decides not to handle this search, it
  6339. should just return nil to give other functions a chance. If it
  6340. does handle the search, it must return a non-nil value to keep
  6341. other functions from trying.
  6342. Each function can access the current prefix argument through the
  6343. variable `current-prefix-argument'. Note that a single prefix is
  6344. used to force opening a link in Emacs, so it may be good to only
  6345. use a numeric or double prefix to guide the search function.
  6346. In case this is needed, a function in this hook can also restore
  6347. the window configuration before `org-open-at-point' was called using:
  6348. (set-window-configuration org-window-config-before-follow-link)")
  6349. (defun org-link-search (s &optional type avoid-pos)
  6350. "Search for a link search option.
  6351. If S is surrounded by forward slashes, it is interpreted as a
  6352. regular expression. In org-mode files, this will create an `org-occur'
  6353. sparse tree. In ordinary files, `occur' will be used to list matches.
  6354. If the current buffer is in `dired-mode', grep will be used to search
  6355. in all files. If AVOID-POS is given, ignore matches near that position."
  6356. (let ((case-fold-search t)
  6357. (s0 (mapconcat 'identity (org-split-string s "[ \t\r\n]+") " "))
  6358. (markers (concat "\\(?:" (mapconcat (lambda (x) (regexp-quote (car x)))
  6359. (append '(("") (" ") ("\t") ("\n"))
  6360. org-emphasis-alist)
  6361. "\\|") "\\)"))
  6362. (pos (point))
  6363. (pre nil) (post nil)
  6364. words re0 re1 re2 re3 re4_ re4 re5 re2a re2a_ reall)
  6365. (cond
  6366. ;; First check if there are any special
  6367. ((run-hook-with-args-until-success 'org-execute-file-search-functions s))
  6368. ;; Now try the builtin stuff
  6369. ((save-excursion
  6370. (goto-char (point-min))
  6371. (and
  6372. (re-search-forward
  6373. (concat "<<" (regexp-quote s0) ">>") nil t)
  6374. (setq type 'dedicated
  6375. pos (match-beginning 0))))
  6376. ;; There is an exact target for this
  6377. (goto-char pos))
  6378. ((string-match "^/\\(.*\\)/$" s)
  6379. ;; A regular expression
  6380. (cond
  6381. ((org-mode-p)
  6382. (org-occur (match-string 1 s)))
  6383. ;;((eq major-mode 'dired-mode)
  6384. ;; (grep (concat "grep -n -e '" (match-string 1 s) "' *")))
  6385. (t (org-do-occur (match-string 1 s)))))
  6386. (t
  6387. ;; A normal search strings
  6388. (when (equal (string-to-char s) ?*)
  6389. ;; Anchor on headlines, post may include tags.
  6390. (setq pre "^\\*+[ \t]+\\(?:\\sw+\\)?[ \t]*"
  6391. post (org-re "[ \t]*\\(?:[ \t]+:[[:alnum:]_@:+]:[ \t]*\\)?$")
  6392. s (substring s 1)))
  6393. (remove-text-properties
  6394. 0 (length s)
  6395. '(face nil mouse-face nil keymap nil fontified nil) s)
  6396. ;; Make a series of regular expressions to find a match
  6397. (setq words (org-split-string s "[ \n\r\t]+")
  6398. re0 (concat "\\(<<" (regexp-quote s0) ">>\\)")
  6399. re2 (concat markers "\\(" (mapconcat 'downcase words "[ \t]+")
  6400. "\\)" markers)
  6401. re2a_ (concat "\\(" (mapconcat 'downcase words "[ \t\r\n]+") "\\)[ \t\r\n]")
  6402. re2a (concat "[ \t\r\n]" re2a_)
  6403. re4_ (concat "\\(" (mapconcat 'downcase words "[^a-zA-Z_\r\n]+") "\\)[^a-zA-Z_]")
  6404. re4 (concat "[^a-zA-Z_]" re4_)
  6405. re1 (concat pre re2 post)
  6406. re3 (concat pre (if pre re4_ re4) post)
  6407. re5 (concat pre ".*" re4)
  6408. re2 (concat pre re2)
  6409. re2a (concat pre (if pre re2a_ re2a))
  6410. re4 (concat pre (if pre re4_ re4))
  6411. reall (concat "\\(" re0 "\\)\\|\\(" re1 "\\)\\|\\(" re2
  6412. "\\)\\|\\(" re3 "\\)\\|\\(" re4 "\\)\\|\\("
  6413. re5 "\\)"
  6414. ))
  6415. (cond
  6416. ((eq type 'org-occur) (org-occur reall))
  6417. ((eq type 'occur) (org-do-occur (downcase reall) 'cleanup))
  6418. (t (goto-char (point-min))
  6419. (setq type 'fuzzy)
  6420. (if (or (and (org-search-not-self 1 re0 nil t) (setq type 'dedicated))
  6421. (org-search-not-self 1 re1 nil t)
  6422. (org-search-not-self 1 re2 nil t)
  6423. (org-search-not-self 1 re2a nil t)
  6424. (org-search-not-self 1 re3 nil t)
  6425. (org-search-not-self 1 re4 nil t)
  6426. (org-search-not-self 1 re5 nil t)
  6427. )
  6428. (goto-char (match-beginning 1))
  6429. (goto-char pos)
  6430. (error "No match")))))
  6431. (t
  6432. ;; Normal string-search
  6433. (goto-char (point-min))
  6434. (if (search-forward s nil t)
  6435. (goto-char (match-beginning 0))
  6436. (error "No match"))))
  6437. (and (org-mode-p) (org-show-context 'link-search))
  6438. type))
  6439. (defun org-search-not-self (group &rest args)
  6440. "Execute `re-search-forward', but only accept matches that do not
  6441. enclose the position of `org-open-link-marker'."
  6442. (let ((m org-open-link-marker))
  6443. (catch 'exit
  6444. (while (apply 're-search-forward args)
  6445. (unless (get-text-property (match-end group) 'intangible) ; Emacs 21
  6446. (goto-char (match-end group))
  6447. (if (and (or (not (eq (marker-buffer m) (current-buffer)))
  6448. (> (match-beginning 0) (marker-position m))
  6449. (< (match-end 0) (marker-position m)))
  6450. (save-match-data
  6451. (or (not (org-in-regexp
  6452. org-bracket-link-analytic-regexp 1))
  6453. (not (match-end 4)) ; no description
  6454. (and (<= (match-beginning 4) (point))
  6455. (>= (match-end 4) (point))))))
  6456. (throw 'exit (point))))))))
  6457. (defun org-get-buffer-for-internal-link (buffer)
  6458. "Return a buffer to be used for displaying the link target of internal links."
  6459. (cond
  6460. ((not org-display-internal-link-with-indirect-buffer)
  6461. buffer)
  6462. ((string-match "(Clone)$" (buffer-name buffer))
  6463. (message "Buffer is already a clone, not making another one")
  6464. ;; we also do not modify visibility in this case
  6465. buffer)
  6466. (t ; make a new indirect buffer for displaying the link
  6467. (let* ((bn (buffer-name buffer))
  6468. (ibn (concat bn "(Clone)"))
  6469. (ib (or (get-buffer ibn) (make-indirect-buffer buffer ibn 'clone))))
  6470. (with-current-buffer ib (org-overview))
  6471. ib))))
  6472. (defun org-do-occur (regexp &optional cleanup)
  6473. "Call the Emacs command `occur'.
  6474. If CLEANUP is non-nil, remove the printout of the regular expression
  6475. in the *Occur* buffer. This is useful if the regex is long and not useful
  6476. to read."
  6477. (occur regexp)
  6478. (when cleanup
  6479. (let ((cwin (selected-window)) win beg end)
  6480. (when (setq win (get-buffer-window "*Occur*"))
  6481. (select-window win))
  6482. (goto-char (point-min))
  6483. (when (re-search-forward "match[a-z]+" nil t)
  6484. (setq beg (match-end 0))
  6485. (if (re-search-forward "^[ \t]*[0-9]+" nil t)
  6486. (setq end (1- (match-beginning 0)))))
  6487. (and beg end (let ((inhibit-read-only t)) (delete-region beg end)))
  6488. (goto-char (point-min))
  6489. (select-window cwin))))
  6490. ;;; The mark ring for links jumps
  6491. (defvar org-mark-ring nil
  6492. "Mark ring for positions before jumps in Org-mode.")
  6493. (defvar org-mark-ring-last-goto nil
  6494. "Last position in the mark ring used to go back.")
  6495. ;; Fill and close the ring
  6496. (setq org-mark-ring nil org-mark-ring-last-goto nil) ;; in case file is reloaded
  6497. (loop for i from 1 to org-mark-ring-length do
  6498. (push (make-marker) org-mark-ring))
  6499. (setcdr (nthcdr (1- org-mark-ring-length) org-mark-ring)
  6500. org-mark-ring)
  6501. (defun org-mark-ring-push (&optional pos buffer)
  6502. "Put the current position or POS into the mark ring and rotate it."
  6503. (interactive)
  6504. (setq pos (or pos (point)))
  6505. (setq org-mark-ring (nthcdr (1- org-mark-ring-length) org-mark-ring))
  6506. (move-marker (car org-mark-ring)
  6507. (or pos (point))
  6508. (or buffer (current-buffer)))
  6509. (message "%s"
  6510. (substitute-command-keys
  6511. "Position saved to mark ring, go back with \\[org-mark-ring-goto].")))
  6512. (defun org-mark-ring-goto (&optional n)
  6513. "Jump to the previous position in the mark ring.
  6514. With prefix arg N, jump back that many stored positions. When
  6515. called several times in succession, walk through the entire ring.
  6516. Org-mode commands jumping to a different position in the current file,
  6517. or to another Org-mode file, automatically push the old position
  6518. onto the ring."
  6519. (interactive "p")
  6520. (let (p m)
  6521. (if (eq last-command this-command)
  6522. (setq p (nthcdr n (or org-mark-ring-last-goto org-mark-ring)))
  6523. (setq p org-mark-ring))
  6524. (setq org-mark-ring-last-goto p)
  6525. (setq m (car p))
  6526. (switch-to-buffer (marker-buffer m))
  6527. (goto-char m)
  6528. (if (or (org-invisible-p) (org-invisible-p2)) (org-show-context 'mark-goto))))
  6529. (defun org-remove-angle-brackets (s)
  6530. (if (equal (substring s 0 1) "<") (setq s (substring s 1)))
  6531. (if (equal (substring s -1) ">") (setq s (substring s 0 -1)))
  6532. s)
  6533. (defun org-add-angle-brackets (s)
  6534. (if (equal (substring s 0 1) "<") nil (setq s (concat "<" s)))
  6535. (if (equal (substring s -1) ">") nil (setq s (concat s ">")))
  6536. s)
  6537. (defun org-remove-double-quotes (s)
  6538. (if (equal (substring s 0 1) "\"") (setq s (substring s 1)))
  6539. (if (equal (substring s -1) "\"") (setq s (substring s 0 -1)))
  6540. s)
  6541. ;;; Following specific links
  6542. (defun org-follow-timestamp-link ()
  6543. (cond
  6544. ((org-at-date-range-p t)
  6545. (let ((org-agenda-start-on-weekday)
  6546. (t1 (match-string 1))
  6547. (t2 (match-string 2)))
  6548. (setq t1 (time-to-days (org-time-string-to-time t1))
  6549. t2 (time-to-days (org-time-string-to-time t2)))
  6550. (org-agenda-list nil t1 (1+ (- t2 t1)))))
  6551. ((org-at-timestamp-p t)
  6552. (org-agenda-list nil (time-to-days (org-time-string-to-time
  6553. (substring (match-string 1) 0 10)))
  6554. 1))
  6555. (t (error "This should not happen"))))
  6556. ;;; Following file links
  6557. (defvar org-wait nil)
  6558. (defun org-open-file (path &optional in-emacs line search)
  6559. "Open the file at PATH.
  6560. First, this expands any special file name abbreviations. Then the
  6561. configuration variable `org-file-apps' is checked if it contains an
  6562. entry for this file type, and if yes, the corresponding command is launched.
  6563. If no application is found, Emacs simply visits the file.
  6564. With optional argument IN-EMACS, Emacs will visit the file.
  6565. Optional LINE specifies a line to go to, optional SEARCH a string to
  6566. search for. If LINE or SEARCH is given, the file will always be
  6567. opened in Emacs.
  6568. If the file does not exist, an error is thrown."
  6569. (setq in-emacs (or in-emacs line search))
  6570. (let* ((file (if (equal path "")
  6571. buffer-file-name
  6572. (substitute-in-file-name (expand-file-name path))))
  6573. (apps (append org-file-apps (org-default-apps)))
  6574. (remp (and (assq 'remote apps) (org-file-remote-p file)))
  6575. (dirp (if remp nil (file-directory-p file)))
  6576. (dfile (downcase file))
  6577. (old-buffer (current-buffer))
  6578. (old-pos (point))
  6579. (old-mode major-mode)
  6580. ext cmd)
  6581. (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\.gz\\)$" dfile)
  6582. (setq ext (match-string 1 dfile))
  6583. (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\)$" dfile)
  6584. (setq ext (match-string 1 dfile))))
  6585. (if in-emacs
  6586. (setq cmd 'emacs)
  6587. (setq cmd (or (and remp (cdr (assoc 'remote apps)))
  6588. (and dirp (cdr (assoc 'directory apps)))
  6589. (cdr (assoc ext apps))
  6590. (cdr (assoc t apps)))))
  6591. (when (eq cmd 'mailcap)
  6592. (require 'mailcap)
  6593. (mailcap-parse-mailcaps)
  6594. (let* ((mime-type (mailcap-extension-to-mime (or ext "")))
  6595. (command (mailcap-mime-info mime-type)))
  6596. (if (stringp command)
  6597. (setq cmd command)
  6598. (setq cmd 'emacs))))
  6599. (if (and (not (eq cmd 'emacs)) ; Emacs has no problems with non-ex files
  6600. (not (file-exists-p file))
  6601. (not org-open-non-existing-files))
  6602. (error "No such file: %s" file))
  6603. (cond
  6604. ((and (stringp cmd) (not (string-match "^\\s-*$" cmd)))
  6605. ;; Remove quotes around the file name - we'll use shell-quote-argument.
  6606. (while (string-match "['\"]%s['\"]" cmd)
  6607. (setq cmd (replace-match "%s" t t cmd)))
  6608. (while (string-match "%s" cmd)
  6609. (setq cmd (replace-match
  6610. (save-match-data (shell-quote-argument file))
  6611. t t cmd)))
  6612. (save-window-excursion
  6613. (start-process-shell-command cmd nil cmd)
  6614. (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
  6615. ))
  6616. ((or (stringp cmd)
  6617. (eq cmd 'emacs))
  6618. (funcall (cdr (assq 'file org-link-frame-setup)) file)
  6619. (widen)
  6620. (if line (goto-line line)
  6621. (if search (org-link-search search))))
  6622. ((consp cmd)
  6623. (eval cmd))
  6624. (t (funcall (cdr (assq 'file org-link-frame-setup)) file)))
  6625. (and (org-mode-p) (eq old-mode 'org-mode)
  6626. (or (not (equal old-buffer (current-buffer)))
  6627. (not (equal old-pos (point))))
  6628. (org-mark-ring-push old-pos old-buffer))))
  6629. (defun org-default-apps ()
  6630. "Return the default applications for this operating system."
  6631. (cond
  6632. ((eq system-type 'darwin)
  6633. org-file-apps-defaults-macosx)
  6634. ((eq system-type 'windows-nt)
  6635. org-file-apps-defaults-windowsnt)
  6636. (t org-file-apps-defaults-gnu)))
  6637. (defvar ange-ftp-name-format) ; to silence the XEmacs compiler.
  6638. (defun org-file-remote-p (file)
  6639. "Test whether FILE specifies a location on a remote system.
  6640. Return non-nil if the location is indeed remote.
  6641. For example, the filename \"/user@host:/foo\" specifies a location
  6642. on the system \"/user@host:\"."
  6643. (cond ((fboundp 'file-remote-p)
  6644. (file-remote-p file))
  6645. ((fboundp 'tramp-handle-file-remote-p)
  6646. (tramp-handle-file-remote-p file))
  6647. ((and (boundp 'ange-ftp-name-format)
  6648. (string-match (car ange-ftp-name-format) file))
  6649. t)
  6650. (t nil)))
  6651. ;;;; Refiling
  6652. (defun org-get-org-file ()
  6653. "Read a filename, with default directory `org-directory'."
  6654. (let ((default (or org-default-notes-file remember-data-file)))
  6655. (read-file-name (format "File name [%s]: " default)
  6656. (file-name-as-directory org-directory)
  6657. default)))
  6658. (defun org-notes-order-reversed-p ()
  6659. "Check if the current file should receive notes in reversed order."
  6660. (cond
  6661. ((not org-reverse-note-order) nil)
  6662. ((eq t org-reverse-note-order) t)
  6663. ((not (listp org-reverse-note-order)) nil)
  6664. (t (catch 'exit
  6665. (let ((all org-reverse-note-order)
  6666. entry)
  6667. (while (setq entry (pop all))
  6668. (if (string-match (car entry) buffer-file-name)
  6669. (throw 'exit (cdr entry))))
  6670. nil)))))
  6671. (defvar org-refile-target-table nil
  6672. "The list of refile targets, created by `org-refile'.")
  6673. (defvar org-agenda-new-buffers nil
  6674. "Buffers created to visit agenda files.")
  6675. (defun org-get-refile-targets (&optional default-buffer)
  6676. "Produce a table with refile targets."
  6677. (let ((entries (or org-refile-targets '((nil . (:level . 1)))))
  6678. targets txt re files f desc descre)
  6679. (with-current-buffer (or default-buffer (current-buffer))
  6680. (while (setq entry (pop entries))
  6681. (setq files (car entry) desc (cdr entry))
  6682. (cond
  6683. ((null files) (setq files (list (current-buffer))))
  6684. ((eq files 'org-agenda-files)
  6685. (setq files (org-agenda-files 'unrestricted)))
  6686. ((and (symbolp files) (fboundp files))
  6687. (setq files (funcall files)))
  6688. ((and (symbolp files) (boundp files))
  6689. (setq files (symbol-value files))))
  6690. (if (stringp files) (setq files (list files)))
  6691. (cond
  6692. ((eq (car desc) :tag)
  6693. (setq descre (concat "^\\*+[ \t]+.*?:" (regexp-quote (cdr desc)) ":")))
  6694. ((eq (car desc) :todo)
  6695. (setq descre (concat "^\\*+[ \t]+" (regexp-quote (cdr desc)) "[ \t]")))
  6696. ((eq (car desc) :regexp)
  6697. (setq descre (cdr desc)))
  6698. ((eq (car desc) :level)
  6699. (setq descre (concat "^\\*\\{" (number-to-string
  6700. (if org-odd-levels-only
  6701. (1- (* 2 (cdr desc)))
  6702. (cdr desc)))
  6703. "\\}[ \t]")))
  6704. ((eq (car desc) :maxlevel)
  6705. (setq descre (concat "^\\*\\{1," (number-to-string
  6706. (if org-odd-levels-only
  6707. (1- (* 2 (cdr desc)))
  6708. (cdr desc)))
  6709. "\\}[ \t]")))
  6710. (t (error "Bad refiling target description %s" desc)))
  6711. (while (setq f (pop files))
  6712. (save-excursion
  6713. (set-buffer (if (bufferp f) f (org-get-agenda-file-buffer f)))
  6714. (if (bufferp f) (setq f (buffer-file-name (buffer-base-buffer f))))
  6715. (save-excursion
  6716. (save-restriction
  6717. (widen)
  6718. (goto-char (point-min))
  6719. (while (re-search-forward descre nil t)
  6720. (goto-char (point-at-bol))
  6721. (when (looking-at org-complex-heading-regexp)
  6722. (setq txt (match-string 4)
  6723. re (concat "^" (regexp-quote
  6724. (buffer-substring (match-beginning 1)
  6725. (match-end 4)))))
  6726. (if (match-end 5) (setq re (concat re "[ \t]+"
  6727. (regexp-quote
  6728. (match-string 5)))))
  6729. (setq re (concat re "[ \t]*$"))
  6730. (when org-refile-use-outline-path
  6731. (setq txt (mapconcat 'identity
  6732. (append
  6733. (if (eq org-refile-use-outline-path 'file)
  6734. (list (file-name-nondirectory
  6735. (buffer-file-name (buffer-base-buffer))))
  6736. (if (eq org-refile-use-outline-path 'full-file-path)
  6737. (list (buffer-file-name (buffer-base-buffer)))))
  6738. (org-get-outline-path)
  6739. (list txt))
  6740. "/")))
  6741. (push (list txt f re (point)) targets))
  6742. (goto-char (point-at-eol))))))))
  6743. (nreverse targets))))
  6744. (defun org-get-outline-path ()
  6745. "Return the outline path to the current entry, as a list."
  6746. (let (rtn)
  6747. (save-excursion
  6748. (while (org-up-heading-safe)
  6749. (when (looking-at org-complex-heading-regexp)
  6750. (push (org-match-string-no-properties 4) rtn)))
  6751. rtn)))
  6752. (defvar org-refile-history nil
  6753. "History for refiling operations.")
  6754. (defun org-refile (&optional goto default-buffer)
  6755. "Move the entry at point to another heading.
  6756. The list of target headings is compiled using the information in
  6757. `org-refile-targets', which see. This list is created before each use
  6758. and will therefore always be up-to-date.
  6759. At the target location, the entry is filed as a subitem of the target heading.
  6760. Depending on `org-reverse-note-order', the new subitem will either be the
  6761. first of the last subitem.
  6762. With prefix arg GOTO, the command will only visit the target location,
  6763. not actually move anything.
  6764. With a double prefix `C-c C-c', go to the location where the last refiling
  6765. operation has put the subtree."
  6766. (interactive "P")
  6767. (let* ((cbuf (current-buffer))
  6768. (filename (buffer-file-name (buffer-base-buffer cbuf)))
  6769. pos it nbuf file re level reversed)
  6770. (if (equal goto '(16))
  6771. (org-refile-goto-last-stored)
  6772. (when (setq it (org-refile-get-location
  6773. (if goto "Goto: " "Refile to: ") default-buffer))
  6774. (setq file (nth 1 it)
  6775. re (nth 2 it)
  6776. pos (nth 3 it))
  6777. (setq nbuf (or (find-buffer-visiting file)
  6778. (find-file-noselect file)))
  6779. (if goto
  6780. (progn
  6781. (switch-to-buffer nbuf)
  6782. (goto-char pos)
  6783. (org-show-context 'org-goto))
  6784. (org-copy-subtree 1 nil t)
  6785. (save-excursion
  6786. (set-buffer (setq nbuf (or (find-buffer-visiting file)
  6787. (find-file-noselect file))))
  6788. (setq reversed (org-notes-order-reversed-p))
  6789. (save-excursion
  6790. (save-restriction
  6791. (widen)
  6792. (goto-char pos)
  6793. (looking-at outline-regexp)
  6794. (setq level (org-get-valid-level (funcall outline-level) 1))
  6795. (goto-char
  6796. (if reversed
  6797. (outline-next-heading)
  6798. (or (save-excursion (outline-get-next-sibling))
  6799. (org-end-of-subtree t t)
  6800. (point-max))))
  6801. (bookmark-set "org-refile-last-stored")
  6802. (org-paste-subtree level))))
  6803. (org-cut-subtree)
  6804. (setq org-markers-to-move nil)
  6805. (message "Entry refiled to \"%s\"" (car it)))))))
  6806. (defun org-refile-goto-last-stored ()
  6807. "Go to the location where the last refile was stored."
  6808. (interactive)
  6809. (bookmark-jump "org-refile-last-stored")
  6810. (message "This is the location of the last refile"))
  6811. (defun org-refile-get-location (&optional prompt default-buffer)
  6812. "Prompt the user for a refile location, using PROMPT."
  6813. (let ((org-refile-targets org-refile-targets)
  6814. (org-refile-use-outline-path org-refile-use-outline-path))
  6815. (setq org-refile-target-table (org-get-refile-targets default-buffer)))
  6816. (unless org-refile-target-table
  6817. (error "No refile targets"))
  6818. (let* ((cbuf (current-buffer))
  6819. (filename (buffer-file-name (buffer-base-buffer cbuf)))
  6820. (fname (and filename (file-truename filename)))
  6821. (tbl (mapcar
  6822. (lambda (x)
  6823. (if (not (equal fname (file-truename (nth 1 x))))
  6824. (cons (concat (car x) " (" (file-name-nondirectory
  6825. (nth 1 x)) ")")
  6826. (cdr x))
  6827. x))
  6828. org-refile-target-table))
  6829. (completion-ignore-case t))
  6830. (assoc (completing-read prompt tbl nil t nil 'org-refile-history)
  6831. tbl)))
  6832. ;;;; Dynamic blocks
  6833. (defun org-find-dblock (name)
  6834. "Find the first dynamic block with name NAME in the buffer.
  6835. If not found, stay at current position and return nil."
  6836. (let (pos)
  6837. (save-excursion
  6838. (goto-char (point-min))
  6839. (setq pos (and (re-search-forward (concat "^#\\+BEGIN:[ \t]+" name "\\>")
  6840. nil t)
  6841. (match-beginning 0))))
  6842. (if pos (goto-char pos))
  6843. pos))
  6844. (defconst org-dblock-start-re
  6845. "^#\\+BEGIN:[ \t]+\\(\\S-+\\)\\([ \t]+\\(.*\\)\\)?"
  6846. "Matches the startline of a dynamic block, with parameters.")
  6847. (defconst org-dblock-end-re "^#\\+END\\([: \t\r\n]\\|$\\)"
  6848. "Matches the end of a dyhamic block.")
  6849. (defun org-create-dblock (plist)
  6850. "Create a dynamic block section, with parameters taken from PLIST.
  6851. PLIST must containe a :name entry which is used as name of the block."
  6852. (unless (bolp) (newline))
  6853. (let ((name (plist-get plist :name)))
  6854. (insert "#+BEGIN: " name)
  6855. (while plist
  6856. (if (eq (car plist) :name)
  6857. (setq plist (cddr plist))
  6858. (insert " " (prin1-to-string (pop plist)))))
  6859. (insert "\n\n#+END:\n")
  6860. (beginning-of-line -2)))
  6861. (defun org-prepare-dblock ()
  6862. "Prepare dynamic block for refresh.
  6863. This empties the block, puts the cursor at the insert position and returns
  6864. the property list including an extra property :name with the block name."
  6865. (unless (looking-at org-dblock-start-re)
  6866. (error "Not at a dynamic block"))
  6867. (let* ((begdel (1+ (match-end 0)))
  6868. (name (org-no-properties (match-string 1)))
  6869. (params (append (list :name name)
  6870. (read (concat "(" (match-string 3) ")")))))
  6871. (unless (re-search-forward org-dblock-end-re nil t)
  6872. (error "Dynamic block not terminated"))
  6873. (setq params
  6874. (append params
  6875. (list :content (buffer-substring
  6876. begdel (match-beginning 0)))))
  6877. (delete-region begdel (match-beginning 0))
  6878. (goto-char begdel)
  6879. (open-line 1)
  6880. params))
  6881. (defun org-map-dblocks (&optional command)
  6882. "Apply COMMAND to all dynamic blocks in the current buffer.
  6883. If COMMAND is not given, use `org-update-dblock'."
  6884. (let ((cmd (or command 'org-update-dblock))
  6885. pos)
  6886. (save-excursion
  6887. (goto-char (point-min))
  6888. (while (re-search-forward org-dblock-start-re nil t)
  6889. (goto-char (setq pos (match-beginning 0)))
  6890. (condition-case nil
  6891. (funcall cmd)
  6892. (error (message "Error during update of dynamic block")))
  6893. (goto-char pos)
  6894. (unless (re-search-forward org-dblock-end-re nil t)
  6895. (error "Dynamic block not terminated"))))))
  6896. (defun org-dblock-update (&optional arg)
  6897. "User command for updating dynamic blocks.
  6898. Update the dynamic block at point. With prefix ARG, update all dynamic
  6899. blocks in the buffer."
  6900. (interactive "P")
  6901. (if arg
  6902. (org-update-all-dblocks)
  6903. (or (looking-at org-dblock-start-re)
  6904. (org-beginning-of-dblock))
  6905. (org-update-dblock)))
  6906. (defun org-update-dblock ()
  6907. "Update the dynamic block at point
  6908. This means to empty the block, parse for parameters and then call
  6909. the correct writing function."
  6910. (save-window-excursion
  6911. (let* ((pos (point))
  6912. (line (org-current-line))
  6913. (params (org-prepare-dblock))
  6914. (name (plist-get params :name))
  6915. (cmd (intern (concat "org-dblock-write:" name))))
  6916. (message "Updating dynamic block `%s' at line %d..." name line)
  6917. (funcall cmd params)
  6918. (message "Updating dynamic block `%s' at line %d...done" name line)
  6919. (goto-char pos))))
  6920. (defun org-beginning-of-dblock ()
  6921. "Find the beginning of the dynamic block at point.
  6922. Error if there is no scuh block at point."
  6923. (let ((pos (point))
  6924. beg)
  6925. (end-of-line 1)
  6926. (if (and (re-search-backward org-dblock-start-re nil t)
  6927. (setq beg (match-beginning 0))
  6928. (re-search-forward org-dblock-end-re nil t)
  6929. (> (match-end 0) pos))
  6930. (goto-char beg)
  6931. (goto-char pos)
  6932. (error "Not in a dynamic block"))))
  6933. (defun org-update-all-dblocks ()
  6934. "Update all dynamic blocks in the buffer.
  6935. This function can be used in a hook."
  6936. (when (org-mode-p)
  6937. (org-map-dblocks 'org-update-dblock)))
  6938. ;;;; Completion
  6939. (defconst org-additional-option-like-keywords
  6940. '("BEGIN_HTML" "BEGIN_LaTeX" "END_HTML" "END_LaTeX"
  6941. "ORGTBL" "HTML:" "LaTeX:" "BEGIN:" "END:" "TBLFM"
  6942. "BEGIN_EXAMPLE" "END_EXAMPLE"))
  6943. (defcustom org-structure-template-alist
  6944. '(
  6945. ("s" "#+begin_src ?\n\n#+end_src")
  6946. ("e" "#+begin_example\n?\n#+end_example")
  6947. ("q" "#+begin_quote\n?\n#+end_quote")
  6948. ("v" "#+begin_verse\n?\n#+end_verse")
  6949. ("l" "#+begin_latex\n?\n#+end_latex")
  6950. ("L" "#+latex: ")
  6951. ("h" "#+begin_html\n?\n#+end_html")
  6952. ("H" "#+html: ")
  6953. ("a" "#+begin_ascii\n?\n#+end_ascii")
  6954. ("A" "#+ascii: ")
  6955. ("i" "#+include: %file ?")
  6956. )
  6957. "Structure completion elements.
  6958. This is a list of abbreviation keys and values. The value gets inserted
  6959. it you type @samp{.} followed by the key and then the completion key,
  6960. usually `M-TAB'. %file will be replaced by a file name after prompting
  6961. for the file uning completion.
  6962. This is an experimental feature, it is undecided if it is going to stay in."
  6963. :group 'org-completion
  6964. :type '(repeat
  6965. (string :tag "Key") (string :tag "Template")))
  6966. (defun org-complete-expand-structure-template (start cell)
  6967. "Expand a structure template."
  6968. (let ((rpl (nth 1 cell)))
  6969. (delete-region start (point))
  6970. (when (string-match "\\`#\\+" rpl)
  6971. (cond
  6972. ((bolp))
  6973. ((not (string-match "\\S-" (buffer-substring (point-at-bol) (point))))
  6974. (delete-region (point-at-bol) (point)))
  6975. (t (newline))))
  6976. (setq start (point))
  6977. (if (string-match "%file" rpl)
  6978. (setq rpl (replace-match
  6979. (concat
  6980. "\""
  6981. (save-match-data
  6982. (abbreviate-file-name (read-file-name "Include file: ")))
  6983. "\"")
  6984. t t rpl)))
  6985. (insert rpl)
  6986. (if (re-search-backward "\\?" start t) (delete-char 1))))
  6987. (defun org-complete (&optional arg)
  6988. "Perform completion on word at point.
  6989. At the beginning of a headline, this completes TODO keywords as given in
  6990. `org-todo-keywords'.
  6991. If the current word is preceded by a backslash, completes the TeX symbols
  6992. that are supported for HTML support.
  6993. If the current word is preceded by \"#+\", completes special words for
  6994. setting file options.
  6995. In the line after \"#+STARTUP:, complete valid keywords.\"
  6996. At all other locations, this simply calls the value of
  6997. `org-completion-fallback-command'."
  6998. (interactive "P")
  6999. (org-without-partial-completion
  7000. (catch 'exit
  7001. (let* ((a nil)
  7002. (end (point))
  7003. (beg1 (save-excursion
  7004. (skip-chars-backward (org-re "[:alnum:]_@"))
  7005. (point)))
  7006. (beg (save-excursion
  7007. (skip-chars-backward "a-zA-Z0-9_:$")
  7008. (point)))
  7009. (confirm (lambda (x) (stringp (car x))))
  7010. (searchhead (equal (char-before beg) ?*))
  7011. (struct
  7012. (when (and (equal (char-before beg1) ?.)
  7013. (setq a (assoc (buffer-substring beg1 (point))
  7014. org-structure-template-alist)))
  7015. (org-complete-expand-structure-template (1- beg1) a)
  7016. (throw 'exit t)))
  7017. (tag (and (equal (char-before beg1) ?:)
  7018. (equal (char-after (point-at-bol)) ?*)))
  7019. (prop (and (equal (char-before beg1) ?:)
  7020. (not (equal (char-after (point-at-bol)) ?*))))
  7021. (texp (equal (char-before beg) ?\\))
  7022. (link (equal (char-before beg) ?\[))
  7023. (opt (equal (buffer-substring (max (point-at-bol) (- beg 2))
  7024. beg)
  7025. "#+"))
  7026. (startup (string-match "^#\\+STARTUP:.*"
  7027. (buffer-substring (point-at-bol) (point))))
  7028. (completion-ignore-case opt)
  7029. (type nil)
  7030. (tbl nil)
  7031. (table (cond
  7032. (opt
  7033. (setq type :opt)
  7034. (require 'org-exp)
  7035. (append
  7036. (mapcar
  7037. (lambda (x)
  7038. (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
  7039. (cons (match-string 2 x) (match-string 1 x)))
  7040. (org-split-string (org-get-current-options) "\n"))
  7041. (mapcar 'list org-additional-option-like-keywords)))
  7042. (startup
  7043. (setq type :startup)
  7044. org-startup-options)
  7045. (link (append org-link-abbrev-alist-local
  7046. org-link-abbrev-alist))
  7047. (texp
  7048. (setq type :tex)
  7049. org-html-entities)
  7050. ((string-match "\\`\\*+[ \t]+\\'"
  7051. (buffer-substring (point-at-bol) beg))
  7052. (setq type :todo)
  7053. (mapcar 'list org-todo-keywords-1))
  7054. (searchhead
  7055. (setq type :searchhead)
  7056. (save-excursion
  7057. (goto-char (point-min))
  7058. (while (re-search-forward org-todo-line-regexp nil t)
  7059. (push (list
  7060. (org-make-org-heading-search-string
  7061. (match-string 3) t))
  7062. tbl)))
  7063. tbl)
  7064. (tag (setq type :tag beg beg1)
  7065. (or org-tag-alist (org-get-buffer-tags)))
  7066. (prop (setq type :prop beg beg1)
  7067. (mapcar 'list (org-buffer-property-keys nil t t)))
  7068. (t (progn
  7069. (call-interactively org-completion-fallback-command)
  7070. (throw 'exit nil)))))
  7071. (pattern (buffer-substring-no-properties beg end))
  7072. (completion (try-completion pattern table confirm)))
  7073. (cond ((eq completion t)
  7074. (if (not (assoc (upcase pattern) table))
  7075. (message "Already complete")
  7076. (if (and (equal type :opt)
  7077. (not (member (car (assoc (upcase pattern) table))
  7078. org-additional-option-like-keywords)))
  7079. (insert (substring (cdr (assoc (upcase pattern) table))
  7080. (length pattern)))
  7081. (if (memq type '(:tag :prop)) (insert ":")))))
  7082. ((null completion)
  7083. (message "Can't find completion for \"%s\"" pattern)
  7084. (ding))
  7085. ((not (string= pattern completion))
  7086. (delete-region beg end)
  7087. (if (string-match " +$" completion)
  7088. (setq completion (replace-match "" t t completion)))
  7089. (insert completion)
  7090. (if (get-buffer-window "*Completions*")
  7091. (delete-window (get-buffer-window "*Completions*")))
  7092. (if (assoc completion table)
  7093. (if (eq type :todo) (insert " ")
  7094. (if (memq type '(:tag :prop)) (insert ":"))))
  7095. (if (and (equal type :opt) (assoc completion table))
  7096. (message "%s" (substitute-command-keys
  7097. "Press \\[org-complete] again to insert example settings"))))
  7098. (t
  7099. (message "Making completion list...")
  7100. (let ((list (sort (all-completions pattern table confirm)
  7101. 'string<)))
  7102. (with-output-to-temp-buffer "*Completions*"
  7103. (condition-case nil
  7104. ;; Protection needed for XEmacs and emacs 21
  7105. (display-completion-list list pattern)
  7106. (error (display-completion-list list)))))
  7107. (message "Making completion list...%s" "done")))))))
  7108. ;;;; TODO, DEADLINE, Comments
  7109. (defun org-toggle-comment ()
  7110. "Change the COMMENT state of an entry."
  7111. (interactive)
  7112. (save-excursion
  7113. (org-back-to-heading)
  7114. (let (case-fold-search)
  7115. (if (looking-at (concat outline-regexp
  7116. "\\( *\\<" org-comment-string "\\>[ \t]*\\)"))
  7117. (replace-match "" t t nil 1)
  7118. (if (looking-at outline-regexp)
  7119. (progn
  7120. (goto-char (match-end 0))
  7121. (insert org-comment-string " ")))))))
  7122. (defvar org-last-todo-state-is-todo nil
  7123. "This is non-nil when the last TODO state change led to a TODO state.
  7124. If the last change removed the TODO tag or switched to DONE, then
  7125. this is nil.")
  7126. (defvar org-setting-tags nil) ; dynamically skiped
  7127. (defun org-parse-local-options (string var)
  7128. "Parse STRING for startup setting relevant for variable VAR."
  7129. (let ((rtn (symbol-value var))
  7130. e opts)
  7131. (save-match-data
  7132. (if (or (not string) (not (string-match "\\S-" string)))
  7133. rtn
  7134. (setq opts (delq nil (mapcar (lambda (x)
  7135. (setq e (assoc x org-startup-options))
  7136. (if (eq (nth 1 e) var) e nil))
  7137. (org-split-string string "[ \t]+"))))
  7138. (if (not opts)
  7139. rtn
  7140. (setq rtn nil)
  7141. (while (setq e (pop opts))
  7142. (if (not (nth 3 e))
  7143. (setq rtn (nth 2 e))
  7144. (if (not (listp rtn)) (setq rtn nil))
  7145. (push (nth 2 e) rtn)))
  7146. rtn)))))
  7147. (defvar org-blocker-hook nil
  7148. "Hook for functions that are allowed to block a state change.
  7149. Each function gets as its single argument a property list, see
  7150. `org-trigger-hook' for more information about this list.
  7151. If any of the functions in this hook returns nil, the state change
  7152. is blocked.")
  7153. (defvar org-trigger-hook nil
  7154. "Hook for functions that are triggered by a state change.
  7155. Each function gets as its single argument a property list with at least
  7156. the following elements:
  7157. (:type type-of-change :position pos-at-entry-start
  7158. :from old-state :to new-state)
  7159. Depending on the type, more properties may be present.
  7160. This mechanism is currently implemented for:
  7161. TODO state changes
  7162. ------------------
  7163. :type todo-state-change
  7164. :from previous state (keyword as a string), or nil
  7165. :to new state (keyword as a string), or nil")
  7166. (defun org-todo (&optional arg)
  7167. "Change the TODO state of an item.
  7168. The state of an item is given by a keyword at the start of the heading,
  7169. like
  7170. *** TODO Write paper
  7171. *** DONE Call mom
  7172. The different keywords are specified in the variable `org-todo-keywords'.
  7173. By default the available states are \"TODO\" and \"DONE\".
  7174. So for this example: when the item starts with TODO, it is changed to DONE.
  7175. When it starts with DONE, the DONE is removed. And when neither TODO nor
  7176. DONE are present, add TODO at the beginning of the heading.
  7177. With C-u prefix arg, use completion to determine the new state.
  7178. With numeric prefix arg, switch to that state.
  7179. For calling through lisp, arg is also interpreted in the following way:
  7180. 'none -> empty state
  7181. \"\"(empty string) -> switch to empty state
  7182. 'done -> switch to DONE
  7183. 'nextset -> switch to the next set of keywords
  7184. 'previousset -> switch to the previous set of keywords
  7185. \"WAITING\" -> switch to the specified keyword, but only if it
  7186. really is a member of `org-todo-keywords'."
  7187. (interactive "P")
  7188. (save-excursion
  7189. (catch 'exit
  7190. (org-back-to-heading)
  7191. (if (looking-at outline-regexp) (goto-char (1- (match-end 0))))
  7192. (or (looking-at (concat " +" org-todo-regexp " *"))
  7193. (looking-at " *"))
  7194. (let* ((match-data (match-data))
  7195. (startpos (point-at-bol))
  7196. (logging (save-match-data (org-entry-get nil "LOGGING" t)))
  7197. (org-log-done org-log-done)
  7198. (org-log-repeat org-log-repeat)
  7199. (org-todo-log-states org-todo-log-states)
  7200. (this (match-string 1))
  7201. (hl-pos (match-beginning 0))
  7202. (head (org-get-todo-sequence-head this))
  7203. (ass (assoc head org-todo-kwd-alist))
  7204. (interpret (nth 1 ass))
  7205. (done-word (nth 3 ass))
  7206. (final-done-word (nth 4 ass))
  7207. (last-state (or this ""))
  7208. (completion-ignore-case t)
  7209. (member (member this org-todo-keywords-1))
  7210. (tail (cdr member))
  7211. (state (cond
  7212. ((and org-todo-key-trigger
  7213. (or (and (equal arg '(4)) (eq org-use-fast-todo-selection 'prefix))
  7214. (and (not arg) org-use-fast-todo-selection
  7215. (not (eq org-use-fast-todo-selection 'prefix)))))
  7216. ;; Use fast selection
  7217. (org-fast-todo-selection))
  7218. ((and (equal arg '(4))
  7219. (or (not org-use-fast-todo-selection)
  7220. (not org-todo-key-trigger)))
  7221. ;; Read a state with completion
  7222. (completing-read "State: " (mapcar (lambda(x) (list x))
  7223. org-todo-keywords-1)
  7224. nil t))
  7225. ((eq arg 'right)
  7226. (if this
  7227. (if tail (car tail) nil)
  7228. (car org-todo-keywords-1)))
  7229. ((eq arg 'left)
  7230. (if (equal member org-todo-keywords-1)
  7231. nil
  7232. (if this
  7233. (nth (- (length org-todo-keywords-1) (length tail) 2)
  7234. org-todo-keywords-1)
  7235. (org-last org-todo-keywords-1))))
  7236. ((and (eq org-use-fast-todo-selection t) (equal arg '(4))
  7237. (setq arg nil))) ; hack to fall back to cycling
  7238. (arg
  7239. ;; user or caller requests a specific state
  7240. (cond
  7241. ((equal arg "") nil)
  7242. ((eq arg 'none) nil)
  7243. ((eq arg 'done) (or done-word (car org-done-keywords)))
  7244. ((eq arg 'nextset)
  7245. (or (car (cdr (member head org-todo-heads)))
  7246. (car org-todo-heads)))
  7247. ((eq arg 'previousset)
  7248. (let ((org-todo-heads (reverse org-todo-heads)))
  7249. (or (car (cdr (member head org-todo-heads)))
  7250. (car org-todo-heads))))
  7251. ((car (member arg org-todo-keywords-1)))
  7252. ((nth (1- (prefix-numeric-value arg))
  7253. org-todo-keywords-1))))
  7254. ((null member) (or head (car org-todo-keywords-1)))
  7255. ((equal this final-done-word) nil) ;; -> make empty
  7256. ((null tail) nil) ;; -> first entry
  7257. ((eq interpret 'sequence)
  7258. (car tail))
  7259. ((memq interpret '(type priority))
  7260. (if (eq this-command last-command)
  7261. (car tail)
  7262. (if (> (length tail) 0)
  7263. (or done-word (car org-done-keywords))
  7264. nil)))
  7265. (t nil)))
  7266. (next (if state (concat " " state " ") " "))
  7267. (change-plist (list :type 'todo-state-change :from this :to state
  7268. :position startpos))
  7269. dolog now-done-p)
  7270. (when org-blocker-hook
  7271. (unless (save-excursion
  7272. (save-match-data
  7273. (run-hook-with-args-until-failure
  7274. 'org-blocker-hook change-plist)))
  7275. (if (interactive-p)
  7276. (error "TODO state change from %s to %s blocked" this state)
  7277. ;; fail silently
  7278. (message "TODO state change from %s to %s blocked" this state)
  7279. (throw 'exit nil))))
  7280. (store-match-data match-data)
  7281. (replace-match next t t)
  7282. (unless (pos-visible-in-window-p hl-pos)
  7283. (message "TODO state changed to %s" (org-trim next)))
  7284. (unless head
  7285. (setq head (org-get-todo-sequence-head state)
  7286. ass (assoc head org-todo-kwd-alist)
  7287. interpret (nth 1 ass)
  7288. done-word (nth 3 ass)
  7289. final-done-word (nth 4 ass)))
  7290. (when (memq arg '(nextset previousset))
  7291. (message "Keyword-Set %d/%d: %s"
  7292. (- (length org-todo-sets) -1
  7293. (length (memq (assoc state org-todo-sets) org-todo-sets)))
  7294. (length org-todo-sets)
  7295. (mapconcat 'identity (assoc state org-todo-sets) " ")))
  7296. (setq org-last-todo-state-is-todo
  7297. (not (member state org-done-keywords)))
  7298. (setq now-done-p (and (member state org-done-keywords)
  7299. (not (member this org-done-keywords))))
  7300. (and logging (org-local-logging logging))
  7301. (when (and (or org-todo-log-states org-log-done)
  7302. (not (memq arg '(nextset previousset))))
  7303. ;; we need to look at recording a time and note
  7304. (setq dolog (or (nth 1 (assoc state org-todo-log-states))
  7305. (nth 2 (assoc this org-todo-log-states))))
  7306. (when (and state
  7307. (member state org-not-done-keywords)
  7308. (not (member this org-not-done-keywords)))
  7309. ;; This is now a todo state and was not one before
  7310. ;; If there was a CLOSED time stamp, get rid of it.
  7311. (org-add-planning-info nil nil 'closed))
  7312. (when (and now-done-p org-log-done)
  7313. ;; It is now done, and it was not done before
  7314. (org-add-planning-info 'closed (org-current-time))
  7315. (if (and (not dolog) (eq 'note org-log-done))
  7316. (org-add-log-setup 'done state 'findpos 'note)))
  7317. (when (and state dolog)
  7318. ;; This is a non-nil state, and we need to log it
  7319. (org-add-log-setup 'state state 'findpos dolog)))
  7320. ;; Fixup tag positioning
  7321. (and org-auto-align-tags (not org-setting-tags) (org-set-tags nil t))
  7322. (run-hooks 'org-after-todo-state-change-hook)
  7323. (if (and arg (not (member state org-done-keywords)))
  7324. (setq head (org-get-todo-sequence-head state)))
  7325. (put-text-property (point-at-bol) (point-at-eol) 'org-todo-head head)
  7326. ;; Do we need to trigger a repeat?
  7327. (when now-done-p (org-auto-repeat-maybe state))
  7328. ;; Fixup cursor location if close to the keyword
  7329. (if (and (outline-on-heading-p)
  7330. (not (bolp))
  7331. (save-excursion (beginning-of-line 1)
  7332. (looking-at org-todo-line-regexp))
  7333. (< (point) (+ 2 (or (match-end 2) (match-end 1)))))
  7334. (progn
  7335. (goto-char (or (match-end 2) (match-end 1)))
  7336. (just-one-space)))
  7337. (when org-trigger-hook
  7338. (save-excursion
  7339. (run-hook-with-args 'org-trigger-hook change-plist)))))))
  7340. (defun org-local-logging (value)
  7341. "Get logging settings from a property VALUE."
  7342. (let* (words w a)
  7343. ;; directly set the variables, they are already local.
  7344. (setq org-log-done nil
  7345. org-log-repeat nil
  7346. org-todo-log-states nil)
  7347. (setq words (org-split-string value))
  7348. (while (setq w (pop words))
  7349. (cond
  7350. ((setq a (assoc w org-startup-options))
  7351. (and (member (nth 1 a) '(org-log-done org-log-repeat))
  7352. (set (nth 1 a) (nth 2 a))))
  7353. ((setq a (org-e