org-agenda.el 393 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2017 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.
  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 'cl-lib)
  42. (require 'org)
  43. (require 'org-macs)
  44. (declare-function diary-add-to-list "diary-lib"
  45. (date string specifier &optional marker globcolor literal))
  46. (declare-function calendar-iso-to-absolute "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-columns-remove-overlays "org-colview" ())
  63. (declare-function org-datetree-find-date-create "org-datetree"
  64. (date &optional keep-restriction))
  65. (declare-function org-columns-quit "org-colview" ())
  66. (declare-function diary-date-display-form "diary-lib" (&optional type))
  67. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  68. (declare-function org-habit-insert-consistency-graphs
  69. "org-habit" (&optional line))
  70. (declare-function org-is-habit-p "org-habit" (&optional pom))
  71. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  72. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  73. (declare-function org-agenda-columns "org-colview" ())
  74. (declare-function org-add-archive-files "org-archive" (files))
  75. (declare-function org-capture "org-capture" (&optional goto keys))
  76. (defvar calendar-mode-map)
  77. (defvar org-clock-current-task)
  78. (defvar org-current-tag-alist)
  79. (defvar org-mobile-force-id-on-agenda-items)
  80. (defvar org-habit-show-habits)
  81. (defvar org-habit-show-habits-only-for-today)
  82. (defvar org-habit-show-all-today)
  83. ;; Defined somewhere in this file, but used before definition.
  84. (defvar org-agenda-buffer-name "*Org Agenda*")
  85. (defvar org-agenda-overriding-header nil)
  86. (defvar org-agenda-title-append nil)
  87. (with-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  88. (with-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  89. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  90. (defvar org-agenda-undo-list nil
  91. "List of undoable operations in the agenda since last refresh.")
  92. (defvar org-agenda-pending-undo-list nil
  93. "In a series of undo commands, this is the list of remaining undo items.")
  94. (defcustom org-agenda-confirm-kill 1
  95. "When set, remote killing from the agenda buffer needs confirmation.
  96. When t, a confirmation is always needed. When a number N, confirmation is
  97. only needed when the text to be killed contains more than N non-white lines."
  98. :group 'org-agenda
  99. :type '(choice
  100. (const :tag "Never" nil)
  101. (const :tag "Always" t)
  102. (integer :tag "When more than N lines")))
  103. (defcustom org-agenda-compact-blocks nil
  104. "Non-nil means make the block agenda more compact.
  105. This is done globally by leaving out lines like the agenda span
  106. name and week number or the separator lines."
  107. :group 'org-agenda
  108. :type 'boolean)
  109. (defcustom org-agenda-block-separator ?=
  110. "The separator between blocks in the agenda.
  111. If this is a string, it will be used as the separator, with a newline added.
  112. If it is a character, it will be repeated to fill the window width.
  113. If nil the separator is disabled. In `org-agenda-custom-commands' this
  114. addresses the separator between the current and the previous block."
  115. :group 'org-agenda
  116. :type '(choice
  117. (const :tag "Disabled" nil)
  118. (character)
  119. (string)))
  120. (defgroup org-agenda-export nil
  121. "Options concerning exporting agenda views in Org mode."
  122. :tag "Org Agenda Export"
  123. :group 'org-agenda)
  124. (defcustom org-agenda-with-colors t
  125. "Non-nil means use colors in agenda views."
  126. :group 'org-agenda-export
  127. :type 'boolean)
  128. (defcustom org-agenda-exporter-settings nil
  129. "Alist of variable/value pairs that should be active during agenda export.
  130. This is a good place to set options for ps-print and for htmlize.
  131. Note that the way this is implemented, the values will be evaluated
  132. before assigned to the variables. So make sure to quote values you do
  133. *not* want evaluated, for example
  134. (setq org-agenda-exporter-settings
  135. \\='((ps-print-color-p \\='black-white)))"
  136. :group 'org-agenda-export
  137. :type '(repeat
  138. (list
  139. (variable)
  140. (sexp :tag "Value"))))
  141. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  142. "Hook run in a temporary buffer before writing the agenda to an export file.
  143. A useful function for this hook is `org-agenda-add-entry-text'."
  144. :group 'org-agenda-export
  145. :type 'hook
  146. :options '(org-agenda-add-entry-text))
  147. (defcustom org-agenda-add-entry-text-maxlines 0
  148. "Maximum number of entry text lines to be added to agenda.
  149. This is only relevant when `org-agenda-add-entry-text' is part of
  150. `org-agenda-before-write-hook', which is the default.
  151. When this is 0, nothing will happen. When it is greater than 0, it
  152. specifies the maximum number of lines that will be added for each entry
  153. that is listed in the agenda view.
  154. Note that this variable is not used during display, only when exporting
  155. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  156. and `org-agenda-entry-text-maxlines'."
  157. :group 'org-agenda
  158. :type 'integer)
  159. (defcustom org-agenda-add-entry-text-descriptive-links t
  160. "Non-nil means export org-links as descriptive links in agenda added text.
  161. This variable applies to the text added to the agenda when
  162. `org-agenda-add-entry-text-maxlines' is larger than 0.
  163. When this variable nil, the URL will (also) be shown."
  164. :group 'org-agenda
  165. :type 'boolean)
  166. (defcustom org-agenda-export-html-style nil
  167. "The style specification for exported HTML Agenda files.
  168. If this variable contains a string, it will replace the default <style>
  169. section as produced by `htmlize'.
  170. Since there are different ways of setting style information, this variable
  171. needs to contain the full HTML structure to provide a style, including the
  172. surrounding HTML tags. The style specifications should include definitions
  173. the fonts used by the agenda, here is an example:
  174. <style type=\"text/css\">
  175. p { font-weight: normal; color: gray; }
  176. .org-agenda-structure {
  177. font-size: 110%;
  178. color: #003399;
  179. font-weight: 600;
  180. }
  181. .org-todo {
  182. color: #cc6666;
  183. font-weight: bold;
  184. }
  185. .org-agenda-done {
  186. color: #339933;
  187. }
  188. .org-done {
  189. color: #339933;
  190. }
  191. .title { text-align: center; }
  192. .todo, .deadline { color: red; }
  193. .done { color: green; }
  194. </style>
  195. or, if you want to keep the style in a file,
  196. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  197. As the value of this option simply gets inserted into the HTML <head> header,
  198. you can \"misuse\" it to also add other text to the header."
  199. :group 'org-agenda-export
  200. :group 'org-export-html
  201. :type '(choice
  202. (const nil)
  203. (string)))
  204. (defcustom org-agenda-persistent-filter nil
  205. "When set, keep filters from one agenda view to the next."
  206. :group 'org-agenda
  207. :type 'boolean)
  208. (defgroup org-agenda-custom-commands nil
  209. "Options concerning agenda views in Org mode."
  210. :tag "Org Agenda Custom Commands"
  211. :group 'org-agenda)
  212. (defconst org-sorting-choice
  213. '(choice
  214. (const time-up) (const time-down)
  215. (const timestamp-up) (const timestamp-down)
  216. (const scheduled-up) (const scheduled-down)
  217. (const deadline-up) (const deadline-down)
  218. (const ts-up) (const ts-down)
  219. (const tsia-up) (const tsia-down)
  220. (const category-keep) (const category-up) (const category-down)
  221. (const tag-down) (const tag-up)
  222. (const priority-up) (const priority-down)
  223. (const todo-state-up) (const todo-state-down)
  224. (const effort-up) (const effort-down)
  225. (const habit-up) (const habit-down)
  226. (const alpha-up) (const alpha-down)
  227. (const user-defined-up) (const user-defined-down))
  228. "Sorting choices.")
  229. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  230. ;; the new variable `org-agenda-tag-filter-preset'.
  231. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  232. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  233. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  234. "List of types searched for when creating the daily/weekly agenda.
  235. This variable is a list of symbols that controls the types of
  236. items that appear in the daily/weekly agenda. Allowed symbols in this
  237. list are are
  238. :timestamp List items containing a date stamp or date range matching
  239. the selected date. This includes sexp entries in angular
  240. brackets.
  241. :sexp List entries resulting from plain diary-like sexps.
  242. :deadline List deadline due on that date. When the date is today,
  243. also list any deadlines past due, or due within
  244. `org-deadline-warning-days'.
  245. :deadline* Same as above, but only include the deadline if it has an
  246. hour specification as [h]h:mm.
  247. :scheduled List all items which are scheduled for the given date.
  248. The diary for *today* also contains items which were
  249. scheduled earlier and are not yet marked DONE.
  250. :scheduled* Same as above, but only include the scheduled item if it
  251. has an hour specification as [h]h:mm.
  252. By default, all four non-starred types are turned on.
  253. When :scheduled* or :deadline* are included, :schedule or :deadline
  254. will be ignored.
  255. Never set this variable globally using `setq', because then it
  256. will apply to all future agenda commands. Instead, bind it with
  257. `let' to scope it dynamically into the agenda-constructing
  258. command. A good way to set it is through options in
  259. `org-agenda-custom-commands'. For a more flexible (though
  260. somewhat less efficient) way of determining what is included in
  261. the daily/weekly agenda, see `org-agenda-skip-function'.")
  262. (defconst org-agenda-custom-commands-local-options
  263. `(repeat :tag "Local settings for this command. Remember to quote values"
  264. (choice :tag "Setting"
  265. (list :tag "Heading for this block"
  266. (const org-agenda-overriding-header)
  267. (string :tag "Headline"))
  268. (list :tag "Files to be searched"
  269. (const org-agenda-files)
  270. (list
  271. (const :format "" quote)
  272. (repeat (file))))
  273. (list :tag "Sorting strategy"
  274. (const org-agenda-sorting-strategy)
  275. (list
  276. (const :format "" quote)
  277. (repeat
  278. ,org-sorting-choice)))
  279. (list :tag "Prefix format"
  280. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  281. (string))
  282. (list :tag "Number of days in agenda"
  283. (const org-agenda-span)
  284. (choice (const :tag "Day" day)
  285. (const :tag "Week" week)
  286. (const :tag "Fortnight" fortnight)
  287. (const :tag "Month" month)
  288. (const :tag "Year" year)
  289. (integer :tag "Custom")))
  290. (list :tag "Fixed starting date"
  291. (const org-agenda-start-day)
  292. (string :value "2007-11-01"))
  293. (list :tag "Start on day of week"
  294. (const org-agenda-start-on-weekday)
  295. (choice :value 1
  296. (const :tag "Today" nil)
  297. (integer :tag "Weekday No.")))
  298. (list :tag "Include data from diary"
  299. (const org-agenda-include-diary)
  300. (boolean))
  301. (list :tag "Deadline Warning days"
  302. (const org-deadline-warning-days)
  303. (integer :value 1))
  304. (list :tag "Category filter preset"
  305. (const org-agenda-category-filter-preset)
  306. (list
  307. (const :format "" quote)
  308. (repeat
  309. (string :tag "+category or -category"))))
  310. (list :tag "Tags filter preset"
  311. (const org-agenda-tag-filter-preset)
  312. (list
  313. (const :format "" quote)
  314. (repeat
  315. (string :tag "+tag or -tag"))))
  316. (list :tag "Effort filter preset"
  317. (const org-agenda-effort-filter-preset)
  318. (list
  319. (const :format "" quote)
  320. (repeat
  321. (string :tag "+=10 or -=10 or +<10 or ->10"))))
  322. (list :tag "Regexp filter preset"
  323. (const org-agenda-regexp-filter-preset)
  324. (list
  325. (const :format "" quote)
  326. (repeat
  327. (string :tag "+regexp or -regexp"))))
  328. (list :tag "Set daily/weekly entry types"
  329. (const org-agenda-entry-types)
  330. (list
  331. (const :format "" quote)
  332. (set :greedy t :value ,org-agenda-entry-types
  333. (const :deadline)
  334. (const :scheduled)
  335. (const :deadline*)
  336. (const :scheduled*)
  337. (const :timestamp)
  338. (const :sexp))))
  339. (list :tag "Standard skipping condition"
  340. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  341. (const org-agenda-skip-function)
  342. (list
  343. (const :format "" quote)
  344. (list
  345. (choice
  346. :tag "Skipping range"
  347. (const :tag "Skip entry" org-agenda-skip-entry-if)
  348. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  349. (repeat :inline t :tag "Conditions for skipping"
  350. (choice
  351. :tag "Condition type"
  352. (list :tag "Regexp matches" :inline t
  353. (const :format "" 'regexp)
  354. (regexp))
  355. (list :tag "Regexp does not match" :inline t
  356. (const :format "" 'notregexp)
  357. (regexp))
  358. (list :tag "TODO state is" :inline t
  359. (const 'todo)
  360. (choice
  361. (const :tag "Any not-done state" 'todo)
  362. (const :tag "Any done state" 'done)
  363. (const :tag "Any state" 'any)
  364. (list :tag "Keyword list"
  365. (const :format "" quote)
  366. (repeat (string :tag "Keyword")))))
  367. (list :tag "TODO state is not" :inline t
  368. (const 'nottodo)
  369. (choice
  370. (const :tag "Any not-done state" 'todo)
  371. (const :tag "Any done state" 'done)
  372. (const :tag "Any state" 'any)
  373. (list :tag "Keyword list"
  374. (const :format "" quote)
  375. (repeat (string :tag "Keyword")))))
  376. (const :tag "scheduled" 'scheduled)
  377. (const :tag "not scheduled" 'notscheduled)
  378. (const :tag "deadline" 'deadline)
  379. (const :tag "no deadline" 'notdeadline)
  380. (const :tag "timestamp" 'timestamp)
  381. (const :tag "no timestamp" 'nottimestamp))))))
  382. (list :tag "Non-standard skipping condition"
  383. :value (org-agenda-skip-function)
  384. (const org-agenda-skip-function)
  385. (sexp :tag "Function or form (quoted!)"))
  386. (list :tag "Any variable"
  387. (variable :tag "Variable")
  388. (sexp :tag "Value (sexp)"))))
  389. "Selection of examples for agenda command settings.
  390. This will be spliced into the custom type of
  391. `org-agenda-custom-commands'.")
  392. (defcustom org-agenda-custom-commands
  393. '(("n" "Agenda and all TODOs" ((agenda "") (alltodo ""))))
  394. "Custom commands for the agenda.
  395. \\<org-mode-map>
  396. These commands will be offered on the splash screen displayed by the
  397. agenda dispatcher `\\[org-agenda]'. Each entry is a list like this:
  398. (key desc type match settings files)
  399. key The key (one or more characters as a string) to be associated
  400. with the command.
  401. desc A description of the command, when omitted or nil, a default
  402. description is built using MATCH.
  403. type The command type, any of the following symbols:
  404. agenda The daily/weekly agenda.
  405. todo Entries with a specific TODO keyword, in all agenda files.
  406. search Entries containing search words entry or headline.
  407. tags Tags/Property/TODO match in all agenda files.
  408. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  409. todo-tree Sparse tree of specific TODO keyword in *current* file.
  410. tags-tree Sparse tree with all tags matches in *current* file.
  411. occur-tree Occur sparse tree for *current* file.
  412. ... A user-defined function.
  413. match What to search for:
  414. - a single keyword for TODO keyword searches
  415. - a tags match expression for tags searches
  416. - a word search expression for text searches.
  417. - a regular expression for occur searches
  418. For all other commands, this should be the empty string.
  419. settings A list of option settings, similar to that in a let form, so like
  420. this: ((opt1 val1) (opt2 val2) ...). The values will be
  421. evaluated at the moment of execution, so quote them when needed.
  422. files A list of files to write the produced agenda buffer to with
  423. the command `org-store-agenda-views'.
  424. If a file name ends in \".html\", an HTML version of the buffer
  425. is written out. If it ends in \".ps\", a postscript version is
  426. produced. Otherwise, only the plain text is written to the file.
  427. You can also define a set of commands, to create a composite agenda buffer.
  428. In this case, an entry looks like this:
  429. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  430. where
  431. desc A description string to be displayed in the dispatcher menu.
  432. cmd An agenda command, similar to the above. However, tree commands
  433. are not allowed, but instead you can get agenda and global todo list.
  434. So valid commands for a set are:
  435. (agenda \"\" settings)
  436. (alltodo \"\" settings)
  437. (stuck \"\" settings)
  438. (todo \"match\" settings files)
  439. (search \"match\" settings files)
  440. (tags \"match\" settings files)
  441. (tags-todo \"match\" settings files)
  442. Each command can carry a list of options, and another set of options can be
  443. given for the whole set of commands. Individual command options take
  444. precedence over the general options.
  445. When using several characters as key to a command, the first characters
  446. are prefix commands. For the dispatcher to display useful information, you
  447. should provide a description for the prefix, like
  448. (setq org-agenda-custom-commands
  449. \\='((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  450. (\"hl\" tags \"+HOME+Lisa\")
  451. (\"hp\" tags \"+HOME+Peter\")
  452. (\"hk\" tags \"+HOME+Kim\")))"
  453. :group 'org-agenda-custom-commands
  454. :type `(repeat
  455. (choice :value ("x" "Describe command here" tags "" nil)
  456. (list :tag "Single command"
  457. (string :tag "Access Key(s) ")
  458. (option (string :tag "Description"))
  459. (choice
  460. (const :tag "Agenda" agenda)
  461. (const :tag "TODO list" alltodo)
  462. (const :tag "Search words" search)
  463. (const :tag "Stuck projects" stuck)
  464. (const :tag "Tags/Property match (all agenda files)" tags)
  465. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  466. (const :tag "TODO keyword search (all agenda files)" todo)
  467. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  468. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  469. (const :tag "Occur tree (current buffer)" occur-tree)
  470. (sexp :tag "Other, user-defined function"))
  471. (string :tag "Match (only for some commands)")
  472. ,org-agenda-custom-commands-local-options
  473. (option (repeat :tag "Export" (file :tag "Export to"))))
  474. (list :tag "Command series, all agenda files"
  475. (string :tag "Access Key(s)")
  476. (string :tag "Description ")
  477. (repeat :tag "Component"
  478. (choice
  479. (list :tag "Agenda"
  480. (const :format "" agenda)
  481. (const :tag "" :format "" "")
  482. ,org-agenda-custom-commands-local-options)
  483. (list :tag "TODO list (all keywords)"
  484. (const :format "" alltodo)
  485. (const :tag "" :format "" "")
  486. ,org-agenda-custom-commands-local-options)
  487. (list :tag "Search words"
  488. (const :format "" search)
  489. (string :tag "Match")
  490. ,org-agenda-custom-commands-local-options)
  491. (list :tag "Stuck projects"
  492. (const :format "" stuck)
  493. (const :tag "" :format "" "")
  494. ,org-agenda-custom-commands-local-options)
  495. (list :tag "Tags search"
  496. (const :format "" tags)
  497. (string :tag "Match")
  498. ,org-agenda-custom-commands-local-options)
  499. (list :tag "Tags search, TODO entries only"
  500. (const :format "" tags-todo)
  501. (string :tag "Match")
  502. ,org-agenda-custom-commands-local-options)
  503. (list :tag "TODO keyword search"
  504. (const :format "" todo)
  505. (string :tag "Match")
  506. ,org-agenda-custom-commands-local-options)
  507. (list :tag "Other, user-defined function"
  508. (symbol :tag "function")
  509. (string :tag "Match")
  510. ,org-agenda-custom-commands-local-options)))
  511. (repeat :tag "Settings for entire command set"
  512. (list (variable :tag "Any variable")
  513. (sexp :tag "Value")))
  514. (option (repeat :tag "Export" (file :tag "Export to"))))
  515. (cons :tag "Prefix key documentation"
  516. (string :tag "Access Key(s)")
  517. (string :tag "Description ")))))
  518. (defcustom org-agenda-query-register ?o
  519. "The register holding the current query string.
  520. The purpose of this is that if you construct a query string interactively,
  521. you can then use it to define a custom command."
  522. :group 'org-agenda-custom-commands
  523. :type 'character)
  524. (defcustom org-stuck-projects
  525. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  526. "How to identify stuck projects.
  527. This is a list of four items:
  528. 1. A tags/todo/property matcher string that is used to identify a project.
  529. See the manual for a description of tag and property searches.
  530. The entire tree below a headline matched by this is considered one project.
  531. 2. A list of TODO keywords identifying non-stuck projects.
  532. If the project subtree contains any headline with one of these todo
  533. keywords, the project is considered to be not stuck. If you specify
  534. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  535. 3. A list of tags identifying non-stuck projects.
  536. If the project subtree contains any headline with one of these tags,
  537. the project is considered to be not stuck. If you specify \"*\" as
  538. a tag, any tag will mark the project unstuck. Note that this is about
  539. the explicit presence of a tag somewhere in the subtree, inherited
  540. tags do not count here. If inherited tags make a project not stuck,
  541. use \"-TAG\" in the tags part of the matcher under (1.) above.
  542. 4. An arbitrary regular expression matching non-stuck projects.
  543. If the project turns out to be not stuck, search continues also in the
  544. subtree to see if any of the subtasks have project status.
  545. See also the variable `org-tags-match-list-sublevels' which applies
  546. to projects matched by this search as well.
  547. After defining this variable, you may use `\\[org-agenda-list-stuck-projects]'
  548. \(bound to `C-c a #') to produce the list."
  549. :group 'org-agenda-custom-commands
  550. :type '(list
  551. (string :tag "Tags/TODO match to identify a project")
  552. (repeat :tag "Projects are *not* stuck if they have an entry with \
  553. TODO keyword any of" (string))
  554. (repeat :tag "Projects are *not* stuck if they have an entry with \
  555. TAG being any of" (string))
  556. (regexp :tag "Projects are *not* stuck if this regexp matches inside \
  557. the subtree")))
  558. (defgroup org-agenda-skip nil
  559. "Options concerning skipping parts of agenda files."
  560. :tag "Org Agenda Skip"
  561. :group 'org-agenda)
  562. (defcustom org-agenda-skip-function-global nil
  563. "Function to be called at each match during agenda construction.
  564. If this function returns nil, the current match should not be skipped.
  565. If the function decided to skip an agenda match, is must return the
  566. buffer position from which the search should be continued.
  567. This may also be a Lisp form, which will be evaluated.
  568. This variable will be applied to every agenda match, including
  569. tags/property searches and TODO lists. So try to make the test function
  570. do its checking as efficiently as possible. To implement a skipping
  571. condition just for specific agenda commands, use the variable
  572. `org-agenda-skip-function' which can be set in the options section
  573. of custom agenda commands."
  574. :group 'org-agenda-skip
  575. :type 'sexp)
  576. (defgroup org-agenda-daily/weekly nil
  577. "Options concerning the daily/weekly agenda."
  578. :tag "Org Agenda Daily/Weekly"
  579. :group 'org-agenda)
  580. (defgroup org-agenda-todo-list nil
  581. "Options concerning the global todo list agenda view."
  582. :tag "Org Agenda Todo List"
  583. :group 'org-agenda)
  584. (defgroup org-agenda-match-view nil
  585. "Options concerning the general tags/property/todo match agenda view."
  586. :tag "Org Agenda Match View"
  587. :group 'org-agenda)
  588. (defgroup org-agenda-search-view nil
  589. "Options concerning the search agenda view."
  590. :tag "Org Agenda Search View"
  591. :group 'org-agenda)
  592. (defvar org-agenda-archives-mode nil
  593. "Non-nil means the agenda will include archived items.
  594. If this is the symbol `trees', trees in the selected agenda scope
  595. that are marked with the ARCHIVE tag will be included anyway. When this is
  596. t, also all archive files associated with the current selection of agenda
  597. files will be included.")
  598. (defcustom org-agenda-restriction-lock-highlight-subtree t
  599. "Non-nil means highlight the whole subtree when restriction is active.
  600. Otherwise only highlight the headline. Highlighting the whole subtree is
  601. useful to ensure no edits happen beyond the restricted region."
  602. :group 'org-agenda
  603. :type 'boolean)
  604. (defcustom org-agenda-skip-comment-trees t
  605. "Non-nil means skip trees that start with the COMMENT keyword.
  606. When nil, these trees are also scanned by agenda commands."
  607. :group 'org-agenda-skip
  608. :type 'boolean)
  609. (defcustom org-agenda-todo-list-sublevels t
  610. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  611. When nil, the sublevels of a TODO entry are not checked, resulting in
  612. potentially much shorter TODO lists."
  613. :group 'org-agenda-skip
  614. :group 'org-agenda-todo-list
  615. :type 'boolean)
  616. (defcustom org-agenda-todo-ignore-with-date nil
  617. "Non-nil means don't show entries with a date in the global todo list.
  618. You can use this if you prefer to mark mere appointments with a TODO keyword,
  619. but don't want them to show up in the TODO list.
  620. When this is set, it also covers deadlines and scheduled items, the settings
  621. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  622. will be ignored.
  623. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  624. :group 'org-agenda-skip
  625. :group 'org-agenda-todo-list
  626. :type 'boolean)
  627. (defcustom org-agenda-todo-ignore-timestamp nil
  628. "Non-nil means don't show entries with a timestamp.
  629. This applies when creating the global todo list.
  630. Valid values are:
  631. past Don't show entries for today or in the past.
  632. future Don't show entries with a timestamp in the future.
  633. The idea behind this is that if it has a future
  634. timestamp, you don't want to think about it until the
  635. date.
  636. all Don't show any entries with a timestamp in the global todo list.
  637. The idea behind this is that by setting a timestamp, you
  638. have already \"taken care\" of this item.
  639. This variable can also have an integer as a value. If positive (N),
  640. todos with a timestamp N or more days in the future will be ignored. If
  641. negative (-N), todos with a timestamp N or more days in the past will be
  642. ignored. If 0, todos with a timestamp either today or in the future will
  643. be ignored. For example, a value of -1 will exclude todos with a
  644. timestamp in the past (yesterday or earlier), while a value of 7 will
  645. exclude todos with a timestamp a week or more in the future.
  646. See also `org-agenda-todo-ignore-with-date'.
  647. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  648. to make his option also apply to the tags-todo list."
  649. :group 'org-agenda-skip
  650. :group 'org-agenda-todo-list
  651. :version "24.1"
  652. :type '(choice
  653. (const :tag "Ignore future timestamp todos" future)
  654. (const :tag "Ignore past or present timestamp todos" past)
  655. (const :tag "Ignore all timestamp todos" all)
  656. (const :tag "Show timestamp todos" nil)
  657. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  658. (defcustom org-agenda-todo-ignore-scheduled nil
  659. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  660. This applies when creating the global todo list.
  661. Valid values are:
  662. past Don't show entries scheduled today or in the past.
  663. future Don't show entries scheduled in the future.
  664. The idea behind this is that by scheduling it, you don't want to
  665. think about it until the scheduled date.
  666. all Don't show any scheduled entries in the global todo list.
  667. The idea behind this is that by scheduling it, you have already
  668. \"taken care\" of this item.
  669. t Same as `all', for backward compatibility.
  670. This variable can also have an integer as a value. See
  671. `org-agenda-todo-ignore-timestamp' for more details.
  672. See also `org-agenda-todo-ignore-with-date'.
  673. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  674. to make his option also apply to the tags-todo list."
  675. :group 'org-agenda-skip
  676. :group 'org-agenda-todo-list
  677. :type '(choice
  678. (const :tag "Ignore future-scheduled todos" future)
  679. (const :tag "Ignore past- or present-scheduled todos" past)
  680. (const :tag "Ignore all scheduled todos" all)
  681. (const :tag "Ignore all scheduled todos (compatibility)" t)
  682. (const :tag "Show scheduled todos" nil)
  683. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  684. (defcustom org-agenda-todo-ignore-deadlines nil
  685. "Non-nil means ignore some deadline TODO items when making TODO list.
  686. There are different motivations for using different values, please think
  687. carefully when configuring this variable.
  688. This applies when creating the global TODO list.
  689. Valid values are:
  690. near Don't show near deadline entries. A deadline is near when it is
  691. closer than `org-deadline-warning-days' days. The idea behind this
  692. is that such items will appear in the agenda anyway.
  693. far Don't show TODO entries where a deadline has been defined, but
  694. is not going to happen anytime soon. This is useful if you want to use
  695. the TODO list to figure out what to do now.
  696. past Don't show entries with a deadline timestamp for today or in the past.
  697. future Don't show entries with a deadline timestamp in the future, not even
  698. when they become `near' ones. Use it with caution.
  699. all Ignore all TODO entries that do have a deadline.
  700. t Same as `near', for backward compatibility.
  701. This variable can also have an integer as a value. See
  702. `org-agenda-todo-ignore-timestamp' for more details.
  703. See also `org-agenda-todo-ignore-with-date'.
  704. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  705. to make his option also apply to the tags-todo list."
  706. :group 'org-agenda-skip
  707. :group 'org-agenda-todo-list
  708. :type '(choice
  709. (const :tag "Ignore near deadlines" near)
  710. (const :tag "Ignore near deadlines (compatibility)" t)
  711. (const :tag "Ignore far deadlines" far)
  712. (const :tag "Ignore all TODOs with a deadlines" all)
  713. (const :tag "Show all TODOs, even if they have a deadline" nil)
  714. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  715. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  716. "Time unit to use when possibly ignoring an agenda item.
  717. See the docstring of various `org-agenda-todo-ignore-*' options.
  718. The default is to compare time stamps using days. An item is thus
  719. considered to be in the future if it is at least one day after today.
  720. Non-nil means to compare time stamps using seconds. An item is then
  721. considered future if it has a time value later than current time."
  722. :group 'org-agenda-skip
  723. :group 'org-agenda-todo-list
  724. :version "24.4"
  725. :package-version '(Org . "8.0")
  726. :type '(choice
  727. (const :tag "Compare time with days" nil)
  728. (const :tag "Compare time with seconds" t)))
  729. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  730. "Non-nil means honor todo-list ignores options also in tags-todo search.
  731. The variables
  732. `org-agenda-todo-ignore-with-date',
  733. `org-agenda-todo-ignore-timestamp',
  734. `org-agenda-todo-ignore-scheduled',
  735. `org-agenda-todo-ignore-deadlines'
  736. make the global TODO list skip entries that have time stamps of certain
  737. kinds. If this option is set, the same options will also apply for the
  738. tags-todo search, which is the general tags/property matcher
  739. restricted to unfinished TODO entries only."
  740. :group 'org-agenda-skip
  741. :group 'org-agenda-todo-list
  742. :group 'org-agenda-match-view
  743. :type 'boolean)
  744. (defcustom org-agenda-skip-scheduled-if-done nil
  745. "Non-nil means don't show scheduled items in agenda when they are done.
  746. This is relevant for the daily/weekly agenda, not for the TODO list. It
  747. applies only to the actual date of the scheduling. Warnings about an item
  748. with a past scheduling dates are always turned off when the item is DONE."
  749. :group 'org-agenda-skip
  750. :group 'org-agenda-daily/weekly
  751. :type 'boolean)
  752. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  753. "Non-nil means skip scheduling line if same entry shows because of deadline.
  754. In the agenda of today, an entry can show up multiple times
  755. because it is both scheduled and has a nearby deadline, and maybe
  756. a plain time stamp as well.
  757. When this variable is nil, the entry will be shown several times.
  758. When set to t, then only the deadline is shown and the fact that
  759. the entry is scheduled today or was scheduled previously is not
  760. shown.
  761. When set to the symbol `not-today', skip scheduled previously,
  762. but not scheduled today.
  763. When set to the symbol `repeated-after-deadline', skip scheduled
  764. items if they are repeated beyond the current deadline."
  765. :group 'org-agenda-skip
  766. :group 'org-agenda-daily/weekly
  767. :type '(choice
  768. (const :tag "Never" nil)
  769. (const :tag "Always" t)
  770. (const :tag "Not when scheduled today" not-today)
  771. (const :tag "When repeated past deadline" repeated-after-deadline)))
  772. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  773. "Non-nil means skip timestamp line if same entry shows because of deadline.
  774. In the agenda of today, an entry can show up multiple times
  775. because it has both a plain timestamp and has a nearby deadline.
  776. When this variable is t, then only the deadline is shown and the
  777. fact that the entry has a timestamp for or including today is not
  778. shown. When this variable is nil, the entry will be shown
  779. several times."
  780. :group 'org-agenda-skip
  781. :group 'org-agenda-daily/weekly
  782. :version "24.1"
  783. :type '(choice
  784. (const :tag "Never" nil)
  785. (const :tag "Always" t)))
  786. (defcustom org-agenda-skip-deadline-if-done nil
  787. "Non-nil means don't show deadlines when the corresponding item is done.
  788. When nil, the deadline is still shown and should give you a happy feeling.
  789. This is relevant for the daily/weekly agenda. It applies only to the
  790. actual date of the deadline. Warnings about approaching and past-due
  791. deadlines are always turned off when the item is DONE."
  792. :group 'org-agenda-skip
  793. :group 'org-agenda-daily/weekly
  794. :type 'boolean)
  795. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  796. "Non-nil means skip deadline prewarning when entry is also scheduled.
  797. This will apply on all days where a prewarning for the deadline would
  798. be shown, but not at the day when the entry is actually due. On that day,
  799. the deadline will be shown anyway.
  800. This variable may be set to nil, t, the symbol `pre-scheduled',
  801. or a number which will then give the number of days before the actual
  802. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  803. eliminates the deadline prewarning only prior to the scheduled date.
  804. This can be used in a workflow where the first showing of the deadline will
  805. trigger you to schedule it, and then you don't want to be reminded of it
  806. because you will take care of it on the day when scheduled."
  807. :group 'org-agenda-skip
  808. :group 'org-agenda-daily/weekly
  809. :version "24.1"
  810. :type '(choice
  811. (const :tag "Always show prewarning" nil)
  812. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  813. (const :tag "Remove prewarning if entry is scheduled" t)
  814. (integer :tag "Restart prewarning N days before deadline")))
  815. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  816. "Non-nil means skip scheduled delay when entry also has a deadline.
  817. This variable may be set to nil, t, the symbol `post-deadline',
  818. or a number which will then give the number of days after the actual
  819. scheduled date when the delay should expire. The symbol `post-deadline'
  820. eliminates the schedule delay when the date is posterior to the deadline."
  821. :group 'org-agenda-skip
  822. :group 'org-agenda-daily/weekly
  823. :version "24.4"
  824. :package-version '(Org . "8.0")
  825. :type '(choice
  826. (const :tag "Always honor delay" nil)
  827. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  828. (const :tag "Ignore delay if entry has a deadline" t)
  829. (integer :tag "Honor delay up until N days after the scheduled date")))
  830. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  831. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  832. When non-nil, after the search for timestamps has matched once in an
  833. entry, the rest of the entry will not be searched."
  834. :group 'org-agenda-skip
  835. :type 'boolean)
  836. (defcustom org-agenda-skip-timestamp-if-done nil
  837. "Non-nil means don't select item by timestamp or -range if it is DONE."
  838. :group 'org-agenda-skip
  839. :group 'org-agenda-daily/weekly
  840. :type 'boolean)
  841. (defcustom org-agenda-dim-blocked-tasks t
  842. "Non-nil means dim blocked tasks in the agenda display.
  843. This causes some overhead during agenda construction, but if you
  844. have turned on `org-enforce-todo-dependencies',
  845. `org-enforce-todo-checkbox-dependencies', or any other blocking
  846. mechanism, this will create useful feedback in the agenda.
  847. Instead of t, this variable can also have the value `invisible'.
  848. Then blocked tasks will be invisible and only become visible when
  849. they become unblocked. An exemption to this behavior is when a task is
  850. blocked because of unchecked checkboxes below it. Since checkboxes do
  851. not show up in the agenda views, making this task invisible you remove any
  852. trace from agenda views that there is something to do. Therefore, a task
  853. that is blocked because of checkboxes will never be made invisible, it
  854. will only be dimmed."
  855. :group 'org-agenda-daily/weekly
  856. :group 'org-agenda-todo-list
  857. :version "24.3"
  858. :type '(choice
  859. (const :tag "Do not dim" nil)
  860. (const :tag "Dim to a gray face" t)
  861. (const :tag "Make invisible" invisible)))
  862. (defgroup org-agenda-startup nil
  863. "Options concerning initial settings in the Agenda in Org Mode."
  864. :tag "Org Agenda Startup"
  865. :group 'org-agenda)
  866. (defcustom org-agenda-menu-show-matcher t
  867. "Non-nil means show the match string in the agenda dispatcher menu.
  868. When nil, the matcher string is not shown, but is put into the help-echo
  869. property so than moving the mouse over the command shows it.
  870. Setting it to nil is good if matcher strings are very long and/or if
  871. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  872. :group 'org-agenda
  873. :version "24.1"
  874. :type 'boolean)
  875. (defcustom org-agenda-menu-two-columns nil
  876. "Non-nil means, use two columns to show custom commands in the dispatcher.
  877. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  878. to nil."
  879. :group 'org-agenda
  880. :version "24.1"
  881. :type 'boolean)
  882. (defcustom org-agenda-finalize-hook nil
  883. "Hook run just before displaying an agenda buffer.
  884. The buffer is still writable when the hook is called.
  885. You can modify some of the buffer substrings but you should be
  886. extra careful not to modify the text properties of the agenda
  887. headlines as the agenda display heavily relies on them."
  888. :group 'org-agenda-startup
  889. :type 'hook)
  890. (defcustom org-agenda-mouse-1-follows-link nil
  891. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  892. A longer mouse click will still set point. Needs to be set
  893. before org.el is loaded."
  894. :group 'org-agenda-startup
  895. :type 'boolean)
  896. (defcustom org-agenda-start-with-follow-mode nil
  897. "The initial value of follow mode in a newly created agenda window."
  898. :group 'org-agenda-startup
  899. :type 'boolean)
  900. (defcustom org-agenda-follow-indirect nil
  901. "Non-nil means `org-agenda-follow-mode' displays only the
  902. current item's tree, in an indirect buffer."
  903. :group 'org-agenda
  904. :version "24.1"
  905. :type 'boolean)
  906. (defcustom org-agenda-show-outline-path t
  907. "Non-nil means show outline path in echo area after line motion."
  908. :group 'org-agenda-startup
  909. :type 'boolean)
  910. (defcustom org-agenda-start-with-entry-text-mode nil
  911. "The initial value of entry-text-mode in a newly created agenda window."
  912. :group 'org-agenda-startup
  913. :type 'boolean)
  914. (defcustom org-agenda-entry-text-maxlines 5
  915. "Number of text lines to be added when `E' is pressed in the agenda.
  916. Note that this variable only used during agenda display. To add entry text
  917. when exporting the agenda, configure the variable
  918. `org-agenda-add-entry-text-maxlines'."
  919. :group 'org-agenda
  920. :type 'integer)
  921. (defcustom org-agenda-entry-text-exclude-regexps nil
  922. "List of regular expressions to clean up entry text.
  923. The complete matches of all regular expressions in this list will be
  924. removed from entry text before it is shown in the agenda."
  925. :group 'org-agenda
  926. :type '(repeat (regexp)))
  927. (defcustom org-agenda-entry-text-leaders " > "
  928. "Text prepended to the entry text in agenda buffers."
  929. :version "24.4"
  930. :package-version '(Org . "8.0")
  931. :group 'org-agenda
  932. :type 'string)
  933. (defvar org-agenda-entry-text-cleanup-hook nil
  934. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  935. This cleanup is done in a temporary buffer, so the function may inspect and
  936. change the entire buffer.
  937. Some default stuff like drawers and scheduling/deadline dates will already
  938. have been removed when this is called, as will any matches for regular
  939. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  940. (defvar org-agenda-include-inactive-timestamps nil
  941. "Non-nil means include inactive time stamps in agenda.
  942. Dynamically scoped.")
  943. (defgroup org-agenda-windows nil
  944. "Options concerning the windows used by the Agenda in Org Mode."
  945. :tag "Org Agenda Windows"
  946. :group 'org-agenda)
  947. (defcustom org-agenda-window-setup 'reorganize-frame
  948. "How the agenda buffer should be displayed.
  949. Possible values for this option are:
  950. current-window Show agenda in the current window, keeping all other windows.
  951. other-window Use `switch-to-buffer-other-window' to display agenda.
  952. only-window Show agenda, deleting all other windows.
  953. reorganize-frame Show only two windows on the current frame, the current
  954. window and the agenda.
  955. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  956. Also, when exiting the agenda, kill that frame.
  957. See also the variable `org-agenda-restore-windows-after-quit'."
  958. :group 'org-agenda-windows
  959. :type '(choice
  960. (const current-window)
  961. (const other-frame)
  962. (const other-window)
  963. (const only-window)
  964. (const reorganize-frame)))
  965. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  966. "The min and max height of the agenda window as a fraction of frame height.
  967. The value of the variable is a cons cell with two numbers between 0 and 1.
  968. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  969. :group 'org-agenda-windows
  970. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  971. (defcustom org-agenda-restore-windows-after-quit nil
  972. "Non-nil means restore window configuration upon exiting agenda.
  973. Before the window configuration is changed for displaying the agenda,
  974. the current status is recorded. When the agenda is exited with
  975. `q' or `x' and this option is set, the old state is restored. If
  976. `org-agenda-window-setup' is `other-frame', the value of this
  977. option will be ignored."
  978. :group 'org-agenda-windows
  979. :type 'boolean)
  980. (defcustom org-agenda-span 'week
  981. "Number of days to include in overview display.
  982. Can be day, week, month, year, or any number of days.
  983. Custom commands can set this variable in the options section."
  984. :group 'org-agenda-daily/weekly
  985. :type '(choice (const :tag "Day" day)
  986. (const :tag "Week" week)
  987. (const :tag "Fortnight" fortnight)
  988. (const :tag "Month" month)
  989. (const :tag "Year" year)
  990. (integer :tag "Custom")))
  991. (defcustom org-agenda-start-on-weekday 1
  992. "Non-nil means start the overview always on the specified weekday.
  993. 0 denotes Sunday, 1 denotes Monday, etc.
  994. When nil, always start on the current day.
  995. Custom commands can set this variable in the options section."
  996. :group 'org-agenda-daily/weekly
  997. :type '(choice (const :tag "Today" nil)
  998. (integer :tag "Weekday No.")))
  999. (defcustom org-agenda-show-all-dates t
  1000. "Non-nil means `org-agenda' shows every day in the selected range.
  1001. When nil, only the days which actually have entries are shown."
  1002. :group 'org-agenda-daily/weekly
  1003. :type 'boolean)
  1004. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1005. "Format string for displaying dates in the agenda.
  1006. Used by the daily/weekly agenda. This should be a format string
  1007. understood by `format-time-string', or a function returning the
  1008. formatted date as a string. The function must take a single
  1009. argument, a calendar-style date list like (month day year)."
  1010. :group 'org-agenda-daily/weekly
  1011. :type '(choice
  1012. (string :tag "Format string")
  1013. (function :tag "Function")))
  1014. (defun org-agenda-format-date-aligned (date)
  1015. "Format a DATE string for display in the daily/weekly agenda.
  1016. This function makes sure that dates are aligned for easy reading."
  1017. (require 'cal-iso)
  1018. (let* ((dayname (calendar-day-name date))
  1019. (day (cadr date))
  1020. (day-of-week (calendar-day-of-week date))
  1021. (month (car date))
  1022. (monthname (calendar-month-name month))
  1023. (year (nth 2 date))
  1024. (iso-week (org-days-to-iso-week
  1025. (calendar-absolute-from-gregorian date)))
  1026. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1027. (1- year))
  1028. ((and (= month 12) (<= iso-week 1))
  1029. (1+ year))
  1030. (t year)))
  1031. (weekstring (if (= day-of-week 1)
  1032. (format " W%02d" iso-week)
  1033. "")))
  1034. (format "%-10s %2d %s %4d%s"
  1035. dayname day monthname year weekstring)))
  1036. (defcustom org-agenda-time-leading-zero nil
  1037. "Non-nil means use leading zero for military times in agenda.
  1038. For example, 9:30am would become 09:30 rather than 9:30."
  1039. :group 'org-agenda-daily/weekly
  1040. :version "24.1"
  1041. :type 'boolean)
  1042. (defcustom org-agenda-timegrid-use-ampm nil
  1043. "When set, show AM/PM style timestamps on the timegrid."
  1044. :group 'org-agenda
  1045. :version "24.1"
  1046. :type 'boolean)
  1047. (defun org-agenda-time-of-day-to-ampm (time)
  1048. "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
  1049. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1050. (minute (substring time -2))
  1051. (ampm "am"))
  1052. (cond
  1053. ((equal hour-number 12)
  1054. (setq ampm "pm"))
  1055. ((> hour-number 12)
  1056. (setq ampm "pm")
  1057. (setq hour-number (- hour-number 12))))
  1058. (concat
  1059. (if org-agenda-time-leading-zero
  1060. (format "%02d" hour-number)
  1061. (format "%02s" (number-to-string hour-number)))
  1062. ":" minute ampm)))
  1063. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1064. "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
  1065. (if org-agenda-timegrid-use-ampm
  1066. (org-agenda-time-of-day-to-ampm time)
  1067. time))
  1068. (defcustom org-agenda-weekend-days '(6 0)
  1069. "Which days are weekend?
  1070. These days get the special face `org-agenda-date-weekend' in the agenda."
  1071. :group 'org-agenda-daily/weekly
  1072. :type '(set :greedy t
  1073. (const :tag "Monday" 1)
  1074. (const :tag "Tuesday" 2)
  1075. (const :tag "Wednesday" 3)
  1076. (const :tag "Thursday" 4)
  1077. (const :tag "Friday" 5)
  1078. (const :tag "Saturday" 6)
  1079. (const :tag "Sunday" 0)))
  1080. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1081. "Non-nil means jump to today when moving a past date forward in time.
  1082. When using S-right in the agenda to move a a date forward, and the date
  1083. stamp currently points to the past, the first key press will move it
  1084. to today. WHen nil, just move one day forward even if the date stays
  1085. in the past."
  1086. :group 'org-agenda-daily/weekly
  1087. :version "24.1"
  1088. :type 'boolean)
  1089. (defcustom org-agenda-include-diary nil
  1090. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1091. Custom commands can set this variable in the options section."
  1092. :group 'org-agenda-daily/weekly
  1093. :type 'boolean)
  1094. (defcustom org-agenda-include-deadlines t
  1095. "If non-nil, include entries within their deadline warning period.
  1096. Custom commands can set this variable in the options section."
  1097. :group 'org-agenda-daily/weekly
  1098. :version "24.1"
  1099. :type 'boolean)
  1100. (defcustom org-agenda-show-future-repeats t
  1101. "Non-nil shows repeated entries in the future part of the agenda.
  1102. When set to the symbol `next' only the first future repeat is shown."
  1103. :group 'org-agenda-daily/weekly
  1104. :type '(choice
  1105. (const :tag "Show all repeated entries" t)
  1106. (const :tag "Show next repeated entry" next)
  1107. (const :tag "Do not show repeated entries" nil))
  1108. :version "26.1"
  1109. :package-version '(Org . "9.1")
  1110. :safe #'symbolp)
  1111. (defcustom org-agenda-prefer-last-repeat nil
  1112. "Non-nil sets date for repeated entries to their last repeat.
  1113. When nil, display SCHEDULED and DEADLINE dates at their base
  1114. date, and in today's agenda, as a reminder. Display plain
  1115. time-stamps, on the other hand, at every repeat date in the past
  1116. in addition to the base date.
  1117. When non-nil, show a repeated entry at its latest repeat date,
  1118. possibly being today even if it wasn't marked as done. This
  1119. setting is useful if you do not always mark repeated entries as
  1120. done and, yet, consider that reaching repeat date starts the task
  1121. anew.
  1122. When set to a list of strings, prefer last repeats only for
  1123. entries with these TODO keywords."
  1124. :group 'org-agenda-daily/weekly
  1125. :type '(choice
  1126. (const :tag "Prefer last repeat" t)
  1127. (const :tag "Prefer base date" nil)
  1128. (repeat :tag "Prefer last repeat for entries with these TODO keywords"
  1129. (string :tag "TODO keyword")))
  1130. :version "26.1"
  1131. :package-version '(Org . "9.1")
  1132. :safe (lambda (x) (or (booleanp x) (consp x))))
  1133. (defcustom org-scheduled-past-days 10000
  1134. "Number of days to continue listing scheduled items not marked DONE.
  1135. When an item is scheduled on a date, it shows up in the agenda on
  1136. this day and will be listed until it is marked done or for the
  1137. number of days given here."
  1138. :group 'org-agenda-daily/weekly
  1139. :type 'integer
  1140. :safe 'integerp)
  1141. (defcustom org-deadline-past-days 10000
  1142. "Number of days to warn about missed deadlines.
  1143. When an item has deadline on a date, it shows up in the agenda on
  1144. this day and will appear as a reminder until it is marked DONE or
  1145. for the number of days given here."
  1146. :group 'org-agenda-daily/weekly
  1147. :type 'integer
  1148. :version "26.1"
  1149. :package-version '(Org . "9.1")
  1150. :safe 'integerp)
  1151. (defcustom org-agenda-log-mode-items '(closed clock)
  1152. "List of items that should be shown in agenda log mode.
  1153. \\<org-agenda-mode-map>\
  1154. This list may contain the following symbols:
  1155. closed Show entries that have been closed on that day.
  1156. clock Show entries that have received clocked time on that day.
  1157. state Show all logged state changes.
  1158. Note that instead of changing this variable, you can also press \
  1159. `\\[universal-argument] \\[org-agenda-log-mode]' in
  1160. the agenda to display all available LOG items temporarily."
  1161. :group 'org-agenda-daily/weekly
  1162. :type '(set :greedy t (const closed) (const clock) (const state)))
  1163. (defcustom org-agenda-clock-consistency-checks
  1164. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1165. :gap-ok-around ("4:00")
  1166. :default-face ((:background "DarkRed") (:foreground "white"))
  1167. :overlap-face nil :gap-face nil :no-end-time-face nil
  1168. :long-face nil :short-face nil)
  1169. "This is a property list, with the following keys:
  1170. :max-duration Mark clocking chunks that are longer than this time.
  1171. This is a time string like \"HH:MM\", or the number
  1172. of minutes as an integer.
  1173. :min-duration Mark clocking chunks that are shorter that this.
  1174. This is a time string like \"HH:MM\", or the number
  1175. of minutes as an integer.
  1176. :max-gap Mark gaps between clocking chunks that are longer than
  1177. this duration. A number of minutes, or a string
  1178. like \"HH:MM\".
  1179. :gap-ok-around List of times during the day which are usually not working
  1180. times. When a gap is detected, but the gap contains any
  1181. of these times, the gap is *not* reported. For example,
  1182. if this is (\"4:00\" \"13:00\") then gaps that contain
  1183. 4:00 in the morning (i.e. the night) and 13:00
  1184. (i.e. a typical lunch time) do not cause a warning.
  1185. You should have at least one time during the night in this
  1186. list, or otherwise the first task each morning will trigger
  1187. a warning because it follows a long gap.
  1188. Furthermore, the following properties can be used to define faces for
  1189. issue display.
  1190. :default-face the default face, if the specific face is undefined
  1191. :overlap-face face for overlapping clocks
  1192. :gap-face face for gaps between clocks
  1193. :no-end-time-face face for incomplete clocks
  1194. :long-face face for clock intervals that are too long
  1195. :short-face face for clock intervals that are too short"
  1196. :group 'org-agenda-daily/weekly
  1197. :group 'org-clock
  1198. :version "24.1"
  1199. :type 'plist)
  1200. (defcustom org-agenda-log-mode-add-notes t
  1201. "Non-nil means add first line of notes to log entries in agenda views.
  1202. If a log item like a state change or a clock entry is associated with
  1203. notes, the first line of these notes will be added to the entry in the
  1204. agenda display."
  1205. :group 'org-agenda-daily/weekly
  1206. :type 'boolean)
  1207. (defcustom org-agenda-start-with-log-mode nil
  1208. "The initial value of log-mode in a newly created agenda window.
  1209. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1210. explanations on the possible values."
  1211. :group 'org-agenda-startup
  1212. :group 'org-agenda-daily/weekly
  1213. :type '(choice (const :tag "Don't show log items" nil)
  1214. (const :tag "Show only log items" only)
  1215. (const :tag "Show all possible log items" clockcheck)
  1216. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1217. (choice (const :tag "Show closed log items" closed)
  1218. (const :tag "Show clocked log items" clock)
  1219. (const :tag "Show all logged state changes" state)))))
  1220. (defcustom org-agenda-start-with-clockreport-mode nil
  1221. "The initial value of clockreport-mode in a newly created agenda window."
  1222. :group 'org-agenda-startup
  1223. :group 'org-agenda-daily/weekly
  1224. :type 'boolean)
  1225. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1226. "Property list with parameters for the clocktable in clockreport mode.
  1227. This is the display mode that shows a clock table in the daily/weekly
  1228. agenda, the properties for this dynamic block can be set here.
  1229. The usual clocktable parameters are allowed here, but you cannot set
  1230. the properties :name, :tstart, :tend, :block, and :scope - these will
  1231. be overwritten to make sure the content accurately reflects the
  1232. current display in the agenda."
  1233. :group 'org-agenda-daily/weekly
  1234. :type 'plist)
  1235. (defcustom org-agenda-search-view-always-boolean nil
  1236. "Non-nil means the search string is interpreted as individual parts.
  1237. The search string for search view can either be interpreted as a phrase,
  1238. or as a list of snippets that define a boolean search for a number of
  1239. strings.
  1240. When this is non-nil, the string will be split on whitespace, and each
  1241. snippet will be searched individually, and all must match in order to
  1242. select an entry. A snippet is then a single string of non-white
  1243. characters, or a string in double quotes, or a regexp in {} braces.
  1244. If a snippet is preceded by \"-\", the snippet must *not* match.
  1245. \"+\" is syntactic sugar for positive selection. Each snippet may
  1246. be found as a full word or a partial word, but see the variable
  1247. `org-agenda-search-view-force-full-words'.
  1248. When this is nil, search will look for the entire search phrase as one,
  1249. with each space character matching any amount of whitespace, including
  1250. line breaks.
  1251. Even when this is nil, you can still switch to Boolean search dynamically
  1252. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1253. is a regexp marked with braces like \"{abc}\", this will also switch to
  1254. boolean search."
  1255. :group 'org-agenda-search-view
  1256. :version "24.1"
  1257. :type 'boolean)
  1258. (defvaralias 'org-agenda-search-view-search-words-only
  1259. 'org-agenda-search-view-always-boolean)
  1260. (defcustom org-agenda-search-view-force-full-words nil
  1261. "Non-nil means, search words must be matches as complete words.
  1262. When nil, they may also match part of a word."
  1263. :group 'org-agenda-search-view
  1264. :version "24.1"
  1265. :type 'boolean)
  1266. (defcustom org-agenda-search-view-max-outline-level 0
  1267. "Maximum outline level to display in search view.
  1268. E.g. when this is set to 1, the search view will only
  1269. show headlines of level 1. When set to 0, the default
  1270. value, don't limit agenda view by outline level."
  1271. :group 'org-agenda-search-view
  1272. :version "24.4"
  1273. :package-version '(Org . "8.3")
  1274. :type 'integer)
  1275. (defgroup org-agenda-time-grid nil
  1276. "Options concerning the time grid in the Org Agenda."
  1277. :tag "Org Agenda Time Grid"
  1278. :group 'org-agenda)
  1279. (defcustom org-agenda-search-headline-for-time t
  1280. "Non-nil means search headline for a time-of-day.
  1281. If the headline contains a time-of-day in one format or another, it will
  1282. be used to sort the entry into the time sequence of items for a day.
  1283. Some people have time stamps in the headline that refer to the creation
  1284. time or so, and then this produces an unwanted side effect. If this is
  1285. the case for your, use this variable to turn off searching the headline
  1286. for a time."
  1287. :group 'org-agenda-time-grid
  1288. :type 'boolean)
  1289. (defcustom org-agenda-use-time-grid t
  1290. "Non-nil means show a time grid in the agenda schedule.
  1291. A time grid is a set of lines for specific times (like every two hours between
  1292. 8:00 and 20:00). The items scheduled for a day at specific times are
  1293. sorted in between these lines.
  1294. For details about when the grid will be shown, and what it will look like, see
  1295. the variable `org-agenda-time-grid'."
  1296. :group 'org-agenda-time-grid
  1297. :type 'boolean)
  1298. (defcustom org-agenda-time-grid
  1299. '((daily today require-timed)
  1300. (800 1000 1200 1400 1600 1800 2000)
  1301. "......"
  1302. "----------------")
  1303. "The settings for time grid for agenda display.
  1304. This is a list of four items. The first item is again a list. It contains
  1305. symbols specifying conditions when the grid should be displayed:
  1306. daily if the agenda shows a single day
  1307. weekly if the agenda shows an entire week
  1308. today show grid on current date, independent of daily/weekly display
  1309. require-timed show grid only if at least one item has a time specification
  1310. remove-match skip grid times already present in an entry
  1311. The second item is a list of integers, indicating the times that
  1312. should have a grid line.
  1313. The third item is a string which will be placed right after the
  1314. times that have a grid line.
  1315. The fourth item is a string placed after the grid times. This
  1316. will align with agenda items"
  1317. :group 'org-agenda-time-grid
  1318. :type
  1319. '(list
  1320. (set :greedy t :tag "Grid Display Options"
  1321. (const :tag "Show grid in single day agenda display" daily)
  1322. (const :tag "Show grid in weekly agenda display" weekly)
  1323. (const :tag "Always show grid for today" today)
  1324. (const :tag "Show grid only if any timed entries are present"
  1325. require-timed)
  1326. (const :tag "Skip grid times already present in an entry"
  1327. remove-match))
  1328. (repeat :tag "Grid Times" (integer :tag "Time"))
  1329. (string :tag "Grid String (after agenda times)")
  1330. (string :tag "Grid String (aligns with agenda items)")))
  1331. (defcustom org-agenda-show-current-time-in-grid t
  1332. "Non-nil means show the current time in the time grid."
  1333. :group 'org-agenda-time-grid
  1334. :version "24.1"
  1335. :type 'boolean)
  1336. (defcustom org-agenda-current-time-string
  1337. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1338. "The string for the current time marker in the agenda."
  1339. :group 'org-agenda-time-grid
  1340. :version "24.1"
  1341. :type 'string)
  1342. (defgroup org-agenda-sorting nil
  1343. "Options concerning sorting in the Org Agenda."
  1344. :tag "Org Agenda Sorting"
  1345. :group 'org-agenda)
  1346. (defcustom org-agenda-sorting-strategy
  1347. '((agenda habit-down time-up priority-down category-keep)
  1348. (todo priority-down category-keep)
  1349. (tags priority-down category-keep)
  1350. (search category-keep))
  1351. "Sorting structure for the agenda items of a single day.
  1352. This is a list of symbols which will be used in sequence to determine
  1353. if an entry should be listed before another entry. The following
  1354. symbols are recognized:
  1355. time-up Put entries with time-of-day indications first, early first
  1356. time-down Put entries with time-of-day indications first, late first
  1357. timestamp-up Sort by any timestamp, early first
  1358. timestamp-down Sort by any timestamp, late first
  1359. scheduled-up Sort by scheduled timestamp, early first
  1360. scheduled-down Sort by scheduled timestamp, late first
  1361. deadline-up Sort by deadline timestamp, early first
  1362. deadline-down Sort by deadline timestamp, late first
  1363. ts-up Sort by active timestamp, early first
  1364. ts-down Sort by active timestamp, late first
  1365. tsia-up Sort by inactive timestamp, early first
  1366. tsia-down Sort by inactive timestamp, late first
  1367. category-keep Keep the default order of categories, corresponding to the
  1368. sequence in `org-agenda-files'.
  1369. category-up Sort alphabetically by category, A-Z.
  1370. category-down Sort alphabetically by category, Z-A.
  1371. tag-up Sort alphabetically by last tag, A-Z.
  1372. tag-down Sort alphabetically by last tag, Z-A.
  1373. priority-up Sort numerically by priority, high priority last.
  1374. priority-down Sort numerically by priority, high priority first.
  1375. todo-state-up Sort by todo state, tasks that are done last.
  1376. todo-state-down Sort by todo state, tasks that are done first.
  1377. effort-up Sort numerically by estimated effort, high effort last.
  1378. effort-down Sort numerically by estimated effort, high effort first.
  1379. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1380. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1381. habit-up Put entries that are habits first
  1382. habit-down Put entries that are habits last
  1383. alpha-up Sort headlines alphabetically
  1384. alpha-down Sort headlines alphabetically, reversed
  1385. The different possibilities will be tried in sequence, and testing stops
  1386. if one comparison returns a \"not-equal\". For example, the default
  1387. '(time-up category-keep priority-down)
  1388. means: Pull out all entries having a specified time of day and sort them,
  1389. in order to make a time schedule for the current day the first thing in the
  1390. agenda listing for the day. Of the entries without a time indication, keep
  1391. the grouped in categories, don't sort the categories, but keep them in
  1392. the sequence given in `org-agenda-files'. Within each category sort by
  1393. priority.
  1394. Leaving out `category-keep' would mean that items will be sorted across
  1395. categories by priority.
  1396. Instead of a single list, this can also be a set of list for specific
  1397. contents, with a context symbol in the car of the list, any of
  1398. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1399. Custom commands can bind this variable in the options section."
  1400. :group 'org-agenda-sorting
  1401. :type `(choice
  1402. (repeat :tag "General" ,org-sorting-choice)
  1403. (list :tag "Individually"
  1404. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1405. (repeat ,org-sorting-choice))
  1406. (cons (const :tag "Strategy for TODO lists" todo)
  1407. (repeat ,org-sorting-choice))
  1408. (cons (const :tag "Strategy for Tags matches" tags)
  1409. (repeat ,org-sorting-choice))
  1410. (cons (const :tag "Strategy for search matches" search)
  1411. (repeat ,org-sorting-choice)))))
  1412. (defcustom org-agenda-cmp-user-defined nil
  1413. "A function to define the comparison `user-defined'.
  1414. This function must receive two arguments, agenda entry a and b.
  1415. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1416. the user comparison, return nil.
  1417. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1418. part of an agenda sorting strategy."
  1419. :group 'org-agenda-sorting
  1420. :type 'symbol)
  1421. (defcustom org-sort-agenda-notime-is-late t
  1422. "Non-nil means items without time are considered late.
  1423. This is only relevant for sorting. When t, items which have no explicit
  1424. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1425. do have a time. When nil, the default time is before 0:00. You can use this
  1426. option to decide if the schedule for today should come before or after timeless
  1427. agenda entries."
  1428. :group 'org-agenda-sorting
  1429. :type 'boolean)
  1430. (defcustom org-sort-agenda-noeffort-is-high t
  1431. "Non-nil means items without effort estimate are sorted as high effort.
  1432. This also applies when filtering an agenda view with respect to the
  1433. < or > effort operator. Then, tasks with no effort defined will be treated
  1434. as tasks with high effort.
  1435. When nil, such items are sorted as 0 minutes effort."
  1436. :group 'org-agenda-sorting
  1437. :type 'boolean)
  1438. (defgroup org-agenda-line-format nil
  1439. "Options concerning the entry prefix in the Org agenda display."
  1440. :tag "Org Agenda Line Format"
  1441. :group 'org-agenda)
  1442. (defcustom org-agenda-prefix-format
  1443. '((agenda . " %i %-12:c%?-12t% s")
  1444. (todo . " %i %-12:c")
  1445. (tags . " %i %-12:c")
  1446. (search . " %i %-12:c"))
  1447. "Format specifications for the prefix of items in the agenda views.
  1448. An alist with five entries, each for the different agenda types. The
  1449. keys of the sublists are `agenda', `todo', `search' and `tags'.
  1450. The values are format strings.
  1451. This format works similar to a printf format, with the following meaning:
  1452. %c the category of the item, \"Diary\" for entries from the diary,
  1453. or as given by the CATEGORY keyword or derived from the file name
  1454. %e the effort required by the item
  1455. %l the level of the item (insert X space(s) if item is of level X)
  1456. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1457. %T the last tag of the item (ignore inherited tags, which come first)
  1458. %t the HH:MM time-of-day specification if one applies to the entry
  1459. %s Scheduling/Deadline information, a short string
  1460. %b show breadcrumbs, i.e., the names of the higher levels
  1461. %(expression) Eval EXPRESSION and replace the control string
  1462. by the result
  1463. All specifiers work basically like the standard `%s' of printf, but may
  1464. contain two additional characters: a question mark just after the `%'
  1465. and a whitespace/punctuation character just before the final letter.
  1466. If the first character after `%' is a question mark, the entire field
  1467. will only be included if the corresponding value applies to the current
  1468. entry. This is useful for fields which should have fixed width when
  1469. present, but zero width when absent. For example, \"%?-12t\" will
  1470. result in a 12 character time field if a time of the day is specified,
  1471. but will completely disappear in entries which do not contain a time.
  1472. If there is punctuation or whitespace character just before the
  1473. final format letter, this character will be appended to the field
  1474. value if the value is not empty. For example, the format
  1475. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1476. the category is empty, no additional colon is inserted.
  1477. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1478. which means:
  1479. - Indent the line with two space characters
  1480. - Give the category a 12 chars wide field, padded with whitespace on
  1481. the right (because of `-'). Append a colon if there is a category
  1482. (because of `:').
  1483. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1484. time, don't put in an empty field, just skip it (because of '?').
  1485. - Finally, put the scheduling information.
  1486. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1487. `org-agenda-remove-tags'.
  1488. Custom commands can set this variable in the options section."
  1489. :type '(choice
  1490. (string :tag "General format")
  1491. (list :greedy t :tag "View dependent"
  1492. (cons (const agenda) (string :tag "Format"))
  1493. (cons (const todo) (string :tag "Format"))
  1494. (cons (const tags) (string :tag "Format"))
  1495. (cons (const search) (string :tag "Format"))))
  1496. :group 'org-agenda-line-format
  1497. :version "26.1"
  1498. :package-version '(Org . "9.1"))
  1499. (defvar org-prefix-format-compiled nil
  1500. "The compiled prefix format and associated variables.
  1501. This is a list where first element is a list of variable bindings, and second
  1502. element is the compiled format expression. See the variable
  1503. `org-agenda-prefix-format'.")
  1504. (defcustom org-agenda-todo-keyword-format "%-1s"
  1505. "Format for the TODO keyword in agenda lines.
  1506. Set this to something like \"%-12s\" if you want all TODO keywords
  1507. to occupy a fixed space in the agenda display."
  1508. :group 'org-agenda-line-format
  1509. :type 'string)
  1510. (defcustom org-agenda-diary-sexp-prefix nil
  1511. "A regexp that matches part of a diary sexp entry
  1512. which should be treated as scheduling/deadline information in
  1513. `org-agenda'.
  1514. For example, you can use this to extract the `diary-remind-message' from
  1515. `diary-remind' entries."
  1516. :group 'org-agenda-line-format
  1517. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1518. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1519. "Text preceding timerange entries in the agenda view.
  1520. This is a list with two strings. The first applies when the range
  1521. is entirely on one day. The second applies if the range spans several days.
  1522. The strings may have two \"%d\" format specifiers which will be filled
  1523. with the sequence number of the days, and the total number of days in the
  1524. range, respectively."
  1525. :group 'org-agenda-line-format
  1526. :type '(list
  1527. (string :tag "Deadline today ")
  1528. (choice :tag "Deadline relative"
  1529. (string :tag "Format string")
  1530. (function))))
  1531. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1532. "Text preceding scheduled items in the agenda view.
  1533. This is a list with two strings. The first applies when the item is
  1534. scheduled on the current day. The second applies when it has been scheduled
  1535. previously, it may contain a %d indicating that this is the nth time that
  1536. this item is scheduled, due to automatic rescheduling of unfinished items
  1537. for the following day. So this number is one larger than the number of days
  1538. that passed since this item was scheduled first."
  1539. :group 'org-agenda-line-format
  1540. :version "24.4"
  1541. :package-version '(Org . "8.0")
  1542. :type '(list
  1543. (string :tag "Scheduled today ")
  1544. (string :tag "Scheduled previously")))
  1545. (defcustom org-agenda-inactive-leader "["
  1546. "Text preceding item pulled into the agenda by inactive time stamps.
  1547. These entries are added to the agenda when pressing \"[\"."
  1548. :group 'org-agenda-line-format
  1549. :version "24.1"
  1550. :type 'string)
  1551. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1552. "Text preceding deadline items in the agenda view.
  1553. This is a list with three strings. The first applies when the item has its
  1554. deadline on the current day. The second applies when the deadline is in the
  1555. future, the third one when it is in the past. The strings may contain %d
  1556. to capture the number of days."
  1557. :group 'org-agenda-line-format
  1558. :version "24.4"
  1559. :package-version '(Org . "8.0")
  1560. :type '(list
  1561. (string :tag "Deadline today ")
  1562. (string :tag "Deadline in the future ")
  1563. (string :tag "Deadline in the past ")))
  1564. (defcustom org-agenda-remove-times-when-in-prefix t
  1565. "Non-nil means remove duplicate time specifications in agenda items.
  1566. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1567. time-of-day specification in a headline or diary entry is extracted and
  1568. placed into the prefix. If this option is non-nil, the original specification
  1569. \(a timestamp or -range, or just a plain time(range) specification like
  1570. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1571. cluttered.
  1572. The option can be t or nil. It may also be the symbol `beg', indicating
  1573. that the time should only be removed when it is located at the beginning of
  1574. the headline/diary entry."
  1575. :group 'org-agenda-line-format
  1576. :type '(choice
  1577. (const :tag "Always" t)
  1578. (const :tag "Never" nil)
  1579. (const :tag "When at beginning of entry" beg)))
  1580. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1581. "Non-nil means remove time ranges specifications in agenda
  1582. items that span on several days."
  1583. :group 'org-agenda-line-format
  1584. :version "24.1"
  1585. :type 'boolean)
  1586. (defcustom org-agenda-default-appointment-duration nil
  1587. "Default duration for appointments that only have a starting time.
  1588. When nil, no duration is specified in such cases.
  1589. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1590. :group 'org-agenda-line-format
  1591. :type '(choice
  1592. (integer :tag "Minutes")
  1593. (const :tag "No default duration")))
  1594. (defcustom org-agenda-show-inherited-tags t
  1595. "Non-nil means show inherited tags in each agenda line.
  1596. When this option is set to `always', it takes precedence over
  1597. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1598. in every agenda.
  1599. When this option is set to t (the default), inherited tags are
  1600. shown when they are available, i.e. when the value of
  1601. `org-agenda-use-tag-inheritance' enables tag inheritance for the
  1602. given agenda type.
  1603. This can be set to a list of agenda types in which the agenda
  1604. must display the inherited tags. Available types are `todo',
  1605. `agenda' and `search'.
  1606. When set to nil, never show inherited tags in agenda lines."
  1607. :group 'org-agenda-line-format
  1608. :group 'org-agenda
  1609. :version "24.3"
  1610. :type '(choice
  1611. (const :tag "Show inherited tags when available" t)
  1612. (const :tag "Always show inherited tags" always)
  1613. (repeat :tag "Show inherited tags only in selected agenda types"
  1614. (symbol :tag "Agenda type"))))
  1615. (defcustom org-agenda-use-tag-inheritance '(todo search agenda)
  1616. "List of agenda view types where to use tag inheritance.
  1617. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1618. controlled by `org-use-tag-inheritance'. In other agenda types,
  1619. `org-use-tag-inheritance' is not used for the selection of the
  1620. agenda entries. Still, you may want the agenda to be aware of
  1621. the inherited tags anyway, e.g. for later tag filtering.
  1622. Allowed value are `todo', `search' and `agenda'.
  1623. This variable has no effect if `org-agenda-show-inherited-tags'
  1624. is set to `always'. In that case, the agenda is aware of those
  1625. tags.
  1626. The default value sets tags in every agenda type. Setting this
  1627. option to nil will speed up non-tags agenda view a lot."
  1628. :group 'org-agenda
  1629. :version "26.1"
  1630. :package-version '(Org . "9.1")
  1631. :type '(choice
  1632. (const :tag "Use tag inheritance in all agenda types" t)
  1633. (repeat :tag "Use tag inheritance in selected agenda types"
  1634. (symbol :tag "Agenda type"))))
  1635. (defcustom org-agenda-hide-tags-regexp nil
  1636. "Regular expression used to filter away specific tags in agenda views.
  1637. This means that these tags will be present, but not be shown in the agenda
  1638. line. Secondary filtering will still work on the hidden tags.
  1639. Nil means don't hide any tags."
  1640. :group 'org-agenda-line-format
  1641. :type '(choice
  1642. (const :tag "Hide none" nil)
  1643. (string :tag "Regexp ")))
  1644. (defcustom org-agenda-remove-tags nil
  1645. "Non-nil means remove the tags from the headline copy in the agenda.
  1646. When this is the symbol `prefix', only remove tags when
  1647. `org-agenda-prefix-format' contains a `%T' specifier."
  1648. :group 'org-agenda-line-format
  1649. :type '(choice
  1650. (const :tag "Always" t)
  1651. (const :tag "Never" nil)
  1652. (const :tag "When prefix format contains %T" prefix)))
  1653. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1654. 'org-agenda-remove-tags)
  1655. (defcustom org-agenda-tags-column 'auto
  1656. "Shift tags in agenda items to this column.
  1657. If set to `auto', tags will be automatically aligned to the right
  1658. edge of the window.
  1659. If set to a positive number, tags will be left-aligned to that
  1660. column. If set to a negative number, tags will be right-aligned
  1661. to that column. For example, -80 works well for a normal 80
  1662. character screen."
  1663. :group 'org-agenda-line-format
  1664. :type '(choice
  1665. (const :tag "Automatically align to right edge of window" auto)
  1666. (integer :tag "Specific column" -80))
  1667. :package-version '(Org . "9.1")
  1668. :version "26.1")
  1669. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1670. (defcustom org-agenda-fontify-priorities 'cookies
  1671. "Non-nil means highlight low and high priorities in agenda.
  1672. When t, the highest priority entries are bold, lowest priority italic.
  1673. However, settings in `org-priority-faces' will overrule these faces.
  1674. When this variable is the symbol `cookies', only fontify the
  1675. cookies, not the entire task.
  1676. This may also be an association list of priority faces, whose
  1677. keys are the character values of `org-highest-priority',
  1678. `org-default-priority', and `org-lowest-priority' (the default values
  1679. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1680. color as a string, or a list like `(:background \"Red\")'.
  1681. If it is a color, the variable `org-faces-easy-properties'
  1682. determines if it is a foreground or a background color."
  1683. :group 'org-agenda-line-format
  1684. :type '(choice
  1685. (const :tag "Never" nil)
  1686. (const :tag "Defaults" t)
  1687. (const :tag "Cookies only" cookies)
  1688. (repeat :tag "Specify"
  1689. (list (character :tag "Priority" :value ?A)
  1690. (choice :tag "Face "
  1691. (string :tag "Color")
  1692. (sexp :tag "Face"))))))
  1693. (defcustom org-agenda-day-face-function nil
  1694. "Function called to determine what face should be used to display a day.
  1695. The only argument passed to that function is the day. It should
  1696. returns a face, or nil if does not want to specify a face and let
  1697. the normal rules apply."
  1698. :group 'org-agenda-line-format
  1699. :version "24.1"
  1700. :type '(choice (const nil) (function)))
  1701. (defcustom org-agenda-category-icon-alist nil
  1702. "Alist of category icon to be displayed in agenda views.
  1703. Each entry should have the following format:
  1704. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1705. Where CATEGORY-REGEXP is a regexp matching the categories where
  1706. the icon should be displayed.
  1707. FILE-OR-DATA either a file path or a string containing image data.
  1708. The other fields can be omitted safely if not needed:
  1709. TYPE indicates the image type.
  1710. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1711. image data.
  1712. PROPS are additional image attributes to assign to the image,
  1713. like, e.g. `:ascent center'.
  1714. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1715. If you want to set the display properties yourself, just put a
  1716. list as second element:
  1717. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1718. For example, to display a 16px horizontal space for Emacs
  1719. category, you can use:
  1720. (\"Emacs\" \\='(space . (:width (16))))"
  1721. :group 'org-agenda-line-format
  1722. :version "24.1"
  1723. :type '(alist :key-type (string :tag "Regexp matching category")
  1724. :value-type (choice (list :tag "Icon"
  1725. (string :tag "File or data")
  1726. (symbol :tag "Type")
  1727. (boolean :tag "Data?")
  1728. (repeat :tag "Extra image properties" :inline t symbol))
  1729. (list :tag "Display properties" sexp))))
  1730. (defgroup org-agenda-column-view nil
  1731. "Options concerning column view in the agenda."
  1732. :tag "Org Agenda Column View"
  1733. :group 'org-agenda)
  1734. (defcustom org-agenda-view-columns-initially nil
  1735. "When non-nil, switch to columns view right after creating the agenda."
  1736. :group 'org-agenda-column-view
  1737. :type 'boolean
  1738. :version "26.1"
  1739. :package-version '(Org . "9.0")
  1740. :safe #'booleanp)
  1741. (defcustom org-agenda-columns-show-summaries t
  1742. "Non-nil means show summaries for columns displayed in the agenda view."
  1743. :group 'org-agenda-column-view
  1744. :type 'boolean)
  1745. (defcustom org-agenda-columns-compute-summary-properties t
  1746. "Non-nil means recompute all summary properties before column view.
  1747. When column view in the agenda is listing properties that have a summary
  1748. operator, it can go to all relevant buffers and recompute the summaries
  1749. there. This can mean overhead for the agenda column view, but is necessary
  1750. to have thing up to date.
  1751. As a special case, a CLOCKSUM property also makes sure that the clock
  1752. computations are current."
  1753. :group 'org-agenda-column-view
  1754. :type 'boolean)
  1755. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1756. "Non-nil means the duration of an appointment will add to day effort.
  1757. The property to which appointment durations will be added is the one given
  1758. in the option `org-effort-property'. If an appointment does not have
  1759. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1760. is not set, an appointment without end time will not contribute to the time
  1761. estimate."
  1762. :group 'org-agenda-column-view
  1763. :type 'boolean)
  1764. (defcustom org-agenda-auto-exclude-function nil
  1765. "A function called with a tag to decide if it is filtered on \
  1766. \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
  1767. The sole argument to the function, which is called once for each
  1768. possible tag, is a string giving the name of the tag. The
  1769. function should return either nil if the tag should be included
  1770. as normal, or \"-<TAG>\" to exclude the tag.
  1771. Note that for the purpose of tag filtering, only the lower-case version of
  1772. all tags will be considered, so that this function will only ever see
  1773. the lower-case version of all tags."
  1774. :group 'org-agenda
  1775. :type '(choice (const nil) (function)))
  1776. (defcustom org-agenda-bulk-custom-functions nil
  1777. "Alist of characters and custom functions for bulk actions.
  1778. For example, this value makes those two functions available:
  1779. \\='((?R set-category)
  1780. (?C bulk-cut))
  1781. With selected entries in an agenda buffer, `B R' will call
  1782. the custom function `set-category' on the selected entries.
  1783. Note that functions in this alist don't need to be quoted."
  1784. :type '(alist :key-type character :value-type (group function))
  1785. :version "24.1"
  1786. :group 'org-agenda)
  1787. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1788. "Execute BODY with point at location given by `org-hd-marker' property.
  1789. If STRING is non-nil, the text property will be fetched from position 0
  1790. in that string. If STRING is nil, it will be fetched from the beginning
  1791. of the current line."
  1792. (org-with-gensyms (marker)
  1793. `(let ((,marker (get-text-property (if ,string 0 (point-at-bol))
  1794. 'org-hd-marker ,string)))
  1795. (with-current-buffer (marker-buffer ,marker)
  1796. (save-excursion
  1797. (goto-char ,marker)
  1798. ,@body)))))
  1799. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1800. (defun org-add-agenda-custom-command (entry)
  1801. "Replace or add a command in `org-agenda-custom-commands'.
  1802. This is mostly for hacking and trying a new command - once the command
  1803. works you probably want to add it to `org-agenda-custom-commands' for good."
  1804. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1805. (if ass
  1806. (setcdr ass (cdr entry))
  1807. (push entry org-agenda-custom-commands))))
  1808. ;;; Define the org-agenda-mode
  1809. (defvar org-agenda-mode-map (make-sparse-keymap)
  1810. "Keymap for `org-agenda-mode'.")
  1811. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1812. (defvar org-agenda-menu) ; defined later in this file.
  1813. (defvar org-agenda-restrict nil) ; defined later in this file.
  1814. (defvar org-agenda-follow-mode nil)
  1815. (defvar org-agenda-entry-text-mode nil)
  1816. (defvar org-agenda-clockreport-mode nil)
  1817. (defvar org-agenda-show-log nil)
  1818. (defvar org-agenda-redo-command nil)
  1819. (defvar org-agenda-query-string nil)
  1820. (defvar org-agenda-mode-hook nil
  1821. "Hook run after `org-agenda-mode' is turned on.
  1822. The buffer is still writable when this hook is called.")
  1823. (defvar org-agenda-type nil)
  1824. (defvar org-agenda-force-single-file nil)
  1825. (defvar org-agenda-bulk-marked-entries nil
  1826. "List of markers that refer to marked entries in the agenda.")
  1827. (defvar org-agenda-current-date nil
  1828. "Active date when building the agenda.")
  1829. ;;; Multiple agenda buffers support
  1830. (defcustom org-agenda-sticky nil
  1831. "Non-nil means agenda q key will bury agenda buffers.
  1832. Agenda commands will then show existing buffer instead of generating new ones.
  1833. When nil, `q' will kill the single agenda buffer."
  1834. :group 'org-agenda
  1835. :version "24.3"
  1836. :type 'boolean)
  1837. ;;;###autoload
  1838. (defun org-toggle-sticky-agenda (&optional arg)
  1839. "Toggle `org-agenda-sticky'."
  1840. (interactive "P")
  1841. (let ((new-value (if arg
  1842. (> (prefix-numeric-value arg) 0)
  1843. (not org-agenda-sticky))))
  1844. (if (equal new-value org-agenda-sticky)
  1845. (and (called-interactively-p 'interactive)
  1846. (message "Sticky agenda was already %s"
  1847. (if org-agenda-sticky "enabled" "disabled")))
  1848. (setq org-agenda-sticky new-value)
  1849. (org-agenda-kill-all-agenda-buffers)
  1850. (and (called-interactively-p 'interactive)
  1851. (message "Sticky agenda %s"
  1852. (if org-agenda-sticky "enabled" "disabled"))))))
  1853. (defvar org-agenda-buffer nil
  1854. "Agenda buffer currently being generated.")
  1855. (defvar org-agenda-last-prefix-arg nil)
  1856. (defvar org-agenda-this-buffer-name nil)
  1857. (defvar org-agenda-doing-sticky-redo nil)
  1858. (defvar org-agenda-this-buffer-is-sticky nil)
  1859. (defvar org-agenda-last-indirect-buffer nil
  1860. "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
  1861. (defconst org-agenda-local-vars
  1862. '(org-agenda-this-buffer-name
  1863. org-agenda-undo-list
  1864. org-agenda-pending-undo-list
  1865. org-agenda-follow-mode
  1866. org-agenda-entry-text-mode
  1867. org-agenda-clockreport-mode
  1868. org-agenda-show-log
  1869. org-agenda-redo-command
  1870. org-agenda-query-string
  1871. org-agenda-type
  1872. org-agenda-bulk-marked-entries
  1873. org-agenda-undo-has-started-in
  1874. org-agenda-info
  1875. org-agenda-pre-window-conf
  1876. org-agenda-columns-active
  1877. org-agenda-tag-filter
  1878. org-agenda-category-filter
  1879. org-agenda-top-headline-filter
  1880. org-agenda-regexp-filter
  1881. org-agenda-effort-filter
  1882. org-agenda-markers
  1883. org-agenda-last-search-view-search-was-boolean
  1884. org-agenda-last-indirect-buffer
  1885. org-agenda-filtered-by-category
  1886. org-agenda-filter-form
  1887. org-agenda-cycle-counter
  1888. org-agenda-last-prefix-arg)
  1889. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1890. (defun org-agenda-mode ()
  1891. "Mode for time-sorted view on action items in Org files.
  1892. The following commands are available:
  1893. \\{org-agenda-mode-map}"
  1894. (interactive)
  1895. (cond (org-agenda-doing-sticky-redo
  1896. ;; Refreshing sticky agenda-buffer
  1897. ;;
  1898. ;; Preserve the value of `org-agenda-local-vars' variables,
  1899. ;; while letting `kill-all-local-variables' kill the rest
  1900. (let ((save (buffer-local-variables)))
  1901. (kill-all-local-variables)
  1902. (mapc #'make-local-variable org-agenda-local-vars)
  1903. (dolist (elem save)
  1904. (pcase elem
  1905. (`(,var . ,val) ;ignore unbound variables
  1906. (when (and val (memq var org-agenda-local-vars))
  1907. (set var val))))))
  1908. (setq-local org-agenda-this-buffer-is-sticky t))
  1909. (org-agenda-sticky
  1910. ;; Creating a sticky Agenda buffer for the first time
  1911. (kill-all-local-variables)
  1912. (mapc 'make-local-variable org-agenda-local-vars)
  1913. (setq-local org-agenda-this-buffer-is-sticky t))
  1914. (t
  1915. ;; Creating a non-sticky agenda buffer
  1916. (kill-all-local-variables)
  1917. (setq-local org-agenda-this-buffer-is-sticky nil)))
  1918. (setq org-agenda-undo-list nil
  1919. org-agenda-pending-undo-list nil
  1920. org-agenda-bulk-marked-entries nil)
  1921. (setq major-mode 'org-agenda-mode)
  1922. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1923. (setq-local font-lock-global-modes (list 'not major-mode))
  1924. (setq mode-name "Org-Agenda")
  1925. (setq indent-tabs-mode nil)
  1926. (use-local-map org-agenda-mode-map)
  1927. (easy-menu-add org-agenda-menu)
  1928. (if org-startup-truncated (setq truncate-lines t))
  1929. (setq-local line-move-visual nil)
  1930. (add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1931. (add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1932. ;; Make sure properties are removed when copying text
  1933. (add-hook 'filter-buffer-substring-functions
  1934. (lambda (fun start end delete)
  1935. (substring-no-properties (funcall fun start end delete)))
  1936. nil t)
  1937. (unless org-agenda-keep-modes
  1938. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1939. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode))
  1940. (setq org-agenda-show-log org-agenda-start-with-log-mode)
  1941. (setq org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode)
  1942. (add-to-invisibility-spec '(org-filtered))
  1943. (add-to-invisibility-spec '(org-link))
  1944. (easy-menu-change
  1945. '("Agenda") "Agenda Files"
  1946. (append
  1947. (list
  1948. (vector
  1949. (if (get 'org-agenda-files 'org-restrict)
  1950. "Restricted to single file"
  1951. "Edit File List")
  1952. '(org-edit-agenda-file-list)
  1953. (not (get 'org-agenda-files 'org-restrict)))
  1954. "--")
  1955. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1956. (org-agenda-set-mode-name)
  1957. (apply
  1958. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1959. (list 'org-agenda-mode-hook)))
  1960. (substitute-key-definition 'undo 'org-agenda-undo
  1961. org-agenda-mode-map global-map)
  1962. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1963. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1964. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1965. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1966. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1967. (org-defkey org-agenda-mode-map [(meta down)] 'org-agenda-drag-line-forward)
  1968. (org-defkey org-agenda-mode-map [(meta up)] 'org-agenda-drag-line-backward)
  1969. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1970. (org-defkey org-agenda-mode-map "\M-m" 'org-agenda-bulk-toggle)
  1971. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1972. (org-defkey org-agenda-mode-map "\M-*" 'org-agenda-bulk-toggle-all)
  1973. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1974. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1975. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1976. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1977. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1978. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1979. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1980. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1981. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1982. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1983. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1984. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1985. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1986. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1987. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1988. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1989. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1990. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1991. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1992. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1993. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1994. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1995. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1996. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1997. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1998. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1999. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  2000. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  2001. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  2002. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  2003. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  2004. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  2005. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  2006. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  2007. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  2008. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  2009. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  2010. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  2011. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  2012. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  2013. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  2014. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  2015. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  2016. (while l (org-defkey org-agenda-mode-map
  2017. (int-to-string (pop l)) 'digit-argument)))
  2018. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  2019. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  2020. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  2021. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  2022. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  2023. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  2024. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  2025. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  2026. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  2027. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo-all)
  2028. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  2029. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  2030. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  2031. 'org-clock-modify-effort-estimate)
  2032. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  2033. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  2034. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  2035. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  2036. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  2037. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  2038. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  2039. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  2040. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  2041. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  2042. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  2043. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  2044. (substitute-key-definition 'next-line 'org-agenda-next-line
  2045. org-agenda-mode-map global-map)
  2046. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  2047. org-agenda-mode-map global-map)
  2048. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  2049. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  2050. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  2051. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  2052. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  2053. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  2054. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  2055. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  2056. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  2057. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  2058. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  2059. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  2060. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  2061. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  2062. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  2063. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  2064. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  2065. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  2066. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  2067. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  2068. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  2069. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  2070. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  2071. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  2072. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  2073. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  2074. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  2075. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  2076. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  2077. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  2078. (org-defkey org-agenda-mode-map "\C-c\C-x<" 'org-agenda-set-restriction-lock-from-agenda)
  2079. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  2080. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  2081. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  2082. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  2083. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  2084. (org-defkey org-agenda-mode-map "_" 'org-agenda-filter-by-effort)
  2085. (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
  2086. (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
  2087. (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
  2088. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  2089. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
  2090. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  2091. (org-defkey org-agenda-mode-map "\C-c\C-x_" 'org-timer-stop)
  2092. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  2093. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  2094. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  2095. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  2096. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  2097. (define-key org-agenda-mode-map [remap forward-paragraph] 'org-agenda-forward-block)
  2098. (define-key org-agenda-mode-map [remap backward-paragraph] 'org-agenda-backward-block)
  2099. (when org-agenda-mouse-1-follows-link
  2100. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2101. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  2102. '("Agenda"
  2103. ("Agenda Files")
  2104. "--"
  2105. ("Agenda Dates"
  2106. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda)]
  2107. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2108. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2109. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2110. "--"
  2111. ("View"
  2112. ["Day View" org-agenda-day-view
  2113. :active (org-agenda-check-type nil 'agenda)
  2114. :style radio :selected (eq org-agenda-current-span 'day)
  2115. :keys "v d (or just d)"]
  2116. ["Week View" org-agenda-week-view
  2117. :active (org-agenda-check-type nil 'agenda)
  2118. :style radio :selected (eq org-agenda-current-span 'week)
  2119. :keys "v w"]
  2120. ["Fortnight View" org-agenda-fortnight-view
  2121. :active (org-agenda-check-type nil 'agenda)
  2122. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2123. :keys "v t"]
  2124. ["Month View" org-agenda-month-view
  2125. :active (org-agenda-check-type nil 'agenda)
  2126. :style radio :selected (eq org-agenda-current-span 'month)
  2127. :keys "v m"]
  2128. ["Year View" org-agenda-year-view
  2129. :active (org-agenda-check-type nil 'agenda)
  2130. :style radio :selected (eq org-agenda-current-span 'year)
  2131. :keys "v y"]
  2132. "--"
  2133. ["Include Diary" org-agenda-toggle-diary
  2134. :style toggle :selected org-agenda-include-diary
  2135. :active (org-agenda-check-type nil 'agenda)]
  2136. ["Include Deadlines" org-agenda-toggle-deadlines
  2137. :style toggle :selected org-agenda-include-deadlines
  2138. :active (org-agenda-check-type nil 'agenda)]
  2139. ["Use Time Grid" org-agenda-toggle-time-grid
  2140. :style toggle :selected org-agenda-use-time-grid
  2141. :active (org-agenda-check-type nil 'agenda)]
  2142. "--"
  2143. ["Show clock report" org-agenda-clockreport-mode
  2144. :style toggle :selected org-agenda-clockreport-mode
  2145. :active (org-agenda-check-type nil 'agenda)]
  2146. ["Show some entry text" org-agenda-entry-text-mode
  2147. :style toggle :selected org-agenda-entry-text-mode
  2148. :active t]
  2149. "--"
  2150. ["Show Logbook entries" org-agenda-log-mode
  2151. :style toggle :selected org-agenda-show-log
  2152. :active (org-agenda-check-type nil 'agenda)
  2153. :keys "v l (or just l)"]
  2154. ["Include archived trees" org-agenda-archives-mode
  2155. :style toggle :selected org-agenda-archives-mode :active t
  2156. :keys "v a"]
  2157. ["Include archive files" (org-agenda-archives-mode t)
  2158. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2159. :keys "v A"]
  2160. "--"
  2161. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2162. ["Write view to file" org-agenda-write t]
  2163. ["Rebuild buffer" org-agenda-redo t]
  2164. ["Save all Org buffers" org-save-all-org-buffers t]
  2165. "--"
  2166. ["Show original entry" org-agenda-show t]
  2167. ["Go To (other window)" org-agenda-goto t]
  2168. ["Go To (this window)" org-agenda-switch-to t]
  2169. ["Capture with cursor date" org-agenda-capture t]
  2170. ["Follow Mode" org-agenda-follow-mode
  2171. :style toggle :selected org-agenda-follow-mode :active t]
  2172. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2173. "--"
  2174. ("TODO"
  2175. ["Cycle TODO" org-agenda-todo t]
  2176. ["Next TODO set" org-agenda-todo-nextset t]
  2177. ["Previous TODO set" org-agenda-todo-previousset t]
  2178. ["Add note" org-agenda-add-note t])
  2179. ("Archive/Refile/Delete"
  2180. ["Archive default" org-agenda-archive-default t]
  2181. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2182. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2183. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2184. ["Archive subtree" org-agenda-archive t]
  2185. "--"
  2186. ["Refile" org-agenda-refile t]
  2187. "--"
  2188. ["Delete subtree" org-agenda-kill t])
  2189. ("Bulk action"
  2190. ["Mark entry" org-agenda-bulk-mark t]
  2191. ["Mark all" org-agenda-bulk-mark-all t]
  2192. ["Unmark entry" org-agenda-bulk-unmark t]
  2193. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2194. ["Toggle mark" org-agenda-bulk-toggle t]
  2195. ["Toggle all" org-agenda-bulk-toggle-all t]
  2196. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2197. ["Act on all marked" org-agenda-bulk-action t]
  2198. "--"
  2199. ("Tags and Properties"
  2200. ["Show all Tags" org-agenda-show-tags t]
  2201. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2202. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2203. "--"
  2204. ["Column View" org-columns t])
  2205. ("Deadline/Schedule"
  2206. ["Schedule" org-agenda-schedule t]
  2207. ["Set Deadline" org-agenda-deadline t]
  2208. "--"
  2209. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda)]
  2210. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda)]
  2211. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u S-right"]
  2212. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u S-left"]
  2213. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-right"]
  2214. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-left"]
  2215. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda)])
  2216. ("Clock and Effort"
  2217. ["Clock in" org-agenda-clock-in t]
  2218. ["Clock out" org-agenda-clock-out t]
  2219. ["Clock cancel" org-agenda-clock-cancel t]
  2220. ["Goto running clock" org-clock-goto t]
  2221. "--"
  2222. ["Set Effort" org-agenda-set-effort t]
  2223. ["Change clocked effort" org-clock-modify-effort-estimate
  2224. (org-clock-is-active)])
  2225. ("Priority"
  2226. ["Set Priority" org-agenda-priority t]
  2227. ["Increase Priority" org-agenda-priority-up t]
  2228. ["Decrease Priority" org-agenda-priority-down t]
  2229. ["Show Priority" org-show-priority t])
  2230. ("Calendar/Diary"
  2231. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda)]
  2232. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda)]
  2233. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda)]
  2234. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda)]
  2235. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda)]
  2236. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda)]
  2237. "--"
  2238. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2239. "--"
  2240. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2241. "--"
  2242. ("MobileOrg"
  2243. ["Push Files and Views" org-mobile-push t]
  2244. ["Get Captured and Flagged" org-mobile-pull t]
  2245. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2246. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2247. "--"
  2248. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2249. "--"
  2250. ["Quit" org-agenda-quit t]
  2251. ["Exit and Release Buffers" org-agenda-exit t]
  2252. ))
  2253. ;;; Agenda undo
  2254. (defvar org-agenda-allow-remote-undo t
  2255. "Non-nil means allow remote undo from the agenda buffer.")
  2256. (defvar org-agenda-undo-has-started-in nil
  2257. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2258. (defun org-agenda-undo ()
  2259. "Undo a remote editing step in the agenda.
  2260. This undoes changes both in the agenda buffer and in the remote buffer
  2261. that have been changed along."
  2262. (interactive)
  2263. (or org-agenda-allow-remote-undo
  2264. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2265. (if (not (eq this-command last-command))
  2266. (setq org-agenda-undo-has-started-in nil
  2267. org-agenda-pending-undo-list org-agenda-undo-list))
  2268. (if (not org-agenda-pending-undo-list)
  2269. (user-error "No further undo information"))
  2270. (let* ((entry (pop org-agenda-pending-undo-list))
  2271. buf line cmd rembuf)
  2272. (setq cmd (pop entry) line (pop entry))
  2273. (setq rembuf (nth 2 entry))
  2274. (org-with-remote-undo rembuf
  2275. (while (bufferp (setq buf (pop entry)))
  2276. (if (pop entry)
  2277. (with-current-buffer buf
  2278. (let ((last-undo-buffer buf)
  2279. (inhibit-read-only t))
  2280. (unless (memq buf org-agenda-undo-has-started-in)
  2281. (push buf org-agenda-undo-has-started-in)
  2282. (make-local-variable 'pending-undo-list)
  2283. (undo-start))
  2284. (while (and pending-undo-list
  2285. (listp pending-undo-list)
  2286. (not (car pending-undo-list)))
  2287. (pop pending-undo-list))
  2288. (undo-more 1))))))
  2289. (org-goto-line line)
  2290. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2291. (defun org-verify-change-for-undo (l1 l2)
  2292. "Verify that a real change occurred between the undo lists L1 and L2."
  2293. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2294. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2295. (not (eq l1 l2)))
  2296. ;;; Agenda dispatch
  2297. (defvar org-agenda-restrict-begin (make-marker))
  2298. (defvar org-agenda-restrict-end (make-marker))
  2299. (defvar org-agenda-last-dispatch-buffer nil)
  2300. (defvar org-agenda-overriding-restriction nil)
  2301. (defcustom org-agenda-custom-commands-contexts nil
  2302. "Alist of custom agenda keys and contextual rules.
  2303. For example, if you have a custom agenda command \"p\" and you
  2304. want this command to be accessible only from plain text files,
  2305. use this:
  2306. \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
  2307. Here are the available contexts definitions:
  2308. in-file: command displayed only in matching files
  2309. in-mode: command displayed only in matching modes
  2310. not-in-file: command not displayed in matching files
  2311. not-in-mode: command not displayed in matching modes
  2312. in-buffer: command displayed only in matching buffers
  2313. not-in-buffer: command not displayed in matching buffers
  2314. [function]: a custom function taking no argument
  2315. If you define several checks, the agenda command will be
  2316. accessible if there is at least one valid check.
  2317. You can also bind a key to another agenda custom command
  2318. depending on contextual rules.
  2319. \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
  2320. Here it means: in .txt files, use \"p\" as the key for the
  2321. agenda command otherwise associated with \"q\". (The command
  2322. originally associated with \"q\" is not displayed to avoid
  2323. duplicates.)"
  2324. :version "24.3"
  2325. :group 'org-agenda-custom-commands
  2326. :type '(repeat (list :tag "Rule"
  2327. (string :tag " Agenda key")
  2328. (string :tag "Replace by command")
  2329. (repeat :tag "Available when"
  2330. (choice
  2331. (cons :tag "Condition"
  2332. (choice
  2333. (const :tag "In file" in-file)
  2334. (const :tag "Not in file" not-in-file)
  2335. (const :tag "In buffer" in-buffer)
  2336. (const :tag "Not in buffer" not-in-buffer)
  2337. (const :tag "In mode" in-mode)
  2338. (const :tag "Not in mode" not-in-mode))
  2339. (regexp))
  2340. (function :tag "Custom function"))))))
  2341. (defcustom org-agenda-max-entries nil
  2342. "Maximum number of entries to display in an agenda.
  2343. This can be nil (no limit) or an integer or an alist of agenda
  2344. types with an associated number of entries to display in this
  2345. type."
  2346. :version "24.4"
  2347. :package-version '(Org . "8.0")
  2348. :group 'org-agenda-custom-commands
  2349. :type '(choice (symbol :tag "No limit" nil)
  2350. (integer :tag "Max number of entries")
  2351. (repeat
  2352. (cons (choice :tag "Agenda type"
  2353. (const agenda)
  2354. (const todo)
  2355. (const tags)
  2356. (const search))
  2357. (integer :tag "Max number of entries")))))
  2358. (defcustom org-agenda-max-todos nil
  2359. "Maximum number of TODOs to display in an agenda.
  2360. This can be nil (no limit) or an integer or an alist of agenda
  2361. types with an associated number of entries to display in this
  2362. type."
  2363. :version "24.4"
  2364. :package-version '(Org . "8.0")
  2365. :group 'org-agenda-custom-commands
  2366. :type '(choice (symbol :tag "No limit" nil)
  2367. (integer :tag "Max number of TODOs")
  2368. (repeat
  2369. (cons (choice :tag "Agenda type"
  2370. (const agenda)
  2371. (const todo)
  2372. (const tags)
  2373. (const search))
  2374. (integer :tag "Max number of TODOs")))))
  2375. (defcustom org-agenda-max-tags nil
  2376. "Maximum number of tagged entries to display in an agenda.
  2377. This can be nil (no limit) or an integer or an alist of agenda
  2378. types with an associated number of entries to display in this
  2379. type."
  2380. :version "24.4"
  2381. :package-version '(Org . "8.0")
  2382. :group 'org-agenda-custom-commands
  2383. :type '(choice (symbol :tag "No limit" nil)
  2384. (integer :tag "Max number of tagged entries")
  2385. (repeat
  2386. (cons (choice :tag "Agenda type"
  2387. (const agenda)
  2388. (const todo)
  2389. (const tags)
  2390. (const search))
  2391. (integer :tag "Max number of tagged entries")))))
  2392. (defcustom org-agenda-max-effort nil
  2393. "Maximum cumulated effort duration for the agenda.
  2394. This can be nil (no limit) or a number of minutes (as an integer)
  2395. or an alist of agenda types with an associated number of minutes
  2396. to limit entries to in this type."
  2397. :version "24.4"
  2398. :package-version '(Org . "8.0")
  2399. :group 'org-agenda-custom-commands
  2400. :type '(choice (symbol :tag "No limit" nil)
  2401. (integer :tag "Max number of minutes")
  2402. (repeat
  2403. (cons (choice :tag "Agenda type"
  2404. (const agenda)
  2405. (const todo)
  2406. (const tags)
  2407. (const search))
  2408. (integer :tag "Max number of minutes")))))
  2409. (defvar org-agenda-keep-restricted-file-list nil)
  2410. (defvar org-keys nil)
  2411. (defvar org-match nil)
  2412. ;;;###autoload
  2413. (defun org-agenda (&optional arg org-keys restriction)
  2414. "Dispatch agenda commands to collect entries to the agenda buffer.
  2415. Prompts for a command to execute. Any prefix arg will be passed
  2416. on to the selected command. The default selections are:
  2417. a Call `org-agenda-list' to display the agenda for current day or week.
  2418. t Call `org-todo-list' to display the global todo list.
  2419. T Call `org-todo-list' to display the global todo list, select only
  2420. entries with a specific TODO keyword (the user gets a prompt).
  2421. m Call `org-tags-view' to display headlines with tags matching
  2422. a condition (the user is prompted for the condition).
  2423. M Like `m', but select only TODO entries, no ordinary headlines.
  2424. e Export views to associated files.
  2425. s Search entries for keywords.
  2426. S Search entries for keywords, only with TODO keywords.
  2427. / Multi occur across all agenda files and also files listed
  2428. in `org-agenda-text-search-extra-files'.
  2429. < Restrict agenda commands to buffer, subtree, or region.
  2430. Press several times to get the desired effect.
  2431. > Remove a previous restriction.
  2432. # List \"stuck\" projects.
  2433. ! Configure what \"stuck\" means.
  2434. C Configure custom agenda commands.
  2435. More commands can be added by configuring the variable
  2436. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2437. searches can be pre-defined in this way.
  2438. If the current buffer is in Org mode and visiting a file, you can also
  2439. first press `<' once to indicate that the agenda should be temporarily
  2440. \(until the next use of `\\[org-agenda]') restricted to the current file.
  2441. Pressing `<' twice means to restrict to the current subtree or region
  2442. \(if active)."
  2443. (interactive "P")
  2444. (catch 'exit
  2445. (let* ((prefix-descriptions nil)
  2446. (org-agenda-buffer-name org-agenda-buffer-name)
  2447. (org-agenda-window-setup (if (equal (buffer-name)
  2448. org-agenda-buffer-name)
  2449. 'current-window
  2450. org-agenda-window-setup))
  2451. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2452. (org-agenda-custom-commands
  2453. ;; normalize different versions
  2454. (delq nil
  2455. (mapcar
  2456. (lambda (x)
  2457. (cond ((stringp (cdr x))
  2458. (push x prefix-descriptions)
  2459. nil)
  2460. ((stringp (nth 1 x)) x)
  2461. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2462. (t (cons (car x) (cons "" (cdr x))))))
  2463. org-agenda-custom-commands)))
  2464. (org-agenda-custom-commands
  2465. (org-contextualize-keys
  2466. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2467. (buf (current-buffer))
  2468. (bfn (buffer-file-name (buffer-base-buffer)))
  2469. entry key type org-match lprops ans)
  2470. ;; Turn off restriction unless there is an overriding one,
  2471. (unless org-agenda-overriding-restriction
  2472. (unless org-agenda-keep-restricted-file-list
  2473. ;; There is a request to keep the file list in place
  2474. (put 'org-agenda-files 'org-restrict nil))
  2475. (setq org-agenda-restrict nil)
  2476. (move-marker org-agenda-restrict-begin nil)
  2477. (move-marker org-agenda-restrict-end nil))
  2478. ;; Delete old local properties
  2479. (put 'org-agenda-redo-command 'org-lprops nil)
  2480. ;; Delete previously set last-arguments
  2481. (put 'org-agenda-redo-command 'last-args nil)
  2482. ;; Remember where this call originated
  2483. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2484. (unless org-keys
  2485. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2486. org-keys (car ans)
  2487. restriction (cdr ans)))
  2488. ;; If we have sticky agenda buffers, set a name for the buffer,
  2489. ;; depending on the invoking keys. The user may still set this
  2490. ;; as a command option, which will overwrite what we do here.
  2491. (if org-agenda-sticky
  2492. (setq org-agenda-buffer-name
  2493. (format "*Org Agenda(%s)*" org-keys)))
  2494. ;; Establish the restriction, if any
  2495. (when (and (not org-agenda-overriding-restriction) restriction)
  2496. (put 'org-agenda-files 'org-restrict (list bfn))
  2497. (cond
  2498. ((eq restriction 'region)
  2499. (setq org-agenda-restrict (current-buffer))
  2500. (move-marker org-agenda-restrict-begin (region-beginning))
  2501. (move-marker org-agenda-restrict-end (region-end)))
  2502. ((eq restriction 'subtree)
  2503. (save-excursion
  2504. (setq org-agenda-restrict (current-buffer))
  2505. (org-back-to-heading t)
  2506. (move-marker org-agenda-restrict-begin (point))
  2507. (move-marker org-agenda-restrict-end
  2508. (progn (org-end-of-subtree t)))))))
  2509. ;; For example the todo list should not need it (but does...)
  2510. (cond
  2511. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2512. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2513. (progn
  2514. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2515. lprops (nth 4 entry))
  2516. (if org-agenda-sticky
  2517. (setq org-agenda-buffer-name
  2518. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2519. (format "*Org Agenda(%s)*" org-keys))))
  2520. (put 'org-agenda-redo-command 'org-lprops lprops)
  2521. (cond
  2522. ((eq type 'agenda)
  2523. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2524. ((eq type 'agenda*)
  2525. (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
  2526. ((eq type 'alltodo)
  2527. (org-let lprops '(org-todo-list current-prefix-arg)))
  2528. ((eq type 'search)
  2529. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2530. ((eq type 'stuck)
  2531. (org-let lprops '(org-agenda-list-stuck-projects
  2532. current-prefix-arg)))
  2533. ((eq type 'tags)
  2534. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2535. ((eq type 'tags-todo)
  2536. (org-let lprops '(org-tags-view '(4) org-match)))
  2537. ((eq type 'todo)
  2538. (org-let lprops '(org-todo-list org-match)))
  2539. ((eq type 'tags-tree)
  2540. (org-check-for-org-mode)
  2541. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2542. ((eq type 'todo-tree)
  2543. (org-check-for-org-mode)
  2544. (org-let lprops
  2545. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2546. (regexp-quote org-match) "\\>"))))
  2547. ((eq type 'occur-tree)
  2548. (org-check-for-org-mode)
  2549. (org-let lprops '(org-occur org-match)))
  2550. ((functionp type)
  2551. (org-let lprops '(funcall type org-match)))
  2552. ((fboundp type)
  2553. (org-let lprops '(funcall type org-match)))
  2554. (t (user-error "Invalid custom agenda command type %s" type))))
  2555. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2556. ((equal org-keys "C")
  2557. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2558. (customize-variable 'org-agenda-custom-commands))
  2559. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2560. ((equal org-keys "s") (call-interactively 'org-search-view))
  2561. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2562. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2563. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2564. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2565. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2566. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2567. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2568. (add-hook
  2569. 'post-command-hook
  2570. (lambda ()
  2571. (unless (current-message)
  2572. (let* ((m (org-agenda-get-any-marker))
  2573. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2574. (when note
  2575. (message (concat
  2576. "FLAGGING-NOTE ([?] for more info): "
  2577. (org-add-props
  2578. (replace-regexp-in-string
  2579. "\\\\n" "//"
  2580. (copy-sequence note))
  2581. nil 'face 'org-warning)))))))
  2582. t t))
  2583. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2584. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2585. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2586. (t (user-error "Invalid agenda key"))))))
  2587. (defvar org-agenda-multi)
  2588. (defun org-agenda-append-agenda ()
  2589. "Append another agenda view to the current one.
  2590. This function allows interactive building of block agendas.
  2591. Agenda views are separated by `org-agenda-block-separator'."
  2592. (interactive)
  2593. (unless (derived-mode-p 'org-agenda-mode)
  2594. (user-error "Can only append from within agenda buffer"))
  2595. (let ((org-agenda-multi t))
  2596. (org-agenda)
  2597. (widen)
  2598. (org-agenda-finalize)
  2599. (setq buffer-read-only t)
  2600. (org-agenda-fit-window-to-buffer)))
  2601. (defun org-agenda-normalize-custom-commands (cmds)
  2602. "Normalize custom commands CMDS."
  2603. (delq nil
  2604. (mapcar
  2605. (lambda (x)
  2606. (cond ((stringp (cdr x)) nil)
  2607. ((stringp (nth 1 x)) x)
  2608. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2609. (t (cons (car x) (cons "" (cdr x))))))
  2610. cmds)))
  2611. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2612. "The user interface for selecting an agenda command."
  2613. (catch 'exit
  2614. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2615. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2616. (region-p (org-region-active-p))
  2617. (custom org-agenda-custom-commands)
  2618. (selstring "")
  2619. restriction second-time
  2620. c entry key type match prefixes rmheader header-end custom1 desc
  2621. line lines left right n n1)
  2622. (save-window-excursion
  2623. (delete-other-windows)
  2624. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2625. (erase-buffer)
  2626. (insert (eval-when-compile
  2627. (let ((header
  2628. "Press key for an agenda command:
  2629. -------------------------------- < Buffer, subtree/region restriction
  2630. a Agenda for current week or day > Remove restriction
  2631. t List of all TODO entries e Export agenda views
  2632. m Match a TAGS/PROP/TODO query T Entries with special TODO kwd
  2633. s Search for keywords M Like m, but only TODO entries
  2634. / Multi-occur S Like s, but only TODO entries
  2635. ? Find :FLAGGED: entries C Configure custom agenda commands
  2636. * Toggle sticky agenda views # List stuck projects (!=configure)
  2637. ")
  2638. (start 0))
  2639. (while (string-match
  2640. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2641. header start)
  2642. (setq start (match-end 0))
  2643. (add-text-properties (match-beginning 2) (match-end 2)
  2644. '(face bold) header))
  2645. header)))
  2646. (setq header-end (point-marker))
  2647. (while t
  2648. (setq custom1 custom)
  2649. (when (eq rmheader t)
  2650. (org-goto-line 1)
  2651. (re-search-forward ":" nil t)
  2652. (delete-region (match-end 0) (point-at-eol))
  2653. (forward-char 1)
  2654. (looking-at "-+")
  2655. (delete-region (match-end 0) (point-at-eol))
  2656. (move-marker header-end (match-end 0)))
  2657. (goto-char header-end)
  2658. (delete-region (point) (point-max))
  2659. ;; Produce all the lines that describe custom commands and prefixes
  2660. (setq lines nil)
  2661. (while (setq entry (pop custom1))
  2662. (setq key (car entry) desc (nth 1 entry)
  2663. type (nth 2 entry)
  2664. match (nth 3 entry))
  2665. (if (> (length key) 1)
  2666. (cl-pushnew (string-to-char key) prefixes :test #'equal)
  2667. (setq line
  2668. (format
  2669. "%-4s%-14s"
  2670. (org-add-props (copy-sequence key)
  2671. '(face bold))
  2672. (cond
  2673. ((string-match "\\S-" desc) desc)
  2674. ((eq type 'agenda) "Agenda for current week or day")
  2675. ((eq type 'agenda*) "Appointments for current week or day")
  2676. ((eq type 'alltodo) "List of all TODO entries")
  2677. ((eq type 'search) "Word search")
  2678. ((eq type 'stuck) "List of stuck projects")
  2679. ((eq type 'todo) "TODO keyword")
  2680. ((eq type 'tags) "Tags query")
  2681. ((eq type 'tags-todo) "Tags (TODO)")
  2682. ((eq type 'tags-tree) "Tags tree")
  2683. ((eq type 'todo-tree) "TODO kwd tree")
  2684. ((eq type 'occur-tree) "Occur tree")
  2685. ((functionp type) (if (symbolp type)
  2686. (symbol-name type)
  2687. "Lambda expression"))
  2688. (t "???"))))
  2689. (if org-agenda-menu-show-matcher
  2690. (setq line
  2691. (concat line ": "
  2692. (cond
  2693. ((stringp match)
  2694. (setq match (copy-sequence match))
  2695. (org-add-props match nil 'face 'org-warning))
  2696. ((listp type)
  2697. (format "set of %d commands" (length type))))))
  2698. (if (org-string-nw-p match)
  2699. (add-text-properties
  2700. 0 (length line) (list 'help-echo
  2701. (concat "Matcher: " match)) line)))
  2702. (push line lines)))
  2703. (setq lines (nreverse lines))
  2704. (when prefixes
  2705. (mapc (lambda (x)
  2706. (push
  2707. (format "%s %s"
  2708. (org-add-props (char-to-string x)
  2709. nil 'face 'bold)
  2710. (or (cdr (assoc (concat selstring
  2711. (char-to-string x))
  2712. prefix-descriptions))
  2713. "Prefix key"))
  2714. lines))
  2715. prefixes))
  2716. ;; Check if we should display in two columns
  2717. (if org-agenda-menu-two-columns
  2718. (progn
  2719. (setq n (length lines)
  2720. n1 (+ (/ n 2) (mod n 2))
  2721. right (nthcdr n1 lines)
  2722. left (copy-sequence lines))
  2723. (setcdr (nthcdr (1- n1) left) nil))
  2724. (setq left lines right nil))
  2725. (while left
  2726. (insert "\n" (pop left))
  2727. (when right
  2728. (if (< (current-column) 40)
  2729. (move-to-column 40 t)
  2730. (insert " "))
  2731. (insert (pop right))))
  2732. ;; Make the window the right size
  2733. (goto-char (point-min))
  2734. (if second-time
  2735. (if (not (pos-visible-in-window-p (point-max)))
  2736. (org-fit-window-to-buffer))
  2737. (setq second-time t)
  2738. (org-fit-window-to-buffer))
  2739. ;; Ask for selection
  2740. (message "Press key for agenda command%s:"
  2741. (if (or restrict-ok org-agenda-overriding-restriction)
  2742. (if org-agenda-overriding-restriction
  2743. " (restriction lock active)"
  2744. (if restriction
  2745. (format " (restricted to %s)" restriction)
  2746. " (unrestricted)"))
  2747. ""))
  2748. (setq c (read-char-exclusive))
  2749. (message "")
  2750. (cond
  2751. ((assoc (char-to-string c) custom)
  2752. (setq selstring (concat selstring (char-to-string c)))
  2753. (throw 'exit (cons selstring restriction)))
  2754. ((memq c prefixes)
  2755. (setq selstring (concat selstring (char-to-string c))
  2756. prefixes nil
  2757. rmheader (or rmheader t)
  2758. custom (delq nil (mapcar
  2759. (lambda (x)
  2760. (if (or (= (length (car x)) 1)
  2761. (/= (string-to-char (car x)) c))
  2762. nil
  2763. (cons (substring (car x) 1) (cdr x))))
  2764. custom))))
  2765. ((eq c ?*)
  2766. (call-interactively 'org-toggle-sticky-agenda)
  2767. (sit-for 2))
  2768. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2769. (message "Restriction is only possible in Org buffers")
  2770. (ding) (sit-for 1))
  2771. ((eq c ?1)
  2772. (org-agenda-remove-restriction-lock 'noupdate)
  2773. (setq restriction 'buffer))
  2774. ((eq c ?0)
  2775. (org-agenda-remove-restriction-lock 'noupdate)
  2776. (setq restriction (if region-p 'region 'subtree)))
  2777. ((eq c ?<)
  2778. (org-agenda-remove-restriction-lock 'noupdate)
  2779. (setq restriction
  2780. (cond
  2781. ((eq restriction 'buffer)
  2782. (if region-p 'region 'subtree))
  2783. ((memq restriction '(subtree region))
  2784. nil)
  2785. (t 'buffer))))
  2786. ((eq c ?>)
  2787. (org-agenda-remove-restriction-lock 'noupdate)
  2788. (setq restriction nil))
  2789. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2790. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2791. ((and (> (length selstring) 0) (eq c ?\d))
  2792. (delete-window)
  2793. (org-agenda-get-restriction-and-command prefix-descriptions))
  2794. ((equal c ?q) (error "Abort"))
  2795. (t (user-error "Invalid key %c" c))))))))
  2796. (defun org-agenda-fit-window-to-buffer ()
  2797. "Fit the window to the buffer size."
  2798. (and (memq org-agenda-window-setup '(reorganize-frame))
  2799. (fboundp 'fit-window-to-buffer)
  2800. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2801. (= (car org-agenda-window-frame-fractions) 1.0))
  2802. (delete-other-windows)
  2803. (org-fit-window-to-buffer
  2804. nil
  2805. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2806. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2807. (defvar org-cmd nil)
  2808. (defvar org-agenda-overriding-cmd nil)
  2809. (defvar org-agenda-overriding-arguments nil)
  2810. (defvar org-agenda-overriding-cmd-arguments nil)
  2811. (defun org-agenda-run-series (name series)
  2812. "Run agenda NAME as a SERIES of agenda commands."
  2813. (org-let (nth 1 series) '(org-agenda-prepare name))
  2814. ;; We need to reset agenda markers here, because when constructing a
  2815. ;; block agenda, the individual blocks do not do that.
  2816. (org-agenda-reset-markers)
  2817. (let* ((org-agenda-multi t)
  2818. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2819. (cmds (car series))
  2820. (gprops (nth 1 series))
  2821. match ;; The byte compiler incorrectly complains about this. Keep it!
  2822. org-cmd type lprops)
  2823. (while (setq org-cmd (pop cmds))
  2824. (setq type (car org-cmd))
  2825. (setq match (eval (nth 1 org-cmd)))
  2826. (setq lprops (nth 2 org-cmd))
  2827. (let ((org-agenda-overriding-arguments
  2828. (if (eq org-agenda-overriding-cmd org-cmd)
  2829. (or org-agenda-overriding-arguments
  2830. org-agenda-overriding-cmd-arguments))))
  2831. (cond
  2832. ((eq type 'agenda)
  2833. (org-let2 gprops lprops
  2834. '(call-interactively 'org-agenda-list)))
  2835. ((eq type 'agenda*)
  2836. (org-let2 gprops lprops
  2837. '(funcall 'org-agenda-list nil nil t)))
  2838. ((eq type 'alltodo)
  2839. (org-let2 gprops lprops
  2840. '(call-interactively 'org-todo-list)))
  2841. ((eq type 'search)
  2842. (org-let2 gprops lprops
  2843. '(org-search-view current-prefix-arg match nil)))
  2844. ((eq type 'stuck)
  2845. (org-let2 gprops lprops
  2846. '(call-interactively 'org-agenda-list-stuck-projects)))
  2847. ((eq type 'tags)
  2848. (org-let2 gprops lprops
  2849. '(org-tags-view current-prefix-arg match)))
  2850. ((eq type 'tags-todo)
  2851. (org-let2 gprops lprops
  2852. '(org-tags-view '(4) match)))
  2853. ((eq type 'todo)
  2854. (org-let2 gprops lprops
  2855. '(org-todo-list match)))
  2856. ((fboundp type)
  2857. (org-let2 gprops lprops
  2858. '(funcall type match)))
  2859. (t (error "Invalid type in command series")))))
  2860. (widen)
  2861. (let ((inhibit-read-only t))
  2862. (add-text-properties (point-min) (point-max)
  2863. `(org-series t org-series-redo-cmd ,redo)))
  2864. (setq org-agenda-redo-command redo)
  2865. (goto-char (point-min)))
  2866. (org-agenda-fit-window-to-buffer)
  2867. (org-let (nth 1 series) '(org-agenda-finalize)))
  2868. ;;;###autoload
  2869. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2870. "Run an agenda command in batch mode and send the result to STDOUT.
  2871. If CMD-KEY is a string of length 1, it is used as a key in
  2872. `org-agenda-custom-commands' and triggers this command. If it is a
  2873. longer string it is used as a tags/todo match string.
  2874. Parameters are alternating variable names and values that will be bound
  2875. before running the agenda command."
  2876. (org-eval-in-environment (org-make-parameter-alist parameters)
  2877. (let (org-agenda-sticky)
  2878. (if (> (length cmd-key) 1)
  2879. (org-tags-view nil cmd-key)
  2880. (org-agenda nil cmd-key))))
  2881. (set-buffer org-agenda-buffer-name)
  2882. (princ (buffer-string)))
  2883. (defvar org-agenda-info nil)
  2884. ;;;###autoload
  2885. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2886. "Run an agenda command in batch mode and send the result to STDOUT.
  2887. If CMD-KEY is a string of length 1, it is used as a key in
  2888. `org-agenda-custom-commands' and triggers this command. If it is a
  2889. longer string it is used as a tags/todo match string.
  2890. Parameters are alternating variable names and values that will be bound
  2891. before running the agenda command.
  2892. The output gives a line for each selected agenda item. Each
  2893. item is a list of comma-separated values, like this:
  2894. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2895. category The category of the item
  2896. head The headline, without TODO kwd, TAGS and PRIORITY
  2897. type The type of the agenda entry, can be
  2898. todo selected in TODO match
  2899. tagsmatch selected in tags match
  2900. diary imported from diary
  2901. deadline a deadline on given date
  2902. scheduled scheduled on given date
  2903. timestamp entry has timestamp on given date
  2904. closed entry was closed on given date
  2905. upcoming-deadline warning about deadline
  2906. past-scheduled forwarded scheduled item
  2907. block entry has date block including g. date
  2908. todo The todo keyword, if any
  2909. tags All tags including inherited ones, separated by colons
  2910. date The relevant date, like 2007-2-14
  2911. time The time, like 15:00-16:50
  2912. extra Sting with extra planning info
  2913. priority-l The priority letter if any was given
  2914. priority-n The computed numerical priority
  2915. agenda-day The day in the agenda where this is listed"
  2916. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2917. (org-make-parameter-alist parameters))
  2918. (if (> (length cmd-key) 2)
  2919. (org-tags-view nil cmd-key)
  2920. (org-agenda nil cmd-key)))
  2921. (set-buffer org-agenda-buffer-name)
  2922. (let* ((lines (org-split-string (buffer-string) "\n"))
  2923. line)
  2924. (while (setq line (pop lines))
  2925. (catch 'next
  2926. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2927. (setq org-agenda-info
  2928. (org-fix-agenda-info (text-properties-at 0 line)))
  2929. (princ
  2930. (mapconcat 'org-agenda-export-csv-mapper
  2931. '(org-category txt type todo tags date time extra
  2932. priority-letter priority agenda-day)
  2933. ","))
  2934. (princ "\n")))))
  2935. (defun org-fix-agenda-info (props)
  2936. "Make sure all properties on an agenda item have a canonical form.
  2937. This ensures the export commands can easily use it."
  2938. (let (tmp re)
  2939. (when (setq tmp (plist-get props 'tags))
  2940. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2941. (when (setq tmp (plist-get props 'date))
  2942. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2943. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2944. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2945. (setq tmp (calendar-date-string tmp)))
  2946. (setq props (plist-put props 'date tmp)))
  2947. (when (setq tmp (plist-get props 'day))
  2948. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2949. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2950. (setq tmp (calendar-date-string tmp)))
  2951. (setq props (plist-put props 'day tmp))
  2952. (setq props (plist-put props 'agenda-day tmp)))
  2953. (when (setq tmp (plist-get props 'txt))
  2954. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2955. (plist-put props 'priority-letter (match-string 1 tmp))
  2956. (setq tmp (replace-match "" t t tmp)))
  2957. (when (and (setq re (plist-get props 'org-todo-regexp))
  2958. (setq re (concat "\\`\\.*" re " ?"))
  2959. (let ((case-fold-search nil)) (string-match re tmp)))
  2960. (plist-put props 'todo (match-string 1 tmp))
  2961. (setq tmp (replace-match "" t t tmp)))
  2962. (plist-put props 'txt tmp)))
  2963. props)
  2964. (defun org-agenda-export-csv-mapper (prop)
  2965. (let ((res (plist-get org-agenda-info prop)))
  2966. (setq res
  2967. (cond
  2968. ((not res) "")
  2969. ((stringp res) res)
  2970. (t (prin1-to-string res))))
  2971. (org-trim (replace-regexp-in-string "," ";" res nil t))))
  2972. ;;;###autoload
  2973. (defun org-store-agenda-views (&rest parameters)
  2974. "Store agenda views."
  2975. (interactive)
  2976. (eval (list 'org-batch-store-agenda-views)))
  2977. ;;;###autoload
  2978. (defmacro org-batch-store-agenda-views (&rest parameters)
  2979. "Run all custom agenda commands that have a file argument."
  2980. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2981. (pop-up-frames nil)
  2982. (dir default-directory)
  2983. (pars (org-make-parameter-alist parameters))
  2984. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2985. (save-window-excursion
  2986. (while cmds
  2987. (setq cmd (pop cmds)
  2988. thiscmdkey (car cmd)
  2989. thiscmdcmd (cdr cmd)
  2990. match (nth 2 thiscmdcmd)
  2991. bufname (if org-agenda-sticky
  2992. (or (and (stringp match)
  2993. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2994. (format "*Org Agenda(%s)*" thiscmdkey))
  2995. org-agenda-buffer-name)
  2996. cmd-or-set (nth 2 cmd)
  2997. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2998. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2999. (if (stringp files) (setq files (list files)))
  3000. (when files
  3001. (org-eval-in-environment (append org-agenda-exporter-settings
  3002. opts pars)
  3003. (org-agenda nil thiscmdkey))
  3004. (set-buffer bufname)
  3005. (while files
  3006. (org-eval-in-environment (append org-agenda-exporter-settings
  3007. opts pars)
  3008. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  3009. (and (get-buffer bufname)
  3010. (kill-buffer bufname)))))))
  3011. (defvar org-agenda-current-span nil
  3012. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3013. (defun org-agenda-mark-header-line (pos)
  3014. "Mark the line at POS as an agenda structure header."
  3015. (save-excursion
  3016. (goto-char pos)
  3017. (put-text-property (point-at-bol) (point-at-eol)
  3018. 'org-agenda-structural-header t)
  3019. (when org-agenda-title-append
  3020. (put-text-property (point-at-bol) (point-at-eol)
  3021. 'org-agenda-title-append org-agenda-title-append))))
  3022. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  3023. (defvar org-agenda-write-buffer-name "Agenda View")
  3024. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  3025. "Write the current buffer (an agenda view) as a file.
  3026. Depending on the extension of the file name, plain text (.txt),
  3027. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  3028. If the extension is .ics, translate visible agenda into iCalendar
  3029. format. If the extension is .org, collect all subtrees
  3030. corresponding to the agenda entries and add them in an .org file.
  3031. With prefix argument OPEN, open the new file immediately. If
  3032. NOSETTINGS is given, do not scope the settings of
  3033. `org-agenda-exporter-settings' into the export commands. This is
  3034. used when the settings have already been scoped and we do not
  3035. wish to overrule other, higher priority settings. If
  3036. AGENDA-BUFFER-NAME is provided, use this as the buffer name for
  3037. the agenda to write."
  3038. (interactive "FWrite agenda to file: \nP")
  3039. (if (or (not (file-writable-p file))
  3040. (and (file-exists-p file)
  3041. (if (called-interactively-p 'any)
  3042. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3043. (user-error "Cannot write agenda to file %s" file))
  3044. (org-let (if nosettings nil org-agenda-exporter-settings)
  3045. '(save-excursion
  3046. (save-window-excursion
  3047. (let ((bs (copy-sequence (buffer-string)))
  3048. (extension (file-name-extension file))
  3049. (default-directory (file-name-directory file))
  3050. beg content)
  3051. (with-temp-buffer
  3052. (rename-buffer org-agenda-write-buffer-name t)
  3053. (set-buffer-modified-p nil)
  3054. (insert bs)
  3055. (org-agenda-remove-marked-text 'invisible 'org-filtered)
  3056. (run-hooks 'org-agenda-before-write-hook)
  3057. (cond
  3058. ((bound-and-true-p org-mobile-creating-agendas)
  3059. (org-mobile-write-agenda-for-mobile file))
  3060. ((string= "org" extension)
  3061. (let (content p m message-log-max)
  3062. (goto-char (point-min))
  3063. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3064. (goto-char p)
  3065. (setq m (get-text-property (point) 'org-hd-marker))
  3066. (when m
  3067. (push (save-excursion
  3068. (set-buffer (marker-buffer m))
  3069. (goto-char m)
  3070. (org-copy-subtree 1 nil t t)
  3071. org-subtree-clip)
  3072. content)))
  3073. (find-file file)
  3074. (erase-buffer)
  3075. (dolist (s content) (org-paste-subtree 1 s))
  3076. (write-file file)
  3077. (kill-buffer (current-buffer))
  3078. (message "Org file written to %s" file)))
  3079. ((member extension '("html" "htm"))
  3080. (or (require 'htmlize nil t)
  3081. (error "Please install htmlize from https://github.com/hniksic/emacs-htmlize"))
  3082. (set-buffer (htmlize-buffer (current-buffer)))
  3083. (when org-agenda-export-html-style
  3084. ;; replace <style> section with org-agenda-export-html-style
  3085. (goto-char (point-min))
  3086. (kill-region (- (search-forward "<style") 6)
  3087. (search-forward "</style>"))
  3088. (insert org-agenda-export-html-style))
  3089. (write-file file)
  3090. (kill-buffer (current-buffer))
  3091. (message "HTML written to %s" file))
  3092. ((string= "ps" extension)
  3093. (require 'ps-print)
  3094. (ps-print-buffer-with-faces file)
  3095. (message "Postscript written to %s" file))
  3096. ((string= "pdf" extension)
  3097. (require 'ps-print)
  3098. (ps-print-buffer-with-faces
  3099. (concat (file-name-sans-extension file) ".ps"))
  3100. (call-process "ps2pdf" nil nil nil
  3101. (expand-file-name
  3102. (concat (file-name-sans-extension file) ".ps"))
  3103. (expand-file-name file))
  3104. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3105. (message "PDF written to %s" file))
  3106. ((string= "ics" extension)
  3107. (require 'ox-icalendar)
  3108. (org-icalendar-export-current-agenda (expand-file-name file)))
  3109. (t
  3110. (let ((bs (buffer-string)))
  3111. (find-file file)
  3112. (erase-buffer)
  3113. (insert bs)
  3114. (save-buffer 0)
  3115. (kill-buffer (current-buffer))
  3116. (message "Plain text written to %s" file))))))))
  3117. (set-buffer (or agenda-bufname
  3118. (and (called-interactively-p 'any) (buffer-name))
  3119. org-agenda-buffer-name)))
  3120. (when open (org-open-file file)))
  3121. (defun org-agenda-remove-marked-text (property &optional value)
  3122. "Delete all text marked with VALUE of PROPERTY.
  3123. VALUE defaults to t."
  3124. (let (beg)
  3125. (setq value (or value t))
  3126. (while (setq beg (text-property-any (point-min) (point-max)
  3127. property value))
  3128. (delete-region
  3129. beg (or (next-single-property-change beg property)
  3130. (point-max))))))
  3131. (defun org-agenda-add-entry-text ()
  3132. "Add entry text to agenda lines.
  3133. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3134. entry text following headings shown in the agenda.
  3135. Drawers will be excluded, also the line with scheduling/deadline info."
  3136. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3137. (not (bound-and-true-p org-mobile-creating-agendas)))
  3138. (let (m txt)
  3139. (goto-char (point-min))
  3140. (while (not (eobp))
  3141. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3142. (beginning-of-line 2)
  3143. (setq txt (org-agenda-get-some-entry-text
  3144. m org-agenda-add-entry-text-maxlines " > "))
  3145. (end-of-line 1)
  3146. (if (string-match "\\S-" txt)
  3147. (insert "\n" txt)
  3148. (or (eobp) (forward-char 1))))))))
  3149. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3150. &rest keep)
  3151. "Extract entry text from MARKER, at most N-LINES lines.
  3152. This will ignore drawers etc, just get the text.
  3153. If INDENT is given, prefix every line with this string. If KEEP is
  3154. given, it is a list of symbols, defining stuff that should not be
  3155. removed from the entry content. Currently only `planning' is allowed here."
  3156. (let (txt drawer-re kwd-time-re ind)
  3157. (save-excursion
  3158. (with-current-buffer (marker-buffer marker)
  3159. (if (not (derived-mode-p 'org-mode))
  3160. (setq txt "")
  3161. (org-with-wide-buffer
  3162. (goto-char marker)
  3163. (end-of-line 1)
  3164. (setq txt (buffer-substring
  3165. (min (1+ (point)) (point-max))
  3166. (progn (outline-next-heading) (point)))
  3167. drawer-re org-drawer-regexp
  3168. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3169. ".*\n?"))
  3170. (with-temp-buffer
  3171. (insert txt)
  3172. (when org-agenda-add-entry-text-descriptive-links
  3173. (goto-char (point-min))
  3174. (while (org-activate-links (point-max))
  3175. (add-text-properties (match-beginning 0) (match-end 0)
  3176. '(face org-link))))
  3177. (goto-char (point-min))
  3178. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3179. (set-text-properties (match-beginning 0) (match-end 0)
  3180. nil))
  3181. (goto-char (point-min))
  3182. (while (re-search-forward drawer-re nil t)
  3183. (delete-region
  3184. (match-beginning 0)
  3185. (progn (re-search-forward
  3186. "^[ \t]*:END:.*\n?" nil 'move)
  3187. (point))))
  3188. (unless (member 'planning keep)
  3189. (goto-char (point-min))
  3190. (while (re-search-forward kwd-time-re nil t)
  3191. (replace-match "")))
  3192. (goto-char (point-min))
  3193. (when org-agenda-entry-text-exclude-regexps
  3194. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3195. (while (setq re (pop re-list))
  3196. (goto-char (point-min))
  3197. (while (re-search-forward re nil t)
  3198. (replace-match "")))))
  3199. (goto-char (point-max))
  3200. (skip-chars-backward " \t\n")
  3201. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3202. ;; find and remove min common indentation
  3203. (goto-char (point-min))
  3204. (untabify (point-min) (point-max))
  3205. (setq ind (org-get-indentation))
  3206. (while (not (eobp))
  3207. (unless (looking-at "[ \t]*$")
  3208. (setq ind (min ind (org-get-indentation))))
  3209. (beginning-of-line 2))
  3210. (goto-char (point-min))
  3211. (while (not (eobp))
  3212. (unless (looking-at "[ \t]*$")
  3213. (move-to-column ind)
  3214. (delete-region (point-at-bol) (point)))
  3215. (beginning-of-line 2))
  3216. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3217. (goto-char (point-min))
  3218. (when indent
  3219. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3220. (replace-match indent t t)))
  3221. (goto-char (point-min))
  3222. (while (looking-at "[ \t]*\n") (replace-match ""))
  3223. (goto-char (point-max))
  3224. (when (> (org-current-line)
  3225. n-lines)
  3226. (org-goto-line (1+ n-lines))
  3227. (backward-char 1))
  3228. (setq txt (buffer-substring (point-min) (point))))))))
  3229. txt))
  3230. (defun org-check-for-org-mode ()
  3231. "Make sure current buffer is in org-mode. Error if not."
  3232. (or (derived-mode-p 'org-mode)
  3233. (error "Cannot execute Org agenda command on buffer in %s"
  3234. major-mode)))
  3235. ;;; Agenda prepare and finalize
  3236. (defvar org-agenda-multi nil) ; dynamically scoped
  3237. (defvar org-agenda-pre-window-conf nil)
  3238. (defvar org-agenda-columns-active nil)
  3239. (defvar org-agenda-name nil)
  3240. (defvar org-agenda-tag-filter nil)
  3241. (defvar org-agenda-category-filter nil)
  3242. (defvar org-agenda-regexp-filter nil)
  3243. (defvar org-agenda-effort-filter nil)
  3244. (defvar org-agenda-top-headline-filter nil)
  3245. (defvar org-agenda-tag-filter-preset nil
  3246. "A preset of the tags filter used for secondary agenda filtering.
  3247. This must be a list of strings, each string must be a single tag preceded
  3248. by \"+\" or \"-\".
  3249. This variable should not be set directly, but agenda custom commands can
  3250. bind it in the options section. The preset filter is a global property of
  3251. the entire agenda view. In a block agenda, it will not work reliably to
  3252. define a filter for one of the individual blocks. You need to set it in
  3253. the global options and expect it to be applied to the entire view.")
  3254. (defvar org-agenda-category-filter-preset nil
  3255. "A preset of the category filter used for secondary agenda filtering.
  3256. This must be a list of strings, each string must be a single category
  3257. preceded by \"+\" or \"-\".
  3258. This variable should not be set directly, but agenda custom commands can
  3259. bind it in the options section. The preset filter is a global property of
  3260. the entire agenda view. In a block agenda, it will not work reliably to
  3261. define a filter for one of the individual blocks. You need to set it in
  3262. the global options and expect it to be applied to the entire view.")
  3263. (defvar org-agenda-regexp-filter-preset nil
  3264. "A preset of the regexp filter used for secondary agenda filtering.
  3265. This must be a list of strings, each string must be a single regexp
  3266. preceded by \"+\" or \"-\".
  3267. This variable should not be set directly, but agenda custom commands can
  3268. bind it in the options section. The preset filter is a global property of
  3269. the entire agenda view. In a block agenda, it will not work reliably to
  3270. define a filter for one of the individual blocks. You need to set it in
  3271. the global options and expect it to be applied to the entire view.")
  3272. (defvar org-agenda-effort-filter-preset nil
  3273. "A preset of the effort condition used for secondary agenda filtering.
  3274. This must be a list of strings, each string must be a single regexp
  3275. preceded by \"+\" or \"-\".
  3276. This variable should not be set directly, but agenda custom commands can
  3277. bind it in the options section. The preset filter is a global property of
  3278. the entire agenda view. In a block agenda, it will not work reliably to
  3279. define a filter for one of the individual blocks. You need to set it in
  3280. the global options and expect it to be applied to the entire view.")
  3281. (defun org-agenda-use-sticky-p ()
  3282. "Return non-nil if an agenda buffer named
  3283. `org-agenda-buffer-name' exists and should be shown instead of
  3284. generating a new one."
  3285. (and
  3286. ;; turned off by user
  3287. org-agenda-sticky
  3288. ;; For multi-agenda buffer already exists
  3289. (not org-agenda-multi)
  3290. ;; buffer found
  3291. (get-buffer org-agenda-buffer-name)
  3292. ;; C-u parameter is same as last call
  3293. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3294. (and
  3295. (equal current-prefix-arg
  3296. org-agenda-last-prefix-arg)
  3297. ;; In case user turned stickiness on, while having existing
  3298. ;; Agenda buffer active, don't reuse that buffer, because it
  3299. ;; does not have org variables local
  3300. org-agenda-this-buffer-is-sticky))))
  3301. (defun org-agenda-prepare-window (abuf filter-alist)
  3302. "Setup agenda buffer in the window.
  3303. ABUF is the buffer for the agenda window.
  3304. FILTER-ALIST is an alist of filters we need to apply when
  3305. `org-agenda-persistent-filter' is non-nil."
  3306. (let* ((awin (get-buffer-window abuf)) wconf)
  3307. (cond
  3308. ((equal (current-buffer) abuf) nil)
  3309. (awin (select-window awin))
  3310. ((not (setq wconf (current-window-configuration))))
  3311. ((eq org-agenda-window-setup 'current-window)
  3312. (pop-to-buffer-same-window abuf))
  3313. ((eq org-agenda-window-setup 'other-window)
  3314. (org-switch-to-buffer-other-window abuf))
  3315. ((eq org-agenda-window-setup 'other-frame)
  3316. (switch-to-buffer-other-frame abuf))
  3317. ((eq org-agenda-window-setup 'only-window)
  3318. (delete-other-windows)
  3319. (pop-to-buffer-same-window abuf))
  3320. ((eq org-agenda-window-setup 'reorganize-frame)
  3321. (delete-other-windows)
  3322. (org-switch-to-buffer-other-window abuf)))
  3323. (setq org-agenda-tag-filter (cdr (assq 'tag filter-alist)))
  3324. (setq org-agenda-category-filter (cdr (assq 'cat filter-alist)))
  3325. (setq org-agenda-effort-filter (cdr (assq 'effort filter-alist)))
  3326. (setq org-agenda-regexp-filter (cdr (assq 're filter-alist)))
  3327. ;; Additional test in case agenda is invoked from within agenda
  3328. ;; buffer via elisp link.
  3329. (unless (equal (current-buffer) abuf)
  3330. (pop-to-buffer-same-window abuf))
  3331. (setq org-agenda-pre-window-conf
  3332. (or wconf org-agenda-pre-window-conf))))
  3333. (defun org-agenda-prepare (&optional name)
  3334. (let ((filter-alist (if org-agenda-persistent-filter
  3335. (with-current-buffer
  3336. (get-buffer-create org-agenda-buffer-name)
  3337. (list `(tag . ,org-agenda-tag-filter)
  3338. `(re . ,org-agenda-regexp-filter)
  3339. `(effort . ,org-agenda-effort-filter)
  3340. `(cat . ,org-agenda-category-filter))))))
  3341. (if (org-agenda-use-sticky-p)
  3342. (progn
  3343. (put 'org-agenda-tag-filter :preset-filter nil)
  3344. (put 'org-agenda-category-filter :preset-filter nil)
  3345. (put 'org-agenda-regexp-filter :preset-filter nil)
  3346. ;; Popup existing buffer
  3347. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3348. filter-alist)
  3349. (message "Sticky Agenda buffer, use `r' to refresh")
  3350. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3351. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3352. (setq org-todo-keywords-for-agenda nil)
  3353. (put 'org-agenda-tag-filter :preset-filter
  3354. org-agenda-tag-filter-preset)
  3355. (put 'org-agenda-category-filter :preset-filter
  3356. org-agenda-category-filter-preset)
  3357. (put 'org-agenda-regexp-filter :preset-filter
  3358. org-agenda-regexp-filter-preset)
  3359. (put 'org-agenda-effort-filter :preset-filter
  3360. org-agenda-effort-filter-preset)
  3361. (if org-agenda-multi
  3362. (progn
  3363. (setq buffer-read-only nil)
  3364. (goto-char (point-max))
  3365. (unless (or (bobp) org-agenda-compact-blocks
  3366. (not org-agenda-block-separator))
  3367. (insert "\n"
  3368. (if (stringp org-agenda-block-separator)
  3369. org-agenda-block-separator
  3370. (make-string (window-width) org-agenda-block-separator))
  3371. "\n"))
  3372. (narrow-to-region (point) (point-max)))
  3373. (setq org-done-keywords-for-agenda nil)
  3374. ;; Setting any org variables that are in org-agenda-local-vars
  3375. ;; list need to be done after the prepare call
  3376. (org-agenda-prepare-window
  3377. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3378. (setq buffer-read-only nil)
  3379. (org-agenda-reset-markers)
  3380. (let ((inhibit-read-only t)) (erase-buffer))
  3381. (org-agenda-mode)
  3382. (setq org-agenda-buffer (current-buffer))
  3383. (setq org-agenda-contributing-files nil)
  3384. (setq org-agenda-columns-active nil)
  3385. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3386. (setq org-todo-keywords-for-agenda
  3387. (org-uniquify org-todo-keywords-for-agenda))
  3388. (setq org-done-keywords-for-agenda
  3389. (org-uniquify org-done-keywords-for-agenda))
  3390. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3391. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3392. (and name (not org-agenda-name)
  3393. (setq-local org-agenda-name name)))
  3394. (setq buffer-read-only nil))))
  3395. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3396. (defun org-agenda-finalize ()
  3397. "Finishing touch for the agenda buffer, called just before displaying it."
  3398. (unless org-agenda-multi
  3399. (save-excursion
  3400. (let ((inhibit-read-only t))
  3401. (goto-char (point-min))
  3402. (save-excursion
  3403. (while (org-activate-links (point-max))
  3404. (add-text-properties (match-beginning 0) (match-end 0)
  3405. '(face org-link))))
  3406. (unless (eq org-agenda-remove-tags t)
  3407. (org-agenda-align-tags))
  3408. (unless org-agenda-with-colors
  3409. (remove-text-properties (point-min) (point-max) '(face nil)))
  3410. (if (and (boundp 'org-agenda-overriding-columns-format)
  3411. org-agenda-overriding-columns-format)
  3412. (setq-local org-agenda-overriding-columns-format
  3413. org-agenda-overriding-columns-format))
  3414. (if (and (boundp 'org-agenda-view-columns-initially)
  3415. org-agenda-view-columns-initially)
  3416. (org-agenda-columns))
  3417. (when org-agenda-fontify-priorities
  3418. (org-agenda-fontify-priorities))
  3419. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3420. (org-agenda-dim-blocked-tasks))
  3421. (org-agenda-mark-clocking-task)
  3422. (when org-agenda-entry-text-mode
  3423. (org-agenda-entry-text-hide)
  3424. (org-agenda-entry-text-show))
  3425. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3426. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3427. (org-habit-insert-consistency-graphs))
  3428. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3429. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3430. (and (listp org-agenda-show-inherited-tags)
  3431. (memq org-agenda-type org-agenda-show-inherited-tags))
  3432. (and (eq org-agenda-show-inherited-tags t)
  3433. (or (eq org-agenda-use-tag-inheritance t)
  3434. (and (listp org-agenda-use-tag-inheritance)
  3435. (not (memq org-agenda-type
  3436. org-agenda-use-tag-inheritance))))))
  3437. (let (mrk)
  3438. (save-excursion
  3439. (goto-char (point-min))
  3440. (while (equal (forward-line) 0)
  3441. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3442. (put-text-property (point-at-bol) (point-at-eol)
  3443. 'tags (org-with-point-at mrk
  3444. (delete-dups
  3445. (mapcar 'downcase (org-get-tags-at))))))))))
  3446. (run-hooks 'org-agenda-finalize-hook)
  3447. (when org-agenda-top-headline-filter
  3448. (org-agenda-filter-top-headline-apply
  3449. org-agenda-top-headline-filter))
  3450. (when org-agenda-tag-filter
  3451. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3452. (when (get 'org-agenda-tag-filter :preset-filter)
  3453. (org-agenda-filter-apply
  3454. (get 'org-agenda-tag-filter :preset-filter) 'tag t))
  3455. (when org-agenda-category-filter
  3456. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3457. (when (get 'org-agenda-category-filter :preset-filter)
  3458. (org-agenda-filter-apply
  3459. (get 'org-agenda-category-filter :preset-filter) 'category))
  3460. (when org-agenda-regexp-filter
  3461. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3462. (when (get 'org-agenda-regexp-filter :preset-filter)
  3463. (org-agenda-filter-apply
  3464. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3465. (when org-agenda-effort-filter
  3466. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3467. (when (get 'org-agenda-effort-filter :preset-filter)
  3468. (org-agenda-filter-apply
  3469. (get 'org-agenda-effort-filter :preset-filter) 'effort))
  3470. (add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3471. (defun org-agenda-mark-clocking-task ()
  3472. "Mark the current clock entry in the agenda if it is present."
  3473. ;; We need to widen when `org-agenda-finalize' is called from
  3474. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3475. (when (bound-and-true-p org-clock-current-task)
  3476. (save-restriction
  3477. (widen)
  3478. (org-agenda-unmark-clocking-task)
  3479. (when (marker-buffer org-clock-hd-marker)
  3480. (save-excursion
  3481. (goto-char (point-min))
  3482. (let (s ov)
  3483. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3484. (goto-char s)
  3485. (when (equal (org-get-at-bol 'org-hd-marker)
  3486. org-clock-hd-marker)
  3487. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3488. (overlay-put ov 'type 'org-agenda-clocking)
  3489. (overlay-put ov 'face 'org-agenda-clocking)
  3490. (overlay-put ov 'help-echo
  3491. "The clock is running in this item")))))))))
  3492. (defun org-agenda-unmark-clocking-task ()
  3493. "Unmark the current clocking task."
  3494. (mapc (lambda (o)
  3495. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3496. (delete-overlay o)))
  3497. (overlays-in (point-min) (point-max))))
  3498. (defun org-agenda-fontify-priorities ()
  3499. "Make highest priority lines bold, and lowest italic."
  3500. (interactive)
  3501. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3502. (delete-overlay o)))
  3503. (overlays-in (point-min) (point-max)))
  3504. (save-excursion
  3505. (let (b e p ov h l)
  3506. (goto-char (point-min))
  3507. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3508. (setq h (or (get-char-property (point) 'org-highest-priority)
  3509. org-highest-priority)
  3510. l (or (get-char-property (point) 'org-lowest-priority)
  3511. org-lowest-priority)
  3512. p (string-to-char (match-string 1))
  3513. b (match-beginning 0)
  3514. e (if (eq org-agenda-fontify-priorities 'cookies)
  3515. (match-end 0)
  3516. (point-at-eol))
  3517. ov (make-overlay b e))
  3518. (overlay-put
  3519. ov 'face
  3520. (let ((special-face
  3521. (cond ((org-face-from-face-or-color
  3522. 'priority 'org-priority
  3523. (cdr (assoc p org-priority-faces))))
  3524. ((and (listp org-agenda-fontify-priorities)
  3525. (org-face-from-face-or-color
  3526. 'priority 'org-priority
  3527. (cdr (assoc p org-agenda-fontify-priorities)))))
  3528. ((equal p l) 'italic)
  3529. ((equal p h) 'bold))))
  3530. (if special-face (list special-face 'org-priority) 'org-priority)))
  3531. (overlay-put ov 'org-type 'org-priority)))))
  3532. (defvar org-depend-tag-blocked)
  3533. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3534. "Dim currently blocked TODOs in the agenda display.
  3535. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3536. dimming them."
  3537. (interactive "P")
  3538. (when (called-interactively-p 'interactive)
  3539. (message "Dim or hide blocked tasks..."))
  3540. (dolist (o (overlays-in (point-min) (point-max)))
  3541. (when (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3542. (delete-overlay o)))
  3543. (save-excursion
  3544. (let ((inhibit-read-only t))
  3545. (goto-char (point-min))
  3546. (while (let ((pos (text-property-not-all
  3547. (point) (point-max) 'org-todo-blocked nil)))
  3548. (when pos (goto-char pos)))
  3549. (let* ((invisible (eq (org-get-at-bol 'org-todo-blocked) 'invisible))
  3550. (ov (make-overlay (if invisible
  3551. (line-end-position 0)
  3552. (line-beginning-position))
  3553. (line-end-position))))
  3554. (if invisible
  3555. (overlay-put ov 'invisible t)
  3556. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3557. (overlay-put ov 'org-type 'org-blocked-todo))
  3558. (forward-line))))
  3559. (when (called-interactively-p 'interactive)
  3560. (message "Dim or hide blocked tasks...done")))
  3561. (defun org-agenda--mark-blocked-entry (entry)
  3562. "For ENTRY a string with the text property `org-hd-marker', if
  3563. the header at `org-hd-marker' is blocked according to
  3564. `org-entry-blocked-p', then if `org-agenda-dim-blocked-tasks' is
  3565. 'invisible and the header is not blocked by checkboxes, set the
  3566. text property `org-todo-blocked' to 'invisible, otherwise set it
  3567. to t."
  3568. (when (get-text-property 0 'todo-state entry)
  3569. (let ((entry-marker (get-text-property 0 'org-hd-marker entry))
  3570. (org-blocked-by-checkboxes nil)
  3571. ;; Necessary so that `org-entry-blocked-p' does not change
  3572. ;; the buffer.
  3573. (org-depend-tag-blocked nil))
  3574. (when entry-marker
  3575. (let ((blocked
  3576. (with-current-buffer (marker-buffer entry-marker)
  3577. (save-excursion
  3578. (goto-char entry-marker)
  3579. (org-entry-blocked-p)))))
  3580. (when blocked
  3581. (let ((really-invisible
  3582. (and (not org-blocked-by-checkboxes)
  3583. (eq org-agenda-dim-blocked-tasks 'invisible))))
  3584. (put-text-property
  3585. 0 (length entry) 'org-todo-blocked
  3586. (if really-invisible 'invisible t)
  3587. entry)))))))
  3588. entry)
  3589. (defvar org-agenda-skip-function nil
  3590. "Function to be called at each match during agenda construction.
  3591. If this function returns nil, the current match should not be skipped.
  3592. Otherwise, the function must return a position from where the search
  3593. should be continued.
  3594. This may also be a Lisp form, it will be evaluated.
  3595. Never set this variable using `setq' or so, because then it will apply
  3596. to all future agenda commands. If you do want a global skipping condition,
  3597. use the option `org-agenda-skip-function-global' instead.
  3598. The correct usage for `org-agenda-skip-function' is to bind it with
  3599. `let' to scope it dynamically into the agenda-constructing command.
  3600. A good way to set it is through options in `org-agenda-custom-commands'.")
  3601. (defun org-agenda-skip ()
  3602. "Throw to `:skip' in places that should be skipped.
  3603. Also moves point to the end of the skipped region, so that search can
  3604. continue from there."
  3605. (let ((p (point-at-bol)) to)
  3606. (when (or
  3607. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3608. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3609. (get-text-property p :org-archived)
  3610. (org-end-of-subtree t))
  3611. (and org-agenda-skip-comment-trees
  3612. (get-text-property p :org-comment)
  3613. (org-end-of-subtree t))
  3614. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3615. (org-agenda-skip-eval org-agenda-skip-function)))
  3616. (goto-char to))
  3617. (org-in-src-block-p t))
  3618. (throw :skip t))))
  3619. (defun org-agenda-skip-eval (form)
  3620. "If FORM is a function or a list, call (or eval) it and return the result.
  3621. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3622. and match data are returned to the previous state no matter what these
  3623. functions do."
  3624. (let (fp)
  3625. (and form
  3626. (or (setq fp (functionp form))
  3627. (consp form))
  3628. (save-excursion
  3629. (save-match-data
  3630. (if fp
  3631. (funcall form)
  3632. (eval form)))))))
  3633. (defvar org-agenda-markers nil
  3634. "List of all currently active markers created by `org-agenda'.")
  3635. (defvar org-agenda-last-marker-time (float-time)
  3636. "Creation time of the last agenda marker.")
  3637. (defun org-agenda-new-marker (&optional pos)
  3638. "Return a new agenda marker.
  3639. Maker is at point, or at POS if non-nil. Org mode keeps a list of
  3640. these markers and resets them when they are no longer in use."
  3641. (let ((m (copy-marker (or pos (point)) t)))
  3642. (setq org-agenda-last-marker-time (float-time))
  3643. (if org-agenda-buffer
  3644. (with-current-buffer org-agenda-buffer
  3645. (push m org-agenda-markers))
  3646. (push m org-agenda-markers))
  3647. m))
  3648. (defun org-agenda-reset-markers ()
  3649. "Reset markers created by `org-agenda'."
  3650. (while org-agenda-markers
  3651. (move-marker (pop org-agenda-markers) nil)))
  3652. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3653. "Save relative positions of markers in region.
  3654. This check for agenda markers in all agenda buffers currently active."
  3655. (dolist (buf (buffer-list))
  3656. (with-current-buffer buf
  3657. (when (eq major-mode 'org-agenda-mode)
  3658. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3659. org-agenda-markers)))))
  3660. ;;; Entry text mode
  3661. (defun org-agenda-entry-text-show-here ()
  3662. "Add some text from the entry as context to the current line."
  3663. (let (m txt o)
  3664. (setq m (org-get-at-bol 'org-hd-marker))
  3665. (unless (marker-buffer m)
  3666. (error "No marker points to an entry here"))
  3667. (setq txt (concat "\n" (org-no-properties
  3668. (org-agenda-get-some-entry-text
  3669. m org-agenda-entry-text-maxlines
  3670. org-agenda-entry-text-leaders))))
  3671. (when (string-match "\\S-" txt)
  3672. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3673. (overlay-put o 'evaporate t)
  3674. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3675. (overlay-put o 'after-string txt))))
  3676. (defun org-agenda-entry-text-show ()
  3677. "Add entry context for all agenda lines."
  3678. (interactive)
  3679. (save-excursion
  3680. (goto-char (point-max))
  3681. (beginning-of-line 1)
  3682. (while (not (bobp))
  3683. (when (org-get-at-bol 'org-hd-marker)
  3684. (org-agenda-entry-text-show-here))
  3685. (beginning-of-line 0))))
  3686. (defun org-agenda-entry-text-hide ()
  3687. "Remove any shown entry context."
  3688. (delq nil
  3689. (mapcar (lambda (o)
  3690. (if (eq (overlay-get o 'org-overlay-type)
  3691. 'agenda-entry-content)
  3692. (progn (delete-overlay o) t)))
  3693. (overlays-in (point-min) (point-max)))))
  3694. (defun org-agenda-get-day-face (date)
  3695. "Return the face DATE should be displayed with."
  3696. (cond ((and (functionp org-agenda-day-face-function)
  3697. (funcall org-agenda-day-face-function date)))
  3698. ((org-agenda-today-p date) 'org-agenda-date-today)
  3699. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3700. 'org-agenda-date-weekend)
  3701. (t 'org-agenda-date)))
  3702. (defvar org-agenda-show-log-scoped)
  3703. ;;; Agenda Daily/Weekly
  3704. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3705. "Start day for the agenda view.
  3706. Custom commands can set this variable in the options section.
  3707. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3708. input allowed when reading a date through the Org calendar.
  3709. See the docstring of `org-read-date' for details.")
  3710. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3711. (defvar org-arg-loc nil) ; local variable
  3712. (defvar org-agenda-buffer-tmp-name nil)
  3713. ;;;###autoload
  3714. (defun org-agenda-list (&optional arg start-day span with-hour)
  3715. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3716. The view will be for the current day or week, but from the overview buffer
  3717. you will be able to go to other days/weeks.
  3718. With a numeric prefix argument in an interactive call, the agenda will
  3719. span ARG days. Lisp programs should instead specify SPAN to change
  3720. the number of days. SPAN defaults to `org-agenda-span'.
  3721. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3722. given in `org-agenda-start-on-weekday'.
  3723. When WITH-HOUR is non-nil, only include scheduled and deadline
  3724. items if they have an hour specification like [h]h:mm."
  3725. (interactive "P")
  3726. (if org-agenda-overriding-arguments
  3727. (setq arg (car org-agenda-overriding-arguments)
  3728. start-day (nth 1 org-agenda-overriding-arguments)
  3729. span (nth 2 org-agenda-overriding-arguments)))
  3730. (if (and (integerp arg) (> arg 0))
  3731. (setq span arg arg nil))
  3732. (catch 'exit
  3733. (setq org-agenda-buffer-name
  3734. (or org-agenda-buffer-tmp-name
  3735. (and org-agenda-doing-sticky-redo org-agenda-buffer-name)
  3736. (if org-agenda-sticky
  3737. (cond ((and org-keys (stringp org-match))
  3738. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3739. (org-keys
  3740. (format "*Org Agenda(%s)*" org-keys))
  3741. (t "*Org Agenda(a)*")))
  3742. "*Org Agenda*"))
  3743. (org-agenda-prepare "Day/Week")
  3744. (setq start-day (or start-day org-agenda-start-day))
  3745. (if (stringp start-day)
  3746. ;; Convert to an absolute day number
  3747. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3748. (org-compile-prefix-format 'agenda)
  3749. (org-set-sorting-strategy 'agenda)
  3750. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
  3751. (today (org-today))
  3752. (sd (or start-day today))
  3753. (ndays (org-agenda-span-to-ndays span sd))
  3754. (org-agenda-start-on-weekday
  3755. (if (or (eq ndays 7) (eq ndays 14))
  3756. org-agenda-start-on-weekday))
  3757. (thefiles (org-agenda-files nil 'ifmode))
  3758. (files thefiles)
  3759. (start (if (or (null org-agenda-start-on-weekday)
  3760. (< ndays 7))
  3761. sd
  3762. (let* ((nt (calendar-day-of-week
  3763. (calendar-gregorian-from-absolute sd)))
  3764. (n1 org-agenda-start-on-weekday)
  3765. (d (- nt n1)))
  3766. (- sd (+ (if (< d 0) 7 0) d)))))
  3767. (day-numbers (list start))
  3768. (day-cnt 0)
  3769. (inhibit-redisplay (not debug-on-error))
  3770. (org-agenda-show-log-scoped org-agenda-show-log)
  3771. s e rtn rtnall file date d start-pos end-pos todayp
  3772. clocktable-start clocktable-end filter)
  3773. (setq org-agenda-redo-command
  3774. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3775. (dotimes (n (1- ndays))
  3776. (push (1+ (car day-numbers)) day-numbers))
  3777. (setq day-numbers (nreverse day-numbers))
  3778. (setq clocktable-start (car day-numbers)
  3779. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3780. (setq-local org-starting-day (car day-numbers))
  3781. (setq-local org-arg-loc arg)
  3782. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  3783. (unless org-agenda-compact-blocks
  3784. (let* ((d1 (car day-numbers))
  3785. (d2 (org-last day-numbers))
  3786. (w1 (org-days-to-iso-week d1))
  3787. (w2 (org-days-to-iso-week d2)))
  3788. (setq s (point))
  3789. (if org-agenda-overriding-header
  3790. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3791. nil 'face 'org-agenda-structure) "\n")
  3792. (insert (org-agenda-span-name span)
  3793. "-agenda"
  3794. (if (< (- d2 d1) 350)
  3795. (if (= w1 w2)
  3796. (format " (W%02d)" w1)
  3797. (format " (W%02d-W%02d)" w1 w2))
  3798. "")
  3799. ":\n")))
  3800. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3801. 'org-date-line t))
  3802. (org-agenda-mark-header-line s))
  3803. (while (setq d (pop day-numbers))
  3804. (setq date (calendar-gregorian-from-absolute d)
  3805. s (point))
  3806. (if (or (setq todayp (= d today))
  3807. (and (not start-pos) (= d sd)))
  3808. (setq start-pos (point))
  3809. (if (and start-pos (not end-pos))
  3810. (setq end-pos (point))))
  3811. (setq files thefiles
  3812. rtnall nil)
  3813. (while (setq file (pop files))
  3814. (catch 'nextfile
  3815. (org-check-agenda-file file)
  3816. (let ((org-agenda-entry-types org-agenda-entry-types))
  3817. ;; Starred types override non-starred equivalents
  3818. (when (member :deadline* org-agenda-entry-types)
  3819. (setq org-agenda-entry-types
  3820. (delq :deadline org-agenda-entry-types)))
  3821. (when (member :scheduled* org-agenda-entry-types)
  3822. (setq org-agenda-entry-types
  3823. (delq :scheduled org-agenda-entry-types)))
  3824. ;; Honor with-hour
  3825. (when with-hour
  3826. (when (member :deadline org-agenda-entry-types)
  3827. (setq org-agenda-entry-types
  3828. (delq :deadline org-agenda-entry-types))
  3829. (push :deadline* org-agenda-entry-types))
  3830. (when (member :scheduled org-agenda-entry-types)
  3831. (setq org-agenda-entry-types
  3832. (delq :scheduled org-agenda-entry-types))
  3833. (push :scheduled* org-agenda-entry-types)))
  3834. (unless org-agenda-include-deadlines
  3835. (setq org-agenda-entry-types
  3836. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  3837. (cond
  3838. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3839. (setq rtn (org-agenda-get-day-entries
  3840. file date :closed)))
  3841. (org-agenda-show-log-scoped
  3842. (setq rtn (apply 'org-agenda-get-day-entries
  3843. file date
  3844. (append '(:closed) org-agenda-entry-types))))
  3845. (t
  3846. (setq rtn (apply 'org-agenda-get-day-entries
  3847. file date
  3848. org-agenda-entry-types)))))
  3849. (setq rtnall (append rtnall rtn)))) ;; all entries
  3850. (if org-agenda-include-diary
  3851. (let ((org-agenda-search-headline-for-time t))
  3852. (require 'diary-lib)
  3853. (setq rtn (org-get-entries-from-diary date))
  3854. (setq rtnall (append rtnall rtn))))
  3855. (if (or rtnall org-agenda-show-all-dates)
  3856. (progn
  3857. (setq day-cnt (1+ day-cnt))
  3858. (insert
  3859. (if (stringp org-agenda-format-date)
  3860. (format-time-string org-agenda-format-date
  3861. (org-time-from-absolute date))
  3862. (funcall org-agenda-format-date date))
  3863. "\n")
  3864. (put-text-property s (1- (point)) 'face
  3865. (org-agenda-get-day-face date))
  3866. (put-text-property s (1- (point)) 'org-date-line t)
  3867. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3868. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3869. (when todayp
  3870. (put-text-property s (1- (point)) 'org-today t))
  3871. (setq rtnall
  3872. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3873. (if rtnall (insert ;; all entries
  3874. (org-agenda-finalize-entries rtnall 'agenda)
  3875. "\n"))
  3876. (put-text-property s (1- (point)) 'day d)
  3877. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3878. (when (and org-agenda-clockreport-mode clocktable-start)
  3879. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3880. ;; the above line is to ensure the restricted range!
  3881. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3882. tbl)
  3883. (setq p (org-plist-delete p :block))
  3884. (setq p (plist-put p :tstart clocktable-start))
  3885. (setq p (plist-put p :tend clocktable-end))
  3886. (setq p (plist-put p :scope 'agenda))
  3887. (setq tbl (apply 'org-clock-get-clocktable p))
  3888. (insert tbl)))
  3889. (goto-char (point-min))
  3890. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3891. (unless (and (pos-visible-in-window-p (point-min))
  3892. (pos-visible-in-window-p (point-max)))
  3893. (goto-char (1- (point-max)))
  3894. (recenter -1)
  3895. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3896. (progn
  3897. (goto-char (or start-pos 1))
  3898. (recenter 1))))
  3899. (goto-char (or start-pos 1))
  3900. (add-text-properties (point-min) (point-max)
  3901. `(org-agenda-type agenda
  3902. org-last-args (,arg ,start-day ,span)
  3903. org-redo-cmd ,org-agenda-redo-command
  3904. org-series-cmd ,org-cmd))
  3905. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3906. (org-agenda-show-clocking-issues))
  3907. (org-agenda-finalize)
  3908. (setq buffer-read-only t)
  3909. (message ""))))
  3910. (defun org-agenda-ndays-to-span (n)
  3911. "Return a span symbol for a span of N days, or N if none matches."
  3912. (cond ((symbolp n) n)
  3913. ((= n 1) 'day)
  3914. ((= n 7) 'week)
  3915. ((= n 14) 'fortnight)
  3916. (t n)))
  3917. (defun org-agenda-span-to-ndays (span &optional start-day)
  3918. "Return ndays from SPAN, possibly starting at START-DAY.
  3919. START-DAY is an absolute time value."
  3920. (cond ((numberp span) span)
  3921. ((eq span 'day) 1)
  3922. ((eq span 'week) 7)
  3923. ((eq span 'fortnight) 14)
  3924. ((eq span 'month)
  3925. (let ((date (calendar-gregorian-from-absolute start-day)))
  3926. (calendar-last-day-of-month (car date) (cl-caddr date))))
  3927. ((eq span 'year)
  3928. (let ((date (calendar-gregorian-from-absolute start-day)))
  3929. (if (calendar-leap-year-p (cl-caddr date)) 366 365)))))
  3930. (defun org-agenda-span-name (span)
  3931. "Return a SPAN name."
  3932. (if (null span)
  3933. ""
  3934. (if (symbolp span)
  3935. (capitalize (symbol-name span))
  3936. (format "%d days" span))))
  3937. ;;; Agenda word search
  3938. (defvar org-agenda-search-history nil)
  3939. (defvar org-search-syntax-table nil
  3940. "Special syntax table for Org search.
  3941. In this table, we have single quotes not as word constituents, to
  3942. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3943. (defvar org-mode-syntax-table) ; From org.el
  3944. (defun org-search-syntax-table ()
  3945. (unless org-search-syntax-table
  3946. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3947. (modify-syntax-entry ?' "." org-search-syntax-table)
  3948. (modify-syntax-entry ?` "." org-search-syntax-table))
  3949. org-search-syntax-table)
  3950. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3951. ;;;###autoload
  3952. (defun org-search-view (&optional todo-only string edit-at)
  3953. "Show all entries that contain a phrase or words or regular expressions.
  3954. With optional prefix argument TODO-ONLY, only consider entries that are
  3955. TODO entries. The argument STRING can be used to pass a default search
  3956. string into this function. If EDIT-AT is non-nil, it means that the
  3957. user should get a chance to edit this string, with cursor at position
  3958. EDIT-AT.
  3959. The search string can be viewed either as a phrase that should be found as
  3960. is, or it can be broken into a number of snippets, each of which must match
  3961. in a Boolean way to select an entry. The default depends on the variable
  3962. `org-agenda-search-view-always-boolean'.
  3963. Even if this is turned off (the default) you can always switch to
  3964. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3965. The default is a direct search of the whole phrase, where each space in
  3966. the search string can expand to an arbitrary amount of whitespace,
  3967. including newlines.
  3968. If using a Boolean search, the search string is split on whitespace and
  3969. each snippet is searched separately, with logical AND to select an entry.
  3970. Words prefixed with a minus must *not* occur in the entry. Words without
  3971. a prefix or prefixed with a plus must occur in the entry. Matching is
  3972. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3973. match whole words, not parts of a word) if
  3974. `org-agenda-search-view-force-full-words' is set (default is nil).
  3975. Boolean search snippets enclosed by curly braces are interpreted as
  3976. regular expressions that must or (when preceded with \"-\") must not
  3977. match in the entry. Snippets enclosed into double quotes will be taken
  3978. as a whole, to include whitespace.
  3979. - If the search string starts with an asterisk, search only in headlines.
  3980. - If (possibly after the leading star) the search string starts with an
  3981. exclamation mark, this also means to look at TODO entries only, an effect
  3982. that can also be achieved with a prefix argument.
  3983. - If (possibly after star and exclamation mark) the search string starts
  3984. with a colon, this will mean that the (non-regexp) snippets of the
  3985. Boolean search must match as full words.
  3986. This command searches the agenda files, and in addition the files listed
  3987. in `org-agenda-text-search-extra-files'."
  3988. (interactive "P")
  3989. (if org-agenda-overriding-arguments
  3990. (setq todo-only (car org-agenda-overriding-arguments)
  3991. string (nth 1 org-agenda-overriding-arguments)
  3992. edit-at (nth 2 org-agenda-overriding-arguments)))
  3993. (let* ((props (list 'face nil
  3994. 'done-face 'org-agenda-done
  3995. 'org-not-done-regexp org-not-done-regexp
  3996. 'org-todo-regexp org-todo-regexp
  3997. 'org-complex-heading-regexp org-complex-heading-regexp
  3998. 'mouse-face 'highlight
  3999. 'help-echo (format "mouse-2 or RET jump to location")))
  4000. (full-words org-agenda-search-view-force-full-words)
  4001. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4002. regexp rtn rtnall files file pos inherited-tags
  4003. marker category level tags c neg re boolean
  4004. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4005. (unless (and (not edit-at)
  4006. (stringp string)
  4007. (string-match "\\S-" string))
  4008. (setq string (read-string
  4009. (if org-agenda-search-view-always-boolean
  4010. "[+-]Word/{Regexp} ...: "
  4011. "Phrase or [+-]Word/{Regexp} ...: ")
  4012. (cond
  4013. ((integerp edit-at) (cons string edit-at))
  4014. (edit-at string))
  4015. 'org-agenda-search-history)))
  4016. (catch 'exit
  4017. (if org-agenda-sticky
  4018. (setq org-agenda-buffer-name
  4019. (if (stringp string)
  4020. (format "*Org Agenda(%s:%s)*"
  4021. (or org-keys (or (and todo-only "S") "s")) string)
  4022. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  4023. (org-agenda-prepare "SEARCH")
  4024. (org-compile-prefix-format 'search)
  4025. (org-set-sorting-strategy 'search)
  4026. (setq org-agenda-redo-command
  4027. (list 'org-search-view (if todo-only t nil)
  4028. (list 'if 'current-prefix-arg nil string)))
  4029. (setq org-agenda-query-string string)
  4030. (if (equal (string-to-char string) ?*)
  4031. (setq hdl-only t
  4032. words (substring string 1))
  4033. (setq words string))
  4034. (when (equal (string-to-char words) ?!)
  4035. (setq todo-only t
  4036. words (substring words 1)))
  4037. (when (equal (string-to-char words) ?:)
  4038. (setq full-words t
  4039. words (substring words 1)))
  4040. (if (or org-agenda-search-view-always-boolean
  4041. (member (string-to-char words) '(?- ?+ ?\{)))
  4042. (setq boolean t))
  4043. (setq words (org-split-string words))
  4044. (let (www w)
  4045. (while (setq w (pop words))
  4046. (while (and (string-match "\\\\\\'" w) words)
  4047. (setq w (concat (substring w 0 -1) " " (pop words))))
  4048. (push w www))
  4049. (setq words (nreverse www) www nil)
  4050. (while (setq w (pop words))
  4051. (when (and (string-match "\\`[-+]?{" w)
  4052. (not (string-match "}\\'" w)))
  4053. (while (and words (not (string-match "}\\'" (car words))))
  4054. (setq w (concat w " " (pop words))))
  4055. (setq w (concat w " " (pop words))))
  4056. (push w www))
  4057. (setq words (nreverse www)))
  4058. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4059. (when boolean
  4060. (let (wds w)
  4061. (while (setq w (pop words))
  4062. (if (or (equal (substring w 0 1) "\"")
  4063. (and (> (length w) 1)
  4064. (member (substring w 0 1) '("+" "-"))
  4065. (equal (substring w 1 2) "\"")))
  4066. (while (and words (not (equal (substring w -1) "\"")))
  4067. (setq w (concat w " " (pop words)))))
  4068. (and (string-match "\\`\\([-+]?\\)\"" w)
  4069. (setq w (replace-match "\\1" nil nil w)))
  4070. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4071. (push w wds))
  4072. (setq words (nreverse wds))))
  4073. (if boolean
  4074. (mapc (lambda (w)
  4075. (setq c (string-to-char w))
  4076. (if (equal c ?-)
  4077. (setq neg t w (substring w 1))
  4078. (if (equal c ?+)
  4079. (setq neg nil w (substring w 1))
  4080. (setq neg nil)))
  4081. (if (string-match "\\`{.*}\\'" w)
  4082. (setq re (substring w 1 -1))
  4083. (if full-words
  4084. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4085. (setq re (regexp-quote (downcase w)))))
  4086. (if neg (push re regexps-) (push re regexps+)))
  4087. words)
  4088. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4089. regexps+))
  4090. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4091. (if (not regexps+)
  4092. (setq regexp org-outline-regexp-bol)
  4093. (setq regexp (pop regexps+))
  4094. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4095. regexp))))
  4096. (setq files (org-agenda-files nil 'ifmode))
  4097. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4098. (pop org-agenda-text-search-extra-files)
  4099. (setq files (org-add-archive-files files)))
  4100. (setq files (append files org-agenda-text-search-extra-files)
  4101. rtnall nil)
  4102. (while (setq file (pop files))
  4103. (setq ee nil)
  4104. (catch 'nextfile
  4105. (org-check-agenda-file file)
  4106. (setq buffer (if (file-exists-p file)
  4107. (org-get-agenda-file-buffer file)
  4108. (error "No such file %s" file)))
  4109. (if (not buffer)
  4110. ;; If file does not exist, make sure an error message is sent
  4111. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4112. file))))
  4113. (with-current-buffer buffer
  4114. (with-syntax-table (org-search-syntax-table)
  4115. (unless (derived-mode-p 'org-mode)
  4116. (error "Agenda file %s is not in `org-mode'" file))
  4117. (let ((case-fold-search t))
  4118. (save-excursion
  4119. (save-restriction
  4120. (if (eq buffer org-agenda-restrict)
  4121. (narrow-to-region org-agenda-restrict-begin
  4122. org-agenda-restrict-end)
  4123. (widen))
  4124. (goto-char (point-min))
  4125. (unless (or (org-at-heading-p)
  4126. (outline-next-heading))
  4127. (throw 'nextfile t))
  4128. (goto-char (max (point-min) (1- (point))))
  4129. (while (re-search-forward regexp nil t)
  4130. (org-back-to-heading t)
  4131. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4132. (> (org-reduced-level (org-outline-level))
  4133. org-agenda-search-view-max-outline-level)
  4134. (forward-line -1)
  4135. (org-back-to-heading t)))
  4136. (skip-chars-forward "* ")
  4137. (setq beg (point-at-bol)
  4138. beg1 (point)
  4139. end (progn
  4140. (outline-next-heading)
  4141. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4142. (> (org-reduced-level (org-outline-level))
  4143. org-agenda-search-view-max-outline-level)
  4144. (forward-line 1)
  4145. (outline-next-heading)))
  4146. (point)))
  4147. (catch :skip
  4148. (goto-char beg)
  4149. (org-agenda-skip)
  4150. (setq str (buffer-substring-no-properties
  4151. (point-at-bol)
  4152. (if hdl-only (point-at-eol) end)))
  4153. (mapc (lambda (wr) (when (string-match wr str)
  4154. (goto-char (1- end))
  4155. (throw :skip t)))
  4156. regexps-)
  4157. (mapc (lambda (wr) (unless (string-match wr str)
  4158. (goto-char (1- end))
  4159. (throw :skip t)))
  4160. (if todo-only
  4161. (cons (concat "^\\*+[ \t]+"
  4162. org-not-done-regexp)
  4163. regexps+)
  4164. regexps+))
  4165. (goto-char beg)
  4166. (setq marker (org-agenda-new-marker (point))
  4167. category (org-get-category)
  4168. level (make-string (org-reduced-level (org-outline-level)) ? )
  4169. inherited-tags
  4170. (or (eq org-agenda-show-inherited-tags 'always)
  4171. (and (listp org-agenda-show-inherited-tags)
  4172. (memq 'todo org-agenda-show-inherited-tags))
  4173. (and (eq org-agenda-show-inherited-tags t)
  4174. (or (eq org-agenda-use-tag-inheritance t)
  4175. (memq 'todo org-agenda-use-tag-inheritance))))
  4176. tags (org-get-tags-at nil (not inherited-tags))
  4177. txt (org-agenda-format-item
  4178. ""
  4179. (buffer-substring-no-properties
  4180. beg1 (point-at-eol))
  4181. level category tags t))
  4182. (org-add-props txt props
  4183. 'org-marker marker 'org-hd-marker marker
  4184. 'org-todo-regexp org-todo-regexp
  4185. 'level level
  4186. 'org-complex-heading-regexp org-complex-heading-regexp
  4187. 'priority 1000
  4188. 'type "search")
  4189. (push txt ee)
  4190. (goto-char (1- end))))))))))
  4191. (setq rtn (nreverse ee))
  4192. (setq rtnall (append rtnall rtn)))
  4193. (if org-agenda-overriding-header
  4194. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4195. nil 'face 'org-agenda-structure) "\n")
  4196. (insert "Search words: ")
  4197. (add-text-properties (point-min) (1- (point))
  4198. (list 'face 'org-agenda-structure))
  4199. (setq pos (point))
  4200. (insert string "\n")
  4201. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4202. (setq pos (point))
  4203. (unless org-agenda-multi
  4204. (insert (substitute-command-keys "\
  4205. Press `\\[org-agenda-manipulate-query-add]', \
  4206. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4207. `\\[org-agenda-manipulate-query-add-re]', \
  4208. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4209. `\\[universal-argument] \\[org-agenda-redo]' to edit\n"))
  4210. (add-text-properties pos (1- (point))
  4211. (list 'face 'org-agenda-structure))))
  4212. (org-agenda-mark-header-line (point-min))
  4213. (when rtnall
  4214. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4215. (goto-char (point-min))
  4216. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4217. (add-text-properties (point-min) (point-max)
  4218. `(org-agenda-type search
  4219. org-last-args (,todo-only ,string ,edit-at)
  4220. org-redo-cmd ,org-agenda-redo-command
  4221. org-series-cmd ,org-cmd))
  4222. (org-agenda-finalize)
  4223. (setq buffer-read-only t))))
  4224. ;;; Agenda TODO list
  4225. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4226. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4227. (concat
  4228. (if (or (equal keywords "ALL") (not keywords))
  4229. (propertize "ALL" 'face 'warning)
  4230. (mapconcat
  4231. (lambda (kw)
  4232. (propertize kw 'face (org-get-todo-face kw)))
  4233. (org-split-string keywords "|")
  4234. "|"))
  4235. "\n"))
  4236. (defvar org-select-this-todo-keyword nil)
  4237. (defvar org-last-arg nil)
  4238. ;;;###autoload
  4239. (defun org-todo-list (&optional arg)
  4240. "Show all (not done) TODO entries from all agenda file in a single list.
  4241. The prefix arg can be used to select a specific TODO keyword and limit
  4242. the list to these. When using `\\[universal-argument]', you will be prompted
  4243. for a keyword. A numeric prefix directly selects the Nth keyword in
  4244. `org-todo-keywords-1'."
  4245. (interactive "P")
  4246. (if org-agenda-overriding-arguments
  4247. (setq arg org-agenda-overriding-arguments))
  4248. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4249. (let* ((today (org-today))
  4250. (date (calendar-gregorian-from-absolute today))
  4251. (kwds org-todo-keywords-for-agenda)
  4252. (completion-ignore-case t)
  4253. (org-select-this-todo-keyword
  4254. (if (stringp arg) arg
  4255. (and arg (integerp arg) (> arg 0)
  4256. (nth (1- arg) kwds))))
  4257. rtn rtnall files file pos)
  4258. (when (equal arg '(4))
  4259. (setq org-select-this-todo-keyword
  4260. (completing-read "Keyword (or KWD1|K2D2|...): "
  4261. (mapcar #'list kwds) nil nil)))
  4262. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4263. (catch 'exit
  4264. (if org-agenda-sticky
  4265. (setq org-agenda-buffer-name
  4266. (if (stringp org-select-this-todo-keyword)
  4267. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4268. org-select-this-todo-keyword)
  4269. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4270. (org-agenda-prepare "TODO")
  4271. (org-compile-prefix-format 'todo)
  4272. (org-set-sorting-strategy 'todo)
  4273. (setq org-agenda-redo-command
  4274. `(org-todo-list (or (and (numberp current-prefix-arg)
  4275. current-prefix-arg)
  4276. ,org-select-this-todo-keyword
  4277. current-prefix-arg ,arg)))
  4278. (setq files (org-agenda-files nil 'ifmode)
  4279. rtnall nil)
  4280. (while (setq file (pop files))
  4281. (catch 'nextfile
  4282. (org-check-agenda-file file)
  4283. (setq rtn (org-agenda-get-day-entries file date :todo))
  4284. (setq rtnall (append rtnall rtn))))
  4285. (if org-agenda-overriding-header
  4286. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4287. nil 'face 'org-agenda-structure) "\n")
  4288. (insert "Global list of TODO items of type: ")
  4289. (add-text-properties (point-min) (1- (point))
  4290. (list 'face 'org-agenda-structure
  4291. 'short-heading
  4292. (concat "ToDo: "
  4293. (or org-select-this-todo-keyword "ALL"))))
  4294. (org-agenda-mark-header-line (point-min))
  4295. (insert (org-agenda-propertize-selected-todo-keywords
  4296. org-select-this-todo-keyword))
  4297. (setq pos (point))
  4298. (unless org-agenda-multi
  4299. (insert (substitute-command-keys "Available with \
  4300. `N \\[org-agenda-redo]': (0)[ALL]"))
  4301. (let ((n 0) s)
  4302. (mapc (lambda (x)
  4303. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4304. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4305. (insert "\n "))
  4306. (insert " " s))
  4307. kwds))
  4308. (insert "\n"))
  4309. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4310. (org-agenda-mark-header-line (point-min))
  4311. (when rtnall
  4312. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4313. (goto-char (point-min))
  4314. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4315. (add-text-properties (point-min) (point-max)
  4316. `(org-agenda-type todo
  4317. org-last-args ,arg
  4318. org-redo-cmd ,org-agenda-redo-command
  4319. org-series-cmd ,org-cmd))
  4320. (org-agenda-finalize)
  4321. (setq buffer-read-only t))))
  4322. ;;; Agenda tags match
  4323. ;;;###autoload
  4324. (defun org-tags-view (&optional todo-only match)
  4325. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4326. The prefix arg TODO-ONLY limits the search to TODO entries."
  4327. (interactive "P")
  4328. (if org-agenda-overriding-arguments
  4329. (setq todo-only (car org-agenda-overriding-arguments)
  4330. match (nth 1 org-agenda-overriding-arguments)))
  4331. (let* ((org-tags-match-list-sublevels
  4332. org-tags-match-list-sublevels)
  4333. (completion-ignore-case t)
  4334. (org--matcher-tags-todo-only todo-only)
  4335. rtn rtnall files file pos matcher
  4336. buffer)
  4337. (when (and (stringp match) (not (string-match "\\S-" match)))
  4338. (setq match nil))
  4339. (catch 'exit
  4340. (if org-agenda-sticky
  4341. (setq org-agenda-buffer-name
  4342. (if (stringp match)
  4343. (format "*Org Agenda(%s:%s)*"
  4344. (or org-keys (or (and todo-only "M") "m")) match)
  4345. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4346. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4347. ;; expanding tags within `org-make-tags-matcher'
  4348. (org-agenda-prepare (concat "TAGS " match))
  4349. (setq matcher (org-make-tags-matcher match)
  4350. match (car matcher)
  4351. matcher (cdr matcher))
  4352. (org-compile-prefix-format 'tags)
  4353. (org-set-sorting-strategy 'tags)
  4354. (setq org-agenda-query-string match)
  4355. (setq org-agenda-redo-command
  4356. (list 'org-tags-view
  4357. `(quote ,org--matcher-tags-todo-only)
  4358. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4359. (setq files (org-agenda-files nil 'ifmode)
  4360. rtnall nil)
  4361. (while (setq file (pop files))
  4362. (catch 'nextfile
  4363. (org-check-agenda-file file)
  4364. (setq buffer (if (file-exists-p file)
  4365. (org-get-agenda-file-buffer file)
  4366. (error "No such file %s" file)))
  4367. (if (not buffer)
  4368. ;; If file does not exist, error message to agenda
  4369. (setq rtn (list
  4370. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4371. rtnall (append rtnall rtn))
  4372. (with-current-buffer buffer
  4373. (unless (derived-mode-p 'org-mode)
  4374. (error "Agenda file %s is not in `org-mode'" file))
  4375. (save-excursion
  4376. (save-restriction
  4377. (if (eq buffer org-agenda-restrict)
  4378. (narrow-to-region org-agenda-restrict-begin
  4379. org-agenda-restrict-end)
  4380. (widen))
  4381. (setq rtn (org-scan-tags 'agenda
  4382. matcher
  4383. org--matcher-tags-todo-only))
  4384. (setq rtnall (append rtnall rtn))))))))
  4385. (if org-agenda-overriding-header
  4386. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4387. nil 'face 'org-agenda-structure) "\n")
  4388. (insert "Headlines with TAGS match: ")
  4389. (add-text-properties (point-min) (1- (point))
  4390. (list 'face 'org-agenda-structure
  4391. 'short-heading
  4392. (concat "Match: " match)))
  4393. (setq pos (point))
  4394. (insert match "\n")
  4395. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4396. (setq pos (point))
  4397. (unless org-agenda-multi
  4398. (insert (substitute-command-keys
  4399. "Press `\\[universal-argument] \\[org-agenda-redo]' \
  4400. to search again with new search string\n")))
  4401. (add-text-properties pos (1- (point))
  4402. (list 'face 'org-agenda-structure)))
  4403. (org-agenda-mark-header-line (point-min))
  4404. (when rtnall
  4405. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4406. (goto-char (point-min))
  4407. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4408. (add-text-properties
  4409. (point-min) (point-max)
  4410. `(org-agenda-type tags
  4411. org-last-args (,org--matcher-tags-todo-only ,match)
  4412. org-redo-cmd ,org-agenda-redo-command
  4413. org-series-cmd ,org-cmd))
  4414. (org-agenda-finalize)
  4415. (setq buffer-read-only t))))
  4416. ;;; Agenda Finding stuck projects
  4417. (defvar org-agenda-skip-regexp nil
  4418. "Regular expression used in skipping subtrees for the agenda.
  4419. This is basically a temporary global variable that can be set and then
  4420. used by user-defined selections using `org-agenda-skip-function'.")
  4421. (defvar org-agenda-overriding-header nil
  4422. "When set during agenda, todo and tags searches it replaces the header.
  4423. This variable should not be set directly, but custom commands can bind it
  4424. in the options section.")
  4425. (defun org-agenda-skip-entry-if (&rest conditions)
  4426. "Skip entry if any of CONDITIONS is true.
  4427. See `org-agenda-skip-if' for details."
  4428. (org-agenda-skip-if nil conditions))
  4429. (defun org-agenda-skip-subtree-if (&rest conditions)
  4430. "Skip subtree if any of CONDITIONS is true.
  4431. See `org-agenda-skip-if' for details."
  4432. (org-agenda-skip-if t conditions))
  4433. (defun org-agenda-skip-if (subtree conditions)
  4434. "Checks current entity for CONDITIONS.
  4435. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4436. the entry (i.e. the text before the next heading) is checked.
  4437. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4438. from different tests. Valid conditions are:
  4439. scheduled Check if there is a scheduled cookie
  4440. notscheduled Check if there is no scheduled cookie
  4441. deadline Check if there is a deadline
  4442. notdeadline Check if there is no deadline
  4443. timestamp Check if there is a timestamp (also deadline or scheduled)
  4444. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4445. regexp Check if regexp matches
  4446. notregexp Check if regexp does not match.
  4447. todo Check if TODO keyword matches
  4448. nottodo Check if TODO keyword does not match
  4449. The regexp is taken from the conditions list, it must come right after
  4450. the `regexp' or `notregexp' element.
  4451. `todo' and `nottodo' accept as an argument a list of todo
  4452. keywords, which may include \"*\" to match any todo keyword.
  4453. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4454. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4455. Instead of a list, a keyword class may be given. For example:
  4456. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4457. would skip entries that haven't been marked with any of \"DONE\"
  4458. keywords. Possible classes are: `todo', `done', `any'.
  4459. If any of these conditions is met, this function returns the end point of
  4460. the entity, causing the search to continue from there. This is a function
  4461. that can be put into `org-agenda-skip-function' for the duration of a command."
  4462. (let (beg end m)
  4463. (org-back-to-heading t)
  4464. (setq beg (point)
  4465. end (if subtree
  4466. (progn (org-end-of-subtree t) (point))
  4467. (progn (outline-next-heading) (1- (point)))))
  4468. (goto-char beg)
  4469. (and
  4470. (or
  4471. (and (memq 'scheduled conditions)
  4472. (re-search-forward org-scheduled-time-regexp end t))
  4473. (and (memq 'notscheduled conditions)
  4474. (not (re-search-forward org-scheduled-time-regexp end t)))
  4475. (and (memq 'deadline conditions)
  4476. (re-search-forward org-deadline-time-regexp end t))
  4477. (and (memq 'notdeadline conditions)
  4478. (not (re-search-forward org-deadline-time-regexp end t)))
  4479. (and (memq 'timestamp conditions)
  4480. (re-search-forward org-ts-regexp end t))
  4481. (and (memq 'nottimestamp conditions)
  4482. (not (re-search-forward org-ts-regexp end t)))
  4483. (and (setq m (memq 'regexp conditions))
  4484. (stringp (nth 1 m))
  4485. (re-search-forward (nth 1 m) end t))
  4486. (and (setq m (memq 'notregexp conditions))
  4487. (stringp (nth 1 m))
  4488. (not (re-search-forward (nth 1 m) end t)))
  4489. (and (or
  4490. (setq m (memq 'nottodo conditions))
  4491. (setq m (memq 'todo-unblocked conditions))
  4492. (setq m (memq 'nottodo-unblocked conditions))
  4493. (setq m (memq 'todo conditions)))
  4494. (org-agenda-skip-if-todo m end)))
  4495. end)))
  4496. (defun org-agenda-skip-if-todo (args end)
  4497. "Helper function for `org-agenda-skip-if', do not use it directly.
  4498. ARGS is a list with first element either `todo', `nottodo',
  4499. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4500. a list of TODO keywords, or a state symbol `todo' or `done' or
  4501. `any'."
  4502. (let ((kw (car args))
  4503. (arg (cadr args))
  4504. todo-wds todo-re)
  4505. (setq todo-wds
  4506. (org-uniquify
  4507. (cond
  4508. ((listp arg) ;; list of keywords
  4509. (if (member "*" arg)
  4510. (mapcar 'substring-no-properties org-todo-keywords-1)
  4511. arg))
  4512. ((symbolp arg) ;; keyword class name
  4513. (cond
  4514. ((eq arg 'todo)
  4515. (org-delete-all org-done-keywords
  4516. (mapcar 'substring-no-properties
  4517. org-todo-keywords-1)))
  4518. ((eq arg 'done) org-done-keywords)
  4519. ((eq arg 'any)
  4520. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4521. (setq todo-re
  4522. (concat "^\\*+[ \t]+\\<\\("
  4523. (mapconcat 'identity todo-wds "\\|")
  4524. "\\)\\>"))
  4525. (cond
  4526. ((eq kw 'todo) (re-search-forward todo-re end t))
  4527. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4528. ((eq kw 'todo-unblocked)
  4529. (catch 'unblocked
  4530. (while (re-search-forward todo-re end t)
  4531. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4532. nil))
  4533. ((eq kw 'nottodo-unblocked)
  4534. (catch 'unblocked
  4535. (while (re-search-forward todo-re end t)
  4536. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4537. t))
  4538. )))
  4539. ;;;###autoload
  4540. (defun org-agenda-list-stuck-projects (&rest ignore)
  4541. "Create agenda view for projects that are stuck.
  4542. Stuck projects are project that have no next actions. For the definitions
  4543. of what a project is and how to check if it stuck, customize the variable
  4544. `org-stuck-projects'."
  4545. (interactive)
  4546. (let* ((org-agenda-overriding-header
  4547. (or org-agenda-overriding-header "List of stuck projects: "))
  4548. (matcher (nth 0 org-stuck-projects))
  4549. (todo (nth 1 org-stuck-projects))
  4550. (tags (nth 2 org-stuck-projects))
  4551. (gen-re (org-string-nw-p (nth 3 org-stuck-projects)))
  4552. (todo-wds
  4553. (if (not (member "*" todo)) todo
  4554. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  4555. (org-delete-all org-done-keywords-for-agenda
  4556. (copy-sequence org-todo-keywords-for-agenda))))
  4557. (todo-re (and todo
  4558. (format "^\\*+[ \t]+\\(%s\\)\\>"
  4559. (mapconcat #'identity todo-wds "\\|"))))
  4560. (tags-re (cond ((null tags) nil)
  4561. ((member "*" tags)
  4562. (eval-when-compile
  4563. (concat org-outline-regexp-bol
  4564. ".*:[[:alnum:]_@#%]+:[ \t]*$")))
  4565. (tags (concat org-outline-regexp-bol
  4566. ".*:\\("
  4567. (mapconcat #'identity tags "\\|")
  4568. "\\):[[:alnum:]_@#%:]*[ \t]*$"))
  4569. (t nil)))
  4570. (re-list (delq nil (list todo-re tags-re gen-re)))
  4571. (skip-re
  4572. (if (null re-list)
  4573. (error "Missing information to identify unstuck projects")
  4574. (mapconcat #'identity re-list "\\|")))
  4575. (org-agenda-skip-function
  4576. ;; Skip entry if `org-agenda-skip-regexp' matches anywhere
  4577. ;; in the subtree.
  4578. `(lambda ()
  4579. (and (save-excursion
  4580. (let ((case-fold-search nil))
  4581. (re-search-forward
  4582. ,skip-re (save-excursion (org-end-of-subtree t)) t)))
  4583. (progn (outline-next-heading) (point))))))
  4584. (org-tags-view nil matcher)
  4585. (setq org-agenda-buffer-name (buffer-name))
  4586. (with-current-buffer org-agenda-buffer-name
  4587. (setq org-agenda-redo-command
  4588. `(org-agenda-list-stuck-projects ,current-prefix-arg))
  4589. (let ((inhibit-read-only t))
  4590. (add-text-properties
  4591. (point-min) (point-max)
  4592. `(org-redo-cmd ,org-agenda-redo-command))))))
  4593. ;;; Diary integration
  4594. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4595. (defvar diary-list-entries-hook)
  4596. (defvar diary-time-regexp)
  4597. (defun org-get-entries-from-diary (date)
  4598. "Get the (Emacs Calendar) diary entries for DATE."
  4599. (require 'diary-lib)
  4600. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4601. (diary-display-function 'diary-fancy-display)
  4602. (pop-up-frames nil)
  4603. (diary-list-entries-hook
  4604. (cons 'org-diary-default-entry diary-list-entries-hook))
  4605. (diary-file-name-prefix nil) ; turn this feature off
  4606. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4607. entries
  4608. (org-disable-agenda-to-diary t))
  4609. (save-excursion
  4610. (save-window-excursion
  4611. (funcall (if (fboundp 'diary-list-entries)
  4612. 'diary-list-entries 'list-diary-entries)
  4613. date 1)))
  4614. (if (not (get-buffer diary-fancy-buffer))
  4615. (setq entries nil)
  4616. (with-current-buffer diary-fancy-buffer
  4617. (setq buffer-read-only nil)
  4618. (if (zerop (buffer-size))
  4619. ;; No entries
  4620. (setq entries nil)
  4621. ;; Omit the date and other unnecessary stuff
  4622. (org-agenda-cleanup-fancy-diary)
  4623. ;; Add prefix to each line and extend the text properties
  4624. (if (zerop (buffer-size))
  4625. (setq entries nil)
  4626. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4627. (setq entries
  4628. (with-temp-buffer
  4629. (insert entries) (goto-char (point-min))
  4630. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4631. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4632. (replace-match (concat "; " (match-string 1)))))
  4633. (buffer-string)))))
  4634. (set-buffer-modified-p nil)
  4635. (kill-buffer diary-fancy-buffer)))
  4636. (when entries
  4637. (setq entries (org-split-string entries "\n"))
  4638. (setq entries
  4639. (mapcar
  4640. (lambda (x)
  4641. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4642. ;; Extend the text properties to the beginning of the line
  4643. (org-add-props x (text-properties-at (1- (length x)) x)
  4644. 'type "diary" 'date date 'face 'org-agenda-diary))
  4645. entries)))))
  4646. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4647. "Hook run when the fancy diary buffer is cleaned up.")
  4648. (defun org-agenda-cleanup-fancy-diary ()
  4649. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4650. This gets rid of the date, the underline under the date, and
  4651. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4652. date. It also removes lines that contain only whitespace."
  4653. (goto-char (point-min))
  4654. (if (looking-at ".*?:[ \t]*")
  4655. (progn
  4656. (replace-match "")
  4657. (re-search-forward "\n=+$" nil t)
  4658. (replace-match "")
  4659. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4660. (re-search-forward "\n=+$" nil t)
  4661. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4662. (goto-char (point-min))
  4663. (while (re-search-forward "^ +\n" nil t)
  4664. (replace-match ""))
  4665. (goto-char (point-min))
  4666. (if (re-search-forward "^Org mode dummy\n?" nil t)
  4667. (replace-match ""))
  4668. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4669. ;; Make sure entries from the diary have the right text properties.
  4670. (eval-after-load "diary-lib"
  4671. '(if (boundp 'diary-modify-entry-list-string-function)
  4672. ;; We can rely on the hook, nothing to do
  4673. nil
  4674. ;; Hook not available, must use advice to make this work
  4675. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4676. "Make the position visible."
  4677. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4678. (stringp string)
  4679. buffer-file-name)
  4680. (setq string (org-modify-diary-entry-string string))))))
  4681. (defun org-modify-diary-entry-string (string)
  4682. "Add text properties to string, allowing Org to act on it."
  4683. (org-add-props string nil
  4684. 'mouse-face 'highlight
  4685. 'help-echo (if buffer-file-name
  4686. (format "mouse-2 or RET jump to diary file %s"
  4687. (abbreviate-file-name buffer-file-name))
  4688. "")
  4689. 'org-agenda-diary-link t
  4690. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4691. (defun org-diary-default-entry ()
  4692. "Add a dummy entry to the diary.
  4693. Needed to avoid empty dates which mess up holiday display."
  4694. ;; Catch the error if dealing with the new add-to-diary-alist
  4695. (when org-disable-agenda-to-diary
  4696. (condition-case nil
  4697. (org-add-to-diary-list original-date "Org mode dummy" "")
  4698. (error
  4699. (org-add-to-diary-list original-date "Org mode dummy" "" nil)))))
  4700. (defun org-add-to-diary-list (&rest args)
  4701. (if (fboundp 'diary-add-to-list)
  4702. (apply 'diary-add-to-list args)
  4703. (apply 'add-to-diary-list args)))
  4704. (defvar org-diary-last-run-time nil)
  4705. ;;;###autoload
  4706. (defun org-diary (&rest args)
  4707. "Return diary information from org files.
  4708. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4709. It accesses org files and extracts information from those files to be
  4710. listed in the diary. The function accepts arguments specifying what
  4711. items should be listed. For a list of arguments allowed here, see the
  4712. variable `org-agenda-entry-types'.
  4713. The call in the diary file should look like this:
  4714. &%%(org-diary) ~/path/to/some/orgfile.org
  4715. Use a separate line for each org file to check. Or, if you omit the file name,
  4716. all files listed in `org-agenda-files' will be checked automatically:
  4717. &%%(org-diary)
  4718. If you don't give any arguments (as in the example above), the default value
  4719. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4720. So the example above may also be written as
  4721. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4722. The function expects the lisp variables `entry' and `date' to be provided
  4723. by the caller, because this is how the calendar works. Don't use this
  4724. function from a program - use `org-agenda-get-day-entries' instead."
  4725. (when (> (- (float-time)
  4726. org-agenda-last-marker-time)
  4727. 5)
  4728. ;; I am not sure if this works with sticky agendas, because the marker
  4729. ;; list is then no longer a global variable.
  4730. (org-agenda-reset-markers))
  4731. (org-compile-prefix-format 'agenda)
  4732. (org-set-sorting-strategy 'agenda)
  4733. (setq args (or args org-agenda-entry-types))
  4734. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4735. (list entry)
  4736. (org-agenda-files t)))
  4737. (time (float-time))
  4738. file rtn results)
  4739. (when (or (not org-diary-last-run-time)
  4740. (> (- time
  4741. org-diary-last-run-time)
  4742. 3))
  4743. (org-agenda-prepare-buffers files))
  4744. (setq org-diary-last-run-time time)
  4745. ;; If this is called during org-agenda, don't return any entries to
  4746. ;; the calendar. Org Agenda will list these entries itself.
  4747. (if org-disable-agenda-to-diary (setq files nil))
  4748. (while (setq file (pop files))
  4749. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4750. (setq results (append results rtn)))
  4751. (when results
  4752. (setq results
  4753. (mapcar (lambda (i) (replace-regexp-in-string
  4754. org-bracket-link-regexp "\\3" i)) results))
  4755. (concat (org-agenda-finalize-entries results) "\n"))))
  4756. ;;; Agenda entry finders
  4757. (defun org-agenda--timestamp-to-absolute (&rest args)
  4758. "Call `org-time-string-to-absolute' with ARGS.
  4759. However, throw `:skip' whenever an error is raised."
  4760. (condition-case e
  4761. (apply #'org-time-string-to-absolute args)
  4762. (org-diary-sexp-no-match (throw :skip nil))
  4763. (error
  4764. (message "%s; Skipping entry" (error-message-string e))
  4765. (throw :skip nil))))
  4766. (defun org-agenda-get-day-entries (file date &rest args)
  4767. "Does the work for `org-diary' and `org-agenda'.
  4768. FILE is the path to a file to be checked for entries. DATE is date like
  4769. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4770. which kind of entries should be extracted. For details about these, see
  4771. the documentation of `org-diary'."
  4772. (let* ((org-startup-folded nil)
  4773. (org-startup-align-all-tables nil)
  4774. (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
  4775. (error "No such file %s" file))))
  4776. (if (not buffer)
  4777. ;; If file does not exist, signal it in diary nonetheless.
  4778. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4779. (with-current-buffer buffer
  4780. (unless (derived-mode-p 'org-mode)
  4781. (error "Agenda file %s is not in `org-mode'" file))
  4782. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4783. (setf org-agenda-current-date date)
  4784. (save-excursion
  4785. (save-restriction
  4786. (if (eq buffer org-agenda-restrict)
  4787. (narrow-to-region org-agenda-restrict-begin
  4788. org-agenda-restrict-end)
  4789. (widen))
  4790. ;; Rationalize ARGS. Also make sure `:deadline' comes
  4791. ;; first in order to populate DEADLINES before passing it.
  4792. ;;
  4793. ;; We use `delq' since `org-uniquify' duplicates ARGS,
  4794. ;; guarding us from modifying `org-agenda-entry-types'.
  4795. (setf args (org-uniquify (or args org-agenda-entry-types)))
  4796. (when (and (memq :scheduled args) (memq :scheduled* args))
  4797. (setf args (delq :scheduled* args)))
  4798. (cond
  4799. ((memq :deadline args)
  4800. (setf args (cons :deadline
  4801. (delq :deadline (delq :deadline* args)))))
  4802. ((memq :deadline* args)
  4803. (setf args (cons :deadline* (delq :deadline* args)))))
  4804. ;; Collect list of headlines. Return them flattened.
  4805. (let ((case-fold-search nil) results deadlines)
  4806. (dolist (arg args (apply #'nconc (nreverse results)))
  4807. (pcase arg
  4808. ((and :todo (guard (org-agenda-today-p date)))
  4809. (push (org-agenda-get-todos) results))
  4810. (:timestamp
  4811. (push (org-agenda-get-blocks) results)
  4812. (push (org-agenda-get-timestamps deadlines) results))
  4813. (:sexp
  4814. (push (org-agenda-get-sexps) results))
  4815. (:scheduled
  4816. (push (org-agenda-get-scheduled deadlines) results))
  4817. (:scheduled*
  4818. (push (org-agenda-get-scheduled deadlines t) results))
  4819. (:closed
  4820. (push (org-agenda-get-progress) results))
  4821. (:deadline
  4822. (setf deadlines (org-agenda-get-deadlines))
  4823. (push deadlines results))
  4824. (:deadline*
  4825. (setf deadlines (org-agenda-get-deadlines t))
  4826. (push deadlines results)))))))))))
  4827. (defsubst org-em (x y list)
  4828. "Is X or Y a member of LIST?"
  4829. (or (memq x list) (memq y list)))
  4830. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4831. (defvar org-agenda-sorting-strategy-selected nil)
  4832. (defun org-agenda-entry-get-agenda-timestamp (pom)
  4833. "Retrieve timestamp information for sorting agenda views.
  4834. Given a point or marker POM, returns a cons cell of the timestamp
  4835. and the timestamp type relevant for the sorting strategy in
  4836. `org-agenda-sorting-strategy-selected'."
  4837. (let (ts ts-date-type)
  4838. (save-match-data
  4839. (cond ((org-em 'scheduled-up 'scheduled-down
  4840. org-agenda-sorting-strategy-selected)
  4841. (setq ts (org-entry-get pom "SCHEDULED")
  4842. ts-date-type " scheduled"))
  4843. ((org-em 'deadline-up 'deadline-down
  4844. org-agenda-sorting-strategy-selected)
  4845. (setq ts (org-entry-get pom "DEADLINE")
  4846. ts-date-type " deadline"))
  4847. ((org-em 'ts-up 'ts-down
  4848. org-agenda-sorting-strategy-selected)
  4849. (setq ts (org-entry-get pom "TIMESTAMP")
  4850. ts-date-type " timestamp"))
  4851. ((org-em 'tsia-up 'tsia-down
  4852. org-agenda-sorting-strategy-selected)
  4853. (setq ts (org-entry-get pom "TIMESTAMP_IA")
  4854. ts-date-type " timestamp_ia"))
  4855. ((org-em 'timestamp-up 'timestamp-down
  4856. org-agenda-sorting-strategy-selected)
  4857. (setq ts (or (org-entry-get pom "SCHEDULED")
  4858. (org-entry-get pom "DEADLINE")
  4859. (org-entry-get pom "TIMESTAMP")
  4860. (org-entry-get pom "TIMESTAMP_IA"))
  4861. ts-date-type ""))
  4862. (t (setq ts-date-type "")))
  4863. (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
  4864. ts-date-type))))
  4865. (defun org-agenda-get-todos ()
  4866. "Return the TODO information for agenda display."
  4867. (let* ((props (list 'face nil
  4868. 'done-face 'org-agenda-done
  4869. 'org-not-done-regexp org-not-done-regexp
  4870. 'org-todo-regexp org-todo-regexp
  4871. 'org-complex-heading-regexp org-complex-heading-regexp
  4872. 'mouse-face 'highlight
  4873. 'help-echo
  4874. (format "mouse-2 or RET jump to org file %s"
  4875. (abbreviate-file-name buffer-file-name))))
  4876. (case-fold-search nil)
  4877. (regexp (format org-heading-keyword-regexp-format
  4878. (cond
  4879. ((and org-select-this-todo-keyword
  4880. (equal org-select-this-todo-keyword "*"))
  4881. org-todo-regexp)
  4882. (org-select-this-todo-keyword
  4883. (concat "\\("
  4884. (mapconcat 'identity
  4885. (org-split-string
  4886. org-select-this-todo-keyword
  4887. "|")
  4888. "\\|") "\\)"))
  4889. (t org-not-done-regexp))))
  4890. marker priority category level tags todo-state
  4891. ts-date ts-date-type ts-date-pair
  4892. ee txt beg end inherited-tags todo-state-end-pos)
  4893. (goto-char (point-min))
  4894. (while (re-search-forward regexp nil t)
  4895. (catch :skip
  4896. (save-match-data
  4897. (beginning-of-line)
  4898. (org-agenda-skip)
  4899. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4900. (unless (and (setq todo-state (org-get-todo-state))
  4901. (setq todo-state-end-pos (match-end 2)))
  4902. (goto-char end)
  4903. (throw :skip nil))
  4904. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4905. (goto-char (1+ beg))
  4906. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4907. (throw :skip nil)))
  4908. (goto-char (match-beginning 2))
  4909. (setq marker (org-agenda-new-marker (match-beginning 0))
  4910. category (org-get-category)
  4911. ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
  4912. ts-date (car ts-date-pair)
  4913. ts-date-type (cdr ts-date-pair)
  4914. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  4915. inherited-tags
  4916. (or (eq org-agenda-show-inherited-tags 'always)
  4917. (and (listp org-agenda-show-inherited-tags)
  4918. (memq 'todo org-agenda-show-inherited-tags))
  4919. (and (eq org-agenda-show-inherited-tags t)
  4920. (or (eq org-agenda-use-tag-inheritance t)
  4921. (memq 'todo org-agenda-use-tag-inheritance))))
  4922. tags (org-get-tags-at nil (not inherited-tags))
  4923. level (make-string (org-reduced-level (org-outline-level)) ? )
  4924. txt (org-agenda-format-item "" txt level category tags t)
  4925. priority (1+ (org-get-priority txt)))
  4926. (org-add-props txt props
  4927. 'org-marker marker 'org-hd-marker marker
  4928. 'priority priority
  4929. 'level level
  4930. 'ts-date ts-date
  4931. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  4932. (push txt ee)
  4933. (if org-agenda-todo-list-sublevels
  4934. (goto-char todo-state-end-pos)
  4935. (org-end-of-subtree 'invisible))))
  4936. (nreverse ee)))
  4937. (defun org-agenda-todo-custom-ignore-p (time n)
  4938. "Check whether timestamp is farther away than n number of days.
  4939. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4940. `org-agenda-todo-ignore-scheduled' or
  4941. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4942. (let ((days (org-time-stamp-to-now
  4943. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  4944. (if (>= n 0)
  4945. (>= days n)
  4946. (<= days n))))
  4947. ;;;###autoload
  4948. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4949. (&optional end)
  4950. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4951. (when (or org-agenda-todo-ignore-with-date
  4952. org-agenda-todo-ignore-scheduled
  4953. org-agenda-todo-ignore-deadlines
  4954. org-agenda-todo-ignore-timestamp)
  4955. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4956. (save-excursion
  4957. (or (and org-agenda-todo-ignore-with-date
  4958. (re-search-forward org-ts-regexp end t))
  4959. (and org-agenda-todo-ignore-scheduled
  4960. (re-search-forward org-scheduled-time-regexp end t)
  4961. (cond
  4962. ((eq org-agenda-todo-ignore-scheduled 'future)
  4963. (> (org-time-stamp-to-now
  4964. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4965. ((eq org-agenda-todo-ignore-scheduled 'past)
  4966. (<= (org-time-stamp-to-now
  4967. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4968. ((numberp org-agenda-todo-ignore-scheduled)
  4969. (org-agenda-todo-custom-ignore-p
  4970. (match-string 1) org-agenda-todo-ignore-scheduled))
  4971. (t)))
  4972. (and org-agenda-todo-ignore-deadlines
  4973. (re-search-forward org-deadline-time-regexp end t)
  4974. (cond
  4975. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4976. ((eq org-agenda-todo-ignore-deadlines 'far)
  4977. (not (org-deadline-close-p (match-string 1))))
  4978. ((eq org-agenda-todo-ignore-deadlines 'future)
  4979. (> (org-time-stamp-to-now
  4980. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4981. ((eq org-agenda-todo-ignore-deadlines 'past)
  4982. (<= (org-time-stamp-to-now
  4983. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4984. ((numberp org-agenda-todo-ignore-deadlines)
  4985. (org-agenda-todo-custom-ignore-p
  4986. (match-string 1) org-agenda-todo-ignore-deadlines))
  4987. (t (org-deadline-close-p (match-string 1)))))
  4988. (and org-agenda-todo-ignore-timestamp
  4989. (let ((buffer (current-buffer))
  4990. (regexp
  4991. (concat
  4992. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4993. (start (point)))
  4994. ;; Copy current buffer into a temporary one
  4995. (with-temp-buffer
  4996. (insert-buffer-substring buffer start end)
  4997. (goto-char (point-min))
  4998. ;; Delete SCHEDULED and DEADLINE items
  4999. (while (re-search-forward regexp end t)
  5000. (delete-region (match-beginning 0) (match-end 0)))
  5001. (goto-char (point-min))
  5002. ;; No search for timestamp left
  5003. (when (re-search-forward org-ts-regexp nil t)
  5004. (cond
  5005. ((eq org-agenda-todo-ignore-timestamp 'future)
  5006. (> (org-time-stamp-to-now
  5007. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5008. ((eq org-agenda-todo-ignore-timestamp 'past)
  5009. (<= (org-time-stamp-to-now
  5010. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5011. ((numberp org-agenda-todo-ignore-timestamp)
  5012. (org-agenda-todo-custom-ignore-p
  5013. (match-string 1) org-agenda-todo-ignore-timestamp))
  5014. (t))))))))))
  5015. (defun org-agenda-get-timestamps (&optional deadlines)
  5016. "Return the date stamp information for agenda display.
  5017. Optional argument DEADLINES is a list of deadline items to be
  5018. displayed in agenda view."
  5019. (let* ((props (list 'face 'org-agenda-calendar-event
  5020. 'org-not-done-regexp org-not-done-regexp
  5021. 'org-todo-regexp org-todo-regexp
  5022. 'org-complex-heading-regexp org-complex-heading-regexp
  5023. 'mouse-face 'highlight
  5024. 'help-echo
  5025. (format "mouse-2 or RET jump to Org file %s"
  5026. (abbreviate-file-name buffer-file-name))))
  5027. (current (calendar-absolute-from-gregorian date))
  5028. (today (org-today))
  5029. (deadline-position-alist
  5030. (mapcar (lambda (d)
  5031. (let ((m (get-text-property 0 'org-hd-marker d)))
  5032. (and m (marker-position m))))
  5033. deadlines))
  5034. ;; Match time-stamps set to current date, time-stamps with
  5035. ;; a repeater, and S-exp time-stamps.
  5036. (regexp
  5037. (concat
  5038. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5039. (regexp-quote
  5040. (substring
  5041. (format-time-string
  5042. (car org-time-stamp-formats)
  5043. (apply #'encode-time ; DATE bound by calendar
  5044. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5045. 1 11))
  5046. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5047. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5048. timestamp-items)
  5049. (goto-char (point-min))
  5050. (while (re-search-forward regexp nil t)
  5051. ;; Skip date ranges, scheduled and deadlines, which are handled
  5052. ;; specially. Also skip time-stamps before first headline as
  5053. ;; there would be no entry to add to the agenda. Eventually,
  5054. ;; ignore clock entries.
  5055. (catch :skip
  5056. (save-match-data
  5057. (when (or (org-at-date-range-p)
  5058. (org-at-planning-p)
  5059. (org-before-first-heading-p)
  5060. (and org-agenda-include-inactive-timestamps
  5061. (org-at-clock-log-p)))
  5062. (throw :skip nil))
  5063. (org-agenda-skip))
  5064. (let* ((pos (match-beginning 0))
  5065. (repeat (match-string 1))
  5066. (sexp-entry (match-string 3))
  5067. (time-stamp (if (or repeat sexp-entry) (match-string 0)
  5068. (save-excursion
  5069. (goto-char pos)
  5070. (looking-at org-ts-regexp-both)
  5071. (match-string 0))))
  5072. (todo-state (org-get-todo-state))
  5073. (warntime (get-text-property (point) 'org-appt-warntime))
  5074. (done? (member todo-state org-done-keywords)))
  5075. ;; Possibly skip done tasks.
  5076. (when (and done? org-agenda-skip-timestamp-if-done)
  5077. (throw :skip t))
  5078. ;; S-exp entry doesn't match current day: skip it.
  5079. (when (and sexp-entry (not (org-diary-sexp-entry sexp-entry "" date)))
  5080. (throw :skip nil))
  5081. (when repeat
  5082. (let* ((past
  5083. ;; A repeating time stamp is shown at its base
  5084. ;; date and every repeated date up to TODAY. If
  5085. ;; `org-agenda-prefer-last-repeat' is non-nil,
  5086. ;; however, only the last repeat before today
  5087. ;; (inclusive) is shown.
  5088. (org-agenda--timestamp-to-absolute
  5089. repeat
  5090. (if (or (> current today)
  5091. (eq org-agenda-prefer-last-repeat t)
  5092. (member todo-state org-agenda-prefer-last-repeat))
  5093. today
  5094. current)
  5095. 'past (current-buffer) pos))
  5096. (future
  5097. ;; Display every repeated date past TODAY
  5098. ;; (exclusive) unless
  5099. ;; `org-agenda-show-future-repeats' is nil. If
  5100. ;; this variable is set to `next', only display
  5101. ;; the first repeated date after TODAY
  5102. ;; (exclusive).
  5103. (cond
  5104. ((<= current today) past)
  5105. ((not org-agenda-show-future-repeats) past)
  5106. (t
  5107. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5108. (1+ today)
  5109. current)))
  5110. (org-agenda--timestamp-to-absolute
  5111. repeat base 'future (current-buffer) pos))))))
  5112. (when (and (/= current past) (/= current future))
  5113. (throw :skip nil))))
  5114. (save-excursion
  5115. (re-search-backward org-outline-regexp-bol nil t)
  5116. ;; Possibly skip time-stamp when a deadline is set.
  5117. (when (and org-agenda-skip-timestamp-if-deadline-is-shown
  5118. (assq (point) deadline-position-alist))
  5119. (throw :skip nil))
  5120. (let* ((category (org-get-category pos))
  5121. (inherited-tags
  5122. (or (eq org-agenda-show-inherited-tags 'always)
  5123. (and (consp org-agenda-show-inherited-tags)
  5124. (memq 'agenda org-agenda-show-inherited-tags))
  5125. (and (eq org-agenda-show-inherited-tags t)
  5126. (or (eq org-agenda-use-tag-inheritance t)
  5127. (memq 'agenda
  5128. org-agenda-use-tag-inheritance)))))
  5129. (tags (org-get-tags-at nil (not inherited-tags)))
  5130. (level (make-string (org-reduced-level (org-outline-level))
  5131. ?\s))
  5132. (head (and (looking-at "\\*+[ \t]+\\(.*\\)")
  5133. (match-string 1)))
  5134. (inactive? (= (char-after pos) ?\[))
  5135. (habit? (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5136. (item
  5137. (org-agenda-format-item
  5138. (and inactive? org-agenda-inactive-leader)
  5139. head level category tags time-stamp org-ts-regexp habit?)))
  5140. (org-add-props item props
  5141. 'priority (if habit?
  5142. (org-habit-get-priority (org-habit-parse-todo))
  5143. (org-get-priority item))
  5144. 'org-marker (org-agenda-new-marker pos)
  5145. 'org-hd-marker (org-agenda-new-marker)
  5146. 'date date
  5147. 'level level
  5148. 'ts-date (if repeat (org-agenda--timestamp-to-absolute repeat)
  5149. current)
  5150. 'todo-state todo-state
  5151. 'warntime warntime
  5152. 'type "timestamp")
  5153. (push item timestamp-items))))
  5154. (when org-agenda-skip-additional-timestamps-same-entry
  5155. (outline-next-heading))))
  5156. (nreverse timestamp-items)))
  5157. (defun org-agenda-get-sexps ()
  5158. "Return the sexp information for agenda display."
  5159. (require 'diary-lib)
  5160. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5161. 'mouse-face 'highlight
  5162. 'help-echo
  5163. (format "mouse-2 or RET jump to org file %s"
  5164. (abbreviate-file-name buffer-file-name))))
  5165. (regexp "^&?%%(")
  5166. marker category extra level ee txt tags entry
  5167. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5168. (goto-char (point-min))
  5169. (while (re-search-forward regexp nil t)
  5170. (catch :skip
  5171. (org-agenda-skip)
  5172. (setq beg (match-beginning 0))
  5173. (goto-char (1- (match-end 0)))
  5174. (setq b (point))
  5175. (forward-sexp 1)
  5176. (setq sexp (buffer-substring b (point)))
  5177. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5178. (org-trim (match-string 1))
  5179. ""))
  5180. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5181. (when result
  5182. (setq marker (org-agenda-new-marker beg)
  5183. level (make-string (org-reduced-level (org-outline-level)) ? )
  5184. category (org-get-category beg)
  5185. inherited-tags
  5186. (or (eq org-agenda-show-inherited-tags 'always)
  5187. (and (listp org-agenda-show-inherited-tags)
  5188. (memq 'agenda org-agenda-show-inherited-tags))
  5189. (and (eq org-agenda-show-inherited-tags t)
  5190. (or (eq org-agenda-use-tag-inheritance t)
  5191. (memq 'agenda org-agenda-use-tag-inheritance))))
  5192. tags (org-get-tags-at nil (not inherited-tags))
  5193. todo-state (org-get-todo-state)
  5194. warntime (get-text-property (point) 'org-appt-warntime)
  5195. extra nil)
  5196. (dolist (r (if (stringp result)
  5197. (list result)
  5198. result)) ;; we expect a list here
  5199. (when (and org-agenda-diary-sexp-prefix
  5200. (string-match org-agenda-diary-sexp-prefix r))
  5201. (setq extra (match-string 0 r)
  5202. r (replace-match "" nil nil r)))
  5203. (if (string-match "\\S-" r)
  5204. (setq txt r)
  5205. (setq txt "SEXP entry returned empty string"))
  5206. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5207. (org-add-props txt props 'org-marker marker
  5208. 'date date 'todo-state todo-state
  5209. 'level level 'type "sexp" 'warntime warntime)
  5210. (push txt ee)))))
  5211. (nreverse ee)))
  5212. ;; Calendar sanity: define some functions that are independent of
  5213. ;; `calendar-date-style'.
  5214. (defun org-anniversary (year month day &optional mark)
  5215. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5216. (with-no-warnings
  5217. (let ((calendar-date-style 'iso))
  5218. (diary-anniversary year month day mark))))
  5219. (defun org-cyclic (N year month day &optional mark)
  5220. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5221. (with-no-warnings
  5222. (let ((calendar-date-style 'iso))
  5223. (diary-cyclic N year month day mark))))
  5224. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5225. "Like `diary-block', but with fixed (ISO) order of arguments."
  5226. (with-no-warnings
  5227. (let ((calendar-date-style 'iso))
  5228. (diary-block Y1 M1 D1 Y2 M2 D2 mark))))
  5229. (defun org-date (year month day &optional mark)
  5230. "Like `diary-date', but with fixed (ISO) order of arguments."
  5231. (with-no-warnings
  5232. (let ((calendar-date-style 'iso))
  5233. (diary-date year month day mark))))
  5234. ;; Define the `org-class' function
  5235. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5236. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5237. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5238. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5239. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5240. `holidays', then any date that is known by the Emacs calendar to be a
  5241. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5242. then those holidays will be skipped."
  5243. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5244. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5245. (d (calendar-absolute-from-gregorian date))
  5246. (h (when skip-weeks (calendar-check-holidays date))))
  5247. (and
  5248. (<= date1 d)
  5249. (<= d date2)
  5250. (= (calendar-day-of-week date) dayname)
  5251. (or (not skip-weeks)
  5252. (progn
  5253. (require 'cal-iso)
  5254. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5255. (not (or (and h (memq 'holidays skip-weeks))
  5256. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5257. entry)))
  5258. (defalias 'org-get-closed 'org-agenda-get-progress)
  5259. (defun org-agenda-get-progress ()
  5260. "Return the logged TODO entries for agenda display."
  5261. (let* ((props (list 'mouse-face 'highlight
  5262. 'org-not-done-regexp org-not-done-regexp
  5263. 'org-todo-regexp org-todo-regexp
  5264. 'org-complex-heading-regexp org-complex-heading-regexp
  5265. 'help-echo
  5266. (format "mouse-2 or RET jump to org file %s"
  5267. (abbreviate-file-name buffer-file-name))))
  5268. (items (if (consp org-agenda-show-log-scoped)
  5269. org-agenda-show-log-scoped
  5270. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5271. '(clock)
  5272. org-agenda-log-mode-items)))
  5273. (parts
  5274. (delq nil
  5275. (list
  5276. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5277. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5278. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5279. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5280. (error "`org-agenda-log-mode-items' is empty")))
  5281. (regexp (concat
  5282. "\\(" parts-re "\\)"
  5283. " *\\["
  5284. (regexp-quote
  5285. (substring
  5286. (format-time-string
  5287. (car org-time-stamp-formats)
  5288. (apply 'encode-time ; DATE bound by calendar
  5289. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5290. 1 11))))
  5291. (org-agenda-search-headline-for-time nil)
  5292. marker hdmarker priority category level tags closedp
  5293. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5294. (goto-char (point-min))
  5295. (while (re-search-forward regexp nil t)
  5296. (catch :skip
  5297. (org-agenda-skip)
  5298. (setq marker (org-agenda-new-marker (match-beginning 0))
  5299. closedp (equal (match-string 1) org-closed-string)
  5300. statep (equal (string-to-char (match-string 1)) ?-)
  5301. clockp (not (or closedp statep))
  5302. state (and statep (match-string 2))
  5303. category (org-get-category (match-beginning 0))
  5304. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5305. (when (string-match "\\]" timestr)
  5306. ;; substring should only run to end of time stamp
  5307. (setq rest (substring timestr (match-end 0))
  5308. timestr (substring timestr 0 (match-end 0)))
  5309. (if (and (not closedp) (not statep)
  5310. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5311. rest))
  5312. (progn (setq timestr (concat (substring timestr 0 -1)
  5313. "-" (match-string 1 rest) "]"))
  5314. (setq clocked (match-string 2 rest)))
  5315. (setq clocked "-")))
  5316. (save-excursion
  5317. (setq extra
  5318. (cond
  5319. ((not org-agenda-log-mode-add-notes) nil)
  5320. (statep
  5321. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5322. (match-string 1)))
  5323. (clockp
  5324. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5325. (match-string 1)))))
  5326. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5327. (throw :skip nil)
  5328. (goto-char (match-beginning 0))
  5329. (setq hdmarker (org-agenda-new-marker)
  5330. inherited-tags
  5331. (or (eq org-agenda-show-inherited-tags 'always)
  5332. (and (listp org-agenda-show-inherited-tags)
  5333. (memq 'todo org-agenda-show-inherited-tags))
  5334. (and (eq org-agenda-show-inherited-tags t)
  5335. (or (eq org-agenda-use-tag-inheritance t)
  5336. (memq 'todo org-agenda-use-tag-inheritance))))
  5337. tags (org-get-tags-at nil (not inherited-tags))
  5338. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5339. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5340. (setq txt (match-string 1))
  5341. (when extra
  5342. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5343. (setq txt (concat (substring txt 0 (match-beginning 1))
  5344. " - " extra " " (match-string 2 txt)))
  5345. (setq txt (concat txt " - " extra))))
  5346. (setq txt (org-agenda-format-item
  5347. (cond
  5348. (closedp "Closed: ")
  5349. (statep (concat "State: (" state ")"))
  5350. (t (concat "Clocked: (" clocked ")")))
  5351. txt level category tags timestr)))
  5352. (setq priority 100000)
  5353. (org-add-props txt props
  5354. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5355. 'priority priority 'level level
  5356. 'type "closed" 'date date
  5357. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5358. (push txt ee))
  5359. (goto-char (point-at-eol))))
  5360. (nreverse ee)))
  5361. (defun org-agenda-show-clocking-issues ()
  5362. "Add overlays, showing issues with clocking.
  5363. See also the user option `org-agenda-clock-consistency-checks'."
  5364. (interactive)
  5365. (let* ((pl org-agenda-clock-consistency-checks)
  5366. (re (concat "^[ \t]*"
  5367. org-clock-string
  5368. "[ \t]+"
  5369. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5370. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5371. (tlstart 0.)
  5372. (tlend 0.)
  5373. (maxtime (org-duration-to-minutes
  5374. (or (plist-get pl :max-duration) "24:00")))
  5375. (mintime (org-duration-to-minutes
  5376. (or (plist-get pl :min-duration) 0)))
  5377. (maxgap (org-duration-to-minutes
  5378. ;; default 30:00 means never complain
  5379. (or (plist-get pl :max-gap) "30:00")))
  5380. (gapok (mapcar #'org-duration-to-minutes
  5381. (plist-get pl :gap-ok-around)))
  5382. (def-face (or (plist-get pl :default-face)
  5383. '((:background "DarkRed") (:foreground "white"))))
  5384. issue face m te ts dt ov)
  5385. (goto-char (point-min))
  5386. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5387. (setq issue nil face def-face)
  5388. (catch 'next
  5389. (setq m (org-get-at-bol 'org-marker)
  5390. te nil ts nil)
  5391. (unless (and m (markerp m))
  5392. (setq issue "No valid clock line") (throw 'next t))
  5393. (org-with-point-at m
  5394. (save-excursion
  5395. (goto-char (point-at-bol))
  5396. (unless (looking-at re)
  5397. (error "No valid Clock line")
  5398. (throw 'next t))
  5399. (unless (match-end 3)
  5400. (setq issue "No end time"
  5401. face (or (plist-get pl :no-end-time-face) face))
  5402. (throw 'next t))
  5403. (setq ts (match-string 1)
  5404. te (match-string 3)
  5405. ts (float-time
  5406. (apply #'encode-time (org-parse-time-string ts)))
  5407. te (float-time
  5408. (apply #'encode-time (org-parse-time-string te)))
  5409. dt (- te ts))))
  5410. (cond
  5411. ((> dt (* 60 maxtime))
  5412. ;; a very long clocking chunk
  5413. (setq issue (format "Clocking interval is very long: %s"
  5414. (org-duration-from-minutes (floor (/ dt 60.))))
  5415. face (or (plist-get pl :long-face) face)))
  5416. ((< dt (* 60 mintime))
  5417. ;; a very short clocking chunk
  5418. (setq issue (format "Clocking interval is very short: %s"
  5419. (org-duration-from-minutes (floor (/ dt 60.))))
  5420. face (or (plist-get pl :short-face) face)))
  5421. ((and (> tlend 0) (< ts tlend))
  5422. ;; Two clock entries are overlapping
  5423. (setq issue (format "Clocking overlap: %d minutes"
  5424. (/ (- tlend ts) 60))
  5425. face (or (plist-get pl :overlap-face) face)))
  5426. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5427. ;; There is a gap, lets see if we need to report it
  5428. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5429. (setq issue (format "Clocking gap: %d minutes"
  5430. (/ (- ts tlend) 60))
  5431. face (or (plist-get pl :gap-face) face))))
  5432. (t nil)))
  5433. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5434. (when issue
  5435. ;; OK, there was some issue, add an overlay to show the issue
  5436. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5437. (overlay-put ov 'before-string
  5438. (concat
  5439. (org-add-props
  5440. (format "%-43s" (concat " " issue))
  5441. nil
  5442. 'face face)
  5443. "\n"))
  5444. (overlay-put ov 'evaporate t)))))
  5445. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5446. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5447. (catch 'exit
  5448. (unless ok-list
  5449. ;; there are no OK times for gaps...
  5450. (throw 'exit nil))
  5451. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5452. ;; This is more than 24 hours, so it is OK.
  5453. ;; because we have at least one OK time, that must be in the
  5454. ;; 24 hour interval.
  5455. (throw 'exit t))
  5456. ;; We have a shorter gap.
  5457. ;; Now we have to get the minute of the day when these times are
  5458. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5459. (t2dec (decode-time (seconds-to-time t2)))
  5460. ;; compute the minute on the day
  5461. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5462. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5463. (when (< min2 min1)
  5464. ;; if min2 is smaller than min1, this means it is on the next day.
  5465. ;; Wrap it to after midnight.
  5466. (setq min2 (+ min2 1440)))
  5467. ;; Now check if any of the OK times is in the gap
  5468. (mapc (lambda (x)
  5469. ;; Wrap the time to after midnight if necessary
  5470. (if (< x min1) (setq x (+ x 1440)))
  5471. ;; Check if in interval
  5472. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5473. ok-list)
  5474. ;; Nope, this gap is not OK
  5475. nil)))
  5476. (defun org-agenda-get-deadlines (&optional with-hour)
  5477. "Return the deadline information for agenda display.
  5478. When WITH-HOUR is non-nil, only return deadlines with an hour
  5479. specification like [h]h:mm."
  5480. (let* ((props (list 'mouse-face 'highlight
  5481. 'org-not-done-regexp org-not-done-regexp
  5482. 'org-todo-regexp org-todo-regexp
  5483. 'org-complex-heading-regexp org-complex-heading-regexp
  5484. 'help-echo
  5485. (format "mouse-2 or RET jump to org file %s"
  5486. (abbreviate-file-name buffer-file-name))))
  5487. (regexp (if with-hour
  5488. org-deadline-time-hour-regexp
  5489. org-deadline-time-regexp))
  5490. (today (org-today))
  5491. (today? (org-agenda-today-p date)) ; DATE bound by calendar.
  5492. (current (calendar-absolute-from-gregorian date))
  5493. deadline-items)
  5494. (goto-char (point-min))
  5495. (while (re-search-forward regexp nil t)
  5496. (catch :skip
  5497. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5498. (org-agenda-skip)
  5499. (let* ((s (match-string 1))
  5500. (pos (1- (match-beginning 1)))
  5501. (todo-state (save-match-data (org-get-todo-state)))
  5502. (done? (member todo-state org-done-keywords))
  5503. (sexp? (string-prefix-p "%%" s))
  5504. ;; DEADLINE is the deadline date for the entry. It is
  5505. ;; either the base date or the last repeat, according
  5506. ;; to `org-agenda-prefer-last-repeat'.
  5507. (deadline
  5508. (cond
  5509. (sexp? (org-agenda--timestamp-to-absolute s current))
  5510. ((or (eq org-agenda-prefer-last-repeat t)
  5511. (member todo-state org-agenda-prefer-last-repeat))
  5512. (org-agenda--timestamp-to-absolute
  5513. s today 'past (current-buffer) pos))
  5514. (t (org-agenda--timestamp-to-absolute s))))
  5515. ;; REPEAT is the future repeat closest from CURRENT,
  5516. ;; according to `org-agenda-show-future-repeats'. If
  5517. ;; the latter is nil, or if the time stamp has no
  5518. ;; repeat part, default to DEADLINE.
  5519. (repeat
  5520. (cond
  5521. (sexp? deadline)
  5522. ((<= current today) deadline)
  5523. ((not org-agenda-show-future-repeats) deadline)
  5524. (t
  5525. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5526. (1+ today)
  5527. current)))
  5528. (org-agenda--timestamp-to-absolute
  5529. s base 'future (current-buffer) pos)))))
  5530. (diff (- deadline current))
  5531. (suppress-prewarning
  5532. (let ((scheduled
  5533. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5534. (org-entry-get nil "SCHEDULED"))))
  5535. (cond
  5536. ((not scheduled) nil)
  5537. ;; The current item has a scheduled date, so
  5538. ;; evaluate its prewarning lead time.
  5539. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5540. ;; Use global prewarning-restart lead time.
  5541. org-agenda-skip-deadline-prewarning-if-scheduled)
  5542. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5543. 'pre-scheduled)
  5544. ;; Set pre-warning to no earlier than SCHEDULED.
  5545. (min (- deadline
  5546. (org-agenda--timestamp-to-absolute scheduled))
  5547. org-deadline-warning-days))
  5548. ;; Set pre-warning to deadline.
  5549. (t 0))))
  5550. (wdays (if suppress-prewarning
  5551. (let ((org-deadline-warning-days suppress-prewarning))
  5552. (org-get-wdays s))
  5553. (org-get-wdays s))))
  5554. (cond
  5555. ;; Only display deadlines at their base date, at future
  5556. ;; repeat occurrences or in today agenda.
  5557. ((= current deadline) nil)
  5558. ((= current repeat) nil)
  5559. ((not today?) (throw :skip nil))
  5560. ;; Upcoming deadline: display within warning period WDAYS.
  5561. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  5562. ;; Overdue deadline: warn about it for
  5563. ;; `org-deadline-past-days' duration.
  5564. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  5565. ;; Possibly skip done tasks.
  5566. (when (and done?
  5567. (or org-agenda-skip-deadline-if-done
  5568. (/= deadline current)))
  5569. (throw :skip nil))
  5570. (save-excursion
  5571. (re-search-backward "^\\*+[ \t]+" nil t)
  5572. (goto-char (match-end 0))
  5573. (let* ((category (org-get-category))
  5574. (level (make-string (org-reduced-level (org-outline-level))
  5575. ?\s))
  5576. (head (buffer-substring (point) (line-end-position)))
  5577. (inherited-tags
  5578. (or (eq org-agenda-show-inherited-tags 'always)
  5579. (and (listp org-agenda-show-inherited-tags)
  5580. (memq 'agenda org-agenda-show-inherited-tags))
  5581. (and (eq org-agenda-show-inherited-tags t)
  5582. (or (eq org-agenda-use-tag-inheritance t)
  5583. (memq 'agenda
  5584. org-agenda-use-tag-inheritance)))))
  5585. (tags (org-get-tags-at nil (not inherited-tags)))
  5586. (time
  5587. (cond
  5588. ;; No time of day designation if it is only
  5589. ;; a reminder.
  5590. ((and (/= current deadline) (/= current repeat)) nil)
  5591. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5592. (concat (substring s (match-beginning 1)) " "))
  5593. (t 'time)))
  5594. (item
  5595. (org-agenda-format-item
  5596. ;; Insert appropriate suffixes before deadlines.
  5597. ;; Those only apply to today agenda.
  5598. (pcase-let ((`(,now ,future ,past)
  5599. org-agenda-deadline-leaders))
  5600. (cond
  5601. ((and today? (< deadline today)) (format past (- diff)))
  5602. ((and today? (> deadline today)) (format future diff))
  5603. (t now)))
  5604. head level category tags time))
  5605. (face (org-agenda-deadline-face
  5606. (- 1 (/ (float diff) (max wdays 1)))))
  5607. (upcoming? (and today? (> deadline today)))
  5608. (warntime (get-text-property (point) 'org-appt-warntime)))
  5609. (org-add-props item props
  5610. 'org-marker (org-agenda-new-marker pos)
  5611. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5612. 'warntime warntime
  5613. 'level level
  5614. 'ts-date deadline
  5615. 'priority
  5616. ;; Adjust priority to today reminders about deadlines.
  5617. ;; Overdue deadlines get the highest priority
  5618. ;; increase, then imminent deadlines and eventually
  5619. ;; more distant deadlines.
  5620. (let ((adjust (if today? (- diff) 0)))
  5621. (+ adjust (org-get-priority item)))
  5622. 'todo-state todo-state
  5623. 'type (if upcoming? "upcoming-deadline" "deadline")
  5624. 'date (if upcoming? date deadline)
  5625. 'face (if done? 'org-agenda-done face)
  5626. 'undone-face face
  5627. 'done-face 'org-agenda-done)
  5628. (push item deadline-items))))))
  5629. (nreverse deadline-items)))
  5630. (defun org-agenda-deadline-face (fraction)
  5631. "Return the face to displaying a deadline item.
  5632. FRACTION is what fraction of the head-warning time has passed."
  5633. (assoc-default fraction org-agenda-deadline-faces #'<=))
  5634. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  5635. "Return the scheduled information for agenda display.
  5636. Optional argument DEADLINES is a list of deadline items to be
  5637. displayed in agenda view. When WITH-HOUR is non-nil, only return
  5638. scheduled items with an hour specification like [h]h:mm."
  5639. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5640. 'org-todo-regexp org-todo-regexp
  5641. 'org-complex-heading-regexp org-complex-heading-regexp
  5642. 'done-face 'org-agenda-done
  5643. 'mouse-face 'highlight
  5644. 'help-echo
  5645. (format "mouse-2 or RET jump to Org file %s"
  5646. (abbreviate-file-name buffer-file-name))))
  5647. (regexp (if with-hour
  5648. org-scheduled-time-hour-regexp
  5649. org-scheduled-time-regexp))
  5650. (today (org-today))
  5651. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  5652. (current (calendar-absolute-from-gregorian date))
  5653. (deadline-pos
  5654. (mapcar (lambda (d)
  5655. (let ((m (get-text-property 0 'org-hd-marker d)))
  5656. (and m (marker-position m))))
  5657. deadlines))
  5658. scheduled-items)
  5659. (goto-char (point-min))
  5660. (while (re-search-forward regexp nil t)
  5661. (catch :skip
  5662. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5663. (org-agenda-skip)
  5664. (let* ((s (match-string 1))
  5665. (pos (1- (match-beginning 1)))
  5666. (todo-state (save-match-data (org-get-todo-state)))
  5667. (donep (member todo-state org-done-keywords))
  5668. (sexp? (string-prefix-p "%%" s))
  5669. ;; SCHEDULE is the scheduled date for the entry. It is
  5670. ;; either the bare date or the last repeat, according
  5671. ;; to `org-agenda-prefer-last-repeat'.
  5672. (schedule
  5673. (cond
  5674. (sexp? (org-agenda--timestamp-to-absolute s current))
  5675. ((or (eq org-agenda-prefer-last-repeat t)
  5676. (member todo-state org-agenda-prefer-last-repeat))
  5677. (org-agenda--timestamp-to-absolute
  5678. s today 'past (current-buffer) pos))
  5679. (t (org-agenda--timestamp-to-absolute s))))
  5680. ;; REPEAT is the future repeat closest from CURRENT,
  5681. ;; according to `org-agenda-show-future-repeats'. If
  5682. ;; the latter is nil, or if the time stamp has no
  5683. ;; repeat part, default to SCHEDULE.
  5684. (repeat
  5685. (cond
  5686. (sexp? schedule)
  5687. ((<= current today) schedule)
  5688. ((not org-agenda-show-future-repeats) schedule)
  5689. (t
  5690. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5691. (1+ today)
  5692. current)))
  5693. (org-agenda--timestamp-to-absolute
  5694. s base 'future (current-buffer) pos)))))
  5695. (diff (- current schedule))
  5696. (warntime (get-text-property (point) 'org-appt-warntime))
  5697. (pastschedp (< schedule today))
  5698. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5699. (suppress-delay
  5700. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  5701. (org-entry-get nil "DEADLINE"))))
  5702. (cond
  5703. ((not deadline) nil)
  5704. ;; The current item has a deadline date, so
  5705. ;; evaluate its delay time.
  5706. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5707. ;; Use global delay time.
  5708. (- org-agenda-skip-scheduled-delay-if-deadline))
  5709. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5710. 'post-deadline)
  5711. ;; Set delay to no later than DEADLINE.
  5712. (min (- schedule
  5713. (org-agenda--timestamp-to-absolute deadline))
  5714. org-scheduled-delay-days))
  5715. (t 0))))
  5716. (ddays
  5717. (cond
  5718. ;; Nullify delay when a repeater triggered already
  5719. ;; and the delay is of the form --Xd.
  5720. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  5721. (> current schedule))
  5722. 0)
  5723. (suppress-delay
  5724. (let ((org-scheduled-delay-days suppress-delay))
  5725. (org-get-wdays s t t)))
  5726. (t (org-get-wdays s t)))))
  5727. ;; Display scheduled items at base date (SCHEDULE), today if
  5728. ;; scheduled before the current date, and at any repeat past
  5729. ;; today. However, skip delayed items and items that have
  5730. ;; been displayed for more than `org-scheduled-past-days'.
  5731. (unless (and todayp
  5732. habitp
  5733. (bound-and-true-p org-habit-show-all-today))
  5734. (when (or (and (> ddays 0) (< diff ddays))
  5735. (> diff org-scheduled-past-days)
  5736. (> schedule current)
  5737. (and (/= current schedule)
  5738. (/= current today)
  5739. (/= current repeat)))
  5740. (throw :skip nil)))
  5741. ;; Possibly skip done tasks.
  5742. (when (and donep
  5743. (or org-agenda-skip-scheduled-if-done
  5744. (/= schedule current)))
  5745. (throw :skip nil))
  5746. ;; Skip entry if it already appears as a deadline, per
  5747. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  5748. ;; doesn't apply to habits.
  5749. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  5750. ((guard
  5751. (or (not (memq (line-beginning-position 0) deadline-pos))
  5752. habitp))
  5753. nil)
  5754. (`repeated-after-deadline
  5755. (let ((deadline (time-to-days
  5756. (org-get-deadline-time (point)))))
  5757. (and (<= schedule deadline) (> current deadline))))
  5758. (`not-today pastschedp)
  5759. (`t t)
  5760. (_ nil))
  5761. (throw :skip nil))
  5762. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  5763. ;; only show them for today. Also skip done habits.
  5764. (when (and habitp
  5765. (or donep
  5766. (not (bound-and-true-p org-habit-show-habits))
  5767. (and (not todayp)
  5768. (bound-and-true-p
  5769. org-habit-show-habits-only-for-today))))
  5770. (throw :skip nil))
  5771. (save-excursion
  5772. (re-search-backward "^\\*+[ \t]+" nil t)
  5773. (goto-char (match-end 0))
  5774. (let* ((category (org-get-category))
  5775. (inherited-tags
  5776. (or (eq org-agenda-show-inherited-tags 'always)
  5777. (and (listp org-agenda-show-inherited-tags)
  5778. (memq 'agenda org-agenda-show-inherited-tags))
  5779. (and (eq org-agenda-show-inherited-tags t)
  5780. (or (eq org-agenda-use-tag-inheritance t)
  5781. (memq 'agenda
  5782. org-agenda-use-tag-inheritance)))))
  5783. (tags (org-get-tags-at nil (not inherited-tags)))
  5784. (level (make-string (org-reduced-level (org-outline-level))
  5785. ?\s))
  5786. (head (buffer-substring (point) (line-end-position)))
  5787. (time
  5788. (cond
  5789. ;; No time of day designation if it is only
  5790. ;; a reminder.
  5791. ((and (/= current schedule) (/= current repeat)) nil)
  5792. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5793. (concat (substring s (match-beginning 1)) " "))
  5794. (t 'time)))
  5795. (item
  5796. (org-agenda-format-item
  5797. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  5798. ;; Show a reminder of a past scheduled today.
  5799. (if (and todayp pastschedp)
  5800. (format past diff)
  5801. first))
  5802. head level category tags time nil habitp))
  5803. (face (cond ((and (not habitp) pastschedp)
  5804. 'org-scheduled-previously)
  5805. (todayp 'org-scheduled-today)
  5806. (t 'org-scheduled)))
  5807. (habitp (and habitp (org-habit-parse-todo))))
  5808. (org-add-props item props
  5809. 'undone-face face
  5810. 'face (if donep 'org-agenda-done face)
  5811. 'org-marker (org-agenda-new-marker pos)
  5812. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5813. 'type (if pastschedp "past-scheduled" "scheduled")
  5814. 'date (if pastschedp schedule date)
  5815. 'ts-date schedule
  5816. 'warntime warntime
  5817. 'level level
  5818. 'priority (if habitp (org-habit-get-priority habitp)
  5819. (+ 99 diff (org-get-priority item)))
  5820. 'org-habit-p habitp
  5821. 'todo-state todo-state)
  5822. (push item scheduled-items))))))
  5823. (nreverse scheduled-items)))
  5824. (defun org-agenda-get-blocks ()
  5825. "Return the date-range information for agenda display."
  5826. (let* ((props (list 'face nil
  5827. 'org-not-done-regexp org-not-done-regexp
  5828. 'org-todo-regexp org-todo-regexp
  5829. 'org-complex-heading-regexp org-complex-heading-regexp
  5830. 'mouse-face 'highlight
  5831. 'help-echo
  5832. (format "mouse-2 or RET jump to org file %s"
  5833. (abbreviate-file-name buffer-file-name))))
  5834. (regexp org-tr-regexp)
  5835. (d0 (calendar-absolute-from-gregorian date))
  5836. marker hdmarker ee txt d1 d2 s1 s2 category
  5837. level todo-state tags pos head donep inherited-tags)
  5838. (goto-char (point-min))
  5839. (while (re-search-forward regexp nil t)
  5840. (catch :skip
  5841. (org-agenda-skip)
  5842. (setq pos (point))
  5843. (let ((start-time (match-string 1))
  5844. (end-time (match-string 2)))
  5845. (setq s1 (match-string 1)
  5846. s2 (match-string 2)
  5847. d1 (time-to-days
  5848. (condition-case err
  5849. (org-time-string-to-time s1)
  5850. (error
  5851. (error
  5852. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  5853. s1
  5854. pos
  5855. (current-buffer)
  5856. (error-message-string err)))))
  5857. d2 (time-to-days
  5858. (condition-case err
  5859. (org-time-string-to-time s2)
  5860. (error
  5861. (error
  5862. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  5863. s2
  5864. pos
  5865. (current-buffer)
  5866. (error-message-string err))))))
  5867. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5868. ;; Only allow days between the limits, because the normal
  5869. ;; date stamps will catch the limits.
  5870. (save-excursion
  5871. (setq todo-state (org-get-todo-state))
  5872. (setq donep (member todo-state org-done-keywords))
  5873. (if (and donep org-agenda-skip-timestamp-if-done)
  5874. (throw :skip t))
  5875. (setq marker (org-agenda-new-marker (point))
  5876. category (org-get-category))
  5877. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5878. (throw :skip nil)
  5879. (goto-char (match-beginning 0))
  5880. (setq hdmarker (org-agenda-new-marker (point))
  5881. inherited-tags
  5882. (or (eq org-agenda-show-inherited-tags 'always)
  5883. (and (listp org-agenda-show-inherited-tags)
  5884. (memq 'agenda org-agenda-show-inherited-tags))
  5885. (and (eq org-agenda-show-inherited-tags t)
  5886. (or (eq org-agenda-use-tag-inheritance t)
  5887. (memq 'agenda org-agenda-use-tag-inheritance))))
  5888. tags (org-get-tags-at nil (not inherited-tags)))
  5889. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5890. (looking-at "\\*+[ \t]+\\(.*\\)")
  5891. (setq head (match-string 1))
  5892. (let ((remove-re
  5893. (if org-agenda-remove-timeranges-from-blocks
  5894. (concat
  5895. "<" (regexp-quote s1) ".*?>"
  5896. "--"
  5897. "<" (regexp-quote s2) ".*?>")
  5898. nil)))
  5899. (setq txt (org-agenda-format-item
  5900. (format
  5901. (nth (if (= d1 d2) 0 1)
  5902. org-agenda-timerange-leaders)
  5903. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5904. head level category tags
  5905. (cond ((and (= d1 d0) (= d2 d0))
  5906. (concat "<" start-time ">--<" end-time ">"))
  5907. ((= d1 d0)
  5908. (concat "<" start-time ">"))
  5909. ((= d2 d0)
  5910. (concat "<" end-time ">")))
  5911. remove-re))))
  5912. (org-add-props txt props
  5913. 'org-marker marker 'org-hd-marker hdmarker
  5914. 'type "block" 'date date
  5915. 'level level
  5916. 'todo-state todo-state
  5917. 'priority (org-get-priority txt))
  5918. (push txt ee))))
  5919. (goto-char pos)))
  5920. ;; Sort the entries by expiration date.
  5921. (nreverse ee)))
  5922. ;;; Agenda presentation and sorting
  5923. (defvar org-prefix-has-time nil
  5924. "A flag, set by `org-compile-prefix-format'.
  5925. The flag is set if the currently compiled format contains a `%t'.")
  5926. (defvar org-prefix-has-tag nil
  5927. "A flag, set by `org-compile-prefix-format'.
  5928. The flag is set if the currently compiled format contains a `%T'.")
  5929. (defvar org-prefix-has-effort nil
  5930. "A flag, set by `org-compile-prefix-format'.
  5931. The flag is set if the currently compiled format contains a `%e'.")
  5932. (defvar org-prefix-has-breadcrumbs nil
  5933. "A flag, set by `org-compile-prefix-format'.
  5934. The flag is set if the currently compiled format contains a `%b'.")
  5935. (defvar org-prefix-category-length nil
  5936. "Used by `org-compile-prefix-format' to remember the category field width.")
  5937. (defvar org-prefix-category-max-length nil
  5938. "Used by `org-compile-prefix-format' to remember the category field width.")
  5939. (defun org-agenda-get-category-icon (category)
  5940. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5941. (cl-dolist (entry org-agenda-category-icon-alist)
  5942. (when (string-match-p (car entry) category)
  5943. (if (listp (cadr entry))
  5944. (cl-return (cadr entry))
  5945. (cl-return (apply #'create-image (cdr entry)))))))
  5946. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5947. remove-re habitp)
  5948. "Format TXT to be inserted into the agenda buffer.
  5949. In particular, add the prefix and corresponding text properties.
  5950. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5951. LEVEL may be a string to replace the `%l' specifier.
  5952. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5953. category taken from local variable or file name. It will replace the `%c'
  5954. specifier in the format.
  5955. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5956. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5957. When DOTIME is a string, this string is searched for a time before TXT is.
  5958. TAGS can be the tags of the headline.
  5959. Any match of REMOVE-RE will be removed from TXT."
  5960. ;; We keep the org-prefix-* variable values along with a compiled
  5961. ;; formatter, so that multiple agendas existing at the same time do
  5962. ;; not step on each other toes.
  5963. ;;
  5964. ;; It was inconvenient to make these variables buffer local in
  5965. ;; Agenda buffers, because this function expects to be called with
  5966. ;; the buffer where item comes from being current, and not agenda
  5967. ;; buffer
  5968. (let* ((bindings (car org-prefix-format-compiled))
  5969. (formatter (cadr org-prefix-format-compiled)))
  5970. (cl-loop for (var value) in bindings
  5971. do (set var value))
  5972. (save-match-data
  5973. ;; Diary entries sometimes have extra whitespace at the beginning
  5974. (setq txt (org-trim txt))
  5975. ;; Fix the tags part in txt
  5976. (setq txt (org-agenda-fix-displayed-tags
  5977. txt tags
  5978. org-agenda-show-inherited-tags
  5979. org-agenda-hide-tags-regexp))
  5980. (let* ((category (or category
  5981. (if buffer-file-name
  5982. (file-name-sans-extension
  5983. (file-name-nondirectory buffer-file-name))
  5984. "")))
  5985. (category-icon (org-agenda-get-category-icon category))
  5986. (category-icon (if category-icon
  5987. (propertize " " 'display category-icon)
  5988. ""))
  5989. (effort (and (not (string= txt ""))
  5990. (get-text-property 1 'effort txt)))
  5991. ;; time, tag, effort are needed for the eval of the prefix format
  5992. (tag (if tags (nth (1- (length tags)) tags) ""))
  5993. (time-grid-trailing-characters (nth 2 org-agenda-time-grid))
  5994. time
  5995. (ts (if dotime (concat
  5996. (if (stringp dotime) dotime "")
  5997. (and org-agenda-search-headline-for-time txt))))
  5998. (time-of-day (and dotime (org-get-time-of-day ts)))
  5999. stamp plain s0 s1 s2 rtn srp l
  6000. duration breadcrumbs)
  6001. (and (derived-mode-p 'org-mode) buffer-file-name
  6002. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6003. (when (and dotime time-of-day)
  6004. ;; Extract starting and ending time and move them to prefix
  6005. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6006. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6007. (setq s0 (match-string 0 ts)
  6008. srp (and stamp (match-end 3))
  6009. s1 (match-string (if plain 1 2) ts)
  6010. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6011. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6012. ;; them, we might want to remove them there to avoid duplication.
  6013. ;; The user can turn this off with a variable.
  6014. (if (and org-prefix-has-time
  6015. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6016. (string-match (concat (regexp-quote s0) " *") txt)
  6017. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6018. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6019. (= (match-beginning 0) 0)
  6020. t))
  6021. (setq txt (replace-match "" nil nil txt))))
  6022. ;; Normalize the time(s) to 24 hour
  6023. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  6024. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  6025. ;; Try to set s2 if s1 and
  6026. ;; `org-agenda-default-appointment-duration' are set
  6027. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6028. (setq s2
  6029. (org-duration-from-minutes
  6030. (+ (org-duration-to-minutes s1 t)
  6031. org-agenda-default-appointment-duration)
  6032. nil t)))
  6033. ;; Compute the duration
  6034. (when s2
  6035. (setq duration (- (org-duration-to-minutes s2)
  6036. (org-duration-to-minutes s1)))))
  6037. (when (string-match "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$" txt)
  6038. ;; Tags are in the string
  6039. (if (or (eq org-agenda-remove-tags t)
  6040. (and org-agenda-remove-tags
  6041. org-prefix-has-tag))
  6042. (setq txt (replace-match "" t t txt))
  6043. (setq txt (replace-match
  6044. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6045. (match-string 2 txt))
  6046. t t txt))))
  6047. (when remove-re
  6048. (while (string-match remove-re txt)
  6049. (setq txt (replace-match "" t t txt))))
  6050. ;; Set org-heading property on `txt' to mark the start of the
  6051. ;; heading.
  6052. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6053. ;; Prepare the variables needed in the eval of the compiled format
  6054. (if org-prefix-has-breadcrumbs
  6055. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6056. (let ((s (org-display-outline-path nil nil "->" t)))
  6057. (if (eq "" s) "" (concat s "->"))))))
  6058. (setq time (cond (s2 (concat
  6059. (org-agenda-time-of-day-to-ampm-maybe s1)
  6060. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6061. (if org-agenda-timegrid-use-ampm " ")))
  6062. (s1 (concat
  6063. (org-agenda-time-of-day-to-ampm-maybe s1)
  6064. (if org-agenda-timegrid-use-ampm
  6065. (concat time-grid-trailing-characters " ")
  6066. time-grid-trailing-characters)))
  6067. (t ""))
  6068. extra (or (and (not habitp) extra) "")
  6069. category (if (symbolp category) (symbol-name category) category)
  6070. level (or level ""))
  6071. (if (string-match org-bracket-link-regexp category)
  6072. (progn
  6073. (setq l (if (match-end 3)
  6074. (- (match-end 3) (match-beginning 3))
  6075. (- (match-end 1) (match-beginning 1))))
  6076. (when (< l (or org-prefix-category-length 0))
  6077. (setq category (copy-sequence category))
  6078. (org-add-props category nil
  6079. 'extra-space (make-string
  6080. (- org-prefix-category-length l 1) ?\ ))))
  6081. (if (and org-prefix-category-max-length
  6082. (>= (length category) org-prefix-category-max-length))
  6083. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6084. ;; Evaluate the compiled format
  6085. (setq rtn (concat (eval formatter) txt))
  6086. ;; And finally add the text properties
  6087. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6088. (org-add-props rtn nil
  6089. 'org-category category
  6090. 'tags (mapcar 'org-downcase-keep-props tags)
  6091. 'org-highest-priority org-highest-priority
  6092. 'org-lowest-priority org-lowest-priority
  6093. 'time-of-day time-of-day
  6094. 'duration duration
  6095. 'breadcrumbs breadcrumbs
  6096. 'txt txt
  6097. 'level level
  6098. 'time time
  6099. 'extra extra
  6100. 'format org-prefix-format-compiled
  6101. 'dotime dotime)))))
  6102. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6103. "Remove tags string from TXT, and add a modified list of tags.
  6104. The modified list may contain inherited tags, and tags matched by
  6105. `org-agenda-hide-tags-regexp' will be removed."
  6106. (when (or add-inherited hide-re)
  6107. (if (string-match "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$" txt)
  6108. (setq txt (substring txt 0 (match-beginning 0))))
  6109. (setq tags
  6110. (delq nil
  6111. (mapcar (lambda (tg)
  6112. (if (or (and hide-re (string-match hide-re tg))
  6113. (and (not add-inherited)
  6114. (get-text-property 0 'inherited tg)))
  6115. nil
  6116. tg))
  6117. tags)))
  6118. (when tags
  6119. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6120. i)
  6121. (setq txt (concat txt " :"
  6122. (mapconcat
  6123. (lambda (x)
  6124. (setq i (get-text-property 0 'inherited x))
  6125. (if (and have-i (not i))
  6126. (progn
  6127. (setq have-i nil)
  6128. (concat ":" x))
  6129. x))
  6130. tags ":")
  6131. (if have-i "::" ":"))))))
  6132. txt)
  6133. (defun org-downcase-keep-props (s)
  6134. (let ((props (text-properties-at 0 s)))
  6135. (setq s (downcase s))
  6136. (add-text-properties 0 (length s) props s)
  6137. s))
  6138. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6139. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6140. "Add a time-grid for agenda items which need it.
  6141. LIST is the list of agenda items formatted by `org-agenda-list'.
  6142. NDAYS is the span of the current agenda view.
  6143. TODAYP is t when the current agenda view is on today."
  6144. (catch 'exit
  6145. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6146. ((and todayp (member 'today (car org-agenda-time-grid))))
  6147. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6148. ((member 'weekly (car org-agenda-time-grid)))
  6149. (t (throw 'exit list)))
  6150. (let* ((have (delq nil (mapcar
  6151. (lambda (x) (get-text-property 1 'time-of-day x))
  6152. list)))
  6153. (string (nth 3 org-agenda-time-grid))
  6154. (gridtimes (nth 1 org-agenda-time-grid))
  6155. (req (car org-agenda-time-grid))
  6156. (remove (member 'remove-match req))
  6157. new time)
  6158. (if (and (member 'require-timed req) (not have))
  6159. ;; don't show empty grid
  6160. (throw 'exit list))
  6161. (while (setq time (pop gridtimes))
  6162. (unless (and remove (member time have))
  6163. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6164. (push (org-agenda-format-item
  6165. nil string nil "" nil
  6166. (concat (substring time 0 -2) ":" (substring time -2)))
  6167. new)
  6168. (put-text-property
  6169. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6170. (when (and todayp org-agenda-show-current-time-in-grid)
  6171. (push (org-agenda-format-item
  6172. nil org-agenda-current-time-string nil "" nil
  6173. (format-time-string "%H:%M "))
  6174. new)
  6175. (put-text-property
  6176. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6177. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6178. (append new list)
  6179. (append list new)))))
  6180. (defun org-compile-prefix-format (key)
  6181. "Compile the prefix format into a Lisp form that can be evaluated.
  6182. The resulting form and associated variable bindings is returned
  6183. and stored in the variable `org-prefix-format-compiled'."
  6184. (setq org-prefix-has-time nil
  6185. org-prefix-has-tag nil
  6186. org-prefix-category-length nil
  6187. org-prefix-has-effort nil
  6188. org-prefix-has-breadcrumbs nil)
  6189. (let ((s (cond
  6190. ((stringp org-agenda-prefix-format)
  6191. org-agenda-prefix-format)
  6192. ((assq key org-agenda-prefix-format)
  6193. (cdr (assq key org-agenda-prefix-format)))
  6194. (t " %-12:c%?-12t% s")))
  6195. (start 0)
  6196. varform vars var e c f opt)
  6197. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6198. s start)
  6199. (setq var (or (cdr (assoc (match-string 4 s)
  6200. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6201. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6202. 'eval)
  6203. c (or (match-string 3 s) "")
  6204. opt (match-beginning 1)
  6205. start (1+ (match-beginning 0)))
  6206. (if (eq var 'time) (setq org-prefix-has-time t))
  6207. (if (eq var 'tag) (setq org-prefix-has-tag t))
  6208. (if (eq var 'effort) (setq org-prefix-has-effort t))
  6209. (if (eq var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
  6210. (setq f (concat "%" (match-string 2 s) "s"))
  6211. (when (eq var 'category)
  6212. (setq org-prefix-category-length
  6213. (floor (abs (string-to-number (match-string 2 s)))))
  6214. (setq org-prefix-category-max-length
  6215. (let ((x (match-string 2 s)))
  6216. (save-match-data
  6217. (if (string-match "\\.[0-9]+" x)
  6218. (string-to-number (substring (match-string 0 x) 1)))))))
  6219. (if (eq var 'eval)
  6220. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6221. (if opt
  6222. (setq varform
  6223. `(if (or (equal "" ,var) (equal nil ,var))
  6224. ""
  6225. (format ,f (concat ,var ,c))))
  6226. (setq varform
  6227. `(format ,f (if (or (equal ,var "")
  6228. (equal ,var nil)) ""
  6229. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6230. (setq s (replace-match "%s" t nil s))
  6231. (push varform vars))
  6232. (setq vars (nreverse vars))
  6233. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6234. (setq org-prefix-format-compiled
  6235. (list
  6236. `((org-prefix-has-time ,org-prefix-has-time)
  6237. (org-prefix-has-tag ,org-prefix-has-tag)
  6238. (org-prefix-category-length ,org-prefix-category-length)
  6239. (org-prefix-has-effort ,org-prefix-has-effort)
  6240. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6241. `(format ,s ,@vars))))))
  6242. (defun org-set-sorting-strategy (key)
  6243. (if (symbolp (car org-agenda-sorting-strategy))
  6244. ;; the old format
  6245. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6246. (setq org-agenda-sorting-strategy-selected
  6247. (or (cdr (assq key org-agenda-sorting-strategy))
  6248. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6249. '(time-up category-keep priority-down)))))
  6250. (defun org-get-time-of-day (s &optional string mod24)
  6251. "Check string S for a time of day.
  6252. If found, return it as a military time number between 0 and 2400.
  6253. If not found, return nil.
  6254. The optional STRING argument forces conversion into a 5 character wide string
  6255. HH:MM."
  6256. (save-match-data
  6257. (when
  6258. (and
  6259. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6260. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6261. (not (eq (get-text-property 1 'face s) 'org-link)))
  6262. (let* ((h (string-to-number (match-string 1 s)))
  6263. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6264. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6265. (am-p (equal ampm "am"))
  6266. (h1 (cond ((not ampm) h)
  6267. ((= h 12) (if am-p 0 12))
  6268. (t (+ h (if am-p 0 12)))))
  6269. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6270. (mod h1 24) h1))
  6271. (t0 (+ (* 100 h2) m))
  6272. (t1 (concat (if (>= h1 24) "+" " ")
  6273. (if (and org-agenda-time-leading-zero
  6274. (< t0 1000)) "0" "")
  6275. (if (< t0 100) "0" "")
  6276. (if (< t0 10) "0" "")
  6277. (int-to-string t0))))
  6278. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6279. (defvar org-agenda-before-sorting-filter-function nil
  6280. "Function to be applied to agenda items prior to sorting.
  6281. Prior to sorting also means just before they are inserted into the agenda.
  6282. To aid sorting, you may revisit the original entries and add more text
  6283. properties which will later be used by the sorting functions.
  6284. The function should take a string argument, an agenda line.
  6285. It has access to the text properties in that line, which contain among
  6286. other things, the property `org-hd-marker' that points to the entry
  6287. where the line comes from. Note that not all lines going into the agenda
  6288. have this property, only most.
  6289. The function should return the modified string. It is probably best
  6290. to ONLY change text properties.
  6291. You can also use this function as a filter, by returning nil for lines
  6292. you don't want to have in the agenda at all. For this application, you
  6293. could bind the variable in the options section of a custom command.")
  6294. (defun org-agenda-finalize-entries (list &optional type)
  6295. "Sort, limit and concatenate the LIST of agenda items.
  6296. The optional argument TYPE tells the agenda type."
  6297. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6298. (cdr (assoc type org-agenda-max-effort)))
  6299. (t org-agenda-max-effort)))
  6300. (max-todo (cond ((listp org-agenda-max-todos)
  6301. (cdr (assoc type org-agenda-max-todos)))
  6302. (t org-agenda-max-todos)))
  6303. (max-tags (cond ((listp org-agenda-max-tags)
  6304. (cdr (assoc type org-agenda-max-tags)))
  6305. (t org-agenda-max-tags)))
  6306. (max-entries (cond ((listp org-agenda-max-entries)
  6307. (cdr (assoc type org-agenda-max-entries)))
  6308. (t org-agenda-max-entries))))
  6309. (when org-agenda-before-sorting-filter-function
  6310. (setq list
  6311. (delq nil
  6312. (mapcar
  6313. org-agenda-before-sorting-filter-function list))))
  6314. (setq list (mapcar 'org-agenda-highlight-todo list)
  6315. list (mapcar 'identity (sort list 'org-entries-lessp)))
  6316. (when max-effort
  6317. (setq list (org-agenda-limit-entries
  6318. list 'effort-minutes max-effort
  6319. (lambda (e) (or e (if org-sort-agenda-noeffort-is-high
  6320. 32767 -1))))))
  6321. (when max-todo
  6322. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6323. (when max-tags
  6324. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6325. (when max-entries
  6326. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6327. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  6328. (setq list (mapcar #'org-agenda--mark-blocked-entry list)))
  6329. (mapconcat 'identity list "\n")))
  6330. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6331. "Limit the number of agenda entries."
  6332. (let ((include (and limit (< limit 0))))
  6333. (if limit
  6334. (let ((fun (or fn (lambda (p) (if p 1))))
  6335. (lim 0))
  6336. (delq nil
  6337. (mapcar
  6338. (lambda (e)
  6339. (let ((pval (funcall
  6340. fun (get-text-property (1- (length e))
  6341. prop e))))
  6342. (if pval (setq lim (+ lim pval)))
  6343. (cond ((and pval (<= lim (abs limit))) e)
  6344. ((and include (not pval)) e))))
  6345. list)))
  6346. list)))
  6347. (defun org-agenda-limit-interactively (remove)
  6348. "In agenda, interactively limit entries to various maximums."
  6349. (interactive "P")
  6350. (if remove
  6351. (progn (setq org-agenda-max-entries nil
  6352. org-agenda-max-todos nil
  6353. org-agenda-max-tags nil
  6354. org-agenda-max-effort nil)
  6355. (org-agenda-redo))
  6356. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6357. (msg (cond ((= max ?E) "How many minutes? ")
  6358. ((= max ?e) "How many entries? ")
  6359. ((= max ?t) "How many TODO entries? ")
  6360. ((= max ?T) "How many tagged entries? ")
  6361. (t (user-error "Wrong input"))))
  6362. (num (string-to-number (read-from-minibuffer msg))))
  6363. (cond ((equal max ?e)
  6364. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6365. ((equal max ?t)
  6366. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6367. ((equal max ?T)
  6368. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6369. ((equal max ?E)
  6370. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  6371. (org-agenda-fit-window-to-buffer))
  6372. (defun org-agenda-highlight-todo (x)
  6373. (let ((org-done-keywords org-done-keywords-for-agenda)
  6374. (case-fold-search nil)
  6375. re)
  6376. (if (eq x 'line)
  6377. (save-excursion
  6378. (beginning-of-line 1)
  6379. (setq re (org-get-at-bol 'org-todo-regexp))
  6380. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6381. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6382. (add-text-properties (match-beginning 0) (match-end 1)
  6383. (list 'face (org-get-todo-face 1)))
  6384. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6385. (delete-region (match-beginning 1) (1- (match-end 0)))
  6386. (goto-char (match-beginning 1))
  6387. (insert (format org-agenda-todo-keyword-format s)))))
  6388. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6389. (setq re (get-text-property 0 'org-todo-regexp x))
  6390. (when (and re
  6391. ;; Test `pl' because if there's no heading content,
  6392. ;; there's no point matching to highlight. Note
  6393. ;; that if we didn't test `pl' first, and there
  6394. ;; happened to be no keyword from `org-todo-regexp'
  6395. ;; on this heading line, then the `equal' comparison
  6396. ;; afterwards would spuriously succeed in the case
  6397. ;; where `pl' is nil -- causing an args-out-of-range
  6398. ;; error when we try to add text properties to text
  6399. ;; that isn't there.
  6400. pl
  6401. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6402. x pl) pl))
  6403. (add-text-properties
  6404. (or (match-end 1) (match-end 0)) (match-end 0)
  6405. (list 'face (org-get-todo-face (match-string 2 x)))
  6406. x)
  6407. (when (match-end 1)
  6408. (setq x
  6409. (concat
  6410. (substring x 0 (match-end 1))
  6411. (format org-agenda-todo-keyword-format
  6412. (match-string 2 x))
  6413. ;; Remove `display' property as the icon could leak
  6414. ;; on the white space.
  6415. (org-add-props " " (org-plist-delete (text-properties-at 0 x)
  6416. 'display))
  6417. (substring x (match-end 3)))))))
  6418. x)))
  6419. (defsubst org-cmp-values (a b property)
  6420. "Compare the numeric value of text PROPERTY for string A and B."
  6421. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  6422. (pb (or (get-text-property (1- (length b)) property b) 0)))
  6423. (cond ((> pa pb) +1)
  6424. ((< pa pb) -1))))
  6425. (defsubst org-cmp-effort (a b)
  6426. "Compare the effort values of string A and B."
  6427. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6428. ;; `effort-minutes' property is not directly accessible from
  6429. ;; the strings, but is stored as a property in `txt'.
  6430. (ea (or (get-text-property
  6431. 0 'effort-minutes (get-text-property 0 'txt a))
  6432. def))
  6433. (eb (or (get-text-property
  6434. 0 'effort-minutes (get-text-property 0 'txt b))
  6435. def)))
  6436. (cond ((> ea eb) +1)
  6437. ((< ea eb) -1))))
  6438. (defsubst org-cmp-category (a b)
  6439. "Compare the string values of categories of strings A and B."
  6440. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  6441. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  6442. (cond ((string-lessp ca cb) -1)
  6443. ((string-lessp cb ca) +1))))
  6444. (defsubst org-cmp-todo-state (a b)
  6445. "Compare the todo states of strings A and B."
  6446. (let* ((ma (or (get-text-property 1 'org-marker a)
  6447. (get-text-property 1 'org-hd-marker a)))
  6448. (mb (or (get-text-property 1 'org-marker b)
  6449. (get-text-property 1 'org-hd-marker b)))
  6450. (fa (and ma (marker-buffer ma)))
  6451. (fb (and mb (marker-buffer mb)))
  6452. (todo-kwds
  6453. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6454. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6455. (ta (or (get-text-property 1 'todo-state a) ""))
  6456. (tb (or (get-text-property 1 'todo-state b) ""))
  6457. (la (- (length (member ta todo-kwds))))
  6458. (lb (- (length (member tb todo-kwds))))
  6459. (donepa (member ta org-done-keywords-for-agenda))
  6460. (donepb (member tb org-done-keywords-for-agenda)))
  6461. (cond ((and donepa (not donepb)) -1)
  6462. ((and (not donepa) donepb) +1)
  6463. ((< la lb) -1)
  6464. ((< lb la) +1))))
  6465. (defsubst org-cmp-alpha (a b)
  6466. "Compare the headlines, alphabetically."
  6467. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6468. (plb (text-property-any 0 (length b) 'org-heading t b))
  6469. (ta (and pla (substring a pla)))
  6470. (tb (and plb (substring b plb)))
  6471. (case-fold-search nil))
  6472. (when pla
  6473. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6474. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6475. (setq ta (substring ta (match-end 0))))
  6476. (setq ta (downcase ta)))
  6477. (when plb
  6478. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6479. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6480. (setq tb (substring tb (match-end 0))))
  6481. (setq tb (downcase tb)))
  6482. (cond ((not ta) +1)
  6483. ((not tb) -1)
  6484. ((string-lessp ta tb) -1)
  6485. ((string-lessp tb ta) +1))))
  6486. (defsubst org-cmp-tag (a b)
  6487. "Compare the string values of the first tags of A and B."
  6488. (let ((ta (car (last (get-text-property 1 'tags a))))
  6489. (tb (car (last (get-text-property 1 'tags b)))))
  6490. (cond ((not ta) +1)
  6491. ((not tb) -1)
  6492. ((string-lessp ta tb) -1)
  6493. ((string-lessp tb ta) +1))))
  6494. (defsubst org-cmp-time (a b)
  6495. "Compare the time-of-day values of strings A and B."
  6496. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6497. (ta (or (get-text-property 1 'time-of-day a) def))
  6498. (tb (or (get-text-property 1 'time-of-day b) def)))
  6499. (cond ((< ta tb) -1)
  6500. ((< tb ta) +1))))
  6501. (defsubst org-cmp-ts (a b type)
  6502. "Compare the timestamps values of entries A and B.
  6503. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  6504. \"timestamp_ia\", compare within each of these type. When TYPE
  6505. is the empty string, compare all timestamps without respect of
  6506. their type."
  6507. (let* ((def (if org-sort-agenda-notime-is-late most-positive-fixnum -1))
  6508. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  6509. (get-text-property 1 'ts-date a))
  6510. def))
  6511. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  6512. (get-text-property 1 'ts-date b))
  6513. def)))
  6514. (cond ((< ta tb) -1)
  6515. ((< tb ta) +1))))
  6516. (defsubst org-cmp-habit-p (a b)
  6517. "Compare the todo states of strings A and B."
  6518. (let ((ha (get-text-property 1 'org-habit-p a))
  6519. (hb (get-text-property 1 'org-habit-p b)))
  6520. (cond ((and ha (not hb)) -1)
  6521. ((and (not ha) hb) +1))))
  6522. (defun org-entries-lessp (a b)
  6523. "Predicate for sorting agenda entries."
  6524. ;; The following variables will be used when the form is evaluated.
  6525. ;; So even though the compiler complains, keep them.
  6526. (let* ((ss org-agenda-sorting-strategy-selected)
  6527. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6528. (org-cmp-ts a b "")))
  6529. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6530. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6531. (org-cmp-ts a b "scheduled")))
  6532. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6533. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6534. (org-cmp-ts a b "deadline")))
  6535. (deadline-down (if deadline-up (- deadline-up) nil))
  6536. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6537. (org-cmp-ts a b "timestamp_ia")))
  6538. (tsia-down (if tsia-up (- tsia-up) nil))
  6539. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6540. (org-cmp-ts a b "timestamp")))
  6541. (ts-down (if ts-up (- ts-up) nil))
  6542. (time-up (and (org-em 'time-up 'time-down ss)
  6543. (org-cmp-time a b)))
  6544. (time-down (if time-up (- time-up) nil))
  6545. (stats-up (and (org-em 'stats-up 'stats-down ss)
  6546. (org-cmp-values a b 'org-stats)))
  6547. (stats-down (if stats-up (- stats-up) nil))
  6548. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6549. (org-cmp-values a b 'priority)))
  6550. (priority-down (if priority-up (- priority-up) nil))
  6551. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6552. (org-cmp-effort a b)))
  6553. (effort-down (if effort-up (- effort-up) nil))
  6554. (category-up (and (or (org-em 'category-up 'category-down ss)
  6555. (memq 'category-keep ss))
  6556. (org-cmp-category a b)))
  6557. (category-down (if category-up (- category-up) nil))
  6558. (category-keep (if category-up +1 nil))
  6559. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6560. (org-cmp-tag a b)))
  6561. (tag-down (if tag-up (- tag-up) nil))
  6562. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6563. (org-cmp-todo-state a b)))
  6564. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6565. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6566. (org-cmp-habit-p a b)))
  6567. (habit-down (if habit-up (- habit-up) nil))
  6568. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6569. (org-cmp-alpha a b)))
  6570. (alpha-down (if alpha-up (- alpha-up) nil))
  6571. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6572. user-defined-up user-defined-down)
  6573. (if (and need-user-cmp org-agenda-cmp-user-defined
  6574. (functionp org-agenda-cmp-user-defined))
  6575. (setq user-defined-up
  6576. (funcall org-agenda-cmp-user-defined a b)
  6577. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6578. (cdr (assoc
  6579. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6580. '((-1 . t) (1 . nil) (nil . nil))))))
  6581. ;;; Agenda restriction lock
  6582. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6583. "Overlay to mark the headline to which agenda commands are restricted.")
  6584. (overlay-put org-agenda-restriction-lock-overlay
  6585. 'face 'org-agenda-restriction-lock)
  6586. (overlay-put org-agenda-restriction-lock-overlay
  6587. 'help-echo "Agendas are currently limited to this subtree.")
  6588. (delete-overlay org-agenda-restriction-lock-overlay)
  6589. (defun org-agenda-set-restriction-lock-from-agenda (arg)
  6590. "Set the restriction lock to the agenda item at point from within the agenda.
  6591. When called with a `\\[universal-argument]' prefix, restrict to
  6592. the file which contains the item.
  6593. Argument ARG is the prefix argument."
  6594. (interactive "P")
  6595. (unless (derived-mode-p 'org-agenda-mode)
  6596. (user-error "Not in an Org agenda buffer"))
  6597. (let* ((marker (or (org-get-at-bol 'org-marker)
  6598. (org-agenda-error)))
  6599. (buffer (marker-buffer marker))
  6600. (pos (marker-position marker)))
  6601. (with-current-buffer buffer
  6602. (goto-char pos)
  6603. (org-agenda-set-restriction-lock arg))))
  6604. ;;;###autoload
  6605. (defun org-agenda-set-restriction-lock (&optional type)
  6606. "Set restriction lock for agenda, to current subtree or file.
  6607. Restriction will be the file if TYPE is `file', or if type is the
  6608. universal prefix \\='(4), or if the cursor is before the first headline
  6609. in the file. Otherwise, restriction will be to the current subtree."
  6610. (interactive "P")
  6611. (org-agenda-remove-restriction-lock 'noupdate)
  6612. (and (equal type '(4)) (setq type 'file))
  6613. (setq type (cond
  6614. (type type)
  6615. ((org-at-heading-p) 'subtree)
  6616. ((condition-case nil (org-back-to-heading t) (error nil))
  6617. 'subtree)
  6618. (t 'file)))
  6619. (if (eq type 'subtree)
  6620. (progn
  6621. (setq org-agenda-restrict (current-buffer))
  6622. (setq org-agenda-overriding-restriction 'subtree)
  6623. (put 'org-agenda-files 'org-restrict
  6624. (list (buffer-file-name (buffer-base-buffer))))
  6625. (org-back-to-heading t)
  6626. (move-overlay org-agenda-restriction-lock-overlay
  6627. (point)
  6628. (if org-agenda-restriction-lock-highlight-subtree
  6629. (save-excursion (org-end-of-subtree t t) (point))
  6630. (point-at-eol)))
  6631. (move-marker org-agenda-restrict-begin (point))
  6632. (move-marker org-agenda-restrict-end
  6633. (save-excursion (org-end-of-subtree t t)))
  6634. (message "Locking agenda restriction to subtree"))
  6635. (put 'org-agenda-files 'org-restrict
  6636. (list (buffer-file-name (buffer-base-buffer))))
  6637. (setq org-agenda-restrict nil)
  6638. (setq org-agenda-overriding-restriction 'file)
  6639. (move-marker org-agenda-restrict-begin nil)
  6640. (move-marker org-agenda-restrict-end nil)
  6641. (message "Locking agenda restriction to file"))
  6642. (setq current-prefix-arg nil)
  6643. (org-agenda-maybe-redo))
  6644. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6645. "Remove the agenda restriction lock."
  6646. (interactive "P")
  6647. (delete-overlay org-agenda-restriction-lock-overlay)
  6648. (delete-overlay org-speedbar-restriction-lock-overlay)
  6649. (setq org-agenda-overriding-restriction nil)
  6650. (setq org-agenda-restrict nil)
  6651. (put 'org-agenda-files 'org-restrict nil)
  6652. (move-marker org-agenda-restrict-begin nil)
  6653. (move-marker org-agenda-restrict-end nil)
  6654. (setq current-prefix-arg nil)
  6655. (message "Agenda restriction lock removed")
  6656. (or noupdate (org-agenda-maybe-redo)))
  6657. (defun org-agenda-maybe-redo ()
  6658. "If there is any window showing the agenda view, update it."
  6659. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  6660. org-agenda-buffer-name)
  6661. t))
  6662. (w0 (selected-window)))
  6663. (when w
  6664. (select-window w)
  6665. (org-agenda-redo)
  6666. (select-window w0)
  6667. (if org-agenda-overriding-restriction
  6668. (message "Agenda view shifted to new %s restriction"
  6669. org-agenda-overriding-restriction)
  6670. (message "Agenda restriction lock removed")))))
  6671. ;;; Agenda commands
  6672. (defun org-agenda-check-type (error &rest types)
  6673. "Check if agenda buffer is of allowed type.
  6674. If ERROR is non-nil, throw an error, otherwise just return nil.
  6675. Allowed types are `agenda' `todo' `tags' `search'."
  6676. (cond ((not org-agenda-type)
  6677. (error "No Org agenda currently displayed"))
  6678. ((memq org-agenda-type types) t)
  6679. (error
  6680. (error "Not allowed in %s-type agenda buffers" org-agenda-type))
  6681. (t nil)))
  6682. (defun org-agenda-Quit ()
  6683. "Exit the agenda, killing the agenda buffer.
  6684. Like `org-agenda-quit', but kill the buffer even when
  6685. `org-agenda-sticky' is non-nil."
  6686. (interactive)
  6687. (org-agenda--quit))
  6688. (defun org-agenda-quit ()
  6689. "Exit the agenda.
  6690. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  6691. instead of killing it.
  6692. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  6693. the pre-agenda window configuration.
  6694. When column view is active, exit column view instead of the
  6695. agenda."
  6696. (interactive)
  6697. (org-agenda--quit org-agenda-sticky))
  6698. (defun org-agenda--quit (&optional bury)
  6699. (if org-agenda-columns-active
  6700. (org-columns-quit)
  6701. (let ((wconf org-agenda-pre-window-conf)
  6702. (buf (current-buffer))
  6703. (org-agenda-last-indirect-window
  6704. (and (eq org-indirect-buffer-display 'other-window)
  6705. org-agenda-last-indirect-buffer
  6706. (get-buffer-window org-agenda-last-indirect-buffer))))
  6707. (cond
  6708. ((eq org-agenda-window-setup 'other-frame)
  6709. (delete-frame))
  6710. ((and org-agenda-restore-windows-after-quit
  6711. wconf)
  6712. ;; Maybe restore the pre-agenda window configuration. Reset
  6713. ;; `org-agenda-pre-window-conf' before running
  6714. ;; `set-window-configuration', which loses the current buffer.
  6715. (setq org-agenda-pre-window-conf nil)
  6716. (set-window-configuration wconf))
  6717. (t
  6718. (when org-agenda-last-indirect-window
  6719. (delete-window org-agenda-last-indirect-window))
  6720. (and (not (eq org-agenda-window-setup 'current-window))
  6721. (not (one-window-p))
  6722. (delete-window))))
  6723. (if bury
  6724. ;; Set the agenda buffer as the current buffer instead of
  6725. ;; passing it as an argument to `bury-buffer' so that
  6726. ;; `bury-buffer' removes it from the window.
  6727. (with-current-buffer buf
  6728. (bury-buffer))
  6729. (kill-buffer buf)
  6730. (setq org-agenda-archives-mode nil
  6731. org-agenda-buffer nil)))))
  6732. (defun org-agenda-exit ()
  6733. "Exit the agenda, killing Org buffers loaded by the agenda.
  6734. Like `org-agenda-Quit', but kill any buffers that were created by
  6735. the agenda. Org buffers visited directly by the user will not be
  6736. touched. Also, exit the agenda even if it is in column view."
  6737. (interactive)
  6738. (when org-agenda-columns-active
  6739. (org-columns-quit))
  6740. (org-release-buffers org-agenda-new-buffers)
  6741. (setq org-agenda-new-buffers nil)
  6742. (org-agenda-Quit))
  6743. (defun org-agenda-kill-all-agenda-buffers ()
  6744. "Kill all buffers in `org-agenda-mode'.
  6745. This is used when toggling sticky agendas."
  6746. (interactive)
  6747. (let (blist)
  6748. (dolist (buf (buffer-list))
  6749. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6750. (push buf blist)))
  6751. (mapc 'kill-buffer blist)))
  6752. (defun org-agenda-execute (arg)
  6753. "Execute another agenda command, keeping same window.
  6754. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6755. in the agenda."
  6756. (interactive "P")
  6757. (let ((org-agenda-window-setup 'current-window))
  6758. (org-agenda arg)))
  6759. (defun org-agenda-redo (&optional all)
  6760. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6761. (interactive "P")
  6762. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6763. (cpa (unless (eq all t) current-prefix-arg))
  6764. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6765. (org-agenda-sticky nil)
  6766. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6767. org-agenda-buffer-name))
  6768. (org-agenda-keep-modes t)
  6769. (tag-filter org-agenda-tag-filter)
  6770. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6771. (top-hl-filter org-agenda-top-headline-filter)
  6772. (cat-filter org-agenda-category-filter)
  6773. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6774. (re-filter org-agenda-regexp-filter)
  6775. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  6776. (effort-filter org-agenda-effort-filter)
  6777. (effort-preset (get 'org-agenda-effort-filter :preset-filter))
  6778. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6779. (cols org-agenda-columns-active)
  6780. (line (org-current-line))
  6781. (window-line (- line (org-current-line (window-start))))
  6782. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6783. (redo-cmd (get-text-property p 'org-redo-cmd))
  6784. (last-args (get-text-property p 'org-last-args))
  6785. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6786. (org-agenda-overriding-cmd-arguments
  6787. (unless (eq all t)
  6788. (cond ((listp last-args)
  6789. (cons (or cpa (car last-args)) (cdr last-args)))
  6790. ((stringp last-args)
  6791. last-args))))
  6792. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6793. (put 'org-agenda-tag-filter :preset-filter nil)
  6794. (put 'org-agenda-category-filter :preset-filter nil)
  6795. (put 'org-agenda-regexp-filter :preset-filter nil)
  6796. (put 'org-agenda-effort-filter :preset-filter nil)
  6797. (and cols (org-columns-quit))
  6798. (message "Rebuilding agenda buffer...")
  6799. (if series-redo-cmd
  6800. (eval series-redo-cmd)
  6801. (org-let lprops redo-cmd))
  6802. (setq org-agenda-undo-list nil
  6803. org-agenda-pending-undo-list nil
  6804. org-agenda-tag-filter tag-filter
  6805. org-agenda-category-filter cat-filter
  6806. org-agenda-regexp-filter re-filter
  6807. org-agenda-effort-filter effort-filter
  6808. org-agenda-top-headline-filter top-hl-filter)
  6809. (message "Rebuilding agenda buffer...done")
  6810. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6811. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6812. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  6813. (put 'org-agenda-effort-filter :preset-filter effort-preset)
  6814. (let ((tag (or tag-filter tag-preset))
  6815. (cat (or cat-filter cat-preset))
  6816. (effort (or effort-filter effort-preset))
  6817. (re (or re-filter re-preset)))
  6818. (when tag (org-agenda-filter-apply tag 'tag t))
  6819. (when cat (org-agenda-filter-apply cat 'category))
  6820. (when effort (org-agenda-filter-apply effort 'effort))
  6821. (when re (org-agenda-filter-apply re 'regexp)))
  6822. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  6823. (and cols (called-interactively-p 'any) (org-agenda-columns))
  6824. (org-goto-line line)
  6825. (recenter window-line)))
  6826. (defun org-agenda-redo-all (&optional exhaustive)
  6827. "Rebuild all agenda views in the current buffer.
  6828. With a prefix argument, do so in all agenda buffers."
  6829. (interactive "P")
  6830. (if exhaustive
  6831. (dolist (buffer (buffer-list))
  6832. (with-current-buffer buffer
  6833. (when (derived-mode-p 'org-agenda-mode)
  6834. (org-agenda-redo t))))
  6835. (org-agenda-redo t)))
  6836. (defvar org-global-tags-completion-table nil)
  6837. (defvar org-agenda-filter-form nil)
  6838. (defvar org-agenda-filtered-by-category nil)
  6839. (defun org-agenda-filter-by-category (strip)
  6840. "Filter lines in the agenda buffer that have a specific category.
  6841. The category is that of the current line.
  6842. Without prefix argument, keep only the lines of that category.
  6843. With a prefix argument, exclude the lines of that category.
  6844. "
  6845. (interactive "P")
  6846. (if (and org-agenda-filtered-by-category
  6847. org-agenda-category-filter)
  6848. (org-agenda-filter-show-all-cat)
  6849. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  6850. (cond
  6851. ((and cat strip)
  6852. (org-agenda-filter-apply
  6853. (push (concat "-" cat) org-agenda-category-filter) 'category))
  6854. (cat
  6855. (org-agenda-filter-apply
  6856. (setq org-agenda-category-filter
  6857. (list (concat "+" cat))) 'category))
  6858. (t (error "No category at point"))))))
  6859. (defun org-find-top-headline (&optional pos)
  6860. "Find the topmost parent headline and return it.
  6861. POS when non-nil is the marker or buffer position to start the
  6862. search from."
  6863. (save-excursion
  6864. (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
  6865. (when pos (goto-char pos))
  6866. ;; Skip up to the topmost parent.
  6867. (while (org-up-heading-safe))
  6868. (ignore-errors (nth 4 (org-heading-components))))))
  6869. (defvar org-agenda-filtered-by-top-headline nil)
  6870. (defun org-agenda-filter-by-top-headline (strip)
  6871. "Keep only those lines that are descendants from the same top headline.
  6872. The top headline is that of the current line."
  6873. (interactive "P")
  6874. (if org-agenda-filtered-by-top-headline
  6875. (progn
  6876. (setq org-agenda-filtered-by-top-headline nil
  6877. org-agenda-top-headline-filter nil)
  6878. (org-agenda-filter-show-all-top-filter))
  6879. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  6880. (if toph (org-agenda-filter-top-headline-apply toph strip)
  6881. (error "No top-level headline at point")))))
  6882. (defvar org-agenda-regexp-filter nil)
  6883. (defun org-agenda-filter-by-regexp (strip)
  6884. "Filter agenda entries by a regular expression.
  6885. Regexp filters are cumulative.
  6886. With no prefix argument, keep entries matching the regexp.
  6887. With one prefix argument, filter out entries matching the regexp.
  6888. With two prefix arguments, remove the regexp filters."
  6889. (interactive "P")
  6890. (if (not (equal strip '(16)))
  6891. (let ((flt (concat (if (equal strip '(4)) "-" "+")
  6892. (read-from-minibuffer
  6893. (if (equal strip '(4))
  6894. "Filter out entries matching regexp: "
  6895. "Narrow to entries matching regexp: ")))))
  6896. (push flt org-agenda-regexp-filter)
  6897. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  6898. (org-agenda-filter-show-all-re)
  6899. (message "Regexp filter removed")))
  6900. (defvar org-agenda-effort-filter nil)
  6901. (defun org-agenda-filter-by-effort (strip)
  6902. "Filter agenda entries by effort.
  6903. With no prefix argument, keep entries matching the effort condition.
  6904. With one prefix argument, filter out entries matching the condition.
  6905. With two prefix arguments, remove the effort filters."
  6906. (interactive "P")
  6907. (cond
  6908. ((member strip '(nil 4))
  6909. (let* ((efforts (split-string
  6910. (or (cdr (assoc (concat org-effort-property "_ALL")
  6911. org-global-properties))
  6912. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
  6913. ;; XXX: the following handles only up to 10 different
  6914. ;; effort values.
  6915. (allowed-keys (if (null efforts) nil
  6916. (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
  6917. (number-sequence 1 (length efforts)))))
  6918. (op nil))
  6919. (while (not (memq op '(?< ?> ?=)))
  6920. (setq op (read-char-exclusive "Effort operator? (> = or <)")))
  6921. ;; Select appropriate duration. Ignore non-digit characters.
  6922. (let ((prompt
  6923. (apply #'format
  6924. (concat "Effort %c "
  6925. (mapconcat (lambda (s) (concat "[%d]" s))
  6926. efforts
  6927. " "))
  6928. op allowed-keys))
  6929. (eff -1))
  6930. (while (not (memq eff allowed-keys))
  6931. (message prompt)
  6932. (setq eff (- (read-char-exclusive) 48)))
  6933. (setq org-agenda-effort-filter
  6934. (list (concat (if strip "-" "+")
  6935. (char-to-string op)
  6936. ;; Numbering is 1 2 3 ... 9 0, but we want
  6937. ;; 0 1 2 ... 8 9.
  6938. (nth (mod (1- eff) 10) efforts)))))
  6939. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))
  6940. (t (org-agenda-filter-show-all-effort)
  6941. (message "Effort filter removed"))))
  6942. (defun org-agenda-filter-remove-all ()
  6943. "Remove all filters from the current agenda buffer."
  6944. (interactive)
  6945. (when org-agenda-tag-filter
  6946. (org-agenda-filter-show-all-tag))
  6947. (when org-agenda-category-filter
  6948. (org-agenda-filter-show-all-cat))
  6949. (when org-agenda-regexp-filter
  6950. (org-agenda-filter-show-all-re))
  6951. (when org-agenda-top-headline-filter
  6952. (org-agenda-filter-show-all-top-filter))
  6953. (when org-agenda-effort-filter
  6954. (org-agenda-filter-show-all-effort))
  6955. (org-agenda-finalize))
  6956. (defun org-agenda-filter-by-tag (arg &optional char exclude)
  6957. "Keep only those lines in the agenda buffer that have a specific tag.
  6958. The tag is selected with its fast selection letter, as configured.
  6959. With a `\\[universal-argument]' prefix, exclude the agenda search.
  6960. With a `\\[universal-argument] \\[universal-argument]' prefix, filter the literal tag, \
  6961. i.e. don't
  6962. filter on all its group members.
  6963. A lisp caller can specify CHAR. EXCLUDE means that the new tag
  6964. should be used to exclude the search - the interactive user can
  6965. also press `-' or `+' to switch between filtering and excluding."
  6966. (interactive "P")
  6967. (let* ((alist org-tag-alist-for-agenda)
  6968. (tag-chars (mapconcat
  6969. (lambda (x) (if (and (not (symbolp (car x)))
  6970. (cdr x))
  6971. (char-to-string (cdr x))
  6972. ""))
  6973. org-tag-alist-for-agenda ""))
  6974. (valid-char-list (append '(?\t ?\r ?/ ?. ?\s ?q)
  6975. (string-to-list tag-chars)))
  6976. (exclude (or exclude (equal arg '(4))))
  6977. (expand (not (equal arg '(16))))
  6978. (inhibit-read-only t)
  6979. (current org-agenda-tag-filter)
  6980. a n tag)
  6981. (unless char
  6982. (while (not (memq char valid-char-list))
  6983. (message
  6984. "%s by tag [%s ]:tag-char, [TAB]:tag, %s[/]:off, [+/-]:filter/exclude%s, [q]:quit"
  6985. (if exclude "Exclude" "Filter")
  6986. tag-chars
  6987. (if org-agenda-auto-exclude-function "[RET], " "")
  6988. (if expand "" ", no grouptag expand"))
  6989. (setq char (read-char-exclusive))
  6990. ;; Excluding or filtering down
  6991. (cond ((eq char ?-) (setq exclude t))
  6992. ((eq char ?+) (setq exclude nil)))))
  6993. (when (eq char ?\t)
  6994. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6995. (setq-local org-global-tags-completion-table
  6996. (org-global-tags-completion-table)))
  6997. (let ((completion-ignore-case t))
  6998. (setq tag (completing-read
  6999. "Tag: " org-global-tags-completion-table nil t))))
  7000. (cond
  7001. ((eq char ?\r)
  7002. (org-agenda-filter-show-all-tag)
  7003. (when org-agenda-auto-exclude-function
  7004. (setq org-agenda-tag-filter nil)
  7005. (dolist (tag (org-agenda-get-represented-tags))
  7006. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7007. (if modifier
  7008. (push modifier org-agenda-tag-filter))))
  7009. (if (not (null org-agenda-tag-filter))
  7010. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  7011. ((eq char ?/)
  7012. (org-agenda-filter-show-all-tag)
  7013. (when (get 'org-agenda-tag-filter :preset-filter)
  7014. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  7015. ((eq char ?.)
  7016. (setq org-agenda-tag-filter
  7017. (mapcar (lambda(tag) (concat "+" tag))
  7018. (org-get-at-bol 'tags)))
  7019. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7020. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  7021. ((or (eq char ?\s)
  7022. (setq a (rassoc char alist))
  7023. (and tag (setq a (cons tag nil))))
  7024. (org-agenda-filter-show-all-tag)
  7025. (setq tag (car a))
  7026. (setq org-agenda-tag-filter
  7027. (cons (concat (if exclude "-" "+") tag)
  7028. current))
  7029. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7030. (t (error "Invalid tag selection character %c" char)))))
  7031. (defun org-agenda-get-represented-tags ()
  7032. "Get a list of all tags currently represented in the agenda."
  7033. (let (p tags)
  7034. (save-excursion
  7035. (goto-char (point-min))
  7036. (while (setq p (next-single-property-change (point) 'tags))
  7037. (goto-char p)
  7038. (mapc (lambda (x) (add-to-list 'tags x))
  7039. (get-text-property (point) 'tags))))
  7040. tags))
  7041. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  7042. "Create the form that tests a line for agenda filter. Optional
  7043. argument EXPAND can be used for the TYPE tag and will expand the
  7044. tags in the FILTER if any of the tags in FILTER are grouptags."
  7045. (let (f f1)
  7046. (cond
  7047. ;; Tag filter
  7048. ((eq type 'tag)
  7049. (setq filter
  7050. (delete-dups
  7051. (append (get 'org-agenda-tag-filter :preset-filter)
  7052. filter)))
  7053. (dolist (x filter)
  7054. (let ((op (string-to-char x)))
  7055. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  7056. (setq x (list x)))
  7057. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  7058. (push f1 f))))
  7059. ;; Category filter
  7060. ((eq type 'category)
  7061. (setq filter
  7062. (delete-dups
  7063. (append (get 'org-agenda-category-filter :preset-filter)
  7064. filter)))
  7065. (dolist (x filter)
  7066. (if (equal "-" (substring x 0 1))
  7067. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  7068. (setq f1 (list 'equal (substring x 1) 'cat)))
  7069. (push f1 f)))
  7070. ;; Regexp filter
  7071. ((eq type 'regexp)
  7072. (setq filter
  7073. (delete-dups
  7074. (append (get 'org-agenda-regexp-filter :preset-filter)
  7075. filter)))
  7076. (dolist (x filter)
  7077. (if (equal "-" (substring x 0 1))
  7078. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  7079. (setq f1 (list 'string-match (substring x 1) 'txt)))
  7080. (push f1 f)))
  7081. ;; Effort filter
  7082. ((eq type 'effort)
  7083. (setq filter
  7084. (delete-dups
  7085. (append (get 'org-agenda-effort-filter :preset-filter)
  7086. filter)))
  7087. (dolist (x filter)
  7088. (push (org-agenda-filter-effort-form x) f))))
  7089. (cons 'and (nreverse f))))
  7090. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  7091. "Return a form associated to tag-expression TAGS.
  7092. Build a form testing a line for agenda filter for
  7093. tag-expressions. OP is an operator of type CHAR that allows the
  7094. function to set the right switches in the returned form."
  7095. (let (form)
  7096. ;; Any of the expressions can match if OP is +, all must match if
  7097. ;; the operator is -.
  7098. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  7099. (let* ((tag (substring x 1))
  7100. (f (cond
  7101. ((string= "" tag) '(not tags))
  7102. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  7103. ;; TAG is a regexp.
  7104. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  7105. (t (list 'member (downcase tag) 'tags)))))
  7106. (push (if (eq op ?-) (list 'not f) f) form)))))
  7107. (defun org-agenda-filter-effort-form (e)
  7108. "Return the form to compare the effort of the current line with what E says.
  7109. E looks like \"+<2:25\"."
  7110. (let (op)
  7111. (setq e (substring e 1))
  7112. (setq op (string-to-char e) e (substring e 1))
  7113. (setq op (cond ((equal op ?<) '<=)
  7114. ((equal op ?>) '>=)
  7115. ((equal op ??) op)
  7116. (t '=)))
  7117. (list 'org-agenda-compare-effort (list 'quote op)
  7118. (org-duration-to-minutes e))))
  7119. (defun org-agenda-compare-effort (op value)
  7120. "Compare the effort of the current line with VALUE, using OP.
  7121. If the line does not have an effort defined, return nil."
  7122. ;; `effort-minutes' property cannot be extracted directly from
  7123. ;; current line but is stored as a property in `txt'.
  7124. (let ((effort (get-text-property 0 'effort-minutes (org-get-at-bol 'txt))))
  7125. (funcall op
  7126. (or effort (if org-sort-agenda-noeffort-is-high 32767 -1))
  7127. value)))
  7128. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  7129. "Expand group tags in FILTER for the agenda.
  7130. When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
  7131. (if org-group-tags
  7132. (let ((case-fold-search t) rtn)
  7133. (mapc
  7134. (lambda (f)
  7135. (let (f0 dir)
  7136. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  7137. (setq dir (match-string 1 f) f0 (match-string 2 f))
  7138. (setq dir (if no-operator "" "+") f0 f))
  7139. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  7140. (org-tags-expand f0 t t))
  7141. rtn))))
  7142. filter)
  7143. (reverse rtn))
  7144. filter))
  7145. (defun org-agenda-filter-apply (filter type &optional expand)
  7146. "Set FILTER as the new agenda filter and apply it. Optional
  7147. argument EXPAND can be used for the TYPE tag and will expand the
  7148. tags in the FILTER if any of the tags in FILTER are grouptags."
  7149. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  7150. (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  7151. (let (tags cat txt)
  7152. (setq org-agenda-filter-form (org-agenda-filter-make-matcher filter type expand))
  7153. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  7154. ;; category is used as the filter:
  7155. (setq org-agenda-filtered-by-category
  7156. (and (eq type 'category)
  7157. (not (equal (substring (car filter) 0 1) "-"))))
  7158. (org-agenda-set-mode-name)
  7159. (save-excursion
  7160. (goto-char (point-min))
  7161. (while (not (eobp))
  7162. (if (org-get-at-bol 'org-marker)
  7163. (progn
  7164. (setq tags (org-get-at-bol 'tags)
  7165. cat (org-get-at-eol 'org-category 1)
  7166. txt (org-get-at-bol 'txt))
  7167. (if (not (eval org-agenda-filter-form))
  7168. (org-agenda-filter-hide-line type))
  7169. (beginning-of-line 2))
  7170. (beginning-of-line 2))))
  7171. (if (get-char-property (point) 'invisible)
  7172. (ignore-errors (org-agenda-previous-line)))))
  7173. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  7174. "Filter by top headline HL."
  7175. (org-agenda-set-mode-name)
  7176. (save-excursion
  7177. (goto-char (point-min))
  7178. (while (not (eobp))
  7179. (let* ((pos (org-get-at-bol 'org-hd-marker))
  7180. (tophl (and pos (org-find-top-headline pos))))
  7181. (if (and tophl (funcall (if negative 'identity 'not)
  7182. (string= hl tophl)))
  7183. (org-agenda-filter-hide-line 'top-headline)))
  7184. (beginning-of-line 2)))
  7185. (if (get-char-property (point) 'invisible)
  7186. (org-agenda-previous-line))
  7187. (setq org-agenda-top-headline-filter hl
  7188. org-agenda-filtered-by-top-headline t))
  7189. (defun org-agenda-filter-hide-line (type)
  7190. "Hide lines with TYPE in the agenda buffer."
  7191. (let* ((b (max (point-min) (1- (point-at-bol))))
  7192. (e (point-at-eol)))
  7193. (let ((inhibit-read-only t))
  7194. (add-text-properties
  7195. b e `(invisible org-filtered org-filter-type ,type)))))
  7196. (defun org-agenda-remove-filter (type)
  7197. (interactive)
  7198. "Remove filter of type TYPE from the agenda buffer."
  7199. (save-excursion
  7200. (goto-char (point-min))
  7201. (let ((inhibit-read-only t) pos)
  7202. (while (setq pos (text-property-any (point) (point-max) 'org-filter-type type))
  7203. (goto-char pos)
  7204. (remove-text-properties
  7205. (point) (next-single-property-change (point) 'org-filter-type)
  7206. `(invisible org-filtered org-filter-type ,type))))
  7207. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  7208. (setq org-agenda-filter-form nil)
  7209. (org-agenda-set-mode-name)
  7210. (org-agenda-finalize)))
  7211. (defun org-agenda-filter-show-all-tag nil
  7212. (org-agenda-remove-filter 'tag))
  7213. (defun org-agenda-filter-show-all-re nil
  7214. (org-agenda-remove-filter 'regexp))
  7215. (defun org-agenda-filter-show-all-effort nil
  7216. (org-agenda-remove-filter 'effort))
  7217. (defun org-agenda-filter-show-all-cat nil
  7218. (org-agenda-remove-filter 'category))
  7219. (defun org-agenda-filter-show-all-top-filter nil
  7220. (org-agenda-remove-filter 'top-headline))
  7221. (defun org-agenda-manipulate-query-add ()
  7222. "Manipulate the query by adding a search term with positive selection.
  7223. Positive selection means the term must be matched for selection of an entry."
  7224. (interactive)
  7225. (org-agenda-manipulate-query ?\[))
  7226. (defun org-agenda-manipulate-query-subtract ()
  7227. "Manipulate the query by adding a search term with negative selection.
  7228. Negative selection means term must not be matched for selection of an entry."
  7229. (interactive)
  7230. (org-agenda-manipulate-query ?\]))
  7231. (defun org-agenda-manipulate-query-add-re ()
  7232. "Manipulate the query by adding a search regexp with positive selection.
  7233. Positive selection means the regexp must match for selection of an entry."
  7234. (interactive)
  7235. (org-agenda-manipulate-query ?\{))
  7236. (defun org-agenda-manipulate-query-subtract-re ()
  7237. "Manipulate the query by adding a search regexp with negative selection.
  7238. Negative selection means regexp must not match for selection of an entry."
  7239. (interactive)
  7240. (org-agenda-manipulate-query ?\}))
  7241. (defun org-agenda-manipulate-query (char)
  7242. (cond
  7243. ((eq org-agenda-type 'agenda)
  7244. (let ((org-agenda-include-inactive-timestamps t))
  7245. (org-agenda-redo))
  7246. (message "Display now includes inactive timestamps as well"))
  7247. ((eq org-agenda-type 'search)
  7248. (org-add-to-string
  7249. 'org-agenda-query-string
  7250. (if org-agenda-last-search-view-search-was-boolean
  7251. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7252. (?\{ . " +{}") (?\} . " -{}"))))
  7253. " "))
  7254. (setq org-agenda-redo-command
  7255. (list 'org-search-view
  7256. (car (get-text-property (min (1- (point-max)) (point))
  7257. 'org-last-args))
  7258. org-agenda-query-string
  7259. (+ (length org-agenda-query-string)
  7260. (if (member char '(?\{ ?\})) 0 1))))
  7261. (set-register org-agenda-query-register org-agenda-query-string)
  7262. (let ((org-agenda-overriding-arguments
  7263. (cdr org-agenda-redo-command)))
  7264. (org-agenda-redo)))
  7265. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7266. org-agenda-type))))
  7267. (defun org-add-to-string (var string)
  7268. (set var (concat (symbol-value var) string)))
  7269. (defun org-agenda-goto-date (span)
  7270. "Jump to DATE in agenda."
  7271. (interactive "P")
  7272. (let* ((org-read-date-prefer-future
  7273. (eval org-agenda-jump-prefer-future))
  7274. (date (org-read-date))
  7275. (day (time-to-days (org-time-string-to-time date)))
  7276. (org-agenda-sticky-orig org-agenda-sticky)
  7277. (org-agenda-buffer-tmp-name (buffer-name))
  7278. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7279. (0-arg (or current-prefix-arg (car args)))
  7280. (2-arg (nth 2 args))
  7281. (with-hour-p (nth 4 org-agenda-redo-command))
  7282. (newcmd (list 'org-agenda-list 0-arg date
  7283. (org-agenda-span-to-ndays
  7284. 2-arg (org-time-string-to-absolute date))
  7285. with-hour-p))
  7286. (newargs (cdr newcmd))
  7287. (inhibit-read-only t)
  7288. org-agenda-sticky)
  7289. (if (not (org-agenda-check-type t 'agenda))
  7290. (error "Not available in non-agenda views")
  7291. (add-text-properties (point-min) (point-max)
  7292. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7293. (org-agenda-redo)
  7294. (goto-char (point-min))
  7295. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7296. (save-excursion (move-beginning-of-line 2) (eobp))))
  7297. (move-beginning-of-line 2))
  7298. (setq org-agenda-sticky org-agenda-sticky-orig
  7299. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7300. (defun org-agenda-goto-today ()
  7301. "Go to today."
  7302. (interactive)
  7303. (org-agenda-check-type t 'agenda)
  7304. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7305. (curspan (nth 2 args))
  7306. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7307. (cond
  7308. (tdpos (goto-char tdpos))
  7309. ((eq org-agenda-type 'agenda)
  7310. (let* ((sd (org-agenda-compute-starting-span
  7311. (org-today) (or curspan org-agenda-span)))
  7312. (org-agenda-overriding-arguments args))
  7313. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7314. (org-agenda-redo)
  7315. (org-agenda-find-same-or-today-or-agenda)))
  7316. (t (error "Cannot find today")))))
  7317. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7318. (goto-char
  7319. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7320. (text-property-any (point-min) (point-max) 'org-today t)
  7321. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7322. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7323. (org-agenda-backward-block))
  7324. (point-min))))
  7325. (defun org-agenda-backward-block ()
  7326. "Move backward by one agenda block."
  7327. (interactive)
  7328. (org-agenda-forward-block 'backward))
  7329. (defun org-agenda-forward-block (&optional backward)
  7330. "Move forward by one agenda block.
  7331. When optional argument BACKWARD is set, go backward"
  7332. (interactive)
  7333. (cond ((not (derived-mode-p 'org-agenda-mode))
  7334. (user-error
  7335. "Cannot execute this command outside of org-agenda-mode buffers"))
  7336. ((looking-at (if backward "\\`" "\\'"))
  7337. (message "Already at the %s block" (if backward "first" "last")))
  7338. (t (let ((pos (prog1 (point)
  7339. (ignore-errors (if backward (backward-char 1)
  7340. (move-end-of-line 1)))))
  7341. (f (if backward
  7342. 'previous-single-property-change
  7343. 'next-single-property-change))
  7344. moved dest)
  7345. (while (and (setq dest (funcall
  7346. f (point) 'org-agenda-structural-header))
  7347. (not (get-text-property
  7348. (point) 'org-agenda-structural-header)))
  7349. (setq moved t)
  7350. (goto-char dest))
  7351. (if moved (move-beginning-of-line 1)
  7352. (goto-char (if backward (point-min) (point-max)))
  7353. (move-beginning-of-line 1)
  7354. (message "No %s block" (if backward "previous" "further")))))))
  7355. (defun org-agenda-later (arg)
  7356. "Go forward in time by the current span.
  7357. With prefix ARG, go forward that many times the current span."
  7358. (interactive "p")
  7359. (org-agenda-check-type t 'agenda)
  7360. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7361. (span (or (nth 2 args) org-agenda-current-span))
  7362. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7363. (greg (calendar-gregorian-from-absolute sd))
  7364. (cnt (org-get-at-bol 'org-day-cnt))
  7365. greg2)
  7366. (cond
  7367. ((numberp span)
  7368. (setq sd (+ (* span arg) sd)))
  7369. ((eq span 'day)
  7370. (setq sd (+ arg sd)))
  7371. ((eq span 'week)
  7372. (setq sd (+ (* 7 arg) sd)))
  7373. ((eq span 'fortnight)
  7374. (setq sd (+ (* 14 arg) sd)))
  7375. ((eq span 'month)
  7376. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7377. sd (calendar-absolute-from-gregorian greg2))
  7378. (setcar greg2 (1+ (car greg2))))
  7379. ((eq span 'year)
  7380. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7381. sd (calendar-absolute-from-gregorian greg2))
  7382. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7383. (t
  7384. (setq sd (+ (* span arg) sd))))
  7385. (let ((org-agenda-overriding-cmd
  7386. ;; `cmd' may have been set by `org-agenda-run-series' which
  7387. ;; uses `org-agenda-overriding-cmd' to decide whether
  7388. ;; overriding is allowed for `cmd'
  7389. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7390. (org-agenda-overriding-arguments
  7391. (list (car args) sd span)))
  7392. (org-agenda-redo)
  7393. (org-agenda-find-same-or-today-or-agenda cnt))))
  7394. (defun org-agenda-earlier (arg)
  7395. "Go backward in time by the current span.
  7396. With prefix ARG, go backward that many times the current span."
  7397. (interactive "p")
  7398. (org-agenda-later (- arg)))
  7399. (defun org-agenda-view-mode-dispatch ()
  7400. "Call one of the view mode commands."
  7401. (interactive)
  7402. (message "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  7403. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7404. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7405. (pcase (read-char-exclusive)
  7406. (?\ (call-interactively 'org-agenda-reset-view))
  7407. (?d (call-interactively 'org-agenda-day-view))
  7408. (?w (call-interactively 'org-agenda-week-view))
  7409. (?t (call-interactively 'org-agenda-fortnight-view))
  7410. (?m (call-interactively 'org-agenda-month-view))
  7411. (?y (call-interactively 'org-agenda-year-view))
  7412. (?l (call-interactively 'org-agenda-log-mode))
  7413. (?L (org-agenda-log-mode '(4)))
  7414. (?c (org-agenda-log-mode 'clockcheck))
  7415. ((or ?F ?f) (call-interactively 'org-agenda-follow-mode))
  7416. (?a (call-interactively 'org-agenda-archives-mode))
  7417. (?A (org-agenda-archives-mode 'files))
  7418. ((or ?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7419. ((or ?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7420. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7421. (?D (call-interactively 'org-agenda-toggle-diary))
  7422. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7423. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7424. (org-agenda-check-type t 'agenda)
  7425. (org-agenda-redo))
  7426. (message "Display now includes inactive timestamps as well"))
  7427. (?q (message "Abort"))
  7428. (key (user-error "Invalid key: %s" key))))
  7429. (defun org-agenda-reset-view ()
  7430. "Switch to default view for agenda."
  7431. (interactive)
  7432. (org-agenda-change-time-span org-agenda-span))
  7433. (defun org-agenda-day-view (&optional day-of-month)
  7434. "Switch to daily view for agenda.
  7435. With argument DAY-OF-MONTH, switch to that day of the month."
  7436. (interactive "P")
  7437. (org-agenda-change-time-span 'day day-of-month))
  7438. (defun org-agenda-week-view (&optional iso-week)
  7439. "Switch to weekly view for agenda.
  7440. With argument ISO-WEEK, switch to the corresponding ISO week.
  7441. If ISO-WEEK has more then 2 digits, only the last two encode
  7442. the week. Any digits before this encode a year. So 200712
  7443. means week 12 of year 2007. Years ranging from 70 years ago
  7444. to 30 years in the future can also be written as 2-digit years."
  7445. (interactive "P")
  7446. (org-agenda-change-time-span 'week iso-week))
  7447. (defun org-agenda-fortnight-view (&optional iso-week)
  7448. "Switch to fortnightly view for agenda.
  7449. With argument ISO-WEEK, switch to the corresponding ISO week.
  7450. If ISO-WEEK has more then 2 digits, only the last two encode
  7451. the week. Any digits before this encode a year. So 200712
  7452. means week 12 of year 2007. Years ranging from 70 years ago
  7453. to 30 years in the future can also be written as 2-digit years."
  7454. (interactive "P")
  7455. (org-agenda-change-time-span 'fortnight iso-week))
  7456. (defun org-agenda-month-view (&optional month)
  7457. "Switch to monthly view for agenda.
  7458. With argument MONTH, switch to that month. If MONTH has more
  7459. then 2 digits, only the last two encode the month. Any digits
  7460. before this encode a year. So 200712 means December year 2007.
  7461. Years ranging from 70 years ago to 30 years in the future can
  7462. also be written as 2-digit years."
  7463. (interactive "P")
  7464. (org-agenda-change-time-span 'month month))
  7465. (defun org-agenda-year-view (&optional year)
  7466. "Switch to yearly view for agenda.
  7467. With argument YEAR, switch to that year. Years ranging from 70
  7468. years ago to 30 years in the future can also be written as
  7469. 2-digit years."
  7470. (interactive "P")
  7471. (when year
  7472. (setq year (org-small-year-to-year year)))
  7473. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7474. (org-agenda-change-time-span 'year year)
  7475. (error "Abort")))
  7476. (defun org-agenda-change-time-span (span &optional n)
  7477. "Change the agenda view to SPAN.
  7478. SPAN may be `day', `week', `fortnight', `month', `year'."
  7479. (org-agenda-check-type t 'agenda)
  7480. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7481. (curspan (nth 2 args)))
  7482. (if (and (not n) (equal curspan span))
  7483. (error "Viewing span is already \"%s\"" span))
  7484. (let* ((sd (or (org-get-at-bol 'day)
  7485. (nth 1 args)
  7486. org-starting-day))
  7487. (sd (org-agenda-compute-starting-span sd span n))
  7488. (org-agenda-overriding-cmd
  7489. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7490. (org-agenda-overriding-arguments
  7491. (list (car args) sd span)))
  7492. (org-agenda-redo)
  7493. (org-agenda-find-same-or-today-or-agenda))
  7494. (org-agenda-set-mode-name)
  7495. (message "Switched to %s view" span)))
  7496. (defun org-agenda-compute-starting-span (sd span &optional n)
  7497. "Compute starting date for agenda.
  7498. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  7499. is a cons cell with the starting date and the number of days,
  7500. so that the date SD will be in that range."
  7501. (let* ((greg (calendar-gregorian-from-absolute sd))
  7502. (dg (nth 1 greg))
  7503. (mg (car greg))
  7504. (yg (nth 2 greg)))
  7505. (cond
  7506. ((eq span 'day)
  7507. (when n
  7508. (setq sd (+ (calendar-absolute-from-gregorian
  7509. (list mg 1 yg))
  7510. n -1))))
  7511. ((or (eq span 'week) (eq span 'fortnight))
  7512. (let* ((nt (calendar-day-of-week
  7513. (calendar-gregorian-from-absolute sd)))
  7514. (d (if org-agenda-start-on-weekday
  7515. (- nt org-agenda-start-on-weekday)
  7516. 0))
  7517. y1)
  7518. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7519. (when n
  7520. (require 'cal-iso)
  7521. (when (> n 99)
  7522. (setq y1 (org-small-year-to-year (/ n 100))
  7523. n (mod n 100)))
  7524. (setq sd
  7525. (calendar-iso-to-absolute
  7526. (list n 1
  7527. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7528. ((eq span 'month)
  7529. (let (y1)
  7530. (when (and n (> n 99))
  7531. (setq y1 (org-small-year-to-year (/ n 100))
  7532. n (mod n 100)))
  7533. (setq sd (calendar-absolute-from-gregorian
  7534. (list (or n mg) 1 (or y1 yg))))))
  7535. ((eq span 'year)
  7536. (setq sd (calendar-absolute-from-gregorian
  7537. (list 1 1 (or n yg))))))
  7538. sd))
  7539. (defun org-agenda-next-date-line (&optional arg)
  7540. "Jump to the next line indicating a date in agenda buffer."
  7541. (interactive "p")
  7542. (org-agenda-check-type t 'agenda)
  7543. (beginning-of-line 1)
  7544. ;; This does not work if user makes date format that starts with a blank
  7545. (if (looking-at "^\\S-") (forward-char 1))
  7546. (if (not (re-search-forward "^\\S-" nil t arg))
  7547. (progn
  7548. (backward-char 1)
  7549. (error "No next date after this line in this buffer")))
  7550. (goto-char (match-beginning 0)))
  7551. (defun org-agenda-previous-date-line (&optional arg)
  7552. "Jump to the previous line indicating a date in agenda buffer."
  7553. (interactive "p")
  7554. (org-agenda-check-type t 'agenda)
  7555. (beginning-of-line 1)
  7556. (if (not (re-search-backward "^\\S-" nil t arg))
  7557. (error "No previous date before this line in this buffer")))
  7558. ;; Initialize the highlight
  7559. (defvar org-hl (make-overlay 1 1))
  7560. (overlay-put org-hl 'face 'highlight)
  7561. (defun org-highlight (begin end &optional buffer)
  7562. "Highlight a region with overlay."
  7563. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7564. (defun org-unhighlight ()
  7565. "Detach overlay INDEX."
  7566. (delete-overlay org-hl))
  7567. (defun org-unhighlight-once ()
  7568. "Remove the highlight from its position, and this function from the hook."
  7569. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7570. (org-unhighlight))
  7571. (defvar org-agenda-pre-follow-window-conf nil)
  7572. (defun org-agenda-follow-mode ()
  7573. "Toggle follow mode in an agenda buffer."
  7574. (interactive)
  7575. (unless org-agenda-follow-mode
  7576. (setq org-agenda-pre-follow-window-conf
  7577. (current-window-configuration)))
  7578. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7579. (unless org-agenda-follow-mode
  7580. (set-window-configuration org-agenda-pre-follow-window-conf))
  7581. (org-agenda-set-mode-name)
  7582. (org-agenda-do-context-action)
  7583. (message "Follow mode is %s"
  7584. (if org-agenda-follow-mode "on" "off")))
  7585. (defun org-agenda-entry-text-mode (&optional arg)
  7586. "Toggle entry text mode in an agenda buffer."
  7587. (interactive "P")
  7588. (if (or org-agenda-tag-filter
  7589. org-agenda-category-filter
  7590. org-agenda-regexp-filter
  7591. org-agenda-top-headline-filter)
  7592. (user-error "Can't show entry text in filtered views")
  7593. (setq org-agenda-entry-text-mode (or (integerp arg)
  7594. (not org-agenda-entry-text-mode)))
  7595. (org-agenda-entry-text-hide)
  7596. (and org-agenda-entry-text-mode
  7597. (let ((org-agenda-entry-text-maxlines
  7598. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7599. (org-agenda-entry-text-show)))
  7600. (org-agenda-set-mode-name)
  7601. (message "Entry text mode is %s%s"
  7602. (if org-agenda-entry-text-mode "on" "off")
  7603. (if (not org-agenda-entry-text-mode) ""
  7604. (format " (maximum number of lines is %d)"
  7605. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7606. (defun org-agenda-clockreport-mode ()
  7607. "Toggle clocktable mode in an agenda buffer."
  7608. (interactive)
  7609. (org-agenda-check-type t 'agenda)
  7610. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  7611. (setq org-agenda-start-with-clockreport-mode org-agenda-clockreport-mode)
  7612. (org-agenda-set-mode-name)
  7613. (org-agenda-redo)
  7614. (message "Clocktable mode is %s"
  7615. (if org-agenda-clockreport-mode "on" "off")))
  7616. (defun org-agenda-log-mode (&optional special)
  7617. "Toggle log mode in an agenda buffer.
  7618. With argument SPECIAL, show all possible log items, not only the ones
  7619. configured in `org-agenda-log-mode-items'.
  7620. With a `\\[universal-argument] \\[universal-argument]' prefix, show *only* \
  7621. log items, nothing else."
  7622. (interactive "P")
  7623. (org-agenda-check-type t 'agenda)
  7624. (setq org-agenda-show-log
  7625. (cond
  7626. ((equal special '(16)) 'only)
  7627. ((eq special 'clockcheck)
  7628. (if (eq org-agenda-show-log 'clockcheck)
  7629. nil 'clockcheck))
  7630. (special '(closed clock state))
  7631. (t (not org-agenda-show-log))))
  7632. (setq org-agenda-start-with-log-mode org-agenda-show-log)
  7633. (org-agenda-set-mode-name)
  7634. (org-agenda-redo)
  7635. (message "Log mode is %s" (if org-agenda-show-log "on" "off")))
  7636. (defun org-agenda-archives-mode (&optional with-files)
  7637. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7638. When called with a prefix argument, include all archive files as well."
  7639. (interactive "P")
  7640. (setq org-agenda-archives-mode
  7641. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7642. (org-agenda-set-mode-name)
  7643. (org-agenda-redo)
  7644. (message
  7645. "%s"
  7646. (cond
  7647. ((eq org-agenda-archives-mode nil)
  7648. "No archives are included")
  7649. ((eq org-agenda-archives-mode 'trees)
  7650. (format "Trees with :%s: tag are included" org-archive-tag))
  7651. ((eq org-agenda-archives-mode t)
  7652. (format "Trees with :%s: tag and all active archive files are included"
  7653. org-archive-tag)))))
  7654. (defun org-agenda-toggle-diary ()
  7655. "Toggle diary inclusion in an agenda buffer."
  7656. (interactive)
  7657. (org-agenda-check-type t 'agenda)
  7658. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7659. (org-agenda-redo)
  7660. (org-agenda-set-mode-name)
  7661. (message "Diary inclusion turned %s"
  7662. (if org-agenda-include-diary "on" "off")))
  7663. (defun org-agenda-toggle-deadlines ()
  7664. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7665. (interactive)
  7666. (org-agenda-check-type t 'agenda)
  7667. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7668. (org-agenda-redo)
  7669. (org-agenda-set-mode-name)
  7670. (message "Deadlines inclusion turned %s"
  7671. (if org-agenda-include-deadlines "on" "off")))
  7672. (defun org-agenda-toggle-time-grid ()
  7673. "Toggle time grid in an agenda buffer."
  7674. (interactive)
  7675. (org-agenda-check-type t 'agenda)
  7676. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7677. (org-agenda-redo)
  7678. (org-agenda-set-mode-name)
  7679. (message "Time-grid turned %s"
  7680. (if org-agenda-use-time-grid "on" "off")))
  7681. (defun org-agenda-set-mode-name ()
  7682. "Set the mode name to indicate all the small mode settings."
  7683. (setq mode-name
  7684. (list "Org-Agenda"
  7685. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7686. " "
  7687. '(:eval (org-agenda-span-name org-agenda-current-span))
  7688. (if org-agenda-follow-mode " Follow" "")
  7689. (if org-agenda-entry-text-mode " ETxt" "")
  7690. (if org-agenda-include-diary " Diary" "")
  7691. (if org-agenda-include-deadlines " Ddl" "")
  7692. (if org-agenda-use-time-grid " Grid" "")
  7693. (if (and (boundp 'org-habit-show-habits)
  7694. org-habit-show-habits) " Habit" "")
  7695. (cond
  7696. ((consp org-agenda-show-log) " LogAll")
  7697. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7698. (org-agenda-show-log " Log")
  7699. (t ""))
  7700. (if (or org-agenda-category-filter
  7701. (get 'org-agenda-category-filter :preset-filter))
  7702. '(:eval (propertize
  7703. (concat " <"
  7704. (mapconcat
  7705. 'identity
  7706. (append
  7707. (get 'org-agenda-category-filter :preset-filter)
  7708. org-agenda-category-filter)
  7709. "")
  7710. ">")
  7711. 'face 'org-agenda-filter-category
  7712. 'help-echo "Category used in filtering")) "")
  7713. (if (or org-agenda-tag-filter
  7714. (get 'org-agenda-tag-filter :preset-filter))
  7715. '(:eval (propertize
  7716. (concat " {"
  7717. (mapconcat
  7718. 'identity
  7719. (append
  7720. (get 'org-agenda-tag-filter :preset-filter)
  7721. org-agenda-tag-filter)
  7722. "")
  7723. "}")
  7724. 'face 'org-agenda-filter-tags
  7725. 'help-echo "Tags used in filtering")) "")
  7726. (if (or org-agenda-effort-filter
  7727. (get 'org-agenda-effort-filter :preset-filter))
  7728. '(:eval (propertize
  7729. (concat " {"
  7730. (mapconcat
  7731. 'identity
  7732. (append
  7733. (get 'org-agenda-effort-filter :preset-filter)
  7734. org-agenda-effort-filter)
  7735. "")
  7736. "}")
  7737. 'face 'org-agenda-filter-effort
  7738. 'help-echo "Effort conditions used in filtering")) "")
  7739. (if (or org-agenda-regexp-filter
  7740. (get 'org-agenda-regexp-filter :preset-filter))
  7741. '(:eval (propertize
  7742. (concat " ["
  7743. (mapconcat
  7744. 'identity
  7745. (append
  7746. (get 'org-agenda-regexp-filter :preset-filter)
  7747. org-agenda-regexp-filter)
  7748. "")
  7749. "]")
  7750. 'face 'org-agenda-filter-regexp
  7751. 'help-echo "Regexp used in filtering")) "")
  7752. (if org-agenda-archives-mode
  7753. (if (eq org-agenda-archives-mode t)
  7754. " Archives"
  7755. (format " :%s:" org-archive-tag))
  7756. "")
  7757. (if org-agenda-clockreport-mode " Clock" "")))
  7758. (force-mode-line-update))
  7759. (defun org-agenda-update-agenda-type ()
  7760. "Update the agenda type after each command."
  7761. (setq org-agenda-type
  7762. (or (get-text-property (point) 'org-agenda-type)
  7763. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7764. (defun org-agenda-next-line ()
  7765. "Move cursor to the next line, and show if follow mode is active."
  7766. (interactive)
  7767. (call-interactively 'next-line)
  7768. (org-agenda-do-context-action))
  7769. (defun org-agenda-previous-line ()
  7770. "Move cursor to the previous line, and show if follow-mode is active."
  7771. (interactive)
  7772. (call-interactively 'previous-line)
  7773. (org-agenda-do-context-action))
  7774. (defun org-agenda-next-item (n)
  7775. "Move cursor to next agenda item."
  7776. (interactive "p")
  7777. (let ((col (current-column)))
  7778. (dotimes (c n)
  7779. (when (next-single-property-change (point-at-eol) 'org-marker)
  7780. (move-end-of-line 1)
  7781. (goto-char (next-single-property-change (point) 'org-marker))))
  7782. (org-move-to-column col))
  7783. (org-agenda-do-context-action))
  7784. (defun org-agenda-previous-item (n)
  7785. "Move cursor to next agenda item."
  7786. (interactive "p")
  7787. (dotimes (c n)
  7788. (let ((col (current-column))
  7789. (goto (save-excursion
  7790. (move-end-of-line 0)
  7791. (previous-single-property-change (point) 'org-marker))))
  7792. (if goto (goto-char goto))
  7793. (org-move-to-column col)))
  7794. (org-agenda-do-context-action))
  7795. (defun org-agenda-do-context-action ()
  7796. "Show outline path and, maybe, follow mode window."
  7797. (let ((m (org-get-at-bol 'org-marker)))
  7798. (when (and (markerp m) (marker-buffer m))
  7799. (and org-agenda-follow-mode
  7800. (if org-agenda-follow-indirect
  7801. (org-agenda-tree-to-indirect-buffer nil)
  7802. (org-agenda-show)))
  7803. (and org-agenda-show-outline-path
  7804. (org-with-point-at m (org-display-outline-path t))))))
  7805. (defun org-agenda-show-tags ()
  7806. "Show the tags applicable to the current item."
  7807. (interactive)
  7808. (let* ((tags (org-get-at-bol 'tags)))
  7809. (if tags
  7810. (message "Tags are :%s:"
  7811. (org-no-properties (mapconcat 'identity tags ":")))
  7812. (message "No tags associated with this line"))))
  7813. (defun org-agenda-goto (&optional highlight)
  7814. "Go to the entry at point in the corresponding Org file."
  7815. (interactive)
  7816. (let* ((marker (or (org-get-at-bol 'org-marker)
  7817. (org-agenda-error)))
  7818. (buffer (marker-buffer marker))
  7819. (pos (marker-position marker)))
  7820. (switch-to-buffer-other-window buffer)
  7821. (widen)
  7822. (push-mark)
  7823. (goto-char pos)
  7824. (when (derived-mode-p 'org-mode)
  7825. (org-show-context 'agenda)
  7826. (recenter (/ (window-height) 2))
  7827. (org-back-to-heading t)
  7828. (let ((case-fold-search nil))
  7829. (when (re-search-forward org-complex-heading-regexp nil t)
  7830. (goto-char (match-beginning 4)))))
  7831. (run-hooks 'org-agenda-after-show-hook)
  7832. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7833. (defvar org-agenda-after-show-hook nil
  7834. "Normal hook run after an item has been shown from the agenda.
  7835. Point is in the buffer where the item originated.")
  7836. (defun org-agenda-kill ()
  7837. "Kill the entry or subtree belonging to the current agenda entry."
  7838. (interactive)
  7839. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7840. (let* ((bufname-orig (buffer-name))
  7841. (marker (or (org-get-at-bol 'org-marker)
  7842. (org-agenda-error)))
  7843. (buffer (marker-buffer marker))
  7844. (pos (marker-position marker))
  7845. (type (org-get-at-bol 'type))
  7846. dbeg dend (n 0) conf)
  7847. (org-with-remote-undo buffer
  7848. (with-current-buffer buffer
  7849. (save-excursion
  7850. (goto-char pos)
  7851. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7852. (setq dbeg (progn (org-back-to-heading t) (point))
  7853. dend (org-end-of-subtree t t))
  7854. (setq dbeg (point-at-bol)
  7855. dend (min (point-max) (1+ (point-at-eol)))))
  7856. (goto-char dbeg)
  7857. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7858. (setq conf (or (eq t org-agenda-confirm-kill)
  7859. (and (numberp org-agenda-confirm-kill)
  7860. (> n org-agenda-confirm-kill))))
  7861. (and conf
  7862. (not (y-or-n-p
  7863. (format "Delete entry with %d lines in buffer \"%s\"? "
  7864. n (buffer-name buffer))))
  7865. (error "Abort"))
  7866. (let ((org-agenda-buffer-name bufname-orig))
  7867. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7868. (with-current-buffer buffer (delete-region dbeg dend))
  7869. (message "Agenda item and source killed"))))
  7870. (defvar org-archive-default-command) ; defined in org-archive.el
  7871. (defun org-agenda-archive-default ()
  7872. "Archive the entry or subtree belonging to the current agenda entry."
  7873. (interactive)
  7874. (require 'org-archive)
  7875. (org-agenda-archive-with org-archive-default-command))
  7876. (defun org-agenda-archive-default-with-confirmation ()
  7877. "Archive the entry or subtree belonging to the current agenda entry."
  7878. (interactive)
  7879. (require 'org-archive)
  7880. (org-agenda-archive-with org-archive-default-command 'confirm))
  7881. (defun org-agenda-archive ()
  7882. "Archive the entry or subtree belonging to the current agenda entry."
  7883. (interactive)
  7884. (org-agenda-archive-with 'org-archive-subtree))
  7885. (defun org-agenda-archive-to-archive-sibling ()
  7886. "Move the entry to the archive sibling."
  7887. (interactive)
  7888. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7889. (defun org-agenda-archive-with (cmd &optional confirm)
  7890. "Move the entry to the archive sibling."
  7891. (interactive)
  7892. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7893. (let* ((bufname-orig (buffer-name))
  7894. (marker (or (org-get-at-bol 'org-marker)
  7895. (org-agenda-error)))
  7896. (buffer (marker-buffer marker))
  7897. (pos (marker-position marker)))
  7898. (org-with-remote-undo buffer
  7899. (with-current-buffer buffer
  7900. (if (derived-mode-p 'org-mode)
  7901. (if (and confirm
  7902. (not (y-or-n-p "Archive this subtree or entry? ")))
  7903. (error "Abort")
  7904. (save-window-excursion
  7905. (goto-char pos)
  7906. (let ((org-agenda-buffer-name bufname-orig))
  7907. (org-remove-subtree-entries-from-agenda))
  7908. (org-back-to-heading t)
  7909. (funcall cmd)))
  7910. (error "Archiving works only in Org files"))))))
  7911. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7912. "Remove all lines in the agenda that correspond to a given subtree.
  7913. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7914. If this information is not given, the function uses the tree at point."
  7915. (let ((buf (or buf (current-buffer))) m p)
  7916. (save-excursion
  7917. (unless (and beg end)
  7918. (org-back-to-heading t)
  7919. (setq beg (point))
  7920. (org-end-of-subtree t)
  7921. (setq end (point)))
  7922. (set-buffer (get-buffer org-agenda-buffer-name))
  7923. (save-excursion
  7924. (goto-char (point-max))
  7925. (beginning-of-line 1)
  7926. (while (not (bobp))
  7927. (when (and (setq m (org-get-at-bol 'org-marker))
  7928. (equal buf (marker-buffer m))
  7929. (setq p (marker-position m))
  7930. (>= p beg)
  7931. (< p end))
  7932. (let ((inhibit-read-only t))
  7933. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7934. (beginning-of-line 0))))))
  7935. (defun org-agenda-refile (&optional goto rfloc no-update)
  7936. "Refile the item at point.
  7937. When called with `\\[universal-argument] \\[universal-argument]', \
  7938. go to the location of the last
  7939. refiled item.
  7940. When called with `\\[universal-argument] \\[universal-argument] \
  7941. \\[universal-argument]' prefix or when GOTO is 0, clear
  7942. the refile cache.
  7943. RFLOC can be a refile location obtained in a different way.
  7944. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  7945. (interactive "P")
  7946. (cond
  7947. ((member goto '(0 (64)))
  7948. (org-refile-cache-clear))
  7949. ((equal goto '(16))
  7950. (org-refile-goto-last-stored))
  7951. (t
  7952. (let* ((buffer-orig (buffer-name))
  7953. (marker (or (org-get-at-bol 'org-hd-marker)
  7954. (org-agenda-error)))
  7955. (buffer (marker-buffer marker))
  7956. (pos (marker-position marker))
  7957. (rfloc (or rfloc
  7958. (org-refile-get-location
  7959. (if goto "Goto" "Refile to") buffer
  7960. org-refile-allow-creating-parent-nodes))))
  7961. (with-current-buffer buffer
  7962. (org-with-wide-buffer
  7963. (goto-char marker)
  7964. (let ((org-agenda-buffer-name buffer-orig))
  7965. (org-remove-subtree-entries-from-agenda))
  7966. (org-refile goto buffer rfloc))))
  7967. (unless no-update (org-agenda-redo)))))
  7968. (defun org-agenda-open-link (&optional arg)
  7969. "Open the link(s) in the current entry, if any.
  7970. This looks for a link in the displayed line in the agenda.
  7971. It also looks at the text of the entry itself."
  7972. (interactive "P")
  7973. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7974. (org-get-at-bol 'org-marker)))
  7975. (buffer (and marker (marker-buffer marker)))
  7976. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  7977. (lkall (and buffer (org-offer-links-in-entry
  7978. buffer marker arg prefix)))
  7979. (lk0 (car lkall))
  7980. (lk (if (stringp lk0) (list lk0) lk0))
  7981. (lkend (cdr lkall))
  7982. trg)
  7983. (cond
  7984. ((and buffer lk)
  7985. (mapcar (lambda(l)
  7986. (with-current-buffer buffer
  7987. (setq trg (and (string-match org-bracket-link-regexp l)
  7988. (match-string 1 l)))
  7989. (if (or (not trg) (string-match org-any-link-re trg))
  7990. (org-with-wide-buffer
  7991. (goto-char marker)
  7992. (when (search-forward l nil lkend)
  7993. (goto-char (match-beginning 0))
  7994. (org-open-at-point)))
  7995. ;; This is an internal link, widen the buffer
  7996. (switch-to-buffer-other-window buffer)
  7997. (widen)
  7998. (goto-char marker)
  7999. (when (search-forward l nil lkend)
  8000. (goto-char (match-beginning 0))
  8001. (org-open-at-point)))))
  8002. lk))
  8003. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  8004. (save-excursion
  8005. (beginning-of-line 1)
  8006. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  8007. (org-open-link-from-string (match-string 1)))
  8008. (t (message "No link to open here")))))
  8009. (defun org-agenda-copy-local-variable (var)
  8010. "Get a variable from a referenced buffer and install it here."
  8011. (let ((m (org-get-at-bol 'org-marker)))
  8012. (when (and m (buffer-live-p (marker-buffer m)))
  8013. (set (make-local-variable var)
  8014. (with-current-buffer (marker-buffer m)
  8015. (symbol-value var))))))
  8016. (defun org-agenda-switch-to (&optional delete-other-windows)
  8017. "Go to the Org mode file which contains the item at point.
  8018. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  8019. displayed Org file fills the frame."
  8020. (interactive)
  8021. (if (and org-return-follows-link
  8022. (not (org-get-at-bol 'org-marker))
  8023. (org-in-regexp org-bracket-link-regexp))
  8024. (org-open-link-from-string (match-string 0))
  8025. (let* ((marker (or (org-get-at-bol 'org-marker)
  8026. (org-agenda-error)))
  8027. (buffer (marker-buffer marker))
  8028. (pos (marker-position marker)))
  8029. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  8030. (pop-to-buffer-same-window buffer)
  8031. (when delete-other-windows (delete-other-windows))
  8032. (widen)
  8033. (goto-char pos)
  8034. (when (derived-mode-p 'org-mode)
  8035. (org-show-context 'agenda)
  8036. (run-hooks 'org-agenda-after-show-hook)))))
  8037. (defun org-agenda-goto-mouse (ev)
  8038. "Go to the Org file which contains the item at the mouse click."
  8039. (interactive "e")
  8040. (mouse-set-point ev)
  8041. (org-agenda-goto))
  8042. (defun org-agenda-show (&optional full-entry)
  8043. "Display the Org file which contains the item at point.
  8044. With prefix argument FULL-ENTRY, make the entire entry visible
  8045. if it was hidden in the outline."
  8046. (interactive "P")
  8047. (let ((win (selected-window)))
  8048. (org-agenda-goto t)
  8049. (when full-entry (org-show-entry))
  8050. (select-window win)))
  8051. (defvar org-agenda-show-window nil)
  8052. (defun org-agenda-show-and-scroll-up (&optional arg)
  8053. "Display the Org file which contains the item at point.
  8054. When called repeatedly, scroll the window that is displaying the buffer.
  8055. With a `\\[universal-argument]' prefix, use `org-show-entry' instead of \
  8056. `outline-show-subtree'
  8057. to display the item, so that drawers and logbooks stay folded."
  8058. (interactive "P")
  8059. (let ((win (selected-window)))
  8060. (if (and (window-live-p org-agenda-show-window)
  8061. (eq this-command last-command))
  8062. (progn
  8063. (select-window org-agenda-show-window)
  8064. (ignore-errors (scroll-up)))
  8065. (org-agenda-goto t)
  8066. (if arg (org-show-entry) (outline-show-subtree))
  8067. (setq org-agenda-show-window (selected-window)))
  8068. (select-window win)))
  8069. (defun org-agenda-show-scroll-down ()
  8070. "Scroll down the window showing the agenda."
  8071. (interactive)
  8072. (let ((win (selected-window)))
  8073. (when (window-live-p org-agenda-show-window)
  8074. (select-window org-agenda-show-window)
  8075. (ignore-errors (scroll-down))
  8076. (select-window win))))
  8077. (defun org-agenda-show-1 (&optional more)
  8078. "Display the Org file which contains the item at point.
  8079. The prefix arg selects the amount of information to display:
  8080. 0 hide the subtree
  8081. 1 just show the entry according to defaults.
  8082. 2 show the children view
  8083. 3 show the subtree view
  8084. 4 show the entire subtree and any LOGBOOK drawers
  8085. 5 show the entire subtree and any drawers
  8086. With prefix argument FULL-ENTRY, make the entire entry visible
  8087. if it was hidden in the outline."
  8088. (interactive "p")
  8089. (let ((win (selected-window)))
  8090. (org-agenda-goto t)
  8091. (org-back-to-heading)
  8092. (set-window-start (selected-window) (point-at-bol))
  8093. (cond
  8094. ((= more 0)
  8095. (outline-hide-subtree)
  8096. (save-excursion
  8097. (org-back-to-heading)
  8098. (run-hook-with-args 'org-cycle-hook 'folded))
  8099. (message "Remote: FOLDED"))
  8100. ((and (called-interactively-p 'any) (= more 1))
  8101. (message "Remote: show with default settings"))
  8102. ((= more 2)
  8103. (outline-show-entry)
  8104. (org-show-children)
  8105. (save-excursion
  8106. (org-back-to-heading)
  8107. (run-hook-with-args 'org-cycle-hook 'children))
  8108. (message "Remote: CHILDREN"))
  8109. ((= more 3)
  8110. (outline-show-subtree)
  8111. (save-excursion
  8112. (org-back-to-heading)
  8113. (run-hook-with-args 'org-cycle-hook 'subtree))
  8114. (message "Remote: SUBTREE"))
  8115. ((= more 4)
  8116. (outline-show-subtree)
  8117. (save-excursion
  8118. (org-back-to-heading)
  8119. (org-cycle-hide-drawers 'subtree '("LOGBOOK")))
  8120. (message "Remote: SUBTREE AND LOGBOOK"))
  8121. ((> more 4)
  8122. (outline-show-subtree)
  8123. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8124. (select-window win)))
  8125. (defvar org-agenda-cycle-counter nil)
  8126. (defun org-agenda-cycle-show (&optional n)
  8127. "Show the current entry in another window, with default settings.
  8128. Default settings are taken from `org-show-context-detail'. When
  8129. use repeatedly in immediate succession, the remote entry will
  8130. cycle through visibility
  8131. children -> subtree -> folded
  8132. When called with a numeric prefix arg, that arg will be passed through to
  8133. `org-agenda-show-1'. For the interpretation of that argument, see the
  8134. docstring of `org-agenda-show-1'."
  8135. (interactive "P")
  8136. (if (integerp n)
  8137. (setq org-agenda-cycle-counter n)
  8138. (if (not (eq last-command this-command))
  8139. (setq org-agenda-cycle-counter 1)
  8140. (if (equal org-agenda-cycle-counter 0)
  8141. (setq org-agenda-cycle-counter 2)
  8142. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8143. (if (> org-agenda-cycle-counter 3)
  8144. (setq org-agenda-cycle-counter 0)))))
  8145. (org-agenda-show-1 org-agenda-cycle-counter))
  8146. (defun org-agenda-recenter (arg)
  8147. "Display the Org file which contains the item at point and recenter."
  8148. (interactive "P")
  8149. (let ((win (selected-window)))
  8150. (org-agenda-goto t)
  8151. (recenter arg)
  8152. (select-window win)))
  8153. (defun org-agenda-show-mouse (ev)
  8154. "Display the Org file which contains the item at the mouse click."
  8155. (interactive "e")
  8156. (mouse-set-point ev)
  8157. (org-agenda-show))
  8158. (defun org-agenda-check-no-diary ()
  8159. "Check if the entry is a diary link and abort if yes."
  8160. (if (org-get-at-bol 'org-agenda-diary-link)
  8161. (org-agenda-error)))
  8162. (defun org-agenda-error ()
  8163. "Throw an error when a command is not allowed in the agenda."
  8164. (user-error "Command not allowed in this line"))
  8165. (defun org-agenda-tree-to-indirect-buffer (arg)
  8166. "Show the subtree corresponding to the current entry in an indirect buffer.
  8167. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  8168. With a numerical prefix ARG, go up to this level and then take that tree.
  8169. With a negative numeric ARG, go up by this number of levels.
  8170. With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
  8171. i.e. don't use
  8172. the dedicated frame."
  8173. (interactive "P")
  8174. (if current-prefix-arg
  8175. (org-agenda-do-tree-to-indirect-buffer arg)
  8176. (let ((agenda-buffer (buffer-name))
  8177. (agenda-window (selected-window))
  8178. (indirect-window
  8179. (and org-last-indirect-buffer
  8180. (get-buffer-window org-last-indirect-buffer))))
  8181. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  8182. (unless (or (eq org-indirect-buffer-display 'new-frame)
  8183. (eq org-indirect-buffer-display 'dedicated-frame))
  8184. (unwind-protect
  8185. (unless (and indirect-window (window-live-p indirect-window))
  8186. (setq indirect-window (split-window agenda-window)))
  8187. (and indirect-window (select-window indirect-window))
  8188. (switch-to-buffer org-last-indirect-buffer :norecord)
  8189. (fit-window-to-buffer indirect-window)))
  8190. (select-window (get-buffer-window agenda-buffer))
  8191. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  8192. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  8193. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  8194. (org-agenda-check-no-diary)
  8195. (let* ((marker (or (org-get-at-bol 'org-marker)
  8196. (org-agenda-error)))
  8197. (buffer (marker-buffer marker))
  8198. (pos (marker-position marker)))
  8199. (with-current-buffer buffer
  8200. (save-excursion
  8201. (goto-char pos)
  8202. (funcall 'org-tree-to-indirect-buffer arg)))))
  8203. (defvar org-last-heading-marker (make-marker)
  8204. "Marker pointing to the headline that last changed its TODO state
  8205. by a remote command from the agenda.")
  8206. (defun org-agenda-todo-nextset ()
  8207. "Switch TODO entry to next sequence."
  8208. (interactive)
  8209. (org-agenda-todo 'nextset))
  8210. (defun org-agenda-todo-previousset ()
  8211. "Switch TODO entry to previous sequence."
  8212. (interactive)
  8213. (org-agenda-todo 'previousset))
  8214. (defun org-agenda-todo (&optional arg)
  8215. "Cycle TODO state of line at point, also in Org file.
  8216. This changes the line at point, all other lines in the agenda referring to
  8217. the same tree node, and the headline of the tree node in the Org file."
  8218. (interactive "P")
  8219. (org-agenda-check-no-diary)
  8220. (let* ((col (current-column))
  8221. (marker (or (org-get-at-bol 'org-marker)
  8222. (org-agenda-error)))
  8223. (buffer (marker-buffer marker))
  8224. (pos (marker-position marker))
  8225. (hdmarker (org-get-at-bol 'org-hd-marker))
  8226. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  8227. (inhibit-read-only t)
  8228. org-agenda-headline-snapshot-before-repeat newhead just-one)
  8229. (org-with-remote-undo buffer
  8230. (with-current-buffer buffer
  8231. (widen)
  8232. (goto-char pos)
  8233. (org-show-context 'agenda)
  8234. (let ((current-prefix-arg arg))
  8235. (call-interactively 'org-todo))
  8236. (and (bolp) (forward-char 1))
  8237. (setq newhead (org-get-heading))
  8238. (when (and (bound-and-true-p
  8239. org-agenda-headline-snapshot-before-repeat)
  8240. (not (equal org-agenda-headline-snapshot-before-repeat
  8241. newhead))
  8242. todayp)
  8243. (setq newhead org-agenda-headline-snapshot-before-repeat
  8244. just-one t))
  8245. (save-excursion
  8246. (org-back-to-heading)
  8247. (move-marker org-last-heading-marker (point))))
  8248. (beginning-of-line 1)
  8249. (save-window-excursion
  8250. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8251. (when (bound-and-true-p org-clock-out-when-done)
  8252. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  8253. newhead)
  8254. (org-agenda-unmark-clocking-task))
  8255. (org-move-to-column col)
  8256. (org-agenda-mark-clocking-task))))
  8257. (defun org-agenda-add-note (&optional arg)
  8258. "Add a time-stamped note to the entry at point."
  8259. (interactive "P")
  8260. (org-agenda-check-no-diary)
  8261. (let* ((marker (or (org-get-at-bol 'org-marker)
  8262. (org-agenda-error)))
  8263. (buffer (marker-buffer marker))
  8264. (pos (marker-position marker))
  8265. (hdmarker (org-get-at-bol 'org-hd-marker))
  8266. (inhibit-read-only t))
  8267. (with-current-buffer buffer
  8268. (widen)
  8269. (goto-char pos)
  8270. (org-show-context 'agenda)
  8271. (org-add-note))))
  8272. (defun org-agenda-change-all-lines (newhead hdmarker
  8273. &optional fixface just-this)
  8274. "Change all lines in the agenda buffer which match HDMARKER.
  8275. The new content of the line will be NEWHEAD (as modified by
  8276. `org-agenda-format-item'). HDMARKER is checked with
  8277. `equal' against all `org-hd-marker' text properties in the file.
  8278. If FIXFACE is non-nil, the face of each item is modified according to
  8279. the new TODO state.
  8280. If JUST-THIS is non-nil, change just the current line, not all.
  8281. If FORCE-TAGS is non nil, the car of it returns the new tags."
  8282. (let* ((inhibit-read-only t)
  8283. (line (org-current-line))
  8284. (org-agenda-buffer (current-buffer))
  8285. (thetags (with-current-buffer (marker-buffer hdmarker)
  8286. (org-with-wide-buffer
  8287. (goto-char hdmarker)
  8288. (org-get-tags-at))))
  8289. props m pl undone-face done-face finish new dotime level cat tags)
  8290. (save-excursion
  8291. (goto-char (point-max))
  8292. (beginning-of-line 1)
  8293. (while (not finish)
  8294. (setq finish (bobp))
  8295. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8296. (or (not just-this) (= (org-current-line) line))
  8297. (equal m hdmarker))
  8298. (setq props (text-properties-at (point))
  8299. dotime (org-get-at-bol 'dotime)
  8300. cat (org-get-at-eol 'org-category 1)
  8301. level (org-get-at-bol 'level)
  8302. tags thetags
  8303. new
  8304. (let ((org-prefix-format-compiled
  8305. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8306. org-prefix-format-compiled))
  8307. (extra (org-get-at-bol 'extra)))
  8308. (with-current-buffer (marker-buffer hdmarker)
  8309. (org-with-wide-buffer
  8310. (org-agenda-format-item extra newhead level cat tags dotime))))
  8311. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  8312. undone-face (org-get-at-bol 'undone-face)
  8313. done-face (org-get-at-bol 'done-face))
  8314. (beginning-of-line 1)
  8315. (cond
  8316. ((equal new "") (delete-region (point) (line-beginning-position 2)))
  8317. ((looking-at ".*")
  8318. ;; When replacing the whole line, preserve bulk mark
  8319. ;; overlay, if any.
  8320. (let ((mark (catch :overlay
  8321. (dolist (o (overlays-in (point) (+ 2 (point))))
  8322. (when (eq (overlay-get o 'type)
  8323. 'org-marked-entry-overlay)
  8324. (throw :overlay o))))))
  8325. (replace-match new t t)
  8326. (beginning-of-line)
  8327. (when mark (move-overlay mark (point) (+ 2 (point)))))
  8328. (add-text-properties (point-at-bol) (point-at-eol) props)
  8329. (when fixface
  8330. (add-text-properties
  8331. (point-at-bol) (point-at-eol)
  8332. (list 'face
  8333. (if org-last-todo-state-is-todo
  8334. undone-face done-face))))
  8335. (org-agenda-highlight-todo 'line)
  8336. (beginning-of-line 1))
  8337. (t (error "Line update did not work")))
  8338. (save-restriction
  8339. (narrow-to-region (point-at-bol) (point-at-eol))
  8340. (org-agenda-finalize)))
  8341. (beginning-of-line 0)))))
  8342. (defun org-agenda-align-tags (&optional line)
  8343. "Align all tags in agenda items to `org-agenda-tags-column'."
  8344. (let ((inhibit-read-only t)
  8345. (org-agenda-tags-column (if (eq 'auto org-agenda-tags-column)
  8346. (- (window-text-width))
  8347. org-agenda-tags-column))
  8348. l c)
  8349. (save-excursion
  8350. (goto-char (if line (point-at-bol) (point-min)))
  8351. (while (re-search-forward "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$"
  8352. (if line (point-at-eol) nil) t)
  8353. (add-text-properties
  8354. (match-beginning 2) (match-end 2)
  8355. (list 'face (delq nil (let ((prop (get-text-property
  8356. (match-beginning 2) 'face)))
  8357. (or (listp prop) (setq prop (list prop)))
  8358. (if (memq 'org-tag prop)
  8359. prop
  8360. (cons 'org-tag prop))))))
  8361. (setq l (- (match-end 2) (match-beginning 2))
  8362. c (if (< org-agenda-tags-column 0)
  8363. (- (abs org-agenda-tags-column) l)
  8364. org-agenda-tags-column))
  8365. (delete-region (match-beginning 1) (match-end 1))
  8366. (goto-char (match-beginning 1))
  8367. (insert (org-add-props
  8368. (make-string (max 1 (- c (current-column))) ?\ )
  8369. (plist-put (copy-sequence (text-properties-at (point)))
  8370. 'face nil))))
  8371. (goto-char (point-min))
  8372. (org-font-lock-add-tag-faces (point-max)))))
  8373. (defun org-agenda-priority-up ()
  8374. "Increase the priority of line at point, also in Org file."
  8375. (interactive)
  8376. (org-agenda-priority 'up))
  8377. (defun org-agenda-priority-down ()
  8378. "Decrease the priority of line at point, also in Org file."
  8379. (interactive)
  8380. (org-agenda-priority 'down))
  8381. (defun org-agenda-priority (&optional force-direction)
  8382. "Set the priority of line at point, also in Org file.
  8383. This changes the line at point, all other lines in the agenda referring to
  8384. the same tree node, and the headline of the tree node in the Org file.
  8385. Called with a universal prefix arg, show the priority instead of setting it."
  8386. (interactive "P")
  8387. (if (equal force-direction '(4))
  8388. (org-show-priority)
  8389. (unless org-enable-priority-commands
  8390. (error "Priority commands are disabled"))
  8391. (org-agenda-check-no-diary)
  8392. (let* ((col (current-column))
  8393. (marker (or (org-get-at-bol 'org-marker)
  8394. (org-agenda-error)))
  8395. (hdmarker (org-get-at-bol 'org-hd-marker))
  8396. (buffer (marker-buffer hdmarker))
  8397. (pos (marker-position hdmarker))
  8398. (inhibit-read-only t)
  8399. newhead)
  8400. (org-with-remote-undo buffer
  8401. (with-current-buffer buffer
  8402. (widen)
  8403. (goto-char pos)
  8404. (org-show-context 'agenda)
  8405. (funcall 'org-priority force-direction)
  8406. (end-of-line 1)
  8407. (setq newhead (org-get-heading)))
  8408. (org-agenda-change-all-lines newhead hdmarker)
  8409. (org-move-to-column col)))))
  8410. ;; FIXME: should fix the tags property of the agenda line.
  8411. (defun org-agenda-set-tags (&optional tag onoff)
  8412. "Set tags for the current headline."
  8413. (interactive)
  8414. (org-agenda-check-no-diary)
  8415. (if (and (org-region-active-p) (called-interactively-p 'any))
  8416. (call-interactively 'org-change-tag-in-region)
  8417. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8418. (org-agenda-error)))
  8419. (buffer (marker-buffer hdmarker))
  8420. (pos (marker-position hdmarker))
  8421. (inhibit-read-only t)
  8422. newhead)
  8423. (org-with-remote-undo buffer
  8424. (with-current-buffer buffer
  8425. (widen)
  8426. (goto-char pos)
  8427. (org-show-context 'agenda)
  8428. (if tag
  8429. (org-toggle-tag tag onoff)
  8430. (call-interactively 'org-set-tags))
  8431. (end-of-line 1)
  8432. (setq newhead (org-get-heading)))
  8433. (org-agenda-change-all-lines newhead hdmarker)
  8434. (beginning-of-line 1)))))
  8435. (defun org-agenda-set-property ()
  8436. "Set a property for the current headline."
  8437. (interactive)
  8438. (org-agenda-check-no-diary)
  8439. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8440. (org-agenda-error)))
  8441. (buffer (marker-buffer hdmarker))
  8442. (pos (marker-position hdmarker))
  8443. (inhibit-read-only t)
  8444. newhead)
  8445. (org-with-remote-undo buffer
  8446. (with-current-buffer buffer
  8447. (widen)
  8448. (goto-char pos)
  8449. (org-show-context 'agenda)
  8450. (call-interactively 'org-set-property)))))
  8451. (defun org-agenda-set-effort ()
  8452. "Set the effort property for the current headline."
  8453. (interactive)
  8454. (org-agenda-check-no-diary)
  8455. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8456. (org-agenda-error)))
  8457. (buffer (marker-buffer hdmarker))
  8458. (pos (marker-position hdmarker))
  8459. (inhibit-read-only t)
  8460. newhead)
  8461. (org-with-remote-undo buffer
  8462. (with-current-buffer buffer
  8463. (widen)
  8464. (goto-char pos)
  8465. (org-show-context 'agenda)
  8466. (call-interactively 'org-set-effort)
  8467. (end-of-line 1)
  8468. (setq newhead (org-get-heading)))
  8469. (org-agenda-change-all-lines newhead hdmarker))))
  8470. (defun org-agenda-toggle-archive-tag ()
  8471. "Toggle the archive tag for the current entry."
  8472. (interactive)
  8473. (org-agenda-check-no-diary)
  8474. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8475. (org-agenda-error)))
  8476. (buffer (marker-buffer hdmarker))
  8477. (pos (marker-position hdmarker))
  8478. (inhibit-read-only t)
  8479. newhead)
  8480. (org-with-remote-undo buffer
  8481. (with-current-buffer buffer
  8482. (widen)
  8483. (goto-char pos)
  8484. (org-show-context 'agenda)
  8485. (call-interactively 'org-toggle-archive-tag)
  8486. (end-of-line 1)
  8487. (setq newhead (org-get-heading)))
  8488. (org-agenda-change-all-lines newhead hdmarker)
  8489. (beginning-of-line 1))))
  8490. (defun org-agenda-do-date-later (arg)
  8491. (interactive "P")
  8492. (cond
  8493. ((or (equal arg '(16))
  8494. (memq last-command
  8495. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8496. (setq this-command 'org-agenda-date-later-minutes)
  8497. (org-agenda-date-later-minutes 1))
  8498. ((or (equal arg '(4))
  8499. (memq last-command
  8500. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8501. (setq this-command 'org-agenda-date-later-hours)
  8502. (org-agenda-date-later-hours 1))
  8503. (t
  8504. (org-agenda-date-later (prefix-numeric-value arg)))))
  8505. (defun org-agenda-do-date-earlier (arg)
  8506. (interactive "P")
  8507. (cond
  8508. ((or (equal arg '(16))
  8509. (memq last-command
  8510. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8511. (setq this-command 'org-agenda-date-earlier-minutes)
  8512. (org-agenda-date-earlier-minutes 1))
  8513. ((or (equal arg '(4))
  8514. (memq last-command
  8515. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8516. (setq this-command 'org-agenda-date-earlier-hours)
  8517. (org-agenda-date-earlier-hours 1))
  8518. (t
  8519. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8520. (defun org-agenda-date-later (arg &optional what)
  8521. "Change the date of this item to ARG day(s) later."
  8522. (interactive "p")
  8523. (org-agenda-check-type t 'agenda)
  8524. (org-agenda-check-no-diary)
  8525. (let* ((marker (or (org-get-at-bol 'org-marker)
  8526. (org-agenda-error)))
  8527. (buffer (marker-buffer marker))
  8528. (pos (marker-position marker))
  8529. cdate today)
  8530. (org-with-remote-undo buffer
  8531. (with-current-buffer buffer
  8532. (widen)
  8533. (goto-char pos)
  8534. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  8535. (when (and org-agenda-move-date-from-past-immediately-to-today
  8536. (equal arg 1)
  8537. (or (not what) (eq what 'day))
  8538. (not (save-match-data (org-at-date-range-p))))
  8539. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8540. cdate (calendar-absolute-from-gregorian
  8541. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8542. today (org-today))
  8543. (if (> today cdate)
  8544. ;; immediately shift to today
  8545. (setq arg (- today cdate))))
  8546. (org-timestamp-change arg (or what 'day))
  8547. (when (and (org-at-date-range-p)
  8548. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8549. (let ((end org-last-changed-timestamp))
  8550. (org-timestamp-change arg (or what 'day))
  8551. (setq org-last-changed-timestamp
  8552. (concat org-last-changed-timestamp "--" end)))))
  8553. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8554. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8555. (defun org-agenda-date-earlier (arg &optional what)
  8556. "Change the date of this item to ARG day(s) earlier."
  8557. (interactive "p")
  8558. (org-agenda-date-later (- arg) what))
  8559. (defun org-agenda-date-later-minutes (arg)
  8560. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8561. (interactive "p")
  8562. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8563. (org-agenda-date-later arg 'minute))
  8564. (defun org-agenda-date-earlier-minutes (arg)
  8565. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8566. (interactive "p")
  8567. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8568. (org-agenda-date-earlier arg 'minute))
  8569. (defun org-agenda-date-later-hours (arg)
  8570. "Change the time of this item, in hour steps."
  8571. (interactive "p")
  8572. (org-agenda-date-later arg 'hour))
  8573. (defun org-agenda-date-earlier-hours (arg)
  8574. "Change the time of this item, in hour steps."
  8575. (interactive "p")
  8576. (org-agenda-date-earlier arg 'hour))
  8577. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8578. "Show new date stamp via text properties."
  8579. ;; We use text properties to make this undoable
  8580. (let ((inhibit-read-only t))
  8581. (setq stamp (concat prefix " => " stamp " "))
  8582. (save-excursion
  8583. (goto-char (point-max))
  8584. (while (not (bobp))
  8585. (when (equal marker (org-get-at-bol 'org-marker))
  8586. (remove-text-properties (point-at-bol) (point-at-eol) '(display))
  8587. (org-move-to-column (- (window-width) (length stamp)) t)
  8588. (add-text-properties
  8589. (1- (point)) (point-at-eol)
  8590. (list 'display (org-add-props stamp nil
  8591. 'face '(secondary-selection default))))
  8592. (beginning-of-line 1))
  8593. (beginning-of-line 0)))))
  8594. (defun org-agenda-date-prompt (arg)
  8595. "Change the date of this item. Date is prompted for, with default today.
  8596. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8597. be used to request time specification in the time stamp."
  8598. (interactive "P")
  8599. (org-agenda-check-type t 'agenda)
  8600. (org-agenda-check-no-diary)
  8601. (let* ((marker (or (org-get-at-bol 'org-marker)
  8602. (org-agenda-error)))
  8603. (buffer (marker-buffer marker))
  8604. (pos (marker-position marker)))
  8605. (org-with-remote-undo buffer
  8606. (with-current-buffer buffer
  8607. (widen)
  8608. (goto-char pos)
  8609. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  8610. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8611. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8612. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8613. (defun org-agenda-schedule (arg &optional time)
  8614. "Schedule the item at point.
  8615. ARG is passed through to `org-schedule'."
  8616. (interactive "P")
  8617. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  8618. (org-agenda-check-no-diary)
  8619. (let* ((marker (or (org-get-at-bol 'org-marker)
  8620. (org-agenda-error)))
  8621. (type (marker-insertion-type marker))
  8622. (buffer (marker-buffer marker))
  8623. (pos (marker-position marker))
  8624. ts)
  8625. (set-marker-insertion-type marker t)
  8626. (org-with-remote-undo buffer
  8627. (with-current-buffer buffer
  8628. (widen)
  8629. (goto-char pos)
  8630. (setq ts (org-schedule arg time)))
  8631. (org-agenda-show-new-time marker ts " S"))
  8632. (message "%s" ts)))
  8633. (defun org-agenda-deadline (arg &optional time)
  8634. "Schedule the item at point.
  8635. ARG is passed through to `org-deadline'."
  8636. (interactive "P")
  8637. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  8638. (org-agenda-check-no-diary)
  8639. (let* ((marker (or (org-get-at-bol 'org-marker)
  8640. (org-agenda-error)))
  8641. (buffer (marker-buffer marker))
  8642. (pos (marker-position marker))
  8643. ts)
  8644. (org-with-remote-undo buffer
  8645. (with-current-buffer buffer
  8646. (widen)
  8647. (goto-char pos)
  8648. (setq ts (org-deadline arg time)))
  8649. (org-agenda-show-new-time marker ts " D"))
  8650. (message "%s" ts)))
  8651. (defun org-agenda-clock-in (&optional arg)
  8652. "Start the clock on the currently selected item."
  8653. (interactive "P")
  8654. (org-agenda-check-no-diary)
  8655. (if (equal arg '(4))
  8656. (org-clock-in arg)
  8657. (let* ((marker (or (org-get-at-bol 'org-marker)
  8658. (org-agenda-error)))
  8659. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  8660. (pos (marker-position marker))
  8661. (col (current-column))
  8662. newhead)
  8663. (org-with-remote-undo (marker-buffer marker)
  8664. (with-current-buffer (marker-buffer marker)
  8665. (widen)
  8666. (goto-char pos)
  8667. (org-show-context 'agenda)
  8668. (org-cycle-hide-drawers 'children)
  8669. (org-clock-in arg)
  8670. (setq newhead (org-get-heading)))
  8671. (org-agenda-change-all-lines newhead hdmarker))
  8672. (org-move-to-column col))))
  8673. (defun org-agenda-clock-out ()
  8674. "Stop the currently running clock."
  8675. (interactive)
  8676. (unless (marker-buffer org-clock-marker)
  8677. (error "No running clock"))
  8678. (let ((marker (make-marker)) (col (current-column)) newhead)
  8679. (org-with-remote-undo (marker-buffer org-clock-marker)
  8680. (with-current-buffer (marker-buffer org-clock-marker)
  8681. (org-with-wide-buffer
  8682. (goto-char org-clock-marker)
  8683. (org-back-to-heading t)
  8684. (move-marker marker (point))
  8685. (org-clock-out)
  8686. (setq newhead (org-get-heading)))))
  8687. (org-agenda-change-all-lines newhead marker)
  8688. (move-marker marker nil)
  8689. (org-move-to-column col)
  8690. (org-agenda-unmark-clocking-task)))
  8691. (defun org-agenda-clock-cancel (&optional arg)
  8692. "Cancel the currently running clock."
  8693. (interactive "P")
  8694. (unless (marker-buffer org-clock-marker)
  8695. (user-error "No running clock"))
  8696. (org-with-remote-undo (marker-buffer org-clock-marker)
  8697. (org-clock-cancel)))
  8698. (defun org-agenda-clock-goto ()
  8699. "Jump to the currently clocked in task within the agenda.
  8700. If the currently clocked in task is not listed in the agenda
  8701. buffer, display it in another window."
  8702. (interactive)
  8703. (let (pos)
  8704. (mapc (lambda (o)
  8705. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8706. (setq pos (overlay-start o))))
  8707. (overlays-in (point-min) (point-max)))
  8708. (cond (pos (goto-char pos))
  8709. ;; If the currently clocked entry is not in the agenda
  8710. ;; buffer, we visit it in another window:
  8711. ((bound-and-true-p org-clock-current-task)
  8712. (org-switch-to-buffer-other-window (org-clock-goto)))
  8713. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8714. (defun org-agenda-diary-entry-in-org-file ()
  8715. "Make a diary entry in the file `org-agenda-diary-file'."
  8716. (let (d1 d2 char (text "") dp1 dp2)
  8717. (if (equal (buffer-name) "*Calendar*")
  8718. (setq d1 (calendar-cursor-to-date t)
  8719. d2 (car calendar-mark-ring))
  8720. (setq dp1 (get-text-property (point-at-bol) 'day))
  8721. (unless dp1 (user-error "No date defined in current line"))
  8722. (setq d1 (calendar-gregorian-from-absolute dp1)
  8723. d2 (and (ignore-errors (mark))
  8724. (save-excursion
  8725. (goto-char (mark))
  8726. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8727. (calendar-gregorian-from-absolute dp2))))
  8728. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8729. (setq char (read-char-exclusive))
  8730. (cond
  8731. ((equal char ?d)
  8732. (setq text (read-string "Day entry: "))
  8733. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8734. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8735. ((equal char ?a)
  8736. (setq d1 (list (car d1) (nth 1 d1)
  8737. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8738. (nth 2 d1))))
  8739. (setq text (read-string "Anniversary (use %d to show years): "))
  8740. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8741. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8742. ((equal char ?b)
  8743. (setq text (read-string "Block entry: "))
  8744. (unless (and d1 d2 (not (equal d1 d2)))
  8745. (user-error "No block of days selected"))
  8746. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8747. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8748. ((equal char ?j)
  8749. (org-switch-to-buffer-other-window
  8750. (find-file-noselect org-agenda-diary-file))
  8751. (require 'org-datetree)
  8752. (org-datetree-find-date-create d1)
  8753. (org-reveal t))
  8754. (t (user-error "Invalid selection character `%c'" char)))))
  8755. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8756. "Where in `org-agenda-diary-file' should new entries be added?
  8757. Valid values:
  8758. date-tree in the date tree, as first child of the date
  8759. date-tree-last in the date tree, as last child of the date
  8760. top-level as top-level entries at the end of the file."
  8761. :group 'org-agenda
  8762. :type '(choice
  8763. (const :tag "first in a date tree" date-tree)
  8764. (const :tag "last in a date tree" date-tree-last)
  8765. (const :tag "as top level at end of file" top-level)))
  8766. (defcustom org-agenda-insert-diary-extract-time nil
  8767. "Non-nil means extract any time specification from the diary entry."
  8768. :group 'org-agenda
  8769. :version "24.1"
  8770. :type 'boolean)
  8771. (defcustom org-agenda-bulk-mark-char ">"
  8772. "A single-character string to be used as the bulk mark."
  8773. :group 'org-agenda
  8774. :version "24.1"
  8775. :type 'string)
  8776. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8777. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8778. If TEXT is not empty, it will become the headline of the new entry, and
  8779. the resulting entry will not be shown. When TEXT is empty, switch to
  8780. `org-agenda-diary-file' and let the user finish the entry there."
  8781. (let ((cw (current-window-configuration)))
  8782. (org-switch-to-buffer-other-window
  8783. (find-file-noselect org-agenda-diary-file))
  8784. (widen)
  8785. (goto-char (point-min))
  8786. (cond
  8787. ((eq type 'anniversary)
  8788. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8789. (progn
  8790. (or (org-at-heading-p t)
  8791. (progn
  8792. (outline-next-heading)
  8793. (insert "* Anniversaries\n\n")
  8794. (beginning-of-line -1)))))
  8795. (outline-next-heading)
  8796. (org-back-over-empty-lines)
  8797. (backward-char 1)
  8798. (insert "\n")
  8799. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8800. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8801. ((eq type 'day)
  8802. (let ((org-prefix-has-time t)
  8803. (org-agenda-time-leading-zero t)
  8804. fmt time time2)
  8805. (if org-agenda-insert-diary-extract-time
  8806. ;; Use org-agenda-format-item to parse text for a time-range and
  8807. ;; remove it. FIXME: This is a hack, we should refactor
  8808. ;; that function to make time extraction available separately
  8809. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8810. time (get-text-property 0 'time fmt)
  8811. time2 (if (> (length time) 0)
  8812. ;; split-string removes trailing ...... if
  8813. ;; no end time given. First space
  8814. ;; separates time from date.
  8815. (concat " " (car (split-string time "\\.")))
  8816. nil)
  8817. text (get-text-property 0 'txt fmt)))
  8818. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8819. (org-agenda-insert-diary-as-top-level text)
  8820. (require 'org-datetree)
  8821. (org-datetree-find-date-create d1)
  8822. (org-agenda-insert-diary-make-new-entry text))
  8823. (org-insert-time-stamp (org-time-from-absolute
  8824. (calendar-absolute-from-gregorian d1))
  8825. nil nil nil nil time2))
  8826. (end-of-line 0))
  8827. ((eq type 'block)
  8828. (if (> (calendar-absolute-from-gregorian d1)
  8829. (calendar-absolute-from-gregorian d2))
  8830. (setq d1 (prog1 d2 (setq d2 d1))))
  8831. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8832. (org-agenda-insert-diary-as-top-level text)
  8833. (require 'org-datetree)
  8834. (org-datetree-find-date-create d1)
  8835. (org-agenda-insert-diary-make-new-entry text))
  8836. (org-insert-time-stamp (org-time-from-absolute
  8837. (calendar-absolute-from-gregorian d1)))
  8838. (insert "--")
  8839. (org-insert-time-stamp (org-time-from-absolute
  8840. (calendar-absolute-from-gregorian d2)))
  8841. (end-of-line 0)))
  8842. (if (string-match "\\S-" text)
  8843. (progn
  8844. (set-window-configuration cw)
  8845. (message "%s entry added to %s"
  8846. (capitalize (symbol-name type))
  8847. (abbreviate-file-name org-agenda-diary-file)))
  8848. (org-reveal t)
  8849. (message "Please finish entry here"))))
  8850. (defun org-agenda-insert-diary-as-top-level (text)
  8851. "Make new entry as a top-level entry at the end of the file.
  8852. Add TEXT as headline, and position the cursor in the second line so that
  8853. a timestamp can be added there."
  8854. (widen)
  8855. (goto-char (point-max))
  8856. (unless (bolp) (insert "\n"))
  8857. (org-insert-heading nil t t)
  8858. (insert text)
  8859. (org-end-of-meta-data)
  8860. (unless (bolp) (insert "\n"))
  8861. (when org-adapt-indentation (indent-to-column 2)))
  8862. (defun org-agenda-insert-diary-make-new-entry (text)
  8863. "Make a new entry with TEXT as a child of the current subtree.
  8864. Position the point in the heading's first body line so that
  8865. a timestamp can be added there."
  8866. (cond
  8867. ((eq org-agenda-insert-diary-strategy 'date-tree-last)
  8868. (end-of-line)
  8869. (org-insert-heading '(4) t)
  8870. (org-do-demote))
  8871. (t
  8872. (outline-next-heading)
  8873. (org-back-over-empty-lines)
  8874. (unless (looking-at "[ \t]*$") (save-excursion (insert "\n")))
  8875. (org-insert-heading nil t)
  8876. (org-do-demote)))
  8877. (let ((col (current-column)))
  8878. (insert text)
  8879. (org-end-of-meta-data)
  8880. ;; Ensure point is left on a blank line, at proper indentation.
  8881. (unless (bolp) (insert "\n"))
  8882. (unless (looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
  8883. (when org-adapt-indentation (indent-to-column col)))
  8884. (org-show-set-visibility 'lineage))
  8885. (defun org-agenda-diary-entry ()
  8886. "Make a diary entry, like the `i' command from the calendar.
  8887. All the standard commands work: block, weekly etc.
  8888. When `org-agenda-diary-file' points to a file,
  8889. `org-agenda-diary-entry-in-org-file' is called instead to create
  8890. entries in that Org file."
  8891. (interactive)
  8892. (if (not (eq org-agenda-diary-file 'diary-file))
  8893. (org-agenda-diary-entry-in-org-file)
  8894. (require 'diary-lib)
  8895. (let* ((char (progn
  8896. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8897. (read-char-exclusive)))
  8898. (cmd (cdr (assoc char
  8899. '((?d . diary-insert-entry)
  8900. (?w . diary-insert-weekly-entry)
  8901. (?m . diary-insert-monthly-entry)
  8902. (?y . diary-insert-yearly-entry)
  8903. (?a . diary-insert-anniversary-entry)
  8904. (?b . diary-insert-block-entry)
  8905. (?c . diary-insert-cyclic-entry)))))
  8906. (oldf (symbol-function 'calendar-cursor-to-date))
  8907. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8908. (point (point))
  8909. (mark (or (mark t) (point))))
  8910. (unless cmd
  8911. (user-error "No command associated with <%c>" char))
  8912. (unless (and (get-text-property point 'day)
  8913. (or (not (equal ?b char))
  8914. (get-text-property mark 'day)))
  8915. (user-error "Don't know which date to use for diary entry"))
  8916. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8917. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8918. (let ((calendar-mark-ring
  8919. (list (calendar-gregorian-from-absolute
  8920. (or (get-text-property mark 'day)
  8921. (get-text-property point 'day))))))
  8922. (unwind-protect
  8923. (progn
  8924. (fset 'calendar-cursor-to-date
  8925. (lambda (&optional error dummy)
  8926. (calendar-gregorian-from-absolute
  8927. (get-text-property point 'day))))
  8928. (call-interactively cmd))
  8929. (fset 'calendar-cursor-to-date oldf))))))
  8930. (defun org-agenda-execute-calendar-command (cmd)
  8931. "Execute a calendar command from the agenda with date from cursor."
  8932. (org-agenda-check-type t 'agenda)
  8933. (require 'diary-lib)
  8934. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8935. (user-error "Don't know which date to use for the calendar command"))
  8936. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8937. (point (point))
  8938. (date (calendar-gregorian-from-absolute
  8939. (get-text-property point 'day)))
  8940. ;; the following 2 vars are needed in the calendar
  8941. (displayed-month (car date))
  8942. (displayed-year (nth 2 date)))
  8943. (unwind-protect
  8944. (progn
  8945. (fset 'calendar-cursor-to-date
  8946. (lambda (&optional error dummy)
  8947. (calendar-gregorian-from-absolute
  8948. (get-text-property point 'day))))
  8949. (call-interactively cmd))
  8950. (fset 'calendar-cursor-to-date oldf))))
  8951. (defun org-agenda-phases-of-moon ()
  8952. "Display the phases of the moon for the 3 months around the cursor date."
  8953. (interactive)
  8954. (org-agenda-execute-calendar-command 'calendar-lunar-phases))
  8955. (defun org-agenda-holidays ()
  8956. "Display the holidays for the 3 months around the cursor date."
  8957. (interactive)
  8958. (org-agenda-execute-calendar-command 'calendar-list-holidays))
  8959. (defvar calendar-longitude) ; defined in calendar.el
  8960. (defvar calendar-latitude) ; defined in calendar.el
  8961. (defvar calendar-location-name) ; defined in calendar.el
  8962. (defun org-agenda-sunrise-sunset (arg)
  8963. "Display sunrise and sunset for the cursor date.
  8964. Latitude and longitude can be specified with the variables
  8965. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8966. argument, latitude and longitude will be prompted for."
  8967. (interactive "P")
  8968. (require 'solar)
  8969. (let ((calendar-longitude (if arg nil calendar-longitude))
  8970. (calendar-latitude (if arg nil calendar-latitude))
  8971. (calendar-location-name
  8972. (if arg "the given coordinates" calendar-location-name)))
  8973. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8974. (defun org-agenda-goto-calendar ()
  8975. "Open the Emacs calendar with the date at the cursor."
  8976. (interactive)
  8977. (org-agenda-check-type t 'agenda)
  8978. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8979. (user-error "Don't know which date to open in calendar")))
  8980. (date (calendar-gregorian-from-absolute day))
  8981. (calendar-move-hook nil)
  8982. (calendar-view-holidays-initially-flag nil)
  8983. (calendar-view-diary-initially-flag nil))
  8984. (calendar)
  8985. (calendar-goto-date date)))
  8986. ;;;###autoload
  8987. (defun org-calendar-goto-agenda ()
  8988. "Compute the Org agenda for the calendar date displayed at the cursor.
  8989. This is a command that has to be installed in `calendar-mode-map'."
  8990. (interactive)
  8991. ;; Temporarily disable sticky agenda since user clearly wants to
  8992. ;; refresh view anyway.
  8993. (let ((org-agenda-buffer-tmp-name "*Org Agenda(a)*")
  8994. (org-agenda-sticky nil))
  8995. (org-agenda-list nil (calendar-absolute-from-gregorian
  8996. (calendar-cursor-to-date))
  8997. nil)))
  8998. (defun org-agenda-convert-date ()
  8999. (interactive)
  9000. (org-agenda-check-type t 'agenda)
  9001. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  9002. date s)
  9003. (unless day
  9004. (user-error "Don't know which date to convert"))
  9005. (setq date (calendar-gregorian-from-absolute day))
  9006. (setq s (concat
  9007. "Gregorian: " (calendar-date-string date) "\n"
  9008. "ISO: " (calendar-iso-date-string date) "\n"
  9009. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  9010. "Julian: " (calendar-julian-date-string date) "\n"
  9011. "Astron. JD: " (calendar-astro-date-string date)
  9012. " (Julian date number at noon UTC)\n"
  9013. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  9014. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  9015. "French: " (calendar-french-date-string date) "\n"
  9016. "Bahá’í: " (calendar-bahai-date-string date) " (until sunset)\n"
  9017. "Mayan: " (calendar-mayan-date-string date) "\n"
  9018. "Coptic: " (calendar-coptic-date-string date) "\n"
  9019. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  9020. "Persian: " (calendar-persian-date-string date) "\n"
  9021. "Chinese: " (calendar-chinese-date-string date) "\n"))
  9022. (with-output-to-temp-buffer "*Dates*"
  9023. (princ s))
  9024. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  9025. ;;; Bulk commands
  9026. (defun org-agenda-bulk-marked-p ()
  9027. "Non-nil when current entry is marked for bulk action."
  9028. (eq (get-char-property (point-at-bol) 'type)
  9029. 'org-marked-entry-overlay))
  9030. (defun org-agenda-bulk-mark (&optional arg)
  9031. "Mark the entry at point for future bulk action."
  9032. (interactive "p")
  9033. (dotimes (i (or arg 1))
  9034. (unless (org-get-at-bol 'org-agenda-diary-link)
  9035. (let* ((m (org-get-at-bol 'org-hd-marker))
  9036. ov)
  9037. (unless (org-agenda-bulk-marked-p)
  9038. (unless m (user-error "Nothing to mark at point"))
  9039. (push m org-agenda-bulk-marked-entries)
  9040. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  9041. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  9042. (org-get-todo-face "TODO")
  9043. 'evaporate)
  9044. (overlay-put ov 'type 'org-marked-entry-overlay))
  9045. (end-of-line 1)
  9046. (or (ignore-errors
  9047. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  9048. (beginning-of-line 2))
  9049. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9050. (beginning-of-line 2))
  9051. (message "%d entries marked for bulk action"
  9052. (length org-agenda-bulk-marked-entries))))))
  9053. (defun org-agenda-bulk-mark-all ()
  9054. "Mark all entries for future agenda bulk action."
  9055. (interactive)
  9056. (org-agenda-bulk-mark-regexp "."))
  9057. (defun org-agenda-bulk-mark-regexp (regexp)
  9058. "Mark entries matching REGEXP for future agenda bulk action."
  9059. (interactive "sMark entries matching regexp: ")
  9060. (let ((entries-marked 0) txt-at-point)
  9061. (save-excursion
  9062. (goto-char (point-min))
  9063. (goto-char (next-single-property-change (point) 'org-hd-marker))
  9064. (while (and (re-search-forward regexp nil t)
  9065. (setq txt-at-point (get-text-property (point) 'txt)))
  9066. (if (get-char-property (point) 'invisible)
  9067. (beginning-of-line 2)
  9068. (when (string-match regexp txt-at-point)
  9069. (setq entries-marked (1+ entries-marked))
  9070. (call-interactively 'org-agenda-bulk-mark)))))
  9071. (if (not entries-marked)
  9072. (message "No entry matching this regexp."))))
  9073. (defun org-agenda-bulk-unmark (&optional arg)
  9074. "Unmark the entry at point for future bulk action."
  9075. (interactive "P")
  9076. (if arg
  9077. (org-agenda-bulk-unmark-all)
  9078. (cond ((org-agenda-bulk-marked-p)
  9079. (org-agenda-bulk-remove-overlays
  9080. (point-at-bol) (+ 2 (point-at-bol)))
  9081. (setq org-agenda-bulk-marked-entries
  9082. (delete (org-get-at-bol 'org-hd-marker)
  9083. org-agenda-bulk-marked-entries))
  9084. (end-of-line 1)
  9085. (or (ignore-errors
  9086. (goto-char (next-single-property-change (point) 'txt)))
  9087. (beginning-of-line 2))
  9088. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9089. (beginning-of-line 2))
  9090. (message "%d entries left marked for bulk action"
  9091. (length org-agenda-bulk-marked-entries)))
  9092. (t (message "No entry to unmark here")))))
  9093. (defun org-agenda-bulk-toggle-all ()
  9094. "Toggle all marks for bulk action."
  9095. (interactive)
  9096. (save-excursion
  9097. (goto-char (point-min))
  9098. (while (ignore-errors
  9099. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  9100. (org-agenda-bulk-toggle))))
  9101. (defun org-agenda-bulk-toggle ()
  9102. "Toggle the mark at point for bulk action."
  9103. (interactive)
  9104. (if (org-agenda-bulk-marked-p)
  9105. (org-agenda-bulk-unmark)
  9106. (org-agenda-bulk-mark)))
  9107. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  9108. "Remove the mark overlays between BEG and END in the agenda buffer.
  9109. BEG and END default to the buffer limits.
  9110. This only removes the overlays, it does not remove the markers
  9111. from the list in `org-agenda-bulk-marked-entries'."
  9112. (interactive)
  9113. (mapc (lambda (ov)
  9114. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  9115. (delete-overlay ov)))
  9116. (overlays-in (or beg (point-min)) (or end (point-max)))))
  9117. (defun org-agenda-bulk-unmark-all ()
  9118. "Remove all marks in the agenda buffer.
  9119. This will remove the markers and the overlays."
  9120. (interactive)
  9121. (if (null org-agenda-bulk-marked-entries)
  9122. (message "No entry to unmark")
  9123. (setq org-agenda-bulk-marked-entries nil)
  9124. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  9125. (defcustom org-agenda-persistent-marks nil
  9126. "Non-nil means marked items will stay marked after a bulk action.
  9127. You can toggle this interactively by typing `p' when prompted for a
  9128. bulk action."
  9129. :group 'org-agenda
  9130. :version "24.1"
  9131. :type 'boolean)
  9132. (defun org-agenda-bulk-action (&optional arg)
  9133. "Execute an remote-editing action on all marked entries.
  9134. The prefix arg is passed through to the command if possible."
  9135. (interactive "P")
  9136. ;; Make sure we have markers, and only valid ones.
  9137. (unless org-agenda-bulk-marked-entries (user-error "No entries are marked"))
  9138. (dolist (m org-agenda-bulk-marked-entries)
  9139. (unless (and (markerp m)
  9140. (marker-buffer m)
  9141. (buffer-live-p (marker-buffer m))
  9142. (marker-position m))
  9143. (user-error "Marker %s for bulk command is invalid" m)))
  9144. ;; Prompt for the bulk command.
  9145. (message
  9146. (concat (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")
  9147. "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  9148. "[S]catter [f]unction "
  9149. (and org-agenda-bulk-custom-functions
  9150. (format " Custom: [%s]"
  9151. (mapconcat (lambda (f) (char-to-string (car f)))
  9152. org-agenda-bulk-custom-functions
  9153. "")))))
  9154. (catch 'exit
  9155. (let* ((org-log-refile (if org-log-refile 'time nil))
  9156. (entries (reverse org-agenda-bulk-marked-entries))
  9157. (org-overriding-default-time
  9158. (and (get-text-property (point) 'org-agenda-date-header)
  9159. (org-get-cursor-date)))
  9160. redo-at-end
  9161. cmd)
  9162. (pcase (read-char-exclusive)
  9163. (?p
  9164. (let ((org-agenda-persistent-marks
  9165. (not org-agenda-persistent-marks)))
  9166. (org-agenda-bulk-action)
  9167. (throw 'exit nil)))
  9168. (?$
  9169. (setq cmd #'org-agenda-archive))
  9170. (?A
  9171. (setq cmd #'org-agenda-archive-to-archive-sibling))
  9172. ((or ?r ?w)
  9173. (let ((refile-location
  9174. (org-refile-get-location
  9175. "Refile to"
  9176. (marker-buffer (car entries))
  9177. org-refile-allow-creating-parent-nodes)))
  9178. (when (nth 3 refile-location)
  9179. (setcar (nthcdr 3 refile-location)
  9180. (move-marker
  9181. (make-marker)
  9182. (nth 3 refile-location)
  9183. (or (get-file-buffer (nth 1 refile-location))
  9184. (find-buffer-visiting (nth 1 refile-location))
  9185. (error "This should not happen")))))
  9186. (setq cmd `(lambda () (org-agenda-refile nil ',refile-location t)))
  9187. (setq redo-at-end t)))
  9188. (?t
  9189. (let ((state (completing-read
  9190. "Todo state: "
  9191. (with-current-buffer (marker-buffer (car entries))
  9192. (mapcar #'list org-todo-keywords-1)))))
  9193. (setq cmd `(lambda ()
  9194. (let ((org-inhibit-blocking t)
  9195. (org-inhibit-logging 'note))
  9196. (org-agenda-todo ,state))))))
  9197. ((and (or ?- ?+) action)
  9198. (let ((tag (completing-read
  9199. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  9200. (with-current-buffer (marker-buffer (car entries))
  9201. (delq nil
  9202. (mapcar (lambda (x) (and (stringp (car x)) x))
  9203. org-current-tag-alist))))))
  9204. (setq cmd
  9205. `(lambda ()
  9206. (org-agenda-set-tags ,tag
  9207. ,(if (eq action ?+) ''on ''off))))))
  9208. (?s
  9209. (let ((time
  9210. (and (not arg)
  9211. (org-read-date nil nil nil "(Re)Schedule to"
  9212. org-overriding-default-time))))
  9213. ;; Make sure to not prompt for a note when bulk
  9214. ;; rescheduling as Org cannot cope with simultaneous notes.
  9215. ;; Besides, it could be annoying depending on the number of
  9216. ;; items re-scheduled.
  9217. (setq cmd
  9218. `(lambda ()
  9219. (let ((org-log-reschedule (and org-log-reschedule 'time)))
  9220. (org-agenda-schedule arg ,time))))))
  9221. (?d
  9222. (let ((time
  9223. (and (not arg)
  9224. (org-read-date nil nil nil "(Re)Set Deadline to"
  9225. org-overriding-default-time))))
  9226. ;; Make sure to not prompt for a note when bulk
  9227. ;; rescheduling as Org cannot cope with simultaneous
  9228. ;; notes. Besides, it could be annoying depending on the
  9229. ;; number of items re-scheduled.
  9230. (setq cmd
  9231. `(lambda ()
  9232. (let ((org-log-redeadline (and org-log-redeadline 'time)))
  9233. (org-agenda-deadline arg ,time))))))
  9234. (?S
  9235. (unless (org-agenda-check-type nil 'agenda 'todo)
  9236. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type))
  9237. (let ((days (read-number
  9238. (format "Scatter tasks across how many %sdays: "
  9239. (if arg "week" ""))
  9240. 7)))
  9241. (setq cmd
  9242. `(lambda ()
  9243. (let ((distance (1+ (random ,days))))
  9244. (when arg
  9245. (let ((dist distance)
  9246. (day-of-week
  9247. (calendar-day-of-week
  9248. (calendar-gregorian-from-absolute (org-today)))))
  9249. (dotimes (i (1+ dist))
  9250. (while (member day-of-week org-agenda-weekend-days)
  9251. (cl-incf distance)
  9252. (cl-incf day-of-week)
  9253. (when (= day-of-week 7)
  9254. (setq day-of-week 0)))
  9255. (cl-incf day-of-week)
  9256. (when (= day-of-week 7)
  9257. (setq day-of-week 0)))))
  9258. ;; Silently fail when try to replan a sexp entry.
  9259. (ignore-errors
  9260. (let* ((date (calendar-gregorian-from-absolute
  9261. (+ (org-today) distance)))
  9262. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  9263. (nth 2 date))))
  9264. (org-agenda-schedule nil time))))))))
  9265. (?f
  9266. (setq cmd
  9267. (intern
  9268. (completing-read "Function: " obarray #'fboundp t nil nil))))
  9269. (action
  9270. (pcase (assoc action org-agenda-bulk-custom-functions)
  9271. (`(,_ ,f) (setq cmd f) (setq redo-at-end t))
  9272. (_ (user-error "Invalid bulk action: %c" action)))))
  9273. ;; Sort the markers, to make sure that parents are handled
  9274. ;; before children.
  9275. (setq entries (sort entries
  9276. (lambda (a b)
  9277. (cond
  9278. ((eq (marker-buffer a) (marker-buffer b))
  9279. (< (marker-position a) (marker-position b)))
  9280. (t
  9281. (string< (buffer-name (marker-buffer a))
  9282. (buffer-name (marker-buffer b))))))))
  9283. ;; Now loop over all markers and apply CMD.
  9284. (let ((processed 0)
  9285. (skipped 0))
  9286. (dolist (e entries)
  9287. (let ((pos (text-property-any (point-min) (point-max) 'org-hd-marker e)))
  9288. (if (not pos)
  9289. (progn (message "Skipping removed entry at %s" e)
  9290. (cl-incf skipped))
  9291. (goto-char pos)
  9292. (let (org-loop-over-headlines-in-active-region) (funcall cmd))
  9293. ;; `post-command-hook' is not run yet. We make sure any
  9294. ;; pending log note is processed.
  9295. (when (or (memq 'org-add-log-note (default-value 'post-command-hook))
  9296. (memq 'org-add-log-note post-command-hook))
  9297. (org-add-log-note))
  9298. (cl-incf processed))))
  9299. (when redo-at-end (org-agenda-redo))
  9300. (unless org-agenda-persistent-marks (org-agenda-bulk-unmark-all))
  9301. (message "Acted on %d entries%s%s"
  9302. processed
  9303. (if (= skipped 0)
  9304. ""
  9305. (format ", skipped %d (disappeared before their turn)"
  9306. skipped))
  9307. (if (not org-agenda-persistent-marks) "" " (kept marked)"))))))
  9308. (defun org-agenda-capture (&optional with-time)
  9309. "Call `org-capture' with the date at point.
  9310. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  9311. current HH:MM time."
  9312. (interactive "P")
  9313. (if (not (eq major-mode 'org-agenda-mode))
  9314. (user-error "You cannot do this outside of agenda buffers")
  9315. (let ((org-overriding-default-time
  9316. (org-get-cursor-date (equal with-time 1))))
  9317. (call-interactively 'org-capture))))
  9318. ;;; Dragging agenda lines forward/backward
  9319. (defun org-agenda-reapply-filters ()
  9320. "Re-apply all agenda filters."
  9321. (mapcar
  9322. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f) t)))
  9323. `((,org-agenda-tag-filter tag)
  9324. (,org-agenda-category-filter category)
  9325. (,org-agenda-regexp-filter regexp)
  9326. (,org-agenda-effort-filter effort)
  9327. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  9328. (,(get 'org-agenda-category-filter :preset-filter) category)
  9329. (,(get 'org-agenda-effort-filter :preset-filter) effort)
  9330. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  9331. (defun org-agenda-drag-line-forward (arg &optional backward)
  9332. "Drag an agenda line forward by ARG lines.
  9333. When the optional argument `backward' is non-nil, move backward."
  9334. (interactive "p")
  9335. (let ((inhibit-read-only t) lst line)
  9336. (if (or (not (get-text-property (point) 'txt))
  9337. (save-excursion
  9338. (dotimes (n arg)
  9339. (move-beginning-of-line (if backward 0 2))
  9340. (push (not (get-text-property (point) 'txt)) lst))
  9341. (delq nil lst)))
  9342. (message "Cannot move line forward")
  9343. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  9344. (move-beginning-of-line 1)
  9345. (setq line (buffer-substring (point) end))
  9346. (delete-region (point) end)
  9347. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  9348. (insert line)
  9349. (org-agenda-reapply-filters)
  9350. (org-agenda-mark-clocking-task)
  9351. (move-beginning-of-line 0)))))
  9352. (defun org-agenda-drag-line-backward (arg)
  9353. "Drag an agenda line backward by ARG lines."
  9354. (interactive "p")
  9355. (org-agenda-drag-line-forward arg t))
  9356. ;;; Flagging notes
  9357. (defun org-agenda-show-the-flagging-note ()
  9358. "Display the flagging note in the other window.
  9359. When called a second time in direct sequence, offer to remove the FLAGGING
  9360. tag and (if present) the flagging note."
  9361. (interactive)
  9362. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  9363. (win (selected-window))
  9364. note heading newhead)
  9365. (unless hdmarker
  9366. (user-error "No linked entry at point"))
  9367. (if (and (eq this-command last-command)
  9368. (y-or-n-p "Unflag and remove any flagging note? "))
  9369. (progn
  9370. (org-agenda-remove-flag hdmarker)
  9371. (let ((win (get-buffer-window "*Flagging Note*")))
  9372. (and win (delete-window win)))
  9373. (message "Entry unflagged"))
  9374. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  9375. (unless note
  9376. (user-error "No flagging note"))
  9377. (org-kill-new note)
  9378. (org-switch-to-buffer-other-window "*Flagging Note*")
  9379. (erase-buffer)
  9380. (insert note)
  9381. (goto-char (point-min))
  9382. (while (re-search-forward "\\\\n" nil t)
  9383. (replace-match "\n" t t))
  9384. (goto-char (point-min))
  9385. (select-window win)
  9386. (message "%s" (substitute-command-keys "Flagging note pushed to \
  9387. kill ring. Press `\\[org-agenda-show-the-flagging-note]' again to remove \
  9388. tag and note")))))
  9389. (defun org-agenda-remove-flag (marker)
  9390. "Remove the FLAGGED tag and any flagging note in the entry."
  9391. (let (newhead)
  9392. (org-with-point-at marker
  9393. (org-toggle-tag "FLAGGED" 'off)
  9394. (org-entry-delete nil "THEFLAGGINGNOTE")
  9395. (setq newhead (org-get-heading)))
  9396. (org-agenda-change-all-lines newhead marker)
  9397. (message "Entry unflagged")))
  9398. (defun org-agenda-get-any-marker (&optional pos)
  9399. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  9400. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  9401. ;;; Appointment reminders
  9402. (defvar appt-time-msg-list) ; defined in appt.el
  9403. ;;;###autoload
  9404. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  9405. "Activate appointments found in `org-agenda-files'.
  9406. With a `\\[universal-argument]' prefix, refresh the list of \
  9407. appointments.
  9408. If FILTER is t, interactively prompt the user for a regular
  9409. expression, and filter out entries that don't match it.
  9410. If FILTER is a string, use this string as a regular expression
  9411. for filtering entries out.
  9412. If FILTER is a function, filter out entries against which
  9413. calling the function returns nil. This function takes one
  9414. argument: an entry from `org-agenda-get-day-entries'.
  9415. FILTER can also be an alist with the car of each cell being
  9416. either `headline' or `category'. For example:
  9417. \\='((headline \"IMPORTANT\")
  9418. (category \"Work\"))
  9419. will only add headlines containing IMPORTANT or headlines
  9420. belonging to the \"Work\" category.
  9421. ARGS are symbols indicating what kind of entries to consider.
  9422. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  9423. \(i.e., deadlines and scheduled items with a hh:mm specification)
  9424. and :timestamp entries. See the docstring of `org-diary' for
  9425. details and examples.
  9426. If an entry has a APPT_WARNTIME property, its value will be used
  9427. to override `appt-message-warning-time'."
  9428. (interactive "P")
  9429. (if refresh (setq appt-time-msg-list nil))
  9430. (if (eq filter t)
  9431. (setq filter (read-from-minibuffer "Regexp filter: ")))
  9432. (let* ((cnt 0) ; count added events
  9433. (scope (or args '(:deadline* :scheduled* :timestamp)))
  9434. (org-agenda-new-buffers nil)
  9435. (org-deadline-warning-days 0)
  9436. ;; Do not use `org-today' here because appt only takes
  9437. ;; time and without date as argument, so it may pass wrong
  9438. ;; information otherwise
  9439. (today (org-date-to-gregorian
  9440. (time-to-days (current-time))))
  9441. (org-agenda-restrict nil)
  9442. (files (org-agenda-files 'unrestricted)) entries file
  9443. (org-agenda-buffer nil))
  9444. ;; Get all entries which may contain an appt
  9445. (org-agenda-prepare-buffers files)
  9446. (while (setq file (pop files))
  9447. (setq entries
  9448. (delq nil
  9449. (append entries
  9450. (apply 'org-agenda-get-day-entries
  9451. file today scope)))))
  9452. ;; Map thru entries and find if we should filter them out
  9453. (mapc
  9454. (lambda (x)
  9455. (let* ((evt (org-trim
  9456. (replace-regexp-in-string
  9457. org-bracket-link-regexp "\\3"
  9458. (or (get-text-property 1 'txt x) ""))))
  9459. (cat (get-text-property (1- (length x)) 'org-category x))
  9460. (tod (get-text-property 1 'time-of-day x))
  9461. (ok (or (null filter)
  9462. (and (stringp filter) (string-match filter evt))
  9463. (and (functionp filter) (funcall filter x))
  9464. (and (listp filter)
  9465. (let ((cat-filter (cadr (assq 'category filter)))
  9466. (evt-filter (cadr (assq 'headline filter))))
  9467. (or (and (stringp cat-filter)
  9468. (string-match cat-filter cat))
  9469. (and (stringp evt-filter)
  9470. (string-match evt-filter evt)))))))
  9471. (wrn (get-text-property 1 'warntime x)))
  9472. ;; FIXME: Shall we remove text-properties for the appt text?
  9473. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  9474. (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
  9475. (setq tod (concat "00" (number-to-string tod)))
  9476. (setq tod (when (string-match
  9477. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  9478. (concat (match-string 1 tod) ":"
  9479. (match-string 2 tod))))
  9480. (when (appt-add tod evt wrn)
  9481. (setq cnt (1+ cnt))))))
  9482. entries)
  9483. (org-release-buffers org-agenda-new-buffers)
  9484. (if (eq cnt 0)
  9485. (message "No event to add")
  9486. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  9487. (defun org-agenda-today-p (date)
  9488. "Non nil when DATE means today.
  9489. DATE is either a list of the form (month day year) or a number of
  9490. days as returned by `calendar-absolute-from-gregorian' or
  9491. `org-today'. This function considers `org-extend-today-until'
  9492. when defining today."
  9493. (eq (org-today)
  9494. (if (consp date) (calendar-absolute-from-gregorian date) date)))
  9495. (defun org-agenda-todo-yesterday (&optional arg)
  9496. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  9497. (interactive "P")
  9498. (let* ((org-use-effective-time t)
  9499. (hour (nth 2 (decode-time (org-current-time))))
  9500. (org-extend-today-until (1+ hour)))
  9501. (org-agenda-todo arg)))
  9502. (provide 'org-agenda)
  9503. ;;; org-agenda.el ends here