org-agenda.el 314 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  5. ;; Keywords: outlines, hypermedia, calendar, wp
  6. ;; Homepage: http://orgmode.org
  7. ;; Version: 7.4
  8. ;;
  9. ;; This file is part of GNU Emacs.
  10. ;;
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;;; Commentary:
  24. ;; This file contains the code for creating and using the Agenda for Org-mode.
  25. ;;; Code:
  26. (require 'org)
  27. (eval-when-compile
  28. (require 'cl))
  29. (declare-function diary-add-to-list "diary-lib"
  30. (date string specifier &optional marker globcolor literal))
  31. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  32. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  33. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  34. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  35. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  36. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  37. (declare-function calendar-french-date-string "cal-french" (&optional date))
  38. (declare-function calendar-goto-date "cal-move" (date))
  39. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  40. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  41. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  42. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  43. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  44. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  45. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  46. (declare-function org-datetree-find-date-create "org-datetree"
  47. (date &optional keep-restriction))
  48. (declare-function org-columns-quit "org-colview" ())
  49. (declare-function diary-date-display-form "diary-lib" (&optional type))
  50. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  51. (declare-function org-habit-insert-consistency-graphs
  52. "org-habit" (&optional line))
  53. (declare-function org-is-habit-p "org-habit" (&optional pom))
  54. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  55. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  56. (defvar calendar-mode-map)
  57. (defvar org-clock-current-task) ; defined in org-clock.el
  58. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  59. (defvar org-habit-show-habits)
  60. (defvar org-habit-show-habits-only-for-today)
  61. ;; Defined somewhere in this file, but used before definition.
  62. (defvar org-agenda-buffer-name)
  63. (defvar org-agenda-overriding-header)
  64. (defvar org-agenda-title-append nil)
  65. (defvar entry)
  66. (defvar date)
  67. (defvar org-agenda-undo-list)
  68. (defvar org-agenda-pending-undo-list)
  69. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  70. (defcustom org-agenda-confirm-kill 1
  71. "When set, remote killing from the agenda buffer needs confirmation.
  72. When t, a confirmation is always needed. When a number N, confirmation is
  73. only needed when the text to be killed contains more than N non-white lines."
  74. :group 'org-agenda
  75. :type '(choice
  76. (const :tag "Never" nil)
  77. (const :tag "Always" t)
  78. (integer :tag "When more than N lines")))
  79. (defcustom org-agenda-compact-blocks nil
  80. "Non-nil means make the block agenda more compact.
  81. This is done by leaving out unnecessary lines."
  82. :group 'org-agenda
  83. :type 'boolean)
  84. (defcustom org-agenda-block-separator ?=
  85. "The separator between blocks in the agenda.
  86. If this is a string, it will be used as the separator, with a newline added.
  87. If it is a character, it will be repeated to fill the window width."
  88. :group 'org-agenda
  89. :type '(choice
  90. (character)
  91. (string)))
  92. (defgroup org-agenda-export nil
  93. "Options concerning exporting agenda views in Org-mode."
  94. :tag "Org Agenda Export"
  95. :group 'org-agenda)
  96. (defcustom org-agenda-with-colors t
  97. "Non-nil means use colors in agenda views."
  98. :group 'org-agenda-export
  99. :type 'boolean)
  100. (defcustom org-agenda-exporter-settings nil
  101. "Alist of variable/value pairs that should be active during agenda export.
  102. This is a good place to set options for ps-print and for htmlize.
  103. Note that the way this is implemented, the values will be evaluated
  104. before assigned to the variables. So make sure to quote values you do
  105. *not* want evaluated, for example
  106. (setq org-agenda-exporter-settings
  107. '((ps-print-color-p 'black-white)))"
  108. :group 'org-agenda-export
  109. :type '(repeat
  110. (list
  111. (variable)
  112. (sexp :tag "Value"))))
  113. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  114. "Hook run in temporary buffer before writing it to an export file.
  115. A useful function is `org-agenda-add-entry-text'."
  116. :group 'org-agenda-export
  117. :type 'hook
  118. :options '(org-agenda-add-entry-text))
  119. (defcustom org-agenda-add-entry-text-maxlines 0
  120. "Maximum number of entry text lines to be added to agenda.
  121. This is only relevant when `org-agenda-add-entry-text' is part of
  122. `org-agenda-before-write-hook', which it is by default.
  123. When this is 0, nothing will happen. When it is greater than 0, it
  124. specifies the maximum number of lines that will be added for each entry
  125. that is listed in the agenda view.
  126. Note that this variable is not used during display, only when exporting
  127. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  128. and `org-agenda-entry-text-maxlines'."
  129. :group 'org-agenda
  130. :type 'integer)
  131. (defcustom org-agenda-add-entry-text-descriptive-links t
  132. "Non-nil means export org-links as descriptive links in agenda added text.
  133. This variable applies to the text added to the agenda when
  134. `org-agenda-add-entry-text-maxlines' is larger than 0.
  135. When this variable nil, the URL will (also) be shown."
  136. :group 'org-agenda
  137. :type 'boolean)
  138. (defcustom org-agenda-export-html-style ""
  139. "The style specification for exported HTML Agenda files.
  140. If this variable contains a string, it will replace the default <style>
  141. section as produced by `htmlize'.
  142. Since there are different ways of setting style information, this variable
  143. needs to contain the full HTML structure to provide a style, including the
  144. surrounding HTML tags. The style specifications should include definitions
  145. the fonts used by the agenda, here is an example:
  146. <style type=\"text/css\">
  147. p { font-weight: normal; color: gray; }
  148. .org-agenda-structure {
  149. font-size: 110%;
  150. color: #003399;
  151. font-weight: 600;
  152. }
  153. .org-todo {
  154. color: #cc6666;
  155. font-weight: bold;
  156. }
  157. .org-agenda-done {
  158. color: #339933;
  159. }
  160. .org-done {
  161. color: #339933;
  162. }
  163. .title { text-align: center; }
  164. .todo, .deadline { color: red; }
  165. .done { color: green; }
  166. </style>
  167. or, if you want to keep the style in a file,
  168. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  169. As the value of this option simply gets inserted into the HTML <head> header,
  170. you can \"misuse\" it to also add other text to the header. However,
  171. <style>...</style> is required, if not present the variable will be ignored."
  172. :group 'org-agenda-export
  173. :group 'org-export-html
  174. :type 'string)
  175. (defcustom org-agenda-persistent-filter nil
  176. "When set, keep filters from one agenda view to the next."
  177. :group 'org-agenda
  178. :type 'boolean)
  179. (defgroup org-agenda-custom-commands nil
  180. "Options concerning agenda views in Org-mode."
  181. :tag "Org Agenda Custom Commands"
  182. :group 'org-agenda)
  183. (defconst org-sorting-choice
  184. '(choice
  185. (const time-up) (const time-down)
  186. (const category-keep) (const category-up) (const category-down)
  187. (const tag-down) (const tag-up)
  188. (const priority-up) (const priority-down)
  189. (const todo-state-up) (const todo-state-down)
  190. (const effort-up) (const effort-down)
  191. (const habit-up) (const habit-down)
  192. (const alpha-up) (const alpha-down)
  193. (const user-defined-up) (const user-defined-down))
  194. "Sorting choices.")
  195. (defconst org-agenda-custom-commands-local-options
  196. `(repeat :tag "Local settings for this command. Remember to quote values"
  197. (choice :tag "Setting"
  198. (list :tag "Heading for this block"
  199. (const org-agenda-overriding-header)
  200. (string :tag "Headline"))
  201. (list :tag "Files to be searched"
  202. (const org-agenda-files)
  203. (list
  204. (const :format "" quote)
  205. (repeat (file))))
  206. (list :tag "Sorting strategy"
  207. (const org-agenda-sorting-strategy)
  208. (list
  209. (const :format "" quote)
  210. (repeat
  211. ,org-sorting-choice)))
  212. (list :tag "Prefix format"
  213. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  214. (string))
  215. (list :tag "Number of days in agenda"
  216. (const org-agenda-span)
  217. (choice (const :tag "Day" 'day)
  218. (const :tag "Week" 'week)
  219. (const :tag "Month" 'month)
  220. (const :tag "Year" 'year)
  221. (integer :tag "Custom")))
  222. (list :tag "Fixed starting date"
  223. (const org-agenda-start-day)
  224. (string :value "2007-11-01"))
  225. (list :tag "Start on day of week"
  226. (const org-agenda-start-on-weekday)
  227. (choice :value 1
  228. (const :tag "Today" nil)
  229. (integer :tag "Weekday No.")))
  230. (list :tag "Include data from diary"
  231. (const org-agenda-include-diary)
  232. (boolean))
  233. (list :tag "Deadline Warning days"
  234. (const org-deadline-warning-days)
  235. (integer :value 1))
  236. (list :tag "Tags filter preset"
  237. (const org-agenda-filter-preset)
  238. (list
  239. (const :format "" quote)
  240. (repeat
  241. (string :tag "+tag or -tag"))))
  242. (list :tag "Set daily/weekly entry types"
  243. (const org-agenda-entry-types)
  244. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  245. (const :deadline)
  246. (const :scheduled)
  247. (const :timestamp)
  248. (const :sexp)))
  249. (list :tag "Standard skipping condition"
  250. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  251. (const org-agenda-skip-function)
  252. (list
  253. (const :format "" quote)
  254. (list
  255. (choice
  256. :tag "Skipping range"
  257. (const :tag "Skip entry" org-agenda-skip-entry-if)
  258. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  259. (repeat :inline t :tag "Conditions for skipping"
  260. (choice
  261. :tag "Condition type"
  262. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  263. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  264. (list :tag "TODO state is" :inline t
  265. (const 'todo)
  266. (choice
  267. (const :tag "any not-done state" 'todo)
  268. (const :tag "any done state" 'done)
  269. (const :tag "any state" 'any)
  270. (list :tag "Keyword list"
  271. (const :format "" quote)
  272. (repeat (string :tag "Keyword")))))
  273. (list :tag "TODO state is not" :inline t
  274. (const 'nottodo)
  275. (choice
  276. (const :tag "any not-done state" 'todo)
  277. (const :tag "any done state" 'done)
  278. (const :tag "any state" 'any)
  279. (list :tag "Keyword list"
  280. (const :format "" quote)
  281. (repeat (string :tag "Keyword")))))
  282. (const :tag "scheduled" 'scheduled)
  283. (const :tag "not scheduled" 'notscheduled)
  284. (const :tag "deadline" 'deadline)
  285. (const :tag "no deadline" 'notdeadline)
  286. (const :tag "timestamp" 'timestamp)
  287. (const :tag "no timestamp" 'nottimestamp))))))
  288. (list :tag "Non-standard skipping condition"
  289. :value (org-agenda-skip-function)
  290. (const org-agenda-skip-function)
  291. (sexp :tag "Function or form (quoted!)"))
  292. (list :tag "Any variable"
  293. (variable :tag "Variable")
  294. (sexp :tag "Value (sexp)"))))
  295. "Selection of examples for agenda command settings.
  296. This will be spliced into the custom type of
  297. `org-agenda-custom-commands'.")
  298. (defcustom org-agenda-custom-commands nil
  299. "Custom commands for the agenda.
  300. These commands will be offered on the splash screen displayed by the
  301. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  302. (key desc type match settings files)
  303. key The key (one or more characters as a string) to be associated
  304. with the command.
  305. desc A description of the command, when omitted or nil, a default
  306. description is built using MATCH.
  307. type The command type, any of the following symbols:
  308. agenda The daily/weekly agenda.
  309. todo Entries with a specific TODO keyword, in all agenda files.
  310. search Entries containing search words entry or headline.
  311. tags Tags/Property/TODO match in all agenda files.
  312. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  313. todo-tree Sparse tree of specific TODO keyword in *current* file.
  314. tags-tree Sparse tree with all tags matches in *current* file.
  315. occur-tree Occur sparse tree for *current* file.
  316. ... A user-defined function.
  317. match What to search for:
  318. - a single keyword for TODO keyword searches
  319. - a tags match expression for tags searches
  320. - a word search expression for text searches.
  321. - a regular expression for occur searches
  322. For all other commands, this should be the empty string.
  323. settings A list of option settings, similar to that in a let form, so like
  324. this: ((opt1 val1) (opt2 val2) ...). The values will be
  325. evaluated at the moment of execution, so quote them when needed.
  326. files A list of files file to write the produced agenda buffer to
  327. with the command `org-store-agenda-views'.
  328. If a file name ends in \".html\", an HTML version of the buffer
  329. is written out. If it ends in \".ps\", a postscript version is
  330. produced. Otherwise, only the plain text is written to the file.
  331. You can also define a set of commands, to create a composite agenda buffer.
  332. In this case, an entry looks like this:
  333. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  334. where
  335. desc A description string to be displayed in the dispatcher menu.
  336. cmd An agenda command, similar to the above. However, tree commands
  337. are no allowed, but instead you can get agenda and global todo list.
  338. So valid commands for a set are:
  339. (agenda \"\" settings)
  340. (alltodo \"\" settings)
  341. (stuck \"\" settings)
  342. (todo \"match\" settings files)
  343. (search \"match\" settings files)
  344. (tags \"match\" settings files)
  345. (tags-todo \"match\" settings files)
  346. Each command can carry a list of options, and another set of options can be
  347. given for the whole set of commands. Individual command options take
  348. precedence over the general options.
  349. When using several characters as key to a command, the first characters
  350. are prefix commands. For the dispatcher to display useful information, you
  351. should provide a description for the prefix, like
  352. (setq org-agenda-custom-commands
  353. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  354. (\"hl\" tags \"+HOME+Lisa\")
  355. (\"hp\" tags \"+HOME+Peter\")
  356. (\"hk\" tags \"+HOME+Kim\")))"
  357. :group 'org-agenda-custom-commands
  358. :type `(repeat
  359. (choice :value ("x" "Describe command here" tags "" nil)
  360. (list :tag "Single command"
  361. (string :tag "Access Key(s) ")
  362. (option (string :tag "Description"))
  363. (choice
  364. (const :tag "Agenda" agenda)
  365. (const :tag "TODO list" alltodo)
  366. (const :tag "Search words" search)
  367. (const :tag "Stuck projects" stuck)
  368. (const :tag "Tags/Property match (all agenda files)" tags)
  369. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  370. (const :tag "TODO keyword search (all agenda files)" todo)
  371. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  372. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  373. (const :tag "Occur tree (current buffer)" occur-tree)
  374. (sexp :tag "Other, user-defined function"))
  375. (string :tag "Match (only for some commands)")
  376. ,org-agenda-custom-commands-local-options
  377. (option (repeat :tag "Export" (file :tag "Export to"))))
  378. (list :tag "Command series, all agenda files"
  379. (string :tag "Access Key(s)")
  380. (string :tag "Description ")
  381. (repeat :tag "Component"
  382. (choice
  383. (list :tag "Agenda"
  384. (const :format "" agenda)
  385. (const :tag "" :format "" "")
  386. ,org-agenda-custom-commands-local-options)
  387. (list :tag "TODO list (all keywords)"
  388. (const :format "" alltodo)
  389. (const :tag "" :format "" "")
  390. ,org-agenda-custom-commands-local-options)
  391. (list :tag "Search words"
  392. (const :format "" search)
  393. (string :tag "Match")
  394. ,org-agenda-custom-commands-local-options)
  395. (list :tag "Stuck projects"
  396. (const :format "" stuck)
  397. (const :tag "" :format "" "")
  398. ,org-agenda-custom-commands-local-options)
  399. (list :tag "Tags search"
  400. (const :format "" tags)
  401. (string :tag "Match")
  402. ,org-agenda-custom-commands-local-options)
  403. (list :tag "Tags search, TODO entries only"
  404. (const :format "" tags-todo)
  405. (string :tag "Match")
  406. ,org-agenda-custom-commands-local-options)
  407. (list :tag "TODO keyword search"
  408. (const :format "" todo)
  409. (string :tag "Match")
  410. ,org-agenda-custom-commands-local-options)
  411. (list :tag "Other, user-defined function"
  412. (symbol :tag "function")
  413. (string :tag "Match")
  414. ,org-agenda-custom-commands-local-options)))
  415. (repeat :tag "Settings for entire command set"
  416. (list (variable :tag "Any variable")
  417. (sexp :tag "Value")))
  418. (option (repeat :tag "Export" (file :tag "Export to"))))
  419. (cons :tag "Prefix key documentation"
  420. (string :tag "Access Key(s)")
  421. (string :tag "Description ")))))
  422. (defcustom org-agenda-query-register ?o
  423. "The register holding the current query string.
  424. The purpose of this is that if you construct a query string interactively,
  425. you can then use it to define a custom command."
  426. :group 'org-agenda-custom-commands
  427. :type 'character)
  428. (defcustom org-stuck-projects
  429. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  430. "How to identify stuck projects.
  431. This is a list of four items:
  432. 1. A tags/todo/property matcher string that is used to identify a project.
  433. See the manual for a description of tag and property searches.
  434. The entire tree below a headline matched by this is considered one project.
  435. 2. A list of TODO keywords identifying non-stuck projects.
  436. If the project subtree contains any headline with one of these todo
  437. keywords, the project is considered to be not stuck. If you specify
  438. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  439. 3. A list of tags identifying non-stuck projects.
  440. If the project subtree contains any headline with one of these tags,
  441. the project is considered to be not stuck. If you specify \"*\" as
  442. a tag, any tag will mark the project unstuck. Note that this is about
  443. the explicit presence of a tag somewhere in the subtree, inherited
  444. tags to not count here. If inherited tags make a project not stuck,
  445. use \"-TAG\" in the tags part of the matcher under (1.) above.
  446. 4. An arbitrary regular expression matching non-stuck projects.
  447. If the project turns out to be not stuck, search continues also in the
  448. subtree to see if any of the subtasks have project status.
  449. See also the variable `org-tags-match-list-sublevels' which applies
  450. to projects matched by this search as well.
  451. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  452. or `C-c a #' to produce the list."
  453. :group 'org-agenda-custom-commands
  454. :type '(list
  455. (string :tag "Tags/TODO match to identify a project")
  456. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  457. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  458. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  459. (defcustom org-agenda-filter-effort-default-operator "<"
  460. "The default operator for effort estimate filtering.
  461. If you select an effort estimate limit without first pressing an operator,
  462. this one will be used."
  463. :group 'org-agenda-custom-commands
  464. :type '(choice (const :tag "less or equal" "<")
  465. (const :tag "greater or equal"">")
  466. (const :tag "equal" "=")))
  467. (defgroup org-agenda-skip nil
  468. "Options concerning skipping parts of agenda files."
  469. :tag "Org Agenda Skip"
  470. :group 'org-agenda)
  471. (defcustom org-agenda-skip-function-global nil
  472. "Function to be called at each match during agenda construction.
  473. If this function returns nil, the current match should not be skipped.
  474. If the function decided to skip an agenda match, is must return the
  475. buffer position from which the search should be continued.
  476. This may also be a Lisp form, which will be evaluated.
  477. This variable will be applied to every agenda match, including
  478. tags/property searches and TODO lists. So try to make the test function
  479. do its checking as efficiently as possible. To implement a skipping
  480. condition just for specific agenda commands, use the variable
  481. `org-agenda-skip-function' which can be set in the options section
  482. of custom agenda commands."
  483. :group 'org-agenda-skip
  484. :type 'sexp)
  485. (defgroup org-agenda-daily/weekly nil
  486. "Options concerning the daily/weekly agenda."
  487. :tag "Org Agenda Daily/Weekly"
  488. :group 'org-agenda)
  489. (defgroup org-agenda-todo-list nil
  490. "Options concerning the global todo list agenda view."
  491. :tag "Org Agenda Todo List"
  492. :group 'org-agenda)
  493. (defgroup org-agenda-match-view nil
  494. "Options concerning the general tags/property/todo match agenda view."
  495. :tag "Org Agenda Match View"
  496. :group 'org-agenda)
  497. (defgroup org-agenda-search-view nil
  498. "Options concerning the general tags/property/todo match agenda view."
  499. :tag "Org Agenda Match View"
  500. :group 'org-agenda)
  501. (defvar org-agenda-archives-mode nil
  502. "Non-nil means the agenda will include archived items.
  503. If this is the symbol `trees', trees in the selected agenda scope
  504. that are marked with the ARCHIVE tag will be included anyway. When this is
  505. t, also all archive files associated with the current selection of agenda
  506. files will be included.")
  507. (defcustom org-agenda-skip-comment-trees t
  508. "Non-nil means skip trees that start with the COMMENT keyword.
  509. When nil, these trees are also scanned by agenda commands."
  510. :group 'org-agenda-skip
  511. :type 'boolean)
  512. (defcustom org-agenda-todo-list-sublevels t
  513. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  514. When nil, the sublevels of a TODO entry are not checked, resulting in
  515. potentially much shorter TODO lists."
  516. :group 'org-agenda-skip
  517. :group 'org-agenda-todo-list
  518. :type 'boolean)
  519. (defcustom org-agenda-todo-ignore-with-date nil
  520. "Non-nil means don't show entries with a date in the global todo list.
  521. You can use this if you prefer to mark mere appointments with a TODO keyword,
  522. but don't want them to show up in the TODO list.
  523. When this is set, it also covers deadlines and scheduled items, the settings
  524. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  525. will be ignored.
  526. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  527. :group 'org-agenda-skip
  528. :group 'org-agenda-todo-list
  529. :type 'boolean)
  530. (defcustom org-agenda-todo-ignore-timestamp nil
  531. "Non-nil means don't show entries with a timestamp.
  532. This applies when creating the global todo list.
  533. Valid values are:
  534. past Don't show entries for today or in the past.
  535. future Don't show entries with a timestamp in the future.
  536. The idea behind this is that if it has a future
  537. timestamp, you don't want to think about it until the
  538. date.
  539. all Don't show any entries with a timestamp in the global todo list.
  540. The idea behind this is that by setting a timestamp, you
  541. have already \"taken care\" of this item.
  542. This variable can also have an integer as a value. If positive (N),
  543. todos with a timestamp N or more days in the future will be ignored. If
  544. negative (-N), todos with a timestamp N or more days in the past will be
  545. ignored. If 0, todos with a timestamp either today or in the future will
  546. be ignored. For example, a value of -1 will exclude todos with a
  547. timestamp in the past (yesterday or earlier), while a value of 7 will
  548. exclude todos with a timestamp a week or more in the future.
  549. See also `org-agenda-todo-ignore-with-date'.
  550. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  551. to make his option also apply to the tags-todo list."
  552. :group 'org-agenda-skip
  553. :group 'org-agenda-todo-list
  554. :type '(choice
  555. (const :tag "Ignore future timestamp todos" future)
  556. (const :tag "Ignore past or present timestamp todos" past)
  557. (const :tag "Ignore all timestamp todos" all)
  558. (const :tag "Show timestamp todos" nil)
  559. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  560. (defcustom org-agenda-todo-ignore-scheduled nil
  561. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  562. This applies when creating the global todo list.
  563. Valid values are:
  564. past Don't show entries scheduled today or in the past.
  565. future Don't show entries scheduled in the future.
  566. The idea behind this is that by scheduling it, you don't want to
  567. think about it until the scheduled date.
  568. all Don't show any scheduled entries in the global todo list.
  569. The idea behind this is that by scheduling it, you have already
  570. \"taken care\" of this item.
  571. t Same as `all', for backward compatibility.
  572. This variable can also have an integer as a value. See
  573. `org-agenda-todo-ignore-timestamp' for more details.
  574. See also `org-agenda-todo-ignore-with-date'.
  575. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  576. to make his option also apply to the tags-todo list."
  577. :group 'org-agenda-skip
  578. :group 'org-agenda-todo-list
  579. :type '(choice
  580. (const :tag "Ignore future-scheduled todos" future)
  581. (const :tag "Ignore past- or present-scheduled todos" past)
  582. (const :tag "Ignore all scheduled todos" all)
  583. (const :tag "Ignore all scheduled todos (compatibility)" t)
  584. (const :tag "Show scheduled todos" nil)
  585. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  586. (defcustom org-agenda-todo-ignore-deadlines nil
  587. "Non-nil means ignore some deadlined TODO items when making TODO list.
  588. There are different motivations for using different values, please think
  589. carefully when configuring this variable.
  590. This applies when creating the global todo list.
  591. Valid values are:
  592. near Don't show near deadline entries. A deadline is near when it is
  593. closer than `org-deadline-warning-days' days. The idea behind this
  594. is that such items will appear in the agenda anyway.
  595. far Don't show TODO entries where a deadline has been defined, but
  596. the deadline is not near. This is useful if you don't want to
  597. use the todo list to figure out what to do now.
  598. past Don't show entries with a deadline timestamp for today or in the past.
  599. future Don't show entries with a deadline timestamp in the future, not even
  600. when they become `near' ones. Use it with caution.
  601. all Ignore all TODO entries that do have a deadline.
  602. t Same as `near', for backward compatibility.
  603. This variable can also have an integer as a value. See
  604. `org-agenda-todo-ignore-timestamp' for more details.
  605. See also `org-agenda-todo-ignore-with-date'.
  606. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  607. to make his option also apply to the tags-todo list."
  608. :group 'org-agenda-skip
  609. :group 'org-agenda-todo-list
  610. :type '(choice
  611. (const :tag "Ignore near deadlines" near)
  612. (const :tag "Ignore near deadlines (compatibility)" t)
  613. (const :tag "Ignore far deadlines" far)
  614. (const :tag "Ignore all TODOs with a deadlines" all)
  615. (const :tag "Show all TODOs, even if they have a deadline" nil)
  616. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  617. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  618. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  619. The variables
  620. `org-agenda-todo-ignore-with-date',
  621. `org-agenda-todo-ignore-timestamp',
  622. `org-agenda-todo-ignore-scheduled',
  623. `org-agenda-todo-ignore-deadlines'
  624. make the global TODO list skip entries that have time stamps of certain
  625. kinds. If this option is set, the same options will also apply for the
  626. tags-todo search, which is the general tags/property matcher
  627. restricted to unfinished TODO entries only."
  628. :group 'org-agenda-skip
  629. :group 'org-agenda-todo-list
  630. :group 'org-agenda-match-view
  631. :type 'boolean)
  632. (defcustom org-agenda-skip-scheduled-if-done nil
  633. "Non-nil means don't show scheduled items in agenda when they are done.
  634. This is relevant for the daily/weekly agenda, not for the TODO list. And
  635. it applies only to the actual date of the scheduling. Warnings about
  636. an item with a past scheduling dates are always turned off when the item
  637. is DONE."
  638. :group 'org-agenda-skip
  639. :group 'org-agenda-daily/weekly
  640. :type 'boolean)
  641. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  642. "Non-nil means skip scheduling line if same entry shows because of deadline.
  643. In the agenda of today, an entry can show up multiple times because
  644. it is both scheduled and has a nearby deadline, and maybe a plain time
  645. stamp as well.
  646. When this variable is t, then only the deadline is shown and the fact that
  647. the entry is scheduled today or was scheduled previously is not shown.
  648. When this variable is nil, the entry will be shown several times. When
  649. the variable is the symbol `not-today', then skip scheduled previously,
  650. but not scheduled today."
  651. :group 'org-agenda-skip
  652. :group 'org-agenda-daily/weekly
  653. :type '(choice
  654. (const :tag "Never" nil)
  655. (const :tag "Always" t)
  656. (const :tag "Not when scheduled today" not-today)))
  657. (defcustom org-agenda-skip-deadline-if-done nil
  658. "Non-nil means don't show deadlines when the corresponding item is done.
  659. When nil, the deadline is still shown and should give you a happy feeling.
  660. This is relevant for the daily/weekly agenda. And it applied only to the
  661. actually date of the deadline. Warnings about approaching and past-due
  662. deadlines are always turned off when the item is DONE."
  663. :group 'org-agenda-skip
  664. :group 'org-agenda-daily/weekly
  665. :type 'boolean)
  666. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  667. "Non-nil means skip deadline prewarning when entry is also scheduled.
  668. This will apply on all days where a prewarning for the deadline would
  669. be shown, but not at the day when the entry is actually due. On that day,
  670. the deadline will be shown anyway.
  671. This variable may be set to nil, t, or a number which will then give
  672. the number of days before the actual deadline when the prewarnings
  673. should resume.
  674. This can be used in a workflow where the first showing of the deadline will
  675. trigger you to schedule it, and then you don't want to be reminded of it
  676. because you will take care of it on the day when scheduled."
  677. :group 'org-agenda-skip
  678. :group 'org-agenda-daily/weekly
  679. :type '(choice
  680. (const :tag "Alwas show prewarning" nil)
  681. (const :tag "Remove prewarning if entry is scheduled" t)
  682. (integer :tag "Restart prewarning N days before deadline")))
  683. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  684. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  685. When non-nil, after the search for timestamps has matched once in an
  686. entry, the rest of the entry will not be searched."
  687. :group 'org-agenda-skip
  688. :type 'boolean)
  689. (defcustom org-agenda-skip-timestamp-if-done nil
  690. "Non-nil means don't select item by timestamp or -range if it is DONE."
  691. :group 'org-agenda-skip
  692. :group 'org-agenda-daily/weekly
  693. :type 'boolean)
  694. (defcustom org-agenda-dim-blocked-tasks t
  695. "Non-nil means dim blocked tasks in the agenda display.
  696. This causes some overhead during agenda construction, but if you
  697. have turned on `org-enforce-todo-dependencies',
  698. `org-enforce-todo-checkbox-dependencies', or any other blocking
  699. mechanism, this will create useful feedback in the agenda.
  700. Instead of t, this variable can also have the value `invisible'.
  701. Then blocked tasks will be invisible and only become visible when
  702. they become unblocked. An exemption to this behavior is when a task is
  703. blocked because of unchecked checkboxes below it. Since checkboxes do
  704. not show up in the agenda views, making this task invisible you remove any
  705. trace from agenda views that there is something to do. Therefore, a task
  706. that is blocked because of checkboxes will never be made invisible, it
  707. will only be dimmed."
  708. :group 'org-agenda-daily/weekly
  709. :group 'org-agenda-todo-list
  710. :type '(choice
  711. (const :tag "Do not dim" nil)
  712. (const :tag "Dim to a grey face" t)
  713. (const :tag "Make invisible" invisible)))
  714. (defcustom org-timeline-show-empty-dates 3
  715. "Non-nil means `org-timeline' also shows dates without an entry.
  716. When nil, only the days which actually have entries are shown.
  717. When t, all days between the first and the last date are shown.
  718. When an integer, show also empty dates, but if there is a gap of more than
  719. N days, just insert a special line indicating the size of the gap."
  720. :group 'org-agenda-skip
  721. :type '(choice
  722. (const :tag "None" nil)
  723. (const :tag "All" t)
  724. (integer :tag "at most")))
  725. (defgroup org-agenda-startup nil
  726. "Options concerning initial settings in the Agenda in Org Mode."
  727. :tag "Org Agenda Startup"
  728. :group 'org-agenda)
  729. (defcustom org-agenda-menu-show-matcher t
  730. "Non-nil means show the match string in the agenda dispatcher menu.
  731. When nil, the matcher string is not shown, but is put into the help-echo
  732. property so than moving the mouse over the command shows it.
  733. Setting it to nil is good if matcher strings are very long and/or if
  734. you want to use two-column display (see `org-agenda-menu-two-column')."
  735. :group 'org-agenda
  736. :type 'boolean)
  737. (defcustom org-agenda-menu-two-column nil
  738. "Non-nil means, use two columns to show custom commands in the dispatcher.
  739. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  740. to nil."
  741. :group 'org-agenda
  742. :type 'boolean)
  743. (defcustom org-finalize-agenda-hook nil
  744. "Hook run just before displaying an agenda buffer."
  745. :group 'org-agenda-startup
  746. :type 'hook)
  747. (defcustom org-agenda-mouse-1-follows-link nil
  748. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  749. A longer mouse click will still set point. Does not work on XEmacs.
  750. Needs to be set before org.el is loaded."
  751. :group 'org-agenda-startup
  752. :type 'boolean)
  753. (defcustom org-agenda-start-with-follow-mode nil
  754. "The initial value of follow mode in a newly created agenda window."
  755. :group 'org-agenda-startup
  756. :type 'boolean)
  757. (defcustom org-agenda-show-outline-path t
  758. "Non-nil means show outline path in echo area after line motion."
  759. :group 'org-agenda-startup
  760. :type 'boolean)
  761. (defcustom org-agenda-start-with-entry-text-mode nil
  762. "The initial value of entry-text-mode in a newly created agenda window."
  763. :group 'org-agenda-startup
  764. :type 'boolean)
  765. (defcustom org-agenda-entry-text-maxlines 5
  766. "Number of text lines to be added when `E' is pressed in the agenda.
  767. Note that this variable only used during agenda display. Add add entry text
  768. when exporting the agenda, configure the variable
  769. `org-agenda-add-entry-ext-maxlines'."
  770. :group 'org-agenda
  771. :type 'integer)
  772. (defcustom org-agenda-entry-text-exclude-regexps nil
  773. "List of regular expressions to clean up entry text.
  774. The complete matches of all regular expressions in this list will be
  775. removed from entry text before it is shown in the agenda."
  776. :group 'org-agenda
  777. :type '(repeat (regexp)))
  778. (defvar org-agenda-entry-text-cleanup-hook nil
  779. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  780. This cleanup is done in a temporary buffer, so the function may inspect and
  781. change the entire buffer.
  782. Some default stuff like drawers and scheduling/deadline dates will already
  783. have been removed when this is called, as will any matches for regular
  784. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  785. (defvar org-agenda-include-inactive-timestamps nil
  786. "Non-nil means include inactive time stamps in agenda and timeline.")
  787. (defgroup org-agenda-windows nil
  788. "Options concerning the windows used by the Agenda in Org Mode."
  789. :tag "Org Agenda Windows"
  790. :group 'org-agenda)
  791. (defcustom org-agenda-window-setup 'reorganize-frame
  792. "How the agenda buffer should be displayed.
  793. Possible values for this option are:
  794. current-window Show agenda in the current window, keeping all other windows.
  795. other-window Use `switch-to-buffer-other-window' to display agenda.
  796. reorganize-frame Show only two windows on the current frame, the current
  797. window and the agenda.
  798. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  799. Also, when exiting the agenda, kill that frame.
  800. See also the variable `org-agenda-restore-windows-after-quit'."
  801. :group 'org-agenda-windows
  802. :type '(choice
  803. (const current-window)
  804. (const other-frame)
  805. (const other-window)
  806. (const reorganize-frame)))
  807. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  808. "The min and max height of the agenda window as a fraction of frame height.
  809. The value of the variable is a cons cell with two numbers between 0 and 1.
  810. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  811. :group 'org-agenda-windows
  812. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  813. (defcustom org-agenda-restore-windows-after-quit nil
  814. "Non-nil means restore window configuration upon exiting agenda.
  815. Before the window configuration is changed for displaying the agenda,
  816. the current status is recorded. When the agenda is exited with
  817. `q' or `x' and this option is set, the old state is restored. If
  818. `org-agenda-window-setup' is `other-frame', the value of this
  819. option will be ignored."
  820. :group 'org-agenda-windows
  821. :type 'boolean)
  822. (defcustom org-agenda-ndays nil
  823. "Number of days to include in overview display.
  824. Should be 1 or 7.
  825. Obsolete, see `org-agenda-span'."
  826. :group 'org-agenda-daily/weekly
  827. :type 'integer)
  828. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  829. (defcustom org-agenda-span 'week
  830. "Number of days to include in overview display.
  831. Can be day, week, month, year, or any number of days.
  832. Custom commands can set this variable in the options section."
  833. :group 'org-agenda-daily/weekly
  834. :type '(choice (const :tag "Day" day)
  835. (const :tag "Week" week)
  836. (const :tag "Month" month)
  837. (const :tag "Year" year)
  838. (integer :tag "Custom")))
  839. (defcustom org-agenda-start-on-weekday 1
  840. "Non-nil means start the overview always on the specified weekday.
  841. 0 denotes Sunday, 1 denotes Monday etc.
  842. When nil, always start on the current day.
  843. Custom commands can set this variable in the options section."
  844. :group 'org-agenda-daily/weekly
  845. :type '(choice (const :tag "Today" nil)
  846. (integer :tag "Weekday No.")))
  847. (defcustom org-agenda-show-all-dates t
  848. "Non-nil means `org-agenda' shows every day in the selected range.
  849. When nil, only the days which actually have entries are shown."
  850. :group 'org-agenda-daily/weekly
  851. :type 'boolean)
  852. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  853. "Format string for displaying dates in the agenda.
  854. Used by the daily/weekly agenda and by the timeline. This should be
  855. a format string understood by `format-time-string', or a function returning
  856. the formatted date as a string. The function must take a single argument,
  857. a calendar-style date list like (month day year)."
  858. :group 'org-agenda-daily/weekly
  859. :type '(choice
  860. (string :tag "Format string")
  861. (function :tag "Function")))
  862. (defun org-agenda-format-date-aligned (date)
  863. "Format a date string for display in the daily/weekly agenda, or timeline.
  864. This function makes sure that dates are aligned for easy reading."
  865. (require 'cal-iso)
  866. (let* ((dayname (calendar-day-name date))
  867. (day (cadr date))
  868. (day-of-week (calendar-day-of-week date))
  869. (month (car date))
  870. (monthname (calendar-month-name month))
  871. (year (nth 2 date))
  872. (iso-week (org-days-to-iso-week
  873. (calendar-absolute-from-gregorian date)))
  874. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  875. (1- year))
  876. ((and (= month 12) (<= iso-week 1))
  877. (1+ year))
  878. (t year)))
  879. (weekstring (if (= day-of-week 1)
  880. (format " W%02d" iso-week)
  881. "")))
  882. (format "%-10s %2d %s %4d%s"
  883. dayname day monthname year weekstring)))
  884. (defcustom org-agenda-time-leading-zero nil
  885. "Non-nil means use leading zero for military times in agenda.
  886. For example, 9:30am would become 09:30 rather than 9:30."
  887. :group 'org-agenda-daily/weekly
  888. :type 'boolean)
  889. (defcustom org-agenda-timegrid-use-ampm nil
  890. "When set, show AM/PM style timestamps on the timegrid."
  891. :group 'org-agenda
  892. :type 'boolean)
  893. (defun org-agenda-time-of-day-to-ampm (time)
  894. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  895. (let* ((hour-number (string-to-number (substring time 0 -3)))
  896. (minute (substring time -2))
  897. (ampm "am"))
  898. (cond
  899. ((equal hour-number 12)
  900. (setq ampm "pm"))
  901. ((> hour-number 12)
  902. (setq ampm "pm")
  903. (setq hour-number (- hour-number 12))))
  904. (concat
  905. (if org-agenda-time-leading-zero
  906. (format "%02d" hour-number)
  907. (format "%02s" (number-to-string hour-number)))
  908. ":" minute ampm)))
  909. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  910. "Conditionally convert TIME to AM/PM format
  911. based on `org-agenda-timegrid-use-ampm'"
  912. (if org-agenda-timegrid-use-ampm
  913. (org-agenda-time-of-day-to-ampm time)
  914. time))
  915. (defcustom org-agenda-weekend-days '(6 0)
  916. "Which days are weekend?
  917. These days get the special face `org-agenda-date-weekend' in the agenda
  918. and timeline buffers."
  919. :group 'org-agenda-daily/weekly
  920. :type '(set :greedy t
  921. (const :tag "Monday" 1)
  922. (const :tag "Tuesday" 2)
  923. (const :tag "Wednesday" 3)
  924. (const :tag "Thursday" 4)
  925. (const :tag "Friday" 5)
  926. (const :tag "Saturday" 6)
  927. (const :tag "Sunday" 0)))
  928. (defcustom org-agenda-include-diary nil
  929. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  930. Custom commands can set this variable in the options section."
  931. :group 'org-agenda-daily/weekly
  932. :type 'boolean)
  933. (defcustom org-agenda-include-deadlines t
  934. "If non-nil, include entries within their deadline warning period.
  935. Custom commands can set this variable in the options section."
  936. :group 'org-agenda-daily/weekly
  937. :type 'boolean)
  938. (defcustom org-agenda-include-all-todo nil
  939. "Set means weekly/daily agenda will always contain all TODO entries.
  940. The TODO entries will be listed at the top of the agenda, before
  941. the entries for specific days.
  942. This option is deprecated, it is better to define a block agenda instead."
  943. :group 'org-agenda-daily/weekly
  944. :type 'boolean)
  945. (defcustom org-agenda-repeating-timestamp-show-all t
  946. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  947. When set to a list of strings, only show occurrences of repeating
  948. stamps for these TODO keywords. When nil, only one occurrence is
  949. shown, either today or the nearest into the future."
  950. :group 'org-agenda-daily/weekly
  951. :type '(choice
  952. (const :tag "Show repeating stamps" t)
  953. (repeat :tag "Show repeating stamps for these TODO keywords"
  954. (string :tag "TODO Keyword"))
  955. (const :tag "Don't show repeating stamps" nil)))
  956. (defcustom org-scheduled-past-days 10000
  957. "No. of days to continue listing scheduled items that are not marked DONE.
  958. When an item is scheduled on a date, it shows up in the agenda on this
  959. day and will be listed until it is marked done for the number of days
  960. given here."
  961. :group 'org-agenda-daily/weekly
  962. :type 'integer)
  963. (defcustom org-agenda-log-mode-items '(closed clock)
  964. "List of items that should be shown in agenda log mode.
  965. This list may contain the following symbols:
  966. closed Show entries that have been closed on that day.
  967. clock Show entries that have received clocked time on that day.
  968. state Show all logged state changes.
  969. Note that instead of changing this variable, you can also press `C-u l' in
  970. the agenda to display all available LOG items temporarily."
  971. :group 'org-agenda-daily/weekly
  972. :type '(set :greedy t (const closed) (const clock) (const state)))
  973. (defcustom org-agenda-log-mode-add-notes t
  974. "Non-nil means add first line of notes to log entries in agenda views.
  975. If a log item like a state change or a clock entry is associated with
  976. notes, the first line of these notes will be added to the entry in the
  977. agenda display."
  978. :group 'org-agenda-daily/weekly
  979. :type 'boolean)
  980. (defcustom org-agenda-start-with-log-mode nil
  981. "The initial value of log-mode in a newly created agenda window."
  982. :group 'org-agenda-startup
  983. :group 'org-agenda-daily/weekly
  984. :type 'boolean)
  985. (defcustom org-agenda-start-with-clockreport-mode nil
  986. "The initial value of clockreport-mode in a newly created agenda window."
  987. :group 'org-agenda-startup
  988. :group 'org-agenda-daily/weekly
  989. :type 'boolean)
  990. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  991. "Property list with parameters for the clocktable in clockreport mode.
  992. This is the display mode that shows a clock table in the daily/weekly
  993. agenda, the properties for this dynamic block can be set here.
  994. The usual clocktable parameters are allowed here, but you cannot set
  995. the properties :name, :tstart, :tend, :block, and :scope - these will
  996. be overwritten to make sure the content accurately reflects the
  997. current display in the agenda."
  998. :group 'org-agenda-daily/weekly
  999. :type 'plist)
  1000. (defcustom org-agenda-search-view-always-boolean nil
  1001. "Non-nil means the search string is interpreted as individual parts.
  1002. The search string for search view can either be interpreted as a phrase,
  1003. or as a list of snippets that define a boolean search for a number of
  1004. strings.
  1005. When this is non-nil, the string will be split on whitespace, and each
  1006. snippet will be searched individually, and all must match in order to
  1007. select an entry. A snippet is then a single string of non-white
  1008. characters, or a string in double quotes, or a regexp in {} braces.
  1009. If a snippet is preceded by \"-\", the snippet must *not* match.
  1010. \"+\" is syntactic sugar for positive selection. Each snippet may
  1011. be found as a full word or a partial word, but see the variable
  1012. `org-agenda-search-view-force-full-words'.
  1013. When this is nil, search will look for the entire search phrase as one,
  1014. with each space character matching any amount of whitespace, including
  1015. line breaks.
  1016. Even when this is nil, you can still switch to Boolean search dynamically
  1017. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1018. is a regexp marked with braces like \"{abc}\", this will also switch to
  1019. boolean search."
  1020. :group 'org-agenda-search-view
  1021. :type 'boolean)
  1022. (if (fboundp 'defvaralias)
  1023. (defvaralias 'org-agenda-search-view-search-words-only
  1024. 'org-agenda-search-view-always-boolean))
  1025. (defcustom org-agenda-search-view-force-full-words nil
  1026. "Non-nil means, search words must be matches as complete words.
  1027. When nil, they may also match part of a word."
  1028. :group 'org-agenda-search-view
  1029. :type 'boolean)
  1030. (defgroup org-agenda-time-grid nil
  1031. "Options concerning the time grid in the Org-mode Agenda."
  1032. :tag "Org Agenda Time Grid"
  1033. :group 'org-agenda)
  1034. (defcustom org-agenda-search-headline-for-time t
  1035. "Non-nil means search headline for a time-of-day.
  1036. If the headline contains a time-of-day in one format or another, it will
  1037. be used to sort the entry into the time sequence of items for a day.
  1038. Some people have time stamps in the headline that refer to the creation
  1039. time or so, and then this produces an unwanted side effect. If this is
  1040. the case for your, use this variable to turn off searching the headline
  1041. for a time."
  1042. :group 'org-agenda-time-grid
  1043. :type 'boolean)
  1044. (defcustom org-agenda-use-time-grid t
  1045. "Non-nil means show a time grid in the agenda schedule.
  1046. A time grid is a set of lines for specific times (like every two hours between
  1047. 8:00 and 20:00). The items scheduled for a day at specific times are
  1048. sorted in between these lines.
  1049. For details about when the grid will be shown, and what it will look like, see
  1050. the variable `org-agenda-time-grid'."
  1051. :group 'org-agenda-time-grid
  1052. :type 'boolean)
  1053. (defcustom org-agenda-time-grid
  1054. '((daily today require-timed)
  1055. "----------------"
  1056. (800 1000 1200 1400 1600 1800 2000))
  1057. "The settings for time grid for agenda display.
  1058. This is a list of three items. The first item is again a list. It contains
  1059. symbols specifying conditions when the grid should be displayed:
  1060. daily if the agenda shows a single day
  1061. weekly if the agenda shows an entire week
  1062. today show grid on current date, independent of daily/weekly display
  1063. require-timed show grid only if at least one item has a time specification
  1064. The second item is a string which will be placed behind the grid time.
  1065. The third item is a list of integers, indicating the times that should have
  1066. a grid line."
  1067. :group 'org-agenda-time-grid
  1068. :type
  1069. '(list
  1070. (set :greedy t :tag "Grid Display Options"
  1071. (const :tag "Show grid in single day agenda display" daily)
  1072. (const :tag "Show grid in weekly agenda display" weekly)
  1073. (const :tag "Always show grid for today" today)
  1074. (const :tag "Show grid only if any timed entries are present"
  1075. require-timed)
  1076. (const :tag "Skip grid times already present in an entry"
  1077. remove-match))
  1078. (string :tag "Grid String")
  1079. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1080. (defcustom org-agenda-show-current-time-in-grid t
  1081. "Non-nil means show the current time in the time grid."
  1082. :group 'org-agenda-time-grid
  1083. :type 'boolean)
  1084. (defcustom org-agenda-current-time-string
  1085. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1086. "The string for the current time marker in the agenda."
  1087. :group 'org-agenda-time-grid
  1088. :type 'string)
  1089. (defgroup org-agenda-sorting nil
  1090. "Options concerning sorting in the Org-mode Agenda."
  1091. :tag "Org Agenda Sorting"
  1092. :group 'org-agenda)
  1093. (defcustom org-agenda-sorting-strategy
  1094. '((agenda habit-down time-up priority-down category-keep)
  1095. (todo priority-down category-keep)
  1096. (tags priority-down category-keep)
  1097. (search category-keep))
  1098. "Sorting structure for the agenda items of a single day.
  1099. This is a list of symbols which will be used in sequence to determine
  1100. if an entry should be listed before another entry. The following
  1101. symbols are recognized:
  1102. time-up Put entries with time-of-day indications first, early first
  1103. time-down Put entries with time-of-day indications first, late first
  1104. category-keep Keep the default order of categories, corresponding to the
  1105. sequence in `org-agenda-files'.
  1106. category-up Sort alphabetically by category, A-Z.
  1107. category-down Sort alphabetically by category, Z-A.
  1108. tag-up Sort alphabetically by last tag, A-Z.
  1109. tag-down Sort alphabetically by last tag, Z-A.
  1110. priority-up Sort numerically by priority, high priority last.
  1111. priority-down Sort numerically by priority, high priority first.
  1112. todo-state-up Sort by todo state, tasks that are done last.
  1113. todo-state-down Sort by todo state, tasks that are done first.
  1114. effort-up Sort numerically by estimated effort, high effort last.
  1115. effort-down Sort numerically by estimated effort, high effort first.
  1116. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1117. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1118. habit-up Put entries that are habits first
  1119. habit-down Put entries that are habits last
  1120. alpha-up Sort headlines alphabetically
  1121. alpha-down Sort headlines alphabetically, reversed
  1122. The different possibilities will be tried in sequence, and testing stops
  1123. if one comparison returns a \"not-equal\". For example, the default
  1124. '(time-up category-keep priority-down)
  1125. means: Pull out all entries having a specified time of day and sort them,
  1126. in order to make a time schedule for the current day the first thing in the
  1127. agenda listing for the day. Of the entries without a time indication, keep
  1128. the grouped in categories, don't sort the categories, but keep them in
  1129. the sequence given in `org-agenda-files'. Within each category sort by
  1130. priority.
  1131. Leaving out `category-keep' would mean that items will be sorted across
  1132. categories by priority.
  1133. Instead of a single list, this can also be a set of list for specific
  1134. contents, with a context symbol in the car of the list, any of
  1135. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1136. Custom commands can bind this variable in the options section."
  1137. :group 'org-agenda-sorting
  1138. :type `(choice
  1139. (repeat :tag "General" ,org-sorting-choice)
  1140. (list :tag "Individually"
  1141. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1142. (repeat ,org-sorting-choice))
  1143. (cons (const :tag "Strategy for TODO lists" todo)
  1144. (repeat ,org-sorting-choice))
  1145. (cons (const :tag "Strategy for Tags matches" tags)
  1146. (repeat ,org-sorting-choice))
  1147. (cons (const :tag "Strategy for search matches" search)
  1148. (repeat ,org-sorting-choice)))))
  1149. (defcustom org-agenda-cmp-user-defined nil
  1150. "A function to define the comparison `user-defined'.
  1151. This function must receive two arguments, agenda entry a and b.
  1152. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1153. the user comparison, return nil.
  1154. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1155. part of an agenda sorting strategy."
  1156. :group 'org-agenda-sorting
  1157. :type 'symbol)
  1158. (defcustom org-sort-agenda-notime-is-late t
  1159. "Non-nil means items without time are considered late.
  1160. This is only relevant for sorting. When t, items which have no explicit
  1161. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1162. do have a time. When nil, the default time is before 0:00. You can use this
  1163. option to decide if the schedule for today should come before or after timeless
  1164. agenda entries."
  1165. :group 'org-agenda-sorting
  1166. :type 'boolean)
  1167. (defcustom org-sort-agenda-noeffort-is-high t
  1168. "Non-nil means items without effort estimate are sorted as high effort.
  1169. This also applies when filtering an agenda view with respect to the
  1170. < or > effort operator. Then, tasks with no effort defined will be treated
  1171. as tasks with high effort.
  1172. When nil, such items are sorted as 0 minutes effort."
  1173. :group 'org-agenda-sorting
  1174. :type 'boolean)
  1175. (defgroup org-agenda-line-format nil
  1176. "Options concerning the entry prefix in the Org-mode agenda display."
  1177. :tag "Org Agenda Line Format"
  1178. :group 'org-agenda)
  1179. (defcustom org-agenda-prefix-format
  1180. '((agenda . " %i %-12:c%?-12t% s")
  1181. (timeline . " % s")
  1182. (todo . " %i %-12:c")
  1183. (tags . " %i %-12:c")
  1184. (search . " %i %-12:c"))
  1185. "Format specifications for the prefix of items in the agenda views.
  1186. An alist with four entries, for the different agenda types. The keys to the
  1187. sublists are `agenda', `timeline', `todo', `search' and `tags'. The values
  1188. are format strings.
  1189. This format works similar to a printf format, with the following meaning:
  1190. %c the category of the item, \"Diary\" for entries from the diary, or
  1191. as given by the CATEGORY keyword or derived from the file name.
  1192. %i the icon category of the item, as give in
  1193. `org-agenda-category-icon-alist'.
  1194. %T the *last* tag of the item. Last because inherited tags come
  1195. first in the list.
  1196. %t the time-of-day specification if one applies to the entry, in the
  1197. format HH:MM
  1198. %s Scheduling/Deadline information, a short string
  1199. %(expression) Eval EXPRESSION and replace the control string
  1200. by the result
  1201. All specifiers work basically like the standard `%s' of printf, but may
  1202. contain two additional characters: A question mark just after the `%' and
  1203. a whitespace/punctuation character just before the final letter.
  1204. If the first character after `%' is a question mark, the entire field
  1205. will only be included if the corresponding value applies to the
  1206. current entry. This is useful for fields which should have fixed
  1207. width when present, but zero width when absent. For example,
  1208. \"%?-12t\" will result in a 12 character time field if a time of the
  1209. day is specified, but will completely disappear in entries which do
  1210. not contain a time.
  1211. If there is punctuation or whitespace character just before the final
  1212. format letter, this character will be appended to the field value if
  1213. the value is not empty. For example, the format \"%-12:c\" leads to
  1214. \"Diary: \" if the category is \"Diary\". If the category were be
  1215. empty, no additional colon would be inserted.
  1216. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  1217. - Indent the line with two space characters
  1218. - Give the category in a 12 chars wide field, padded with whitespace on
  1219. the right (because of `-'). Append a colon if there is a category
  1220. (because of `:').
  1221. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1222. time, don't put in an empty field, just skip it (because of '?').
  1223. - Finally, put the scheduling information and append a whitespace.
  1224. As another example, if you don't want the time-of-day of entries in
  1225. the prefix, you could use:
  1226. (setq org-agenda-prefix-format \" %-11:c% s\")
  1227. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1228. `org-agenda-remove-tags'.
  1229. Custom commands can set this variable in the options section."
  1230. :type '(choice
  1231. (string :tag "General format")
  1232. (list :greedy t :tag "View dependent"
  1233. (cons (const agenda) (string :tag "Format"))
  1234. (cons (const timeline) (string :tag "Format"))
  1235. (cons (const todo) (string :tag "Format"))
  1236. (cons (const tags) (string :tag "Format"))
  1237. (cons (const search) (string :tag "Format"))))
  1238. :group 'org-agenda-line-format)
  1239. (defvar org-prefix-format-compiled nil
  1240. "The compiled version of the most recently used prefix format.
  1241. See the variable `org-agenda-prefix-format'.")
  1242. (defcustom org-agenda-todo-keyword-format "%-1s"
  1243. "Format for the TODO keyword in agenda lines.
  1244. Set this to something like \"%-12s\" if you want all TODO keywords
  1245. to occupy a fixed space in the agenda display."
  1246. :group 'org-agenda-line-format
  1247. :type 'string)
  1248. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1249. "Text preceding timerange entries in the agenda view.
  1250. This is a list with two strings. The first applies when the range
  1251. is entirely on one day. The second applies if the range spans several days.
  1252. The strings may have two \"%d\" format specifiers which will be filled
  1253. with the sequence number of the days, and the total number of days in the
  1254. range, respectively."
  1255. :group 'org-agenda-line-format
  1256. :type '(list
  1257. (string :tag "Deadline today ")
  1258. (choice :tag "Deadline relative"
  1259. (string :tag "Format string")
  1260. (function))))
  1261. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1262. "Text preceding scheduled items in the agenda view.
  1263. This is a list with two strings. The first applies when the item is
  1264. scheduled on the current day. The second applies when it has been scheduled
  1265. previously, it may contain a %d indicating that this is the nth time that
  1266. this item is scheduled, due to automatic rescheduling of unfinished items
  1267. for the following day. So this number is one larger than the number of days
  1268. that passed since this item was scheduled first."
  1269. :group 'org-agenda-line-format
  1270. :type '(list
  1271. (string :tag "Scheduled today ")
  1272. (string :tag "Scheduled previously")))
  1273. (defcustom org-agenda-inactive-leader "["
  1274. "Text preceding item pulled into the agenda by inactive time stamps.
  1275. These entries are added to the agenda when pressing \"[\"."
  1276. :group 'org-agenda-line-format
  1277. :type '(list
  1278. (string :tag "Scheduled today ")
  1279. (string :tag "Scheduled previously")))
  1280. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1281. "Text preceding deadline items in the agenda view.
  1282. This is a list with two strings. The first applies when the item has its
  1283. deadline on the current day. The second applies when it is in the past or
  1284. in the future, it may contain %d to capture how many days away the deadline
  1285. is (was)."
  1286. :group 'org-agenda-line-format
  1287. :type '(list
  1288. (string :tag "Deadline today ")
  1289. (choice :tag "Deadline relative"
  1290. (string :tag "Format string")
  1291. (function))))
  1292. (defcustom org-agenda-remove-times-when-in-prefix t
  1293. "Non-nil means remove duplicate time specifications in agenda items.
  1294. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1295. time-of-day specification in a headline or diary entry is extracted and
  1296. placed into the prefix. If this option is non-nil, the original specification
  1297. \(a timestamp or -range, or just a plain time(range) specification like
  1298. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1299. cluttered.
  1300. The option can be t or nil. It may also be the symbol `beg', indicating
  1301. that the time should only be removed when it is located at the beginning of
  1302. the headline/diary entry."
  1303. :group 'org-agenda-line-format
  1304. :type '(choice
  1305. (const :tag "Always" t)
  1306. (const :tag "Never" nil)
  1307. (const :tag "When at beginning of entry" beg)))
  1308. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1309. "Non-nil means remove time ranges specifications in agenda
  1310. items that span on several days."
  1311. :group 'org-agenda-line-format
  1312. :type 'boolean)
  1313. (defcustom org-agenda-default-appointment-duration nil
  1314. "Default duration for appointments that only have a starting time.
  1315. When nil, no duration is specified in such cases.
  1316. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1317. :group 'org-agenda-line-format
  1318. :type '(choice
  1319. (integer :tag "Minutes")
  1320. (const :tag "No default duration")))
  1321. (defcustom org-agenda-show-inherited-tags t
  1322. "Non-nil means show inherited tags in each agenda line."
  1323. :group 'org-agenda-line-format
  1324. :type 'boolean)
  1325. (defcustom org-agenda-hide-tags-regexp nil
  1326. "Regular expression used to filter away specific tags in agenda views.
  1327. This means that these tags will be present, but not be shown in the agenda
  1328. line. Secondary filtering will still work on the hidden tags.
  1329. Nil means don't hide any tags."
  1330. :group 'org-agenda-line-format
  1331. :type '(choice
  1332. (const :tag "Hide none" nil)
  1333. (string :tag "Regexp ")))
  1334. (defcustom org-agenda-remove-tags nil
  1335. "Non-nil means remove the tags from the headline copy in the agenda.
  1336. When this is the symbol `prefix', only remove tags when
  1337. `org-agenda-prefix-format' contains a `%T' specifier."
  1338. :group 'org-agenda-line-format
  1339. :type '(choice
  1340. (const :tag "Always" t)
  1341. (const :tag "Never" nil)
  1342. (const :tag "When prefix format contains %T" prefix)))
  1343. (if (fboundp 'defvaralias)
  1344. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1345. 'org-agenda-remove-tags))
  1346. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1347. "Shift tags in agenda items to this column.
  1348. If this number is positive, it specifies the column. If it is negative,
  1349. it means that the tags should be flushright to that column. For example,
  1350. -80 works well for a normal 80 character screen."
  1351. :group 'org-agenda-line-format
  1352. :type 'integer)
  1353. (if (fboundp 'defvaralias)
  1354. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1355. (defcustom org-agenda-fontify-priorities 'cookies
  1356. "Non-nil means highlight low and high priorities in agenda.
  1357. When t, the highest priority entries are bold, lowest priority italic.
  1358. However, settings in `org-priority-faces' will overrule these faces.
  1359. When this variable is the symbol `cookies', only fontify the
  1360. cookies, not the entire task.
  1361. This may also be an association list of priority faces, whose
  1362. keys are the character values of `org-highest-priority',
  1363. `org-default-priority', and `org-lowest-priority' (the default values
  1364. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1365. color as a string, or a list like `(:background \"Red\")'.
  1366. If it is a color, the variable `org-faces-easy-properties'
  1367. determines if it is a foreground or a background color."
  1368. :group 'org-agenda-line-format
  1369. :type '(choice
  1370. (const :tag "Never" nil)
  1371. (const :tag "Defaults" t)
  1372. (const :tag "Cookies only" cookies)
  1373. (repeat :tag "Specify"
  1374. (list (character :tag "Priority" :value ?A)
  1375. (choice :tag "Face "
  1376. (string :tag "Color")
  1377. (sexp :tag "Face"))))))
  1378. (defcustom org-agenda-day-face-function nil
  1379. "Function called to determine what face should be used to display a day.
  1380. The only argument passed to that function is the day. It should
  1381. returns a face, or nil if does not want to specify a face and let
  1382. the normal rules apply."
  1383. :group 'org-agenda-line-format
  1384. :type 'function)
  1385. (defcustom org-agenda-category-icon-alist nil
  1386. "Alist of category icon to be displayed in agenda views.
  1387. Each entry should have the following format:
  1388. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1389. Where CATEGORY-REGEXP is a regexp matching the categories where
  1390. the icon should be displayed.
  1391. FILE-OR-DATA either a file path or a string containing image data.
  1392. The other fields can be omited safely if not needed:
  1393. TYPE indicates the image type.
  1394. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1395. image data.
  1396. PROPS are additional image attributes to assign to the image,
  1397. like, e.g. `:ascent center'.
  1398. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1399. If you want to set the display properties yourself, just put a
  1400. list as second element:
  1401. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1402. For example, to display a 16px horizontal space for Emacs
  1403. category, you can use:
  1404. (\"Emacs\" '(space . (:width (16))))"
  1405. :group 'org-agenda-line-format
  1406. :type '(alist :key-type (string :tag "Regexp matching category")
  1407. :value-type (choice (list :tag "Icon"
  1408. (string :tag "File or data")
  1409. (symbol :tag "Type")
  1410. (boolean :tag "Data?")
  1411. (repeat :tag "Extra image properties" :inline t symbol))
  1412. (list :tag "Display properties" sexp))))
  1413. (defgroup org-agenda-column-view nil
  1414. "Options concerning column view in the agenda."
  1415. :tag "Org Agenda Column View"
  1416. :group 'org-agenda)
  1417. (defcustom org-agenda-columns-show-summaries t
  1418. "Non-nil means show summaries for columns displayed in the agenda view."
  1419. :group 'org-agenda-column-view
  1420. :type 'boolean)
  1421. (defcustom org-agenda-columns-remove-prefix-from-item t
  1422. "Non-nil means remove the prefix from a headline for agenda column view.
  1423. The special ITEM field in the columns format contains the current line, with
  1424. all information shown in other columns (like the TODO state or a tag).
  1425. When this variable is non-nil, also the agenda prefix will be removed from
  1426. the content of the ITEM field, to make sure as much as possible of the
  1427. headline can be shown in the limited width of the field."
  1428. :group 'org-agenda
  1429. :type 'boolean)
  1430. (defcustom org-agenda-columns-compute-summary-properties t
  1431. "Non-nil means recompute all summary properties before column view.
  1432. When column view in the agenda is listing properties that have a summary
  1433. operator, it can go to all relevant buffers and recompute the summaries
  1434. there. This can mean overhead for the agenda column view, but is necessary
  1435. to have thing up to date.
  1436. As a special case, a CLOCKSUM property also makes sure that the clock
  1437. computations are current."
  1438. :group 'org-agenda-column-view
  1439. :type 'boolean)
  1440. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1441. "Non-nil means the duration of an appointment will add to day effort.
  1442. The property to which appointment durations will be added is the one given
  1443. in the option `org-effort-property'. If an appointment does not have
  1444. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1445. is not set, an appointment without end time will not contribute to the time
  1446. estimate."
  1447. :group 'org-agenda-column-view
  1448. :type 'boolean)
  1449. (defcustom org-agenda-auto-exclude-function nil
  1450. "A function called with a tag to decide if it is filtered on '/ RET'.
  1451. The sole argument to the function, which is called once for each
  1452. possible tag, is a string giving the name of the tag. The
  1453. function should return either nil if the tag should be included
  1454. as normal, or \"-<TAG>\" to exclude the tag.
  1455. Note that for the purpose of tag filtering, only the lower-case version of
  1456. all tags will be considered, so that this function will only ever see
  1457. the lower-case version of all tags."
  1458. :group 'org-agenda
  1459. :type 'function)
  1460. (eval-when-compile
  1461. (require 'cl))
  1462. (require 'org)
  1463. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1464. "Execute BODY with point at location given by `org-hd-marker' property.
  1465. If STRING is non-nil, the text property will be fetched from position 0
  1466. in that string. If STRING is nil, it will be fetched from the beginning
  1467. of the current line."
  1468. `(let ((marker (get-text-property (if string 0 (point-at-bol))
  1469. 'org-hd-marker string)))
  1470. (with-current-buffer (marker-buffer marker)
  1471. (save-excursion
  1472. (goto-char marker)
  1473. ,@body))))
  1474. (defun org-add-agenda-custom-command (entry)
  1475. "Replace or add a command in `org-agenda-custom-commands'.
  1476. This is mostly for hacking and trying a new command - once the command
  1477. works you probably want to add it to `org-agenda-custom-commands' for good."
  1478. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1479. (if ass
  1480. (setcdr ass (cdr entry))
  1481. (push entry org-agenda-custom-commands))))
  1482. ;;; Define the Org-agenda-mode
  1483. (defvar org-agenda-mode-map (make-sparse-keymap)
  1484. "Keymap for `org-agenda-mode'.")
  1485. (if (fboundp 'defvaralias)
  1486. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1487. (defvar org-agenda-menu) ; defined later in this file.
  1488. (defvar org-agenda-restrict) ; defined later in this file.
  1489. (defvar org-agenda-follow-mode nil)
  1490. (defvar org-agenda-entry-text-mode nil)
  1491. (defvar org-agenda-clockreport-mode nil)
  1492. (defvar org-agenda-show-log nil)
  1493. (defvar org-agenda-redo-command nil)
  1494. (defvar org-agenda-query-string nil)
  1495. (defvar org-agenda-mode-hook nil
  1496. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1497. (defvar org-agenda-type nil)
  1498. (defvar org-agenda-force-single-file nil)
  1499. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1500. (defun org-agenda-mode ()
  1501. "Mode for time-sorted view on action items in Org-mode files.
  1502. The following commands are available:
  1503. \\{org-agenda-mode-map}"
  1504. (interactive)
  1505. (kill-all-local-variables)
  1506. (setq org-agenda-undo-list nil
  1507. org-agenda-pending-undo-list nil
  1508. org-agenda-bulk-marked-entries nil)
  1509. (setq major-mode 'org-agenda-mode)
  1510. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1511. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1512. (setq mode-name "Org-Agenda")
  1513. (use-local-map org-agenda-mode-map)
  1514. (easy-menu-add org-agenda-menu)
  1515. (if org-startup-truncated (setq truncate-lines t))
  1516. (org-set-local 'line-move-visual nil)
  1517. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1518. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1519. ;; Make sure properties are removed when copying text
  1520. (when (boundp 'buffer-substring-filters)
  1521. (org-set-local 'buffer-substring-filters
  1522. (cons (lambda (x)
  1523. (set-text-properties 0 (length x) nil x) x)
  1524. buffer-substring-filters)))
  1525. (unless org-agenda-keep-modes
  1526. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1527. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1528. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1529. org-agenda-show-log org-agenda-start-with-log-mode))
  1530. (easy-menu-change
  1531. '("Agenda") "Agenda Files"
  1532. (append
  1533. (list
  1534. (vector
  1535. (if (get 'org-agenda-files 'org-restrict)
  1536. "Restricted to single file"
  1537. "Edit File List")
  1538. '(org-edit-agenda-file-list)
  1539. (not (get 'org-agenda-files 'org-restrict)))
  1540. "--")
  1541. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1542. (org-agenda-set-mode-name)
  1543. (apply
  1544. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1545. (list 'org-agenda-mode-hook)))
  1546. (substitute-key-definition 'undo 'org-agenda-undo
  1547. org-agenda-mode-map global-map)
  1548. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1549. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1550. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1551. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1552. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1553. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1554. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1555. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1556. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1557. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1558. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1559. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1560. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1561. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1562. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1563. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1564. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1565. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1566. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1567. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1568. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1569. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1570. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1571. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1572. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1573. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1574. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1575. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1576. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1577. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1578. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1579. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1580. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1581. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1582. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1583. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1584. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1585. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1586. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1587. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1588. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1589. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1590. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1591. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1592. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1593. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1594. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1595. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1596. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1597. (while l (org-defkey org-agenda-mode-map
  1598. (int-to-string (pop l)) 'digit-argument)))
  1599. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1600. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1601. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1602. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1603. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1604. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1605. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1606. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1607. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1608. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1609. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1610. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1611. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1612. 'org-clock-modify-effort-estimate)
  1613. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1614. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1615. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1616. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1617. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1618. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1619. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1620. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1621. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1622. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1623. (substitute-key-definition 'next-line 'org-agenda-next-line
  1624. org-agenda-mode-map global-map)
  1625. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1626. org-agenda-mode-map global-map)
  1627. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1628. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1629. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1630. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1631. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1632. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1633. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1634. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1635. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1636. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1637. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1638. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1639. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1640. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1641. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1642. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1643. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1644. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1645. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1646. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1647. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1648. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1649. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1650. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1651. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1652. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1653. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1654. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1655. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1656. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1657. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1658. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1659. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1660. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1661. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1662. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1663. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1664. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1665. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1666. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1667. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1668. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1669. (when org-agenda-mouse-1-follows-link
  1670. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1671. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1672. '("Agenda"
  1673. ("Agenda Files")
  1674. "--"
  1675. ("Agenda Dates"
  1676. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1677. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1678. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1679. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1680. "--"
  1681. ("View"
  1682. ["Day View" org-agenda-day-view
  1683. :active (org-agenda-check-type nil 'agenda)
  1684. :style radio :selected (eq org-agenda-current-span 'day)
  1685. :keys "v d (or just d)"]
  1686. ["Week View" org-agenda-week-view
  1687. :active (org-agenda-check-type nil 'agenda)
  1688. :style radio :selected (eq org-agenda-current-span 'week)
  1689. :keys "v w (or just w)"]
  1690. ["Month View" org-agenda-month-view
  1691. :active (org-agenda-check-type nil 'agenda)
  1692. :style radio :selected (eq org-agenda-current-span 'month)
  1693. :keys "v m"]
  1694. ["Year View" org-agenda-year-view
  1695. :active (org-agenda-check-type nil 'agenda)
  1696. :style radio :selected (eq org-agenda-current-span 'year)
  1697. :keys "v y"]
  1698. "--"
  1699. ["Include Diary" org-agenda-toggle-diary
  1700. :style toggle :selected org-agenda-include-diary
  1701. :active (org-agenda-check-type nil 'agenda)]
  1702. ["Include Deadlines" org-agenda-toggle-deadlines
  1703. :style toggle :selected org-agenda-include-deadlines
  1704. :active (org-agenda-check-type nil 'agenda)]
  1705. ["Use Time Grid" org-agenda-toggle-time-grid
  1706. :style toggle :selected org-agenda-use-time-grid
  1707. :active (org-agenda-check-type nil 'agenda)]
  1708. "--"
  1709. ["Show clock report" org-agenda-clockreport-mode
  1710. :style toggle :selected org-agenda-clockreport-mode
  1711. :active (org-agenda-check-type nil 'agenda)]
  1712. ["Show some entry text" org-agenda-entry-text-mode
  1713. :style toggle :selected org-agenda-entry-text-mode
  1714. :active t]
  1715. "--"
  1716. ["Show Logbook entries" org-agenda-log-mode
  1717. :style toggle :selected org-agenda-show-log
  1718. :active (org-agenda-check-type nil 'agenda 'timeline)
  1719. :keys "v l (or just l)"]
  1720. ["Include archived trees" org-agenda-archives-mode
  1721. :style toggle :selected org-agenda-archives-mode :active t
  1722. :keys "v a"]
  1723. ["Include archive files" (org-agenda-archives-mode t)
  1724. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1725. :keys "v A"]
  1726. "--"
  1727. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1728. ["Write view to file" org-write-agenda t]
  1729. ["Rebuild buffer" org-agenda-redo t]
  1730. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1731. "--"
  1732. ["Show original entry" org-agenda-show t]
  1733. ["Go To (other window)" org-agenda-goto t]
  1734. ["Go To (this window)" org-agenda-switch-to t]
  1735. ["Follow Mode" org-agenda-follow-mode
  1736. :style toggle :selected org-agenda-follow-mode :active t]
  1737. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1738. "--"
  1739. ("TODO"
  1740. ["Cycle TODO" org-agenda-todo t]
  1741. ["Next TODO set" org-agenda-todo-nextset t]
  1742. ["Previous TODO set" org-agenda-todo-previousset t]
  1743. ["Add note" org-agenda-add-note t])
  1744. ("Archive/Refile/Delete"
  1745. ["Archive default" org-agenda-archive-default t]
  1746. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1747. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1748. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1749. ["Archive subtree" org-agenda-archive t]
  1750. "--"
  1751. ["Refile" org-agenda-refile t]
  1752. "--"
  1753. ["Delete subtree" org-agenda-kill t])
  1754. ("Bulk action"
  1755. ["Mark entry" org-agenda-bulk-mark t]
  1756. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1757. ["Unmark entry" org-agenda-bulk-unmark t]
  1758. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1759. ["Act on all marked" org-agenda-bulk-action t]
  1760. "--"
  1761. ("Tags and Properties"
  1762. ["Show all Tags" org-agenda-show-tags t]
  1763. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1764. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1765. "--"
  1766. ["Column View" org-columns t])
  1767. ("Deadline/Schedule"
  1768. ["Schedule" org-agenda-schedule t]
  1769. ["Set Deadline" org-agenda-deadline t]
  1770. "--"
  1771. ["Mark item" org-agenda-action :active t :keys "k m"]
  1772. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1773. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1774. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1775. "--"
  1776. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1777. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1778. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1779. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1780. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1781. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1782. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1783. ("Clock and Effort"
  1784. ["Clock in" org-agenda-clock-in t]
  1785. ["Clock out" org-agenda-clock-out t]
  1786. ["Clock cancel" org-agenda-clock-cancel t]
  1787. ["Goto running clock" org-clock-goto t]
  1788. "--"
  1789. ["Set Effort" org-agenda-set-effort t]
  1790. ["Change clocked effort" org-clock-modify-effort-estimate
  1791. (org-clock-is-active)])
  1792. ("Priority"
  1793. ["Set Priority" org-agenda-priority t]
  1794. ["Increase Priority" org-agenda-priority-up t]
  1795. ["Decrease Priority" org-agenda-priority-down t]
  1796. ["Show Priority" org-agenda-show-priority t])
  1797. ("Calendar/Diary"
  1798. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1799. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1800. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1801. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1802. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1803. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1804. "--"
  1805. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1806. "--"
  1807. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1808. "--"
  1809. ("MobileOrg"
  1810. ["Push Files and Views" org-mobile-push t]
  1811. ["Get Captured and Flagged" org-mobile-pull t]
  1812. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1813. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1814. "--"
  1815. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1816. "--"
  1817. ["Quit" org-agenda-quit t]
  1818. ["Exit and Release Buffers" org-agenda-exit t]
  1819. ))
  1820. ;;; Agenda undo
  1821. (defvar org-agenda-allow-remote-undo t
  1822. "Non-nil means allow remote undo from the agenda buffer.")
  1823. (defvar org-agenda-undo-list nil
  1824. "List of undoable operations in the agenda since last refresh.")
  1825. (defvar org-agenda-undo-has-started-in nil
  1826. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1827. (defvar org-agenda-pending-undo-list nil
  1828. "In a series of undo commands, this is the list of remaining undo items.")
  1829. (defun org-agenda-undo ()
  1830. "Undo a remote editing step in the agenda.
  1831. This undoes changes both in the agenda buffer and in the remote buffer
  1832. that have been changed along."
  1833. (interactive)
  1834. (or org-agenda-allow-remote-undo
  1835. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1836. (if (not (eq this-command last-command))
  1837. (setq org-agenda-undo-has-started-in nil
  1838. org-agenda-pending-undo-list org-agenda-undo-list))
  1839. (if (not org-agenda-pending-undo-list)
  1840. (error "No further undo information"))
  1841. (let* ((entry (pop org-agenda-pending-undo-list))
  1842. buf line cmd rembuf)
  1843. (setq cmd (pop entry) line (pop entry))
  1844. (setq rembuf (nth 2 entry))
  1845. (org-with-remote-undo rembuf
  1846. (while (bufferp (setq buf (pop entry)))
  1847. (if (pop entry)
  1848. (with-current-buffer buf
  1849. (let ((last-undo-buffer buf)
  1850. (inhibit-read-only t))
  1851. (unless (memq buf org-agenda-undo-has-started-in)
  1852. (push buf org-agenda-undo-has-started-in)
  1853. (make-local-variable 'pending-undo-list)
  1854. (undo-start))
  1855. (while (and pending-undo-list
  1856. (listp pending-undo-list)
  1857. (not (car pending-undo-list)))
  1858. (pop pending-undo-list))
  1859. (undo-more 1))))))
  1860. (org-goto-line line)
  1861. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1862. (defun org-verify-change-for-undo (l1 l2)
  1863. "Verify that a real change occurred between the undo lists L1 and L2."
  1864. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1865. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1866. (not (eq l1 l2)))
  1867. ;;; Agenda dispatch
  1868. (defvar org-agenda-restrict nil)
  1869. (defvar org-agenda-restrict-begin (make-marker))
  1870. (defvar org-agenda-restrict-end (make-marker))
  1871. (defvar org-agenda-last-dispatch-buffer nil)
  1872. (defvar org-agenda-overriding-restriction nil)
  1873. ;;;###autoload
  1874. (defun org-agenda (&optional arg keys restriction)
  1875. "Dispatch agenda commands to collect entries to the agenda buffer.
  1876. Prompts for a command to execute. Any prefix arg will be passed
  1877. on to the selected command. The default selections are:
  1878. a Call `org-agenda-list' to display the agenda for current day or week.
  1879. t Call `org-todo-list' to display the global todo list.
  1880. T Call `org-todo-list' to display the global todo list, select only
  1881. entries with a specific TODO keyword (the user gets a prompt).
  1882. m Call `org-tags-view' to display headlines with tags matching
  1883. a condition (the user is prompted for the condition).
  1884. M Like `m', but select only TODO entries, no ordinary headlines.
  1885. L Create a timeline for the current buffer.
  1886. e Export views to associated files.
  1887. s Search entries for keywords.
  1888. / Multi occur across all agenda files and also files listed
  1889. in `org-agenda-text-search-extra-files'.
  1890. < Restrict agenda commands to buffer, subtree, or region.
  1891. Press several times to get the desired effect.
  1892. > Remove a previous restriction.
  1893. # List \"stuck\" projects.
  1894. ! Configure what \"stuck\" means.
  1895. C Configure custom agenda commands.
  1896. More commands can be added by configuring the variable
  1897. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1898. searches can be pre-defined in this way.
  1899. If the current buffer is in Org-mode and visiting a file, you can also
  1900. first press `<' once to indicate that the agenda should be temporarily
  1901. \(until the next use of \\[org-agenda]) restricted to the current file.
  1902. Pressing `<' twice means to restrict to the current subtree or region
  1903. \(if active)."
  1904. (interactive "P")
  1905. (catch 'exit
  1906. (let* ((prefix-descriptions nil)
  1907. (org-agenda-window-setup (if (equal (buffer-name)
  1908. org-agenda-buffer-name)
  1909. 'current-window
  1910. org-agenda-window-setup))
  1911. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1912. (org-agenda-custom-commands
  1913. ;; normalize different versions
  1914. (delq nil
  1915. (mapcar
  1916. (lambda (x)
  1917. (cond ((stringp (cdr x))
  1918. (push x prefix-descriptions)
  1919. nil)
  1920. ((stringp (nth 1 x)) x)
  1921. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1922. (t (cons (car x) (cons "" (cdr x))))))
  1923. org-agenda-custom-commands)))
  1924. (buf (current-buffer))
  1925. (bfn (buffer-file-name (buffer-base-buffer)))
  1926. entry key type match lprops ans)
  1927. ;; Turn off restriction unless there is an overriding one,
  1928. (unless org-agenda-overriding-restriction
  1929. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1930. ;; There is a request to keep the file list in place
  1931. (put 'org-agenda-files 'org-restrict nil))
  1932. (setq org-agenda-restrict nil)
  1933. (move-marker org-agenda-restrict-begin nil)
  1934. (move-marker org-agenda-restrict-end nil))
  1935. ;; Delete old local properties
  1936. (put 'org-agenda-redo-command 'org-lprops nil)
  1937. ;; Delete previously set last-arguments
  1938. (put 'org-agenda-redo-command 'last-args nil)
  1939. ;; Remember where this call originated
  1940. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1941. (unless keys
  1942. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1943. keys (car ans)
  1944. restriction (cdr ans)))
  1945. ;; Establish the restriction, if any
  1946. (when (and (not org-agenda-overriding-restriction) restriction)
  1947. (put 'org-agenda-files 'org-restrict (list bfn))
  1948. (cond
  1949. ((eq restriction 'region)
  1950. (setq org-agenda-restrict t)
  1951. (move-marker org-agenda-restrict-begin (region-beginning))
  1952. (move-marker org-agenda-restrict-end (region-end)))
  1953. ((eq restriction 'subtree)
  1954. (save-excursion
  1955. (setq org-agenda-restrict t)
  1956. (org-back-to-heading t)
  1957. (move-marker org-agenda-restrict-begin (point))
  1958. (move-marker org-agenda-restrict-end
  1959. (progn (org-end-of-subtree t)))))))
  1960. ;; For example the todo list should not need it (but does...)
  1961. (cond
  1962. ((setq entry (assoc keys org-agenda-custom-commands))
  1963. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1964. (progn
  1965. (setq type (nth 2 entry) match (eval (nth 3 entry))
  1966. lprops (nth 4 entry))
  1967. (put 'org-agenda-redo-command 'org-lprops lprops)
  1968. (cond
  1969. ((eq type 'agenda)
  1970. (org-let lprops '(org-agenda-list current-prefix-arg)))
  1971. ((eq type 'alltodo)
  1972. (org-let lprops '(org-todo-list current-prefix-arg)))
  1973. ((eq type 'search)
  1974. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  1975. ((eq type 'stuck)
  1976. (org-let lprops '(org-agenda-list-stuck-projects
  1977. current-prefix-arg)))
  1978. ((eq type 'tags)
  1979. (org-let lprops '(org-tags-view current-prefix-arg match)))
  1980. ((eq type 'tags-todo)
  1981. (org-let lprops '(org-tags-view '(4) match)))
  1982. ((eq type 'todo)
  1983. (org-let lprops '(org-todo-list match)))
  1984. ((eq type 'tags-tree)
  1985. (org-check-for-org-mode)
  1986. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  1987. ((eq type 'todo-tree)
  1988. (org-check-for-org-mode)
  1989. (org-let lprops
  1990. '(org-occur (concat "^" outline-regexp "[ \t]*"
  1991. (regexp-quote match) "\\>"))))
  1992. ((eq type 'occur-tree)
  1993. (org-check-for-org-mode)
  1994. (org-let lprops '(org-occur match)))
  1995. ((functionp type)
  1996. (org-let lprops '(funcall type match)))
  1997. ((fboundp type)
  1998. (org-let lprops '(funcall type match)))
  1999. (t (error "Invalid custom agenda command type %s" type))))
  2000. (org-run-agenda-series (nth 1 entry) (cddr entry))))
  2001. ((equal keys "C")
  2002. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2003. (customize-variable 'org-agenda-custom-commands))
  2004. ((equal keys "a") (call-interactively 'org-agenda-list))
  2005. ((equal keys "s") (call-interactively 'org-search-view))
  2006. ((equal keys "t") (call-interactively 'org-todo-list))
  2007. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2008. ((equal keys "m") (call-interactively 'org-tags-view))
  2009. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2010. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2011. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2012. (org-add-hook
  2013. 'post-command-hook
  2014. (lambda ()
  2015. (unless (current-message)
  2016. (let* ((m (org-agenda-get-any-marker))
  2017. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2018. (when note
  2019. (message (concat
  2020. "FLAGGING-NOTE ([?] for more info): "
  2021. (org-add-props
  2022. (replace-regexp-in-string
  2023. "\\\\n" "//"
  2024. (copy-sequence note))
  2025. nil 'face 'org-warning)))))))
  2026. t t))
  2027. ((equal keys "L")
  2028. (unless (org-mode-p)
  2029. (error "This is not an Org-mode file"))
  2030. (unless restriction
  2031. (put 'org-agenda-files 'org-restrict (list bfn))
  2032. (org-call-with-arg 'org-timeline arg)))
  2033. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2034. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2035. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2036. (t (error "Invalid agenda key"))))))
  2037. (defun org-agenda-append-agenda ()
  2038. "Append another agenda view to the current one.
  2039. This function allows interactive building of block agendas.
  2040. Agenda views are separated by `org-agenda-block-separator'."
  2041. (interactive)
  2042. (let ((org-agenda-multi t))
  2043. (org-agenda)
  2044. (widen)))
  2045. (defun org-agenda-normalize-custom-commands (cmds)
  2046. (delq nil
  2047. (mapcar
  2048. (lambda (x)
  2049. (cond ((stringp (cdr x)) nil)
  2050. ((stringp (nth 1 x)) x)
  2051. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2052. (t (cons (car x) (cons "" (cdr x))))))
  2053. cmds)))
  2054. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2055. "The user interface for selecting an agenda command."
  2056. (catch 'exit
  2057. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2058. (restrict-ok (and bfn (org-mode-p)))
  2059. (region-p (org-region-active-p))
  2060. (custom org-agenda-custom-commands)
  2061. (selstring "")
  2062. restriction second-time
  2063. c entry key type match prefixes rmheader header-end custom1 desc
  2064. line lines left right n n1)
  2065. (save-window-excursion
  2066. (delete-other-windows)
  2067. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2068. (erase-buffer)
  2069. (insert (eval-when-compile
  2070. (let ((header
  2071. "
  2072. Press key for an agenda command: < Buffer, subtree/region restriction
  2073. -------------------------------- > Remove restriction
  2074. a Agenda for current week or day e Export agenda views
  2075. t List of all TODO entries T Entries with special TODO kwd
  2076. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2077. L Timeline for current buffer # List stuck projects (!=configure)
  2078. s Search for keywords C Configure custom agenda commands
  2079. / Multi-occur ? Find :FLAGGED: entries
  2080. ")
  2081. (start 0))
  2082. (while (string-match
  2083. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2084. header start)
  2085. (setq start (match-end 0))
  2086. (add-text-properties (match-beginning 2) (match-end 2)
  2087. '(face bold) header))
  2088. header)))
  2089. (setq header-end (move-marker (make-marker) (point)))
  2090. (while t
  2091. (setq custom1 custom)
  2092. (when (eq rmheader t)
  2093. (org-goto-line 1)
  2094. (re-search-forward ":" nil t)
  2095. (delete-region (match-end 0) (point-at-eol))
  2096. (forward-char 1)
  2097. (looking-at "-+")
  2098. (delete-region (match-end 0) (point-at-eol))
  2099. (move-marker header-end (match-end 0)))
  2100. (goto-char header-end)
  2101. (delete-region (point) (point-max))
  2102. ;; Produce all the lines that describe custom commands and prefixes
  2103. (setq lines nil)
  2104. (while (setq entry (pop custom1))
  2105. (setq key (car entry) desc (nth 1 entry)
  2106. type (nth 2 entry)
  2107. match (nth 3 entry))
  2108. (if (> (length key) 1)
  2109. (add-to-list 'prefixes (string-to-char key))
  2110. (setq line
  2111. (format
  2112. "%-4s%-14s"
  2113. (org-add-props (copy-sequence key)
  2114. '(face bold))
  2115. (cond
  2116. ((string-match "\\S-" desc) desc)
  2117. ((eq type 'agenda) "Agenda for current week or day")
  2118. ((eq type 'alltodo) "List of all TODO entries")
  2119. ((eq type 'search) "Word search")
  2120. ((eq type 'stuck) "List of stuck projects")
  2121. ((eq type 'todo) "TODO keyword")
  2122. ((eq type 'tags) "Tags query")
  2123. ((eq type 'tags-todo) "Tags (TODO)")
  2124. ((eq type 'tags-tree) "Tags tree")
  2125. ((eq type 'todo-tree) "TODO kwd tree")
  2126. ((eq type 'occur-tree) "Occur tree")
  2127. ((functionp type) (if (symbolp type)
  2128. (symbol-name type)
  2129. "Lambda expression"))
  2130. (t "???"))))
  2131. (if org-agenda-menu-show-matcher
  2132. (setq line
  2133. (concat line ": "
  2134. (cond
  2135. ((stringp match)
  2136. (setq match (copy-sequence match))
  2137. (org-add-props match nil 'face 'org-warning))
  2138. (match
  2139. (format "set of %d commands" (length match)))
  2140. (t ""))))
  2141. (if (org-string-nw-p match)
  2142. (add-text-properties
  2143. 0 (length line) (list 'help-echo
  2144. (concat "Matcher: "match)) line)))
  2145. (push line lines)))
  2146. (setq lines (nreverse lines))
  2147. (when prefixes
  2148. (mapc (lambda (x)
  2149. (push
  2150. (format "%s %s"
  2151. (org-add-props (char-to-string x)
  2152. nil 'face 'bold)
  2153. (or (cdr (assoc (concat selstring
  2154. (char-to-string x))
  2155. prefix-descriptions))
  2156. "Prefix key"))
  2157. lines))
  2158. prefixes))
  2159. ;; Check if we should display in two columns
  2160. (if org-agenda-menu-two-column
  2161. (progn
  2162. (setq n (length lines)
  2163. n1 (+ (/ n 2) (mod n 2))
  2164. right (nthcdr n1 lines)
  2165. left (copy-sequence lines))
  2166. (setcdr (nthcdr (1- n1) left) nil))
  2167. (setq left lines right nil))
  2168. (while left
  2169. (insert "\n" (pop left))
  2170. (when right
  2171. (if (< (current-column) 40)
  2172. (move-to-column 40 t)
  2173. (insert " "))
  2174. (insert (pop right))))
  2175. ;; Make the window the right size
  2176. (goto-char (point-min))
  2177. (if second-time
  2178. (if (not (pos-visible-in-window-p (point-max)))
  2179. (org-fit-window-to-buffer))
  2180. (setq second-time t)
  2181. (org-fit-window-to-buffer))
  2182. ;; Ask for selection
  2183. (message "Press key for agenda command%s:"
  2184. (if (or restrict-ok org-agenda-overriding-restriction)
  2185. (if org-agenda-overriding-restriction
  2186. " (restriction lock active)"
  2187. (if restriction
  2188. (format " (restricted to %s)" restriction)
  2189. " (unrestricted)"))
  2190. ""))
  2191. (setq c (read-char-exclusive))
  2192. (message "")
  2193. (cond
  2194. ((assoc (char-to-string c) custom)
  2195. (setq selstring (concat selstring (char-to-string c)))
  2196. (throw 'exit (cons selstring restriction)))
  2197. ((memq c prefixes)
  2198. (setq selstring (concat selstring (char-to-string c))
  2199. prefixes nil
  2200. rmheader (or rmheader t)
  2201. custom (delq nil (mapcar
  2202. (lambda (x)
  2203. (if (or (= (length (car x)) 1)
  2204. (/= (string-to-char (car x)) c))
  2205. nil
  2206. (cons (substring (car x) 1) (cdr x))))
  2207. custom))))
  2208. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2209. (message "Restriction is only possible in Org-mode buffers")
  2210. (ding) (sit-for 1))
  2211. ((eq c ?1)
  2212. (org-agenda-remove-restriction-lock 'noupdate)
  2213. (setq restriction 'buffer))
  2214. ((eq c ?0)
  2215. (org-agenda-remove-restriction-lock 'noupdate)
  2216. (setq restriction (if region-p 'region 'subtree)))
  2217. ((eq c ?<)
  2218. (org-agenda-remove-restriction-lock 'noupdate)
  2219. (setq restriction
  2220. (cond
  2221. ((eq restriction 'buffer)
  2222. (if region-p 'region 'subtree))
  2223. ((memq restriction '(subtree region))
  2224. nil)
  2225. (t 'buffer))))
  2226. ((eq c ?>)
  2227. (org-agenda-remove-restriction-lock 'noupdate)
  2228. (setq restriction nil))
  2229. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2230. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2231. ((and (> (length selstring) 0) (eq c ?\d))
  2232. (delete-window)
  2233. (org-agenda-get-restriction-and-command prefix-descriptions))
  2234. ((equal c ?q) (error "Abort"))
  2235. (t (error "Invalid key %c" c))))))))
  2236. (defun org-run-agenda-series (name series)
  2237. (org-let (nth 1 series) '(org-prepare-agenda name))
  2238. (let* ((org-agenda-multi t)
  2239. (redo (list 'org-run-agenda-series name (list 'quote series)))
  2240. (org-agenda-overriding-arguments
  2241. (or org-agenda-overriding-arguments
  2242. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2243. (get 'org-agenda-redo-command 'last-args))))
  2244. (cmds (car series))
  2245. (gprops (nth 1 series))
  2246. match ;; The byte compiler incorrectly complains about this. Keep it!
  2247. cmd type lprops)
  2248. (while (setq cmd (pop cmds))
  2249. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2250. (cond
  2251. ((eq type 'agenda)
  2252. (org-let2 gprops lprops
  2253. '(call-interactively 'org-agenda-list)))
  2254. ((eq type 'alltodo)
  2255. (org-let2 gprops lprops
  2256. '(call-interactively 'org-todo-list)))
  2257. ((eq type 'search)
  2258. (org-let2 gprops lprops
  2259. '(org-search-view current-prefix-arg match nil)))
  2260. ((eq type 'stuck)
  2261. (org-let2 gprops lprops
  2262. '(call-interactively 'org-agenda-list-stuck-projects)))
  2263. ((eq type 'tags)
  2264. (org-let2 gprops lprops
  2265. '(org-tags-view current-prefix-arg match)))
  2266. ((eq type 'tags-todo)
  2267. (org-let2 gprops lprops
  2268. '(org-tags-view '(4) match)))
  2269. ((eq type 'todo)
  2270. (org-let2 gprops lprops
  2271. '(org-todo-list match)))
  2272. ((fboundp type)
  2273. (org-let2 gprops lprops
  2274. '(funcall type match)))
  2275. (t (error "Invalid type in command series"))))
  2276. (widen)
  2277. (setq org-agenda-redo-command redo)
  2278. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2279. (goto-char (point-min)))
  2280. (org-fit-agenda-window)
  2281. (org-let (nth 1 series) '(org-finalize-agenda)))
  2282. ;;;###autoload
  2283. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2284. "Run an agenda command in batch mode and send the result to STDOUT.
  2285. If CMD-KEY is a string of length 1, it is used as a key in
  2286. `org-agenda-custom-commands' and triggers this command. If it is a
  2287. longer string it is used as a tags/todo match string.
  2288. Parameters are alternating variable names and values that will be bound
  2289. before running the agenda command."
  2290. (let (pars)
  2291. (while parameters
  2292. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2293. (if (> (length cmd-key) 2)
  2294. (eval (list 'let (nreverse pars)
  2295. (list 'org-tags-view nil cmd-key)))
  2296. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2297. (set-buffer org-agenda-buffer-name)
  2298. (princ (org-encode-for-stdout (buffer-string)))))
  2299. ;(defun org-encode-for-stdout (string)
  2300. ; (if (fboundp 'encode-coding-string)
  2301. ; (encode-coding-string string buffer-file-coding-system)
  2302. ; string))
  2303. (defun org-encode-for-stdout (string)
  2304. string)
  2305. (defvar org-agenda-info nil)
  2306. ;;;###autoload
  2307. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2308. "Run an agenda command in batch mode and send the result to STDOUT.
  2309. If CMD-KEY is a string of length 1, it is used as a key in
  2310. `org-agenda-custom-commands' and triggers this command. If it is a
  2311. longer string it is used as a tags/todo match string.
  2312. Parameters are alternating variable names and values that will be bound
  2313. before running the agenda command.
  2314. The output gives a line for each selected agenda item. Each
  2315. item is a list of comma-separated values, like this:
  2316. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2317. category The category of the item
  2318. head The headline, without TODO kwd, TAGS and PRIORITY
  2319. type The type of the agenda entry, can be
  2320. todo selected in TODO match
  2321. tagsmatch selected in tags match
  2322. diary imported from diary
  2323. deadline a deadline on given date
  2324. scheduled scheduled on given date
  2325. timestamp entry has timestamp on given date
  2326. closed entry was closed on given date
  2327. upcoming-deadline warning about deadline
  2328. past-scheduled forwarded scheduled item
  2329. block entry has date block including g. date
  2330. todo The todo keyword, if any
  2331. tags All tags including inherited ones, separated by colons
  2332. date The relevant date, like 2007-2-14
  2333. time The time, like 15:00-16:50
  2334. extra Sting with extra planning info
  2335. priority-l The priority letter if any was given
  2336. priority-n The computed numerical priority
  2337. agenda-day The day in the agenda where this is listed"
  2338. (let (pars)
  2339. (while parameters
  2340. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2341. (push (list 'org-agenda-remove-tags t) pars)
  2342. (if (> (length cmd-key) 2)
  2343. (eval (list 'let (nreverse pars)
  2344. (list 'org-tags-view nil cmd-key)))
  2345. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2346. (set-buffer org-agenda-buffer-name)
  2347. (let* ((lines (org-split-string (buffer-string) "\n"))
  2348. line)
  2349. (while (setq line (pop lines))
  2350. (catch 'next
  2351. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2352. (setq org-agenda-info
  2353. (org-fix-agenda-info (text-properties-at 0 line)))
  2354. (princ
  2355. (org-encode-for-stdout
  2356. (mapconcat 'org-agenda-export-csv-mapper
  2357. '(org-category txt type todo tags date time extra
  2358. priority-letter priority agenda-day)
  2359. ",")))
  2360. (princ "\n"))))))
  2361. (defun org-fix-agenda-info (props)
  2362. "Make sure all properties on an agenda item have a canonical form.
  2363. This ensures the export commands can easily use it."
  2364. (let (tmp re)
  2365. (when (setq tmp (plist-get props 'tags))
  2366. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2367. (when (setq tmp (plist-get props 'date))
  2368. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2369. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2370. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2371. (setq tmp (calendar-date-string tmp)))
  2372. (setq props (plist-put props 'date tmp)))
  2373. (when (setq tmp (plist-get props 'day))
  2374. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2375. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2376. (setq tmp (calendar-date-string tmp)))
  2377. (setq props (plist-put props 'day tmp))
  2378. (setq props (plist-put props 'agenda-day tmp)))
  2379. (when (setq tmp (plist-get props 'txt))
  2380. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2381. (plist-put props 'priority-letter (match-string 1 tmp))
  2382. (setq tmp (replace-match "" t t tmp)))
  2383. (when (and (setq re (plist-get props 'org-todo-regexp))
  2384. (setq re (concat "\\`\\.*" re " ?"))
  2385. (string-match re tmp))
  2386. (plist-put props 'todo (match-string 1 tmp))
  2387. (setq tmp (replace-match "" t t tmp)))
  2388. (plist-put props 'txt tmp)))
  2389. props)
  2390. (defun org-agenda-export-csv-mapper (prop)
  2391. (let ((res (plist-get org-agenda-info prop)))
  2392. (setq res
  2393. (cond
  2394. ((not res) "")
  2395. ((stringp res) res)
  2396. (t (prin1-to-string res))))
  2397. (while (string-match "," res)
  2398. (setq res (replace-match ";" t t res)))
  2399. (org-trim res)))
  2400. ;;;###autoload
  2401. (defun org-store-agenda-views (&rest parameters)
  2402. (interactive)
  2403. (eval (list 'org-batch-store-agenda-views)))
  2404. ;; FIXME, why is this a macro?????
  2405. ;;;###autoload
  2406. (defmacro org-batch-store-agenda-views (&rest parameters)
  2407. "Run all custom agenda commands that have a file argument."
  2408. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2409. (pop-up-frames nil)
  2410. (dir default-directory)
  2411. pars cmd thiscmdkey files opts cmd-or-set)
  2412. (while parameters
  2413. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2414. (setq pars (reverse pars))
  2415. (save-window-excursion
  2416. (while cmds
  2417. (setq cmd (pop cmds)
  2418. thiscmdkey (car cmd)
  2419. cmd-or-set (nth 2 cmd)
  2420. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2421. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2422. (if (stringp files) (setq files (list files)))
  2423. (when files
  2424. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2425. (list 'org-agenda nil thiscmdkey)))
  2426. (set-buffer org-agenda-buffer-name)
  2427. (while files
  2428. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2429. (list 'org-write-agenda
  2430. (expand-file-name (pop files) dir) nil t))))
  2431. (and (get-buffer org-agenda-buffer-name)
  2432. (kill-buffer org-agenda-buffer-name)))))))
  2433. (defun org-agenda-mark-header-line (pos)
  2434. "Mark the line at POS as an agenda structure header."
  2435. (save-excursion
  2436. (goto-char pos)
  2437. (put-text-property (point-at-bol) (point-at-eol)
  2438. 'org-agenda-structural-header t)
  2439. (when org-agenda-title-append
  2440. (put-text-property (point-at-bol) (point-at-eol)
  2441. 'org-agenda-title-append org-agenda-title-append))))
  2442. (defvar org-mobile-creating-agendas)
  2443. (defun org-write-agenda (file &optional open nosettings)
  2444. "Write the current buffer (an agenda view) as a file.
  2445. Depending on the extension of the file name, plain text (.txt),
  2446. HTML (.html or .htm) or Postscript (.ps) is produced.
  2447. If the extension is .ics, run icalendar export over all files used
  2448. to construct the agenda and limit the export to entries listed in the
  2449. agenda now.
  2450. With prefix argument OPEN, open the new file immediately.
  2451. If NOSETTINGS is given, do not scope the settings of
  2452. `org-agenda-exporter-settings' into the export commands. This is used when
  2453. the settings have already been scoped and we do not wish to overrule other,
  2454. higher priority settings."
  2455. (interactive "FWrite agenda to file: \nP")
  2456. (if (not (file-writable-p file))
  2457. (error "Cannot write agenda to file %s" file))
  2458. (org-let (if nosettings nil org-agenda-exporter-settings)
  2459. '(save-excursion
  2460. (save-window-excursion
  2461. (org-agenda-mark-filtered-text)
  2462. (let ((bs (copy-sequence (buffer-string))) beg)
  2463. (org-agenda-unmark-filtered-text)
  2464. (with-temp-buffer
  2465. (rename-buffer "Agenda View" t)
  2466. (set-buffer-modified-p nil)
  2467. (insert bs)
  2468. (org-agenda-remove-marked-text 'org-filtered)
  2469. (while (setq beg (text-property-any (point-min) (point-max)
  2470. 'org-filtered t))
  2471. (delete-region
  2472. beg (or (next-single-property-change beg 'org-filtered)
  2473. (point-max))))
  2474. (run-hooks 'org-agenda-before-write-hook)
  2475. (cond
  2476. ((org-bound-and-true-p org-mobile-creating-agendas)
  2477. (org-mobile-write-agenda-for-mobile file))
  2478. ((string-match "\\.html?\\'" file)
  2479. (require 'htmlize)
  2480. (set-buffer (htmlize-buffer (current-buffer)))
  2481. (when (and org-agenda-export-html-style
  2482. (string-match "<style>" org-agenda-export-html-style))
  2483. ;; replace <style> section with org-agenda-export-html-style
  2484. (goto-char (point-min))
  2485. (kill-region (- (search-forward "<style") 6)
  2486. (search-forward "</style>"))
  2487. (insert org-agenda-export-html-style))
  2488. (write-file file)
  2489. (kill-buffer (current-buffer))
  2490. (message "HTML written to %s" file))
  2491. ((string-match "\\.ps\\'" file)
  2492. (require 'ps-print)
  2493. (ps-print-buffer-with-faces file)
  2494. (message "Postscript written to %s" file))
  2495. ((string-match "\\.pdf\\'" file)
  2496. (require 'ps-print)
  2497. (ps-print-buffer-with-faces
  2498. (concat (file-name-sans-extension file) ".ps"))
  2499. (call-process "ps2pdf" nil nil nil
  2500. (expand-file-name
  2501. (concat (file-name-sans-extension file) ".ps"))
  2502. (expand-file-name file))
  2503. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2504. (message "PDF written to %s" file))
  2505. ((string-match "\\.ics\\'" file)
  2506. (require 'org-icalendar)
  2507. (let ((org-agenda-marker-table
  2508. (org-create-marker-find-array
  2509. (org-agenda-collect-markers)))
  2510. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2511. (org-combined-agenda-icalendar-file file))
  2512. (apply 'org-export-icalendar 'combine
  2513. (org-agenda-files nil 'ifmode))))
  2514. (t
  2515. (let ((bs (buffer-string)))
  2516. (find-file file)
  2517. (erase-buffer)
  2518. (insert bs)
  2519. (save-buffer 0)
  2520. (kill-buffer (current-buffer))
  2521. (message "Plain text written to %s" file))))))))
  2522. (set-buffer org-agenda-buffer-name))
  2523. (when open (org-open-file file)))
  2524. (defvar org-agenda-filter-overlays nil)
  2525. (defun org-agenda-mark-filtered-text ()
  2526. "Mark all text hidden by filtering with a text property."
  2527. (let ((inhibit-read-only t))
  2528. (mapc
  2529. (lambda (o)
  2530. (when (equal (overlay-buffer o) (current-buffer))
  2531. (put-text-property
  2532. (overlay-start o) (overlay-end o)
  2533. 'org-filtered t)))
  2534. org-agenda-filter-overlays)))
  2535. (defun org-agenda-unmark-filtered-text ()
  2536. "Remove the filtering text property."
  2537. (let ((inhibit-read-only t))
  2538. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2539. (defun org-agenda-remove-marked-text (property &optional value)
  2540. "Delete all text marked with VALUE of PROPERTY.
  2541. VALUE defaults to t."
  2542. (let (beg)
  2543. (setq value (or value t))
  2544. (while (setq beg (text-property-any (point-min) (point-max)
  2545. property value))
  2546. (delete-region
  2547. beg (or (next-single-property-change beg 'org-filtered)
  2548. (point-max))))))
  2549. (defun org-agenda-add-entry-text ()
  2550. "Add entry text to agenda lines.
  2551. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2552. entry text following headings shown in the agenda.
  2553. Drawers will be excluded, also the line with scheduling/deadline info."
  2554. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2555. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2556. (let (m txt)
  2557. (goto-char (point-min))
  2558. (while (not (eobp))
  2559. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2560. (beginning-of-line 2)
  2561. (setq txt (org-agenda-get-some-entry-text
  2562. m org-agenda-add-entry-text-maxlines " > "))
  2563. (end-of-line 1)
  2564. (if (string-match "\\S-" txt)
  2565. (insert "\n" txt)
  2566. (or (eobp) (forward-char 1))))))))
  2567. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2568. &rest keep)
  2569. "Extract entry text from MARKER, at most N-LINES lines.
  2570. This will ignore drawers etc, just get the text.
  2571. If INDENT is given, prefix every line with this string. If KEEP is
  2572. given, it is a list of symbols, defining stuff that should not be
  2573. removed from the entry content. Currently only `planning' is allowed here."
  2574. (let (txt drawer-re kwd-time-re ind)
  2575. (save-excursion
  2576. (with-current-buffer (marker-buffer marker)
  2577. (if (not (org-mode-p))
  2578. (setq txt "")
  2579. (save-excursion
  2580. (save-restriction
  2581. (widen)
  2582. (goto-char marker)
  2583. (end-of-line 1)
  2584. (setq txt (buffer-substring
  2585. (min (1+ (point)) (point-max))
  2586. (progn (outline-next-heading) (point)))
  2587. drawer-re org-drawer-regexp
  2588. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2589. ".*\n?"))
  2590. (with-temp-buffer
  2591. (insert txt)
  2592. (when org-agenda-add-entry-text-descriptive-links
  2593. (goto-char (point-min))
  2594. (while (org-activate-bracket-links (point-max))
  2595. (add-text-properties (match-beginning 0) (match-end 0)
  2596. '(face org-link))))
  2597. (goto-char (point-min))
  2598. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2599. (set-text-properties (match-beginning 0) (match-end 0)
  2600. nil))
  2601. (goto-char (point-min))
  2602. (while (re-search-forward drawer-re nil t)
  2603. (delete-region
  2604. (match-beginning 0)
  2605. (progn (re-search-forward
  2606. "^[ \t]*:END:.*\n?" nil 'move)
  2607. (point))))
  2608. (unless (member 'planning keep)
  2609. (goto-char (point-min))
  2610. (while (re-search-forward kwd-time-re nil t)
  2611. (replace-match "")))
  2612. (goto-char (point-min))
  2613. (when org-agenda-entry-text-exclude-regexps
  2614. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2615. (while (setq re (pop re-list))
  2616. (goto-char (point-min))
  2617. (while (re-search-forward re nil t)
  2618. (replace-match "")))))
  2619. (goto-char (point-max))
  2620. (skip-chars-backward " \t\n")
  2621. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2622. ;; find and remove min common indentation
  2623. (goto-char (point-min))
  2624. (untabify (point-min) (point-max))
  2625. (setq ind (org-get-indentation))
  2626. (while (not (eobp))
  2627. (unless (looking-at "[ \t]*$")
  2628. (setq ind (min ind (org-get-indentation))))
  2629. (beginning-of-line 2))
  2630. (goto-char (point-min))
  2631. (while (not (eobp))
  2632. (unless (looking-at "[ \t]*$")
  2633. (move-to-column ind)
  2634. (delete-region (point-at-bol) (point)))
  2635. (beginning-of-line 2))
  2636. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2637. (goto-char (point-min))
  2638. (when indent
  2639. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2640. (replace-match indent t t)))
  2641. (goto-char (point-min))
  2642. (while (looking-at "[ \t]*\n") (replace-match ""))
  2643. (goto-char (point-max))
  2644. (when (> (org-current-line)
  2645. n-lines)
  2646. (org-goto-line (1+ n-lines))
  2647. (backward-char 1))
  2648. (setq txt (buffer-substring (point-min) (point)))))))))
  2649. txt))
  2650. (defun org-agenda-collect-markers ()
  2651. "Collect the markers pointing to entries in the agenda buffer."
  2652. (let (m markers)
  2653. (save-excursion
  2654. (goto-char (point-min))
  2655. (while (not (eobp))
  2656. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2657. (org-get-at-bol 'org-marker)))
  2658. (push m markers))
  2659. (beginning-of-line 2)))
  2660. (nreverse markers)))
  2661. (defun org-create-marker-find-array (marker-list)
  2662. "Create a alist of files names with all marker positions in that file."
  2663. (let (f tbl m a p)
  2664. (while (setq m (pop marker-list))
  2665. (setq p (marker-position m)
  2666. f (buffer-file-name (or (buffer-base-buffer
  2667. (marker-buffer m))
  2668. (marker-buffer m))))
  2669. (if (setq a (assoc f tbl))
  2670. (push (marker-position m) (cdr a))
  2671. (push (list f p) tbl)))
  2672. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2673. tbl)))
  2674. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2675. (defun org-check-agenda-marker-table ()
  2676. "Check of the current entry is on the marker list."
  2677. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2678. a)
  2679. (and (setq a (assoc file org-agenda-marker-table))
  2680. (save-match-data
  2681. (save-excursion
  2682. (org-back-to-heading t)
  2683. (member (point) (cdr a)))))))
  2684. (defun org-check-for-org-mode ()
  2685. "Make sure current buffer is in org-mode. Error if not."
  2686. (or (org-mode-p)
  2687. (error "Cannot execute org-mode agenda command on buffer in %s"
  2688. major-mode)))
  2689. (defun org-fit-agenda-window ()
  2690. "Fit the window to the buffer size."
  2691. (and (memq org-agenda-window-setup '(reorganize-frame))
  2692. (fboundp 'fit-window-to-buffer)
  2693. (org-fit-window-to-buffer
  2694. nil
  2695. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2696. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2697. ;;; Agenda prepare and finalize
  2698. (defvar org-agenda-multi nil) ; dynamically scoped
  2699. (defvar org-agenda-buffer-name "*Org Agenda*")
  2700. (defvar org-pre-agenda-window-conf nil)
  2701. (defvar org-agenda-columns-active nil)
  2702. (defvar org-agenda-name nil)
  2703. (defvar org-agenda-filter nil)
  2704. (defvar org-agenda-filter-while-redo nil)
  2705. (defvar org-agenda-filter-preset nil
  2706. "A preset of the tags filter used for secondary agenda filtering.
  2707. This must be a list of strings, each string must be a single tag preceded
  2708. by \"+\" or \"-\".
  2709. This variable should not be set directly, but agenda custom commands can
  2710. bind it in the options section. The preset filter is a global property of
  2711. the entire agenda view. In a block agenda, it will not work reliably to
  2712. define a filter for one of the individual blocks. You need to set it in
  2713. the global options and expect it to be applied to the entire view.")
  2714. (defun org-prepare-agenda (&optional name)
  2715. (setq org-todo-keywords-for-agenda nil)
  2716. (setq org-done-keywords-for-agenda nil)
  2717. (setq org-drawers-for-agenda nil)
  2718. (unless org-agenda-persistent-filter
  2719. (setq org-agenda-filter nil))
  2720. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2721. (if org-agenda-multi
  2722. (progn
  2723. (setq buffer-read-only nil)
  2724. (goto-char (point-max))
  2725. (unless (or (bobp) org-agenda-compact-blocks)
  2726. (insert "\n"
  2727. (if (stringp org-agenda-block-separator)
  2728. org-agenda-block-separator
  2729. (make-string (window-width) org-agenda-block-separator))
  2730. "\n"))
  2731. (narrow-to-region (point) (point-max)))
  2732. (org-agenda-reset-markers)
  2733. (setq org-agenda-contributing-files nil)
  2734. (setq org-agenda-columns-active nil)
  2735. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2736. (setq org-todo-keywords-for-agenda
  2737. (org-uniquify org-todo-keywords-for-agenda))
  2738. (setq org-done-keywords-for-agenda
  2739. (org-uniquify org-done-keywords-for-agenda))
  2740. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2741. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2742. (awin (get-buffer-window abuf)))
  2743. (cond
  2744. ((equal (current-buffer) abuf) nil)
  2745. (awin (select-window awin))
  2746. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2747. ((equal org-agenda-window-setup 'current-window)
  2748. (switch-to-buffer abuf))
  2749. ((equal org-agenda-window-setup 'other-window)
  2750. (org-switch-to-buffer-other-window abuf))
  2751. ((equal org-agenda-window-setup 'other-frame)
  2752. (switch-to-buffer-other-frame abuf))
  2753. ((equal org-agenda-window-setup 'reorganize-frame)
  2754. (delete-other-windows)
  2755. (org-switch-to-buffer-other-window abuf)))
  2756. ;; additional test in case agenda is invoked from within agenda
  2757. ;; buffer via elisp link
  2758. (unless (equal (current-buffer) abuf)
  2759. (switch-to-buffer abuf)))
  2760. (setq buffer-read-only nil)
  2761. (let ((inhibit-read-only t)) (erase-buffer))
  2762. (org-agenda-mode)
  2763. (and name (not org-agenda-name)
  2764. (org-set-local 'org-agenda-name name)))
  2765. (setq buffer-read-only nil))
  2766. (defun org-finalize-agenda ()
  2767. "Finishing touch for the agenda buffer, called just before displaying it."
  2768. (unless org-agenda-multi
  2769. (save-excursion
  2770. (let ((inhibit-read-only t))
  2771. (goto-char (point-min))
  2772. (while (org-activate-bracket-links (point-max))
  2773. (add-text-properties (match-beginning 0) (match-end 0)
  2774. '(face org-link)))
  2775. (org-agenda-align-tags)
  2776. (unless org-agenda-with-colors
  2777. (remove-text-properties (point-min) (point-max) '(face nil))))
  2778. (if (and (boundp 'org-agenda-overriding-columns-format)
  2779. org-agenda-overriding-columns-format)
  2780. (org-set-local 'org-agenda-overriding-columns-format
  2781. org-agenda-overriding-columns-format))
  2782. (if (and (boundp 'org-agenda-view-columns-initially)
  2783. org-agenda-view-columns-initially)
  2784. (org-agenda-columns))
  2785. (when org-agenda-fontify-priorities
  2786. (org-agenda-fontify-priorities))
  2787. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2788. (org-agenda-dim-blocked-tasks))
  2789. (org-agenda-mark-clocking-task)
  2790. (when org-agenda-entry-text-mode
  2791. (org-agenda-entry-text-hide)
  2792. (org-agenda-entry-text-show))
  2793. (if (functionp 'org-habit-insert-consistency-graphs)
  2794. (org-habit-insert-consistency-graphs))
  2795. (run-hooks 'org-finalize-agenda-hook)
  2796. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2797. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2798. (org-agenda-filter-apply org-agenda-filter))
  2799. )))
  2800. (defun org-agenda-mark-clocking-task ()
  2801. "Mark the current clock entry in the agenda if it is present."
  2802. (mapc (lambda (o)
  2803. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2804. (delete-overlay o)))
  2805. (overlays-in (point-min) (point-max)))
  2806. (when (marker-buffer org-clock-hd-marker)
  2807. (save-excursion
  2808. (goto-char (point-min))
  2809. (let (s ov)
  2810. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2811. (goto-char s)
  2812. (when (equal (org-get-at-bol 'org-hd-marker)
  2813. org-clock-hd-marker)
  2814. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2815. (overlay-put ov 'type 'org-agenda-clocking)
  2816. (overlay-put ov 'face 'org-agenda-clocking)
  2817. (overlay-put ov 'help-echo
  2818. "The clock is running in this item")))))))
  2819. (defun org-agenda-fontify-priorities ()
  2820. "Make highest priority lines bold, and lowest italic."
  2821. (interactive)
  2822. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2823. (delete-overlay o)))
  2824. (overlays-in (point-min) (point-max)))
  2825. (save-excursion
  2826. (let ((inhibit-read-only t)
  2827. b e p ov h l)
  2828. (goto-char (point-min))
  2829. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2830. (setq h (or (get-char-property (point) 'org-highest-priority)
  2831. org-highest-priority)
  2832. l (or (get-char-property (point) 'org-lowest-priority)
  2833. org-lowest-priority)
  2834. p (string-to-char (match-string 1))
  2835. b (match-beginning 0)
  2836. e (if (eq org-agenda-fontify-priorities 'cookies)
  2837. (match-end 0)
  2838. (point-at-eol))
  2839. ov (make-overlay b e))
  2840. (overlay-put
  2841. ov 'face
  2842. (cond ((org-face-from-face-or-color
  2843. 'priority nil
  2844. (cdr (assoc p org-priority-faces))))
  2845. ((and (listp org-agenda-fontify-priorities)
  2846. (org-face-from-face-or-color
  2847. 'priority nil
  2848. (cdr (assoc p org-agenda-fontify-priorities)))))
  2849. ((equal p l) 'italic)
  2850. ((equal p h) 'bold)))
  2851. (overlay-put ov 'org-type 'org-priority)))))
  2852. (defun org-agenda-dim-blocked-tasks ()
  2853. "Dim currently blocked TODO's in the agenda display."
  2854. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2855. (delete-overlay o)))
  2856. (overlays-in (point-min) (point-max)))
  2857. (save-excursion
  2858. (let ((inhibit-read-only t)
  2859. (org-depend-tag-blocked nil)
  2860. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2861. org-blocked-by-checkboxes
  2862. invis1 b e p ov h l)
  2863. (goto-char (point-min))
  2864. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2865. (and pos (goto-char (1+ pos))))
  2866. (setq org-blocked-by-checkboxes nil invis1 invis)
  2867. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2868. (when (and marker
  2869. (not (with-current-buffer (marker-buffer marker)
  2870. (save-excursion
  2871. (goto-char marker)
  2872. (if (org-entry-get nil "NOBLOCKING")
  2873. t ;; Never block this entry
  2874. (run-hook-with-args-until-failure
  2875. 'org-blocker-hook
  2876. (list :type 'todo-state-change
  2877. :position marker
  2878. :from 'todo
  2879. :to 'done)))))))
  2880. (if org-blocked-by-checkboxes (setq invis1 nil))
  2881. (setq b (if invis1
  2882. (max (point-min) (1- (point-at-bol)))
  2883. (point-at-bol))
  2884. e (point-at-eol)
  2885. ov (make-overlay b e))
  2886. (if invis1
  2887. (overlay-put ov 'invisible t)
  2888. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2889. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2890. (defvar org-agenda-skip-function nil
  2891. "Function to be called at each match during agenda construction.
  2892. If this function returns nil, the current match should not be skipped.
  2893. Otherwise, the function must return a position from where the search
  2894. should be continued.
  2895. This may also be a Lisp form, it will be evaluated.
  2896. Never set this variable using `setq' or so, because then it will apply
  2897. to all future agenda commands. If you do want a global skipping condition,
  2898. use the option `org-agenda-skip-function-global' instead.
  2899. The correct usage for `org-agenda-skip-function' is to bind it with
  2900. `let' to scope it dynamically into the agenda-constructing command.
  2901. A good way to set it is through options in `org-agenda-custom-commands'.")
  2902. (defun org-agenda-skip ()
  2903. "Throw to `:skip' in places that should be skipped.
  2904. Also moves point to the end of the skipped region, so that search can
  2905. continue from there."
  2906. (let ((p (point-at-bol)) to)
  2907. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2908. (get-text-property p :org-archived)
  2909. (org-end-of-subtree t)
  2910. (throw :skip t))
  2911. (and org-agenda-skip-comment-trees
  2912. (get-text-property p :org-comment)
  2913. (org-end-of-subtree t)
  2914. (throw :skip t))
  2915. (if (equal (char-after p) ?#) (throw :skip t))
  2916. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  2917. (org-agenda-skip-eval org-agenda-skip-function)))
  2918. (goto-char to)
  2919. (throw :skip t))))
  2920. (defun org-agenda-skip-eval (form)
  2921. "If FORM is a function or a list, call (or eval) is and return result.
  2922. `save-excursion' and `save-match-data' are wrapped around the call, so point
  2923. and match data are returned to the previous state no matter what these
  2924. functions do."
  2925. (let (fp)
  2926. (and form
  2927. (or (setq fp (functionp form))
  2928. (consp form))
  2929. (save-excursion
  2930. (save-match-data
  2931. (if fp
  2932. (funcall form)
  2933. (eval form)))))))
  2934. (defvar org-agenda-markers nil
  2935. "List of all currently active markers created by `org-agenda'.")
  2936. (defvar org-agenda-last-marker-time (org-float-time)
  2937. "Creation time of the last agenda marker.")
  2938. (defun org-agenda-new-marker (&optional pos)
  2939. "Return a new agenda marker.
  2940. Org-mode keeps a list of these markers and resets them when they are
  2941. no longer in use."
  2942. (let ((m (copy-marker (or pos (point)))))
  2943. (setq org-agenda-last-marker-time (org-float-time))
  2944. (push m org-agenda-markers)
  2945. m))
  2946. (defun org-agenda-reset-markers ()
  2947. "Reset markers created by `org-agenda'."
  2948. (while org-agenda-markers
  2949. (move-marker (pop org-agenda-markers) nil)))
  2950. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2951. "Save relative positions of markers in region."
  2952. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2953. org-agenda-markers))
  2954. ;;; Entry text mode
  2955. (defun org-agenda-entry-text-show-here ()
  2956. "Add some text from the entry as context to the current line."
  2957. (let (m txt o)
  2958. (setq m (org-get-at-bol 'org-hd-marker))
  2959. (unless (marker-buffer m)
  2960. (error "No marker points to an entry here"))
  2961. (setq txt (concat "\n" (org-no-properties
  2962. (org-agenda-get-some-entry-text
  2963. m org-agenda-entry-text-maxlines " > "))))
  2964. (when (string-match "\\S-" txt)
  2965. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  2966. (overlay-put o 'evaporate t)
  2967. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  2968. (overlay-put o 'after-string txt))))
  2969. (defun org-agenda-entry-text-show ()
  2970. "Add entry context for all agenda lines."
  2971. (interactive)
  2972. (save-excursion
  2973. (goto-char (point-max))
  2974. (beginning-of-line 1)
  2975. (while (not (bobp))
  2976. (when (org-get-at-bol 'org-hd-marker)
  2977. (org-agenda-entry-text-show-here))
  2978. (beginning-of-line 0))))
  2979. (defun org-agenda-entry-text-hide ()
  2980. "Remove any shown entry context."
  2981. (delq nil
  2982. (mapcar (lambda (o)
  2983. (if (eq (overlay-get o 'org-overlay-type)
  2984. 'agenda-entry-content)
  2985. (progn (delete-overlay o) t)))
  2986. (overlays-in (point-min) (point-max)))))
  2987. (defun org-agenda-get-day-face (date)
  2988. "Return the face DATE should be displayed with."
  2989. (or (and (functionp org-agenda-day-face-function)
  2990. (funcall org-agenda-day-face-function date))
  2991. (cond ((org-agenda-todayp date)
  2992. 'org-agenda-date-today)
  2993. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  2994. 'org-agenda-date-weekend)
  2995. (t 'org-agenda-date))))
  2996. ;;; Agenda timeline
  2997. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  2998. (defun org-timeline (&optional include-all)
  2999. "Show a time-sorted view of the entries in the current org file.
  3000. Only entries with a time stamp of today or later will be listed. With
  3001. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3002. under the current date.
  3003. If the buffer contains an active region, only check the region for
  3004. dates."
  3005. (interactive "P")
  3006. (org-compile-prefix-format 'timeline)
  3007. (org-set-sorting-strategy 'timeline)
  3008. (let* ((dopast t)
  3009. (dotodo include-all)
  3010. (doclosed org-agenda-show-log)
  3011. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3012. (current-buffer))))
  3013. (date (calendar-current-date))
  3014. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3015. (end (if (org-region-active-p) (region-end) (point-max)))
  3016. (day-numbers (org-get-all-dates beg end 'no-ranges
  3017. t doclosed ; always include today
  3018. org-timeline-show-empty-dates))
  3019. (org-deadline-warning-days 0)
  3020. (org-agenda-only-exact-dates t)
  3021. (today (org-today))
  3022. (past t)
  3023. args
  3024. s e rtn d emptyp)
  3025. (setq org-agenda-redo-command
  3026. (list 'progn
  3027. (list 'org-switch-to-buffer-other-window (current-buffer))
  3028. (list 'org-timeline (list 'quote include-all))))
  3029. (if (not dopast)
  3030. ;; Remove past dates from the list of dates.
  3031. (setq day-numbers (delq nil (mapcar (lambda(x)
  3032. (if (>= x today) x nil))
  3033. day-numbers))))
  3034. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3035. (if doclosed (push :closed args))
  3036. (push :timestamp args)
  3037. (push :deadline args)
  3038. (push :scheduled args)
  3039. (push :sexp args)
  3040. (if dotodo (push :todo args))
  3041. (insert "Timeline of file " entry "\n")
  3042. (add-text-properties (point-min) (point)
  3043. (list 'face 'org-agenda-structure))
  3044. (org-agenda-mark-header-line (point-min))
  3045. (while (setq d (pop day-numbers))
  3046. (if (and (listp d) (eq (car d) :omitted))
  3047. (progn
  3048. (setq s (point))
  3049. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3050. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3051. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3052. (if (and (>= d today)
  3053. dopast
  3054. past)
  3055. (progn
  3056. (setq past nil)
  3057. (insert (make-string 79 ?-) "\n")))
  3058. (setq date (calendar-gregorian-from-absolute d))
  3059. (setq s (point))
  3060. (setq rtn (and (not emptyp)
  3061. (apply 'org-agenda-get-day-entries entry
  3062. date args)))
  3063. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3064. (progn
  3065. (insert
  3066. (if (stringp org-agenda-format-date)
  3067. (format-time-string org-agenda-format-date
  3068. (org-time-from-absolute date))
  3069. (funcall org-agenda-format-date date))
  3070. "\n")
  3071. (put-text-property s (1- (point)) 'face
  3072. (org-agenda-get-day-face date))
  3073. (put-text-property s (1- (point)) 'org-date-line t)
  3074. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3075. (if (equal d today)
  3076. (put-text-property s (1- (point)) 'org-today t))
  3077. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3078. (put-text-property s (1- (point)) 'day d)))))
  3079. (goto-char (point-min))
  3080. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3081. (point-min)))
  3082. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3083. (org-finalize-agenda)
  3084. (setq buffer-read-only t)))
  3085. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3086. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3087. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3088. not every single day in the range. If FORCE-TODAY is non-nil, make
  3089. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3090. inactive time stamps (those in square brackets) are included.
  3091. When EMPTY is non-nil, also include days without any entries."
  3092. (let ((re (concat
  3093. (if pre-re pre-re "")
  3094. (if inactive org-ts-regexp-both org-ts-regexp)))
  3095. dates dates1 date day day1 day2 ts1 ts2)
  3096. (if force-today
  3097. (setq dates (list (org-today))))
  3098. (save-excursion
  3099. (goto-char beg)
  3100. (while (re-search-forward re end t)
  3101. (setq day (time-to-days (org-time-string-to-time
  3102. (substring (match-string 1) 0 10))))
  3103. (or (memq day dates) (push day dates)))
  3104. (unless no-ranges
  3105. (goto-char beg)
  3106. (while (re-search-forward org-tr-regexp end t)
  3107. (setq ts1 (substring (match-string 1) 0 10)
  3108. ts2 (substring (match-string 2) 0 10)
  3109. day1 (time-to-days (org-time-string-to-time ts1))
  3110. day2 (time-to-days (org-time-string-to-time ts2)))
  3111. (while (< (setq day1 (1+ day1)) day2)
  3112. (or (memq day1 dates) (push day1 dates)))))
  3113. (setq dates (sort dates '<))
  3114. (when empty
  3115. (while (setq day (pop dates))
  3116. (setq day2 (car dates))
  3117. (push day dates1)
  3118. (when (and day2 empty)
  3119. (if (or (eq empty t)
  3120. (and (numberp empty) (<= (- day2 day) empty)))
  3121. (while (< (setq day (1+ day)) day2)
  3122. (push (list day) dates1))
  3123. (push (cons :omitted (- day2 day)) dates1))))
  3124. (setq dates (nreverse dates1)))
  3125. dates)))
  3126. ;;; Agenda Daily/Weekly
  3127. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  3128. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3129. "Custom commands can set this variable in the options section.")
  3130. (defvar org-agenda-last-arguments nil
  3131. "The arguments of the previous call to `org-agenda'.")
  3132. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3133. (defvar org-agenda-current-span nil
  3134. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3135. (defvar org-include-all-loc nil) ; local variable
  3136. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3137. "List of types searched for when creating the daily/weekly agenda.
  3138. This variable is a list of symbols that controls the types of
  3139. items that appear in the daily/weekly agenda. Allowed symbols in this
  3140. list are are
  3141. :timestamp List items containing a date stamp or date range matching
  3142. the selected date. This includes sexp entries in
  3143. angular brackets.
  3144. :sexp List entries resulting from plain diary-like sexps.
  3145. :deadline List deadline due on that date. When the date is today,
  3146. also list any deadlines past due, or due within
  3147. `org-deadline-warning-days'. `:deadline' must appear before
  3148. `:scheduled' if the setting of
  3149. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3150. any effect.
  3151. :scheduled List all items which are scheduled for the given date.
  3152. The diary for *today* also contains items which were
  3153. scheduled earlier and are not yet marked DONE.
  3154. By default, all four types are turned on.
  3155. Never set this variable globally using `setq', because then it
  3156. will apply to all future agenda commands. Instead, bind it with
  3157. `let' to scope it dynamically into the the agenda-constructing
  3158. command. A good way to set it is through options in
  3159. `org-agenda-custom-commands'. For a more flexible (though
  3160. somewhat less efficient) way of determining what is included in
  3161. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3162. ;;;###autoload
  3163. (defun org-agenda-list (&optional include-all start-day span)
  3164. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3165. The view will be for the current day or week, but from the overview buffer
  3166. you will be able to go to other days/weeks.
  3167. With one \\[universal-argument] prefix argument INCLUDE-ALL,
  3168. all unfinished TODO items will also be shown, before the agenda.
  3169. This feature is considered obsolete, please use the TODO list or a block
  3170. agenda instead.
  3171. With a numeric prefix argument in an interactive call, the agenda will
  3172. span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
  3173. the number of days. SPAN defaults to `org-agenda-span'.
  3174. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3175. given in `org-agenda-start-on-weekday'."
  3176. (interactive "P")
  3177. (if (and (integerp include-all) (> include-all 0))
  3178. (setq span include-all include-all nil))
  3179. (setq start-day (or start-day org-agenda-start-day))
  3180. (if org-agenda-overriding-arguments
  3181. (setq include-all (car org-agenda-overriding-arguments)
  3182. start-day (nth 1 org-agenda-overriding-arguments)
  3183. span (nth 2 org-agenda-overriding-arguments)))
  3184. (if (stringp start-day)
  3185. ;; Convert to an absolute day number
  3186. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3187. (setq org-agenda-last-arguments (list include-all start-day span))
  3188. (org-compile-prefix-format 'agenda)
  3189. (org-set-sorting-strategy 'agenda)
  3190. (let* ((span (org-agenda-ndays-to-span (or span
  3191. org-agenda-current-span
  3192. org-agenda-ndays
  3193. org-agenda-span)))
  3194. (today (org-today))
  3195. (sd (or start-day today))
  3196. (ndays (org-agenda-span-to-ndays span sd))
  3197. (org-agenda-start-on-weekday
  3198. (if (eq ndays 7)
  3199. org-agenda-start-on-weekday))
  3200. (thefiles (org-agenda-files nil 'ifmode))
  3201. (files thefiles)
  3202. (start (if (or (null org-agenda-start-on-weekday)
  3203. (< ndays 7))
  3204. sd
  3205. (let* ((nt (calendar-day-of-week
  3206. (calendar-gregorian-from-absolute sd)))
  3207. (n1 org-agenda-start-on-weekday)
  3208. (d (- nt n1)))
  3209. (- sd (+ (if (< d 0) 7 0) d)))))
  3210. (day-numbers (list start))
  3211. (day-cnt 0)
  3212. (inhibit-redisplay (not debug-on-error))
  3213. s e rtn rtnall file date d start-pos end-pos todayp
  3214. clocktable-start clocktable-end filter)
  3215. (setq org-agenda-redo-command
  3216. (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
  3217. (dotimes (n (1- ndays))
  3218. (push (1+ (car day-numbers)) day-numbers))
  3219. (setq day-numbers (nreverse day-numbers))
  3220. (setq clocktable-start (car day-numbers)
  3221. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3222. (org-prepare-agenda "Day/Week")
  3223. (org-set-local 'org-starting-day (car day-numbers))
  3224. (org-set-local 'org-include-all-loc include-all)
  3225. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3226. (when (and (or include-all org-agenda-include-all-todo)
  3227. (member today day-numbers))
  3228. (setq files thefiles
  3229. rtnall nil)
  3230. (while (setq file (pop files))
  3231. (catch 'nextfile
  3232. (org-check-agenda-file file)
  3233. (setq date (calendar-gregorian-from-absolute today)
  3234. rtn (org-agenda-get-day-entries
  3235. file date :todo))
  3236. (setq rtnall (append rtnall rtn))))
  3237. (when rtnall
  3238. (insert "All currently open TODO items:\n")
  3239. (add-text-properties (point-min) (1- (point))
  3240. (list 'face 'org-agenda-structure
  3241. 'short-heading "All TODO items"))
  3242. (org-agenda-mark-header-line (point-min))
  3243. (insert (org-finalize-agenda-entries rtnall) "\n")))
  3244. (unless org-agenda-compact-blocks
  3245. (let* ((d1 (car day-numbers))
  3246. (d2 (org-last day-numbers))
  3247. (w1 (org-days-to-iso-week d1))
  3248. (w2 (org-days-to-iso-week d2)))
  3249. (setq s (point))
  3250. (if org-agenda-overriding-header
  3251. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3252. nil 'face 'org-agenda-structure) "\n")
  3253. (insert (org-agenda-span-name span)
  3254. "-agenda"
  3255. (if (< (- d2 d1) 350)
  3256. (if (= w1 w2)
  3257. (format " (W%02d)" w1)
  3258. (format " (W%02d-W%02d)" w1 w2))
  3259. "")
  3260. ":\n")))
  3261. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3262. 'org-date-line t))
  3263. (org-agenda-mark-header-line s))
  3264. (while (setq d (pop day-numbers))
  3265. (setq date (calendar-gregorian-from-absolute d)
  3266. s (point))
  3267. (if (or (setq todayp (= d today))
  3268. (and (not start-pos) (= d sd)))
  3269. (setq start-pos (point))
  3270. (if (and start-pos (not end-pos))
  3271. (setq end-pos (point))))
  3272. (setq files thefiles
  3273. rtnall nil)
  3274. (while (setq file (pop files))
  3275. (catch 'nextfile
  3276. (org-check-agenda-file file)
  3277. (let ((org-agenda-entry-types org-agenda-entry-types))
  3278. (unless org-agenda-include-deadlines
  3279. (setq org-agenda-entry-types
  3280. (delq :deadline org-agenda-entry-types)))
  3281. (cond
  3282. ((eq org-agenda-show-log 'only)
  3283. (setq rtn (org-agenda-get-day-entries
  3284. file date :closed)))
  3285. (org-agenda-show-log
  3286. (setq rtn (apply 'org-agenda-get-day-entries
  3287. file date
  3288. (append '(:closed) org-agenda-entry-types))))
  3289. (t
  3290. (setq rtn (apply 'org-agenda-get-day-entries
  3291. file date
  3292. org-agenda-entry-types)))))
  3293. (setq rtnall (append rtnall rtn))))
  3294. (if org-agenda-include-diary
  3295. (let ((org-agenda-search-headline-for-time t))
  3296. (require 'diary-lib)
  3297. (setq rtn (org-get-entries-from-diary date))
  3298. (setq rtnall (append rtnall rtn))))
  3299. (if (or rtnall org-agenda-show-all-dates)
  3300. (progn
  3301. (setq day-cnt (1+ day-cnt))
  3302. (insert
  3303. (if (stringp org-agenda-format-date)
  3304. (format-time-string org-agenda-format-date
  3305. (org-time-from-absolute date))
  3306. (funcall org-agenda-format-date date))
  3307. "\n")
  3308. (put-text-property s (1- (point)) 'face
  3309. (org-agenda-get-day-face date))
  3310. (put-text-property s (1- (point)) 'org-date-line t)
  3311. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3312. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3313. (when todayp
  3314. (put-text-property s (1- (point)) 'org-today t))
  3315. (if rtnall (insert
  3316. (org-finalize-agenda-entries
  3317. (org-agenda-add-time-grid-maybe
  3318. rtnall ndays todayp))
  3319. "\n"))
  3320. (put-text-property s (1- (point)) 'day d)
  3321. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3322. (when (and org-agenda-clockreport-mode clocktable-start)
  3323. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3324. ;; the above line is to ensure the restricted range!
  3325. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3326. tbl)
  3327. (setq p (org-plist-delete p :block))
  3328. (setq p (plist-put p :tstart clocktable-start))
  3329. (setq p (plist-put p :tend clocktable-end))
  3330. (setq p (plist-put p :scope 'agenda))
  3331. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3332. (setq filter (or org-agenda-filter-while-redo
  3333. (get 'org-agenda-filter :preset-filter))))
  3334. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3335. (if (string-match "[<>=]" x)
  3336. ""
  3337. x))
  3338. filter ""))))
  3339. (setq tbl (apply 'org-get-clocktable p))
  3340. (insert tbl)))
  3341. (goto-char (point-min))
  3342. (or org-agenda-multi (org-fit-agenda-window))
  3343. (unless (and (pos-visible-in-window-p (point-min))
  3344. (pos-visible-in-window-p (point-max)))
  3345. (goto-char (1- (point-max)))
  3346. (recenter -1)
  3347. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3348. (progn
  3349. (goto-char (or start-pos 1))
  3350. (recenter 1))))
  3351. (goto-char (or start-pos 1))
  3352. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3353. (org-finalize-agenda)
  3354. (setq buffer-read-only t)
  3355. (message "")))
  3356. (defun org-agenda-ndays-to-span (n)
  3357. "Return a span symbol for a span of N days, or N if none matches."
  3358. (cond ((symbolp n) n)
  3359. ((= n 1) 'day)
  3360. ((= n 7) 'week)
  3361. (t n)))
  3362. (defun org-agenda-span-to-ndays (span start-day)
  3363. "Return ndays from SPAN starting at START-DAY."
  3364. (cond ((numberp span) span)
  3365. ((eq span 'day) 1)
  3366. ((eq span 'week) 7)
  3367. ((eq span 'month)
  3368. (let ((date (calendar-gregorian-from-absolute start-day)))
  3369. (calendar-last-day-of-month (car date) (caddr date))))
  3370. ((eq span 'year)
  3371. (let ((date (calendar-gregorian-from-absolute start-day)))
  3372. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3373. (defun org-agenda-span-name (span)
  3374. "Return a SPAN name."
  3375. (if (null span)
  3376. ""
  3377. (if (symbolp span)
  3378. (capitalize (symbol-name span))
  3379. (format "%d days" span))))
  3380. ;;; Agenda word search
  3381. (defvar org-agenda-search-history nil)
  3382. (defvar org-todo-only nil)
  3383. (defvar org-search-syntax-table nil
  3384. "Special syntax table for org-mode search.
  3385. In this table, we have single quotes not as word constituents, to
  3386. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3387. (defun org-search-syntax-table ()
  3388. (unless org-search-syntax-table
  3389. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3390. (modify-syntax-entry ?' "." org-search-syntax-table)
  3391. (modify-syntax-entry ?` "." org-search-syntax-table))
  3392. org-search-syntax-table)
  3393. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3394. ;;;###autoload
  3395. (defun org-search-view (&optional todo-only string edit-at)
  3396. "Show all entries that contain a phrase or words or regular expressions.
  3397. With optional prefix argument TODO-ONLY, only consider entries that are
  3398. TODO entries. The argument STRING can be used to pass a default search
  3399. string into this function. If EDIT-AT is non-nil, it means that the
  3400. user should get a chance to edit this string, with cursor at position
  3401. EDIT-AT.
  3402. The search string can be viewed either as a phrase that should be found as
  3403. is, or it can be broken into a number of snippets, each of which must match
  3404. in a Boolean way to select an entry. The default depends on the variable
  3405. `org-agenda-search-view-always-boolean'.
  3406. Even if this is turned off (the default) you can always switch to
  3407. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3408. The default is a direct search of the whole phrase, where each space in
  3409. the search string can expand to an arbitrary amount of whitespace,
  3410. including newlines.
  3411. If using a Boolean search, the search string is split on whitespace and
  3412. each snippet is searched separately, with logical AND to select an entry.
  3413. Words prefixed with a minus must *not* occur in the entry. Words without
  3414. a prefix or prefixed with a plus must occur in the entry. Matching is
  3415. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3416. match whole words, not parts of a word) if
  3417. `org-agenda-search-view-force-full-words' is set (default is nil).
  3418. Boolean search snippets enclosed by curly braces are interpreted as
  3419. regular expressions that must or (when preceded with \"-\") must not
  3420. match in the entry. Snippets enclosed into double quotes will be taken
  3421. as a whole, to include whitespace.
  3422. - If the search string starts with an asterisk, search only in headlines.
  3423. - If (possibly after the leading star) the search string starts with an
  3424. exclamation mark, this also means to look at TODO entries only, an effect
  3425. that can also be achieved with a prefix argument.
  3426. - If (possibly after star and exclamation mark) the search string starts
  3427. with a colon, this will mean that the (non-regexp) snippets of the
  3428. Boolean search must match as full words.
  3429. This command searches the agenda files, and in addition the files listed
  3430. in `org-agenda-text-search-extra-files'."
  3431. (interactive "P")
  3432. (org-compile-prefix-format 'search)
  3433. (org-set-sorting-strategy 'search)
  3434. (org-prepare-agenda "SEARCH")
  3435. (let* ((props (list 'face nil
  3436. 'done-face 'org-agenda-done
  3437. 'org-not-done-regexp org-not-done-regexp
  3438. 'org-todo-regexp org-todo-regexp
  3439. 'org-complex-heading-regexp org-complex-heading-regexp
  3440. 'mouse-face 'highlight
  3441. 'help-echo (format "mouse-2 or RET jump to location")))
  3442. (full-words org-agenda-search-view-force-full-words)
  3443. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3444. regexp rtn rtnall files file pos
  3445. marker category tags c neg re boolean
  3446. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3447. (unless (and (not edit-at)
  3448. (stringp string)
  3449. (string-match "\\S-" string))
  3450. (setq string (read-string
  3451. (if org-agenda-search-view-always-boolean
  3452. "[+-]Word/{Regexp} ...: "
  3453. "Phrase, or [+-]Word/{Regexp} ...: ")
  3454. (cond
  3455. ((integerp edit-at) (cons string edit-at))
  3456. (edit-at string))
  3457. 'org-agenda-search-history)))
  3458. (org-set-local 'org-todo-only todo-only)
  3459. (setq org-agenda-redo-command
  3460. (list 'org-search-view (if todo-only t nil) string
  3461. '(if current-prefix-arg 1 nil)))
  3462. (setq org-agenda-query-string string)
  3463. (if (equal (string-to-char string) ?*)
  3464. (setq hdl-only t
  3465. words (substring string 1))
  3466. (setq words string))
  3467. (when (equal (string-to-char words) ?!)
  3468. (setq todo-only t
  3469. words (substring words 1)))
  3470. (when (equal (string-to-char words) ?:)
  3471. (setq full-words t
  3472. words (substring words 1)))
  3473. (if (or org-agenda-search-view-always-boolean
  3474. (member (string-to-char words) '(?- ?+ ?\{)))
  3475. (setq boolean t))
  3476. (setq words (org-split-string words))
  3477. (let (www w)
  3478. (while (setq w (pop words))
  3479. (while (and (string-match "\\\\\\'" w) words)
  3480. (setq w (concat (substring w 0 -1) " " (pop words))))
  3481. (push w www))
  3482. (setq words (nreverse www) www nil)
  3483. (while (setq w (pop words))
  3484. (when (and (string-match "\\`[-+]?{" w)
  3485. (not (string-match "}\\'" w)))
  3486. (while (and words (not (string-match "}\\'" (car words))))
  3487. (setq w (concat w " " (pop words))))
  3488. (setq w (concat w " " (pop words))))
  3489. (push w www))
  3490. (setq words (nreverse www)))
  3491. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3492. (when boolean
  3493. (let (wds w)
  3494. (while (setq w (pop words))
  3495. (if (or (equal (substring w 0 1) "\"")
  3496. (and (> (length w) 1)
  3497. (member (substring w 0 1) '("+" "-"))
  3498. (equal (substring w 1 2) "\"")))
  3499. (while (and words (not (equal (substring w -1) "\"")))
  3500. (setq w (concat w " " (pop words)))))
  3501. (and (string-match "\\`\\([-+]?\\)\"" w)
  3502. (setq w (replace-match "\\1" nil nil w)))
  3503. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3504. (push w wds))
  3505. (setq words (nreverse wds))))
  3506. (if boolean
  3507. (mapc (lambda (w)
  3508. (setq c (string-to-char w))
  3509. (if (equal c ?-)
  3510. (setq neg t w (substring w 1))
  3511. (if (equal c ?+)
  3512. (setq neg nil w (substring w 1))
  3513. (setq neg nil)))
  3514. (if (string-match "\\`{.*}\\'" w)
  3515. (setq re (substring w 1 -1))
  3516. (if full-words
  3517. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3518. (setq re (regexp-quote (downcase w)))))
  3519. (if neg (push re regexps-) (push re regexps+)))
  3520. words)
  3521. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3522. regexps+))
  3523. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3524. (if (not regexps+)
  3525. (setq regexp (concat "^" org-outline-regexp))
  3526. (setq regexp (pop regexps+))
  3527. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3528. regexp))))
  3529. (setq files (org-agenda-files nil 'ifmode))
  3530. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3531. (pop org-agenda-text-search-extra-files)
  3532. (setq files (org-add-archive-files files)))
  3533. (setq files (append files org-agenda-text-search-extra-files)
  3534. rtnall nil)
  3535. (while (setq file (pop files))
  3536. (setq ee nil)
  3537. (catch 'nextfile
  3538. (org-check-agenda-file file)
  3539. (setq buffer (if (file-exists-p file)
  3540. (org-get-agenda-file-buffer file)
  3541. (error "No such file %s" file)))
  3542. (if (not buffer)
  3543. ;; If file does not exist, make sure an error message is sent
  3544. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3545. file))))
  3546. (with-current-buffer buffer
  3547. (with-syntax-table (org-search-syntax-table)
  3548. (unless (org-mode-p)
  3549. (error "Agenda file %s is not in `org-mode'" file))
  3550. (let ((case-fold-search t))
  3551. (save-excursion
  3552. (save-restriction
  3553. (if org-agenda-restrict
  3554. (narrow-to-region org-agenda-restrict-begin
  3555. org-agenda-restrict-end)
  3556. (widen))
  3557. (goto-char (point-min))
  3558. (unless (or (org-on-heading-p)
  3559. (outline-next-heading))
  3560. (throw 'nextfile t))
  3561. (goto-char (max (point-min) (1- (point))))
  3562. (while (re-search-forward regexp nil t)
  3563. (org-back-to-heading t)
  3564. (skip-chars-forward "* ")
  3565. (setq beg (point-at-bol)
  3566. beg1 (point)
  3567. end (progn (outline-next-heading) (point)))
  3568. (catch :skip
  3569. (goto-char beg)
  3570. (org-agenda-skip)
  3571. (setq str (buffer-substring-no-properties
  3572. (point-at-bol)
  3573. (if hdl-only (point-at-eol) end)))
  3574. (mapc (lambda (wr) (when (string-match wr str)
  3575. (goto-char (1- end))
  3576. (throw :skip t)))
  3577. regexps-)
  3578. (mapc (lambda (wr) (unless (string-match wr str)
  3579. (goto-char (1- end))
  3580. (throw :skip t)))
  3581. (if todo-only
  3582. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3583. regexps+)
  3584. regexps+))
  3585. (goto-char beg)
  3586. (setq marker (org-agenda-new-marker (point))
  3587. category (org-get-category)
  3588. tags (org-get-tags-at (point))
  3589. txt (org-format-agenda-item
  3590. ""
  3591. (buffer-substring-no-properties
  3592. beg1 (point-at-eol))
  3593. category tags))
  3594. (org-add-props txt props
  3595. 'org-marker marker 'org-hd-marker marker
  3596. 'org-todo-regexp org-todo-regexp
  3597. 'org-complex-heading-regexp org-complex-heading-regexp
  3598. 'priority 1000 'org-category category
  3599. 'type "search")
  3600. (push txt ee)
  3601. (goto-char (1- end))))))))))
  3602. (setq rtn (nreverse ee))
  3603. (setq rtnall (append rtnall rtn)))
  3604. (if org-agenda-overriding-header
  3605. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3606. nil 'face 'org-agenda-structure) "\n")
  3607. (insert "Search words: ")
  3608. (add-text-properties (point-min) (1- (point))
  3609. (list 'face 'org-agenda-structure))
  3610. (setq pos (point))
  3611. (insert string "\n")
  3612. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3613. (setq pos (point))
  3614. (unless org-agenda-multi
  3615. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3616. (add-text-properties pos (1- (point))
  3617. (list 'face 'org-agenda-structure))))
  3618. (org-agenda-mark-header-line (point-min))
  3619. (when rtnall
  3620. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3621. (goto-char (point-min))
  3622. (or org-agenda-multi (org-fit-agenda-window))
  3623. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3624. (org-finalize-agenda)
  3625. (setq buffer-read-only t)))
  3626. ;;; Agenda TODO list
  3627. (defvar org-select-this-todo-keyword nil)
  3628. (defvar org-last-arg nil)
  3629. ;;;###autoload
  3630. (defun org-todo-list (arg)
  3631. "Show all (not done) TODO entries from all agenda file in a single list.
  3632. The prefix arg can be used to select a specific TODO keyword and limit
  3633. the list to these. When using \\[universal-argument], you will be prompted
  3634. for a keyword. A numeric prefix directly selects the Nth keyword in
  3635. `org-todo-keywords-1'."
  3636. (interactive "P")
  3637. (org-compile-prefix-format 'todo)
  3638. (org-set-sorting-strategy 'todo)
  3639. (org-prepare-agenda "TODO")
  3640. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3641. (let* ((today (org-today))
  3642. (date (calendar-gregorian-from-absolute today))
  3643. (kwds org-todo-keywords-for-agenda)
  3644. (completion-ignore-case t)
  3645. (org-select-this-todo-keyword
  3646. (if (stringp arg) arg
  3647. (and arg (integerp arg) (> arg 0)
  3648. (nth (1- arg) kwds))))
  3649. rtn rtnall files file pos)
  3650. (when (equal arg '(4))
  3651. (setq org-select-this-todo-keyword
  3652. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3653. (mapcar 'list kwds) nil nil)))
  3654. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3655. (org-set-local 'org-last-arg arg)
  3656. (setq org-agenda-redo-command
  3657. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3658. (setq files (org-agenda-files nil 'ifmode)
  3659. rtnall nil)
  3660. (while (setq file (pop files))
  3661. (catch 'nextfile
  3662. (org-check-agenda-file file)
  3663. (setq rtn (org-agenda-get-day-entries file date :todo))
  3664. (setq rtnall (append rtnall rtn))))
  3665. (if org-agenda-overriding-header
  3666. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3667. nil 'face 'org-agenda-structure) "\n")
  3668. (insert "Global list of TODO items of type: ")
  3669. (add-text-properties (point-min) (1- (point))
  3670. (list 'face 'org-agenda-structure
  3671. 'short-heading
  3672. (concat "ToDo: "
  3673. (or org-select-this-todo-keyword "ALL"))))
  3674. (org-agenda-mark-header-line (point-min))
  3675. (setq pos (point))
  3676. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3677. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3678. (setq pos (point))
  3679. (unless org-agenda-multi
  3680. (insert "Available with `N r': (0)ALL")
  3681. (let ((n 0) s)
  3682. (mapc (lambda (x)
  3683. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3684. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3685. (insert "\n "))
  3686. (insert " " s))
  3687. kwds))
  3688. (insert "\n"))
  3689. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3690. (org-agenda-mark-header-line (point-min))
  3691. (when rtnall
  3692. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3693. (goto-char (point-min))
  3694. (or org-agenda-multi (org-fit-agenda-window))
  3695. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3696. (org-finalize-agenda)
  3697. (setq buffer-read-only t)))
  3698. ;;; Agenda tags match
  3699. ;;;###autoload
  3700. (defun org-tags-view (&optional todo-only match)
  3701. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3702. The prefix arg TODO-ONLY limits the search to TODO entries."
  3703. (interactive "P")
  3704. (org-compile-prefix-format 'tags)
  3705. (org-set-sorting-strategy 'tags)
  3706. (let* ((org-tags-match-list-sublevels
  3707. org-tags-match-list-sublevels)
  3708. (completion-ignore-case t)
  3709. rtn rtnall files file pos matcher
  3710. buffer)
  3711. (when (and (stringp match) (not (string-match "\\S-" match)))
  3712. (setq match nil))
  3713. (setq matcher (org-make-tags-matcher match)
  3714. match (car matcher) matcher (cdr matcher))
  3715. (org-prepare-agenda (concat "TAGS " match))
  3716. (setq org-agenda-query-string match)
  3717. (setq org-agenda-redo-command
  3718. (list 'org-tags-view (list 'quote todo-only)
  3719. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3720. (setq files (org-agenda-files nil 'ifmode)
  3721. rtnall nil)
  3722. (while (setq file (pop files))
  3723. (catch 'nextfile
  3724. (org-check-agenda-file file)
  3725. (setq buffer (if (file-exists-p file)
  3726. (org-get-agenda-file-buffer file)
  3727. (error "No such file %s" file)))
  3728. (if (not buffer)
  3729. ;; If file does not exist, error message to agenda
  3730. (setq rtn (list
  3731. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3732. rtnall (append rtnall rtn))
  3733. (with-current-buffer buffer
  3734. (unless (org-mode-p)
  3735. (error "Agenda file %s is not in `org-mode'" file))
  3736. (save-excursion
  3737. (save-restriction
  3738. (if org-agenda-restrict
  3739. (narrow-to-region org-agenda-restrict-begin
  3740. org-agenda-restrict-end)
  3741. (widen))
  3742. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3743. (setq rtnall (append rtnall rtn))))))))
  3744. (if org-agenda-overriding-header
  3745. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3746. nil 'face 'org-agenda-structure) "\n")
  3747. (insert "Headlines with TAGS match: ")
  3748. (add-text-properties (point-min) (1- (point))
  3749. (list 'face 'org-agenda-structure
  3750. 'short-heading
  3751. (concat "Match: " match)))
  3752. (setq pos (point))
  3753. (insert match "\n")
  3754. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3755. (setq pos (point))
  3756. (unless org-agenda-multi
  3757. (insert "Press `C-u r' to search again with new search string\n"))
  3758. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3759. (org-agenda-mark-header-line (point-min))
  3760. (when rtnall
  3761. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3762. (goto-char (point-min))
  3763. (or org-agenda-multi (org-fit-agenda-window))
  3764. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3765. (org-finalize-agenda)
  3766. (setq buffer-read-only t)))
  3767. ;;; Agenda Finding stuck projects
  3768. (defvar org-agenda-skip-regexp nil
  3769. "Regular expression used in skipping subtrees for the agenda.
  3770. This is basically a temporary global variable that can be set and then
  3771. used by user-defined selections using `org-agenda-skip-function'.")
  3772. (defvar org-agenda-overriding-header nil
  3773. "When this is set during todo and tags searches, will replace header.
  3774. This variable should not be set directly, but custom commands can bind it
  3775. in the options section.")
  3776. (defun org-agenda-skip-entry-when-regexp-matches ()
  3777. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3778. If yes, it returns the end position of this entry, causing agenda commands
  3779. to skip the entry but continuing the search in the subtree. This is a
  3780. function that can be put into `org-agenda-skip-function' for the duration
  3781. of a command."
  3782. (let ((end (save-excursion (org-end-of-subtree t)))
  3783. skip)
  3784. (save-excursion
  3785. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3786. (and skip end)))
  3787. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3788. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3789. If yes, it returns the end position of this tree, causing agenda commands
  3790. to skip this subtree. This is a function that can be put into
  3791. `org-agenda-skip-function' for the duration of a command."
  3792. (let ((end (save-excursion (org-end-of-subtree t)))
  3793. skip)
  3794. (save-excursion
  3795. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3796. (and skip end)))
  3797. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3798. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3799. If yes, it returns the end position of the current entry (NOT the tree),
  3800. causing agenda commands to skip the entry but continuing the search in
  3801. the subtree. This is a function that can be put into
  3802. `org-agenda-skip-function' for the duration of a command. An important
  3803. use of this function is for the stuck project list."
  3804. (let ((end (save-excursion (org-end-of-subtree t)))
  3805. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3806. skip)
  3807. (save-excursion
  3808. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3809. (and skip entry-end)))
  3810. (defun org-agenda-skip-entry-if (&rest conditions)
  3811. "Skip entry if any of CONDITIONS is true.
  3812. See `org-agenda-skip-if' for details."
  3813. (org-agenda-skip-if nil conditions))
  3814. (defun org-agenda-skip-subtree-if (&rest conditions)
  3815. "Skip entry if any of CONDITIONS is true.
  3816. See `org-agenda-skip-if' for details."
  3817. (org-agenda-skip-if t conditions))
  3818. (defun org-agenda-skip-if (subtree conditions)
  3819. "Checks current entity for CONDITIONS.
  3820. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3821. the entry, i.e. the text before the next heading is checked.
  3822. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3823. from different tests. Valid conditions are:
  3824. scheduled Check if there is a scheduled cookie
  3825. notscheduled Check if there is no scheduled cookie
  3826. deadline Check if there is a deadline
  3827. notdeadline Check if there is no deadline
  3828. timestamp Check if there is a timestamp (also deadline or scheduled)
  3829. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3830. regexp Check if regexp matches
  3831. notregexp Check if regexp does not match.
  3832. todo Check if TODO keyword matches
  3833. nottodo Check if TODO keyword does not match
  3834. The regexp is taken from the conditions list, it must come right after
  3835. the `regexp' or `notregexp' element.
  3836. `todo' and `nottodo' accept as an argument a list of todo
  3837. keywords, which may include \"*\" to match any todo keyword.
  3838. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3839. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3840. Instead of a list a keyword class may be given
  3841. (org-agenda-skip-entry-if 'nottodo 'done)
  3842. would skip entries that haven't been marked with any of \"DONE\"
  3843. keywords. Possible classes are: `todo', `done', `any'.
  3844. If any of these conditions is met, this function returns the end point of
  3845. the entity, causing the search to continue from there. This is a function
  3846. that can be put into `org-agenda-skip-function' for the duration of a command."
  3847. (let (beg end m)
  3848. (org-back-to-heading t)
  3849. (setq beg (point)
  3850. end (if subtree
  3851. (progn (org-end-of-subtree t) (point))
  3852. (progn (outline-next-heading) (1- (point)))))
  3853. (goto-char beg)
  3854. (and
  3855. (or
  3856. (and (memq 'scheduled conditions)
  3857. (re-search-forward org-scheduled-time-regexp end t))
  3858. (and (memq 'notscheduled conditions)
  3859. (not (re-search-forward org-scheduled-time-regexp end t)))
  3860. (and (memq 'deadline conditions)
  3861. (re-search-forward org-deadline-time-regexp end t))
  3862. (and (memq 'notdeadline conditions)
  3863. (not (re-search-forward org-deadline-time-regexp end t)))
  3864. (and (memq 'timestamp conditions)
  3865. (re-search-forward org-ts-regexp end t))
  3866. (and (memq 'nottimestamp conditions)
  3867. (not (re-search-forward org-ts-regexp end t)))
  3868. (and (setq m (memq 'regexp conditions))
  3869. (stringp (nth 1 m))
  3870. (re-search-forward (nth 1 m) end t))
  3871. (and (setq m (memq 'notregexp conditions))
  3872. (stringp (nth 1 m))
  3873. (not (re-search-forward (nth 1 m) end t)))
  3874. (and (or
  3875. (setq m (memq 'todo conditions))
  3876. (setq m (memq 'nottodo conditions)))
  3877. (org-agenda-skip-if-todo m end)))
  3878. end)))
  3879. (defun org-agenda-skip-if-todo (args end)
  3880. "Helper function for `org-agenda-skip-if', do not use it directly.
  3881. ARGS is a list with first element either `todo' or `nottodo'.
  3882. The remainder is either a list of TODO keywords, or a state symbol
  3883. `todo' or `done' or `any'."
  3884. (let ((kw (car args))
  3885. (arg (cadr args))
  3886. todo-wds todo-re)
  3887. (setq todo-wds
  3888. (org-uniquify
  3889. (cond
  3890. ((listp arg) ;; list of keywords
  3891. (if (member "*" arg)
  3892. (mapcar 'substring-no-properties org-todo-keywords-1)
  3893. arg))
  3894. ((symbolp arg) ;; keyword class name
  3895. (cond
  3896. ((eq arg 'todo)
  3897. (org-delete-all org-done-keywords
  3898. (mapcar 'substring-no-properties
  3899. org-todo-keywords-1)))
  3900. ((eq arg 'done) org-done-keywords)
  3901. ((eq arg 'any)
  3902. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3903. (setq todo-re
  3904. (concat "^\\*+[ \t]+\\<\\("
  3905. (mapconcat 'identity todo-wds "\\|")
  3906. "\\)\\>"))
  3907. (if (eq kw 'todo)
  3908. (re-search-forward todo-re end t)
  3909. (not (re-search-forward todo-re end t)))))
  3910. ;;;###autoload
  3911. (defun org-agenda-list-stuck-projects (&rest ignore)
  3912. "Create agenda view for projects that are stuck.
  3913. Stuck projects are project that have no next actions. For the definitions
  3914. of what a project is and how to check if it stuck, customize the variable
  3915. `org-stuck-projects'."
  3916. (interactive)
  3917. (let* ((org-agenda-skip-function
  3918. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3919. ;; We could have used org-agenda-skip-if here.
  3920. (org-agenda-overriding-header
  3921. (or org-agenda-overriding-header "List of stuck projects: "))
  3922. (matcher (nth 0 org-stuck-projects))
  3923. (todo (nth 1 org-stuck-projects))
  3924. (todo-wds (if (member "*" todo)
  3925. (progn
  3926. (org-prepare-agenda-buffers (org-agenda-files
  3927. nil 'ifmode))
  3928. (org-delete-all
  3929. org-done-keywords-for-agenda
  3930. (copy-sequence org-todo-keywords-for-agenda)))
  3931. todo))
  3932. (todo-re (concat "^\\*+[ \t]+\\("
  3933. (mapconcat 'identity todo-wds "\\|")
  3934. "\\)\\>"))
  3935. (tags (nth 2 org-stuck-projects))
  3936. (tags-re (if (member "*" tags)
  3937. (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
  3938. (if tags
  3939. (concat "^\\*+ .*:\\("
  3940. (mapconcat 'identity tags "\\|")
  3941. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3942. (gen-re (nth 3 org-stuck-projects))
  3943. (re-list
  3944. (delq nil
  3945. (list
  3946. (if todo todo-re)
  3947. (if tags tags-re)
  3948. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3949. gen-re)))))
  3950. (setq org-agenda-skip-regexp
  3951. (if re-list
  3952. (mapconcat 'identity re-list "\\|")
  3953. (error "No information how to identify unstuck projects")))
  3954. (org-tags-view nil matcher)
  3955. (with-current-buffer org-agenda-buffer-name
  3956. (setq org-agenda-redo-command
  3957. '(org-agenda-list-stuck-projects
  3958. (or current-prefix-arg org-last-arg))))))
  3959. ;;; Diary integration
  3960. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3961. (defvar list-diary-entries-hook)
  3962. (defvar diary-time-regexp)
  3963. (defun org-get-entries-from-diary (date)
  3964. "Get the (Emacs Calendar) diary entries for DATE."
  3965. (require 'diary-lib)
  3966. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3967. (diary-display-hook '(fancy-diary-display))
  3968. (diary-display-function 'fancy-diary-display)
  3969. (pop-up-frames nil)
  3970. (list-diary-entries-hook
  3971. (cons 'org-diary-default-entry list-diary-entries-hook))
  3972. (diary-file-name-prefix-function nil) ; turn this feature off
  3973. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3974. entries
  3975. (org-disable-agenda-to-diary t))
  3976. (save-excursion
  3977. (save-window-excursion
  3978. (funcall (if (fboundp 'diary-list-entries)
  3979. 'diary-list-entries 'list-diary-entries)
  3980. date 1)))
  3981. (if (not (get-buffer diary-fancy-buffer))
  3982. (setq entries nil)
  3983. (with-current-buffer diary-fancy-buffer
  3984. (setq buffer-read-only nil)
  3985. (if (zerop (buffer-size))
  3986. ;; No entries
  3987. (setq entries nil)
  3988. ;; Omit the date and other unnecessary stuff
  3989. (org-agenda-cleanup-fancy-diary)
  3990. ;; Add prefix to each line and extend the text properties
  3991. (if (zerop (buffer-size))
  3992. (setq entries nil)
  3993. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  3994. (setq entries
  3995. (with-temp-buffer
  3996. (insert entries) (goto-char (point-min))
  3997. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  3998. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  3999. (replace-match (concat "; " (match-string 1)))))
  4000. (buffer-string)))))
  4001. (set-buffer-modified-p nil)
  4002. (kill-buffer diary-fancy-buffer)))
  4003. (when entries
  4004. (setq entries (org-split-string entries "\n"))
  4005. (setq entries
  4006. (mapcar
  4007. (lambda (x)
  4008. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  4009. ;; Extend the text properties to the beginning of the line
  4010. (org-add-props x (text-properties-at (1- (length x)) x)
  4011. 'type "diary" 'date date 'face 'org-agenda-diary))
  4012. entries)))))
  4013. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4014. "Hook run when the fancy diary buffer is cleaned up.")
  4015. (defun org-agenda-cleanup-fancy-diary ()
  4016. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4017. This gets rid of the date, the underline under the date, and
  4018. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4019. date. It also removes lines that contain only whitespace."
  4020. (goto-char (point-min))
  4021. (if (looking-at ".*?:[ \t]*")
  4022. (progn
  4023. (replace-match "")
  4024. (re-search-forward "\n=+$" nil t)
  4025. (replace-match "")
  4026. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4027. (re-search-forward "\n=+$" nil t)
  4028. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4029. (goto-char (point-min))
  4030. (while (re-search-forward "^ +\n" nil t)
  4031. (replace-match ""))
  4032. (goto-char (point-min))
  4033. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4034. (replace-match ""))
  4035. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4036. ;; Make sure entries from the diary have the right text properties.
  4037. (eval-after-load "diary-lib"
  4038. '(if (boundp 'diary-modify-entry-list-string-function)
  4039. ;; We can rely on the hook, nothing to do
  4040. nil
  4041. ;; Hook not available, must use advice to make this work
  4042. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4043. "Make the position visible."
  4044. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4045. (stringp string)
  4046. buffer-file-name)
  4047. (setq string (org-modify-diary-entry-string string))))))
  4048. (defun org-modify-diary-entry-string (string)
  4049. "Add text properties to string, allowing org-mode to act on it."
  4050. (org-add-props string nil
  4051. 'mouse-face 'highlight
  4052. 'help-echo (if buffer-file-name
  4053. (format "mouse-2 or RET jump to diary file %s"
  4054. (abbreviate-file-name buffer-file-name))
  4055. "")
  4056. 'org-agenda-diary-link t
  4057. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4058. (defun org-diary-default-entry ()
  4059. "Add a dummy entry to the diary.
  4060. Needed to avoid empty dates which mess up holiday display."
  4061. ;; Catch the error if dealing with the new add-to-diary-alist
  4062. (when org-disable-agenda-to-diary
  4063. (condition-case nil
  4064. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4065. (error
  4066. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4067. (defun org-add-to-diary-list (&rest args)
  4068. (if (fboundp 'diary-add-to-list)
  4069. (apply 'diary-add-to-list args)
  4070. (apply 'add-to-diary-list args)))
  4071. (defvar org-diary-last-run-time nil)
  4072. ;;;###autoload
  4073. (defun org-diary (&rest args)
  4074. "Return diary information from org-files.
  4075. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4076. It accesses org files and extracts information from those files to be
  4077. listed in the diary. The function accepts arguments specifying what
  4078. items should be listed. For a list of arguments allowed here, see the
  4079. variable `org-agenda-entry-types'.
  4080. The call in the diary file should look like this:
  4081. &%%(org-diary) ~/path/to/some/orgfile.org
  4082. Use a separate line for each org file to check. Or, if you omit the file name,
  4083. all files listed in `org-agenda-files' will be checked automatically:
  4084. &%%(org-diary)
  4085. If you don't give any arguments (as in the example above), the default
  4086. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4087. So the example above may also be written as
  4088. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4089. The function expects the lisp variables `entry' and `date' to be provided
  4090. by the caller, because this is how the calendar works. Don't use this
  4091. function from a program - use `org-agenda-get-day-entries' instead."
  4092. (when (> (- (org-float-time)
  4093. org-agenda-last-marker-time)
  4094. 5)
  4095. (org-agenda-reset-markers))
  4096. (org-compile-prefix-format 'agenda)
  4097. (org-set-sorting-strategy 'agenda)
  4098. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4099. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4100. (list entry)
  4101. (org-agenda-files t)))
  4102. (time (org-float-time))
  4103. file rtn results)
  4104. (when (or (not org-diary-last-run-time)
  4105. (> (- time
  4106. org-diary-last-run-time)
  4107. 3))
  4108. (org-prepare-agenda-buffers files))
  4109. (setq org-diary-last-run-time time)
  4110. ;; If this is called during org-agenda, don't return any entries to
  4111. ;; the calendar. Org Agenda will list these entries itself.
  4112. (if org-disable-agenda-to-diary (setq files nil))
  4113. (while (setq file (pop files))
  4114. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4115. (setq results (append results rtn)))
  4116. (if results
  4117. (concat (org-finalize-agenda-entries results) "\n"))))
  4118. ;;; Agenda entry finders
  4119. (defun org-agenda-get-day-entries (file date &rest args)
  4120. "Does the work for `org-diary' and `org-agenda'.
  4121. FILE is the path to a file to be checked for entries. DATE is date like
  4122. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4123. which kind of entries should be extracted. For details about these, see
  4124. the documentation of `org-diary'."
  4125. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4126. (let* ((org-startup-folded nil)
  4127. (org-startup-align-all-tables nil)
  4128. (buffer (if (file-exists-p file)
  4129. (org-get-agenda-file-buffer file)
  4130. (error "No such file %s" file)))
  4131. arg results rtn deadline-results)
  4132. (if (not buffer)
  4133. ;; If file does not exist, make sure an error message ends up in diary
  4134. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4135. (with-current-buffer buffer
  4136. (unless (org-mode-p)
  4137. (error "Agenda file %s is not in `org-mode'" file))
  4138. (let ((case-fold-search nil))
  4139. (save-excursion
  4140. (save-restriction
  4141. (if org-agenda-restrict
  4142. (narrow-to-region org-agenda-restrict-begin
  4143. org-agenda-restrict-end)
  4144. (widen))
  4145. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4146. (while (setq arg (pop args))
  4147. (cond
  4148. ((and (eq arg :todo)
  4149. (equal date (calendar-gregorian-from-absolute
  4150. (org-today))))
  4151. (setq rtn (org-agenda-get-todos))
  4152. (setq results (append results rtn)))
  4153. ((eq arg :timestamp)
  4154. (setq rtn (org-agenda-get-blocks))
  4155. (setq results (append results rtn))
  4156. (setq rtn (org-agenda-get-timestamps))
  4157. (setq results (append results rtn)))
  4158. ((eq arg :sexp)
  4159. (setq rtn (org-agenda-get-sexps))
  4160. (setq results (append results rtn)))
  4161. ((eq arg :scheduled)
  4162. (setq rtn (org-agenda-get-scheduled deadline-results))
  4163. (setq results (append results rtn)))
  4164. ((eq arg :closed)
  4165. (setq rtn (org-agenda-get-progress))
  4166. (setq results (append results rtn)))
  4167. ((eq arg :deadline)
  4168. (setq rtn (org-agenda-get-deadlines))
  4169. (setq deadline-results (copy-sequence rtn))
  4170. (setq results (append results rtn))))))))
  4171. results))))
  4172. (defun org-agenda-get-todos ()
  4173. "Return the TODO information for agenda display."
  4174. (let* ((props (list 'face nil
  4175. 'done-face 'org-agenda-done
  4176. 'org-not-done-regexp org-not-done-regexp
  4177. 'org-todo-regexp org-todo-regexp
  4178. 'org-complex-heading-regexp org-complex-heading-regexp
  4179. 'mouse-face 'highlight
  4180. 'help-echo
  4181. (format "mouse-2 or RET jump to org file %s"
  4182. (abbreviate-file-name buffer-file-name))))
  4183. (regexp (concat "^\\*+[ \t]+\\("
  4184. (if org-select-this-todo-keyword
  4185. (if (equal org-select-this-todo-keyword "*")
  4186. org-todo-regexp
  4187. (concat "\\<\\("
  4188. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  4189. "\\)\\>"))
  4190. org-not-done-regexp)
  4191. "[^\n\r]*\\)"))
  4192. marker priority category tags todo-state
  4193. ee txt beg end)
  4194. (goto-char (point-min))
  4195. (while (re-search-forward regexp nil t)
  4196. (catch :skip
  4197. (save-match-data
  4198. (beginning-of-line)
  4199. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4200. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4201. (goto-char (1+ beg))
  4202. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4203. (throw :skip nil)))
  4204. (goto-char beg)
  4205. (org-agenda-skip)
  4206. (goto-char (match-beginning 1))
  4207. (setq marker (org-agenda-new-marker (match-beginning 0))
  4208. category (org-get-category)
  4209. txt (match-string 1)
  4210. tags (org-get-tags-at (point))
  4211. txt (org-format-agenda-item "" txt category tags)
  4212. priority (1+ (org-get-priority txt))
  4213. todo-state (org-get-todo-state))
  4214. (org-add-props txt props
  4215. 'org-marker marker 'org-hd-marker marker
  4216. 'priority priority 'org-category category
  4217. 'type "todo" 'todo-state todo-state)
  4218. (push txt ee)
  4219. (if org-agenda-todo-list-sublevels
  4220. (goto-char (match-end 1))
  4221. (org-end-of-subtree 'invisible))))
  4222. (nreverse ee)))
  4223. (defun org-agenda-todo-custom-ignore-p (time n)
  4224. "Check whether timestamp is farther away then n number of days.
  4225. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4226. `org-agenda-todo-ignore-scheduled' or
  4227. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4228. (let ((days (org-days-to-time time)))
  4229. (if (>= n 0)
  4230. (>= days n)
  4231. (<= days n))))
  4232. ;;;###autoload
  4233. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4234. (&optional end)
  4235. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4236. (when (or org-agenda-todo-ignore-with-date
  4237. org-agenda-todo-ignore-scheduled
  4238. org-agenda-todo-ignore-deadlines
  4239. org-agenda-todo-ignore-timestamp)
  4240. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4241. (save-excursion
  4242. (or (and org-agenda-todo-ignore-with-date
  4243. (re-search-forward org-ts-regexp end t))
  4244. (and org-agenda-todo-ignore-scheduled
  4245. (re-search-forward org-scheduled-time-regexp end t)
  4246. (cond
  4247. ((eq org-agenda-todo-ignore-scheduled 'future)
  4248. (> (org-days-to-time (match-string 1)) 0))
  4249. ((eq org-agenda-todo-ignore-scheduled 'past)
  4250. (<= (org-days-to-time (match-string 1)) 0))
  4251. ((numberp org-agenda-todo-ignore-scheduled)
  4252. (org-agenda-todo-custom-ignore-p
  4253. (match-string 1) org-agenda-todo-ignore-scheduled))
  4254. (t)))
  4255. (and org-agenda-todo-ignore-deadlines
  4256. (re-search-forward org-deadline-time-regexp end t)
  4257. (cond
  4258. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4259. ((eq org-agenda-todo-ignore-deadlines 'far)
  4260. (not (org-deadline-close (match-string 1))))
  4261. ((eq org-agenda-todo-ignore-deadlines 'future)
  4262. (> (org-days-to-time (match-string 1)) 0))
  4263. ((eq org-agenda-todo-ignore-deadlines 'past)
  4264. (<= (org-days-to-time (match-string 1)) 0))
  4265. ((numberp org-agenda-todo-ignore-deadlines)
  4266. (org-agenda-todo-custom-ignore-p
  4267. (match-string 1) org-agenda-todo-ignore-deadlines))
  4268. (t (org-deadline-close (match-string 1)))))
  4269. (and org-agenda-todo-ignore-timestamp
  4270. (let ((buffer (current-buffer))
  4271. (regexp
  4272. (concat
  4273. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4274. (start (point)))
  4275. ;; Copy current buffer into a temporary one
  4276. (with-temp-buffer
  4277. (insert-buffer-substring buffer start end)
  4278. (goto-char (point-min))
  4279. ;; Delete SCHEDULED and DEADLINE items
  4280. (while (re-search-forward regexp end t)
  4281. (delete-region (match-beginning 0) (match-end 0)))
  4282. (goto-char (point-min))
  4283. ;; No search for timestamp left
  4284. (when (re-search-forward org-ts-regexp nil t)
  4285. (cond
  4286. ((eq org-agenda-todo-ignore-timestamp 'future)
  4287. (> (org-days-to-time (match-string 1)) 0))
  4288. ((eq org-agenda-todo-ignore-timestamp 'past)
  4289. (<= (org-days-to-time (match-string 1)) 0))
  4290. ((numberp org-agenda-todo-ignore-timestamp)
  4291. (org-agenda-todo-custom-ignore-p
  4292. (match-string 1) org-agenda-todo-ignore-timestamp))
  4293. (t))))))))))
  4294. (defconst org-agenda-no-heading-message
  4295. "No heading for this item in buffer or region.")
  4296. (defun org-agenda-get-timestamps ()
  4297. "Return the date stamp information for agenda display."
  4298. (let* ((props (list 'face nil
  4299. 'org-not-done-regexp org-not-done-regexp
  4300. 'org-todo-regexp org-todo-regexp
  4301. 'org-complex-heading-regexp org-complex-heading-regexp
  4302. 'mouse-face 'highlight
  4303. 'help-echo
  4304. (format "mouse-2 or RET jump to org file %s"
  4305. (abbreviate-file-name buffer-file-name))))
  4306. (d1 (calendar-absolute-from-gregorian date))
  4307. (remove-re
  4308. (concat
  4309. (regexp-quote
  4310. (format-time-string
  4311. "<%Y-%m-%d"
  4312. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4313. ".*?>"))
  4314. (regexp
  4315. (concat
  4316. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4317. (regexp-quote
  4318. (substring
  4319. (format-time-string
  4320. (car org-time-stamp-formats)
  4321. (apply 'encode-time ; DATE bound by calendar
  4322. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4323. 1 11))
  4324. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4325. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4326. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4327. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  4328. todo-state end-of-match)
  4329. (goto-char (point-min))
  4330. (while (setq end-of-match (re-search-forward regexp nil t))
  4331. (setq b0 (match-beginning 0)
  4332. b3 (match-beginning 3) e3 (match-end 3)
  4333. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4334. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4335. (member todo-state
  4336. org-agenda-repeating-timestamp-show-all)))
  4337. (catch :skip
  4338. (and (org-at-date-range-p) (throw :skip nil))
  4339. (org-agenda-skip)
  4340. (if (and (match-end 1)
  4341. (not (= d1 (org-time-string-to-absolute
  4342. (match-string 1) d1 nil show-all))))
  4343. (throw :skip nil))
  4344. (if (and e3
  4345. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4346. (throw :skip nil))
  4347. (setq tmp (buffer-substring (max (point-min)
  4348. (- b0 org-ds-keyword-length))
  4349. b0)
  4350. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4351. inactivep (= (char-after b0) ?\[)
  4352. deadlinep (string-match org-deadline-regexp tmp)
  4353. scheduledp (string-match org-scheduled-regexp tmp)
  4354. closedp (and org-agenda-include-inactive-timestamps
  4355. (string-match org-closed-string tmp))
  4356. clockp (and org-agenda-include-inactive-timestamps
  4357. (or (string-match org-clock-string tmp)
  4358. (string-match "]-+\\'" tmp)))
  4359. donep (member todo-state org-done-keywords))
  4360. (if (or scheduledp deadlinep closedp clockp
  4361. (and donep org-agenda-skip-timestamp-if-done))
  4362. (throw :skip t))
  4363. (if (string-match ">" timestr)
  4364. ;; substring should only run to end of time stamp
  4365. (setq timestr (substring timestr 0 (match-end 0))))
  4366. (setq marker (org-agenda-new-marker b0)
  4367. category (org-get-category b0))
  4368. (save-excursion
  4369. (if (not (re-search-backward "^\\*+ " nil t))
  4370. (setq txt org-agenda-no-heading-message)
  4371. (goto-char (match-beginning 0))
  4372. (setq hdmarker (org-agenda-new-marker)
  4373. tags (org-get-tags-at))
  4374. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4375. (setq head (match-string 1))
  4376. (setq txt (org-format-agenda-item
  4377. (if inactivep org-agenda-inactive-leader nil)
  4378. head category tags timestr nil
  4379. remove-re)))
  4380. (setq priority (org-get-priority txt))
  4381. (org-add-props txt props
  4382. 'org-marker marker 'org-hd-marker hdmarker)
  4383. (org-add-props txt nil 'priority priority
  4384. 'org-category category 'date date
  4385. 'todo-state todo-state
  4386. 'type "timestamp")
  4387. (push txt ee))
  4388. (if org-agenda-skip-additional-timestamps-same-entry
  4389. (outline-next-heading)
  4390. (goto-char end-of-match))))
  4391. (nreverse ee)))
  4392. (defun org-agenda-get-sexps ()
  4393. "Return the sexp information for agenda display."
  4394. (require 'diary-lib)
  4395. (let* ((props (list 'mouse-face 'highlight
  4396. 'help-echo
  4397. (format "mouse-2 or RET jump to org file %s"
  4398. (abbreviate-file-name buffer-file-name))))
  4399. (regexp "^&?%%(")
  4400. marker category ee txt tags entry result beg b sexp sexp-entry
  4401. todo-state)
  4402. (goto-char (point-min))
  4403. (while (re-search-forward regexp nil t)
  4404. (catch :skip
  4405. (org-agenda-skip)
  4406. (setq beg (match-beginning 0))
  4407. (goto-char (1- (match-end 0)))
  4408. (setq b (point))
  4409. (forward-sexp 1)
  4410. (setq sexp (buffer-substring b (point)))
  4411. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4412. (org-trim (match-string 1))
  4413. ""))
  4414. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4415. (when result
  4416. (setq marker (org-agenda-new-marker beg)
  4417. category (org-get-category beg)
  4418. todo-state (org-get-todo-state))
  4419. (dolist (r (if (stringp result)
  4420. (list result)
  4421. result)) ;; we expect a list here
  4422. (if (string-match "\\S-" r)
  4423. (setq txt r)
  4424. (setq txt "SEXP entry returned empty string"))
  4425. (setq txt (org-format-agenda-item
  4426. "" txt category tags 'time))
  4427. (org-add-props txt props 'org-marker marker)
  4428. (org-add-props txt nil
  4429. 'org-category category 'date date 'todo-state todo-state
  4430. 'type "sexp")
  4431. (push txt ee)))))
  4432. (nreverse ee)))
  4433. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4434. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4435. The order of the first 2 times 3 arguments depends on the variable
  4436. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4437. So for American calendars, give this as MONTH DAY YEAR, for European as
  4438. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4439. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4440. is any number of ISO weeks in the block period for which the item should
  4441. be skipped."
  4442. (let* ((date1 (calendar-absolute-from-gregorian
  4443. (org-order-calendar-date-args m1 d1 y1)))
  4444. (date2 (calendar-absolute-from-gregorian
  4445. (org-order-calendar-date-args m2 d2 y2)))
  4446. (d (calendar-absolute-from-gregorian date)))
  4447. (and
  4448. (<= date1 d)
  4449. (<= d date2)
  4450. (= (calendar-day-of-week date) dayname)
  4451. (or (not skip-weeks)
  4452. (progn
  4453. (require 'cal-iso)
  4454. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4455. entry)))
  4456. (defalias 'org-get-closed 'org-agenda-get-progress)
  4457. (defun org-agenda-get-progress ()
  4458. "Return the logged TODO entries for agenda display."
  4459. (let* ((props (list 'mouse-face 'highlight
  4460. 'org-not-done-regexp org-not-done-regexp
  4461. 'org-todo-regexp org-todo-regexp
  4462. 'org-complex-heading-regexp org-complex-heading-regexp
  4463. 'help-echo
  4464. (format "mouse-2 or RET jump to org file %s"
  4465. (abbreviate-file-name buffer-file-name))))
  4466. (items (if (consp org-agenda-show-log)
  4467. org-agenda-show-log
  4468. org-agenda-log-mode-items))
  4469. (parts
  4470. (delq nil
  4471. (list
  4472. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4473. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4474. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4475. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4476. (error "`org-agenda-log-mode-items' is empty")))
  4477. (regexp (concat
  4478. "\\(" parts-re "\\)"
  4479. " *\\["
  4480. (regexp-quote
  4481. (substring
  4482. (format-time-string
  4483. (car org-time-stamp-formats)
  4484. (apply 'encode-time ; DATE bound by calendar
  4485. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4486. 1 11))))
  4487. (org-agenda-search-headline-for-time nil)
  4488. marker hdmarker priority category tags closedp statep clockp state
  4489. ee txt extra timestr rest clocked)
  4490. (goto-char (point-min))
  4491. (while (re-search-forward regexp nil t)
  4492. (catch :skip
  4493. (org-agenda-skip)
  4494. (setq marker (org-agenda-new-marker (match-beginning 0))
  4495. closedp (equal (match-string 1) org-closed-string)
  4496. statep (equal (string-to-char (match-string 1)) ?-)
  4497. clockp (not (or closedp statep))
  4498. state (and statep (match-string 2))
  4499. category (org-get-category (match-beginning 0))
  4500. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4501. )
  4502. (when (string-match "\\]" timestr)
  4503. ;; substring should only run to end of time stamp
  4504. (setq rest (substring timestr (match-end 0))
  4505. timestr (substring timestr 0 (match-end 0)))
  4506. (if (and (not closedp) (not statep)
  4507. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4508. (progn (setq timestr (concat (substring timestr 0 -1)
  4509. "-" (match-string 1 rest) "]"))
  4510. (setq clocked (match-string 2 rest)))
  4511. (setq clocked "-")))
  4512. (save-excursion
  4513. (setq extra
  4514. (cond
  4515. ((not org-agenda-log-mode-add-notes) nil)
  4516. (statep
  4517. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4518. (match-string 1)))
  4519. (clockp
  4520. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4521. (match-string 1)))))
  4522. (if (not (re-search-backward "^\\*+ " nil t))
  4523. (setq txt org-agenda-no-heading-message)
  4524. (goto-char (match-beginning 0))
  4525. (setq hdmarker (org-agenda-new-marker)
  4526. tags (org-get-tags-at))
  4527. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4528. (setq txt (match-string 1))
  4529. (when extra
  4530. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4531. (setq txt (concat (substring txt 0 (match-beginning 1))
  4532. " - " extra " " (match-string 2 txt)))
  4533. (setq txt (concat txt " - " extra))))
  4534. (setq txt (org-format-agenda-item
  4535. (cond
  4536. (closedp "Closed: ")
  4537. (statep (concat "State: (" state ")"))
  4538. (t (concat "Clocked: (" clocked ")")))
  4539. txt category tags timestr)))
  4540. (setq priority 100000)
  4541. (org-add-props txt props
  4542. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4543. 'priority priority 'org-category category
  4544. 'type "closed" 'date date
  4545. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4546. (push txt ee))
  4547. (goto-char (point-at-eol))))
  4548. (nreverse ee)))
  4549. (defun org-agenda-get-deadlines ()
  4550. "Return the deadline information for agenda display."
  4551. (let* ((props (list 'mouse-face 'highlight
  4552. 'org-not-done-regexp org-not-done-regexp
  4553. 'org-todo-regexp org-todo-regexp
  4554. 'org-complex-heading-regexp org-complex-heading-regexp
  4555. 'help-echo
  4556. (format "mouse-2 or RET jump to org file %s"
  4557. (abbreviate-file-name buffer-file-name))))
  4558. (regexp org-deadline-time-regexp)
  4559. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4560. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4561. d2 diff dfrac wdays pos pos1 category tags
  4562. suppress-prewarning
  4563. ee txt head face s todo-state show-all upcomingp donep timestr)
  4564. (goto-char (point-min))
  4565. (while (re-search-forward regexp nil t)
  4566. (setq suppress-prewarning nil)
  4567. (catch :skip
  4568. (org-agenda-skip)
  4569. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4570. (save-match-data
  4571. (string-match org-scheduled-time-regexp
  4572. (buffer-substring (point-at-bol)
  4573. (point-at-eol)))))
  4574. (setq suppress-prewarning
  4575. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4576. org-agenda-skip-deadline-prewarning-if-scheduled
  4577. 0)))
  4578. (setq s (match-string 1)
  4579. txt nil
  4580. pos (1- (match-beginning 1))
  4581. todo-state (save-match-data (org-get-todo-state))
  4582. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4583. (member todo-state
  4584. org-agenda-repeating-timestamp-show-all))
  4585. d2 (org-time-string-to-absolute
  4586. (match-string 1) d1 'past show-all)
  4587. diff (- d2 d1)
  4588. wdays (if suppress-prewarning
  4589. (let ((org-deadline-warning-days suppress-prewarning))
  4590. (org-get-wdays s))
  4591. (org-get-wdays s))
  4592. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4593. upcomingp (and todayp (> diff 0)))
  4594. ;; When to show a deadline in the calendar:
  4595. ;; If the expiration is within wdays warning time.
  4596. ;; Past-due deadlines are only shown on the current date
  4597. (if (and (or (and (<= diff wdays)
  4598. (and todayp (not org-agenda-only-exact-dates)))
  4599. (= diff 0)))
  4600. (save-excursion
  4601. ;; (setq todo-state (org-get-todo-state))
  4602. (setq donep (member todo-state org-done-keywords))
  4603. (if (and donep
  4604. (or org-agenda-skip-deadline-if-done
  4605. (not (= diff 0))))
  4606. (setq txt nil)
  4607. (setq category (org-get-category))
  4608. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4609. (setq txt org-agenda-no-heading-message)
  4610. (goto-char (match-end 0))
  4611. (setq pos1 (match-beginning 0))
  4612. (setq tags (org-get-tags-at pos1))
  4613. (setq head (buffer-substring-no-properties
  4614. (point)
  4615. (progn (skip-chars-forward "^\r\n")
  4616. (point))))
  4617. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4618. (setq timestr
  4619. (concat (substring s (match-beginning 1)) " "))
  4620. (setq timestr 'time))
  4621. (setq txt (org-format-agenda-item
  4622. (if (= diff 0)
  4623. (car org-agenda-deadline-leaders)
  4624. (if (functionp
  4625. (nth 1 org-agenda-deadline-leaders))
  4626. (funcall
  4627. (nth 1 org-agenda-deadline-leaders)
  4628. diff date)
  4629. (format (nth 1 org-agenda-deadline-leaders)
  4630. diff)))
  4631. head category tags
  4632. (if (not (= diff 0)) nil timestr)))))
  4633. (when txt
  4634. (setq face (org-agenda-deadline-face dfrac wdays))
  4635. (org-add-props txt props
  4636. 'org-marker (org-agenda-new-marker pos)
  4637. 'org-hd-marker (org-agenda-new-marker pos1)
  4638. 'priority (+ (- diff)
  4639. (org-get-priority txt))
  4640. 'org-category category
  4641. 'todo-state todo-state
  4642. 'type (if upcomingp "upcoming-deadline" "deadline")
  4643. 'date (if upcomingp date d2)
  4644. 'face (if donep 'org-agenda-done face)
  4645. 'undone-face face 'done-face 'org-agenda-done)
  4646. (push txt ee))))))
  4647. (nreverse ee)))
  4648. (defun org-agenda-deadline-face (fraction &optional wdays)
  4649. "Return the face to displaying a deadline item.
  4650. FRACTION is what fraction of the head-warning time has passed."
  4651. (if (equal wdays 0) (setq fraction 1.))
  4652. (let ((faces org-agenda-deadline-faces) f)
  4653. (catch 'exit
  4654. (while (setq f (pop faces))
  4655. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4656. (defun org-agenda-get-scheduled (&optional deadline-results)
  4657. "Return the scheduled information for agenda display."
  4658. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4659. 'org-todo-regexp org-todo-regexp
  4660. 'org-complex-heading-regexp org-complex-heading-regexp
  4661. 'done-face 'org-agenda-done
  4662. 'mouse-face 'highlight
  4663. 'help-echo
  4664. (format "mouse-2 or RET jump to org file %s"
  4665. (abbreviate-file-name buffer-file-name))))
  4666. (regexp org-scheduled-time-regexp)
  4667. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4668. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4669. mm
  4670. (deadline-position-alist
  4671. (mapcar (lambda (a) (and (setq mm (get-text-property
  4672. 0 'org-hd-marker a))
  4673. (cons (marker-position mm) a)))
  4674. deadline-results))
  4675. d2 diff pos pos1 category tags donep
  4676. ee txt head pastschedp todo-state face timestr s habitp)
  4677. (goto-char (point-min))
  4678. (while (re-search-forward regexp nil t)
  4679. (catch :skip
  4680. (org-agenda-skip)
  4681. (setq s (match-string 1)
  4682. txt nil
  4683. pos (1- (match-beginning 1))
  4684. todo-state (save-match-data (org-get-todo-state))
  4685. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4686. (member todo-state
  4687. org-agenda-repeating-timestamp-show-all))
  4688. d2 (org-time-string-to-absolute
  4689. (match-string 1) d1 'past show-all)
  4690. diff (- d2 d1))
  4691. (setq pastschedp (and todayp (< diff 0)))
  4692. ;; When to show a scheduled item in the calendar:
  4693. ;; If it is on or past the date.
  4694. (when (or (and (< diff 0)
  4695. (< (abs diff) org-scheduled-past-days)
  4696. (and todayp (not org-agenda-only-exact-dates)))
  4697. (= diff 0))
  4698. (save-excursion
  4699. (setq donep (member todo-state org-done-keywords))
  4700. (if (and donep
  4701. (or org-agenda-skip-scheduled-if-done
  4702. (not (= diff 0))
  4703. (and (functionp 'org-is-habit-p)
  4704. (org-is-habit-p))))
  4705. (setq txt nil)
  4706. (setq habitp (and (functionp 'org-is-habit-p)
  4707. (org-is-habit-p)))
  4708. (setq category (org-get-category))
  4709. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4710. (setq txt org-agenda-no-heading-message)
  4711. (goto-char (match-end 0))
  4712. (setq pos1 (match-beginning 0))
  4713. (if habitp
  4714. (if (or (not org-habit-show-habits)
  4715. (and (not todayp)
  4716. org-habit-show-habits-only-for-today))
  4717. (throw :skip nil))
  4718. (if (and
  4719. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4720. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4721. pastschedp))
  4722. (setq mm (assoc pos1 deadline-position-alist)))
  4723. (throw :skip nil)))
  4724. (setq tags (org-get-tags-at))
  4725. (setq head (buffer-substring-no-properties
  4726. (point)
  4727. (progn (skip-chars-forward "^\r\n") (point))))
  4728. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4729. (setq timestr
  4730. (concat (substring s (match-beginning 1)) " "))
  4731. (setq timestr 'time))
  4732. (setq txt (org-format-agenda-item
  4733. (if (= diff 0)
  4734. (car org-agenda-scheduled-leaders)
  4735. (format (nth 1 org-agenda-scheduled-leaders)
  4736. (- 1 diff)))
  4737. head category tags
  4738. (if (not (= diff 0)) nil timestr)
  4739. nil nil habitp))))
  4740. (when txt
  4741. (setq face
  4742. (cond
  4743. ((and (not habitp) pastschedp)
  4744. 'org-scheduled-previously)
  4745. (todayp 'org-scheduled-today)
  4746. (t 'org-scheduled))
  4747. habitp (and habitp (org-habit-parse-todo)))
  4748. (org-add-props txt props
  4749. 'undone-face face
  4750. 'face (if donep 'org-agenda-done face)
  4751. 'org-marker (org-agenda-new-marker pos)
  4752. 'org-hd-marker (org-agenda-new-marker pos1)
  4753. 'type (if pastschedp "past-scheduled" "scheduled")
  4754. 'date (if pastschedp d2 date)
  4755. 'priority (if habitp
  4756. (org-habit-get-priority habitp)
  4757. (+ 94 (- 5 diff) (org-get-priority txt)))
  4758. 'org-category category
  4759. 'org-habit-p habitp
  4760. 'todo-state todo-state)
  4761. (push txt ee))))))
  4762. (nreverse ee)))
  4763. (defun org-agenda-get-blocks ()
  4764. "Return the date-range information for agenda display."
  4765. (let* ((props (list 'face nil
  4766. 'org-not-done-regexp org-not-done-regexp
  4767. 'org-todo-regexp org-todo-regexp
  4768. 'org-complex-heading-regexp org-complex-heading-regexp
  4769. 'mouse-face 'highlight
  4770. 'help-echo
  4771. (format "mouse-2 or RET jump to org file %s"
  4772. (abbreviate-file-name buffer-file-name))))
  4773. (regexp org-tr-regexp)
  4774. (d0 (calendar-absolute-from-gregorian date))
  4775. marker hdmarker ee txt d1 d2 s1 s2 category todo-state tags pos
  4776. head donep)
  4777. (goto-char (point-min))
  4778. (while (re-search-forward regexp nil t)
  4779. (catch :skip
  4780. (org-agenda-skip)
  4781. (setq pos (point))
  4782. (let ((start-time (match-string 1))
  4783. (end-time (match-string 2)))
  4784. (setq s1 (match-string 1)
  4785. s2 (match-string 2)
  4786. d1 (time-to-days (org-time-string-to-time s1))
  4787. d2 (time-to-days (org-time-string-to-time s2)))
  4788. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4789. ;; Only allow days between the limits, because the normal
  4790. ;; date stamps will catch the limits.
  4791. (save-excursion
  4792. (setq todo-state (org-get-todo-state))
  4793. (setq donep (member todo-state org-done-keywords))
  4794. (if (and donep org-agenda-skip-timestamp-if-done)
  4795. (throw :skip t))
  4796. (setq marker (org-agenda-new-marker (point)))
  4797. (setq category (org-get-category))
  4798. (if (not (re-search-backward "^\\*+ " nil t))
  4799. (setq txt org-agenda-no-heading-message)
  4800. (goto-char (match-beginning 0))
  4801. (setq hdmarker (org-agenda-new-marker (point)))
  4802. (setq tags (org-get-tags-at))
  4803. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4804. (setq head (match-string 1))
  4805. (let ((remove-re
  4806. (if org-agenda-remove-timeranges-from-blocks
  4807. (concat
  4808. "<" (regexp-quote s1) ".*?>"
  4809. "--"
  4810. "<" (regexp-quote s2) ".*?>")
  4811. nil)))
  4812. (setq txt (org-format-agenda-item
  4813. (format
  4814. (nth (if (= d1 d2) 0 1)
  4815. org-agenda-timerange-leaders)
  4816. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4817. head category tags
  4818. (cond ((= d1 d0)
  4819. (concat "<" start-time ">"))
  4820. ((= d2 d0)
  4821. (concat "<" end-time ">"))
  4822. (t nil))
  4823. remove-re))))
  4824. (org-add-props txt props
  4825. 'org-marker marker 'org-hd-marker hdmarker
  4826. 'type "block" 'date date
  4827. 'todo-state todo-state
  4828. 'priority (org-get-priority txt) 'org-category category)
  4829. (push txt ee))))
  4830. (goto-char pos)))
  4831. ;; Sort the entries by expiration date.
  4832. (nreverse ee)))
  4833. ;;; Agenda presentation and sorting
  4834. (defvar org-prefix-has-time nil
  4835. "A flag, set by `org-compile-prefix-format'.
  4836. The flag is set if the currently compiled format contains a `%t'.")
  4837. (defvar org-prefix-has-tag nil
  4838. "A flag, set by `org-compile-prefix-format'.
  4839. The flag is set if the currently compiled format contains a `%T'.")
  4840. (defvar org-prefix-has-effort nil
  4841. "A flag, set by `org-compile-prefix-format'.
  4842. The flag is set if the currently compiled format contains a `%e'.")
  4843. (defvar org-prefix-category-length nil
  4844. "Used by `org-compile-prefix-format' to remember the category field width.")
  4845. (defvar org-prefix-category-max-length nil
  4846. "Used by `org-compile-prefix-format' to remember the category field width.")
  4847. (defun org-agenda-get-category-icon (category)
  4848. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  4849. (dolist (entry org-agenda-category-icon-alist)
  4850. (when (org-string-match-p (car entry) category)
  4851. (if (listp (cadr entry))
  4852. (return (cadr entry))
  4853. (return (apply 'create-image (cdr entry)))))))
  4854. (defun org-format-agenda-item (extra txt &optional category tags dotime
  4855. noprefix remove-re habitp)
  4856. "Format TXT to be inserted into the agenda buffer.
  4857. In particular, it adds the prefix and corresponding text properties. EXTRA
  4858. must be a string and replaces the `%s' specifier in the prefix format.
  4859. CATEGORY (string, symbol or nil) may be used to overrule the default
  4860. category taken from local variable or file name. It will replace the `%c'
  4861. specifier in the format. DOTIME, when non-nil, indicates that a
  4862. time-of-day should be extracted from TXT for sorting of this entry, and for
  4863. the `%t' specifier in the format. When DOTIME is a string, this string is
  4864. searched for a time before TXT is. NOPREFIX is a flag and indicates that
  4865. only the correctly processes TXT should be returned - this is used by
  4866. `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
  4867. Any match of REMOVE-RE will be removed from TXT."
  4868. (save-match-data
  4869. ;; Diary entries sometimes have extra whitespace at the beginning
  4870. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  4871. ;; Fix the tags part in txt
  4872. (setq txt (org-agenda-fix-displayed-tags
  4873. txt tags
  4874. org-agenda-show-inherited-tags
  4875. org-agenda-hide-tags-regexp))
  4876. (let* ((category (or category
  4877. (if (stringp org-category)
  4878. org-category
  4879. (and org-category (symbol-name org-category)))
  4880. (if buffer-file-name
  4881. (file-name-sans-extension
  4882. (file-name-nondirectory buffer-file-name))
  4883. "")))
  4884. (category-icon (org-agenda-get-category-icon category))
  4885. (category-icon (if category-icon
  4886. (propertize " " 'display category-icon)
  4887. ""))
  4888. ;; time, tag, effort are needed for the eval of the prefix format
  4889. (tag (if tags (nth (1- (length tags)) tags) ""))
  4890. time effort neffort
  4891. (ts (if dotime (concat
  4892. (if (stringp dotime) dotime "")
  4893. (and org-agenda-search-headline-for-time txt))))
  4894. (time-of-day (and dotime (org-get-time-of-day ts)))
  4895. stamp plain s0 s1 s2 rtn srp l
  4896. duration thecategory)
  4897. (and (org-mode-p) buffer-file-name
  4898. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  4899. (when (and dotime time-of-day)
  4900. ;; Extract starting and ending time and move them to prefix
  4901. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  4902. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  4903. (setq s0 (match-string 0 ts)
  4904. srp (and stamp (match-end 3))
  4905. s1 (match-string (if plain 1 2) ts)
  4906. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  4907. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  4908. ;; them, we might want to remove them there to avoid duplication.
  4909. ;; The user can turn this off with a variable.
  4910. (if (and org-prefix-has-time
  4911. org-agenda-remove-times-when-in-prefix (or stamp plain)
  4912. (string-match (concat (regexp-quote s0) " *") txt)
  4913. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  4914. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  4915. (= (match-beginning 0) 0)
  4916. t))
  4917. (setq txt (replace-match "" nil nil txt))))
  4918. ;; Normalize the time(s) to 24 hour
  4919. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  4920. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  4921. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  4922. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  4923. (setq s2
  4924. (org-minutes-to-hh:mm-string
  4925. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  4926. ;; Compute the duration
  4927. (when s2
  4928. (setq duration (- (org-hh:mm-string-to-minutes s2)
  4929. (org-hh:mm-string-to-minutes s1)))))
  4930. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  4931. txt)
  4932. ;; Tags are in the string
  4933. (if (or (eq org-agenda-remove-tags t)
  4934. (and org-agenda-remove-tags
  4935. org-prefix-has-tag))
  4936. (setq txt (replace-match "" t t txt))
  4937. (setq txt (replace-match
  4938. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  4939. (match-string 2 txt))
  4940. t t txt))))
  4941. (when (org-mode-p)
  4942. (setq effort
  4943. (condition-case nil
  4944. (org-get-effort
  4945. (or (get-text-property 0 'org-hd-marker txt)
  4946. (get-text-property 0 'org-marker txt)))
  4947. (error nil)))
  4948. (when effort
  4949. (setq neffort (org-hh:mm-string-to-minutes effort)
  4950. effort (setq effort (concat "[" effort "]" )))))
  4951. (when remove-re
  4952. (while (string-match remove-re txt)
  4953. (setq txt (replace-match "" t t txt))))
  4954. ;; Create the final string
  4955. (if noprefix
  4956. (setq rtn txt)
  4957. ;; Prepare the variables needed in the eval of the compiled format
  4958. (setq time (cond (s2 (concat
  4959. (org-agenda-time-of-day-to-ampm-maybe s1)
  4960. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  4961. (if org-agenda-timegrid-use-ampm " ")))
  4962. (s1 (concat
  4963. (org-agenda-time-of-day-to-ampm-maybe s1)
  4964. (if org-agenda-timegrid-use-ampm
  4965. "........ "
  4966. "......")))
  4967. (t ""))
  4968. extra (or (and (not habitp) extra) "")
  4969. category (if (symbolp category) (symbol-name category) category)
  4970. thecategory (copy-sequence category))
  4971. (if (string-match org-bracket-link-regexp category)
  4972. (progn
  4973. (setq l (if (match-end 3)
  4974. (- (match-end 3) (match-beginning 3))
  4975. (- (match-end 1) (match-beginning 1))))
  4976. (when (< l (or org-prefix-category-length 0))
  4977. (setq category (copy-sequence category))
  4978. (org-add-props category nil
  4979. 'extra-space (make-string
  4980. (- org-prefix-category-length l 1) ?\ ))))
  4981. (if (and org-prefix-category-max-length
  4982. (>= (length category) org-prefix-category-max-length))
  4983. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  4984. ;; Evaluate the compiled format
  4985. (setq rtn (concat (eval org-prefix-format-compiled) txt)))
  4986. ;; And finally add the text properties
  4987. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  4988. (org-add-props rtn nil
  4989. 'org-category (if thecategory (downcase thecategory) category)
  4990. 'tags (mapcar 'org-downcase-keep-props tags)
  4991. 'org-highest-priority org-highest-priority
  4992. 'org-lowest-priority org-lowest-priority
  4993. 'prefix-length (- (length rtn) (length txt))
  4994. 'time-of-day time-of-day
  4995. 'duration duration
  4996. 'effort effort
  4997. 'effort-minutes neffort
  4998. 'txt txt
  4999. 'time time
  5000. 'extra extra
  5001. 'dotime dotime))))
  5002. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5003. "Remove tags string from TXT, and add a modified list of tags.
  5004. The modified list may contain inherited tags, and tags matched by
  5005. `org-agenda-hide-tags-regexp' will be removed."
  5006. (when (or add-inherited hide-re)
  5007. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5008. (setq txt (substring txt 0 (match-beginning 0))))
  5009. (setq tags
  5010. (delq nil
  5011. (mapcar (lambda (tg)
  5012. (if (or (and hide-re (string-match hide-re tg))
  5013. (and (not add-inherited)
  5014. (get-text-property 0 'inherited tg)))
  5015. nil
  5016. tg))
  5017. tags)))
  5018. (when tags
  5019. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5020. i)
  5021. (setq txt (concat txt " :"
  5022. (mapconcat
  5023. (lambda (x)
  5024. (setq i (get-text-property 0 'inherited x))
  5025. (if (and have-i (not i))
  5026. (progn
  5027. (setq have-i nil)
  5028. (concat ":" x))
  5029. x))
  5030. tags ":")
  5031. (if have-i "::" ":"))))))
  5032. txt)
  5033. (defun org-downcase-keep-props (s)
  5034. (let ((props (text-properties-at 0 s)))
  5035. (setq s (downcase s))
  5036. (add-text-properties 0 (length s) props s)
  5037. s))
  5038. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5039. (defvar org-agenda-sorting-strategy-selected nil)
  5040. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5041. (catch 'exit
  5042. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5043. ((and todayp (member 'today (car org-agenda-time-grid))))
  5044. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5045. ((member 'weekly (car org-agenda-time-grid)))
  5046. (t (throw 'exit list)))
  5047. (let* ((have (delq nil (mapcar
  5048. (lambda (x) (get-text-property 1 'time-of-day x))
  5049. list)))
  5050. (string (nth 1 org-agenda-time-grid))
  5051. (gridtimes (nth 2 org-agenda-time-grid))
  5052. (req (car org-agenda-time-grid))
  5053. (remove (member 'remove-match req))
  5054. new time)
  5055. (if (and (member 'require-timed req) (not have))
  5056. ;; don't show empty grid
  5057. (throw 'exit list))
  5058. (while (setq time (pop gridtimes))
  5059. (unless (and remove (member time have))
  5060. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5061. (push (org-format-agenda-item
  5062. nil string "" nil
  5063. (concat (substring time 0 -2) ":" (substring time -2)))
  5064. new)
  5065. (put-text-property
  5066. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5067. (when (and todayp org-agenda-show-current-time-in-grid)
  5068. (push (org-format-agenda-item
  5069. nil
  5070. org-agenda-current-time-string
  5071. "" nil
  5072. (format-time-string "%H:%M "))
  5073. new)
  5074. (put-text-property
  5075. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5076. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5077. (append new list)
  5078. (append list new)))))
  5079. (defun org-compile-prefix-format (key)
  5080. "Compile the prefix format into a Lisp form that can be evaluated.
  5081. The resulting form is returned and stored in the variable
  5082. `org-prefix-format-compiled'."
  5083. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5084. org-prefix-category-length nil org-prefix-has-effort nil)
  5085. (let ((s (cond
  5086. ((stringp org-agenda-prefix-format)
  5087. org-agenda-prefix-format)
  5088. ((assq key org-agenda-prefix-format)
  5089. (cdr (assq key org-agenda-prefix-format)))
  5090. (t " %-12:c%?-12t% s")))
  5091. (start 0)
  5092. varform vars var e c f opt)
  5093. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5094. s start)
  5095. (setq var (or (cdr (assoc (match-string 4 s)
  5096. '(("c" . category) ("t" . time) ("s" . extra)
  5097. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5098. 'eval)
  5099. c (or (match-string 3 s) "")
  5100. opt (match-beginning 1)
  5101. start (1+ (match-beginning 0)))
  5102. (if (equal var 'time) (setq org-prefix-has-time t))
  5103. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5104. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5105. (setq f (concat "%" (match-string 2 s) "s"))
  5106. (when (equal var 'category)
  5107. (setq org-prefix-category-length
  5108. (floor (abs (string-to-number (match-string 2 s)))))
  5109. (setq org-prefix-category-max-length
  5110. (let ((x (match-string 2 s)))
  5111. (save-match-data
  5112. (if (string-match "\\.[0-9]+" x)
  5113. (string-to-number (substring (match-string 0 x) 1)))))))
  5114. (if (eq var 'eval)
  5115. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5116. (if opt
  5117. (setq varform
  5118. `(if (equal "" ,var)
  5119. ""
  5120. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5121. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5122. (setq s (replace-match "%s" t nil s))
  5123. (push varform vars))
  5124. (setq vars (nreverse vars))
  5125. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  5126. (defun org-set-sorting-strategy (key)
  5127. (if (symbolp (car org-agenda-sorting-strategy))
  5128. ;; the old format
  5129. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5130. (setq org-agenda-sorting-strategy-selected
  5131. (or (cdr (assq key org-agenda-sorting-strategy))
  5132. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5133. '(time-up category-keep priority-down)))))
  5134. (defun org-get-time-of-day (s &optional string mod24)
  5135. "Check string S for a time of day.
  5136. If found, return it as a military time number between 0 and 2400.
  5137. If not found, return nil.
  5138. The optional STRING argument forces conversion into a 5 character wide string
  5139. HH:MM."
  5140. (save-match-data
  5141. (when
  5142. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5143. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5144. (let* ((h (string-to-number (match-string 1 s)))
  5145. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5146. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5147. (am-p (equal ampm "am"))
  5148. (h1 (cond ((not ampm) h)
  5149. ((= h 12) (if am-p 0 12))
  5150. (t (+ h (if am-p 0 12)))))
  5151. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5152. (mod h1 24) h1))
  5153. (t0 (+ (* 100 h2) m))
  5154. (t1 (concat (if (>= h1 24) "+" " ")
  5155. (if (and org-agenda-time-leading-zero
  5156. (< t0 1000)) "0" "")
  5157. (if (< t0 100) "0" "")
  5158. (if (< t0 10) "0" "")
  5159. (int-to-string t0))))
  5160. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5161. (defvar org-agenda-before-sorting-filter-function nil
  5162. "Function to be applied to agenda items prior to sorting.
  5163. Prior to sorting also means just before they are inserted into the agenda.
  5164. To aid sorting, you may revisit the original entries and add more text
  5165. properties which will later be used by the sorting functions.
  5166. The function should take a string argument, an agenda line.
  5167. It has access to the text properties in that line, which contain among
  5168. other things, the property `org-hd-marker' that points to the entry
  5169. where the line comes from. Note that not all lines going into the agenda
  5170. have this property, only most.
  5171. The function should return the modified string. It is probably best
  5172. to ONLY change text properties.
  5173. You can also use this function as a filter, by returning nil for lines
  5174. you don't want to have in the agenda at all. For this application, you
  5175. could bind the variable in the options section of a custom command.")
  5176. (defun org-finalize-agenda-entries (list &optional nosort)
  5177. "Sort and concatenate the agenda items."
  5178. (setq list (mapcar 'org-agenda-highlight-todo list))
  5179. (if nosort
  5180. list
  5181. (when org-agenda-before-sorting-filter-function
  5182. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5183. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5184. (defun org-agenda-highlight-todo (x)
  5185. (let ((org-done-keywords org-done-keywords-for-agenda)
  5186. (case-fold-search nil)
  5187. re pl)
  5188. (if (eq x 'line)
  5189. (save-excursion
  5190. (beginning-of-line 1)
  5191. (setq re (org-get-at-bol 'org-todo-regexp))
  5192. (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
  5193. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5194. (add-text-properties (match-beginning 0) (match-end 1)
  5195. (list 'face (org-get-todo-face 1)))
  5196. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5197. (delete-region (match-beginning 1) (1- (match-end 0)))
  5198. (goto-char (match-beginning 1))
  5199. (insert (format org-agenda-todo-keyword-format s)))))
  5200. (setq re (concat (get-text-property 0 'org-todo-regexp x))
  5201. pl (get-text-property 0 'prefix-length x))
  5202. (when (and re
  5203. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5204. x (or pl 0)) pl))
  5205. (add-text-properties
  5206. (or (match-end 1) (match-end 0)) (match-end 0)
  5207. (list 'face (org-get-todo-face (match-string 2 x)))
  5208. x)
  5209. (when (match-end 1)
  5210. (setq x (concat (substring x 0 (match-end 1))
  5211. (format org-agenda-todo-keyword-format
  5212. (match-string 2 x))
  5213. (org-add-props " " (text-properties-at 0 x))
  5214. (substring x (match-end 3))))))
  5215. x)))
  5216. (defsubst org-cmp-priority (a b)
  5217. "Compare the priorities of string A and B."
  5218. (let ((pa (or (get-text-property 1 'priority a) 0))
  5219. (pb (or (get-text-property 1 'priority b) 0)))
  5220. (cond ((> pa pb) +1)
  5221. ((< pa pb) -1)
  5222. (t nil))))
  5223. (defsubst org-cmp-effort (a b)
  5224. "Compare the priorities of string A and B."
  5225. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5226. (ea (or (get-text-property 1 'effort-minutes a) def))
  5227. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5228. (cond ((> ea eb) +1)
  5229. ((< ea eb) -1)
  5230. (t nil))))
  5231. (defsubst org-cmp-category (a b)
  5232. "Compare the string values of categories of strings A and B."
  5233. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5234. (cb (or (get-text-property 1 'org-category b) "")))
  5235. (cond ((string-lessp ca cb) -1)
  5236. ((string-lessp cb ca) +1)
  5237. (t nil))))
  5238. (defsubst org-cmp-todo-state (a b)
  5239. "Compare the todo states of strings A and B."
  5240. (let* ((ma (or (get-text-property 1 'org-marker a)
  5241. (get-text-property 1 'org-hd-marker a)))
  5242. (mb (or (get-text-property 1 'org-marker b)
  5243. (get-text-property 1 'org-hd-marker b)))
  5244. (fa (and ma (marker-buffer ma)))
  5245. (fb (and mb (marker-buffer mb)))
  5246. (todo-kwds
  5247. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5248. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5249. (ta (or (get-text-property 1 'todo-state a) ""))
  5250. (tb (or (get-text-property 1 'todo-state b) ""))
  5251. (la (- (length (member ta todo-kwds))))
  5252. (lb (- (length (member tb todo-kwds))))
  5253. (donepa (member ta org-done-keywords-for-agenda))
  5254. (donepb (member tb org-done-keywords-for-agenda)))
  5255. (cond ((and donepa (not donepb)) -1)
  5256. ((and (not donepa) donepb) +1)
  5257. ((< la lb) -1)
  5258. ((< lb la) +1)
  5259. (t nil))))
  5260. (defsubst org-cmp-alpha (a b)
  5261. "Compare the headlines, alphabetically."
  5262. (let* ((pla (get-text-property 0 'prefix-length a))
  5263. (plb (get-text-property 0 'prefix-length b))
  5264. (ta (and pla (substring a pla)))
  5265. (tb (and plb (substring b plb))))
  5266. (when pla
  5267. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5268. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5269. (setq ta (substring ta (match-end 0))))
  5270. (setq ta (downcase ta)))
  5271. (when plb
  5272. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5273. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5274. (setq tb (substring tb (match-end 0))))
  5275. (setq tb (downcase tb)))
  5276. (cond ((not ta) +1)
  5277. ((not tb) -1)
  5278. ((string-lessp ta tb) -1)
  5279. ((string-lessp tb ta) +1)
  5280. (t nil))))
  5281. (defsubst org-cmp-tag (a b)
  5282. "Compare the string values of the first tags of A and B."
  5283. (let ((ta (car (last (get-text-property 1 'tags a))))
  5284. (tb (car (last (get-text-property 1 'tags b)))))
  5285. (cond ((not ta) +1)
  5286. ((not tb) -1)
  5287. ((string-lessp ta tb) -1)
  5288. ((string-lessp tb ta) +1)
  5289. (t nil))))
  5290. (defsubst org-cmp-time (a b)
  5291. "Compare the time-of-day values of strings A and B."
  5292. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5293. (ta (or (get-text-property 1 'time-of-day a) def))
  5294. (tb (or (get-text-property 1 'time-of-day b) def)))
  5295. (cond ((< ta tb) -1)
  5296. ((< tb ta) +1)
  5297. (t nil))))
  5298. (defsubst org-cmp-habit-p (a b)
  5299. "Compare the todo states of strings A and B."
  5300. (let ((ha (get-text-property 1 'org-habit-p a))
  5301. (hb (get-text-property 1 'org-habit-p b)))
  5302. (cond ((and ha (not hb)) -1)
  5303. ((and (not ha) hb) +1)
  5304. (t nil))))
  5305. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5306. (defun org-entries-lessp (a b)
  5307. "Predicate for sorting agenda entries."
  5308. ;; The following variables will be used when the form is evaluated.
  5309. ;; So even though the compiler complains, keep them.
  5310. (let* ((ss org-agenda-sorting-strategy-selected)
  5311. (time-up (and (org-em 'time-up 'time-down ss)
  5312. (org-cmp-time a b)))
  5313. (time-down (if time-up (- time-up) nil))
  5314. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5315. (org-cmp-priority a b)))
  5316. (priority-down (if priority-up (- priority-up) nil))
  5317. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5318. (org-cmp-effort a b)))
  5319. (effort-down (if effort-up (- effort-up) nil))
  5320. (category-up (and (or (org-em 'category-up 'category-down ss)
  5321. (memq 'category-keep ss))
  5322. (org-cmp-category a b)))
  5323. (category-down (if category-up (- category-up) nil))
  5324. (category-keep (if category-up +1 nil))
  5325. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5326. (org-cmp-tag a b)))
  5327. (tag-down (if tag-up (- tag-up) nil))
  5328. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5329. (org-cmp-todo-state a b)))
  5330. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5331. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5332. (org-cmp-habit-p a b)))
  5333. (habit-down (if habit-up (- habit-up) nil))
  5334. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5335. (org-cmp-alpha a b)))
  5336. (alpha-down (if alpha-up (- alpha-up) nil))
  5337. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5338. user-defined-up user-defined-down)
  5339. (if (and need-user-cmp org-agenda-cmp-user-defined
  5340. (functionp org-agenda-cmp-user-defined))
  5341. (setq user-defined-up
  5342. (funcall org-agenda-cmp-user-defined a b)
  5343. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5344. (cdr (assoc
  5345. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5346. '((-1 . t) (1 . nil) (nil . nil))))))
  5347. ;;; Agenda restriction lock
  5348. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5349. "Overlay to mark the headline to which agenda commands are restricted.")
  5350. (overlay-put org-agenda-restriction-lock-overlay
  5351. 'face 'org-agenda-restriction-lock)
  5352. (overlay-put org-agenda-restriction-lock-overlay
  5353. 'help-echo "Agendas are currently limited to this subtree.")
  5354. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5355. (defun org-agenda-set-restriction-lock (&optional type)
  5356. "Set restriction lock for agenda, to current subtree or file.
  5357. Restriction will be the file if TYPE is `file', or if type is the
  5358. universal prefix '(4), or if the cursor is before the first headline
  5359. in the file. Otherwise, restriction will be to the current subtree."
  5360. (interactive "P")
  5361. (and (equal type '(4)) (setq type 'file))
  5362. (setq type (cond
  5363. (type type)
  5364. ((org-at-heading-p) 'subtree)
  5365. ((condition-case nil (org-back-to-heading t) (error nil))
  5366. 'subtree)
  5367. (t 'file)))
  5368. (if (eq type 'subtree)
  5369. (progn
  5370. (setq org-agenda-restrict t)
  5371. (setq org-agenda-overriding-restriction 'subtree)
  5372. (put 'org-agenda-files 'org-restrict
  5373. (list (buffer-file-name (buffer-base-buffer))))
  5374. (org-back-to-heading t)
  5375. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5376. (move-marker org-agenda-restrict-begin (point))
  5377. (move-marker org-agenda-restrict-end
  5378. (save-excursion (org-end-of-subtree t)))
  5379. (message "Locking agenda restriction to subtree"))
  5380. (put 'org-agenda-files 'org-restrict
  5381. (list (buffer-file-name (buffer-base-buffer))))
  5382. (setq org-agenda-restrict nil)
  5383. (setq org-agenda-overriding-restriction 'file)
  5384. (move-marker org-agenda-restrict-begin nil)
  5385. (move-marker org-agenda-restrict-end nil)
  5386. (message "Locking agenda restriction to file"))
  5387. (setq current-prefix-arg nil)
  5388. (org-agenda-maybe-redo))
  5389. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5390. "Remove the agenda restriction lock."
  5391. (interactive "P")
  5392. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5393. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5394. (setq org-agenda-overriding-restriction nil)
  5395. (setq org-agenda-restrict nil)
  5396. (put 'org-agenda-files 'org-restrict nil)
  5397. (move-marker org-agenda-restrict-begin nil)
  5398. (move-marker org-agenda-restrict-end nil)
  5399. (setq current-prefix-arg nil)
  5400. (message "Agenda restriction lock removed")
  5401. (or noupdate (org-agenda-maybe-redo)))
  5402. (defun org-agenda-maybe-redo ()
  5403. "If there is any window showing the agenda view, update it."
  5404. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5405. (w0 (selected-window)))
  5406. (when w
  5407. (select-window w)
  5408. (org-agenda-redo)
  5409. (select-window w0)
  5410. (if org-agenda-overriding-restriction
  5411. (message "Agenda view shifted to new %s restriction"
  5412. org-agenda-overriding-restriction)
  5413. (message "Agenda restriction lock removed")))))
  5414. ;;; Agenda commands
  5415. (defun org-agenda-check-type (error &rest types)
  5416. "Check if agenda buffer is of allowed type.
  5417. If ERROR is non-nil, throw an error, otherwise just return nil."
  5418. (if (memq org-agenda-type types)
  5419. t
  5420. (if error
  5421. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5422. nil)))
  5423. (defun org-agenda-quit ()
  5424. "Exit agenda by removing the window or the buffer."
  5425. (interactive)
  5426. (if org-agenda-columns-active
  5427. (org-columns-quit)
  5428. (let ((buf (current-buffer)))
  5429. (if (eq org-agenda-window-setup 'other-frame)
  5430. (progn
  5431. (kill-buffer buf)
  5432. (org-agenda-reset-markers)
  5433. (org-columns-remove-overlays)
  5434. (setq org-agenda-archives-mode nil)
  5435. (delete-frame))
  5436. (and (not (eq org-agenda-window-setup 'current-window))
  5437. (not (one-window-p))
  5438. (delete-window))
  5439. (kill-buffer buf)
  5440. (org-agenda-reset-markers)
  5441. (org-columns-remove-overlays)
  5442. (setq org-agenda-archives-mode nil)))
  5443. ;; Maybe restore the pre-agenda window configuration.
  5444. (and org-agenda-restore-windows-after-quit
  5445. (not (eq org-agenda-window-setup 'other-frame))
  5446. org-pre-agenda-window-conf
  5447. (set-window-configuration org-pre-agenda-window-conf))))
  5448. (defun org-agenda-exit ()
  5449. "Exit agenda by removing the window or the buffer.
  5450. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5451. Org-mode buffers visited directly by the user will not be touched."
  5452. (interactive)
  5453. (org-release-buffers org-agenda-new-buffers)
  5454. (setq org-agenda-new-buffers nil)
  5455. (org-agenda-quit))
  5456. (defun org-agenda-execute (arg)
  5457. "Execute another agenda command, keeping same window.
  5458. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5459. in the agenda."
  5460. (interactive "P")
  5461. (let ((org-agenda-window-setup 'current-window))
  5462. (org-agenda arg)))
  5463. (defun org-agenda-redo ()
  5464. "Rebuild Agenda.
  5465. When this is the global TODO list, a prefix argument will be interpreted."
  5466. (interactive)
  5467. (let* ((org-agenda-keep-modes t)
  5468. (filter org-agenda-filter)
  5469. (preset (get 'org-agenda-filter :preset-filter))
  5470. (org-agenda-filter-while-redo (or filter preset))
  5471. (cols org-agenda-columns-active)
  5472. (line (org-current-line))
  5473. (window-line (- line (org-current-line (window-start))))
  5474. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5475. (put 'org-agenda-filter :preset-filter nil)
  5476. (and cols (org-columns-quit))
  5477. (message "Rebuilding agenda buffer...")
  5478. (org-let lprops '(eval org-agenda-redo-command))
  5479. (setq org-agenda-undo-list nil
  5480. org-agenda-pending-undo-list nil)
  5481. (message "Rebuilding agenda buffer...done")
  5482. (put 'org-agenda-filter :preset-filter preset)
  5483. (and (or filter preset) (org-agenda-filter-apply filter))
  5484. (and cols (interactive-p) (org-agenda-columns))
  5485. (org-goto-line line)
  5486. (recenter window-line)))
  5487. (defvar org-global-tags-completion-table nil)
  5488. (defvar org-agenda-filter-form nil)
  5489. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5490. "Keep only those lines in the agenda buffer that have a specific tag.
  5491. The tag is selected with its fast selection letter, as configured.
  5492. With prefix argument STRIP, remove all lines that do have the tag.
  5493. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5494. used to narrow the search - the interactive user can also press `-' or `+'
  5495. to switch to narrowing."
  5496. (interactive "P")
  5497. (let* ((alist org-tag-alist-for-agenda)
  5498. (tag-chars (mapconcat
  5499. (lambda (x) (if (and (not (symbolp (car x)))
  5500. (cdr x))
  5501. (char-to-string (cdr x))
  5502. ""))
  5503. alist ""))
  5504. (efforts (org-split-string
  5505. (or (cdr (assoc (concat org-effort-property "_ALL")
  5506. org-global-properties))
  5507. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
  5508. (effort-op org-agenda-filter-effort-default-operator)
  5509. (effort-prompt "")
  5510. (inhibit-read-only t)
  5511. (current org-agenda-filter)
  5512. maybe-reftresh a n tag)
  5513. (unless char
  5514. (message
  5515. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5516. (if narrow "Narrow" "Filter") tag-chars
  5517. (if org-agenda-auto-exclude-function "[RET], " ""))
  5518. (setq char (read-char)))
  5519. (when (member char '(?+ ?-))
  5520. ;; Narrowing down
  5521. (cond ((equal char ?-) (setq strip t narrow t))
  5522. ((equal char ?+) (setq strip nil narrow t)))
  5523. (message
  5524. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5525. (setq char (read-char)))
  5526. (when (member char '(?< ?> ?= ??))
  5527. ;; An effort operator
  5528. (setq effort-op (char-to-string char))
  5529. (setq alist nil) ; to make sure it will be interpreted as effort.
  5530. (unless (equal char ??)
  5531. (loop for i from 0 to 9 do
  5532. (setq effort-prompt
  5533. (concat
  5534. effort-prompt " ["
  5535. (if (= i 9) "0" (int-to-string (1+ i)))
  5536. "]" (nth i efforts))))
  5537. (message "Effort%s: %s " effort-op effort-prompt)
  5538. (setq char (read-char))
  5539. (when (or (< char ?0) (> char ?9))
  5540. (error "Need 1-9,0 to select effort" ))))
  5541. (when (equal char ?\t)
  5542. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5543. (org-set-local 'org-global-tags-completion-table
  5544. (org-global-tags-completion-table)))
  5545. (let ((completion-ignore-case t))
  5546. (setq tag (org-icompleting-read
  5547. "Tag: " org-global-tags-completion-table))))
  5548. (cond
  5549. ((equal char ?\r)
  5550. (org-agenda-filter-by-tag-show-all)
  5551. (when org-agenda-auto-exclude-function
  5552. (setq org-agenda-filter '())
  5553. (dolist (tag (org-agenda-get-represented-tags))
  5554. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5555. (if modifier
  5556. (push modifier org-agenda-filter))))
  5557. (if (not (null org-agenda-filter))
  5558. (org-agenda-filter-apply org-agenda-filter)))
  5559. (setq maybe-reftresh t))
  5560. ((equal char ?/)
  5561. (org-agenda-filter-by-tag-show-all)
  5562. (when (get 'org-agenda-filter :preset-filter)
  5563. (org-agenda-filter-apply org-agenda-filter))
  5564. (setq maybe-reftresh t))
  5565. ((or (equal char ?\ )
  5566. (setq a (rassoc char alist))
  5567. (and (>= char ?0) (<= char ?9)
  5568. (setq n (if (= char ?0) 9 (- char ?0 1))
  5569. tag (concat effort-op (nth n efforts))
  5570. a (cons tag nil)))
  5571. (and (= char ??)
  5572. (setq tag "?eff")
  5573. a (cons tag nil))
  5574. (and tag (setq a (cons tag nil))))
  5575. (org-agenda-filter-by-tag-show-all)
  5576. (setq tag (car a))
  5577. (setq org-agenda-filter
  5578. (cons (concat (if strip "-" "+") tag)
  5579. (if narrow current nil)))
  5580. (org-agenda-filter-apply org-agenda-filter)
  5581. (setq maybe-reftresh t))
  5582. (t (error "Invalid tag selection character %c" char)))
  5583. (when (and maybe-reftresh
  5584. (eq org-agenda-clockreport-mode 'with-filter))
  5585. (org-agenda-redo))))
  5586. (defun org-agenda-get-represented-tags ()
  5587. "Get a list of all tags currently represented in the agenda."
  5588. (let (p tags)
  5589. (save-excursion
  5590. (goto-char (point-min))
  5591. (while (setq p (next-single-property-change (point) 'tags))
  5592. (goto-char p)
  5593. (mapc (lambda (x) (add-to-list 'tags x))
  5594. (get-text-property (point) 'tags))))
  5595. tags))
  5596. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5597. "Refine the current filter. See `org-agenda-filter-by-tag."
  5598. (interactive "P")
  5599. (org-agenda-filter-by-tag strip char 'refine))
  5600. (defun org-agenda-filter-make-matcher ()
  5601. "Create the form that tests a line for the agenda filter."
  5602. (let (f f1)
  5603. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5604. org-agenda-filter))
  5605. (if (member x '("-" "+"))
  5606. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5607. (if (string-match "[<=>?]" x)
  5608. (setq f1 (org-agenda-filter-effort-form x))
  5609. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5610. (if (equal (string-to-char x) ?-)
  5611. (setq f1 (list 'not f1))))
  5612. (push f1 f))
  5613. (cons 'and (nreverse f))))
  5614. (defun org-agenda-filter-effort-form (e)
  5615. "Return the form to compare the effort of the current line with what E says.
  5616. E looks like \"+<2:25\"."
  5617. (let (op)
  5618. (setq e (substring e 1))
  5619. (setq op (string-to-char e) e (substring e 1))
  5620. (setq op (cond ((equal op ?<) '<=)
  5621. ((equal op ?>) '>=)
  5622. ((equal op ??) op)
  5623. (t '=)))
  5624. (list 'org-agenda-compare-effort (list 'quote op)
  5625. (org-hh:mm-string-to-minutes e))))
  5626. (defun org-agenda-compare-effort (op value)
  5627. "Compare the effort of the current line with VALUE, using OP.
  5628. If the line does not have an effort defined, return nil."
  5629. (let ((eff (org-get-at-bol 'effort-minutes)))
  5630. (if (equal op ??)
  5631. (not eff)
  5632. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5633. value))))
  5634. (defun org-agenda-filter-apply (filter)
  5635. "Set FILTER as the new agenda filter and apply it."
  5636. (let (tags)
  5637. (setq org-agenda-filter filter
  5638. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5639. (org-agenda-set-mode-name)
  5640. (save-excursion
  5641. (goto-char (point-min))
  5642. (while (not (eobp))
  5643. (if (org-get-at-bol 'org-marker)
  5644. (progn
  5645. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5646. (if (not (eval org-agenda-filter-form))
  5647. (org-agenda-filter-by-tag-hide-line))
  5648. (beginning-of-line 2))
  5649. (beginning-of-line 2))))
  5650. (if (get-char-property (point) 'invisible)
  5651. (org-agenda-previous-line))))
  5652. (defun org-agenda-filter-by-tag-hide-line ()
  5653. (let (ov)
  5654. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5655. (point-at-eol)))
  5656. (overlay-put ov 'invisible t)
  5657. (overlay-put ov 'type 'tags-filter)
  5658. (push ov org-agenda-filter-overlays)))
  5659. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5660. (setq pos (or pos (point)))
  5661. (save-excursion
  5662. (dolist (ov (overlays-at pos))
  5663. (when (and (overlay-get ov 'invisible)
  5664. (eq (overlay-get ov 'type) 'tags-filter))
  5665. (goto-char pos)
  5666. (if (< (overlay-start ov) (point-at-eol))
  5667. (move-overlay ov (point-at-eol)
  5668. (overlay-end ov)))))))
  5669. (defun org-agenda-filter-by-tag-show-all ()
  5670. (mapc 'delete-overlay org-agenda-filter-overlays)
  5671. (setq org-agenda-filter-overlays nil)
  5672. (setq org-agenda-filter nil)
  5673. (setq org-agenda-filter-form nil)
  5674. (org-agenda-set-mode-name))
  5675. (defun org-agenda-manipulate-query-add ()
  5676. "Manipulate the query by adding a search term with positive selection.
  5677. Positive selection means the term must be matched for selection of an entry."
  5678. (interactive)
  5679. (org-agenda-manipulate-query ?\[))
  5680. (defun org-agenda-manipulate-query-subtract ()
  5681. "Manipulate the query by adding a search term with negative selection.
  5682. Negative selection means term must not be matched for selection of an entry."
  5683. (interactive)
  5684. (org-agenda-manipulate-query ?\]))
  5685. (defun org-agenda-manipulate-query-add-re ()
  5686. "Manipulate the query by adding a search regexp with positive selection.
  5687. Positive selection means the regexp must match for selection of an entry."
  5688. (interactive)
  5689. (org-agenda-manipulate-query ?\{))
  5690. (defun org-agenda-manipulate-query-subtract-re ()
  5691. "Manipulate the query by adding a search regexp with negative selection.
  5692. Negative selection means regexp must not match for selection of an entry."
  5693. (interactive)
  5694. (org-agenda-manipulate-query ?\}))
  5695. (defun org-agenda-manipulate-query (char)
  5696. (cond
  5697. ((memq org-agenda-type '(timeline agenda))
  5698. (let ((org-agenda-include-inactive-timestamps t))
  5699. (org-agenda-redo))
  5700. (message "Display now includes inactive timestamps as well"))
  5701. ((eq org-agenda-type 'search)
  5702. (org-add-to-string
  5703. 'org-agenda-query-string
  5704. (if org-agenda-last-search-view-search-was-boolean
  5705. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5706. (?\{ . " +{}") (?\} . " -{}"))))
  5707. " "))
  5708. (setq org-agenda-redo-command
  5709. (list 'org-search-view
  5710. org-todo-only
  5711. org-agenda-query-string
  5712. (+ (length org-agenda-query-string)
  5713. (if (member char '(?\{ ?\})) 0 1))))
  5714. (set-register org-agenda-query-register org-agenda-query-string)
  5715. (org-agenda-redo))
  5716. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5717. org-agenda-type))))
  5718. (defun org-add-to-string (var string)
  5719. (set var (concat (symbol-value var) string)))
  5720. (defun org-agenda-goto-date (date)
  5721. "Jump to DATE in agenda."
  5722. (interactive (list (let ((org-read-date-prefer-future
  5723. (eval org-agenda-jump-prefer-future)))
  5724. (org-read-date))))
  5725. (org-agenda-list nil date))
  5726. (defun org-agenda-goto-today ()
  5727. "Go to today."
  5728. (interactive)
  5729. (org-agenda-check-type t 'timeline 'agenda)
  5730. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5731. (cond
  5732. (tdpos (goto-char tdpos))
  5733. ((eq org-agenda-type 'agenda)
  5734. (let* ((sd (org-agenda-compute-starting-span
  5735. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  5736. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5737. (setf (nth 1 org-agenda-overriding-arguments) sd)
  5738. (org-agenda-redo)
  5739. (org-agenda-find-same-or-today-or-agenda)))
  5740. (t (error "Cannot find today")))))
  5741. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5742. (goto-char
  5743. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5744. (text-property-any (point-min) (point-max) 'org-today t)
  5745. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5746. (point-min))))
  5747. (defun org-agenda-later (arg)
  5748. "Go forward in time by thee current span.
  5749. With prefix ARG, go forward that many times the current span."
  5750. (interactive "p")
  5751. (org-agenda-check-type t 'agenda)
  5752. (let* ((span org-agenda-current-span)
  5753. (sd org-starting-day)
  5754. (greg (calendar-gregorian-from-absolute sd))
  5755. (cnt (org-get-at-bol 'org-day-cnt))
  5756. greg2)
  5757. (cond
  5758. ((eq span 'day)
  5759. (setq sd (+ arg sd)))
  5760. ((eq span 'week)
  5761. (setq sd (+ (* 7 arg) sd)))
  5762. ((eq span 'month)
  5763. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5764. sd (calendar-absolute-from-gregorian greg2))
  5765. (setcar greg2 (1+ (car greg2))))
  5766. ((eq span 'year)
  5767. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5768. sd (calendar-absolute-from-gregorian greg2))
  5769. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  5770. (t
  5771. (setq sd (+ (* span arg) sd))))
  5772. (let ((org-agenda-overriding-arguments
  5773. (list (car org-agenda-last-arguments) sd span t)))
  5774. (org-agenda-redo)
  5775. (org-agenda-find-same-or-today-or-agenda cnt))))
  5776. (defun org-agenda-earlier (arg)
  5777. "Go backward in time by the current span.
  5778. With prefix ARG, go backward that many times the current span."
  5779. (interactive "p")
  5780. (org-agenda-later (- arg)))
  5781. (defun org-agenda-view-mode-dispatch ()
  5782. "Call one of the view mode commands."
  5783. (interactive)
  5784. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  5785. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
  5786. [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
  5787. (let ((a (read-char-exclusive)))
  5788. (case a
  5789. (?\ (call-interactively 'org-agenda-reset-view))
  5790. (?d (call-interactively 'org-agenda-day-view))
  5791. (?w (call-interactively 'org-agenda-week-view))
  5792. (?m (call-interactively 'org-agenda-month-view))
  5793. (?y (call-interactively 'org-agenda-year-view))
  5794. (?l (call-interactively 'org-agenda-log-mode))
  5795. (?L (org-agenda-log-mode '(4)))
  5796. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5797. (?a (call-interactively 'org-agenda-archives-mode))
  5798. (?A (org-agenda-archives-mode 'files))
  5799. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5800. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5801. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5802. (?D (call-interactively 'org-agenda-toggle-diary))
  5803. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5804. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5805. (org-agenda-check-type t 'timeline 'agenda)
  5806. (org-agenda-redo))
  5807. (message "Display now includes inactive timestamps as well"))
  5808. (?q (message "Abort"))
  5809. (otherwise (error "Invalid key" )))))
  5810. (defun org-agenda-reset-view ()
  5811. "Switch to default view for agenda."
  5812. (interactive)
  5813. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  5814. (defun org-agenda-day-view (&optional day-of-year)
  5815. "Switch to daily view for agenda.
  5816. With argument DAY-OF-YEAR, switch to that day of the year."
  5817. (interactive "P")
  5818. (org-agenda-change-time-span 'day day-of-year))
  5819. (defun org-agenda-week-view (&optional iso-week)
  5820. "Switch to daily view for agenda.
  5821. With argument ISO-WEEK, switch to the corresponding ISO week.
  5822. If ISO-WEEK has more then 2 digits, only the last two encode the
  5823. week. Any digits before this encode a year. So 200712 means
  5824. week 12 of year 2007. Years in the range 1938-2037 can also be
  5825. written as 2-digit years."
  5826. (interactive "P")
  5827. (org-agenda-change-time-span 'week iso-week))
  5828. (defun org-agenda-month-view (&optional month)
  5829. "Switch to monthly view for agenda.
  5830. With argument MONTH, switch to that month."
  5831. (interactive "P")
  5832. (org-agenda-change-time-span 'month month))
  5833. (defun org-agenda-year-view (&optional year)
  5834. "Switch to yearly view for agenda.
  5835. With argument YEAR, switch to that year.
  5836. If MONTH has more then 2 digits, only the last two encode the
  5837. month. Any digits before this encode a year. So 200712 means
  5838. December year 2007. Years in the range 1938-2037 can also be
  5839. written as 2-digit years."
  5840. (interactive "P")
  5841. (when year
  5842. (setq year (org-small-year-to-year year)))
  5843. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  5844. (org-agenda-change-time-span 'year year)
  5845. (error "Abort")))
  5846. (defun org-agenda-change-time-span (span &optional n)
  5847. "Change the agenda view to SPAN.
  5848. SPAN may be `day', `week', `month', `year'."
  5849. (org-agenda-check-type t 'agenda)
  5850. (if (and (not n) (equal org-agenda-current-span span))
  5851. (error "Viewing span is already \"%s\"" span))
  5852. (let* ((sd (or (org-get-at-bol 'day)
  5853. org-starting-day))
  5854. (sd (org-agenda-compute-starting-span sd span n))
  5855. (org-agenda-overriding-arguments
  5856. (or org-agenda-overriding-arguments
  5857. (list (car org-agenda-last-arguments) sd span t))))
  5858. (org-agenda-redo)
  5859. (org-agenda-find-same-or-today-or-agenda))
  5860. (org-agenda-set-mode-name)
  5861. (message "Switched to %s view" span))
  5862. (defun org-agenda-compute-starting-span (sd span &optional n)
  5863. "Compute starting date for agenda.
  5864. SPAN may be `day', `week', `month', `year'. The return value
  5865. is a cons cell with the starting date and the number of days,
  5866. so that the date SD will be in that range."
  5867. (let* ((greg (calendar-gregorian-from-absolute sd))
  5868. (dg (nth 1 greg))
  5869. (mg (car greg))
  5870. (yg (nth 2 greg)))
  5871. (cond
  5872. ((eq span 'day)
  5873. (when n
  5874. (setq sd (+ (calendar-absolute-from-gregorian
  5875. (list mg 1 yg))
  5876. n -1))))
  5877. ((eq span 'week)
  5878. (let* ((nt (calendar-day-of-week
  5879. (calendar-gregorian-from-absolute sd)))
  5880. (d (if org-agenda-start-on-weekday
  5881. (- nt org-agenda-start-on-weekday)
  5882. 0))
  5883. y1)
  5884. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  5885. (when n
  5886. (require 'cal-iso)
  5887. (when (> n 99)
  5888. (setq y1 (org-small-year-to-year (/ n 100))
  5889. n (mod n 100)))
  5890. (setq sd
  5891. (calendar-absolute-from-iso
  5892. (list n 1
  5893. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  5894. ((eq span 'month)
  5895. (let (y1)
  5896. (when (and n (> n 99))
  5897. (setq y1 (org-small-year-to-year (/ n 100))
  5898. n (mod n 100)))
  5899. (setq sd (calendar-absolute-from-gregorian
  5900. (list (or n mg) 1 (or y1 yg))))))
  5901. ((eq span 'year)
  5902. (setq sd (calendar-absolute-from-gregorian
  5903. (list 1 1 (or n yg))))))
  5904. sd))
  5905. (defun org-agenda-next-date-line (&optional arg)
  5906. "Jump to the next line indicating a date in agenda buffer."
  5907. (interactive "p")
  5908. (org-agenda-check-type t 'agenda 'timeline)
  5909. (beginning-of-line 1)
  5910. ;; This does not work if user makes date format that starts with a blank
  5911. (if (looking-at "^\\S-") (forward-char 1))
  5912. (if (not (re-search-forward "^\\S-" nil t arg))
  5913. (progn
  5914. (backward-char 1)
  5915. (error "No next date after this line in this buffer")))
  5916. (goto-char (match-beginning 0)))
  5917. (defun org-agenda-previous-date-line (&optional arg)
  5918. "Jump to the previous line indicating a date in agenda buffer."
  5919. (interactive "p")
  5920. (org-agenda-check-type t 'agenda 'timeline)
  5921. (beginning-of-line 1)
  5922. (if (not (re-search-backward "^\\S-" nil t arg))
  5923. (error "No previous date before this line in this buffer")))
  5924. ;; Initialize the highlight
  5925. (defvar org-hl (make-overlay 1 1))
  5926. (overlay-put org-hl 'face 'highlight)
  5927. (defun org-highlight (begin end &optional buffer)
  5928. "Highlight a region with overlay."
  5929. (move-overlay org-hl begin end (or buffer (current-buffer))))
  5930. (defun org-unhighlight ()
  5931. "Detach overlay INDEX."
  5932. (org-detach-overlay org-hl))
  5933. ;; FIXME this is currently not used.
  5934. (defun org-highlight-until-next-command (beg end &optional buffer)
  5935. "Move the highlight overlay to BEG/END, remove it before the next command."
  5936. (org-highlight beg end buffer)
  5937. (add-hook 'pre-command-hook 'org-unhighlight-once))
  5938. (defun org-unhighlight-once ()
  5939. "Remove the highlight from its position, and this function from the hook."
  5940. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  5941. (org-unhighlight))
  5942. (defun org-agenda-follow-mode ()
  5943. "Toggle follow mode in an agenda buffer."
  5944. (interactive)
  5945. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  5946. (org-agenda-set-mode-name)
  5947. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  5948. (org-agenda-show))
  5949. (message "Follow mode is %s"
  5950. (if org-agenda-follow-mode "on" "off")))
  5951. (defun org-agenda-entry-text-mode (&optional arg)
  5952. "Toggle entry text mode in an agenda buffer."
  5953. (interactive "P")
  5954. (setq org-agenda-entry-text-mode (or (integerp arg)
  5955. (not org-agenda-entry-text-mode)))
  5956. (org-agenda-entry-text-hide)
  5957. (and org-agenda-entry-text-mode
  5958. (let ((org-agenda-entry-text-maxlines
  5959. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5960. (org-agenda-entry-text-show)))
  5961. (org-agenda-set-mode-name)
  5962. (message "Entry text mode is %s. Maximum number of lines is %d"
  5963. (if org-agenda-entry-text-mode "on" "off")
  5964. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5965. (defun org-agenda-clockreport-mode (&optional with-filter)
  5966. "Toggle clocktable mode in an agenda buffer.
  5967. With prefix arg WITH-FILTER, make the clocktable respect the current
  5968. agenda filter."
  5969. (interactive "P")
  5970. (org-agenda-check-type t 'agenda)
  5971. (if with-filter
  5972. (setq org-agenda-clockreport-mode 'with-filter)
  5973. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  5974. (org-agenda-set-mode-name)
  5975. (org-agenda-redo)
  5976. (message "Clocktable mode is %s"
  5977. (if org-agenda-clockreport-mode "on" "off")))
  5978. (defun org-agenda-log-mode (&optional special)
  5979. "Toggle log mode in an agenda buffer.
  5980. With argument SPECIAL, show all possible log items, not only the ones
  5981. configured in `org-agenda-log-mode-items'.
  5982. With a double `C-u' prefix arg, show *only* log items, nothing else."
  5983. (interactive "P")
  5984. (org-agenda-check-type t 'agenda 'timeline)
  5985. (setq org-agenda-show-log
  5986. (if (equal special '(16))
  5987. 'only
  5988. (if special '(closed clock state)
  5989. (not org-agenda-show-log))))
  5990. (org-agenda-set-mode-name)
  5991. (org-agenda-redo)
  5992. (message "Log mode is %s"
  5993. (if org-agenda-show-log "on" "off")))
  5994. (defun org-agenda-archives-mode (&optional with-files)
  5995. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  5996. When called with a prefix argument, include all archive files as well."
  5997. (interactive "P")
  5998. (setq org-agenda-archives-mode
  5999. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6000. (org-agenda-set-mode-name)
  6001. (org-agenda-redo)
  6002. (message
  6003. "%s"
  6004. (cond
  6005. ((eq org-agenda-archives-mode nil)
  6006. "No archives are included")
  6007. ((eq org-agenda-archives-mode 'trees)
  6008. (format "Trees with :%s: tag are included" org-archive-tag))
  6009. ((eq org-agenda-archives-mode t)
  6010. (format "Trees with :%s: tag and all active archive files are included"
  6011. org-archive-tag)))))
  6012. (defun org-agenda-toggle-diary ()
  6013. "Toggle diary inclusion in an agenda buffer."
  6014. (interactive)
  6015. (org-agenda-check-type t 'agenda)
  6016. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6017. (org-agenda-redo)
  6018. (org-agenda-set-mode-name)
  6019. (message "Diary inclusion turned %s"
  6020. (if org-agenda-include-diary "on" "off")))
  6021. (defun org-agenda-toggle-deadlines ()
  6022. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6023. (interactive)
  6024. (org-agenda-check-type t 'agenda)
  6025. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6026. (org-agenda-redo)
  6027. (org-agenda-set-mode-name)
  6028. (message "Deadlines inclusion turned %s"
  6029. (if org-agenda-include-deadlines "on" "off")))
  6030. (defun org-agenda-toggle-time-grid ()
  6031. "Toggle time grid in an agenda buffer."
  6032. (interactive)
  6033. (org-agenda-check-type t 'agenda)
  6034. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6035. (org-agenda-redo)
  6036. (org-agenda-set-mode-name)
  6037. (message "Time-grid turned %s"
  6038. (if org-agenda-use-time-grid "on" "off")))
  6039. (defun org-agenda-set-mode-name ()
  6040. "Set the mode name to indicate all the small mode settings."
  6041. (setq mode-name
  6042. (list "Org-Agenda"
  6043. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6044. " "
  6045. '(:eval (org-agenda-span-name org-agenda-current-span))
  6046. (if org-agenda-follow-mode " Follow" "")
  6047. (if org-agenda-entry-text-mode " ETxt" "")
  6048. (if org-agenda-include-diary " Diary" "")
  6049. (if org-agenda-include-deadlines " Ddl" "")
  6050. (if org-agenda-use-time-grid " Grid" "")
  6051. (if (and (boundp 'org-habit-show-habits)
  6052. org-habit-show-habits) " Habit" "")
  6053. (if (consp org-agenda-show-log) " LogAll"
  6054. (if org-agenda-show-log " Log" ""))
  6055. (if (or org-agenda-filter (get 'org-agenda-filter
  6056. :preset-filter))
  6057. (concat " {" (mapconcat
  6058. 'identity
  6059. (append (get 'org-agenda-filter
  6060. :preset-filter)
  6061. org-agenda-filter) "") "}")
  6062. "")
  6063. (if org-agenda-archives-mode
  6064. (if (eq org-agenda-archives-mode t)
  6065. " Archives"
  6066. (format " :%s:" org-archive-tag))
  6067. "")
  6068. (if org-agenda-clockreport-mode
  6069. (if (eq org-agenda-clockreport-mode 'with-filter)
  6070. " Clock{}" " Clock")
  6071. "")))
  6072. (force-mode-line-update))
  6073. (defun org-agenda-post-command-hook ()
  6074. (setq org-agenda-type
  6075. (or (get-text-property (point) 'org-agenda-type)
  6076. (get-text-property (max (point-min) (1- (point)))
  6077. 'org-agenda-type))))
  6078. (defun org-agenda-next-line ()
  6079. "Move cursor to the next line, and show if follow mode is active."
  6080. (interactive)
  6081. (call-interactively 'next-line)
  6082. (org-agenda-do-context-action))
  6083. (defun org-agenda-previous-line ()
  6084. "Move cursor to the previous line, and show if follow-mode is active."
  6085. (interactive)
  6086. (call-interactively 'previous-line)
  6087. (org-agenda-do-context-action))
  6088. (defun org-agenda-do-context-action ()
  6089. "Show outline path and, maybe, follow mode window."
  6090. (let ((m (org-get-at-bol 'org-marker)))
  6091. (if (and org-agenda-follow-mode m)
  6092. (org-agenda-show))
  6093. (if (and m org-agenda-show-outline-path)
  6094. (org-with-point-at m
  6095. (org-display-outline-path t)))))
  6096. (defun org-agenda-show-priority ()
  6097. "Show the priority of the current item.
  6098. This priority is composed of the main priority given with the [#A] cookies,
  6099. and by additional input from the age of a schedules or deadline entry."
  6100. (interactive)
  6101. (let* ((pri (org-get-at-bol 'priority)))
  6102. (message "Priority is %d" (if pri pri -1000))))
  6103. (defun org-agenda-show-tags ()
  6104. "Show the tags applicable to the current item."
  6105. (interactive)
  6106. (let* ((tags (org-get-at-bol 'tags)))
  6107. (if tags
  6108. (message "Tags are :%s:"
  6109. (org-no-properties (mapconcat 'identity tags ":")))
  6110. (message "No tags associated with this line"))))
  6111. (defun org-agenda-goto (&optional highlight)
  6112. "Go to the Org-mode file which contains the item at point."
  6113. (interactive)
  6114. (let* ((marker (or (org-get-at-bol 'org-marker)
  6115. (org-agenda-error)))
  6116. (buffer (marker-buffer marker))
  6117. (pos (marker-position marker)))
  6118. (switch-to-buffer-other-window buffer)
  6119. (widen)
  6120. (push-mark)
  6121. (goto-char pos)
  6122. (when (org-mode-p)
  6123. (org-show-context 'agenda)
  6124. (save-excursion
  6125. (and (outline-next-heading)
  6126. (org-flag-heading nil)))) ; show the next heading
  6127. (when (outline-invisible-p)
  6128. (show-entry)) ; display invisible text
  6129. (recenter (/ (window-height) 2))
  6130. (run-hooks 'org-agenda-after-show-hook)
  6131. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6132. (defvar org-agenda-after-show-hook nil
  6133. "Normal hook run after an item has been shown from the agenda.
  6134. Point is in the buffer where the item originated.")
  6135. (defun org-agenda-kill ()
  6136. "Kill the entry or subtree belonging to the current agenda entry."
  6137. (interactive)
  6138. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6139. (let* ((marker (or (org-get-at-bol 'org-marker)
  6140. (org-agenda-error)))
  6141. (buffer (marker-buffer marker))
  6142. (pos (marker-position marker))
  6143. (type (org-get-at-bol 'type))
  6144. dbeg dend (n 0) conf)
  6145. (org-with-remote-undo buffer
  6146. (with-current-buffer buffer
  6147. (save-excursion
  6148. (goto-char pos)
  6149. (if (and (org-mode-p) (not (member type '("sexp"))))
  6150. (setq dbeg (progn (org-back-to-heading t) (point))
  6151. dend (org-end-of-subtree t t))
  6152. (setq dbeg (point-at-bol)
  6153. dend (min (point-max) (1+ (point-at-eol)))))
  6154. (goto-char dbeg)
  6155. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6156. (setq conf (or (eq t org-agenda-confirm-kill)
  6157. (and (numberp org-agenda-confirm-kill)
  6158. (> n org-agenda-confirm-kill))))
  6159. (and conf
  6160. (not (y-or-n-p
  6161. (format "Delete entry with %d lines in buffer \"%s\"? "
  6162. n (buffer-name buffer))))
  6163. (error "Abort"))
  6164. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6165. (with-current-buffer buffer (delete-region dbeg dend))
  6166. (message "Agenda item and source killed"))))
  6167. (defvar org-archive-default-command)
  6168. (defun org-agenda-archive-default ()
  6169. "Archive the entry or subtree belonging to the current agenda entry."
  6170. (interactive)
  6171. (require 'org-archive)
  6172. (org-agenda-archive-with org-archive-default-command))
  6173. (defun org-agenda-archive-default-with-confirmation ()
  6174. "Archive the entry or subtree belonging to the current agenda entry."
  6175. (interactive)
  6176. (require 'org-archive)
  6177. (org-agenda-archive-with org-archive-default-command 'confirm))
  6178. (defun org-agenda-archive ()
  6179. "Archive the entry or subtree belonging to the current agenda entry."
  6180. (interactive)
  6181. (org-agenda-archive-with 'org-archive-subtree))
  6182. (defun org-agenda-archive-to-archive-sibling ()
  6183. "Move the entry to the archive sibling."
  6184. (interactive)
  6185. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6186. (defun org-agenda-archive-with (cmd &optional confirm)
  6187. "Move the entry to the archive sibling."
  6188. (interactive)
  6189. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6190. (let* ((marker (or (org-get-at-bol 'org-marker)
  6191. (org-agenda-error)))
  6192. (buffer (marker-buffer marker))
  6193. (pos (marker-position marker)))
  6194. (org-with-remote-undo buffer
  6195. (with-current-buffer buffer
  6196. (if (org-mode-p)
  6197. (if (and confirm
  6198. (not (y-or-n-p "Archive this subtree or entry? ")))
  6199. (error "Abort")
  6200. (save-excursion
  6201. (goto-char pos)
  6202. (org-remove-subtree-entries-from-agenda)
  6203. (org-back-to-heading t)
  6204. (funcall cmd)))
  6205. (error "Archiving works only in Org-mode files"))))))
  6206. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6207. "Remove all lines in the agenda that correspond to a given subtree.
  6208. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6209. If this information is not given, the function uses the tree at point."
  6210. (let ((buf (or buf (current-buffer))) m p)
  6211. (save-excursion
  6212. (unless (and beg end)
  6213. (org-back-to-heading t)
  6214. (setq beg (point))
  6215. (org-end-of-subtree t)
  6216. (setq end (point)))
  6217. (set-buffer (get-buffer org-agenda-buffer-name))
  6218. (save-excursion
  6219. (goto-char (point-max))
  6220. (beginning-of-line 1)
  6221. (while (not (bobp))
  6222. (when (and (setq m (org-get-at-bol 'org-marker))
  6223. (equal buf (marker-buffer m))
  6224. (setq p (marker-position m))
  6225. (>= p beg)
  6226. (< p end))
  6227. (let ((inhibit-read-only t))
  6228. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6229. (beginning-of-line 0))))))
  6230. (defun org-agenda-refile (&optional goto rfloc no-update)
  6231. "Refile the item at point."
  6232. (interactive "P")
  6233. (if (equal goto '(16))
  6234. (org-refile-goto-last-stored)
  6235. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6236. (org-agenda-error)))
  6237. (buffer (marker-buffer marker))
  6238. (pos (marker-position marker))
  6239. (rfloc (or rfloc
  6240. (org-refile-get-location
  6241. (if goto "Goto: " "Refile to: ") buffer
  6242. org-refile-allow-creating-parent-nodes))))
  6243. (with-current-buffer buffer
  6244. (save-excursion
  6245. (save-restriction
  6246. (widen)
  6247. (goto-char marker)
  6248. (org-remove-subtree-entries-from-agenda)
  6249. (org-refile goto buffer rfloc)))))
  6250. (unless no-update (org-agenda-redo))))
  6251. (defun org-agenda-open-link (&optional arg)
  6252. "Follow the link in the current line, if any.
  6253. This looks for a link in the displayed line in the agenda. It also looks
  6254. at the text of the entry itself."
  6255. (interactive "P")
  6256. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6257. (org-get-at-bol 'org-marker)))
  6258. (buffer (and marker (marker-buffer marker)))
  6259. (prefix (buffer-substring
  6260. (point-at-bol)
  6261. (+ (point-at-bol)
  6262. (or (org-get-at-bol 'prefix-length) 0)))))
  6263. (cond
  6264. (buffer
  6265. (with-current-buffer buffer
  6266. (save-excursion
  6267. (save-restriction
  6268. (widen)
  6269. (goto-char marker)
  6270. (org-offer-links-in-entry arg prefix)))))
  6271. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6272. (save-excursion
  6273. (beginning-of-line 1)
  6274. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6275. (org-open-link-from-string (match-string 1)))
  6276. (t (error "No link to open here")))))
  6277. (defun org-agenda-copy-local-variable (var)
  6278. "Get a variable from a referenced buffer and install it here."
  6279. (let ((m (org-get-at-bol 'org-marker)))
  6280. (when (and m (buffer-live-p (marker-buffer m)))
  6281. (org-set-local var (with-current-buffer (marker-buffer m)
  6282. (symbol-value var))))))
  6283. (defun org-agenda-switch-to (&optional delete-other-windows)
  6284. "Go to the Org-mode file which contains the item at point."
  6285. (interactive)
  6286. (if (and org-return-follows-link
  6287. (not (org-get-at-bol 'org-marker))
  6288. (org-in-regexp org-bracket-link-regexp))
  6289. (org-open-link-from-string (match-string 0))
  6290. (let* ((marker (or (org-get-at-bol 'org-marker)
  6291. (org-agenda-error)))
  6292. (buffer (marker-buffer marker))
  6293. (pos (marker-position marker)))
  6294. (switch-to-buffer buffer)
  6295. (and delete-other-windows (delete-other-windows))
  6296. (widen)
  6297. (goto-char pos)
  6298. (when (org-mode-p)
  6299. (org-show-context 'agenda)
  6300. (save-excursion
  6301. (and (outline-next-heading)
  6302. (org-flag-heading nil))) ; show the next heading
  6303. (when (outline-invisible-p)
  6304. (show-entry)))))) ; display invisible text
  6305. (defun org-agenda-goto-mouse (ev)
  6306. "Go to the Org-mode file which contains the item at the mouse click."
  6307. (interactive "e")
  6308. (mouse-set-point ev)
  6309. (org-agenda-goto))
  6310. (defun org-agenda-show (&optional full-entry)
  6311. "Display the Org-mode file which contains the item at point.
  6312. With prefix argument FULL-ENTRY, make the entire entry visible
  6313. if it was hidden in the outline."
  6314. (interactive "P")
  6315. (let ((win (selected-window)))
  6316. (if full-entry
  6317. (let ((org-show-entry-below t))
  6318. (org-agenda-goto t))
  6319. (org-agenda-goto t))
  6320. (select-window win)))
  6321. (defvar org-agenda-show-window nil)
  6322. (defun org-agenda-show-and-scroll-up ()
  6323. "Display the Org-mode file which contains the item at point.
  6324. When called repeatedly, scroll the window that is displaying the buffer."
  6325. (interactive)
  6326. (let ((win (selected-window)))
  6327. (if (and (window-live-p org-agenda-show-window)
  6328. (eq this-command last-command))
  6329. (progn
  6330. (select-window org-agenda-show-window)
  6331. (ignore-errors (scroll-up)))
  6332. (org-agenda-goto t)
  6333. (show-subtree)
  6334. (setq org-agenda-show-window (selected-window)))
  6335. (select-window win)))
  6336. (defun org-agenda-show-scroll-down ()
  6337. "Scroll down the window showing the agenda."
  6338. (interactive)
  6339. (let ((win (selected-window)))
  6340. (when (window-live-p org-agenda-show-window)
  6341. (select-window org-agenda-show-window)
  6342. (ignore-errors (scroll-down))
  6343. (select-window win))))
  6344. (defun org-agenda-show-1 (&optional more)
  6345. "Display the Org-mode file which contains the item at point.
  6346. The prefix arg selects the amount of information to display:
  6347. 0 hide the subtree
  6348. 1 just show the entry according to defaults.
  6349. 2 show the children view
  6350. 3 show the subtree view
  6351. 4 show the entire subtree and any LOGBOOK drawers
  6352. 5 show the entire subtree and any drawers
  6353. With prefix argument FULL-ENTRY, make the entire entry visible
  6354. if it was hidden in the outline."
  6355. (interactive "p")
  6356. (let ((win (selected-window)))
  6357. (org-agenda-goto t)
  6358. (org-recenter-heading 1)
  6359. (cond
  6360. ((= more 0)
  6361. (hide-subtree)
  6362. (save-excursion
  6363. (org-back-to-heading)
  6364. (run-hook-with-args 'org-cycle-hook 'folded))
  6365. (message "Remote: FOLDED"))
  6366. ((and (interactive-p) (= more 1))
  6367. (message "Remote: show with default settings"))
  6368. ((= more 2)
  6369. (show-entry)
  6370. (show-children)
  6371. (save-excursion
  6372. (org-back-to-heading)
  6373. (run-hook-with-args 'org-cycle-hook 'children))
  6374. (message "Remote: CHILDREN"))
  6375. ((= more 3)
  6376. (show-subtree)
  6377. (save-excursion
  6378. (org-back-to-heading)
  6379. (run-hook-with-args 'org-cycle-hook 'subtree))
  6380. (message "Remote: SUBTREE"))
  6381. ((= more 4)
  6382. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6383. (org-drawer-regexp
  6384. (concat "^[ \t]*:\\("
  6385. (mapconcat 'regexp-quote org-drawers "\\|")
  6386. "\\):[ \t]*$")))
  6387. (show-subtree)
  6388. (save-excursion
  6389. (org-back-to-heading)
  6390. (org-cycle-hide-drawers 'subtree)))
  6391. (message "Remote: SUBTREE AND LOGBOOK"))
  6392. ((> more 4)
  6393. (show-subtree)
  6394. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6395. (select-window win)))
  6396. (defun org-recenter-heading (n)
  6397. (save-excursion
  6398. (org-back-to-heading)
  6399. (recenter n)))
  6400. (defvar org-agenda-cycle-counter nil)
  6401. (defun org-agenda-cycle-show (&optional n)
  6402. "Show the current entry in another window, with default settings.
  6403. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6404. When use repeatedly in immediate succession, the remote entry will cycle
  6405. through visibility
  6406. children -> subtree -> folded
  6407. When called with a numeric prefix arg, that arg will be passed through to
  6408. `org-agenda-show-1'. For the interpretation of that argument, see the
  6409. docstring of `org-agenda-show-1'."
  6410. (interactive "P")
  6411. (if (integerp n)
  6412. (setq org-agenda-cycle-counter n)
  6413. (if (not (eq last-command this-command))
  6414. (setq org-agenda-cycle-counter 1)
  6415. (if (equal org-agenda-cycle-counter 0)
  6416. (setq org-agenda-cycle-counter 2)
  6417. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6418. (if (> org-agenda-cycle-counter 3)
  6419. (setq org-agenda-cycle-counter 0)))))
  6420. (org-agenda-show-1 org-agenda-cycle-counter))
  6421. (defun org-agenda-recenter (arg)
  6422. "Display the Org-mode file which contains the item at point and recenter."
  6423. (interactive "P")
  6424. (let ((win (selected-window)))
  6425. (org-agenda-goto t)
  6426. (recenter arg)
  6427. (select-window win)))
  6428. (defun org-agenda-show-mouse (ev)
  6429. "Display the Org-mode file which contains the item at the mouse click."
  6430. (interactive "e")
  6431. (mouse-set-point ev)
  6432. (org-agenda-show))
  6433. (defun org-agenda-check-no-diary ()
  6434. "Check if the entry is a diary link and abort if yes."
  6435. (if (org-get-at-bol 'org-agenda-diary-link)
  6436. (org-agenda-error)))
  6437. (defun org-agenda-error ()
  6438. (error "Command not allowed in this line"))
  6439. (defun org-agenda-tree-to-indirect-buffer ()
  6440. "Show the subtree corresponding to the current entry in an indirect buffer.
  6441. This calls the command `org-tree-to-indirect-buffer' from the original
  6442. Org-mode buffer.
  6443. With numerical prefix arg ARG, go up to this level and then take that tree.
  6444. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6445. use the dedicated frame)."
  6446. (interactive)
  6447. (org-agenda-check-no-diary)
  6448. (let* ((marker (or (org-get-at-bol 'org-marker)
  6449. (org-agenda-error)))
  6450. (buffer (marker-buffer marker))
  6451. (pos (marker-position marker)))
  6452. (with-current-buffer buffer
  6453. (save-excursion
  6454. (goto-char pos)
  6455. (call-interactively 'org-tree-to-indirect-buffer)))))
  6456. (defvar org-last-heading-marker (make-marker)
  6457. "Marker pointing to the headline that last changed its TODO state
  6458. by a remote command from the agenda.")
  6459. (defun org-agenda-todo-nextset ()
  6460. "Switch TODO entry to next sequence."
  6461. (interactive)
  6462. (org-agenda-todo 'nextset))
  6463. (defun org-agenda-todo-previousset ()
  6464. "Switch TODO entry to previous sequence."
  6465. (interactive)
  6466. (org-agenda-todo 'previousset))
  6467. (defun org-agenda-todo (&optional arg)
  6468. "Cycle TODO state of line at point, also in Org-mode file.
  6469. This changes the line at point, all other lines in the agenda referring to
  6470. the same tree node, and the headline of the tree node in the Org-mode file."
  6471. (interactive "P")
  6472. (org-agenda-check-no-diary)
  6473. (let* ((col (current-column))
  6474. (marker (or (org-get-at-bol 'org-marker)
  6475. (org-agenda-error)))
  6476. (buffer (marker-buffer marker))
  6477. (pos (marker-position marker))
  6478. (hdmarker (org-get-at-bol 'org-hd-marker))
  6479. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6480. (inhibit-read-only t)
  6481. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6482. (org-with-remote-undo buffer
  6483. (with-current-buffer buffer
  6484. (widen)
  6485. (goto-char pos)
  6486. (org-show-context 'agenda)
  6487. (save-excursion
  6488. (and (outline-next-heading)
  6489. (org-flag-heading nil))) ; show the next heading
  6490. (let ((current-prefix-arg arg))
  6491. (call-interactively 'org-todo))
  6492. (and (bolp) (forward-char 1))
  6493. (setq newhead (org-get-heading))
  6494. (when (and (org-bound-and-true-p
  6495. org-agenda-headline-snapshot-before-repeat)
  6496. (not (equal org-agenda-headline-snapshot-before-repeat
  6497. newhead))
  6498. todayp)
  6499. (setq newhead org-agenda-headline-snapshot-before-repeat
  6500. just-one t))
  6501. (save-excursion
  6502. (org-back-to-heading)
  6503. (move-marker org-last-heading-marker (point))))
  6504. (beginning-of-line 1)
  6505. (save-excursion
  6506. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6507. (org-move-to-column col))))
  6508. (defun org-agenda-add-note (&optional arg)
  6509. "Add a time-stamped note to the entry at point."
  6510. (interactive "P")
  6511. (org-agenda-check-no-diary)
  6512. (let* ((marker (or (org-get-at-bol 'org-marker)
  6513. (org-agenda-error)))
  6514. (buffer (marker-buffer marker))
  6515. (pos (marker-position marker))
  6516. (hdmarker (org-get-at-bol 'org-hd-marker))
  6517. (inhibit-read-only t))
  6518. (with-current-buffer buffer
  6519. (widen)
  6520. (goto-char pos)
  6521. (org-show-context 'agenda)
  6522. (save-excursion
  6523. (and (outline-next-heading)
  6524. (org-flag-heading nil))) ; show the next heading
  6525. (org-add-note))))
  6526. (defun org-agenda-change-all-lines (newhead hdmarker
  6527. &optional fixface just-this)
  6528. "Change all lines in the agenda buffer which match HDMARKER.
  6529. The new content of the line will be NEWHEAD (as modified by
  6530. `org-format-agenda-item'). HDMARKER is checked with
  6531. `equal' against all `org-hd-marker' text properties in the file.
  6532. If FIXFACE is non-nil, the face of each item is modified according to
  6533. the new TODO state.
  6534. If JUST-THIS is non-nil, change just the current line, not all.
  6535. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6536. (let* ((inhibit-read-only t)
  6537. (line (org-current-line))
  6538. (thetags (with-current-buffer (marker-buffer hdmarker)
  6539. (save-excursion (save-restriction (widen)
  6540. (goto-char hdmarker)
  6541. (org-get-tags-at)))))
  6542. props m pl undone-face done-face finish new dotime cat tags)
  6543. (save-excursion
  6544. (goto-char (point-max))
  6545. (beginning-of-line 1)
  6546. (while (not finish)
  6547. (setq finish (bobp))
  6548. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6549. (or (not just-this) (= (org-current-line) line))
  6550. (equal m hdmarker))
  6551. (setq props (text-properties-at (point))
  6552. dotime (org-get-at-bol 'dotime)
  6553. cat (org-get-at-bol 'org-category)
  6554. tags thetags
  6555. new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
  6556. pl (org-get-at-bol 'prefix-length)
  6557. undone-face (org-get-at-bol 'undone-face)
  6558. done-face (org-get-at-bol 'done-face))
  6559. (goto-char (+ (point) pl))
  6560. ;; (org-move-to-column pl) FIXME: does the above line work correctly?
  6561. (cond
  6562. ((equal new "")
  6563. (beginning-of-line 1)
  6564. (and (looking-at ".*\n?") (replace-match "")))
  6565. ((looking-at ".*")
  6566. (replace-match new t t)
  6567. (beginning-of-line 1)
  6568. (add-text-properties (point-at-bol) (point-at-eol) props)
  6569. (when fixface
  6570. (add-text-properties
  6571. (point-at-bol) (point-at-eol)
  6572. (list 'face
  6573. (if org-last-todo-state-is-todo
  6574. undone-face done-face))))
  6575. (org-agenda-highlight-todo 'line)
  6576. (beginning-of-line 1))
  6577. (t (error "Line update did not work"))))
  6578. (beginning-of-line 0)))
  6579. (org-finalize-agenda)))
  6580. (defun org-agenda-align-tags (&optional line)
  6581. "Align all tags in agenda items to `org-agenda-tags-column'."
  6582. (let ((inhibit-read-only t) l c)
  6583. (save-excursion
  6584. (goto-char (if line (point-at-bol) (point-min)))
  6585. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6586. (if line (point-at-eol) nil) t)
  6587. (add-text-properties
  6588. (match-beginning 2) (match-end 2)
  6589. (list 'face (delq nil (let ((prop (get-text-property
  6590. (match-beginning 2) 'face)))
  6591. (or (listp prop) (setq prop (list prop)))
  6592. (if (memq 'org-tag prop)
  6593. prop
  6594. (cons 'org-tag prop))))))
  6595. (setq l (- (match-end 2) (match-beginning 2))
  6596. c (if (< org-agenda-tags-column 0)
  6597. (- (abs org-agenda-tags-column) l)
  6598. org-agenda-tags-column))
  6599. (delete-region (match-beginning 1) (match-end 1))
  6600. (goto-char (match-beginning 1))
  6601. (insert (org-add-props
  6602. (make-string (max 1 (- c (current-column))) ?\ )
  6603. (plist-put (copy-sequence (text-properties-at (point)))
  6604. 'face nil))))
  6605. (goto-char (point-min))
  6606. (org-font-lock-add-tag-faces (point-max)))))
  6607. (defun org-agenda-priority-up ()
  6608. "Increase the priority of line at point, also in Org-mode file."
  6609. (interactive)
  6610. (org-agenda-priority 'up))
  6611. (defun org-agenda-priority-down ()
  6612. "Decrease the priority of line at point, also in Org-mode file."
  6613. (interactive)
  6614. (org-agenda-priority 'down))
  6615. (defun org-agenda-priority (&optional force-direction)
  6616. "Set the priority of line at point, also in Org-mode file.
  6617. This changes the line at point, all other lines in the agenda referring to
  6618. the same tree node, and the headline of the tree node in the Org-mode file."
  6619. (interactive)
  6620. (unless org-enable-priority-commands
  6621. (error "Priority commands are disabled"))
  6622. (org-agenda-check-no-diary)
  6623. (let* ((marker (or (org-get-at-bol 'org-marker)
  6624. (org-agenda-error)))
  6625. (hdmarker (org-get-at-bol 'org-hd-marker))
  6626. (buffer (marker-buffer hdmarker))
  6627. (pos (marker-position hdmarker))
  6628. (inhibit-read-only t)
  6629. newhead)
  6630. (org-with-remote-undo buffer
  6631. (with-current-buffer buffer
  6632. (widen)
  6633. (goto-char pos)
  6634. (org-show-context 'agenda)
  6635. (save-excursion
  6636. (and (outline-next-heading)
  6637. (org-flag-heading nil))) ; show the next heading
  6638. (funcall 'org-priority force-direction)
  6639. (end-of-line 1)
  6640. (setq newhead (org-get-heading)))
  6641. (org-agenda-change-all-lines newhead hdmarker)
  6642. (beginning-of-line 1))))
  6643. ;; FIXME: should fix the tags property of the agenda line.
  6644. (defun org-agenda-set-tags (&optional tag onoff)
  6645. "Set tags for the current headline."
  6646. (interactive)
  6647. (org-agenda-check-no-diary)
  6648. (if (and (org-region-active-p) (interactive-p))
  6649. (call-interactively 'org-change-tag-in-region)
  6650. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6651. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6652. (org-agenda-error)))
  6653. (buffer (marker-buffer hdmarker))
  6654. (pos (marker-position hdmarker))
  6655. (inhibit-read-only t)
  6656. newhead)
  6657. (org-with-remote-undo buffer
  6658. (with-current-buffer buffer
  6659. (widen)
  6660. (goto-char pos)
  6661. (save-excursion
  6662. (org-show-context 'agenda))
  6663. (save-excursion
  6664. (and (outline-next-heading)
  6665. (org-flag-heading nil))) ; show the next heading
  6666. (goto-char pos)
  6667. (if tag
  6668. (org-toggle-tag tag onoff)
  6669. (call-interactively 'org-set-tags))
  6670. (end-of-line 1)
  6671. (setq newhead (org-get-heading)))
  6672. (org-agenda-change-all-lines newhead hdmarker)
  6673. (beginning-of-line 1)))))
  6674. (defun org-agenda-set-property ()
  6675. "Set a property for the current headline."
  6676. (interactive)
  6677. (org-agenda-check-no-diary)
  6678. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6679. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6680. (org-agenda-error)))
  6681. (buffer (marker-buffer hdmarker))
  6682. (pos (marker-position hdmarker))
  6683. (inhibit-read-only t)
  6684. newhead)
  6685. (org-with-remote-undo buffer
  6686. (with-current-buffer buffer
  6687. (widen)
  6688. (goto-char pos)
  6689. (save-excursion
  6690. (org-show-context 'agenda))
  6691. (save-excursion
  6692. (and (outline-next-heading)
  6693. (org-flag-heading nil))) ; show the next heading
  6694. (goto-char pos)
  6695. (call-interactively 'org-set-property)))))
  6696. (defun org-agenda-set-effort ()
  6697. "Set the effort property for the current headline."
  6698. (interactive)
  6699. (org-agenda-check-no-diary)
  6700. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6701. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6702. (org-agenda-error)))
  6703. (buffer (marker-buffer hdmarker))
  6704. (pos (marker-position hdmarker))
  6705. (inhibit-read-only t)
  6706. newhead)
  6707. (org-with-remote-undo buffer
  6708. (with-current-buffer buffer
  6709. (widen)
  6710. (goto-char pos)
  6711. (save-excursion
  6712. (org-show-context 'agenda))
  6713. (save-excursion
  6714. (and (outline-next-heading)
  6715. (org-flag-heading nil))) ; show the next heading
  6716. (goto-char pos)
  6717. (call-interactively 'org-set-effort)
  6718. (end-of-line 1)))))
  6719. (defun org-agenda-toggle-archive-tag ()
  6720. "Toggle the archive tag for the current entry."
  6721. (interactive)
  6722. (org-agenda-check-no-diary)
  6723. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6724. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6725. (org-agenda-error)))
  6726. (buffer (marker-buffer hdmarker))
  6727. (pos (marker-position hdmarker))
  6728. (inhibit-read-only t)
  6729. newhead)
  6730. (org-with-remote-undo buffer
  6731. (with-current-buffer buffer
  6732. (widen)
  6733. (goto-char pos)
  6734. (org-show-context 'agenda)
  6735. (save-excursion
  6736. (and (outline-next-heading)
  6737. (org-flag-heading nil))) ; show the next heading
  6738. (call-interactively 'org-toggle-archive-tag)
  6739. (end-of-line 1)
  6740. (setq newhead (org-get-heading)))
  6741. (org-agenda-change-all-lines newhead hdmarker)
  6742. (beginning-of-line 1))))
  6743. (defun org-agenda-do-date-later (arg)
  6744. (interactive "P")
  6745. (cond
  6746. ((or (equal arg '(16))
  6747. (memq last-command
  6748. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6749. (setq this-command 'org-agenda-date-later-minutes)
  6750. (org-agenda-date-later-minutes 1))
  6751. ((or (equal arg '(4))
  6752. (memq last-command
  6753. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6754. (setq this-command 'org-agenda-date-later-hours)
  6755. (org-agenda-date-later-hours 1))
  6756. (t
  6757. (org-agenda-date-later (prefix-numeric-value arg)))))
  6758. (defun org-agenda-do-date-earlier (arg)
  6759. (interactive "P")
  6760. (cond
  6761. ((or (equal arg '(16))
  6762. (memq last-command
  6763. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6764. (setq this-command 'org-agenda-date-earlier-minutes)
  6765. (org-agenda-date-earlier-minutes 1))
  6766. ((or (equal arg '(4))
  6767. (memq last-command
  6768. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6769. (setq this-command 'org-agenda-date-earlier-hours)
  6770. (org-agenda-date-earlier-hours 1))
  6771. (t
  6772. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6773. (defun org-agenda-date-later (arg &optional what)
  6774. "Change the date of this item to ARG day(s) later."
  6775. (interactive "p")
  6776. (org-agenda-check-type t 'agenda 'timeline)
  6777. (org-agenda-check-no-diary)
  6778. (let* ((marker (or (org-get-at-bol 'org-marker)
  6779. (org-agenda-error)))
  6780. (buffer (marker-buffer marker))
  6781. (pos (marker-position marker)))
  6782. (org-with-remote-undo buffer
  6783. (with-current-buffer buffer
  6784. (widen)
  6785. (goto-char pos)
  6786. (if (not (org-at-timestamp-p))
  6787. (error "Cannot find time stamp"))
  6788. (org-timestamp-change arg (or what 'day)))
  6789. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6790. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6791. (defun org-agenda-date-earlier (arg &optional what)
  6792. "Change the date of this item to ARG day(s) earlier."
  6793. (interactive "p")
  6794. (org-agenda-date-later (- arg) what))
  6795. (defun org-agenda-date-later-minutes (arg)
  6796. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6797. (interactive "p")
  6798. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6799. (org-agenda-date-later arg 'minute))
  6800. (defun org-agenda-date-earlier-minutes (arg)
  6801. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6802. (interactive "p")
  6803. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6804. (org-agenda-date-earlier arg 'minute))
  6805. (defun org-agenda-date-later-hours (arg)
  6806. "Change the time of this item, in hour steps."
  6807. (interactive "p")
  6808. (org-agenda-date-later arg 'hour))
  6809. (defun org-agenda-date-earlier-hours (arg)
  6810. "Change the time of this item, in hour steps."
  6811. (interactive "p")
  6812. (org-agenda-date-earlier arg 'hour))
  6813. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  6814. "Show new date stamp via text properties."
  6815. ;; We use text properties to make this undoable
  6816. (let ((inhibit-read-only t)
  6817. (buffer-invisibility-spec))
  6818. (setq stamp (concat " " prefix " => " stamp))
  6819. (save-excursion
  6820. (goto-char (point-max))
  6821. (while (not (bobp))
  6822. (when (equal marker (org-get-at-bol 'org-marker))
  6823. (org-move-to-column (- (window-width) (length stamp)) t)
  6824. (org-agenda-fix-tags-filter-overlays-at (point))
  6825. (if (featurep 'xemacs)
  6826. ;; Use `duplicable' property to trigger undo recording
  6827. (let ((ex (make-extent nil nil))
  6828. (gl (make-glyph stamp)))
  6829. (set-glyph-face gl 'secondary-selection)
  6830. (set-extent-properties
  6831. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  6832. (insert-extent ex (1- (point)) (point-at-eol)))
  6833. (add-text-properties
  6834. (1- (point)) (point-at-eol)
  6835. (list 'display (org-add-props stamp nil
  6836. 'face 'secondary-selection))))
  6837. (beginning-of-line 1))
  6838. (beginning-of-line 0)))))
  6839. (defun org-agenda-date-prompt (arg)
  6840. "Change the date of this item. Date is prompted for, with default today.
  6841. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  6842. be used to request time specification in the time stamp."
  6843. (interactive "P")
  6844. (org-agenda-check-type t 'agenda 'timeline)
  6845. (org-agenda-check-no-diary)
  6846. (let* ((marker (or (org-get-at-bol 'org-marker)
  6847. (org-agenda-error)))
  6848. (buffer (marker-buffer marker))
  6849. (pos (marker-position marker)))
  6850. (org-with-remote-undo buffer
  6851. (with-current-buffer buffer
  6852. (widen)
  6853. (goto-char pos)
  6854. (if (not (org-at-timestamp-p t))
  6855. (error "Cannot find time stamp"))
  6856. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  6857. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6858. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6859. (defun org-agenda-schedule (arg &optional time)
  6860. "Schedule the item at point.
  6861. Arg is passed through to `org-schedule'."
  6862. (interactive "P")
  6863. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6864. (org-agenda-check-no-diary)
  6865. (let* ((marker (or (org-get-at-bol 'org-marker)
  6866. (org-agenda-error)))
  6867. (type (marker-insertion-type marker))
  6868. (buffer (marker-buffer marker))
  6869. (pos (marker-position marker))
  6870. (org-insert-labeled-timestamps-at-point nil)
  6871. ts)
  6872. (set-marker-insertion-type marker t)
  6873. (org-with-remote-undo buffer
  6874. (with-current-buffer buffer
  6875. (widen)
  6876. (goto-char pos)
  6877. (setq ts (org-schedule arg time)))
  6878. (org-agenda-show-new-time marker ts "S"))
  6879. (message "Item scheduled for %s" ts)))
  6880. (defun org-agenda-deadline (arg &optional time)
  6881. "Schedule the item at point.
  6882. Arg is passed through to `org-deadline'."
  6883. (interactive "P")
  6884. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6885. (org-agenda-check-no-diary)
  6886. (let* ((marker (or (org-get-at-bol 'org-marker)
  6887. (org-agenda-error)))
  6888. (buffer (marker-buffer marker))
  6889. (pos (marker-position marker))
  6890. (org-insert-labeled-timestamps-at-point nil)
  6891. ts)
  6892. (org-with-remote-undo buffer
  6893. (with-current-buffer buffer
  6894. (widen)
  6895. (goto-char pos)
  6896. (setq ts (org-deadline arg time)))
  6897. (org-agenda-show-new-time marker ts "D"))
  6898. (message "Deadline for this item set to %s" ts)))
  6899. (defun org-agenda-action ()
  6900. "Select entry for agenda action, or execute an agenda action.
  6901. This command prompts for another letter. Valid inputs are:
  6902. m Mark the entry at point for an agenda action
  6903. s Schedule the marked entry to the date at the cursor
  6904. d Set the deadline of the marked entry to the date at the cursor
  6905. r Call `org-remember' with cursor date as the default date
  6906. c Call `org-capture' with cursor date as the default date
  6907. SPC Show marked entry in other window
  6908. TAB Visit marked entry in other window
  6909. The cursor may be at a date in the calendar, or in the Org agenda."
  6910. (interactive)
  6911. (let (ans)
  6912. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  6913. (setq ans (read-char-exclusive))
  6914. (cond
  6915. ((equal ans ?m)
  6916. ;; Mark this entry
  6917. (if (eq major-mode 'org-agenda-mode)
  6918. (let ((m (or (org-get-at-bol 'org-hd-marker)
  6919. (org-get-at-bol 'org-marker))))
  6920. (if m
  6921. (progn
  6922. (move-marker org-agenda-action-marker
  6923. (marker-position m) (marker-buffer m))
  6924. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  6925. (error "Don't know which entry to mark")))
  6926. (error "This command works only in the agenda")))
  6927. ((equal ans ?s)
  6928. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  6929. ((equal ans ?d)
  6930. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  6931. ((equal ans ?r)
  6932. (org-agenda-do-action '(org-remember) t))
  6933. ((equal ans ?c)
  6934. (org-agenda-do-action '(org-capture) t))
  6935. ((equal ans ?\ )
  6936. (let ((cw (selected-window)))
  6937. (org-switch-to-buffer-other-window
  6938. (marker-buffer org-agenda-action-marker))
  6939. (goto-char org-agenda-action-marker)
  6940. (org-show-context 'agenda)
  6941. (select-window cw)))
  6942. ((equal ans ?\C-i)
  6943. (org-switch-to-buffer-other-window
  6944. (marker-buffer org-agenda-action-marker))
  6945. (goto-char org-agenda-action-marker)
  6946. (org-show-context 'agenda))
  6947. (t (error "Invalid agenda action %c" ans)))))
  6948. (defun org-agenda-do-action (form &optional current-buffer)
  6949. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  6950. (let ((org-overriding-default-time (org-get-cursor-date)))
  6951. (if current-buffer
  6952. (eval form)
  6953. (if (not (marker-buffer org-agenda-action-marker))
  6954. (error "No entry has been selected for agenda action")
  6955. (with-current-buffer (marker-buffer org-agenda-action-marker)
  6956. (save-excursion
  6957. (save-restriction
  6958. (widen)
  6959. (goto-char org-agenda-action-marker)
  6960. (eval form))))))))
  6961. (defun org-agenda-clock-in (&optional arg)
  6962. "Start the clock on the currently selected item."
  6963. (interactive "P")
  6964. (org-agenda-check-no-diary)
  6965. (if (equal arg '(4))
  6966. (org-clock-in arg)
  6967. (let* ((marker (or (org-get-at-bol 'org-marker)
  6968. (org-agenda-error)))
  6969. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  6970. marker))
  6971. (pos (marker-position marker))
  6972. newhead)
  6973. (org-with-remote-undo (marker-buffer marker)
  6974. (with-current-buffer (marker-buffer marker)
  6975. (widen)
  6976. (goto-char pos)
  6977. (org-show-context 'agenda)
  6978. (org-show-entry)
  6979. (org-cycle-hide-drawers 'children)
  6980. (org-clock-in arg)
  6981. (setq newhead (org-get-heading)))
  6982. (org-agenda-change-all-lines newhead hdmarker)))))
  6983. (defun org-agenda-clock-out ()
  6984. "Stop the currently running clock."
  6985. (interactive)
  6986. (unless (marker-buffer org-clock-marker)
  6987. (error "No running clock"))
  6988. (let ((marker (make-marker)) newhead)
  6989. (org-with-remote-undo (marker-buffer org-clock-marker)
  6990. (with-current-buffer (marker-buffer org-clock-marker)
  6991. (save-excursion
  6992. (save-restriction
  6993. (widen)
  6994. (goto-char org-clock-marker)
  6995. (org-back-to-heading t)
  6996. (move-marker marker (point))
  6997. (org-clock-out)
  6998. (setq newhead (org-get-heading))))))
  6999. (org-agenda-change-all-lines newhead marker)
  7000. (move-marker marker nil)))
  7001. (defun org-agenda-clock-cancel (&optional arg)
  7002. "Cancel the currently running clock."
  7003. (interactive "P")
  7004. (unless (marker-buffer org-clock-marker)
  7005. (error "No running clock"))
  7006. (org-with-remote-undo (marker-buffer org-clock-marker)
  7007. (org-clock-cancel)))
  7008. (defun org-agenda-clock-goto ()
  7009. "Jump to the currently clocked in task within the agenda.
  7010. If the currently clocked in task is not listed in the agenda
  7011. buffer, display it in another window."
  7012. (interactive)
  7013. (let (pos)
  7014. (mapc (lambda (o)
  7015. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7016. (setq pos (overlay-start o))))
  7017. (overlays-in (point-min) (point-max)))
  7018. (cond (pos (goto-char pos))
  7019. ;; If the currently clocked entry is not in the agenda
  7020. ;; buffer, we visit it in another window:
  7021. (org-clock-current-task
  7022. (org-switch-to-buffer-other-window (org-clock-goto)))
  7023. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7024. (defun org-agenda-diary-entry-in-org-file ()
  7025. "Make a diary entry in the file `org-agenda-diary-file'."
  7026. (let (d1 d2 char (text "") dp1 dp2)
  7027. (if (equal (buffer-name) "*Calendar*")
  7028. (setq d1 (calendar-cursor-to-date t)
  7029. d2 (car calendar-mark-ring))
  7030. (setq dp1 (get-text-property (point-at-bol) 'day))
  7031. (unless dp1 (error "No date defined in current line"))
  7032. (setq d1 (calendar-gregorian-from-absolute dp1)
  7033. d2 (and (ignore-errors (mark))
  7034. (save-excursion
  7035. (goto-char (mark))
  7036. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7037. (calendar-gregorian-from-absolute dp2))))
  7038. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7039. (setq char (read-char-exclusive))
  7040. (cond
  7041. ((equal char ?d)
  7042. (setq text (read-string "Day entry: "))
  7043. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7044. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7045. ((equal char ?a)
  7046. (setq d1 (list (car d1) (nth 1 d1)
  7047. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7048. (nth 2 d1))))
  7049. (setq text (read-string "Anniversary (use %d to show years): "))
  7050. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7051. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7052. ((equal char ?b)
  7053. (setq text (read-string "Block entry: "))
  7054. (unless (and d1 d2 (not (equal d1 d2)))
  7055. (error "No block of days selected"))
  7056. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7057. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7058. ((equal char ?j)
  7059. (org-switch-to-buffer-other-window
  7060. (find-file-noselect org-agenda-diary-file))
  7061. (require 'org-datetree)
  7062. (org-datetree-find-date-create d1)
  7063. (org-reveal t))
  7064. (t (error "Invalid selection character `%c'" char)))))
  7065. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7066. "Where in `org-agenda-diary-file' should new entries be added?
  7067. Valid values:
  7068. date-tree in the date tree, as child of the date
  7069. top-level as top-level entries at the end of the file."
  7070. :group 'org-agenda
  7071. :type '(choice
  7072. (const :tag "in a date tree" date-tree)
  7073. (const :tag "as top level at end of file" top-level)))
  7074. (defcustom org-agenda-insert-diary-extract-time nil
  7075. "Non-nil means extract any time specification from the diary entry."
  7076. :group 'org-agenda
  7077. :type 'boolean)
  7078. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7079. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7080. If TEXT is not empty, it will become the headline of the new entry, and
  7081. the resulting entry will not be shown. When TEXT is empty, switch to
  7082. `org-agenda-diary-file' and let the user finish the entry there."
  7083. (let ((cw (current-window-configuration)))
  7084. (org-switch-to-buffer-other-window
  7085. (find-file-noselect org-agenda-diary-file))
  7086. (widen)
  7087. (goto-char (point-min))
  7088. (cond
  7089. ((eq type 'anniversary)
  7090. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7091. (progn
  7092. (or (org-on-heading-p t)
  7093. (progn
  7094. (outline-next-heading)
  7095. (insert "* Anniversaries\n\n")
  7096. (beginning-of-line -1)))))
  7097. (outline-next-heading)
  7098. (org-back-over-empty-lines)
  7099. (backward-char 1)
  7100. (insert "\n")
  7101. (require 'diary-lib)
  7102. (let ((calendar-date-display-form
  7103. (if (if (boundp 'calendar-date-style)
  7104. (eq calendar-date-style 'european)
  7105. (with-no-warnings ;; european-calendar-style is obsolete as of version 23.1
  7106. (org-bound-and-true-p european-calendar-style))) ; Emacs 22
  7107. '(day " " month " " year)
  7108. '(month " " day " " year))))
  7109. (insert (format "%%%%(diary-anniversary %s) %s"
  7110. (calendar-date-string d1 nil t) text))))
  7111. ((eq type 'day)
  7112. (let ((org-prefix-has-time t)
  7113. (org-agenda-time-leading-zero t)
  7114. fmt time time2)
  7115. (if org-agenda-insert-diary-extract-time
  7116. ;; Use org-format-agenda-item to parse text for a time-range and
  7117. ;; remove it. FIXME: This is a hack, we should refactor
  7118. ;; that function to make time extraction available separately
  7119. (setq fmt (org-format-agenda-item nil text nil nil t)
  7120. time (get-text-property 0 'time fmt)
  7121. time2 (if (> (length time) 0)
  7122. ;; split-string removes trailing ...... if
  7123. ;; no end time given. First space
  7124. ;; separates time from date.
  7125. (concat " " (car (split-string time "\\.")))
  7126. nil)
  7127. text (get-text-property 0 'txt fmt)))
  7128. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7129. (org-agenda-insert-diary-as-top-level text)
  7130. (require 'org-datetree)
  7131. (org-datetree-find-date-create d1)
  7132. (org-agenda-insert-diary-make-new-entry text))
  7133. (org-insert-time-stamp (org-time-from-absolute
  7134. (calendar-absolute-from-gregorian d1))
  7135. nil nil nil nil time2))
  7136. (end-of-line 0))
  7137. ((eq type 'block)
  7138. (if (> (calendar-absolute-from-gregorian d1)
  7139. (calendar-absolute-from-gregorian d2))
  7140. (setq d1 (prog1 d2 (setq d2 d1))))
  7141. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7142. (org-agenda-insert-diary-as-top-level text)
  7143. (require 'org-datetree)
  7144. (org-datetree-find-date-create d1)
  7145. (org-agenda-insert-diary-make-new-entry text))
  7146. (org-insert-time-stamp (org-time-from-absolute
  7147. (calendar-absolute-from-gregorian d1)))
  7148. (insert "--")
  7149. (org-insert-time-stamp (org-time-from-absolute
  7150. (calendar-absolute-from-gregorian d2)))
  7151. (end-of-line 0)))
  7152. (if (string-match "\\S-" text)
  7153. (progn
  7154. (set-window-configuration cw)
  7155. (message "%s entry added to %s"
  7156. (capitalize (symbol-name type))
  7157. (abbreviate-file-name org-agenda-diary-file)))
  7158. (org-reveal t)
  7159. (message "Please finish entry here"))))
  7160. (defun org-agenda-insert-diary-as-top-level (text)
  7161. "Make new entry as a top-level entry at the end of the file.
  7162. Add TEXT as headline, and position the cursor in the second line so that
  7163. a timestamp can be added there."
  7164. (widen)
  7165. (goto-char (point-max))
  7166. (or (bolp) (insert "\n"))
  7167. (insert "* " text "\n")
  7168. (if org-adapt-indentation (org-indent-to-column 2)))
  7169. (defun org-agenda-insert-diary-make-new-entry (text)
  7170. "Make new entry as last child of current entry.
  7171. Add TEXT as headline, and position the cursor in the second line so that
  7172. a timestamp can be added there."
  7173. (let ((org-show-following-heading t)
  7174. (org-show-siblings t)
  7175. (org-show-hierarchy-above t)
  7176. (org-show-entry-below t)
  7177. col)
  7178. (outline-next-heading)
  7179. (org-back-over-empty-lines)
  7180. (or (looking-at "[ \t]*$")
  7181. (progn (insert "\n") (backward-char 1)))
  7182. (org-insert-heading nil t)
  7183. (org-do-demote)
  7184. (setq col (current-column))
  7185. (insert text "\n")
  7186. (if org-adapt-indentation (org-indent-to-column col))
  7187. (let ((org-show-following-heading t)
  7188. (org-show-siblings t)
  7189. (org-show-hierarchy-above t)
  7190. (org-show-entry-below t))
  7191. (org-show-context))))
  7192. (defun org-agenda-diary-entry ()
  7193. "Make a diary entry, like the `i' command from the calendar.
  7194. All the standard commands work: block, weekly etc.
  7195. When `org-agenda-diary-file' points to a file,
  7196. `org-agenda-diary-entry-in-org-file' is called instead to create
  7197. entries in that Org-mode file."
  7198. (interactive)
  7199. (org-agenda-check-type t 'agenda 'timeline)
  7200. (if (not (eq org-agenda-diary-file 'diary-file))
  7201. (org-agenda-diary-entry-in-org-file)
  7202. (require 'diary-lib)
  7203. (let* ((char (progn
  7204. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7205. (read-char-exclusive)))
  7206. (cmd (cdr (assoc char
  7207. '((?d . insert-diary-entry)
  7208. (?w . insert-weekly-diary-entry)
  7209. (?m . insert-monthly-diary-entry)
  7210. (?y . insert-yearly-diary-entry)
  7211. (?a . insert-anniversary-diary-entry)
  7212. (?b . insert-block-diary-entry)
  7213. (?c . insert-cyclic-diary-entry)))))
  7214. (oldf (symbol-function 'calendar-cursor-to-date))
  7215. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7216. (point (point))
  7217. (mark (or (mark t) (point))))
  7218. (unless cmd
  7219. (error "No command associated with <%c>" char))
  7220. (unless (and (get-text-property point 'day)
  7221. (or (not (equal ?b char))
  7222. (get-text-property mark 'day)))
  7223. (error "Don't know which date to use for diary entry"))
  7224. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7225. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7226. (let ((calendar-mark-ring
  7227. (list (calendar-gregorian-from-absolute
  7228. (or (get-text-property mark 'day)
  7229. (get-text-property point 'day))))))
  7230. (unwind-protect
  7231. (progn
  7232. (fset 'calendar-cursor-to-date
  7233. (lambda (&optional error dummy)
  7234. (calendar-gregorian-from-absolute
  7235. (get-text-property point 'day))))
  7236. (call-interactively cmd))
  7237. (fset 'calendar-cursor-to-date oldf))))))
  7238. (defun org-agenda-execute-calendar-command (cmd)
  7239. "Execute a calendar command from the agenda, with the date associated to
  7240. the cursor position."
  7241. (org-agenda-check-type t 'agenda 'timeline)
  7242. (require 'diary-lib)
  7243. (unless (get-text-property (point) 'day)
  7244. (error "Don't know which date to use for calendar command"))
  7245. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7246. (point (point))
  7247. (date (calendar-gregorian-from-absolute
  7248. (get-text-property point 'day)))
  7249. ;; the following 2 vars are needed in the calendar
  7250. (displayed-month (car date))
  7251. (displayed-year (nth 2 date)))
  7252. (unwind-protect
  7253. (progn
  7254. (fset 'calendar-cursor-to-date
  7255. (lambda (&optional error dummy)
  7256. (calendar-gregorian-from-absolute
  7257. (get-text-property point 'day))))
  7258. (call-interactively cmd))
  7259. (fset 'calendar-cursor-to-date oldf))))
  7260. (defun org-agenda-phases-of-moon ()
  7261. "Display the phases of the moon for the 3 months around the cursor date."
  7262. (interactive)
  7263. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7264. (defun org-agenda-holidays ()
  7265. "Display the holidays for the 3 months around the cursor date."
  7266. (interactive)
  7267. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7268. (defvar calendar-longitude)
  7269. (defvar calendar-latitude)
  7270. (defvar calendar-location-name)
  7271. (defun org-agenda-sunrise-sunset (arg)
  7272. "Display sunrise and sunset for the cursor date.
  7273. Latitude and longitude can be specified with the variables
  7274. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7275. argument, latitude and longitude will be prompted for."
  7276. (interactive "P")
  7277. (require 'solar)
  7278. (let ((calendar-longitude (if arg nil calendar-longitude))
  7279. (calendar-latitude (if arg nil calendar-latitude))
  7280. (calendar-location-name
  7281. (if arg "the given coordinates" calendar-location-name)))
  7282. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7283. (defun org-agenda-goto-calendar ()
  7284. "Open the Emacs calendar with the date at the cursor."
  7285. (interactive)
  7286. (org-agenda-check-type t 'agenda 'timeline)
  7287. (let* ((day (or (get-text-property (point) 'day)
  7288. (error "Don't know which date to open in calendar")))
  7289. (date (calendar-gregorian-from-absolute day))
  7290. (calendar-move-hook nil)
  7291. (calendar-view-holidays-initially-flag nil)
  7292. (calendar-view-diary-initially-flag nil))
  7293. (calendar)
  7294. (calendar-goto-date date)))
  7295. ;;;###autoload
  7296. (defun org-calendar-goto-agenda ()
  7297. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7298. This is a command that has to be installed in `calendar-mode-map'."
  7299. (interactive)
  7300. (org-agenda-list nil (calendar-absolute-from-gregorian
  7301. (calendar-cursor-to-date))
  7302. nil))
  7303. (defun org-agenda-convert-date ()
  7304. (interactive)
  7305. (org-agenda-check-type t 'agenda 'timeline)
  7306. (let ((day (get-text-property (point) 'day))
  7307. date s)
  7308. (unless day
  7309. (error "Don't know which date to convert"))
  7310. (setq date (calendar-gregorian-from-absolute day))
  7311. (setq s (concat
  7312. "Gregorian: " (calendar-date-string date) "\n"
  7313. "ISO: " (calendar-iso-date-string date) "\n"
  7314. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7315. "Julian: " (calendar-julian-date-string date) "\n"
  7316. "Astron. JD: " (calendar-astro-date-string date)
  7317. " (Julian date number at noon UTC)\n"
  7318. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7319. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7320. "French: " (calendar-french-date-string date) "\n"
  7321. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7322. "Mayan: " (calendar-mayan-date-string date) "\n"
  7323. "Coptic: " (calendar-coptic-date-string date) "\n"
  7324. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7325. "Persian: " (calendar-persian-date-string date) "\n"
  7326. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7327. (with-output-to-temp-buffer "*Dates*"
  7328. (princ s))
  7329. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7330. ;;; Bulk commands
  7331. (defvar org-agenda-bulk-marked-entries nil
  7332. "List of markers that refer to marked entries in the agenda.")
  7333. (defun org-agenda-bulk-marked-p ()
  7334. (eq (get-char-property (point-at-bol) 'type)
  7335. 'org-marked-entry-overlay))
  7336. (defun org-agenda-bulk-mark (&optional arg)
  7337. "Mark the entry at point for future bulk action."
  7338. (interactive "p")
  7339. (dotimes (i (max arg 1))
  7340. (unless (org-get-at-bol 'org-agenda-diary-link)
  7341. (let* ((m (org-get-at-bol 'org-hd-marker))
  7342. ov)
  7343. (unless (org-agenda-bulk-marked-p)
  7344. (unless m (error "Nothing to mark at point"))
  7345. (push m org-agenda-bulk-marked-entries)
  7346. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7347. (org-overlay-display ov "> "
  7348. (org-get-todo-face "TODO")
  7349. 'evaporate)
  7350. (overlay-put ov 'type 'org-marked-entry-overlay))
  7351. (beginning-of-line 2)
  7352. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7353. (beginning-of-line 2))
  7354. (message "%d entries marked for bulk action"
  7355. (length org-agenda-bulk-marked-entries))))))
  7356. (defun org-agenda-bulk-mark-regexp (regexp)
  7357. "Mark entries match REGEXP."
  7358. (interactive "sMark entries matching regexp: ")
  7359. (let (entries-marked)
  7360. (save-excursion
  7361. (goto-char (point-min))
  7362. (goto-char (next-single-property-change (point) 'txt))
  7363. (while (re-search-forward regexp nil t)
  7364. (when (string-match regexp (get-text-property (point) 'txt))
  7365. (setq entries-marked (+ entries-marked 1))
  7366. (call-interactively 'org-agenda-bulk-mark))))
  7367. (if (not entries-marked)
  7368. (message "No entry matching this regexp."))))
  7369. (defun org-agenda-bulk-unmark ()
  7370. "Unmark the entry at point for future bulk action."
  7371. (interactive)
  7372. (when (org-agenda-bulk-marked-p)
  7373. (org-agenda-bulk-remove-overlays
  7374. (point-at-bol) (+ 2 (point-at-bol)))
  7375. (setq org-agenda-bulk-marked-entries
  7376. (delete (org-get-at-bol 'org-hd-marker)
  7377. org-agenda-bulk-marked-entries)))
  7378. (beginning-of-line 2)
  7379. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7380. (beginning-of-line 2))
  7381. (message "%d entries marked for bulk action"
  7382. (length org-agenda-bulk-marked-entries)))
  7383. (defun org-agenda-bulk-toggle ()
  7384. "Toggle marking the entry at point for bulk action."
  7385. (interactive)
  7386. (if (org-agenda-bulk-marked-p)
  7387. (org-agenda-bulk-unmark)
  7388. (org-agenda-bulk-mark)))
  7389. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7390. "Remove the mark overlays between BEG and END in the agenda buffer.
  7391. BEG and END default to the buffer limits.
  7392. This only removes the overlays, it does not remove the markers
  7393. from the list in `org-agenda-bulk-marked-entries'."
  7394. (interactive)
  7395. (mapc (lambda (ov)
  7396. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7397. (delete-overlay ov)))
  7398. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7399. (defun org-agenda-bulk-remove-all-marks ()
  7400. "Remove all marks in the agenda buffer.
  7401. This will remove the markers, and the overlays."
  7402. (interactive)
  7403. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7404. (setq org-agenda-bulk-marked-entries nil)
  7405. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7406. (defun org-agenda-bulk-action (&optional arg)
  7407. "Execute an remote-editing action on all marked entries.
  7408. The prefix arg is passed through to the command if possible."
  7409. (interactive "P")
  7410. (unless org-agenda-bulk-marked-entries
  7411. (error "No entries are marked"))
  7412. (message "Bulk: [r]efile [$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [S]catter [d]eadline")
  7413. (let* ((action (read-char-exclusive))
  7414. (org-log-refile (if org-log-refile 'time nil))
  7415. (entries (reverse org-agenda-bulk-marked-entries))
  7416. redo-at-end
  7417. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7418. (cond
  7419. ((equal action ?$)
  7420. (setq cmd '(org-agenda-archive)))
  7421. ((equal action ?A)
  7422. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7423. ((member action '(?r ?w))
  7424. (setq rfloc (org-refile-get-location
  7425. "Refile to: "
  7426. (marker-buffer (car org-agenda-bulk-marked-entries))
  7427. org-refile-allow-creating-parent-nodes))
  7428. (if (nth 3 rfloc)
  7429. (setcar (nthcdr 3 rfloc)
  7430. (move-marker (make-marker) (nth 3 rfloc)
  7431. (or (get-file-buffer (nth 1 rfloc))
  7432. (find-buffer-visiting (nth 1 rfloc))
  7433. (error "This should not happen")))))
  7434. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7435. redo-at-end t))
  7436. ((equal action ?t)
  7437. (setq state (org-icompleting-read
  7438. "Todo state: "
  7439. (with-current-buffer (marker-buffer (car entries))
  7440. (mapcar 'list org-todo-keywords-1))))
  7441. (setq cmd `(let ((org-inhibit-blocking t)
  7442. (org-inhibit-logging 'note))
  7443. (org-agenda-todo ,state))))
  7444. ((memq action '(?- ?+))
  7445. (setq tag (org-icompleting-read
  7446. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7447. (with-current-buffer (marker-buffer (car entries))
  7448. (delq nil
  7449. (mapcar (lambda (x)
  7450. (if (stringp (car x)) x)) org-tag-alist)))))
  7451. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7452. ((memq action '(?s ?d))
  7453. (let* ((date (unless arg
  7454. (org-read-date
  7455. nil nil nil
  7456. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7457. (ans (if arg nil org-read-date-final-answer))
  7458. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7459. (setq cmd `(let* ((bound (fboundp 'read-string))
  7460. (old (and bound (symbol-function 'read-string))))
  7461. (unwind-protect
  7462. (progn
  7463. (fset 'read-string (lambda (&rest ignore) ,ans))
  7464. (eval '(,c1 arg)))
  7465. (if bound
  7466. (fset 'read-string old)
  7467. (fmakunbound 'read-string)))))))
  7468. ((equal action ?S)
  7469. (if (not (org-agenda-check-type nil 'agenda 'timeline))
  7470. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  7471. (let ((days (read-number
  7472. (format "Scatter tasks across how many %sdays: "
  7473. (if arg "week" "")) 7)))
  7474. (setq cmd
  7475. `(let ((distance (1+ (random ,days))))
  7476. (if arg
  7477. (let ((dist distance)
  7478. (day-of-week
  7479. (calendar-day-of-week
  7480. (calendar-gregorian-from-absolute (org-today)))))
  7481. (dotimes (i (1+ dist))
  7482. (while (member day-of-week org-agenda-weekend-days)
  7483. (incf distance)
  7484. (incf day-of-week)
  7485. (if (= day-of-week 7)
  7486. (setq day-of-week 0)))
  7487. (incf day-of-week)
  7488. (if (= day-of-week 7)
  7489. (setq day-of-week 0)))))
  7490. ;; silently fail when try to replan a sexp entry
  7491. (condition-case nil
  7492. (org-agenda-date-later distance)
  7493. (error nil)))))))
  7494. (t (error "Invalid bulk action")))
  7495. ;; Sort the markers, to make sure that parents are handled before children
  7496. (setq entries (sort entries
  7497. (lambda (a b)
  7498. (cond
  7499. ((equal (marker-buffer a) (marker-buffer b))
  7500. (< (marker-position a) (marker-position b)))
  7501. (t
  7502. (string< (buffer-name (marker-buffer a))
  7503. (buffer-name (marker-buffer b))))))))
  7504. ;; Now loop over all markers and apply cmd
  7505. (while (setq e (pop entries))
  7506. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7507. (if (not pos)
  7508. (progn (message "Skipping removed entry at %s" e)
  7509. (setq cntskip (1+ cntskip)))
  7510. (goto-char pos)
  7511. (eval cmd)
  7512. (setq org-agenda-bulk-marked-entries
  7513. (delete e org-agenda-bulk-marked-entries))
  7514. (setq cnt (1+ cnt))))
  7515. (setq org-agenda-bulk-marked-entries nil)
  7516. (org-agenda-bulk-remove-all-marks)
  7517. (when redo-at-end (org-agenda-redo))
  7518. (message "Acted on %d entries%s"
  7519. cnt
  7520. (if (= cntskip 0)
  7521. ""
  7522. (format ", skipped %d (disappeared before their turn)"
  7523. cntskip)))))
  7524. ;;; Flagging notes
  7525. (defun org-agenda-show-the-flagging-note ()
  7526. "Display the flagging note in the other window.
  7527. When called a second time in direct sequence, offer to remove the FLAGGING
  7528. tag and (if present) the flagging note."
  7529. (interactive)
  7530. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7531. (win (selected-window))
  7532. note heading newhead)
  7533. (unless hdmarker
  7534. (error "No linked entry at point"))
  7535. (if (and (eq this-command last-command)
  7536. (y-or-n-p "Unflag and remove any flagging note? "))
  7537. (progn
  7538. (org-agenda-remove-flag hdmarker)
  7539. (let ((win (get-buffer-window "*Flagging Note*")))
  7540. (and win (delete-window win)))
  7541. (message "Entry unflaged"))
  7542. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7543. (unless note
  7544. (error "No flagging note"))
  7545. (org-kill-new note)
  7546. (org-switch-to-buffer-other-window "*Flagging Note*")
  7547. (erase-buffer)
  7548. (insert note)
  7549. (goto-char (point-min))
  7550. (while (re-search-forward "\\\\n" nil t)
  7551. (replace-match "\n" t t))
  7552. (goto-char (point-min))
  7553. (select-window win)
  7554. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7555. (defun org-agenda-remove-flag (marker)
  7556. "Remove the FLAGGED tag and any flagging note in the entry."
  7557. (let (newhead)
  7558. (org-with-point-at marker
  7559. (org-toggle-tag "FLAGGED" 'off)
  7560. (org-entry-delete nil "THEFLAGGINGNOTE")
  7561. (setq newhead (org-get-heading)))
  7562. (org-agenda-change-all-lines newhead marker)
  7563. (message "Entry unflaged")))
  7564. (defun org-agenda-get-any-marker (&optional pos)
  7565. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7566. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7567. ;;; Appointment reminders
  7568. (defvar appt-time-msg-list)
  7569. ;;;###autoload
  7570. (defun org-agenda-to-appt (&optional refresh filter)
  7571. "Activate appointments found in `org-agenda-files'.
  7572. With a \\[universal-argument] prefix, refresh the list of
  7573. appointments.
  7574. If FILTER is t, interactively prompt the user for a regular
  7575. expression, and filter out entries that don't match it.
  7576. If FILTER is a string, use this string as a regular expression
  7577. for filtering entries out.
  7578. FILTER can also be an alist with the car of each cell being
  7579. either 'headline or 'category. For example:
  7580. '((headline \"IMPORTANT\")
  7581. (category \"Work\"))
  7582. will only add headlines containing IMPORTANT or headlines
  7583. belonging to the \"Work\" category."
  7584. (interactive "P")
  7585. (if refresh (setq appt-time-msg-list nil))
  7586. (if (eq filter t)
  7587. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7588. (let* ((cnt 0) ; count added events
  7589. (org-agenda-new-buffers nil)
  7590. (org-deadline-warning-days 0)
  7591. ;; Do not use `org-today' here because appt only takes
  7592. ;; time and without date as argument, so it may pass wrong
  7593. ;; information otherwise
  7594. (today (org-date-to-gregorian
  7595. (time-to-days (current-time))))
  7596. (org-agenda-restrict nil)
  7597. (files (org-agenda-files 'unrestricted)) entries file)
  7598. ;; Get all entries which may contain an appt
  7599. (org-prepare-agenda-buffers files)
  7600. (while (setq file (pop files))
  7601. (setq entries
  7602. (append entries
  7603. (org-agenda-get-day-entries
  7604. file today :timestamp :scheduled :deadline))))
  7605. (setq entries (delq nil entries))
  7606. ;; Map thru entries and find if we should filter them out
  7607. (mapc
  7608. (lambda(x)
  7609. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7610. (cat (get-text-property 1 'org-category x))
  7611. (tod (get-text-property 1 'time-of-day x))
  7612. (ok (or (null filter)
  7613. (and (stringp filter) (string-match filter evt))
  7614. (and (listp filter)
  7615. (or (string-match
  7616. (cadr (assoc 'category filter)) cat)
  7617. (string-match
  7618. (cadr (assoc 'headline filter)) evt))))))
  7619. ;; FIXME: Shall we remove text-properties for the appt text?
  7620. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7621. (when (and ok tod)
  7622. (setq tod (concat "00" (number-to-string tod))
  7623. tod (when (string-match
  7624. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7625. (concat (match-string 1 tod) ":"
  7626. (match-string 2 tod))))
  7627. (appt-add tod evt)
  7628. (setq cnt (1+ cnt))))) entries)
  7629. (org-release-buffers org-agenda-new-buffers)
  7630. (if (eq cnt 0)
  7631. (message "No event to add")
  7632. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7633. (defun org-agenda-todayp (date)
  7634. "Does DATE mean today, when considering `org-extend-today-until'?"
  7635. (let ((today (org-today))
  7636. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  7637. date)))
  7638. (eq date today)))
  7639. (provide 'org-agenda)
  7640. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  7641. ;;; org-agenda.el ends here