org-agenda.el 332 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2011 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org-mode.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'org)
  42. (eval-when-compile
  43. (require 'cl))
  44. (declare-function diary-add-to-list "diary-lib"
  45. (date string specifier &optional marker globcolor literal))
  46. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  47. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  48. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  49. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  50. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  51. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-french-date-string "cal-french" (&optional date))
  53. (declare-function calendar-goto-date "cal-move" (date))
  54. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  55. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  56. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  57. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  58. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  59. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  60. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  61. (declare-function calendar-check-holidays "holidays" (date))
  62. (declare-function org-datetree-find-date-create "org-datetree"
  63. (date &optional keep-restriction))
  64. (declare-function org-columns-quit "org-colview" ())
  65. (declare-function diary-date-display-form "diary-lib" (&optional type))
  66. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  67. (declare-function org-habit-insert-consistency-graphs
  68. "org-habit" (&optional line))
  69. (declare-function org-is-habit-p "org-habit" (&optional pom))
  70. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  71. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  72. (declare-function org-pop-to-buffer-same-window "org-compat"
  73. (&optional buffer-or-name norecord label))
  74. (defvar calendar-mode-map)
  75. (defvar org-clock-current-task) ; defined in org-clock.el
  76. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  77. (defvar org-habit-show-habits)
  78. (defvar org-habit-show-habits-only-for-today)
  79. ;; Defined somewhere in this file, but used before definition.
  80. (defvar org-agenda-buffer-name)
  81. (defvar org-agenda-overriding-header)
  82. (defvar org-agenda-title-append nil)
  83. (defvar entry)
  84. (defvar date)
  85. (defvar org-agenda-undo-list)
  86. (defvar org-agenda-pending-undo-list)
  87. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  88. (defcustom org-agenda-confirm-kill 1
  89. "When set, remote killing from the agenda buffer needs confirmation.
  90. When t, a confirmation is always needed. When a number N, confirmation is
  91. only needed when the text to be killed contains more than N non-white lines."
  92. :group 'org-agenda
  93. :type '(choice
  94. (const :tag "Never" nil)
  95. (const :tag "Always" t)
  96. (integer :tag "When more than N lines")))
  97. (defcustom org-agenda-compact-blocks nil
  98. "Non-nil means make the block agenda more compact.
  99. This is done globally by leaving out lines like the agenda span
  100. name and week number or the separator lines."
  101. :group 'org-agenda
  102. :type 'boolean)
  103. (defcustom org-agenda-block-separator ?=
  104. "The separator between blocks in the agenda.
  105. If this is a string, it will be used as the separator, with a newline added.
  106. If it is a character, it will be repeated to fill the window width.
  107. If nil the separator is disabled. In `org-agenda-custom-commands' this
  108. addresses the separator between the current and the previous block."
  109. :group 'org-agenda
  110. :type '(choice
  111. (const :tag "Disabled" nil)
  112. (character)
  113. (string)))
  114. (defgroup org-agenda-export nil
  115. "Options concerning exporting agenda views in Org-mode."
  116. :tag "Org Agenda Export"
  117. :group 'org-agenda)
  118. (defcustom org-agenda-with-colors t
  119. "Non-nil means use colors in agenda views."
  120. :group 'org-agenda-export
  121. :type 'boolean)
  122. (defcustom org-agenda-exporter-settings nil
  123. "Alist of variable/value pairs that should be active during agenda export.
  124. This is a good place to set options for ps-print and for htmlize.
  125. Note that the way this is implemented, the values will be evaluated
  126. before assigned to the variables. So make sure to quote values you do
  127. *not* want evaluated, for example
  128. (setq org-agenda-exporter-settings
  129. '((ps-print-color-p 'black-white)))"
  130. :group 'org-agenda-export
  131. :type '(repeat
  132. (list
  133. (variable)
  134. (sexp :tag "Value"))))
  135. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  136. "Hook run in temporary buffer before writing it to an export file.
  137. A useful function is `org-agenda-add-entry-text'."
  138. :group 'org-agenda-export
  139. :type 'hook
  140. :options '(org-agenda-add-entry-text))
  141. (defcustom org-agenda-add-entry-text-maxlines 0
  142. "Maximum number of entry text lines to be added to agenda.
  143. This is only relevant when `org-agenda-add-entry-text' is part of
  144. `org-agenda-before-write-hook', which it is by default.
  145. When this is 0, nothing will happen. When it is greater than 0, it
  146. specifies the maximum number of lines that will be added for each entry
  147. that is listed in the agenda view.
  148. Note that this variable is not used during display, only when exporting
  149. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  150. and `org-agenda-entry-text-maxlines'."
  151. :group 'org-agenda
  152. :type 'integer)
  153. (defcustom org-agenda-add-entry-text-descriptive-links t
  154. "Non-nil means export org-links as descriptive links in agenda added text.
  155. This variable applies to the text added to the agenda when
  156. `org-agenda-add-entry-text-maxlines' is larger than 0.
  157. When this variable nil, the URL will (also) be shown."
  158. :group 'org-agenda
  159. :type 'boolean)
  160. (defcustom org-agenda-export-html-style ""
  161. "The style specification for exported HTML Agenda files.
  162. If this variable contains a string, it will replace the default <style>
  163. section as produced by `htmlize'.
  164. Since there are different ways of setting style information, this variable
  165. needs to contain the full HTML structure to provide a style, including the
  166. surrounding HTML tags. The style specifications should include definitions
  167. the fonts used by the agenda, here is an example:
  168. <style type=\"text/css\">
  169. p { font-weight: normal; color: gray; }
  170. .org-agenda-structure {
  171. font-size: 110%;
  172. color: #003399;
  173. font-weight: 600;
  174. }
  175. .org-todo {
  176. color: #cc6666;
  177. font-weight: bold;
  178. }
  179. .org-agenda-done {
  180. color: #339933;
  181. }
  182. .org-done {
  183. color: #339933;
  184. }
  185. .title { text-align: center; }
  186. .todo, .deadline { color: red; }
  187. .done { color: green; }
  188. </style>
  189. or, if you want to keep the style in a file,
  190. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  191. As the value of this option simply gets inserted into the HTML <head> header,
  192. you can \"misuse\" it to also add other text to the header. However,
  193. <style>...</style> is required, if not present the variable will be ignored."
  194. :group 'org-agenda-export
  195. :group 'org-export-html
  196. :type 'string)
  197. (defcustom org-agenda-persistent-filter nil
  198. "When set, keep filters from one agenda view to the next."
  199. :group 'org-agenda
  200. :type 'boolean)
  201. (defgroup org-agenda-custom-commands nil
  202. "Options concerning agenda views in Org-mode."
  203. :tag "Org Agenda Custom Commands"
  204. :group 'org-agenda)
  205. (defconst org-sorting-choice
  206. '(choice
  207. (const time-up) (const time-down)
  208. (const category-keep) (const category-up) (const category-down)
  209. (const tag-down) (const tag-up)
  210. (const priority-up) (const priority-down)
  211. (const todo-state-up) (const todo-state-down)
  212. (const effort-up) (const effort-down)
  213. (const habit-up) (const habit-down)
  214. (const alpha-up) (const alpha-down)
  215. (const user-defined-up) (const user-defined-down))
  216. "Sorting choices.")
  217. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  218. ;; the new variable `org-agenda-tag-filter-preset'.
  219. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  220. (defconst org-agenda-custom-commands-local-options
  221. `(repeat :tag "Local settings for this command. Remember to quote values"
  222. (choice :tag "Setting"
  223. (list :tag "Heading for this block"
  224. (const org-agenda-overriding-header)
  225. (string :tag "Headline"))
  226. (list :tag "Files to be searched"
  227. (const org-agenda-files)
  228. (list
  229. (const :format "" quote)
  230. (repeat (file))))
  231. (list :tag "Sorting strategy"
  232. (const org-agenda-sorting-strategy)
  233. (list
  234. (const :format "" quote)
  235. (repeat
  236. ,org-sorting-choice)))
  237. (list :tag "Prefix format"
  238. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  239. (string))
  240. (list :tag "Number of days in agenda"
  241. (const org-agenda-span)
  242. (choice (const :tag "Day" 'day)
  243. (const :tag "Week" 'week)
  244. (const :tag "Month" 'month)
  245. (const :tag "Year" 'year)
  246. (integer :tag "Custom")))
  247. (list :tag "Fixed starting date"
  248. (const org-agenda-start-day)
  249. (string :value "2007-11-01"))
  250. (list :tag "Start on day of week"
  251. (const org-agenda-start-on-weekday)
  252. (choice :value 1
  253. (const :tag "Today" nil)
  254. (integer :tag "Weekday No.")))
  255. (list :tag "Include data from diary"
  256. (const org-agenda-include-diary)
  257. (boolean))
  258. (list :tag "Deadline Warning days"
  259. (const org-deadline-warning-days)
  260. (integer :value 1))
  261. (list :tag "Category filter preset"
  262. (const org-agenda-category-filter-preset)
  263. (list
  264. (const :format "" quote)
  265. (repeat
  266. (string :tag "+category or -category"))))
  267. (list :tag "Tags filter preset"
  268. (const org-agenda-tag-filter-preset)
  269. (list
  270. (const :format "" quote)
  271. (repeat
  272. (string :tag "+tag or -tag"))))
  273. (list :tag "Set daily/weekly entry types"
  274. (const org-agenda-entry-types)
  275. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  276. (const :deadline)
  277. (const :scheduled)
  278. (const :timestamp)
  279. (const :sexp)))
  280. (list :tag "Standard skipping condition"
  281. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  282. (const org-agenda-skip-function)
  283. (list
  284. (const :format "" quote)
  285. (list
  286. (choice
  287. :tag "Skipping range"
  288. (const :tag "Skip entry" org-agenda-skip-entry-if)
  289. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  290. (repeat :inline t :tag "Conditions for skipping"
  291. (choice
  292. :tag "Condition type"
  293. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  294. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  295. (list :tag "TODO state is" :inline t
  296. (const 'todo)
  297. (choice
  298. (const :tag "any not-done state" 'todo)
  299. (const :tag "any done state" 'done)
  300. (const :tag "any state" 'any)
  301. (list :tag "Keyword list"
  302. (const :format "" quote)
  303. (repeat (string :tag "Keyword")))))
  304. (list :tag "TODO state is not" :inline t
  305. (const 'nottodo)
  306. (choice
  307. (const :tag "any not-done state" 'todo)
  308. (const :tag "any done state" 'done)
  309. (const :tag "any state" 'any)
  310. (list :tag "Keyword list"
  311. (const :format "" quote)
  312. (repeat (string :tag "Keyword")))))
  313. (const :tag "scheduled" 'scheduled)
  314. (const :tag "not scheduled" 'notscheduled)
  315. (const :tag "deadline" 'deadline)
  316. (const :tag "no deadline" 'notdeadline)
  317. (const :tag "timestamp" 'timestamp)
  318. (const :tag "no timestamp" 'nottimestamp))))))
  319. (list :tag "Non-standard skipping condition"
  320. :value (org-agenda-skip-function)
  321. (const org-agenda-skip-function)
  322. (sexp :tag "Function or form (quoted!)"))
  323. (list :tag "Any variable"
  324. (variable :tag "Variable")
  325. (sexp :tag "Value (sexp)"))))
  326. "Selection of examples for agenda command settings.
  327. This will be spliced into the custom type of
  328. `org-agenda-custom-commands'.")
  329. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  330. ((agenda "") (alltodo))))
  331. "Custom commands for the agenda.
  332. These commands will be offered on the splash screen displayed by the
  333. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  334. (key desc type match settings files)
  335. key The key (one or more characters as a string) to be associated
  336. with the command.
  337. desc A description of the command, when omitted or nil, a default
  338. description is built using MATCH.
  339. type The command type, any of the following symbols:
  340. agenda The daily/weekly agenda.
  341. todo Entries with a specific TODO keyword, in all agenda files.
  342. search Entries containing search words entry or headline.
  343. tags Tags/Property/TODO match in all agenda files.
  344. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  345. todo-tree Sparse tree of specific TODO keyword in *current* file.
  346. tags-tree Sparse tree with all tags matches in *current* file.
  347. occur-tree Occur sparse tree for *current* file.
  348. ... A user-defined function.
  349. match What to search for:
  350. - a single keyword for TODO keyword searches
  351. - a tags match expression for tags searches
  352. - a word search expression for text searches.
  353. - a regular expression for occur searches
  354. For all other commands, this should be the empty string.
  355. settings A list of option settings, similar to that in a let form, so like
  356. this: ((opt1 val1) (opt2 val2) ...). The values will be
  357. evaluated at the moment of execution, so quote them when needed.
  358. files A list of files file to write the produced agenda buffer to
  359. with the command `org-store-agenda-views'.
  360. If a file name ends in \".html\", an HTML version of the buffer
  361. is written out. If it ends in \".ps\", a postscript version is
  362. produced. Otherwise, only the plain text is written to the file.
  363. You can also define a set of commands, to create a composite agenda buffer.
  364. In this case, an entry looks like this:
  365. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  366. where
  367. desc A description string to be displayed in the dispatcher menu.
  368. cmd An agenda command, similar to the above. However, tree commands
  369. are not allowed, but instead you can get agenda and global todo list.
  370. So valid commands for a set are:
  371. (agenda \"\" settings)
  372. (alltodo \"\" settings)
  373. (stuck \"\" settings)
  374. (todo \"match\" settings files)
  375. (search \"match\" settings files)
  376. (tags \"match\" settings files)
  377. (tags-todo \"match\" settings files)
  378. Each command can carry a list of options, and another set of options can be
  379. given for the whole set of commands. Individual command options take
  380. precedence over the general options.
  381. When using several characters as key to a command, the first characters
  382. are prefix commands. For the dispatcher to display useful information, you
  383. should provide a description for the prefix, like
  384. (setq org-agenda-custom-commands
  385. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  386. (\"hl\" tags \"+HOME+Lisa\")
  387. (\"hp\" tags \"+HOME+Peter\")
  388. (\"hk\" tags \"+HOME+Kim\")))"
  389. :group 'org-agenda-custom-commands
  390. :type `(repeat
  391. (choice :value ("x" "Describe command here" tags "" nil)
  392. (list :tag "Single command"
  393. (string :tag "Access Key(s) ")
  394. (option (string :tag "Description"))
  395. (choice
  396. (const :tag "Agenda" agenda)
  397. (const :tag "TODO list" alltodo)
  398. (const :tag "Search words" search)
  399. (const :tag "Stuck projects" stuck)
  400. (const :tag "Tags/Property match (all agenda files)" tags)
  401. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  402. (const :tag "TODO keyword search (all agenda files)" todo)
  403. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  404. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  405. (const :tag "Occur tree (current buffer)" occur-tree)
  406. (sexp :tag "Other, user-defined function"))
  407. (string :tag "Match (only for some commands)")
  408. ,org-agenda-custom-commands-local-options
  409. (option (repeat :tag "Export" (file :tag "Export to"))))
  410. (list :tag "Command series, all agenda files"
  411. (string :tag "Access Key(s)")
  412. (string :tag "Description ")
  413. (repeat :tag "Component"
  414. (choice
  415. (list :tag "Agenda"
  416. (const :format "" agenda)
  417. (const :tag "" :format "" "")
  418. ,org-agenda-custom-commands-local-options)
  419. (list :tag "TODO list (all keywords)"
  420. (const :format "" alltodo)
  421. (const :tag "" :format "" "")
  422. ,org-agenda-custom-commands-local-options)
  423. (list :tag "Search words"
  424. (const :format "" search)
  425. (string :tag "Match")
  426. ,org-agenda-custom-commands-local-options)
  427. (list :tag "Stuck projects"
  428. (const :format "" stuck)
  429. (const :tag "" :format "" "")
  430. ,org-agenda-custom-commands-local-options)
  431. (list :tag "Tags search"
  432. (const :format "" tags)
  433. (string :tag "Match")
  434. ,org-agenda-custom-commands-local-options)
  435. (list :tag "Tags search, TODO entries only"
  436. (const :format "" tags-todo)
  437. (string :tag "Match")
  438. ,org-agenda-custom-commands-local-options)
  439. (list :tag "TODO keyword search"
  440. (const :format "" todo)
  441. (string :tag "Match")
  442. ,org-agenda-custom-commands-local-options)
  443. (list :tag "Other, user-defined function"
  444. (symbol :tag "function")
  445. (string :tag "Match")
  446. ,org-agenda-custom-commands-local-options)))
  447. (repeat :tag "Settings for entire command set"
  448. (list (variable :tag "Any variable")
  449. (sexp :tag "Value")))
  450. (option (repeat :tag "Export" (file :tag "Export to"))))
  451. (cons :tag "Prefix key documentation"
  452. (string :tag "Access Key(s)")
  453. (string :tag "Description ")))))
  454. (defcustom org-agenda-query-register ?o
  455. "The register holding the current query string.
  456. The purpose of this is that if you construct a query string interactively,
  457. you can then use it to define a custom command."
  458. :group 'org-agenda-custom-commands
  459. :type 'character)
  460. (defcustom org-stuck-projects
  461. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  462. "How to identify stuck projects.
  463. This is a list of four items:
  464. 1. A tags/todo/property matcher string that is used to identify a project.
  465. See the manual for a description of tag and property searches.
  466. The entire tree below a headline matched by this is considered one project.
  467. 2. A list of TODO keywords identifying non-stuck projects.
  468. If the project subtree contains any headline with one of these todo
  469. keywords, the project is considered to be not stuck. If you specify
  470. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  471. 3. A list of tags identifying non-stuck projects.
  472. If the project subtree contains any headline with one of these tags,
  473. the project is considered to be not stuck. If you specify \"*\" as
  474. a tag, any tag will mark the project unstuck. Note that this is about
  475. the explicit presence of a tag somewhere in the subtree, inherited
  476. tags to not count here. If inherited tags make a project not stuck,
  477. use \"-TAG\" in the tags part of the matcher under (1.) above.
  478. 4. An arbitrary regular expression matching non-stuck projects.
  479. If the project turns out to be not stuck, search continues also in the
  480. subtree to see if any of the subtasks have project status.
  481. See also the variable `org-tags-match-list-sublevels' which applies
  482. to projects matched by this search as well.
  483. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  484. or `C-c a #' to produce the list."
  485. :group 'org-agenda-custom-commands
  486. :type '(list
  487. (string :tag "Tags/TODO match to identify a project")
  488. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  489. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  490. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  491. (defcustom org-agenda-filter-effort-default-operator "<"
  492. "The default operator for effort estimate filtering.
  493. If you select an effort estimate limit without first pressing an operator,
  494. this one will be used."
  495. :group 'org-agenda-custom-commands
  496. :type '(choice (const :tag "less or equal" "<")
  497. (const :tag "greater or equal"">")
  498. (const :tag "equal" "=")))
  499. (defgroup org-agenda-skip nil
  500. "Options concerning skipping parts of agenda files."
  501. :tag "Org Agenda Skip"
  502. :group 'org-agenda)
  503. (defcustom org-agenda-skip-function-global nil
  504. "Function to be called at each match during agenda construction.
  505. If this function returns nil, the current match should not be skipped.
  506. If the function decided to skip an agenda match, is must return the
  507. buffer position from which the search should be continued.
  508. This may also be a Lisp form, which will be evaluated.
  509. This variable will be applied to every agenda match, including
  510. tags/property searches and TODO lists. So try to make the test function
  511. do its checking as efficiently as possible. To implement a skipping
  512. condition just for specific agenda commands, use the variable
  513. `org-agenda-skip-function' which can be set in the options section
  514. of custom agenda commands."
  515. :group 'org-agenda-skip
  516. :type 'sexp)
  517. (defgroup org-agenda-daily/weekly nil
  518. "Options concerning the daily/weekly agenda."
  519. :tag "Org Agenda Daily/Weekly"
  520. :group 'org-agenda)
  521. (defgroup org-agenda-todo-list nil
  522. "Options concerning the global todo list agenda view."
  523. :tag "Org Agenda Todo List"
  524. :group 'org-agenda)
  525. (defgroup org-agenda-match-view nil
  526. "Options concerning the general tags/property/todo match agenda view."
  527. :tag "Org Agenda Match View"
  528. :group 'org-agenda)
  529. (defgroup org-agenda-search-view nil
  530. "Options concerning the general tags/property/todo match agenda view."
  531. :tag "Org Agenda Match View"
  532. :group 'org-agenda)
  533. (defvar org-agenda-archives-mode nil
  534. "Non-nil means the agenda will include archived items.
  535. If this is the symbol `trees', trees in the selected agenda scope
  536. that are marked with the ARCHIVE tag will be included anyway. When this is
  537. t, also all archive files associated with the current selection of agenda
  538. files will be included.")
  539. (defcustom org-agenda-skip-comment-trees t
  540. "Non-nil means skip trees that start with the COMMENT keyword.
  541. When nil, these trees are also scanned by agenda commands."
  542. :group 'org-agenda-skip
  543. :type 'boolean)
  544. (defcustom org-agenda-todo-list-sublevels t
  545. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  546. When nil, the sublevels of a TODO entry are not checked, resulting in
  547. potentially much shorter TODO lists."
  548. :group 'org-agenda-skip
  549. :group 'org-agenda-todo-list
  550. :type 'boolean)
  551. (defcustom org-agenda-todo-ignore-with-date nil
  552. "Non-nil means don't show entries with a date in the global todo list.
  553. You can use this if you prefer to mark mere appointments with a TODO keyword,
  554. but don't want them to show up in the TODO list.
  555. When this is set, it also covers deadlines and scheduled items, the settings
  556. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  557. will be ignored.
  558. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  559. :group 'org-agenda-skip
  560. :group 'org-agenda-todo-list
  561. :type 'boolean)
  562. (defcustom org-agenda-todo-ignore-timestamp nil
  563. "Non-nil means don't show entries with a timestamp.
  564. This applies when creating the global todo list.
  565. Valid values are:
  566. past Don't show entries for today or in the past.
  567. future Don't show entries with a timestamp in the future.
  568. The idea behind this is that if it has a future
  569. timestamp, you don't want to think about it until the
  570. date.
  571. all Don't show any entries with a timestamp in the global todo list.
  572. The idea behind this is that by setting a timestamp, you
  573. have already \"taken care\" of this item.
  574. This variable can also have an integer as a value. If positive (N),
  575. todos with a timestamp N or more days in the future will be ignored. If
  576. negative (-N), todos with a timestamp N or more days in the past will be
  577. ignored. If 0, todos with a timestamp either today or in the future will
  578. be ignored. For example, a value of -1 will exclude todos with a
  579. timestamp in the past (yesterday or earlier), while a value of 7 will
  580. exclude todos with a timestamp a week or more in the future.
  581. See also `org-agenda-todo-ignore-with-date'.
  582. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  583. to make his option also apply to the tags-todo list."
  584. :group 'org-agenda-skip
  585. :group 'org-agenda-todo-list
  586. :type '(choice
  587. (const :tag "Ignore future timestamp todos" future)
  588. (const :tag "Ignore past or present timestamp todos" past)
  589. (const :tag "Ignore all timestamp todos" all)
  590. (const :tag "Show timestamp todos" nil)
  591. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  592. (defcustom org-agenda-todo-ignore-scheduled nil
  593. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  594. This applies when creating the global todo list.
  595. Valid values are:
  596. past Don't show entries scheduled today or in the past.
  597. future Don't show entries scheduled in the future.
  598. The idea behind this is that by scheduling it, you don't want to
  599. think about it until the scheduled date.
  600. all Don't show any scheduled entries in the global todo list.
  601. The idea behind this is that by scheduling it, you have already
  602. \"taken care\" of this item.
  603. t Same as `all', for backward compatibility.
  604. This variable can also have an integer as a value. See
  605. `org-agenda-todo-ignore-timestamp' for more details.
  606. See also `org-agenda-todo-ignore-with-date'.
  607. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  608. to make his option also apply to the tags-todo list."
  609. :group 'org-agenda-skip
  610. :group 'org-agenda-todo-list
  611. :type '(choice
  612. (const :tag "Ignore future-scheduled todos" future)
  613. (const :tag "Ignore past- or present-scheduled todos" past)
  614. (const :tag "Ignore all scheduled todos" all)
  615. (const :tag "Ignore all scheduled todos (compatibility)" t)
  616. (const :tag "Show scheduled todos" nil)
  617. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  618. (defcustom org-agenda-todo-ignore-deadlines nil
  619. "Non-nil means ignore some deadlined TODO items when making TODO list.
  620. There are different motivations for using different values, please think
  621. carefully when configuring this variable.
  622. This applies when creating the global todo list.
  623. Valid values are:
  624. near Don't show near deadline entries. A deadline is near when it is
  625. closer than `org-deadline-warning-days' days. The idea behind this
  626. is that such items will appear in the agenda anyway.
  627. far Don't show TODO entries where a deadline has been defined, but
  628. the deadline is not near. This is useful if you don't want to
  629. use the todo list to figure out what to do now.
  630. past Don't show entries with a deadline timestamp for today or in the past.
  631. future Don't show entries with a deadline timestamp in the future, not even
  632. when they become `near' ones. Use it with caution.
  633. all Ignore all TODO entries that do have a deadline.
  634. t Same as `near', for backward compatibility.
  635. This variable can also have an integer as a value. See
  636. `org-agenda-todo-ignore-timestamp' for more details.
  637. See also `org-agenda-todo-ignore-with-date'.
  638. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  639. to make his option also apply to the tags-todo list."
  640. :group 'org-agenda-skip
  641. :group 'org-agenda-todo-list
  642. :type '(choice
  643. (const :tag "Ignore near deadlines" near)
  644. (const :tag "Ignore near deadlines (compatibility)" t)
  645. (const :tag "Ignore far deadlines" far)
  646. (const :tag "Ignore all TODOs with a deadlines" all)
  647. (const :tag "Show all TODOs, even if they have a deadline" nil)
  648. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  649. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  650. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  651. The variables
  652. `org-agenda-todo-ignore-with-date',
  653. `org-agenda-todo-ignore-timestamp',
  654. `org-agenda-todo-ignore-scheduled',
  655. `org-agenda-todo-ignore-deadlines'
  656. make the global TODO list skip entries that have time stamps of certain
  657. kinds. If this option is set, the same options will also apply for the
  658. tags-todo search, which is the general tags/property matcher
  659. restricted to unfinished TODO entries only."
  660. :group 'org-agenda-skip
  661. :group 'org-agenda-todo-list
  662. :group 'org-agenda-match-view
  663. :type 'boolean)
  664. (defcustom org-agenda-skip-scheduled-if-done nil
  665. "Non-nil means don't show scheduled items in agenda when they are done.
  666. This is relevant for the daily/weekly agenda, not for the TODO list. And
  667. it applies only to the actual date of the scheduling. Warnings about
  668. an item with a past scheduling dates are always turned off when the item
  669. is DONE."
  670. :group 'org-agenda-skip
  671. :group 'org-agenda-daily/weekly
  672. :type 'boolean)
  673. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  674. "Non-nil means skip scheduling line if same entry shows because of deadline.
  675. In the agenda of today, an entry can show up multiple times because
  676. it is both scheduled and has a nearby deadline, and maybe a plain time
  677. stamp as well.
  678. When this variable is t, then only the deadline is shown and the fact that
  679. the entry is scheduled today or was scheduled previously is not shown.
  680. When this variable is nil, the entry will be shown several times. When
  681. the variable is the symbol `not-today', then skip scheduled previously,
  682. but not scheduled today."
  683. :group 'org-agenda-skip
  684. :group 'org-agenda-daily/weekly
  685. :type '(choice
  686. (const :tag "Never" nil)
  687. (const :tag "Always" t)
  688. (const :tag "Not when scheduled today" not-today)))
  689. (defcustom org-agenda-skip-deadline-if-done nil
  690. "Non-nil means don't show deadlines when the corresponding item is done.
  691. When nil, the deadline is still shown and should give you a happy feeling.
  692. This is relevant for the daily/weekly agenda. And it applied only to the
  693. actually date of the deadline. Warnings about approaching and past-due
  694. deadlines are always turned off when the item is DONE."
  695. :group 'org-agenda-skip
  696. :group 'org-agenda-daily/weekly
  697. :type 'boolean)
  698. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  699. "Non-nil means skip deadline prewarning when entry is also scheduled.
  700. This will apply on all days where a prewarning for the deadline would
  701. be shown, but not at the day when the entry is actually due. On that day,
  702. the deadline will be shown anyway.
  703. This variable may be set to nil, t, or a number which will then give
  704. the number of days before the actual deadline when the prewarnings
  705. should resume.
  706. This can be used in a workflow where the first showing of the deadline will
  707. trigger you to schedule it, and then you don't want to be reminded of it
  708. because you will take care of it on the day when scheduled."
  709. :group 'org-agenda-skip
  710. :group 'org-agenda-daily/weekly
  711. :type '(choice
  712. (const :tag "Alwas show prewarning" nil)
  713. (const :tag "Remove prewarning if entry is scheduled" t)
  714. (integer :tag "Restart prewarning N days before deadline")))
  715. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  716. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  717. When non-nil, after the search for timestamps has matched once in an
  718. entry, the rest of the entry will not be searched."
  719. :group 'org-agenda-skip
  720. :type 'boolean)
  721. (defcustom org-agenda-skip-timestamp-if-done nil
  722. "Non-nil means don't select item by timestamp or -range if it is DONE."
  723. :group 'org-agenda-skip
  724. :group 'org-agenda-daily/weekly
  725. :type 'boolean)
  726. (defcustom org-agenda-dim-blocked-tasks t
  727. "Non-nil means dim blocked tasks in the agenda display.
  728. This causes some overhead during agenda construction, but if you
  729. have turned on `org-enforce-todo-dependencies',
  730. `org-enforce-todo-checkbox-dependencies', or any other blocking
  731. mechanism, this will create useful feedback in the agenda.
  732. Instead of t, this variable can also have the value `invisible'.
  733. Then blocked tasks will be invisible and only become visible when
  734. they become unblocked. An exemption to this behavior is when a task is
  735. blocked because of unchecked checkboxes below it. Since checkboxes do
  736. not show up in the agenda views, making this task invisible you remove any
  737. trace from agenda views that there is something to do. Therefore, a task
  738. that is blocked because of checkboxes will never be made invisible, it
  739. will only be dimmed."
  740. :group 'org-agenda-daily/weekly
  741. :group 'org-agenda-todo-list
  742. :type '(choice
  743. (const :tag "Do not dim" nil)
  744. (const :tag "Dim to a gray face" t)
  745. (const :tag "Make invisible" invisible)))
  746. (defcustom org-timeline-show-empty-dates 3
  747. "Non-nil means `org-timeline' also shows dates without an entry.
  748. When nil, only the days which actually have entries are shown.
  749. When t, all days between the first and the last date are shown.
  750. When an integer, show also empty dates, but if there is a gap of more than
  751. N days, just insert a special line indicating the size of the gap."
  752. :group 'org-agenda-skip
  753. :type '(choice
  754. (const :tag "None" nil)
  755. (const :tag "All" t)
  756. (integer :tag "at most")))
  757. (defgroup org-agenda-startup nil
  758. "Options concerning initial settings in the Agenda in Org Mode."
  759. :tag "Org Agenda Startup"
  760. :group 'org-agenda)
  761. (defcustom org-agenda-menu-show-matcher t
  762. "Non-nil means show the match string in the agenda dispatcher menu.
  763. When nil, the matcher string is not shown, but is put into the help-echo
  764. property so than moving the mouse over the command shows it.
  765. Setting it to nil is good if matcher strings are very long and/or if
  766. you want to use two-column display (see `org-agenda-menu-two-column')."
  767. :group 'org-agenda
  768. :type 'boolean)
  769. (defcustom org-agenda-menu-two-column nil
  770. "Non-nil means, use two columns to show custom commands in the dispatcher.
  771. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  772. to nil."
  773. :group 'org-agenda
  774. :type 'boolean)
  775. (defcustom org-finalize-agenda-hook nil
  776. "Hook run just before displaying an agenda buffer."
  777. :group 'org-agenda-startup
  778. :type 'hook)
  779. (defcustom org-agenda-mouse-1-follows-link nil
  780. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  781. A longer mouse click will still set point. Does not work on XEmacs.
  782. Needs to be set before org.el is loaded."
  783. :group 'org-agenda-startup
  784. :type 'boolean)
  785. (defcustom org-agenda-start-with-follow-mode nil
  786. "The initial value of follow mode in a newly created agenda window."
  787. :group 'org-agenda-startup
  788. :type 'boolean)
  789. (defcustom org-agenda-follow-indirect nil
  790. "Non-nil means `org-agenda-follow-mode' displays only the
  791. current item's tree, in an indirect buffer."
  792. :group 'org-agenda
  793. :type 'boolean)
  794. (defcustom org-agenda-show-outline-path t
  795. "Non-nil means show outline path in echo area after line motion."
  796. :group 'org-agenda-startup
  797. :type 'boolean)
  798. (defcustom org-agenda-start-with-entry-text-mode nil
  799. "The initial value of entry-text-mode in a newly created agenda window."
  800. :group 'org-agenda-startup
  801. :type 'boolean)
  802. (defcustom org-agenda-entry-text-maxlines 5
  803. "Number of text lines to be added when `E' is pressed in the agenda.
  804. Note that this variable only used during agenda display. Add add entry text
  805. when exporting the agenda, configure the variable
  806. `org-agenda-add-entry-ext-maxlines'."
  807. :group 'org-agenda
  808. :type 'integer)
  809. (defcustom org-agenda-entry-text-exclude-regexps nil
  810. "List of regular expressions to clean up entry text.
  811. The complete matches of all regular expressions in this list will be
  812. removed from entry text before it is shown in the agenda."
  813. :group 'org-agenda
  814. :type '(repeat (regexp)))
  815. (defvar org-agenda-entry-text-cleanup-hook nil
  816. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  817. This cleanup is done in a temporary buffer, so the function may inspect and
  818. change the entire buffer.
  819. Some default stuff like drawers and scheduling/deadline dates will already
  820. have been removed when this is called, as will any matches for regular
  821. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  822. (defvar org-agenda-include-inactive-timestamps nil
  823. "Non-nil means include inactive time stamps in agenda and timeline.")
  824. (defgroup org-agenda-windows nil
  825. "Options concerning the windows used by the Agenda in Org Mode."
  826. :tag "Org Agenda Windows"
  827. :group 'org-agenda)
  828. (defcustom org-agenda-window-setup 'reorganize-frame
  829. "How the agenda buffer should be displayed.
  830. Possible values for this option are:
  831. current-window Show agenda in the current window, keeping all other windows.
  832. other-window Use `switch-to-buffer-other-window' to display agenda.
  833. reorganize-frame Show only two windows on the current frame, the current
  834. window and the agenda.
  835. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  836. Also, when exiting the agenda, kill that frame.
  837. See also the variable `org-agenda-restore-windows-after-quit'."
  838. :group 'org-agenda-windows
  839. :type '(choice
  840. (const current-window)
  841. (const other-frame)
  842. (const other-window)
  843. (const reorganize-frame)))
  844. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  845. "The min and max height of the agenda window as a fraction of frame height.
  846. The value of the variable is a cons cell with two numbers between 0 and 1.
  847. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  848. :group 'org-agenda-windows
  849. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  850. (defcustom org-agenda-restore-windows-after-quit nil
  851. "Non-nil means restore window configuration upon exiting agenda.
  852. Before the window configuration is changed for displaying the agenda,
  853. the current status is recorded. When the agenda is exited with
  854. `q' or `x' and this option is set, the old state is restored. If
  855. `org-agenda-window-setup' is `other-frame', the value of this
  856. option will be ignored."
  857. :group 'org-agenda-windows
  858. :type 'boolean)
  859. (defcustom org-agenda-ndays nil
  860. "Number of days to include in overview display.
  861. Should be 1 or 7.
  862. Obsolete, see `org-agenda-span'."
  863. :group 'org-agenda-daily/weekly
  864. :type 'integer)
  865. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  866. (defcustom org-agenda-span 'week
  867. "Number of days to include in overview display.
  868. Can be day, week, month, year, or any number of days.
  869. Custom commands can set this variable in the options section."
  870. :group 'org-agenda-daily/weekly
  871. :type '(choice (const :tag "Day" day)
  872. (const :tag "Week" week)
  873. (const :tag "Month" month)
  874. (const :tag "Year" year)
  875. (integer :tag "Custom")))
  876. (defcustom org-agenda-start-on-weekday 1
  877. "Non-nil means start the overview always on the specified weekday.
  878. 0 denotes Sunday, 1 denotes Monday etc.
  879. When nil, always start on the current day.
  880. Custom commands can set this variable in the options section."
  881. :group 'org-agenda-daily/weekly
  882. :type '(choice (const :tag "Today" nil)
  883. (integer :tag "Weekday No.")))
  884. (defcustom org-agenda-show-all-dates t
  885. "Non-nil means `org-agenda' shows every day in the selected range.
  886. When nil, only the days which actually have entries are shown."
  887. :group 'org-agenda-daily/weekly
  888. :type 'boolean)
  889. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  890. "Format string for displaying dates in the agenda.
  891. Used by the daily/weekly agenda and by the timeline. This should be
  892. a format string understood by `format-time-string', or a function returning
  893. the formatted date as a string. The function must take a single argument,
  894. a calendar-style date list like (month day year)."
  895. :group 'org-agenda-daily/weekly
  896. :type '(choice
  897. (string :tag "Format string")
  898. (function :tag "Function")))
  899. (defun org-agenda-format-date-aligned (date)
  900. "Format a date string for display in the daily/weekly agenda, or timeline.
  901. This function makes sure that dates are aligned for easy reading."
  902. (require 'cal-iso)
  903. (let* ((dayname (calendar-day-name date))
  904. (day (cadr date))
  905. (day-of-week (calendar-day-of-week date))
  906. (month (car date))
  907. (monthname (calendar-month-name month))
  908. (year (nth 2 date))
  909. (iso-week (org-days-to-iso-week
  910. (calendar-absolute-from-gregorian date)))
  911. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  912. (1- year))
  913. ((and (= month 12) (<= iso-week 1))
  914. (1+ year))
  915. (t year)))
  916. (weekstring (if (= day-of-week 1)
  917. (format " W%02d" iso-week)
  918. "")))
  919. (format "%-10s %2d %s %4d%s"
  920. dayname day monthname year weekstring)))
  921. (defcustom org-agenda-time-leading-zero nil
  922. "Non-nil means use leading zero for military times in agenda.
  923. For example, 9:30am would become 09:30 rather than 9:30."
  924. :group 'org-agenda-daily/weekly
  925. :type 'boolean)
  926. (defcustom org-agenda-timegrid-use-ampm nil
  927. "When set, show AM/PM style timestamps on the timegrid."
  928. :group 'org-agenda
  929. :type 'boolean)
  930. (defun org-agenda-time-of-day-to-ampm (time)
  931. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  932. (let* ((hour-number (string-to-number (substring time 0 -3)))
  933. (minute (substring time -2))
  934. (ampm "am"))
  935. (cond
  936. ((equal hour-number 12)
  937. (setq ampm "pm"))
  938. ((> hour-number 12)
  939. (setq ampm "pm")
  940. (setq hour-number (- hour-number 12))))
  941. (concat
  942. (if org-agenda-time-leading-zero
  943. (format "%02d" hour-number)
  944. (format "%02s" (number-to-string hour-number)))
  945. ":" minute ampm)))
  946. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  947. "Conditionally convert TIME to AM/PM format
  948. based on `org-agenda-timegrid-use-ampm'"
  949. (if org-agenda-timegrid-use-ampm
  950. (org-agenda-time-of-day-to-ampm time)
  951. time))
  952. (defcustom org-agenda-weekend-days '(6 0)
  953. "Which days are weekend?
  954. These days get the special face `org-agenda-date-weekend' in the agenda
  955. and timeline buffers."
  956. :group 'org-agenda-daily/weekly
  957. :type '(set :greedy t
  958. (const :tag "Monday" 1)
  959. (const :tag "Tuesday" 2)
  960. (const :tag "Wednesday" 3)
  961. (const :tag "Thursday" 4)
  962. (const :tag "Friday" 5)
  963. (const :tag "Saturday" 6)
  964. (const :tag "Sunday" 0)))
  965. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  966. "Non-nil means jump to today when moving a past date forward in time.
  967. When using S-right in the agenda to move a a date forward, and the date
  968. stamp currently points to the past, the first key press will move it
  969. to today. WHen nil, just move one day forward even if the date stays
  970. in the past."
  971. :group 'org-agenda-daily/weekly
  972. :type 'boolean)
  973. (defcustom org-agenda-include-diary nil
  974. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  975. Custom commands can set this variable in the options section."
  976. :group 'org-agenda-daily/weekly
  977. :type 'boolean)
  978. (defcustom org-agenda-include-deadlines t
  979. "If non-nil, include entries within their deadline warning period.
  980. Custom commands can set this variable in the options section."
  981. :group 'org-agenda-daily/weekly
  982. :type 'boolean)
  983. (defcustom org-agenda-repeating-timestamp-show-all t
  984. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  985. When set to a list of strings, only show occurrences of repeating
  986. stamps for these TODO keywords. When nil, only one occurrence is
  987. shown, either today or the nearest into the future."
  988. :group 'org-agenda-daily/weekly
  989. :type '(choice
  990. (const :tag "Show repeating stamps" t)
  991. (repeat :tag "Show repeating stamps for these TODO keywords"
  992. (string :tag "TODO Keyword"))
  993. (const :tag "Don't show repeating stamps" nil)))
  994. (defcustom org-scheduled-past-days 10000
  995. "No. of days to continue listing scheduled items that are not marked DONE.
  996. When an item is scheduled on a date, it shows up in the agenda on this
  997. day and will be listed until it is marked done for the number of days
  998. given here."
  999. :group 'org-agenda-daily/weekly
  1000. :type 'integer)
  1001. (defcustom org-agenda-log-mode-items '(closed clock)
  1002. "List of items that should be shown in agenda log mode.
  1003. This list may contain the following symbols:
  1004. closed Show entries that have been closed on that day.
  1005. clock Show entries that have received clocked time on that day.
  1006. state Show all logged state changes.
  1007. Note that instead of changing this variable, you can also press `C-u l' in
  1008. the agenda to display all available LOG items temporarily."
  1009. :group 'org-agenda-daily/weekly
  1010. :type '(set :greedy t (const closed) (const clock) (const state)))
  1011. (defcustom org-agenda-clock-consistency-checks
  1012. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1013. :gap-ok-around ("4:00")
  1014. :default-face ((:background "DarkRed") (:foreground "white"))
  1015. :overlap-face nil :gap-face nil :no-end-time-face nil
  1016. :long-face nil :short-face nil)
  1017. "This is a property list, with the following keys:
  1018. :max-duration Mark clocking chunks that are longer than this time.
  1019. This is a time string like \"HH:MM\", or the number
  1020. of minutes as an integer.
  1021. :min-duration Mark clocking chunks that are shorter that this.
  1022. This is a time string like \"HH:MM\", or the number
  1023. of minutes as an integer.
  1024. :max-gap Mark gaps between clocking chunks that are longer than
  1025. this duration. A number of minutes, or a string
  1026. like \"HH:MM\".
  1027. :gap-ok-around List of times during the day which are usually not working
  1028. times. When a gap is detected, but the gap contains any
  1029. of these times, the gap is *not* reported. For example,
  1030. if this is (\"4:00\" \"13:00\") then gaps that contain
  1031. 4:00 in the morning (i.e. the night) and 13:00
  1032. (i.e. a typical lunch time) do not cause a warning.
  1033. You should have at least one time during the night in this
  1034. list, or otherwise the first task each morning will trigger
  1035. a warning because it follows a long gap.
  1036. Furthermore, the following properties can be used to define faces for
  1037. issue display.
  1038. :default-face the default face, if the specific face is undefined
  1039. :overlap-face face for overlapping clocks
  1040. :gap-face face for gaps between clocks
  1041. :no-end-time-face face for incomplete clocks
  1042. :long-face face for clock intervals that are too long
  1043. :short-face face for clock intervals that are too short"
  1044. :group 'org-agenda-daily/weekly
  1045. :group 'org-clock
  1046. :type 'plist)
  1047. (defcustom org-agenda-log-mode-add-notes t
  1048. "Non-nil means add first line of notes to log entries in agenda views.
  1049. If a log item like a state change or a clock entry is associated with
  1050. notes, the first line of these notes will be added to the entry in the
  1051. agenda display."
  1052. :group 'org-agenda-daily/weekly
  1053. :type 'boolean)
  1054. (defcustom org-agenda-start-with-log-mode nil
  1055. "The initial value of log-mode in a newly created agenda window."
  1056. :group 'org-agenda-startup
  1057. :group 'org-agenda-daily/weekly
  1058. :type 'boolean)
  1059. (defcustom org-agenda-start-with-clockreport-mode nil
  1060. "The initial value of clockreport-mode in a newly created agenda window."
  1061. :group 'org-agenda-startup
  1062. :group 'org-agenda-daily/weekly
  1063. :type 'boolean)
  1064. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1065. "Property list with parameters for the clocktable in clockreport mode.
  1066. This is the display mode that shows a clock table in the daily/weekly
  1067. agenda, the properties for this dynamic block can be set here.
  1068. The usual clocktable parameters are allowed here, but you cannot set
  1069. the properties :name, :tstart, :tend, :block, and :scope - these will
  1070. be overwritten to make sure the content accurately reflects the
  1071. current display in the agenda."
  1072. :group 'org-agenda-daily/weekly
  1073. :type 'plist)
  1074. (defcustom org-agenda-search-view-always-boolean nil
  1075. "Non-nil means the search string is interpreted as individual parts.
  1076. The search string for search view can either be interpreted as a phrase,
  1077. or as a list of snippets that define a boolean search for a number of
  1078. strings.
  1079. When this is non-nil, the string will be split on whitespace, and each
  1080. snippet will be searched individually, and all must match in order to
  1081. select an entry. A snippet is then a single string of non-white
  1082. characters, or a string in double quotes, or a regexp in {} braces.
  1083. If a snippet is preceded by \"-\", the snippet must *not* match.
  1084. \"+\" is syntactic sugar for positive selection. Each snippet may
  1085. be found as a full word or a partial word, but see the variable
  1086. `org-agenda-search-view-force-full-words'.
  1087. When this is nil, search will look for the entire search phrase as one,
  1088. with each space character matching any amount of whitespace, including
  1089. line breaks.
  1090. Even when this is nil, you can still switch to Boolean search dynamically
  1091. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1092. is a regexp marked with braces like \"{abc}\", this will also switch to
  1093. boolean search."
  1094. :group 'org-agenda-search-view
  1095. :type 'boolean)
  1096. (if (fboundp 'defvaralias)
  1097. (defvaralias 'org-agenda-search-view-search-words-only
  1098. 'org-agenda-search-view-always-boolean))
  1099. (defcustom org-agenda-search-view-force-full-words nil
  1100. "Non-nil means, search words must be matches as complete words.
  1101. When nil, they may also match part of a word."
  1102. :group 'org-agenda-search-view
  1103. :type 'boolean)
  1104. (defgroup org-agenda-time-grid nil
  1105. "Options concerning the time grid in the Org-mode Agenda."
  1106. :tag "Org Agenda Time Grid"
  1107. :group 'org-agenda)
  1108. (defcustom org-agenda-search-headline-for-time t
  1109. "Non-nil means search headline for a time-of-day.
  1110. If the headline contains a time-of-day in one format or another, it will
  1111. be used to sort the entry into the time sequence of items for a day.
  1112. Some people have time stamps in the headline that refer to the creation
  1113. time or so, and then this produces an unwanted side effect. If this is
  1114. the case for your, use this variable to turn off searching the headline
  1115. for a time."
  1116. :group 'org-agenda-time-grid
  1117. :type 'boolean)
  1118. (defcustom org-agenda-use-time-grid t
  1119. "Non-nil means show a time grid in the agenda schedule.
  1120. A time grid is a set of lines for specific times (like every two hours between
  1121. 8:00 and 20:00). The items scheduled for a day at specific times are
  1122. sorted in between these lines.
  1123. For details about when the grid will be shown, and what it will look like, see
  1124. the variable `org-agenda-time-grid'."
  1125. :group 'org-agenda-time-grid
  1126. :type 'boolean)
  1127. (defcustom org-agenda-time-grid
  1128. '((daily today require-timed)
  1129. "----------------"
  1130. (800 1000 1200 1400 1600 1800 2000))
  1131. "The settings for time grid for agenda display.
  1132. This is a list of three items. The first item is again a list. It contains
  1133. symbols specifying conditions when the grid should be displayed:
  1134. daily if the agenda shows a single day
  1135. weekly if the agenda shows an entire week
  1136. today show grid on current date, independent of daily/weekly display
  1137. require-timed show grid only if at least one item has a time specification
  1138. The second item is a string which will be placed behind the grid time.
  1139. The third item is a list of integers, indicating the times that should have
  1140. a grid line."
  1141. :group 'org-agenda-time-grid
  1142. :type
  1143. '(list
  1144. (set :greedy t :tag "Grid Display Options"
  1145. (const :tag "Show grid in single day agenda display" daily)
  1146. (const :tag "Show grid in weekly agenda display" weekly)
  1147. (const :tag "Always show grid for today" today)
  1148. (const :tag "Show grid only if any timed entries are present"
  1149. require-timed)
  1150. (const :tag "Skip grid times already present in an entry"
  1151. remove-match))
  1152. (string :tag "Grid String")
  1153. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1154. (defcustom org-agenda-show-current-time-in-grid t
  1155. "Non-nil means show the current time in the time grid."
  1156. :group 'org-agenda-time-grid
  1157. :type 'boolean)
  1158. (defcustom org-agenda-current-time-string
  1159. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1160. "The string for the current time marker in the agenda."
  1161. :group 'org-agenda-time-grid
  1162. :type 'string)
  1163. (defgroup org-agenda-sorting nil
  1164. "Options concerning sorting in the Org-mode Agenda."
  1165. :tag "Org Agenda Sorting"
  1166. :group 'org-agenda)
  1167. (defcustom org-agenda-sorting-strategy
  1168. '((agenda habit-down time-up priority-down category-keep)
  1169. (todo priority-down category-keep)
  1170. (tags priority-down category-keep)
  1171. (search category-keep))
  1172. "Sorting structure for the agenda items of a single day.
  1173. This is a list of symbols which will be used in sequence to determine
  1174. if an entry should be listed before another entry. The following
  1175. symbols are recognized:
  1176. time-up Put entries with time-of-day indications first, early first
  1177. time-down Put entries with time-of-day indications first, late first
  1178. category-keep Keep the default order of categories, corresponding to the
  1179. sequence in `org-agenda-files'.
  1180. category-up Sort alphabetically by category, A-Z.
  1181. category-down Sort alphabetically by category, Z-A.
  1182. tag-up Sort alphabetically by last tag, A-Z.
  1183. tag-down Sort alphabetically by last tag, Z-A.
  1184. priority-up Sort numerically by priority, high priority last.
  1185. priority-down Sort numerically by priority, high priority first.
  1186. todo-state-up Sort by todo state, tasks that are done last.
  1187. todo-state-down Sort by todo state, tasks that are done first.
  1188. effort-up Sort numerically by estimated effort, high effort last.
  1189. effort-down Sort numerically by estimated effort, high effort first.
  1190. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1191. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1192. habit-up Put entries that are habits first
  1193. habit-down Put entries that are habits last
  1194. alpha-up Sort headlines alphabetically
  1195. alpha-down Sort headlines alphabetically, reversed
  1196. The different possibilities will be tried in sequence, and testing stops
  1197. if one comparison returns a \"not-equal\". For example, the default
  1198. '(time-up category-keep priority-down)
  1199. means: Pull out all entries having a specified time of day and sort them,
  1200. in order to make a time schedule for the current day the first thing in the
  1201. agenda listing for the day. Of the entries without a time indication, keep
  1202. the grouped in categories, don't sort the categories, but keep them in
  1203. the sequence given in `org-agenda-files'. Within each category sort by
  1204. priority.
  1205. Leaving out `category-keep' would mean that items will be sorted across
  1206. categories by priority.
  1207. Instead of a single list, this can also be a set of list for specific
  1208. contents, with a context symbol in the car of the list, any of
  1209. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1210. Custom commands can bind this variable in the options section."
  1211. :group 'org-agenda-sorting
  1212. :type `(choice
  1213. (repeat :tag "General" ,org-sorting-choice)
  1214. (list :tag "Individually"
  1215. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1216. (repeat ,org-sorting-choice))
  1217. (cons (const :tag "Strategy for TODO lists" todo)
  1218. (repeat ,org-sorting-choice))
  1219. (cons (const :tag "Strategy for Tags matches" tags)
  1220. (repeat ,org-sorting-choice))
  1221. (cons (const :tag "Strategy for search matches" search)
  1222. (repeat ,org-sorting-choice)))))
  1223. (defcustom org-agenda-cmp-user-defined nil
  1224. "A function to define the comparison `user-defined'.
  1225. This function must receive two arguments, agenda entry a and b.
  1226. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1227. the user comparison, return nil.
  1228. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1229. part of an agenda sorting strategy."
  1230. :group 'org-agenda-sorting
  1231. :type 'symbol)
  1232. (defcustom org-sort-agenda-notime-is-late t
  1233. "Non-nil means items without time are considered late.
  1234. This is only relevant for sorting. When t, items which have no explicit
  1235. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1236. do have a time. When nil, the default time is before 0:00. You can use this
  1237. option to decide if the schedule for today should come before or after timeless
  1238. agenda entries."
  1239. :group 'org-agenda-sorting
  1240. :type 'boolean)
  1241. (defcustom org-sort-agenda-noeffort-is-high t
  1242. "Non-nil means items without effort estimate are sorted as high effort.
  1243. This also applies when filtering an agenda view with respect to the
  1244. < or > effort operator. Then, tasks with no effort defined will be treated
  1245. as tasks with high effort.
  1246. When nil, such items are sorted as 0 minutes effort."
  1247. :group 'org-agenda-sorting
  1248. :type 'boolean)
  1249. (defgroup org-agenda-line-format nil
  1250. "Options concerning the entry prefix in the Org-mode agenda display."
  1251. :tag "Org Agenda Line Format"
  1252. :group 'org-agenda)
  1253. (defcustom org-agenda-prefix-format
  1254. '((agenda . " %i %-12:c%?-12t% s")
  1255. (timeline . " % s")
  1256. (todo . " %i %-12:c")
  1257. (tags . " %i %-12:c")
  1258. (search . " %i %-12:c"))
  1259. "Format specifications for the prefix of items in the agenda views.
  1260. An alist with five entries, each for the different agenda types. The
  1261. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1262. The values are format strings.
  1263. This format works similar to a printf format, with the following meaning:
  1264. %c the category of the item, \"Diary\" for entries from the diary,
  1265. or as given by the CATEGORY keyword or derived from the file name
  1266. %e the effort required by the item
  1267. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1268. %T the last tag of the item (ignore inherited tags, which come first)
  1269. %t the HH:MM time-of-day specification if one applies to the entry
  1270. %s Scheduling/Deadline information, a short string
  1271. %(expression) Eval EXPRESSION and replace the control string
  1272. by the result
  1273. All specifiers work basically like the standard `%s' of printf, but may
  1274. contain two additional characters: a question mark just after the `%'
  1275. and a whitespace/punctuation character just before the final letter.
  1276. If the first character after `%' is a question mark, the entire field
  1277. will only be included if the corresponding value applies to the current
  1278. entry. This is useful for fields which should have fixed width when
  1279. present, but zero width when absent. For example, \"%?-12t\" will
  1280. result in a 12 character time field if a time of the day is specified,
  1281. but will completely disappear in entries which do not contain a time.
  1282. If there is punctuation or whitespace character just before the final
  1283. format letter, this character will be appended to the field value if
  1284. the value is not empty. For example, the format \"%-12:c\" leads to
  1285. \"Diary: \" if the category is \"Diary\". If the category were be
  1286. empty, no additional colon would be inserted.
  1287. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1288. which means:
  1289. - Indent the line with two space characters
  1290. - Give the category a 12 chars wide field, padded with whitespace on
  1291. the right (because of `-'). Append a colon if there is a category
  1292. (because of `:').
  1293. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1294. time, don't put in an empty field, just skip it (because of '?').
  1295. - Finally, put the scheduling information.
  1296. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1297. `org-agenda-remove-tags'.
  1298. Custom commands can set this variable in the options section."
  1299. :type '(choice
  1300. (string :tag "General format")
  1301. (list :greedy t :tag "View dependent"
  1302. (cons (const agenda) (string :tag "Format"))
  1303. (cons (const timeline) (string :tag "Format"))
  1304. (cons (const todo) (string :tag "Format"))
  1305. (cons (const tags) (string :tag "Format"))
  1306. (cons (const search) (string :tag "Format"))))
  1307. :group 'org-agenda-line-format)
  1308. (defvar org-prefix-format-compiled nil
  1309. "The compiled version of the most recently used prefix format.
  1310. See the variable `org-agenda-prefix-format'.")
  1311. (defcustom org-agenda-todo-keyword-format "%-1s"
  1312. "Format for the TODO keyword in agenda lines.
  1313. Set this to something like \"%-12s\" if you want all TODO keywords
  1314. to occupy a fixed space in the agenda display."
  1315. :group 'org-agenda-line-format
  1316. :type 'string)
  1317. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1318. "Text preceding timerange entries in the agenda view.
  1319. This is a list with two strings. The first applies when the range
  1320. is entirely on one day. The second applies if the range spans several days.
  1321. The strings may have two \"%d\" format specifiers which will be filled
  1322. with the sequence number of the days, and the total number of days in the
  1323. range, respectively."
  1324. :group 'org-agenda-line-format
  1325. :type '(list
  1326. (string :tag "Deadline today ")
  1327. (choice :tag "Deadline relative"
  1328. (string :tag "Format string")
  1329. (function))))
  1330. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1331. "Text preceding scheduled items in the agenda view.
  1332. This is a list with two strings. The first applies when the item is
  1333. scheduled on the current day. The second applies when it has been scheduled
  1334. previously, it may contain a %d indicating that this is the nth time that
  1335. this item is scheduled, due to automatic rescheduling of unfinished items
  1336. for the following day. So this number is one larger than the number of days
  1337. that passed since this item was scheduled first."
  1338. :group 'org-agenda-line-format
  1339. :type '(list
  1340. (string :tag "Scheduled today ")
  1341. (string :tag "Scheduled previously")))
  1342. (defcustom org-agenda-inactive-leader "["
  1343. "Text preceding item pulled into the agenda by inactive time stamps.
  1344. These entries are added to the agenda when pressing \"[\"."
  1345. :group 'org-agenda-line-format
  1346. :type '(list
  1347. (string :tag "Scheduled today ")
  1348. (string :tag "Scheduled previously")))
  1349. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1350. "Text preceding deadline items in the agenda view.
  1351. This is a list with two strings. The first applies when the item has its
  1352. deadline on the current day. The second applies when it is in the past or
  1353. in the future, it may contain %d to capture how many days away the deadline
  1354. is (was)."
  1355. :group 'org-agenda-line-format
  1356. :type '(list
  1357. (string :tag "Deadline today ")
  1358. (choice :tag "Deadline relative"
  1359. (string :tag "Format string")
  1360. (function))))
  1361. (defcustom org-agenda-remove-times-when-in-prefix t
  1362. "Non-nil means remove duplicate time specifications in agenda items.
  1363. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1364. time-of-day specification in a headline or diary entry is extracted and
  1365. placed into the prefix. If this option is non-nil, the original specification
  1366. \(a timestamp or -range, or just a plain time(range) specification like
  1367. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1368. cluttered.
  1369. The option can be t or nil. It may also be the symbol `beg', indicating
  1370. that the time should only be removed when it is located at the beginning of
  1371. the headline/diary entry."
  1372. :group 'org-agenda-line-format
  1373. :type '(choice
  1374. (const :tag "Always" t)
  1375. (const :tag "Never" nil)
  1376. (const :tag "When at beginning of entry" beg)))
  1377. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1378. "Non-nil means remove time ranges specifications in agenda
  1379. items that span on several days."
  1380. :group 'org-agenda-line-format
  1381. :type 'boolean)
  1382. (defcustom org-agenda-default-appointment-duration nil
  1383. "Default duration for appointments that only have a starting time.
  1384. When nil, no duration is specified in such cases.
  1385. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1386. :group 'org-agenda-line-format
  1387. :type '(choice
  1388. (integer :tag "Minutes")
  1389. (const :tag "No default duration")))
  1390. (defcustom org-agenda-show-inherited-tags t
  1391. "Non-nil means show inherited tags in each agenda line."
  1392. :group 'org-agenda-line-format
  1393. :type 'boolean)
  1394. (defcustom org-agenda-hide-tags-regexp nil
  1395. "Regular expression used to filter away specific tags in agenda views.
  1396. This means that these tags will be present, but not be shown in the agenda
  1397. line. Secondary filtering will still work on the hidden tags.
  1398. Nil means don't hide any tags."
  1399. :group 'org-agenda-line-format
  1400. :type '(choice
  1401. (const :tag "Hide none" nil)
  1402. (string :tag "Regexp ")))
  1403. (defcustom org-agenda-remove-tags nil
  1404. "Non-nil means remove the tags from the headline copy in the agenda.
  1405. When this is the symbol `prefix', only remove tags when
  1406. `org-agenda-prefix-format' contains a `%T' specifier."
  1407. :group 'org-agenda-line-format
  1408. :type '(choice
  1409. (const :tag "Always" t)
  1410. (const :tag "Never" nil)
  1411. (const :tag "When prefix format contains %T" prefix)))
  1412. (if (fboundp 'defvaralias)
  1413. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1414. 'org-agenda-remove-tags))
  1415. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1416. "Shift tags in agenda items to this column.
  1417. If this number is positive, it specifies the column. If it is negative,
  1418. it means that the tags should be flushright to that column. For example,
  1419. -80 works well for a normal 80 character screen."
  1420. :group 'org-agenda-line-format
  1421. :type 'integer)
  1422. (if (fboundp 'defvaralias)
  1423. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1424. (defcustom org-agenda-fontify-priorities 'cookies
  1425. "Non-nil means highlight low and high priorities in agenda.
  1426. When t, the highest priority entries are bold, lowest priority italic.
  1427. However, settings in `org-priority-faces' will overrule these faces.
  1428. When this variable is the symbol `cookies', only fontify the
  1429. cookies, not the entire task.
  1430. This may also be an association list of priority faces, whose
  1431. keys are the character values of `org-highest-priority',
  1432. `org-default-priority', and `org-lowest-priority' (the default values
  1433. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1434. color as a string, or a list like `(:background \"Red\")'.
  1435. If it is a color, the variable `org-faces-easy-properties'
  1436. determines if it is a foreground or a background color."
  1437. :group 'org-agenda-line-format
  1438. :type '(choice
  1439. (const :tag "Never" nil)
  1440. (const :tag "Defaults" t)
  1441. (const :tag "Cookies only" cookies)
  1442. (repeat :tag "Specify"
  1443. (list (character :tag "Priority" :value ?A)
  1444. (choice :tag "Face "
  1445. (string :tag "Color")
  1446. (sexp :tag "Face"))))))
  1447. (defcustom org-agenda-day-face-function nil
  1448. "Function called to determine what face should be used to display a day.
  1449. The only argument passed to that function is the day. It should
  1450. returns a face, or nil if does not want to specify a face and let
  1451. the normal rules apply."
  1452. :group 'org-agenda-line-format
  1453. :type 'function)
  1454. (defcustom org-agenda-category-icon-alist nil
  1455. "Alist of category icon to be displayed in agenda views.
  1456. Each entry should have the following format:
  1457. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1458. Where CATEGORY-REGEXP is a regexp matching the categories where
  1459. the icon should be displayed.
  1460. FILE-OR-DATA either a file path or a string containing image data.
  1461. The other fields can be omitted safely if not needed:
  1462. TYPE indicates the image type.
  1463. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1464. image data.
  1465. PROPS are additional image attributes to assign to the image,
  1466. like, e.g. `:ascent center'.
  1467. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1468. If you want to set the display properties yourself, just put a
  1469. list as second element:
  1470. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1471. For example, to display a 16px horizontal space for Emacs
  1472. category, you can use:
  1473. (\"Emacs\" '(space . (:width (16))))"
  1474. :group 'org-agenda-line-format
  1475. :type '(alist :key-type (string :tag "Regexp matching category")
  1476. :value-type (choice (list :tag "Icon"
  1477. (string :tag "File or data")
  1478. (symbol :tag "Type")
  1479. (boolean :tag "Data?")
  1480. (repeat :tag "Extra image properties" :inline t symbol))
  1481. (list :tag "Display properties" sexp))))
  1482. (defgroup org-agenda-column-view nil
  1483. "Options concerning column view in the agenda."
  1484. :tag "Org Agenda Column View"
  1485. :group 'org-agenda)
  1486. (defcustom org-agenda-columns-show-summaries t
  1487. "Non-nil means show summaries for columns displayed in the agenda view."
  1488. :group 'org-agenda-column-view
  1489. :type 'boolean)
  1490. (defcustom org-agenda-columns-compute-summary-properties t
  1491. "Non-nil means recompute all summary properties before column view.
  1492. When column view in the agenda is listing properties that have a summary
  1493. operator, it can go to all relevant buffers and recompute the summaries
  1494. there. This can mean overhead for the agenda column view, but is necessary
  1495. to have thing up to date.
  1496. As a special case, a CLOCKSUM property also makes sure that the clock
  1497. computations are current."
  1498. :group 'org-agenda-column-view
  1499. :type 'boolean)
  1500. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1501. "Non-nil means the duration of an appointment will add to day effort.
  1502. The property to which appointment durations will be added is the one given
  1503. in the option `org-effort-property'. If an appointment does not have
  1504. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1505. is not set, an appointment without end time will not contribute to the time
  1506. estimate."
  1507. :group 'org-agenda-column-view
  1508. :type 'boolean)
  1509. (defcustom org-agenda-auto-exclude-function nil
  1510. "A function called with a tag to decide if it is filtered on '/ RET'.
  1511. The sole argument to the function, which is called once for each
  1512. possible tag, is a string giving the name of the tag. The
  1513. function should return either nil if the tag should be included
  1514. as normal, or \"-<TAG>\" to exclude the tag.
  1515. Note that for the purpose of tag filtering, only the lower-case version of
  1516. all tags will be considered, so that this function will only ever see
  1517. the lower-case version of all tags."
  1518. :group 'org-agenda
  1519. :type 'function)
  1520. (defcustom org-agenda-bulk-custom-functions nil
  1521. "Alist of characters and custom functions for bulk actions.
  1522. For example, this value makes those two functions available:
  1523. '((?R set-category)
  1524. (?C bulk-cut))
  1525. With selected entries in an agenda buffer, `B R' will call
  1526. the custom function `set-category' on the selected entries.
  1527. Note that functions in this alist don't need to be quoted."
  1528. :type 'alist
  1529. :group 'org-agenda)
  1530. (eval-when-compile
  1531. (require 'cl))
  1532. (require 'org)
  1533. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1534. "Execute BODY with point at location given by `org-hd-marker' property.
  1535. If STRING is non-nil, the text property will be fetched from position 0
  1536. in that string. If STRING is nil, it will be fetched from the beginning
  1537. of the current line."
  1538. (org-with-gensyms (marker)
  1539. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1540. 'org-hd-marker ,string)))
  1541. (with-current-buffer (marker-buffer ,marker)
  1542. (save-excursion
  1543. (goto-char ,marker)
  1544. ,@body)))))
  1545. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1546. (defun org-add-agenda-custom-command (entry)
  1547. "Replace or add a command in `org-agenda-custom-commands'.
  1548. This is mostly for hacking and trying a new command - once the command
  1549. works you probably want to add it to `org-agenda-custom-commands' for good."
  1550. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1551. (if ass
  1552. (setcdr ass (cdr entry))
  1553. (push entry org-agenda-custom-commands))))
  1554. ;;; Define the Org-agenda-mode
  1555. (defvar org-agenda-mode-map (make-sparse-keymap)
  1556. "Keymap for `org-agenda-mode'.")
  1557. (if (fboundp 'defvaralias)
  1558. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1559. (defvar org-agenda-menu) ; defined later in this file.
  1560. (defvar org-agenda-restrict) ; defined later in this file.
  1561. (defvar org-agenda-follow-mode nil)
  1562. (defvar org-agenda-entry-text-mode nil)
  1563. (defvar org-agenda-clockreport-mode nil)
  1564. (defvar org-agenda-show-log nil)
  1565. (defvar org-agenda-redo-command nil)
  1566. (defvar org-agenda-query-string nil)
  1567. (defvar org-agenda-mode-hook nil
  1568. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1569. (defvar org-agenda-type nil)
  1570. (defvar org-agenda-force-single-file nil)
  1571. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1572. (defun org-agenda-mode ()
  1573. "Mode for time-sorted view on action items in Org-mode files.
  1574. The following commands are available:
  1575. \\{org-agenda-mode-map}"
  1576. (interactive)
  1577. (kill-all-local-variables)
  1578. (setq org-agenda-undo-list nil
  1579. org-agenda-pending-undo-list nil
  1580. org-agenda-bulk-marked-entries nil)
  1581. (setq major-mode 'org-agenda-mode)
  1582. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1583. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1584. (setq mode-name "Org-Agenda")
  1585. (use-local-map org-agenda-mode-map)
  1586. (easy-menu-add org-agenda-menu)
  1587. (if org-startup-truncated (setq truncate-lines t))
  1588. (org-set-local 'line-move-visual nil)
  1589. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1590. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1591. ;; Make sure properties are removed when copying text
  1592. (when (boundp 'buffer-substring-filters)
  1593. (org-set-local 'buffer-substring-filters
  1594. (cons (lambda (x)
  1595. (set-text-properties 0 (length x) nil x) x)
  1596. buffer-substring-filters)))
  1597. (unless org-agenda-keep-modes
  1598. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1599. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1600. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1601. org-agenda-show-log org-agenda-start-with-log-mode))
  1602. (easy-menu-change
  1603. '("Agenda") "Agenda Files"
  1604. (append
  1605. (list
  1606. (vector
  1607. (if (get 'org-agenda-files 'org-restrict)
  1608. "Restricted to single file"
  1609. "Edit File List")
  1610. '(org-edit-agenda-file-list)
  1611. (not (get 'org-agenda-files 'org-restrict)))
  1612. "--")
  1613. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1614. (org-agenda-set-mode-name)
  1615. (apply
  1616. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1617. (list 'org-agenda-mode-hook)))
  1618. (substitute-key-definition 'undo 'org-agenda-undo
  1619. org-agenda-mode-map global-map)
  1620. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1621. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1622. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1623. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1624. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1625. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1626. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1627. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1628. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1629. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1630. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1631. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1632. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1633. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1634. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1635. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1636. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1637. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1638. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1639. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1640. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1641. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1642. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1643. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1644. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1645. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1646. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1647. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1648. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1649. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1650. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1651. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1652. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1653. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1654. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1655. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1656. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1657. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1658. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1659. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1660. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1661. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1662. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1663. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1664. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1665. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1666. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1667. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1668. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1669. (while l (org-defkey org-agenda-mode-map
  1670. (int-to-string (pop l)) 'digit-argument)))
  1671. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1672. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1673. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1674. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1675. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1676. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1677. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1678. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1679. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1680. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1681. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1682. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1683. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1684. 'org-clock-modify-effort-estimate)
  1685. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1686. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1687. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1688. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1689. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1690. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1691. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1692. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1693. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1694. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1695. (substitute-key-definition 'next-line 'org-agenda-next-line
  1696. org-agenda-mode-map global-map)
  1697. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1698. org-agenda-mode-map global-map)
  1699. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1700. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1701. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1702. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1703. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1704. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1705. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1706. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1707. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1708. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1709. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1710. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1711. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1712. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1713. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1714. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1715. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1716. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1717. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1718. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1719. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1720. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1721. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1722. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1723. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1724. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1725. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1726. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1727. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1728. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1729. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1730. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1731. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1732. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1733. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1734. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1735. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1736. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1737. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1738. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1739. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1740. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1741. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1742. (when org-agenda-mouse-1-follows-link
  1743. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1744. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1745. '("Agenda"
  1746. ("Agenda Files")
  1747. "--"
  1748. ("Agenda Dates"
  1749. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1750. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1751. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1752. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1753. "--"
  1754. ("View"
  1755. ["Day View" org-agenda-day-view
  1756. :active (org-agenda-check-type nil 'agenda)
  1757. :style radio :selected (eq org-agenda-current-span 'day)
  1758. :keys "v d (or just d)"]
  1759. ["Week View" org-agenda-week-view
  1760. :active (org-agenda-check-type nil 'agenda)
  1761. :style radio :selected (eq org-agenda-current-span 'week)
  1762. :keys "v w (or just w)"]
  1763. ["Month View" org-agenda-month-view
  1764. :active (org-agenda-check-type nil 'agenda)
  1765. :style radio :selected (eq org-agenda-current-span 'month)
  1766. :keys "v m"]
  1767. ["Year View" org-agenda-year-view
  1768. :active (org-agenda-check-type nil 'agenda)
  1769. :style radio :selected (eq org-agenda-current-span 'year)
  1770. :keys "v y"]
  1771. "--"
  1772. ["Include Diary" org-agenda-toggle-diary
  1773. :style toggle :selected org-agenda-include-diary
  1774. :active (org-agenda-check-type nil 'agenda)]
  1775. ["Include Deadlines" org-agenda-toggle-deadlines
  1776. :style toggle :selected org-agenda-include-deadlines
  1777. :active (org-agenda-check-type nil 'agenda)]
  1778. ["Use Time Grid" org-agenda-toggle-time-grid
  1779. :style toggle :selected org-agenda-use-time-grid
  1780. :active (org-agenda-check-type nil 'agenda)]
  1781. "--"
  1782. ["Show clock report" org-agenda-clockreport-mode
  1783. :style toggle :selected org-agenda-clockreport-mode
  1784. :active (org-agenda-check-type nil 'agenda)]
  1785. ["Show some entry text" org-agenda-entry-text-mode
  1786. :style toggle :selected org-agenda-entry-text-mode
  1787. :active t]
  1788. "--"
  1789. ["Show Logbook entries" org-agenda-log-mode
  1790. :style toggle :selected org-agenda-show-log
  1791. :active (org-agenda-check-type nil 'agenda 'timeline)
  1792. :keys "v l (or just l)"]
  1793. ["Include archived trees" org-agenda-archives-mode
  1794. :style toggle :selected org-agenda-archives-mode :active t
  1795. :keys "v a"]
  1796. ["Include archive files" (org-agenda-archives-mode t)
  1797. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1798. :keys "v A"]
  1799. "--"
  1800. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1801. ["Write view to file" org-agenda-write t]
  1802. ["Rebuild buffer" org-agenda-redo t]
  1803. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1804. "--"
  1805. ["Show original entry" org-agenda-show t]
  1806. ["Go To (other window)" org-agenda-goto t]
  1807. ["Go To (this window)" org-agenda-switch-to t]
  1808. ["Follow Mode" org-agenda-follow-mode
  1809. :style toggle :selected org-agenda-follow-mode :active t]
  1810. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1811. "--"
  1812. ("TODO"
  1813. ["Cycle TODO" org-agenda-todo t]
  1814. ["Next TODO set" org-agenda-todo-nextset t]
  1815. ["Previous TODO set" org-agenda-todo-previousset t]
  1816. ["Add note" org-agenda-add-note t])
  1817. ("Archive/Refile/Delete"
  1818. ["Archive default" org-agenda-archive-default t]
  1819. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1820. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1821. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1822. ["Archive subtree" org-agenda-archive t]
  1823. "--"
  1824. ["Refile" org-agenda-refile t]
  1825. "--"
  1826. ["Delete subtree" org-agenda-kill t])
  1827. ("Bulk action"
  1828. ["Mark entry" org-agenda-bulk-mark t]
  1829. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1830. ["Unmark entry" org-agenda-bulk-unmark t]
  1831. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1832. ["Act on all marked" org-agenda-bulk-action t]
  1833. "--"
  1834. ("Tags and Properties"
  1835. ["Show all Tags" org-agenda-show-tags t]
  1836. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1837. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1838. "--"
  1839. ["Column View" org-columns t])
  1840. ("Deadline/Schedule"
  1841. ["Schedule" org-agenda-schedule t]
  1842. ["Set Deadline" org-agenda-deadline t]
  1843. "--"
  1844. ["Mark item" org-agenda-action :active t :keys "k m"]
  1845. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1846. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1847. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1848. "--"
  1849. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1850. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1851. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1852. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1853. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1854. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1855. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1856. ("Clock and Effort"
  1857. ["Clock in" org-agenda-clock-in t]
  1858. ["Clock out" org-agenda-clock-out t]
  1859. ["Clock cancel" org-agenda-clock-cancel t]
  1860. ["Goto running clock" org-clock-goto t]
  1861. "--"
  1862. ["Set Effort" org-agenda-set-effort t]
  1863. ["Change clocked effort" org-clock-modify-effort-estimate
  1864. (org-clock-is-active)])
  1865. ("Priority"
  1866. ["Set Priority" org-agenda-priority t]
  1867. ["Increase Priority" org-agenda-priority-up t]
  1868. ["Decrease Priority" org-agenda-priority-down t]
  1869. ["Show Priority" org-agenda-show-priority t])
  1870. ("Calendar/Diary"
  1871. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1872. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1873. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1874. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1875. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1876. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1877. "--"
  1878. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1879. "--"
  1880. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1881. "--"
  1882. ("MobileOrg"
  1883. ["Push Files and Views" org-mobile-push t]
  1884. ["Get Captured and Flagged" org-mobile-pull t]
  1885. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1886. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1887. "--"
  1888. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1889. "--"
  1890. ["Quit" org-agenda-quit t]
  1891. ["Exit and Release Buffers" org-agenda-exit t]
  1892. ))
  1893. ;;; Agenda undo
  1894. (defvar org-agenda-allow-remote-undo t
  1895. "Non-nil means allow remote undo from the agenda buffer.")
  1896. (defvar org-agenda-undo-list nil
  1897. "List of undoable operations in the agenda since last refresh.")
  1898. (defvar org-agenda-undo-has-started-in nil
  1899. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1900. (defvar org-agenda-pending-undo-list nil
  1901. "In a series of undo commands, this is the list of remaining undo items.")
  1902. (defun org-agenda-undo ()
  1903. "Undo a remote editing step in the agenda.
  1904. This undoes changes both in the agenda buffer and in the remote buffer
  1905. that have been changed along."
  1906. (interactive)
  1907. (or org-agenda-allow-remote-undo
  1908. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1909. (if (not (eq this-command last-command))
  1910. (setq org-agenda-undo-has-started-in nil
  1911. org-agenda-pending-undo-list org-agenda-undo-list))
  1912. (if (not org-agenda-pending-undo-list)
  1913. (error "No further undo information"))
  1914. (let* ((entry (pop org-agenda-pending-undo-list))
  1915. buf line cmd rembuf)
  1916. (setq cmd (pop entry) line (pop entry))
  1917. (setq rembuf (nth 2 entry))
  1918. (org-with-remote-undo rembuf
  1919. (while (bufferp (setq buf (pop entry)))
  1920. (if (pop entry)
  1921. (with-current-buffer buf
  1922. (let ((last-undo-buffer buf)
  1923. (inhibit-read-only t))
  1924. (unless (memq buf org-agenda-undo-has-started-in)
  1925. (push buf org-agenda-undo-has-started-in)
  1926. (make-local-variable 'pending-undo-list)
  1927. (undo-start))
  1928. (while (and pending-undo-list
  1929. (listp pending-undo-list)
  1930. (not (car pending-undo-list)))
  1931. (pop pending-undo-list))
  1932. (undo-more 1))))))
  1933. (org-goto-line line)
  1934. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1935. (defun org-verify-change-for-undo (l1 l2)
  1936. "Verify that a real change occurred between the undo lists L1 and L2."
  1937. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1938. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1939. (not (eq l1 l2)))
  1940. ;;; Agenda dispatch
  1941. (defvar org-agenda-restrict nil)
  1942. (defvar org-agenda-restrict-begin (make-marker))
  1943. (defvar org-agenda-restrict-end (make-marker))
  1944. (defvar org-agenda-last-dispatch-buffer nil)
  1945. (defvar org-agenda-overriding-restriction nil)
  1946. ;;;###autoload
  1947. (defun org-agenda (&optional arg keys restriction)
  1948. "Dispatch agenda commands to collect entries to the agenda buffer.
  1949. Prompts for a command to execute. Any prefix arg will be passed
  1950. on to the selected command. The default selections are:
  1951. a Call `org-agenda-list' to display the agenda for current day or week.
  1952. t Call `org-todo-list' to display the global todo list.
  1953. T Call `org-todo-list' to display the global todo list, select only
  1954. entries with a specific TODO keyword (the user gets a prompt).
  1955. m Call `org-tags-view' to display headlines with tags matching
  1956. a condition (the user is prompted for the condition).
  1957. M Like `m', but select only TODO entries, no ordinary headlines.
  1958. L Create a timeline for the current buffer.
  1959. e Export views to associated files.
  1960. s Search entries for keywords.
  1961. / Multi occur across all agenda files and also files listed
  1962. in `org-agenda-text-search-extra-files'.
  1963. < Restrict agenda commands to buffer, subtree, or region.
  1964. Press several times to get the desired effect.
  1965. > Remove a previous restriction.
  1966. # List \"stuck\" projects.
  1967. ! Configure what \"stuck\" means.
  1968. C Configure custom agenda commands.
  1969. More commands can be added by configuring the variable
  1970. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1971. searches can be pre-defined in this way.
  1972. If the current buffer is in Org-mode and visiting a file, you can also
  1973. first press `<' once to indicate that the agenda should be temporarily
  1974. \(until the next use of \\[org-agenda]) restricted to the current file.
  1975. Pressing `<' twice means to restrict to the current subtree or region
  1976. \(if active)."
  1977. (interactive "P")
  1978. (catch 'exit
  1979. (let* ((prefix-descriptions nil)
  1980. (org-agenda-window-setup (if (equal (buffer-name)
  1981. org-agenda-buffer-name)
  1982. 'current-window
  1983. org-agenda-window-setup))
  1984. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1985. (org-agenda-custom-commands
  1986. ;; normalize different versions
  1987. (delq nil
  1988. (mapcar
  1989. (lambda (x)
  1990. (cond ((stringp (cdr x))
  1991. (push x prefix-descriptions)
  1992. nil)
  1993. ((stringp (nth 1 x)) x)
  1994. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1995. (t (cons (car x) (cons "" (cdr x))))))
  1996. org-agenda-custom-commands)))
  1997. (buf (current-buffer))
  1998. (bfn (buffer-file-name (buffer-base-buffer)))
  1999. entry key type match lprops ans)
  2000. ;; Turn off restriction unless there is an overriding one,
  2001. (unless org-agenda-overriding-restriction
  2002. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2003. ;; There is a request to keep the file list in place
  2004. (put 'org-agenda-files 'org-restrict nil))
  2005. (setq org-agenda-restrict nil)
  2006. (move-marker org-agenda-restrict-begin nil)
  2007. (move-marker org-agenda-restrict-end nil))
  2008. ;; Delete old local properties
  2009. (put 'org-agenda-redo-command 'org-lprops nil)
  2010. ;; Delete previously set last-arguments
  2011. (put 'org-agenda-redo-command 'last-args nil)
  2012. ;; Remember where this call originated
  2013. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2014. (unless keys
  2015. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2016. keys (car ans)
  2017. restriction (cdr ans)))
  2018. ;; Establish the restriction, if any
  2019. (when (and (not org-agenda-overriding-restriction) restriction)
  2020. (put 'org-agenda-files 'org-restrict (list bfn))
  2021. (cond
  2022. ((eq restriction 'region)
  2023. (setq org-agenda-restrict t)
  2024. (move-marker org-agenda-restrict-begin (region-beginning))
  2025. (move-marker org-agenda-restrict-end (region-end)))
  2026. ((eq restriction 'subtree)
  2027. (save-excursion
  2028. (setq org-agenda-restrict t)
  2029. (org-back-to-heading t)
  2030. (move-marker org-agenda-restrict-begin (point))
  2031. (move-marker org-agenda-restrict-end
  2032. (progn (org-end-of-subtree t)))))))
  2033. ;; For example the todo list should not need it (but does...)
  2034. (cond
  2035. ((setq entry (assoc keys org-agenda-custom-commands))
  2036. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2037. (progn
  2038. (setq type (nth 2 entry) match (eval (nth 3 entry))
  2039. lprops (nth 4 entry))
  2040. (put 'org-agenda-redo-command 'org-lprops lprops)
  2041. (cond
  2042. ((eq type 'agenda)
  2043. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2044. ((eq type 'alltodo)
  2045. (org-let lprops '(org-todo-list current-prefix-arg)))
  2046. ((eq type 'search)
  2047. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  2048. ((eq type 'stuck)
  2049. (org-let lprops '(org-agenda-list-stuck-projects
  2050. current-prefix-arg)))
  2051. ((eq type 'tags)
  2052. (org-let lprops '(org-tags-view current-prefix-arg match)))
  2053. ((eq type 'tags-todo)
  2054. (org-let lprops '(org-tags-view '(4) match)))
  2055. ((eq type 'todo)
  2056. (org-let lprops '(org-todo-list match)))
  2057. ((eq type 'tags-tree)
  2058. (org-check-for-org-mode)
  2059. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  2060. ((eq type 'todo-tree)
  2061. (org-check-for-org-mode)
  2062. (org-let lprops
  2063. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2064. (regexp-quote match) "\\>"))))
  2065. ((eq type 'occur-tree)
  2066. (org-check-for-org-mode)
  2067. (org-let lprops '(org-occur match)))
  2068. ((functionp type)
  2069. (org-let lprops '(funcall type match)))
  2070. ((fboundp type)
  2071. (org-let lprops '(funcall type match)))
  2072. (t (error "Invalid custom agenda command type %s" type))))
  2073. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2074. ((equal keys "C")
  2075. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2076. (customize-variable 'org-agenda-custom-commands))
  2077. ((equal keys "a") (call-interactively 'org-agenda-list))
  2078. ((equal keys "s") (call-interactively 'org-search-view))
  2079. ((equal keys "t") (call-interactively 'org-todo-list))
  2080. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2081. ((equal keys "m") (call-interactively 'org-tags-view))
  2082. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2083. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2084. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2085. (org-add-hook
  2086. 'post-command-hook
  2087. (lambda ()
  2088. (unless (current-message)
  2089. (let* ((m (org-agenda-get-any-marker))
  2090. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2091. (when note
  2092. (message (concat
  2093. "FLAGGING-NOTE ([?] for more info): "
  2094. (org-add-props
  2095. (replace-regexp-in-string
  2096. "\\\\n" "//"
  2097. (copy-sequence note))
  2098. nil 'face 'org-warning)))))))
  2099. t t))
  2100. ((equal keys "L")
  2101. (unless (eq major-mode 'org-mode)
  2102. (error "This is not an Org-mode file"))
  2103. (unless restriction
  2104. (put 'org-agenda-files 'org-restrict (list bfn))
  2105. (org-call-with-arg 'org-timeline arg)))
  2106. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2107. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2108. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2109. (t (error "Invalid agenda key"))))))
  2110. (defun org-agenda-append-agenda ()
  2111. "Append another agenda view to the current one.
  2112. This function allows interactive building of block agendas.
  2113. Agenda views are separated by `org-agenda-block-separator'."
  2114. (interactive)
  2115. (unless (string= (buffer-name) org-agenda-buffer-name)
  2116. (error "Can only append from within agenda buffer"))
  2117. (let ((org-agenda-multi t))
  2118. (org-agenda)
  2119. (widen)))
  2120. (defun org-agenda-normalize-custom-commands (cmds)
  2121. (delq nil
  2122. (mapcar
  2123. (lambda (x)
  2124. (cond ((stringp (cdr x)) nil)
  2125. ((stringp (nth 1 x)) x)
  2126. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2127. (t (cons (car x) (cons "" (cdr x))))))
  2128. cmds)))
  2129. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2130. "The user interface for selecting an agenda command."
  2131. (catch 'exit
  2132. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2133. (restrict-ok (and bfn (eq major-mode 'org-mode)))
  2134. (region-p (org-region-active-p))
  2135. (custom org-agenda-custom-commands)
  2136. (selstring "")
  2137. restriction second-time
  2138. c entry key type match prefixes rmheader header-end custom1 desc
  2139. line lines left right n n1)
  2140. (save-window-excursion
  2141. (delete-other-windows)
  2142. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2143. (erase-buffer)
  2144. (insert (eval-when-compile
  2145. (let ((header
  2146. "
  2147. Press key for an agenda command: < Buffer, subtree/region restriction
  2148. -------------------------------- > Remove restriction
  2149. a Agenda for current week or day e Export agenda views
  2150. t List of all TODO entries T Entries with special TODO kwd
  2151. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2152. L Timeline for current buffer # List stuck projects (!=configure)
  2153. s Search for keywords C Configure custom agenda commands
  2154. / Multi-occur ? Find :FLAGGED: entries
  2155. ")
  2156. (start 0))
  2157. (while (string-match
  2158. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2159. header start)
  2160. (setq start (match-end 0))
  2161. (add-text-properties (match-beginning 2) (match-end 2)
  2162. '(face bold) header))
  2163. header)))
  2164. (setq header-end (move-marker (make-marker) (point)))
  2165. (while t
  2166. (setq custom1 custom)
  2167. (when (eq rmheader t)
  2168. (org-goto-line 1)
  2169. (re-search-forward ":" nil t)
  2170. (delete-region (match-end 0) (point-at-eol))
  2171. (forward-char 1)
  2172. (looking-at "-+")
  2173. (delete-region (match-end 0) (point-at-eol))
  2174. (move-marker header-end (match-end 0)))
  2175. (goto-char header-end)
  2176. (delete-region (point) (point-max))
  2177. ;; Produce all the lines that describe custom commands and prefixes
  2178. (setq lines nil)
  2179. (while (setq entry (pop custom1))
  2180. (setq key (car entry) desc (nth 1 entry)
  2181. type (nth 2 entry)
  2182. match (nth 3 entry))
  2183. (if (> (length key) 1)
  2184. (add-to-list 'prefixes (string-to-char key))
  2185. (setq line
  2186. (format
  2187. "%-4s%-14s"
  2188. (org-add-props (copy-sequence key)
  2189. '(face bold))
  2190. (cond
  2191. ((string-match "\\S-" desc) desc)
  2192. ((eq type 'agenda) "Agenda for current week or day")
  2193. ((eq type 'alltodo) "List of all TODO entries")
  2194. ((eq type 'search) "Word search")
  2195. ((eq type 'stuck) "List of stuck projects")
  2196. ((eq type 'todo) "TODO keyword")
  2197. ((eq type 'tags) "Tags query")
  2198. ((eq type 'tags-todo) "Tags (TODO)")
  2199. ((eq type 'tags-tree) "Tags tree")
  2200. ((eq type 'todo-tree) "TODO kwd tree")
  2201. ((eq type 'occur-tree) "Occur tree")
  2202. ((functionp type) (if (symbolp type)
  2203. (symbol-name type)
  2204. "Lambda expression"))
  2205. (t "???"))))
  2206. (if org-agenda-menu-show-matcher
  2207. (setq line
  2208. (concat line ": "
  2209. (cond
  2210. ((stringp match)
  2211. (setq match (copy-sequence match))
  2212. (org-add-props match nil 'face 'org-warning))
  2213. (match
  2214. (format "set of %d commands" (length match)))
  2215. (t ""))))
  2216. (if (org-string-nw-p match)
  2217. (add-text-properties
  2218. 0 (length line) (list 'help-echo
  2219. (concat "Matcher: "match)) line)))
  2220. (push line lines)))
  2221. (setq lines (nreverse lines))
  2222. (when prefixes
  2223. (mapc (lambda (x)
  2224. (push
  2225. (format "%s %s"
  2226. (org-add-props (char-to-string x)
  2227. nil 'face 'bold)
  2228. (or (cdr (assoc (concat selstring
  2229. (char-to-string x))
  2230. prefix-descriptions))
  2231. "Prefix key"))
  2232. lines))
  2233. prefixes))
  2234. ;; Check if we should display in two columns
  2235. (if org-agenda-menu-two-column
  2236. (progn
  2237. (setq n (length lines)
  2238. n1 (+ (/ n 2) (mod n 2))
  2239. right (nthcdr n1 lines)
  2240. left (copy-sequence lines))
  2241. (setcdr (nthcdr (1- n1) left) nil))
  2242. (setq left lines right nil))
  2243. (while left
  2244. (insert "\n" (pop left))
  2245. (when right
  2246. (if (< (current-column) 40)
  2247. (move-to-column 40 t)
  2248. (insert " "))
  2249. (insert (pop right))))
  2250. ;; Make the window the right size
  2251. (goto-char (point-min))
  2252. (if second-time
  2253. (if (not (pos-visible-in-window-p (point-max)))
  2254. (org-fit-window-to-buffer))
  2255. (setq second-time t)
  2256. (org-fit-window-to-buffer))
  2257. ;; Ask for selection
  2258. (message "Press key for agenda command%s:"
  2259. (if (or restrict-ok org-agenda-overriding-restriction)
  2260. (if org-agenda-overriding-restriction
  2261. " (restriction lock active)"
  2262. (if restriction
  2263. (format " (restricted to %s)" restriction)
  2264. " (unrestricted)"))
  2265. ""))
  2266. (setq c (read-char-exclusive))
  2267. (message "")
  2268. (cond
  2269. ((assoc (char-to-string c) custom)
  2270. (setq selstring (concat selstring (char-to-string c)))
  2271. (throw 'exit (cons selstring restriction)))
  2272. ((memq c prefixes)
  2273. (setq selstring (concat selstring (char-to-string c))
  2274. prefixes nil
  2275. rmheader (or rmheader t)
  2276. custom (delq nil (mapcar
  2277. (lambda (x)
  2278. (if (or (= (length (car x)) 1)
  2279. (/= (string-to-char (car x)) c))
  2280. nil
  2281. (cons (substring (car x) 1) (cdr x))))
  2282. custom))))
  2283. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2284. (message "Restriction is only possible in Org-mode buffers")
  2285. (ding) (sit-for 1))
  2286. ((eq c ?1)
  2287. (org-agenda-remove-restriction-lock 'noupdate)
  2288. (setq restriction 'buffer))
  2289. ((eq c ?0)
  2290. (org-agenda-remove-restriction-lock 'noupdate)
  2291. (setq restriction (if region-p 'region 'subtree)))
  2292. ((eq c ?<)
  2293. (org-agenda-remove-restriction-lock 'noupdate)
  2294. (setq restriction
  2295. (cond
  2296. ((eq restriction 'buffer)
  2297. (if region-p 'region 'subtree))
  2298. ((memq restriction '(subtree region))
  2299. nil)
  2300. (t 'buffer))))
  2301. ((eq c ?>)
  2302. (org-agenda-remove-restriction-lock 'noupdate)
  2303. (setq restriction nil))
  2304. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2305. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2306. ((and (> (length selstring) 0) (eq c ?\d))
  2307. (delete-window)
  2308. (org-agenda-get-restriction-and-command prefix-descriptions))
  2309. ((equal c ?q) (error "Abort"))
  2310. (t (error "Invalid key %c" c))))))))
  2311. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2312. (defvar org-agenda-last-arguments nil
  2313. "The arguments of the previous call to `org-agenda'.")
  2314. (defun org-agenda-run-series (name series)
  2315. (org-let (nth 1 series) '(org-prepare-agenda name))
  2316. (let* ((org-agenda-multi t)
  2317. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2318. (org-agenda-overriding-arguments
  2319. (or org-agenda-overriding-arguments
  2320. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2321. (get 'org-agenda-redo-command 'last-args))))
  2322. (cmds (car series))
  2323. (gprops (nth 1 series))
  2324. match ;; The byte compiler incorrectly complains about this. Keep it!
  2325. cmd type lprops)
  2326. (while (setq cmd (pop cmds))
  2327. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2328. (cond
  2329. ((eq type 'agenda)
  2330. (org-let2 gprops lprops
  2331. '(call-interactively 'org-agenda-list)))
  2332. ((eq type 'alltodo)
  2333. (org-let2 gprops lprops
  2334. '(call-interactively 'org-todo-list)))
  2335. ((eq type 'search)
  2336. (org-let2 gprops lprops
  2337. '(org-search-view current-prefix-arg match nil)))
  2338. ((eq type 'stuck)
  2339. (org-let2 gprops lprops
  2340. '(call-interactively 'org-agenda-list-stuck-projects)))
  2341. ((eq type 'tags)
  2342. (org-let2 gprops lprops
  2343. '(org-tags-view current-prefix-arg match)))
  2344. ((eq type 'tags-todo)
  2345. (org-let2 gprops lprops
  2346. '(org-tags-view '(4) match)))
  2347. ((eq type 'todo)
  2348. (org-let2 gprops lprops
  2349. '(org-todo-list match)))
  2350. ((fboundp type)
  2351. (org-let2 gprops lprops
  2352. '(funcall type match)))
  2353. (t (error "Invalid type in command series"))))
  2354. (widen)
  2355. (setq org-agenda-redo-command redo)
  2356. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2357. (goto-char (point-min)))
  2358. (org-fit-agenda-window)
  2359. (org-let (nth 1 series) '(org-finalize-agenda)))
  2360. ;;;###autoload
  2361. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2362. "Run an agenda command in batch mode and send the result to STDOUT.
  2363. If CMD-KEY is a string of length 1, it is used as a key in
  2364. `org-agenda-custom-commands' and triggers this command. If it is a
  2365. longer string it is used as a tags/todo match string.
  2366. Parameters are alternating variable names and values that will be bound
  2367. before running the agenda command."
  2368. (org-eval-in-environment (org-make-parameter-alist parameters)
  2369. (if (> (length cmd-key) 2)
  2370. (org-tags-view nil cmd-key)
  2371. (org-agenda nil cmd-key)))
  2372. (set-buffer org-agenda-buffer-name)
  2373. (princ (buffer-string)))
  2374. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2375. (defvar org-agenda-info nil)
  2376. ;;;###autoload
  2377. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2378. "Run an agenda command in batch mode and send the result to STDOUT.
  2379. If CMD-KEY is a string of length 1, it is used as a key in
  2380. `org-agenda-custom-commands' and triggers this command. If it is a
  2381. longer string it is used as a tags/todo match string.
  2382. Parameters are alternating variable names and values that will be bound
  2383. before running the agenda command.
  2384. The output gives a line for each selected agenda item. Each
  2385. item is a list of comma-separated values, like this:
  2386. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2387. category The category of the item
  2388. head The headline, without TODO kwd, TAGS and PRIORITY
  2389. type The type of the agenda entry, can be
  2390. todo selected in TODO match
  2391. tagsmatch selected in tags match
  2392. diary imported from diary
  2393. deadline a deadline on given date
  2394. scheduled scheduled on given date
  2395. timestamp entry has timestamp on given date
  2396. closed entry was closed on given date
  2397. upcoming-deadline warning about deadline
  2398. past-scheduled forwarded scheduled item
  2399. block entry has date block including g. date
  2400. todo The todo keyword, if any
  2401. tags All tags including inherited ones, separated by colons
  2402. date The relevant date, like 2007-2-14
  2403. time The time, like 15:00-16:50
  2404. extra Sting with extra planning info
  2405. priority-l The priority letter if any was given
  2406. priority-n The computed numerical priority
  2407. agenda-day The day in the agenda where this is listed"
  2408. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2409. (org-make-parameter-alist parameters))
  2410. (if (> (length cmd-key) 2)
  2411. (org-tags-view nil cmd-key)
  2412. (org-agenda nil cmd-key)))
  2413. (set-buffer org-agenda-buffer-name)
  2414. (let* ((lines (org-split-string (buffer-string) "\n"))
  2415. line)
  2416. (while (setq line (pop lines))
  2417. (catch 'next
  2418. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2419. (setq org-agenda-info
  2420. (org-fix-agenda-info (text-properties-at 0 line)))
  2421. (princ
  2422. (mapconcat 'org-agenda-export-csv-mapper
  2423. '(org-category txt type todo tags date time extra
  2424. priority-letter priority agenda-day)
  2425. ","))
  2426. (princ "\n")))))
  2427. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2428. (defun org-fix-agenda-info (props)
  2429. "Make sure all properties on an agenda item have a canonical form.
  2430. This ensures the export commands can easily use it."
  2431. (let (tmp re)
  2432. (when (setq tmp (plist-get props 'tags))
  2433. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2434. (when (setq tmp (plist-get props 'date))
  2435. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2436. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2437. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2438. (setq tmp (calendar-date-string tmp)))
  2439. (setq props (plist-put props 'date tmp)))
  2440. (when (setq tmp (plist-get props 'day))
  2441. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2442. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2443. (setq tmp (calendar-date-string tmp)))
  2444. (setq props (plist-put props 'day tmp))
  2445. (setq props (plist-put props 'agenda-day tmp)))
  2446. (when (setq tmp (plist-get props 'txt))
  2447. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2448. (plist-put props 'priority-letter (match-string 1 tmp))
  2449. (setq tmp (replace-match "" t t tmp)))
  2450. (when (and (setq re (plist-get props 'org-todo-regexp))
  2451. (setq re (concat "\\`\\.*" re " ?"))
  2452. (string-match re tmp))
  2453. (plist-put props 'todo (match-string 1 tmp))
  2454. (setq tmp (replace-match "" t t tmp)))
  2455. (plist-put props 'txt tmp)))
  2456. props)
  2457. (defun org-agenda-export-csv-mapper (prop)
  2458. (let ((res (plist-get org-agenda-info prop)))
  2459. (setq res
  2460. (cond
  2461. ((not res) "")
  2462. ((stringp res) res)
  2463. (t (prin1-to-string res))))
  2464. (while (string-match "," res)
  2465. (setq res (replace-match ";" t t res)))
  2466. (org-trim res)))
  2467. ;;;###autoload
  2468. (defun org-store-agenda-views (&rest parameters)
  2469. (interactive)
  2470. (eval (list 'org-batch-store-agenda-views)))
  2471. ;;;###autoload
  2472. (defmacro org-batch-store-agenda-views (&rest parameters)
  2473. "Run all custom agenda commands that have a file argument."
  2474. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2475. (pop-up-frames nil)
  2476. (dir default-directory)
  2477. (pars (org-make-parameter-alist parameters))
  2478. cmd thiscmdkey files opts cmd-or-set)
  2479. (save-window-excursion
  2480. (while cmds
  2481. (setq cmd (pop cmds)
  2482. thiscmdkey (car cmd)
  2483. cmd-or-set (nth 2 cmd)
  2484. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2485. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2486. (if (stringp files) (setq files (list files)))
  2487. (when files
  2488. (org-eval-in-environment (append org-agenda-exporter-settings
  2489. opts pars)
  2490. (org-agenda nil thiscmdkey))
  2491. (set-buffer org-agenda-buffer-name)
  2492. (while files
  2493. (org-eval-in-environment (append org-agenda-exporter-settings
  2494. opts pars)
  2495. (org-agenda-write (expand-file-name (pop files) dir) nil t)))
  2496. (and (get-buffer org-agenda-buffer-name)
  2497. (kill-buffer org-agenda-buffer-name)))))))
  2498. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2499. (defun org-agenda-mark-header-line (pos)
  2500. "Mark the line at POS as an agenda structure header."
  2501. (save-excursion
  2502. (goto-char pos)
  2503. (put-text-property (point-at-bol) (point-at-eol)
  2504. 'org-agenda-structural-header t)
  2505. (when org-agenda-title-append
  2506. (put-text-property (point-at-bol) (point-at-eol)
  2507. 'org-agenda-title-append org-agenda-title-append))))
  2508. (defvar org-mobile-creating-agendas)
  2509. (defvar org-agenda-write-buffer-name "Agenda View")
  2510. (defun org-agenda-write (file &optional open nosettings)
  2511. "Write the current buffer (an agenda view) as a file.
  2512. Depending on the extension of the file name, plain text (.txt),
  2513. HTML (.html or .htm) or Postscript (.ps) is produced.
  2514. If the extension is .ics, run icalendar export over all files used
  2515. to construct the agenda and limit the export to entries listed in the
  2516. agenda now.
  2517. With prefix argument OPEN, open the new file immediately.
  2518. If NOSETTINGS is given, do not scope the settings of
  2519. `org-agenda-exporter-settings' into the export commands. This is used when
  2520. the settings have already been scoped and we do not wish to overrule other,
  2521. higher priority settings."
  2522. (interactive "FWrite agenda to file: \nP")
  2523. (if (not (file-writable-p file))
  2524. (error "Cannot write agenda to file %s" file))
  2525. (org-let (if nosettings nil org-agenda-exporter-settings)
  2526. '(save-excursion
  2527. (save-window-excursion
  2528. (org-agenda-mark-filtered-text)
  2529. (let ((bs (copy-sequence (buffer-string))) beg)
  2530. (org-agenda-unmark-filtered-text)
  2531. (with-temp-buffer
  2532. (rename-buffer org-agenda-write-buffer-name t)
  2533. (set-buffer-modified-p nil)
  2534. (insert bs)
  2535. (org-agenda-remove-marked-text 'org-filtered)
  2536. (while (setq beg (text-property-any (point-min) (point-max)
  2537. 'org-filtered t))
  2538. (delete-region
  2539. beg (or (next-single-property-change beg 'org-filtered)
  2540. (point-max))))
  2541. (run-hooks 'org-agenda-before-write-hook)
  2542. (cond
  2543. ((org-bound-and-true-p org-mobile-creating-agendas)
  2544. (org-mobile-write-agenda-for-mobile file))
  2545. ((string-match "\\.html?\\'" file)
  2546. (require 'htmlize)
  2547. (set-buffer (htmlize-buffer (current-buffer)))
  2548. (when (and org-agenda-export-html-style
  2549. (string-match "<style>" org-agenda-export-html-style))
  2550. ;; replace <style> section with org-agenda-export-html-style
  2551. (goto-char (point-min))
  2552. (kill-region (- (search-forward "<style") 6)
  2553. (search-forward "</style>"))
  2554. (insert org-agenda-export-html-style))
  2555. (write-file file)
  2556. (kill-buffer (current-buffer))
  2557. (message "HTML written to %s" file))
  2558. ((string-match "\\.ps\\'" file)
  2559. (require 'ps-print)
  2560. (ps-print-buffer-with-faces file)
  2561. (message "Postscript written to %s" file))
  2562. ((string-match "\\.pdf\\'" file)
  2563. (require 'ps-print)
  2564. (ps-print-buffer-with-faces
  2565. (concat (file-name-sans-extension file) ".ps"))
  2566. (call-process "ps2pdf" nil nil nil
  2567. (expand-file-name
  2568. (concat (file-name-sans-extension file) ".ps"))
  2569. (expand-file-name file))
  2570. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2571. (message "PDF written to %s" file))
  2572. ((string-match "\\.ics\\'" file)
  2573. (require 'org-icalendar)
  2574. (let ((org-agenda-marker-table
  2575. (org-create-marker-find-array
  2576. (org-agenda-collect-markers)))
  2577. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2578. (org-combined-agenda-icalendar-file file))
  2579. (apply 'org-export-icalendar 'combine
  2580. (org-agenda-files nil 'ifmode))))
  2581. (t
  2582. (let ((bs (buffer-string)))
  2583. (find-file file)
  2584. (erase-buffer)
  2585. (insert bs)
  2586. (save-buffer 0)
  2587. (kill-buffer (current-buffer))
  2588. (message "Plain text written to %s" file))))))))
  2589. (set-buffer org-agenda-buffer-name))
  2590. (when open (org-open-file file)))
  2591. (defvar org-agenda-tag-filter-overlays nil)
  2592. (defvar org-agenda-cat-filter-overlays nil)
  2593. (defun org-agenda-mark-filtered-text ()
  2594. "Mark all text hidden by filtering with a text property."
  2595. (let ((inhibit-read-only t))
  2596. (mapc
  2597. (lambda (o)
  2598. (when (equal (overlay-buffer o) (current-buffer))
  2599. (put-text-property
  2600. (overlay-start o) (overlay-end o)
  2601. 'org-filtered t)))
  2602. (append org-agenda-tag-filter-overlays
  2603. org-agenda-cat-filter-overlays))))
  2604. (defun org-agenda-unmark-filtered-text ()
  2605. "Remove the filtering text property."
  2606. (let ((inhibit-read-only t))
  2607. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2608. (defun org-agenda-remove-marked-text (property &optional value)
  2609. "Delete all text marked with VALUE of PROPERTY.
  2610. VALUE defaults to t."
  2611. (let (beg)
  2612. (setq value (or value t))
  2613. (while (setq beg (text-property-any (point-min) (point-max)
  2614. property value))
  2615. (delete-region
  2616. beg (or (next-single-property-change beg 'org-filtered)
  2617. (point-max))))))
  2618. (defun org-agenda-add-entry-text ()
  2619. "Add entry text to agenda lines.
  2620. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2621. entry text following headings shown in the agenda.
  2622. Drawers will be excluded, also the line with scheduling/deadline info."
  2623. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2624. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2625. (let (m txt)
  2626. (goto-char (point-min))
  2627. (while (not (eobp))
  2628. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2629. (beginning-of-line 2)
  2630. (setq txt (org-agenda-get-some-entry-text
  2631. m org-agenda-add-entry-text-maxlines " > "))
  2632. (end-of-line 1)
  2633. (if (string-match "\\S-" txt)
  2634. (insert "\n" txt)
  2635. (or (eobp) (forward-char 1))))))))
  2636. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2637. &rest keep)
  2638. "Extract entry text from MARKER, at most N-LINES lines.
  2639. This will ignore drawers etc, just get the text.
  2640. If INDENT is given, prefix every line with this string. If KEEP is
  2641. given, it is a list of symbols, defining stuff that should not be
  2642. removed from the entry content. Currently only `planning' is allowed here."
  2643. (let (txt drawer-re kwd-time-re ind)
  2644. (save-excursion
  2645. (with-current-buffer (marker-buffer marker)
  2646. (if (not (eq major-mode 'org-mode))
  2647. (setq txt "")
  2648. (save-excursion
  2649. (save-restriction
  2650. (widen)
  2651. (goto-char marker)
  2652. (end-of-line 1)
  2653. (setq txt (buffer-substring
  2654. (min (1+ (point)) (point-max))
  2655. (progn (outline-next-heading) (point)))
  2656. drawer-re org-drawer-regexp
  2657. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2658. ".*\n?"))
  2659. (with-temp-buffer
  2660. (insert txt)
  2661. (when org-agenda-add-entry-text-descriptive-links
  2662. (goto-char (point-min))
  2663. (while (org-activate-bracket-links (point-max))
  2664. (add-text-properties (match-beginning 0) (match-end 0)
  2665. '(face org-link))))
  2666. (goto-char (point-min))
  2667. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2668. (set-text-properties (match-beginning 0) (match-end 0)
  2669. nil))
  2670. (goto-char (point-min))
  2671. (while (re-search-forward drawer-re nil t)
  2672. (delete-region
  2673. (match-beginning 0)
  2674. (progn (re-search-forward
  2675. "^[ \t]*:END:.*\n?" nil 'move)
  2676. (point))))
  2677. (unless (member 'planning keep)
  2678. (goto-char (point-min))
  2679. (while (re-search-forward kwd-time-re nil t)
  2680. (replace-match "")))
  2681. (goto-char (point-min))
  2682. (when org-agenda-entry-text-exclude-regexps
  2683. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2684. (while (setq re (pop re-list))
  2685. (goto-char (point-min))
  2686. (while (re-search-forward re nil t)
  2687. (replace-match "")))))
  2688. (goto-char (point-max))
  2689. (skip-chars-backward " \t\n")
  2690. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2691. ;; find and remove min common indentation
  2692. (goto-char (point-min))
  2693. (untabify (point-min) (point-max))
  2694. (setq ind (org-get-indentation))
  2695. (while (not (eobp))
  2696. (unless (looking-at "[ \t]*$")
  2697. (setq ind (min ind (org-get-indentation))))
  2698. (beginning-of-line 2))
  2699. (goto-char (point-min))
  2700. (while (not (eobp))
  2701. (unless (looking-at "[ \t]*$")
  2702. (move-to-column ind)
  2703. (delete-region (point-at-bol) (point)))
  2704. (beginning-of-line 2))
  2705. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2706. (goto-char (point-min))
  2707. (when indent
  2708. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2709. (replace-match indent t t)))
  2710. (goto-char (point-min))
  2711. (while (looking-at "[ \t]*\n") (replace-match ""))
  2712. (goto-char (point-max))
  2713. (when (> (org-current-line)
  2714. n-lines)
  2715. (org-goto-line (1+ n-lines))
  2716. (backward-char 1))
  2717. (setq txt (buffer-substring (point-min) (point)))))))))
  2718. txt))
  2719. (defun org-agenda-collect-markers ()
  2720. "Collect the markers pointing to entries in the agenda buffer."
  2721. (let (m markers)
  2722. (save-excursion
  2723. (goto-char (point-min))
  2724. (while (not (eobp))
  2725. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2726. (org-get-at-bol 'org-marker)))
  2727. (push m markers))
  2728. (beginning-of-line 2)))
  2729. (nreverse markers)))
  2730. (defun org-create-marker-find-array (marker-list)
  2731. "Create a alist of files names with all marker positions in that file."
  2732. (let (f tbl m a p)
  2733. (while (setq m (pop marker-list))
  2734. (setq p (marker-position m)
  2735. f (buffer-file-name (or (buffer-base-buffer
  2736. (marker-buffer m))
  2737. (marker-buffer m))))
  2738. (if (setq a (assoc f tbl))
  2739. (push (marker-position m) (cdr a))
  2740. (push (list f p) tbl)))
  2741. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2742. tbl)))
  2743. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2744. (defun org-check-agenda-marker-table ()
  2745. "Check of the current entry is on the marker list."
  2746. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2747. a)
  2748. (and (setq a (assoc file org-agenda-marker-table))
  2749. (save-match-data
  2750. (save-excursion
  2751. (org-back-to-heading t)
  2752. (member (point) (cdr a)))))))
  2753. (defun org-check-for-org-mode ()
  2754. "Make sure current buffer is in org-mode. Error if not."
  2755. (or (eq major-mode 'org-mode)
  2756. (error "Cannot execute org-mode agenda command on buffer in %s"
  2757. major-mode)))
  2758. (defun org-fit-agenda-window ()
  2759. "Fit the window to the buffer size."
  2760. (and (memq org-agenda-window-setup '(reorganize-frame))
  2761. (fboundp 'fit-window-to-buffer)
  2762. (org-fit-window-to-buffer
  2763. nil
  2764. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2765. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2766. ;;; Agenda prepare and finalize
  2767. (defvar org-agenda-multi nil) ; dynamically scoped
  2768. (defvar org-agenda-buffer-name "*Org Agenda*")
  2769. (defvar org-pre-agenda-window-conf nil)
  2770. (defvar org-agenda-columns-active nil)
  2771. (defvar org-agenda-name nil)
  2772. (defvar org-agenda-tag-filter nil)
  2773. (defvar org-agenda-category-filter nil)
  2774. (defvar org-agenda-tag-filter-while-redo nil)
  2775. (defvar org-agenda-tag-filter-preset nil
  2776. "A preset of the tags filter used for secondary agenda filtering.
  2777. This must be a list of strings, each string must be a single tag preceded
  2778. by \"+\" or \"-\".
  2779. This variable should not be set directly, but agenda custom commands can
  2780. bind it in the options section. The preset filter is a global property of
  2781. the entire agenda view. In a block agenda, it will not work reliably to
  2782. define a filter for one of the individual blocks. You need to set it in
  2783. the global options and expect it to be applied to the entire view.")
  2784. (defvar org-agenda-category-filter-preset nil
  2785. "A preset of the category filter used for secondary agenda filtering.
  2786. This must be a list of strings, each string must be a single category
  2787. preceded by \"+\" or \"-\".
  2788. This variable should not be set directly, but agenda custom commands can
  2789. bind it in the options section. The preset filter is a global property of
  2790. the entire agenda view. In a block agenda, it will not work reliably to
  2791. define a filter for one of the individual blocks. You need to set it in
  2792. the global options and expect it to be applied to the entire view.")
  2793. (defun org-prepare-agenda (&optional name)
  2794. (setq org-todo-keywords-for-agenda nil)
  2795. (setq org-done-keywords-for-agenda nil)
  2796. (setq org-drawers-for-agenda nil)
  2797. (unless org-agenda-persistent-filter
  2798. (setq org-agenda-tag-filter nil
  2799. org-agenda-category-filter nil))
  2800. (put 'org-agenda-tag-filter :preset-filter org-agenda-tag-filter-preset)
  2801. (put 'org-agenda-category-filter :preset-filter org-agenda-category-filter-preset)
  2802. (if org-agenda-multi
  2803. (progn
  2804. (setq buffer-read-only nil)
  2805. (goto-char (point-max))
  2806. (unless (or (bobp) org-agenda-compact-blocks
  2807. (not org-agenda-block-separator))
  2808. (insert "\n"
  2809. (if (stringp org-agenda-block-separator)
  2810. org-agenda-block-separator
  2811. (make-string (window-width) org-agenda-block-separator))
  2812. "\n"))
  2813. (narrow-to-region (point) (point-max)))
  2814. (org-agenda-reset-markers)
  2815. (setq org-agenda-contributing-files nil)
  2816. (setq org-agenda-columns-active nil)
  2817. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2818. (setq org-todo-keywords-for-agenda
  2819. (org-uniquify org-todo-keywords-for-agenda))
  2820. (setq org-done-keywords-for-agenda
  2821. (org-uniquify org-done-keywords-for-agenda))
  2822. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2823. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2824. (awin (get-buffer-window abuf)))
  2825. (cond
  2826. ((equal (current-buffer) abuf) nil)
  2827. (awin (select-window awin))
  2828. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2829. ((equal org-agenda-window-setup 'current-window)
  2830. (org-pop-to-buffer-same-window abuf))
  2831. ((equal org-agenda-window-setup 'other-window)
  2832. (org-switch-to-buffer-other-window abuf))
  2833. ((equal org-agenda-window-setup 'other-frame)
  2834. (switch-to-buffer-other-frame abuf))
  2835. ((equal org-agenda-window-setup 'reorganize-frame)
  2836. (delete-other-windows)
  2837. (org-switch-to-buffer-other-window abuf)))
  2838. ;; additional test in case agenda is invoked from within agenda
  2839. ;; buffer via elisp link
  2840. (unless (equal (current-buffer) abuf)
  2841. (org-pop-to-buffer-same-window abuf)))
  2842. (setq buffer-read-only nil)
  2843. (let ((inhibit-read-only t)) (erase-buffer))
  2844. (org-agenda-mode)
  2845. (and name (not org-agenda-name)
  2846. (org-set-local 'org-agenda-name name)))
  2847. (setq buffer-read-only nil))
  2848. (defun org-finalize-agenda ()
  2849. "Finishing touch for the agenda buffer, called just before displaying it."
  2850. (unless org-agenda-multi
  2851. (save-excursion
  2852. (let ((inhibit-read-only t))
  2853. (goto-char (point-min))
  2854. (while (org-activate-bracket-links (point-max))
  2855. (add-text-properties (match-beginning 0) (match-end 0)
  2856. '(face org-link)))
  2857. (org-agenda-align-tags)
  2858. (unless org-agenda-with-colors
  2859. (remove-text-properties (point-min) (point-max) '(face nil))))
  2860. (if (and (boundp 'org-agenda-overriding-columns-format)
  2861. org-agenda-overriding-columns-format)
  2862. (org-set-local 'org-agenda-overriding-columns-format
  2863. org-agenda-overriding-columns-format))
  2864. (if (and (boundp 'org-agenda-view-columns-initially)
  2865. org-agenda-view-columns-initially)
  2866. (org-agenda-columns))
  2867. (when org-agenda-fontify-priorities
  2868. (org-agenda-fontify-priorities))
  2869. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2870. (org-agenda-dim-blocked-tasks))
  2871. (org-agenda-mark-clocking-task)
  2872. (when org-agenda-entry-text-mode
  2873. (org-agenda-entry-text-hide)
  2874. (org-agenda-entry-text-show))
  2875. (if (functionp 'org-habit-insert-consistency-graphs)
  2876. (org-habit-insert-consistency-graphs))
  2877. (run-hooks 'org-finalize-agenda-hook)
  2878. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2879. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  2880. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  2881. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  2882. (org-agenda-filter-apply org-agenda-category-filter 'category))
  2883. )))
  2884. (defun org-agenda-mark-clocking-task ()
  2885. "Mark the current clock entry in the agenda if it is present."
  2886. (mapc (lambda (o)
  2887. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2888. (delete-overlay o)))
  2889. (overlays-in (point-min) (point-max)))
  2890. (when (marker-buffer org-clock-hd-marker)
  2891. (save-excursion
  2892. (goto-char (point-min))
  2893. (let (s ov)
  2894. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2895. (goto-char s)
  2896. (when (equal (org-get-at-bol 'org-hd-marker)
  2897. org-clock-hd-marker)
  2898. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2899. (overlay-put ov 'type 'org-agenda-clocking)
  2900. (overlay-put ov 'face 'org-agenda-clocking)
  2901. (overlay-put ov 'help-echo
  2902. "The clock is running in this item")))))))
  2903. (defun org-agenda-fontify-priorities ()
  2904. "Make highest priority lines bold, and lowest italic."
  2905. (interactive)
  2906. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2907. (delete-overlay o)))
  2908. (overlays-in (point-min) (point-max)))
  2909. (save-excursion
  2910. (let ((inhibit-read-only t)
  2911. b e p ov h l)
  2912. (goto-char (point-min))
  2913. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2914. (setq h (or (get-char-property (point) 'org-highest-priority)
  2915. org-highest-priority)
  2916. l (or (get-char-property (point) 'org-lowest-priority)
  2917. org-lowest-priority)
  2918. p (string-to-char (match-string 1))
  2919. b (match-beginning 0)
  2920. e (if (eq org-agenda-fontify-priorities 'cookies)
  2921. (match-end 0)
  2922. (point-at-eol))
  2923. ov (make-overlay b e))
  2924. (overlay-put
  2925. ov 'face
  2926. (cond ((org-face-from-face-or-color
  2927. 'priority nil
  2928. (cdr (assoc p org-priority-faces))))
  2929. ((and (listp org-agenda-fontify-priorities)
  2930. (org-face-from-face-or-color
  2931. 'priority nil
  2932. (cdr (assoc p org-agenda-fontify-priorities)))))
  2933. ((equal p l) 'italic)
  2934. ((equal p h) 'bold)))
  2935. (overlay-put ov 'org-type 'org-priority)))))
  2936. (defun org-agenda-dim-blocked-tasks ()
  2937. "Dim currently blocked TODO's in the agenda display."
  2938. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2939. (delete-overlay o)))
  2940. (overlays-in (point-min) (point-max)))
  2941. (save-excursion
  2942. (let ((inhibit-read-only t)
  2943. (org-depend-tag-blocked nil)
  2944. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2945. org-blocked-by-checkboxes
  2946. invis1 b e p ov h l)
  2947. (goto-char (point-min))
  2948. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2949. (and pos (goto-char (1+ pos))))
  2950. (setq org-blocked-by-checkboxes nil invis1 invis)
  2951. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2952. (when (and marker
  2953. (with-current-buffer (marker-buffer marker)
  2954. (save-excursion (goto-char marker)
  2955. (org-entry-blocked-p))))
  2956. (if org-blocked-by-checkboxes (setq invis1 nil))
  2957. (setq b (if invis1
  2958. (max (point-min) (1- (point-at-bol)))
  2959. (point-at-bol))
  2960. e (point-at-eol)
  2961. ov (make-overlay b e))
  2962. (if invis1
  2963. (overlay-put ov 'invisible t)
  2964. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2965. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2966. (defvar org-agenda-skip-function nil
  2967. "Function to be called at each match during agenda construction.
  2968. If this function returns nil, the current match should not be skipped.
  2969. Otherwise, the function must return a position from where the search
  2970. should be continued.
  2971. This may also be a Lisp form, it will be evaluated.
  2972. Never set this variable using `setq' or so, because then it will apply
  2973. to all future agenda commands. If you do want a global skipping condition,
  2974. use the option `org-agenda-skip-function-global' instead.
  2975. The correct usage for `org-agenda-skip-function' is to bind it with
  2976. `let' to scope it dynamically into the agenda-constructing command.
  2977. A good way to set it is through options in `org-agenda-custom-commands'.")
  2978. (defun org-agenda-skip ()
  2979. "Throw to `:skip' in places that should be skipped.
  2980. Also moves point to the end of the skipped region, so that search can
  2981. continue from there."
  2982. (let ((p (point-at-bol)) to)
  2983. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2984. (get-text-property p :org-archived)
  2985. (org-end-of-subtree t)
  2986. (throw :skip t))
  2987. (and org-agenda-skip-comment-trees
  2988. (get-text-property p :org-comment)
  2989. (org-end-of-subtree t)
  2990. (throw :skip t))
  2991. (if (equal (char-after p) ?#) (throw :skip t))
  2992. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  2993. (org-agenda-skip-eval org-agenda-skip-function)))
  2994. (goto-char to)
  2995. (throw :skip t))))
  2996. (defun org-agenda-skip-eval (form)
  2997. "If FORM is a function or a list, call (or eval) is and return result.
  2998. `save-excursion' and `save-match-data' are wrapped around the call, so point
  2999. and match data are returned to the previous state no matter what these
  3000. functions do."
  3001. (let (fp)
  3002. (and form
  3003. (or (setq fp (functionp form))
  3004. (consp form))
  3005. (save-excursion
  3006. (save-match-data
  3007. (if fp
  3008. (funcall form)
  3009. (eval form)))))))
  3010. (defvar org-agenda-markers nil
  3011. "List of all currently active markers created by `org-agenda'.")
  3012. (defvar org-agenda-last-marker-time (org-float-time)
  3013. "Creation time of the last agenda marker.")
  3014. (defun org-agenda-new-marker (&optional pos)
  3015. "Return a new agenda marker.
  3016. Org-mode keeps a list of these markers and resets them when they are
  3017. no longer in use."
  3018. (let ((m (copy-marker (or pos (point)))))
  3019. (setq org-agenda-last-marker-time (org-float-time))
  3020. (push m org-agenda-markers)
  3021. m))
  3022. (defun org-agenda-reset-markers ()
  3023. "Reset markers created by `org-agenda'."
  3024. (while org-agenda-markers
  3025. (move-marker (pop org-agenda-markers) nil)))
  3026. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3027. "Save relative positions of markers in region."
  3028. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3029. org-agenda-markers))
  3030. ;;; Entry text mode
  3031. (defun org-agenda-entry-text-show-here ()
  3032. "Add some text from the entry as context to the current line."
  3033. (let (m txt o)
  3034. (setq m (org-get-at-bol 'org-hd-marker))
  3035. (unless (marker-buffer m)
  3036. (error "No marker points to an entry here"))
  3037. (setq txt (concat "\n" (org-no-properties
  3038. (org-agenda-get-some-entry-text
  3039. m org-agenda-entry-text-maxlines " > "))))
  3040. (when (string-match "\\S-" txt)
  3041. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3042. (overlay-put o 'evaporate t)
  3043. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3044. (overlay-put o 'after-string txt))))
  3045. (defun org-agenda-entry-text-show ()
  3046. "Add entry context for all agenda lines."
  3047. (interactive)
  3048. (save-excursion
  3049. (goto-char (point-max))
  3050. (beginning-of-line 1)
  3051. (while (not (bobp))
  3052. (when (org-get-at-bol 'org-hd-marker)
  3053. (org-agenda-entry-text-show-here))
  3054. (beginning-of-line 0))))
  3055. (defun org-agenda-entry-text-hide ()
  3056. "Remove any shown entry context."
  3057. (delq nil
  3058. (mapcar (lambda (o)
  3059. (if (eq (overlay-get o 'org-overlay-type)
  3060. 'agenda-entry-content)
  3061. (progn (delete-overlay o) t)))
  3062. (overlays-in (point-min) (point-max)))))
  3063. (defun org-agenda-get-day-face (date)
  3064. "Return the face DATE should be displayed with."
  3065. (or (and (functionp org-agenda-day-face-function)
  3066. (funcall org-agenda-day-face-function date))
  3067. (cond ((org-agenda-todayp date)
  3068. 'org-agenda-date-today)
  3069. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3070. 'org-agenda-date-weekend)
  3071. (t 'org-agenda-date))))
  3072. ;;; Agenda timeline
  3073. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3074. (defun org-timeline (&optional dotodo)
  3075. "Show a time-sorted view of the entries in the current org file.
  3076. Only entries with a time stamp of today or later will be listed. With
  3077. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3078. under the current date.
  3079. If the buffer contains an active region, only check the region for
  3080. dates."
  3081. (interactive "P")
  3082. (org-compile-prefix-format 'timeline)
  3083. (org-set-sorting-strategy 'timeline)
  3084. (let* ((dopast t)
  3085. (doclosed org-agenda-show-log)
  3086. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3087. (current-buffer))))
  3088. (date (calendar-current-date))
  3089. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3090. (end (if (org-region-active-p) (region-end) (point-max)))
  3091. (day-numbers (org-get-all-dates beg end 'no-ranges
  3092. t doclosed ; always include today
  3093. org-timeline-show-empty-dates))
  3094. (org-deadline-warning-days 0)
  3095. (org-agenda-only-exact-dates t)
  3096. (today (org-today))
  3097. (past t)
  3098. args
  3099. s e rtn d emptyp)
  3100. (setq org-agenda-redo-command
  3101. (list 'progn
  3102. (list 'org-switch-to-buffer-other-window (current-buffer))
  3103. (list 'org-timeline (list 'quote dotodo))))
  3104. (if (not dopast)
  3105. ;; Remove past dates from the list of dates.
  3106. (setq day-numbers (delq nil (mapcar (lambda(x)
  3107. (if (>= x today) x nil))
  3108. day-numbers))))
  3109. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3110. (if doclosed (push :closed args))
  3111. (push :timestamp args)
  3112. (push :deadline args)
  3113. (push :scheduled args)
  3114. (push :sexp args)
  3115. (if dotodo (push :todo args))
  3116. (insert "Timeline of file " entry "\n")
  3117. (add-text-properties (point-min) (point)
  3118. (list 'face 'org-agenda-structure))
  3119. (org-agenda-mark-header-line (point-min))
  3120. (while (setq d (pop day-numbers))
  3121. (if (and (listp d) (eq (car d) :omitted))
  3122. (progn
  3123. (setq s (point))
  3124. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3125. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3126. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3127. (if (and (>= d today)
  3128. dopast
  3129. past)
  3130. (progn
  3131. (setq past nil)
  3132. (insert (make-string 79 ?-) "\n")))
  3133. (setq date (calendar-gregorian-from-absolute d))
  3134. (setq s (point))
  3135. (setq rtn (and (not emptyp)
  3136. (apply 'org-agenda-get-day-entries entry
  3137. date args)))
  3138. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3139. (progn
  3140. (insert
  3141. (if (stringp org-agenda-format-date)
  3142. (format-time-string org-agenda-format-date
  3143. (org-time-from-absolute date))
  3144. (funcall org-agenda-format-date date))
  3145. "\n")
  3146. (put-text-property s (1- (point)) 'face
  3147. (org-agenda-get-day-face date))
  3148. (put-text-property s (1- (point)) 'org-date-line t)
  3149. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3150. (if (equal d today)
  3151. (put-text-property s (1- (point)) 'org-today t))
  3152. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3153. (put-text-property s (1- (point)) 'day d)))))
  3154. (goto-char (point-min))
  3155. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3156. (point-min)))
  3157. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3158. (org-finalize-agenda)
  3159. (setq buffer-read-only t)))
  3160. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3161. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3162. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3163. not every single day in the range. If FORCE-TODAY is non-nil, make
  3164. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3165. inactive time stamps (those in square brackets) are included.
  3166. When EMPTY is non-nil, also include days without any entries."
  3167. (let ((re (concat
  3168. (if pre-re pre-re "")
  3169. (if inactive org-ts-regexp-both org-ts-regexp)))
  3170. dates dates1 date day day1 day2 ts1 ts2 pos)
  3171. (if force-today
  3172. (setq dates (list (org-today))))
  3173. (save-excursion
  3174. (goto-char beg)
  3175. (while (re-search-forward re end t)
  3176. (setq day (time-to-days (org-time-string-to-time
  3177. (substring (match-string 1) 0 10)
  3178. (current-buffer) (match-beginning 0))))
  3179. (or (memq day dates) (push day dates)))
  3180. (unless no-ranges
  3181. (goto-char beg)
  3182. (while (re-search-forward org-tr-regexp end t)
  3183. (setq pos (match-beginning 0))
  3184. (setq ts1 (substring (match-string 1) 0 10)
  3185. ts2 (substring (match-string 2) 0 10)
  3186. day1 (time-to-days (org-time-string-to-time
  3187. ts1 (current-buffer) pos))
  3188. day2 (time-to-days (org-time-string-to-time
  3189. ts2 (current-buffer) pos)))
  3190. (while (< (setq day1 (1+ day1)) day2)
  3191. (or (memq day1 dates) (push day1 dates)))))
  3192. (setq dates (sort dates '<))
  3193. (when empty
  3194. (while (setq day (pop dates))
  3195. (setq day2 (car dates))
  3196. (push day dates1)
  3197. (when (and day2 empty)
  3198. (if (or (eq empty t)
  3199. (and (numberp empty) (<= (- day2 day) empty)))
  3200. (while (< (setq day (1+ day)) day2)
  3201. (push (list day) dates1))
  3202. (push (cons :omitted (- day2 day)) dates1))))
  3203. (setq dates (nreverse dates1)))
  3204. dates)))
  3205. ;;; Agenda Daily/Weekly
  3206. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3207. "Start day for the agenda view.
  3208. Custom commands can set this variable in the options section.")
  3209. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3210. (defvar org-agenda-current-span nil
  3211. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3212. (defvar org-arg-loc nil) ; local variable
  3213. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3214. "List of types searched for when creating the daily/weekly agenda.
  3215. This variable is a list of symbols that controls the types of
  3216. items that appear in the daily/weekly agenda. Allowed symbols in this
  3217. list are are
  3218. :timestamp List items containing a date stamp or date range matching
  3219. the selected date. This includes sexp entries in
  3220. angular brackets.
  3221. :sexp List entries resulting from plain diary-like sexps.
  3222. :deadline List deadline due on that date. When the date is today,
  3223. also list any deadlines past due, or due within
  3224. `org-deadline-warning-days'. `:deadline' must appear before
  3225. `:scheduled' if the setting of
  3226. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3227. any effect.
  3228. :scheduled List all items which are scheduled for the given date.
  3229. The diary for *today* also contains items which were
  3230. scheduled earlier and are not yet marked DONE.
  3231. By default, all four types are turned on.
  3232. Never set this variable globally using `setq', because then it
  3233. will apply to all future agenda commands. Instead, bind it with
  3234. `let' to scope it dynamically into the agenda-constructing
  3235. command. A good way to set it is through options in
  3236. `org-agenda-custom-commands'. For a more flexible (though
  3237. somewhat less efficient) way of determining what is included in
  3238. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3239. ;;;###autoload
  3240. (defun org-agenda-list (&optional arg start-day span)
  3241. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3242. The view will be for the current day or week, but from the overview buffer
  3243. you will be able to go to other days/weeks.
  3244. With a numeric prefix argument in an interactive call, the agenda will
  3245. span ARG days. Lisp programs should instead specify SPAN to change
  3246. the number of days. SPAN defaults to `org-agenda-span'.
  3247. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3248. given in `org-agenda-start-on-weekday'."
  3249. (interactive "P")
  3250. (if (and (integerp arg) (> arg 0))
  3251. (setq span arg arg nil))
  3252. (setq start-day (or start-day org-agenda-start-day))
  3253. (if org-agenda-overriding-arguments
  3254. (setq arg (car org-agenda-overriding-arguments)
  3255. start-day (nth 1 org-agenda-overriding-arguments)
  3256. span (nth 2 org-agenda-overriding-arguments)))
  3257. (if (stringp start-day)
  3258. ;; Convert to an absolute day number
  3259. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3260. (setq org-agenda-last-arguments (list arg start-day span))
  3261. (org-compile-prefix-format 'agenda)
  3262. (org-set-sorting-strategy 'agenda)
  3263. (let* ((span (org-agenda-ndays-to-span
  3264. (or span org-agenda-ndays org-agenda-span)))
  3265. (today (org-today))
  3266. (sd (or start-day today))
  3267. (ndays (org-agenda-span-to-ndays span sd))
  3268. (org-agenda-start-on-weekday
  3269. (if (eq ndays 7)
  3270. org-agenda-start-on-weekday))
  3271. (thefiles (org-agenda-files nil 'ifmode))
  3272. (files thefiles)
  3273. (start (if (or (null org-agenda-start-on-weekday)
  3274. (< ndays 7))
  3275. sd
  3276. (let* ((nt (calendar-day-of-week
  3277. (calendar-gregorian-from-absolute sd)))
  3278. (n1 org-agenda-start-on-weekday)
  3279. (d (- nt n1)))
  3280. (- sd (+ (if (< d 0) 7 0) d)))))
  3281. (day-numbers (list start))
  3282. (day-cnt 0)
  3283. (inhibit-redisplay (not debug-on-error))
  3284. s e rtn rtnall file date d start-pos end-pos todayp
  3285. clocktable-start clocktable-end filter)
  3286. (setq org-agenda-redo-command
  3287. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3288. (dotimes (n (1- ndays))
  3289. (push (1+ (car day-numbers)) day-numbers))
  3290. (setq day-numbers (nreverse day-numbers))
  3291. (setq clocktable-start (car day-numbers)
  3292. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3293. (org-prepare-agenda "Day/Week")
  3294. (org-set-local 'org-starting-day (car day-numbers))
  3295. (org-set-local 'org-arg-loc arg)
  3296. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3297. (unless org-agenda-compact-blocks
  3298. (let* ((d1 (car day-numbers))
  3299. (d2 (org-last day-numbers))
  3300. (w1 (org-days-to-iso-week d1))
  3301. (w2 (org-days-to-iso-week d2)))
  3302. (setq s (point))
  3303. (if org-agenda-overriding-header
  3304. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3305. nil 'face 'org-agenda-structure) "\n")
  3306. (insert (org-agenda-span-name span)
  3307. "-agenda"
  3308. (if (< (- d2 d1) 350)
  3309. (if (= w1 w2)
  3310. (format " (W%02d)" w1)
  3311. (format " (W%02d-W%02d)" w1 w2))
  3312. "")
  3313. ":\n")))
  3314. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3315. 'org-date-line t))
  3316. (org-agenda-mark-header-line s))
  3317. (while (setq d (pop day-numbers))
  3318. (setq date (calendar-gregorian-from-absolute d)
  3319. s (point))
  3320. (if (or (setq todayp (= d today))
  3321. (and (not start-pos) (= d sd)))
  3322. (setq start-pos (point))
  3323. (if (and start-pos (not end-pos))
  3324. (setq end-pos (point))))
  3325. (setq files thefiles
  3326. rtnall nil)
  3327. (while (setq file (pop files))
  3328. (catch 'nextfile
  3329. (org-check-agenda-file file)
  3330. (let ((org-agenda-entry-types org-agenda-entry-types))
  3331. (unless org-agenda-include-deadlines
  3332. (setq org-agenda-entry-types
  3333. (delq :deadline org-agenda-entry-types)))
  3334. (cond
  3335. ((memq org-agenda-show-log '(only clockcheck))
  3336. (setq rtn (org-agenda-get-day-entries
  3337. file date :closed)))
  3338. (org-agenda-show-log
  3339. (setq rtn (apply 'org-agenda-get-day-entries
  3340. file date
  3341. (append '(:closed) org-agenda-entry-types))))
  3342. (t
  3343. (setq rtn (apply 'org-agenda-get-day-entries
  3344. file date
  3345. org-agenda-entry-types)))))
  3346. (setq rtnall (append rtnall rtn)))) ;; all entries
  3347. (if org-agenda-include-diary
  3348. (let ((org-agenda-search-headline-for-time t))
  3349. (require 'diary-lib)
  3350. (setq rtn (org-get-entries-from-diary date))
  3351. (setq rtnall (append rtnall rtn))))
  3352. (if (or rtnall org-agenda-show-all-dates)
  3353. (progn
  3354. (setq day-cnt (1+ day-cnt))
  3355. (insert
  3356. (if (stringp org-agenda-format-date)
  3357. (format-time-string org-agenda-format-date
  3358. (org-time-from-absolute date))
  3359. (funcall org-agenda-format-date date))
  3360. "\n")
  3361. (put-text-property s (1- (point)) 'face
  3362. (org-agenda-get-day-face date))
  3363. (put-text-property s (1- (point)) 'org-date-line t)
  3364. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3365. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3366. (when todayp
  3367. (put-text-property s (1- (point)) 'org-today t))
  3368. (if rtnall (insert ;; all entries
  3369. (org-finalize-agenda-entries
  3370. (org-agenda-add-time-grid-maybe
  3371. rtnall ndays todayp))
  3372. "\n"))
  3373. (put-text-property s (1- (point)) 'day d)
  3374. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3375. (when (and org-agenda-clockreport-mode clocktable-start)
  3376. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3377. ;; the above line is to ensure the restricted range!
  3378. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3379. tbl)
  3380. (setq p (org-plist-delete p :block))
  3381. (setq p (plist-put p :tstart clocktable-start))
  3382. (setq p (plist-put p :tend clocktable-end))
  3383. (setq p (plist-put p :scope 'agenda))
  3384. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3385. (setq filter (or org-agenda-tag-filter-while-redo
  3386. (get 'org-agenda-tag-filter :preset-filter))))
  3387. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3388. (if (string-match "[<>=]" x)
  3389. ""
  3390. x))
  3391. filter ""))))
  3392. (setq tbl (apply 'org-get-clocktable p))
  3393. (insert tbl)))
  3394. (goto-char (point-min))
  3395. (or org-agenda-multi (org-fit-agenda-window))
  3396. (unless (and (pos-visible-in-window-p (point-min))
  3397. (pos-visible-in-window-p (point-max)))
  3398. (goto-char (1- (point-max)))
  3399. (recenter -1)
  3400. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3401. (progn
  3402. (goto-char (or start-pos 1))
  3403. (recenter 1))))
  3404. (goto-char (or start-pos 1))
  3405. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3406. (if (eq org-agenda-show-log 'clockcheck)
  3407. (org-agenda-show-clocking-issues))
  3408. (org-finalize-agenda)
  3409. (setq buffer-read-only t)
  3410. (message "")))
  3411. (defun org-agenda-ndays-to-span (n)
  3412. "Return a span symbol for a span of N days, or N if none matches."
  3413. (cond ((symbolp n) n)
  3414. ((= n 1) 'day)
  3415. ((= n 7) 'week)
  3416. (t n)))
  3417. (defun org-agenda-span-to-ndays (span start-day)
  3418. "Return ndays from SPAN starting at START-DAY."
  3419. (cond ((numberp span) span)
  3420. ((eq span 'day) 1)
  3421. ((eq span 'week) 7)
  3422. ((eq span 'month)
  3423. (let ((date (calendar-gregorian-from-absolute start-day)))
  3424. (calendar-last-day-of-month (car date) (caddr date))))
  3425. ((eq span 'year)
  3426. (let ((date (calendar-gregorian-from-absolute start-day)))
  3427. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3428. (defun org-agenda-span-name (span)
  3429. "Return a SPAN name."
  3430. (if (null span)
  3431. ""
  3432. (if (symbolp span)
  3433. (capitalize (symbol-name span))
  3434. (format "%d days" span))))
  3435. ;;; Agenda word search
  3436. (defvar org-agenda-search-history nil)
  3437. (defvar org-todo-only nil)
  3438. (defvar org-search-syntax-table nil
  3439. "Special syntax table for org-mode search.
  3440. In this table, we have single quotes not as word constituents, to
  3441. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3442. (defun org-search-syntax-table ()
  3443. (unless org-search-syntax-table
  3444. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3445. (modify-syntax-entry ?' "." org-search-syntax-table)
  3446. (modify-syntax-entry ?` "." org-search-syntax-table))
  3447. org-search-syntax-table)
  3448. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3449. ;;;###autoload
  3450. (defun org-search-view (&optional todo-only string edit-at)
  3451. "Show all entries that contain a phrase or words or regular expressions.
  3452. With optional prefix argument TODO-ONLY, only consider entries that are
  3453. TODO entries. The argument STRING can be used to pass a default search
  3454. string into this function. If EDIT-AT is non-nil, it means that the
  3455. user should get a chance to edit this string, with cursor at position
  3456. EDIT-AT.
  3457. The search string can be viewed either as a phrase that should be found as
  3458. is, or it can be broken into a number of snippets, each of which must match
  3459. in a Boolean way to select an entry. The default depends on the variable
  3460. `org-agenda-search-view-always-boolean'.
  3461. Even if this is turned off (the default) you can always switch to
  3462. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3463. The default is a direct search of the whole phrase, where each space in
  3464. the search string can expand to an arbitrary amount of whitespace,
  3465. including newlines.
  3466. If using a Boolean search, the search string is split on whitespace and
  3467. each snippet is searched separately, with logical AND to select an entry.
  3468. Words prefixed with a minus must *not* occur in the entry. Words without
  3469. a prefix or prefixed with a plus must occur in the entry. Matching is
  3470. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3471. match whole words, not parts of a word) if
  3472. `org-agenda-search-view-force-full-words' is set (default is nil).
  3473. Boolean search snippets enclosed by curly braces are interpreted as
  3474. regular expressions that must or (when preceded with \"-\") must not
  3475. match in the entry. Snippets enclosed into double quotes will be taken
  3476. as a whole, to include whitespace.
  3477. - If the search string starts with an asterisk, search only in headlines.
  3478. - If (possibly after the leading star) the search string starts with an
  3479. exclamation mark, this also means to look at TODO entries only, an effect
  3480. that can also be achieved with a prefix argument.
  3481. - If (possibly after star and exclamation mark) the search string starts
  3482. with a colon, this will mean that the (non-regexp) snippets of the
  3483. Boolean search must match as full words.
  3484. This command searches the agenda files, and in addition the files listed
  3485. in `org-agenda-text-search-extra-files'."
  3486. (interactive "P")
  3487. (org-compile-prefix-format 'search)
  3488. (org-set-sorting-strategy 'search)
  3489. (org-prepare-agenda "SEARCH")
  3490. (let* ((props (list 'face nil
  3491. 'done-face 'org-agenda-done
  3492. 'org-not-done-regexp org-not-done-regexp
  3493. 'org-todo-regexp org-todo-regexp
  3494. 'org-complex-heading-regexp org-complex-heading-regexp
  3495. 'mouse-face 'highlight
  3496. 'help-echo (format "mouse-2 or RET jump to location")))
  3497. (full-words org-agenda-search-view-force-full-words)
  3498. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3499. regexp rtn rtnall files file pos
  3500. marker category org-category-pos tags c neg re boolean
  3501. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3502. (unless (and (not edit-at)
  3503. (stringp string)
  3504. (string-match "\\S-" string))
  3505. (setq string (read-string
  3506. (if org-agenda-search-view-always-boolean
  3507. "[+-]Word/{Regexp} ...: "
  3508. "Phrase, or [+-]Word/{Regexp} ...: ")
  3509. (cond
  3510. ((integerp edit-at) (cons string edit-at))
  3511. (edit-at string))
  3512. 'org-agenda-search-history)))
  3513. (org-set-local 'org-todo-only todo-only)
  3514. (setq org-agenda-redo-command
  3515. (list 'org-search-view (if todo-only t nil) string
  3516. '(if current-prefix-arg 1 nil)))
  3517. (setq org-agenda-query-string string)
  3518. (if (equal (string-to-char string) ?*)
  3519. (setq hdl-only t
  3520. words (substring string 1))
  3521. (setq words string))
  3522. (when (equal (string-to-char words) ?!)
  3523. (setq todo-only t
  3524. words (substring words 1)))
  3525. (when (equal (string-to-char words) ?:)
  3526. (setq full-words t
  3527. words (substring words 1)))
  3528. (if (or org-agenda-search-view-always-boolean
  3529. (member (string-to-char words) '(?- ?+ ?\{)))
  3530. (setq boolean t))
  3531. (setq words (org-split-string words))
  3532. (let (www w)
  3533. (while (setq w (pop words))
  3534. (while (and (string-match "\\\\\\'" w) words)
  3535. (setq w (concat (substring w 0 -1) " " (pop words))))
  3536. (push w www))
  3537. (setq words (nreverse www) www nil)
  3538. (while (setq w (pop words))
  3539. (when (and (string-match "\\`[-+]?{" w)
  3540. (not (string-match "}\\'" w)))
  3541. (while (and words (not (string-match "}\\'" (car words))))
  3542. (setq w (concat w " " (pop words))))
  3543. (setq w (concat w " " (pop words))))
  3544. (push w www))
  3545. (setq words (nreverse www)))
  3546. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3547. (when boolean
  3548. (let (wds w)
  3549. (while (setq w (pop words))
  3550. (if (or (equal (substring w 0 1) "\"")
  3551. (and (> (length w) 1)
  3552. (member (substring w 0 1) '("+" "-"))
  3553. (equal (substring w 1 2) "\"")))
  3554. (while (and words (not (equal (substring w -1) "\"")))
  3555. (setq w (concat w " " (pop words)))))
  3556. (and (string-match "\\`\\([-+]?\\)\"" w)
  3557. (setq w (replace-match "\\1" nil nil w)))
  3558. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3559. (push w wds))
  3560. (setq words (nreverse wds))))
  3561. (if boolean
  3562. (mapc (lambda (w)
  3563. (setq c (string-to-char w))
  3564. (if (equal c ?-)
  3565. (setq neg t w (substring w 1))
  3566. (if (equal c ?+)
  3567. (setq neg nil w (substring w 1))
  3568. (setq neg nil)))
  3569. (if (string-match "\\`{.*}\\'" w)
  3570. (setq re (substring w 1 -1))
  3571. (if full-words
  3572. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3573. (setq re (regexp-quote (downcase w)))))
  3574. (if neg (push re regexps-) (push re regexps+)))
  3575. words)
  3576. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3577. regexps+))
  3578. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3579. (if (not regexps+)
  3580. (setq regexp org-outline-regexp-bol)
  3581. (setq regexp (pop regexps+))
  3582. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  3583. regexp))))
  3584. (setq files (org-agenda-files nil 'ifmode))
  3585. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3586. (pop org-agenda-text-search-extra-files)
  3587. (setq files (org-add-archive-files files)))
  3588. (setq files (append files org-agenda-text-search-extra-files)
  3589. rtnall nil)
  3590. (while (setq file (pop files))
  3591. (setq ee nil)
  3592. (catch 'nextfile
  3593. (org-check-agenda-file file)
  3594. (setq buffer (if (file-exists-p file)
  3595. (org-get-agenda-file-buffer file)
  3596. (error "No such file %s" file)))
  3597. (if (not buffer)
  3598. ;; If file does not exist, make sure an error message is sent
  3599. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3600. file))))
  3601. (with-current-buffer buffer
  3602. (with-syntax-table (org-search-syntax-table)
  3603. (unless (eq major-mode 'org-mode)
  3604. (error "Agenda file %s is not in `org-mode'" file))
  3605. (let ((case-fold-search t))
  3606. (save-excursion
  3607. (save-restriction
  3608. (if org-agenda-restrict
  3609. (narrow-to-region org-agenda-restrict-begin
  3610. org-agenda-restrict-end)
  3611. (widen))
  3612. (goto-char (point-min))
  3613. (unless (or (org-at-heading-p)
  3614. (outline-next-heading))
  3615. (throw 'nextfile t))
  3616. (goto-char (max (point-min) (1- (point))))
  3617. (while (re-search-forward regexp nil t)
  3618. (org-back-to-heading t)
  3619. (skip-chars-forward "* ")
  3620. (setq beg (point-at-bol)
  3621. beg1 (point)
  3622. end (progn (outline-next-heading) (point)))
  3623. (catch :skip
  3624. (goto-char beg)
  3625. (org-agenda-skip)
  3626. (setq str (buffer-substring-no-properties
  3627. (point-at-bol)
  3628. (if hdl-only (point-at-eol) end)))
  3629. (mapc (lambda (wr) (when (string-match wr str)
  3630. (goto-char (1- end))
  3631. (throw :skip t)))
  3632. regexps-)
  3633. (mapc (lambda (wr) (unless (string-match wr str)
  3634. (goto-char (1- end))
  3635. (throw :skip t)))
  3636. (if todo-only
  3637. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3638. regexps+)
  3639. regexps+))
  3640. (goto-char beg)
  3641. (setq marker (org-agenda-new-marker (point))
  3642. category (org-get-category)
  3643. org-category-pos (get-text-property (point) 'org-category-position)
  3644. tags (org-get-tags-at (point))
  3645. txt (org-agenda-format-item
  3646. ""
  3647. (buffer-substring-no-properties
  3648. beg1 (point-at-eol))
  3649. category tags))
  3650. (org-add-props txt props
  3651. 'org-marker marker 'org-hd-marker marker
  3652. 'org-todo-regexp org-todo-regexp
  3653. 'org-complex-heading-regexp org-complex-heading-regexp
  3654. 'priority 1000 'org-category category
  3655. 'org-category-position org-category-pos
  3656. 'type "search")
  3657. (push txt ee)
  3658. (goto-char (1- end))))))))))
  3659. (setq rtn (nreverse ee))
  3660. (setq rtnall (append rtnall rtn)))
  3661. (if org-agenda-overriding-header
  3662. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3663. nil 'face 'org-agenda-structure) "\n")
  3664. (insert "Search words: ")
  3665. (add-text-properties (point-min) (1- (point))
  3666. (list 'face 'org-agenda-structure))
  3667. (setq pos (point))
  3668. (insert string "\n")
  3669. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3670. (setq pos (point))
  3671. (unless org-agenda-multi
  3672. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3673. (add-text-properties pos (1- (point))
  3674. (list 'face 'org-agenda-structure))))
  3675. (org-agenda-mark-header-line (point-min))
  3676. (when rtnall
  3677. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3678. (goto-char (point-min))
  3679. (or org-agenda-multi (org-fit-agenda-window))
  3680. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3681. (org-finalize-agenda)
  3682. (setq buffer-read-only t)))
  3683. ;;; Agenda TODO list
  3684. (defvar org-select-this-todo-keyword nil)
  3685. (defvar org-last-arg nil)
  3686. ;;;###autoload
  3687. (defun org-todo-list (arg)
  3688. "Show all (not done) TODO entries from all agenda file in a single list.
  3689. The prefix arg can be used to select a specific TODO keyword and limit
  3690. the list to these. When using \\[universal-argument], you will be prompted
  3691. for a keyword. A numeric prefix directly selects the Nth keyword in
  3692. `org-todo-keywords-1'."
  3693. (interactive "P")
  3694. (org-compile-prefix-format 'todo)
  3695. (org-set-sorting-strategy 'todo)
  3696. (org-prepare-agenda "TODO")
  3697. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3698. (let* ((today (org-today))
  3699. (date (calendar-gregorian-from-absolute today))
  3700. (kwds org-todo-keywords-for-agenda)
  3701. (completion-ignore-case t)
  3702. (org-select-this-todo-keyword
  3703. (if (stringp arg) arg
  3704. (and arg (integerp arg) (> arg 0)
  3705. (nth (1- arg) kwds))))
  3706. rtn rtnall files file pos)
  3707. (when (equal arg '(4))
  3708. (setq org-select-this-todo-keyword
  3709. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3710. (mapcar 'list kwds) nil nil)))
  3711. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3712. (org-set-local 'org-last-arg arg)
  3713. (setq org-agenda-redo-command
  3714. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3715. (setq files (org-agenda-files nil 'ifmode)
  3716. rtnall nil)
  3717. (while (setq file (pop files))
  3718. (catch 'nextfile
  3719. (org-check-agenda-file file)
  3720. (setq rtn (org-agenda-get-day-entries file date :todo))
  3721. (setq rtnall (append rtnall rtn))))
  3722. (if org-agenda-overriding-header
  3723. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3724. nil 'face 'org-agenda-structure) "\n")
  3725. (insert "Global list of TODO items of type: ")
  3726. (add-text-properties (point-min) (1- (point))
  3727. (list 'face 'org-agenda-structure
  3728. 'short-heading
  3729. (concat "ToDo: "
  3730. (or org-select-this-todo-keyword "ALL"))))
  3731. (org-agenda-mark-header-line (point-min))
  3732. (setq pos (point))
  3733. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3734. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3735. (setq pos (point))
  3736. (unless org-agenda-multi
  3737. (insert "Available with `N r': (0)ALL")
  3738. (let ((n 0) s)
  3739. (mapc (lambda (x)
  3740. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3741. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3742. (insert "\n "))
  3743. (insert " " s))
  3744. kwds))
  3745. (insert "\n"))
  3746. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3747. (org-agenda-mark-header-line (point-min))
  3748. (when rtnall
  3749. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3750. (goto-char (point-min))
  3751. (or org-agenda-multi (org-fit-agenda-window))
  3752. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3753. (org-finalize-agenda)
  3754. (setq buffer-read-only t)))
  3755. ;;; Agenda tags match
  3756. ;;;###autoload
  3757. (defun org-tags-view (&optional todo-only match)
  3758. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3759. The prefix arg TODO-ONLY limits the search to TODO entries."
  3760. (interactive "P")
  3761. (org-compile-prefix-format 'tags)
  3762. (org-set-sorting-strategy 'tags)
  3763. (let* ((org-tags-match-list-sublevels
  3764. org-tags-match-list-sublevels)
  3765. (completion-ignore-case t)
  3766. rtn rtnall files file pos matcher
  3767. buffer)
  3768. (when (and (stringp match) (not (string-match "\\S-" match)))
  3769. (setq match nil))
  3770. (setq matcher (org-make-tags-matcher match)
  3771. match (car matcher) matcher (cdr matcher))
  3772. (org-prepare-agenda (concat "TAGS " match))
  3773. (setq org-agenda-query-string match)
  3774. (setq org-agenda-redo-command
  3775. (list 'org-tags-view (list 'quote todo-only)
  3776. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3777. (setq files (org-agenda-files nil 'ifmode)
  3778. rtnall nil)
  3779. (while (setq file (pop files))
  3780. (catch 'nextfile
  3781. (org-check-agenda-file file)
  3782. (setq buffer (if (file-exists-p file)
  3783. (org-get-agenda-file-buffer file)
  3784. (error "No such file %s" file)))
  3785. (if (not buffer)
  3786. ;; If file does not exist, error message to agenda
  3787. (setq rtn (list
  3788. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3789. rtnall (append rtnall rtn))
  3790. (with-current-buffer buffer
  3791. (unless (eq major-mode 'org-mode)
  3792. (error "Agenda file %s is not in `org-mode'" file))
  3793. (save-excursion
  3794. (save-restriction
  3795. (if org-agenda-restrict
  3796. (narrow-to-region org-agenda-restrict-begin
  3797. org-agenda-restrict-end)
  3798. (widen))
  3799. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3800. (setq rtnall (append rtnall rtn))))))))
  3801. (if org-agenda-overriding-header
  3802. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3803. nil 'face 'org-agenda-structure) "\n")
  3804. (insert "Headlines with TAGS match: ")
  3805. (add-text-properties (point-min) (1- (point))
  3806. (list 'face 'org-agenda-structure
  3807. 'short-heading
  3808. (concat "Match: " match)))
  3809. (setq pos (point))
  3810. (insert match "\n")
  3811. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3812. (setq pos (point))
  3813. (unless org-agenda-multi
  3814. (insert "Press `C-u r' to search again with new search string\n"))
  3815. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3816. (org-agenda-mark-header-line (point-min))
  3817. (when rtnall
  3818. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3819. (goto-char (point-min))
  3820. (or org-agenda-multi (org-fit-agenda-window))
  3821. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3822. (org-finalize-agenda)
  3823. (setq buffer-read-only t)))
  3824. ;;; Agenda Finding stuck projects
  3825. (defvar org-agenda-skip-regexp nil
  3826. "Regular expression used in skipping subtrees for the agenda.
  3827. This is basically a temporary global variable that can be set and then
  3828. used by user-defined selections using `org-agenda-skip-function'.")
  3829. (defvar org-agenda-overriding-header nil
  3830. "When set during agenda, todo and tags searches it replaces the header.
  3831. This variable should not be set directly, but custom commands can bind it
  3832. in the options section.")
  3833. (defun org-agenda-skip-entry-when-regexp-matches ()
  3834. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3835. If yes, it returns the end position of this entry, causing agenda commands
  3836. to skip the entry but continuing the search in the subtree. This is a
  3837. function that can be put into `org-agenda-skip-function' for the duration
  3838. of a command."
  3839. (let ((end (save-excursion (org-end-of-subtree t)))
  3840. skip)
  3841. (save-excursion
  3842. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3843. (and skip end)))
  3844. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3845. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3846. If yes, it returns the end position of this tree, causing agenda commands
  3847. to skip this subtree. This is a function that can be put into
  3848. `org-agenda-skip-function' for the duration of a command."
  3849. (let ((end (save-excursion (org-end-of-subtree t)))
  3850. skip)
  3851. (save-excursion
  3852. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3853. (and skip end)))
  3854. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3855. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3856. If yes, it returns the end position of the current entry (NOT the tree),
  3857. causing agenda commands to skip the entry but continuing the search in
  3858. the subtree. This is a function that can be put into
  3859. `org-agenda-skip-function' for the duration of a command. An important
  3860. use of this function is for the stuck project list."
  3861. (let ((end (save-excursion (org-end-of-subtree t)))
  3862. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3863. skip)
  3864. (save-excursion
  3865. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3866. (and skip entry-end)))
  3867. (defun org-agenda-skip-entry-if (&rest conditions)
  3868. "Skip entry if any of CONDITIONS is true.
  3869. See `org-agenda-skip-if' for details."
  3870. (org-agenda-skip-if nil conditions))
  3871. (defun org-agenda-skip-subtree-if (&rest conditions)
  3872. "Skip entry if any of CONDITIONS is true.
  3873. See `org-agenda-skip-if' for details."
  3874. (org-agenda-skip-if t conditions))
  3875. (defun org-agenda-skip-if (subtree conditions)
  3876. "Checks current entity for CONDITIONS.
  3877. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3878. the entry (i.e. the text before the next heading) is checked.
  3879. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3880. from different tests. Valid conditions are:
  3881. scheduled Check if there is a scheduled cookie
  3882. notscheduled Check if there is no scheduled cookie
  3883. deadline Check if there is a deadline
  3884. notdeadline Check if there is no deadline
  3885. timestamp Check if there is a timestamp (also deadline or scheduled)
  3886. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3887. regexp Check if regexp matches
  3888. notregexp Check if regexp does not match.
  3889. todo Check if TODO keyword matches
  3890. nottodo Check if TODO keyword does not match
  3891. The regexp is taken from the conditions list, it must come right after
  3892. the `regexp' or `notregexp' element.
  3893. `todo' and `nottodo' accept as an argument a list of todo
  3894. keywords, which may include \"*\" to match any todo keyword.
  3895. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3896. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3897. Instead of a list, a keyword class may be given. For example:
  3898. (org-agenda-skip-entry-if 'nottodo 'done)
  3899. would skip entries that haven't been marked with any of \"DONE\"
  3900. keywords. Possible classes are: `todo', `done', `any'.
  3901. If any of these conditions is met, this function returns the end point of
  3902. the entity, causing the search to continue from there. This is a function
  3903. that can be put into `org-agenda-skip-function' for the duration of a command."
  3904. (let (beg end m)
  3905. (org-back-to-heading t)
  3906. (setq beg (point)
  3907. end (if subtree
  3908. (progn (org-end-of-subtree t) (point))
  3909. (progn (outline-next-heading) (1- (point)))))
  3910. (goto-char beg)
  3911. (and
  3912. (or
  3913. (and (memq 'scheduled conditions)
  3914. (re-search-forward org-scheduled-time-regexp end t))
  3915. (and (memq 'notscheduled conditions)
  3916. (not (re-search-forward org-scheduled-time-regexp end t)))
  3917. (and (memq 'deadline conditions)
  3918. (re-search-forward org-deadline-time-regexp end t))
  3919. (and (memq 'notdeadline conditions)
  3920. (not (re-search-forward org-deadline-time-regexp end t)))
  3921. (and (memq 'timestamp conditions)
  3922. (re-search-forward org-ts-regexp end t))
  3923. (and (memq 'nottimestamp conditions)
  3924. (not (re-search-forward org-ts-regexp end t)))
  3925. (and (setq m (memq 'regexp conditions))
  3926. (stringp (nth 1 m))
  3927. (re-search-forward (nth 1 m) end t))
  3928. (and (setq m (memq 'notregexp conditions))
  3929. (stringp (nth 1 m))
  3930. (not (re-search-forward (nth 1 m) end t)))
  3931. (and (or
  3932. (setq m (memq 'nottodo conditions))
  3933. (setq m (memq 'todo conditions)))
  3934. (org-agenda-skip-if-todo m end)))
  3935. end)))
  3936. (defun org-agenda-skip-if-todo (args end)
  3937. "Helper function for `org-agenda-skip-if', do not use it directly.
  3938. ARGS is a list with first element either `todo' or `nottodo'.
  3939. The remainder is either a list of TODO keywords, or a state symbol
  3940. `todo' or `done' or `any'."
  3941. (let ((kw (car args))
  3942. (arg (cadr args))
  3943. todo-wds todo-re)
  3944. (setq todo-wds
  3945. (org-uniquify
  3946. (cond
  3947. ((listp arg) ;; list of keywords
  3948. (if (member "*" arg)
  3949. (mapcar 'substring-no-properties org-todo-keywords-1)
  3950. arg))
  3951. ((symbolp arg) ;; keyword class name
  3952. (cond
  3953. ((eq arg 'todo)
  3954. (org-delete-all org-done-keywords
  3955. (mapcar 'substring-no-properties
  3956. org-todo-keywords-1)))
  3957. ((eq arg 'done) org-done-keywords)
  3958. ((eq arg 'any)
  3959. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3960. (setq todo-re
  3961. (concat "^\\*+[ \t]+\\<\\("
  3962. (mapconcat 'identity todo-wds "\\|")
  3963. "\\)\\>"))
  3964. (if (eq kw 'todo)
  3965. (re-search-forward todo-re end t)
  3966. (not (re-search-forward todo-re end t)))))
  3967. ;;;###autoload
  3968. (defun org-agenda-list-stuck-projects (&rest ignore)
  3969. "Create agenda view for projects that are stuck.
  3970. Stuck projects are project that have no next actions. For the definitions
  3971. of what a project is and how to check if it stuck, customize the variable
  3972. `org-stuck-projects'."
  3973. (interactive)
  3974. (let* ((org-agenda-skip-function
  3975. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3976. ;; We could have used org-agenda-skip-if here.
  3977. (org-agenda-overriding-header
  3978. (or org-agenda-overriding-header "List of stuck projects: "))
  3979. (matcher (nth 0 org-stuck-projects))
  3980. (todo (nth 1 org-stuck-projects))
  3981. (todo-wds (if (member "*" todo)
  3982. (progn
  3983. (org-prepare-agenda-buffers (org-agenda-files
  3984. nil 'ifmode))
  3985. (org-delete-all
  3986. org-done-keywords-for-agenda
  3987. (copy-sequence org-todo-keywords-for-agenda)))
  3988. todo))
  3989. (todo-re (concat "^\\*+[ \t]+\\("
  3990. (mapconcat 'identity todo-wds "\\|")
  3991. "\\)\\>"))
  3992. (tags (nth 2 org-stuck-projects))
  3993. (tags-re (if (member "*" tags)
  3994. (concat org-outline-regexp-bol
  3995. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  3996. (if tags
  3997. (concat org-outline-regexp-bol
  3998. ".*:\\("
  3999. (mapconcat 'identity tags "\\|")
  4000. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4001. (gen-re (nth 3 org-stuck-projects))
  4002. (re-list
  4003. (delq nil
  4004. (list
  4005. (if todo todo-re)
  4006. (if tags tags-re)
  4007. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4008. gen-re)))))
  4009. (setq org-agenda-skip-regexp
  4010. (if re-list
  4011. (mapconcat 'identity re-list "\\|")
  4012. (error "No information how to identify unstuck projects")))
  4013. (org-tags-view nil matcher)
  4014. (with-current-buffer org-agenda-buffer-name
  4015. (setq org-agenda-redo-command
  4016. '(org-agenda-list-stuck-projects
  4017. (or current-prefix-arg org-last-arg))))))
  4018. ;;; Diary integration
  4019. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4020. (defvar list-diary-entries-hook)
  4021. (defvar diary-time-regexp)
  4022. (defun org-get-entries-from-diary (date)
  4023. "Get the (Emacs Calendar) diary entries for DATE."
  4024. (require 'diary-lib)
  4025. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4026. (diary-display-hook '(fancy-diary-display))
  4027. (diary-display-function 'fancy-diary-display)
  4028. (pop-up-frames nil)
  4029. (list-diary-entries-hook
  4030. (cons 'org-diary-default-entry list-diary-entries-hook))
  4031. (diary-file-name-prefix-function nil) ; turn this feature off
  4032. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4033. entries
  4034. (org-disable-agenda-to-diary t))
  4035. (save-excursion
  4036. (save-window-excursion
  4037. (funcall (if (fboundp 'diary-list-entries)
  4038. 'diary-list-entries 'list-diary-entries)
  4039. date 1)))
  4040. (if (not (get-buffer diary-fancy-buffer))
  4041. (setq entries nil)
  4042. (with-current-buffer diary-fancy-buffer
  4043. (setq buffer-read-only nil)
  4044. (if (zerop (buffer-size))
  4045. ;; No entries
  4046. (setq entries nil)
  4047. ;; Omit the date and other unnecessary stuff
  4048. (org-agenda-cleanup-fancy-diary)
  4049. ;; Add prefix to each line and extend the text properties
  4050. (if (zerop (buffer-size))
  4051. (setq entries nil)
  4052. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4053. (setq entries
  4054. (with-temp-buffer
  4055. (insert entries) (goto-char (point-min))
  4056. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4057. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4058. (replace-match (concat "; " (match-string 1)))))
  4059. (buffer-string)))))
  4060. (set-buffer-modified-p nil)
  4061. (kill-buffer diary-fancy-buffer)))
  4062. (when entries
  4063. (setq entries (org-split-string entries "\n"))
  4064. (setq entries
  4065. (mapcar
  4066. (lambda (x)
  4067. (setq x (org-agenda-format-item "" x "Diary" nil 'time))
  4068. ;; Extend the text properties to the beginning of the line
  4069. (org-add-props x (text-properties-at (1- (length x)) x)
  4070. 'type "diary" 'date date 'face 'org-agenda-diary))
  4071. entries)))))
  4072. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4073. "Hook run when the fancy diary buffer is cleaned up.")
  4074. (defun org-agenda-cleanup-fancy-diary ()
  4075. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4076. This gets rid of the date, the underline under the date, and
  4077. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4078. date. It also removes lines that contain only whitespace."
  4079. (goto-char (point-min))
  4080. (if (looking-at ".*?:[ \t]*")
  4081. (progn
  4082. (replace-match "")
  4083. (re-search-forward "\n=+$" nil t)
  4084. (replace-match "")
  4085. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4086. (re-search-forward "\n=+$" nil t)
  4087. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4088. (goto-char (point-min))
  4089. (while (re-search-forward "^ +\n" nil t)
  4090. (replace-match ""))
  4091. (goto-char (point-min))
  4092. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4093. (replace-match ""))
  4094. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4095. ;; Make sure entries from the diary have the right text properties.
  4096. (eval-after-load "diary-lib"
  4097. '(if (boundp 'diary-modify-entry-list-string-function)
  4098. ;; We can rely on the hook, nothing to do
  4099. nil
  4100. ;; Hook not available, must use advice to make this work
  4101. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4102. "Make the position visible."
  4103. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4104. (stringp string)
  4105. buffer-file-name)
  4106. (setq string (org-modify-diary-entry-string string))))))
  4107. (defun org-modify-diary-entry-string (string)
  4108. "Add text properties to string, allowing org-mode to act on it."
  4109. (org-add-props string nil
  4110. 'mouse-face 'highlight
  4111. 'help-echo (if buffer-file-name
  4112. (format "mouse-2 or RET jump to diary file %s"
  4113. (abbreviate-file-name buffer-file-name))
  4114. "")
  4115. 'org-agenda-diary-link t
  4116. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4117. (defun org-diary-default-entry ()
  4118. "Add a dummy entry to the diary.
  4119. Needed to avoid empty dates which mess up holiday display."
  4120. ;; Catch the error if dealing with the new add-to-diary-alist
  4121. (when org-disable-agenda-to-diary
  4122. (condition-case nil
  4123. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4124. (error
  4125. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4126. (defun org-add-to-diary-list (&rest args)
  4127. (if (fboundp 'diary-add-to-list)
  4128. (apply 'diary-add-to-list args)
  4129. (apply 'add-to-diary-list args)))
  4130. (defvar org-diary-last-run-time nil)
  4131. ;;;###autoload
  4132. (defun org-diary (&rest args)
  4133. "Return diary information from org-files.
  4134. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4135. It accesses org files and extracts information from those files to be
  4136. listed in the diary. The function accepts arguments specifying what
  4137. items should be listed. For a list of arguments allowed here, see the
  4138. variable `org-agenda-entry-types'.
  4139. The call in the diary file should look like this:
  4140. &%%(org-diary) ~/path/to/some/orgfile.org
  4141. Use a separate line for each org file to check. Or, if you omit the file name,
  4142. all files listed in `org-agenda-files' will be checked automatically:
  4143. &%%(org-diary)
  4144. If you don't give any arguments (as in the example above), the default
  4145. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4146. So the example above may also be written as
  4147. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4148. The function expects the lisp variables `entry' and `date' to be provided
  4149. by the caller, because this is how the calendar works. Don't use this
  4150. function from a program - use `org-agenda-get-day-entries' instead."
  4151. (when (> (- (org-float-time)
  4152. org-agenda-last-marker-time)
  4153. 5)
  4154. (org-agenda-reset-markers))
  4155. (org-compile-prefix-format 'agenda)
  4156. (org-set-sorting-strategy 'agenda)
  4157. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4158. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4159. (list entry)
  4160. (org-agenda-files t)))
  4161. (time (org-float-time))
  4162. file rtn results)
  4163. (when (or (not org-diary-last-run-time)
  4164. (> (- time
  4165. org-diary-last-run-time)
  4166. 3))
  4167. (org-prepare-agenda-buffers files))
  4168. (setq org-diary-last-run-time time)
  4169. ;; If this is called during org-agenda, don't return any entries to
  4170. ;; the calendar. Org Agenda will list these entries itself.
  4171. (if org-disable-agenda-to-diary (setq files nil))
  4172. (while (setq file (pop files))
  4173. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4174. (setq results (append results rtn)))
  4175. (if results
  4176. (concat (org-finalize-agenda-entries results) "\n"))))
  4177. ;;; Agenda entry finders
  4178. (defun org-agenda-get-day-entries (file date &rest args)
  4179. "Does the work for `org-diary' and `org-agenda'.
  4180. FILE is the path to a file to be checked for entries. DATE is date like
  4181. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4182. which kind of entries should be extracted. For details about these, see
  4183. the documentation of `org-diary'."
  4184. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4185. (let* ((org-startup-folded nil)
  4186. (org-startup-align-all-tables nil)
  4187. (buffer (if (file-exists-p file)
  4188. (org-get-agenda-file-buffer file)
  4189. (error "No such file %s" file)))
  4190. arg results rtn deadline-results)
  4191. (if (not buffer)
  4192. ;; If file does not exist, make sure an error message ends up in diary
  4193. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4194. (with-current-buffer buffer
  4195. (unless (eq major-mode 'org-mode)
  4196. (error "Agenda file %s is not in `org-mode'" file))
  4197. (let ((case-fold-search nil))
  4198. (save-excursion
  4199. (save-restriction
  4200. (if org-agenda-restrict
  4201. (narrow-to-region org-agenda-restrict-begin
  4202. org-agenda-restrict-end)
  4203. (widen))
  4204. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4205. (while (setq arg (pop args))
  4206. (cond
  4207. ((and (eq arg :todo)
  4208. (equal date (calendar-gregorian-from-absolute
  4209. (org-today))))
  4210. (setq rtn (org-agenda-get-todos))
  4211. (setq results (append results rtn)))
  4212. ((eq arg :timestamp)
  4213. (setq rtn (org-agenda-get-blocks))
  4214. (setq results (append results rtn))
  4215. (setq rtn (org-agenda-get-timestamps))
  4216. (setq results (append results rtn)))
  4217. ((eq arg :sexp)
  4218. (setq rtn (org-agenda-get-sexps))
  4219. (setq results (append results rtn)))
  4220. ((eq arg :scheduled)
  4221. (setq rtn (org-agenda-get-scheduled deadline-results))
  4222. (setq results (append results rtn)))
  4223. ((eq arg :closed)
  4224. (setq rtn (org-agenda-get-progress))
  4225. (setq results (append results rtn)))
  4226. ((eq arg :deadline)
  4227. (setq rtn (org-agenda-get-deadlines))
  4228. (setq deadline-results (copy-sequence rtn))
  4229. (setq results (append results rtn))))))))
  4230. results))))
  4231. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4232. (defun org-agenda-get-todos ()
  4233. "Return the TODO information for agenda display."
  4234. (let* ((props (list 'face nil
  4235. 'done-face 'org-agenda-done
  4236. 'org-not-done-regexp org-not-done-regexp
  4237. 'org-todo-regexp org-todo-regexp
  4238. 'org-complex-heading-regexp org-complex-heading-regexp
  4239. 'mouse-face 'highlight
  4240. 'help-echo
  4241. (format "mouse-2 or RET jump to org file %s"
  4242. (abbreviate-file-name buffer-file-name))))
  4243. (regexp (format org-heading-keyword-regexp-format
  4244. (cond
  4245. ((and org-select-this-todo-keyword
  4246. (equal org-select-this-todo-keyword "*"))
  4247. org-todo-regexp)
  4248. (org-select-this-todo-keyword
  4249. (concat "\\("
  4250. (mapconcat 'identity
  4251. (org-split-string
  4252. org-select-this-todo-keyword
  4253. "|")
  4254. "\\|") "\\)"))
  4255. (t org-not-done-regexp))))
  4256. marker priority category org-category-pos tags todo-state
  4257. ee txt beg end)
  4258. (goto-char (point-min))
  4259. (while (re-search-forward regexp nil t)
  4260. (catch :skip
  4261. (save-match-data
  4262. (beginning-of-line)
  4263. (org-agenda-skip)
  4264. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4265. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4266. (goto-char (1+ beg))
  4267. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4268. (throw :skip nil)))
  4269. (goto-char (match-beginning 2))
  4270. (setq marker (org-agenda-new-marker (match-beginning 0))
  4271. category (org-get-category)
  4272. org-category-pos (get-text-property (point) 'org-category-position)
  4273. txt (org-trim
  4274. (buffer-substring (match-beginning 2) (match-end 0)))
  4275. tags (org-get-tags-at (point))
  4276. txt (org-agenda-format-item "" txt category tags)
  4277. priority (1+ (org-get-priority txt))
  4278. todo-state (org-get-todo-state))
  4279. (org-add-props txt props
  4280. 'org-marker marker 'org-hd-marker marker
  4281. 'priority priority 'org-category category
  4282. 'org-category-position org-category-pos
  4283. 'type "todo" 'todo-state todo-state)
  4284. (push txt ee)
  4285. (if org-agenda-todo-list-sublevels
  4286. (goto-char (match-end 2))
  4287. (org-end-of-subtree 'invisible))))
  4288. (nreverse ee)))
  4289. (defun org-agenda-todo-custom-ignore-p (time n)
  4290. "Check whether timestamp is farther away then n number of days.
  4291. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4292. `org-agenda-todo-ignore-scheduled' or
  4293. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4294. (let ((days (org-days-to-time time)))
  4295. (if (>= n 0)
  4296. (>= days n)
  4297. (<= days n))))
  4298. ;;;###autoload
  4299. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4300. (&optional end)
  4301. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4302. (when (or org-agenda-todo-ignore-with-date
  4303. org-agenda-todo-ignore-scheduled
  4304. org-agenda-todo-ignore-deadlines
  4305. org-agenda-todo-ignore-timestamp)
  4306. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4307. (save-excursion
  4308. (or (and org-agenda-todo-ignore-with-date
  4309. (re-search-forward org-ts-regexp end t))
  4310. (and org-agenda-todo-ignore-scheduled
  4311. (re-search-forward org-scheduled-time-regexp end t)
  4312. (cond
  4313. ((eq org-agenda-todo-ignore-scheduled 'future)
  4314. (> (org-days-to-time (match-string 1)) 0))
  4315. ((eq org-agenda-todo-ignore-scheduled 'past)
  4316. (<= (org-days-to-time (match-string 1)) 0))
  4317. ((numberp org-agenda-todo-ignore-scheduled)
  4318. (org-agenda-todo-custom-ignore-p
  4319. (match-string 1) org-agenda-todo-ignore-scheduled))
  4320. (t)))
  4321. (and org-agenda-todo-ignore-deadlines
  4322. (re-search-forward org-deadline-time-regexp end t)
  4323. (cond
  4324. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4325. ((eq org-agenda-todo-ignore-deadlines 'far)
  4326. (not (org-deadline-close (match-string 1))))
  4327. ((eq org-agenda-todo-ignore-deadlines 'future)
  4328. (> (org-days-to-time (match-string 1)) 0))
  4329. ((eq org-agenda-todo-ignore-deadlines 'past)
  4330. (<= (org-days-to-time (match-string 1)) 0))
  4331. ((numberp org-agenda-todo-ignore-deadlines)
  4332. (org-agenda-todo-custom-ignore-p
  4333. (match-string 1) org-agenda-todo-ignore-deadlines))
  4334. (t (org-deadline-close (match-string 1)))))
  4335. (and org-agenda-todo-ignore-timestamp
  4336. (let ((buffer (current-buffer))
  4337. (regexp
  4338. (concat
  4339. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4340. (start (point)))
  4341. ;; Copy current buffer into a temporary one
  4342. (with-temp-buffer
  4343. (insert-buffer-substring buffer start end)
  4344. (goto-char (point-min))
  4345. ;; Delete SCHEDULED and DEADLINE items
  4346. (while (re-search-forward regexp end t)
  4347. (delete-region (match-beginning 0) (match-end 0)))
  4348. (goto-char (point-min))
  4349. ;; No search for timestamp left
  4350. (when (re-search-forward org-ts-regexp nil t)
  4351. (cond
  4352. ((eq org-agenda-todo-ignore-timestamp 'future)
  4353. (> (org-days-to-time (match-string 1)) 0))
  4354. ((eq org-agenda-todo-ignore-timestamp 'past)
  4355. (<= (org-days-to-time (match-string 1)) 0))
  4356. ((numberp org-agenda-todo-ignore-timestamp)
  4357. (org-agenda-todo-custom-ignore-p
  4358. (match-string 1) org-agenda-todo-ignore-timestamp))
  4359. (t))))))))))
  4360. (defconst org-agenda-no-heading-message
  4361. "No heading for this item in buffer or region.")
  4362. (defun org-agenda-get-timestamps ()
  4363. "Return the date stamp information for agenda display."
  4364. (let* ((props (list 'face 'org-agenda-calendar-event
  4365. 'org-not-done-regexp org-not-done-regexp
  4366. 'org-todo-regexp org-todo-regexp
  4367. 'org-complex-heading-regexp org-complex-heading-regexp
  4368. 'mouse-face 'highlight
  4369. 'help-echo
  4370. (format "mouse-2 or RET jump to org file %s"
  4371. (abbreviate-file-name buffer-file-name))))
  4372. (d1 (calendar-absolute-from-gregorian date))
  4373. (remove-re
  4374. (concat
  4375. (regexp-quote
  4376. (format-time-string
  4377. "<%Y-%m-%d"
  4378. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4379. ".*?>"))
  4380. (regexp
  4381. (concat
  4382. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4383. (regexp-quote
  4384. (substring
  4385. (format-time-string
  4386. (car org-time-stamp-formats)
  4387. (apply 'encode-time ; DATE bound by calendar
  4388. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4389. 1 11))
  4390. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4391. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4392. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4393. donep tmp priority category org-category-pos ee txt timestr tags
  4394. b0 b3 e3 head todo-state end-of-match show-all)
  4395. (goto-char (point-min))
  4396. (while (setq end-of-match (re-search-forward regexp nil t))
  4397. (setq b0 (match-beginning 0)
  4398. b3 (match-beginning 3) e3 (match-end 3)
  4399. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4400. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4401. (member todo-state
  4402. org-agenda-repeating-timestamp-show-all)))
  4403. (catch :skip
  4404. (and (org-at-date-range-p) (throw :skip nil))
  4405. (org-agenda-skip)
  4406. (if (and (match-end 1)
  4407. (not (= d1 (org-time-string-to-absolute
  4408. (match-string 1) d1 nil show-all
  4409. (current-buffer) b0))))
  4410. (throw :skip nil))
  4411. (if (and e3
  4412. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4413. (throw :skip nil))
  4414. (setq tmp (buffer-substring (max (point-min)
  4415. (- b0 org-ds-keyword-length))
  4416. b0)
  4417. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4418. inactivep (= (char-after b0) ?\[)
  4419. deadlinep (string-match org-deadline-regexp tmp)
  4420. scheduledp (string-match org-scheduled-regexp tmp)
  4421. closedp (and org-agenda-include-inactive-timestamps
  4422. (string-match org-closed-string tmp))
  4423. clockp (and org-agenda-include-inactive-timestamps
  4424. (or (string-match org-clock-string tmp)
  4425. (string-match "]-+\\'" tmp)))
  4426. donep (member todo-state org-done-keywords))
  4427. (if (or scheduledp deadlinep closedp clockp
  4428. (and donep org-agenda-skip-timestamp-if-done))
  4429. (throw :skip t))
  4430. (if (string-match ">" timestr)
  4431. ;; substring should only run to end of time stamp
  4432. (setq timestr (substring timestr 0 (match-end 0))))
  4433. (setq marker (org-agenda-new-marker b0)
  4434. category (org-get-category b0)
  4435. org-category-pos (get-text-property b0 'org-category-position))
  4436. (save-excursion
  4437. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4438. (setq txt org-agenda-no-heading-message)
  4439. (goto-char (match-beginning 0))
  4440. (setq hdmarker (org-agenda-new-marker)
  4441. tags (org-get-tags-at))
  4442. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4443. (setq head (or (match-string 1) ""))
  4444. (setq txt (org-agenda-format-item
  4445. (if inactivep org-agenda-inactive-leader nil)
  4446. head category tags timestr
  4447. remove-re)))
  4448. (setq priority (org-get-priority txt))
  4449. (org-add-props txt props
  4450. 'org-marker marker 'org-hd-marker hdmarker)
  4451. (org-add-props txt nil 'priority priority
  4452. 'org-category category 'date date
  4453. 'org-category-position org-category-pos
  4454. 'todo-state todo-state
  4455. 'type "timestamp")
  4456. (push txt ee))
  4457. (if org-agenda-skip-additional-timestamps-same-entry
  4458. (outline-next-heading)
  4459. (goto-char end-of-match))))
  4460. (nreverse ee)))
  4461. (defun org-agenda-get-sexps ()
  4462. "Return the sexp information for agenda display."
  4463. (require 'diary-lib)
  4464. (let* ((props (list 'face 'org-agenda-calendar-sexp
  4465. 'mouse-face 'highlight
  4466. 'help-echo
  4467. (format "mouse-2 or RET jump to org file %s"
  4468. (abbreviate-file-name buffer-file-name))))
  4469. (regexp "^&?%%(")
  4470. marker category org-category-pos ee txt tags entry
  4471. result beg b sexp sexp-entry todo-state)
  4472. (goto-char (point-min))
  4473. (while (re-search-forward regexp nil t)
  4474. (catch :skip
  4475. (org-agenda-skip)
  4476. (setq beg (match-beginning 0))
  4477. (goto-char (1- (match-end 0)))
  4478. (setq b (point))
  4479. (forward-sexp 1)
  4480. (setq sexp (buffer-substring b (point)))
  4481. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4482. (org-trim (match-string 1))
  4483. ""))
  4484. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4485. (when result
  4486. (setq marker (org-agenda-new-marker beg)
  4487. category (org-get-category beg)
  4488. org-category-pos (get-text-property beg 'org-category-position)
  4489. todo-state (org-get-todo-state))
  4490. (dolist (r (if (stringp result)
  4491. (list result)
  4492. result)) ;; we expect a list here
  4493. (if (string-match "\\S-" r)
  4494. (setq txt r)
  4495. (setq txt "SEXP entry returned empty string"))
  4496. (setq txt (org-agenda-format-item
  4497. "" txt category tags 'time))
  4498. (org-add-props txt props 'org-marker marker)
  4499. (org-add-props txt nil
  4500. 'org-category category 'date date 'todo-state todo-state
  4501. 'org-category-position org-category-pos
  4502. 'type "sexp")
  4503. (push txt ee)))))
  4504. (nreverse ee)))
  4505. ;; Calendar sanity: define some functions that are independent of
  4506. ;; `calendar-date-style'.
  4507. ;; Normally I would like to use ISO format when calling the diary functions,
  4508. ;; but to make sure we still have Emacs 22 compatibility we bind
  4509. ;; also `european-calendar-style' and use european format
  4510. (defun org-anniversary (year month day &optional mark)
  4511. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4512. (org-no-warnings
  4513. (let ((calendar-date-style 'european) (european-calendar-style t))
  4514. (diary-anniversary day month year mark))))
  4515. (defun org-cyclic (N year month day &optional mark)
  4516. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4517. (org-no-warnings
  4518. (let ((calendar-date-style 'european) (european-calendar-style t))
  4519. (diary-cyclic N day month year mark))))
  4520. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4521. "Like `diary-block', but with fixed (ISO) order of arguments."
  4522. (org-no-warnings
  4523. (let ((calendar-date-style 'european) (european-calendar-style t))
  4524. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4525. (defun org-date (year month day &optional mark)
  4526. "Like `diary-date', but with fixed (ISO) order of arguments."
  4527. (org-no-warnings
  4528. (let ((calendar-date-style 'european) (european-calendar-style t))
  4529. (diary-date day month year mark))))
  4530. (defalias 'org-float 'diary-float)
  4531. ;; Define the` org-class' function
  4532. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4533. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4534. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  4535. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  4536. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  4537. `holidays', then any date that is known by the Emacs calendar to be a
  4538. holiday will also be skipped."
  4539. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4540. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4541. (d (calendar-absolute-from-gregorian date)))
  4542. (and
  4543. (<= date1 d)
  4544. (<= d date2)
  4545. (= (calendar-day-of-week date) dayname)
  4546. (or (not skip-weeks)
  4547. (progn
  4548. (require 'cal-iso)
  4549. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4550. (not (and (memq 'holidays skip-weeks)
  4551. (calendar-check-holidays date)))
  4552. entry)))
  4553. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4554. "Like `org-class', but honor `calendar-date-style'.
  4555. The order of the first 2 times 3 arguments depends on the variable
  4556. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4557. So for American calendars, give this as MONTH DAY YEAR, for European as
  4558. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4559. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4560. is any number of ISO weeks in the block period for which the item should
  4561. be skipped.
  4562. This function is here only for backward compatibility and it is deprecated,
  4563. please use `org-class' instead."
  4564. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4565. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4566. (org-class
  4567. (nth 2 date1) (car date1) (nth 1 date1)
  4568. (nth 2 date2) (car date2) (nth 1 date2)
  4569. dayname skip-weeks)))
  4570. (make-obsolete 'org-diary-class 'org-class "")
  4571. (defalias 'org-get-closed 'org-agenda-get-progress)
  4572. (defun org-agenda-get-progress ()
  4573. "Return the logged TODO entries for agenda display."
  4574. (let* ((props (list 'mouse-face 'highlight
  4575. 'org-not-done-regexp org-not-done-regexp
  4576. 'org-todo-regexp org-todo-regexp
  4577. 'org-complex-heading-regexp org-complex-heading-regexp
  4578. 'help-echo
  4579. (format "mouse-2 or RET jump to org file %s"
  4580. (abbreviate-file-name buffer-file-name))))
  4581. (items (if (consp org-agenda-show-log)
  4582. org-agenda-show-log
  4583. (if (eq org-agenda-show-log 'clockcheck)
  4584. '(clock)
  4585. org-agenda-log-mode-items)))
  4586. (parts
  4587. (delq nil
  4588. (list
  4589. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4590. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4591. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4592. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4593. (error "`org-agenda-log-mode-items' is empty")))
  4594. (regexp (concat
  4595. "\\(" parts-re "\\)"
  4596. " *\\["
  4597. (regexp-quote
  4598. (substring
  4599. (format-time-string
  4600. (car org-time-stamp-formats)
  4601. (apply 'encode-time ; DATE bound by calendar
  4602. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4603. 1 11))))
  4604. (org-agenda-search-headline-for-time nil)
  4605. marker hdmarker priority category org-category-pos tags closedp
  4606. statep clockp state ee txt extra timestr rest clocked)
  4607. (goto-char (point-min))
  4608. (while (re-search-forward regexp nil t)
  4609. (catch :skip
  4610. (org-agenda-skip)
  4611. (setq marker (org-agenda-new-marker (match-beginning 0))
  4612. closedp (equal (match-string 1) org-closed-string)
  4613. statep (equal (string-to-char (match-string 1)) ?-)
  4614. clockp (not (or closedp statep))
  4615. state (and statep (match-string 2))
  4616. category (org-get-category (match-beginning 0))
  4617. org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
  4618. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  4619. (when (string-match "\\]" timestr)
  4620. ;; substring should only run to end of time stamp
  4621. (setq rest (substring timestr (match-end 0))
  4622. timestr (substring timestr 0 (match-end 0)))
  4623. (if (and (not closedp) (not statep)
  4624. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  4625. rest))
  4626. (progn (setq timestr (concat (substring timestr 0 -1)
  4627. "-" (match-string 1 rest) "]"))
  4628. (setq clocked (match-string 2 rest)))
  4629. (setq clocked "-")))
  4630. (save-excursion
  4631. (setq extra
  4632. (cond
  4633. ((not org-agenda-log-mode-add-notes) nil)
  4634. (statep
  4635. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4636. (match-string 1)))
  4637. (clockp
  4638. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4639. (match-string 1)))))
  4640. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4641. (setq txt org-agenda-no-heading-message)
  4642. (goto-char (match-beginning 0))
  4643. (setq hdmarker (org-agenda-new-marker)
  4644. tags (org-get-tags-at))
  4645. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4646. (setq txt (match-string 1))
  4647. (when extra
  4648. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4649. (setq txt (concat (substring txt 0 (match-beginning 1))
  4650. " - " extra " " (match-string 2 txt)))
  4651. (setq txt (concat txt " - " extra))))
  4652. (setq txt (org-agenda-format-item
  4653. (cond
  4654. (closedp "Closed: ")
  4655. (statep (concat "State: (" state ")"))
  4656. (t (concat "Clocked: (" clocked ")")))
  4657. txt category tags timestr)))
  4658. (setq priority 100000)
  4659. (org-add-props txt props
  4660. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4661. 'priority priority 'org-category category
  4662. 'org-category-position org-category-pos
  4663. 'type "closed" 'date date
  4664. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4665. (push txt ee))
  4666. (goto-char (point-at-eol))))
  4667. (nreverse ee)))
  4668. (defun org-agenda-show-clocking-issues ()
  4669. "Add overlays, showing issues with clocking.
  4670. See also the user option `org-agenda-clock-consistency-checks'."
  4671. (interactive)
  4672. (let* ((pl org-agenda-clock-consistency-checks)
  4673. (re (concat "^[ \t]*"
  4674. org-clock-string
  4675. "[ \t]+"
  4676. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4677. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4678. (tlstart 0.)
  4679. (tlend 0.)
  4680. (maxtime (org-hh:mm-string-to-minutes
  4681. (or (plist-get pl :max-duration) "24:00")))
  4682. (mintime (org-hh:mm-string-to-minutes
  4683. (or (plist-get pl :min-duration) 0)))
  4684. (maxgap (org-hh:mm-string-to-minutes
  4685. ;; default 30:00 means never complain
  4686. (or (plist-get pl :max-gap) "30:00")))
  4687. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4688. (plist-get pl :gap-ok-around)))
  4689. (def-face (or (plist-get pl :default-face)
  4690. '((:background "DarkRed") (:foreground "white"))))
  4691. issue face m te ts dt ov)
  4692. (goto-char (point-min))
  4693. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4694. (setq issue nil face def-face)
  4695. (catch 'next
  4696. (setq m (org-get-at-bol 'org-marker)
  4697. te nil ts nil)
  4698. (unless (and m (markerp m))
  4699. (setq issue "No valid clock line") (throw 'next t))
  4700. (org-with-point-at m
  4701. (save-excursion
  4702. (goto-char (point-at-bol))
  4703. (unless (looking-at re)
  4704. (error "No valid Clock line")
  4705. (throw 'next t))
  4706. (unless (match-end 3)
  4707. (setq issue "No end time"
  4708. face (or (plist-get pl :no-end-time-face) face))
  4709. (throw 'next t))
  4710. (setq ts (match-string 1)
  4711. te (match-string 3)
  4712. ts (org-float-time
  4713. (apply 'encode-time (org-parse-time-string ts)))
  4714. te (org-float-time
  4715. (apply 'encode-time (org-parse-time-string te)))
  4716. dt (- te ts))))
  4717. (cond
  4718. ((> dt (* 60 maxtime))
  4719. ;; a very long clocking chunk
  4720. (setq issue (format "Clocking interval is very long: %s"
  4721. (org-minutes-to-hh:mm-string
  4722. (floor (/ (float dt) 60.))))
  4723. face (or (plist-get pl :long-face) face)))
  4724. ((< dt (* 60 mintime))
  4725. ;; a very short clocking chunk
  4726. (setq issue (format "Clocking interval is very short: %s"
  4727. (org-minutes-to-hh:mm-string
  4728. (floor (/ (float dt) 60.))))
  4729. face (or (plist-get pl :short-face) face)))
  4730. ((and (> tlend 0) (< ts tlend))
  4731. ;; Two clock entries are overlapping
  4732. (setq issue (format "Clocking overlap: %d minutes"
  4733. (/ (- tlend ts) 60))
  4734. face (or (plist-get pl :overlap-face) face)))
  4735. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4736. ;; There is a gap, lets see if we need to report it
  4737. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4738. (setq issue (format "Clocking gap: %d minutes"
  4739. (/ (- ts tlend) 60))
  4740. face (or (plist-get pl :gap-face) face))))
  4741. (t nil)))
  4742. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4743. (when issue
  4744. ;; OK, there was some issue, add an overlay to show the issue
  4745. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4746. (overlay-put ov 'before-string
  4747. (concat
  4748. (org-add-props
  4749. (format "%-43s" (concat " " issue))
  4750. nil
  4751. 'face face)
  4752. "\n"))
  4753. (overlay-put ov 'evaporate t)))))
  4754. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4755. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4756. (catch 'exit
  4757. (unless ok-list
  4758. ;; there are no OK times for gaps...
  4759. (throw 'exit nil))
  4760. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4761. ;; This is more than 24 hours, so it is OK.
  4762. ;; because we have at least one OK time, that must be in the
  4763. ;; 24 hour interval.
  4764. (throw 'exit t))
  4765. ;; We have a shorter gap.
  4766. ;; Now we have to get the minute of the day when these times are
  4767. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4768. (t2dec (decode-time (seconds-to-time t2)))
  4769. ;; compute the minute on the day
  4770. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4771. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4772. (when (< min2 min1)
  4773. ;; if min2 is smaller than min1, this means it is on the next day.
  4774. ;; Wrap it to after midnight.
  4775. (setq min2 (+ min2 1440)))
  4776. ;; Now check if any of the OK times is in the gap
  4777. (mapc (lambda (x)
  4778. ;; Wrap the time to after midnight if necessary
  4779. (if (< x min1) (setq x (+ x 1440)))
  4780. ;; Check if in interval
  4781. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  4782. ok-list)
  4783. ;; Nope, this gap is not OK
  4784. nil)))
  4785. (defun org-agenda-get-deadlines ()
  4786. "Return the deadline information for agenda display."
  4787. (let* ((props (list 'mouse-face 'highlight
  4788. 'org-not-done-regexp org-not-done-regexp
  4789. 'org-todo-regexp org-todo-regexp
  4790. 'org-complex-heading-regexp org-complex-heading-regexp
  4791. 'help-echo
  4792. (format "mouse-2 or RET jump to org file %s"
  4793. (abbreviate-file-name buffer-file-name))))
  4794. (regexp org-deadline-time-regexp)
  4795. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4796. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4797. d2 diff dfrac wdays pos pos1 category org-category-pos
  4798. tags suppress-prewarning ee txt head face s todo-state
  4799. show-all upcomingp donep timestr)
  4800. (goto-char (point-min))
  4801. (while (re-search-forward regexp nil t)
  4802. (setq suppress-prewarning nil)
  4803. (catch :skip
  4804. (org-agenda-skip)
  4805. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4806. (save-match-data
  4807. (string-match org-scheduled-time-regexp
  4808. (buffer-substring (point-at-bol)
  4809. (point-at-eol)))))
  4810. (setq suppress-prewarning
  4811. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4812. org-agenda-skip-deadline-prewarning-if-scheduled
  4813. 0)))
  4814. (setq s (match-string 1)
  4815. txt nil
  4816. pos (1- (match-beginning 1))
  4817. todo-state (save-match-data (org-get-todo-state))
  4818. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4819. (member todo-state
  4820. org-agenda-repeating-timestamp-show-all))
  4821. d2 (org-time-string-to-absolute
  4822. (match-string 1) d1 'past show-all
  4823. (current-buffer) pos)
  4824. diff (- d2 d1)
  4825. wdays (if suppress-prewarning
  4826. (let ((org-deadline-warning-days suppress-prewarning))
  4827. (org-get-wdays s))
  4828. (org-get-wdays s))
  4829. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  4830. upcomingp (and todayp (> diff 0)))
  4831. ;; When to show a deadline in the calendar:
  4832. ;; If the expiration is within wdays warning time.
  4833. ;; Past-due deadlines are only shown on the current date
  4834. (if (and (or (and (<= diff wdays)
  4835. (and todayp (not org-agenda-only-exact-dates)))
  4836. (= diff 0)))
  4837. (save-excursion
  4838. ;; (setq todo-state (org-get-todo-state))
  4839. (setq donep (member todo-state org-done-keywords))
  4840. (if (and donep
  4841. (or org-agenda-skip-deadline-if-done
  4842. (not (= diff 0))))
  4843. (setq txt nil)
  4844. (setq category (org-get-category)
  4845. org-category-pos (get-text-property (point) 'org-category-position))
  4846. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4847. (setq txt org-agenda-no-heading-message)
  4848. (goto-char (match-end 0))
  4849. (setq pos1 (match-beginning 0))
  4850. (setq tags (org-get-tags-at pos1))
  4851. (setq head (buffer-substring-no-properties
  4852. (point)
  4853. (progn (skip-chars-forward "^\r\n")
  4854. (point))))
  4855. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4856. (setq timestr
  4857. (concat (substring s (match-beginning 1)) " "))
  4858. (setq timestr 'time))
  4859. (setq txt (org-agenda-format-item
  4860. (if (= diff 0)
  4861. (car org-agenda-deadline-leaders)
  4862. (if (functionp
  4863. (nth 1 org-agenda-deadline-leaders))
  4864. (funcall
  4865. (nth 1 org-agenda-deadline-leaders)
  4866. diff date)
  4867. (format (nth 1 org-agenda-deadline-leaders)
  4868. diff)))
  4869. head category tags
  4870. (if (not (= diff 0)) nil timestr)))))
  4871. (when txt
  4872. (setq face (org-agenda-deadline-face dfrac))
  4873. (org-add-props txt props
  4874. 'org-marker (org-agenda-new-marker pos)
  4875. 'org-hd-marker (org-agenda-new-marker pos1)
  4876. 'priority (+ (- diff)
  4877. (org-get-priority txt))
  4878. 'org-category category
  4879. 'org-category-position org-category-pos
  4880. 'todo-state todo-state
  4881. 'type (if upcomingp "upcoming-deadline" "deadline")
  4882. 'date (if upcomingp date d2)
  4883. 'face (if donep 'org-agenda-done face)
  4884. 'undone-face face 'done-face 'org-agenda-done)
  4885. (push txt ee))))))
  4886. (nreverse ee)))
  4887. (defun org-agenda-deadline-face (fraction)
  4888. "Return the face to displaying a deadline item.
  4889. FRACTION is what fraction of the head-warning time has passed."
  4890. (let ((faces org-agenda-deadline-faces) f)
  4891. (catch 'exit
  4892. (while (setq f (pop faces))
  4893. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4894. (defun org-agenda-get-scheduled (&optional deadline-results)
  4895. "Return the scheduled information for agenda display."
  4896. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4897. 'org-todo-regexp org-todo-regexp
  4898. 'org-complex-heading-regexp org-complex-heading-regexp
  4899. 'done-face 'org-agenda-done
  4900. 'mouse-face 'highlight
  4901. 'help-echo
  4902. (format "mouse-2 or RET jump to org file %s"
  4903. (abbreviate-file-name buffer-file-name))))
  4904. (regexp org-scheduled-time-regexp)
  4905. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4906. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4907. mm
  4908. (deadline-position-alist
  4909. (mapcar (lambda (a) (and (setq mm (get-text-property
  4910. 0 'org-hd-marker a))
  4911. (cons (marker-position mm) a)))
  4912. deadline-results))
  4913. d2 diff pos pos1 category org-category-pos tags donep
  4914. ee txt head pastschedp todo-state face timestr s habitp show-all)
  4915. (goto-char (point-min))
  4916. (while (re-search-forward regexp nil t)
  4917. (catch :skip
  4918. (org-agenda-skip)
  4919. (setq s (match-string 1)
  4920. txt nil
  4921. pos (1- (match-beginning 1))
  4922. todo-state (save-match-data (org-get-todo-state))
  4923. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4924. (member todo-state
  4925. org-agenda-repeating-timestamp-show-all))
  4926. d2 (org-time-string-to-absolute
  4927. (match-string 1) d1 'past show-all
  4928. (current-buffer) pos)
  4929. diff (- d2 d1))
  4930. (setq pastschedp (and todayp (< diff 0)))
  4931. ;; When to show a scheduled item in the calendar:
  4932. ;; If it is on or past the date.
  4933. (when (or (and (< diff 0)
  4934. (< (abs diff) org-scheduled-past-days)
  4935. (and todayp (not org-agenda-only-exact-dates)))
  4936. (= diff 0))
  4937. (save-excursion
  4938. (setq donep (member todo-state org-done-keywords))
  4939. (if (and donep
  4940. (or org-agenda-skip-scheduled-if-done
  4941. (not (= diff 0))
  4942. (and (functionp 'org-is-habit-p)
  4943. (org-is-habit-p))))
  4944. (setq txt nil)
  4945. (setq habitp (and (functionp 'org-is-habit-p)
  4946. (org-is-habit-p)))
  4947. (setq category (org-get-category)
  4948. org-category-pos (get-text-property (point) 'org-category-position))
  4949. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4950. (setq txt org-agenda-no-heading-message)
  4951. (goto-char (match-end 0))
  4952. (setq pos1 (match-beginning 0))
  4953. (if habitp
  4954. (if (or (not org-habit-show-habits)
  4955. (and (not todayp)
  4956. org-habit-show-habits-only-for-today))
  4957. (throw :skip nil))
  4958. (if (and
  4959. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4960. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4961. pastschedp))
  4962. (setq mm (assoc pos1 deadline-position-alist)))
  4963. (throw :skip nil)))
  4964. (setq tags (org-get-tags-at))
  4965. (setq head (buffer-substring-no-properties
  4966. (point)
  4967. (progn (skip-chars-forward "^\r\n") (point))))
  4968. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4969. (setq timestr
  4970. (concat (substring s (match-beginning 1)) " "))
  4971. (setq timestr 'time))
  4972. (setq txt (org-agenda-format-item
  4973. (if (= diff 0)
  4974. (car org-agenda-scheduled-leaders)
  4975. (format (nth 1 org-agenda-scheduled-leaders)
  4976. (- 1 diff)))
  4977. head category tags
  4978. (if (not (= diff 0)) nil timestr)
  4979. nil habitp))))
  4980. (when txt
  4981. (setq face
  4982. (cond
  4983. ((and (not habitp) pastschedp)
  4984. 'org-scheduled-previously)
  4985. (todayp 'org-scheduled-today)
  4986. (t 'org-scheduled))
  4987. habitp (and habitp (org-habit-parse-todo)))
  4988. (org-add-props txt props
  4989. 'undone-face face
  4990. 'face (if donep 'org-agenda-done face)
  4991. 'org-marker (org-agenda-new-marker pos)
  4992. 'org-hd-marker (org-agenda-new-marker pos1)
  4993. 'type (if pastschedp "past-scheduled" "scheduled")
  4994. 'date (if pastschedp d2 date)
  4995. 'priority (if habitp
  4996. (org-habit-get-priority habitp)
  4997. (+ 94 (- 5 diff) (org-get-priority txt)))
  4998. 'org-category category
  4999. 'org-category-position org-category-pos
  5000. 'org-habit-p habitp
  5001. 'todo-state todo-state)
  5002. (push txt ee))))))
  5003. (nreverse ee)))
  5004. (defun org-agenda-get-blocks ()
  5005. "Return the date-range information for agenda display."
  5006. (let* ((props (list 'face nil
  5007. 'org-not-done-regexp org-not-done-regexp
  5008. 'org-todo-regexp org-todo-regexp
  5009. 'org-complex-heading-regexp org-complex-heading-regexp
  5010. 'mouse-face 'highlight
  5011. 'help-echo
  5012. (format "mouse-2 or RET jump to org file %s"
  5013. (abbreviate-file-name buffer-file-name))))
  5014. (regexp org-tr-regexp)
  5015. (d0 (calendar-absolute-from-gregorian date))
  5016. marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
  5017. todo-state tags pos head donep)
  5018. (goto-char (point-min))
  5019. (while (re-search-forward regexp nil t)
  5020. (catch :skip
  5021. (org-agenda-skip)
  5022. (setq pos (point))
  5023. (let ((start-time (match-string 1))
  5024. (end-time (match-string 2)))
  5025. (setq s1 (match-string 1)
  5026. s2 (match-string 2)
  5027. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5028. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5029. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5030. ;; Only allow days between the limits, because the normal
  5031. ;; date stamps will catch the limits.
  5032. (save-excursion
  5033. (setq todo-state (org-get-todo-state))
  5034. (setq donep (member todo-state org-done-keywords))
  5035. (if (and donep org-agenda-skip-timestamp-if-done)
  5036. (throw :skip t))
  5037. (setq marker (org-agenda-new-marker (point)))
  5038. (setq category (org-get-category)
  5039. org-category-pos (get-text-property (point) 'org-category-position))
  5040. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5041. (setq txt org-agenda-no-heading-message)
  5042. (goto-char (match-beginning 0))
  5043. (setq hdmarker (org-agenda-new-marker (point)))
  5044. (setq tags (org-get-tags-at))
  5045. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5046. (setq head (match-string 1))
  5047. (let ((remove-re
  5048. (if org-agenda-remove-timeranges-from-blocks
  5049. (concat
  5050. "<" (regexp-quote s1) ".*?>"
  5051. "--"
  5052. "<" (regexp-quote s2) ".*?>")
  5053. nil)))
  5054. (setq txt (org-agenda-format-item
  5055. (format
  5056. (nth (if (= d1 d2) 0 1)
  5057. org-agenda-timerange-leaders)
  5058. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5059. head category tags
  5060. (cond ((and (= d1 d0) (= d2 d0))
  5061. (concat "<" start-time ">--<" end-time ">"))
  5062. ((= d1 d0)
  5063. (concat "<" start-time ">"))
  5064. ((= d2 d0)
  5065. (concat "<" end-time ">"))
  5066. (t nil))
  5067. remove-re))))
  5068. (org-add-props txt props
  5069. 'org-marker marker 'org-hd-marker hdmarker
  5070. 'type "block" 'date date
  5071. 'todo-state todo-state
  5072. 'priority (org-get-priority txt) 'org-category category
  5073. 'org-category-position org-category-pos)
  5074. (push txt ee))))
  5075. (goto-char pos)))
  5076. ;; Sort the entries by expiration date.
  5077. (nreverse ee)))
  5078. ;;; Agenda presentation and sorting
  5079. (defvar org-prefix-has-time nil
  5080. "A flag, set by `org-compile-prefix-format'.
  5081. The flag is set if the currently compiled format contains a `%t'.")
  5082. (defvar org-prefix-has-tag nil
  5083. "A flag, set by `org-compile-prefix-format'.
  5084. The flag is set if the currently compiled format contains a `%T'.")
  5085. (defvar org-prefix-has-effort nil
  5086. "A flag, set by `org-compile-prefix-format'.
  5087. The flag is set if the currently compiled format contains a `%e'.")
  5088. (defvar org-prefix-category-length nil
  5089. "Used by `org-compile-prefix-format' to remember the category field width.")
  5090. (defvar org-prefix-category-max-length nil
  5091. "Used by `org-compile-prefix-format' to remember the category field width.")
  5092. (defun org-agenda-get-category-icon (category)
  5093. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5094. (dolist (entry org-agenda-category-icon-alist)
  5095. (when (org-string-match-p (car entry) category)
  5096. (if (listp (cadr entry))
  5097. (return (cadr entry))
  5098. (return (apply 'create-image (cdr entry)))))))
  5099. (defun org-agenda-format-item (extra txt &optional category tags dotime
  5100. remove-re habitp)
  5101. "Format TXT to be inserted into the agenda buffer.
  5102. In particular, it adds the prefix and corresponding text properties. EXTRA
  5103. must be a string and replaces the `%s' specifier in the prefix format.
  5104. CATEGORY (string, symbol or nil) may be used to overrule the default
  5105. category taken from local variable or file name. It will replace the `%c'
  5106. specifier in the format. DOTIME, when non-nil, indicates that a
  5107. time-of-day should be extracted from TXT for sorting of this entry, and for
  5108. the `%t' specifier in the format. When DOTIME is a string, this string is
  5109. searched for a time before TXT is. TAGS can be the tags of the headline.
  5110. Any match of REMOVE-RE will be removed from TXT."
  5111. (save-match-data
  5112. ;; Diary entries sometimes have extra whitespace at the beginning
  5113. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5114. ;; Fix the tags part in txt
  5115. (setq txt (org-agenda-fix-displayed-tags
  5116. txt tags
  5117. org-agenda-show-inherited-tags
  5118. org-agenda-hide-tags-regexp))
  5119. (let* ((category (or category
  5120. (if (stringp org-category)
  5121. org-category
  5122. (and org-category (symbol-name org-category)))
  5123. (if buffer-file-name
  5124. (file-name-sans-extension
  5125. (file-name-nondirectory buffer-file-name))
  5126. "")))
  5127. (category-icon (org-agenda-get-category-icon category))
  5128. (category-icon (if category-icon
  5129. (propertize " " 'display category-icon)
  5130. ""))
  5131. ;; time, tag, effort are needed for the eval of the prefix format
  5132. (tag (if tags (nth (1- (length tags)) tags) ""))
  5133. time effort neffort
  5134. (ts (if dotime (concat
  5135. (if (stringp dotime) dotime "")
  5136. (and org-agenda-search-headline-for-time txt))))
  5137. (time-of-day (and dotime (org-get-time-of-day ts)))
  5138. stamp plain s0 s1 s2 rtn srp l
  5139. duration thecategory)
  5140. (and (eq major-mode 'org-mode) buffer-file-name
  5141. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5142. (when (and dotime time-of-day)
  5143. ;; Extract starting and ending time and move them to prefix
  5144. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5145. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5146. (setq s0 (match-string 0 ts)
  5147. srp (and stamp (match-end 3))
  5148. s1 (match-string (if plain 1 2) ts)
  5149. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5150. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5151. ;; them, we might want to remove them there to avoid duplication.
  5152. ;; The user can turn this off with a variable.
  5153. (if (and org-prefix-has-time
  5154. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5155. (string-match (concat (regexp-quote s0) " *") txt)
  5156. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5157. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5158. (= (match-beginning 0) 0)
  5159. t))
  5160. (setq txt (replace-match "" nil nil txt))))
  5161. ;; Normalize the time(s) to 24 hour
  5162. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5163. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5164. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5165. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5166. (setq s2
  5167. (org-minutes-to-hh:mm-string
  5168. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5169. ;; Compute the duration
  5170. (when s2
  5171. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5172. (org-hh:mm-string-to-minutes s1)))))
  5173. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5174. txt)
  5175. ;; Tags are in the string
  5176. (if (or (eq org-agenda-remove-tags t)
  5177. (and org-agenda-remove-tags
  5178. org-prefix-has-tag))
  5179. (setq txt (replace-match "" t t txt))
  5180. (setq txt (replace-match
  5181. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5182. (match-string 2 txt))
  5183. t t txt))))
  5184. (when (eq major-mode 'org-mode)
  5185. (setq effort
  5186. (condition-case nil
  5187. (org-get-effort
  5188. (or (get-text-property 0 'org-hd-marker txt)
  5189. (get-text-property 0 'org-marker txt)))
  5190. (error nil)))
  5191. (when effort
  5192. (setq neffort (org-duration-string-to-minutes effort)
  5193. effort (setq effort (concat "[" effort "]")))))
  5194. ;; prevent erroring out with %e format when there is no effort
  5195. (or effort (setq effort ""))
  5196. (when remove-re
  5197. (while (string-match remove-re txt)
  5198. (setq txt (replace-match "" t t txt))))
  5199. ;; Set org-heading property on `txt' to mark the start of the
  5200. ;; heading.
  5201. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5202. ;; Prepare the variables needed in the eval of the compiled format
  5203. (setq time (cond (s2 (concat
  5204. (org-agenda-time-of-day-to-ampm-maybe s1)
  5205. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5206. (if org-agenda-timegrid-use-ampm " ")))
  5207. (s1 (concat
  5208. (org-agenda-time-of-day-to-ampm-maybe s1)
  5209. (if org-agenda-timegrid-use-ampm
  5210. "........ "
  5211. "......")))
  5212. (t ""))
  5213. extra (or (and (not habitp) extra) "")
  5214. category (if (symbolp category) (symbol-name category) category)
  5215. thecategory (copy-sequence category))
  5216. (if (string-match org-bracket-link-regexp category)
  5217. (progn
  5218. (setq l (if (match-end 3)
  5219. (- (match-end 3) (match-beginning 3))
  5220. (- (match-end 1) (match-beginning 1))))
  5221. (when (< l (or org-prefix-category-length 0))
  5222. (setq category (copy-sequence category))
  5223. (org-add-props category nil
  5224. 'extra-space (make-string
  5225. (- org-prefix-category-length l 1) ?\ ))))
  5226. (if (and org-prefix-category-max-length
  5227. (>= (length category) org-prefix-category-max-length))
  5228. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5229. ;; Evaluate the compiled format
  5230. (setq rtn (concat (eval org-prefix-format-compiled) txt))
  5231. ;; And finally add the text properties
  5232. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5233. (org-add-props rtn nil
  5234. 'org-category (if thecategory (downcase thecategory) category)
  5235. 'tags (mapcar 'org-downcase-keep-props tags)
  5236. 'org-highest-priority org-highest-priority
  5237. 'org-lowest-priority org-lowest-priority
  5238. 'time-of-day time-of-day
  5239. 'duration duration
  5240. 'effort effort
  5241. 'effort-minutes neffort
  5242. 'txt txt
  5243. 'time time
  5244. 'extra extra
  5245. 'format org-prefix-format-compiled
  5246. 'dotime dotime))))
  5247. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5248. "Remove tags string from TXT, and add a modified list of tags.
  5249. The modified list may contain inherited tags, and tags matched by
  5250. `org-agenda-hide-tags-regexp' will be removed."
  5251. (when (or add-inherited hide-re)
  5252. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5253. (setq txt (substring txt 0 (match-beginning 0))))
  5254. (setq tags
  5255. (delq nil
  5256. (mapcar (lambda (tg)
  5257. (if (or (and hide-re (string-match hide-re tg))
  5258. (and (not add-inherited)
  5259. (get-text-property 0 'inherited tg)))
  5260. nil
  5261. tg))
  5262. tags)))
  5263. (when tags
  5264. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5265. i)
  5266. (setq txt (concat txt " :"
  5267. (mapconcat
  5268. (lambda (x)
  5269. (setq i (get-text-property 0 'inherited x))
  5270. (if (and have-i (not i))
  5271. (progn
  5272. (setq have-i nil)
  5273. (concat ":" x))
  5274. x))
  5275. tags ":")
  5276. (if have-i "::" ":"))))))
  5277. txt)
  5278. (defun org-downcase-keep-props (s)
  5279. (let ((props (text-properties-at 0 s)))
  5280. (setq s (downcase s))
  5281. (add-text-properties 0 (length s) props s)
  5282. s))
  5283. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5284. (defvar org-agenda-sorting-strategy-selected nil)
  5285. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5286. (catch 'exit
  5287. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5288. ((and todayp (member 'today (car org-agenda-time-grid))))
  5289. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5290. ((member 'weekly (car org-agenda-time-grid)))
  5291. (t (throw 'exit list)))
  5292. (let* ((have (delq nil (mapcar
  5293. (lambda (x) (get-text-property 1 'time-of-day x))
  5294. list)))
  5295. (string (nth 1 org-agenda-time-grid))
  5296. (gridtimes (nth 2 org-agenda-time-grid))
  5297. (req (car org-agenda-time-grid))
  5298. (remove (member 'remove-match req))
  5299. new time)
  5300. (if (and (member 'require-timed req) (not have))
  5301. ;; don't show empty grid
  5302. (throw 'exit list))
  5303. (while (setq time (pop gridtimes))
  5304. (unless (and remove (member time have))
  5305. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5306. (push (org-agenda-format-item
  5307. nil string "" nil
  5308. (concat (substring time 0 -2) ":" (substring time -2)))
  5309. new)
  5310. (put-text-property
  5311. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5312. (when (and todayp org-agenda-show-current-time-in-grid)
  5313. (push (org-agenda-format-item
  5314. nil
  5315. org-agenda-current-time-string
  5316. "" nil
  5317. (format-time-string "%H:%M "))
  5318. new)
  5319. (put-text-property
  5320. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5321. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5322. (append new list)
  5323. (append list new)))))
  5324. (defun org-compile-prefix-format (key)
  5325. "Compile the prefix format into a Lisp form that can be evaluated.
  5326. The resulting form is returned and stored in the variable
  5327. `org-prefix-format-compiled'."
  5328. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5329. org-prefix-category-length nil
  5330. org-prefix-has-effort nil)
  5331. (let ((s (cond
  5332. ((stringp org-agenda-prefix-format)
  5333. org-agenda-prefix-format)
  5334. ((assq key org-agenda-prefix-format)
  5335. (cdr (assq key org-agenda-prefix-format)))
  5336. (t " %-12:c%?-12t% s")))
  5337. (start 0)
  5338. varform vars var e c f opt)
  5339. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5340. s start)
  5341. (setq var (or (cdr (assoc (match-string 4 s)
  5342. '(("c" . category) ("t" . time) ("s" . extra)
  5343. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5344. 'eval)
  5345. c (or (match-string 3 s) "")
  5346. opt (match-beginning 1)
  5347. start (1+ (match-beginning 0)))
  5348. (if (equal var 'time) (setq org-prefix-has-time t))
  5349. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5350. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5351. (setq f (concat "%" (match-string 2 s) "s"))
  5352. (when (equal var 'category)
  5353. (setq org-prefix-category-length
  5354. (floor (abs (string-to-number (match-string 2 s)))))
  5355. (setq org-prefix-category-max-length
  5356. (let ((x (match-string 2 s)))
  5357. (save-match-data
  5358. (if (string-match "\\.[0-9]+" x)
  5359. (string-to-number (substring (match-string 0 x) 1)))))))
  5360. (if (eq var 'eval)
  5361. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5362. (if opt
  5363. (setq varform
  5364. `(if (equal "" ,var)
  5365. ""
  5366. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5367. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5368. (setq s (replace-match "%s" t nil s))
  5369. (push varform vars))
  5370. (setq vars (nreverse vars))
  5371. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  5372. (defun org-set-sorting-strategy (key)
  5373. (if (symbolp (car org-agenda-sorting-strategy))
  5374. ;; the old format
  5375. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5376. (setq org-agenda-sorting-strategy-selected
  5377. (or (cdr (assq key org-agenda-sorting-strategy))
  5378. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5379. '(time-up category-keep priority-down)))))
  5380. (defun org-get-time-of-day (s &optional string mod24)
  5381. "Check string S for a time of day.
  5382. If found, return it as a military time number between 0 and 2400.
  5383. If not found, return nil.
  5384. The optional STRING argument forces conversion into a 5 character wide string
  5385. HH:MM."
  5386. (save-match-data
  5387. (when
  5388. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5389. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5390. (let* ((h (string-to-number (match-string 1 s)))
  5391. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5392. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5393. (am-p (equal ampm "am"))
  5394. (h1 (cond ((not ampm) h)
  5395. ((= h 12) (if am-p 0 12))
  5396. (t (+ h (if am-p 0 12)))))
  5397. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5398. (mod h1 24) h1))
  5399. (t0 (+ (* 100 h2) m))
  5400. (t1 (concat (if (>= h1 24) "+" " ")
  5401. (if (and org-agenda-time-leading-zero
  5402. (< t0 1000)) "0" "")
  5403. (if (< t0 100) "0" "")
  5404. (if (< t0 10) "0" "")
  5405. (int-to-string t0))))
  5406. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5407. (defvar org-agenda-before-sorting-filter-function nil
  5408. "Function to be applied to agenda items prior to sorting.
  5409. Prior to sorting also means just before they are inserted into the agenda.
  5410. To aid sorting, you may revisit the original entries and add more text
  5411. properties which will later be used by the sorting functions.
  5412. The function should take a string argument, an agenda line.
  5413. It has access to the text properties in that line, which contain among
  5414. other things, the property `org-hd-marker' that points to the entry
  5415. where the line comes from. Note that not all lines going into the agenda
  5416. have this property, only most.
  5417. The function should return the modified string. It is probably best
  5418. to ONLY change text properties.
  5419. You can also use this function as a filter, by returning nil for lines
  5420. you don't want to have in the agenda at all. For this application, you
  5421. could bind the variable in the options section of a custom command.")
  5422. (defun org-finalize-agenda-entries (list &optional nosort)
  5423. "Sort and concatenate the agenda items."
  5424. (setq list (mapcar 'org-agenda-highlight-todo list))
  5425. (if nosort
  5426. list
  5427. (when org-agenda-before-sorting-filter-function
  5428. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5429. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5430. (defun org-agenda-highlight-todo (x)
  5431. (let ((org-done-keywords org-done-keywords-for-agenda)
  5432. (case-fold-search nil)
  5433. re)
  5434. (if (eq x 'line)
  5435. (save-excursion
  5436. (beginning-of-line 1)
  5437. (setq re (org-get-at-bol 'org-todo-regexp))
  5438. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5439. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5440. (add-text-properties (match-beginning 0) (match-end 1)
  5441. (list 'face (org-get-todo-face 1)))
  5442. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5443. (delete-region (match-beginning 1) (1- (match-end 0)))
  5444. (goto-char (match-beginning 1))
  5445. (insert (format org-agenda-todo-keyword-format s)))))
  5446. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5447. (setq re (get-text-property 0 'org-todo-regexp x))
  5448. (when (and re
  5449. ;; Test `pl' because if there's no heading content,
  5450. ;; there's no point matching to highlight. Note
  5451. ;; that if we didn't test `pl' first, and there
  5452. ;; happened to be no keyword from `org-todo-regexp'
  5453. ;; on this heading line, then the `equal' comparison
  5454. ;; afterwards would spuriously succeed in the case
  5455. ;; where `pl' is nil -- causing an args-out-of-range
  5456. ;; error when we try to add text properties to text
  5457. ;; that isn't there.
  5458. pl
  5459. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5460. x pl) pl))
  5461. (add-text-properties
  5462. (or (match-end 1) (match-end 0)) (match-end 0)
  5463. (list 'face (org-get-todo-face (match-string 2 x)))
  5464. x)
  5465. (when (match-end 1)
  5466. (setq x (concat (substring x 0 (match-end 1))
  5467. (format org-agenda-todo-keyword-format
  5468. (match-string 2 x))
  5469. (org-add-props " " (text-properties-at 0 x))
  5470. (substring x (match-end 3)))))))
  5471. x)))
  5472. (defsubst org-cmp-priority (a b)
  5473. "Compare the priorities of string A and B."
  5474. (let ((pa (or (get-text-property 1 'priority a) 0))
  5475. (pb (or (get-text-property 1 'priority b) 0)))
  5476. (cond ((> pa pb) +1)
  5477. ((< pa pb) -1)
  5478. (t nil))))
  5479. (defsubst org-cmp-effort (a b)
  5480. "Compare the effort values of string A and B."
  5481. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5482. (ea (or (get-text-property 1 'effort-minutes a) def))
  5483. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5484. (cond ((> ea eb) +1)
  5485. ((< ea eb) -1)
  5486. (t nil))))
  5487. (defsubst org-cmp-category (a b)
  5488. "Compare the string values of categories of strings A and B."
  5489. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5490. (cb (or (get-text-property 1 'org-category b) "")))
  5491. (cond ((string-lessp ca cb) -1)
  5492. ((string-lessp cb ca) +1)
  5493. (t nil))))
  5494. (defsubst org-cmp-todo-state (a b)
  5495. "Compare the todo states of strings A and B."
  5496. (let* ((ma (or (get-text-property 1 'org-marker a)
  5497. (get-text-property 1 'org-hd-marker a)))
  5498. (mb (or (get-text-property 1 'org-marker b)
  5499. (get-text-property 1 'org-hd-marker b)))
  5500. (fa (and ma (marker-buffer ma)))
  5501. (fb (and mb (marker-buffer mb)))
  5502. (todo-kwds
  5503. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5504. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5505. (ta (or (get-text-property 1 'todo-state a) ""))
  5506. (tb (or (get-text-property 1 'todo-state b) ""))
  5507. (la (- (length (member ta todo-kwds))))
  5508. (lb (- (length (member tb todo-kwds))))
  5509. (donepa (member ta org-done-keywords-for-agenda))
  5510. (donepb (member tb org-done-keywords-for-agenda)))
  5511. (cond ((and donepa (not donepb)) -1)
  5512. ((and (not donepa) donepb) +1)
  5513. ((< la lb) -1)
  5514. ((< lb la) +1)
  5515. (t nil))))
  5516. (defsubst org-cmp-alpha (a b)
  5517. "Compare the headlines, alphabetically."
  5518. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5519. (plb (text-property-any 0 (length b) 'org-heading t b))
  5520. (ta (and pla (substring a pla)))
  5521. (tb (and plb (substring b plb))))
  5522. (when pla
  5523. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5524. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5525. (setq ta (substring ta (match-end 0))))
  5526. (setq ta (downcase ta)))
  5527. (when plb
  5528. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5529. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5530. (setq tb (substring tb (match-end 0))))
  5531. (setq tb (downcase tb)))
  5532. (cond ((not ta) +1)
  5533. ((not tb) -1)
  5534. ((string-lessp ta tb) -1)
  5535. ((string-lessp tb ta) +1)
  5536. (t nil))))
  5537. (defsubst org-cmp-tag (a b)
  5538. "Compare the string values of the first tags of A and B."
  5539. (let ((ta (car (last (get-text-property 1 'tags a))))
  5540. (tb (car (last (get-text-property 1 'tags b)))))
  5541. (cond ((not ta) +1)
  5542. ((not tb) -1)
  5543. ((string-lessp ta tb) -1)
  5544. ((string-lessp tb ta) +1)
  5545. (t nil))))
  5546. (defsubst org-cmp-time (a b)
  5547. "Compare the time-of-day values of strings A and B."
  5548. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5549. (ta (or (get-text-property 1 'time-of-day a) def))
  5550. (tb (or (get-text-property 1 'time-of-day b) def)))
  5551. (cond ((< ta tb) -1)
  5552. ((< tb ta) +1)
  5553. (t nil))))
  5554. (defsubst org-cmp-habit-p (a b)
  5555. "Compare the todo states of strings A and B."
  5556. (let ((ha (get-text-property 1 'org-habit-p a))
  5557. (hb (get-text-property 1 'org-habit-p b)))
  5558. (cond ((and ha (not hb)) -1)
  5559. ((and (not ha) hb) +1)
  5560. (t nil))))
  5561. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5562. (defun org-entries-lessp (a b)
  5563. "Predicate for sorting agenda entries."
  5564. ;; The following variables will be used when the form is evaluated.
  5565. ;; So even though the compiler complains, keep them.
  5566. (let* ((ss org-agenda-sorting-strategy-selected)
  5567. (time-up (and (org-em 'time-up 'time-down ss)
  5568. (org-cmp-time a b)))
  5569. (time-down (if time-up (- time-up) nil))
  5570. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5571. (org-cmp-priority a b)))
  5572. (priority-down (if priority-up (- priority-up) nil))
  5573. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5574. (org-cmp-effort a b)))
  5575. (effort-down (if effort-up (- effort-up) nil))
  5576. (category-up (and (or (org-em 'category-up 'category-down ss)
  5577. (memq 'category-keep ss))
  5578. (org-cmp-category a b)))
  5579. (category-down (if category-up (- category-up) nil))
  5580. (category-keep (if category-up +1 nil))
  5581. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5582. (org-cmp-tag a b)))
  5583. (tag-down (if tag-up (- tag-up) nil))
  5584. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5585. (org-cmp-todo-state a b)))
  5586. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5587. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5588. (org-cmp-habit-p a b)))
  5589. (habit-down (if habit-up (- habit-up) nil))
  5590. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5591. (org-cmp-alpha a b)))
  5592. (alpha-down (if alpha-up (- alpha-up) nil))
  5593. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5594. user-defined-up user-defined-down)
  5595. (if (and need-user-cmp org-agenda-cmp-user-defined
  5596. (functionp org-agenda-cmp-user-defined))
  5597. (setq user-defined-up
  5598. (funcall org-agenda-cmp-user-defined a b)
  5599. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5600. (cdr (assoc
  5601. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5602. '((-1 . t) (1 . nil) (nil . nil))))))
  5603. ;;; Agenda restriction lock
  5604. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5605. "Overlay to mark the headline to which agenda commands are restricted.")
  5606. (overlay-put org-agenda-restriction-lock-overlay
  5607. 'face 'org-agenda-restriction-lock)
  5608. (overlay-put org-agenda-restriction-lock-overlay
  5609. 'help-echo "Agendas are currently limited to this subtree.")
  5610. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5611. (defun org-agenda-set-restriction-lock (&optional type)
  5612. "Set restriction lock for agenda, to current subtree or file.
  5613. Restriction will be the file if TYPE is `file', or if type is the
  5614. universal prefix '(4), or if the cursor is before the first headline
  5615. in the file. Otherwise, restriction will be to the current subtree."
  5616. (interactive "P")
  5617. (and (equal type '(4)) (setq type 'file))
  5618. (setq type (cond
  5619. (type type)
  5620. ((org-at-heading-p) 'subtree)
  5621. ((condition-case nil (org-back-to-heading t) (error nil))
  5622. 'subtree)
  5623. (t 'file)))
  5624. (if (eq type 'subtree)
  5625. (progn
  5626. (setq org-agenda-restrict t)
  5627. (setq org-agenda-overriding-restriction 'subtree)
  5628. (put 'org-agenda-files 'org-restrict
  5629. (list (buffer-file-name (buffer-base-buffer))))
  5630. (org-back-to-heading t)
  5631. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5632. (move-marker org-agenda-restrict-begin (point))
  5633. (move-marker org-agenda-restrict-end
  5634. (save-excursion (org-end-of-subtree t)))
  5635. (message "Locking agenda restriction to subtree"))
  5636. (put 'org-agenda-files 'org-restrict
  5637. (list (buffer-file-name (buffer-base-buffer))))
  5638. (setq org-agenda-restrict nil)
  5639. (setq org-agenda-overriding-restriction 'file)
  5640. (move-marker org-agenda-restrict-begin nil)
  5641. (move-marker org-agenda-restrict-end nil)
  5642. (message "Locking agenda restriction to file"))
  5643. (setq current-prefix-arg nil)
  5644. (org-agenda-maybe-redo))
  5645. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5646. "Remove the agenda restriction lock."
  5647. (interactive "P")
  5648. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5649. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5650. (setq org-agenda-overriding-restriction nil)
  5651. (setq org-agenda-restrict nil)
  5652. (put 'org-agenda-files 'org-restrict nil)
  5653. (move-marker org-agenda-restrict-begin nil)
  5654. (move-marker org-agenda-restrict-end nil)
  5655. (setq current-prefix-arg nil)
  5656. (message "Agenda restriction lock removed")
  5657. (or noupdate (org-agenda-maybe-redo)))
  5658. (defun org-agenda-maybe-redo ()
  5659. "If there is any window showing the agenda view, update it."
  5660. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5661. (w0 (selected-window)))
  5662. (when w
  5663. (select-window w)
  5664. (org-agenda-redo)
  5665. (select-window w0)
  5666. (if org-agenda-overriding-restriction
  5667. (message "Agenda view shifted to new %s restriction"
  5668. org-agenda-overriding-restriction)
  5669. (message "Agenda restriction lock removed")))))
  5670. ;;; Agenda commands
  5671. (defun org-agenda-check-type (error &rest types)
  5672. "Check if agenda buffer is of allowed type.
  5673. If ERROR is non-nil, throw an error, otherwise just return nil."
  5674. (if (memq org-agenda-type types)
  5675. t
  5676. (if error
  5677. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5678. nil)))
  5679. (defun org-agenda-quit ()
  5680. "Exit agenda by removing the window or the buffer."
  5681. (interactive)
  5682. (if org-agenda-columns-active
  5683. (org-columns-quit)
  5684. (let ((buf (current-buffer)))
  5685. (if (eq org-agenda-window-setup 'other-frame)
  5686. (progn
  5687. (kill-buffer buf)
  5688. (org-agenda-reset-markers)
  5689. (org-columns-remove-overlays)
  5690. (setq org-agenda-archives-mode nil)
  5691. (delete-frame))
  5692. (and (not (eq org-agenda-window-setup 'current-window))
  5693. (not (one-window-p))
  5694. (delete-window))
  5695. (kill-buffer buf)
  5696. (org-agenda-reset-markers)
  5697. (org-columns-remove-overlays)
  5698. (setq org-agenda-archives-mode nil)))
  5699. ;; Maybe restore the pre-agenda window configuration.
  5700. (and org-agenda-restore-windows-after-quit
  5701. (not (eq org-agenda-window-setup 'other-frame))
  5702. org-pre-agenda-window-conf
  5703. (set-window-configuration org-pre-agenda-window-conf))))
  5704. (defun org-agenda-exit ()
  5705. "Exit agenda by removing the window or the buffer.
  5706. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5707. Org-mode buffers visited directly by the user will not be touched."
  5708. (interactive)
  5709. (org-release-buffers org-agenda-new-buffers)
  5710. (setq org-agenda-new-buffers nil)
  5711. (org-agenda-quit))
  5712. (defun org-agenda-execute (arg)
  5713. "Execute another agenda command, keeping same window.
  5714. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5715. in the agenda."
  5716. (interactive "P")
  5717. (let ((org-agenda-window-setup 'current-window))
  5718. (org-agenda arg)))
  5719. (defun org-agenda-redo ()
  5720. "Rebuild Agenda.
  5721. When this is the global TODO list, a prefix argument will be interpreted."
  5722. (interactive)
  5723. (let* ((org-agenda-keep-modes t)
  5724. (tag-filter org-agenda-tag-filter)
  5725. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  5726. (cat-filter org-agenda-category-filter)
  5727. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  5728. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  5729. (cols org-agenda-columns-active)
  5730. (line (org-current-line))
  5731. (window-line (- line (org-current-line (window-start))))
  5732. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5733. (put 'org-agenda-tag-filter :preset-filter nil)
  5734. (put 'org-agenda-category-filter :preset-filter nil)
  5735. (and cols (org-columns-quit))
  5736. (message "Rebuilding agenda buffer...")
  5737. (org-let lprops '(eval org-agenda-redo-command))
  5738. (setq org-agenda-undo-list nil
  5739. org-agenda-pending-undo-list nil)
  5740. (message "Rebuilding agenda buffer...done")
  5741. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  5742. (put 'org-agenda-category-filter :preset-filter cat-preset)
  5743. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  5744. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  5745. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  5746. (org-goto-line line)
  5747. (recenter window-line)))
  5748. (defvar org-global-tags-completion-table nil)
  5749. (defvar org-agenda-filter-form nil)
  5750. (defun org-agenda-filter-by-category (strip)
  5751. "Keep only those lines in the agenda buffer that have a specific category.
  5752. The category is that of the current line."
  5753. (interactive "P")
  5754. (if org-agenda-filtered-by-category
  5755. (org-agenda-filter-show-all-cat)
  5756. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  5757. (if cat (org-agenda-filter-apply
  5758. (list (concat (if strip "-" "+") cat)) 'category)
  5759. (error "No category at point")))))
  5760. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5761. "Keep only those lines in the agenda buffer that have a specific tag.
  5762. The tag is selected with its fast selection letter, as configured.
  5763. With prefix argument STRIP, remove all lines that do have the tag.
  5764. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5765. used to narrow the search - the interactive user can also press `-' or `+'
  5766. to switch to narrowing."
  5767. (interactive "P")
  5768. (let* ((alist org-tag-alist-for-agenda)
  5769. (tag-chars (mapconcat
  5770. (lambda (x) (if (and (not (symbolp (car x)))
  5771. (cdr x))
  5772. (char-to-string (cdr x))
  5773. ""))
  5774. alist ""))
  5775. (efforts (org-split-string
  5776. (or (cdr (assoc (concat org-effort-property "_ALL")
  5777. org-global-properties))
  5778. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  5779. "")))
  5780. (effort-op org-agenda-filter-effort-default-operator)
  5781. (effort-prompt "")
  5782. (inhibit-read-only t)
  5783. (current org-agenda-tag-filter)
  5784. maybe-refresh a n tag)
  5785. (unless char
  5786. (message
  5787. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5788. (if narrow "Narrow" "Filter") tag-chars
  5789. (if org-agenda-auto-exclude-function "[RET], " ""))
  5790. (setq char (read-char-exclusive)))
  5791. (when (member char '(?+ ?-))
  5792. ;; Narrowing down
  5793. (cond ((equal char ?-) (setq strip t narrow t))
  5794. ((equal char ?+) (setq strip nil narrow t)))
  5795. (message
  5796. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5797. (setq char (read-char-exclusive)))
  5798. (when (member char '(?< ?> ?= ??))
  5799. ;; An effort operator
  5800. (setq effort-op (char-to-string char))
  5801. (setq alist nil) ; to make sure it will be interpreted as effort.
  5802. (unless (equal char ??)
  5803. (loop for i from 0 to 9 do
  5804. (setq effort-prompt
  5805. (concat
  5806. effort-prompt " ["
  5807. (if (= i 9) "0" (int-to-string (1+ i)))
  5808. "]" (nth i efforts))))
  5809. (message "Effort%s: %s " effort-op effort-prompt)
  5810. (setq char (read-char-exclusive))
  5811. (when (or (< char ?0) (> char ?9))
  5812. (error "Need 1-9,0 to select effort" ))))
  5813. (when (equal char ?\t)
  5814. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5815. (org-set-local 'org-global-tags-completion-table
  5816. (org-global-tags-completion-table)))
  5817. (let ((completion-ignore-case t))
  5818. (setq tag (org-icompleting-read
  5819. "Tag: " org-global-tags-completion-table))))
  5820. (cond
  5821. ((equal char ?\r)
  5822. (org-agenda-filter-show-all-tag)
  5823. (when org-agenda-auto-exclude-function
  5824. (setq org-agenda-tag-filter '())
  5825. (dolist (tag (org-agenda-get-represented-tags))
  5826. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5827. (if modifier
  5828. (push modifier org-agenda-tag-filter))))
  5829. (if (not (null org-agenda-tag-filter))
  5830. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  5831. (setq maybe-refresh t))
  5832. ((equal char ?/)
  5833. (org-agenda-filter-show-all-tag)
  5834. (when (get 'org-agenda-tag-filter :preset-filter)
  5835. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  5836. (setq maybe-refresh t))
  5837. ((equal char ?. )
  5838. (setq org-agenda-tag-filter
  5839. (mapcar (lambda(tag) (concat "+" tag))
  5840. (org-get-at-bol 'tags)))
  5841. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  5842. (setq maybe-refresh t))
  5843. ((or (equal char ?\ )
  5844. (setq a (rassoc char alist))
  5845. (and (>= char ?0) (<= char ?9)
  5846. (setq n (if (= char ?0) 9 (- char ?0 1))
  5847. tag (concat effort-op (nth n efforts))
  5848. a (cons tag nil)))
  5849. (and (= char ??)
  5850. (setq tag "?eff")
  5851. a (cons tag nil))
  5852. (and tag (setq a (cons tag nil))))
  5853. (org-agenda-filter-show-all-tag)
  5854. (setq tag (car a))
  5855. (setq org-agenda-tag-filter
  5856. (cons (concat (if strip "-" "+") tag)
  5857. (if narrow current nil)))
  5858. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  5859. (setq maybe-refresh t))
  5860. (t (error "Invalid tag selection character %c" char)))
  5861. (when (and maybe-refresh
  5862. (eq org-agenda-clockreport-mode 'with-filter))
  5863. (org-agenda-redo))))
  5864. (defun org-agenda-get-represented-tags ()
  5865. "Get a list of all tags currently represented in the agenda."
  5866. (let (p tags)
  5867. (save-excursion
  5868. (goto-char (point-min))
  5869. (while (setq p (next-single-property-change (point) 'tags))
  5870. (goto-char p)
  5871. (mapc (lambda (x) (add-to-list 'tags x))
  5872. (get-text-property (point) 'tags))))
  5873. tags))
  5874. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5875. "Refine the current filter. See `org-agenda-filter-by-tag'."
  5876. (interactive "P")
  5877. (org-agenda-filter-by-tag strip char 'refine))
  5878. (defun org-agenda-filter-make-matcher ()
  5879. "Create the form that tests a line for agenda filter."
  5880. (let (f f1)
  5881. ;; first compute the tag-filter matcher
  5882. (dolist (x (delete-dups
  5883. (append (get 'org-agenda-tag-filter
  5884. :preset-filter) org-agenda-tag-filter)))
  5885. (if (member x '("-" "+"))
  5886. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5887. (if (string-match "[<=>?]" x)
  5888. (setq f1 (org-agenda-filter-effort-form x))
  5889. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5890. (if (equal (string-to-char x) ?-)
  5891. (setq f1 (list 'not f1))))
  5892. (push f1 f))
  5893. ;; then compute the category-filter matcher
  5894. (dolist (x (delete-dups
  5895. (append (get 'org-agenda-category-filter
  5896. :preset-filter) org-agenda-category-filter)))
  5897. (setq f1 (list 'equal (substring x 1) 'cat))
  5898. (push f1 f))
  5899. (cons 'and (nreverse f))))
  5900. (defun org-agenda-filter-effort-form (e)
  5901. "Return the form to compare the effort of the current line with what E says.
  5902. E looks like \"+<2:25\"."
  5903. (let (op)
  5904. (setq e (substring e 1))
  5905. (setq op (string-to-char e) e (substring e 1))
  5906. (setq op (cond ((equal op ?<) '<=)
  5907. ((equal op ?>) '>=)
  5908. ((equal op ??) op)
  5909. (t '=)))
  5910. (list 'org-agenda-compare-effort (list 'quote op)
  5911. (org-duration-string-to-minutes e))))
  5912. (defun org-agenda-compare-effort (op value)
  5913. "Compare the effort of the current line with VALUE, using OP.
  5914. If the line does not have an effort defined, return nil."
  5915. (let ((eff (org-get-at-bol 'effort-minutes)))
  5916. (if (equal op ??)
  5917. (not eff)
  5918. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5919. value))))
  5920. (defvar org-agenda-filtered-by-category nil)
  5921. (defun org-agenda-filter-apply (filter type)
  5922. "Set FILTER as the new agenda filter and apply it."
  5923. (let (tags)
  5924. (if (eq type 'tag)
  5925. (setq org-agenda-tag-filter filter)
  5926. (setq org-agenda-category-filter filter
  5927. org-agenda-filtered-by-category t))
  5928. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  5929. (org-agenda-set-mode-name)
  5930. (save-excursion
  5931. (goto-char (point-min))
  5932. (while (not (eobp))
  5933. (if (org-get-at-bol 'org-marker)
  5934. (progn
  5935. (setq tags (org-get-at-bol 'tags) ; used in eval
  5936. cat (get-text-property (point) 'org-category))
  5937. (if (not (eval org-agenda-filter-form))
  5938. (org-agenda-filter-hide-line type))
  5939. (beginning-of-line 2))
  5940. (beginning-of-line 2))))
  5941. (if (get-char-property (point) 'invisible)
  5942. (org-agenda-previous-line))))
  5943. (defun org-agenda-filter-hide-line (type)
  5944. (let (ov)
  5945. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5946. (point-at-eol)))
  5947. (overlay-put ov 'invisible t)
  5948. (overlay-put ov 'type type)
  5949. (if (eq type 'tag)
  5950. (push ov org-agenda-tag-filter-overlays)
  5951. (push ov org-agenda-cat-filter-overlays))))
  5952. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5953. (setq pos (or pos (point)))
  5954. (save-excursion
  5955. (dolist (ov (overlays-at pos))
  5956. (when (and (overlay-get ov 'invisible)
  5957. (eq (overlay-get ov 'type) 'tag))
  5958. (goto-char pos)
  5959. (if (< (overlay-start ov) (point-at-eol))
  5960. (move-overlay ov (point-at-eol)
  5961. (overlay-end ov)))))))
  5962. (defun org-agenda-filter-show-all-tag nil
  5963. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  5964. (setq org-agenda-tag-filter-overlays nil
  5965. org-agenda-tag-filter nil
  5966. org-agenda-filter-form nil)
  5967. (org-agenda-set-mode-name))
  5968. (defun org-agenda-filter-show-all-cat nil
  5969. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  5970. (setq org-agenda-cat-filter-overlays nil
  5971. org-agenda-filtered-by-category nil
  5972. org-agenda-category-filter nil
  5973. org-agenda-filter-form nil)
  5974. (org-agenda-set-mode-name))
  5975. (defun org-agenda-manipulate-query-add ()
  5976. "Manipulate the query by adding a search term with positive selection.
  5977. Positive selection means the term must be matched for selection of an entry."
  5978. (interactive)
  5979. (org-agenda-manipulate-query ?\[))
  5980. (defun org-agenda-manipulate-query-subtract ()
  5981. "Manipulate the query by adding a search term with negative selection.
  5982. Negative selection means term must not be matched for selection of an entry."
  5983. (interactive)
  5984. (org-agenda-manipulate-query ?\]))
  5985. (defun org-agenda-manipulate-query-add-re ()
  5986. "Manipulate the query by adding a search regexp with positive selection.
  5987. Positive selection means the regexp must match for selection of an entry."
  5988. (interactive)
  5989. (org-agenda-manipulate-query ?\{))
  5990. (defun org-agenda-manipulate-query-subtract-re ()
  5991. "Manipulate the query by adding a search regexp with negative selection.
  5992. Negative selection means regexp must not match for selection of an entry."
  5993. (interactive)
  5994. (org-agenda-manipulate-query ?\}))
  5995. (defun org-agenda-manipulate-query (char)
  5996. (cond
  5997. ((memq org-agenda-type '(timeline agenda))
  5998. (let ((org-agenda-include-inactive-timestamps t))
  5999. (org-agenda-redo))
  6000. (message "Display now includes inactive timestamps as well"))
  6001. ((eq org-agenda-type 'search)
  6002. (org-add-to-string
  6003. 'org-agenda-query-string
  6004. (if org-agenda-last-search-view-search-was-boolean
  6005. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6006. (?\{ . " +{}") (?\} . " -{}"))))
  6007. " "))
  6008. (setq org-agenda-redo-command
  6009. (list 'org-search-view
  6010. org-todo-only
  6011. org-agenda-query-string
  6012. (+ (length org-agenda-query-string)
  6013. (if (member char '(?\{ ?\})) 0 1))))
  6014. (set-register org-agenda-query-register org-agenda-query-string)
  6015. (org-agenda-redo))
  6016. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6017. org-agenda-type))))
  6018. (defun org-add-to-string (var string)
  6019. (set var (concat (symbol-value var) string)))
  6020. (defun org-agenda-goto-date (date)
  6021. "Jump to DATE in agenda."
  6022. (interactive (list (let ((org-read-date-prefer-future
  6023. (eval org-agenda-jump-prefer-future)))
  6024. (org-read-date))))
  6025. (org-agenda-list nil date))
  6026. (defun org-agenda-goto-today ()
  6027. "Go to today."
  6028. (interactive)
  6029. (org-agenda-check-type t 'timeline 'agenda)
  6030. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6031. (cond
  6032. (tdpos (goto-char tdpos))
  6033. ((eq org-agenda-type 'agenda)
  6034. (let* ((sd (org-agenda-compute-starting-span
  6035. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  6036. (org-agenda-overriding-arguments org-agenda-last-arguments))
  6037. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6038. (org-agenda-redo)
  6039. (org-agenda-find-same-or-today-or-agenda)))
  6040. (t (error "Cannot find today")))))
  6041. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6042. (goto-char
  6043. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6044. (text-property-any (point-min) (point-max) 'org-today t)
  6045. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6046. (point-min))))
  6047. (defun org-agenda-later (arg)
  6048. "Go forward in time by thee current span.
  6049. With prefix ARG, go forward that many times the current span."
  6050. (interactive "p")
  6051. (org-agenda-check-type t 'agenda)
  6052. (let* ((span org-agenda-current-span)
  6053. (sd org-starting-day)
  6054. (greg (calendar-gregorian-from-absolute sd))
  6055. (cnt (org-get-at-bol 'org-day-cnt))
  6056. greg2)
  6057. (cond
  6058. ((eq span 'day)
  6059. (setq sd (+ arg sd)))
  6060. ((eq span 'week)
  6061. (setq sd (+ (* 7 arg) sd)))
  6062. ((eq span 'month)
  6063. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6064. sd (calendar-absolute-from-gregorian greg2))
  6065. (setcar greg2 (1+ (car greg2))))
  6066. ((eq span 'year)
  6067. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6068. sd (calendar-absolute-from-gregorian greg2))
  6069. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6070. (t
  6071. (setq sd (+ (* span arg) sd))))
  6072. (let ((org-agenda-overriding-arguments
  6073. (list (car org-agenda-last-arguments) sd span t)))
  6074. (org-agenda-redo)
  6075. (org-agenda-find-same-or-today-or-agenda cnt))))
  6076. (defun org-agenda-earlier (arg)
  6077. "Go backward in time by the current span.
  6078. With prefix ARG, go backward that many times the current span."
  6079. (interactive "p")
  6080. (org-agenda-later (- arg)))
  6081. (defun org-agenda-view-mode-dispatch ()
  6082. "Call one of the view mode commands."
  6083. (interactive)
  6084. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6085. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6086. [a]rch-trees [A]rch-files clock[R]eport include[D]iary
  6087. [E]ntryText")
  6088. (let ((a (read-char-exclusive)))
  6089. (case a
  6090. (?\ (call-interactively 'org-agenda-reset-view))
  6091. (?d (call-interactively 'org-agenda-day-view))
  6092. (?w (call-interactively 'org-agenda-week-view))
  6093. (?m (call-interactively 'org-agenda-month-view))
  6094. (?y (call-interactively 'org-agenda-year-view))
  6095. (?l (call-interactively 'org-agenda-log-mode))
  6096. (?L (org-agenda-log-mode '(4)))
  6097. (?c (org-agenda-log-mode 'clockcheck))
  6098. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6099. (?a (call-interactively 'org-agenda-archives-mode))
  6100. (?A (org-agenda-archives-mode 'files))
  6101. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6102. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6103. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6104. (?D (call-interactively 'org-agenda-toggle-diary))
  6105. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6106. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6107. (org-agenda-check-type t 'timeline 'agenda)
  6108. (org-agenda-redo))
  6109. (message "Display now includes inactive timestamps as well"))
  6110. (?q (message "Abort"))
  6111. (otherwise (error "Invalid key" )))))
  6112. (defun org-agenda-reset-view ()
  6113. "Switch to default view for agenda."
  6114. (interactive)
  6115. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6116. (defun org-agenda-day-view (&optional day-of-year)
  6117. "Switch to daily view for agenda.
  6118. With argument DAY-OF-YEAR, switch to that day of the year."
  6119. (interactive "P")
  6120. (org-agenda-change-time-span 'day day-of-year))
  6121. (defun org-agenda-week-view (&optional iso-week)
  6122. "Switch to daily view for agenda.
  6123. With argument ISO-WEEK, switch to the corresponding ISO week.
  6124. If ISO-WEEK has more then 2 digits, only the last two encode the
  6125. week. Any digits before this encode a year. So 200712 means
  6126. week 12 of year 2007. Years in the range 1938-2037 can also be
  6127. written as 2-digit years."
  6128. (interactive "P")
  6129. (org-agenda-change-time-span 'week iso-week))
  6130. (defun org-agenda-month-view (&optional month)
  6131. "Switch to monthly view for agenda.
  6132. With argument MONTH, switch to that month."
  6133. (interactive "P")
  6134. (org-agenda-change-time-span 'month month))
  6135. (defun org-agenda-year-view (&optional year)
  6136. "Switch to yearly view for agenda.
  6137. With argument YEAR, switch to that year.
  6138. If MONTH has more then 2 digits, only the last two encode the
  6139. month. Any digits before this encode a year. So 200712 means
  6140. December year 2007. Years in the range 1938-2037 can also be
  6141. written as 2-digit years."
  6142. (interactive "P")
  6143. (when year
  6144. (setq year (org-small-year-to-year year)))
  6145. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6146. (org-agenda-change-time-span 'year year)
  6147. (error "Abort")))
  6148. (defun org-agenda-change-time-span (span &optional n)
  6149. "Change the agenda view to SPAN.
  6150. SPAN may be `day', `week', `month', `year'."
  6151. (org-agenda-check-type t 'agenda)
  6152. (if (and (not n) (equal org-agenda-current-span span))
  6153. (error "Viewing span is already \"%s\"" span))
  6154. (let* ((sd (or (org-get-at-bol 'day)
  6155. org-starting-day))
  6156. (sd (org-agenda-compute-starting-span sd span n))
  6157. (org-agenda-overriding-arguments
  6158. (or org-agenda-overriding-arguments
  6159. (list (car org-agenda-last-arguments) sd span t))))
  6160. (org-agenda-redo)
  6161. (org-agenda-find-same-or-today-or-agenda))
  6162. (org-agenda-set-mode-name)
  6163. (message "Switched to %s view" span))
  6164. (defun org-agenda-compute-starting-span (sd span &optional n)
  6165. "Compute starting date for agenda.
  6166. SPAN may be `day', `week', `month', `year'. The return value
  6167. is a cons cell with the starting date and the number of days,
  6168. so that the date SD will be in that range."
  6169. (let* ((greg (calendar-gregorian-from-absolute sd))
  6170. (dg (nth 1 greg))
  6171. (mg (car greg))
  6172. (yg (nth 2 greg)))
  6173. (cond
  6174. ((eq span 'day)
  6175. (when n
  6176. (setq sd (+ (calendar-absolute-from-gregorian
  6177. (list mg 1 yg))
  6178. n -1))))
  6179. ((eq span 'week)
  6180. (let* ((nt (calendar-day-of-week
  6181. (calendar-gregorian-from-absolute sd)))
  6182. (d (if org-agenda-start-on-weekday
  6183. (- nt org-agenda-start-on-weekday)
  6184. 0))
  6185. y1)
  6186. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6187. (when n
  6188. (require 'cal-iso)
  6189. (when (> n 99)
  6190. (setq y1 (org-small-year-to-year (/ n 100))
  6191. n (mod n 100)))
  6192. (setq sd
  6193. (calendar-absolute-from-iso
  6194. (list n 1
  6195. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6196. ((eq span 'month)
  6197. (let (y1)
  6198. (when (and n (> n 99))
  6199. (setq y1 (org-small-year-to-year (/ n 100))
  6200. n (mod n 100)))
  6201. (setq sd (calendar-absolute-from-gregorian
  6202. (list (or n mg) 1 (or y1 yg))))))
  6203. ((eq span 'year)
  6204. (setq sd (calendar-absolute-from-gregorian
  6205. (list 1 1 (or n yg))))))
  6206. sd))
  6207. (defun org-agenda-next-date-line (&optional arg)
  6208. "Jump to the next line indicating a date in agenda buffer."
  6209. (interactive "p")
  6210. (org-agenda-check-type t 'agenda 'timeline)
  6211. (beginning-of-line 1)
  6212. ;; This does not work if user makes date format that starts with a blank
  6213. (if (looking-at "^\\S-") (forward-char 1))
  6214. (if (not (re-search-forward "^\\S-" nil t arg))
  6215. (progn
  6216. (backward-char 1)
  6217. (error "No next date after this line in this buffer")))
  6218. (goto-char (match-beginning 0)))
  6219. (defun org-agenda-previous-date-line (&optional arg)
  6220. "Jump to the previous line indicating a date in agenda buffer."
  6221. (interactive "p")
  6222. (org-agenda-check-type t 'agenda 'timeline)
  6223. (beginning-of-line 1)
  6224. (if (not (re-search-backward "^\\S-" nil t arg))
  6225. (error "No previous date before this line in this buffer")))
  6226. ;; Initialize the highlight
  6227. (defvar org-hl (make-overlay 1 1))
  6228. (overlay-put org-hl 'face 'highlight)
  6229. (defun org-highlight (begin end &optional buffer)
  6230. "Highlight a region with overlay."
  6231. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6232. (defun org-unhighlight ()
  6233. "Detach overlay INDEX."
  6234. (org-detach-overlay org-hl))
  6235. ;; FIXME this is currently not used.
  6236. (defun org-highlight-until-next-command (beg end &optional buffer)
  6237. "Move the highlight overlay to BEG/END, remove it before the next command."
  6238. (org-highlight beg end buffer)
  6239. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6240. (defun org-unhighlight-once ()
  6241. "Remove the highlight from its position, and this function from the hook."
  6242. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6243. (org-unhighlight))
  6244. (defun org-agenda-follow-mode ()
  6245. "Toggle follow mode in an agenda buffer."
  6246. (interactive)
  6247. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6248. (org-agenda-set-mode-name)
  6249. (org-agenda-do-context-action)
  6250. (message "Follow mode is %s"
  6251. (if org-agenda-follow-mode "on" "off")))
  6252. (defun org-agenda-entry-text-mode (&optional arg)
  6253. "Toggle entry text mode in an agenda buffer."
  6254. (interactive "P")
  6255. (setq org-agenda-entry-text-mode (or (integerp arg)
  6256. (not org-agenda-entry-text-mode)))
  6257. (org-agenda-entry-text-hide)
  6258. (and org-agenda-entry-text-mode
  6259. (let ((org-agenda-entry-text-maxlines
  6260. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6261. (org-agenda-entry-text-show)))
  6262. (org-agenda-set-mode-name)
  6263. (message "Entry text mode is %s. Maximum number of lines is %d"
  6264. (if org-agenda-entry-text-mode "on" "off")
  6265. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6266. (defun org-agenda-clockreport-mode (&optional with-filter)
  6267. "Toggle clocktable mode in an agenda buffer.
  6268. With prefix arg WITH-FILTER, make the clocktable respect the current
  6269. agenda filter."
  6270. (interactive "P")
  6271. (org-agenda-check-type t 'agenda)
  6272. (if with-filter
  6273. (setq org-agenda-clockreport-mode 'with-filter)
  6274. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6275. (org-agenda-set-mode-name)
  6276. (org-agenda-redo)
  6277. (message "Clocktable mode is %s"
  6278. (if org-agenda-clockreport-mode "on" "off")))
  6279. (defun org-agenda-log-mode (&optional special)
  6280. "Toggle log mode in an agenda buffer.
  6281. With argument SPECIAL, show all possible log items, not only the ones
  6282. configured in `org-agenda-log-mode-items'.
  6283. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6284. (interactive "P")
  6285. (org-agenda-check-type t 'agenda 'timeline)
  6286. (setq org-agenda-show-log
  6287. (cond
  6288. ((equal special '(16)) 'only)
  6289. ((eq special 'clockcheck)
  6290. (if (eq org-agenda-show-log 'clockcheck)
  6291. nil 'clockcheck))
  6292. (special '(closed clock state))
  6293. (t (not org-agenda-show-log))))
  6294. (org-agenda-set-mode-name)
  6295. (org-agenda-redo)
  6296. (message "Log mode is %s"
  6297. (if org-agenda-show-log "on" "off")))
  6298. (defun org-agenda-archives-mode (&optional with-files)
  6299. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6300. When called with a prefix argument, include all archive files as well."
  6301. (interactive "P")
  6302. (setq org-agenda-archives-mode
  6303. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6304. (org-agenda-set-mode-name)
  6305. (org-agenda-redo)
  6306. (message
  6307. "%s"
  6308. (cond
  6309. ((eq org-agenda-archives-mode nil)
  6310. "No archives are included")
  6311. ((eq org-agenda-archives-mode 'trees)
  6312. (format "Trees with :%s: tag are included" org-archive-tag))
  6313. ((eq org-agenda-archives-mode t)
  6314. (format "Trees with :%s: tag and all active archive files are included"
  6315. org-archive-tag)))))
  6316. (defun org-agenda-toggle-diary ()
  6317. "Toggle diary inclusion in an agenda buffer."
  6318. (interactive)
  6319. (org-agenda-check-type t 'agenda)
  6320. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6321. (org-agenda-redo)
  6322. (org-agenda-set-mode-name)
  6323. (message "Diary inclusion turned %s"
  6324. (if org-agenda-include-diary "on" "off")))
  6325. (defun org-agenda-toggle-deadlines ()
  6326. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6327. (interactive)
  6328. (org-agenda-check-type t 'agenda)
  6329. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6330. (org-agenda-redo)
  6331. (org-agenda-set-mode-name)
  6332. (message "Deadlines inclusion turned %s"
  6333. (if org-agenda-include-deadlines "on" "off")))
  6334. (defun org-agenda-toggle-time-grid ()
  6335. "Toggle time grid in an agenda buffer."
  6336. (interactive)
  6337. (org-agenda-check-type t 'agenda)
  6338. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6339. (org-agenda-redo)
  6340. (org-agenda-set-mode-name)
  6341. (message "Time-grid turned %s"
  6342. (if org-agenda-use-time-grid "on" "off")))
  6343. (defun org-agenda-set-mode-name ()
  6344. "Set the mode name to indicate all the small mode settings."
  6345. (setq mode-name
  6346. (list "Org-Agenda"
  6347. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6348. " "
  6349. '(:eval (org-agenda-span-name org-agenda-current-span))
  6350. (if org-agenda-follow-mode " Follow" "")
  6351. (if org-agenda-entry-text-mode " ETxt" "")
  6352. (if org-agenda-include-diary " Diary" "")
  6353. (if org-agenda-include-deadlines " Ddl" "")
  6354. (if org-agenda-use-time-grid " Grid" "")
  6355. (if (and (boundp 'org-habit-show-habits)
  6356. org-habit-show-habits) " Habit" "")
  6357. (cond
  6358. ((consp org-agenda-show-log) " LogAll")
  6359. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6360. (org-agenda-show-log " Log")
  6361. (t ""))
  6362. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  6363. :preset-filter))
  6364. '(:eval (org-propertize
  6365. (concat " <"
  6366. (mapconcat
  6367. 'identity
  6368. (append
  6369. (get 'org-agenda-category-filter :preset-filter)
  6370. org-agenda-category-filter)
  6371. "")
  6372. ">")
  6373. 'face 'org-agenda-filter-category
  6374. 'help-echo "Category used in filtering"))
  6375. "")
  6376. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  6377. :preset-filter))
  6378. '(:eval (org-propertize
  6379. (concat " {"
  6380. (mapconcat
  6381. 'identity
  6382. (append
  6383. (get 'org-agenda-tag-filter :preset-filter)
  6384. org-agenda-tag-filter)
  6385. "")
  6386. "}")
  6387. 'face 'org-agenda-filter-tags
  6388. 'help-echo "Tags used in filtering"))
  6389. "")
  6390. (if org-agenda-archives-mode
  6391. (if (eq org-agenda-archives-mode t)
  6392. " Archives"
  6393. (format " :%s:" org-archive-tag))
  6394. "")
  6395. (if org-agenda-clockreport-mode
  6396. (if (eq org-agenda-clockreport-mode 'with-filter)
  6397. " Clock{}" " Clock")
  6398. "")))
  6399. (force-mode-line-update))
  6400. (defun org-agenda-post-command-hook ()
  6401. (setq org-agenda-type
  6402. (or (get-text-property (point) 'org-agenda-type)
  6403. (get-text-property (max (point-min) (1- (point)))
  6404. 'org-agenda-type))))
  6405. (defun org-agenda-next-line ()
  6406. "Move cursor to the next line, and show if follow mode is active."
  6407. (interactive)
  6408. (call-interactively 'next-line)
  6409. (org-agenda-do-context-action))
  6410. (defun org-agenda-previous-line ()
  6411. "Move cursor to the previous line, and show if follow-mode is active."
  6412. (interactive)
  6413. (call-interactively 'previous-line)
  6414. (org-agenda-do-context-action))
  6415. (defun org-agenda-do-context-action ()
  6416. "Show outline path and, maybe, follow mode window."
  6417. (let ((m (org-get-at-bol 'org-marker)))
  6418. (when (and (markerp m) (marker-buffer m))
  6419. (and org-agenda-follow-mode
  6420. (if org-agenda-follow-indirect
  6421. (org-agenda-tree-to-indirect-buffer)
  6422. (org-agenda-show)))
  6423. (and org-agenda-show-outline-path
  6424. (org-with-point-at m (org-display-outline-path t))))))
  6425. (defun org-agenda-show-priority ()
  6426. "Show the priority of the current item.
  6427. This priority is composed of the main priority given with the [#A] cookies,
  6428. and by additional input from the age of a schedules or deadline entry."
  6429. (interactive)
  6430. (let* ((pri (org-get-at-bol 'priority)))
  6431. (message "Priority is %d" (if pri pri -1000))))
  6432. (defun org-agenda-show-tags ()
  6433. "Show the tags applicable to the current item."
  6434. (interactive)
  6435. (let* ((tags (org-get-at-bol 'tags)))
  6436. (if tags
  6437. (message "Tags are :%s:"
  6438. (org-no-properties (mapconcat 'identity tags ":")))
  6439. (message "No tags associated with this line"))))
  6440. (defun org-agenda-goto (&optional highlight)
  6441. "Go to the Org-mode file which contains the item at point."
  6442. (interactive)
  6443. (let* ((marker (or (org-get-at-bol 'org-marker)
  6444. (org-agenda-error)))
  6445. (buffer (marker-buffer marker))
  6446. (pos (marker-position marker)))
  6447. (switch-to-buffer-other-window buffer)
  6448. (widen)
  6449. (push-mark)
  6450. (goto-char pos)
  6451. (when (eq major-mode 'org-mode)
  6452. (org-show-context 'agenda)
  6453. (save-excursion
  6454. (and (outline-next-heading)
  6455. (org-flag-heading nil)))) ; show the next heading
  6456. (when (outline-invisible-p)
  6457. (show-entry)) ; display invisible text
  6458. (recenter (/ (window-height) 2))
  6459. (run-hooks 'org-agenda-after-show-hook)
  6460. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6461. (defvar org-agenda-after-show-hook nil
  6462. "Normal hook run after an item has been shown from the agenda.
  6463. Point is in the buffer where the item originated.")
  6464. (defun org-agenda-kill ()
  6465. "Kill the entry or subtree belonging to the current agenda entry."
  6466. (interactive)
  6467. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6468. (let* ((marker (or (org-get-at-bol 'org-marker)
  6469. (org-agenda-error)))
  6470. (buffer (marker-buffer marker))
  6471. (pos (marker-position marker))
  6472. (type (org-get-at-bol 'type))
  6473. dbeg dend (n 0) conf)
  6474. (org-with-remote-undo buffer
  6475. (with-current-buffer buffer
  6476. (save-excursion
  6477. (goto-char pos)
  6478. (if (and (eq major-mode 'org-mode) (not (member type '("sexp"))))
  6479. (setq dbeg (progn (org-back-to-heading t) (point))
  6480. dend (org-end-of-subtree t t))
  6481. (setq dbeg (point-at-bol)
  6482. dend (min (point-max) (1+ (point-at-eol)))))
  6483. (goto-char dbeg)
  6484. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6485. (setq conf (or (eq t org-agenda-confirm-kill)
  6486. (and (numberp org-agenda-confirm-kill)
  6487. (> n org-agenda-confirm-kill))))
  6488. (and conf
  6489. (not (y-or-n-p
  6490. (format "Delete entry with %d lines in buffer \"%s\"? "
  6491. n (buffer-name buffer))))
  6492. (error "Abort"))
  6493. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6494. (with-current-buffer buffer (delete-region dbeg dend))
  6495. (message "Agenda item and source killed"))))
  6496. (defvar org-archive-default-command)
  6497. (defun org-agenda-archive-default ()
  6498. "Archive the entry or subtree belonging to the current agenda entry."
  6499. (interactive)
  6500. (require 'org-archive)
  6501. (org-agenda-archive-with org-archive-default-command))
  6502. (defun org-agenda-archive-default-with-confirmation ()
  6503. "Archive the entry or subtree belonging to the current agenda entry."
  6504. (interactive)
  6505. (require 'org-archive)
  6506. (org-agenda-archive-with org-archive-default-command 'confirm))
  6507. (defun org-agenda-archive ()
  6508. "Archive the entry or subtree belonging to the current agenda entry."
  6509. (interactive)
  6510. (org-agenda-archive-with 'org-archive-subtree))
  6511. (defun org-agenda-archive-to-archive-sibling ()
  6512. "Move the entry to the archive sibling."
  6513. (interactive)
  6514. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6515. (defun org-agenda-archive-with (cmd &optional confirm)
  6516. "Move the entry to the archive sibling."
  6517. (interactive)
  6518. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6519. (let* ((marker (or (org-get-at-bol 'org-marker)
  6520. (org-agenda-error)))
  6521. (buffer (marker-buffer marker))
  6522. (pos (marker-position marker)))
  6523. (org-with-remote-undo buffer
  6524. (with-current-buffer buffer
  6525. (if (eq major-mode 'org-mode)
  6526. (if (and confirm
  6527. (not (y-or-n-p "Archive this subtree or entry? ")))
  6528. (error "Abort")
  6529. (save-excursion
  6530. (goto-char pos)
  6531. (org-remove-subtree-entries-from-agenda)
  6532. (org-back-to-heading t)
  6533. (funcall cmd)))
  6534. (error "Archiving works only in Org-mode files"))))))
  6535. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6536. "Remove all lines in the agenda that correspond to a given subtree.
  6537. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6538. If this information is not given, the function uses the tree at point."
  6539. (let ((buf (or buf (current-buffer))) m p)
  6540. (save-excursion
  6541. (unless (and beg end)
  6542. (org-back-to-heading t)
  6543. (setq beg (point))
  6544. (org-end-of-subtree t)
  6545. (setq end (point)))
  6546. (set-buffer (get-buffer org-agenda-buffer-name))
  6547. (save-excursion
  6548. (goto-char (point-max))
  6549. (beginning-of-line 1)
  6550. (while (not (bobp))
  6551. (when (and (setq m (org-get-at-bol 'org-marker))
  6552. (equal buf (marker-buffer m))
  6553. (setq p (marker-position m))
  6554. (>= p beg)
  6555. (< p end))
  6556. (let ((inhibit-read-only t))
  6557. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6558. (beginning-of-line 0))))))
  6559. (defun org-agenda-refile (&optional goto rfloc no-update)
  6560. "Refile the item at point."
  6561. (interactive "P")
  6562. (if (equal goto '(16))
  6563. (org-refile-goto-last-stored)
  6564. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6565. (org-agenda-error)))
  6566. (buffer (marker-buffer marker))
  6567. (pos (marker-position marker))
  6568. (rfloc (or rfloc
  6569. (org-refile-get-location
  6570. (if goto "Goto" "Refile to") buffer
  6571. org-refile-allow-creating-parent-nodes))))
  6572. (with-current-buffer buffer
  6573. (save-excursion
  6574. (save-restriction
  6575. (widen)
  6576. (goto-char marker)
  6577. (org-remove-subtree-entries-from-agenda)
  6578. (org-refile goto buffer rfloc)))))
  6579. (unless no-update (org-agenda-redo))))
  6580. (defun org-agenda-open-link (&optional arg)
  6581. "Follow the link in the current line, if any.
  6582. This looks for a link in the displayed line in the agenda. It also looks
  6583. at the text of the entry itself."
  6584. (interactive "P")
  6585. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6586. (org-get-at-bol 'org-marker)))
  6587. (buffer (and marker (marker-buffer marker)))
  6588. (prefix (buffer-substring
  6589. (point-at-bol) (point-at-eol))))
  6590. (cond
  6591. (buffer
  6592. (with-current-buffer buffer
  6593. (save-excursion
  6594. (save-restriction
  6595. (widen)
  6596. (goto-char marker)
  6597. (org-offer-links-in-entry arg prefix)))))
  6598. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6599. (save-excursion
  6600. (beginning-of-line 1)
  6601. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6602. (org-open-link-from-string (match-string 1)))
  6603. (t (error "No link to open here")))))
  6604. (defun org-agenda-copy-local-variable (var)
  6605. "Get a variable from a referenced buffer and install it here."
  6606. (let ((m (org-get-at-bol 'org-marker)))
  6607. (when (and m (buffer-live-p (marker-buffer m)))
  6608. (org-set-local var (with-current-buffer (marker-buffer m)
  6609. (symbol-value var))))))
  6610. (defun org-agenda-switch-to (&optional delete-other-windows)
  6611. "Go to the Org-mode file which contains the item at point."
  6612. (interactive)
  6613. (if (and org-return-follows-link
  6614. (not (org-get-at-bol 'org-marker))
  6615. (org-in-regexp org-bracket-link-regexp))
  6616. (org-open-link-from-string (match-string 0))
  6617. (let* ((marker (or (org-get-at-bol 'org-marker)
  6618. (org-agenda-error)))
  6619. (buffer (marker-buffer marker))
  6620. (pos (marker-position marker)))
  6621. (org-pop-to-buffer-same-window buffer)
  6622. (and delete-other-windows (delete-other-windows))
  6623. (widen)
  6624. (goto-char pos)
  6625. (when (eq major-mode 'org-mode)
  6626. (org-show-context 'agenda)
  6627. (save-excursion
  6628. (and (outline-next-heading)
  6629. (org-flag-heading nil))) ; show the next heading
  6630. (when (outline-invisible-p)
  6631. (show-entry)))))) ; display invisible text
  6632. (defun org-agenda-goto-mouse (ev)
  6633. "Go to the Org-mode file which contains the item at the mouse click."
  6634. (interactive "e")
  6635. (mouse-set-point ev)
  6636. (org-agenda-goto))
  6637. (defun org-agenda-show (&optional full-entry)
  6638. "Display the Org-mode file which contains the item at point.
  6639. With prefix argument FULL-ENTRY, make the entire entry visible
  6640. if it was hidden in the outline."
  6641. (interactive "P")
  6642. (let ((win (selected-window)))
  6643. (if full-entry
  6644. (let ((org-show-entry-below t))
  6645. (org-agenda-goto t))
  6646. (org-agenda-goto t))
  6647. (select-window win)))
  6648. (defvar org-agenda-show-window nil)
  6649. (defun org-agenda-show-and-scroll-up ()
  6650. "Display the Org-mode file which contains the item at point.
  6651. When called repeatedly, scroll the window that is displaying the buffer."
  6652. (interactive)
  6653. (let ((win (selected-window)))
  6654. (if (and (window-live-p org-agenda-show-window)
  6655. (eq this-command last-command))
  6656. (progn
  6657. (select-window org-agenda-show-window)
  6658. (ignore-errors (scroll-up)))
  6659. (org-agenda-goto t)
  6660. (show-subtree)
  6661. (setq org-agenda-show-window (selected-window)))
  6662. (select-window win)))
  6663. (defun org-agenda-show-scroll-down ()
  6664. "Scroll down the window showing the agenda."
  6665. (interactive)
  6666. (let ((win (selected-window)))
  6667. (when (window-live-p org-agenda-show-window)
  6668. (select-window org-agenda-show-window)
  6669. (ignore-errors (scroll-down))
  6670. (select-window win))))
  6671. (defun org-agenda-show-1 (&optional more)
  6672. "Display the Org-mode file which contains the item at point.
  6673. The prefix arg selects the amount of information to display:
  6674. 0 hide the subtree
  6675. 1 just show the entry according to defaults.
  6676. 2 show the children view
  6677. 3 show the subtree view
  6678. 4 show the entire subtree and any LOGBOOK drawers
  6679. 5 show the entire subtree and any drawers
  6680. With prefix argument FULL-ENTRY, make the entire entry visible
  6681. if it was hidden in the outline."
  6682. (interactive "p")
  6683. (let ((win (selected-window)))
  6684. (org-agenda-goto t)
  6685. (org-recenter-heading 1)
  6686. (cond
  6687. ((= more 0)
  6688. (hide-subtree)
  6689. (save-excursion
  6690. (org-back-to-heading)
  6691. (run-hook-with-args 'org-cycle-hook 'folded))
  6692. (message "Remote: FOLDED"))
  6693. ((and (org-called-interactively-p 'any) (= more 1))
  6694. (message "Remote: show with default settings"))
  6695. ((= more 2)
  6696. (show-entry)
  6697. (show-children)
  6698. (save-excursion
  6699. (org-back-to-heading)
  6700. (run-hook-with-args 'org-cycle-hook 'children))
  6701. (message "Remote: CHILDREN"))
  6702. ((= more 3)
  6703. (show-subtree)
  6704. (save-excursion
  6705. (org-back-to-heading)
  6706. (run-hook-with-args 'org-cycle-hook 'subtree))
  6707. (message "Remote: SUBTREE"))
  6708. ((= more 4)
  6709. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6710. (org-drawer-regexp
  6711. (concat "^[ \t]*:\\("
  6712. (mapconcat 'regexp-quote org-drawers "\\|")
  6713. "\\):[ \t]*$")))
  6714. (show-subtree)
  6715. (save-excursion
  6716. (org-back-to-heading)
  6717. (org-cycle-hide-drawers 'subtree)))
  6718. (message "Remote: SUBTREE AND LOGBOOK"))
  6719. ((> more 4)
  6720. (show-subtree)
  6721. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6722. (select-window win)))
  6723. (defun org-recenter-heading (n)
  6724. (save-excursion
  6725. (org-back-to-heading)
  6726. (recenter n)))
  6727. (defvar org-agenda-cycle-counter nil)
  6728. (defun org-agenda-cycle-show (&optional n)
  6729. "Show the current entry in another window, with default settings.
  6730. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6731. When use repeatedly in immediate succession, the remote entry will cycle
  6732. through visibility
  6733. children -> subtree -> folded
  6734. When called with a numeric prefix arg, that arg will be passed through to
  6735. `org-agenda-show-1'. For the interpretation of that argument, see the
  6736. docstring of `org-agenda-show-1'."
  6737. (interactive "P")
  6738. (if (integerp n)
  6739. (setq org-agenda-cycle-counter n)
  6740. (if (not (eq last-command this-command))
  6741. (setq org-agenda-cycle-counter 1)
  6742. (if (equal org-agenda-cycle-counter 0)
  6743. (setq org-agenda-cycle-counter 2)
  6744. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6745. (if (> org-agenda-cycle-counter 3)
  6746. (setq org-agenda-cycle-counter 0)))))
  6747. (org-agenda-show-1 org-agenda-cycle-counter))
  6748. (defun org-agenda-recenter (arg)
  6749. "Display the Org-mode file which contains the item at point and recenter."
  6750. (interactive "P")
  6751. (let ((win (selected-window)))
  6752. (org-agenda-goto t)
  6753. (recenter arg)
  6754. (select-window win)))
  6755. (defun org-agenda-show-mouse (ev)
  6756. "Display the Org-mode file which contains the item at the mouse click."
  6757. (interactive "e")
  6758. (mouse-set-point ev)
  6759. (org-agenda-show))
  6760. (defun org-agenda-check-no-diary ()
  6761. "Check if the entry is a diary link and abort if yes."
  6762. (if (org-get-at-bol 'org-agenda-diary-link)
  6763. (org-agenda-error)))
  6764. (defun org-agenda-error ()
  6765. (error "Command not allowed in this line"))
  6766. (defun org-agenda-tree-to-indirect-buffer ()
  6767. "Show the subtree corresponding to the current entry in an indirect buffer.
  6768. This calls the command `org-tree-to-indirect-buffer' from the original
  6769. Org-mode buffer.
  6770. With numerical prefix arg ARG, go up to this level and then take that tree.
  6771. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6772. use the dedicated frame)."
  6773. (interactive)
  6774. (if (and current-prefix-arg (listp current-prefix-arg))
  6775. (org-agenda-do-tree-to-indirect-buffer)
  6776. (let ((agenda-window (selected-window))
  6777. (indirect-window
  6778. (and org-last-indirect-buffer
  6779. (get-buffer-window org-last-indirect-buffer))))
  6780. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
  6781. (unwind-protect
  6782. (progn
  6783. (unless (and indirect-window (window-live-p indirect-window))
  6784. (setq indirect-window (split-window agenda-window)))
  6785. (select-window indirect-window)
  6786. (switch-to-buffer org-last-indirect-buffer :norecord)
  6787. (fit-window-to-buffer indirect-window))
  6788. (select-window (get-buffer-window org-agenda-buffer-name))))))
  6789. (defun org-agenda-do-tree-to-indirect-buffer ()
  6790. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  6791. (org-agenda-check-no-diary)
  6792. (let* ((marker (or (org-get-at-bol 'org-marker)
  6793. (org-agenda-error)))
  6794. (buffer (marker-buffer marker))
  6795. (pos (marker-position marker)))
  6796. (with-current-buffer buffer
  6797. (save-excursion
  6798. (goto-char pos)
  6799. (call-interactively 'org-tree-to-indirect-buffer)))))
  6800. (defvar org-last-heading-marker (make-marker)
  6801. "Marker pointing to the headline that last changed its TODO state
  6802. by a remote command from the agenda.")
  6803. (defun org-agenda-todo-nextset ()
  6804. "Switch TODO entry to next sequence."
  6805. (interactive)
  6806. (org-agenda-todo 'nextset))
  6807. (defun org-agenda-todo-previousset ()
  6808. "Switch TODO entry to previous sequence."
  6809. (interactive)
  6810. (org-agenda-todo 'previousset))
  6811. (defun org-agenda-todo (&optional arg)
  6812. "Cycle TODO state of line at point, also in Org-mode file.
  6813. This changes the line at point, all other lines in the agenda referring to
  6814. the same tree node, and the headline of the tree node in the Org-mode file."
  6815. (interactive "P")
  6816. (org-agenda-check-no-diary)
  6817. (let* ((col (current-column))
  6818. (marker (or (org-get-at-bol 'org-marker)
  6819. (org-agenda-error)))
  6820. (buffer (marker-buffer marker))
  6821. (pos (marker-position marker))
  6822. (hdmarker (org-get-at-bol 'org-hd-marker))
  6823. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6824. (inhibit-read-only t)
  6825. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6826. (org-with-remote-undo buffer
  6827. (with-current-buffer buffer
  6828. (widen)
  6829. (goto-char pos)
  6830. (org-show-context 'agenda)
  6831. (save-excursion
  6832. (and (outline-next-heading)
  6833. (org-flag-heading nil))) ; show the next heading
  6834. (let ((current-prefix-arg arg))
  6835. (call-interactively 'org-todo))
  6836. (and (bolp) (forward-char 1))
  6837. (setq newhead (org-get-heading))
  6838. (when (and (org-bound-and-true-p
  6839. org-agenda-headline-snapshot-before-repeat)
  6840. (not (equal org-agenda-headline-snapshot-before-repeat
  6841. newhead))
  6842. todayp)
  6843. (setq newhead org-agenda-headline-snapshot-before-repeat
  6844. just-one t))
  6845. (save-excursion
  6846. (org-back-to-heading)
  6847. (move-marker org-last-heading-marker (point))))
  6848. (beginning-of-line 1)
  6849. (save-excursion
  6850. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6851. (org-move-to-column col))))
  6852. (defun org-agenda-add-note (&optional arg)
  6853. "Add a time-stamped note to the entry at point."
  6854. (interactive "P")
  6855. (org-agenda-check-no-diary)
  6856. (let* ((marker (or (org-get-at-bol 'org-marker)
  6857. (org-agenda-error)))
  6858. (buffer (marker-buffer marker))
  6859. (pos (marker-position marker))
  6860. (hdmarker (org-get-at-bol 'org-hd-marker))
  6861. (inhibit-read-only t))
  6862. (with-current-buffer buffer
  6863. (widen)
  6864. (goto-char pos)
  6865. (org-show-context 'agenda)
  6866. (save-excursion
  6867. (and (outline-next-heading)
  6868. (org-flag-heading nil))) ; show the next heading
  6869. (org-add-note))))
  6870. (defun org-agenda-change-all-lines (newhead hdmarker
  6871. &optional fixface just-this)
  6872. "Change all lines in the agenda buffer which match HDMARKER.
  6873. The new content of the line will be NEWHEAD (as modified by
  6874. `org-agenda-format-item'). HDMARKER is checked with
  6875. `equal' against all `org-hd-marker' text properties in the file.
  6876. If FIXFACE is non-nil, the face of each item is modified according to
  6877. the new TODO state.
  6878. If JUST-THIS is non-nil, change just the current line, not all.
  6879. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6880. (let* ((inhibit-read-only t)
  6881. (line (org-current-line))
  6882. (thetags (with-current-buffer (marker-buffer hdmarker)
  6883. (save-excursion (save-restriction (widen)
  6884. (goto-char hdmarker)
  6885. (org-get-tags-at)))))
  6886. props m pl undone-face done-face finish new dotime cat tags)
  6887. (save-excursion
  6888. (goto-char (point-max))
  6889. (beginning-of-line 1)
  6890. (while (not finish)
  6891. (setq finish (bobp))
  6892. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6893. (or (not just-this) (= (org-current-line) line))
  6894. (equal m hdmarker))
  6895. (setq props (text-properties-at (point))
  6896. dotime (org-get-at-bol 'dotime)
  6897. cat (org-get-at-bol 'org-category)
  6898. tags thetags
  6899. new
  6900. (let ((org-prefix-format-compiled
  6901. (or (get-text-property (point) 'format)
  6902. org-prefix-format-compiled)))
  6903. (with-current-buffer (marker-buffer hdmarker)
  6904. (save-excursion
  6905. (save-restriction
  6906. (widen)
  6907. (org-agenda-format-item (org-get-at-bol 'extra)
  6908. newhead cat tags dotime)))))
  6909. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  6910. undone-face (org-get-at-bol 'undone-face)
  6911. done-face (org-get-at-bol 'done-face))
  6912. (beginning-of-line 1)
  6913. (cond
  6914. ((equal new "")
  6915. (and (looking-at ".*\n?") (replace-match "")))
  6916. ((looking-at ".*")
  6917. (replace-match new t t)
  6918. (beginning-of-line 1)
  6919. (add-text-properties (point-at-bol) (point-at-eol) props)
  6920. (when fixface
  6921. (add-text-properties
  6922. (point-at-bol) (point-at-eol)
  6923. (list 'face
  6924. (if org-last-todo-state-is-todo
  6925. undone-face done-face))))
  6926. (org-agenda-highlight-todo 'line)
  6927. (beginning-of-line 1))
  6928. (t (error "Line update did not work"))))
  6929. (beginning-of-line 0)))
  6930. (org-finalize-agenda)))
  6931. (defun org-agenda-align-tags (&optional line)
  6932. "Align all tags in agenda items to `org-agenda-tags-column'."
  6933. (let ((inhibit-read-only t) l c)
  6934. (save-excursion
  6935. (goto-char (if line (point-at-bol) (point-min)))
  6936. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6937. (if line (point-at-eol) nil) t)
  6938. (add-text-properties
  6939. (match-beginning 2) (match-end 2)
  6940. (list 'face (delq nil (let ((prop (get-text-property
  6941. (match-beginning 2) 'face)))
  6942. (or (listp prop) (setq prop (list prop)))
  6943. (if (memq 'org-tag prop)
  6944. prop
  6945. (cons 'org-tag prop))))))
  6946. (setq l (- (match-end 2) (match-beginning 2))
  6947. c (if (< org-agenda-tags-column 0)
  6948. (- (abs org-agenda-tags-column) l)
  6949. org-agenda-tags-column))
  6950. (delete-region (match-beginning 1) (match-end 1))
  6951. (goto-char (match-beginning 1))
  6952. (insert (org-add-props
  6953. (make-string (max 1 (- c (current-column))) ?\ )
  6954. (plist-put (copy-sequence (text-properties-at (point)))
  6955. 'face nil))))
  6956. (goto-char (point-min))
  6957. (org-font-lock-add-tag-faces (point-max)))))
  6958. (defun org-agenda-priority-up ()
  6959. "Increase the priority of line at point, also in Org-mode file."
  6960. (interactive)
  6961. (org-agenda-priority 'up))
  6962. (defun org-agenda-priority-down ()
  6963. "Decrease the priority of line at point, also in Org-mode file."
  6964. (interactive)
  6965. (org-agenda-priority 'down))
  6966. (defun org-agenda-priority (&optional force-direction)
  6967. "Set the priority of line at point, also in Org-mode file.
  6968. This changes the line at point, all other lines in the agenda referring to
  6969. the same tree node, and the headline of the tree node in the Org-mode file."
  6970. (interactive)
  6971. (unless org-enable-priority-commands
  6972. (error "Priority commands are disabled"))
  6973. (org-agenda-check-no-diary)
  6974. (let* ((marker (or (org-get-at-bol 'org-marker)
  6975. (org-agenda-error)))
  6976. (hdmarker (org-get-at-bol 'org-hd-marker))
  6977. (buffer (marker-buffer hdmarker))
  6978. (pos (marker-position hdmarker))
  6979. (inhibit-read-only t)
  6980. newhead)
  6981. (org-with-remote-undo buffer
  6982. (with-current-buffer buffer
  6983. (widen)
  6984. (goto-char pos)
  6985. (org-show-context 'agenda)
  6986. (save-excursion
  6987. (and (outline-next-heading)
  6988. (org-flag-heading nil))) ; show the next heading
  6989. (funcall 'org-priority force-direction)
  6990. (end-of-line 1)
  6991. (setq newhead (org-get-heading)))
  6992. (org-agenda-change-all-lines newhead hdmarker)
  6993. (beginning-of-line 1))))
  6994. ;; FIXME: should fix the tags property of the agenda line.
  6995. (defun org-agenda-set-tags (&optional tag onoff)
  6996. "Set tags for the current headline."
  6997. (interactive)
  6998. (org-agenda-check-no-diary)
  6999. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7000. (call-interactively 'org-change-tag-in-region)
  7001. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7002. (org-agenda-error)))
  7003. (buffer (marker-buffer hdmarker))
  7004. (pos (marker-position hdmarker))
  7005. (inhibit-read-only t)
  7006. newhead)
  7007. (org-with-remote-undo buffer
  7008. (with-current-buffer buffer
  7009. (widen)
  7010. (goto-char pos)
  7011. (save-excursion
  7012. (org-show-context 'agenda))
  7013. (save-excursion
  7014. (and (outline-next-heading)
  7015. (org-flag-heading nil))) ; show the next heading
  7016. (goto-char pos)
  7017. (if tag
  7018. (org-toggle-tag tag onoff)
  7019. (call-interactively 'org-set-tags))
  7020. (end-of-line 1)
  7021. (setq newhead (org-get-heading)))
  7022. (org-agenda-change-all-lines newhead hdmarker)
  7023. (beginning-of-line 1)))))
  7024. (defun org-agenda-set-property ()
  7025. "Set a property for the current headline."
  7026. (interactive)
  7027. (org-agenda-check-no-diary)
  7028. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7029. (org-agenda-error)))
  7030. (buffer (marker-buffer hdmarker))
  7031. (pos (marker-position hdmarker))
  7032. (inhibit-read-only t)
  7033. newhead)
  7034. (org-with-remote-undo buffer
  7035. (with-current-buffer buffer
  7036. (widen)
  7037. (goto-char pos)
  7038. (save-excursion
  7039. (org-show-context 'agenda))
  7040. (save-excursion
  7041. (and (outline-next-heading)
  7042. (org-flag-heading nil))) ; show the next heading
  7043. (goto-char pos)
  7044. (call-interactively 'org-set-property)))))
  7045. (defun org-agenda-set-effort ()
  7046. "Set the effort property for the current headline."
  7047. (interactive)
  7048. (org-agenda-check-no-diary)
  7049. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7050. (org-agenda-error)))
  7051. (buffer (marker-buffer hdmarker))
  7052. (pos (marker-position hdmarker))
  7053. (inhibit-read-only t)
  7054. newhead)
  7055. (org-with-remote-undo buffer
  7056. (with-current-buffer buffer
  7057. (widen)
  7058. (goto-char pos)
  7059. (save-excursion
  7060. (org-show-context 'agenda))
  7061. (save-excursion
  7062. (and (outline-next-heading)
  7063. (org-flag-heading nil))) ; show the next heading
  7064. (goto-char pos)
  7065. (call-interactively 'org-set-effort)
  7066. (end-of-line 1)
  7067. (setq newhead (org-get-heading)))
  7068. (org-agenda-change-all-lines newhead hdmarker))))
  7069. (defun org-agenda-toggle-archive-tag ()
  7070. "Toggle the archive tag for the current entry."
  7071. (interactive)
  7072. (org-agenda-check-no-diary)
  7073. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7074. (org-agenda-error)))
  7075. (buffer (marker-buffer hdmarker))
  7076. (pos (marker-position hdmarker))
  7077. (inhibit-read-only t)
  7078. newhead)
  7079. (org-with-remote-undo buffer
  7080. (with-current-buffer buffer
  7081. (widen)
  7082. (goto-char pos)
  7083. (org-show-context 'agenda)
  7084. (save-excursion
  7085. (and (outline-next-heading)
  7086. (org-flag-heading nil))) ; show the next heading
  7087. (call-interactively 'org-toggle-archive-tag)
  7088. (end-of-line 1)
  7089. (setq newhead (org-get-heading)))
  7090. (org-agenda-change-all-lines newhead hdmarker)
  7091. (beginning-of-line 1))))
  7092. (defun org-agenda-do-date-later (arg)
  7093. (interactive "P")
  7094. (cond
  7095. ((or (equal arg '(16))
  7096. (memq last-command
  7097. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7098. (setq this-command 'org-agenda-date-later-minutes)
  7099. (org-agenda-date-later-minutes 1))
  7100. ((or (equal arg '(4))
  7101. (memq last-command
  7102. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7103. (setq this-command 'org-agenda-date-later-hours)
  7104. (org-agenda-date-later-hours 1))
  7105. (t
  7106. (org-agenda-date-later (prefix-numeric-value arg)))))
  7107. (defun org-agenda-do-date-earlier (arg)
  7108. (interactive "P")
  7109. (cond
  7110. ((or (equal arg '(16))
  7111. (memq last-command
  7112. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7113. (setq this-command 'org-agenda-date-earlier-minutes)
  7114. (org-agenda-date-earlier-minutes 1))
  7115. ((or (equal arg '(4))
  7116. (memq last-command
  7117. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7118. (setq this-command 'org-agenda-date-earlier-hours)
  7119. (org-agenda-date-earlier-hours 1))
  7120. (t
  7121. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7122. (defun org-agenda-date-later (arg &optional what)
  7123. "Change the date of this item to ARG day(s) later."
  7124. (interactive "p")
  7125. (org-agenda-check-type t 'agenda 'timeline)
  7126. (org-agenda-check-no-diary)
  7127. (let* ((marker (or (org-get-at-bol 'org-marker)
  7128. (org-agenda-error)))
  7129. (buffer (marker-buffer marker))
  7130. (pos (marker-position marker))
  7131. cdate today)
  7132. (org-with-remote-undo buffer
  7133. (with-current-buffer buffer
  7134. (widen)
  7135. (goto-char pos)
  7136. (if (not (org-at-timestamp-p))
  7137. (error "Cannot find time stamp"))
  7138. (when (and org-agenda-move-date-from-past-immediately-to-today
  7139. (equal arg 1)
  7140. (or (not what) (eq what 'day))
  7141. (not (save-match-data (org-at-date-range-p))))
  7142. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7143. cdate (calendar-absolute-from-gregorian
  7144. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7145. today (org-today))
  7146. (if (> today cdate)
  7147. ;; immediately shift to today
  7148. (setq arg (- today cdate))))
  7149. (org-timestamp-change arg (or what 'day))
  7150. (when (and (org-at-date-range-p)
  7151. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7152. (let ((end org-last-changed-timestamp))
  7153. (org-timestamp-change arg (or what 'day))
  7154. (setq org-last-changed-timestamp
  7155. (concat org-last-changed-timestamp "--" end)))))
  7156. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7157. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7158. (defun org-agenda-date-earlier (arg &optional what)
  7159. "Change the date of this item to ARG day(s) earlier."
  7160. (interactive "p")
  7161. (org-agenda-date-later (- arg) what))
  7162. (defun org-agenda-date-later-minutes (arg)
  7163. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7164. (interactive "p")
  7165. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7166. (org-agenda-date-later arg 'minute))
  7167. (defun org-agenda-date-earlier-minutes (arg)
  7168. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7169. (interactive "p")
  7170. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7171. (org-agenda-date-earlier arg 'minute))
  7172. (defun org-agenda-date-later-hours (arg)
  7173. "Change the time of this item, in hour steps."
  7174. (interactive "p")
  7175. (org-agenda-date-later arg 'hour))
  7176. (defun org-agenda-date-earlier-hours (arg)
  7177. "Change the time of this item, in hour steps."
  7178. (interactive "p")
  7179. (org-agenda-date-earlier arg 'hour))
  7180. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7181. "Show new date stamp via text properties."
  7182. ;; We use text properties to make this undoable
  7183. (let ((inhibit-read-only t)
  7184. (buffer-invisibility-spec))
  7185. (setq stamp (concat " " prefix " => " stamp))
  7186. (save-excursion
  7187. (goto-char (point-max))
  7188. (while (not (bobp))
  7189. (when (equal marker (org-get-at-bol 'org-marker))
  7190. (org-move-to-column (- (window-width) (length stamp)) t)
  7191. (org-agenda-fix-tags-filter-overlays-at (point))
  7192. (if (featurep 'xemacs)
  7193. ;; Use `duplicable' property to trigger undo recording
  7194. (let ((ex (make-extent nil nil))
  7195. (gl (make-glyph stamp)))
  7196. (set-glyph-face gl 'secondary-selection)
  7197. (set-extent-properties
  7198. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7199. (insert-extent ex (1- (point)) (point-at-eol)))
  7200. (add-text-properties
  7201. (1- (point)) (point-at-eol)
  7202. (list 'display (org-add-props stamp nil
  7203. 'face 'secondary-selection))))
  7204. (beginning-of-line 1))
  7205. (beginning-of-line 0)))))
  7206. (defun org-agenda-date-prompt (arg)
  7207. "Change the date of this item. Date is prompted for, with default today.
  7208. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7209. be used to request time specification in the time stamp."
  7210. (interactive "P")
  7211. (org-agenda-check-type t 'agenda 'timeline)
  7212. (org-agenda-check-no-diary)
  7213. (let* ((marker (or (org-get-at-bol 'org-marker)
  7214. (org-agenda-error)))
  7215. (buffer (marker-buffer marker))
  7216. (pos (marker-position marker)))
  7217. (org-with-remote-undo buffer
  7218. (with-current-buffer buffer
  7219. (widen)
  7220. (goto-char pos)
  7221. (if (not (org-at-timestamp-p t))
  7222. (error "Cannot find time stamp"))
  7223. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7224. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7225. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7226. (defun org-agenda-schedule (arg &optional time)
  7227. "Schedule the item at point.
  7228. ARG is passed through to `org-schedule'."
  7229. (interactive "P")
  7230. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7231. (org-agenda-check-no-diary)
  7232. (let* ((marker (or (org-get-at-bol 'org-marker)
  7233. (org-agenda-error)))
  7234. (type (marker-insertion-type marker))
  7235. (buffer (marker-buffer marker))
  7236. (pos (marker-position marker))
  7237. (org-insert-labeled-timestamps-at-point nil)
  7238. ts)
  7239. (set-marker-insertion-type marker t)
  7240. (org-with-remote-undo buffer
  7241. (with-current-buffer buffer
  7242. (widen)
  7243. (goto-char pos)
  7244. (setq ts (org-schedule arg time)))
  7245. (org-agenda-show-new-time marker ts "S"))
  7246. (message "Item scheduled for %s" ts)))
  7247. (defun org-agenda-deadline (arg &optional time)
  7248. "Schedule the item at point.
  7249. ARG is passed through to `org-deadline'."
  7250. (interactive "P")
  7251. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7252. (org-agenda-check-no-diary)
  7253. (let* ((marker (or (org-get-at-bol 'org-marker)
  7254. (org-agenda-error)))
  7255. (buffer (marker-buffer marker))
  7256. (pos (marker-position marker))
  7257. (org-insert-labeled-timestamps-at-point nil)
  7258. ts)
  7259. (org-with-remote-undo buffer
  7260. (with-current-buffer buffer
  7261. (widen)
  7262. (goto-char pos)
  7263. (setq ts (org-deadline arg time)))
  7264. (org-agenda-show-new-time marker ts "D"))
  7265. (message "Deadline for this item set to %s" ts)))
  7266. (defun org-agenda-action ()
  7267. "Select entry for agenda action, or execute an agenda action.
  7268. This command prompts for another letter. Valid inputs are:
  7269. m Mark the entry at point for an agenda action
  7270. s Schedule the marked entry to the date at the cursor
  7271. d Set the deadline of the marked entry to the date at the cursor
  7272. r Call `org-remember' with cursor date as the default date
  7273. c Call `org-capture' with cursor date as the default date
  7274. SPC Show marked entry in other window
  7275. TAB Visit marked entry in other window
  7276. The cursor may be at a date in the calendar, or in the Org agenda."
  7277. (interactive)
  7278. (let (ans)
  7279. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7280. (setq ans (read-char-exclusive))
  7281. (cond
  7282. ((equal ans ?m)
  7283. ;; Mark this entry
  7284. (if (eq major-mode 'org-agenda-mode)
  7285. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7286. (org-get-at-bol 'org-marker))))
  7287. (if m
  7288. (progn
  7289. (move-marker org-agenda-action-marker
  7290. (marker-position m) (marker-buffer m))
  7291. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7292. (error "Don't know which entry to mark")))
  7293. (error "This command works only in the agenda")))
  7294. ((equal ans ?s)
  7295. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7296. ((equal ans ?d)
  7297. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7298. ((equal ans ?r)
  7299. (org-agenda-do-action '(org-remember) t))
  7300. ((equal ans ?c)
  7301. (org-agenda-do-action '(org-capture) t))
  7302. ((equal ans ?\ )
  7303. (let ((cw (selected-window)))
  7304. (org-switch-to-buffer-other-window
  7305. (marker-buffer org-agenda-action-marker))
  7306. (goto-char org-agenda-action-marker)
  7307. (org-show-context 'agenda)
  7308. (select-window cw)))
  7309. ((equal ans ?\C-i)
  7310. (org-switch-to-buffer-other-window
  7311. (marker-buffer org-agenda-action-marker))
  7312. (goto-char org-agenda-action-marker)
  7313. (org-show-context 'agenda))
  7314. (t (error "Invalid agenda action %c" ans)))))
  7315. (defun org-agenda-do-action (form &optional current-buffer)
  7316. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7317. (let ((org-overriding-default-time (org-get-cursor-date)))
  7318. (if current-buffer
  7319. (eval form)
  7320. (if (not (marker-buffer org-agenda-action-marker))
  7321. (error "No entry has been selected for agenda action")
  7322. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7323. (save-excursion
  7324. (save-restriction
  7325. (widen)
  7326. (goto-char org-agenda-action-marker)
  7327. (eval form))))))))
  7328. (defun org-agenda-clock-in (&optional arg)
  7329. "Start the clock on the currently selected item."
  7330. (interactive "P")
  7331. (org-agenda-check-no-diary)
  7332. (if (equal arg '(4))
  7333. (org-clock-in arg)
  7334. (let* ((marker (or (org-get-at-bol 'org-marker)
  7335. (org-agenda-error)))
  7336. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7337. marker))
  7338. (pos (marker-position marker))
  7339. newhead)
  7340. (org-with-remote-undo (marker-buffer marker)
  7341. (with-current-buffer (marker-buffer marker)
  7342. (widen)
  7343. (goto-char pos)
  7344. (org-show-context 'agenda)
  7345. (org-show-entry)
  7346. (org-cycle-hide-drawers 'children)
  7347. (org-clock-in arg)
  7348. (setq newhead (org-get-heading)))
  7349. (org-agenda-change-all-lines newhead hdmarker)))))
  7350. (defun org-agenda-clock-out ()
  7351. "Stop the currently running clock."
  7352. (interactive)
  7353. (unless (marker-buffer org-clock-marker)
  7354. (error "No running clock"))
  7355. (let ((marker (make-marker)) newhead)
  7356. (org-with-remote-undo (marker-buffer org-clock-marker)
  7357. (with-current-buffer (marker-buffer org-clock-marker)
  7358. (save-excursion
  7359. (save-restriction
  7360. (widen)
  7361. (goto-char org-clock-marker)
  7362. (org-back-to-heading t)
  7363. (move-marker marker (point))
  7364. (org-clock-out)
  7365. (setq newhead (org-get-heading))))))
  7366. (org-agenda-change-all-lines newhead marker)
  7367. (move-marker marker nil)))
  7368. (defun org-agenda-clock-cancel (&optional arg)
  7369. "Cancel the currently running clock."
  7370. (interactive "P")
  7371. (unless (marker-buffer org-clock-marker)
  7372. (error "No running clock"))
  7373. (org-with-remote-undo (marker-buffer org-clock-marker)
  7374. (org-clock-cancel)))
  7375. (defun org-agenda-clock-goto ()
  7376. "Jump to the currently clocked in task within the agenda.
  7377. If the currently clocked in task is not listed in the agenda
  7378. buffer, display it in another window."
  7379. (interactive)
  7380. (let (pos)
  7381. (mapc (lambda (o)
  7382. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7383. (setq pos (overlay-start o))))
  7384. (overlays-in (point-min) (point-max)))
  7385. (cond (pos (goto-char pos))
  7386. ;; If the currently clocked entry is not in the agenda
  7387. ;; buffer, we visit it in another window:
  7388. (org-clock-current-task
  7389. (org-switch-to-buffer-other-window (org-clock-goto)))
  7390. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7391. (defun org-agenda-diary-entry-in-org-file ()
  7392. "Make a diary entry in the file `org-agenda-diary-file'."
  7393. (let (d1 d2 char (text "") dp1 dp2)
  7394. (if (equal (buffer-name) "*Calendar*")
  7395. (setq d1 (calendar-cursor-to-date t)
  7396. d2 (car calendar-mark-ring))
  7397. (setq dp1 (get-text-property (point-at-bol) 'day))
  7398. (unless dp1 (error "No date defined in current line"))
  7399. (setq d1 (calendar-gregorian-from-absolute dp1)
  7400. d2 (and (ignore-errors (mark))
  7401. (save-excursion
  7402. (goto-char (mark))
  7403. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7404. (calendar-gregorian-from-absolute dp2))))
  7405. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7406. (setq char (read-char-exclusive))
  7407. (cond
  7408. ((equal char ?d)
  7409. (setq text (read-string "Day entry: "))
  7410. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7411. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7412. ((equal char ?a)
  7413. (setq d1 (list (car d1) (nth 1 d1)
  7414. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7415. (nth 2 d1))))
  7416. (setq text (read-string "Anniversary (use %d to show years): "))
  7417. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7418. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7419. ((equal char ?b)
  7420. (setq text (read-string "Block entry: "))
  7421. (unless (and d1 d2 (not (equal d1 d2)))
  7422. (error "No block of days selected"))
  7423. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7424. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7425. ((equal char ?j)
  7426. (org-switch-to-buffer-other-window
  7427. (find-file-noselect org-agenda-diary-file))
  7428. (require 'org-datetree)
  7429. (org-datetree-find-date-create d1)
  7430. (org-reveal t))
  7431. (t (error "Invalid selection character `%c'" char)))))
  7432. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7433. "Where in `org-agenda-diary-file' should new entries be added?
  7434. Valid values:
  7435. date-tree in the date tree, as child of the date
  7436. top-level as top-level entries at the end of the file."
  7437. :group 'org-agenda
  7438. :type '(choice
  7439. (const :tag "in a date tree" date-tree)
  7440. (const :tag "as top level at end of file" top-level)))
  7441. (defcustom org-agenda-insert-diary-extract-time nil
  7442. "Non-nil means extract any time specification from the diary entry."
  7443. :group 'org-agenda
  7444. :type 'boolean)
  7445. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7446. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7447. If TEXT is not empty, it will become the headline of the new entry, and
  7448. the resulting entry will not be shown. When TEXT is empty, switch to
  7449. `org-agenda-diary-file' and let the user finish the entry there."
  7450. (let ((cw (current-window-configuration)))
  7451. (org-switch-to-buffer-other-window
  7452. (find-file-noselect org-agenda-diary-file))
  7453. (widen)
  7454. (goto-char (point-min))
  7455. (cond
  7456. ((eq type 'anniversary)
  7457. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7458. (progn
  7459. (or (org-at-heading-p t)
  7460. (progn
  7461. (outline-next-heading)
  7462. (insert "* Anniversaries\n\n")
  7463. (beginning-of-line -1)))))
  7464. (outline-next-heading)
  7465. (org-back-over-empty-lines)
  7466. (backward-char 1)
  7467. (insert "\n")
  7468. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7469. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7470. ((eq type 'day)
  7471. (let ((org-prefix-has-time t)
  7472. (org-agenda-time-leading-zero t)
  7473. fmt time time2)
  7474. (if org-agenda-insert-diary-extract-time
  7475. ;; Use org-agenda-format-item to parse text for a time-range and
  7476. ;; remove it. FIXME: This is a hack, we should refactor
  7477. ;; that function to make time extraction available separately
  7478. (setq fmt (org-agenda-format-item nil text nil nil t)
  7479. time (get-text-property 0 'time fmt)
  7480. time2 (if (> (length time) 0)
  7481. ;; split-string removes trailing ...... if
  7482. ;; no end time given. First space
  7483. ;; separates time from date.
  7484. (concat " " (car (split-string time "\\.")))
  7485. nil)
  7486. text (get-text-property 0 'txt fmt)))
  7487. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7488. (org-agenda-insert-diary-as-top-level text)
  7489. (require 'org-datetree)
  7490. (org-datetree-find-date-create d1)
  7491. (org-agenda-insert-diary-make-new-entry text))
  7492. (org-insert-time-stamp (org-time-from-absolute
  7493. (calendar-absolute-from-gregorian d1))
  7494. nil nil nil nil time2))
  7495. (end-of-line 0))
  7496. ((eq type 'block)
  7497. (if (> (calendar-absolute-from-gregorian d1)
  7498. (calendar-absolute-from-gregorian d2))
  7499. (setq d1 (prog1 d2 (setq d2 d1))))
  7500. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7501. (org-agenda-insert-diary-as-top-level text)
  7502. (require 'org-datetree)
  7503. (org-datetree-find-date-create d1)
  7504. (org-agenda-insert-diary-make-new-entry text))
  7505. (org-insert-time-stamp (org-time-from-absolute
  7506. (calendar-absolute-from-gregorian d1)))
  7507. (insert "--")
  7508. (org-insert-time-stamp (org-time-from-absolute
  7509. (calendar-absolute-from-gregorian d2)))
  7510. (end-of-line 0)))
  7511. (if (string-match "\\S-" text)
  7512. (progn
  7513. (set-window-configuration cw)
  7514. (message "%s entry added to %s"
  7515. (capitalize (symbol-name type))
  7516. (abbreviate-file-name org-agenda-diary-file)))
  7517. (org-reveal t)
  7518. (message "Please finish entry here"))))
  7519. (defun org-agenda-insert-diary-as-top-level (text)
  7520. "Make new entry as a top-level entry at the end of the file.
  7521. Add TEXT as headline, and position the cursor in the second line so that
  7522. a timestamp can be added there."
  7523. (widen)
  7524. (goto-char (point-max))
  7525. (or (bolp) (insert "\n"))
  7526. (insert "* " text "\n")
  7527. (if org-adapt-indentation (org-indent-to-column 2)))
  7528. (defun org-agenda-insert-diary-make-new-entry (text)
  7529. "Make new entry as last child of current entry.
  7530. Add TEXT as headline, and position the cursor in the second line so that
  7531. a timestamp can be added there."
  7532. (let ((org-show-following-heading t)
  7533. (org-show-siblings t)
  7534. (org-show-hierarchy-above t)
  7535. (org-show-entry-below t)
  7536. col)
  7537. (outline-next-heading)
  7538. (org-back-over-empty-lines)
  7539. (or (looking-at "[ \t]*$")
  7540. (progn (insert "\n") (backward-char 1)))
  7541. (org-insert-heading nil t)
  7542. (org-do-demote)
  7543. (setq col (current-column))
  7544. (insert text "\n")
  7545. (if org-adapt-indentation (org-indent-to-column col))
  7546. (let ((org-show-following-heading t)
  7547. (org-show-siblings t)
  7548. (org-show-hierarchy-above t)
  7549. (org-show-entry-below t))
  7550. (org-show-context))))
  7551. (defun org-agenda-diary-entry ()
  7552. "Make a diary entry, like the `i' command from the calendar.
  7553. All the standard commands work: block, weekly etc.
  7554. When `org-agenda-diary-file' points to a file,
  7555. `org-agenda-diary-entry-in-org-file' is called instead to create
  7556. entries in that Org-mode file."
  7557. (interactive)
  7558. (org-agenda-check-type t 'agenda 'timeline)
  7559. (if (not (eq org-agenda-diary-file 'diary-file))
  7560. (org-agenda-diary-entry-in-org-file)
  7561. (require 'diary-lib)
  7562. (let* ((char (progn
  7563. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7564. (read-char-exclusive)))
  7565. (cmd (cdr (assoc char
  7566. '((?d . insert-diary-entry)
  7567. (?w . insert-weekly-diary-entry)
  7568. (?m . insert-monthly-diary-entry)
  7569. (?y . insert-yearly-diary-entry)
  7570. (?a . insert-anniversary-diary-entry)
  7571. (?b . insert-block-diary-entry)
  7572. (?c . insert-cyclic-diary-entry)))))
  7573. (oldf (symbol-function 'calendar-cursor-to-date))
  7574. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7575. (point (point))
  7576. (mark (or (mark t) (point))))
  7577. (unless cmd
  7578. (error "No command associated with <%c>" char))
  7579. (unless (and (get-text-property point 'day)
  7580. (or (not (equal ?b char))
  7581. (get-text-property mark 'day)))
  7582. (error "Don't know which date to use for diary entry"))
  7583. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7584. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7585. (let ((calendar-mark-ring
  7586. (list (calendar-gregorian-from-absolute
  7587. (or (get-text-property mark 'day)
  7588. (get-text-property point 'day))))))
  7589. (unwind-protect
  7590. (progn
  7591. (fset 'calendar-cursor-to-date
  7592. (lambda (&optional error dummy)
  7593. (calendar-gregorian-from-absolute
  7594. (get-text-property point 'day))))
  7595. (call-interactively cmd))
  7596. (fset 'calendar-cursor-to-date oldf))))))
  7597. (defun org-agenda-execute-calendar-command (cmd)
  7598. "Execute a calendar command from the agenda, with the date associated to
  7599. the cursor position."
  7600. (org-agenda-check-type t 'agenda 'timeline)
  7601. (require 'diary-lib)
  7602. (unless (get-text-property (point) 'day)
  7603. (error "Don't know which date to use for calendar command"))
  7604. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7605. (point (point))
  7606. (date (calendar-gregorian-from-absolute
  7607. (get-text-property point 'day)))
  7608. ;; the following 2 vars are needed in the calendar
  7609. (displayed-month (car date))
  7610. (displayed-year (nth 2 date)))
  7611. (unwind-protect
  7612. (progn
  7613. (fset 'calendar-cursor-to-date
  7614. (lambda (&optional error dummy)
  7615. (calendar-gregorian-from-absolute
  7616. (get-text-property point 'day))))
  7617. (call-interactively cmd))
  7618. (fset 'calendar-cursor-to-date oldf))))
  7619. (defun org-agenda-phases-of-moon ()
  7620. "Display the phases of the moon for the 3 months around the cursor date."
  7621. (interactive)
  7622. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7623. (defun org-agenda-holidays ()
  7624. "Display the holidays for the 3 months around the cursor date."
  7625. (interactive)
  7626. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7627. (defvar calendar-longitude)
  7628. (defvar calendar-latitude)
  7629. (defvar calendar-location-name)
  7630. (defun org-agenda-sunrise-sunset (arg)
  7631. "Display sunrise and sunset for the cursor date.
  7632. Latitude and longitude can be specified with the variables
  7633. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7634. argument, latitude and longitude will be prompted for."
  7635. (interactive "P")
  7636. (require 'solar)
  7637. (let ((calendar-longitude (if arg nil calendar-longitude))
  7638. (calendar-latitude (if arg nil calendar-latitude))
  7639. (calendar-location-name
  7640. (if arg "the given coordinates" calendar-location-name)))
  7641. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7642. (defun org-agenda-goto-calendar ()
  7643. "Open the Emacs calendar with the date at the cursor."
  7644. (interactive)
  7645. (org-agenda-check-type t 'agenda 'timeline)
  7646. (let* ((day (or (get-text-property (point) 'day)
  7647. (error "Don't know which date to open in calendar")))
  7648. (date (calendar-gregorian-from-absolute day))
  7649. (calendar-move-hook nil)
  7650. (calendar-view-holidays-initially-flag nil)
  7651. (calendar-view-diary-initially-flag nil))
  7652. (calendar)
  7653. (calendar-goto-date date)))
  7654. ;;;###autoload
  7655. (defun org-calendar-goto-agenda ()
  7656. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7657. This is a command that has to be installed in `calendar-mode-map'."
  7658. (interactive)
  7659. (org-agenda-list nil (calendar-absolute-from-gregorian
  7660. (calendar-cursor-to-date))
  7661. nil))
  7662. (defun org-agenda-convert-date ()
  7663. (interactive)
  7664. (org-agenda-check-type t 'agenda 'timeline)
  7665. (let ((day (get-text-property (point) 'day))
  7666. date s)
  7667. (unless day
  7668. (error "Don't know which date to convert"))
  7669. (setq date (calendar-gregorian-from-absolute day))
  7670. (setq s (concat
  7671. "Gregorian: " (calendar-date-string date) "\n"
  7672. "ISO: " (calendar-iso-date-string date) "\n"
  7673. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7674. "Julian: " (calendar-julian-date-string date) "\n"
  7675. "Astron. JD: " (calendar-astro-date-string date)
  7676. " (Julian date number at noon UTC)\n"
  7677. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7678. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7679. "French: " (calendar-french-date-string date) "\n"
  7680. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7681. "Mayan: " (calendar-mayan-date-string date) "\n"
  7682. "Coptic: " (calendar-coptic-date-string date) "\n"
  7683. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7684. "Persian: " (calendar-persian-date-string date) "\n"
  7685. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7686. (with-output-to-temp-buffer "*Dates*"
  7687. (princ s))
  7688. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7689. ;;; Bulk commands
  7690. (defvar org-agenda-bulk-marked-entries nil
  7691. "List of markers that refer to marked entries in the agenda.")
  7692. (defun org-agenda-bulk-marked-p ()
  7693. (eq (get-char-property (point-at-bol) 'type)
  7694. 'org-marked-entry-overlay))
  7695. (defun org-agenda-bulk-mark (&optional arg)
  7696. "Mark the entry at point for future bulk action."
  7697. (interactive "p")
  7698. (dotimes (i (max arg 1))
  7699. (unless (org-get-at-bol 'org-agenda-diary-link)
  7700. (let* ((m (org-get-at-bol 'org-hd-marker))
  7701. ov)
  7702. (unless (org-agenda-bulk-marked-p)
  7703. (unless m (error "Nothing to mark at point"))
  7704. (push m org-agenda-bulk-marked-entries)
  7705. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7706. (org-overlay-display ov "> "
  7707. (org-get-todo-face "TODO")
  7708. 'evaporate)
  7709. (overlay-put ov 'type 'org-marked-entry-overlay))
  7710. (beginning-of-line 2)
  7711. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7712. (beginning-of-line 2))
  7713. (message "%d entries marked for bulk action"
  7714. (length org-agenda-bulk-marked-entries))))))
  7715. (defun org-agenda-bulk-mark-regexp (regexp)
  7716. "Mark entries match REGEXP."
  7717. (interactive "sMark entries matching regexp: ")
  7718. (let (entries-marked)
  7719. (save-excursion
  7720. (goto-char (point-min))
  7721. (goto-char (next-single-property-change (point) 'txt))
  7722. (while (re-search-forward regexp nil t)
  7723. (when (string-match regexp (get-text-property (point) 'txt))
  7724. (setq entries-marked (+ entries-marked 1))
  7725. (call-interactively 'org-agenda-bulk-mark))))
  7726. (if (not entries-marked)
  7727. (message "No entry matching this regexp."))))
  7728. (defun org-agenda-bulk-unmark ()
  7729. "Unmark the entry at point for future bulk action."
  7730. (interactive)
  7731. (when (org-agenda-bulk-marked-p)
  7732. (org-agenda-bulk-remove-overlays
  7733. (point-at-bol) (+ 2 (point-at-bol)))
  7734. (setq org-agenda-bulk-marked-entries
  7735. (delete (org-get-at-bol 'org-hd-marker)
  7736. org-agenda-bulk-marked-entries)))
  7737. (beginning-of-line 2)
  7738. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7739. (beginning-of-line 2))
  7740. (message "%d entries marked for bulk action"
  7741. (length org-agenda-bulk-marked-entries)))
  7742. (defun org-agenda-bulk-toggle ()
  7743. "Toggle marking the entry at point for bulk action."
  7744. (interactive)
  7745. (if (org-agenda-bulk-marked-p)
  7746. (org-agenda-bulk-unmark)
  7747. (org-agenda-bulk-mark)))
  7748. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7749. "Remove the mark overlays between BEG and END in the agenda buffer.
  7750. BEG and END default to the buffer limits.
  7751. This only removes the overlays, it does not remove the markers
  7752. from the list in `org-agenda-bulk-marked-entries'."
  7753. (interactive)
  7754. (mapc (lambda (ov)
  7755. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7756. (delete-overlay ov)))
  7757. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7758. (defun org-agenda-bulk-remove-all-marks ()
  7759. "Remove all marks in the agenda buffer.
  7760. This will remove the markers, and the overlays."
  7761. (interactive)
  7762. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7763. (setq org-agenda-bulk-marked-entries nil)
  7764. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7765. (defun org-agenda-bulk-action (&optional arg)
  7766. "Execute an remote-editing action on all marked entries.
  7767. The prefix arg is passed through to the command if possible."
  7768. (interactive "P")
  7769. ;; Make sure we have markers, and only valid ones
  7770. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  7771. (mapc
  7772. (lambda (m)
  7773. (unless (and (markerp m)
  7774. (marker-buffer m)
  7775. (buffer-live-p (marker-buffer m))
  7776. (marker-position m))
  7777. (error "Marker %s for bulk command is invalid" m)))
  7778. org-agenda-bulk-marked-entries)
  7779. ;; Prompt for the bulk command
  7780. (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
  7781. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
  7782. (when org-agenda-bulk-custom-functions
  7783. (concat " Custom: ["
  7784. (mapconcat (lambda(f) (char-to-string (car f)))
  7785. org-agenda-bulk-custom-functions "")
  7786. "]"))))
  7787. (let* ((action (read-char-exclusive))
  7788. (org-log-refile (if org-log-refile 'time nil))
  7789. (entries (reverse org-agenda-bulk-marked-entries))
  7790. redo-at-end
  7791. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7792. (cond
  7793. ((equal action ?$)
  7794. (setq cmd '(org-agenda-archive)))
  7795. ((equal action ?A)
  7796. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7797. ((member action '(?r ?w))
  7798. (setq rfloc (org-refile-get-location
  7799. "Refile to"
  7800. (marker-buffer (car org-agenda-bulk-marked-entries))
  7801. org-refile-allow-creating-parent-nodes))
  7802. (if (nth 3 rfloc)
  7803. (setcar (nthcdr 3 rfloc)
  7804. (move-marker (make-marker) (nth 3 rfloc)
  7805. (or (get-file-buffer (nth 1 rfloc))
  7806. (find-buffer-visiting (nth 1 rfloc))
  7807. (error "This should not happen")))))
  7808. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7809. redo-at-end t))
  7810. ((equal action ?t)
  7811. (setq state (org-icompleting-read
  7812. "Todo state: "
  7813. (with-current-buffer (marker-buffer (car entries))
  7814. (mapcar 'list org-todo-keywords-1))))
  7815. (setq cmd `(let ((org-inhibit-blocking t)
  7816. (org-inhibit-logging 'note))
  7817. (org-agenda-todo ,state))))
  7818. ((memq action '(?- ?+))
  7819. (setq tag (org-icompleting-read
  7820. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7821. (with-current-buffer (marker-buffer (car entries))
  7822. (delq nil
  7823. (mapcar (lambda (x)
  7824. (if (stringp (car x)) x)) org-tag-alist)))))
  7825. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7826. ((memq action '(?s ?d))
  7827. (let* ((date (unless arg
  7828. (org-read-date
  7829. nil nil nil
  7830. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7831. (ans (if arg nil org-read-date-final-answer))
  7832. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7833. (setq cmd `(let* ((bound (fboundp 'read-string))
  7834. (old (and bound (symbol-function 'read-string))))
  7835. (unwind-protect
  7836. (progn
  7837. (fset 'read-string (lambda (&rest ignore) ,ans))
  7838. (eval '(,c1 arg)))
  7839. (if bound
  7840. (fset 'read-string old)
  7841. (fmakunbound 'read-string)))))))
  7842. ((equal action ?S)
  7843. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  7844. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  7845. (let ((days (read-number
  7846. (format "Scatter tasks across how many %sdays: "
  7847. (if arg "week" "")) 7)))
  7848. (setq cmd
  7849. `(let ((distance (1+ (random ,days))))
  7850. (if arg
  7851. (let ((dist distance)
  7852. (day-of-week
  7853. (calendar-day-of-week
  7854. (calendar-gregorian-from-absolute (org-today)))))
  7855. (dotimes (i (1+ dist))
  7856. (while (member day-of-week org-agenda-weekend-days)
  7857. (incf distance)
  7858. (incf day-of-week)
  7859. (if (= day-of-week 7)
  7860. (setq day-of-week 0)))
  7861. (incf day-of-week)
  7862. (if (= day-of-week 7)
  7863. (setq day-of-week 0)))))
  7864. ;; silently fail when try to replan a sexp entry
  7865. (condition-case nil
  7866. (let* ((date (calendar-gregorian-from-absolute
  7867. (+ (org-today) distance)))
  7868. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  7869. (nth 2 date))))
  7870. (org-agenda-schedule nil time))
  7871. (error nil)))))))
  7872. ((assoc action org-agenda-bulk-custom-functions)
  7873. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  7874. redo-at-end t))
  7875. ((equal action ?f)
  7876. (setq cmd (list (intern
  7877. (org-icompleting-read "Function: "
  7878. obarray 'fboundp t nil nil)))))
  7879. (t (error "Invalid bulk action")))
  7880. ;; Sort the markers, to make sure that parents are handled before children
  7881. (setq entries (sort entries
  7882. (lambda (a b)
  7883. (cond
  7884. ((equal (marker-buffer a) (marker-buffer b))
  7885. (< (marker-position a) (marker-position b)))
  7886. (t
  7887. (string< (buffer-name (marker-buffer a))
  7888. (buffer-name (marker-buffer b))))))))
  7889. ;; Now loop over all markers and apply cmd
  7890. (while (setq e (pop entries))
  7891. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7892. (if (not pos)
  7893. (progn (message "Skipping removed entry at %s" e)
  7894. (setq cntskip (1+ cntskip)))
  7895. (goto-char pos)
  7896. (let (org-loop-over-headlines-in-active-region)
  7897. (eval cmd))
  7898. (setq org-agenda-bulk-marked-entries
  7899. (delete e org-agenda-bulk-marked-entries))
  7900. (setq cnt (1+ cnt))))
  7901. (setq org-agenda-bulk-marked-entries nil)
  7902. (org-agenda-bulk-remove-all-marks)
  7903. (when redo-at-end (org-agenda-redo))
  7904. (message "Acted on %d entries%s"
  7905. cnt
  7906. (if (= cntskip 0)
  7907. ""
  7908. (format ", skipped %d (disappeared before their turn)"
  7909. cntskip)))))
  7910. ;;; Flagging notes
  7911. (defun org-agenda-show-the-flagging-note ()
  7912. "Display the flagging note in the other window.
  7913. When called a second time in direct sequence, offer to remove the FLAGGING
  7914. tag and (if present) the flagging note."
  7915. (interactive)
  7916. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7917. (win (selected-window))
  7918. note heading newhead)
  7919. (unless hdmarker
  7920. (error "No linked entry at point"))
  7921. (if (and (eq this-command last-command)
  7922. (y-or-n-p "Unflag and remove any flagging note? "))
  7923. (progn
  7924. (org-agenda-remove-flag hdmarker)
  7925. (let ((win (get-buffer-window "*Flagging Note*")))
  7926. (and win (delete-window win)))
  7927. (message "Entry unflagged"))
  7928. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7929. (unless note
  7930. (error "No flagging note"))
  7931. (org-kill-new note)
  7932. (org-switch-to-buffer-other-window "*Flagging Note*")
  7933. (erase-buffer)
  7934. (insert note)
  7935. (goto-char (point-min))
  7936. (while (re-search-forward "\\\\n" nil t)
  7937. (replace-match "\n" t t))
  7938. (goto-char (point-min))
  7939. (select-window win)
  7940. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7941. (defun org-agenda-remove-flag (marker)
  7942. "Remove the FLAGGED tag and any flagging note in the entry."
  7943. (let (newhead)
  7944. (org-with-point-at marker
  7945. (org-toggle-tag "FLAGGED" 'off)
  7946. (org-entry-delete nil "THEFLAGGINGNOTE")
  7947. (setq newhead (org-get-heading)))
  7948. (org-agenda-change-all-lines newhead marker)
  7949. (message "Entry unflagged")))
  7950. (defun org-agenda-get-any-marker (&optional pos)
  7951. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7952. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7953. ;;; Appointment reminders
  7954. (defvar appt-time-msg-list)
  7955. ;;;###autoload
  7956. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  7957. "Activate appointments found in `org-agenda-files'.
  7958. With a \\[universal-argument] prefix, refresh the list of
  7959. appointments.
  7960. If FILTER is t, interactively prompt the user for a regular
  7961. expression, and filter out entries that don't match it.
  7962. If FILTER is a string, use this string as a regular expression
  7963. for filtering entries out.
  7964. If FILTER is a function, filter out entries against which
  7965. calling the function returns nil. This function takes one
  7966. argument: an entry from `org-agenda-get-day-entries'.
  7967. FILTER can also be an alist with the car of each cell being
  7968. either 'headline or 'category. For example:
  7969. '((headline \"IMPORTANT\")
  7970. (category \"Work\"))
  7971. will only add headlines containing IMPORTANT or headlines
  7972. belonging to the \"Work\" category.
  7973. ARGS are symbols indicating what kind of entries to consider.
  7974. By default `org-agenda-to-appt' will use :deadline, :scheduled
  7975. and :timestamp entries. See the docstring of `org-diary' for
  7976. details and examples."
  7977. (interactive "P")
  7978. (if refresh (setq appt-time-msg-list nil))
  7979. (if (eq filter t)
  7980. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7981. (let* ((cnt 0) ; count added events
  7982. (scope (or args '(:deadline :scheduled :timestamp)))
  7983. (org-agenda-new-buffers nil)
  7984. (org-deadline-warning-days 0)
  7985. ;; Do not use `org-today' here because appt only takes
  7986. ;; time and without date as argument, so it may pass wrong
  7987. ;; information otherwise
  7988. (today (org-date-to-gregorian
  7989. (time-to-days (current-time))))
  7990. (org-agenda-restrict nil)
  7991. (files (org-agenda-files 'unrestricted)) entries file)
  7992. ;; Get all entries which may contain an appt
  7993. (org-prepare-agenda-buffers files)
  7994. (while (setq file (pop files))
  7995. (setq entries
  7996. (delq nil
  7997. (append entries
  7998. (apply 'org-agenda-get-day-entries
  7999. file today scope)))))
  8000. ;; Map thru entries and find if we should filter them out
  8001. (mapc
  8002. (lambda(x)
  8003. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8004. (cat (get-text-property 1 'org-category x))
  8005. (tod (get-text-property 1 'time-of-day x))
  8006. (ok (or (null filter)
  8007. (and (stringp filter) (string-match filter evt))
  8008. (and (functionp filter) (funcall filter x))
  8009. (and (listp filter)
  8010. (let ((cat-filter (cadr (assoc 'category filter)))
  8011. (evt-filter (cadr (assoc 'headline filter))))
  8012. (or (and (stringp cat-filter)
  8013. (string-match cat-filter cat))
  8014. (and (stringp evt-filter)
  8015. (string-match evt-filter evt))))))))
  8016. ;; FIXME: Shall we remove text-properties for the appt text?
  8017. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8018. (when (and ok tod)
  8019. (setq tod (concat "00" (number-to-string tod))
  8020. tod (when (string-match
  8021. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8022. (concat (match-string 1 tod) ":"
  8023. (match-string 2 tod))))
  8024. (appt-add tod evt)
  8025. (setq cnt (1+ cnt))))) entries)
  8026. (org-release-buffers org-agenda-new-buffers)
  8027. (if (eq cnt 0)
  8028. (message "No event to add")
  8029. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8030. (defun org-agenda-todayp (date)
  8031. "Does DATE mean today, when considering `org-extend-today-until'?"
  8032. (let ((today (org-today))
  8033. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8034. date)))
  8035. (eq date today)))
  8036. (defun org-agenda-todo-yesterday (&optional arg)
  8037. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
  8038. (interactive "P")
  8039. (let* ((hour (third (decode-time
  8040. (org-current-time))))
  8041. (org-extend-today-until (1+ hour)))
  8042. (org-agenda-todo arg)))
  8043. (provide 'org-agenda)
  8044. ;;; org-agenda.el ends here