org.el 622 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679
  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, 2009
  4. ;; Free Software Foundation, Inc.
  5. ;;
  6. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  7. ;; Keywords: outlines, hypermedia, calendar, wp
  8. ;; Homepage: http://orgmode.org
  9. ;; Version: 6.28trans
  10. ;;
  11. ;; This file is part of GNU Emacs.
  12. ;;
  13. ;; GNU Emacs is free software: you can redistribute it and/or modify
  14. ;; it under the terms of the GNU General Public License as published by
  15. ;; the Free Software Foundation, either version 3 of the License, or
  16. ;; (at your option) any later version.
  17. ;; GNU Emacs is distributed in the hope that it will be useful,
  18. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. ;; GNU General Public License for more details.
  21. ;; You should have received a copy of the GNU General Public License
  22. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  23. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  24. ;;
  25. ;;; Commentary:
  26. ;;
  27. ;; Org-mode is a mode for keeping notes, maintaining ToDo lists, and doing
  28. ;; project planning with a fast and effective plain-text system.
  29. ;;
  30. ;; Org-mode develops organizational tasks around NOTES files that contain
  31. ;; information about projects as plain text. Org-mode is implemented on
  32. ;; top of outline-mode, which makes it possible to keep the content of
  33. ;; large files well structured. Visibility cycling and structure editing
  34. ;; help to work with the tree. Tables are easily created with a built-in
  35. ;; table editor. Org-mode supports ToDo items, deadlines, time stamps,
  36. ;; and scheduling. It dynamically compiles entries into an agenda that
  37. ;; utilizes and smoothly integrates much of the Emacs calendar and diary.
  38. ;; Plain text URL-like links connect to websites, emails, Usenet
  39. ;; messages, BBDB entries, and any files related to the projects. For
  40. ;; printing and sharing of notes, an Org-mode file can be exported as a
  41. ;; structured ASCII file, as HTML, or (todo and agenda items only) as an
  42. ;; iCalendar file. It can also serve as a publishing tool for a set of
  43. ;; linked webpages.
  44. ;;
  45. ;; Installation and Activation
  46. ;; ---------------------------
  47. ;; See the corresponding sections in the manual at
  48. ;;
  49. ;; http://orgmode.org/org.html#Installation
  50. ;;
  51. ;; Documentation
  52. ;; -------------
  53. ;; The documentation of Org-mode can be found in the TeXInfo file. The
  54. ;; distribution also contains a PDF version of it. At the homepage of
  55. ;; Org-mode, you can read the same text online as HTML. There is also an
  56. ;; excellent reference card made by Philip Rooke. This card can be found
  57. ;; in the etc/ directory of Emacs 22.
  58. ;;
  59. ;; A list of recent changes can be found at
  60. ;; http://orgmode.org/Changes.html
  61. ;;
  62. ;;; Code:
  63. (defvar org-inhibit-highlight-removal nil) ; dynamically scoped param
  64. (defvar org-table-formula-constants-local nil
  65. "Local version of `org-table-formula-constants'.")
  66. (make-variable-buffer-local 'org-table-formula-constants-local)
  67. ;;;; Require other packages
  68. (eval-when-compile
  69. (require 'cl)
  70. (require 'gnus-sum)
  71. (require 'calendar))
  72. ;; For XEmacs, noutline is not yet provided by outline.el, so arrange for
  73. ;; the file noutline.el being loaded.
  74. (if (featurep 'xemacs) (condition-case nil (require 'noutline)))
  75. ;; We require noutline, which might be provided in outline.el
  76. (require 'outline) (require 'noutline)
  77. ;; Other stuff we need.
  78. (require 'time-date)
  79. (unless (fboundp 'time-subtract) (defalias 'time-subtract 'subtract-time))
  80. (require 'easymenu)
  81. (require 'org-macs)
  82. (require 'org-compat)
  83. (require 'org-faces)
  84. (require 'org-list)
  85. (require 'org-src)
  86. (require 'org-footnote)
  87. ;;;; Customization variables
  88. ;;; Version
  89. (defconst org-version "6.28trans"
  90. "The version number of the file org.el.")
  91. (defun org-version (&optional here)
  92. "Show the org-mode version in the echo area.
  93. With prefix arg HERE, insert it at point."
  94. (interactive "P")
  95. (let ((version (format "Org-mode version %s" org-version)))
  96. (message version)
  97. (if here
  98. (insert version))))
  99. ;;; Compatibility constants
  100. ;;; The custom variables
  101. (defgroup org nil
  102. "Outline-based notes management and organizer."
  103. :tag "Org"
  104. :group 'outlines
  105. :group 'hypermedia
  106. :group 'calendar)
  107. (defcustom org-load-hook nil
  108. "Hook that is run after org.el has been loaded."
  109. :group 'org
  110. :type 'hook)
  111. (defvar org-modules) ; defined below
  112. (defvar org-modules-loaded nil
  113. "Have the modules been loaded already?")
  114. (defun org-load-modules-maybe (&optional force)
  115. "Load all extensions listed in `org-modules'."
  116. (when (or force (not org-modules-loaded))
  117. (mapc (lambda (ext)
  118. (condition-case nil (require ext)
  119. (error (message "Problems while trying to load feature `%s'" ext))))
  120. org-modules)
  121. (setq org-modules-loaded t)))
  122. (defun org-set-modules (var value)
  123. "Set VAR to VALUE and call `org-load-modules-maybe' with the force flag."
  124. (set var value)
  125. (when (featurep 'org)
  126. (org-load-modules-maybe 'force)))
  127. (when (org-bound-and-true-p org-modules)
  128. (let ((a (member 'org-infojs org-modules)))
  129. (and a (setcar a 'org-jsinfo))))
  130. (defcustom org-modules '(org-bbdb org-bibtex org-gnus org-info org-jsinfo org-irc org-mew org-mhe org-rmail org-vm org-w3m org-wl)
  131. "Modules that should always be loaded together with org.el.
  132. If a description starts with <C>, the file is not part of Emacs
  133. and loading it will require that you have downloaded and properly installed
  134. the org-mode distribution.
  135. You can also use this system to load external packages (i.e. neither Org
  136. core modules, not modules from the CONTRIB directory). Just add symbols
  137. to the end of the list. If the package is called org-xyz.el, then you need
  138. to add the symbol `xyz', and the package must have a call to
  139. (provide 'org-xyz)"
  140. :group 'org
  141. :set 'org-set-modules
  142. :type
  143. '(set :greedy t
  144. (const :tag " bbdb: Links to BBDB entries" org-bbdb)
  145. (const :tag " bibtex: Links to BibTeX entries" org-bibtex)
  146. (const :tag " gnus: Links to GNUS folders/messages" org-gnus)
  147. (const :tag " id: Global IDs for identifying entries" org-id)
  148. (const :tag " info: Links to Info nodes" org-info)
  149. (const :tag " jsinfo: Set up Sebastian Rose's JavaScript org-info.js" org-jsinfo)
  150. (const :tag " inlinetask: Tasks independent of outline hierarchy" org-inlinetask)
  151. (const :tag " irc: Links to IRC/ERC chat sessions" org-irc)
  152. (const :tag " mac-message: Links to messages in Apple Mail" org-mac-message)
  153. (const :tag " mew Links to Mew folders/messages" org-mew)
  154. (const :tag " mhe: Links to MHE folders/messages" org-mhe)
  155. (const :tag " protocol: Intercept calls from emacsclient" org-protocol)
  156. (const :tag " rmail: Links to RMAIL folders/messages" org-rmail)
  157. (const :tag " vm: Links to VM folders/messages" org-vm)
  158. (const :tag " wl: Links to Wanderlust folders/messages" org-wl)
  159. (const :tag " w3m: Special cut/paste from w3m to Org." org-w3m)
  160. (const :tag " mouse: Additional mouse support" org-mouse)
  161. (const :tag "C annotate-file: Annotate a file with org syntax" org-annotate-file)
  162. (const :tag "C annotation-helper: Call Remember directly from Browser (OBSOLETE, use org-protocol)" org-annotation-helper)
  163. (const :tag "C bookmark: Org links to bookmarks" org-bookmark)
  164. (const :tag "C browser-url: Store link, directly from Browser (OBSOLETE, use org-protocol)" org-browser-url)
  165. (const :tag "C choose: Use TODO keywords to mark decisions states" org-choose)
  166. (const :tag "C collector: Collect properties into tables" org-collector)
  167. (const :tag "C depend: TODO dependencies for Org-mode (PARTIALLY OBSOLETE, see built-in dependency support))" org-depend)
  168. (const :tag "C elisp-symbol: Org links to emacs-lisp symbols" org-elisp-symbol)
  169. (const :tag "C eval: Include command output as text" org-eval)
  170. (const :tag "C eval-light: Evaluate inbuffer-code on demand" org-eval-light)
  171. (const :tag "C expiry: Expiry mechanism for Org entries" org-expiry)
  172. (const :tag "C exp-bibtex: Export citations using BibTeX" org-exp-bibtex)
  173. (const :tag "C interactive-query: Interactive modification of tags query (PARTIALLY OBSOLETE, see secondary filtering)" org-interactive-query)
  174. (const :tag "C jira Add a jira:ticket protocol to Org" org-jira)
  175. (const :tag "C mairix: Hook mairix search into Org for different MUAs" org-mairix)
  176. (const :tag "C mac-iCal Imports events from iCal.app to the Emacs diary" org-mac-iCal)
  177. (const :tag "C man: Support for links to manpages in Org-mode" org-man)
  178. (const :tag "C mtags: Support for muse-like tags" org-mtags)
  179. (const :tag "C panel: Simple routines for us with bad memory" org-panel)
  180. (const :tag "C R: Computation using the R language" org-R)
  181. (const :tag "C registry: A registry for Org links" org-registry)
  182. (const :tag "C org2rem: Convert org appointments into reminders" org2rem)
  183. (const :tag "C screen: Visit screen sessions through Org-mode links" org-screen)
  184. (const :tag "C special-blocks: Turn blocks into LaTeX envs and HTML divs" org-special-blocks)
  185. (const :tag "C sqlinsert: Convert Org-mode tables to SQL insertions" orgtbl-sqlinsert)
  186. (const :tag "C toc: Table of contents for Org-mode buffer" org-toc)
  187. (repeat :tag "External packages" :inline t (symbol :tag "Package"))))
  188. (defcustom org-support-shift-select nil
  189. "Non-nil means, make shift-cursor commands select text when possible.
  190. In Emacs 23, when `shift-select-mode' is on, shifted cursor keys start
  191. selecting a region, or enlarge thusly regions started in this way.
  192. In Org-mode, in special contexts, these same keys are used for other
  193. purposes, important enough to compete with shift selection. Org tries
  194. to balance these needs by supporting `shift-select-mode' outside these
  195. special contexts, under control of this variable.
  196. The default of this variable is nil, to avoid confusing behavior. Shifted
  197. cursor keys will then execute Org commands in the following contexts:
  198. - on a headline, changing TODO state (left/right) and priority (up/down)
  199. - on a time stamp, changing the time
  200. - in a plain list item, changing the bullet type
  201. - in a property definition line, switching between allowed values
  202. - in the BEGIN line of a clock table (changing the time block).
  203. Outside these contexts, the commands will throw an error.
  204. When this variable is t and the cursor is not in a special context,
  205. Org-mode will support shift-selection for making and enlarging regions.
  206. To make this more effective, the bullet cycling will no longer happen
  207. anywhere in an item line, but only if the cursor is exactly on the bullet.
  208. If you set this variable to the symbol `always', then the keys
  209. will not be special in headlines, property lines, and item lines, to make
  210. shift selection work there as well. If this is what you want, you can
  211. use the following alternative commands: `C-c C-t' and `C-c ,' to
  212. change TODO state and priority, `C-u C-u C-c C-t' can be used to switch
  213. TODO sets, `C-c -' to cycle item bullet types, and properties can be
  214. edited by hand or in column view.
  215. However, when the cursor is on a timestamp, shift-cursor commands
  216. will still edit the time stamp - this is just too good to give up.
  217. XEmacs user should have this variable set to nil, because shift-select-mode
  218. is Emacs 23 only."
  219. :group 'org
  220. :type '(choice
  221. (const :tag "Never" nil)
  222. (const :tag "When outside special context" t)
  223. (const :tag "Everywhere except timestamps" always)))
  224. (defgroup org-startup nil
  225. "Options concerning startup of Org-mode."
  226. :tag "Org Startup"
  227. :group 'org)
  228. (defcustom org-startup-folded t
  229. "Non-nil means, entering Org-mode will switch to OVERVIEW.
  230. This can also be configured on a per-file basis by adding one of
  231. the following lines anywhere in the buffer:
  232. #+STARTUP: fold
  233. #+STARTUP: nofold
  234. #+STARTUP: content"
  235. :group 'org-startup
  236. :type '(choice
  237. (const :tag "nofold: show all" nil)
  238. (const :tag "fold: overview" t)
  239. (const :tag "content: all headlines" content)))
  240. (defcustom org-startup-truncated t
  241. "Non-nil means, entering Org-mode will set `truncate-lines'.
  242. This is useful since some lines containing links can be very long and
  243. uninteresting. Also tables look terrible when wrapped."
  244. :group 'org-startup
  245. :type 'boolean)
  246. (defcustom org-startup-align-all-tables nil
  247. "Non-nil means, align all tables when visiting a file.
  248. This is useful when the column width in tables is forced with <N> cookies
  249. in table fields. Such tables will look correct only after the first re-align.
  250. This can also be configured on a per-file basis by adding one of
  251. the following lines anywhere in the buffer:
  252. #+STARTUP: align
  253. #+STARTUP: noalign"
  254. :group 'org-startup
  255. :type 'boolean)
  256. (defcustom org-insert-mode-line-in-empty-file nil
  257. "Non-nil means insert the first line setting Org-mode in empty files.
  258. When the function `org-mode' is called interactively in an empty file, this
  259. normally means that the file name does not automatically trigger Org-mode.
  260. To ensure that the file will always be in Org-mode in the future, a
  261. line enforcing Org-mode will be inserted into the buffer, if this option
  262. has been set."
  263. :group 'org-startup
  264. :type 'boolean)
  265. (defcustom org-replace-disputed-keys nil
  266. "Non-nil means use alternative key bindings for some keys.
  267. Org-mode uses S-<cursor> keys for changing timestamps and priorities.
  268. These keys are also used by other packages like shift-selection-mode'
  269. \(built into Emacs 23), `CUA-mode' or `windmove.el'.
  270. If you want to use Org-mode together with one of these other modes,
  271. or more generally if you would like to move some Org-mode commands to
  272. other keys, set this variable and configure the keys with the variable
  273. `org-disputed-keys'.
  274. This option is only relevant at load-time of Org-mode, and must be set
  275. *before* org.el is loaded. Changing it requires a restart of Emacs to
  276. become effective."
  277. :group 'org-startup
  278. :type 'boolean)
  279. (defcustom org-use-extra-keys nil
  280. "Non-nil means use extra key sequence definitions for certain
  281. commands. This happens automatically if you run XEmacs or if
  282. window-system is nil. This variable lets you do the same
  283. manually. You must set it before loading org.
  284. Example: on Carbon Emacs 22 running graphically, with an external
  285. keyboard on a Powerbook, the default way of setting M-left might
  286. not work for either Alt or ESC. Setting this variable will make
  287. it work for ESC."
  288. :group 'org-startup
  289. :type 'boolean)
  290. (if (fboundp 'defvaralias)
  291. (defvaralias 'org-CUA-compatible 'org-replace-disputed-keys))
  292. (defcustom org-disputed-keys
  293. '(([(shift up)] . [(meta p)])
  294. ([(shift down)] . [(meta n)])
  295. ([(shift left)] . [(meta -)])
  296. ([(shift right)] . [(meta +)])
  297. ([(control shift right)] . [(meta shift +)])
  298. ([(control shift left)] . [(meta shift -)]))
  299. "Keys for which Org-mode and other modes compete.
  300. This is an alist, cars are the default keys, second element specifies
  301. the alternative to use when `org-replace-disputed-keys' is t.
  302. Keys can be specified in any syntax supported by `define-key'.
  303. The value of this option takes effect only at Org-mode's startup,
  304. therefore you'll have to restart Emacs to apply it after changing."
  305. :group 'org-startup
  306. :type 'alist)
  307. (defun org-key (key)
  308. "Select key according to `org-replace-disputed-keys' and `org-disputed-keys'.
  309. Or return the original if not disputed."
  310. (if org-replace-disputed-keys
  311. (let* ((nkey (key-description key))
  312. (x (org-find-if (lambda (x)
  313. (equal (key-description (car x)) nkey))
  314. org-disputed-keys)))
  315. (if x (cdr x) key))
  316. key))
  317. (defun org-find-if (predicate seq)
  318. (catch 'exit
  319. (while seq
  320. (if (funcall predicate (car seq))
  321. (throw 'exit (car seq))
  322. (pop seq)))))
  323. (defun org-defkey (keymap key def)
  324. "Define a key, possibly translated, as returned by `org-key'."
  325. (define-key keymap (org-key key) def))
  326. (defcustom org-ellipsis nil
  327. "The ellipsis to use in the Org-mode outline.
  328. When nil, just use the standard three dots. When a string, use that instead,
  329. When a face, use the standard 3 dots, but with the specified face.
  330. The change affects only Org-mode (which will then use its own display table).
  331. Changing this requires executing `M-x org-mode' in a buffer to become
  332. effective."
  333. :group 'org-startup
  334. :type '(choice (const :tag "Default" nil)
  335. (face :tag "Face" :value org-warning)
  336. (string :tag "String" :value "...#")))
  337. (defvar org-display-table nil
  338. "The display table for org-mode, in case `org-ellipsis' is non-nil.")
  339. (defgroup org-keywords nil
  340. "Keywords in Org-mode."
  341. :tag "Org Keywords"
  342. :group 'org)
  343. (defcustom org-deadline-string "DEADLINE:"
  344. "String to mark deadline entries.
  345. A deadline is this string, followed by a time stamp. Should be a word,
  346. terminated by a colon. You can insert a schedule keyword and
  347. a timestamp with \\[org-deadline].
  348. Changes become only effective after restarting Emacs."
  349. :group 'org-keywords
  350. :type 'string)
  351. (defcustom org-scheduled-string "SCHEDULED:"
  352. "String to mark scheduled TODO entries.
  353. A schedule is this string, followed by a time stamp. Should be a word,
  354. terminated by a colon. You can insert a schedule keyword and
  355. a timestamp with \\[org-schedule].
  356. Changes become only effective after restarting Emacs."
  357. :group 'org-keywords
  358. :type 'string)
  359. (defcustom org-closed-string "CLOSED:"
  360. "String used as the prefix for timestamps logging closing a TODO entry."
  361. :group 'org-keywords
  362. :type 'string)
  363. (defcustom org-clock-string "CLOCK:"
  364. "String used as prefix for timestamps clocking work hours on an item."
  365. :group 'org-keywords
  366. :type 'string)
  367. (defcustom org-comment-string "COMMENT"
  368. "Entries starting with this keyword will never be exported.
  369. An entry can be toggled between COMMENT and normal with
  370. \\[org-toggle-comment].
  371. Changes become only effective after restarting Emacs."
  372. :group 'org-keywords
  373. :type 'string)
  374. (defcustom org-quote-string "QUOTE"
  375. "Entries starting with this keyword will be exported in fixed-width font.
  376. Quoting applies only to the text in the entry following the headline, and does
  377. not extend beyond the next headline, even if that is lower level.
  378. An entry can be toggled between QUOTE and normal with
  379. \\[org-toggle-fixed-width-section]."
  380. :group 'org-keywords
  381. :type 'string)
  382. (defconst org-repeat-re
  383. "<[0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9] [^>\n]*\\([.+]?\\+[0-9]+[dwmy]\\)"
  384. "Regular expression for specifying repeated events.
  385. After a match, group 1 contains the repeat expression.")
  386. (defgroup org-structure nil
  387. "Options concerning the general structure of Org-mode files."
  388. :tag "Org Structure"
  389. :group 'org)
  390. (defgroup org-reveal-location nil
  391. "Options about how to make context of a location visible."
  392. :tag "Org Reveal Location"
  393. :group 'org-structure)
  394. (defconst org-context-choice
  395. '(choice
  396. (const :tag "Always" t)
  397. (const :tag "Never" nil)
  398. (repeat :greedy t :tag "Individual contexts"
  399. (cons
  400. (choice :tag "Context"
  401. (const agenda)
  402. (const org-goto)
  403. (const occur-tree)
  404. (const tags-tree)
  405. (const link-search)
  406. (const mark-goto)
  407. (const bookmark-jump)
  408. (const isearch)
  409. (const default))
  410. (boolean))))
  411. "Contexts for the reveal options.")
  412. (defcustom org-show-hierarchy-above '((default . t))
  413. "Non-nil means, show full hierarchy when revealing a location.
  414. Org-mode often shows locations in an org-mode file which might have
  415. been invisible before. When this is set, the hierarchy of headings
  416. above the exposed location is shown.
  417. Turning this off for example for sparse trees makes them very compact.
  418. Instead of t, this can also be an alist specifying this option for different
  419. contexts. Valid contexts are
  420. agenda when exposing an entry from the agenda
  421. org-goto when using the command `org-goto' on key C-c C-j
  422. occur-tree when using the command `org-occur' on key C-c /
  423. tags-tree when constructing a sparse tree based on tags matches
  424. link-search when exposing search matches associated with a link
  425. mark-goto when exposing the jump goal of a mark
  426. bookmark-jump when exposing a bookmark location
  427. isearch when exiting from an incremental search
  428. default default for all contexts not set explicitly"
  429. :group 'org-reveal-location
  430. :type org-context-choice)
  431. (defcustom org-show-following-heading '((default . nil))
  432. "Non-nil means, show following heading when revealing a location.
  433. Org-mode often shows locations in an org-mode file which might have
  434. been invisible before. When this is set, the heading following the
  435. match is shown.
  436. Turning this off for example for sparse trees makes them very compact,
  437. but makes it harder to edit the location of the match. In such a case,
  438. use the command \\[org-reveal] to show more context.
  439. Instead of t, this can also be an alist specifying this option for different
  440. contexts. See `org-show-hierarchy-above' for valid contexts."
  441. :group 'org-reveal-location
  442. :type org-context-choice)
  443. (defcustom org-show-siblings '((default . nil) (isearch t))
  444. "Non-nil means, show all sibling heading when revealing a location.
  445. Org-mode often shows locations in an org-mode file which might have
  446. been invisible before. When this is set, the sibling of the current entry
  447. heading are all made visible. If `org-show-hierarchy-above' is t,
  448. the same happens on each level of the hierarchy above the current entry.
  449. By default this is on for the isearch context, off for all other contexts.
  450. Turning this off for example for sparse trees makes them very compact,
  451. but makes it harder to edit the location of the match. In such a case,
  452. use the command \\[org-reveal] to show more context.
  453. Instead of t, this can also be an alist specifying this option for different
  454. contexts. See `org-show-hierarchy-above' for valid contexts."
  455. :group 'org-reveal-location
  456. :type org-context-choice)
  457. (defcustom org-show-entry-below '((default . nil))
  458. "Non-nil means, show the entry below a headline when revealing a location.
  459. Org-mode often shows locations in an org-mode file which might have
  460. been invisible before. When this is set, the text below the headline that is
  461. exposed is also shown.
  462. By default this is off for all contexts.
  463. Instead of t, this can also be an alist specifying this option for different
  464. contexts. See `org-show-hierarchy-above' for valid contexts."
  465. :group 'org-reveal-location
  466. :type org-context-choice)
  467. (defcustom org-indirect-buffer-display 'other-window
  468. "How should indirect tree buffers be displayed?
  469. This applies to indirect buffers created with the commands
  470. \\[org-tree-to-indirect-buffer] and \\[org-agenda-tree-to-indirect-buffer].
  471. Valid values are:
  472. current-window Display in the current window
  473. other-window Just display in another window.
  474. dedicated-frame Create one new frame, and re-use it each time.
  475. new-frame Make a new frame each time. Note that in this case
  476. previously-made indirect buffers are kept, and you need to
  477. kill these buffers yourself."
  478. :group 'org-structure
  479. :group 'org-agenda-windows
  480. :type '(choice
  481. (const :tag "In current window" current-window)
  482. (const :tag "In current frame, other window" other-window)
  483. (const :tag "Each time a new frame" new-frame)
  484. (const :tag "One dedicated frame" dedicated-frame)))
  485. (defgroup org-cycle nil
  486. "Options concerning visibility cycling in Org-mode."
  487. :tag "Org Cycle"
  488. :group 'org-structure)
  489. (defcustom org-cycle-max-level nil
  490. "Maximum level which should still be subject to visibility cycling.
  491. Levels higher than this will, for cycling, be treated as text, not a headline.
  492. When `org-odd-levels-only' is set, a value of N in this variable actually
  493. means 2N-1 stars as the limiting headline.
  494. When nil, cycle all levels.
  495. Note that the limiting level of cycling is also influenced by
  496. `org-inlinetask-min-level'. When `org-cycle-max-level' is not set but
  497. `org-inlinetask-min-level' is, cycling will be limited to levels one less
  498. than its value."
  499. :group 'org-cycle
  500. :type '(choice
  501. (const :tag "No limit" nil)
  502. (integer :tag "Maximum level")))
  503. (defcustom org-drawers '("PROPERTIES" "CLOCK" "LOGBOOK")
  504. "Names of drawers. Drawers are not opened by cycling on the headline above.
  505. Drawers only open with a TAB on the drawer line itself. A drawer looks like
  506. this:
  507. :DRAWERNAME:
  508. .....
  509. :END:
  510. The drawer \"PROPERTIES\" is special for capturing properties through
  511. the property API.
  512. Drawers can be defined on the per-file basis with a line like:
  513. #+DRAWERS: HIDDEN STATE PROPERTIES"
  514. :group 'org-structure
  515. :group 'org-cycle
  516. :type '(repeat (string :tag "Drawer Name")))
  517. (defcustom org-hide-block-startup nil
  518. "Non-nil means, , entering Org-mode will fold all blocks.
  519. This can also be set in on a per-file basis with
  520. #+STARTUP: hideblocks
  521. #+STARTUP: showblocks"
  522. :group 'org-startup
  523. :group 'org-cycle
  524. :type 'boolean)
  525. (defcustom org-cycle-global-at-bob nil
  526. "Cycle globally if cursor is at beginning of buffer and not at a headline.
  527. This makes it possible to do global cycling without having to use S-TAB or
  528. C-u TAB. For this special case to work, the first line of the buffer
  529. must not be a headline - it may be empty or some other text. When used in
  530. this way, `org-cycle-hook' is disables temporarily, to make sure the
  531. cursor stays at the beginning of the buffer.
  532. When this option is nil, don't do anything special at the beginning
  533. of the buffer."
  534. :group 'org-cycle
  535. :type 'boolean)
  536. (defcustom org-cycle-emulate-tab t
  537. "Where should `org-cycle' emulate TAB.
  538. nil Never
  539. white Only in completely white lines
  540. whitestart Only at the beginning of lines, before the first non-white char
  541. t Everywhere except in headlines
  542. exc-hl-bol Everywhere except at the start of a headline
  543. If TAB is used in a place where it does not emulate TAB, the current subtree
  544. visibility is cycled."
  545. :group 'org-cycle
  546. :type '(choice (const :tag "Never" nil)
  547. (const :tag "Only in completely white lines" white)
  548. (const :tag "Before first char in a line" whitestart)
  549. (const :tag "Everywhere except in headlines" t)
  550. (const :tag "Everywhere except at bol in headlines" exc-hl-bol)
  551. ))
  552. (defcustom org-cycle-separator-lines 2
  553. "Number of empty lines needed to keep an empty line between collapsed trees.
  554. If you leave an empty line between the end of a subtree and the following
  555. headline, this empty line is hidden when the subtree is folded.
  556. Org-mode will leave (exactly) one empty line visible if the number of
  557. empty lines is equal or larger to the number given in this variable.
  558. So the default 2 means, at least 2 empty lines after the end of a subtree
  559. are needed to produce free space between a collapsed subtree and the
  560. following headline.
  561. Special case: when 0, never leave empty lines in collapsed view."
  562. :group 'org-cycle
  563. :type 'integer)
  564. (put 'org-cycle-separator-lines 'safe-local-variable 'integerp)
  565. (defcustom org-pre-cycle-hook nil
  566. "Hook that is run before visibility cycling is happening.
  567. The function(s) in this hook must accept a single argument which indicates
  568. the new state that will be set right after running this hook. The
  569. argument is a symbol. Before a global state change, it can have the values
  570. `overview', `content', or `all'. Before a local state change, it can have
  571. the values `folded', `children', or `subtree'."
  572. :group 'org-cycle
  573. :type 'hook)
  574. (defcustom org-cycle-hook '(org-cycle-hide-archived-subtrees
  575. org-cycle-hide-drawers
  576. org-cycle-show-empty-lines
  577. org-optimize-window-after-visibility-change)
  578. "Hook that is run after `org-cycle' has changed the buffer visibility.
  579. The function(s) in this hook must accept a single argument which indicates
  580. the new state that was set by the most recent `org-cycle' command. The
  581. argument is a symbol. After a global state change, it can have the values
  582. `overview', `content', or `all'. After a local state change, it can have
  583. the values `folded', `children', or `subtree'."
  584. :group 'org-cycle
  585. :type 'hook)
  586. (defgroup org-edit-structure nil
  587. "Options concerning structure editing in Org-mode."
  588. :tag "Org Edit Structure"
  589. :group 'org-structure)
  590. (defcustom org-odd-levels-only nil
  591. "Non-nil means, skip even levels and only use odd levels for the outline.
  592. This has the effect that two stars are being added/taken away in
  593. promotion/demotion commands. It also influences how levels are
  594. handled by the exporters.
  595. Changing it requires restart of `font-lock-mode' to become effective
  596. for fontification also in regions already fontified.
  597. You may also set this on a per-file basis by adding one of the following
  598. lines to the buffer:
  599. #+STARTUP: odd
  600. #+STARTUP: oddeven"
  601. :group 'org-edit-structure
  602. :group 'org-font-lock
  603. :type 'boolean)
  604. (defcustom org-adapt-indentation t
  605. "Non-nil means, adapt indentation when promoting and demoting.
  606. When this is set and the *entire* text in an entry is indented, the
  607. indentation is increased by one space in a demotion command, and
  608. decreased by one in a promotion command. If any line in the entry
  609. body starts at column 0, indentation is not changed at all.
  610. This variable also influences how property drawers and planning
  611. information is inserted. When t, these lines drawers will be inserted
  612. indented. When nil, they will not be indented."
  613. :group 'org-edit-structure
  614. :type 'boolean)
  615. (defcustom org-special-ctrl-a/e nil
  616. "Non-nil means `C-a' and `C-e' behave specially in headlines and items.
  617. When t, `C-a' will bring back the cursor to the beginning of the
  618. headline text, i.e. after the stars and after a possible TODO keyword.
  619. In an item, this will be the position after the bullet.
  620. When the cursor is already at that position, another `C-a' will bring
  621. it to the beginning of the line.
  622. `C-e' will jump to the end of the headline, ignoring the presence of tags
  623. in the headline. A second `C-e' will then jump to the true end of the
  624. line, after any tags.
  625. When set to the symbol `reversed', the first `C-a' or `C-e' works normally,
  626. going to the true line boundary first. Only a directly following, identical
  627. keypress will bring the cursor to the special positions.
  628. This may also be a cons cell where the behavior for `C-a' and `C-e' is
  629. set separately."
  630. :group 'org-edit-structure
  631. :type '(choice
  632. (const :tag "off" nil)
  633. (const :tag "after stars/bullet and before tags first" t)
  634. (const :tag "true line boundary first" reversed)
  635. (cons :tag "Set C-a and C-e separately"
  636. (choice :tag "Special C-a"
  637. (const :tag "off" nil)
  638. (const :tag "after stars/bullet first" t)
  639. (const :tag "before stars/bullet first" reversed))
  640. (choice :tag "Special C-e"
  641. (const :tag "off" nil)
  642. (const :tag "before tags first" t)
  643. (const :tag "after tags first" reversed)))))
  644. (if (fboundp 'defvaralias)
  645. (defvaralias 'org-special-ctrl-a 'org-special-ctrl-a/e))
  646. (defcustom org-special-ctrl-k nil
  647. "Non-nil means `C-k' will behave specially in headlines.
  648. When nil, `C-k' will call the default `kill-line' command.
  649. When t, the following will happen while the cursor is in the headline:
  650. - When the cursor is at the beginning of a headline, kill the entire
  651. line and possible the folded subtree below the line.
  652. - When in the middle of the headline text, kill the headline up to the tags.
  653. - When after the headline text, kill the tags."
  654. :group 'org-edit-structure
  655. :type 'boolean)
  656. (defcustom org-yank-folded-subtrees t
  657. "Non-nil means, when yanking subtrees, fold them.
  658. If the kill is a single subtree, or a sequence of subtrees, i.e. if
  659. it starts with a heading and all other headings in it are either children
  660. or siblings, then fold all the subtrees. However, do this only if no
  661. text after the yank would be swallowed into a folded tree by this action."
  662. :group 'org-edit-structure
  663. :type 'boolean)
  664. (defcustom org-yank-adjusted-subtrees nil
  665. "Non-nil means, when yanking subtrees, adjust the level.
  666. With this setting, `org-paste-subtree' is used to insert the subtree, see
  667. this function for details."
  668. :group 'org-edit-structure
  669. :type 'boolean)
  670. (defcustom org-M-RET-may-split-line '((default . t))
  671. "Non-nil means, M-RET will split the line at the cursor position.
  672. When nil, it will go to the end of the line before making a
  673. new line.
  674. You may also set this option in a different way for different
  675. contexts. Valid contexts are:
  676. headline when creating a new headline
  677. item when creating a new item
  678. table in a table field
  679. default the value to be used for all contexts not explicitly
  680. customized"
  681. :group 'org-structure
  682. :group 'org-table
  683. :type '(choice
  684. (const :tag "Always" t)
  685. (const :tag "Never" nil)
  686. (repeat :greedy t :tag "Individual contexts"
  687. (cons
  688. (choice :tag "Context"
  689. (const headline)
  690. (const item)
  691. (const table)
  692. (const default))
  693. (boolean)))))
  694. (defcustom org-insert-heading-respect-content nil
  695. "Non-nil means, insert new headings after the current subtree.
  696. When nil, the new heading is created directly after the current line.
  697. The commands \\[org-insert-heading-respect-content] and
  698. \\[org-insert-todo-heading-respect-content] turn this variable on
  699. for the duration of the command."
  700. :group 'org-structure
  701. :type 'boolean)
  702. (defcustom org-blank-before-new-entry '((heading . auto)
  703. (plain-list-item . auto))
  704. "Should `org-insert-heading' leave a blank line before new heading/item?
  705. The value is an alist, with `heading' and `plain-list-item' as car,
  706. and a boolean flag as cdr. For plain lists, if the variable
  707. `org-empty-line-terminates-plain-lists' is set, the setting here
  708. is ignored and no empty line is inserted, to keep the list in tact."
  709. :group 'org-edit-structure
  710. :type '(list
  711. (cons (const heading)
  712. (choice (const :tag "Never" nil)
  713. (const :tag "Always" t)
  714. (const :tag "Auto" auto)))
  715. (cons (const plain-list-item)
  716. (choice (const :tag "Never" nil)
  717. (const :tag "Always" t)
  718. (const :tag "Auto" auto)))))
  719. (defcustom org-insert-heading-hook nil
  720. "Hook being run after inserting a new heading."
  721. :group 'org-edit-structure
  722. :type 'hook)
  723. (defcustom org-enable-fixed-width-editor t
  724. "Non-nil means, lines starting with \":\" are treated as fixed-width.
  725. This currently only means, they are never auto-wrapped.
  726. When nil, such lines will be treated like ordinary lines.
  727. See also the QUOTE keyword."
  728. :group 'org-edit-structure
  729. :type 'boolean)
  730. (defcustom org-goto-auto-isearch t
  731. "Non-nil means, typing characters in org-goto starts incremental search."
  732. :group 'org-edit-structure
  733. :type 'boolean)
  734. (defgroup org-sparse-trees nil
  735. "Options concerning sparse trees in Org-mode."
  736. :tag "Org Sparse Trees"
  737. :group 'org-structure)
  738. (defcustom org-highlight-sparse-tree-matches t
  739. "Non-nil means, highlight all matches that define a sparse tree.
  740. The highlights will automatically disappear the next time the buffer is
  741. changed by an edit command."
  742. :group 'org-sparse-trees
  743. :type 'boolean)
  744. (defcustom org-remove-highlights-with-change t
  745. "Non-nil means, any change to the buffer will remove temporary highlights.
  746. Such highlights are created by `org-occur' and `org-clock-display'.
  747. When nil, `C-c C-c needs to be used to get rid of the highlights.
  748. The highlights created by `org-preview-latex-fragment' always need
  749. `C-c C-c' to be removed."
  750. :group 'org-sparse-trees
  751. :group 'org-time
  752. :type 'boolean)
  753. (defcustom org-occur-hook '(org-first-headline-recenter)
  754. "Hook that is run after `org-occur' has constructed a sparse tree.
  755. This can be used to recenter the window to show as much of the structure
  756. as possible."
  757. :group 'org-sparse-trees
  758. :type 'hook)
  759. (defgroup org-imenu-and-speedbar nil
  760. "Options concerning imenu and speedbar in Org-mode."
  761. :tag "Org Imenu and Speedbar"
  762. :group 'org-structure)
  763. (defcustom org-imenu-depth 2
  764. "The maximum level for Imenu access to Org-mode headlines.
  765. This also applied for speedbar access."
  766. :group 'org-imenu-and-speedbar
  767. :type 'integer)
  768. (defgroup org-table nil
  769. "Options concerning tables in Org-mode."
  770. :tag "Org Table"
  771. :group 'org)
  772. (defcustom org-enable-table-editor 'optimized
  773. "Non-nil means, lines starting with \"|\" are handled by the table editor.
  774. When nil, such lines will be treated like ordinary lines.
  775. When equal to the symbol `optimized', the table editor will be optimized to
  776. do the following:
  777. - Automatic overwrite mode in front of whitespace in table fields.
  778. This makes the structure of the table stay in tact as long as the edited
  779. field does not exceed the column width.
  780. - Minimize the number of realigns. Normally, the table is aligned each time
  781. TAB or RET are pressed to move to another field. With optimization this
  782. happens only if changes to a field might have changed the column width.
  783. Optimization requires replacing the functions `self-insert-command',
  784. `delete-char', and `backward-delete-char' in Org-mode buffers, with a
  785. slight (in fact: unnoticeable) speed impact for normal typing. Org-mode is
  786. very good at guessing when a re-align will be necessary, but you can always
  787. force one with \\[org-ctrl-c-ctrl-c].
  788. If you would like to use the optimized version in Org-mode, but the
  789. un-optimized version in OrgTbl-mode, see the variable `orgtbl-optimized'.
  790. This variable can be used to turn on and off the table editor during a session,
  791. but in order to toggle optimization, a restart is required.
  792. See also the variable `org-table-auto-blank-field'."
  793. :group 'org-table
  794. :type '(choice
  795. (const :tag "off" nil)
  796. (const :tag "on" t)
  797. (const :tag "on, optimized" optimized)))
  798. (defcustom org-self-insert-cluster-for-undo t
  799. "Non-nil means cluster self-insert commands for undo when possible.
  800. If this is set, then, like in the Emacs command loop, 20 consequtive
  801. characters will be undone together.
  802. This is configurable, because there is some impact on typing performance."
  803. :group 'org-table
  804. :type 'boolean)
  805. (defcustom org-table-tab-recognizes-table.el t
  806. "Non-nil means, TAB will automatically notice a table.el table.
  807. When it sees such a table, it moves point into it and - if necessary -
  808. calls `table-recognize-table'."
  809. :group 'org-table-editing
  810. :type 'boolean)
  811. (defgroup org-link nil
  812. "Options concerning links in Org-mode."
  813. :tag "Org Link"
  814. :group 'org)
  815. (defvar org-link-abbrev-alist-local nil
  816. "Buffer-local version of `org-link-abbrev-alist', which see.
  817. The value of this is taken from the #+LINK lines.")
  818. (make-variable-buffer-local 'org-link-abbrev-alist-local)
  819. (defcustom org-link-abbrev-alist nil
  820. "Alist of link abbreviations.
  821. The car of each element is a string, to be replaced at the start of a link.
  822. The cdrs are replacement values, like (\"linkkey\" . REPLACE). Abbreviated
  823. links in Org-mode buffers can have an optional tag after a double colon, e.g.
  824. [[linkkey:tag][description]]
  825. The 'linkkey' must be a word word, starting with a letter, followed
  826. by letters, numbers, '-' or '_'.
  827. If REPLACE is a string, the tag will simply be appended to create the link.
  828. If the string contains \"%s\", the tag will be inserted there. Alternatively,
  829. the placeholder \"%h\" will cause a url-encoded version of the tag to
  830. be inserted at that point (see the function `url-hexify-string').
  831. REPLACE may also be a function that will be called with the tag as the
  832. only argument to create the link, which should be returned as a string.
  833. See the manual for examples."
  834. :group 'org-link
  835. :type '(repeat
  836. (cons
  837. (string :tag "Protocol")
  838. (choice
  839. (string :tag "Format")
  840. (function)))))
  841. (defcustom org-descriptive-links t
  842. "Non-nil means, hide link part and only show description of bracket links.
  843. Bracket links are like [[link][description]]. This variable sets the initial
  844. state in new org-mode buffers. The setting can then be toggled on a
  845. per-buffer basis from the Org->Hyperlinks menu."
  846. :group 'org-link
  847. :type 'boolean)
  848. (defcustom org-link-file-path-type 'adaptive
  849. "How the path name in file links should be stored.
  850. Valid values are:
  851. relative Relative to the current directory, i.e. the directory of the file
  852. into which the link is being inserted.
  853. absolute Absolute path, if possible with ~ for home directory.
  854. noabbrev Absolute path, no abbreviation of home directory.
  855. adaptive Use relative path for files in the current directory and sub-
  856. directories of it. For other files, use an absolute path."
  857. :group 'org-link
  858. :type '(choice
  859. (const relative)
  860. (const absolute)
  861. (const noabbrev)
  862. (const adaptive)))
  863. (defcustom org-activate-links '(bracket angle plain radio tag date footnote)
  864. "Types of links that should be activated in Org-mode files.
  865. This is a list of symbols, each leading to the activation of a certain link
  866. type. In principle, it does not hurt to turn on most link types - there may
  867. be a small gain when turning off unused link types. The types are:
  868. bracket The recommended [[link][description]] or [[link]] links with hiding.
  869. angular Links in angular brackets that may contain whitespace like
  870. <bbdb:Carsten Dominik>.
  871. plain Plain links in normal text, no whitespace, like http://google.com.
  872. radio Text that is matched by a radio target, see manual for details.
  873. tag Tag settings in a headline (link to tag search).
  874. date Time stamps (link to calendar).
  875. footnote Footnote labels.
  876. Changing this variable requires a restart of Emacs to become effective."
  877. :group 'org-link
  878. :type '(set :greedy t
  879. (const :tag "Double bracket links (new style)" bracket)
  880. (const :tag "Angular bracket links (old style)" angular)
  881. (const :tag "Plain text links" plain)
  882. (const :tag "Radio target matches" radio)
  883. (const :tag "Tags" tag)
  884. (const :tag "Timestamps" date)
  885. (const :tag "Footnotes" footnote)))
  886. (defcustom org-make-link-description-function nil
  887. "Function to use to generate link descriptions from links. If
  888. nil the link location will be used. This function must take two
  889. parameters; the first is the link and the second the description
  890. org-insert-link has generated, and should return the description
  891. to use."
  892. :group 'org-link
  893. :type 'function)
  894. (defgroup org-link-store nil
  895. "Options concerning storing links in Org-mode."
  896. :tag "Org Store Link"
  897. :group 'org-link)
  898. (defcustom org-email-link-description-format "Email %c: %.30s"
  899. "Format of the description part of a link to an email or usenet message.
  900. The following %-escapes will be replaced by corresponding information:
  901. %F full \"From\" field
  902. %f name, taken from \"From\" field, address if no name
  903. %T full \"To\" field
  904. %t first name in \"To\" field, address if no name
  905. %c correspondent. Usually \"from NAME\", but if you sent it yourself, it
  906. will be \"to NAME\". See also the variable `org-from-is-user-regexp'.
  907. %s subject
  908. %m message-id.
  909. You may use normal field width specification between the % and the letter.
  910. This is for example useful to limit the length of the subject.
  911. Examples: \"%f on: %.30s\", \"Email from %f\", \"Email %c\""
  912. :group 'org-link-store
  913. :type 'string)
  914. (defcustom org-from-is-user-regexp
  915. (let (r1 r2)
  916. (when (and user-mail-address (not (string= user-mail-address "")))
  917. (setq r1 (concat "\\<" (regexp-quote user-mail-address) "\\>")))
  918. (when (and user-full-name (not (string= user-full-name "")))
  919. (setq r2 (concat "\\<" (regexp-quote user-full-name) "\\>")))
  920. (if (and r1 r2) (concat r1 "\\|" r2) (or r1 r2)))
  921. "Regexp matched against the \"From:\" header of an email or usenet message.
  922. It should match if the message is from the user him/herself."
  923. :group 'org-link-store
  924. :type 'regexp)
  925. (defcustom org-link-to-org-use-id 'create-if-interactive-and-no-custom-id
  926. "Non-nil means, storing a link to an Org file will use entry IDs.
  927. Note that before this variable is even considered, org-id must be loaded,
  928. so please customize `org-modules' and turn it on.
  929. The variable can have the following values:
  930. t Create an ID if needed to make a link to the current entry.
  931. create-if-interactive
  932. If `org-store-link' is called directly (interactively, as a user
  933. command), do create an ID to support the link. But when doing the
  934. job for remember, only use the ID if it already exists. The
  935. purpose of this setting is to avoid proliferation of unwanted
  936. IDs, just because you happen to be in an Org file when you
  937. call `org-remember' that automatically and preemptively
  938. creates a link. If you do want to get an ID link in a remember
  939. template to an entry not having an ID, create it first by
  940. explicitly creating a link to it, using `C-c C-l' first.
  941. create-if-interactive-and-no-custom-id
  942. Like create-if-interactive, but do not create an ID if there is
  943. a CUSTOM_ID property defined in the entry. This is the default.
  944. use-existing
  945. Use existing ID, do not create one.
  946. nil Never use an ID to make a link, instead link using a text search for
  947. the headline text."
  948. :group 'org-link-store
  949. :type '(choice
  950. (const :tag "Create ID to make link" t)
  951. (const :tag "Create if storing link interactively"
  952. create-if-interactive)
  953. (const :tag "Create if storing link interactively and no CUSTOM_ID is present"
  954. create-if-interactive-and-no-custom-id)
  955. (const :tag "Only use existing" use-existing)
  956. (const :tag "Do not use ID to create link" nil)))
  957. (defcustom org-context-in-file-links t
  958. "Non-nil means, file links from `org-store-link' contain context.
  959. A search string will be added to the file name with :: as separator and
  960. used to find the context when the link is activated by the command
  961. `org-open-at-point'.
  962. Using a prefix arg to the command \\[org-store-link] (`org-store-link')
  963. negates this setting for the duration of the command."
  964. :group 'org-link-store
  965. :type 'boolean)
  966. (defcustom org-keep-stored-link-after-insertion nil
  967. "Non-nil means, keep link in list for entire session.
  968. The command `org-store-link' adds a link pointing to the current
  969. location to an internal list. These links accumulate during a session.
  970. The command `org-insert-link' can be used to insert links into any
  971. Org-mode file (offering completion for all stored links). When this
  972. option is nil, every link which has been inserted once using \\[org-insert-link]
  973. will be removed from the list, to make completing the unused links
  974. more efficient."
  975. :group 'org-link-store
  976. :type 'boolean)
  977. (defgroup org-link-follow nil
  978. "Options concerning following links in Org-mode."
  979. :tag "Org Follow Link"
  980. :group 'org-link)
  981. (defcustom org-link-translation-function nil
  982. "Function to translate links with different syntax to Org syntax.
  983. This can be used to translate links created for example by the Planner
  984. or emacs-wiki packages to Org syntax.
  985. The function must accept two parameters, a TYPE containing the link
  986. protocol name like \"rmail\" or \"gnus\" as a string, and the linked path,
  987. which is everything after the link protocol. It should return a cons
  988. with possibly modified values of type and path.
  989. Org contains a function for this, so if you set this variable to
  990. `org-translate-link-from-planner', you should be able follow many
  991. links created by planner."
  992. :group 'org-link-follow
  993. :type 'function)
  994. (defcustom org-follow-link-hook nil
  995. "Hook that is run after a link has been followed."
  996. :group 'org-link-follow
  997. :type 'hook)
  998. (defcustom org-tab-follows-link nil
  999. "Non-nil means, on links TAB will follow the link.
  1000. Needs to be set before org.el is loaded.
  1001. This really should not be used, it does not make sense, and the
  1002. implementation is bad."
  1003. :group 'org-link-follow
  1004. :type 'boolean)
  1005. (defcustom org-return-follows-link nil
  1006. "Non-nil means, on links RET will follow the link.
  1007. Needs to be set before org.el is loaded."
  1008. :group 'org-link-follow
  1009. :type 'boolean)
  1010. (defcustom org-mouse-1-follows-link
  1011. (if (boundp 'mouse-1-click-follows-link) mouse-1-click-follows-link t)
  1012. "Non-nil means, mouse-1 on a link will follow the link.
  1013. A longer mouse click will still set point. Does not work on XEmacs.
  1014. Needs to be set before org.el is loaded."
  1015. :group 'org-link-follow
  1016. :type 'boolean)
  1017. (defcustom org-mark-ring-length 4
  1018. "Number of different positions to be recorded in the ring
  1019. Changing this requires a restart of Emacs to work correctly."
  1020. :group 'org-link-follow
  1021. :type 'integer)
  1022. (defcustom org-link-frame-setup
  1023. '((vm . vm-visit-folder-other-frame)
  1024. (gnus . gnus-other-frame)
  1025. (file . find-file-other-window))
  1026. "Setup the frame configuration for following links.
  1027. When following a link with Emacs, it may often be useful to display
  1028. this link in another window or frame. This variable can be used to
  1029. set this up for the different types of links.
  1030. For VM, use any of
  1031. `vm-visit-folder'
  1032. `vm-visit-folder-other-frame'
  1033. For Gnus, use any of
  1034. `gnus'
  1035. `gnus-other-frame'
  1036. `org-gnus-no-new-news'
  1037. For FILE, use any of
  1038. `find-file'
  1039. `find-file-other-window'
  1040. `find-file-other-frame'
  1041. For the calendar, use the variable `calendar-setup'.
  1042. For BBDB, it is currently only possible to display the matches in
  1043. another window."
  1044. :group 'org-link-follow
  1045. :type '(list
  1046. (cons (const vm)
  1047. (choice
  1048. (const vm-visit-folder)
  1049. (const vm-visit-folder-other-window)
  1050. (const vm-visit-folder-other-frame)))
  1051. (cons (const gnus)
  1052. (choice
  1053. (const gnus)
  1054. (const gnus-other-frame)
  1055. (const org-gnus-no-new-news)))
  1056. (cons (const file)
  1057. (choice
  1058. (const find-file)
  1059. (const find-file-other-window)
  1060. (const find-file-other-frame)))))
  1061. (defcustom org-display-internal-link-with-indirect-buffer nil
  1062. "Non-nil means, use indirect buffer to display infile links.
  1063. Activating internal links (from one location in a file to another location
  1064. in the same file) normally just jumps to the location. When the link is
  1065. activated with a C-u prefix (or with mouse-3), the link is displayed in
  1066. another window. When this option is set, the other window actually displays
  1067. an indirect buffer clone of the current buffer, to avoid any visibility
  1068. changes to the current buffer."
  1069. :group 'org-link-follow
  1070. :type 'boolean)
  1071. (defcustom org-open-non-existing-files nil
  1072. "Non-nil means, `org-open-file' will open non-existing files.
  1073. When nil, an error will be generated.
  1074. This variable applies only to external applications because they
  1075. might choke on non-existing files. If the link is to a file that
  1076. will be openend in Emacs, the variable is ignored."
  1077. :group 'org-link-follow
  1078. :type 'boolean)
  1079. (defcustom org-open-directory-means-index-dot-org nil
  1080. "Non-nil means, a link to a directory really means to index.org.
  1081. When nil, following a directory link will run dired or open a finder/explorer
  1082. window on that directory."
  1083. :group 'org-link-follow
  1084. :type 'boolean)
  1085. (defcustom org-link-mailto-program '(browse-url "mailto:%a?subject=%s")
  1086. "Function and arguments to call for following mailto links.
  1087. This is a list with the first element being a lisp function, and the
  1088. remaining elements being arguments to the function. In string arguments,
  1089. %a will be replaced by the address, and %s will be replaced by the subject
  1090. if one was given like in <mailto:arthur@galaxy.org::this subject>."
  1091. :group 'org-link-follow
  1092. :type '(choice
  1093. (const :tag "browse-url" (browse-url-mail "mailto:%a?subject=%s"))
  1094. (const :tag "compose-mail" (compose-mail "%a" "%s"))
  1095. (const :tag "message-mail" (message-mail "%a" "%s"))
  1096. (cons :tag "other" (function) (repeat :tag "argument" sexp))))
  1097. (defcustom org-confirm-shell-link-function 'yes-or-no-p
  1098. "Non-nil means, ask for confirmation before executing shell links.
  1099. Shell links can be dangerous: just think about a link
  1100. [[shell:rm -rf ~/*][Google Search]]
  1101. This link would show up in your Org-mode document as \"Google Search\",
  1102. but really it would remove your entire home directory.
  1103. Therefore we advise against setting this variable to nil.
  1104. Just change it to `y-or-n-p' if you want to confirm with a
  1105. single keystroke rather than having to type \"yes\"."
  1106. :group 'org-link-follow
  1107. :type '(choice
  1108. (const :tag "with yes-or-no (safer)" yes-or-no-p)
  1109. (const :tag "with y-or-n (faster)" y-or-n-p)
  1110. (const :tag "no confirmation (dangerous)" nil)))
  1111. (defcustom org-confirm-elisp-link-function 'yes-or-no-p
  1112. "Non-nil means, ask for confirmation before executing Emacs Lisp links.
  1113. Elisp links can be dangerous: just think about a link
  1114. [[elisp:(shell-command \"rm -rf ~/*\")][Google Search]]
  1115. This link would show up in your Org-mode document as \"Google Search\",
  1116. but really it would remove your entire home directory.
  1117. Therefore we advise against setting this variable to nil.
  1118. Just change it to `y-or-n-p' if you want to confirm with a
  1119. single keystroke rather than having to type \"yes\"."
  1120. :group 'org-link-follow
  1121. :type '(choice
  1122. (const :tag "with yes-or-no (safer)" yes-or-no-p)
  1123. (const :tag "with y-or-n (faster)" y-or-n-p)
  1124. (const :tag "no confirmation (dangerous)" nil)))
  1125. (defconst org-file-apps-defaults-gnu
  1126. '((remote . emacs)
  1127. (system . mailcap)
  1128. (t . mailcap))
  1129. "Default file applications on a UNIX or GNU/Linux system.
  1130. See `org-file-apps'.")
  1131. (defconst org-file-apps-defaults-macosx
  1132. '((remote . emacs)
  1133. (t . "open %s")
  1134. (system . "open %s")
  1135. ("ps.gz" . "gv %s")
  1136. ("eps.gz" . "gv %s")
  1137. ("dvi" . "xdvi %s")
  1138. ("fig" . "xfig %s"))
  1139. "Default file applications on a MacOS X system.
  1140. The system \"open\" is known as a default, but we use X11 applications
  1141. for some files for which the OS does not have a good default.
  1142. See `org-file-apps'.")
  1143. (defconst org-file-apps-defaults-windowsnt
  1144. (list
  1145. '(remote . emacs)
  1146. (cons t
  1147. (list (if (featurep 'xemacs)
  1148. 'mswindows-shell-execute
  1149. 'w32-shell-execute)
  1150. "open" 'file))
  1151. (cons 'system
  1152. (list (if (featurep 'xemacs)
  1153. 'mswindows-shell-execute
  1154. 'w32-shell-execute)
  1155. "open" 'file)))
  1156. "Default file applications on a Windows NT system.
  1157. The system \"open\" is used for most files.
  1158. See `org-file-apps'.")
  1159. (defcustom org-file-apps
  1160. '(
  1161. (auto-mode . emacs)
  1162. ("\\.x?html?\\'" . default)
  1163. ("\\.pdf\\'" . default)
  1164. )
  1165. "External applications for opening `file:path' items in a document.
  1166. Org-mode uses system defaults for different file types, but
  1167. you can use this variable to set the application for a given file
  1168. extension. The entries in this list are cons cells where the car identifies
  1169. files and the cdr the corresponding command. Possible values for the
  1170. file identifier are
  1171. \"regex\" Regular expression matched against the file name. For backward
  1172. compatibility, this can also be a string with only alphanumeric
  1173. characters, which is then interpreted as an extension.
  1174. `directory' Matches a directory
  1175. `remote' Matches a remote file, accessible through tramp or efs.
  1176. Remote files most likely should be visited through Emacs
  1177. because external applications cannot handle such paths.
  1178. `auto-mode' Matches files that are matched by any entry in `auto-mode-alist',
  1179. so all files Emacs knows how to handle. Using this with
  1180. command `emacs' will open most files in Emacs. Beware that this
  1181. will also open html files inside Emacs, unless you add
  1182. (\"html\" . default) to the list as well.
  1183. t Default for files not matched by any of the other options.
  1184. `system' The system command to open files, like `open' on Windows
  1185. and Mac OS X, and mailcap under GNU/Linux. This is the command
  1186. that will be selected if you call `C-c C-o' with a double
  1187. `C-u C-u' prefix.
  1188. Possible values for the command are:
  1189. `emacs' The file will be visited by the current Emacs process.
  1190. `default' Use the default application for this file type, which is the
  1191. association for t in the list, most likely in the system-specific
  1192. part.
  1193. This can be used to overrule an unwanted setting in the
  1194. system-specific variable.
  1195. `system' Use the system command for opening files, like \"open\".
  1196. This command is specified by the entry whose car is `system'.
  1197. Most likely, the system-specific version of this variable
  1198. does define this command, but you can overrule/replace it
  1199. here.
  1200. string A command to be executed by a shell; %s will be replaced
  1201. by the path to the file.
  1202. sexp A Lisp form which will be evaluated. The file path will
  1203. be available in the Lisp variable `file'.
  1204. For more examples, see the system specific constants
  1205. `org-file-apps-defaults-macosx'
  1206. `org-file-apps-defaults-windowsnt'
  1207. `org-file-apps-defaults-gnu'."
  1208. :group 'org-link-follow
  1209. :type '(repeat
  1210. (cons (choice :value ""
  1211. (string :tag "Extension")
  1212. (const :tag "System command to open files" system)
  1213. (const :tag "Default for unrecognized files" t)
  1214. (const :tag "Remote file" remote)
  1215. (const :tag "Links to a directory" directory)
  1216. (const :tag "Any files that have Emacs modes"
  1217. auto-mode))
  1218. (choice :value ""
  1219. (const :tag "Visit with Emacs" emacs)
  1220. (const :tag "Use default" default)
  1221. (const :tag "Use the system command" system)
  1222. (string :tag "Command")
  1223. (sexp :tag "Lisp form")))))
  1224. (defgroup org-refile nil
  1225. "Options concerning refiling entries in Org-mode."
  1226. :tag "Org Refile"
  1227. :group 'org)
  1228. (defcustom org-directory "~/org"
  1229. "Directory with org files.
  1230. This is just a default location to look for Org files. There is no need
  1231. at all to put your files into this directory. It is only used in the
  1232. following situations:
  1233. 1. When a remember template specifies a target file that is not an
  1234. absolute path. The path will then be interpreted relative to
  1235. `org-directory'
  1236. 2. When a remember note is filed away in an interactive way (when exiting the
  1237. note buffer with `C-1 C-c C-c'. The the user is prompted for an org file,
  1238. with `org-directory' as the default path."
  1239. :group 'org-refile
  1240. :group 'org-remember
  1241. :type 'directory)
  1242. (defcustom org-default-notes-file (convert-standard-filename "~/.notes")
  1243. "Default target for storing notes.
  1244. Used by the hooks for remember.el. This can be a string, or nil to mean
  1245. the value of `remember-data-file'.
  1246. You can set this on a per-template basis with the variable
  1247. `org-remember-templates'."
  1248. :group 'org-refile
  1249. :group 'org-remember
  1250. :type '(choice
  1251. (const :tag "Default from remember-data-file" nil)
  1252. file))
  1253. (defcustom org-goto-interface 'outline
  1254. "The default interface to be used for `org-goto'.
  1255. Allowed values are:
  1256. outline The interface shows an outline of the relevant file
  1257. and the correct heading is found by moving through
  1258. the outline or by searching with incremental search.
  1259. outline-path-completion Headlines in the current buffer are offered via
  1260. completion. This is the interface also used by
  1261. the refile command."
  1262. :group 'org-refile
  1263. :type '(choice
  1264. (const :tag "Outline" outline)
  1265. (const :tag "Outline-path-completion" outline-path-completion)))
  1266. (defcustom org-goto-max-level 5
  1267. "Maximum level to be considered when running org-goto with refile interface."
  1268. :group 'org-refile
  1269. :type 'integer)
  1270. (defcustom org-reverse-note-order nil
  1271. "Non-nil means, store new notes at the beginning of a file or entry.
  1272. When nil, new notes will be filed to the end of a file or entry.
  1273. This can also be a list with cons cells of regular expressions that
  1274. are matched against file names, and values."
  1275. :group 'org-remember
  1276. :group 'org-refile
  1277. :type '(choice
  1278. (const :tag "Reverse always" t)
  1279. (const :tag "Reverse never" nil)
  1280. (repeat :tag "By file name regexp"
  1281. (cons regexp boolean))))
  1282. (defcustom org-refile-targets nil
  1283. "Targets for refiling entries with \\[org-refile].
  1284. This is list of cons cells. Each cell contains:
  1285. - a specification of the files to be considered, either a list of files,
  1286. or a symbol whose function or variable value will be used to retrieve
  1287. a file name or a list of file names. If you use `org-agenda-files' for
  1288. that, all agenda files will be scanned for targets. Nil means, consider
  1289. headings in the current buffer.
  1290. - A specification of how to find candidate refile targets. This may be
  1291. any of:
  1292. - a cons cell (:tag . \"TAG\") to identify refile targets by a tag.
  1293. This tag has to be present in all target headlines, inheritance will
  1294. not be considered.
  1295. - a cons cell (:todo . \"KEYWORD\") to identify refile targets by
  1296. todo keyword.
  1297. - a cons cell (:regexp . \"REGEXP\") with a regular expression matching
  1298. headlines that are refiling targets.
  1299. - a cons cell (:level . N). Any headline of level N is considered a target.
  1300. Note that, when `org-odd-levels-only' is set, level corresponds to
  1301. order in hierarchy, not to the number of stars.
  1302. - a cons cell (:maxlevel . N). Any headline with level <= N is a target.
  1303. Note that, when `org-odd-levels-only' is set, level corresponds to
  1304. order in hierarchy, not to the number of stars.
  1305. You can set the variable `org-refile-target-verify-function' to a function
  1306. to verify each headline found by the simple critery above.
  1307. When this variable is nil, all top-level headlines in the current buffer
  1308. are used, equivalent to the value `((nil . (:level . 1))'."
  1309. :group 'org-refile
  1310. :type '(repeat
  1311. (cons
  1312. (choice :value org-agenda-files
  1313. (const :tag "All agenda files" org-agenda-files)
  1314. (const :tag "Current buffer" nil)
  1315. (function) (variable) (file))
  1316. (choice :tag "Identify target headline by"
  1317. (cons :tag "Specific tag" (const :value :tag) (string))
  1318. (cons :tag "TODO keyword" (const :value :todo) (string))
  1319. (cons :tag "Regular expression" (const :value :regexp) (regexp))
  1320. (cons :tag "Level number" (const :value :level) (integer))
  1321. (cons :tag "Max Level number" (const :value :maxlevel) (integer))))))
  1322. (defcustom org-refile-target-verify-function nil
  1323. "Function to verify if the headline at point should be a refile target.
  1324. The function will be called without arguments, with point at the
  1325. beginning of the headline. It should return t and leave point
  1326. where it is if the headline is a valid target for refiling.
  1327. If the target should not be selected, the function must return nil.
  1328. In addition to this, it may move point to a place from where the search
  1329. should be continued. For example, the function may decide that the entire
  1330. subtree of the current entry should be excluded and move point to the end
  1331. of the subtree."
  1332. :group 'org-refile
  1333. :type 'function)
  1334. (defcustom org-refile-use-outline-path nil
  1335. "Non-nil means, provide refile targets as paths.
  1336. So a level 3 headline will be available as level1/level2/level3.
  1337. When the value is `file', also include the file name (without directory)
  1338. into the path. In this case, you can also stop the completion after
  1339. the file name, to get entries inserted as top level in the file.
  1340. When `full-file-path', include the full file path."
  1341. :group 'org-refile
  1342. :type '(choice
  1343. (const :tag "Not" nil)
  1344. (const :tag "Yes" t)
  1345. (const :tag "Start with file name" file)
  1346. (const :tag "Start with full file path" full-file-path)))
  1347. (defcustom org-outline-path-complete-in-steps t
  1348. "Non-nil means, complete the outline path in hierarchical steps.
  1349. When Org-mode uses the refile interface to select an outline path
  1350. \(see variable `org-refile-use-outline-path'), the completion of
  1351. the path can be done is a single go, or if can be done in steps down
  1352. the headline hierarchy. Going in steps is probably the best if you
  1353. do not use a special completion package like `ido' or `icicles'.
  1354. However, when using these packages, going in one step can be very
  1355. fast, while still showing the whole path to the entry."
  1356. :group 'org-refile
  1357. :type 'boolean)
  1358. (defcustom org-refile-allow-creating-parent-nodes nil
  1359. "Non-nil means, allow to create new nodes as refile targets.
  1360. New nodes are then created by adding \"/new node name\" to the completion
  1361. of an existing node. When the value of this variable is `confirm',
  1362. new node creation must be confirmed by the user (recommended)
  1363. When nil, the completion must match an existing entry.
  1364. Note that, if the new heading is not seen by the criteria
  1365. listed in `org-refile-targets', multiple instances of the same
  1366. heading would be created by trying again to file under the new
  1367. heading."
  1368. :group 'org-refile
  1369. :type '(choice
  1370. (const :tag "Never" nil)
  1371. (const :tag "Always" t)
  1372. (const :tag "Prompt for confirmation" confirm)))
  1373. (defgroup org-todo nil
  1374. "Options concerning TODO items in Org-mode."
  1375. :tag "Org TODO"
  1376. :group 'org)
  1377. (defgroup org-progress nil
  1378. "Options concerning Progress logging in Org-mode."
  1379. :tag "Org Progress"
  1380. :group 'org-time)
  1381. (defvar org-todo-interpretation-widgets
  1382. '(
  1383. (:tag "Sequence (cycling hits every state)" sequence)
  1384. (:tag "Type (cycling directly to DONE)" type))
  1385. "The available interpretation symbols for customizing
  1386. `org-todo-keywords'.
  1387. Interested libraries should add to this list.")
  1388. (defcustom org-todo-keywords '((sequence "TODO" "DONE"))
  1389. "List of TODO entry keyword sequences and their interpretation.
  1390. \\<org-mode-map>This is a list of sequences.
  1391. Each sequence starts with a symbol, either `sequence' or `type',
  1392. indicating if the keywords should be interpreted as a sequence of
  1393. action steps, or as different types of TODO items. The first
  1394. keywords are states requiring action - these states will select a headline
  1395. for inclusion into the global TODO list Org-mode produces. If one of
  1396. the \"keywords\" is the vertical bat \"|\" the remaining keywords
  1397. signify that no further action is necessary. If \"|\" is not found,
  1398. the last keyword is treated as the only DONE state of the sequence.
  1399. The command \\[org-todo] cycles an entry through these states, and one
  1400. additional state where no keyword is present. For details about this
  1401. cycling, see the manual.
  1402. TODO keywords and interpretation can also be set on a per-file basis with
  1403. the special #+SEQ_TODO and #+TYP_TODO lines.
  1404. Each keyword can optionally specify a character for fast state selection
  1405. \(in combination with the variable `org-use-fast-todo-selection')
  1406. and specifiers for state change logging, using the same syntax
  1407. that is used in the \"#+TODO:\" lines. For example, \"WAIT(w)\" says
  1408. that the WAIT state can be selected with the \"w\" key. \"WAIT(w!)\"
  1409. indicates to record a time stamp each time this state is selected.
  1410. Each keyword may also specify if a timestamp or a note should be
  1411. recorded when entering or leaving the state, by adding additional
  1412. characters in the parenthesis after the keyword. This looks like this:
  1413. \"WAIT(w@/!)\". \"@\" means to add a note (with time), \"!\" means to
  1414. record only the time of the state change. With X and Y being either
  1415. \"@\" or \"!\", \"X/Y\" means use X when entering the state, and use
  1416. Y when leaving the state if and only if the *target* state does not
  1417. define X. You may omit any of the fast-selection key or X or /Y,
  1418. so WAIT(w@), WAIT(w/@) and WAIT(@/@) are all valid.
  1419. For backward compatibility, this variable may also be just a list
  1420. of keywords - in this case the interpretation (sequence or type) will be
  1421. taken from the (otherwise obsolete) variable `org-todo-interpretation'."
  1422. :group 'org-todo
  1423. :group 'org-keywords
  1424. :type '(choice
  1425. (repeat :tag "Old syntax, just keywords"
  1426. (string :tag "Keyword"))
  1427. (repeat :tag "New syntax"
  1428. (cons
  1429. (choice
  1430. :tag "Interpretation"
  1431. ;;Quick and dirty way to see
  1432. ;;`org-todo-interpretations'. This takes the
  1433. ;;place of item arguments
  1434. :convert-widget
  1435. (lambda (widget)
  1436. (widget-put widget
  1437. :args (mapcar
  1438. #'(lambda (x)
  1439. (widget-convert
  1440. (cons 'const x)))
  1441. org-todo-interpretation-widgets))
  1442. widget))
  1443. (repeat
  1444. (string :tag "Keyword"))))))
  1445. (defvar org-todo-keywords-1 nil
  1446. "All TODO and DONE keywords active in a buffer.")
  1447. (make-variable-buffer-local 'org-todo-keywords-1)
  1448. (defvar org-todo-keywords-for-agenda nil)
  1449. (defvar org-done-keywords-for-agenda nil)
  1450. (defvar org-todo-keyword-alist-for-agenda nil)
  1451. (defvar org-tag-alist-for-agenda nil)
  1452. (defvar org-agenda-contributing-files nil)
  1453. (defvar org-not-done-keywords nil)
  1454. (make-variable-buffer-local 'org-not-done-keywords)
  1455. (defvar org-done-keywords nil)
  1456. (make-variable-buffer-local 'org-done-keywords)
  1457. (defvar org-todo-heads nil)
  1458. (make-variable-buffer-local 'org-todo-heads)
  1459. (defvar org-todo-sets nil)
  1460. (make-variable-buffer-local 'org-todo-sets)
  1461. (defvar org-todo-log-states nil)
  1462. (make-variable-buffer-local 'org-todo-log-states)
  1463. (defvar org-todo-kwd-alist nil)
  1464. (make-variable-buffer-local 'org-todo-kwd-alist)
  1465. (defvar org-todo-key-alist nil)
  1466. (make-variable-buffer-local 'org-todo-key-alist)
  1467. (defvar org-todo-key-trigger nil)
  1468. (make-variable-buffer-local 'org-todo-key-trigger)
  1469. (defcustom org-todo-interpretation 'sequence
  1470. "Controls how TODO keywords are interpreted.
  1471. This variable is in principle obsolete and is only used for
  1472. backward compatibility, if the interpretation of todo keywords is
  1473. not given already in `org-todo-keywords'. See that variable for
  1474. more information."
  1475. :group 'org-todo
  1476. :group 'org-keywords
  1477. :type '(choice (const sequence)
  1478. (const type)))
  1479. (defcustom org-use-fast-todo-selection t
  1480. "Non-nil means, use the fast todo selection scheme with C-c C-t.
  1481. This variable describes if and under what circumstances the cycling
  1482. mechanism for TODO keywords will be replaced by a single-key, direct
  1483. selection scheme.
  1484. When nil, fast selection is never used.
  1485. When the symbol `prefix', it will be used when `org-todo' is called with
  1486. a prefix argument, i.e. `C-u C-c C-t' in an Org-mode buffer, and `C-u t'
  1487. in an agenda buffer.
  1488. When t, fast selection is used by default. In this case, the prefix
  1489. argument forces cycling instead.
  1490. In all cases, the special interface is only used if access keys have actually
  1491. been assigned by the user, i.e. if keywords in the configuration are followed
  1492. by a letter in parenthesis, like TODO(t)."
  1493. :group 'org-todo
  1494. :type '(choice
  1495. (const :tag "Never" nil)
  1496. (const :tag "By default" t)
  1497. (const :tag "Only with C-u C-c C-t" prefix)))
  1498. (defcustom org-provide-todo-statistics t
  1499. "Non-nil means, update todo statistics after insert and toggle.
  1500. ALL-HEADLINES means update todo statistics by including headlines
  1501. with no TODO keyword as well. When this is set, todo statistics
  1502. is updated in the parent of the current entry each time a todo
  1503. state is changed."
  1504. :group 'org-todo
  1505. :type '(choice
  1506. (const :tag "For TODO entries" t)
  1507. (const :tag "By all headlines" 'all-headlines)
  1508. (const :tag "No TODO statistics" nil)))
  1509. (defcustom org-hierarchical-todo-statistics t
  1510. "Non-nil means, TODO statistics covers just direct children.
  1511. When nil, all entries in the subtree are considered.
  1512. This has only an effect if `org-provide-todo-statistics' is set."
  1513. :group 'org-todo
  1514. :type 'boolean)
  1515. (defcustom org-after-todo-state-change-hook nil
  1516. "Hook which is run after the state of a TODO item was changed.
  1517. The new state (a string with a TODO keyword, or nil) is available in the
  1518. Lisp variable `state'."
  1519. :group 'org-todo
  1520. :type 'hook)
  1521. (defvar org-blocker-hook nil
  1522. "Hook for functions that are allowed to block a state change.
  1523. Each function gets as its single argument a property list, see
  1524. `org-trigger-hook' for more information about this list.
  1525. If any of the functions in this hook returns nil, the state change
  1526. is blocked.")
  1527. (defvar org-trigger-hook nil
  1528. "Hook for functions that are triggered by a state change.
  1529. Each function gets as its single argument a property list with at least
  1530. the following elements:
  1531. (:type type-of-change :position pos-at-entry-start
  1532. :from old-state :to new-state)
  1533. Depending on the type, more properties may be present.
  1534. This mechanism is currently implemented for:
  1535. TODO state changes
  1536. ------------------
  1537. :type todo-state-change
  1538. :from previous state (keyword as a string), or nil, or a symbol
  1539. 'todo' or 'done', to indicate the general type of state.
  1540. :to new state, like in :from")
  1541. (defcustom org-enforce-todo-dependencies nil
  1542. "Non-nil means, undone TODO entries will block switching the parent to DONE.
  1543. Also, if a parent has an :ORDERED: property, switching an entry to DONE will
  1544. be blocked if any prior sibling is not yet done.
  1545. Finally, if the parent is blocked because of ordered siblings of its own,
  1546. the child will also be blocked.
  1547. This variable needs to be set before org.el is loaded, and you need to
  1548. restart Emacs after a change to make the change effective. The only way
  1549. to change is while Emacs is running is through the customize interface."
  1550. :set (lambda (var val)
  1551. (set var val)
  1552. (if val
  1553. (add-hook 'org-blocker-hook
  1554. 'org-block-todo-from-children-or-siblings-or-parent)
  1555. (remove-hook 'org-blocker-hook
  1556. 'org-block-todo-from-children-or-siblings-or-parent)))
  1557. :group 'org-todo
  1558. :type 'boolean)
  1559. (defcustom org-enforce-todo-checkbox-dependencies nil
  1560. "Non-nil means, unchecked boxes will block switching the parent to DONE.
  1561. When this is nil, checkboxes have no influence on switching TODO states.
  1562. When non-nil, you first need to check off all check boxes before the TODO
  1563. entry can be switched to DONE.
  1564. This variable needs to be set before org.el is loaded, and you need to
  1565. restart Emacs after a change to make the change effective. The only way
  1566. to change is while Emacs is running is through the customize interface."
  1567. :set (lambda (var val)
  1568. (set var val)
  1569. (if val
  1570. (add-hook 'org-blocker-hook
  1571. 'org-block-todo-from-checkboxes)
  1572. (remove-hook 'org-blocker-hook
  1573. 'org-block-todo-from-checkboxes)))
  1574. :group 'org-todo
  1575. :type 'boolean)
  1576. (defcustom org-treat-insert-todo-heading-as-state-change nil
  1577. "Non-nil means, inserting a TODO heading is treated as state change.
  1578. So when the command \\[org-insert-todo-heading] is used, state change
  1579. logging will apply if appropriate. When nil, the new TODO item will
  1580. be inserted directly, and no logging will take place."
  1581. :group 'org-todo
  1582. :type 'boolean)
  1583. (defcustom org-treat-S-cursor-todo-selection-as-state-change t
  1584. "Non-nil means, switching TODO states with S-cursor counts as state change.
  1585. This is the default behavior. However, setting this to nil allows a
  1586. convenient way to select a TODO state and bypass any logging associated
  1587. with that."
  1588. :group 'org-todo
  1589. :type 'boolean)
  1590. (defcustom org-todo-state-tags-triggers nil
  1591. "Tag changes that should be triggered by TODO state changes.
  1592. This is a list. Each entry is
  1593. (state-change (tag . flag) .......)
  1594. State-change can be a string with a state, and empty string to indicate the
  1595. state that has no TODO keyword, or it can be one of the symbols `todo'
  1596. or `done', meaning any not-done or done state, respectively."
  1597. :group 'org-todo
  1598. :group 'org-tags
  1599. :type '(repeat
  1600. (cons (choice :tag "When changing to"
  1601. (const :tag "Not-done state" todo)
  1602. (const :tag "Done state" done)
  1603. (string :tag "State"))
  1604. (repeat
  1605. (cons :tag "Tag action"
  1606. (string :tag "Tag")
  1607. (choice (const :tag "Add" t) (const :tag "Remove" nil)))))))
  1608. (defcustom org-log-done nil
  1609. "Information to record when a task moves to the DONE state.
  1610. Possible values are:
  1611. nil Don't add anything, just change the keyword
  1612. time Add a time stamp to the task
  1613. note Prompt a closing note and add it with template `org-log-note-headings'
  1614. This option can also be set with on a per-file-basis with
  1615. #+STARTUP: nologdone
  1616. #+STARTUP: logdone
  1617. #+STARTUP: lognotedone
  1618. You can have local logging settings for a subtree by setting the LOGGING
  1619. property to one or more of these keywords."
  1620. :group 'org-todo
  1621. :group 'org-progress
  1622. :type '(choice
  1623. (const :tag "No logging" nil)
  1624. (const :tag "Record CLOSED timestamp" time)
  1625. (const :tag "Record CLOSED timestamp with closing note." note)))
  1626. ;; Normalize old uses of org-log-done.
  1627. (cond
  1628. ((eq org-log-done t) (setq org-log-done 'time))
  1629. ((and (listp org-log-done) (memq 'done org-log-done))
  1630. (setq org-log-done 'note)))
  1631. (defcustom org-log-note-clock-out nil
  1632. "Non-nil means, record a note when clocking out of an item.
  1633. This can also be configured on a per-file basis by adding one of
  1634. the following lines anywhere in the buffer:
  1635. #+STARTUP: lognoteclock-out
  1636. #+STARTUP: nolognoteclock-out"
  1637. :group 'org-todo
  1638. :group 'org-progress
  1639. :type 'boolean)
  1640. (defcustom org-log-done-with-time t
  1641. "Non-nil means, the CLOSED time stamp will contain date and time.
  1642. When nil, only the date will be recorded."
  1643. :group 'org-progress
  1644. :type 'boolean)
  1645. (defcustom org-log-note-headings
  1646. '((done . "CLOSING NOTE %t")
  1647. (state . "State %-12s from %-12S %t")
  1648. (note . "Note taken on %t")
  1649. (clock-out . ""))
  1650. "Headings for notes added to entries.
  1651. The value is an alist, with the car being a symbol indicating the note
  1652. context, and the cdr is the heading to be used. The heading may also be the
  1653. empty string.
  1654. %t in the heading will be replaced by a time stamp.
  1655. %s will be replaced by the new TODO state, in double quotes.
  1656. %S will be replaced by the old TODO state, in double quotes.
  1657. %u will be replaced by the user name.
  1658. %U will be replaced by the full user name."
  1659. :group 'org-todo
  1660. :group 'org-progress
  1661. :type '(list :greedy t
  1662. (cons (const :tag "Heading when closing an item" done) string)
  1663. (cons (const :tag
  1664. "Heading when changing todo state (todo sequence only)"
  1665. state) string)
  1666. (cons (const :tag "Heading when just taking a note" note) string)
  1667. (cons (const :tag "Heading when clocking out" clock-out) string)))
  1668. (unless (assq 'note org-log-note-headings)
  1669. (push '(note . "%t") org-log-note-headings))
  1670. (defcustom org-log-into-drawer nil
  1671. "Non-nil means, insert state change notes and time stamps into a drawer.
  1672. When nil, state changes notes will be inserted after the headline and
  1673. any scheduling and clock lines, but not inside a drawer.
  1674. The value of this variable should be the name of the drawer to use.
  1675. LOGBOOK is proposed at the default drawer for this purpose, you can
  1676. also set this to a string to define the drawer of your choice.
  1677. A value of t is also allowed, representing \"LOGBOOK\".
  1678. If this variable is set, `org-log-state-notes-insert-after-drawers'
  1679. will be ignored.
  1680. You can set the property LOG_INTO_DRAWER to overrule this setting for
  1681. a subtree."
  1682. :group 'org-todo
  1683. :group 'org-progress
  1684. :type '(choice
  1685. (const :tag "Not into a drawer" nil)
  1686. (const :tag "LOGBOOK" t)
  1687. (string :tag "Other")))
  1688. (if (fboundp 'defvaralias)
  1689. (defvaralias 'org-log-state-notes-into-drawer 'org-log-into-drawer))
  1690. (defun org-log-into-drawer ()
  1691. "Return the value of `org-log-into-drawer', but let properties overrule.
  1692. If the current entry has or inherits a LOG_INTO_DRAWER property, it will be
  1693. used instead of the default value."
  1694. (let ((p (ignore-errors (org-entry-get nil "LOG_INTO_DRAWER" 'inherit))))
  1695. (cond
  1696. ((or (not p) (equal p "nil")) org-log-into-drawer)
  1697. ((equal p "t") "LOGBOOK")
  1698. (t p))))
  1699. (defcustom org-log-state-notes-insert-after-drawers nil
  1700. "Non-nil means, insert state change notes after any drawers in entry.
  1701. Only the drawers that *immediately* follow the headline and the
  1702. deadline/scheduled line are skipped.
  1703. When nil, insert notes right after the heading and perhaps the line
  1704. with deadline/scheduling if present.
  1705. This variable will have no effect if `org-log-into-drawer' is
  1706. set."
  1707. :group 'org-todo
  1708. :group 'org-progress
  1709. :type 'boolean)
  1710. (defcustom org-log-states-order-reversed t
  1711. "Non-nil means, the latest state change note will be directly after heading.
  1712. When nil, the notes will be orderer according to time."
  1713. :group 'org-todo
  1714. :group 'org-progress
  1715. :type 'boolean)
  1716. (defcustom org-log-repeat 'time
  1717. "Non-nil means, record moving through the DONE state when triggering repeat.
  1718. An auto-repeating tasks is immediately switched back to TODO when marked
  1719. done. If you are not logging state changes (by adding \"@\" or \"!\" to
  1720. the TODO keyword definition, or recording a closing note by setting
  1721. `org-log-done', there will be no record of the task moving through DONE.
  1722. This variable forces taking a note anyway. Possible values are:
  1723. nil Don't force a record
  1724. time Record a time stamp
  1725. note Record a note
  1726. This option can also be set with on a per-file-basis with
  1727. #+STARTUP: logrepeat
  1728. #+STARTUP: lognoterepeat
  1729. #+STARTUP: nologrepeat
  1730. You can have local logging settings for a subtree by setting the LOGGING
  1731. property to one or more of these keywords."
  1732. :group 'org-todo
  1733. :group 'org-progress
  1734. :type '(choice
  1735. (const :tag "Don't force a record" nil)
  1736. (const :tag "Force recording the DONE state" time)
  1737. (const :tag "Force recording a note with the DONE state" note)))
  1738. (defgroup org-priorities nil
  1739. "Priorities in Org-mode."
  1740. :tag "Org Priorities"
  1741. :group 'org-todo)
  1742. (defcustom org-enable-priority-commands t
  1743. "Non-nil means, priority commands are active.
  1744. When nil, these commands will be disabled, so that you never accidentally
  1745. set a priority."
  1746. :group 'org-priorities
  1747. :type 'boolean)
  1748. (defcustom org-highest-priority ?A
  1749. "The highest priority of TODO items. A character like ?A, ?B etc.
  1750. Must have a smaller ASCII number than `org-lowest-priority'."
  1751. :group 'org-priorities
  1752. :type 'character)
  1753. (defcustom org-lowest-priority ?C
  1754. "The lowest priority of TODO items. A character like ?A, ?B etc.
  1755. Must have a larger ASCII number than `org-highest-priority'."
  1756. :group 'org-priorities
  1757. :type 'character)
  1758. (defcustom org-default-priority ?B
  1759. "The default priority of TODO items.
  1760. This is the priority an item get if no explicit priority is given."
  1761. :group 'org-priorities
  1762. :type 'character)
  1763. (defcustom org-priority-start-cycle-with-default t
  1764. "Non-nil means, start with default priority when starting to cycle.
  1765. When this is nil, the first step in the cycle will be (depending on the
  1766. command used) one higher or lower that the default priority."
  1767. :group 'org-priorities
  1768. :type 'boolean)
  1769. (defgroup org-time nil
  1770. "Options concerning time stamps and deadlines in Org-mode."
  1771. :tag "Org Time"
  1772. :group 'org)
  1773. (defcustom org-insert-labeled-timestamps-at-point nil
  1774. "Non-nil means, SCHEDULED and DEADLINE timestamps are inserted at point.
  1775. When nil, these labeled time stamps are forces into the second line of an
  1776. entry, just after the headline. When scheduling from the global TODO list,
  1777. the time stamp will always be forced into the second line."
  1778. :group 'org-time
  1779. :type 'boolean)
  1780. (defconst org-time-stamp-formats '("<%Y-%m-%d %a>" . "<%Y-%m-%d %a %H:%M>")
  1781. "Formats for `format-time-string' which are used for time stamps.
  1782. It is not recommended to change this constant.")
  1783. (defcustom org-time-stamp-rounding-minutes '(0 5)
  1784. "Number of minutes to round time stamps to.
  1785. These are two values, the first applies when first creating a time stamp.
  1786. The second applies when changing it with the commands `S-up' and `S-down'.
  1787. When changing the time stamp, this means that it will change in steps
  1788. of N minutes, as given by the second value.
  1789. When a setting is 0 or 1, insert the time unmodified. Useful rounding
  1790. numbers should be factors of 60, so for example 5, 10, 15.
  1791. When this is larger than 1, you can still force an exact time-stamp by using
  1792. a double prefix argument to a time-stamp command like `C-c .' or `C-c !',
  1793. and by using a prefix arg to `S-up/down' to specify the exact number
  1794. of minutes to shift."
  1795. :group 'org-time
  1796. :get '(lambda (var) ; Make sure all entries have 5 elements
  1797. (if (integerp (default-value var))
  1798. (list (default-value var) 5)
  1799. (default-value var)))
  1800. :type '(list
  1801. (integer :tag "when inserting times")
  1802. (integer :tag "when modifying times")))
  1803. ;; Normalize old customizations of this variable.
  1804. (when (integerp org-time-stamp-rounding-minutes)
  1805. (setq org-time-stamp-rounding-minutes
  1806. (list org-time-stamp-rounding-minutes
  1807. org-time-stamp-rounding-minutes)))
  1808. (defcustom org-display-custom-times nil
  1809. "Non-nil means, overlay custom formats over all time stamps.
  1810. The formats are defined through the variable `org-time-stamp-custom-formats'.
  1811. To turn this on on a per-file basis, insert anywhere in the file:
  1812. #+STARTUP: customtime"
  1813. :group 'org-time
  1814. :set 'set-default
  1815. :type 'sexp)
  1816. (make-variable-buffer-local 'org-display-custom-times)
  1817. (defcustom org-time-stamp-custom-formats
  1818. '("<%m/%d/%y %a>" . "<%m/%d/%y %a %H:%M>") ; american
  1819. "Custom formats for time stamps. See `format-time-string' for the syntax.
  1820. These are overlayed over the default ISO format if the variable
  1821. `org-display-custom-times' is set. Time like %H:%M should be at the
  1822. end of the second format. The custom formats are also honored by export
  1823. commands, if custom time display is turned on at the time of export."
  1824. :group 'org-time
  1825. :type 'sexp)
  1826. (defun org-time-stamp-format (&optional long inactive)
  1827. "Get the right format for a time string."
  1828. (let ((f (if long (cdr org-time-stamp-formats)
  1829. (car org-time-stamp-formats))))
  1830. (if inactive
  1831. (concat "[" (substring f 1 -1) "]")
  1832. f)))
  1833. (defcustom org-time-clocksum-format "%d:%02d"
  1834. "The format string used when creating CLOCKSUM lines, or when
  1835. org-mode generates a time duration."
  1836. :group 'org-time
  1837. :type 'string)
  1838. (defcustom org-deadline-warning-days 14
  1839. "No. of days before expiration during which a deadline becomes active.
  1840. This variable governs the display in sparse trees and in the agenda.
  1841. When 0 or negative, it means use this number (the absolute value of it)
  1842. even if a deadline has a different individual lead time specified.
  1843. Custom commands can set this variable in the options section."
  1844. :group 'org-time
  1845. :group 'org-agenda-daily/weekly
  1846. :type 'integer)
  1847. (defcustom org-read-date-prefer-future t
  1848. "Non-nil means, assume future for incomplete date input from user.
  1849. This affects the following situations:
  1850. 1. The user gives a day, but no month.
  1851. For example, if today is the 15th, and you enter \"3\", Org-mode will
  1852. read this as the third of *next* month. However, if you enter \"17\",
  1853. it will be considered as *this* month.
  1854. 2. The user gives a month but not a year.
  1855. For example, if it is april and you enter \"feb 2\", this will be read
  1856. as feb 2, *next* year. \"May 5\", however, will be this year.
  1857. Currently this does not work for ISO week specifications.
  1858. When this option is nil, the current month and year will always be used
  1859. as defaults."
  1860. :group 'org-time
  1861. :type 'boolean)
  1862. (defcustom org-read-date-display-live t
  1863. "Non-nil means, display current interpretation of date prompt live.
  1864. This display will be in an overlay, in the minibuffer."
  1865. :group 'org-time
  1866. :type 'boolean)
  1867. (defcustom org-read-date-popup-calendar t
  1868. "Non-nil means, pop up a calendar when prompting for a date.
  1869. In the calendar, the date can be selected with mouse-1. However, the
  1870. minibuffer will also be active, and you can simply enter the date as well.
  1871. When nil, only the minibuffer will be available."
  1872. :group 'org-time
  1873. :type 'boolean)
  1874. (if (fboundp 'defvaralias)
  1875. (defvaralias 'org-popup-calendar-for-date-prompt
  1876. 'org-read-date-popup-calendar))
  1877. (defcustom org-read-date-minibuffer-setup-hook nil
  1878. "Hook to be used to set up keys for the date/time interface.
  1879. Add key definitions to `minibuffer-local-map', which will be a temporary
  1880. copy."
  1881. :group 'org-time
  1882. :type 'hook)
  1883. (defcustom org-extend-today-until 0
  1884. "The hour when your day really ends. Must be an integer.
  1885. This has influence for the following applications:
  1886. - When switching the agenda to \"today\". It it is still earlier than
  1887. the time given here, the day recognized as TODAY is actually yesterday.
  1888. - When a date is read from the user and it is still before the time given
  1889. here, the current date and time will be assumed to be yesterday, 23:59.
  1890. Also, timestamps inserted in remember templates follow this rule.
  1891. IMPORTANT: This is a feature whose implementation is and likely will
  1892. remain incomplete. Really, it is only here because past midnight seems to
  1893. be the favorite working time of John Wiegley :-)"
  1894. :group 'org-time
  1895. :type 'integer)
  1896. (defcustom org-edit-timestamp-down-means-later nil
  1897. "Non-nil means, S-down will increase the time in a time stamp.
  1898. When nil, S-up will increase."
  1899. :group 'org-time
  1900. :type 'boolean)
  1901. (defcustom org-calendar-follow-timestamp-change t
  1902. "Non-nil means, make the calendar window follow timestamp changes.
  1903. When a timestamp is modified and the calendar window is visible, it will be
  1904. moved to the new date."
  1905. :group 'org-time
  1906. :type 'boolean)
  1907. (defgroup org-tags nil
  1908. "Options concerning tags in Org-mode."
  1909. :tag "Org Tags"
  1910. :group 'org)
  1911. (defcustom org-tag-alist nil
  1912. "List of tags allowed in Org-mode files.
  1913. When this list is nil, Org-mode will base TAG input on what is already in the
  1914. buffer.
  1915. The value of this variable is an alist, the car of each entry must be a
  1916. keyword as a string, the cdr may be a character that is used to select
  1917. that tag through the fast-tag-selection interface.
  1918. See the manual for details."
  1919. :group 'org-tags
  1920. :type '(repeat
  1921. (choice
  1922. (cons (string :tag "Tag name")
  1923. (character :tag "Access char"))
  1924. (const :tag "Start radio group" (:startgroup))
  1925. (const :tag "End radio group" (:endgroup))
  1926. (const :tag "New line" (:newline)))))
  1927. (defcustom org-tag-persistent-alist nil
  1928. "List of tags that will always appear in all Org-mode files.
  1929. This is in addition to any in buffer settings or customizations
  1930. of `org-tag-alist'.
  1931. When this list is nil, Org-mode will base TAG input on `org-tag-alist'.
  1932. The value of this variable is an alist, the car of each entry must be a
  1933. keyword as a string, the cdr may be a character that is used to select
  1934. that tag through the fast-tag-selection interface.
  1935. See the manual for details.
  1936. To disable these tags on a per-file basis, insert anywhere in the file:
  1937. #+STARTUP: noptag"
  1938. :group 'org-tags
  1939. :type '(repeat
  1940. (choice
  1941. (cons (string :tag "Tag name")
  1942. (character :tag "Access char"))
  1943. (const :tag "Start radio group" (:startgroup))
  1944. (const :tag "End radio group" (:endgroup))
  1945. (const :tag "New line" (:newline)))))
  1946. (defvar org-file-tags nil
  1947. "List of tags that can be inherited by all entries in the file.
  1948. The tags will be inherited if the variable `org-use-tag-inheritance'
  1949. says they should be.
  1950. This variable is populated from #+TAG lines.")
  1951. (defcustom org-use-fast-tag-selection 'auto
  1952. "Non-nil means, use fast tag selection scheme.
  1953. This is a special interface to select and deselect tags with single keys.
  1954. When nil, fast selection is never used.
  1955. When the symbol `auto', fast selection is used if and only if selection
  1956. characters for tags have been configured, either through the variable
  1957. `org-tag-alist' or through a #+TAGS line in the buffer.
  1958. When t, fast selection is always used and selection keys are assigned
  1959. automatically if necessary."
  1960. :group 'org-tags
  1961. :type '(choice
  1962. (const :tag "Always" t)
  1963. (const :tag "Never" nil)
  1964. (const :tag "When selection characters are configured" 'auto)))
  1965. (defcustom org-fast-tag-selection-single-key nil
  1966. "Non-nil means, fast tag selection exits after first change.
  1967. When nil, you have to press RET to exit it.
  1968. During fast tag selection, you can toggle this flag with `C-c'.
  1969. This variable can also have the value `expert'. In this case, the window
  1970. displaying the tags menu is not even shown, until you press C-c again."
  1971. :group 'org-tags
  1972. :type '(choice
  1973. (const :tag "No" nil)
  1974. (const :tag "Yes" t)
  1975. (const :tag "Expert" expert)))
  1976. (defvar org-fast-tag-selection-include-todo nil
  1977. "Non-nil means, fast tags selection interface will also offer TODO states.
  1978. This is an undocumented feature, you should not rely on it.")
  1979. (defcustom org-tags-column (if (featurep 'xemacs) -76 -77)
  1980. "The column to which tags should be indented in a headline.
  1981. If this number is positive, it specifies the column. If it is negative,
  1982. it means that the tags should be flushright to that column. For example,
  1983. -80 works well for a normal 80 character screen."
  1984. :group 'org-tags
  1985. :type 'integer)
  1986. (defcustom org-auto-align-tags t
  1987. "Non-nil means, realign tags after pro/demotion of TODO state change.
  1988. These operations change the length of a headline and therefore shift
  1989. the tags around. With this options turned on, after each such operation
  1990. the tags are again aligned to `org-tags-column'."
  1991. :group 'org-tags
  1992. :type 'boolean)
  1993. (defcustom org-use-tag-inheritance t
  1994. "Non-nil means, tags in levels apply also for sublevels.
  1995. When nil, only the tags directly given in a specific line apply there.
  1996. This may also be a list of tags that should be inherited, or a regexp that
  1997. matches tags that should be inherited. Additional control is possible
  1998. with the variable `org-tags-exclude-from-inheritance' which gives an
  1999. explicit list of tags to be excluded from inheritance., even if the value of
  2000. `org-use-tag-inheritance' would select it for inheritance.
  2001. If this option is t, a match early-on in a tree can lead to a large
  2002. number of matches in the subtree when constructing the agenda or creating
  2003. a sparse tree. If you only want to see the first match in a tree during
  2004. a search, check out the variable `org-tags-match-list-sublevels'."
  2005. :group 'org-tags
  2006. :type '(choice
  2007. (const :tag "Not" nil)
  2008. (const :tag "Always" t)
  2009. (repeat :tag "Specific tags" (string :tag "Tag"))
  2010. (regexp :tag "Tags matched by regexp")))
  2011. (defcustom org-tags-exclude-from-inheritance nil
  2012. "List of tags that should never be inherited.
  2013. This is a way to exclude a few tags from inheritance. For way to do
  2014. the opposite, to actively allow inheritance for selected tags,
  2015. see the variable `org-use-tag-inheritance'."
  2016. :group 'org-tags
  2017. :type '(repeat (string :tag "Tag")))
  2018. (defun org-tag-inherit-p (tag)
  2019. "Check if TAG is one that should be inherited."
  2020. (cond
  2021. ((member tag org-tags-exclude-from-inheritance) nil)
  2022. ((eq org-use-tag-inheritance t) t)
  2023. ((not org-use-tag-inheritance) nil)
  2024. ((stringp org-use-tag-inheritance)
  2025. (string-match org-use-tag-inheritance tag))
  2026. ((listp org-use-tag-inheritance)
  2027. (member tag org-use-tag-inheritance))
  2028. (t (error "Invalid setting of `org-use-tag-inheritance'"))))
  2029. (defcustom org-tags-match-list-sublevels t
  2030. "Non-nil means list also sublevels of headlines matching a search.
  2031. This variable applies to tags/property searches, and also to stuck
  2032. projects because this search is based on a tags match as well.
  2033. When set to the symbol `indented', sublevels are indented with
  2034. leading dots.
  2035. Because of tag inheritance (see variable `org-use-tag-inheritance'),
  2036. the sublevels of a headline matching a tag search often also match
  2037. the same search. Listing all of them can create very long lists.
  2038. Setting this variable to nil causes subtrees of a match to be skipped.
  2039. This variable is semi-obsolete and probably should always be true. It
  2040. is better to limit inheritance to certain tags using the variables
  2041. `org-use-tag-inheritance' and `org-tags-exclude-from-inheritance'."
  2042. :group 'org-tags
  2043. :type '(choice
  2044. (const :tag "No, don't list them" nil)
  2045. (const :tag "Yes, do list them" t)
  2046. (const :tag "List them, indented with leading dots" indented)))
  2047. (defcustom org-tags-sort-function nil
  2048. "When set, tags are sorted using this function as a comparator"
  2049. :group 'org-tags
  2050. :type '(choice
  2051. (const :tag "No sorting" nil)
  2052. (const :tag "Alphabetical" string<)
  2053. (const :tag "Reverse alphabetical" string>)
  2054. (function :tag "Custom function" nil)))
  2055. (defvar org-tags-history nil
  2056. "History of minibuffer reads for tags.")
  2057. (defvar org-last-tags-completion-table nil
  2058. "The last used completion table for tags.")
  2059. (defvar org-after-tags-change-hook nil
  2060. "Hook that is run after the tags in a line have changed.")
  2061. (defgroup org-properties nil
  2062. "Options concerning properties in Org-mode."
  2063. :tag "Org Properties"
  2064. :group 'org)
  2065. (defcustom org-property-format "%-10s %s"
  2066. "How property key/value pairs should be formatted by `indent-line'.
  2067. When `indent-line' hits a property definition, it will format the line
  2068. according to this format, mainly to make sure that the values are
  2069. lined-up with respect to each other."
  2070. :group 'org-properties
  2071. :type 'string)
  2072. (defcustom org-use-property-inheritance nil
  2073. "Non-nil means, properties apply also for sublevels.
  2074. This setting is chiefly used during property searches. Turning it on can
  2075. cause significant overhead when doing a search, which is why it is not
  2076. on by default.
  2077. When nil, only the properties directly given in the current entry count.
  2078. When t, every property is inherited. The value may also be a list of
  2079. properties that should have inheritance, or a regular expression matching
  2080. properties that should be inherited.
  2081. However, note that some special properties use inheritance under special
  2082. circumstances (not in searches). Examples are CATEGORY, ARCHIVE, COLUMNS,
  2083. and the properties ending in \"_ALL\" when they are used as descriptor
  2084. for valid values of a property.
  2085. Note for programmers:
  2086. When querying an entry with `org-entry-get', you can control if inheritance
  2087. should be used. By default, `org-entry-get' looks only at the local
  2088. properties. You can request inheritance by setting the inherit argument
  2089. to t (to force inheritance) or to `selective' (to respect the setting
  2090. in this variable)."
  2091. :group 'org-properties
  2092. :type '(choice
  2093. (const :tag "Not" nil)
  2094. (const :tag "Always" t)
  2095. (repeat :tag "Specific properties" (string :tag "Property"))
  2096. (regexp :tag "Properties matched by regexp")))
  2097. (defun org-property-inherit-p (property)
  2098. "Check if PROPERTY is one that should be inherited."
  2099. (cond
  2100. ((eq org-use-property-inheritance t) t)
  2101. ((not org-use-property-inheritance) nil)
  2102. ((stringp org-use-property-inheritance)
  2103. (string-match org-use-property-inheritance property))
  2104. ((listp org-use-property-inheritance)
  2105. (member property org-use-property-inheritance))
  2106. (t (error "Invalid setting of `org-use-property-inheritance'"))))
  2107. (defcustom org-columns-default-format "%25ITEM %TODO %3PRIORITY %TAGS"
  2108. "The default column format, if no other format has been defined.
  2109. This variable can be set on the per-file basis by inserting a line
  2110. #+COLUMNS: %25ITEM ....."
  2111. :group 'org-properties
  2112. :type 'string)
  2113. (defcustom org-columns-ellipses ".."
  2114. "The ellipses to be used when a field in column view is truncated.
  2115. When this is the empty string, as many characters as possible are shown,
  2116. but then there will be no visual indication that the field has been truncated.
  2117. When this is a string of length N, the last N characters of a truncated
  2118. field are replaced by this string. If the column is narrower than the
  2119. ellipses string, only part of the ellipses string will be shown."
  2120. :group 'org-properties
  2121. :type 'string)
  2122. (defcustom org-columns-modify-value-for-display-function nil
  2123. "Function that modifies values for display in column view.
  2124. For example, it can be used to cut out a certain part from a time stamp.
  2125. The function must take 2 arguments:
  2126. column-title The title of the column (*not* the property name)
  2127. value The value that should be modified.
  2128. The function should return the value that should be displayed,
  2129. or nil if the normal value should be used."
  2130. :group 'org-properties
  2131. :type 'function)
  2132. (defcustom org-effort-property "Effort"
  2133. "The property that is being used to keep track of effort estimates.
  2134. Effort estimates given in this property need to have the format H:MM."
  2135. :group 'org-properties
  2136. :group 'org-progress
  2137. :type '(string :tag "Property"))
  2138. (defconst org-global-properties-fixed
  2139. '(("VISIBILITY_ALL" . "folded children content all")
  2140. ("CLOCK_MODELINE_TOTAL_ALL" . "current today repeat all auto"))
  2141. "List of property/value pairs that can be inherited by any entry.
  2142. These are fixed values, for the preset properties. The user variable
  2143. that can be used to add to this list is `org-global-properties'.
  2144. The entries in this list are cons cells where the car is a property
  2145. name and cdr is a string with the value. If the value represents
  2146. multiple items like an \"_ALL\" property, separate the items by
  2147. spaces.")
  2148. (defcustom org-global-properties nil
  2149. "List of property/value pairs that can be inherited by any entry.
  2150. This list will be combined with the constant `org-global-properties-fixed'.
  2151. The entries in this list are cons cells where the car is a property
  2152. name and cdr is a string with the value.
  2153. You can set buffer-local values for the same purpose in the variable
  2154. `org-file-properties' this by adding lines like
  2155. #+PROPERTY: NAME VALUE"
  2156. :group 'org-properties
  2157. :type '(repeat
  2158. (cons (string :tag "Property")
  2159. (string :tag "Value"))))
  2160. (defvar org-file-properties nil
  2161. "List of property/value pairs that can be inherited by any entry.
  2162. Valid for the current buffer.
  2163. This variable is populated from #+PROPERTY lines.")
  2164. (make-variable-buffer-local 'org-file-properties)
  2165. (defgroup org-agenda nil
  2166. "Options concerning agenda views in Org-mode."
  2167. :tag "Org Agenda"
  2168. :group 'org)
  2169. (defvar org-category nil
  2170. "Variable used by org files to set a category for agenda display.
  2171. Such files should use a file variable to set it, for example
  2172. # -*- mode: org; org-category: \"ELisp\"
  2173. or contain a special line
  2174. #+CATEGORY: ELisp
  2175. If the file does not specify a category, then file's base name
  2176. is used instead.")
  2177. (make-variable-buffer-local 'org-category)
  2178. (put 'org-category 'safe-local-variable '(lambda (x) (or (symbolp x) (stringp x))))
  2179. (defcustom org-agenda-files nil
  2180. "The files to be used for agenda display.
  2181. Entries may be added to this list with \\[org-agenda-file-to-front] and removed with
  2182. \\[org-remove-file]. You can also use customize to edit the list.
  2183. If an entry is a directory, all files in that directory that are matched by
  2184. `org-agenda-file-regexp' will be part of the file list.
  2185. If the value of the variable is not a list but a single file name, then
  2186. the list of agenda files is actually stored and maintained in that file, one
  2187. agenda file per line."
  2188. :group 'org-agenda
  2189. :type '(choice
  2190. (repeat :tag "List of files and directories" file)
  2191. (file :tag "Store list in a file\n" :value "~/.agenda_files")))
  2192. (defcustom org-agenda-file-regexp "\\`[^.].*\\.org\\'"
  2193. "Regular expression to match files for `org-agenda-files'.
  2194. If any element in the list in that variable contains a directory instead
  2195. of a normal file, all files in that directory that are matched by this
  2196. regular expression will be included."
  2197. :group 'org-agenda
  2198. :type 'regexp)
  2199. (defcustom org-agenda-text-search-extra-files nil
  2200. "List of extra files to be searched by text search commands.
  2201. These files will be search in addition to the agenda files by the
  2202. commands `org-search-view' (`C-c a s') and `org-occur-in-agenda-files'.
  2203. Note that these files will only be searched for text search commands,
  2204. not for the other agenda views like todo lists, tag searches or the weekly
  2205. agenda. This variable is intended to list notes and possibly archive files
  2206. that should also be searched by these two commands.
  2207. In fact, if the first element in the list is the symbol `agenda-archives',
  2208. than all archive files of all agenda files will be added to the search
  2209. scope."
  2210. :group 'org-agenda
  2211. :type '(set :greedy t
  2212. (const :tag "Agenda Archives" agenda-archives)
  2213. (repeat :inline t (file))))
  2214. (if (fboundp 'defvaralias)
  2215. (defvaralias 'org-agenda-multi-occur-extra-files
  2216. 'org-agenda-text-search-extra-files))
  2217. (defcustom org-agenda-skip-unavailable-files nil
  2218. "Non-nil means to just skip non-reachable files in `org-agenda-files'.
  2219. A nil value means to remove them, after a query, from the list."
  2220. :group 'org-agenda
  2221. :type 'boolean)
  2222. (defcustom org-calendar-to-agenda-key [?c]
  2223. "The key to be installed in `calendar-mode-map' for switching to the agenda.
  2224. The command `org-calendar-goto-agenda' will be bound to this key. The
  2225. default is the character `c' because then `c' can be used to switch back and
  2226. forth between agenda and calendar."
  2227. :group 'org-agenda
  2228. :type 'sexp)
  2229. (defcustom org-calendar-agenda-action-key [?k]
  2230. "The key to be installed in `calendar-mode-map' for agenda-action.
  2231. The command `org-agenda-action' will be bound to this key. The
  2232. default is the character `k' because we use the same key in the agenda."
  2233. :group 'org-agenda
  2234. :type 'sexp)
  2235. (eval-after-load "calendar"
  2236. '(progn
  2237. (org-defkey calendar-mode-map org-calendar-to-agenda-key
  2238. 'org-calendar-goto-agenda)
  2239. (org-defkey calendar-mode-map org-calendar-agenda-action-key
  2240. 'org-agenda-action)))
  2241. (defgroup org-latex nil
  2242. "Options for embedding LaTeX code into Org-mode."
  2243. :tag "Org LaTeX"
  2244. :group 'org)
  2245. (defcustom org-format-latex-options
  2246. '(:foreground default :background default :scale 1.0
  2247. :html-foreground "Black" :html-background "Transparent" :html-scale 1.0
  2248. :matchers ("begin" "$1" "$" "$$" "\\(" "\\["))
  2249. "Options for creating images from LaTeX fragments.
  2250. This is a property list with the following properties:
  2251. :foreground the foreground color for images embedded in Emacs, e.g. \"Black\".
  2252. `default' means use the foreground of the default face.
  2253. :background the background color, or \"Transparent\".
  2254. `default' means use the background of the default face.
  2255. :scale a scaling factor for the size of the images.
  2256. :html-foreground, :html-background, :html-scale
  2257. the same numbers for HTML export.
  2258. :matchers a list indicating which matchers should be used to
  2259. find LaTeX fragments. Valid members of this list are:
  2260. \"begin\" find environments
  2261. \"$1\" find single characters surrounded by $.$
  2262. \"$\" find math expressions surrounded by $...$
  2263. \"$$\" find math expressions surrounded by $$....$$
  2264. \"\\(\" find math expressions surrounded by \\(...\\)
  2265. \"\\ [\" find math expressions surrounded by \\ [...\\]"
  2266. :group 'org-latex
  2267. :type 'plist)
  2268. (defcustom org-format-latex-header "\\documentclass{article}
  2269. \\usepackage{fullpage} % do not remove
  2270. \\usepackage{amssymb}
  2271. \\usepackage[usenames]{color}
  2272. \\usepackage{amsmath}
  2273. \\usepackage{latexsym}
  2274. \\usepackage[mathscr]{eucal}
  2275. \\pagestyle{empty} % do not remove"
  2276. "The document header used for processing LaTeX fragments."
  2277. :group 'org-latex
  2278. :type 'string)
  2279. (defgroup org-font-lock nil
  2280. "Font-lock settings for highlighting in Org-mode."
  2281. :tag "Org Font Lock"
  2282. :group 'org)
  2283. (defcustom org-level-color-stars-only nil
  2284. "Non-nil means fontify only the stars in each headline.
  2285. When nil, the entire headline is fontified.
  2286. Changing it requires restart of `font-lock-mode' to become effective
  2287. also in regions already fontified."
  2288. :group 'org-font-lock
  2289. :type 'boolean)
  2290. (defcustom org-hide-leading-stars nil
  2291. "Non-nil means, hide the first N-1 stars in a headline.
  2292. This works by using the face `org-hide' for these stars. This
  2293. face is white for a light background, and black for a dark
  2294. background. You may have to customize the face `org-hide' to
  2295. make this work.
  2296. Changing it requires restart of `font-lock-mode' to become effective
  2297. also in regions already fontified.
  2298. You may also set this on a per-file basis by adding one of the following
  2299. lines to the buffer:
  2300. #+STARTUP: hidestars
  2301. #+STARTUP: showstars"
  2302. :group 'org-font-lock
  2303. :type 'boolean)
  2304. (defcustom org-fontify-done-headline nil
  2305. "Non-nil means, change the face of a headline if it is marked DONE.
  2306. Normally, only the TODO/DONE keyword indicates the state of a headline.
  2307. When this is non-nil, the headline after the keyword is set to the
  2308. `org-headline-done' as an additional indication."
  2309. :group 'org-font-lock
  2310. :type 'boolean)
  2311. (defcustom org-fontify-emphasized-text t
  2312. "Non-nil means fontify *bold*, /italic/ and _underlined_ text.
  2313. Changing this variable requires a restart of Emacs to take effect."
  2314. :group 'org-font-lock
  2315. :type 'boolean)
  2316. (defcustom org-fontify-whole-heading-line nil
  2317. "Non-nil means fontify the whole line for headings.
  2318. This is useful when setting a background color for the
  2319. org-leve-* faces."
  2320. :group 'org-font-lock
  2321. :type 'boolean)
  2322. (defcustom org-highlight-latex-fragments-and-specials nil
  2323. "Non-nil means, fontify what is treated specially by the exporters."
  2324. :group 'org-font-lock
  2325. :type 'boolean)
  2326. (defcustom org-hide-emphasis-markers nil
  2327. "Non-nil mean font-lock should hide the emphasis marker characters."
  2328. :group 'org-font-lock
  2329. :type 'boolean)
  2330. (defvar org-emph-re nil
  2331. "Regular expression for matching emphasis.")
  2332. (defvar org-verbatim-re nil
  2333. "Regular expression for matching verbatim text.")
  2334. (defvar org-emphasis-regexp-components) ; defined just below
  2335. (defvar org-emphasis-alist) ; defined just below
  2336. (defun org-set-emph-re (var val)
  2337. "Set variable and compute the emphasis regular expression."
  2338. (set var val)
  2339. (when (and (boundp 'org-emphasis-alist)
  2340. (boundp 'org-emphasis-regexp-components)
  2341. org-emphasis-alist org-emphasis-regexp-components)
  2342. (let* ((e org-emphasis-regexp-components)
  2343. (pre (car e))
  2344. (post (nth 1 e))
  2345. (border (nth 2 e))
  2346. (body (nth 3 e))
  2347. (nl (nth 4 e))
  2348. (body1 (concat body "*?"))
  2349. (markers (mapconcat 'car org-emphasis-alist ""))
  2350. (vmarkers (mapconcat
  2351. (lambda (x) (if (eq (nth 4 x) 'verbatim) (car x) ""))
  2352. org-emphasis-alist "")))
  2353. ;; make sure special characters appear at the right position in the class
  2354. (if (string-match "\\^" markers)
  2355. (setq markers (concat (replace-match "" t t markers) "^")))
  2356. (if (string-match "-" markers)
  2357. (setq markers (concat (replace-match "" t t markers) "-")))
  2358. (if (string-match "\\^" vmarkers)
  2359. (setq vmarkers (concat (replace-match "" t t vmarkers) "^")))
  2360. (if (string-match "-" vmarkers)
  2361. (setq vmarkers (concat (replace-match "" t t vmarkers) "-")))
  2362. (if (> nl 0)
  2363. (setq body1 (concat body1 "\\(?:\n" body "*?\\)\\{0,"
  2364. (int-to-string nl) "\\}")))
  2365. ;; Make the regexp
  2366. (setq org-emph-re
  2367. (concat "\\([" pre "]\\|^\\)"
  2368. "\\("
  2369. "\\([" markers "]\\)"
  2370. "\\("
  2371. "[^" border "]\\|"
  2372. "[^" border "]"
  2373. body1
  2374. "[^" border "]"
  2375. "\\)"
  2376. "\\3\\)"
  2377. "\\([" post "]\\|$\\)?"))
  2378. (setq org-verbatim-re
  2379. (concat "\\([" pre "]\\|^\\)"
  2380. "\\("
  2381. "\\([" vmarkers "]\\)"
  2382. "\\("
  2383. "[^" border "]\\|"
  2384. "[^" border "]"
  2385. body1
  2386. "[^" border "]"
  2387. "\\)"
  2388. "\\3\\)"
  2389. "\\([" post "]\\|$\\)?")))))
  2390. (defcustom org-emphasis-regexp-components
  2391. '(" \t('\"{" "- \t.,:!?;'\")}" " \t\r\n,\"'" "." 1)
  2392. "Components used to build the regular expression for emphasis.
  2393. This is a list with 6 entries. Terminology: In an emphasis string
  2394. like \" *strong word* \", we call the initial space PREMATCH, the final
  2395. space POSTMATCH, the stars MARKERS, \"s\" and \"d\" are BORDER characters
  2396. and \"trong wor\" is the body. The different components in this variable
  2397. specify what is allowed/forbidden in each part:
  2398. pre Chars allowed as prematch. Beginning of line will be allowed too.
  2399. post Chars allowed as postmatch. End of line will be allowed too.
  2400. border The chars *forbidden* as border characters.
  2401. body-regexp A regexp like \".\" to match a body character. Don't use
  2402. non-shy groups here, and don't allow newline here.
  2403. newline The maximum number of newlines allowed in an emphasis exp.
  2404. Use customize to modify this, or restart Emacs after changing it."
  2405. :group 'org-font-lock
  2406. :set 'org-set-emph-re
  2407. :type '(list
  2408. (sexp :tag "Allowed chars in pre ")
  2409. (sexp :tag "Allowed chars in post ")
  2410. (sexp :tag "Forbidden chars in border ")
  2411. (sexp :tag "Regexp for body ")
  2412. (integer :tag "number of newlines allowed")
  2413. (option (boolean :tag "Please ignore this button"))))
  2414. (defcustom org-emphasis-alist
  2415. `(("*" bold "<b>" "</b>")
  2416. ("/" italic "<i>" "</i>")
  2417. ("_" underline "<span style=\"text-decoration:underline;\">" "</span>")
  2418. ("=" org-code "<code>" "</code>" verbatim)
  2419. ("~" org-verbatim "<code>" "</code>" verbatim)
  2420. ("+" ,(if (featurep 'xemacs) 'org-table '(:strike-through t))
  2421. "<del>" "</del>")
  2422. )
  2423. "Special syntax for emphasized text.
  2424. Text starting and ending with a special character will be emphasized, for
  2425. example *bold*, _underlined_ and /italic/. This variable sets the marker
  2426. characters, the face to be used by font-lock for highlighting in Org-mode
  2427. Emacs buffers, and the HTML tags to be used for this.
  2428. For LaTeX export, see the variable `org-export-latex-emphasis-alist'.
  2429. Use customize to modify this, or restart Emacs after changing it."
  2430. :group 'org-font-lock
  2431. :set 'org-set-emph-re
  2432. :type '(repeat
  2433. (list
  2434. (string :tag "Marker character")
  2435. (choice
  2436. (face :tag "Font-lock-face")
  2437. (plist :tag "Face property list"))
  2438. (string :tag "HTML start tag")
  2439. (string :tag "HTML end tag")
  2440. (option (const verbatim)))))
  2441. (defvar org-protecting-blocks
  2442. '("src" "example" "latex" "ascii" "html" "docbook" "ditaa" "dot" "r" "R")
  2443. "Blocks that contain text that is quoted, i.e. not processed as Org syntax.
  2444. This is needed for font-lock setup.")
  2445. ;;; Miscellaneous options
  2446. (defgroup org-completion nil
  2447. "Completion in Org-mode."
  2448. :tag "Org Completion"
  2449. :group 'org)
  2450. (defcustom org-completion-use-ido nil
  2451. "Non-nil means, use ido completion wherever possible.
  2452. Note that `ido-mode' must be active for this variable to be relevant.
  2453. If you decide to turn this variable on, you might well want to turn off
  2454. `org-outline-path-complete-in-steps'."
  2455. :group 'org-completion
  2456. :type 'boolean)
  2457. (defcustom org-completion-fallback-command 'hippie-expand
  2458. "The expansion command called by \\[org-complete] in normal context.
  2459. Normal means, no org-mode-specific context."
  2460. :group 'org-completion
  2461. :type 'function)
  2462. ;;; Functions and variables from ther packages
  2463. ;; Declared here to avoid compiler warnings
  2464. ;; XEmacs only
  2465. (defvar outline-mode-menu-heading)
  2466. (defvar outline-mode-menu-show)
  2467. (defvar outline-mode-menu-hide)
  2468. (defvar zmacs-regions) ; XEmacs regions
  2469. ;; Emacs only
  2470. (defvar mark-active)
  2471. ;; Various packages
  2472. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  2473. (declare-function calendar-forward-day "cal-move" (arg))
  2474. (declare-function calendar-goto-date "cal-move" (date))
  2475. (declare-function calendar-goto-today "cal-move" ())
  2476. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  2477. (defvar calc-embedded-close-formula)
  2478. (defvar calc-embedded-open-formula)
  2479. (declare-function cdlatex-tab "ext:cdlatex" ())
  2480. (declare-function dired-get-filename "dired" (&optional localp no-error-if-not-filep))
  2481. (defvar font-lock-unfontify-region-function)
  2482. (declare-function iswitchb-mode "iswitchb" (&optional arg))
  2483. (declare-function iswitchb-read-buffer (prompt &optional default require-match start matches-set))
  2484. (defvar iswitchb-temp-buflist)
  2485. (declare-function org-gnus-follow-link "org-gnus" (&optional group article))
  2486. (defvar org-agenda-tags-todo-honor-ignore-options)
  2487. (declare-function org-agenda-skip "org-agenda" ())
  2488. (declare-function org-format-agenda-item "org-agenda"
  2489. (extra txt &optional category tags dotime noprefix remove-re))
  2490. (declare-function org-agenda-new-marker "org-agenda" (&optional pos))
  2491. (declare-function org-agenda-change-all-lines "org-agenda"
  2492. (newhead hdmarker &optional fixface just-this))
  2493. (declare-function org-agenda-set-restriction-lock "org-agenda" (&optional type))
  2494. (declare-function org-agenda-maybe-redo "org-agenda" ())
  2495. (declare-function org-agenda-save-markers-for-cut-and-paste "org-agenda"
  2496. (beg end))
  2497. (declare-function org-agenda-copy-local-variable "org-agenda" (var))
  2498. (declare-function org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  2499. "org-agenda" (&optional end))
  2500. (declare-function parse-time-string "parse-time" (string))
  2501. (declare-function remember "remember" (&optional initial))
  2502. (declare-function remember-buffer-desc "remember" ())
  2503. (declare-function remember-finalize "remember" ())
  2504. (defvar remember-save-after-remembering)
  2505. (defvar remember-data-file)
  2506. (defvar remember-register)
  2507. (defvar remember-buffer)
  2508. (defvar remember-handler-functions)
  2509. (defvar remember-annotation-functions)
  2510. (defvar texmathp-why)
  2511. (declare-function speedbar-line-directory "speedbar" (&optional depth))
  2512. (declare-function table--at-cell-p "table" (position &optional object at-column))
  2513. (defvar w3m-current-url)
  2514. (defvar w3m-current-title)
  2515. (defvar org-latex-regexps)
  2516. ;;; Autoload and prepare some org modules
  2517. ;; Some table stuff that needs to be defined here, because it is used
  2518. ;; by the functions setting up org-mode or checking for table context.
  2519. (defconst org-table-any-line-regexp "^[ \t]*\\(|\\|\\+-[-+]\\)"
  2520. "Detects an org-type or table-type table.")
  2521. (defconst org-table-line-regexp "^[ \t]*|"
  2522. "Detects an org-type table line.")
  2523. (defconst org-table-dataline-regexp "^[ \t]*|[^-]"
  2524. "Detects an org-type table line.")
  2525. (defconst org-table-hline-regexp "^[ \t]*|-"
  2526. "Detects an org-type table hline.")
  2527. (defconst org-table1-hline-regexp "^[ \t]*\\+-[-+]"
  2528. "Detects a table-type table hline.")
  2529. (defconst org-table-any-border-regexp "^[ \t]*[^|+ \t]"
  2530. "Searching from within a table (any type) this finds the first line
  2531. outside the table.")
  2532. ;; Autoload the functions in org-table.el that are needed by functions here.
  2533. (eval-and-compile
  2534. (org-autoload "org-table"
  2535. '(org-table-align org-table-begin org-table-blank-field
  2536. org-table-convert org-table-convert-region org-table-copy-down
  2537. org-table-copy-region org-table-create
  2538. org-table-create-or-convert-from-region
  2539. org-table-create-with-table.el org-table-current-dline
  2540. org-table-cut-region org-table-delete-column org-table-edit-field
  2541. org-table-edit-formulas org-table-end org-table-eval-formula
  2542. org-table-export org-table-field-info
  2543. org-table-get-stored-formulas org-table-goto-column
  2544. org-table-hline-and-move org-table-import org-table-insert-column
  2545. org-table-insert-hline org-table-insert-row org-table-iterate
  2546. org-table-justify-field-maybe org-table-kill-row
  2547. org-table-maybe-eval-formula org-table-maybe-recalculate-line
  2548. org-table-move-column org-table-move-column-left
  2549. org-table-move-column-right org-table-move-row
  2550. org-table-move-row-down org-table-move-row-up
  2551. org-table-next-field org-table-next-row org-table-paste-rectangle
  2552. org-table-previous-field org-table-recalculate
  2553. org-table-rotate-recalc-marks org-table-sort-lines org-table-sum
  2554. org-table-toggle-coordinate-overlays
  2555. org-table-toggle-formula-debugger org-table-wrap-region
  2556. orgtbl-mode turn-on-orgtbl org-table-to-lisp)))
  2557. (defun org-at-table-p (&optional table-type)
  2558. "Return t if the cursor is inside an org-type table.
  2559. If TABLE-TYPE is non-nil, also check for table.el-type tables."
  2560. (if org-enable-table-editor
  2561. (save-excursion
  2562. (beginning-of-line 1)
  2563. (looking-at (if table-type org-table-any-line-regexp
  2564. org-table-line-regexp)))
  2565. nil))
  2566. (defsubst org-table-p () (org-at-table-p))
  2567. (defun org-at-table.el-p ()
  2568. "Return t if and only if we are at a table.el table."
  2569. (and (org-at-table-p 'any)
  2570. (save-excursion
  2571. (goto-char (org-table-begin 'any))
  2572. (looking-at org-table1-hline-regexp))))
  2573. (defun org-table-recognize-table.el ()
  2574. "If there is a table.el table nearby, recognize it and move into it."
  2575. (if org-table-tab-recognizes-table.el
  2576. (if (org-at-table.el-p)
  2577. (progn
  2578. (beginning-of-line 1)
  2579. (if (looking-at org-table-dataline-regexp)
  2580. nil
  2581. (if (looking-at org-table1-hline-regexp)
  2582. (progn
  2583. (beginning-of-line 2)
  2584. (if (looking-at org-table-any-border-regexp)
  2585. (beginning-of-line -1)))))
  2586. (if (re-search-forward "|" (org-table-end t) t)
  2587. (progn
  2588. (require 'table)
  2589. (if (table--at-cell-p (point))
  2590. t
  2591. (message "recognizing table.el table...")
  2592. (table-recognize-table)
  2593. (message "recognizing table.el table...done")))
  2594. (error "This should not happen..."))
  2595. t)
  2596. nil)
  2597. nil))
  2598. (defun org-at-table-hline-p ()
  2599. "Return t if the cursor is inside a hline in a table."
  2600. (if org-enable-table-editor
  2601. (save-excursion
  2602. (beginning-of-line 1)
  2603. (looking-at org-table-hline-regexp))
  2604. nil))
  2605. (defvar org-table-clean-did-remove-column nil)
  2606. (defun org-table-map-tables (function)
  2607. "Apply FUNCTION to the start of all tables in the buffer."
  2608. (save-excursion
  2609. (save-restriction
  2610. (widen)
  2611. (goto-char (point-min))
  2612. (while (re-search-forward org-table-any-line-regexp nil t)
  2613. (message "Mapping tables: %d%%" (/ (* 100.0 (point)) (buffer-size)))
  2614. (beginning-of-line 1)
  2615. (if (looking-at org-table-line-regexp)
  2616. (save-excursion (funcall function)))
  2617. (re-search-forward org-table-any-border-regexp nil 1))))
  2618. (message "Mapping tables: done"))
  2619. ;; Declare and autoload functions from org-exp.el & Co
  2620. (declare-function org-default-export-plist "org-exp")
  2621. (declare-function org-infile-export-plist "org-exp")
  2622. (declare-function org-get-current-options "org-exp")
  2623. (eval-and-compile
  2624. (org-autoload "org-exp"
  2625. '(org-export org-export-visible
  2626. org-insert-export-options-template
  2627. org-table-clean-before-export))
  2628. (org-autoload "org-ascii"
  2629. '(org-export-as-ascii org-export-ascii-preprocess
  2630. org-export-as-ascii-to-buffer org-replace-region-by-ascii
  2631. org-export-region-as-ascii))
  2632. (org-autoload "org-html"
  2633. '(org-export-as-html-and-open
  2634. org-export-as-html-batch org-export-as-html-to-buffer
  2635. org-replace-region-by-html org-export-region-as-html
  2636. org-export-as-html))
  2637. (org-autoload "org-icalendar"
  2638. '(org-export-icalendar-this-file
  2639. org-export-icalendar-all-agenda-files
  2640. org-export-icalendar-combine-agenda-files))
  2641. (org-autoload "org-xoxo" '(org-export-as-xoxo)))
  2642. ;; Declare and autoload functions from org-agenda.el
  2643. (eval-and-compile
  2644. (org-autoload "org-agenda"
  2645. '(org-agenda org-agenda-list org-search-view
  2646. org-todo-list org-tags-view org-agenda-list-stuck-projects
  2647. org-diary org-agenda-to-appt
  2648. org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item)))
  2649. ;; Autoload org-remember
  2650. (eval-and-compile
  2651. (org-autoload "org-remember"
  2652. '(org-remember-insinuate org-remember-annotation
  2653. org-remember-apply-template org-remember org-remember-handler)))
  2654. ;; Autoload org-clock.el
  2655. (declare-function org-clock-save-markers-for-cut-and-paste "org-clock"
  2656. (beg end))
  2657. (declare-function org-clock-update-mode-line "org-clock" ())
  2658. (defvar org-clock-start-time)
  2659. (defvar org-clock-marker (make-marker)
  2660. "Marker recording the last clock-in.")
  2661. (defun org-clock-is-active ()
  2662. "Return non-nil if clock is currently running.
  2663. The return value is actually the clock marker."
  2664. (marker-buffer org-clock-marker))
  2665. (eval-and-compile
  2666. (org-autoload
  2667. "org-clock"
  2668. '(org-clock-in org-clock-out org-clock-cancel
  2669. org-clock-goto org-clock-sum org-clock-display
  2670. org-clock-remove-overlays org-clock-report
  2671. org-clocktable-shift org-dblock-write:clocktable
  2672. org-get-clocktable)))
  2673. (defun org-clock-update-time-maybe ()
  2674. "If this is a CLOCK line, update it and return t.
  2675. Otherwise, return nil."
  2676. (interactive)
  2677. (save-excursion
  2678. (beginning-of-line 1)
  2679. (skip-chars-forward " \t")
  2680. (when (looking-at org-clock-string)
  2681. (let ((re (concat "[ \t]*" org-clock-string
  2682. " *[[<]\\([^]>]+\\)[]>]\\(-+[[<]\\([^]>]+\\)[]>]"
  2683. "\\([ \t]*=>.*\\)?\\)?"))
  2684. ts te h m s neg)
  2685. (cond
  2686. ((not (looking-at re))
  2687. nil)
  2688. ((not (match-end 2))
  2689. (when (and (equal (marker-buffer org-clock-marker) (current-buffer))
  2690. (> org-clock-marker (point))
  2691. (<= org-clock-marker (point-at-eol)))
  2692. ;; The clock is running here
  2693. (setq org-clock-start-time
  2694. (apply 'encode-time
  2695. (org-parse-time-string (match-string 1))))
  2696. (org-clock-update-mode-line)))
  2697. (t
  2698. (and (match-end 4) (delete-region (match-beginning 4) (match-end 4)))
  2699. (end-of-line 1)
  2700. (setq ts (match-string 1)
  2701. te (match-string 3))
  2702. (setq s (- (time-to-seconds
  2703. (apply 'encode-time (org-parse-time-string te)))
  2704. (time-to-seconds
  2705. (apply 'encode-time (org-parse-time-string ts))))
  2706. neg (< s 0)
  2707. s (abs s)
  2708. h (floor (/ s 3600))
  2709. s (- s (* 3600 h))
  2710. m (floor (/ s 60))
  2711. s (- s (* 60 s)))
  2712. (insert " => " (format (if neg "-%d:%02d" "%2d:%02d") h m))
  2713. t))))))
  2714. (defun org-check-running-clock ()
  2715. "Check if the current buffer contains the running clock.
  2716. If yes, offer to stop it and to save the buffer with the changes."
  2717. (when (and (equal (marker-buffer org-clock-marker) (current-buffer))
  2718. (y-or-n-p (format "Clock-out in buffer %s before killing it? "
  2719. (buffer-name))))
  2720. (org-clock-out)
  2721. (when (y-or-n-p "Save changed buffer?")
  2722. (save-buffer))))
  2723. (defun org-clocktable-try-shift (dir n)
  2724. "Check if this line starts a clock table, if yes, shift the time block."
  2725. (when (org-match-line "#\\+BEGIN: clocktable\\>")
  2726. (org-clocktable-shift dir n)))
  2727. ;; Autoload org-timer.el
  2728. (eval-and-compile
  2729. (org-autoload
  2730. "org-timer"
  2731. '(org-timer-start org-timer org-timer-item
  2732. org-timer-change-times-in-region)))
  2733. ;; Autoload org-feed.el
  2734. (eval-and-compile
  2735. (org-autoload
  2736. "org-feed"
  2737. '(org-feed-update org-feed-update-all org-feed-goto-inbox)))
  2738. ;; Autoload archiving code
  2739. ;; The stuff that is needed for cycling and tags has to be defined here.
  2740. (defgroup org-archive nil
  2741. "Options concerning archiving in Org-mode."
  2742. :tag "Org Archive"
  2743. :group 'org-structure)
  2744. (defcustom org-archive-location "%s_archive::"
  2745. "The location where subtrees should be archived.
  2746. The value of this variable is a string, consisting of two parts,
  2747. separated by a double-colon. The first part is a filename and
  2748. the second part is a headline.
  2749. When the filename is omitted, archiving happens in the same file.
  2750. %s in the filename will be replaced by the current file
  2751. name (without the directory part). Archiving to a different file
  2752. is useful to keep archived entries from contributing to the
  2753. Org-mode Agenda.
  2754. The archived entries will be filed as subtrees of the specified
  2755. headline. When the headline is omitted, the subtrees are simply
  2756. filed away at the end of the file, as top-level entries. Also in
  2757. the heading you can use %s to represent the file name, this can be
  2758. useful when using the same archive for a number of different files.
  2759. Here are a few examples:
  2760. \"%s_archive::\"
  2761. If the current file is Projects.org, archive in file
  2762. Projects.org_archive, as top-level trees. This is the default.
  2763. \"::* Archived Tasks\"
  2764. Archive in the current file, under the top-level headline
  2765. \"* Archived Tasks\".
  2766. \"~/org/archive.org::\"
  2767. Archive in file ~/org/archive.org (absolute path), as top-level trees.
  2768. \"~/org/archive.org::From %s\"
  2769. Archive in file ~/org/archive.org (absolute path), und headlines
  2770. \"From FILENAME\" where file name is the current file name.
  2771. \"basement::** Finished Tasks\"
  2772. Archive in file ./basement (relative path), as level 3 trees
  2773. below the level 2 heading \"** Finished Tasks\".
  2774. You may set this option on a per-file basis by adding to the buffer a
  2775. line like
  2776. #+ARCHIVE: basement::** Finished Tasks
  2777. You may also define it locally for a subtree by setting an ARCHIVE property
  2778. in the entry. If such a property is found in an entry, or anywhere up
  2779. the hierarchy, it will be used."
  2780. :group 'org-archive
  2781. :type 'string)
  2782. (defcustom org-archive-tag "ARCHIVE"
  2783. "The tag that marks a subtree as archived.
  2784. An archived subtree does not open during visibility cycling, and does
  2785. not contribute to the agenda listings.
  2786. After changing this, font-lock must be restarted in the relevant buffers to
  2787. get the proper fontification."
  2788. :group 'org-archive
  2789. :group 'org-keywords
  2790. :type 'string)
  2791. (defcustom org-agenda-skip-archived-trees t
  2792. "Non-nil means, the agenda will skip any items located in archived trees.
  2793. An archived tree is a tree marked with the tag ARCHIVE. The use of this
  2794. variable is no longer recommended, you should leave it at the value t.
  2795. Instead, use the key `v' to cycle the archives-mode in the agenda."
  2796. :group 'org-archive
  2797. :group 'org-agenda-skip
  2798. :type 'boolean)
  2799. (defcustom org-columns-skip-arrchived-trees t
  2800. "Non-nil means, irgnore archived trees when creating column view."
  2801. :group 'org-archive
  2802. :group 'org-properties
  2803. :type 'boolean)
  2804. (defcustom org-cycle-open-archived-trees nil
  2805. "Non-nil means, `org-cycle' will open archived trees.
  2806. An archived tree is a tree marked with the tag ARCHIVE.
  2807. When nil, archived trees will stay folded. You can still open them with
  2808. normal outline commands like `show-all', but not with the cycling commands."
  2809. :group 'org-archive
  2810. :group 'org-cycle
  2811. :type 'boolean)
  2812. (defcustom org-sparse-tree-open-archived-trees nil
  2813. "Non-nil means sparse tree construction shows matches in archived trees.
  2814. When nil, matches in these trees are highlighted, but the trees are kept in
  2815. collapsed state."
  2816. :group 'org-archive
  2817. :group 'org-sparse-trees
  2818. :type 'boolean)
  2819. (defun org-cycle-hide-archived-subtrees (state)
  2820. "Re-hide all archived subtrees after a visibility state change."
  2821. (when (and (not org-cycle-open-archived-trees)
  2822. (not (memq state '(overview folded))))
  2823. (save-excursion
  2824. (let* ((globalp (memq state '(contents all)))
  2825. (beg (if globalp (point-min) (point)))
  2826. (end (if globalp (point-max) (org-end-of-subtree t))))
  2827. (org-hide-archived-subtrees beg end)
  2828. (goto-char beg)
  2829. (if (looking-at (concat ".*:" org-archive-tag ":"))
  2830. (message "%s" (substitute-command-keys
  2831. "Subtree is archived and stays closed. Use \\[org-force-cycle-archived] to cycle it anyway.")))))))
  2832. (defun org-force-cycle-archived ()
  2833. "Cycle subtree even if it is archived."
  2834. (interactive)
  2835. (setq this-command 'org-cycle)
  2836. (let ((org-cycle-open-archived-trees t))
  2837. (call-interactively 'org-cycle)))
  2838. (defun org-hide-archived-subtrees (beg end)
  2839. "Re-hide all archived subtrees after a visibility state change."
  2840. (save-excursion
  2841. (let* ((re (concat ":" org-archive-tag ":")))
  2842. (goto-char beg)
  2843. (while (re-search-forward re end t)
  2844. (and (org-on-heading-p) (hide-subtree))
  2845. (org-end-of-subtree t)))))
  2846. (defalias 'org-advertized-archive-subtree 'org-archive-subtree)
  2847. (eval-and-compile
  2848. (org-autoload "org-archive"
  2849. '(org-add-archive-files org-archive-subtree
  2850. org-archive-to-archive-sibling org-toggle-archive-tag)))
  2851. ;; Autoload Column View Code
  2852. (declare-function org-columns-number-to-string "org-colview")
  2853. (declare-function org-columns-get-format-and-top-level "org-colview")
  2854. (declare-function org-columns-compute "org-colview")
  2855. (org-autoload (if (featurep 'xemacs) "org-colview-xemacs" "org-colview")
  2856. '(org-columns-number-to-string org-columns-get-format-and-top-level
  2857. org-columns-compute org-agenda-columns org-columns-remove-overlays
  2858. org-columns org-insert-columns-dblock org-dblock-write:columnview))
  2859. ;; Autoload ID code
  2860. (declare-function org-id-store-link "org-id")
  2861. (declare-function org-id-locations-load "org-id")
  2862. (declare-function org-id-locations-save "org-id")
  2863. (defvar org-id-track-globally)
  2864. (org-autoload "org-id"
  2865. '(org-id-get-create org-id-new org-id-copy org-id-get
  2866. org-id-get-with-outline-path-completion
  2867. org-id-get-with-outline-drilling
  2868. org-id-goto org-id-find org-id-store-link))
  2869. ;; Autoload Plotting Code
  2870. (org-autoload "org-plot"
  2871. '(org-plot/gnuplot))
  2872. ;;; Variables for pre-computed regular expressions, all buffer local
  2873. (defvar org-drawer-regexp nil
  2874. "Matches first line of a hidden block.")
  2875. (make-variable-buffer-local 'org-drawer-regexp)
  2876. (defvar org-todo-regexp nil
  2877. "Matches any of the TODO state keywords.")
  2878. (make-variable-buffer-local 'org-todo-regexp)
  2879. (defvar org-not-done-regexp nil
  2880. "Matches any of the TODO state keywords except the last one.")
  2881. (make-variable-buffer-local 'org-not-done-regexp)
  2882. (defvar org-not-done-heading-regexp nil
  2883. "Matches a TODO headline that is not done.")
  2884. (make-variable-buffer-local 'org-not-done-regexp)
  2885. (defvar org-todo-line-regexp nil
  2886. "Matches a headline and puts TODO state into group 2 if present.")
  2887. (make-variable-buffer-local 'org-todo-line-regexp)
  2888. (defvar org-complex-heading-regexp nil
  2889. "Matches a headline and puts everything into groups:
  2890. group 1: the stars
  2891. group 2: The todo keyword, maybe
  2892. group 3: Priority cookie
  2893. group 4: True headline
  2894. group 5: Tags")
  2895. (make-variable-buffer-local 'org-complex-heading-regexp)
  2896. (defvar org-todo-line-tags-regexp nil
  2897. "Matches a headline and puts TODO state into group 2 if present.
  2898. Also put tags into group 4 if tags are present.")
  2899. (make-variable-buffer-local 'org-todo-line-tags-regexp)
  2900. (defvar org-nl-done-regexp nil
  2901. "Matches newline followed by a headline with the DONE keyword.")
  2902. (make-variable-buffer-local 'org-nl-done-regexp)
  2903. (defvar org-looking-at-done-regexp nil
  2904. "Matches the DONE keyword a point.")
  2905. (make-variable-buffer-local 'org-looking-at-done-regexp)
  2906. (defvar org-ds-keyword-length 12
  2907. "Maximum length of the Deadline and SCHEDULED keywords.")
  2908. (make-variable-buffer-local 'org-ds-keyword-length)
  2909. (defvar org-deadline-regexp nil
  2910. "Matches the DEADLINE keyword.")
  2911. (make-variable-buffer-local 'org-deadline-regexp)
  2912. (defvar org-deadline-time-regexp nil
  2913. "Matches the DEADLINE keyword together with a time stamp.")
  2914. (make-variable-buffer-local 'org-deadline-time-regexp)
  2915. (defvar org-deadline-line-regexp nil
  2916. "Matches the DEADLINE keyword and the rest of the line.")
  2917. (make-variable-buffer-local 'org-deadline-line-regexp)
  2918. (defvar org-scheduled-regexp nil
  2919. "Matches the SCHEDULED keyword.")
  2920. (make-variable-buffer-local 'org-scheduled-regexp)
  2921. (defvar org-scheduled-time-regexp nil
  2922. "Matches the SCHEDULED keyword together with a time stamp.")
  2923. (make-variable-buffer-local 'org-scheduled-time-regexp)
  2924. (defvar org-closed-time-regexp nil
  2925. "Matches the CLOSED keyword together with a time stamp.")
  2926. (make-variable-buffer-local 'org-closed-time-regexp)
  2927. (defvar org-keyword-time-regexp nil
  2928. "Matches any of the 4 keywords, together with the time stamp.")
  2929. (make-variable-buffer-local 'org-keyword-time-regexp)
  2930. (defvar org-keyword-time-not-clock-regexp nil
  2931. "Matches any of the 3 keywords, together with the time stamp.")
  2932. (make-variable-buffer-local 'org-keyword-time-not-clock-regexp)
  2933. (defvar org-maybe-keyword-time-regexp nil
  2934. "Matches a timestamp, possibly preceeded by a keyword.")
  2935. (make-variable-buffer-local 'org-maybe-keyword-time-regexp)
  2936. (defvar org-planning-or-clock-line-re nil
  2937. "Matches a line with planning or clock info.")
  2938. (make-variable-buffer-local 'org-planning-or-clock-line-re)
  2939. (defconst org-plain-time-of-day-regexp
  2940. (concat
  2941. "\\(\\<[012]?[0-9]"
  2942. "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
  2943. "\\(--?"
  2944. "\\(\\<[012]?[0-9]"
  2945. "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
  2946. "\\)?")
  2947. "Regular expression to match a plain time or time range.
  2948. Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
  2949. groups carry important information:
  2950. 0 the full match
  2951. 1 the first time, range or not
  2952. 8 the second time, if it is a range.")
  2953. (defconst org-plain-time-extension-regexp
  2954. (concat
  2955. "\\(\\<[012]?[0-9]"
  2956. "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
  2957. "\\+\\([0-9]+\\)\\(:\\([0-5][0-9]\\)\\)?")
  2958. "Regular expression to match a time range like 13:30+2:10 = 13:30-15:40.
  2959. Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
  2960. groups carry important information:
  2961. 0 the full match
  2962. 7 hours of duration
  2963. 9 minutes of duration")
  2964. (defconst org-stamp-time-of-day-regexp
  2965. (concat
  2966. "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} +\\sw+ +\\)"
  2967. "\\([012][0-9]:[0-5][0-9]\\(-\\([012][0-9]:[0-5][0-9]\\)\\)?[^\n\r>]*?\\)>"
  2968. "\\(--?"
  2969. "<\\1\\([012][0-9]:[0-5][0-9]\\)>\\)?")
  2970. "Regular expression to match a timestamp time or time range.
  2971. After a match, the following groups carry important information:
  2972. 0 the full match
  2973. 1 date plus weekday, for backreferencing to make sure both times on same day
  2974. 2 the first time, range or not
  2975. 4 the second time, if it is a range.")
  2976. (defconst org-startup-options
  2977. '(("fold" org-startup-folded t)
  2978. ("overview" org-startup-folded t)
  2979. ("nofold" org-startup-folded nil)
  2980. ("showall" org-startup-folded nil)
  2981. ("content" org-startup-folded content)
  2982. ("hidestars" org-hide-leading-stars t)
  2983. ("showstars" org-hide-leading-stars nil)
  2984. ("odd" org-odd-levels-only t)
  2985. ("oddeven" org-odd-levels-only nil)
  2986. ("align" org-startup-align-all-tables t)
  2987. ("noalign" org-startup-align-all-tables nil)
  2988. ("customtime" org-display-custom-times t)
  2989. ("logdone" org-log-done time)
  2990. ("lognotedone" org-log-done note)
  2991. ("nologdone" org-log-done nil)
  2992. ("lognoteclock-out" org-log-note-clock-out t)
  2993. ("nolognoteclock-out" org-log-note-clock-out nil)
  2994. ("logrepeat" org-log-repeat state)
  2995. ("lognoterepeat" org-log-repeat note)
  2996. ("nologrepeat" org-log-repeat nil)
  2997. ("fninline" org-footnote-define-inline t)
  2998. ("nofninline" org-footnote-define-inline nil)
  2999. ("fnlocal" org-footnote-section nil)
  3000. ("fnauto" org-footnote-auto-label t)
  3001. ("fnprompt" org-footnote-auto-label nil)
  3002. ("fnconfirm" org-footnote-auto-label confirm)
  3003. ("fnplain" org-footnote-auto-label plain)
  3004. ("fnadjust" org-footnote-auto-adjust t)
  3005. ("nofnadjust" org-footnote-auto-adjust nil)
  3006. ("constcgs" constants-unit-system cgs)
  3007. ("constSI" constants-unit-system SI)
  3008. ("noptag" org-tag-persistent-alist nil)
  3009. ("hideblocks" org-hide-block-startup t)
  3010. ("nohideblocks" org-hide-block-startup nil))
  3011. "Variable associated with STARTUP options for org-mode.
  3012. Each element is a list of three items: The startup options as written
  3013. in the #+STARTUP line, the corresponding variable, and the value to
  3014. set this variable to if the option is found. An optional forth element PUSH
  3015. means to push this value onto the list in the variable.")
  3016. (defun org-set-regexps-and-options ()
  3017. "Precompute regular expressions for current buffer."
  3018. (when (org-mode-p)
  3019. (org-set-local 'org-todo-kwd-alist nil)
  3020. (org-set-local 'org-todo-key-alist nil)
  3021. (org-set-local 'org-todo-key-trigger nil)
  3022. (org-set-local 'org-todo-keywords-1 nil)
  3023. (org-set-local 'org-done-keywords nil)
  3024. (org-set-local 'org-todo-heads nil)
  3025. (org-set-local 'org-todo-sets nil)
  3026. (org-set-local 'org-todo-log-states nil)
  3027. (org-set-local 'org-file-properties nil)
  3028. (org-set-local 'org-file-tags nil)
  3029. (let ((re (org-make-options-regexp
  3030. '("CATEGORY" "TODO" "COLUMNS"
  3031. "STARTUP" "ARCHIVE" "FILETAGS" "TAGS" "LINK" "PRIORITIES"
  3032. "CONSTANTS" "PROPERTY" "DRAWERS" "SETUPFILE")
  3033. "\\(?:[a-zA-Z][0-9a-zA-Z_]*_TODO\\)"))
  3034. (splitre "[ \t]+")
  3035. kwds kws0 kwsa key log value cat arch tags const links hw dws
  3036. tail sep kws1 prio props ftags drawers
  3037. ext-setup-or-nil setup-contents (start 0))
  3038. (save-excursion
  3039. (save-restriction
  3040. (widen)
  3041. (goto-char (point-min))
  3042. (while (or (and ext-setup-or-nil
  3043. (string-match re ext-setup-or-nil start)
  3044. (setq start (match-end 0)))
  3045. (and (setq ext-setup-or-nil nil start 0)
  3046. (re-search-forward re nil t)))
  3047. (setq key (upcase (match-string 1 ext-setup-or-nil))
  3048. value (org-match-string-no-properties 2 ext-setup-or-nil))
  3049. (cond
  3050. ((equal key "CATEGORY")
  3051. (if (string-match "[ \t]+$" value)
  3052. (setq value (replace-match "" t t value)))
  3053. (setq cat value))
  3054. ((member key '("SEQ_TODO" "TODO"))
  3055. (push (cons 'sequence (org-split-string value splitre)) kwds))
  3056. ((equal key "TYP_TODO")
  3057. (push (cons 'type (org-split-string value splitre)) kwds))
  3058. ((string-match "\\`\\([a-zA-Z][0-9a-zA-Z_]*\\)_TODO\\'" key)
  3059. ;; general TODO-like setup
  3060. (push (cons (intern (downcase (match-string 1 key)))
  3061. (org-split-string value splitre)) kwds))
  3062. ((equal key "TAGS")
  3063. (setq tags (append tags (if tags '("\\n") nil)
  3064. (org-split-string value splitre))))
  3065. ((equal key "COLUMNS")
  3066. (org-set-local 'org-columns-default-format value))
  3067. ((equal key "LINK")
  3068. (when (string-match "^\\(\\S-+\\)[ \t]+\\(.+\\)" value)
  3069. (push (cons (match-string 1 value)
  3070. (org-trim (match-string 2 value)))
  3071. links)))
  3072. ((equal key "PRIORITIES")
  3073. (setq prio (org-split-string value " +")))
  3074. ((equal key "PROPERTY")
  3075. (when (string-match "\\(\\S-+\\)\\s-+\\(.*\\)" value)
  3076. (push (cons (match-string 1 value) (match-string 2 value))
  3077. props)))
  3078. ((equal key "FILETAGS")
  3079. (when (string-match "\\S-" value)
  3080. (setq ftags
  3081. (append
  3082. ftags
  3083. (apply 'append
  3084. (mapcar (lambda (x) (org-split-string x ":"))
  3085. (org-split-string value)))))))
  3086. ((equal key "DRAWERS")
  3087. (setq drawers (org-split-string value splitre)))
  3088. ((equal key "CONSTANTS")
  3089. (setq const (append const (org-split-string value splitre))))
  3090. ((equal key "STARTUP")
  3091. (let ((opts (org-split-string value splitre))
  3092. l var val)
  3093. (while (setq l (pop opts))
  3094. (when (setq l (assoc l org-startup-options))
  3095. (setq var (nth 1 l) val (nth 2 l))
  3096. (if (not (nth 3 l))
  3097. (set (make-local-variable var) val)
  3098. (if (not (listp (symbol-value var)))
  3099. (set (make-local-variable var) nil))
  3100. (set (make-local-variable var) (symbol-value var))
  3101. (add-to-list var val))))))
  3102. ((equal key "ARCHIVE")
  3103. (string-match " *$" value)
  3104. (setq arch (replace-match "" t t value))
  3105. (remove-text-properties 0 (length arch)
  3106. '(face t fontified t) arch))
  3107. ((equal key "SETUPFILE")
  3108. (setq setup-contents (org-file-contents
  3109. (expand-file-name
  3110. (org-remove-double-quotes value))
  3111. 'noerror))
  3112. (if (not ext-setup-or-nil)
  3113. (setq ext-setup-or-nil setup-contents start 0)
  3114. (setq ext-setup-or-nil
  3115. (concat (substring ext-setup-or-nil 0 start)
  3116. "\n" setup-contents "\n"
  3117. (substring ext-setup-or-nil start)))))
  3118. ))))
  3119. (when cat
  3120. (org-set-local 'org-category (intern cat))
  3121. (push (cons "CATEGORY" cat) props))
  3122. (when prio
  3123. (if (< (length prio) 3) (setq prio '("A" "C" "B")))
  3124. (setq prio (mapcar 'string-to-char prio))
  3125. (org-set-local 'org-highest-priority (nth 0 prio))
  3126. (org-set-local 'org-lowest-priority (nth 1 prio))
  3127. (org-set-local 'org-default-priority (nth 2 prio)))
  3128. (and props (org-set-local 'org-file-properties (nreverse props)))
  3129. (and ftags (org-set-local 'org-file-tags
  3130. (mapcar 'org-add-prop-inherited ftags)))
  3131. (and drawers (org-set-local 'org-drawers drawers))
  3132. (and arch (org-set-local 'org-archive-location arch))
  3133. (and links (setq org-link-abbrev-alist-local (nreverse links)))
  3134. ;; Process the TODO keywords
  3135. (unless kwds
  3136. ;; Use the global values as if they had been given locally.
  3137. (setq kwds (default-value 'org-todo-keywords))
  3138. (if (stringp (car kwds))
  3139. (setq kwds (list (cons org-todo-interpretation
  3140. (default-value 'org-todo-keywords)))))
  3141. (setq kwds (reverse kwds)))
  3142. (setq kwds (nreverse kwds))
  3143. (let (inter kws kw)
  3144. (while (setq kws (pop kwds))
  3145. (let ((kws (or
  3146. (run-hook-with-args-until-success
  3147. 'org-todo-setup-filter-hook kws)
  3148. kws)))
  3149. (setq inter (pop kws) sep (member "|" kws)
  3150. kws0 (delete "|" (copy-sequence kws))
  3151. kwsa nil
  3152. kws1 (mapcar
  3153. (lambda (x)
  3154. ;; 1 2
  3155. (if (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?.*?)\\)?$" x)
  3156. (progn
  3157. (setq kw (match-string 1 x)
  3158. key (and (match-end 2) (match-string 2 x))
  3159. log (org-extract-log-state-settings x))
  3160. (push (cons kw (and key (string-to-char key))) kwsa)
  3161. (and log (push log org-todo-log-states))
  3162. kw)
  3163. (error "Invalid TODO keyword %s" x)))
  3164. kws0)
  3165. kwsa (if kwsa (append '((:startgroup))
  3166. (nreverse kwsa)
  3167. '((:endgroup))))
  3168. hw (car kws1)
  3169. dws (if sep (org-remove-keyword-keys (cdr sep)) (last kws1))
  3170. tail (list inter hw (car dws) (org-last dws))))
  3171. (add-to-list 'org-todo-heads hw 'append)
  3172. (push kws1 org-todo-sets)
  3173. (setq org-done-keywords (append org-done-keywords dws nil))
  3174. (setq org-todo-key-alist (append org-todo-key-alist kwsa))
  3175. (mapc (lambda (x) (push (cons x tail) org-todo-kwd-alist)) kws1)
  3176. (setq org-todo-keywords-1 (append org-todo-keywords-1 kws1 nil)))
  3177. (setq org-todo-sets (nreverse org-todo-sets)
  3178. org-todo-kwd-alist (nreverse org-todo-kwd-alist)
  3179. org-todo-key-trigger (delq nil (mapcar 'cdr org-todo-key-alist))
  3180. org-todo-key-alist (org-assign-fast-keys org-todo-key-alist)))
  3181. ;; Process the constants
  3182. (when const
  3183. (let (e cst)
  3184. (while (setq e (pop const))
  3185. (if (string-match "^\\([a-zA-Z0][_a-zA-Z0-9]*\\)=\\(.*\\)" e)
  3186. (push (cons (match-string 1 e) (match-string 2 e)) cst)))
  3187. (setq org-table-formula-constants-local cst)))
  3188. ;; Process the tags.
  3189. (when tags
  3190. (let (e tgs)
  3191. (while (setq e (pop tags))
  3192. (cond
  3193. ((equal e "{") (push '(:startgroup) tgs))
  3194. ((equal e "}") (push '(:endgroup) tgs))
  3195. ((equal e "\\n") (push '(:newline) tgs))
  3196. ((string-match (org-re "^\\([[:alnum:]_@]+\\)(\\(.\\))$") e)
  3197. (push (cons (match-string 1 e)
  3198. (string-to-char (match-string 2 e)))
  3199. tgs))
  3200. (t (push (list e) tgs))))
  3201. (org-set-local 'org-tag-alist nil)
  3202. (while (setq e (pop tgs))
  3203. (or (and (stringp (car e))
  3204. (assoc (car e) org-tag-alist))
  3205. (push e org-tag-alist)))))
  3206. ;; Compute the regular expressions and other local variables
  3207. (if (not org-done-keywords)
  3208. (setq org-done-keywords (list (org-last org-todo-keywords-1))))
  3209. (setq org-ds-keyword-length (+ 2 (max (length org-deadline-string)
  3210. (length org-scheduled-string)
  3211. (length org-clock-string)
  3212. (length org-closed-string)))
  3213. org-drawer-regexp
  3214. (concat "^[ \t]*:\\("
  3215. (mapconcat 'regexp-quote org-drawers "\\|")
  3216. "\\):[ \t]*$")
  3217. org-not-done-keywords
  3218. (org-delete-all org-done-keywords (copy-sequence org-todo-keywords-1))
  3219. org-todo-regexp
  3220. (concat "\\<\\(" (mapconcat 'regexp-quote org-todo-keywords-1
  3221. "\\|") "\\)\\>")
  3222. org-not-done-regexp
  3223. (concat "\\<\\("
  3224. (mapconcat 'regexp-quote org-not-done-keywords "\\|")
  3225. "\\)\\>")
  3226. org-not-done-heading-regexp
  3227. (concat "^\\(\\*+\\)[ \t]+\\("
  3228. (mapconcat 'regexp-quote org-not-done-keywords "\\|")
  3229. "\\)\\>")
  3230. org-todo-line-regexp
  3231. (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
  3232. (mapconcat 'regexp-quote org-todo-keywords-1 "\\|")
  3233. "\\)\\>\\)?[ \t]*\\(.*\\)")
  3234. org-complex-heading-regexp
  3235. (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
  3236. (mapconcat 'regexp-quote org-todo-keywords-1 "\\|")
  3237. "\\)\\>\\)?\\(?:[ \t]*\\(\\[#.\\]\\)\\)?[ \t]*\\(.*?\\)"
  3238. "\\(?:[ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
  3239. org-nl-done-regexp
  3240. (concat "\n\\*+[ \t]+"
  3241. "\\(?:" (mapconcat 'regexp-quote org-done-keywords "\\|")
  3242. "\\)" "\\>")
  3243. org-todo-line-tags-regexp
  3244. (concat "^\\(\\*+\\)[ \t]+\\(?:\\("
  3245. (mapconcat 'regexp-quote org-todo-keywords-1 "\\|")
  3246. (org-re
  3247. "\\)\\>\\)? *\\(.*?\\([ \t]:[[:alnum:]:_@]+:[ \t]*\\)?$\\)"))
  3248. org-looking-at-done-regexp
  3249. (concat "^" "\\(?:"
  3250. (mapconcat 'regexp-quote org-done-keywords "\\|") "\\)"
  3251. "\\>")
  3252. org-deadline-regexp (concat "\\<" org-deadline-string)
  3253. org-deadline-time-regexp
  3254. (concat "\\<" org-deadline-string " *<\\([^>]+\\)>")
  3255. org-deadline-line-regexp
  3256. (concat "\\<\\(" org-deadline-string "\\).*")
  3257. org-scheduled-regexp
  3258. (concat "\\<" org-scheduled-string)
  3259. org-scheduled-time-regexp
  3260. (concat "\\<" org-scheduled-string " *<\\([^>]+\\)>")
  3261. org-closed-time-regexp
  3262. (concat "\\<" org-closed-string " *\\[\\([^]]+\\)\\]")
  3263. org-keyword-time-regexp
  3264. (concat "\\<\\(" org-scheduled-string
  3265. "\\|" org-deadline-string
  3266. "\\|" org-closed-string
  3267. "\\|" org-clock-string "\\)"
  3268. " *[[<]\\([^]>]+\\)[]>]")
  3269. org-keyword-time-not-clock-regexp
  3270. (concat "\\<\\(" org-scheduled-string
  3271. "\\|" org-deadline-string
  3272. "\\|" org-closed-string
  3273. "\\)"
  3274. " *[[<]\\([^]>]+\\)[]>]")
  3275. org-maybe-keyword-time-regexp
  3276. (concat "\\(\\<\\(" org-scheduled-string
  3277. "\\|" org-deadline-string
  3278. "\\|" org-closed-string
  3279. "\\|" org-clock-string "\\)\\)?"
  3280. " *\\([[<][0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^]\r\n>]*?[]>]\\|<%%([^\r\n>]*>\\)")
  3281. org-planning-or-clock-line-re
  3282. (concat "\\(?:^[ \t]*\\(" org-scheduled-string
  3283. "\\|" org-deadline-string
  3284. "\\|" org-closed-string "\\|" org-clock-string
  3285. "\\)\\>\\)")
  3286. )
  3287. (org-compute-latex-and-specials-regexp)
  3288. (org-set-font-lock-defaults))))
  3289. (defun org-file-contents (file &optional noerror)
  3290. "Return the contents of FILE, as a string."
  3291. (if (or (not file)
  3292. (not (file-readable-p file)))
  3293. (if noerror
  3294. (progn
  3295. (message "Cannot read file %s" file)
  3296. (ding) (sit-for 2)
  3297. "")
  3298. (error "Cannot read file %s" file))
  3299. (with-temp-buffer
  3300. (insert-file-contents file)
  3301. (buffer-string))))
  3302. (defun org-extract-log-state-settings (x)
  3303. "Extract the log state setting from a TODO keyword string.
  3304. This will extract info from a string like \"WAIT(w@/!)\"."
  3305. (let (kw key log1 log2)
  3306. (when (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?\\([!@]\\)?\\(?:/\\([!@]\\)\\)?)\\)?$" x)
  3307. (setq kw (match-string 1 x)
  3308. key (and (match-end 2) (match-string 2 x))
  3309. log1 (and (match-end 3) (match-string 3 x))
  3310. log2 (and (match-end 4) (match-string 4 x)))
  3311. (and (or log1 log2)
  3312. (list kw
  3313. (and log1 (if (equal log1 "!") 'time 'note))
  3314. (and log2 (if (equal log2 "!") 'time 'note)))))))
  3315. (defun org-remove-keyword-keys (list)
  3316. "Remove a pair of parenthesis at the end of each string in LIST."
  3317. (mapcar (lambda (x)
  3318. (if (string-match "(.*)$" x)
  3319. (substring x 0 (match-beginning 0))
  3320. x))
  3321. list))
  3322. ;; FIXME: this could be done much better, using second characters etc.
  3323. (defun org-assign-fast-keys (alist)
  3324. "Assign fast keys to a keyword-key alist.
  3325. Respect keys that are already there."
  3326. (let (new e k c c1 c2 (char ?a))
  3327. (while (setq e (pop alist))
  3328. (cond
  3329. ((equal e '(:startgroup)) (push e new))
  3330. ((equal e '(:endgroup)) (push e new))
  3331. ((equal e '(:newline)) (push e new))
  3332. (t
  3333. (setq k (car e) c2 nil)
  3334. (if (cdr e)
  3335. (setq c (cdr e))
  3336. ;; automatically assign a character.
  3337. (setq c1 (string-to-char
  3338. (downcase (substring
  3339. k (if (= (string-to-char k) ?@) 1 0)))))
  3340. (if (or (rassoc c1 new) (rassoc c1 alist))
  3341. (while (or (rassoc char new) (rassoc char alist))
  3342. (setq char (1+ char)))
  3343. (setq c2 c1))
  3344. (setq c (or c2 char)))
  3345. (push (cons k c) new))))
  3346. (nreverse new)))
  3347. ;;; Some variables used in various places
  3348. (defvar org-window-configuration nil
  3349. "Used in various places to store a window configuration.")
  3350. (defvar org-finish-function nil
  3351. "Function to be called when `C-c C-c' is used.
  3352. This is for getting out of special buffers like remember.")
  3353. ;; FIXME: Occasionally check by commenting these, to make sure
  3354. ;; no other functions uses these, forgetting to let-bind them.
  3355. (defvar entry)
  3356. (defvar last-state)
  3357. (defvar date)
  3358. ;; Defined somewhere in this file, but used before definition.
  3359. (defvar org-html-entities)
  3360. (defvar org-struct-menu)
  3361. (defvar org-org-menu)
  3362. (defvar org-tbl-menu)
  3363. (defvar org-agenda-keymap)
  3364. ;;;; Define the Org-mode
  3365. (if (and (not (keymapp outline-mode-map)) (featurep 'allout))
  3366. (error "Conflict with outdated version of allout.el. Load org.el before allout.el, or upgrade to newer allout, for example by switching to Emacs 22."))
  3367. ;; We use a before-change function to check if a table might need
  3368. ;; an update.
  3369. (defvar org-table-may-need-update t
  3370. "Indicates that a table might need an update.
  3371. This variable is set by `org-before-change-function'.
  3372. `org-table-align' sets it back to nil.")
  3373. (defun org-before-change-function (beg end)
  3374. "Every change indicates that a table might need an update."
  3375. (setq org-table-may-need-update t))
  3376. (defvar org-mode-map)
  3377. (defvar org-mode-hook nil
  3378. "Mode hook for Org-mode, run after the mode was turned on.")
  3379. (defvar org-inhibit-startup nil) ; Dynamically-scoped param.
  3380. (defvar org-agenda-keep-modes nil) ; Dynamically-scoped param.
  3381. (defvar org-inhibit-logging nil) ; Dynamically-scoped param.
  3382. (defvar org-inhibit-blocking nil) ; Dynamically-scoped param.
  3383. (defvar org-table-buffer-is-an nil)
  3384. (defconst org-outline-regexp "\\*+ ")
  3385. ;;;###autoload
  3386. (define-derived-mode org-mode outline-mode "Org"
  3387. "Outline-based notes management and organizer, alias
  3388. \"Carsten's outline-mode for keeping track of everything.\"
  3389. Org-mode develops organizational tasks around a NOTES file which
  3390. contains information about projects as plain text. Org-mode is
  3391. implemented on top of outline-mode, which is ideal to keep the content
  3392. of large files well structured. It supports ToDo items, deadlines and
  3393. time stamps, which magically appear in the diary listing of the Emacs
  3394. calendar. Tables are easily created with a built-in table editor.
  3395. Plain text URL-like links connect to websites, emails (VM), Usenet
  3396. messages (Gnus), BBDB entries, and any files related to the project.
  3397. For printing and sharing of notes, an Org-mode file (or a part of it)
  3398. can be exported as a structured ASCII or HTML file.
  3399. The following commands are available:
  3400. \\{org-mode-map}"
  3401. ;; Get rid of Outline menus, they are not needed
  3402. ;; Need to do this here because define-derived-mode sets up
  3403. ;; the keymap so late. Still, it is a waste to call this each time
  3404. ;; we switch another buffer into org-mode.
  3405. (if (featurep 'xemacs)
  3406. (when (boundp 'outline-mode-menu-heading)
  3407. ;; Assume this is Greg's port, it used easymenu
  3408. (easy-menu-remove outline-mode-menu-heading)
  3409. (easy-menu-remove outline-mode-menu-show)
  3410. (easy-menu-remove outline-mode-menu-hide))
  3411. (define-key org-mode-map [menu-bar headings] 'undefined)
  3412. (define-key org-mode-map [menu-bar hide] 'undefined)
  3413. (define-key org-mode-map [menu-bar show] 'undefined))
  3414. (org-load-modules-maybe)
  3415. (easy-menu-add org-org-menu)
  3416. (easy-menu-add org-tbl-menu)
  3417. (org-install-agenda-files-menu)
  3418. (if org-descriptive-links (org-add-to-invisibility-spec '(org-link)))
  3419. (org-add-to-invisibility-spec '(org-cwidth))
  3420. (org-add-to-invisibility-spec '(org-hide-block . t))
  3421. (when (featurep 'xemacs)
  3422. (org-set-local 'line-move-ignore-invisible t))
  3423. (org-set-local 'outline-regexp org-outline-regexp)
  3424. (org-set-local 'outline-level 'org-outline-level)
  3425. (when (and org-ellipsis
  3426. (fboundp 'set-display-table-slot) (boundp 'buffer-display-table)
  3427. (fboundp 'make-glyph-code))
  3428. (unless org-display-table
  3429. (setq org-display-table (make-display-table)))
  3430. (set-display-table-slot
  3431. org-display-table 4
  3432. (vconcat (mapcar
  3433. (lambda (c) (make-glyph-code c (and (not (stringp org-ellipsis))
  3434. org-ellipsis)))
  3435. (if (stringp org-ellipsis) org-ellipsis "..."))))
  3436. (setq buffer-display-table org-display-table))
  3437. (org-set-regexps-and-options)
  3438. (when (and org-tag-faces (not org-tags-special-faces-re))
  3439. ;; tag faces set outside customize.... force initialization.
  3440. (org-set-tag-faces 'org-tag-faces org-tag-faces))
  3441. ;; Calc embedded
  3442. (org-set-local 'calc-embedded-open-mode "# ")
  3443. (modify-syntax-entry ?# "<")
  3444. (modify-syntax-entry ?@ "w")
  3445. (if org-startup-truncated (setq truncate-lines t))
  3446. (org-set-local 'font-lock-unfontify-region-function
  3447. 'org-unfontify-region)
  3448. ;; Activate before-change-function
  3449. (org-set-local 'org-table-may-need-update t)
  3450. (org-add-hook 'before-change-functions 'org-before-change-function nil
  3451. 'local)
  3452. ;; Check for running clock before killing a buffer
  3453. (org-add-hook 'kill-buffer-hook 'org-check-running-clock nil 'local)
  3454. ;; Paragraphs and auto-filling
  3455. (org-set-autofill-regexps)
  3456. (setq indent-line-function 'org-indent-line-function)
  3457. (org-update-radio-target-regexp)
  3458. ;; Make sure dependence stuff works reliably, even for users who set it
  3459. ;; too late :-(
  3460. (if org-enforce-todo-dependencies
  3461. (add-hook 'org-blocker-hook
  3462. 'org-block-todo-from-children-or-siblings-or-parent)
  3463. (remove-hook 'org-blocker-hook
  3464. 'org-block-todo-from-children-or-siblings-or-parent))
  3465. (if org-enforce-todo-checkbox-dependencies
  3466. (add-hook 'org-blocker-hook
  3467. 'org-block-todo-from-checkboxes)
  3468. (remove-hook 'org-blocker-hook
  3469. 'org-block-todo-from-checkboxes))
  3470. ;; Comment characters
  3471. ; (org-set-local 'comment-start "#") ;; FIXME: this breaks wrapping
  3472. (org-set-local 'comment-padding " ")
  3473. ;; Align options lines
  3474. (org-set-local
  3475. 'align-mode-rules-list
  3476. '((org-in-buffer-settings
  3477. (regexp . "^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
  3478. (modes . '(org-mode)))))
  3479. ;; Imenu
  3480. (org-set-local 'imenu-create-index-function
  3481. 'org-imenu-get-tree)
  3482. ;; Make isearch reveal context
  3483. (if (or (featurep 'xemacs)
  3484. (not (boundp 'outline-isearch-open-invisible-function)))
  3485. ;; Emacs 21 and XEmacs make use of the hook
  3486. (org-add-hook 'isearch-mode-end-hook 'org-isearch-end 'append 'local)
  3487. ;; Emacs 22 deals with this through a special variable
  3488. (org-set-local 'outline-isearch-open-invisible-function
  3489. (lambda (&rest ignore) (org-show-context 'isearch))))
  3490. ;; If empty file that did not turn on org-mode automatically, make it to.
  3491. (if (and org-insert-mode-line-in-empty-file
  3492. (interactive-p)
  3493. (= (point-min) (point-max)))
  3494. (insert "# -*- mode: org -*-\n\n"))
  3495. (unless org-inhibit-startup
  3496. (when org-startup-align-all-tables
  3497. (let ((bmp (buffer-modified-p)))
  3498. (org-table-map-tables 'org-table-align)
  3499. (set-buffer-modified-p bmp)))
  3500. (org-set-startup-visibility)))
  3501. (put 'org-mode 'flyspell-mode-predicate 'org-mode-flyspell-verify)
  3502. (defun org-current-time ()
  3503. "Current time, possibly rounded to `org-time-stamp-rounding-minutes'."
  3504. (if (> (car org-time-stamp-rounding-minutes) 1)
  3505. (let ((r (car org-time-stamp-rounding-minutes))
  3506. (time (decode-time)))
  3507. (apply 'encode-time
  3508. (append (list 0 (* r (floor (+ .5 (/ (float (nth 1 time)) r)))))
  3509. (nthcdr 2 time))))
  3510. (current-time)))
  3511. ;;;; Font-Lock stuff, including the activators
  3512. (defvar org-mouse-map (make-sparse-keymap))
  3513. (org-defkey org-mouse-map
  3514. (if (featurep 'xemacs) [button2] [mouse-2]) 'org-open-at-mouse)
  3515. (org-defkey org-mouse-map
  3516. (if (featurep 'xemacs) [button3] [mouse-3]) 'org-find-file-at-mouse)
  3517. (when org-mouse-1-follows-link
  3518. (org-defkey org-mouse-map [follow-link] 'mouse-face))
  3519. (when org-tab-follows-link
  3520. (org-defkey org-mouse-map [(tab)] 'org-open-at-point)
  3521. (org-defkey org-mouse-map "\C-i" 'org-open-at-point))
  3522. (require 'font-lock)
  3523. (defconst org-non-link-chars "]\t\n\r<>")
  3524. (defvar org-link-types '("http" "https" "ftp" "mailto" "file" "news"
  3525. "shell" "elisp"))
  3526. (defvar org-link-types-re nil
  3527. "Matches a link that has a url-like prefix like \"http:\"")
  3528. (defvar org-link-re-with-space nil
  3529. "Matches a link with spaces, optional angular brackets around it.")
  3530. (defvar org-link-re-with-space2 nil
  3531. "Matches a link with spaces, optional angular brackets around it.")
  3532. (defvar org-link-re-with-space3 nil
  3533. "Matches a link with spaces, only for internal part in bracket links.")
  3534. (defvar org-angle-link-re nil
  3535. "Matches link with angular brackets, spaces are allowed.")
  3536. (defvar org-plain-link-re nil
  3537. "Matches plain link, without spaces.")
  3538. (defvar org-bracket-link-regexp nil
  3539. "Matches a link in double brackets.")
  3540. (defvar org-bracket-link-analytic-regexp nil
  3541. "Regular expression used to analyze links.
  3542. Here is what the match groups contain after a match:
  3543. 1: http:
  3544. 2: http
  3545. 3: path
  3546. 4: [desc]
  3547. 5: desc")
  3548. (defvar org-bracket-link-analytic-regexp++ nil
  3549. "Like org-bracket-link-analytic-regexp, but include coderef internal type.")
  3550. (defvar org-any-link-re nil
  3551. "Regular expression matching any link.")
  3552. (defun org-make-link-regexps ()
  3553. "Update the link regular expressions.
  3554. This should be called after the variable `org-link-types' has changed."
  3555. (setq org-link-types-re
  3556. (concat
  3557. "\\`\\(" (mapconcat 'identity org-link-types "\\|") "\\):")
  3558. org-link-re-with-space
  3559. (concat
  3560. "<?\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
  3561. "\\([^" org-non-link-chars " ]"
  3562. "[^" org-non-link-chars "]*"
  3563. "[^" org-non-link-chars " ]\\)>?")
  3564. org-link-re-with-space2
  3565. (concat
  3566. "<?\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
  3567. "\\([^" org-non-link-chars " ]"
  3568. "[^\t\n\r]*"
  3569. "[^" org-non-link-chars " ]\\)>?")
  3570. org-link-re-with-space3
  3571. (concat
  3572. "<?\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
  3573. "\\([^" org-non-link-chars " ]"
  3574. "[^\t\n\r]*\\)")
  3575. org-angle-link-re
  3576. (concat
  3577. "<\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
  3578. "\\([^" org-non-link-chars " ]"
  3579. "[^" org-non-link-chars "]*"
  3580. "\\)>")
  3581. org-plain-link-re
  3582. (concat
  3583. "\\<\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
  3584. "\\([^]\t\n\r<>() ]+[^]\t\n\r<>,.;() ]\\)")
  3585. org-bracket-link-regexp
  3586. "\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]"
  3587. org-bracket-link-analytic-regexp
  3588. (concat
  3589. "\\[\\["
  3590. "\\(\\(" (mapconcat 'identity org-link-types "\\|") "\\):\\)?"
  3591. "\\([^]]+\\)"
  3592. "\\]"
  3593. "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
  3594. "\\]")
  3595. org-bracket-link-analytic-regexp++
  3596. (concat
  3597. "\\[\\["
  3598. "\\(\\(" (mapconcat 'identity (cons "coderef" org-link-types) "\\|") "\\):\\)?"
  3599. "\\([^]]+\\)"
  3600. "\\]"
  3601. "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
  3602. "\\]")
  3603. org-any-link-re
  3604. (concat "\\(" org-bracket-link-regexp "\\)\\|\\("
  3605. org-angle-link-re "\\)\\|\\("
  3606. org-plain-link-re "\\)")))
  3607. (org-make-link-regexps)
  3608. (defconst org-ts-regexp "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^\r\n>]*?\\)>"
  3609. "Regular expression for fast time stamp matching.")
  3610. (defconst org-ts-regexp-both "[[<]\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^\r\n>]*?\\)[]>]"
  3611. "Regular expression for fast time stamp matching.")
  3612. (defconst org-ts-regexp0 "\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) *\\([^]-+0-9>\r\n ]*\\)\\( \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
  3613. "Regular expression matching time strings for analysis.
  3614. This one does not require the space after the date, so it can be used
  3615. on a string that terminates immediately after the date.")
  3616. (defconst org-ts-regexp1 "\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) +\\([^]-+0-9>\r\n ]*\\)\\( \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
  3617. "Regular expression matching time strings for analysis.")
  3618. (defconst org-ts-regexp2 (concat "<" org-ts-regexp1 "[^>\n]\\{0,16\\}>")
  3619. "Regular expression matching time stamps, with groups.")
  3620. (defconst org-ts-regexp3 (concat "[[<]" org-ts-regexp1 "[^]>\n]\\{0,16\\}[]>]")
  3621. "Regular expression matching time stamps (also [..]), with groups.")
  3622. (defconst org-tr-regexp (concat org-ts-regexp "--?-?" org-ts-regexp)
  3623. "Regular expression matching a time stamp range.")
  3624. (defconst org-tr-regexp-both
  3625. (concat org-ts-regexp-both "--?-?" org-ts-regexp-both)
  3626. "Regular expression matching a time stamp range.")
  3627. (defconst org-tsr-regexp (concat org-ts-regexp "\\(--?-?"
  3628. org-ts-regexp "\\)?")
  3629. "Regular expression matching a time stamp or time stamp range.")
  3630. (defconst org-tsr-regexp-both (concat org-ts-regexp-both "\\(--?-?"
  3631. org-ts-regexp-both "\\)?")
  3632. "Regular expression matching a time stamp or time stamp range.
  3633. The time stamps may be either active or inactive.")
  3634. (defvar org-emph-face nil)
  3635. (defun org-do-emphasis-faces (limit)
  3636. "Run through the buffer and add overlays to links."
  3637. (let (rtn a)
  3638. (while (and (not rtn) (re-search-forward org-emph-re limit t))
  3639. (if (not (= (char-after (match-beginning 3))
  3640. (char-after (match-beginning 4))))
  3641. (progn
  3642. (setq rtn t)
  3643. (setq a (assoc (match-string 3) org-emphasis-alist))
  3644. (font-lock-prepend-text-property (match-beginning 2) (match-end 2)
  3645. 'face
  3646. (nth 1 a))
  3647. (and (nth 4 a)
  3648. (org-remove-flyspell-overlays-in
  3649. (match-beginning 0) (match-end 0)))
  3650. (add-text-properties (match-beginning 2) (match-end 2)
  3651. '(font-lock-multiline t))
  3652. (when org-hide-emphasis-markers
  3653. (add-text-properties (match-end 4) (match-beginning 5)
  3654. '(invisible org-link))
  3655. (add-text-properties (match-beginning 3) (match-end 3)
  3656. '(invisible org-link)))))
  3657. (backward-char 1))
  3658. rtn))
  3659. (defun org-emphasize (&optional char)
  3660. "Insert or change an emphasis, i.e. a font like bold or italic.
  3661. If there is an active region, change that region to a new emphasis.
  3662. If there is no region, just insert the marker characters and position
  3663. the cursor between them.
  3664. CHAR should be either the marker character, or the first character of the
  3665. HTML tag associated with that emphasis. If CHAR is a space, the means
  3666. to remove the emphasis of the selected region.
  3667. If char is not given (for example in an interactive call) it
  3668. will be prompted for."
  3669. (interactive)
  3670. (let ((eal org-emphasis-alist) e det
  3671. (erc org-emphasis-regexp-components)
  3672. (prompt "")
  3673. (string "") beg end move tag c s)
  3674. (if (org-region-active-p)
  3675. (setq beg (region-beginning) end (region-end)
  3676. string (buffer-substring beg end))
  3677. (setq move t))
  3678. (while (setq e (pop eal))
  3679. (setq tag (car (org-split-string (nth 2 e) "[ <>/]+"))
  3680. c (aref tag 0))
  3681. (push (cons c (string-to-char (car e))) det)
  3682. (setq prompt (concat prompt (format " [%s%c]%s" (car e) c
  3683. (substring tag 1)))))
  3684. (setq det (nreverse det))
  3685. (unless char
  3686. (message "%s" (concat "Emphasis marker or tag:" prompt))
  3687. (setq char (read-char-exclusive)))
  3688. (setq char (or (cdr (assoc char det)) char))
  3689. (if (equal char ?\ )
  3690. (setq s "" move nil)
  3691. (unless (assoc (char-to-string char) org-emphasis-alist)
  3692. (error "No such emphasis marker: \"%c\"" char))
  3693. (setq s (char-to-string char)))
  3694. (while (and (> (length string) 1)
  3695. (equal (substring string 0 1) (substring string -1))
  3696. (assoc (substring string 0 1) org-emphasis-alist))
  3697. (setq string (substring string 1 -1)))
  3698. (setq string (concat s string s))
  3699. (if beg (delete-region beg end))
  3700. (unless (or (bolp)
  3701. (string-match (concat "[" (nth 0 erc) "\n]")
  3702. (char-to-string (char-before (point)))))
  3703. (insert " "))
  3704. (unless (string-match (concat "[" (nth 1 erc) "\n]")
  3705. (char-to-string (char-after (point))))
  3706. (insert " ") (backward-char 1))
  3707. (insert string)
  3708. (and move (backward-char 1))))
  3709. (defconst org-nonsticky-props
  3710. '(mouse-face highlight keymap invisible intangible help-echo org-linked-text))
  3711. (defsubst org-rear-nonsticky-at (pos)
  3712. (add-text-properties (1- pos) pos (list 'rear-nonsticky org-nonsticky-props)))
  3713. (defun org-activate-plain-links (limit)
  3714. "Run through the buffer and add overlays to links."
  3715. (catch 'exit
  3716. (let (f)
  3717. (while (re-search-forward org-plain-link-re limit t)
  3718. (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
  3719. (setq f (get-text-property (match-beginning 0) 'face))
  3720. (if (or (eq f 'org-tag)
  3721. (and (listp f) (memq 'org-tag f)))
  3722. nil
  3723. (add-text-properties (match-beginning 0) (match-end 0)
  3724. (list 'mouse-face 'highlight
  3725. 'keymap org-mouse-map))
  3726. (org-rear-nonsticky-at (match-end 0))
  3727. (throw 'exit t))))))
  3728. (defun org-activate-code (limit)
  3729. (if (re-search-forward "^[ \t]*\\(: .*\n?\\)" limit t)
  3730. (progn
  3731. (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
  3732. (remove-text-properties (match-beginning 0) (match-end 0)
  3733. '(display t invisible t intangible t))
  3734. t)))
  3735. (defun org-fontify-meta-lines-and-blocks (limit)
  3736. "Fontify #+ lines and blocks, in the correct ways."
  3737. (let ((case-fold-search t))
  3738. (if (re-search-forward
  3739. "^\\([ \t]*#\\+\\(\\([a-zA-Z]+:?\\)\\(_\\([a-zA-Z]+\\)\\)?\\)\\(.*\\)\\)"
  3740. limit t)
  3741. (let ((beg (match-beginning 0))
  3742. (beg1 (line-beginning-position 2))
  3743. (dc1 (downcase (match-string 2)))
  3744. (dc3 (downcase (match-string 3)))
  3745. end end1 quoting)
  3746. (cond
  3747. ((member dc1 '("html:" "ascii:" "latex:" "docbook:"))
  3748. ;; a single line of backend-specific content
  3749. (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
  3750. (remove-text-properties (match-beginning 0) (match-end 0)
  3751. '(display t invisible t intangible t))
  3752. (add-text-properties (match-beginning 1) (match-end 3)
  3753. '(font-lock-fontified t face org-meta-line))
  3754. (add-text-properties (match-beginning 6) (match-end 6)
  3755. '(font-lock-fontified t face org-block))
  3756. t)
  3757. ((and (match-end 4) (equal dc3 "begin"))
  3758. ;; Truely a block
  3759. (setq quoting (member (downcase (match-string 5))
  3760. org-protecting-blocks))
  3761. (when (re-search-forward
  3762. (concat "^[ \t]*#\\+end" (match-string 4) "\\>.*")
  3763. nil t) ;; on purpose, we look further than LIMIT
  3764. (setq end (match-end 0) end1 (1- (match-beginning 0)))
  3765. (when quoting
  3766. (remove-text-properties beg end
  3767. '(display t invisible t intangible t)))
  3768. (add-text-properties
  3769. beg end
  3770. '(font-lock-fontified t font-lock-multiline t))
  3771. (add-text-properties beg beg1 '(face org-meta-line))
  3772. (add-text-properties end1 end '(face org-meta-line))
  3773. (when quoting
  3774. (add-text-properties beg1 end1 '(face org-block)))
  3775. t))
  3776. ((not (member (char-after beg) '(?\ ?\t)))
  3777. ;; just any other in-buffer setting, but not indented
  3778. (add-text-properties
  3779. beg (match-end 0)
  3780. '(font-lock-fontified t face org-meta-line))
  3781. t)
  3782. ((or (member dc1 '("caption:" "label:" "orgtbl:" "tblfm:" "tblname:"))
  3783. (and (match-end 4) (equal dc3 "attr")))
  3784. (add-text-properties
  3785. beg (match-end 0)
  3786. '(font-lock-fontified t face org-meta-line))
  3787. t)
  3788. (t nil))))))
  3789. (defun org-activate-angle-links (limit)
  3790. "Run through the buffer and add overlays to links."
  3791. (if (re-search-forward org-angle-link-re limit t)
  3792. (progn
  3793. (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
  3794. (add-text-properties (match-beginning 0) (match-end 0)
  3795. (list 'mouse-face 'highlight
  3796. 'keymap org-mouse-map))
  3797. (org-rear-nonsticky-at (match-end 0))
  3798. t)))
  3799. (defun org-activate-footnote-links (limit)
  3800. "Run through the buffer and add overlays to links."
  3801. (if (re-search-forward "\\(^\\|[^][]\\)\\(\\[\\([0-9]+\\]\\|fn:[^ \t\r\n:]+?[]:]\\)\\)"
  3802. limit t)
  3803. (progn
  3804. (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
  3805. (add-text-properties (match-beginning 2) (match-end 2)
  3806. (list 'mouse-face 'highlight
  3807. 'keymap org-mouse-map
  3808. 'help-echo
  3809. (if (= (point-at-bol) (match-beginning 2))
  3810. "Footnote definition"
  3811. "Footnote reference")
  3812. ))
  3813. (org-rear-nonsticky-at (match-end 2))
  3814. t)))
  3815. (defun org-activate-bracket-links (limit)
  3816. "Run through the buffer and add overlays to bracketed links."
  3817. (if (re-search-forward org-bracket-link-regexp limit t)
  3818. (let* ((help (concat "LINK: "
  3819. (org-match-string-no-properties 1)))
  3820. ;; FIXME: above we should remove the escapes.
  3821. ;; but that requires another match, protecting match data,
  3822. ;; a lot of overhead for font-lock.
  3823. (ip (org-maybe-intangible
  3824. (list 'invisible 'org-link
  3825. 'keymap org-mouse-map 'mouse-face 'highlight
  3826. 'font-lock-multiline t 'help-echo help)))
  3827. (vp (list 'keymap org-mouse-map 'mouse-face 'highlight
  3828. 'font-lock-multiline t 'help-echo help)))
  3829. ;; We need to remove the invisible property here. Table narrowing
  3830. ;; may have made some of this invisible.
  3831. (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
  3832. (remove-text-properties (match-beginning 0) (match-end 0)
  3833. '(invisible nil))
  3834. (if (match-end 3)
  3835. (progn
  3836. (add-text-properties (match-beginning 0) (match-beginning 3) ip)
  3837. (org-rear-nonsticky-at (match-beginning 3))
  3838. (add-text-properties (match-beginning 3) (match-end 3) vp)
  3839. (org-rear-nonsticky-at (match-end 3))
  3840. (add-text-properties (match-end 3) (match-end 0) ip)
  3841. (org-rear-nonsticky-at (match-end 0)))
  3842. (add-text-properties (match-beginning 0) (match-beginning 1) ip)
  3843. (org-rear-nonsticky-at (match-beginning 1))
  3844. (add-text-properties (match-beginning 1) (match-end 1) vp)
  3845. (org-rear-nonsticky-at (match-end 1))
  3846. (add-text-properties (match-end 1) (match-end 0) ip)
  3847. (org-rear-nonsticky-at (match-end 0)))
  3848. t)))
  3849. (defun org-activate-dates (limit)
  3850. "Run through the buffer and add overlays to dates."
  3851. (if (re-search-forward org-tsr-regexp-both limit t)
  3852. (progn
  3853. (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
  3854. (add-text-properties (match-beginning 0) (match-end 0)
  3855. (list 'mouse-face 'highlight
  3856. 'keymap org-mouse-map))
  3857. (org-rear-nonsticky-at (match-end 0))
  3858. (when org-display-custom-times
  3859. (if (match-end 3)
  3860. (org-display-custom-time (match-beginning 3) (match-end 3)))
  3861. (org-display-custom-time (match-beginning 1) (match-end 1)))
  3862. t)))
  3863. (defvar org-target-link-regexp nil
  3864. "Regular expression matching radio targets in plain text.")
  3865. (make-variable-buffer-local 'org-target-link-regexp)
  3866. (defvar org-target-regexp "<<\\([^<>\n\r]+\\)>>"
  3867. "Regular expression matching a link target.")
  3868. (defvar org-radio-target-regexp "<<<\\([^<>\n\r]+\\)>>>"
  3869. "Regular expression matching a radio target.")
  3870. (defvar org-any-target-regexp "<<<?\\([^<>\n\r]+\\)>>>?" ; FIXME, not exact, would match <<<aaa>> as a radio target.
  3871. "Regular expression matching any target.")
  3872. (defun org-activate-target-links (limit)
  3873. "Run through the buffer and add overlays to target matches."
  3874. (when org-target-link-regexp
  3875. (let ((case-fold-search t))
  3876. (if (re-search-forward org-target-link-regexp limit t)
  3877. (progn
  3878. (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
  3879. (add-text-properties (match-beginning 0) (match-end 0)
  3880. (list 'mouse-face 'highlight
  3881. 'keymap org-mouse-map
  3882. 'help-echo "Radio target link"
  3883. 'org-linked-text t))
  3884. (org-rear-nonsticky-at (match-end 0))
  3885. t)))))
  3886. (defun org-update-radio-target-regexp ()
  3887. "Find all radio targets in this file and update the regular expression."
  3888. (interactive)
  3889. (when (memq 'radio org-activate-links)
  3890. (setq org-target-link-regexp
  3891. (org-make-target-link-regexp (org-all-targets 'radio)))
  3892. (org-restart-font-lock)))
  3893. (defun org-hide-wide-columns (limit)
  3894. (let (s e)
  3895. (setq s (text-property-any (point) (or limit (point-max))
  3896. 'org-cwidth t))
  3897. (when s
  3898. (setq e (next-single-property-change s 'org-cwidth))
  3899. (add-text-properties s e (org-maybe-intangible '(invisible org-cwidth)))
  3900. (goto-char e)
  3901. t)))
  3902. (defvar org-latex-and-specials-regexp nil
  3903. "Regular expression for highlighting export special stuff.")
  3904. (defvar org-match-substring-regexp)
  3905. (defvar org-match-substring-with-braces-regexp)
  3906. (defvar org-export-html-special-string-regexps)
  3907. (defun org-compute-latex-and-specials-regexp ()
  3908. "Compute regular expression for stuff treated specially by exporters."
  3909. (if (not org-highlight-latex-fragments-and-specials)
  3910. (org-set-local 'org-latex-and-specials-regexp nil)
  3911. (require 'org-exp)
  3912. (let*
  3913. ((matchers (plist-get org-format-latex-options :matchers))
  3914. (latexs (delq nil (mapcar (lambda (x) (if (member (car x) matchers) x))
  3915. org-latex-regexps)))
  3916. (options (org-combine-plists (org-default-export-plist)
  3917. (org-infile-export-plist)))
  3918. (org-export-with-sub-superscripts (plist-get options :sub-superscript))
  3919. (org-export-with-LaTeX-fragments (plist-get options :LaTeX-fragments))
  3920. (org-export-with-TeX-macros (plist-get options :TeX-macros))
  3921. (org-export-html-expand (plist-get options :expand-quoted-html))
  3922. (org-export-with-special-strings (plist-get options :special-strings))
  3923. (re-sub
  3924. (cond
  3925. ((equal org-export-with-sub-superscripts '{})
  3926. (list org-match-substring-with-braces-regexp))
  3927. (org-export-with-sub-superscripts
  3928. (list org-match-substring-regexp))
  3929. (t nil)))
  3930. (re-latex
  3931. (if org-export-with-LaTeX-fragments
  3932. (mapcar (lambda (x) (nth 1 x)) latexs)))
  3933. (re-macros
  3934. (if org-export-with-TeX-macros
  3935. (list (concat "\\\\"
  3936. (regexp-opt
  3937. (append (mapcar 'car org-html-entities)
  3938. (if (boundp 'org-latex-entities)
  3939. (mapcar (lambda (x)
  3940. (or (car-safe x) x))
  3941. org-latex-entities)
  3942. nil))
  3943. 'words))) ; FIXME
  3944. ))
  3945. ;; (list "\\\\\\(?:[a-zA-Z]+\\)")))
  3946. (re-special (if org-export-with-special-strings
  3947. (mapcar (lambda (x) (car x))
  3948. org-export-html-special-string-regexps)))
  3949. (re-rest
  3950. (delq nil
  3951. (list
  3952. (if org-export-html-expand "@<[^>\n]+>")
  3953. ))))
  3954. (org-set-local
  3955. 'org-latex-and-specials-regexp
  3956. (mapconcat 'identity (append re-latex re-sub re-macros re-special
  3957. re-rest) "\\|")))))
  3958. (defun org-do-latex-and-special-faces (limit)
  3959. "Run through the buffer and add overlays to links."
  3960. (when org-latex-and-specials-regexp
  3961. (let (rtn d)
  3962. (while (and (not rtn) (re-search-forward org-latex-and-specials-regexp
  3963. limit t))
  3964. (if (not (memq (car-safe (get-text-property (1+ (match-beginning 0))
  3965. 'face))
  3966. '(org-code org-verbatim underline)))
  3967. (progn
  3968. (setq rtn t
  3969. d (cond ((member (char-after (1+ (match-beginning 0)))
  3970. '(?_ ?^)) 1)
  3971. (t 0)))
  3972. (font-lock-prepend-text-property
  3973. (+ d (match-beginning 0)) (match-end 0)
  3974. 'face 'org-latex-and-export-specials)
  3975. (add-text-properties (+ d (match-beginning 0)) (match-end 0)
  3976. '(font-lock-multiline t)))))
  3977. rtn)))
  3978. (defun org-restart-font-lock ()
  3979. "Restart font-lock-mode, to force refontification."
  3980. (when (and (boundp 'font-lock-mode) font-lock-mode)
  3981. (font-lock-mode -1)
  3982. (font-lock-mode 1)))
  3983. (defun org-all-targets (&optional radio)
  3984. "Return a list of all targets in this file.
  3985. With optional argument RADIO, only find radio targets."
  3986. (let ((re (if radio org-radio-target-regexp org-target-regexp))
  3987. rtn)
  3988. (save-excursion
  3989. (goto-char (point-min))
  3990. (while (re-search-forward re nil t)
  3991. (add-to-list 'rtn (downcase (org-match-string-no-properties 1))))
  3992. rtn)))
  3993. (defun org-make-target-link-regexp (targets)
  3994. "Make regular expression matching all strings in TARGETS.
  3995. The regular expression finds the targets also if there is a line break
  3996. between words."
  3997. (and targets
  3998. (concat
  3999. "\\<\\("
  4000. (mapconcat
  4001. (lambda (x)
  4002. (while (string-match " +" x)
  4003. (setq x (replace-match "\\s-+" t t x)))
  4004. x)
  4005. targets
  4006. "\\|")
  4007. "\\)\\>")))
  4008. (defun org-activate-tags (limit)
  4009. (if (re-search-forward (org-re "^\\*+.*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \r\n]") limit t)
  4010. (progn
  4011. (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
  4012. (add-text-properties (match-beginning 1) (match-end 1)
  4013. (list 'mouse-face 'highlight
  4014. 'keymap org-mouse-map))
  4015. (org-rear-nonsticky-at (match-end 1))
  4016. t)))
  4017. (defun org-outline-level ()
  4018. (save-excursion
  4019. (looking-at outline-regexp)
  4020. (if (match-beginning 1)
  4021. (+ (org-get-string-indentation (match-string 1)) 1000)
  4022. (1- (- (match-end 0) (match-beginning 0))))))
  4023. (defvar org-font-lock-keywords nil)
  4024. (defconst org-property-re (org-re "^[ \t]*\\(:\\([-[:alnum:]_]+\\):\\)[ \t]*\\([^ \t\r\n].*\\)")
  4025. "Regular expression matching a property line.")
  4026. (defvar org-font-lock-hook nil
  4027. "Functions to be called for special font lock stuff.")
  4028. (defun org-font-lock-hook (limit)
  4029. (run-hook-with-args 'org-font-lock-hook limit))
  4030. (defun org-set-font-lock-defaults ()
  4031. (let* ((em org-fontify-emphasized-text)
  4032. (lk org-activate-links)
  4033. (org-font-lock-extra-keywords
  4034. (list
  4035. ;; Call the hook
  4036. '(org-font-lock-hook)
  4037. ;; Headlines
  4038. `(,(if org-fontify-whole-heading-line
  4039. "^\\(\\**\\)\\(\\* \\)\\(.*\xa\\)"
  4040. "^\\(\\**\\)\\(\\* \\)\\(.*\\)")
  4041. (1 (org-get-level-face 1))
  4042. (2 (org-get-level-face 2))
  4043. (3 (org-get-level-face 3)))
  4044. ;; Table lines
  4045. '("^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)"
  4046. (1 'org-table t))
  4047. ;; Table internals
  4048. '("^[ \t]*|\\(?:.*?|\\)? *\\(:?=[^|\n]*\\)" (1 'org-formula t))
  4049. '("^[ \t]*| *\\([#*]\\) *|" (1 'org-formula t))
  4050. '("^[ \t]*|\\( *\\([$!_^/]\\) *|.*\\)|" (1 'org-formula t))
  4051. '("| *\\(<[lr]?[0-9]*>\\)" (1 'org-formula t))
  4052. ;; Drawers
  4053. (list org-drawer-regexp '(0 'org-special-keyword t))
  4054. (list "^[ \t]*:END:" '(0 'org-special-keyword t))
  4055. ;; Properties
  4056. (list org-property-re
  4057. '(1 'org-special-keyword t)
  4058. '(3 'org-property-value t))
  4059. ;; Links
  4060. (if (memq 'tag lk) '(org-activate-tags (1 'org-tag prepend)))
  4061. (if (memq 'angle lk) '(org-activate-angle-links (0 'org-link t)))
  4062. (if (memq 'plain lk) '(org-activate-plain-links (0 'org-link t)))
  4063. (if (memq 'bracket lk) '(org-activate-bracket-links (0 'org-link t)))
  4064. (if (memq 'radio lk) '(org-activate-target-links (0 'org-link t)))
  4065. (if (memq 'date lk) '(org-activate-dates (0 'org-date t)))
  4066. (if (memq 'footnote lk) '(org-activate-footnote-links
  4067. (2 'org-footnote t)))
  4068. '("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org-sexp-date t))
  4069. '(org-hide-wide-columns (0 nil append))
  4070. ;; TODO lines
  4071. (list (concat "^\\*+[ \t]+" org-todo-regexp "\\([ \t]\\|$\\)")
  4072. '(1 (org-get-todo-face 1) t))
  4073. ;; DONE
  4074. (if org-fontify-done-headline
  4075. (list (concat "^[*]+ +\\<\\("
  4076. (mapconcat 'regexp-quote org-done-keywords "\\|")
  4077. "\\)\\(.*\\)")
  4078. '(2 'org-headline-done t))
  4079. nil)
  4080. ;; Priorities
  4081. '(org-font-lock-add-priority-faces)
  4082. ;; Tags
  4083. '(org-font-lock-add-tag-faces)
  4084. ;; Special keywords
  4085. (list (concat "\\<" org-deadline-string) '(0 'org-special-keyword t))
  4086. (list (concat "\\<" org-scheduled-string) '(0 'org-special-keyword t))
  4087. (list (concat "\\<" org-closed-string) '(0 'org-special-keyword t))
  4088. (list (concat "\\<" org-clock-string) '(0 'org-special-keyword t))
  4089. ;; Emphasis
  4090. (if em
  4091. (if (featurep 'xemacs)
  4092. '(org-do-emphasis-faces (0 nil append))
  4093. '(org-do-emphasis-faces)))
  4094. ;; Checkboxes
  4095. '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(\\[[- X]\\]\\)"
  4096. 2 'org-checkbox prepend)
  4097. (if org-provide-checkbox-statistics
  4098. '("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
  4099. (0 (org-get-checkbox-statistics-face) t)))
  4100. ;; Description list items
  4101. '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(.*? ::\\)"
  4102. 2 'bold prepend)
  4103. (list (concat "^\\*+ \\(.*:" org-archive-tag ":.*\\)")
  4104. '(1 'org-archived prepend))
  4105. ;; Specials
  4106. '(org-do-latex-and-special-faces)
  4107. ;; Code
  4108. '(org-activate-code (1 'org-code t))
  4109. ;; COMMENT
  4110. (list (concat "^\\*+[ \t]+\\<\\(" org-comment-string
  4111. "\\|" org-quote-string "\\)\\>")
  4112. '(1 'org-special-keyword t))
  4113. '("^#.*" (0 'font-lock-comment-face t))
  4114. ;; Blocks and meta lines
  4115. '(org-fontify-meta-lines-and-blocks)
  4116. )))
  4117. (setq org-font-lock-extra-keywords (delq nil org-font-lock-extra-keywords))
  4118. ;; Now set the full font-lock-keywords
  4119. (org-set-local 'org-font-lock-keywords org-font-lock-extra-keywords)
  4120. (org-set-local 'font-lock-defaults
  4121. '(org-font-lock-keywords t nil nil backward-paragraph))
  4122. (kill-local-variable 'font-lock-keywords) nil))
  4123. (defun org-fontify-like-in-org-mode (s &optional odd-levels)
  4124. "Fontify string S like in Org-mode"
  4125. (with-temp-buffer
  4126. (insert s)
  4127. (let ((org-odd-levels-only odd-levels))
  4128. (org-mode)
  4129. (font-lock-fontify-buffer)
  4130. (buffer-string))))
  4131. (defvar org-m nil)
  4132. (defvar org-l nil)
  4133. (defvar org-f nil)
  4134. (defun org-get-level-face (n)
  4135. "Get the right face for match N in font-lock matching of headlines."
  4136. (setq org-l (- (match-end 2) (match-beginning 1) 1))
  4137. (if org-odd-levels-only (setq org-l (1+ (/ org-l 2))))
  4138. (setq org-f (nth (% (1- org-l) org-n-level-faces) org-level-faces))
  4139. (cond
  4140. ((eq n 1) (if org-hide-leading-stars 'org-hide org-f))
  4141. ((eq n 2) org-f)
  4142. (t (if org-level-color-stars-only nil org-f))))
  4143. (defun org-get-todo-face (kwd)
  4144. "Get the right face for a TODO keyword KWD.
  4145. If KWD is a number, get the corresponding match group."
  4146. (if (numberp kwd) (setq kwd (match-string kwd)))
  4147. (or (cdr (assoc kwd org-todo-keyword-faces))
  4148. (and (member kwd org-done-keywords) 'org-done)
  4149. 'org-todo))
  4150. (defun org-font-lock-add-tag-faces (limit)
  4151. "Add the special tag faces."
  4152. (when (and org-tag-faces org-tags-special-faces-re)
  4153. (while (re-search-forward org-tags-special-faces-re limit t)
  4154. (add-text-properties (match-beginning 1) (match-end 1)
  4155. (list 'face (org-get-tag-face 1)
  4156. 'font-lock-fontified t))
  4157. (backward-char 1))))
  4158. (defun org-font-lock-add-priority-faces (limit)
  4159. "Add the special priority faces."
  4160. (while (re-search-forward "\\[#\\([A-Z0-9]\\)\\]" limit t)
  4161. (add-text-properties
  4162. (match-beginning 0) (match-end 0)
  4163. (list 'face (or (cdr (assoc (char-after (match-beginning 1))
  4164. org-priority-faces))
  4165. 'org-special-keyword)
  4166. 'font-lock-fontified t))))
  4167. (defun org-get-tag-face (kwd)
  4168. "Get the right face for a TODO keyword KWD.
  4169. If KWD is a number, get the corresponding match group."
  4170. (if (numberp kwd) (setq kwd (match-string kwd)))
  4171. (or (cdr (assoc kwd org-tag-faces))
  4172. 'org-tag))
  4173. (defun org-unfontify-region (beg end &optional maybe_loudly)
  4174. "Remove fontification and activation overlays from links."
  4175. (font-lock-default-unfontify-region beg end)
  4176. (let* ((buffer-undo-list t)
  4177. (inhibit-read-only t) (inhibit-point-motion-hooks t)
  4178. (inhibit-modification-hooks t)
  4179. deactivate-mark buffer-file-name buffer-file-truename)
  4180. (remove-text-properties beg end
  4181. '(mouse-face t keymap t org-linked-text t
  4182. invisible t intangible t
  4183. org-no-flyspell t))))
  4184. ;;;; Visibility cycling, including org-goto and indirect buffer
  4185. ;;; Cycling
  4186. (defvar org-cycle-global-status nil)
  4187. (make-variable-buffer-local 'org-cycle-global-status)
  4188. (defvar org-cycle-subtree-status nil)
  4189. (make-variable-buffer-local 'org-cycle-subtree-status)
  4190. ;;;###autoload
  4191. (defvar org-inlinetask-min-level)
  4192. (defun org-cycle (&optional arg)
  4193. "TAB-action and visibility cycling for Org-mode.
  4194. This is the command invoked in Org-moe by the TAB key. It's main purpose
  4195. is outine visibility cycling, but it also invokes other actions
  4196. in special contexts.
  4197. - When this function is called with a prefix argument, rotate the entire
  4198. buffer through 3 states (global cycling)
  4199. 1. OVERVIEW: Show only top-level headlines.
  4200. 2. CONTENTS: Show all headlines of all levels, but no body text.
  4201. 3. SHOW ALL: Show everything.
  4202. When called with two `C-u C-u' prefixes, switch to the startup visibility,
  4203. determined by the variable `org-startup-folded', and by any VISIBILITY
  4204. properties in the buffer.
  4205. When called with three `C-u C-u C-u' prefixed, show the entire buffer,
  4206. including any drawers.
  4207. - When inside a table, re-align the table and move to the next field.
  4208. - When point is at the beginning of a headline, rotate the subtree started
  4209. by this line through 3 different states (local cycling)
  4210. 1. FOLDED: Only the main headline is shown.
  4211. 2. CHILDREN: The main headline and the direct children are shown.
  4212. From this state, you can move to one of the children
  4213. and zoom in further.
  4214. 3. SUBTREE: Show the entire subtree, including body text.
  4215. - When there is a numeric prefix, go up to a heading with level ARG, do
  4216. a `show-subtree' and return to the previous cursor position. If ARG
  4217. is negative, go up that many levels.
  4218. - When point is not at the beginning of a headline, execute the global
  4219. binding for TAB, which is re-indenting the line. See the option
  4220. `org-cycle-emulate-tab' for details.
  4221. - Special case: if point is at the beginning of the buffer and there is
  4222. no headline in line 1, this function will act as if called with prefix arg.
  4223. But only if also the variable `org-cycle-global-at-bob' is t."
  4224. (interactive "P")
  4225. (org-load-modules-maybe)
  4226. (unless (run-hook-with-args-until-success 'org-tab-first-hook)
  4227. (let* ((limit-level
  4228. (or org-cycle-max-level
  4229. (and (boundp 'org-inlinetask-min-level)
  4230. org-inlinetask-min-level
  4231. (1- org-inlinetask-min-level))))
  4232. (nstars (and limit-level
  4233. (if org-odd-levels-only
  4234. (and limit-level (1- (* limit-level 2)))
  4235. limit-level)))
  4236. (outline-regexp
  4237. (cond
  4238. ((not (org-mode-p)) outline-regexp)
  4239. ((or (eq org-cycle-include-plain-lists 'integrate)
  4240. (and org-cycle-include-plain-lists (org-at-item-p)))
  4241. (concat "\\(?:\\*"
  4242. (if nstars (format "\\{1,%d\\}" nstars) "+")
  4243. " \\|\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) \\)"))
  4244. (t (concat "\\*" (if nstars (format "\\{1,%d\\} " nstars) "+ ")))))
  4245. (bob-special (and org-cycle-global-at-bob (bobp)
  4246. (not (looking-at outline-regexp))))
  4247. (org-cycle-hook
  4248. (if bob-special
  4249. (delq 'org-optimize-window-after-visibility-change
  4250. (copy-sequence org-cycle-hook))
  4251. org-cycle-hook))
  4252. (pos (point)))
  4253. (if (or bob-special (equal arg '(4)))
  4254. ;; special case: use global cycling
  4255. (setq arg t))
  4256. (cond
  4257. ((equal arg '(16))
  4258. (org-set-startup-visibility)
  4259. (message "Startup visibility, plus VISIBILITY properties"))
  4260. ((equal arg '(64))
  4261. (show-all)
  4262. (message "Entire buffer visible, including drawers"))
  4263. ((org-at-table-p 'any)
  4264. ;; Enter the table or move to the next field in the table
  4265. (or (org-table-recognize-table.el)
  4266. (progn
  4267. (if arg (org-table-edit-field t)
  4268. (org-table-justify-field-maybe)
  4269. (call-interactively 'org-table-next-field)))))
  4270. ((run-hook-with-args-until-success
  4271. 'org-tab-after-check-for-table-hook))
  4272. ((eq arg t) ;; Global cycling
  4273. (org-cycle-internal-global))
  4274. ((and org-drawers org-drawer-regexp
  4275. (save-excursion
  4276. (beginning-of-line 1)
  4277. (looking-at org-drawer-regexp)))
  4278. ;; Toggle block visibility
  4279. (org-flag-drawer
  4280. (not (get-char-property (match-end 0) 'invisible))))
  4281. ((integerp arg)
  4282. ;; Show-subtree, ARG levels up from here.
  4283. (save-excursion
  4284. (org-back-to-heading)
  4285. (outline-up-heading (if (< arg 0) (- arg)
  4286. (- (funcall outline-level) arg)))
  4287. (org-show-subtree)))
  4288. ((and (save-excursion (beginning-of-line 1) (looking-at outline-regexp))
  4289. (or (bolp) (not (eq org-cycle-emulate-tab 'exc-hl-bol))))
  4290. (org-cycle-internal-local))
  4291. ;; TAB emulation and template completion
  4292. (buffer-read-only (org-back-to-heading))
  4293. ((run-hook-with-args-until-success
  4294. 'org-tab-after-check-for-cycling-hook))
  4295. ((org-try-structure-completion))
  4296. ((org-try-cdlatex-tab))
  4297. ((and (eq org-cycle-emulate-tab 'exc-hl-bol)
  4298. (or (not (bolp))
  4299. (not (looking-at outline-regexp))))
  4300. (call-interactively (global-key-binding "\t")))
  4301. ((if (and (memq org-cycle-emulate-tab '(white whitestart))
  4302. (save-excursion (beginning-of-line 1) (looking-at "[ \t]*"))
  4303. (or (and (eq org-cycle-emulate-tab 'white)
  4304. (= (match-end 0) (point-at-eol)))
  4305. (and (eq org-cycle-emulate-tab 'whitestart)
  4306. (>= (match-end 0) pos))))
  4307. t
  4308. (eq org-cycle-emulate-tab t))
  4309. (call-interactively (global-key-binding "\t")))
  4310. (t (save-excursion
  4311. (org-back-to-heading)
  4312. (org-cycle)))))))
  4313. (defun org-cycle-internal-global ()
  4314. "Do the global cycling action."
  4315. (cond
  4316. ((and (eq last-command this-command)
  4317. (eq org-cycle-global-status 'overview))
  4318. ;; We just created the overview - now do table of contents
  4319. ;; This can be slow in very large buffers, so indicate action
  4320. (run-hook-with-args 'org-pre-cycle-hook 'contents)
  4321. (message "CONTENTS...")
  4322. (org-content)
  4323. (message "CONTENTS...done")
  4324. (setq org-cycle-global-status 'contents)
  4325. (run-hook-with-args 'org-cycle-hook 'contents))
  4326. ((and (eq last-command this-command)
  4327. (eq org-cycle-global-status 'contents))
  4328. ;; We just showed the table of contents - now show everything
  4329. (run-hook-with-args 'org-pre-cycle-hook 'all)
  4330. (show-all)
  4331. (message "SHOW ALL")
  4332. (setq org-cycle-global-status 'all)
  4333. (run-hook-with-args 'org-cycle-hook 'all))
  4334. (t
  4335. ;; Default action: go to overview
  4336. (run-hook-with-args 'org-pre-cycle-hook 'overview)
  4337. (org-overview)
  4338. (message "OVERVIEW")
  4339. (setq org-cycle-global-status 'overview)
  4340. (run-hook-with-args 'org-cycle-hook 'overview))))
  4341. (defun org-cycle-internal-local ()
  4342. "Do the local cycling action."
  4343. (org-back-to-heading)
  4344. (let ((goal-column 0) eoh eol eos)
  4345. ;; First, some boundaries
  4346. (save-excursion
  4347. (org-back-to-heading)
  4348. (save-excursion
  4349. (beginning-of-line 2)
  4350. (while (and (not (eobp)) ;; this is like `next-line'
  4351. (get-char-property (1- (point)) 'invisible))
  4352. (beginning-of-line 2)) (setq eol (point)))
  4353. (outline-end-of-heading) (setq eoh (point))
  4354. (org-end-of-subtree t)
  4355. (unless (eobp)
  4356. (skip-chars-forward " \t\n")
  4357. (beginning-of-line 1) ; in case this is an item
  4358. )
  4359. (setq eos (1- (point))))
  4360. ;; Find out what to do next and set `this-command'
  4361. (cond
  4362. ((= eos eoh)
  4363. ;; Nothing is hidden behind this heading
  4364. (run-hook-with-args 'org-pre-cycle-hook 'empty)
  4365. (message "EMPTY ENTRY")
  4366. (setq org-cycle-subtree-status nil)
  4367. (save-excursion
  4368. (goto-char eos)
  4369. (outline-next-heading)
  4370. (if (org-invisible-p) (org-flag-heading nil))))
  4371. ((or (>= eol eos)
  4372. (not (string-match "\\S-" (buffer-substring eol eos))))
  4373. ;; Entire subtree is hidden in one line: open it
  4374. (run-hook-with-args 'org-pre-cycle-hook 'children)
  4375. (org-show-entry)
  4376. (show-children)
  4377. (message "CHILDREN")
  4378. (save-excursion
  4379. (goto-char eos)
  4380. (outline-next-heading)
  4381. (if (org-invisible-p) (org-flag-heading nil)))
  4382. (setq org-cycle-subtree-status 'children)
  4383. (run-hook-with-args 'org-cycle-hook 'children))
  4384. ((and (eq last-command this-command)
  4385. (eq org-cycle-subtree-status 'children))
  4386. ;; We just showed the children, now show everything.
  4387. (run-hook-with-args 'org-pre-cycle-hook 'subtree)
  4388. (org-show-subtree)
  4389. (message "SUBTREE")
  4390. (setq org-cycle-subtree-status 'subtree)
  4391. (run-hook-with-args 'org-cycle-hook 'subtree))
  4392. (t
  4393. ;; Default action: hide the subtree.
  4394. (run-hook-with-args 'org-pre-cycle-hook 'folded)
  4395. (hide-subtree)
  4396. (message "FOLDED")
  4397. (setq org-cycle-subtree-status 'folded)
  4398. (run-hook-with-args 'org-cycle-hook 'folded)))))
  4399. ;;;###autoload
  4400. (defun org-global-cycle (&optional arg)
  4401. "Cycle the global visibility. For details see `org-cycle'.
  4402. With C-u prefix arg, switch to startup visibility.
  4403. With a numeric prefix, show all headlines up to that level."
  4404. (interactive "P")
  4405. (let ((org-cycle-include-plain-lists
  4406. (if (org-mode-p) org-cycle-include-plain-lists nil)))
  4407. (cond
  4408. ((integerp arg)
  4409. (show-all)
  4410. (hide-sublevels arg)
  4411. (setq org-cycle-global-status 'contents))
  4412. ((equal arg '(4))
  4413. (org-set-startup-visibility)
  4414. (message "Startup visibility, plus VISIBILITY properties."))
  4415. (t
  4416. (org-cycle '(4))))))
  4417. (defun org-set-startup-visibility ()
  4418. "Set the visibility required by startup options and properties."
  4419. (cond
  4420. ((eq org-startup-folded t)
  4421. (org-cycle '(4)))
  4422. ((eq org-startup-folded 'content)
  4423. (let ((this-command 'org-cycle) (last-command 'org-cycle))
  4424. (org-cycle '(4)) (org-cycle '(4)))))
  4425. (if org-hide-block-startup (org-hide-block-all))
  4426. (org-set-visibility-according-to-property 'no-cleanup)
  4427. (org-cycle-hide-archived-subtrees 'all)
  4428. (org-cycle-hide-drawers 'all)
  4429. (org-cycle-show-empty-lines 'all))
  4430. (defun org-set-visibility-according-to-property (&optional no-cleanup)
  4431. "Switch subtree visibilities according to :VISIBILITY: property."
  4432. (interactive)
  4433. (let (org-show-entry-below state)
  4434. (save-excursion
  4435. (goto-char (point-min))
  4436. (while (re-search-forward
  4437. "^[ \t]*:VISIBILITY:[ \t]+\\([a-z]+\\)"
  4438. nil t)
  4439. (setq state (match-string 1))
  4440. (save-excursion
  4441. (org-back-to-heading t)
  4442. (hide-subtree)
  4443. (org-reveal)
  4444. (cond
  4445. ((equal state '("fold" "folded"))
  4446. (hide-subtree))
  4447. ((equal state "children")
  4448. (org-show-hidden-entry)
  4449. (show-children))
  4450. ((equal state "content")
  4451. (save-excursion
  4452. (save-restriction
  4453. (org-narrow-to-subtree)
  4454. (org-content))))
  4455. ((member state '("all" "showall"))
  4456. (show-subtree)))))
  4457. (unless no-cleanup
  4458. (org-cycle-hide-archived-subtrees 'all)
  4459. (org-cycle-hide-drawers 'all)
  4460. (org-cycle-show-empty-lines 'all)))))
  4461. (defun org-overview ()
  4462. "Switch to overview mode, showing only top-level headlines.
  4463. Really, this shows all headlines with level equal or greater than the level
  4464. of the first headline in the buffer. This is important, because if the
  4465. first headline is not level one, then (hide-sublevels 1) gives confusing
  4466. results."
  4467. (interactive)
  4468. (let ((level (save-excursion
  4469. (goto-char (point-min))
  4470. (if (re-search-forward (concat "^" outline-regexp) nil t)
  4471. (progn
  4472. (goto-char (match-beginning 0))
  4473. (funcall outline-level))))))
  4474. (and level (hide-sublevels level))))
  4475. (defun org-content (&optional arg)
  4476. "Show all headlines in the buffer, like a table of contents.
  4477. With numerical argument N, show content up to level N."
  4478. (interactive "P")
  4479. (save-excursion
  4480. ;; Visit all headings and show their offspring
  4481. (and (integerp arg) (org-overview))
  4482. (goto-char (point-max))
  4483. (catch 'exit
  4484. (while (and (progn (condition-case nil
  4485. (outline-previous-visible-heading 1)
  4486. (error (goto-char (point-min))))
  4487. t)
  4488. (looking-at outline-regexp))
  4489. (if (integerp arg)
  4490. (show-children (1- arg))
  4491. (show-branches))
  4492. (if (bobp) (throw 'exit nil))))))
  4493. (defun org-optimize-window-after-visibility-change (state)
  4494. "Adjust the window after a change in outline visibility.
  4495. This function is the default value of the hook `org-cycle-hook'."
  4496. (when (get-buffer-window (current-buffer))
  4497. (cond
  4498. ((eq state 'content) nil)
  4499. ((eq state 'all) nil)
  4500. ((eq state 'folded) nil)
  4501. ((eq state 'children) (or (org-subtree-end-visible-p) (recenter 1)))
  4502. ((eq state 'subtree) (or (org-subtree-end-visible-p) (recenter 1))))))
  4503. (defun org-compact-display-after-subtree-move ()
  4504. "Show a compacter version of the tree of the entry's parent."
  4505. (save-excursion
  4506. (if (org-up-heading-safe)
  4507. (progn
  4508. (hide-subtree)
  4509. (show-entry)
  4510. (show-children)
  4511. (org-cycle-show-empty-lines 'children)
  4512. (org-cycle-hide-drawers 'children))
  4513. (org-overview))))
  4514. (defun org-cycle-show-empty-lines (state)
  4515. "Show empty lines above all visible headlines.
  4516. The region to be covered depends on STATE when called through
  4517. `org-cycle-hook'. Lisp program can use t for STATE to get the
  4518. entire buffer covered. Note that an empty line is only shown if there
  4519. are at least `org-cycle-separator-lines' empty lines before the headline."
  4520. (when (> org-cycle-separator-lines 0)
  4521. (save-excursion
  4522. (let* ((n org-cycle-separator-lines)
  4523. (re (cond
  4524. ((= n 1) "\\(\n[ \t]*\n\\*+\\) ")
  4525. ((= n 2) "^[ \t]*\\(\n[ \t]*\n\\*+\\) ")
  4526. (t (let ((ns (number-to-string (- n 2))))
  4527. (concat "^\\(?:[ \t]*\n\\)\\{" ns "," ns "\\}"
  4528. "[ \t]*\\(\n[ \t]*\n\\*+\\) ")))))
  4529. beg end)
  4530. (cond
  4531. ((memq state '(overview contents t))
  4532. (setq beg (point-min) end (point-max)))
  4533. ((memq state '(children folded))
  4534. (setq beg (point) end (progn (org-end-of-subtree t t)
  4535. (beginning-of-line 2)
  4536. (point)))))
  4537. (when beg
  4538. (goto-char beg)
  4539. (while (re-search-forward re end t)
  4540. (if (not (get-char-property (match-end 1) 'invisible))
  4541. (outline-flag-region
  4542. (match-beginning 1) (match-end 1) nil)))))))
  4543. ;; Never hide empty lines at the end of the file.
  4544. (save-excursion
  4545. (goto-char (point-max))
  4546. (outline-previous-heading)
  4547. (outline-end-of-heading)
  4548. (if (and (looking-at "[ \t\n]+")
  4549. (= (match-end 0) (point-max)))
  4550. (outline-flag-region (point) (match-end 0) nil))))
  4551. (defun org-show-empty-lines-in-parent ()
  4552. "Move to the parent and re-show empty lines before visible headlines."
  4553. (save-excursion
  4554. (let ((context (if (org-up-heading-safe) 'children 'overview)))
  4555. (org-cycle-show-empty-lines context))))
  4556. (defun org-cycle-hide-drawers (state)
  4557. "Re-hide all drawers after a visibility state change."
  4558. (when (and (org-mode-p)
  4559. (not (memq state '(overview folded))))
  4560. (save-excursion
  4561. (let* ((globalp (memq state '(contents all)))
  4562. (beg (if globalp (point-min) (point)))
  4563. (end (if globalp (point-max) (org-end-of-subtree t))))
  4564. (goto-char beg)
  4565. (while (re-search-forward org-drawer-regexp end t)
  4566. (org-flag-drawer t))))))
  4567. (defun org-flag-drawer (flag)
  4568. (save-excursion
  4569. (beginning-of-line 1)
  4570. (when (looking-at "^[ \t]*:[a-zA-Z][a-zA-Z0-9]*:")
  4571. (let ((b (match-end 0))
  4572. (outline-regexp org-outline-regexp))
  4573. (if (re-search-forward
  4574. "^[ \t]*:END:"
  4575. (save-excursion (outline-next-heading) (point)) t)
  4576. (outline-flag-region b (point-at-eol) flag)
  4577. (error ":END: line missing"))))))
  4578. (defun org-subtree-end-visible-p ()
  4579. "Is the end of the current subtree visible?"
  4580. (pos-visible-in-window-p
  4581. (save-excursion (org-end-of-subtree t) (point))))
  4582. (defun org-first-headline-recenter (&optional N)
  4583. "Move cursor to the first headline and recenter the headline.
  4584. Optional argument N means, put the headline into the Nth line of the window."
  4585. (goto-char (point-min))
  4586. (when (re-search-forward (concat "^\\(" outline-regexp "\\)") nil t)
  4587. (beginning-of-line)
  4588. (recenter (prefix-numeric-value N))))
  4589. ;;; Folding of blocks
  4590. (defconst org-block-regexp
  4591. "^[ \t]*#\\+begin_\\([^ \n]+\\)\\(\\([^\n]+\\)\\)?\n\\([^\000]+?\\)#\\+end_\\1[ \t]*$"
  4592. "Regular expression for hiding blocks.")
  4593. (defvar org-hide-block-overlays nil
  4594. "Overays hiding blocks.")
  4595. (make-variable-buffer-local 'org-hide-block-overlays)
  4596. (defun org-block-map (function &optional start end)
  4597. "Call func at the head of all source blocks in the current
  4598. buffer. Optional arguments START and END can be used to limit
  4599. the range."
  4600. (let ((start (or start (point-min)))
  4601. (end (or end (point-max))))
  4602. (save-excursion
  4603. (goto-char start)
  4604. (while (and (< (point) end) (re-search-forward org-block-regexp end t))
  4605. (save-excursion
  4606. (save-match-data
  4607. (goto-char (match-beginning 0))
  4608. (funcall function)))))))
  4609. (defun org-hide-block-toggle-all ()
  4610. "Toggle the visibility of all blocks in the current buffer."
  4611. (org-block-map #'org-hide-block-toggle))
  4612. (defun org-hide-block-all ()
  4613. "Fold all blocks in the current buffer."
  4614. (interactive)
  4615. (org-show-block-all)
  4616. (org-block-map #'org-hide-block-toggle-maybe))
  4617. (defun org-show-block-all ()
  4618. "Unfold all blocks in the current buffer."
  4619. (mapc 'org-delete-overlay org-hide-block-overlays)
  4620. (setq org-hide-block-overlays nil))
  4621. (defun org-hide-block-toggle-maybe ()
  4622. "Toggle visibility of block at point."
  4623. (interactive)
  4624. (let ((case-fold-search t))
  4625. (if (save-excursion
  4626. (beginning-of-line 1)
  4627. (looking-at org-block-regexp))
  4628. (progn (org-hide-block-toggle)
  4629. t) ;; to signal that we took action
  4630. nil))) ;; to signal that we did not
  4631. (defun org-hide-block-toggle (&optional force)
  4632. "Toggle the visibility of the current block."
  4633. (interactive)
  4634. (save-excursion
  4635. (beginning-of-line)
  4636. (if (re-search-forward org-block-regexp nil t)
  4637. (let ((start (- (match-beginning 4) 1)) ;; beginning of body
  4638. (end (match-end 0))
  4639. ov) ;; end of entire body
  4640. (if (memq t (mapcar (lambda (overlay)
  4641. (eq (org-overlay-get overlay 'invisible)
  4642. 'org-hide-block))
  4643. (org-overlays-at start)))
  4644. (if (or (not force) (eq force 'off))
  4645. (mapc (lambda (ov)
  4646. (when (member ov org-hide-block-overlays)
  4647. (setq org-hide-block-overlays
  4648. (delq ov org-hide-block-overlays)))
  4649. (when (eq (org-overlay-get ov 'invisible)
  4650. 'org-hide-block)
  4651. (org-delete-overlay ov)))
  4652. (org-overlays-at start)))
  4653. (setq ov (org-make-overlay start end))
  4654. (org-overlay-put ov 'invisible 'org-hide-block)
  4655. (push ov org-hide-block-overlays)))
  4656. (error "Not looking at a source block"))))
  4657. ;; org-tab-after-check-for-cycling-hook
  4658. (add-hook 'org-tab-first-hook 'org-hide-block-toggle-maybe)
  4659. ;; Remove overlays when changing major mode
  4660. (add-hook 'org-mode-hook
  4661. (lambda () (org-add-hook 'change-major-mode-hook
  4662. 'org-show-block-all 'append 'local)))
  4663. ;;; Org-goto
  4664. (defvar org-goto-window-configuration nil)
  4665. (defvar org-goto-marker nil)
  4666. (defvar org-goto-map
  4667. (let ((map (make-sparse-keymap)))
  4668. (let ((cmds '(isearch-forward isearch-backward kill-ring-save set-mark-command mouse-drag-region universal-argument org-occur)) cmd)
  4669. (while (setq cmd (pop cmds))
  4670. (substitute-key-definition cmd cmd map global-map)))
  4671. (suppress-keymap map)
  4672. (org-defkey map "\C-m" 'org-goto-ret)
  4673. (org-defkey map [(return)] 'org-goto-ret)
  4674. (org-defkey map [(left)] 'org-goto-left)
  4675. (org-defkey map [(right)] 'org-goto-right)
  4676. (org-defkey map [(control ?g)] 'org-goto-quit)
  4677. (org-defkey map "\C-i" 'org-cycle)
  4678. (org-defkey map [(tab)] 'org-cycle)
  4679. (org-defkey map [(down)] 'outline-next-visible-heading)
  4680. (org-defkey map [(up)] 'outline-previous-visible-heading)
  4681. (if org-goto-auto-isearch
  4682. (if (fboundp 'define-key-after)
  4683. (define-key-after map [t] 'org-goto-local-auto-isearch)
  4684. nil)
  4685. (org-defkey map "q" 'org-goto-quit)
  4686. (org-defkey map "n" 'outline-next-visible-heading)
  4687. (org-defkey map "p" 'outline-previous-visible-heading)
  4688. (org-defkey map "f" 'outline-forward-same-level)
  4689. (org-defkey map "b" 'outline-backward-same-level)
  4690. (org-defkey map "u" 'outline-up-heading))
  4691. (org-defkey map "/" 'org-occur)
  4692. (org-defkey map "\C-c\C-n" 'outline-next-visible-heading)
  4693. (org-defkey map "\C-c\C-p" 'outline-previous-visible-heading)
  4694. (org-defkey map "\C-c\C-f" 'outline-forward-same-level)
  4695. (org-defkey map "\C-c\C-b" 'outline-backward-same-level)
  4696. (org-defkey map "\C-c\C-u" 'outline-up-heading)
  4697. map))
  4698. (defconst org-goto-help
  4699. "Browse buffer copy, to find location or copy text. Just type for auto-isearch.
  4700. RET=jump to location [Q]uit and return to previous location
  4701. \[Up]/[Down]=next/prev headline TAB=cycle visibility [/] org-occur")
  4702. (defvar org-goto-start-pos) ; dynamically scoped parameter
  4703. ;; FIXME: Docstring doe not mention both interfaces
  4704. (defun org-goto (&optional alternative-interface)
  4705. "Look up a different location in the current file, keeping current visibility.
  4706. When you want look-up or go to a different location in a document, the
  4707. fastest way is often to fold the entire buffer and then dive into the tree.
  4708. This method has the disadvantage, that the previous location will be folded,
  4709. which may not be what you want.
  4710. This command works around this by showing a copy of the current buffer
  4711. in an indirect buffer, in overview mode. You can dive into the tree in
  4712. that copy, use org-occur and incremental search to find a location.
  4713. When pressing RET or `Q', the command returns to the original buffer in
  4714. which the visibility is still unchanged. After RET is will also jump to
  4715. the location selected in the indirect buffer and expose the
  4716. the headline hierarchy above."
  4717. (interactive "P")
  4718. (let* ((org-refile-targets `((nil . (:maxlevel . ,org-goto-max-level))))
  4719. (org-refile-use-outline-path t)
  4720. (org-refile-target-verify-function nil)
  4721. (interface
  4722. (if (not alternative-interface)
  4723. org-goto-interface
  4724. (if (eq org-goto-interface 'outline)
  4725. 'outline-path-completion
  4726. 'outline)))
  4727. (org-goto-start-pos (point))
  4728. (selected-point
  4729. (if (eq interface 'outline)
  4730. (car (org-get-location (current-buffer) org-goto-help))
  4731. (nth 3 (org-refile-get-location "Goto: ")))))
  4732. (if selected-point
  4733. (progn
  4734. (org-mark-ring-push org-goto-start-pos)
  4735. (goto-char selected-point)
  4736. (if (or (org-invisible-p) (org-invisible-p2))
  4737. (org-show-context 'org-goto)))
  4738. (message "Quit"))))
  4739. (defvar org-goto-selected-point nil) ; dynamically scoped parameter
  4740. (defvar org-goto-exit-command nil) ; dynamically scoped parameter
  4741. (defvar org-goto-local-auto-isearch-map) ; defined below
  4742. (defun org-get-location (buf help)
  4743. "Let the user select a location in the Org-mode buffer BUF.
  4744. This function uses a recursive edit. It returns the selected position
  4745. or nil."
  4746. (let ((isearch-mode-map org-goto-local-auto-isearch-map)
  4747. (isearch-hide-immediately nil)
  4748. (isearch-search-fun-function
  4749. (lambda () 'org-goto-local-search-headings))
  4750. (org-goto-selected-point org-goto-exit-command))
  4751. (save-excursion
  4752. (save-window-excursion
  4753. (delete-other-windows)
  4754. (and (get-buffer "*org-goto*") (kill-buffer "*org-goto*"))
  4755. (switch-to-buffer
  4756. (condition-case nil
  4757. (make-indirect-buffer (current-buffer) "*org-goto*")
  4758. (error (make-indirect-buffer (current-buffer) "*org-goto*"))))
  4759. (with-output-to-temp-buffer "*Help*"
  4760. (princ help))
  4761. (org-fit-window-to-buffer (get-buffer-window "*Help*"))
  4762. (setq buffer-read-only nil)
  4763. (let ((org-startup-truncated t)
  4764. (org-startup-folded nil)
  4765. (org-startup-align-all-tables nil))
  4766. (org-mode)
  4767. (org-overview))
  4768. (setq buffer-read-only t)
  4769. (if (and (boundp 'org-goto-start-pos)
  4770. (integer-or-marker-p org-goto-start-pos))
  4771. (let ((org-show-hierarchy-above t)
  4772. (org-show-siblings t)
  4773. (org-show-following-heading t))
  4774. (goto-char org-goto-start-pos)
  4775. (and (org-invisible-p) (org-show-context)))
  4776. (goto-char (point-min)))
  4777. (let (org-special-ctrl-a/e) (org-beginning-of-line))
  4778. (message "Select location and press RET")
  4779. (use-local-map org-goto-map)
  4780. (recursive-edit)
  4781. ))
  4782. (kill-buffer "*org-goto*")
  4783. (cons org-goto-selected-point org-goto-exit-command)))
  4784. (defvar org-goto-local-auto-isearch-map (make-sparse-keymap))
  4785. (set-keymap-parent org-goto-local-auto-isearch-map isearch-mode-map)
  4786. (define-key org-goto-local-auto-isearch-map "\C-i" 'isearch-other-control-char)
  4787. (define-key org-goto-local-auto-isearch-map "\C-m" 'isearch-other-control-char)
  4788. (defun org-goto-local-search-headings (string bound noerror)
  4789. "Search and make sure that any matches are in headlines."
  4790. (catch 'return
  4791. (while (if isearch-forward
  4792. (search-forward string bound noerror)
  4793. (search-backward string bound noerror))
  4794. (when (let ((context (mapcar 'car (save-match-data (org-context)))))
  4795. (and (member :headline context)
  4796. (not (member :tags context))))
  4797. (throw 'return (point))))))
  4798. (defun org-goto-local-auto-isearch ()
  4799. "Start isearch."
  4800. (interactive)
  4801. (goto-char (point-min))
  4802. (let ((keys (this-command-keys)))
  4803. (when (eq (lookup-key isearch-mode-map keys) 'isearch-printing-char)
  4804. (isearch-mode t)
  4805. (isearch-process-search-char (string-to-char keys)))))
  4806. (defun org-goto-ret (&optional arg)
  4807. "Finish `org-goto' by going to the new location."
  4808. (interactive "P")
  4809. (setq org-goto-selected-point (point)
  4810. org-goto-exit-command 'return)
  4811. (throw 'exit nil))
  4812. (defun org-goto-left ()
  4813. "Finish `org-goto' by going to the new location."
  4814. (interactive)
  4815. (if (org-on-heading-p)
  4816. (progn
  4817. (beginning-of-line 1)
  4818. (setq org-goto-selected-point (point)
  4819. org-goto-exit-command 'left)
  4820. (throw 'exit nil))
  4821. (error "Not on a heading")))
  4822. (defun org-goto-right ()
  4823. "Finish `org-goto' by going to the new location."
  4824. (interactive)
  4825. (if (org-on-heading-p)
  4826. (progn
  4827. (setq org-goto-selected-point (point)
  4828. org-goto-exit-command 'right)
  4829. (throw 'exit nil))
  4830. (error "Not on a heading")))
  4831. (defun org-goto-quit ()
  4832. "Finish `org-goto' without cursor motion."
  4833. (interactive)
  4834. (setq org-goto-selected-point nil)
  4835. (setq org-goto-exit-command 'quit)
  4836. (throw 'exit nil))
  4837. ;;; Indirect buffer display of subtrees
  4838. (defvar org-indirect-dedicated-frame nil
  4839. "This is the frame being used for indirect tree display.")
  4840. (defvar org-last-indirect-buffer nil)
  4841. (defun org-tree-to-indirect-buffer (&optional arg)
  4842. "Create indirect buffer and narrow it to current subtree.
  4843. With numerical prefix ARG, go up to this level and then take that tree.
  4844. If ARG is negative, go up that many levels.
  4845. If `org-indirect-buffer-display' is not `new-frame', the command removes the
  4846. indirect buffer previously made with this command, to avoid proliferation of
  4847. indirect buffers. However, when you call the command with a `C-u' prefix, or
  4848. when `org-indirect-buffer-display' is `new-frame', the last buffer
  4849. is kept so that you can work with several indirect buffers at the same time.
  4850. If `org-indirect-buffer-display' is `dedicated-frame', the C-u prefix also
  4851. requests that a new frame be made for the new buffer, so that the dedicated
  4852. frame is not changed."
  4853. (interactive "P")
  4854. (let ((cbuf (current-buffer))
  4855. (cwin (selected-window))
  4856. (pos (point))
  4857. beg end level heading ibuf)
  4858. (save-excursion
  4859. (org-back-to-heading t)
  4860. (when (numberp arg)
  4861. (setq level (org-outline-level))
  4862. (if (< arg 0) (setq arg (+ level arg)))
  4863. (while (> (setq level (org-outline-level)) arg)
  4864. (outline-up-heading 1 t)))
  4865. (setq beg (point)
  4866. heading (org-get-heading))
  4867. (org-end-of-subtree t) (setq end (point)))
  4868. (if (and (buffer-live-p org-last-indirect-buffer)
  4869. (not (eq org-indirect-buffer-display 'new-frame))
  4870. (not arg))
  4871. (kill-buffer org-last-indirect-buffer))
  4872. (setq ibuf (org-get-indirect-buffer cbuf)
  4873. org-last-indirect-buffer ibuf)
  4874. (cond
  4875. ((or (eq org-indirect-buffer-display 'new-frame)
  4876. (and arg (eq org-indirect-buffer-display 'dedicated-frame)))
  4877. (select-frame (make-frame))
  4878. (delete-other-windows)
  4879. (switch-to-buffer ibuf)
  4880. (org-set-frame-title heading))
  4881. ((eq org-indirect-buffer-display 'dedicated-frame)
  4882. (raise-frame
  4883. (select-frame (or (and org-indirect-dedicated-frame
  4884. (frame-live-p org-indirect-dedicated-frame)
  4885. org-indirect-dedicated-frame)
  4886. (setq org-indirect-dedicated-frame (make-frame)))))
  4887. (delete-other-windows)
  4888. (switch-to-buffer ibuf)
  4889. (org-set-frame-title (concat "Indirect: " heading)))
  4890. ((eq org-indirect-buffer-display 'current-window)
  4891. (switch-to-buffer ibuf))
  4892. ((eq org-indirect-buffer-display 'other-window)
  4893. (pop-to-buffer ibuf))
  4894. (t (error "Invalid value.")))
  4895. (if (featurep 'xemacs)
  4896. (save-excursion (org-mode) (turn-on-font-lock)))
  4897. (narrow-to-region beg end)
  4898. (show-all)
  4899. (goto-char pos)
  4900. (and (window-live-p cwin) (select-window cwin))))
  4901. (defun org-get-indirect-buffer (&optional buffer)
  4902. (setq buffer (or buffer (current-buffer)))
  4903. (let ((n 1) (base (buffer-name buffer)) bname)
  4904. (while (buffer-live-p
  4905. (get-buffer (setq bname (concat base "-" (number-to-string n)))))
  4906. (setq n (1+ n)))
  4907. (condition-case nil
  4908. (make-indirect-buffer buffer bname 'clone)
  4909. (error (make-indirect-buffer buffer bname)))))
  4910. (defun org-set-frame-title (title)
  4911. "Set the title of the current frame to the string TITLE."
  4912. ;; FIXME: how to name a single frame in XEmacs???
  4913. (unless (featurep 'xemacs)
  4914. (modify-frame-parameters (selected-frame) (list (cons 'name title)))))
  4915. ;;;; Structure editing
  4916. ;;; Inserting headlines
  4917. (defun org-previous-line-empty-p ()
  4918. (save-excursion
  4919. (and (not (bobp))
  4920. (or (beginning-of-line 0) t)
  4921. (save-match-data
  4922. (looking-at "[ \t]*$")))))
  4923. (defun org-insert-heading (&optional force-heading)
  4924. "Insert a new heading or item with same depth at point.
  4925. If point is in a plain list and FORCE-HEADING is nil, create a new list item.
  4926. If point is at the beginning of a headline, insert a sibling before the
  4927. current headline. If point is not at the beginning, do not split the line,
  4928. but create the new headline after the current line."
  4929. (interactive "P")
  4930. (if (= (buffer-size) 0)
  4931. (insert "\n* ")
  4932. (when (or force-heading (not (org-insert-item)))
  4933. (let* ((empty-line-p nil)
  4934. (head (save-excursion
  4935. (condition-case nil
  4936. (progn
  4937. (org-back-to-heading)
  4938. (setq empty-line-p (org-previous-line-empty-p))
  4939. (match-string 0))
  4940. (error "*"))))
  4941. (blank-a (cdr (assq 'heading org-blank-before-new-entry)))
  4942. (blank (if (eq blank-a 'auto) empty-line-p blank-a))
  4943. pos hide-previous previous-pos)
  4944. (cond
  4945. ((and (org-on-heading-p) (bolp)
  4946. (or (bobp)
  4947. (save-excursion (backward-char 1) (not (org-invisible-p)))))
  4948. ;; insert before the current line
  4949. (open-line (if blank 2 1)))
  4950. ((and (bolp)
  4951. (or (bobp)
  4952. (save-excursion
  4953. (backward-char 1) (not (org-invisible-p)))))
  4954. ;; insert right here
  4955. nil)
  4956. (t
  4957. ;; somewhere in the line
  4958. (save-excursion
  4959. (setq previous-pos (point-at-bol))
  4960. (end-of-line)
  4961. (setq hide-previous (org-invisible-p)))
  4962. (and org-insert-heading-respect-content (org-show-subtree))
  4963. (let ((split
  4964. (and (org-get-alist-option org-M-RET-may-split-line 'headline)
  4965. (save-excursion
  4966. (let ((p (point)))
  4967. (goto-char (point-at-bol))
  4968. (and (looking-at org-complex-heading-regexp)
  4969. (> p (match-beginning 4)))))))
  4970. tags pos)
  4971. (cond
  4972. (org-insert-heading-respect-content
  4973. (org-end-of-subtree nil t)
  4974. (or (bolp) (newline))
  4975. (or (org-previous-line-empty-p)
  4976. (and blank (newline)))
  4977. (open-line 1))
  4978. ((org-on-heading-p)
  4979. (when hide-previous
  4980. (show-children)
  4981. (org-show-entry))
  4982. (looking-at ".*?\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
  4983. (setq tags (and (match-end 2) (match-string 2)))
  4984. (and (match-end 1)
  4985. (delete-region (match-beginning 1) (match-end 1)))
  4986. (setq pos (point-at-bol))
  4987. (or split (end-of-line 1))
  4988. (delete-horizontal-space)
  4989. (newline (if blank 2 1))
  4990. (when tags
  4991. (save-excursion
  4992. (goto-char pos)
  4993. (end-of-line 1)
  4994. (insert " " tags)
  4995. (org-set-tags nil 'align))))
  4996. (t
  4997. (or split (end-of-line 1))
  4998. (newline (if blank 2 1)))))))
  4999. (insert head) (just-one-space)
  5000. (setq pos (point))
  5001. (end-of-line 1)
  5002. (unless (= (point) pos) (just-one-space) (backward-delete-char 1))
  5003. (when (and org-insert-heading-respect-content hide-previous)
  5004. (save-excursion
  5005. (goto-char previous-pos)
  5006. (hide-subtree)))
  5007. (run-hooks 'org-insert-heading-hook)))))
  5008. (defun org-get-heading (&optional no-tags)
  5009. "Return the heading of the current entry, without the stars."
  5010. (save-excursion
  5011. (org-back-to-heading t)
  5012. (if (looking-at
  5013. (if no-tags
  5014. (org-re "\\*+[ \t]+\\([^\n\r]*?\\)\\([ \t]+:[[:alnum:]:_@]+:[ \t]*\\)?$")
  5015. "\\*+[ \t]+\\([^\r\n]*\\)"))
  5016. (match-string 1) "")))
  5017. (defun org-heading-components ()
  5018. "Return the components of the current heading.
  5019. This is a list with the following elements:
  5020. - the level as an integer
  5021. - the reduced level, different if `org-odd-levels-only' is set.
  5022. - the TODO keyword, or nil
  5023. - the priority character, like ?A, or nil if no priority is given
  5024. - the headline text itself, or the tags string if no headline text
  5025. - the tags string, or nil."
  5026. (save-excursion
  5027. (org-back-to-heading t)
  5028. (if (looking-at org-complex-heading-regexp)
  5029. (list (length (match-string 1))
  5030. (org-reduced-level (length (match-string 1)))
  5031. (org-match-string-no-properties 2)
  5032. (and (match-end 3) (aref (match-string 3) 2))
  5033. (org-match-string-no-properties 4)
  5034. (org-match-string-no-properties 5)))))
  5035. (defun org-get-entry ()
  5036. "Get the entry text, after heading, entire subtree."
  5037. (save-excursion
  5038. (org-back-to-heading t)
  5039. (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
  5040. (defun org-insert-heading-after-current ()
  5041. "Insert a new heading with same level as current, after current subtree."
  5042. (interactive)
  5043. (org-back-to-heading)
  5044. (org-insert-heading)
  5045. (org-move-subtree-down)
  5046. (end-of-line 1))
  5047. (defun org-insert-heading-respect-content ()
  5048. (interactive)
  5049. (let ((org-insert-heading-respect-content t))
  5050. (org-insert-heading t)))
  5051. (defun org-insert-todo-heading-respect-content (&optional force-state)
  5052. (interactive "P")
  5053. (let ((org-insert-heading-respect-content t))
  5054. (org-insert-todo-heading force-state t)))
  5055. (defun org-insert-todo-heading (arg &optional force-heading)
  5056. "Insert a new heading with the same level and TODO state as current heading.
  5057. If the heading has no TODO state, or if the state is DONE, use the first
  5058. state (TODO by default). Also with prefix arg, force first state."
  5059. (interactive "P")
  5060. (when (or force-heading (not (org-insert-item 'checkbox)))
  5061. (org-insert-heading force-heading)
  5062. (save-excursion
  5063. (org-back-to-heading)
  5064. (outline-previous-heading)
  5065. (looking-at org-todo-line-regexp))
  5066. (let*
  5067. ((new-mark-x
  5068. (if (or arg
  5069. (not (match-beginning 2))
  5070. (member (match-string 2) org-done-keywords))
  5071. (car org-todo-keywords-1)
  5072. (match-string 2)))
  5073. (new-mark
  5074. (or
  5075. (run-hook-with-args-until-success
  5076. 'org-todo-get-default-hook new-mark-x nil)
  5077. new-mark-x)))
  5078. (beginning-of-line 1)
  5079. (and (looking-at "\\*+ ") (goto-char (match-end 0))
  5080. (if org-treat-insert-todo-heading-as-state-change
  5081. (org-todo new-mark)
  5082. (insert new-mark " "))))
  5083. (when org-provide-todo-statistics
  5084. (org-update-parent-todo-statistics))))
  5085. (defun org-insert-subheading (arg)
  5086. "Insert a new subheading and demote it.
  5087. Works for outline headings and for plain lists alike."
  5088. (interactive "P")
  5089. (org-insert-heading arg)
  5090. (cond
  5091. ((org-on-heading-p) (org-do-demote))
  5092. ((org-at-item-p) (org-indent-item 1))))
  5093. (defun org-insert-todo-subheading (arg)
  5094. "Insert a new subheading with TODO keyword or checkbox and demote it.
  5095. Works for outline headings and for plain lists alike."
  5096. (interactive "P")
  5097. (org-insert-todo-heading arg)
  5098. (cond
  5099. ((org-on-heading-p) (org-do-demote))
  5100. ((org-at-item-p) (org-indent-item 1))))
  5101. ;;; Promotion and Demotion
  5102. (defun org-promote-subtree ()
  5103. "Promote the entire subtree.
  5104. See also `org-promote'."
  5105. (interactive)
  5106. (save-excursion
  5107. (org-map-tree 'org-promote))
  5108. (org-fix-position-after-promote))
  5109. (defun org-demote-subtree ()
  5110. "Demote the entire subtree. See `org-demote'.
  5111. See also `org-promote'."
  5112. (interactive)
  5113. (save-excursion
  5114. (org-map-tree 'org-demote))
  5115. (org-fix-position-after-promote))
  5116. (defun org-do-promote ()
  5117. "Promote the current heading higher up the tree.
  5118. If the region is active in `transient-mark-mode', promote all headings
  5119. in the region."
  5120. (interactive)
  5121. (save-excursion
  5122. (if (org-region-active-p)
  5123. (org-map-region 'org-promote (region-beginning) (region-end))
  5124. (org-promote)))
  5125. (org-fix-position-after-promote))
  5126. (defun org-do-demote ()
  5127. "Demote the current heading lower down the tree.
  5128. If the region is active in `transient-mark-mode', demote all headings
  5129. in the region."
  5130. (interactive)
  5131. (save-excursion
  5132. (if (org-region-active-p)
  5133. (org-map-region 'org-demote (region-beginning) (region-end))
  5134. (org-demote)))
  5135. (org-fix-position-after-promote))
  5136. (defun org-fix-position-after-promote ()
  5137. "Make sure that after pro/demotion cursor position is right."
  5138. (let ((pos (point)))
  5139. (when (save-excursion
  5140. (beginning-of-line 1)
  5141. (looking-at org-todo-line-regexp)
  5142. (or (equal pos (match-end 1)) (equal pos (match-end 2))))
  5143. (cond ((eobp) (insert " "))
  5144. ((eolp) (insert " "))
  5145. ((equal (char-after) ?\ ) (forward-char 1))))))
  5146. (defun org-reduced-level (l)
  5147. "Compute the effective level of a heading.
  5148. This takes into account the setting of `org-odd-levels-only'."
  5149. (if org-odd-levels-only (1+ (floor (/ l 2))) l))
  5150. (defun org-get-valid-level (level &optional change)
  5151. "Rectify a level change under the influence of `org-odd-levels-only'
  5152. LEVEL is a current level, CHANGE is by how much the level should be
  5153. modified. Even if CHANGE is nil, LEVEL may be returned modified because
  5154. even level numbers will become the next higher odd number."
  5155. (if org-odd-levels-only
  5156. (cond ((or (not change) (= 0 change)) (1+ (* 2 (/ level 2))))
  5157. ((> change 0) (1+ (* 2 (/ (+ level (* 2 change)) 2))))
  5158. ((< change 0) (max 1 (1+ (* 2 (/ (+ level (* 2 change)) 2))))))
  5159. (max 1 (+ level (or change 0)))))
  5160. (if (boundp 'define-obsolete-function-alias)
  5161. (if (or (featurep 'xemacs) (< emacs-major-version 23))
  5162. (define-obsolete-function-alias 'org-get-legal-level
  5163. 'org-get-valid-level)
  5164. (define-obsolete-function-alias 'org-get-legal-level
  5165. 'org-get-valid-level "23.1")))
  5166. (defun org-promote ()
  5167. "Promote the current heading higher up the tree.
  5168. If the region is active in `transient-mark-mode', promote all headings
  5169. in the region."
  5170. (org-back-to-heading t)
  5171. (let* ((level (save-match-data (funcall outline-level)))
  5172. (up-head (concat (make-string (org-get-valid-level level -1) ?*) " "))
  5173. (diff (abs (- level (length up-head) -1))))
  5174. (if (= level 1) (error "Cannot promote to level 0. UNDO to recover if necessary"))
  5175. (replace-match up-head nil t)
  5176. ;; Fixup tag positioning
  5177. (and org-auto-align-tags (org-set-tags nil t))
  5178. (if org-adapt-indentation (org-fixup-indentation (- diff)))))
  5179. (defun org-demote ()
  5180. "Demote the current heading lower down the tree.
  5181. If the region is active in `transient-mark-mode', demote all headings
  5182. in the region."
  5183. (org-back-to-heading t)
  5184. (let* ((level (save-match-data (funcall outline-level)))
  5185. (down-head (concat (make-string (org-get-valid-level level 1) ?*) " "))
  5186. (diff (abs (- level (length down-head) -1))))
  5187. (replace-match down-head nil t)
  5188. ;; Fixup tag positioning
  5189. (and org-auto-align-tags (org-set-tags nil t))
  5190. (if org-adapt-indentation (org-fixup-indentation diff))))
  5191. (defun org-map-tree (fun)
  5192. "Call FUN for every heading underneath the current one."
  5193. (org-back-to-heading)
  5194. (let ((level (funcall outline-level)))
  5195. (save-excursion
  5196. (funcall fun)
  5197. (while (and (progn
  5198. (outline-next-heading)
  5199. (> (funcall outline-level) level))
  5200. (not (eobp)))
  5201. (funcall fun)))))
  5202. (defun org-map-region (fun beg end)
  5203. "Call FUN for every heading between BEG and END."
  5204. (let ((org-ignore-region t))
  5205. (save-excursion
  5206. (setq end (copy-marker end))
  5207. (goto-char beg)
  5208. (if (and (re-search-forward (concat "^" outline-regexp) nil t)
  5209. (< (point) end))
  5210. (funcall fun))
  5211. (while (and (progn
  5212. (outline-next-heading)
  5213. (< (point) end))
  5214. (not (eobp)))
  5215. (funcall fun)))))
  5216. (defun org-fixup-indentation (diff)
  5217. "Change the indentation in the current entry by DIFF
  5218. However, if any line in the current entry has no indentation, or if it
  5219. would end up with no indentation after the change, nothing at all is done."
  5220. (save-excursion
  5221. (let ((end (save-excursion (outline-next-heading)
  5222. (point-marker)))
  5223. (prohibit (if (> diff 0)
  5224. "^\\S-"
  5225. (concat "^ \\{0," (int-to-string (- diff)) "\\}\\S-")))
  5226. col)
  5227. (unless (save-excursion (end-of-line 1)
  5228. (re-search-forward prohibit end t))
  5229. (while (and (< (point) end)
  5230. (re-search-forward "^[ \t]+" end t))
  5231. (goto-char (match-end 0))
  5232. (setq col (current-column))
  5233. (if (< diff 0) (replace-match ""))
  5234. (org-indent-to-column (+ diff col))))
  5235. (move-marker end nil))))
  5236. (defun org-convert-to-odd-levels ()
  5237. "Convert an org-mode file with all levels allowed to one with odd levels.
  5238. This will leave level 1 alone, convert level 2 to level 3, level 3 to
  5239. level 5 etc."
  5240. (interactive)
  5241. (when (yes-or-no-p "Are you sure you want to globally change levels to odd? ")
  5242. (let ((org-odd-levels-only nil) n)
  5243. (save-excursion
  5244. (goto-char (point-min))
  5245. (while (re-search-forward "^\\*\\*+ " nil t)
  5246. (setq n (- (length (match-string 0)) 2))
  5247. (while (>= (setq n (1- n)) 0)
  5248. (org-demote))
  5249. (end-of-line 1))))))
  5250. (defun org-convert-to-oddeven-levels ()
  5251. "Convert an org-mode file with only odd levels to one with odd and even levels.
  5252. This promotes level 3 to level 2, level 5 to level 3 etc. If the file contains a
  5253. section with an even level, conversion would destroy the structure of the file. An error
  5254. is signaled in this case."
  5255. (interactive)
  5256. (goto-char (point-min))
  5257. ;; First check if there are no even levels
  5258. (when (re-search-forward "^\\(\\*\\*\\)+ " nil t)
  5259. (org-show-context t)
  5260. (error "Not all levels are odd in this file. Conversion not possible."))
  5261. (when (yes-or-no-p "Are you sure you want to globally change levels to odd-even? ")
  5262. (let ((org-odd-levels-only nil) n)
  5263. (save-excursion
  5264. (goto-char (point-min))
  5265. (while (re-search-forward "^\\*\\*+ " nil t)
  5266. (setq n (/ (1- (length (match-string 0))) 2))
  5267. (while (>= (setq n (1- n)) 0)
  5268. (org-promote))
  5269. (end-of-line 1))))))
  5270. (defun org-tr-level (n)
  5271. "Make N odd if required."
  5272. (if org-odd-levels-only (1+ (/ n 2)) n))
  5273. ;;; Vertical tree motion, cutting and pasting of subtrees
  5274. (defun org-move-subtree-up (&optional arg)
  5275. "Move the current subtree up past ARG headlines of the same level."
  5276. (interactive "p")
  5277. (org-move-subtree-down (- (prefix-numeric-value arg))))
  5278. (defun org-move-subtree-down (&optional arg)
  5279. "Move the current subtree down past ARG headlines of the same level."
  5280. (interactive "p")
  5281. (setq arg (prefix-numeric-value arg))
  5282. (let ((movfunc (if (> arg 0) 'outline-get-next-sibling
  5283. 'outline-get-last-sibling))
  5284. (ins-point (make-marker))
  5285. (cnt (abs arg))
  5286. beg beg0 end txt folded ne-beg ne-end ne-ins ins-end)
  5287. ;; Select the tree
  5288. (org-back-to-heading)
  5289. (setq beg0 (point))
  5290. (save-excursion
  5291. (setq ne-beg (org-back-over-empty-lines))
  5292. (setq beg (point)))
  5293. (save-match-data
  5294. (save-excursion (outline-end-of-heading)
  5295. (setq folded (org-invisible-p)))
  5296. (outline-end-of-subtree))
  5297. (outline-next-heading)
  5298. (setq ne-end (org-back-over-empty-lines))
  5299. (setq end (point))
  5300. (goto-char beg0)
  5301. (when (and (> arg 0) (org-first-sibling-p) (< ne-end ne-beg))
  5302. ;; include less whitespace
  5303. (save-excursion
  5304. (goto-char beg)
  5305. (forward-line (- ne-beg ne-end))
  5306. (setq beg (point))))
  5307. ;; Find insertion point, with error handling
  5308. (while (> cnt 0)
  5309. (or (and (funcall movfunc) (looking-at outline-regexp))
  5310. (progn (goto-char beg0)
  5311. (error "Cannot move past superior level or buffer limit")))
  5312. (setq cnt (1- cnt)))
  5313. (if (> arg 0)
  5314. ;; Moving forward - still need to move over subtree
  5315. (progn (org-end-of-subtree t t)
  5316. (save-excursion
  5317. (org-back-over-empty-lines)
  5318. (or (bolp) (newline)))))
  5319. (setq ne-ins (org-back-over-empty-lines))
  5320. (move-marker ins-point (point))
  5321. (setq txt (buffer-substring beg end))
  5322. (org-save-markers-in-region beg end)
  5323. (delete-region beg end)
  5324. (or (= beg (point-min)) (outline-flag-region (1- beg) beg nil))
  5325. (or (bobp) (outline-flag-region (1- (point)) (point) nil))
  5326. (and (not (bolp)) (looking-at "\n") (forward-char 1))
  5327. (let ((bbb (point)))
  5328. (insert-before-markers txt)
  5329. (org-reinstall-markers-in-region bbb)
  5330. (move-marker ins-point bbb))
  5331. (or (bolp) (insert "\n"))
  5332. (setq ins-end (point))
  5333. (goto-char ins-point)
  5334. (org-skip-whitespace)
  5335. (when (and (< arg 0)
  5336. (org-first-sibling-p)
  5337. (> ne-ins ne-beg))
  5338. ;; Move whitespace back to beginning
  5339. (save-excursion
  5340. (goto-char ins-end)
  5341. (let ((kill-whole-line t))
  5342. (kill-line (- ne-ins ne-beg)) (point)))
  5343. (insert (make-string (- ne-ins ne-beg) ?\n)))
  5344. (move-marker ins-point nil)
  5345. (org-compact-display-after-subtree-move)
  5346. (org-show-empty-lines-in-parent)
  5347. (unless folded
  5348. (org-show-entry)
  5349. (show-children)
  5350. (org-cycle-hide-drawers 'children))))
  5351. (defvar org-subtree-clip ""
  5352. "Clipboard for cut and paste of subtrees.
  5353. This is actually only a copy of the kill, because we use the normal kill
  5354. ring. We need it to check if the kill was created by `org-copy-subtree'.")
  5355. (defvar org-subtree-clip-folded nil
  5356. "Was the last copied subtree folded?
  5357. This is used to fold the tree back after pasting.")
  5358. (defun org-cut-subtree (&optional n)
  5359. "Cut the current subtree into the clipboard.
  5360. With prefix arg N, cut this many sequential subtrees.
  5361. This is a short-hand for marking the subtree and then cutting it."
  5362. (interactive "p")
  5363. (org-copy-subtree n 'cut))
  5364. (defun org-copy-subtree (&optional n cut force-store-markers)
  5365. "Cut the current subtree into the clipboard.
  5366. With prefix arg N, cut this many sequential subtrees.
  5367. This is a short-hand for marking the subtree and then copying it.
  5368. If CUT is non-nil, actually cut the subtree.
  5369. If FORCE-STORE-MARKERS is non-nil, store the relative locations
  5370. of some markers in the region, even if CUT is non-nil. This is
  5371. useful if the caller implements cut-and-paste as copy-then-paste-then-cut."
  5372. (interactive "p")
  5373. (let (beg end folded (beg0 (point)))
  5374. (if (interactive-p)
  5375. (org-back-to-heading nil) ; take what looks like a subtree
  5376. (org-back-to-heading t)) ; take what is really there
  5377. (org-back-over-empty-lines)
  5378. (setq beg (point))
  5379. (skip-chars-forward " \t\r\n")
  5380. (save-match-data
  5381. (save-excursion (outline-end-of-heading)
  5382. (setq folded (org-invisible-p)))
  5383. (condition-case nil
  5384. (outline-forward-same-level (1- n))
  5385. (error nil))
  5386. (org-end-of-subtree t t))
  5387. (org-back-over-empty-lines)
  5388. (setq end (point))
  5389. (goto-char beg0)
  5390. (when (> end beg)
  5391. (setq org-subtree-clip-folded folded)
  5392. (when (or cut force-store-markers)
  5393. (org-save-markers-in-region beg end))
  5394. (if cut (kill-region beg end) (copy-region-as-kill beg end))
  5395. (setq org-subtree-clip (current-kill 0))
  5396. (message "%s: Subtree(s) with %d characters"
  5397. (if cut "Cut" "Copied")
  5398. (length org-subtree-clip)))))
  5399. (defun org-paste-subtree (&optional level tree for-yank)
  5400. "Paste the clipboard as a subtree, with modification of headline level.
  5401. The entire subtree is promoted or demoted in order to match a new headline
  5402. level.
  5403. If the cursor is at the beginning of a headline, the same level as
  5404. that headline is used to paste the tree
  5405. If not, the new level is derived from the *visible* headings
  5406. before and after the insertion point, and taken to be the inferior headline
  5407. level of the two. So if the previous visible heading is level 3 and the
  5408. next is level 4 (or vice versa), level 4 will be used for insertion.
  5409. This makes sure that the subtree remains an independent subtree and does
  5410. not swallow low level entries.
  5411. You can also force a different level, either by using a numeric prefix
  5412. argument, or by inserting the heading marker by hand. For example, if the
  5413. cursor is after \"*****\", then the tree will be shifted to level 5.
  5414. If optional TREE is given, use this text instead of the kill ring.
  5415. When FOR-YANK is set, this is called by `org-yank'. In this case, do not
  5416. move back over whitespace before inserting, and move point to the end of
  5417. the inserted text when done."
  5418. (interactive "P")
  5419. (unless (org-kill-is-subtree-p tree)
  5420. (error "%s"
  5421. (substitute-command-keys
  5422. "The kill is not a (set of) tree(s) - please use \\[yank] to yank anyway")))
  5423. (let* ((visp (not (org-invisible-p)))
  5424. (txt (or tree (and kill-ring (current-kill 0))))
  5425. (^re (concat "^\\(" outline-regexp "\\)"))
  5426. (re (concat "\\(" outline-regexp "\\)"))
  5427. (^re_ (concat "\\(\\*+\\)[ \t]*"))
  5428. (old-level (if (string-match ^re txt)
  5429. (- (match-end 0) (match-beginning 0) 1)
  5430. -1))
  5431. (force-level (cond (level (prefix-numeric-value level))
  5432. ((and (looking-at "[ \t]*$")
  5433. (string-match
  5434. ^re_ (buffer-substring
  5435. (point-at-bol) (point))))
  5436. (- (match-end 1) (match-beginning 1)))
  5437. ((and (bolp)
  5438. (looking-at org-outline-regexp))
  5439. (- (match-end 0) (point) 1))
  5440. (t nil)))
  5441. (previous-level (save-excursion
  5442. (condition-case nil
  5443. (progn
  5444. (outline-previous-visible-heading 1)
  5445. (if (looking-at re)
  5446. (- (match-end 0) (match-beginning 0) 1)
  5447. 1))
  5448. (error 1))))
  5449. (next-level (save-excursion
  5450. (condition-case nil
  5451. (progn
  5452. (or (looking-at outline-regexp)
  5453. (outline-next-visible-heading 1))
  5454. (if (looking-at re)
  5455. (- (match-end 0) (match-beginning 0) 1)
  5456. 1))
  5457. (error 1))))
  5458. (new-level (or force-level (max previous-level next-level)))
  5459. (shift (if (or (= old-level -1)
  5460. (= new-level -1)
  5461. (= old-level new-level))
  5462. 0
  5463. (- new-level old-level)))
  5464. (delta (if (> shift 0) -1 1))
  5465. (func (if (> shift 0) 'org-demote 'org-promote))
  5466. (org-odd-levels-only nil)
  5467. beg end newend)
  5468. ;; Remove the forced level indicator
  5469. (if force-level
  5470. (delete-region (point-at-bol) (point)))
  5471. ;; Paste
  5472. (beginning-of-line 1)
  5473. (unless for-yank (org-back-over-empty-lines))
  5474. (setq beg (point))
  5475. (and (fboundp 'org-id-paste-tracker) (org-id-paste-tracker txt))
  5476. (insert-before-markers txt)
  5477. (unless (string-match "\n\\'" txt) (insert "\n"))
  5478. (setq newend (point))
  5479. (org-reinstall-markers-in-region beg)
  5480. (setq end (point))
  5481. (goto-char beg)
  5482. (skip-chars-forward " \t\n\r")
  5483. (setq beg (point))
  5484. (if (and (org-invisible-p) visp)
  5485. (save-excursion (outline-show-heading)))
  5486. ;; Shift if necessary
  5487. (unless (= shift 0)
  5488. (save-restriction
  5489. (narrow-to-region beg end)
  5490. (while (not (= shift 0))
  5491. (org-map-region func (point-min) (point-max))
  5492. (setq shift (+ delta shift)))
  5493. (goto-char (point-min))
  5494. (setq newend (point-max))))
  5495. (when (or (interactive-p) for-yank)
  5496. (message "Clipboard pasted as level %d subtree" new-level))
  5497. (if (and (not for-yank) ; in this case, org-yank will decide about folding
  5498. kill-ring
  5499. (eq org-subtree-clip (current-kill 0))
  5500. org-subtree-clip-folded)
  5501. ;; The tree was folded before it was killed/copied
  5502. (hide-subtree))
  5503. (and for-yank (goto-char newend))))
  5504. (defun org-kill-is-subtree-p (&optional txt)
  5505. "Check if the current kill is an outline subtree, or a set of trees.
  5506. Returns nil if kill does not start with a headline, or if the first
  5507. headline level is not the largest headline level in the tree.
  5508. So this will actually accept several entries of equal levels as well,
  5509. which is OK for `org-paste-subtree'.
  5510. If optional TXT is given, check this string instead of the current kill."
  5511. (let* ((kill (or txt (and kill-ring (current-kill 0)) ""))
  5512. (start-level (and kill
  5513. (string-match (concat "\\`\\([ \t\n\r]*?\n\\)?\\("
  5514. org-outline-regexp "\\)")
  5515. kill)
  5516. (- (match-end 2) (match-beginning 2) 1)))
  5517. (re (concat "^" org-outline-regexp))
  5518. (start (1+ (or (match-beginning 2) -1))))
  5519. (if (not start-level)
  5520. (progn
  5521. nil) ;; does not even start with a heading
  5522. (catch 'exit
  5523. (while (setq start (string-match re kill (1+ start)))
  5524. (when (< (- (match-end 0) (match-beginning 0) 1) start-level)
  5525. (throw 'exit nil)))
  5526. t))))
  5527. (defvar org-markers-to-move nil
  5528. "Markers that should be moved with a cut-and-paste operation.
  5529. Those markers are stored together with their positions relative to
  5530. the start of the region.")
  5531. (defun org-save-markers-in-region (beg end)
  5532. "Check markers in region.
  5533. If these markers are between BEG and END, record their position relative
  5534. to BEG, so that after moving the block of text, we can put the markers back
  5535. into place.
  5536. This function gets called just before an entry or tree gets cut from the
  5537. buffer. After re-insertion, `org-reinstall-markers-in-region' must be
  5538. called immediately, to move the markers with the entries."
  5539. (setq org-markers-to-move nil)
  5540. (when (featurep 'org-clock)
  5541. (org-clock-save-markers-for-cut-and-paste beg end))
  5542. (when (featurep 'org-agenda)
  5543. (org-agenda-save-markers-for-cut-and-paste beg end)))
  5544. (defun org-check-and-save-marker (marker beg end)
  5545. "Check if MARKER is between BEG and END.
  5546. If yes, remember the marker and the distance to BEG."
  5547. (when (and (marker-buffer marker)
  5548. (equal (marker-buffer marker) (current-buffer)))
  5549. (if (and (>= marker beg) (< marker end))
  5550. (push (cons marker (- marker beg)) org-markers-to-move))))
  5551. (defun org-reinstall-markers-in-region (beg)
  5552. "Move all remembered markers to their position relative to BEG."
  5553. (mapc (lambda (x)
  5554. (move-marker (car x) (+ beg (cdr x))))
  5555. org-markers-to-move)
  5556. (setq org-markers-to-move nil))
  5557. (defun org-narrow-to-subtree ()
  5558. "Narrow buffer to the current subtree."
  5559. (interactive)
  5560. (save-excursion
  5561. (save-match-data
  5562. (narrow-to-region
  5563. (progn (org-back-to-heading t) (point))
  5564. (progn (org-end-of-subtree t) (point))))))
  5565. (defun org-clone-subtree-with-time-shift (n &optional shift)
  5566. "Clone the task (subtree) at point N times.
  5567. The clones will be inserted as siblings.
  5568. In interactive use, the user will be prompted for the number of clones
  5569. to be produced, and for a time SHIFT, which may be a repeater as used
  5570. in time stamps, for example `+3d'.
  5571. When a valid repeater is given and the entry contains any time stamps,
  5572. the clones will become a sequence in time, with time stamps in the
  5573. subtree shifted for each clone produced. If SHIFT is nil or the
  5574. empty string, time stamps will be left alone.
  5575. If the original subtree did contain time stamps with a repeater,
  5576. the following will happen:
  5577. - the repeater will be removed in each clone
  5578. - an additional clone will be produced, with the current, unshifted
  5579. date(s) in the entry.
  5580. - the original entry will be placed *after* all the clones, with
  5581. repeater intact.
  5582. - the start days in the repeater in the original entry will be shifted
  5583. to past the last clone.
  5584. I this way you can spell out a number of instances of a repeating task,
  5585. and still retain the repeater to cover future instances of the task."
  5586. (interactive "nNumber of clones to produce: \nsDate shift per clone (e.g. +1w, empty to copy unchanged): ")
  5587. (let (beg end template task
  5588. shift-n shift-what doshift nmin nmax (n-no-remove -1))
  5589. (if (not (and (integerp n) (> n 0)))
  5590. (error "Invalid number of replications %s" n))
  5591. (if (and (setq doshift (and (stringp shift) (string-match "\\S-" shift)))
  5592. (not (string-match "\\`[ \t]*\\+?\\([0-9]+\\)\\([dwmy]\\)[ \t]*\\'"
  5593. shift)))
  5594. (error "Invalid shift specification %s" shift))
  5595. (when doshift
  5596. (setq shift-n (string-to-number (match-string 1 shift))
  5597. shift-what (cdr (assoc (match-string 2 shift)
  5598. '(("d" . day) ("w" . week)
  5599. ("m" . month) ("y" . year))))))
  5600. (if (eq shift-what 'week) (setq shift-n (* 7 shift-n) shift-what 'day))
  5601. (setq nmin 1 nmax n)
  5602. (org-back-to-heading t)
  5603. (setq beg (point))
  5604. (org-end-of-subtree t t)
  5605. (setq end (point))
  5606. (setq template (buffer-substring beg end))
  5607. (when (and doshift
  5608. (string-match "<[^<>\n]+ \\+[0-9]+[dwmy][^<>\n]*>" template))
  5609. (delete-region beg end)
  5610. (setq end beg)
  5611. (setq nmin 0 nmax (1+ nmax) n-no-remove nmax))
  5612. (goto-char end)
  5613. (loop for n from nmin to nmax do
  5614. (if (not doshift)
  5615. (setq task template)
  5616. (with-temp-buffer
  5617. (insert template)
  5618. (org-mode)
  5619. (goto-char (point-min))
  5620. (while (re-search-forward org-ts-regexp-both nil t)
  5621. (org-timestamp-change (* n shift-n) shift-what))
  5622. (unless (= n n-no-remove)
  5623. (goto-char (point-min))
  5624. (while (re-search-forward org-ts-regexp nil t)
  5625. (save-excursion
  5626. (goto-char (match-beginning 0))
  5627. (if (looking-at "<[^<>\n]+\\( +\\+[0-9]+[dwmy]\\)")
  5628. (delete-region (match-beginning 1) (match-end 1))))))
  5629. (setq task (buffer-string))))
  5630. (insert task))
  5631. (goto-char beg)))
  5632. ;;; Outline Sorting
  5633. (defun org-sort (with-case)
  5634. "Call `org-sort-entries-or-items' or `org-table-sort-lines'.
  5635. Optional argument WITH-CASE means sort case-sensitively.
  5636. With a double prefix argument, also remove duplicate entries."
  5637. (interactive "P")
  5638. (if (org-at-table-p)
  5639. (org-call-with-arg 'org-table-sort-lines with-case)
  5640. (org-call-with-arg 'org-sort-entries-or-items with-case)))
  5641. (defun org-sort-remove-invisible (s)
  5642. (remove-text-properties 0 (length s) org-rm-props s)
  5643. (while (string-match org-bracket-link-regexp s)
  5644. (setq s (replace-match (if (match-end 2)
  5645. (match-string 3 s)
  5646. (match-string 1 s)) t t s)))
  5647. s)
  5648. (defvar org-priority-regexp) ; defined later in the file
  5649. (defvar org-after-sorting-entries-or-items-hook nil
  5650. "Hook that is run after a bunch of entries or items have been sorted.
  5651. When children are sorted, the cursor is in the parent line when this
  5652. hook gets called. When a region or a plain list is sorted, the cursor
  5653. will be in the first entry of the sorted region/list.")
  5654. (defun org-sort-entries-or-items
  5655. (&optional with-case sorting-type getkey-func compare-func property)
  5656. "Sort entries on a certain level of an outline tree, or plain list items.
  5657. If there is an active region, the entries in the region are sorted.
  5658. Else, if the cursor is before the first entry, sort the top-level items.
  5659. Else, the children of the entry at point are sorted.
  5660. If the cursor is at the first item in a plain list, the list items will be
  5661. sorted.
  5662. Sorting can be alphabetically, numerically, by date/time as given by
  5663. a time stamp, by a property or by priority.
  5664. The command prompts for the sorting type unless it has been given to the
  5665. function through the SORTING-TYPE argument, which needs to a character,
  5666. \(?n ?N ?a ?A ?t ?T ?s ?S ?d ?D ?p ?P ?r ?R ?f ?F). Here is the
  5667. precise meaning of each character:
  5668. n Numerically, by converting the beginning of the entry/item to a number.
  5669. a Alphabetically, ignoring the TODO keyword and the priority, if any.
  5670. t By date/time, either the first active time stamp in the entry, or, if
  5671. none exist, by the first inactive one.
  5672. In items, only the first line will be chekced.
  5673. s By the scheduled date/time.
  5674. d By deadline date/time.
  5675. c By creation time, which is assumed to be the first inactive time stamp
  5676. at the beginning of a line.
  5677. p By priority according to the cookie.
  5678. r By the value of a property.
  5679. Capital letters will reverse the sort order.
  5680. If the SORTING-TYPE is ?f or ?F, then GETKEY-FUNC specifies a function to be
  5681. called with point at the beginning of the record. It must return either
  5682. a string or a number that should serve as the sorting key for that record.
  5683. Comparing entries ignores case by default. However, with an optional argument
  5684. WITH-CASE, the sorting considers case as well."
  5685. (interactive "P")
  5686. (let ((case-func (if with-case 'identity 'downcase))
  5687. start beg end stars re re2
  5688. txt what tmp plain-list-p)
  5689. ;; Find beginning and end of region to sort
  5690. (cond
  5691. ((org-region-active-p)
  5692. ;; we will sort the region
  5693. (setq end (region-end)
  5694. what "region")
  5695. (goto-char (region-beginning))
  5696. (if (not (org-on-heading-p)) (outline-next-heading))
  5697. (setq start (point)))
  5698. ((org-at-item-p)
  5699. ;; we will sort this plain list
  5700. (org-beginning-of-item-list) (setq start (point))
  5701. (org-end-of-item-list) (setq end (point))
  5702. (goto-char start)
  5703. (setq plain-list-p t
  5704. what "plain list"))
  5705. ((or (org-on-heading-p)
  5706. (condition-case nil (progn (org-back-to-heading) t) (error nil)))
  5707. ;; we will sort the children of the current headline
  5708. (org-back-to-heading)
  5709. (setq start (point)
  5710. end (progn (org-end-of-subtree t t)
  5711. (org-back-over-empty-lines)
  5712. (point))
  5713. what "children")
  5714. (goto-char start)
  5715. (show-subtree)
  5716. (outline-next-heading))
  5717. (t
  5718. ;; we will sort the top-level entries in this file
  5719. (goto-char (point-min))
  5720. (or (org-on-heading-p) (outline-next-heading))
  5721. (setq start (point) end (point-max) what "top-level")
  5722. (goto-char start)
  5723. (show-all)))
  5724. (setq beg (point))
  5725. (if (>= beg end) (error "Nothing to sort"))
  5726. (unless plain-list-p
  5727. (looking-at "\\(\\*+\\)")
  5728. (setq stars (match-string 1)
  5729. re (concat "^" (regexp-quote stars) " +")
  5730. re2 (concat "^" (regexp-quote (substring stars 0 -1)) "[^*]")
  5731. txt (buffer-substring beg end))
  5732. (if (not (equal (substring txt -1) "\n")) (setq txt (concat txt "\n")))
  5733. (if (and (not (equal stars "*")) (string-match re2 txt))
  5734. (error "Region to sort contains a level above the first entry")))
  5735. (unless sorting-type
  5736. (message
  5737. (if plain-list-p
  5738. "Sort %s: [a]lpha [n]umeric [t]ime [f]unc A/N/T/F means reversed:"
  5739. "Sort %s: [a]lpha [n]umeric [p]riority p[r]operty todo[o]rder [f]unc
  5740. [t]ime [s]cheduled [d]eadline [c]reated
  5741. A/N/T/S/D/C/P/O/F means reversed:")
  5742. what)
  5743. (setq sorting-type (read-char-exclusive))
  5744. (and (= (downcase sorting-type) ?f)
  5745. (setq getkey-func
  5746. (org-ido-completing-read "Sort using function: "
  5747. obarray 'fboundp t nil nil))
  5748. (setq getkey-func (intern getkey-func)))
  5749. (and (= (downcase sorting-type) ?r)
  5750. (setq property
  5751. (org-ido-completing-read "Property: "
  5752. (mapcar 'list (org-buffer-property-keys t))
  5753. nil t))))
  5754. (message "Sorting entries...")
  5755. (save-restriction
  5756. (narrow-to-region start end)
  5757. (let ((dcst (downcase sorting-type))
  5758. (case-fold-search nil)
  5759. (now (current-time)))
  5760. (sort-subr
  5761. (/= dcst sorting-type)
  5762. ;; This function moves to the beginning character of the "record" to
  5763. ;; be sorted.
  5764. (if plain-list-p
  5765. (lambda nil
  5766. (if (org-at-item-p) t (goto-char (point-max))))
  5767. (lambda nil
  5768. (if (re-search-forward re nil t)
  5769. (goto-char (match-beginning 0))
  5770. (goto-char (point-max)))))
  5771. ;; This function moves to the last character of the "record" being
  5772. ;; sorted.
  5773. (if plain-list-p
  5774. 'org-end-of-item
  5775. (lambda nil
  5776. (save-match-data
  5777. (condition-case nil
  5778. (outline-forward-same-level 1)
  5779. (error
  5780. (goto-char (point-max)))))))
  5781. ;; This function returns the value that gets sorted against.
  5782. (if plain-list-p
  5783. (lambda nil
  5784. (when (looking-at "[ \t]*[-+*0-9.)]+[ \t]+")
  5785. (cond
  5786. ((= dcst ?n)
  5787. (string-to-number (buffer-substring (match-end 0)
  5788. (point-at-eol))))
  5789. ((= dcst ?a)
  5790. (buffer-substring (match-end 0) (point-at-eol)))
  5791. ((= dcst ?t)
  5792. (if (or (re-search-forward org-ts-regexp (point-at-eol) t)
  5793. (re-search-forward org-ts-regexp-both
  5794. (point-at-eol) t))
  5795. (org-time-string-to-seconds (match-string 0))
  5796. (time-to-seconds now)))
  5797. ((= dcst ?f)
  5798. (if getkey-func
  5799. (progn
  5800. (setq tmp (funcall getkey-func))
  5801. (if (stringp tmp) (setq tmp (funcall case-func tmp)))
  5802. tmp)
  5803. (error "Invalid key function `%s'" getkey-func)))
  5804. (t (error "Invalid sorting type `%c'" sorting-type)))))
  5805. (lambda nil
  5806. (cond
  5807. ((= dcst ?n)
  5808. (if (looking-at org-complex-heading-regexp)
  5809. (string-to-number (match-string 4))
  5810. nil))
  5811. ((= dcst ?a)
  5812. (if (looking-at org-complex-heading-regexp)
  5813. (funcall case-func (match-string 4))
  5814. nil))
  5815. ((= dcst ?t)
  5816. (let ((end (save-excursion (outline-next-heading) (point))))
  5817. (if (or (re-search-forward org-ts-regexp end t)
  5818. (re-search-forward org-ts-regexp-both end t))
  5819. (org-time-string-to-seconds (match-string 0))
  5820. (time-to-seconds now))))
  5821. ((= dcst ?c)
  5822. (let ((end (save-excursion (outline-next-heading) (point))))
  5823. (if (re-search-forward
  5824. (concat "^[ \t]*\\[" org-ts-regexp1 "\\]")
  5825. end t)
  5826. (org-time-string-to-seconds (match-string 0))
  5827. (time-to-seconds now))))
  5828. ((= dcst ?s)
  5829. (let ((end (save-excursion (outline-next-heading) (point))))
  5830. (if (re-search-forward org-scheduled-time-regexp end t)
  5831. (org-time-string-to-seconds (match-string 1))
  5832. (time-to-seconds now))))
  5833. ((= dcst ?d)
  5834. (let ((end (save-excursion (outline-next-heading) (point))))
  5835. (if (re-search-forward org-deadline-time-regexp end t)
  5836. (org-time-string-to-seconds (match-string 1))
  5837. (time-to-seconds now))))
  5838. ((= dcst ?p)
  5839. (if (re-search-forward org-priority-regexp (point-at-eol) t)
  5840. (string-to-char (match-string 2))
  5841. org-default-priority))
  5842. ((= dcst ?r)
  5843. (or (org-entry-get nil property) ""))
  5844. ((= dcst ?o)
  5845. (if (looking-at org-complex-heading-regexp)
  5846. (- 9999 (length (member (match-string 2)
  5847. org-todo-keywords-1)))))
  5848. ((= dcst ?f)
  5849. (if getkey-func
  5850. (progn
  5851. (setq tmp (funcall getkey-func))
  5852. (if (stringp tmp) (setq tmp (funcall case-func tmp)))
  5853. tmp)
  5854. (error "Invalid key function `%s'" getkey-func)))
  5855. (t (error "Invalid sorting type `%c'" sorting-type)))))
  5856. nil
  5857. (cond
  5858. ((= dcst ?a) 'string<)
  5859. ((= dcst ?f) compare-func)
  5860. ((member dcst '(?p ?t ?s ?d ?c)) '<)
  5861. (t nil)))))
  5862. (run-hooks 'org-after-sorting-entries-or-items-hook)
  5863. (message "Sorting entries...done")))
  5864. (defun org-do-sort (table what &optional with-case sorting-type)
  5865. "Sort TABLE of WHAT according to SORTING-TYPE.
  5866. The user will be prompted for the SORTING-TYPE if the call to this
  5867. function does not specify it. WHAT is only for the prompt, to indicate
  5868. what is being sorted. The sorting key will be extracted from
  5869. the car of the elements of the table.
  5870. If WITH-CASE is non-nil, the sorting will be case-sensitive."
  5871. (unless sorting-type
  5872. (message
  5873. "Sort %s: [a]lphabetic. [n]umeric. [t]ime. A/N/T means reversed:"
  5874. what)
  5875. (setq sorting-type (read-char-exclusive)))
  5876. (let ((dcst (downcase sorting-type))
  5877. extractfun comparefun)
  5878. ;; Define the appropriate functions
  5879. (cond
  5880. ((= dcst ?n)
  5881. (setq extractfun 'string-to-number
  5882. comparefun (if (= dcst sorting-type) '< '>)))
  5883. ((= dcst ?a)
  5884. (setq extractfun (if with-case (lambda(x) (org-sort-remove-invisible x))
  5885. (lambda(x) (downcase (org-sort-remove-invisible x))))
  5886. comparefun (if (= dcst sorting-type)
  5887. 'string<
  5888. (lambda (a b) (and (not (string< a b))
  5889. (not (string= a b)))))))
  5890. ((= dcst ?t)
  5891. (setq extractfun
  5892. (lambda (x)
  5893. (if (or (string-match org-ts-regexp x)
  5894. (string-match org-ts-regexp-both x))
  5895. (time-to-seconds
  5896. (org-time-string-to-time (match-string 0 x)))
  5897. 0))
  5898. comparefun (if (= dcst sorting-type) '< '>)))
  5899. (t (error "Invalid sorting type `%c'" sorting-type)))
  5900. (sort (mapcar (lambda (x) (cons (funcall extractfun (car x)) (cdr x)))
  5901. table)
  5902. (lambda (a b) (funcall comparefun (car a) (car b))))))
  5903. ;;; The orgstruct minor mode
  5904. ;; Define a minor mode which can be used in other modes in order to
  5905. ;; integrate the org-mode structure editing commands.
  5906. ;; This is really a hack, because the org-mode structure commands use
  5907. ;; keys which normally belong to the major mode. Here is how it
  5908. ;; works: The minor mode defines all the keys necessary to operate the
  5909. ;; structure commands, but wraps the commands into a function which
  5910. ;; tests if the cursor is currently at a headline or a plain list
  5911. ;; item. If that is the case, the structure command is used,
  5912. ;; temporarily setting many Org-mode variables like regular
  5913. ;; expressions for filling etc. However, when any of those keys is
  5914. ;; used at a different location, function uses `key-binding' to look
  5915. ;; up if the key has an associated command in another currently active
  5916. ;; keymap (minor modes, major mode, global), and executes that
  5917. ;; command. There might be problems if any of the keys is otherwise
  5918. ;; used as a prefix key.
  5919. ;; Another challenge is that the key binding for TAB can be tab or \C-i,
  5920. ;; likewise the binding for RET can be return or \C-m. Orgtbl-mode
  5921. ;; addresses this by checking explicitly for both bindings.
  5922. (defvar orgstruct-mode-map (make-sparse-keymap)
  5923. "Keymap for the minor `orgstruct-mode'.")
  5924. (defvar org-local-vars nil
  5925. "List of local variables, for use by `orgstruct-mode'")
  5926. ;;;###autoload
  5927. (define-minor-mode orgstruct-mode
  5928. "Toggle the minor more `orgstruct-mode'.
  5929. This mode is for using Org-mode structure commands in other modes.
  5930. The following key behave as if Org-mode was active, if the cursor
  5931. is on a headline, or on a plain list item (both in the definition
  5932. of Org-mode).
  5933. M-up Move entry/item up
  5934. M-down Move entry/item down
  5935. M-left Promote
  5936. M-right Demote
  5937. M-S-up Move entry/item up
  5938. M-S-down Move entry/item down
  5939. M-S-left Promote subtree
  5940. M-S-right Demote subtree
  5941. M-q Fill paragraph and items like in Org-mode
  5942. C-c ^ Sort entries
  5943. C-c - Cycle list bullet
  5944. TAB Cycle item visibility
  5945. M-RET Insert new heading/item
  5946. S-M-RET Insert new TODO heading / Checkbox item
  5947. C-c C-c Set tags / toggle checkbox"
  5948. nil " OrgStruct" nil
  5949. (org-load-modules-maybe)
  5950. (and (orgstruct-setup) (defun orgstruct-setup () nil)))
  5951. ;;;###autoload
  5952. (defun turn-on-orgstruct ()
  5953. "Unconditionally turn on `orgstruct-mode'."
  5954. (orgstruct-mode 1))
  5955. (defun orgstruct++-mode (&optional arg)
  5956. "Toggle `orgstruct-mode', the enhanced version of it.
  5957. In addition to setting orgstruct-mode, this also exports all indentation
  5958. and autofilling variables from org-mode into the buffer. It will also
  5959. recognize item context in multiline items.
  5960. Note that turning off orgstruct-mode will *not* remove the
  5961. indentation/paragraph settings. This can only be done by refreshing the
  5962. major mode, for example with \\[normal-mode]."
  5963. (interactive "P")
  5964. (setq arg (prefix-numeric-value (or arg (if orgstruct-mode -1 1))))
  5965. (if (< arg 1)
  5966. (orgstruct-mode -1)
  5967. (orgstruct-mode 1)
  5968. (let (var val)
  5969. (mapc
  5970. (lambda (x)
  5971. (when (string-match
  5972. "^\\(paragraph-\\|auto-fill\\|fill-paragraph\\|adaptive-fill\\|indent-\\)"
  5973. (symbol-name (car x)))
  5974. (setq var (car x) val (nth 1 x))
  5975. (org-set-local var (if (eq (car-safe val) 'quote) (nth 1 val) val))))
  5976. org-local-vars)
  5977. (org-set-local 'orgstruct-is-++ t))))
  5978. (defvar orgstruct-is-++ nil
  5979. "Is orgstruct-mode in ++ version in the current-buffer?")
  5980. (make-variable-buffer-local 'orgstruct-is-++)
  5981. ;;;###autoload
  5982. (defun turn-on-orgstruct++ ()
  5983. "Unconditionally turn on `orgstruct++-mode'."
  5984. (orgstruct++-mode 1))
  5985. (defun orgstruct-error ()
  5986. "Error when there is no default binding for a structure key."
  5987. (interactive)
  5988. (error "This key has no function outside structure elements"))
  5989. (defun orgstruct-setup ()
  5990. "Setup orgstruct keymaps."
  5991. (let ((nfunc 0)
  5992. (bindings
  5993. (list
  5994. '([(meta up)] org-metaup)
  5995. '([(meta down)] org-metadown)
  5996. '([(meta left)] org-metaleft)
  5997. '([(meta right)] org-metaright)
  5998. '([(meta shift up)] org-shiftmetaup)
  5999. '([(meta shift down)] org-shiftmetadown)
  6000. '([(meta shift left)] org-shiftmetaleft)
  6001. '([(meta shift right)] org-shiftmetaright)
  6002. '([?\e (up)] org-metaup)
  6003. '([?\e (down)] org-metadown)
  6004. '([?\e (left)] org-metaleft)
  6005. '([?\e (right)] org-metaright)
  6006. '([?\e (shift up)] org-shiftmetaup)
  6007. '([?\e (shift down)] org-shiftmetadown)
  6008. '([?\e (shift left)] org-shiftmetaleft)
  6009. '([?\e (shift right)] org-shiftmetaright)
  6010. '([(shift up)] org-shiftup)
  6011. '([(shift down)] org-shiftdown)
  6012. '([(shift left)] org-shiftleft)
  6013. '([(shift right)] org-shiftright)
  6014. '("\C-c\C-c" org-ctrl-c-ctrl-c)
  6015. '("\M-q" fill-paragraph)
  6016. '("\C-c^" org-sort)
  6017. '("\C-c-" org-cycle-list-bullet)))
  6018. elt key fun cmd)
  6019. (while (setq elt (pop bindings))
  6020. (setq nfunc (1+ nfunc))
  6021. (setq key (org-key (car elt))
  6022. fun (nth 1 elt)
  6023. cmd (orgstruct-make-binding fun nfunc key))
  6024. (org-defkey orgstruct-mode-map key cmd))
  6025. ;; Special treatment needed for TAB and RET
  6026. (org-defkey orgstruct-mode-map [(tab)]
  6027. (orgstruct-make-binding 'org-cycle 102 [(tab)] "\C-i"))
  6028. (org-defkey orgstruct-mode-map "\C-i"
  6029. (orgstruct-make-binding 'org-cycle 103 "\C-i" [(tab)]))
  6030. (org-defkey orgstruct-mode-map "\M-\C-m"
  6031. (orgstruct-make-binding 'org-insert-heading 105
  6032. "\M-\C-m" [(meta return)]))
  6033. (org-defkey orgstruct-mode-map [(meta return)]
  6034. (orgstruct-make-binding 'org-insert-heading 106
  6035. [(meta return)] "\M-\C-m"))
  6036. (org-defkey orgstruct-mode-map [(shift meta return)]
  6037. (orgstruct-make-binding 'org-insert-todo-heading 107
  6038. [(meta return)] "\M-\C-m"))
  6039. (org-defkey orgstruct-mode-map "\e\C-m"
  6040. (orgstruct-make-binding 'org-insert-heading 108
  6041. "\e\C-m" [?\e (return)]))
  6042. (org-defkey orgstruct-mode-map [?\e (return)]
  6043. (orgstruct-make-binding 'org-insert-heading 109
  6044. [?\e (return)] "\e\C-m"))
  6045. (org-defkey orgstruct-mode-map [?\e (shift return)]
  6046. (orgstruct-make-binding 'org-insert-todo-heading 110
  6047. [?\e (return)] "\e\C-m"))
  6048. (unless org-local-vars
  6049. (setq org-local-vars (org-get-local-variables)))
  6050. t))
  6051. (defun orgstruct-make-binding (fun n &rest keys)
  6052. "Create a function for binding in the structure minor mode.
  6053. FUN is the command to call inside a table. N is used to create a unique
  6054. command name. KEYS are keys that should be checked in for a command
  6055. to execute outside of tables."
  6056. (eval
  6057. (list 'defun
  6058. (intern (concat "orgstruct-hijacker-command-" (int-to-string n)))
  6059. '(arg)
  6060. (concat "In Structure, run `" (symbol-name fun) "'.\n"
  6061. "Outside of structure, run the binding of `"
  6062. (mapconcat (lambda (x) (format "%s" x)) keys "' or `")
  6063. "'.")
  6064. '(interactive "p")
  6065. (list 'if
  6066. `(org-context-p 'headline 'item
  6067. (and orgstruct-is-++
  6068. ,(and (memq fun '(org-insert-heading org-insert-todo-heading)) t)
  6069. 'item-body))
  6070. (list 'org-run-like-in-org-mode (list 'quote fun))
  6071. (list 'let '(orgstruct-mode)
  6072. (list 'call-interactively
  6073. (append '(or)
  6074. (mapcar (lambda (k)
  6075. (list 'key-binding k))
  6076. keys)
  6077. '('orgstruct-error))))))))
  6078. (defun org-context-p (&rest contexts)
  6079. "Check if local context is any of CONTEXTS.
  6080. Possible values in the list of contexts are `table', `headline', and `item'."
  6081. (let ((pos (point)))
  6082. (goto-char (point-at-bol))
  6083. (prog1 (or (and (memq 'table contexts)
  6084. (looking-at "[ \t]*|"))
  6085. (and (memq 'headline contexts)
  6086. ;;????????? (looking-at "\\*+"))
  6087. (looking-at outline-regexp))
  6088. (and (memq 'item contexts)
  6089. (looking-at "[ \t]*\\([-+*] \\|[0-9]+[.)] \\)"))
  6090. (and (memq 'item-body contexts)
  6091. (org-in-item-p)))
  6092. (goto-char pos))))
  6093. (defun org-get-local-variables ()
  6094. "Return a list of all local variables in an org-mode buffer."
  6095. (let (varlist)
  6096. (with-current-buffer (get-buffer-create "*Org tmp*")
  6097. (erase-buffer)
  6098. (org-mode)
  6099. (setq varlist (buffer-local-variables)))
  6100. (kill-buffer "*Org tmp*")
  6101. (delq nil
  6102. (mapcar
  6103. (lambda (x)
  6104. (setq x
  6105. (if (symbolp x)
  6106. (list x)
  6107. (list (car x) (list 'quote (cdr x)))))
  6108. (if (string-match
  6109. "^\\(org-\\|orgtbl-\\|outline-\\|comment-\\|paragraph-\\|auto-fill\\|fill-paragraph\\|adaptive-fill\\|indent-\\)"
  6110. (symbol-name (car x)))
  6111. x nil))
  6112. varlist))))
  6113. ;;;###autoload
  6114. (defun org-run-like-in-org-mode (cmd)
  6115. "Run a command, pretending that the current buffer is in Org-mode.
  6116. This will temporarily bind local variables that are typically bound in
  6117. Org-mode to the values they have in Org-mode, and then interactively
  6118. call CMD."
  6119. (org-load-modules-maybe)
  6120. (unless org-local-vars
  6121. (setq org-local-vars (org-get-local-variables)))
  6122. (eval (list 'let org-local-vars
  6123. (list 'call-interactively (list 'quote cmd)))))
  6124. ;;;; Archiving
  6125. (defun org-get-category (&optional pos)
  6126. "Get the category applying to position POS."
  6127. (get-text-property (or pos (point)) 'org-category))
  6128. (defun org-refresh-category-properties ()
  6129. "Refresh category text properties in the buffer."
  6130. (let ((def-cat (cond
  6131. ((null org-category)
  6132. (if buffer-file-name
  6133. (file-name-sans-extension
  6134. (file-name-nondirectory buffer-file-name))
  6135. "???"))
  6136. ((symbolp org-category) (symbol-name org-category))
  6137. (t org-category)))
  6138. beg end cat pos optionp)
  6139. (org-unmodified
  6140. (save-excursion
  6141. (save-restriction
  6142. (widen)
  6143. (goto-char (point-min))
  6144. (put-text-property (point) (point-max) 'org-category def-cat)
  6145. (while (re-search-forward
  6146. "^\\(#\\+CATEGORY:\\|[ \t]*:CATEGORY:\\)\\(.*\\)" nil t)
  6147. (setq pos (match-end 0)
  6148. optionp (equal (char-after (match-beginning 0)) ?#)
  6149. cat (org-trim (match-string 2)))
  6150. (if optionp
  6151. (setq beg (point-at-bol) end (point-max))
  6152. (org-back-to-heading t)
  6153. (setq beg (point) end (org-end-of-subtree t t)))
  6154. (put-text-property beg end 'org-category cat)
  6155. (goto-char pos)))))))
  6156. ;;;; Link Stuff
  6157. ;;; Link abbreviations
  6158. (defun org-link-expand-abbrev (link)
  6159. "Apply replacements as defined in `org-link-abbrev-alist."
  6160. (if (string-match "^\\([a-zA-Z][-_a-zA-Z0-9]*\\)\\(::?\\(.*\\)\\)?$" link)
  6161. (let* ((key (match-string 1 link))
  6162. (as (or (assoc key org-link-abbrev-alist-local)
  6163. (assoc key org-link-abbrev-alist)))
  6164. (tag (and (match-end 2) (match-string 3 link)))
  6165. rpl)
  6166. (if (not as)
  6167. link