org-agenda.el 450 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2004-2022 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten.dominik@gmail.com>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; URL: https://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 <https://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 'org-macs)
  42. (org-assert-version)
  43. (require 'cl-lib)
  44. (require 'ol)
  45. (require 'org-fold-core)
  46. (require 'org)
  47. (require 'org-macs)
  48. (require 'org-refile)
  49. (declare-function diary-add-to-list "diary-lib"
  50. (date string specifier &optional marker globcolor literal))
  51. (declare-function calendar-iso-to-absolute "cal-iso" (date))
  52. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  53. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  54. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  55. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  56. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  57. (declare-function calendar-french-date-string "cal-french" (&optional date))
  58. (declare-function calendar-goto-date "cal-move" (date))
  59. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  60. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  61. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  62. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  63. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  64. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  65. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  66. (declare-function calendar-check-holidays "holidays" (date))
  67. (declare-function org-columns-remove-overlays "org-colview" ())
  68. (declare-function org-datetree-find-date-create "org-datetree"
  69. (date &optional keep-restriction))
  70. (declare-function org-columns-quit "org-colview" ())
  71. (declare-function diary-date-display-form "diary-lib" (&optional type))
  72. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  73. (declare-function org-element-property "org-element" (property element))
  74. (declare-function org-element--cache-active-p "org-element"
  75. (&optional called-from-cache-change-func-p))
  76. (declare-function org-element-lineage "org-element"
  77. (datum &optional types with-self))
  78. (declare-function org-habit-insert-consistency-graphs
  79. "org-habit" (&optional line))
  80. (declare-function org-is-habit-p "org-habit" (&optional pom))
  81. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  82. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  83. (declare-function org-agenda-columns "org-colview" ())
  84. (declare-function org-add-archive-files "org-archive" (files))
  85. (declare-function org-capture "org-capture" (&optional goto keys))
  86. (declare-function org-clock-modify-effort-estimate "org-clock" (&optional value))
  87. (declare-function org-element-type "org-element" (&optional element))
  88. (defvar calendar-mode-map)
  89. (defvar org-clock-current-task)
  90. (defvar org-current-tag-alist)
  91. (defvar org-mobile-force-id-on-agenda-items)
  92. (defvar org-habit-show-habits)
  93. (defvar org-habit-show-habits-only-for-today)
  94. (defvar org-habit-show-all-today)
  95. (defvar org-habit-scheduled-past-days)
  96. ;; Defined somewhere in this file, but used before definition.
  97. (defvar org-agenda-buffer-name "*Org Agenda*")
  98. (defvar org-agenda-title-append nil)
  99. (defvar org-agenda-overriding-header)
  100. ;; (with-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  101. ;; (with-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  102. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  103. (defvar org-agenda-undo-list nil
  104. "List of undoable operations in the agenda since last refresh.")
  105. (defvar org-agenda-pending-undo-list nil
  106. "In a series of undo commands, this is the list of remaining undo items.")
  107. (defcustom org-agenda-confirm-kill 1
  108. "When set, remote killing from the agenda buffer needs confirmation.
  109. When t, a confirmation is always needed. When a number N, confirmation is
  110. only needed when the text to be killed contains more than N non-white lines."
  111. :group 'org-agenda
  112. :type '(choice
  113. (const :tag "Never" nil)
  114. (const :tag "Always" t)
  115. (integer :tag "When more than N lines")))
  116. (defcustom org-agenda-compact-blocks nil
  117. "Non-nil means make the block agenda more compact.
  118. This is done globally by leaving out lines like the agenda span
  119. name and week number or the separator lines."
  120. :group 'org-agenda
  121. :type 'boolean)
  122. (defcustom org-agenda-block-separator
  123. (if (and (display-graphic-p)
  124. (char-displayable-p ?─))
  125. ?─
  126. ?=)
  127. "The separator between blocks in the agenda.
  128. If this is a string, it will be used as the separator, with a newline added.
  129. If it is a character, it will be repeated to fill the window width.
  130. If nil the separator is disabled. In `org-agenda-custom-commands' this
  131. addresses the separator between the current and the previous block."
  132. :group 'org-agenda
  133. :package-version '(Org . "9.6")
  134. :type '(choice
  135. (const :tag "Disabled" nil)
  136. (character)
  137. (string)))
  138. (defgroup org-agenda-export nil
  139. "Options concerning exporting agenda views in Org mode."
  140. :tag "Org Agenda Export"
  141. :group 'org-agenda)
  142. (defcustom org-agenda-with-colors t
  143. "Non-nil means use colors in agenda views."
  144. :group 'org-agenda-export
  145. :type 'boolean)
  146. (defcustom org-agenda-exporter-settings nil
  147. ;; FIXME: Do we really want to evaluate those settings and thus force
  148. ;; the user to use `quote' all the time?
  149. "Alist of variable/value pairs that should be active during agenda export.
  150. This is a good place to set options for ps-print and for htmlize.
  151. Note that the way this is implemented, the values will be evaluated
  152. before assigned to the variables. So make sure to quote values you do
  153. *not* want evaluated, for example
  154. (setq org-agenda-exporter-settings
  155. \\='((ps-print-color-p \\='black-white)))"
  156. :group 'org-agenda-export
  157. :type '(repeat
  158. (list
  159. (variable)
  160. (sexp :tag "Value"))))
  161. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  162. "Hook run in a temporary buffer before writing the agenda to an export file.
  163. A useful function for this hook is `org-agenda-add-entry-text'."
  164. :group 'org-agenda-export
  165. :type 'hook
  166. :options '(org-agenda-add-entry-text))
  167. (defcustom org-agenda-add-entry-text-maxlines 0
  168. "Maximum number of entry text lines to be added to agenda.
  169. This is only relevant when `org-agenda-add-entry-text' is part of
  170. `org-agenda-before-write-hook', which is the default.
  171. When this is 0, nothing will happen. When it is greater than 0, it
  172. specifies the maximum number of lines that will be added for each entry
  173. that is listed in the agenda view.
  174. Note that this variable is not used during display, only when exporting
  175. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  176. and `org-agenda-entry-text-maxlines'."
  177. :group 'org-agenda
  178. :type 'integer)
  179. (defcustom org-agenda-add-entry-text-descriptive-links t
  180. "Non-nil means export org-links as descriptive links in agenda added text.
  181. This variable applies to the text added to the agenda when
  182. `org-agenda-add-entry-text-maxlines' is larger than 0.
  183. When this variable is nil, the URL will (also) be shown."
  184. :group 'org-agenda
  185. :type 'boolean)
  186. (defcustom org-agenda-export-html-style nil
  187. "The style specification for exported HTML Agenda files.
  188. If this variable contains a string, it will replace the default <style>
  189. section as produced by `htmlize'.
  190. Since there are different ways of setting style information, this variable
  191. needs to contain the full HTML structure to provide a style, including the
  192. surrounding HTML tags. The style specifications should include definitions
  193. the fonts used by the agenda, here is an example:
  194. <style type=\"text/css\">
  195. p { font-weight: normal; color: gray; }
  196. .org-agenda-structure {
  197. font-size: 110%;
  198. color: #003399;
  199. font-weight: 600;
  200. }
  201. .org-todo {
  202. color: #cc6666;
  203. font-weight: bold;
  204. }
  205. .org-agenda-done {
  206. color: #339933;
  207. }
  208. .org-done {
  209. color: #339933;
  210. }
  211. .title { text-align: center; }
  212. .todo, .deadline { color: red; }
  213. .done { color: green; }
  214. </style>
  215. or, if you want to keep the style in a file,
  216. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  217. As the value of this option simply gets inserted into the HTML <head> header,
  218. you can \"misuse\" it to also add other text to the header."
  219. :group 'org-agenda-export
  220. :group 'org-export-html
  221. :type '(choice
  222. (const nil)
  223. (string)))
  224. (defcustom org-agenda-persistent-filter nil
  225. "When set, keep filters from one agenda view to the next."
  226. :group 'org-agenda
  227. :type 'boolean)
  228. (defgroup org-agenda-custom-commands nil
  229. "Options concerning agenda views in Org mode."
  230. :tag "Org Agenda Custom Commands"
  231. :group 'org-agenda)
  232. (defconst org-sorting-choice
  233. '(choice
  234. (const time-up) (const time-down)
  235. (const timestamp-up) (const timestamp-down)
  236. (const scheduled-up) (const scheduled-down)
  237. (const deadline-up) (const deadline-down)
  238. (const ts-up) (const ts-down)
  239. (const tsia-up) (const tsia-down)
  240. (const category-keep) (const category-up) (const category-down)
  241. (const tag-down) (const tag-up)
  242. (const priority-up) (const priority-down)
  243. (const todo-state-up) (const todo-state-down)
  244. (const effort-up) (const effort-down)
  245. (const habit-up) (const habit-down)
  246. (const alpha-up) (const alpha-down)
  247. (const user-defined-up) (const user-defined-down))
  248. "Sorting choices.")
  249. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  250. ;; the new variable `org-agenda-tag-filter-preset'.
  251. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  252. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  253. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  254. "List of types searched for when creating the daily/weekly agenda.
  255. This variable is a list of symbols that controls the types of
  256. items that appear in the daily/weekly agenda. Allowed symbols in this
  257. list are
  258. :timestamp List items containing a date stamp or date range matching
  259. the selected date. This includes sexp entries in angular
  260. brackets.
  261. :sexp List entries resulting from plain diary-like sexps.
  262. :deadline List deadline due on that date. When the date is today,
  263. also list any deadlines past due, or due within
  264. `org-deadline-warning-days'.
  265. :deadline* Same as above, but only include the deadline if it has an
  266. hour specification as [h]h:mm.
  267. :scheduled List all items which are scheduled for the given date.
  268. The diary for *today* also contains items which were
  269. scheduled earlier and are not yet marked DONE.
  270. :scheduled* Same as above, but only include the scheduled item if it
  271. has an hour specification as [h]h:mm.
  272. By default, all four non-starred types are turned on.
  273. When :scheduled* or :deadline* are included, :schedule or :deadline
  274. will be ignored.
  275. Never set this variable globally using `setq', because then it
  276. will apply to all future agenda commands. Instead, bind it with
  277. `let' to scope it dynamically into the agenda-constructing
  278. command. A good way to set it is through options in
  279. `org-agenda-custom-commands'. For a more flexible (though
  280. somewhat less efficient) way of determining what is included in
  281. the daily/weekly agenda, see `org-agenda-skip-function'.")
  282. (defconst org-agenda-custom-commands-local-options
  283. `(repeat :tag "Local settings for this command. Remember to quote values"
  284. (choice :tag "Setting"
  285. (list :tag "Heading for this block"
  286. (const org-agenda-overriding-header)
  287. (string :tag "Headline"))
  288. (list :tag "Files to be searched"
  289. (const org-agenda-files)
  290. (list
  291. (const :format "" quote)
  292. (repeat (file))))
  293. (list :tag "Sorting strategy"
  294. (const org-agenda-sorting-strategy)
  295. (list
  296. (const :format "" quote)
  297. (repeat
  298. ,org-sorting-choice)))
  299. (list :tag "Prefix format"
  300. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  301. (string))
  302. (list :tag "Number of days in agenda"
  303. (const org-agenda-span)
  304. (list
  305. (const :format "" quote)
  306. (choice (const :tag "Day" day)
  307. (const :tag "Week" week)
  308. (const :tag "Fortnight" fortnight)
  309. (const :tag "Month" month)
  310. (const :tag "Year" year)
  311. (integer :tag "Custom"))))
  312. (list :tag "Fixed starting date"
  313. (const org-agenda-start-day)
  314. (string :value "2007-11-01"))
  315. (list :tag "Start on day of week"
  316. (const org-agenda-start-on-weekday)
  317. (choice :value 1
  318. (const :tag "Today" nil)
  319. (integer :tag "Weekday No.")))
  320. (list :tag "Include data from diary"
  321. (const org-agenda-include-diary)
  322. (boolean))
  323. (list :tag "Deadline Warning days"
  324. (const org-deadline-warning-days)
  325. (integer :value 1))
  326. (list :tag "Category filter preset"
  327. (const org-agenda-category-filter-preset)
  328. (list
  329. (const :format "" quote)
  330. (repeat
  331. (string :tag "+category or -category"))))
  332. (list :tag "Tags filter preset"
  333. (const org-agenda-tag-filter-preset)
  334. (list
  335. (const :format "" quote)
  336. (repeat
  337. (string :tag "+tag or -tag"))))
  338. (list :tag "Effort filter preset"
  339. (const org-agenda-effort-filter-preset)
  340. (list
  341. (const :format "" quote)
  342. (repeat
  343. (string :tag "+=10 or -=10 or +<10 or ->10"))))
  344. (list :tag "Regexp filter preset"
  345. (const org-agenda-regexp-filter-preset)
  346. (list
  347. (const :format "" quote)
  348. (repeat
  349. (string :tag "+regexp or -regexp"))))
  350. (list :tag "Set daily/weekly entry types"
  351. (const org-agenda-entry-types)
  352. (list
  353. (const :format "" quote)
  354. (set :greedy t :value ,org-agenda-entry-types
  355. (const :deadline)
  356. (const :scheduled)
  357. (const :deadline*)
  358. (const :scheduled*)
  359. (const :timestamp)
  360. (const :sexp))))
  361. (list :tag "Columns format"
  362. (const org-overriding-columns-format)
  363. (string :tag "Format"))
  364. (list :tag "Standard skipping condition"
  365. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  366. (const org-agenda-skip-function)
  367. (list
  368. (const :format "" quote)
  369. (list
  370. (choice
  371. :tag "Skipping range"
  372. (const :tag "Skip entry" org-agenda-skip-entry-if)
  373. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  374. (repeat :inline t :tag "Conditions for skipping"
  375. (choice
  376. :tag "Condition type"
  377. (list :tag "Regexp matches" :inline t
  378. (const :format "" regexp)
  379. (regexp))
  380. (list :tag "Regexp does not match" :inline t
  381. (const :format "" notregexp)
  382. (regexp))
  383. (list :tag "TODO state is" :inline t
  384. (const todo)
  385. (choice
  386. (const :tag "Any not-done state" todo)
  387. (const :tag "Any done state" done)
  388. (const :tag "Any state" any)
  389. (list :tag "Keyword list"
  390. (const :format "" quote)
  391. (repeat (string :tag "Keyword")))))
  392. (list :tag "TODO state is not" :inline t
  393. (const nottodo)
  394. (choice
  395. (const :tag "Any not-done state" todo)
  396. (const :tag "Any done state" done)
  397. (const :tag "Any state" any)
  398. (list :tag "Keyword list"
  399. (const :format "" quote)
  400. (repeat (string :tag "Keyword")))))
  401. (const :tag "scheduled" scheduled)
  402. (const :tag "not scheduled" notscheduled)
  403. (const :tag "deadline" deadline)
  404. (const :tag "no deadline" notdeadline)
  405. (const :tag "timestamp" timestamp)
  406. (const :tag "no timestamp" nottimestamp))))))
  407. (list :tag "Non-standard skipping condition"
  408. :value (org-agenda-skip-function)
  409. (const org-agenda-skip-function)
  410. (sexp :tag "Function or form (quoted!)"))
  411. (list :tag "Any variable"
  412. (variable :tag "Variable")
  413. (sexp :tag "Value (sexp)"))))
  414. "Selection of examples for agenda command settings.
  415. This will be spliced into the custom type of
  416. `org-agenda-custom-commands'.")
  417. (defcustom org-agenda-custom-commands
  418. '(("n" "Agenda and all TODOs" ((agenda "") (alltodo ""))))
  419. "Custom commands for the agenda.
  420. \\<org-mode-map>
  421. These commands will be offered on the splash screen displayed by the
  422. agenda dispatcher `\\[org-agenda]'. Each entry is a list like this:
  423. (key desc type match settings files)
  424. key The key (one or more characters as a string) to be associated
  425. with the command.
  426. desc A description of the command. When omitted or nil, a default
  427. description is built using MATCH.
  428. type The command type, any of the following symbols:
  429. agenda The daily/weekly agenda.
  430. agenda* Appointments for current week/day.
  431. todo Entries with a specific TODO keyword, in all agenda files.
  432. search Entries containing search words entry or headline.
  433. tags Tags/Property/TODO match in all agenda files.
  434. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  435. todo-tree Sparse tree of specific TODO keyword in *current* file.
  436. tags-tree Sparse tree with all tags matches in *current* file.
  437. occur-tree Occur sparse tree for *current* file.
  438. alltodo The global TODO list.
  439. stuck Stuck projects.
  440. ... A user-defined function.
  441. match What to search for:
  442. - a single keyword for TODO keyword searches
  443. - a tags/property/todo match expression for searches
  444. - a word search expression for text searches.
  445. - a regular expression for occur searches
  446. For all other commands, this should be the empty string.
  447. settings A list of option settings, similar to that in a let form, so like
  448. this: ((opt1 val1) (opt2 val2) ...). The values will be
  449. evaluated at the moment of execution, so quote them when needed.
  450. files A list of files to write the produced agenda buffer to with
  451. the command `org-store-agenda-views'.
  452. If a file name ends in \".html\", an HTML version of the buffer
  453. is written out. If it ends in \".ps\", a PostScript version is
  454. produced. Otherwise, only the plain text is written to the file.
  455. You can also define a set of commands, to create a composite agenda buffer.
  456. In this case, an entry looks like this:
  457. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  458. where
  459. desc A description string to be displayed in the dispatcher menu.
  460. cmd An agenda command, similar to the above. However, tree commands
  461. are not allowed. Valid commands for a set are:
  462. (agenda \"\" settings)
  463. (agenda* \"\" settings)
  464. (alltodo \"\" settings)
  465. (stuck \"\" settings)
  466. (todo \"match\" settings files)
  467. (search \"match\" settings files)
  468. (tags \"match\" settings files)
  469. (tags-todo \"match\" settings files)
  470. Each command can carry a list of options, and another set of options can be
  471. given for the whole set of commands. Individual command options take
  472. precedence over the general options.
  473. When using several characters as key to a command, the first characters
  474. are prefix commands. For the dispatcher to display useful information, you
  475. should provide a description for the prefix, like
  476. (setq org-agenda-custom-commands
  477. \\='((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  478. (\"hl\" tags \"+HOME+Lisa\")
  479. (\"hp\" tags \"+HOME+Peter\")
  480. (\"hk\" tags \"+HOME+Kim\")))
  481. See also Info node `(org) Custom Agenda Views'."
  482. :group 'org-agenda-custom-commands
  483. :type `(repeat
  484. (choice :value ("x" "Describe command here" tags "" nil)
  485. (list :tag "Single command"
  486. (string :tag "Access Key(s) ")
  487. (option (string :tag "Description"))
  488. (choice
  489. (const :tag "Agenda" agenda)
  490. (const :tag "TODO list" alltodo)
  491. (const :tag "Search words" search)
  492. (const :tag "Stuck projects" stuck)
  493. (const :tag "Tags/Property match (all agenda files)" tags)
  494. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  495. (const :tag "TODO keyword search (all agenda files)" todo)
  496. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  497. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  498. (const :tag "Occur tree (current buffer)" occur-tree)
  499. (sexp :tag "Other, user-defined function"))
  500. (string :tag "Match (only for some commands)")
  501. ,org-agenda-custom-commands-local-options
  502. (option (repeat :tag "Export" (file :tag "Export to"))))
  503. (list :tag "Command series, all agenda files"
  504. (string :tag "Access Key(s)")
  505. (string :tag "Description ")
  506. (repeat :tag "Component"
  507. (choice
  508. (list :tag "Agenda"
  509. (const :format "" agenda)
  510. (const :tag "" :format "" "")
  511. ,org-agenda-custom-commands-local-options)
  512. (list :tag "TODO list (all keywords)"
  513. (const :format "" alltodo)
  514. (const :tag "" :format "" "")
  515. ,org-agenda-custom-commands-local-options)
  516. (list :tag "Search words"
  517. (const :format "" search)
  518. (string :tag "Match")
  519. ,org-agenda-custom-commands-local-options)
  520. (list :tag "Stuck projects"
  521. (const :format "" stuck)
  522. (const :tag "" :format "" "")
  523. ,org-agenda-custom-commands-local-options)
  524. (list :tag "Tags/Property match (all agenda files)"
  525. (const :format "" tags)
  526. (string :tag "Match")
  527. ,org-agenda-custom-commands-local-options)
  528. (list :tag "Tags/Property match of TODO entries (all agenda files)"
  529. (const :format "" tags-todo)
  530. (string :tag "Match")
  531. ,org-agenda-custom-commands-local-options)
  532. (list :tag "TODO keyword search"
  533. (const :format "" todo)
  534. (string :tag "Match")
  535. ,org-agenda-custom-commands-local-options)
  536. (list :tag "Other, user-defined function"
  537. (symbol :tag "function")
  538. (string :tag "Match")
  539. ,org-agenda-custom-commands-local-options)))
  540. (repeat :tag "Settings for entire command set"
  541. (list (variable :tag "Any variable")
  542. (sexp :tag "Value")))
  543. (option (repeat :tag "Export" (file :tag "Export to"))))
  544. (cons :tag "Prefix key documentation"
  545. (string :tag "Access Key(s)")
  546. (string :tag "Description ")))))
  547. (defcustom org-agenda-query-register ?o
  548. "The register holding the current query string.
  549. The purpose of this is that if you construct a query string interactively,
  550. you can then use it to define a custom command."
  551. :group 'org-agenda-custom-commands
  552. :type 'character)
  553. (defcustom org-stuck-projects
  554. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  555. "How to identify stuck projects.
  556. This is a list of four items:
  557. 1. A tags/todo/property matcher string that is used to identify a project.
  558. See Info node `(org) Matching tags and properties' for a
  559. description of tag and property searches. The entire tree
  560. below a headline matched by this is considered one project.
  561. 2. A list of TODO keywords identifying non-stuck projects.
  562. If the project subtree contains any headline with one of these todo
  563. keywords, the project is considered to be not stuck. If you specify
  564. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  565. 3. A list of tags identifying non-stuck projects.
  566. If the project subtree contains any headline with one of these tags,
  567. the project is considered to be not stuck. If you specify \"*\" as
  568. a tag, any tag will mark the project unstuck. Note that this is about
  569. the explicit presence of a tag somewhere in the subtree, inherited
  570. tags do not count here. If inherited tags make a project not stuck,
  571. use \"-TAG\" in the tags part of the matcher under (1.) above.
  572. 4. An arbitrary regular expression matching non-stuck projects.
  573. If the project turns out to be not stuck, search continues also in the
  574. subtree to see if any of the subtasks have project status.
  575. See also the variable `org-tags-match-list-sublevels' which applies
  576. to projects matched by this search as well.
  577. After defining this variable, you may use `org-agenda-list-stuck-projects'
  578. \(bound to `\\[org-agenda] #') to produce the list."
  579. :group 'org-agenda-custom-commands
  580. :type '(list
  581. (string :tag "Tags/TODO match to identify a project")
  582. (repeat :tag "Projects are *not* stuck if they have an entry with \
  583. TODO keyword any of" (string))
  584. (repeat :tag "Projects are *not* stuck if they have an entry with \
  585. TAG being any of" (string))
  586. (regexp :tag "Projects are *not* stuck if this regexp matches inside \
  587. the subtree")))
  588. (defgroup org-agenda-skip nil
  589. "Options concerning skipping parts of agenda files."
  590. :tag "Org Agenda Skip"
  591. :group 'org-agenda)
  592. (defcustom org-agenda-skip-function-global nil
  593. "Function to be called at each match during agenda construction.
  594. If this function returns nil, the current match should not be skipped.
  595. If the function decided to skip an agenda match, is must return the
  596. buffer position from which the search should be continued.
  597. This may also be a Lisp form, which will be evaluated.
  598. This variable will be applied to every agenda match, including
  599. tags/property searches and TODO lists. So try to make the test function
  600. do its checking as efficiently as possible. To implement a skipping
  601. condition just for specific agenda commands, use the variable
  602. `org-agenda-skip-function' which can be set in the options section
  603. of custom agenda commands."
  604. :group 'org-agenda-skip
  605. :type 'sexp)
  606. (defgroup org-agenda-daily/weekly nil
  607. "Options concerning the daily/weekly agenda."
  608. :tag "Org Agenda Daily/Weekly"
  609. :group 'org-agenda)
  610. (defgroup org-agenda-todo-list nil
  611. "Options concerning the global todo list agenda view."
  612. :tag "Org Agenda Todo List"
  613. :group 'org-agenda)
  614. (defgroup org-agenda-match-view nil
  615. "Options concerning the general tags/property/todo match agenda view."
  616. :tag "Org Agenda Match View"
  617. :group 'org-agenda)
  618. (defgroup org-agenda-search-view nil
  619. "Options concerning the search agenda view."
  620. :tag "Org Agenda Search View"
  621. :group 'org-agenda)
  622. (defvar org-agenda-archives-mode nil
  623. "Non-nil means the agenda will include archived items.
  624. If this is the symbol `trees', trees in the selected agenda scope
  625. that are marked with the ARCHIVE tag will be included anyway. When this is
  626. t, also all archive files associated with the current selection of agenda
  627. files will be included.")
  628. (defcustom org-agenda-restriction-lock-highlight-subtree t
  629. "Non-nil means highlight the whole subtree when restriction is active.
  630. Otherwise only highlight the headline. Highlighting the whole subtree is
  631. useful to ensure no edits happen beyond the restricted region."
  632. :group 'org-agenda
  633. :type 'boolean)
  634. (defcustom org-agenda-skip-comment-trees t
  635. "Non-nil means skip trees that start with the COMMENT keyword.
  636. When nil, these trees are also scanned by agenda commands."
  637. :group 'org-agenda-skip
  638. :type 'boolean)
  639. (defcustom org-agenda-todo-list-sublevels t
  640. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  641. When nil, the sublevels of a TODO entry are not checked, resulting in
  642. potentially much shorter TODO lists."
  643. :group 'org-agenda-skip
  644. :group 'org-agenda-todo-list
  645. :type 'boolean)
  646. (defcustom org-agenda-todo-ignore-with-date nil
  647. "Non-nil means don't show entries with a date in the global todo list.
  648. You can use this if you prefer to mark mere appointments with a TODO keyword,
  649. but don't want them to show up in the TODO list.
  650. When this is set, it also covers deadlines and scheduled items, the settings
  651. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  652. will be ignored.
  653. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  654. :group 'org-agenda-skip
  655. :group 'org-agenda-todo-list
  656. :type 'boolean)
  657. (defcustom org-agenda-todo-ignore-timestamp nil
  658. "Non-nil means don't show entries with a timestamp.
  659. This applies when creating the global todo list.
  660. Valid values are:
  661. past Don't show entries for today or in the past.
  662. future Don't show entries with a timestamp in the future.
  663. The idea behind this is that if it has a future
  664. timestamp, you don't want to think about it until the
  665. date.
  666. all Don't show any entries with a timestamp in the global todo list.
  667. The idea behind this is that by setting a timestamp, you
  668. have already \"taken care\" of this item.
  669. This variable can also have an integer as a value. If positive (N),
  670. todos with a timestamp N or more days in the future will be ignored. If
  671. negative (-N), todos with a timestamp N or more days in the past will be
  672. ignored. If 0, todos with a timestamp either today or in the future will
  673. be ignored. For example, a value of -1 will exclude todos with a
  674. timestamp in the past (yesterday or earlier), while a value of 7 will
  675. exclude todos with a timestamp a week or more in the future.
  676. See also `org-agenda-todo-ignore-with-date'.
  677. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  678. to make his option also apply to the tags-todo list."
  679. :group 'org-agenda-skip
  680. :group 'org-agenda-todo-list
  681. :version "24.1"
  682. :type '(choice
  683. (const :tag "Ignore future timestamp todos" future)
  684. (const :tag "Ignore past or present timestamp todos" past)
  685. (const :tag "Ignore all timestamp todos" all)
  686. (const :tag "Show timestamp todos" nil)
  687. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  688. (defcustom org-agenda-todo-ignore-scheduled nil
  689. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  690. This applies when creating the global todo list.
  691. Valid values are:
  692. past Don't show entries scheduled today or in the past.
  693. future Don't show entries scheduled in the future.
  694. The idea behind this is that by scheduling it, you don't want to
  695. think about it until the scheduled date.
  696. all Don't show any scheduled entries in the global todo list.
  697. The idea behind this is that by scheduling it, you have already
  698. \"taken care\" of this item.
  699. t Same as `all', for backward compatibility.
  700. This variable can also have an integer as a value. See
  701. `org-agenda-todo-ignore-timestamp' for more details.
  702. See also `org-agenda-todo-ignore-with-date'.
  703. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  704. to make his option also apply to the tags-todo list."
  705. :group 'org-agenda-skip
  706. :group 'org-agenda-todo-list
  707. :type '(choice
  708. (const :tag "Ignore future-scheduled todos" future)
  709. (const :tag "Ignore past- or present-scheduled todos" past)
  710. (const :tag "Ignore all scheduled todos" all)
  711. (const :tag "Ignore all scheduled todos (compatibility)" t)
  712. (const :tag "Show scheduled todos" nil)
  713. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  714. (defcustom org-agenda-todo-ignore-deadlines nil
  715. "Non-nil means ignore some deadline TODO items when making TODO list.
  716. There are different motivations for using different values, please think
  717. carefully when configuring this variable.
  718. This applies when creating the global TODO list.
  719. Valid values are:
  720. near Don't show near deadline entries. A deadline is near when it is
  721. closer than `org-deadline-warning-days' days. The idea behind this
  722. is that such items will appear in the agenda anyway.
  723. far Don't show TODO entries where a deadline has been defined, but
  724. is not going to happen anytime soon. This is useful if you want to use
  725. the TODO list to figure out what to do now.
  726. past Don't show entries with a deadline timestamp for today or in the past.
  727. future Don't show entries with a deadline timestamp in the future, not even
  728. when they become `near' ones. Use it with caution.
  729. all Ignore all TODO entries that do have a deadline.
  730. t Same as `near', for backward compatibility.
  731. This variable can also have an integer as a value. See
  732. `org-agenda-todo-ignore-timestamp' for more details.
  733. See also `org-agenda-todo-ignore-with-date'.
  734. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  735. to make his option also apply to the tags-todo list."
  736. :group 'org-agenda-skip
  737. :group 'org-agenda-todo-list
  738. :type '(choice
  739. (const :tag "Ignore near deadlines" near)
  740. (const :tag "Ignore near deadlines (compatibility)" t)
  741. (const :tag "Ignore far deadlines" far)
  742. (const :tag "Ignore all TODOs with a deadlines" all)
  743. (const :tag "Show all TODOs, even if they have a deadline" nil)
  744. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  745. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  746. "Time unit to use when possibly ignoring an agenda item.
  747. See the docstring of various `org-agenda-todo-ignore-*' options.
  748. The default is to compare time stamps using days. An item is thus
  749. considered to be in the future if it is at least one day after today.
  750. Non-nil means to compare time stamps using seconds. An item is then
  751. considered future if it has a time value later than current time."
  752. :group 'org-agenda-skip
  753. :group 'org-agenda-todo-list
  754. :version "24.4"
  755. :package-version '(Org . "8.0")
  756. :type '(choice
  757. (const :tag "Compare time with days" nil)
  758. (const :tag "Compare time with seconds" t)))
  759. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  760. "Non-nil means honor todo-list ignores options also in tags-todo search.
  761. The variables
  762. `org-agenda-todo-ignore-with-date',
  763. `org-agenda-todo-ignore-timestamp',
  764. `org-agenda-todo-ignore-scheduled',
  765. `org-agenda-todo-ignore-deadlines'
  766. make the global TODO list skip entries that have time stamps of certain
  767. kinds. If this option is set, the same options will also apply for the
  768. tags-todo search, which is the general tags/property matcher
  769. restricted to unfinished TODO entries only."
  770. :group 'org-agenda-skip
  771. :group 'org-agenda-todo-list
  772. :group 'org-agenda-match-view
  773. :type 'boolean)
  774. (defcustom org-agenda-skip-scheduled-if-done nil
  775. "Non-nil means don't show scheduled items in agenda when they are done.
  776. This is relevant for the daily/weekly agenda, not for the TODO list. It
  777. applies only to the actual date of the scheduling. Warnings about an item
  778. with a past scheduling dates are always turned off when the item is DONE."
  779. :group 'org-agenda-skip
  780. :group 'org-agenda-daily/weekly
  781. :type 'boolean)
  782. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  783. "Non-nil means skip scheduling line if same entry shows because of deadline.
  784. In the agenda of today, an entry can show up multiple times
  785. because it is both scheduled and has a nearby deadline, and maybe
  786. a plain time stamp as well.
  787. When this variable is nil, the entry will be shown several times.
  788. When set to t, then only the deadline is shown and the fact that
  789. the entry is scheduled today or was scheduled previously is not
  790. shown.
  791. When set to the symbol `not-today', skip scheduled previously,
  792. but not scheduled today.
  793. When set to the symbol `repeated-after-deadline', skip scheduled
  794. items if they are repeated beyond the current deadline."
  795. :group 'org-agenda-skip
  796. :group 'org-agenda-daily/weekly
  797. :type '(choice
  798. (const :tag "Never" nil)
  799. (const :tag "Always" t)
  800. (const :tag "Not when scheduled today" not-today)
  801. (const :tag "When repeated past deadline" repeated-after-deadline)))
  802. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  803. "Non-nil means skip timestamp line if same entry shows because of deadline.
  804. In the agenda of today, an entry can show up multiple times
  805. because it has both a plain timestamp and has a nearby deadline.
  806. When this variable is t, then only the deadline is shown and the
  807. fact that the entry has a timestamp for or including today is not
  808. shown. When this variable is nil, the entry will be shown
  809. several times."
  810. :group 'org-agenda-skip
  811. :group 'org-agenda-daily/weekly
  812. :version "24.1"
  813. :type '(choice
  814. (const :tag "Never" nil)
  815. (const :tag "Always" t)))
  816. (defcustom org-agenda-skip-deadline-if-done nil
  817. "Non-nil means don't show deadlines when the corresponding item is done.
  818. When nil, the deadline is still shown and should give you a happy feeling.
  819. This is relevant for the daily/weekly agenda. It applies only to the
  820. actual date of the deadline. Warnings about approaching and past-due
  821. deadlines are always turned off when the item is DONE."
  822. :group 'org-agenda-skip
  823. :group 'org-agenda-daily/weekly
  824. :type 'boolean)
  825. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  826. "Non-nil means skip deadline prewarning when entry is also scheduled.
  827. This will apply on all days where a prewarning for the deadline would
  828. be shown, but not at the day when the entry is actually due. On that day,
  829. the deadline will be shown anyway.
  830. This variable may be set to nil, t, the symbol `pre-scheduled',
  831. or a number which will then give the number of days before the actual
  832. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  833. eliminates the deadline prewarning only prior to the scheduled date.
  834. This can be used in a workflow where the first showing of the deadline will
  835. trigger you to schedule it, and then you don't want to be reminded of it
  836. because you will take care of it on the day when scheduled."
  837. :group 'org-agenda-skip
  838. :group 'org-agenda-daily/weekly
  839. :version "24.1"
  840. :type '(choice
  841. (const :tag "Always show prewarning" nil)
  842. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  843. (const :tag "Remove prewarning if entry is scheduled" t)
  844. (integer :tag "Restart prewarning N days before deadline")))
  845. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  846. "Non-nil means skip scheduled delay when entry also has a deadline.
  847. This variable may be set to nil, t, the symbol `post-deadline',
  848. or a number which will then give the number of days after the actual
  849. scheduled date when the delay should expire. The symbol `post-deadline'
  850. eliminates the schedule delay when the date is posterior to the deadline."
  851. :group 'org-agenda-skip
  852. :group 'org-agenda-daily/weekly
  853. :version "24.4"
  854. :package-version '(Org . "8.0")
  855. :type '(choice
  856. (const :tag "Always honor delay" nil)
  857. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  858. (const :tag "Ignore delay if entry has a deadline" t)
  859. (integer :tag "Honor delay up until N days after the scheduled date")))
  860. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  861. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  862. When non-nil, after the search for timestamps has matched once in an
  863. entry, the rest of the entry will not be searched."
  864. :group 'org-agenda-skip
  865. :type 'boolean)
  866. (defcustom org-agenda-skip-timestamp-if-done nil
  867. "Non-nil means don't select item by timestamp or -range if it is DONE."
  868. :group 'org-agenda-skip
  869. :group 'org-agenda-daily/weekly
  870. :type 'boolean)
  871. (defcustom org-agenda-dim-blocked-tasks t
  872. "Non-nil means dim blocked tasks in the agenda display.
  873. This causes some overhead during agenda construction, but if you
  874. have turned on `org-enforce-todo-dependencies',
  875. `org-enforce-todo-checkbox-dependencies', or any other blocking
  876. mechanism, this will create useful feedback in the agenda.
  877. Instead of t, this variable can also have the value `invisible'.
  878. Then blocked tasks will be invisible and only become visible when
  879. they become unblocked. An exemption to this behavior is when a task is
  880. blocked because of unchecked checkboxes below it. Since checkboxes do
  881. not show up in the agenda views, making this task invisible you remove any
  882. trace from agenda views that there is something to do. Therefore, a task
  883. that is blocked because of checkboxes will never be made invisible, it
  884. will only be dimmed."
  885. :group 'org-agenda-daily/weekly
  886. :group 'org-agenda-todo-list
  887. :version "24.3"
  888. :type '(choice
  889. (const :tag "Do not dim" nil)
  890. (const :tag "Dim to a gray face" t)
  891. (const :tag "Make invisible" invisible)))
  892. (defgroup org-agenda-startup nil
  893. "Options concerning initial settings in the Agenda in Org Mode."
  894. :tag "Org Agenda Startup"
  895. :group 'org-agenda)
  896. (defcustom org-agenda-menu-show-matcher t
  897. "Non-nil means show the match string in the agenda dispatcher menu.
  898. When nil, the matcher string is not shown, but is put into the help-echo
  899. property so than moving the mouse over the command shows it.
  900. Setting it to nil is good if matcher strings are very long and/or if
  901. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  902. :group 'org-agenda
  903. :version "24.1"
  904. :type 'boolean)
  905. (defcustom org-agenda-menu-two-columns nil
  906. "Non-nil means, use two columns to show custom commands in the dispatcher.
  907. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  908. to nil."
  909. :group 'org-agenda
  910. :version "24.1"
  911. :type 'boolean)
  912. (defcustom org-agenda-finalize-hook nil
  913. "Hook run just before displaying an agenda buffer.
  914. The buffer is still writable when the hook is called.
  915. You can modify some of the buffer substrings but you should be
  916. extra careful not to modify the text properties of the agenda
  917. headlines as the agenda display heavily relies on them."
  918. :group 'org-agenda-startup
  919. :type 'hook)
  920. (defcustom org-agenda-filter-hook nil
  921. "Hook run just after filtering with `org-agenda-filter'."
  922. :group 'org-agenda-startup
  923. :package-version '(Org . "9.4")
  924. :type 'hook)
  925. (defcustom org-agenda-mouse-1-follows-link nil
  926. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  927. A longer mouse click will still set point. Needs to be set
  928. before org.el is loaded."
  929. :group 'org-agenda-startup
  930. :type 'boolean)
  931. (defcustom org-agenda-start-with-follow-mode nil
  932. "The initial value of follow mode in a newly created agenda window."
  933. :group 'org-agenda-startup
  934. :type 'boolean)
  935. (defcustom org-agenda-follow-indirect nil
  936. "Non-nil means `org-agenda-follow-mode' displays only the
  937. current item's tree, in an indirect buffer."
  938. :group 'org-agenda
  939. :version "24.1"
  940. :type 'boolean)
  941. (defcustom org-agenda-show-outline-path t
  942. "Non-nil means show outline path in echo area after line motion."
  943. :group 'org-agenda-startup
  944. :type 'boolean)
  945. (defcustom org-agenda-start-with-entry-text-mode nil
  946. "The initial value of entry-text-mode in a newly created agenda window."
  947. :group 'org-agenda-startup
  948. :type 'boolean)
  949. (defcustom org-agenda-entry-text-maxlines 5
  950. "Number of text lines to be added when `E' is pressed in the agenda.
  951. Note that this variable only used during agenda display. To add entry text
  952. when exporting the agenda, configure the variable
  953. `org-agenda-add-entry-text-maxlines'."
  954. :group 'org-agenda
  955. :type 'integer)
  956. (defcustom org-agenda-entry-text-exclude-regexps nil
  957. "List of regular expressions to clean up entry text.
  958. The complete matches of all regular expressions in this list will be
  959. removed from entry text before it is shown in the agenda."
  960. :group 'org-agenda
  961. :type '(repeat (regexp)))
  962. (defcustom org-agenda-entry-text-leaders " > "
  963. "Text prepended to the entry text in agenda buffers."
  964. :version "24.4"
  965. :package-version '(Org . "8.0")
  966. :group 'org-agenda
  967. :type 'string)
  968. (defvar org-agenda-entry-text-cleanup-hook nil
  969. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  970. This cleanup is done in a temporary buffer, so the function may inspect and
  971. change the entire buffer.
  972. Some default stuff like drawers and scheduling/deadline dates will already
  973. have been removed when this is called, as will any matches for regular
  974. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  975. (defvar org-agenda-include-inactive-timestamps nil
  976. "Non-nil means include inactive time stamps in agenda.
  977. Dynamically scoped.")
  978. (defgroup org-agenda-windows nil
  979. "Options concerning the windows used by the Agenda in Org Mode."
  980. :tag "Org Agenda Windows"
  981. :group 'org-agenda)
  982. (defcustom org-agenda-window-setup 'reorganize-frame
  983. "How the agenda buffer should be displayed.
  984. Possible values for this option are:
  985. current-window Show agenda in the current window, keeping all other windows.
  986. other-window Use `switch-to-buffer-other-window' to display agenda.
  987. only-window Show agenda, deleting all other windows.
  988. reorganize-frame Show only two windows on the current frame, the current
  989. window and the agenda.
  990. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  991. Also, when exiting the agenda, kill that frame.
  992. other-tab Use `switch-to-buffer-other-tab' to display the
  993. agenda, making use of the `tab-bar-mode' introduced
  994. in Emacs version 27.1. Also, kill that tab when
  995. exiting the agenda view.
  996. See also the variable `org-agenda-restore-windows-after-quit'."
  997. :group 'org-agenda-windows
  998. :type '(choice
  999. (const current-window)
  1000. (const other-frame)
  1001. (const other-tab)
  1002. (const other-window)
  1003. (const only-window)
  1004. (const reorganize-frame))
  1005. :package-version '(Org . "9.4"))
  1006. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  1007. "The min and max height of the agenda window as a fraction of frame height.
  1008. The value of the variable is a cons cell with two numbers between 0 and 1.
  1009. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  1010. :group 'org-agenda-windows
  1011. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  1012. (defcustom org-agenda-restore-windows-after-quit nil
  1013. "Non-nil means restore window configuration upon exiting agenda.
  1014. Before the window configuration is changed for displaying the
  1015. agenda, the current status is recorded. When the agenda is
  1016. exited with `q' or `x' and this option is set, the old state is
  1017. restored. If `org-agenda-window-setup' is `other-frame' or
  1018. `other-tab', the value of this option will be ignored."
  1019. :group 'org-agenda-windows
  1020. :type 'boolean)
  1021. (defcustom org-agenda-span 'week
  1022. "Number of days to include in overview display.
  1023. Can be day, week, month, year, or any number of days.
  1024. Custom commands can set this variable in the options section."
  1025. :group 'org-agenda-daily/weekly
  1026. :type '(choice (const :tag "Day" day)
  1027. (const :tag "Week" week)
  1028. (const :tag "Fortnight" fortnight)
  1029. (const :tag "Month" month)
  1030. (const :tag "Year" year)
  1031. (integer :tag "Custom")))
  1032. (defcustom org-agenda-start-on-weekday 1
  1033. "Non-nil means start the overview always on the specified weekday.
  1034. 0 denotes Sunday, 1 denotes Monday, etc.
  1035. When nil, always start on the current day.
  1036. Custom commands can set this variable in the options section."
  1037. :group 'org-agenda-daily/weekly
  1038. :type '(choice (const :tag "Today" nil)
  1039. (integer :tag "Weekday No.")))
  1040. (defcustom org-agenda-show-all-dates t
  1041. "Non-nil means `org-agenda' shows every day in the selected range.
  1042. When nil, only the days which actually have entries are shown."
  1043. :group 'org-agenda-daily/weekly
  1044. :type 'boolean)
  1045. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1046. "Format string for displaying dates in the agenda.
  1047. Used by the daily/weekly agenda. This should be a format string
  1048. understood by `format-time-string', or a function returning the
  1049. formatted date as a string. The function must take a single
  1050. argument, a calendar-style date list like (month day year)."
  1051. :group 'org-agenda-daily/weekly
  1052. :type '(choice
  1053. (string :tag "Format string")
  1054. (function :tag "Function")))
  1055. (defun org-agenda-end-of-line ()
  1056. "Go to the end of visible line."
  1057. (interactive)
  1058. (goto-char (line-end-position)))
  1059. (defun org-agenda-format-date-aligned (date)
  1060. "Format a DATE string for display in the daily/weekly agenda.
  1061. This function makes sure that dates are aligned for easy reading."
  1062. (require 'cal-iso)
  1063. (let* ((dayname (calendar-day-name date))
  1064. (day (cadr date))
  1065. (day-of-week (calendar-day-of-week date))
  1066. (month (car date))
  1067. (monthname (calendar-month-name month))
  1068. (year (nth 2 date))
  1069. (iso-week (org-days-to-iso-week
  1070. (calendar-absolute-from-gregorian date)))
  1071. ;; (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1072. ;; (1- year))
  1073. ;; ((and (= month 12) (<= iso-week 1))
  1074. ;; (1+ year))
  1075. ;; (t year)))
  1076. (weekstring (if (= day-of-week 1)
  1077. (format " W%02d" iso-week)
  1078. "")))
  1079. (format "%-10s %2d %s %4d%s"
  1080. dayname day monthname year weekstring)))
  1081. (defcustom org-agenda-time-leading-zero nil
  1082. "Non-nil means use leading zero for military times in agenda.
  1083. For example, 9:30am would become 09:30 rather than 9:30."
  1084. :group 'org-agenda-daily/weekly
  1085. :version "24.1"
  1086. :type 'boolean)
  1087. (defcustom org-agenda-timegrid-use-ampm nil
  1088. "When set, show AM/PM style timestamps on the timegrid."
  1089. :group 'org-agenda
  1090. :version "24.1"
  1091. :type 'boolean)
  1092. (defcustom org-agenda-clock-report-header nil
  1093. "Header inserted before the table in Org agenda clock report mode.
  1094. See Info node `(org) Agenda Commands' for more details."
  1095. :group 'org-agenda
  1096. :type '(choice
  1097. (string :tag "Header")
  1098. (const :tag "No header" nil))
  1099. :safe #'stringp
  1100. :package-version '(Org . "9.6"))
  1101. (defun org-agenda-time-of-day-to-ampm (time)
  1102. "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
  1103. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1104. (minute (substring time -2))
  1105. (ampm "am"))
  1106. (cond
  1107. ((equal hour-number 12)
  1108. (setq ampm "pm"))
  1109. ((> hour-number 12)
  1110. (setq ampm "pm")
  1111. (setq hour-number (- hour-number 12))))
  1112. (concat
  1113. (if org-agenda-time-leading-zero
  1114. (format "%02d" hour-number)
  1115. (format "%02s" (number-to-string hour-number)))
  1116. ":" minute ampm)))
  1117. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1118. "Conditionally convert TIME to AM/PM format.
  1119. This is based on `org-agenda-timegrid-use-ampm'."
  1120. (if org-agenda-timegrid-use-ampm
  1121. (org-agenda-time-of-day-to-ampm time)
  1122. time))
  1123. (defcustom org-agenda-weekend-days '(6 0)
  1124. "Which days are weekend?
  1125. These days get the special face `org-agenda-date-weekend' in the agenda."
  1126. :group 'org-agenda-daily/weekly
  1127. :type '(set :greedy t
  1128. (const :tag "Monday" 1)
  1129. (const :tag "Tuesday" 2)
  1130. (const :tag "Wednesday" 3)
  1131. (const :tag "Thursday" 4)
  1132. (const :tag "Friday" 5)
  1133. (const :tag "Saturday" 6)
  1134. (const :tag "Sunday" 0)))
  1135. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1136. "Non-nil means jump to today when moving a past date forward in time.
  1137. When using S-right in the agenda to move a date forward, and the date
  1138. stamp currently points to the past, the first key press will move it
  1139. to today. When nil, just move one day forward even if the date stays
  1140. in the past."
  1141. :group 'org-agenda-daily/weekly
  1142. :version "24.1"
  1143. :type 'boolean)
  1144. (defcustom org-agenda-diary-file 'diary-file
  1145. "File to which to add new entries with the `i' key in agenda and calendar.
  1146. When this is the symbol `diary-file', the functionality in the Emacs
  1147. calendar will be used to add entries to the `diary-file'. But when this
  1148. points to a file, `org-agenda-diary-entry' will be used instead."
  1149. :group 'org-agenda
  1150. :type '(choice
  1151. (const :tag "The standard Emacs diary file" diary-file)
  1152. (file :tag "Special Org file diary entries")))
  1153. (defcustom org-agenda-include-diary nil
  1154. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1155. Custom commands can set this variable in the options section."
  1156. :group 'org-agenda-daily/weekly
  1157. :type 'boolean)
  1158. (defcustom org-agenda-include-deadlines t
  1159. "If non-nil, include entries within their deadline warning period.
  1160. Custom commands can set this variable in the options section."
  1161. :group 'org-agenda-daily/weekly
  1162. :version "24.1"
  1163. :type 'boolean)
  1164. (defcustom org-agenda-show-future-repeats t
  1165. "Non-nil shows repeated entries in the future part of the agenda.
  1166. When set to the symbol `next' only the first future repeat is shown."
  1167. :group 'org-agenda-daily/weekly
  1168. :type '(choice
  1169. (const :tag "Show all repeated entries" t)
  1170. (const :tag "Show next repeated entry" next)
  1171. (const :tag "Do not show repeated entries" nil))
  1172. :version "26.1"
  1173. :package-version '(Org . "9.1")
  1174. :safe #'symbolp)
  1175. (defcustom org-agenda-prefer-last-repeat nil
  1176. "Non-nil sets date for repeated entries to their last repeat.
  1177. When nil, display SCHEDULED and DEADLINE dates at their base
  1178. date, and in today's agenda, as a reminder. Display plain
  1179. time-stamps, on the other hand, at every repeat date in the past
  1180. in addition to the base date.
  1181. When non-nil, show a repeated entry at its latest repeat date,
  1182. possibly being today even if it wasn't marked as done. This
  1183. setting is useful if you do not always mark repeated entries as
  1184. done and, yet, consider that reaching repeat date starts the task
  1185. anew.
  1186. When set to a list of strings, prefer last repeats only for
  1187. entries with these TODO keywords."
  1188. :group 'org-agenda-daily/weekly
  1189. :type '(choice
  1190. (const :tag "Prefer last repeat" t)
  1191. (const :tag "Prefer base date" nil)
  1192. (repeat :tag "Prefer last repeat for entries with these TODO keywords"
  1193. (string :tag "TODO keyword")))
  1194. :version "26.1"
  1195. :package-version '(Org . "9.1")
  1196. :safe (lambda (x) (or (booleanp x) (consp x))))
  1197. (defcustom org-scheduled-past-days 10000
  1198. "Number of days to continue listing scheduled items not marked DONE.
  1199. When an item is scheduled on a date, it shows up in the agenda on
  1200. this day and will be listed until it is marked done or for the
  1201. number of days given here."
  1202. :group 'org-agenda-daily/weekly
  1203. :type 'integer
  1204. :safe 'integerp)
  1205. (defcustom org-deadline-past-days 10000
  1206. "Number of days to warn about missed deadlines.
  1207. When an item has deadline on a date, it shows up in the agenda on
  1208. this day and will appear as a reminder until it is marked DONE or
  1209. for the number of days given here."
  1210. :group 'org-agenda-daily/weekly
  1211. :type 'integer
  1212. :version "26.1"
  1213. :package-version '(Org . "9.1")
  1214. :safe 'integerp)
  1215. (defcustom org-agenda-log-mode-items '(closed clock)
  1216. "List of items that should be shown in agenda log mode.
  1217. \\<org-agenda-mode-map>\
  1218. This list may contain the following symbols:
  1219. closed Show entries that have been closed on that day.
  1220. clock Show entries that have received clocked time on that day.
  1221. state Show all logged state changes.
  1222. Note that instead of changing this variable, you can also press \
  1223. `\\[universal-argument] \\[org-agenda-log-mode]' in
  1224. the agenda to display all available LOG items temporarily."
  1225. :group 'org-agenda-daily/weekly
  1226. :type '(set :greedy t (const closed) (const clock) (const state)))
  1227. (defcustom org-agenda-clock-consistency-checks
  1228. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1229. :gap-ok-around ("4:00")
  1230. :default-face ((:background "DarkRed") (:foreground "white"))
  1231. :overlap-face nil :gap-face nil :no-end-time-face nil
  1232. :long-face nil :short-face nil)
  1233. "This is a property list, with the following keys:
  1234. :max-duration Mark clocking chunks that are longer than this time.
  1235. This is a time string like \"HH:MM\", or the number
  1236. of minutes as an integer.
  1237. :min-duration Mark clocking chunks that are shorter that this.
  1238. This is a time string like \"HH:MM\", or the number
  1239. of minutes as an integer.
  1240. :max-gap Mark gaps between clocking chunks that are longer than
  1241. this duration. A number of minutes, or a string
  1242. like \"HH:MM\".
  1243. :gap-ok-around List of times during the day which are usually not working
  1244. times. When a gap is detected, but the gap contains any
  1245. of these times, the gap is *not* reported. For example,
  1246. if this is (\"4:00\" \"13:00\") then gaps that contain
  1247. 4:00 in the morning (i.e. the night) and 13:00
  1248. (i.e. a typical lunch time) do not cause a warning.
  1249. You should have at least one time during the night in this
  1250. list, or otherwise the first task each morning will trigger
  1251. a warning because it follows a long gap.
  1252. Furthermore, the following properties can be used to define faces for
  1253. issue display.
  1254. :default-face the default face, if the specific face is undefined
  1255. :overlap-face face for overlapping clocks
  1256. :gap-face face for gaps between clocks
  1257. :no-end-time-face face for incomplete clocks
  1258. :long-face face for clock intervals that are too long
  1259. :short-face face for clock intervals that are too short"
  1260. :group 'org-agenda-daily/weekly
  1261. :group 'org-clock
  1262. :version "24.1"
  1263. :type 'plist)
  1264. (defcustom org-agenda-log-mode-add-notes t
  1265. "Non-nil means add first line of notes to log entries in agenda views.
  1266. If a log item like a state change or a clock entry is associated with
  1267. notes, the first line of these notes will be added to the entry in the
  1268. agenda display."
  1269. :group 'org-agenda-daily/weekly
  1270. :type 'boolean)
  1271. (defcustom org-agenda-start-with-log-mode nil
  1272. "The initial value of log-mode in a newly created agenda window.
  1273. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1274. explanations on the possible values."
  1275. :group 'org-agenda-startup
  1276. :group 'org-agenda-daily/weekly
  1277. :type '(choice (const :tag "Don't show log items" nil)
  1278. (const :tag "Show only log items" only)
  1279. (const :tag "Show all possible log items" clockcheck)
  1280. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1281. (choice (const :tag "Show closed log items" closed)
  1282. (const :tag "Show clocked log items" clock)
  1283. (const :tag "Show all logged state changes" state)))))
  1284. (defcustom org-agenda-start-with-clockreport-mode nil
  1285. "The initial value of clockreport-mode in a newly created agenda window."
  1286. :group 'org-agenda-startup
  1287. :group 'org-agenda-daily/weekly
  1288. :type 'boolean)
  1289. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1290. "Property list with parameters for the clocktable in clockreport mode.
  1291. This is the display mode that shows a clock table in the daily/weekly
  1292. agenda, the properties for this dynamic block can be set here.
  1293. The usual clocktable parameters are allowed here, but you cannot set
  1294. the properties :name, :tstart, :tend, :block, and :scope - these will
  1295. be overwritten to make sure the content accurately reflects the
  1296. current display in the agenda."
  1297. :group 'org-agenda-daily/weekly
  1298. :type 'plist)
  1299. (defvaralias 'org-agenda-search-view-search-words-only
  1300. 'org-agenda-search-view-always-boolean)
  1301. (defcustom org-agenda-search-view-always-boolean nil
  1302. "Non-nil means the search string is interpreted as individual parts.
  1303. The search string for search view can either be interpreted as a phrase,
  1304. or as a list of snippets that define a boolean search for a number of
  1305. strings.
  1306. When this is non-nil, the string will be split on whitespace, and each
  1307. snippet will be searched individually, and all must match in order to
  1308. select an entry. A snippet is then a single string of non-white
  1309. characters, or a string in double quotes, or a regexp in {} braces.
  1310. If a snippet is preceded by \"-\", the snippet must *not* match.
  1311. \"+\" is syntactic sugar for positive selection. Each snippet may
  1312. be found as a full word or a partial word, but see the variable
  1313. `org-agenda-search-view-force-full-words'.
  1314. When this is nil, search will look for the entire search phrase as one,
  1315. with each space character matching any amount of whitespace, including
  1316. line breaks.
  1317. Even when this is nil, you can still switch to Boolean search dynamically
  1318. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1319. is a regexp marked with braces like \"{abc}\", this will also switch to
  1320. boolean search."
  1321. :group 'org-agenda-search-view
  1322. :version "24.1"
  1323. :type 'boolean)
  1324. (defcustom org-agenda-search-view-force-full-words nil
  1325. "Non-nil means, search words must be matches as complete words.
  1326. When nil, they may also match part of a word."
  1327. :group 'org-agenda-search-view
  1328. :version "24.1"
  1329. :type 'boolean)
  1330. (defcustom org-agenda-search-view-max-outline-level 0
  1331. "Maximum outline level to display in search view.
  1332. E.g. when this is set to 1, the search view will only
  1333. show headlines of level 1. When set to 0, the default
  1334. value, don't limit agenda view by outline level."
  1335. :group 'org-agenda-search-view
  1336. :version "26.1"
  1337. :package-version '(Org . "8.3")
  1338. :type 'integer)
  1339. (defgroup org-agenda-time-grid nil
  1340. "Options concerning the time grid in the Org Agenda."
  1341. :tag "Org Agenda Time Grid"
  1342. :group 'org-agenda)
  1343. (defcustom org-agenda-search-headline-for-time t
  1344. "Non-nil means search headline for a time-of-day.
  1345. If the headline contains a time-of-day in one format or another, it will
  1346. be used to sort the entry into the time sequence of items for a day.
  1347. Some people have time stamps in the headline that refer to the creation
  1348. time or so, and then this produces an unwanted side effect. If this is
  1349. the case for your, use this variable to turn off searching the headline
  1350. for a time."
  1351. :group 'org-agenda-time-grid
  1352. :type 'boolean)
  1353. (defcustom org-agenda-use-time-grid t
  1354. "Non-nil means show a time grid in the agenda schedule.
  1355. A time grid is a set of lines for specific times (like every two hours between
  1356. 8:00 and 20:00). The items scheduled for a day at specific times are
  1357. sorted in between these lines.
  1358. For details about when the grid will be shown, and what it will look like, see
  1359. the variable `org-agenda-time-grid'."
  1360. :group 'org-agenda-time-grid
  1361. :type 'boolean)
  1362. (defcustom org-agenda-time-grid
  1363. (let ((graphical (and (display-graphic-p)
  1364. (char-displayable-p ?┄))))
  1365. `((daily today require-timed)
  1366. (800 1000 1200 1400 1600 1800 2000)
  1367. ,(if graphical " ┄┄┄┄┄ " "......")
  1368. ,(if graphical "┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄" "----------------")))
  1369. "The settings for time grid for agenda display.
  1370. This is a list of four items. The first item is again a list. It contains
  1371. symbols specifying conditions when the grid should be displayed:
  1372. daily if the agenda shows a single day
  1373. weekly if the agenda shows an entire week
  1374. today show grid on current date, independent of daily/weekly display
  1375. require-timed show grid only if at least one item has a time specification
  1376. remove-match skip grid times already present in an entry
  1377. The second item is a list of integers, indicating the times that
  1378. should have a grid line.
  1379. The third item is a string which will be placed right after the
  1380. times that have a grid line.
  1381. The fourth item is a string placed after the grid times. This
  1382. will align with agenda items."
  1383. :group 'org-agenda-time-grid
  1384. :package-version '(Org . "9.6")
  1385. :type
  1386. '(list
  1387. (set :greedy t :tag "Grid Display Options"
  1388. (const :tag "Show grid in single day agenda display" daily)
  1389. (const :tag "Show grid in weekly agenda display" weekly)
  1390. (const :tag "Always show grid for today" today)
  1391. (const :tag "Show grid only if any timed entries are present"
  1392. require-timed)
  1393. (const :tag "Skip grid times already present in an entry"
  1394. remove-match))
  1395. (repeat :tag "Grid Times" (integer :tag "Time"))
  1396. (string :tag "Grid String (after agenda times)")
  1397. (string :tag "Grid String (aligns with agenda items)")))
  1398. (defcustom org-agenda-show-current-time-in-grid t
  1399. "Non-nil means show the current time in the time grid."
  1400. :group 'org-agenda-time-grid
  1401. :version "24.1"
  1402. :type 'boolean)
  1403. (defcustom org-agenda-current-time-string
  1404. (if (and (display-graphic-p)
  1405. (char-displayable-p ?←)
  1406. (char-displayable-p ?─))
  1407. "← now ───────────────────────────────────────────────"
  1408. "now - - - - - - - - - - - - - - - - - - - - - - - - -")
  1409. "The string for the current time marker in the agenda."
  1410. :group 'org-agenda-time-grid
  1411. :package-version '(Org . "9.6")
  1412. :type 'string)
  1413. (defgroup org-agenda-sorting nil
  1414. "Options concerning sorting in the Org Agenda."
  1415. :tag "Org Agenda Sorting"
  1416. :group 'org-agenda)
  1417. (defcustom org-agenda-sorting-strategy
  1418. '((agenda habit-down time-up priority-down category-keep)
  1419. (todo priority-down category-keep)
  1420. (tags priority-down category-keep)
  1421. (search category-keep))
  1422. "Sorting structure for the agenda items of a single day.
  1423. This is a list of symbols which will be used in sequence to determine
  1424. if an entry should be listed before another entry. The following
  1425. symbols are recognized:
  1426. time-up Put entries with time-of-day indications first, early first.
  1427. time-down Put entries with time-of-day indications first, late first.
  1428. timestamp-up Sort by any timestamp, early first.
  1429. timestamp-down Sort by any timestamp, late first.
  1430. scheduled-up Sort by scheduled timestamp, early first.
  1431. scheduled-down Sort by scheduled timestamp, late first.
  1432. deadline-up Sort by deadline timestamp, early first.
  1433. deadline-down Sort by deadline timestamp, late first.
  1434. ts-up Sort by active timestamp, early first.
  1435. ts-down Sort by active timestamp, late first.
  1436. tsia-up Sort by inactive timestamp, early first.
  1437. tsia-down Sort by inactive timestamp, late first.
  1438. category-keep Keep the default order of categories, corresponding to the
  1439. sequence in `org-agenda-files'.
  1440. category-up Sort alphabetically by category, A-Z.
  1441. category-down Sort alphabetically by category, Z-A.
  1442. tag-up Sort alphabetically by last tag, A-Z.
  1443. tag-down Sort alphabetically by last tag, Z-A.
  1444. priority-up Sort numerically by priority, high priority last.
  1445. priority-down Sort numerically by priority, high priority first.
  1446. todo-state-up Sort by todo state, tasks that are done last.
  1447. todo-state-down Sort by todo state, tasks that are done first.
  1448. effort-up Sort numerically by estimated effort, high effort last.
  1449. effort-down Sort numerically by estimated effort, high effort first.
  1450. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1451. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1452. habit-up Put entries that are habits first.
  1453. habit-down Put entries that are habits last.
  1454. alpha-up Sort headlines alphabetically.
  1455. alpha-down Sort headlines alphabetically, reversed.
  1456. The different possibilities will be tried in sequence, and testing stops
  1457. if one comparison returns a \"not-equal\". For example,
  1458. (setq org-agenda-sorting-strategy
  1459. \\='(time-up category-keep priority-down))
  1460. means: Pull out all entries having a specified time of day and sort them,
  1461. in order to make a time schedule for the current day the first thing in the
  1462. agenda listing for the day. Of the entries without a time indication, keep
  1463. the grouped in categories, don't sort the categories, but keep them in
  1464. the sequence given in `org-agenda-files'. Within each category sort by
  1465. priority.
  1466. Leaving out `category-keep' would mean that items will be sorted across
  1467. categories by priority.
  1468. Instead of a single list, this can also be a set of list for specific
  1469. contents, with a context symbol in the car of the list, any of
  1470. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1471. Custom commands can bind this variable in the options section."
  1472. :group 'org-agenda-sorting
  1473. :type `(choice
  1474. (repeat :tag "General" ,org-sorting-choice)
  1475. (list :tag "Individually"
  1476. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1477. (repeat ,org-sorting-choice))
  1478. (cons (const :tag "Strategy for TODO lists" todo)
  1479. (repeat ,org-sorting-choice))
  1480. (cons (const :tag "Strategy for Tags matches" tags)
  1481. (repeat ,org-sorting-choice))
  1482. (cons (const :tag "Strategy for search matches" search)
  1483. (repeat ,org-sorting-choice)))))
  1484. (defcustom org-agenda-cmp-user-defined nil
  1485. "A function to define the comparison `user-defined'.
  1486. This function must receive two arguments, agenda entry a and b.
  1487. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1488. the user comparison, return nil.
  1489. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1490. part of an agenda sorting strategy."
  1491. :group 'org-agenda-sorting
  1492. :type 'symbol)
  1493. (defcustom org-agenda-sort-notime-is-late t
  1494. "Non-nil means items without time are considered late.
  1495. This is only relevant for sorting. When t, items which have no explicit
  1496. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1497. do have a time. When nil, the default time is before 0:00. You can use this
  1498. option to decide if the schedule for today should come before or after timeless
  1499. agenda entries."
  1500. :group 'org-agenda-sorting
  1501. :type 'boolean)
  1502. (defcustom org-agenda-sort-noeffort-is-high t
  1503. "Non-nil means items without effort estimate are sorted as high effort.
  1504. This also applies when filtering an agenda view with respect to the
  1505. < or > effort operator. Then, tasks with no effort defined will be treated
  1506. as tasks with high effort.
  1507. When nil, such items are sorted as 0 minutes effort."
  1508. :group 'org-agenda-sorting
  1509. :type 'boolean)
  1510. (defgroup org-agenda-line-format nil
  1511. "Options concerning the entry prefix in the Org agenda display."
  1512. :tag "Org Agenda Line Format"
  1513. :group 'org-agenda)
  1514. (defcustom org-agenda-prefix-format
  1515. '((agenda . " %i %-12:c%?-12t% s")
  1516. (todo . " %i %-12:c")
  1517. (tags . " %i %-12:c")
  1518. (search . " %i %-12:c"))
  1519. "Format specifications for the prefix of items in the agenda views.
  1520. An alist with one entry per agenda type. The keys of the
  1521. sublists are `agenda', `todo', `search' and `tags'. The values
  1522. are format strings.
  1523. This format works similar to a printf format, with the following meaning:
  1524. %c the category of the item, \"Diary\" for entries from the diary,
  1525. or as given by the CATEGORY keyword or derived from the file name
  1526. %e the effort required by the item
  1527. %l the level of the item (insert X space(s) if item is of level X)
  1528. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1529. %T the last tag of the item (ignore inherited tags, which come first)
  1530. %t the HH:MM time-of-day specification if one applies to the entry
  1531. %s Scheduling/Deadline information, a short string
  1532. %b show breadcrumbs, i.e., the names of the higher levels
  1533. %(expression) Eval EXPRESSION and replace the control string
  1534. by the result
  1535. All specifiers work basically like the standard `%s' of printf, but may
  1536. contain two additional characters: a question mark just after the `%'
  1537. and a whitespace/punctuation character just before the final letter.
  1538. If the first character after `%' is a question mark, the entire field
  1539. will only be included if the corresponding value applies to the current
  1540. entry. This is useful for fields which should have fixed width when
  1541. present, but zero width when absent. For example, \"%?-12t\" will
  1542. result in a 12 character time field if a time of the day is specified,
  1543. but will completely disappear in entries which do not contain a time.
  1544. If there is punctuation or whitespace character just before the
  1545. final format letter, this character will be appended to the field
  1546. value if the value is not empty. For example, the format
  1547. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1548. the category is empty, no additional colon is inserted.
  1549. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1550. which means:
  1551. - Indent the line with two space characters
  1552. - Give the category a 12 chars wide field, padded with whitespace on
  1553. the right (because of `-'). Append a colon if there is a category
  1554. (because of `:').
  1555. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1556. time, don't put in an empty field, just skip it (because of '?').
  1557. - Finally, put the scheduling information.
  1558. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1559. `org-agenda-remove-tags'.
  1560. Custom commands can set this variable in the options section."
  1561. :type '(choice
  1562. (string :tag "General format")
  1563. (list :greedy t :tag "View dependent"
  1564. (cons (const agenda) (string :tag "Format"))
  1565. (cons (const todo) (string :tag "Format"))
  1566. (cons (const tags) (string :tag "Format"))
  1567. (cons (const search) (string :tag "Format"))))
  1568. :group 'org-agenda-line-format
  1569. :version "26.1"
  1570. :package-version '(Org . "9.1"))
  1571. (defcustom org-agenda-breadcrumbs-separator "->"
  1572. "The separator of breadcrumbs in agenda lines."
  1573. :group 'org-agenda-line-format
  1574. :package-version '(Org . "9.3")
  1575. :type 'string
  1576. :safe #'stringp)
  1577. (defvar org-prefix-format-compiled nil
  1578. "The compiled prefix format and associated variables.
  1579. This is a list where first element is a list of variable bindings, and second
  1580. element is the compiled format expression. See the variable
  1581. `org-agenda-prefix-format'.")
  1582. (defcustom org-agenda-todo-keyword-format "%-1s"
  1583. "Format for the TODO keyword in agenda lines.
  1584. Set this to something like \"%-12s\" if you want all TODO keywords
  1585. to occupy a fixed space in the agenda display."
  1586. :group 'org-agenda-line-format
  1587. :type 'string)
  1588. (defcustom org-agenda-diary-sexp-prefix nil
  1589. "A regexp that matches part of a diary sexp entry
  1590. which should be treated as scheduling/deadline information in
  1591. `org-agenda'.
  1592. For example, you can use this to extract the `diary-remind-message' from
  1593. `diary-remind' entries."
  1594. :group 'org-agenda-line-format
  1595. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1596. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1597. "Text preceding timerange entries in the agenda view.
  1598. This is a list with two strings. The first applies when the range
  1599. is entirely on one day. The second applies if the range spans several days.
  1600. The strings may have two \"%d\" format specifiers which will be filled
  1601. with the sequence number of the days, and the total number of days in the
  1602. range, respectively."
  1603. :group 'org-agenda-line-format
  1604. :type '(list
  1605. (string :tag "Deadline today ")
  1606. (choice :tag "Deadline relative"
  1607. (string :tag "Format string")
  1608. (function))))
  1609. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1610. "Text preceding scheduled items in the agenda view.
  1611. This is a list with two strings. The first applies when the item is
  1612. scheduled on the current day. The second applies when it has been scheduled
  1613. previously, it may contain a %d indicating that this is the nth time that
  1614. this item is scheduled, due to automatic rescheduling of unfinished items
  1615. for the following day. So this number is one larger than the number of days
  1616. that passed since this item was scheduled first."
  1617. :group 'org-agenda-line-format
  1618. :version "24.4"
  1619. :package-version '(Org . "8.0")
  1620. :type '(list
  1621. (string :tag "Scheduled today ")
  1622. (string :tag "Scheduled previously")))
  1623. (defcustom org-agenda-inactive-leader "["
  1624. "Text preceding item pulled into the agenda by inactive time stamps.
  1625. These entries are added to the agenda when pressing \"[\"."
  1626. :group 'org-agenda-line-format
  1627. :version "24.1"
  1628. :type 'string)
  1629. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1630. "Text preceding deadline items in the agenda view.
  1631. This is a list with three strings. The first applies when the item has its
  1632. deadline on the current day. The second applies when the deadline is in the
  1633. future, the third one when it is in the past. The strings may contain %d
  1634. to capture the number of days."
  1635. :group 'org-agenda-line-format
  1636. :version "24.4"
  1637. :package-version '(Org . "8.0")
  1638. :type '(list
  1639. (string :tag "Deadline today ")
  1640. (string :tag "Deadline in the future ")
  1641. (string :tag "Deadline in the past ")))
  1642. (defcustom org-agenda-remove-times-when-in-prefix t
  1643. "Non-nil means remove duplicate time specifications in agenda items.
  1644. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1645. time-of-day specification in a headline or diary entry is extracted and
  1646. placed into the prefix. If this option is non-nil, the original specification
  1647. \(a timestamp or -range, or just a plain time(range) specification like
  1648. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1649. cluttered.
  1650. The option can be t or nil. It may also be the symbol `beg', indicating
  1651. that the time should only be removed when it is located at the beginning of
  1652. the headline/diary entry."
  1653. :group 'org-agenda-line-format
  1654. :type '(choice
  1655. (const :tag "Always" t)
  1656. (const :tag "Never" nil)
  1657. (const :tag "When at beginning of entry" beg)))
  1658. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1659. "Non-nil means remove time ranges specifications in agenda
  1660. items that span on several days."
  1661. :group 'org-agenda-line-format
  1662. :version "24.1"
  1663. :type 'boolean)
  1664. (defcustom org-agenda-default-appointment-duration nil
  1665. "Default duration for appointments that only have a starting time.
  1666. When nil, no duration is specified in such cases.
  1667. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1668. :group 'org-agenda-line-format
  1669. :type '(choice
  1670. (integer :tag "Minutes")
  1671. (const :tag "No default duration")))
  1672. (defcustom org-agenda-show-inherited-tags t
  1673. "Non-nil means show inherited tags in each agenda line.
  1674. When this option is set to `always', it takes precedence over
  1675. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1676. in every agenda.
  1677. When this option is set to t (the default), inherited tags are
  1678. shown when they are available, i.e. when the value of
  1679. `org-agenda-use-tag-inheritance' enables tag inheritance for the
  1680. given agenda type.
  1681. This can be set to a list of agenda types in which the agenda
  1682. must display the inherited tags. Available types are `todo',
  1683. `agenda' and `search'.
  1684. When set to nil, never show inherited tags in agenda lines."
  1685. :group 'org-agenda-line-format
  1686. :group 'org-agenda
  1687. :version "24.3"
  1688. :type '(choice
  1689. (const :tag "Show inherited tags when available" t)
  1690. (const :tag "Always show inherited tags" always)
  1691. (repeat :tag "Show inherited tags only in selected agenda types"
  1692. (symbol :tag "Agenda type"))))
  1693. (defcustom org-agenda-use-tag-inheritance '(todo search agenda)
  1694. "List of agenda view types where to use tag inheritance.
  1695. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1696. controlled by `org-use-tag-inheritance'. In other agenda types,
  1697. `org-use-tag-inheritance' is not used for the selection of the
  1698. agenda entries. Still, you may want the agenda to be aware of
  1699. the inherited tags anyway, e.g. for later tag filtering.
  1700. Allowed value are `todo', `search' and `agenda'.
  1701. This variable has no effect if `org-agenda-show-inherited-tags'
  1702. is set to `always'. In that case, the agenda is aware of those
  1703. tags.
  1704. The default value sets tags in every agenda type. Setting this
  1705. option to nil will speed up non-tags agenda view a lot."
  1706. :group 'org-agenda
  1707. :version "26.1"
  1708. :package-version '(Org . "9.1")
  1709. :type '(choice
  1710. (const :tag "Use tag inheritance in all agenda types" t)
  1711. (repeat :tag "Use tag inheritance in selected agenda types"
  1712. (symbol :tag "Agenda type"))))
  1713. (defcustom org-agenda-hide-tags-regexp nil
  1714. "Regular expression used to filter away specific tags in agenda views.
  1715. This means that these tags will be present, but not be shown in the agenda
  1716. line. Secondary filtering will still work on the hidden tags.
  1717. Nil means don't hide any tags."
  1718. :group 'org-agenda-line-format
  1719. :type '(choice
  1720. (const :tag "Hide none" nil)
  1721. (regexp :tag "Regexp ")))
  1722. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1723. 'org-agenda-remove-tags)
  1724. (defcustom org-agenda-remove-tags nil
  1725. "Non-nil means remove the tags from the headline copy in the agenda.
  1726. When this is the symbol `prefix', only remove tags when
  1727. `org-agenda-prefix-format' contains a `%T' specifier."
  1728. :group 'org-agenda-line-format
  1729. :type '(choice
  1730. (const :tag "Always" t)
  1731. (const :tag "Never" nil)
  1732. (const :tag "When prefix format contains %T" prefix)))
  1733. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1734. (defcustom org-agenda-tags-column 'auto
  1735. "Shift tags in agenda items to this column.
  1736. If set to `auto', tags will be automatically aligned to the right
  1737. edge of the window.
  1738. If set to a positive number, tags will be left-aligned to that
  1739. column. If set to a negative number, tags will be right-aligned
  1740. to that column. For example, -80 works well for a normal 80
  1741. character screen."
  1742. :group 'org-agenda-line-format
  1743. :type '(choice
  1744. (const :tag "Automatically align to right edge of window" auto)
  1745. (integer :tag "Specific column" -80))
  1746. :package-version '(Org . "9.1")
  1747. :version "26.1")
  1748. (defcustom org-agenda-fontify-priorities 'cookies
  1749. "Non-nil means highlight low and high priorities in agenda.
  1750. When t, the highest priority entries are bold, lowest priority italic.
  1751. However, settings in `org-priority-faces' will overrule these faces.
  1752. When this variable is the symbol `cookies', only fontify the
  1753. cookies, not the entire task.
  1754. This may also be an association list of priority faces, whose
  1755. keys are the character values of `org-priority-highest',
  1756. `org-priority-default', and `org-priority-lowest' (the default values
  1757. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1758. color as a string, or a list like `(:background \"Red\")'.
  1759. If it is a color, the variable `org-faces-easy-properties'
  1760. determines if it is a foreground or a background color."
  1761. :group 'org-agenda-line-format
  1762. :type '(choice
  1763. (const :tag "Never" nil)
  1764. (const :tag "Defaults" t)
  1765. (const :tag "Cookies only" cookies)
  1766. (repeat :tag "Specify"
  1767. (list (character :tag "Priority" :value ?A)
  1768. (choice :tag "Face "
  1769. (string :tag "Color")
  1770. (sexp :tag "Face"))))))
  1771. (defcustom org-agenda-day-face-function nil
  1772. "Function called to determine what face should be used to display a day.
  1773. The only argument passed to that function is the day. It should
  1774. returns a face, or nil if does not want to specify a face and let
  1775. the normal rules apply."
  1776. :group 'org-agenda-line-format
  1777. :version "24.1"
  1778. :type '(choice (const nil) (function)))
  1779. (defcustom org-agenda-category-icon-alist nil
  1780. "Alist of category icon to be displayed in agenda views.
  1781. Each entry should have the following format:
  1782. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1783. Where CATEGORY-REGEXP is a regexp matching the categories where
  1784. the icon should be displayed.
  1785. FILE-OR-DATA either a file path or a string containing image data.
  1786. The other fields can be omitted safely if not needed:
  1787. TYPE indicates the image type.
  1788. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1789. image data.
  1790. PROPS are additional image attributes to assign to the image,
  1791. like, e.g. `:ascent center'.
  1792. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1793. If you want to set the display properties yourself, just put a
  1794. list as second element:
  1795. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1796. For example, to display a 16px horizontal space for Emacs
  1797. category, you can use:
  1798. (\"Emacs\" \\='(space . (:width (16))))"
  1799. :group 'org-agenda-line-format
  1800. :version "24.1"
  1801. :type '(alist :key-type (regexp :tag "Regexp matching category")
  1802. :value-type (choice (list :tag "Icon"
  1803. (string :tag "File or data")
  1804. (symbol :tag "Type")
  1805. (boolean :tag "Data?")
  1806. (repeat :tag "Extra image properties" :inline t sexp))
  1807. (list :tag "Display properties" sexp))))
  1808. (defgroup org-agenda-column-view nil
  1809. "Options concerning column view in the agenda."
  1810. :tag "Org Agenda Column View"
  1811. :group 'org-agenda)
  1812. (defcustom org-agenda-view-columns-initially nil
  1813. "When non-nil, switch to columns view right after creating the agenda."
  1814. :group 'org-agenda-column-view
  1815. :type 'boolean
  1816. :version "26.1"
  1817. :package-version '(Org . "9.0")
  1818. :safe #'booleanp)
  1819. (defcustom org-agenda-columns-show-summaries t
  1820. "Non-nil means show summaries for columns displayed in the agenda view."
  1821. :group 'org-agenda-column-view
  1822. :type 'boolean)
  1823. (defcustom org-agenda-columns-compute-summary-properties t
  1824. "Non-nil means recompute all summary properties before column view.
  1825. When column view in the agenda is listing properties that have a summary
  1826. operator, it can go to all relevant buffers and recompute the summaries
  1827. there. This can mean overhead for the agenda column view, but is necessary
  1828. to have thing up to date.
  1829. As a special case, a CLOCKSUM property also makes sure that the clock
  1830. computations are current."
  1831. :group 'org-agenda-column-view
  1832. :type 'boolean)
  1833. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1834. "Non-nil means the duration of an appointment will add to day effort.
  1835. The property to which appointment durations will be added is the one given
  1836. in the option `org-effort-property'. If an appointment does not have
  1837. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1838. is not set, an appointment without end time will not contribute to the time
  1839. estimate."
  1840. :group 'org-agenda-column-view
  1841. :type 'boolean)
  1842. (defcustom org-agenda-auto-exclude-function nil
  1843. "A function called with a tag to decide if it is filtered on \
  1844. \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
  1845. The sole argument to the function, which is called once for each
  1846. possible tag, is a string giving the name of the tag. The
  1847. function should return either nil if the tag should be included
  1848. as normal, \"-<TAG>\" to exclude the tag, or \"+<TAG>\" to exclude
  1849. lines not carrying this tag.
  1850. Note that for the purpose of tag filtering, only the lower-case version of
  1851. all tags will be considered, so that this function will only ever see
  1852. the lower-case version of all tags."
  1853. :group 'org-agenda
  1854. :type '(choice (const nil) (function)))
  1855. (defcustom org-agenda-bulk-custom-functions nil
  1856. "Alist of characters and custom functions for bulk actions.
  1857. For example, this makes those two functions available:
  1858. (setq org-agenda-bulk-custom-functions
  1859. \\='((?R set-category)
  1860. (?C bulk-cut)))
  1861. With selected entries in an agenda buffer, `B R' will call
  1862. the custom function `set-category' on the selected entries.
  1863. Note that functions in this alist don't need to be quoted.
  1864. You can also specify a function which collects arguments to be
  1865. used for each call to your bulk custom function. The argument
  1866. collecting function will be run once and should return a list of
  1867. arguments to pass to the bulk function. For example:
  1868. (setq org-agenda-bulk-custom-functions
  1869. \\='((?R set-category get-category)))
  1870. Now, `B R' will call the custom `get-category' which would prompt
  1871. the user once for a category. That category is then passed as an
  1872. argument to `set-category' for each entry it's called against."
  1873. :type
  1874. '(alist :key-type character
  1875. :value-type
  1876. (group (function :tag "Bulk Custom Function")
  1877. (choice (function :tag "Bulk Custom Argument Function")
  1878. (const :tag "No Bulk Custom Argument Function" nil))))
  1879. :package-version '(Org . "9.5")
  1880. :group 'org-agenda)
  1881. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1882. "Execute BODY with point at location given by `org-hd-marker' property.
  1883. If STRING is non-nil, the text property will be fetched from position 0
  1884. in that string. If STRING is nil, it will be fetched from the beginning
  1885. of the current line."
  1886. (declare (debug t) (indent 1))
  1887. (org-with-gensyms (marker)
  1888. `(let ((,marker (get-text-property (if ,string 0 (line-beginning-position))
  1889. 'org-hd-marker ,string)))
  1890. (with-current-buffer (marker-buffer ,marker)
  1891. (save-excursion
  1892. (goto-char ,marker)
  1893. ,@body)))))
  1894. (defun org-add-agenda-custom-command (entry)
  1895. "Replace or add a command in `org-agenda-custom-commands'.
  1896. This is mostly for hacking and trying a new command - once the command
  1897. works you probably want to add it to `org-agenda-custom-commands' for good."
  1898. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1899. (if ass
  1900. (setcdr ass (cdr entry))
  1901. (push entry org-agenda-custom-commands))))
  1902. (defmacro org-agenda--insert-overriding-header (default)
  1903. "Insert header into agenda view.
  1904. The inserted header depends on `org-agenda-overriding-header'.
  1905. If the empty string, don't insert a header. If any other string,
  1906. insert it as a header. If nil, insert DEFAULT, which should
  1907. evaluate to a string. If a function, call it and insert the
  1908. string that it returns."
  1909. (declare (debug (form)) (indent defun))
  1910. `(cond
  1911. ((not org-agenda-overriding-header) (insert ,default))
  1912. ((equal org-agenda-overriding-header "") nil)
  1913. ((stringp org-agenda-overriding-header)
  1914. (insert (propertize org-agenda-overriding-header
  1915. 'face 'org-agenda-structure)
  1916. "\n"))
  1917. ((functionp org-agenda-overriding-header)
  1918. (insert (funcall org-agenda-overriding-header)))
  1919. (t (user-error "Invalid value for `org-agenda-overriding-header': %S"
  1920. org-agenda-overriding-header))))
  1921. ;;; Define the org-agenda-mode
  1922. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1923. (defvar org-agenda-mode-map (make-sparse-keymap)
  1924. "Keymap for `org-agenda-mode'.")
  1925. (org-remap org-agenda-mode-map 'move-end-of-line 'org-agenda-end-of-line)
  1926. (defvar org-agenda-menu) ; defined later in this file.
  1927. (defvar org-agenda-restrict nil
  1928. "Non-nil means agenda restriction is active.
  1929. This is an internal flag indicating either temporary or extended
  1930. agenda restriction. Specifically, it is set to t if the agenda
  1931. is restricted to an entire file, and is set to the corresponding
  1932. buffer if the agenda is restricted to a part of a file, e.g. a
  1933. region or a substree. In the latter case,
  1934. `org-agenda-restrict-begin' and `org-agenda-restrict-end' are set
  1935. to the beginning and the end of the part.
  1936. See also `org-agenda-set-restriction-lock'.")
  1937. (defvar org-agenda-follow-mode nil)
  1938. (defvar org-agenda-entry-text-mode nil)
  1939. (defvar org-agenda-clockreport-mode nil)
  1940. (defvar org-agenda-show-log nil
  1941. "When non-nil, show the log in the agenda.
  1942. Do not set this directly; instead use
  1943. `org-agenda-start-with-log-mode', which see.")
  1944. (defvar org-agenda-redo-command nil)
  1945. (defvar org-agenda-query-string nil)
  1946. (defvar org-agenda-mode-hook nil
  1947. "Hook run after `org-agenda-mode' is turned on.
  1948. The buffer is still writable when this hook is called.")
  1949. (defvar org-agenda-type nil)
  1950. (defvar org-agenda-force-single-file nil)
  1951. (defvar org-agenda-bulk-marked-entries nil
  1952. "List of markers that refer to marked entries in the agenda.")
  1953. (defvar org-agenda-current-date nil
  1954. "Active date when building the agenda.")
  1955. ;;; Multiple agenda buffers support
  1956. (defcustom org-agenda-sticky nil
  1957. "Non-nil means agenda q key will bury agenda buffers.
  1958. Agenda commands will then show existing buffer instead of generating new ones.
  1959. When nil, `q' will kill the single agenda buffer."
  1960. :group 'org-agenda
  1961. :version "24.3"
  1962. :type 'boolean)
  1963. ;;;###autoload
  1964. (defun org-toggle-sticky-agenda (&optional arg)
  1965. "Toggle `org-agenda-sticky'."
  1966. (interactive "P")
  1967. (let ((new-value (if arg
  1968. (> (prefix-numeric-value arg) 0)
  1969. (not org-agenda-sticky))))
  1970. (if (equal new-value org-agenda-sticky)
  1971. (and (called-interactively-p 'interactive)
  1972. (message "Sticky agenda was already %s"
  1973. (if org-agenda-sticky "enabled" "disabled")))
  1974. (setq org-agenda-sticky new-value)
  1975. (org-agenda-kill-all-agenda-buffers)
  1976. (and (called-interactively-p 'interactive)
  1977. (message "Sticky agenda %s"
  1978. (if org-agenda-sticky "enabled" "disabled"))))))
  1979. (defvar org-agenda-buffer nil
  1980. "Agenda buffer currently being generated.")
  1981. (defvar org-agenda-last-prefix-arg nil)
  1982. (defvar org-agenda-this-buffer-name nil)
  1983. (defvar org-agenda-doing-sticky-redo nil)
  1984. (defvar org-agenda-this-buffer-is-sticky nil)
  1985. (defvar org-agenda-last-indirect-buffer nil
  1986. "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
  1987. (defconst org-agenda-local-vars
  1988. '(org-agenda-this-buffer-name
  1989. org-agenda-undo-list
  1990. org-agenda-pending-undo-list
  1991. org-agenda-follow-mode
  1992. org-agenda-entry-text-mode
  1993. org-agenda-clockreport-mode
  1994. org-agenda-show-log
  1995. org-agenda-redo-command
  1996. org-agenda-query-string
  1997. org-agenda-type
  1998. org-agenda-bulk-marked-entries
  1999. org-agenda-undo-has-started-in
  2000. org-agenda-info
  2001. org-agenda-pre-window-conf
  2002. org-agenda-columns-active
  2003. org-agenda-tag-filter
  2004. org-agenda-category-filter
  2005. org-agenda-top-headline-filter
  2006. org-agenda-regexp-filter
  2007. org-agenda-effort-filter
  2008. org-agenda-filters-preset
  2009. org-agenda-markers
  2010. org-agenda-last-search-view-search-was-boolean
  2011. org-agenda-last-indirect-buffer
  2012. org-agenda-filtered-by-category
  2013. org-agenda-filter-form
  2014. org-agenda-cycle-counter
  2015. org-agenda-last-prefix-arg)
  2016. "Variables that must be local in agenda buffers to allow multiple buffers.")
  2017. (defun org-agenda-mode ()
  2018. "Mode for time-sorted view on action items in Org files.
  2019. The following commands are available:
  2020. \\{org-agenda-mode-map}"
  2021. (interactive)
  2022. (ignore-errors (require 'face-remap))
  2023. (let ((agenda-local-vars-to-keep
  2024. '(text-scale-mode-amount
  2025. text-scale-mode
  2026. text-scale-mode-lighter
  2027. face-remapping-alist))
  2028. (save (buffer-local-variables)))
  2029. (kill-all-local-variables)
  2030. (cl-flet ((reset-saved (var-set)
  2031. "Reset variables in VAR-SET to possibly stored value in SAVE."
  2032. (dolist (elem save)
  2033. (pcase elem
  2034. (`(,var . ,val) ;ignore unbound variables
  2035. (when (and val (memq var var-set))
  2036. (set var val)))))))
  2037. (cond (org-agenda-doing-sticky-redo
  2038. ;; Refreshing sticky agenda-buffer
  2039. ;;
  2040. ;; Preserve the value of `org-agenda-local-vars' variables.
  2041. (mapc #'make-local-variable org-agenda-local-vars)
  2042. (reset-saved org-agenda-local-vars)
  2043. (setq-local org-agenda-this-buffer-is-sticky t))
  2044. (org-agenda-sticky
  2045. ;; Creating a sticky Agenda buffer for the first time
  2046. (mapc #'make-local-variable org-agenda-local-vars)
  2047. (setq-local org-agenda-this-buffer-is-sticky t))
  2048. (t
  2049. ;; Creating a non-sticky agenda buffer
  2050. (setq-local org-agenda-this-buffer-is-sticky nil)))
  2051. (mapc #'make-local-variable agenda-local-vars-to-keep)
  2052. (reset-saved agenda-local-vars-to-keep)))
  2053. (setq org-agenda-undo-list nil
  2054. org-agenda-pending-undo-list nil
  2055. org-agenda-bulk-marked-entries nil)
  2056. (setq major-mode 'org-agenda-mode)
  2057. ;; Keep global-font-lock-mode from turning on font-lock-mode
  2058. (setq-local font-lock-global-modes (list 'not major-mode))
  2059. (setq mode-name "Org-Agenda")
  2060. (setq indent-tabs-mode nil)
  2061. (use-local-map org-agenda-mode-map)
  2062. (when org-startup-truncated (setq truncate-lines t))
  2063. (setq-local line-move-visual nil)
  2064. (add-hook 'post-command-hook #'org-agenda-update-agenda-type nil 'local)
  2065. (add-hook 'pre-command-hook #'org-unhighlight nil 'local)
  2066. ;; Make sure properties are removed when copying text
  2067. (if (boundp 'filter-buffer-substring-functions)
  2068. (add-hook 'filter-buffer-substring-functions
  2069. (lambda (fun start end delete)
  2070. (substring-no-properties (funcall fun start end delete)))
  2071. nil t)
  2072. ;; Emacs >= 24.4.
  2073. (add-function :filter-return (local 'filter-buffer-substring-function)
  2074. #'substring-no-properties))
  2075. (unless org-agenda-keep-modes
  2076. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  2077. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  2078. org-agenda-show-log org-agenda-start-with-log-mode
  2079. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode))
  2080. (add-to-invisibility-spec '(org-filtered))
  2081. (org-fold-core-initialize `(,org-link--description-folding-spec
  2082. ,org-link--link-folding-spec))
  2083. (easy-menu-change
  2084. '("Agenda") "Agenda Files"
  2085. (append
  2086. (list
  2087. (vector
  2088. (if (get 'org-agenda-files 'org-restrict)
  2089. "Restricted to single file"
  2090. "Edit File List")
  2091. '(org-edit-agenda-file-list)
  2092. (not (get 'org-agenda-files 'org-restrict)))
  2093. "--")
  2094. (mapcar #'org-file-menu-entry (org-agenda-files))))
  2095. (org-agenda-set-mode-name)
  2096. (run-mode-hooks 'org-agenda-mode-hook))
  2097. (substitute-key-definition #'undo #'org-agenda-undo
  2098. org-agenda-mode-map global-map)
  2099. (org-defkey org-agenda-mode-map "\C-i" #'org-agenda-goto)
  2100. (org-defkey org-agenda-mode-map [(tab)] #'org-agenda-goto)
  2101. (org-defkey org-agenda-mode-map "\C-m" #'org-agenda-switch-to)
  2102. (org-defkey org-agenda-mode-map "\C-k" #'org-agenda-kill)
  2103. (org-defkey org-agenda-mode-map "\C-c\C-w" #'org-agenda-refile)
  2104. (org-defkey org-agenda-mode-map [(meta down)] #'org-agenda-drag-line-forward)
  2105. (org-defkey org-agenda-mode-map [(meta up)] #'org-agenda-drag-line-backward)
  2106. (org-defkey org-agenda-mode-map "m" #'org-agenda-bulk-mark)
  2107. (org-defkey org-agenda-mode-map "\M-m" #'org-agenda-bulk-toggle)
  2108. (org-defkey org-agenda-mode-map "*" #'org-agenda-bulk-mark-all)
  2109. (org-defkey org-agenda-mode-map "\M-*" #'org-agenda-bulk-toggle-all)
  2110. (org-defkey org-agenda-mode-map "#" #'org-agenda-dim-blocked-tasks)
  2111. (org-defkey org-agenda-mode-map "%" #'org-agenda-bulk-mark-regexp)
  2112. (org-defkey org-agenda-mode-map "u" #'org-agenda-bulk-unmark)
  2113. (org-defkey org-agenda-mode-map "U" #'org-agenda-bulk-unmark-all)
  2114. (org-defkey org-agenda-mode-map "B" #'org-agenda-bulk-action)
  2115. (org-defkey org-agenda-mode-map "k" #'org-agenda-capture)
  2116. (org-defkey org-agenda-mode-map "A" #'org-agenda-append-agenda)
  2117. (org-defkey org-agenda-mode-map "\C-c\C-x!" #'org-reload)
  2118. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" #'org-agenda-archive-default)
  2119. (org-defkey org-agenda-mode-map "\C-c\C-xa" #'org-agenda-toggle-archive-tag)
  2120. (org-defkey org-agenda-mode-map "\C-c\C-xA" #'org-agenda-archive-to-archive-sibling)
  2121. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" #'org-agenda-archive)
  2122. (org-defkey org-agenda-mode-map "\C-c$" #'org-agenda-archive)
  2123. (org-defkey org-agenda-mode-map "$" #'org-agenda-archive)
  2124. (org-defkey org-agenda-mode-map "\C-c\C-o" #'org-agenda-open-link)
  2125. (org-defkey org-agenda-mode-map " " #'org-agenda-show-and-scroll-up)
  2126. (org-defkey org-agenda-mode-map [backspace] #'org-agenda-show-scroll-down)
  2127. (org-defkey org-agenda-mode-map "\d" #'org-agenda-show-scroll-down)
  2128. (org-defkey org-agenda-mode-map [(control shift right)] #'org-agenda-todo-nextset)
  2129. (org-defkey org-agenda-mode-map [(control shift left)] #'org-agenda-todo-previousset)
  2130. (org-defkey org-agenda-mode-map "\C-c\C-xb" #'org-agenda-tree-to-indirect-buffer)
  2131. (org-defkey org-agenda-mode-map "o" #'delete-other-windows)
  2132. (org-defkey org-agenda-mode-map "L" #'org-agenda-recenter)
  2133. (org-defkey org-agenda-mode-map "\C-c\C-t" #'org-agenda-todo)
  2134. (org-defkey org-agenda-mode-map "t" #'org-agenda-todo)
  2135. (org-defkey org-agenda-mode-map "a" #'org-agenda-archive-default-with-confirmation)
  2136. (org-defkey org-agenda-mode-map ":" #'org-agenda-set-tags)
  2137. (org-defkey org-agenda-mode-map "\C-c\C-q" #'org-agenda-set-tags)
  2138. (org-defkey org-agenda-mode-map "." #'org-agenda-goto-today)
  2139. (org-defkey org-agenda-mode-map "j" #'org-agenda-goto-date)
  2140. (org-defkey org-agenda-mode-map "d" #'org-agenda-day-view)
  2141. (org-defkey org-agenda-mode-map "w" #'org-agenda-week-view)
  2142. (org-defkey org-agenda-mode-map "y" #'org-agenda-year-view)
  2143. (org-defkey org-agenda-mode-map "\C-c\C-z" #'org-agenda-add-note)
  2144. (org-defkey org-agenda-mode-map "z" #'org-agenda-add-note)
  2145. (org-defkey org-agenda-mode-map [(shift right)] #'org-agenda-do-date-later)
  2146. (org-defkey org-agenda-mode-map [(shift left)] #'org-agenda-do-date-earlier)
  2147. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] #'org-agenda-do-date-later)
  2148. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] #'org-agenda-do-date-earlier)
  2149. (org-defkey org-agenda-mode-map ">" #'org-agenda-date-prompt)
  2150. (org-defkey org-agenda-mode-map "\C-c\C-s" #'org-agenda-schedule)
  2151. (org-defkey org-agenda-mode-map "\C-c\C-d" #'org-agenda-deadline)
  2152. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  2153. (while l (org-defkey org-agenda-mode-map
  2154. (number-to-string (pop l)) #'digit-argument)))
  2155. (org-defkey org-agenda-mode-map "F" #'org-agenda-follow-mode)
  2156. (org-defkey org-agenda-mode-map "R" #'org-agenda-clockreport-mode)
  2157. (org-defkey org-agenda-mode-map "E" #'org-agenda-entry-text-mode)
  2158. (org-defkey org-agenda-mode-map "l" #'org-agenda-log-mode)
  2159. (org-defkey org-agenda-mode-map "v" #'org-agenda-view-mode-dispatch)
  2160. (org-defkey org-agenda-mode-map "D" #'org-agenda-toggle-diary)
  2161. (org-defkey org-agenda-mode-map "!" #'org-agenda-toggle-deadlines)
  2162. (org-defkey org-agenda-mode-map "G" #'org-agenda-toggle-time-grid)
  2163. (org-defkey org-agenda-mode-map "r" #'org-agenda-redo)
  2164. (org-defkey org-agenda-mode-map "g" #'org-agenda-redo-all)
  2165. (org-defkey org-agenda-mode-map "e" #'org-agenda-set-effort)
  2166. (org-defkey org-agenda-mode-map "\C-c\C-xe" #'org-agenda-set-effort)
  2167. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  2168. #'org-clock-modify-effort-estimate)
  2169. (org-defkey org-agenda-mode-map "\C-c\C-xp" #'org-agenda-set-property)
  2170. (org-defkey org-agenda-mode-map "q" #'org-agenda-quit)
  2171. (org-defkey org-agenda-mode-map "Q" #'org-agenda-Quit)
  2172. (org-defkey org-agenda-mode-map "x" #'org-agenda-exit)
  2173. (org-defkey org-agenda-mode-map "\C-x\C-w" #'org-agenda-write)
  2174. (org-defkey org-agenda-mode-map "\C-x\C-s" #'org-save-all-org-buffers)
  2175. (org-defkey org-agenda-mode-map "s" #'org-save-all-org-buffers)
  2176. (org-defkey org-agenda-mode-map "T" #'org-agenda-show-tags)
  2177. (org-defkey org-agenda-mode-map "n" #'org-agenda-next-line)
  2178. (org-defkey org-agenda-mode-map "p" #'org-agenda-previous-line)
  2179. (org-defkey org-agenda-mode-map "N" #'org-agenda-next-item)
  2180. (org-defkey org-agenda-mode-map "P" #'org-agenda-previous-item)
  2181. (substitute-key-definition #'next-line #'org-agenda-next-line
  2182. org-agenda-mode-map global-map)
  2183. (substitute-key-definition #'previous-line #'org-agenda-previous-line
  2184. org-agenda-mode-map global-map)
  2185. (org-defkey org-agenda-mode-map "\C-c\C-a" #'org-attach)
  2186. (org-defkey org-agenda-mode-map "\C-c\C-n" #'org-agenda-next-date-line)
  2187. (org-defkey org-agenda-mode-map "\C-c\C-p" #'org-agenda-previous-date-line)
  2188. (org-defkey org-agenda-mode-map "\C-c," #'org-agenda-priority)
  2189. (org-defkey org-agenda-mode-map "," #'org-agenda-priority)
  2190. (org-defkey org-agenda-mode-map "i" #'org-agenda-diary-entry)
  2191. (org-defkey org-agenda-mode-map "c" #'org-agenda-goto-calendar)
  2192. (org-defkey org-agenda-mode-map "C" #'org-agenda-convert-date)
  2193. (org-defkey org-agenda-mode-map "M" #'org-agenda-phases-of-moon)
  2194. (org-defkey org-agenda-mode-map "S" #'org-agenda-sunrise-sunset)
  2195. (org-defkey org-agenda-mode-map "h" #'org-agenda-holidays)
  2196. (org-defkey org-agenda-mode-map "H" #'org-agenda-holidays)
  2197. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" #'org-agenda-clock-in)
  2198. (org-defkey org-agenda-mode-map "I" #'org-agenda-clock-in)
  2199. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" #'org-agenda-clock-out)
  2200. (org-defkey org-agenda-mode-map "O" #'org-agenda-clock-out)
  2201. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" #'org-agenda-clock-cancel)
  2202. (org-defkey org-agenda-mode-map "X" #'org-agenda-clock-cancel)
  2203. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" #'org-clock-goto)
  2204. (org-defkey org-agenda-mode-map "J" #'org-agenda-clock-goto)
  2205. (org-defkey org-agenda-mode-map "+" #'org-agenda-priority-up)
  2206. (org-defkey org-agenda-mode-map "-" #'org-agenda-priority-down)
  2207. (org-defkey org-agenda-mode-map [(shift up)] #'org-agenda-priority-up)
  2208. (org-defkey org-agenda-mode-map [(shift down)] #'org-agenda-priority-down)
  2209. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] #'org-agenda-priority-up)
  2210. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] #'org-agenda-priority-down)
  2211. (org-defkey org-agenda-mode-map "f" #'org-agenda-later)
  2212. (org-defkey org-agenda-mode-map "b" #'org-agenda-earlier)
  2213. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" #'org-agenda-columns)
  2214. (org-defkey org-agenda-mode-map "\C-c\C-x>" #'org-agenda-remove-restriction-lock)
  2215. (org-defkey org-agenda-mode-map "\C-c\C-x<" #'org-agenda-set-restriction-lock-from-agenda)
  2216. (org-defkey org-agenda-mode-map "[" #'org-agenda-manipulate-query-add)
  2217. (org-defkey org-agenda-mode-map "]" #'org-agenda-manipulate-query-subtract)
  2218. (org-defkey org-agenda-mode-map "{" #'org-agenda-manipulate-query-add-re)
  2219. (org-defkey org-agenda-mode-map "}" #'org-agenda-manipulate-query-subtract-re)
  2220. (org-defkey org-agenda-mode-map "\\" #'org-agenda-filter-by-tag)
  2221. (org-defkey org-agenda-mode-map "_" #'org-agenda-filter-by-effort)
  2222. (org-defkey org-agenda-mode-map "=" #'org-agenda-filter-by-regexp)
  2223. (org-defkey org-agenda-mode-map "/" #'org-agenda-filter)
  2224. (org-defkey org-agenda-mode-map "|" #'org-agenda-filter-remove-all)
  2225. (org-defkey org-agenda-mode-map "~" #'org-agenda-limit-interactively)
  2226. (org-defkey org-agenda-mode-map "<" #'org-agenda-filter-by-category)
  2227. (org-defkey org-agenda-mode-map "^" #'org-agenda-filter-by-top-headline)
  2228. (org-defkey org-agenda-mode-map ";" #'org-timer-set-timer)
  2229. (org-defkey org-agenda-mode-map "\C-c\C-x_" #'org-timer-stop)
  2230. (org-defkey org-agenda-mode-map "?" #'org-agenda-show-the-flagging-note)
  2231. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" #'org-mobile-pull)
  2232. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" #'org-mobile-push)
  2233. (org-defkey org-agenda-mode-map "\C-c\C-xI" #'org-info-find-node)
  2234. (org-defkey org-agenda-mode-map [mouse-2] #'org-agenda-goto-mouse)
  2235. (org-defkey org-agenda-mode-map [mouse-3] #'org-agenda-show-mouse)
  2236. (org-defkey org-agenda-mode-map [remap forward-paragraph] #'org-agenda-forward-block)
  2237. (org-defkey org-agenda-mode-map [remap backward-paragraph] #'org-agenda-backward-block)
  2238. (org-defkey org-agenda-mode-map "\C-c\C-c" #'org-agenda-ctrl-c-ctrl-c)
  2239. (when org-agenda-mouse-1-follows-link
  2240. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2241. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu."
  2242. '("Agenda"
  2243. ("Agenda Files")
  2244. "--"
  2245. ("Agenda Dates"
  2246. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda)]
  2247. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2248. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2249. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2250. "--"
  2251. ("View"
  2252. ["Day View" org-agenda-day-view
  2253. :active (org-agenda-check-type nil 'agenda)
  2254. :style radio :selected (eq org-agenda-current-span 'day)
  2255. :keys "v d (or just d)"]
  2256. ["Week View" org-agenda-week-view
  2257. :active (org-agenda-check-type nil 'agenda)
  2258. :style radio :selected (eq org-agenda-current-span 'week)
  2259. :keys "v w"]
  2260. ["Fortnight View" org-agenda-fortnight-view
  2261. :active (org-agenda-check-type nil 'agenda)
  2262. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2263. :keys "v t"]
  2264. ["Month View" org-agenda-month-view
  2265. :active (org-agenda-check-type nil 'agenda)
  2266. :style radio :selected (eq org-agenda-current-span 'month)
  2267. :keys "v m"]
  2268. ["Year View" org-agenda-year-view
  2269. :active (org-agenda-check-type nil 'agenda)
  2270. :style radio :selected (eq org-agenda-current-span 'year)
  2271. :keys "v y"]
  2272. "--"
  2273. ["Include Diary" org-agenda-toggle-diary
  2274. :style toggle :selected org-agenda-include-diary
  2275. :active (org-agenda-check-type nil 'agenda)]
  2276. ["Include Deadlines" org-agenda-toggle-deadlines
  2277. :style toggle :selected org-agenda-include-deadlines
  2278. :active (org-agenda-check-type nil 'agenda)]
  2279. ["Use Time Grid" org-agenda-toggle-time-grid
  2280. :style toggle :selected org-agenda-use-time-grid
  2281. :active (org-agenda-check-type nil 'agenda)]
  2282. "--"
  2283. ["Show clock report" org-agenda-clockreport-mode
  2284. :style toggle :selected org-agenda-clockreport-mode
  2285. :active (org-agenda-check-type nil 'agenda)]
  2286. ["Show some entry text" org-agenda-entry-text-mode
  2287. :style toggle :selected org-agenda-entry-text-mode
  2288. :active t]
  2289. "--"
  2290. ["Show Logbook entries" org-agenda-log-mode
  2291. :style toggle :selected org-agenda-show-log
  2292. :active (org-agenda-check-type nil 'agenda)
  2293. :keys "v l (or just l)"]
  2294. ["Include archived trees" org-agenda-archives-mode
  2295. :style toggle :selected org-agenda-archives-mode :active t
  2296. :keys "v a"]
  2297. ["Include archive files" (org-agenda-archives-mode t)
  2298. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2299. :keys "v A"]
  2300. "--"
  2301. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2302. ("Filter current view"
  2303. ["with generic interface" org-agenda-filter t]
  2304. "--"
  2305. ["by category at cursor" org-agenda-filter-by-category t]
  2306. ["by tag" org-agenda-filter-by-tag t]
  2307. ["by effort" org-agenda-filter-by-effort t]
  2308. ["by regexp" org-agenda-filter-by-regexp t]
  2309. ["by top-level headline" org-agenda-filter-by-top-headline t]
  2310. "--"
  2311. ["Remove all filtering" org-agenda-filter-remove-all t]
  2312. "--"
  2313. ["limit" org-agenda-limit-interactively t])
  2314. ["Rebuild buffer" org-agenda-redo t]
  2315. ["Write view to file" org-agenda-write t]
  2316. ["Save all Org buffers" org-save-all-org-buffers t]
  2317. "--"
  2318. ["Show original entry" org-agenda-show t]
  2319. ["Go To (other window)" org-agenda-goto t]
  2320. ["Go To (this window)" org-agenda-switch-to t]
  2321. ["Capture with cursor date" org-agenda-capture t]
  2322. ["Follow Mode" org-agenda-follow-mode
  2323. :style toggle :selected org-agenda-follow-mode :active t]
  2324. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2325. "--"
  2326. ("TODO"
  2327. ["Cycle TODO" org-agenda-todo t]
  2328. ["Next TODO set" org-agenda-todo-nextset t]
  2329. ["Previous TODO set" org-agenda-todo-previousset t]
  2330. ["Add note" org-agenda-add-note t])
  2331. ("Archive/Refile/Delete"
  2332. ["Archive default" org-agenda-archive-default t]
  2333. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2334. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2335. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2336. ["Archive subtree" org-agenda-archive t]
  2337. "--"
  2338. ["Refile" org-agenda-refile t]
  2339. "--"
  2340. ["Delete subtree" org-agenda-kill t])
  2341. ("Bulk action"
  2342. ["Mark entry" org-agenda-bulk-mark t]
  2343. ["Mark all" org-agenda-bulk-mark-all t]
  2344. ["Unmark entry" org-agenda-bulk-unmark t]
  2345. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2346. ["Toggle mark" org-agenda-bulk-toggle t]
  2347. ["Toggle all" org-agenda-bulk-toggle-all t]
  2348. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2349. ["Act on all marked" org-agenda-bulk-action t]
  2350. "--"
  2351. ("Tags and Properties"
  2352. ["Show all Tags" org-agenda-show-tags t]
  2353. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2354. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2355. "--"
  2356. ["Column View" org-columns t])
  2357. ("Deadline/Schedule"
  2358. ["Schedule" org-agenda-schedule t]
  2359. ["Set Deadline" org-agenda-deadline t]
  2360. "--"
  2361. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda)]
  2362. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda)]
  2363. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u S-right"]
  2364. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u S-left"]
  2365. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-right"]
  2366. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-left"]
  2367. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda)])
  2368. ("Clock and Effort"
  2369. ["Clock in" org-agenda-clock-in t]
  2370. ["Clock out" org-agenda-clock-out t]
  2371. ["Clock cancel" org-agenda-clock-cancel t]
  2372. ["Goto running clock" org-clock-goto t]
  2373. "--"
  2374. ["Set Effort" org-agenda-set-effort t]
  2375. ["Change clocked effort" org-clock-modify-effort-estimate
  2376. (org-clock-is-active)])
  2377. ("Priority"
  2378. ["Set Priority" org-agenda-priority t]
  2379. ["Increase Priority" org-agenda-priority-up t]
  2380. ["Decrease Priority" org-agenda-priority-down t]
  2381. ["Show Priority" org-priority-show t])
  2382. ("Calendar/Diary"
  2383. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda)]
  2384. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda)]
  2385. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda)]
  2386. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda)]
  2387. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda)]
  2388. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda)]
  2389. "--"
  2390. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2391. "--"
  2392. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2393. "--"
  2394. ("MobileOrg"
  2395. ["Push Files and Views" org-mobile-push t]
  2396. ["Get Captured and Flagged" org-mobile-pull t]
  2397. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "\\[org-agenda] ?"]
  2398. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2399. "--"
  2400. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2401. "--"
  2402. ["Quit" org-agenda-quit t]
  2403. ["Exit and Release Buffers" org-agenda-exit t]
  2404. ))
  2405. ;;; Agenda undo
  2406. (defvar org-agenda-allow-remote-undo t
  2407. "Non-nil means allow remote undo from the agenda buffer.")
  2408. (defvar org-agenda-undo-has-started-in nil
  2409. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2410. (defun org-agenda-undo ()
  2411. "Undo a remote editing step in the agenda.
  2412. This undoes changes both in the agenda buffer and in the remote buffer
  2413. that have been changed along."
  2414. (interactive)
  2415. (or org-agenda-allow-remote-undo
  2416. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2417. (when (not (eq this-command last-command))
  2418. (setq org-agenda-undo-has-started-in nil
  2419. org-agenda-pending-undo-list org-agenda-undo-list))
  2420. (when (not org-agenda-pending-undo-list)
  2421. (user-error "No further undo information"))
  2422. (let* ((entry (pop org-agenda-pending-undo-list))
  2423. buf line cmd rembuf)
  2424. (setq cmd (pop entry) line (pop entry))
  2425. (setq rembuf (nth 2 entry))
  2426. (org-with-remote-undo rembuf
  2427. (while (bufferp (setq buf (pop entry)))
  2428. (when (pop entry)
  2429. (with-current-buffer buf
  2430. (let (;; (last-undo-buffer buf)
  2431. (inhibit-read-only t))
  2432. (unless (memq buf org-agenda-undo-has-started-in)
  2433. (push buf org-agenda-undo-has-started-in)
  2434. (make-local-variable 'pending-undo-list)
  2435. (undo-start))
  2436. (while (and pending-undo-list
  2437. (listp pending-undo-list)
  2438. (not (car pending-undo-list)))
  2439. (pop pending-undo-list))
  2440. (undo-more 1))))))
  2441. (org-goto-line line)
  2442. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2443. (defun org-verify-change-for-undo (l1 l2)
  2444. "Verify that a real change occurred between the undo lists L1 and L2."
  2445. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2446. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2447. (not (eq l1 l2)))
  2448. ;;; Agenda dispatch
  2449. (defvar org-agenda-restrict-begin (make-marker)
  2450. "Internal variable used to mark the restriction beginning.
  2451. It is only relevant when `org-agenda-restrict' is a buffer.")
  2452. (defvar org-agenda-restrict-end (make-marker)
  2453. "Internal variable used to mark the restriction end.
  2454. It is only relevant when `org-agenda-restrict' is a buffer.")
  2455. (defvar org-agenda-last-dispatch-buffer nil)
  2456. (defvar org-agenda-overriding-restriction nil
  2457. "Non-nil means extended agenda restriction is active.
  2458. This is an internal flag set by `org-agenda-set-restriction-lock'.")
  2459. (defcustom org-agenda-custom-commands-contexts nil
  2460. "Alist of custom agenda keys and contextual rules.
  2461. For example, if you have a custom agenda command \"p\" and you
  2462. want this command to be accessible only from plain text files,
  2463. use this:
  2464. (setq org-agenda-custom-commands-contexts
  2465. \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\")))))
  2466. Here are the available contexts definitions:
  2467. in-file: command displayed only in matching files
  2468. in-mode: command displayed only in matching modes
  2469. not-in-file: command not displayed in matching files
  2470. not-in-mode: command not displayed in matching modes
  2471. in-buffer: command displayed only in matching buffers
  2472. not-in-buffer: command not displayed in matching buffers
  2473. [function]: a custom function taking no argument
  2474. If you define several checks, the agenda command will be
  2475. accessible if there is at least one valid check.
  2476. You can also bind a key to another agenda custom command
  2477. depending on contextual rules.
  2478. (setq org-agenda-custom-commands-contexts
  2479. \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\")))))
  2480. Here it means: in .txt files, use \"p\" as the key for the
  2481. agenda command otherwise associated with \"q\". (The command
  2482. originally associated with \"q\" is not displayed to avoid
  2483. duplicates.)"
  2484. :version "24.3"
  2485. :group 'org-agenda-custom-commands
  2486. :type '(repeat (list :tag "Rule"
  2487. (string :tag " Agenda key")
  2488. (string :tag "Replace by command")
  2489. (repeat :tag "Available when"
  2490. (choice
  2491. (cons :tag "Condition"
  2492. (choice
  2493. (const :tag "In file" in-file)
  2494. (const :tag "Not in file" not-in-file)
  2495. (const :tag "In buffer" in-buffer)
  2496. (const :tag "Not in buffer" not-in-buffer)
  2497. (const :tag "In mode" in-mode)
  2498. (const :tag "Not in mode" not-in-mode))
  2499. (regexp))
  2500. (function :tag "Custom function"))))))
  2501. (defcustom org-agenda-max-entries nil
  2502. "Maximum number of entries to display in an agenda.
  2503. This can be nil (no limit) or an integer or an alist of agenda
  2504. types with an associated number of entries to display in this
  2505. type."
  2506. :version "24.4"
  2507. :package-version '(Org . "8.0")
  2508. :group 'org-agenda-custom-commands
  2509. :type '(choice (symbol :tag "No limit" nil)
  2510. (integer :tag "Max number of entries")
  2511. (repeat
  2512. (cons (choice :tag "Agenda type"
  2513. (const agenda)
  2514. (const todo)
  2515. (const tags)
  2516. (const search))
  2517. (integer :tag "Max number of entries")))))
  2518. (defcustom org-agenda-max-todos nil
  2519. "Maximum number of TODOs to display in an agenda.
  2520. This can be nil (no limit) or an integer or an alist of agenda
  2521. types with an associated number of entries to display in this
  2522. type."
  2523. :version "24.4"
  2524. :package-version '(Org . "8.0")
  2525. :group 'org-agenda-custom-commands
  2526. :type '(choice (symbol :tag "No limit" nil)
  2527. (integer :tag "Max number of TODOs")
  2528. (repeat
  2529. (cons (choice :tag "Agenda type"
  2530. (const agenda)
  2531. (const todo)
  2532. (const tags)
  2533. (const search))
  2534. (integer :tag "Max number of TODOs")))))
  2535. (defcustom org-agenda-max-tags nil
  2536. "Maximum number of tagged entries to display in an agenda.
  2537. This can be nil (no limit) or an integer or an alist of agenda
  2538. types with an associated number of entries to display in this
  2539. type."
  2540. :version "24.4"
  2541. :package-version '(Org . "8.0")
  2542. :group 'org-agenda-custom-commands
  2543. :type '(choice (symbol :tag "No limit" nil)
  2544. (integer :tag "Max number of tagged entries")
  2545. (repeat
  2546. (cons (choice :tag "Agenda type"
  2547. (const agenda)
  2548. (const todo)
  2549. (const tags)
  2550. (const search))
  2551. (integer :tag "Max number of tagged entries")))))
  2552. (defcustom org-agenda-max-effort nil
  2553. "Maximum cumulated effort duration for the agenda.
  2554. This can be nil (no limit) or a number of minutes (as an integer)
  2555. or an alist of agenda types with an associated number of minutes
  2556. to limit entries to in this type."
  2557. :version "24.4"
  2558. :package-version '(Org . "8.0")
  2559. :group 'org-agenda-custom-commands
  2560. :type '(choice (symbol :tag "No limit" nil)
  2561. (integer :tag "Max number of minutes")
  2562. (repeat
  2563. (cons (choice :tag "Agenda type"
  2564. (const agenda)
  2565. (const todo)
  2566. (const tags)
  2567. (const search))
  2568. (integer :tag "Max number of minutes")))))
  2569. (defvar org-agenda-keep-restricted-file-list nil)
  2570. (defvar org-keys nil)
  2571. (defvar org-match nil)
  2572. ;;;###autoload
  2573. (defun org-agenda (&optional arg keys restriction)
  2574. "Dispatch agenda commands to collect entries to the agenda buffer.
  2575. Prompts for a command to execute. Any prefix arg will be passed
  2576. on to the selected command. The default selections are:
  2577. a Call `org-agenda-list' to display the agenda for current day or week.
  2578. t Call `org-todo-list' to display the global todo list.
  2579. T Call `org-todo-list' to display the global todo list, select only
  2580. entries with a specific TODO keyword (the user gets a prompt).
  2581. m Call `org-tags-view' to display headlines with tags matching
  2582. a condition (the user is prompted for the condition).
  2583. M Like `m', but select only TODO entries, no ordinary headlines.
  2584. e Export views to associated files.
  2585. s Search entries for keywords.
  2586. S Search entries for keywords, only with TODO keywords.
  2587. / Multi occur across all agenda files and also files listed
  2588. in `org-agenda-text-search-extra-files'.
  2589. < Restrict agenda commands to buffer, subtree, or region.
  2590. Press several times to get the desired effect.
  2591. > Remove a previous restriction.
  2592. # List \"stuck\" projects.
  2593. ! Configure what \"stuck\" means.
  2594. C Configure custom agenda commands.
  2595. More commands can be added by configuring the variable
  2596. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2597. searches can be pre-defined in this way.
  2598. If the current buffer is in Org mode and visiting a file, you can also
  2599. first press `<' once to indicate that the agenda should be temporarily
  2600. \(until the next use of `\\[org-agenda]') restricted to the current file.
  2601. Pressing `<' twice means to restrict to the current subtree or region
  2602. \(if active)."
  2603. (interactive "P")
  2604. (catch 'exit
  2605. (let* ((org-keys keys)
  2606. (prefix-descriptions nil)
  2607. (org-agenda-buffer-name org-agenda-buffer-name)
  2608. (org-agenda-window-setup (if (equal (buffer-name)
  2609. org-agenda-buffer-name)
  2610. 'current-window
  2611. org-agenda-window-setup))
  2612. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2613. (org-agenda-custom-commands
  2614. ;; normalize different versions
  2615. (delq nil
  2616. (mapcar
  2617. (lambda (x)
  2618. (cond ((stringp (cdr x))
  2619. (push x prefix-descriptions)
  2620. nil)
  2621. ((stringp (nth 1 x)) x)
  2622. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2623. (t (cons (car x) (cons "" (cdr x))))))
  2624. org-agenda-custom-commands)))
  2625. (org-agenda-custom-commands
  2626. (org-contextualize-keys
  2627. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2628. ;; (buf (current-buffer))
  2629. (bfn (buffer-file-name (buffer-base-buffer)))
  2630. entry type org-match lprops ans) ;; key
  2631. ;; Turn off restriction unless there is an overriding one,
  2632. (unless org-agenda-overriding-restriction
  2633. (unless org-agenda-keep-restricted-file-list
  2634. ;; There is a request to keep the file list in place
  2635. (put 'org-agenda-files 'org-restrict nil))
  2636. (setq org-agenda-restrict nil)
  2637. (move-marker org-agenda-restrict-begin nil)
  2638. (move-marker org-agenda-restrict-end nil))
  2639. ;; Remember where this call originated
  2640. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2641. (unless org-keys
  2642. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2643. org-keys (car ans)
  2644. restriction (cdr ans)))
  2645. ;; If we have sticky agenda buffers, set a name for the buffer,
  2646. ;; depending on the invoking keys. The user may still set this
  2647. ;; as a command option, which will overwrite what we do here.
  2648. (when org-agenda-sticky
  2649. (setq org-agenda-buffer-name
  2650. (format "*Org Agenda(%s)*" org-keys)))
  2651. ;; Establish the restriction, if any
  2652. (when (and (not org-agenda-overriding-restriction) restriction)
  2653. (put 'org-agenda-files 'org-restrict (list bfn))
  2654. (cond
  2655. ((eq restriction 'region)
  2656. (setq org-agenda-restrict (current-buffer))
  2657. (move-marker org-agenda-restrict-begin (region-beginning))
  2658. (move-marker org-agenda-restrict-end (region-end)))
  2659. ((eq restriction 'subtree)
  2660. (save-excursion
  2661. (setq org-agenda-restrict (current-buffer))
  2662. (org-back-to-heading t)
  2663. (move-marker org-agenda-restrict-begin (point))
  2664. (move-marker org-agenda-restrict-end
  2665. (progn (org-end-of-subtree t)))))
  2666. ((eq restriction 'buffer)
  2667. (if (not (buffer-narrowed-p))
  2668. (setq org-agenda-restrict t)
  2669. (setq org-agenda-restrict (current-buffer))
  2670. (move-marker org-agenda-restrict-begin (point-min))
  2671. (move-marker org-agenda-restrict-end (point-max))))))
  2672. ;; For example the todo list should not need it (but does...)
  2673. (cond
  2674. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2675. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2676. (progn
  2677. ;; FIXME: Is (nth 3 entry) supposed to have access (via dynvars)
  2678. ;; to some of the local variables? There's no doc about
  2679. ;; that for `org-agenda-custom-commands'.
  2680. (setq type (nth 2 entry) org-match (eval (nth 3 entry) t)
  2681. lprops (nth 4 entry))
  2682. (when org-agenda-sticky
  2683. (setq org-agenda-buffer-name
  2684. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2685. (format "*Org Agenda(%s)*" org-keys))))
  2686. (cl-progv
  2687. (mapcar #'car lprops)
  2688. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  2689. (pcase type
  2690. (`agenda
  2691. (org-agenda-list arg))
  2692. (`agenda*
  2693. (org-agenda-list arg nil nil t))
  2694. (`alltodo
  2695. (org-todo-list arg))
  2696. (`search
  2697. (org-search-view arg org-match nil))
  2698. (`stuck
  2699. (org-agenda-list-stuck-projects arg))
  2700. (`tags
  2701. (org-tags-view arg org-match))
  2702. (`tags-todo
  2703. (org-tags-view '(4) org-match))
  2704. (`todo
  2705. (org-todo-list org-match))
  2706. (`tags-tree
  2707. (org-check-for-org-mode)
  2708. (org-match-sparse-tree arg org-match))
  2709. (`todo-tree
  2710. (org-check-for-org-mode)
  2711. (org-occur (concat "^" org-outline-regexp "[ \t]*"
  2712. (regexp-quote org-match) "\\>")))
  2713. (`occur-tree
  2714. (org-check-for-org-mode)
  2715. (org-occur org-match))
  2716. ((pred functionp)
  2717. (funcall type org-match))
  2718. ;; FIXME: Will signal an error since it's not `functionp'!
  2719. ((pred fboundp) (funcall type org-match))
  2720. (_ (user-error "Invalid custom agenda command type %s" type))))
  2721. (let ((inhibit-read-only t))
  2722. (add-text-properties (point-min) (point-max)
  2723. `(org-lprops ,lprops))))
  2724. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2725. ((equal org-keys "C")
  2726. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2727. (customize-variable 'org-agenda-custom-commands))
  2728. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2729. ((equal org-keys "s") (call-interactively 'org-search-view))
  2730. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2731. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2732. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2733. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2734. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2735. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2736. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2737. (add-hook
  2738. 'post-command-hook
  2739. (lambda ()
  2740. (unless (current-message)
  2741. (let* ((m (org-agenda-get-any-marker))
  2742. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2743. (when note
  2744. (message "FLAGGING-NOTE ([?] for more info): %s"
  2745. (org-add-props
  2746. (replace-regexp-in-string
  2747. "\\\\n" "//"
  2748. (copy-sequence note))
  2749. nil 'face 'org-warning))))))
  2750. t t))
  2751. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2752. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2753. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2754. (t (user-error "Invalid agenda key"))))))
  2755. (defvar org-agenda-multi)
  2756. (defun org-agenda-append-agenda ()
  2757. "Append another agenda view to the current one.
  2758. This function allows interactive building of block agendas.
  2759. Agenda views are separated by `org-agenda-block-separator'."
  2760. (interactive)
  2761. (unless (derived-mode-p 'org-agenda-mode)
  2762. (user-error "Can only append from within agenda buffer"))
  2763. (let ((org-agenda-multi t))
  2764. (org-agenda)
  2765. (widen)
  2766. (org-agenda-finalize)
  2767. (setq buffer-read-only t)
  2768. (org-agenda-fit-window-to-buffer)))
  2769. (defun org-agenda-normalize-custom-commands (cmds)
  2770. "Normalize custom commands CMDS."
  2771. (delq nil
  2772. (mapcar
  2773. (lambda (x)
  2774. (cond ((stringp (cdr x)) nil)
  2775. ((stringp (nth 1 x)) x)
  2776. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2777. (t (cons (car x) (cons "" (cdr x))))))
  2778. cmds)))
  2779. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2780. "The user interface for selecting an agenda command."
  2781. (catch 'exit
  2782. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2783. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2784. (region-p (org-region-active-p))
  2785. (custom org-agenda-custom-commands)
  2786. (selstring "")
  2787. restriction second-time
  2788. c entry key type match prefixes rmheader header-end custom1 desc
  2789. line lines left right n n1)
  2790. (save-window-excursion
  2791. (delete-other-windows)
  2792. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2793. (erase-buffer)
  2794. (insert (eval-when-compile
  2795. (let ((header
  2796. (copy-sequence
  2797. "Press key for an agenda command:
  2798. -------------------------------- < Buffer, subtree/region restriction
  2799. a Agenda for current week or day > Remove restriction
  2800. t List of all TODO entries e Export agenda views
  2801. m Match a TAGS/PROP/TODO query T Entries with special TODO kwd
  2802. s Search for keywords M Like m, but only TODO entries
  2803. / Multi-occur S Like s, but only TODO entries
  2804. ? Find :FLAGGED: entries C Configure custom agenda commands
  2805. * Toggle sticky agenda views # List stuck projects (!=configure)
  2806. "))
  2807. (start 0))
  2808. (while (string-match
  2809. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2810. header start)
  2811. (setq start (match-end 0))
  2812. (add-text-properties (match-beginning 2) (match-end 2)
  2813. '(face bold) header))
  2814. header)))
  2815. (setq header-end (point-marker))
  2816. (while t
  2817. (setq custom1 custom)
  2818. (when (eq rmheader t)
  2819. (org-goto-line 1)
  2820. (re-search-forward ":" nil t)
  2821. (delete-region (match-end 0) (line-end-position))
  2822. (forward-char 1)
  2823. (looking-at "-+")
  2824. (delete-region (match-end 0) (line-end-position))
  2825. (move-marker header-end (match-end 0)))
  2826. (goto-char header-end)
  2827. (delete-region (point) (point-max))
  2828. ;; Produce all the lines that describe custom commands and prefixes
  2829. (setq lines nil)
  2830. (while (setq entry (pop custom1))
  2831. (setq key (car entry) desc (nth 1 entry)
  2832. type (nth 2 entry)
  2833. match (nth 3 entry))
  2834. (if (> (length key) 1)
  2835. (cl-pushnew (string-to-char key) prefixes :test #'equal)
  2836. (setq line
  2837. (format
  2838. "%-4s%-14s"
  2839. (org-add-props (copy-sequence key)
  2840. '(face bold))
  2841. (cond
  2842. ((string-match "\\S-" desc) desc)
  2843. ((eq type 'agenda) "Agenda for current week or day")
  2844. ((eq type 'agenda*) "Appointments for current week or day")
  2845. ((eq type 'alltodo) "List of all TODO entries")
  2846. ((eq type 'search) "Word search")
  2847. ((eq type 'stuck) "List of stuck projects")
  2848. ((eq type 'todo) "TODO keyword")
  2849. ((eq type 'tags) "Tags query")
  2850. ((eq type 'tags-todo) "Tags (TODO)")
  2851. ((eq type 'tags-tree) "Tags tree")
  2852. ((eq type 'todo-tree) "TODO kwd tree")
  2853. ((eq type 'occur-tree) "Occur tree")
  2854. ((functionp type) (if (symbolp type)
  2855. (symbol-name type)
  2856. "Lambda expression"))
  2857. (t "???"))))
  2858. (cond
  2859. ((not (org-string-nw-p match)) nil)
  2860. (org-agenda-menu-show-matcher
  2861. (setq line
  2862. (concat line ": "
  2863. (cond
  2864. ((stringp match)
  2865. (propertize match 'face 'org-warning))
  2866. ((listp type)
  2867. (format "set of %d commands" (length type)))))))
  2868. (t
  2869. (org-add-props line nil 'help-echo (concat "Matcher: " match))))
  2870. (push line lines)))
  2871. (setq lines (nreverse lines))
  2872. (when prefixes
  2873. (mapc (lambda (x)
  2874. (push
  2875. (format "%s %s"
  2876. (org-add-props (char-to-string x)
  2877. nil 'face 'bold)
  2878. (or (cdr (assoc (concat selstring
  2879. (char-to-string x))
  2880. prefix-descriptions))
  2881. "Prefix key"))
  2882. lines))
  2883. prefixes))
  2884. ;; Check if we should display in two columns
  2885. (if org-agenda-menu-two-columns
  2886. (progn
  2887. (setq n (length lines)
  2888. n1 (+ (/ n 2) (mod n 2))
  2889. right (nthcdr n1 lines)
  2890. left (copy-sequence lines))
  2891. (setcdr (nthcdr (1- n1) left) nil))
  2892. (setq left lines right nil))
  2893. (while left
  2894. (insert "\n" (pop left))
  2895. (when right
  2896. (if (< (current-column) 40)
  2897. (move-to-column 40 t)
  2898. (insert " "))
  2899. (insert (pop right))))
  2900. ;; Make the window the right size
  2901. (goto-char (point-min))
  2902. (if second-time
  2903. (when (not (pos-visible-in-window-p (point-max)))
  2904. (org-fit-window-to-buffer))
  2905. (setq second-time t)
  2906. (org-fit-window-to-buffer))
  2907. ;; Hint to navigation if window too small for all information
  2908. (setq header-line-format
  2909. (when (not (pos-visible-in-window-p (point-max)))
  2910. "Use C-v, M-v, C-n or C-p to navigate."))
  2911. ;; Ask for selection
  2912. (cl-loop
  2913. do (progn
  2914. (message "Press key for agenda command%s:"
  2915. (if (or restrict-ok org-agenda-overriding-restriction)
  2916. (if org-agenda-overriding-restriction
  2917. " (restriction lock active)"
  2918. (if restriction
  2919. (format " (restricted to %s)" restriction)
  2920. " (unrestricted)"))
  2921. ""))
  2922. (setq c (read-char-exclusive)))
  2923. until (not (memq c '(14 16 22 134217846)))
  2924. do (org-scroll c))
  2925. (message "")
  2926. (cond
  2927. ((assoc (char-to-string c) custom)
  2928. (setq selstring (concat selstring (char-to-string c)))
  2929. (throw 'exit (cons selstring restriction)))
  2930. ((memq c prefixes)
  2931. (setq selstring (concat selstring (char-to-string c))
  2932. prefixes nil
  2933. rmheader (or rmheader t)
  2934. custom (delq nil (mapcar
  2935. (lambda (x)
  2936. (if (or (= (length (car x)) 1)
  2937. (/= (string-to-char (car x)) c))
  2938. nil
  2939. (cons (substring (car x) 1) (cdr x))))
  2940. custom))))
  2941. ((eq c ?*)
  2942. (call-interactively 'org-toggle-sticky-agenda)
  2943. (sit-for 2))
  2944. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2945. (message "Restriction is only possible in Org buffers")
  2946. (ding) (sit-for 1))
  2947. ((eq c ?1)
  2948. (org-agenda-remove-restriction-lock 'noupdate)
  2949. (setq restriction 'buffer))
  2950. ((eq c ?0)
  2951. (org-agenda-remove-restriction-lock 'noupdate)
  2952. (setq restriction (if region-p 'region 'subtree)))
  2953. ((eq c ?<)
  2954. (org-agenda-remove-restriction-lock 'noupdate)
  2955. (setq restriction
  2956. (cond
  2957. ((eq restriction 'buffer)
  2958. (if region-p 'region 'subtree))
  2959. ((memq restriction '(subtree region))
  2960. nil)
  2961. (t 'buffer))))
  2962. ((eq c ?>)
  2963. (org-agenda-remove-restriction-lock 'noupdate)
  2964. (setq restriction nil))
  2965. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2966. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2967. ((and (> (length selstring) 0) (eq c ?\d))
  2968. (delete-window)
  2969. (org-agenda-get-restriction-and-command prefix-descriptions))
  2970. ((equal c ?q) (user-error "Abort"))
  2971. (t (user-error "Invalid key %c" c))))))))
  2972. (defun org-agenda-fit-window-to-buffer ()
  2973. "Fit the window to the buffer size."
  2974. (and (memq org-agenda-window-setup '(reorganize-frame))
  2975. (fboundp 'fit-window-to-buffer)
  2976. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2977. (= (car org-agenda-window-frame-fractions) 1.0))
  2978. (delete-other-windows)
  2979. (org-fit-window-to-buffer
  2980. nil
  2981. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2982. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2983. (defvar org-cmd nil)
  2984. (defvar org-agenda-overriding-cmd nil)
  2985. (defvar org-agenda-overriding-arguments nil)
  2986. (defvar org-agenda-overriding-cmd-arguments nil)
  2987. (defun org-let (list &rest body) ;FIXME: So many kittens are suffering here.
  2988. (declare (indent 1) (obsolete cl-progv "2021"))
  2989. (eval (cons 'let (cons list body))))
  2990. (defun org-let2 (list1 list2 &rest body) ;FIXME: Where did our karma go?
  2991. (declare (indent 2) (obsolete cl-progv "2021"))
  2992. (eval (cons 'let (cons list1 (list (cons 'let (cons list2 body)))))))
  2993. (defun org-agenda-run-series (name series)
  2994. "Run agenda NAME as a SERIES of agenda commands."
  2995. (let* ((gprops (nth 1 series))
  2996. (gvars (mapcar #'car gprops))
  2997. (gvals (mapcar (lambda (binding) (eval (cadr binding) t)) gprops)))
  2998. (cl-progv gvars gvals (org-agenda-prepare name))
  2999. ;; We need to reset agenda markers here, because when constructing a
  3000. ;; block agenda, the individual blocks do not do that.
  3001. (org-agenda-reset-markers)
  3002. (with-no-warnings
  3003. (defvar match)) ;Used via the `eval' below.
  3004. (let* ((org-agenda-multi t)
  3005. ;; FIXME: Redo should contain lists of (FUNS . ARGS) rather
  3006. ;; than expressions, so you don't need to `quote' the args
  3007. ;; and you just need to `apply' instead of `eval' when using it.
  3008. (redo (list 'org-agenda-run-series name (list 'quote series)))
  3009. (cmds (car series))
  3010. match
  3011. org-cmd type lprops)
  3012. (while (setq org-cmd (pop cmds))
  3013. (setq type (car org-cmd))
  3014. (setq match (eval (nth 1 org-cmd) t))
  3015. (setq lprops (nth 2 org-cmd))
  3016. (let ((org-agenda-overriding-arguments
  3017. (if (eq org-agenda-overriding-cmd org-cmd)
  3018. (or org-agenda-overriding-arguments
  3019. org-agenda-overriding-cmd-arguments)))
  3020. (lvars (mapcar #'car lprops))
  3021. (lvals (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)))
  3022. (cl-progv (append gvars lvars) (append gvals lvals)
  3023. (pcase type
  3024. (`agenda
  3025. (call-interactively 'org-agenda-list))
  3026. (`agenda*
  3027. (funcall 'org-agenda-list nil nil t))
  3028. (`alltodo
  3029. (call-interactively 'org-todo-list))
  3030. (`search
  3031. (org-search-view current-prefix-arg match nil))
  3032. (`stuck
  3033. (call-interactively 'org-agenda-list-stuck-projects))
  3034. (`tags
  3035. (org-tags-view current-prefix-arg match))
  3036. (`tags-todo
  3037. (org-tags-view '(4) match))
  3038. (`todo
  3039. (org-todo-list match))
  3040. ((pred fboundp)
  3041. (funcall type match))
  3042. (_ (error "Invalid type in command series"))))))
  3043. (widen)
  3044. (let ((inhibit-read-only t))
  3045. (add-text-properties (point-min) (point-max)
  3046. `(org-series t org-series-redo-cmd ,redo)))
  3047. (setq org-agenda-redo-command redo)
  3048. (goto-char (point-min)))
  3049. (org-agenda-fit-window-to-buffer)
  3050. (cl-progv gvars gvals (org-agenda-finalize))))
  3051. (defun org-agenda--split-plist (plist)
  3052. ;; We could/should arguably use `map-keys' and `map-values'.
  3053. (let (keys vals)
  3054. (while plist
  3055. (push (pop plist) keys)
  3056. (push (pop plist) vals))
  3057. (cons (nreverse keys) (nreverse vals))))
  3058. ;;;###autoload
  3059. (defmacro org-batch-agenda (cmd-key &rest parameters)
  3060. "Run an agenda command in batch mode and send the result to STDOUT.
  3061. If CMD-KEY is a string of length 1, it is used as a key in
  3062. `org-agenda-custom-commands' and triggers this command. If it is a
  3063. longer string it is used as a tags/todo match string.
  3064. Parameters are alternating variable names and values that will be bound
  3065. before running the agenda command."
  3066. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3067. `(org--batch-agenda ,cmd-key ',vars (list ,@exps))))
  3068. (defun org--batch-agenda (cmd-key vars vals)
  3069. ;; `org-batch-agenda' is a macro because every other "parameter" is
  3070. ;; a variable name rather than an expression to evaluate. Yuck!
  3071. (cl-progv vars vals
  3072. (let (org-agenda-sticky)
  3073. (if (> (length cmd-key) 1)
  3074. (org-tags-view nil cmd-key)
  3075. (org-agenda nil cmd-key))))
  3076. (set-buffer org-agenda-buffer-name)
  3077. (princ (buffer-string)))
  3078. (defvar org-agenda-info nil)
  3079. ;;;###autoload
  3080. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  3081. "Run an agenda command in batch mode and send the result to STDOUT.
  3082. If CMD-KEY is a string of length 1, it is used as a key in
  3083. `org-agenda-custom-commands' and triggers this command. If it is a
  3084. longer string it is used as a tags/todo match string.
  3085. Parameters are alternating variable names and values that will be bound
  3086. before running the agenda command.
  3087. The output gives a line for each selected agenda item. Each
  3088. item is a list of comma-separated values, like this:
  3089. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  3090. category The category of the item
  3091. head The headline, without TODO kwd, TAGS and PRIORITY
  3092. type The type of the agenda entry, can be
  3093. todo selected in TODO match
  3094. tagsmatch selected in tags match
  3095. diary imported from diary
  3096. deadline a deadline on given date
  3097. scheduled scheduled on given date
  3098. timestamp entry has timestamp on given date
  3099. closed entry was closed on given date
  3100. upcoming-deadline warning about deadline
  3101. past-scheduled forwarded scheduled item
  3102. block entry has date block including g. date
  3103. todo The todo keyword, if any
  3104. tags All tags including inherited ones, separated by colons
  3105. date The relevant date, like 2007-2-14
  3106. time The time, like 15:00-16:50
  3107. extra String with extra planning info
  3108. priority-l The priority letter if any was given
  3109. priority-n The computed numerical priority
  3110. agenda-day The day in the agenda where this is listed"
  3111. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3112. `(org--batch-agenda-csv ,cmd-key ',vars (list ,@exps))))
  3113. (defun org--batch-agenda-csv (cmd-key vars vals)
  3114. ;; `org-batch-agenda-csv' is a macro because every other "parameter" is
  3115. ;; a variable name rather than an expression to evaluate. Yuck!
  3116. (let ((org-agenda-remove-tags t))
  3117. (cl-progv vars vals
  3118. ;; FIXME: Shouldn't this be 1 (see commit 10173ad6d610b)?
  3119. (if (> (length cmd-key) 2)
  3120. (org-tags-view nil cmd-key)
  3121. (org-agenda nil cmd-key))))
  3122. (set-buffer org-agenda-buffer-name)
  3123. (let ((lines (org-split-string (buffer-string) "\n")))
  3124. (dolist (line lines)
  3125. (when (get-text-property 0 'org-category line)
  3126. (setq org-agenda-info
  3127. (org-fix-agenda-info (text-properties-at 0 line)))
  3128. (princ
  3129. (mapconcat #'org-agenda-export-csv-mapper
  3130. '(org-category txt type todo tags date time extra
  3131. priority-letter priority agenda-day)
  3132. ","))
  3133. (princ "\n")))))
  3134. (defun org-fix-agenda-info (props)
  3135. "Make sure all properties on an agenda item have a canonical form.
  3136. This ensures the export commands can easily use it."
  3137. (let (tmp re)
  3138. (when (setq tmp (plist-get props 'tags))
  3139. (setq props (plist-put props 'tags (mapconcat #'identity tmp ":"))))
  3140. (when (setq tmp (plist-get props 'date))
  3141. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3142. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3143. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  3144. (setq tmp (calendar-date-string tmp)))
  3145. (setq props (plist-put props 'date tmp)))
  3146. (when (setq tmp (plist-get props 'day))
  3147. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3148. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3149. (setq tmp (calendar-date-string tmp)))
  3150. (setq props (plist-put props 'day tmp))
  3151. (setq props (plist-put props 'agenda-day tmp)))
  3152. (when (setq tmp (plist-get props 'txt))
  3153. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  3154. (plist-put props 'priority-letter (match-string 1 tmp))
  3155. (setq tmp (replace-match "" t t tmp)))
  3156. (when (and (setq re (plist-get props 'org-todo-regexp))
  3157. (setq re (concat "\\`\\.*" re " ?"))
  3158. (let ((case-fold-search nil)) (string-match re tmp)))
  3159. (plist-put props 'todo (match-string 1 tmp))
  3160. (setq tmp (replace-match "" t t tmp)))
  3161. (plist-put props 'txt tmp)))
  3162. props)
  3163. (defun org-agenda-export-csv-mapper (prop)
  3164. (let ((res (plist-get org-agenda-info prop)))
  3165. (setq res
  3166. (cond
  3167. ((not res) "")
  3168. ((stringp res) res)
  3169. (t (prin1-to-string res))))
  3170. (org-trim (replace-regexp-in-string "," ";" res nil t))))
  3171. ;;;###autoload
  3172. (defun org-store-agenda-views (&rest _parameters)
  3173. "Store agenda views."
  3174. (interactive)
  3175. (org--batch-store-agenda-views nil nil))
  3176. ;;;###autoload
  3177. (defmacro org-batch-store-agenda-views (&rest parameters)
  3178. "Run all custom agenda commands that have a file argument."
  3179. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3180. `(org--batch-store-agenda-views ',vars (list ,@exps))))
  3181. (defun org--batch-store-agenda-views (vars vals)
  3182. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  3183. (pop-up-frames nil)
  3184. (dir default-directory)
  3185. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  3186. (save-window-excursion
  3187. (while cmds
  3188. (setq cmd (pop cmds)
  3189. thiscmdkey (car cmd)
  3190. thiscmdcmd (cdr cmd)
  3191. match (nth 2 thiscmdcmd)
  3192. bufname (if org-agenda-sticky
  3193. (or (and (stringp match)
  3194. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  3195. (format "*Org Agenda(%s)*" thiscmdkey))
  3196. org-agenda-buffer-name)
  3197. cmd-or-set (nth 2 cmd)
  3198. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  3199. files (nth (if (listp cmd-or-set) 4 5) cmd))
  3200. (if (stringp files) (setq files (list files)))
  3201. (when files
  3202. (let* ((opts (append org-agenda-exporter-settings opts))
  3203. (vars (append (mapcar #'car opts) vars))
  3204. (vals (append (mapcar (lambda (binding) (eval (cadr binding) t))
  3205. opts)
  3206. vals)))
  3207. (cl-progv vars vals
  3208. (org-agenda nil thiscmdkey))
  3209. (set-buffer bufname)
  3210. (while files
  3211. (cl-progv vars vals
  3212. (org-agenda-write (expand-file-name (pop files) dir)
  3213. nil t bufname))))
  3214. (and (get-buffer bufname)
  3215. (kill-buffer bufname)))))))
  3216. (defvar org-agenda-current-span nil
  3217. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3218. (defun org-agenda-mark-header-line (pos)
  3219. "Mark the line at POS as an agenda structure header."
  3220. (save-excursion
  3221. (goto-char pos)
  3222. (put-text-property (line-beginning-position) (line-end-position)
  3223. 'org-agenda-structural-header t)
  3224. (when org-agenda-title-append
  3225. (put-text-property (line-beginning-position) (line-end-position)
  3226. 'org-agenda-title-append org-agenda-title-append))))
  3227. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  3228. (defvar org-agenda-write-buffer-name "Agenda View")
  3229. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  3230. "Write the current buffer (an agenda view) as a file.
  3231. Depending on the extension of the file name, plain text (.txt),
  3232. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  3233. If the extension is .ics, translate visible agenda into iCalendar
  3234. format. If the extension is .org, collect all subtrees
  3235. corresponding to the agenda entries and add them in an .org file.
  3236. With prefix argument OPEN, open the new file immediately. If
  3237. NOSETTINGS is given, do not scope the settings of
  3238. `org-agenda-exporter-settings' into the export commands. This is
  3239. used when the settings have already been scoped and we do not
  3240. wish to overrule other, higher priority settings. If
  3241. AGENDA-BUFFER-NAME is provided, use this as the buffer name for
  3242. the agenda to write."
  3243. (interactive "FWrite agenda to file: \nP")
  3244. (if (or (not (file-writable-p file))
  3245. (and (file-exists-p file)
  3246. (if (called-interactively-p 'any)
  3247. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3248. (user-error "Cannot write agenda to file %s" file))
  3249. (cl-progv
  3250. (if nosettings nil (mapcar #'car org-agenda-exporter-settings))
  3251. (if nosettings nil (mapcar (lambda (binding) (eval (cadr binding) t))
  3252. org-agenda-exporter-settings))
  3253. (save-excursion
  3254. (save-window-excursion
  3255. (let ((bs (copy-sequence (buffer-string)))
  3256. (extension (file-name-extension file))
  3257. (default-directory (file-name-directory file))
  3258. ) ;; beg content
  3259. (with-temp-buffer
  3260. (rename-buffer org-agenda-write-buffer-name t)
  3261. (set-buffer-modified-p nil)
  3262. (insert bs)
  3263. (org-agenda-remove-marked-text 'invisible 'org-filtered)
  3264. (run-hooks 'org-agenda-before-write-hook)
  3265. (cond
  3266. ((bound-and-true-p org-mobile-creating-agendas)
  3267. (org-mobile-write-agenda-for-mobile file))
  3268. ((string= "org" extension)
  3269. (let (content p m message-log-max)
  3270. (goto-char (point-min))
  3271. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3272. (goto-char p)
  3273. (setq m (get-text-property (point) 'org-hd-marker))
  3274. (when m
  3275. (push (with-current-buffer (marker-buffer m)
  3276. (goto-char m)
  3277. (org-copy-subtree 1 nil t t)
  3278. org-subtree-clip)
  3279. content)))
  3280. (find-file file)
  3281. (erase-buffer)
  3282. (dolist (s content) (org-paste-subtree 1 s))
  3283. (write-file file)
  3284. (kill-buffer (current-buffer))
  3285. (message "Org file written to %s" file)))
  3286. ((member extension '("html" "htm"))
  3287. (or (require 'htmlize nil t)
  3288. (error "Please install htmlize from https://github.com/hniksic/emacs-htmlize"))
  3289. (declare-function htmlize-buffer "htmlize" (&optional buffer))
  3290. (set-buffer (htmlize-buffer (current-buffer)))
  3291. (when org-agenda-export-html-style
  3292. ;; replace <style> section with org-agenda-export-html-style
  3293. (goto-char (point-min))
  3294. (kill-region (- (search-forward "<style") 6)
  3295. (search-forward "</style>"))
  3296. (insert org-agenda-export-html-style))
  3297. (write-file file)
  3298. (kill-buffer (current-buffer))
  3299. (message "HTML written to %s" file))
  3300. ((string= "ps" extension)
  3301. (require 'ps-print)
  3302. (ps-print-buffer-with-faces file)
  3303. (message "Postscript written to %s" file))
  3304. ((string= "pdf" extension)
  3305. (require 'ps-print)
  3306. (ps-print-buffer-with-faces
  3307. (concat (file-name-sans-extension file) ".ps"))
  3308. (call-process "ps2pdf" nil nil nil
  3309. (expand-file-name
  3310. (concat (file-name-sans-extension file) ".ps"))
  3311. (expand-file-name file))
  3312. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3313. (message "PDF written to %s" file))
  3314. ((string= "ics" extension)
  3315. (require 'ox-icalendar)
  3316. (declare-function org-icalendar-export-current-agenda
  3317. "ox-icalendar" (file))
  3318. (org-icalendar-export-current-agenda (expand-file-name file)))
  3319. (t
  3320. (let ((bs (buffer-string)))
  3321. (find-file file)
  3322. (erase-buffer)
  3323. (insert bs)
  3324. (save-buffer 0)
  3325. (kill-buffer (current-buffer))
  3326. (message "Plain text written to %s" file))))))))
  3327. (set-buffer (or agenda-bufname
  3328. ;; FIXME: I'm pretty sure called-interactively-p
  3329. ;; doesn't do what we want here!
  3330. (and (called-interactively-p 'any) (buffer-name))
  3331. org-agenda-buffer-name)))
  3332. (when open (org-open-file file)))
  3333. (defun org-agenda-remove-marked-text (property &optional value)
  3334. "Delete all text marked with VALUE of PROPERTY.
  3335. VALUE defaults to t."
  3336. (let (beg)
  3337. (setq value (or value t))
  3338. (while (setq beg (text-property-any (point-min) (point-max)
  3339. property value))
  3340. (delete-region
  3341. beg (or (next-single-property-change beg property)
  3342. (point-max))))))
  3343. (defun org-agenda-add-entry-text ()
  3344. "Add entry text to agenda lines.
  3345. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3346. entry text following headings shown in the agenda.
  3347. Drawers will be excluded, also the line with scheduling/deadline info."
  3348. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3349. (not (bound-and-true-p org-mobile-creating-agendas)))
  3350. (let (m txt)
  3351. (goto-char (point-min))
  3352. (while (not (eobp))
  3353. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3354. (beginning-of-line 2)
  3355. (setq txt (org-agenda-get-some-entry-text
  3356. m org-agenda-add-entry-text-maxlines " > "))
  3357. (end-of-line 1)
  3358. (if (string-match "\\S-" txt)
  3359. (insert "\n" txt)
  3360. (or (eobp) (forward-char 1))))))))
  3361. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3362. &rest keep)
  3363. "Extract entry text from MARKER, at most N-LINES lines.
  3364. This will ignore drawers etc, just get the text.
  3365. If INDENT is given, prefix every line with this string. If KEEP is
  3366. given, it is a list of symbols, defining stuff that should not be
  3367. removed from the entry content. Currently only `planning' is allowed here."
  3368. (let (txt drawer-re kwd-time-re ind)
  3369. (save-excursion
  3370. (with-current-buffer (marker-buffer marker)
  3371. (if (not (derived-mode-p 'org-mode))
  3372. (setq txt "")
  3373. (org-with-wide-buffer
  3374. (goto-char marker)
  3375. (end-of-line 1)
  3376. (setq txt (buffer-substring
  3377. (min (1+ (point)) (point-max))
  3378. (progn (outline-next-heading) (point)))
  3379. drawer-re org-drawer-regexp
  3380. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3381. ".*\n?"))
  3382. (with-temp-buffer
  3383. (insert txt)
  3384. (when org-agenda-add-entry-text-descriptive-links
  3385. (goto-char (point-min))
  3386. (while (org-activate-links (point-max))
  3387. (goto-char (match-end 0))))
  3388. (goto-char (point-min))
  3389. (while (re-search-forward org-link-bracket-re (point-max) t)
  3390. (set-text-properties (match-beginning 0) (match-end 0)
  3391. nil))
  3392. (goto-char (point-min))
  3393. (while (re-search-forward drawer-re nil t)
  3394. (delete-region
  3395. (match-beginning 0)
  3396. (progn (re-search-forward
  3397. "^[ \t]*:END:.*\n?" nil 'move)
  3398. (point))))
  3399. (unless (member 'planning keep)
  3400. (goto-char (point-min))
  3401. (while (re-search-forward kwd-time-re nil t)
  3402. (replace-match "")))
  3403. (goto-char (point-min))
  3404. (when org-agenda-entry-text-exclude-regexps
  3405. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3406. (while (setq re (pop re-list))
  3407. (goto-char (point-min))
  3408. (while (re-search-forward re nil t)
  3409. (replace-match "")))))
  3410. (goto-char (point-max))
  3411. (skip-chars-backward " \t\n")
  3412. (when (looking-at "[ \t\n]+\\'") (replace-match ""))
  3413. ;; find and remove min common indentation
  3414. (goto-char (point-min))
  3415. (untabify (point-min) (point-max))
  3416. (setq ind (org-current-text-indentation))
  3417. (while (not (eobp))
  3418. (unless (looking-at "[ \t]*$")
  3419. (setq ind (min ind (org-current-text-indentation))))
  3420. (beginning-of-line 2))
  3421. (goto-char (point-min))
  3422. (while (not (eobp))
  3423. (unless (looking-at "[ \t]*$")
  3424. (move-to-column ind)
  3425. (delete-region (line-beginning-position) (point)))
  3426. (beginning-of-line 2))
  3427. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3428. (goto-char (point-min))
  3429. (when indent
  3430. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3431. (replace-match indent t t)))
  3432. (goto-char (point-min))
  3433. (while (looking-at "[ \t]*\n") (replace-match ""))
  3434. (goto-char (point-max))
  3435. (when (> (org-current-line)
  3436. n-lines)
  3437. (org-goto-line (1+ n-lines))
  3438. (backward-char 1))
  3439. (setq txt (buffer-substring (point-min) (point))))))))
  3440. txt))
  3441. (defun org-check-for-org-mode ()
  3442. "Make sure current buffer is in Org mode. Error if not."
  3443. (or (derived-mode-p 'org-mode)
  3444. (error "Cannot execute Org agenda command on buffer in %s"
  3445. major-mode)))
  3446. ;;; Agenda prepare and finalize
  3447. (defvar org-agenda-multi nil) ; dynamically scoped
  3448. (defvar org-agenda-pre-window-conf nil)
  3449. (defvar org-agenda-columns-active nil)
  3450. (defvar org-agenda-name nil)
  3451. (defvar org-agenda-tag-filter nil)
  3452. (defvar org-agenda-category-filter nil)
  3453. (defvar org-agenda-regexp-filter nil)
  3454. (defvar org-agenda-effort-filter nil)
  3455. (defvar org-agenda-top-headline-filter nil)
  3456. (defvar org-agenda-represented-categories nil
  3457. "Cache for the list of all categories in the agenda.")
  3458. (defvar org-agenda-represented-tags nil
  3459. "Cache for the list of all categories in the agenda.")
  3460. (defvar org-agenda-tag-filter-preset nil
  3461. "A preset of the tags filter used for secondary agenda filtering.
  3462. This must be a list of strings, each string must be a single tag preceded
  3463. by \"+\" or \"-\".
  3464. This variable should not be set directly, but agenda custom commands can
  3465. bind it in the options section. The preset filter is a global property of
  3466. the entire agenda view. In a block agenda, it will not work reliably to
  3467. define a filter for one of the individual blocks. You need to set it in
  3468. the global options and expect it to be applied to the entire view.")
  3469. (defvar org-agenda-filters-preset nil
  3470. "Alist of filter types and associated preset of filters.
  3471. This variable is local in `org-agenda' buffers. See `org-agenda-local-vars'.")
  3472. (defconst org-agenda-filter-variables
  3473. '((category . org-agenda-category-filter)
  3474. (tag . org-agenda-tag-filter)
  3475. (effort . org-agenda-effort-filter)
  3476. (regexp . org-agenda-regexp-filter))
  3477. "Alist of filter types and associated variables.")
  3478. (defun org-agenda-filter-any ()
  3479. "Is any filter active?"
  3480. (cl-some (lambda (x)
  3481. (or (symbol-value (cdr x))
  3482. (assoc-default (car x) org-agenda-filters-preset)))
  3483. org-agenda-filter-variables))
  3484. (defvar org-agenda-category-filter-preset nil
  3485. "A preset of the category filter used for secondary agenda filtering.
  3486. This must be a list of strings, each string must be a single category
  3487. preceded by \"+\" or \"-\".
  3488. This variable should not be set directly, but agenda custom commands can
  3489. bind it in the options section. The preset filter is a global property of
  3490. the entire agenda view. In a block agenda, it will not work reliably to
  3491. define a filter for one of the individual blocks. You need to set it in
  3492. the global options and expect it to be applied to the entire view.")
  3493. (defvar org-agenda-regexp-filter-preset nil
  3494. "A preset of the regexp filter used for secondary agenda filtering.
  3495. This must be a list of strings, each string must be a single regexp
  3496. preceded by \"+\" or \"-\".
  3497. This variable should not be set directly, but agenda custom commands can
  3498. bind it in the options section. The preset filter is a global property of
  3499. the entire agenda view. In a block agenda, it will not work reliably to
  3500. define a filter for one of the individual blocks. You need to set it in
  3501. the global options and expect it to be applied to the entire view.")
  3502. (defvar org-agenda-effort-filter-preset nil
  3503. "A preset of the effort condition used for secondary agenda filtering.
  3504. This must be a list of strings, each string must be a single regexp
  3505. preceded by \"+\" or \"-\".
  3506. This variable should not be set directly, but agenda custom commands can
  3507. bind it in the options section. The preset filter is a global property of
  3508. the entire agenda view. In a block agenda, it will not work reliably to
  3509. define a filter for one of the individual blocks. You need to set it in
  3510. the global options and expect it to be applied to the entire view.")
  3511. (defun org-agenda-use-sticky-p ()
  3512. "Return non-nil if an agenda buffer named
  3513. `org-agenda-buffer-name' exists and should be shown instead of
  3514. generating a new one."
  3515. (and
  3516. ;; turned off by user
  3517. org-agenda-sticky
  3518. ;; For multi-agenda buffer already exists
  3519. (not org-agenda-multi)
  3520. ;; buffer found
  3521. (get-buffer org-agenda-buffer-name)
  3522. ;; C-u parameter is same as last call
  3523. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3524. (and
  3525. (equal current-prefix-arg
  3526. org-agenda-last-prefix-arg)
  3527. ;; In case user turned stickiness on, while having existing
  3528. ;; Agenda buffer active, don't reuse that buffer, because it
  3529. ;; does not have org variables local
  3530. org-agenda-this-buffer-is-sticky))))
  3531. (defvar org-agenda-buffer-tmp-name nil)
  3532. (defun org-agenda--get-buffer-name (sticky-name)
  3533. (or org-agenda-buffer-tmp-name
  3534. (and org-agenda-doing-sticky-redo org-agenda-buffer-name)
  3535. sticky-name
  3536. "*Org Agenda*"))
  3537. (defun org-agenda-prepare-window (abuf filter-alist)
  3538. "Setup agenda buffer in the window.
  3539. ABUF is the buffer for the agenda window.
  3540. FILTER-ALIST is an alist of filters we need to apply when
  3541. `org-agenda-persistent-filter' is non-nil."
  3542. (let* ((awin (get-buffer-window abuf)) wconf)
  3543. (cond
  3544. ((equal (current-buffer) abuf) nil)
  3545. (awin (select-window awin))
  3546. ((not (setq wconf (current-window-configuration))))
  3547. ((eq org-agenda-window-setup 'current-window)
  3548. (pop-to-buffer-same-window abuf))
  3549. ((eq org-agenda-window-setup 'other-window)
  3550. (org-switch-to-buffer-other-window abuf))
  3551. ((eq org-agenda-window-setup 'other-frame)
  3552. (switch-to-buffer-other-frame abuf))
  3553. ((eq org-agenda-window-setup 'other-tab)
  3554. (if (fboundp 'switch-to-buffer-other-tab)
  3555. (switch-to-buffer-other-tab abuf)
  3556. (user-error "Your version of Emacs does not have tab bar support")))
  3557. ((eq org-agenda-window-setup 'only-window)
  3558. (delete-other-windows)
  3559. (pop-to-buffer-same-window abuf))
  3560. ((eq org-agenda-window-setup 'reorganize-frame)
  3561. (delete-other-windows)
  3562. (org-switch-to-buffer-other-window abuf)))
  3563. (setq org-agenda-tag-filter (cdr (assq 'tag filter-alist)))
  3564. (setq org-agenda-category-filter (cdr (assq 'cat filter-alist)))
  3565. (setq org-agenda-effort-filter (cdr (assq 'effort filter-alist)))
  3566. (setq org-agenda-regexp-filter (cdr (assq 're filter-alist)))
  3567. ;; Additional test in case agenda is invoked from within agenda
  3568. ;; buffer via elisp link.
  3569. (unless (equal (current-buffer) abuf)
  3570. (pop-to-buffer-same-window abuf))
  3571. (setq org-agenda-pre-window-conf
  3572. (or wconf org-agenda-pre-window-conf))))
  3573. (defun org-agenda-prepare (&optional name)
  3574. (let ((filter-alist (when org-agenda-persistent-filter
  3575. (with-current-buffer
  3576. (get-buffer-create org-agenda-buffer-name)
  3577. `((tag . ,org-agenda-tag-filter)
  3578. (re . ,org-agenda-regexp-filter)
  3579. (effort . ,org-agenda-effort-filter)
  3580. (cat . ,org-agenda-category-filter))))))
  3581. (if (org-agenda-use-sticky-p)
  3582. (progn
  3583. ;; Popup existing buffer
  3584. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3585. filter-alist)
  3586. (message "Sticky Agenda buffer, use `r' to refresh")
  3587. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3588. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3589. (setq org-todo-keywords-for-agenda nil)
  3590. (if org-agenda-multi
  3591. (progn
  3592. (setq buffer-read-only nil)
  3593. (goto-char (point-max))
  3594. (unless (or (bobp) org-agenda-compact-blocks
  3595. (not org-agenda-block-separator))
  3596. (insert "\n"
  3597. (if (stringp org-agenda-block-separator)
  3598. org-agenda-block-separator
  3599. (make-string (window-max-chars-per-line) org-agenda-block-separator))
  3600. "\n"))
  3601. (narrow-to-region (point) (point-max)))
  3602. (setq org-done-keywords-for-agenda nil)
  3603. ;; Setting any org variables that are in org-agenda-local-vars
  3604. ;; list need to be done after the prepare call
  3605. (org-agenda-prepare-window
  3606. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3607. (setq buffer-read-only nil)
  3608. (org-agenda-reset-markers)
  3609. (let ((inhibit-read-only t)) (erase-buffer))
  3610. (org-agenda-mode)
  3611. (setq org-agenda-buffer (current-buffer))
  3612. (setq org-agenda-contributing-files nil)
  3613. (setq org-agenda-columns-active nil)
  3614. (setq org-agenda-filters-preset
  3615. `((tag . ,org-agenda-tag-filter-preset)
  3616. (category . ,org-agenda-category-filter-preset)
  3617. (regexp . ,org-agenda-regexp-filter-preset)
  3618. (effort . ,org-agenda-effort-filter-preset)))
  3619. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3620. (setq org-todo-keywords-for-agenda
  3621. (org-uniquify org-todo-keywords-for-agenda))
  3622. (setq org-done-keywords-for-agenda
  3623. (org-uniquify org-done-keywords-for-agenda))
  3624. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3625. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3626. (and name (not org-agenda-name)
  3627. (setq-local org-agenda-name name)))
  3628. (setq buffer-read-only nil))))
  3629. (defvar org-overriding-columns-format)
  3630. (defvar org-local-columns-format)
  3631. (defun org-agenda-finalize ()
  3632. "Finishing touch for the agenda buffer.
  3633. This function is called just before displaying the agenda. If
  3634. you want to add your own functions to the finalization of the
  3635. agenda display, configure `org-agenda-finalize-hook'."
  3636. (unless org-agenda-multi
  3637. (let ((inhibit-read-only t))
  3638. (save-excursion
  3639. (goto-char (point-min))
  3640. (save-excursion
  3641. (while (org-activate-links (point-max))
  3642. (goto-char (match-end 0))))
  3643. (unless (eq org-agenda-remove-tags t)
  3644. (org-agenda-align-tags))
  3645. (unless org-agenda-with-colors
  3646. (remove-text-properties (point-min) (point-max) '(face nil)))
  3647. (when (bound-and-true-p org-overriding-columns-format)
  3648. (setq-local org-local-columns-format
  3649. org-overriding-columns-format))
  3650. (when org-agenda-view-columns-initially
  3651. (org-agenda-columns))
  3652. (when org-agenda-fontify-priorities
  3653. (org-agenda-fontify-priorities))
  3654. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3655. (org-agenda-dim-blocked-tasks))
  3656. (org-agenda-mark-clocking-task)
  3657. (when org-agenda-entry-text-mode
  3658. (org-agenda-entry-text-hide)
  3659. (org-agenda-entry-text-show))
  3660. (when (and (featurep 'org-habit)
  3661. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3662. (org-habit-insert-consistency-graphs))
  3663. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3664. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3665. (and (listp org-agenda-show-inherited-tags)
  3666. (memq org-agenda-type org-agenda-show-inherited-tags))
  3667. (and (eq org-agenda-show-inherited-tags t)
  3668. (or (eq org-agenda-use-tag-inheritance t)
  3669. (and (listp org-agenda-use-tag-inheritance)
  3670. (not (memq org-agenda-type
  3671. org-agenda-use-tag-inheritance))))))
  3672. (let (mrk)
  3673. (save-excursion
  3674. (goto-char (point-min))
  3675. (while (equal (forward-line) 0)
  3676. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3677. (put-text-property (line-beginning-position) (line-end-position)
  3678. 'tags
  3679. (org-with-point-at mrk
  3680. (org-get-tags))))))))
  3681. (setq org-agenda-represented-tags nil
  3682. org-agenda-represented-categories nil)
  3683. (when org-agenda-top-headline-filter
  3684. (org-agenda-filter-top-headline-apply
  3685. org-agenda-top-headline-filter))
  3686. (when org-agenda-tag-filter
  3687. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3688. (when (assoc-default 'tag org-agenda-filters-preset)
  3689. (org-agenda-filter-apply
  3690. (assoc-default 'tag org-agenda-filters-preset) 'tag t))
  3691. (when org-agenda-category-filter
  3692. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3693. (when (assoc-default 'category org-agenda-filters-preset)
  3694. (org-agenda-filter-apply
  3695. (assoc-default 'category org-agenda-filters-preset) 'category))
  3696. (when org-agenda-regexp-filter
  3697. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3698. (when (assoc-default 'regexp org-agenda-filters-preset)
  3699. (org-agenda-filter-apply
  3700. (assoc-default 'regexp org-agenda-filters-preset) 'regexp))
  3701. (when org-agenda-effort-filter
  3702. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3703. (when (assoc-default 'effort org-agenda-filters-preset)
  3704. (org-agenda-filter-apply
  3705. (assoc-default 'effort org-agenda-filters-preset) 'effort))
  3706. (add-hook 'kill-buffer-hook #'org-agenda-reset-markers 'append 'local))
  3707. (run-hooks 'org-agenda-finalize-hook))))
  3708. (defun org-agenda-mark-clocking-task ()
  3709. "Mark the current clock entry in the agenda if it is present."
  3710. ;; We need to widen when `org-agenda-finalize' is called from
  3711. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in').
  3712. (when (bound-and-true-p org-clock-current-task)
  3713. (save-restriction
  3714. (widen)
  3715. (org-agenda-unmark-clocking-task)
  3716. (when (marker-buffer org-clock-hd-marker)
  3717. (save-excursion
  3718. (goto-char (point-min))
  3719. (let (s ov)
  3720. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3721. (goto-char s)
  3722. (when (equal (org-get-at-bol 'org-hd-marker)
  3723. org-clock-hd-marker)
  3724. (setq ov (make-overlay (line-beginning-position)
  3725. (1+ (line-end-position))))
  3726. (overlay-put ov 'type 'org-agenda-clocking)
  3727. (overlay-put ov 'face 'org-agenda-clocking)
  3728. (overlay-put ov 'help-echo
  3729. "The clock is running in this item")))))))))
  3730. (defun org-agenda-unmark-clocking-task ()
  3731. "Unmark the current clocking task."
  3732. (mapc (lambda (o)
  3733. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  3734. (delete-overlay o)))
  3735. (overlays-in (point-min) (point-max))))
  3736. (defun org-agenda-fontify-priorities ()
  3737. "Make highest priority lines bold, and lowest italic."
  3738. (interactive)
  3739. (mapc (lambda (o) (when (eq (overlay-get o 'org-type) 'org-priority)
  3740. (delete-overlay o)))
  3741. (overlays-in (point-min) (point-max)))
  3742. (save-excursion
  3743. (let (b e p ov h l)
  3744. (goto-char (point-min))
  3745. (while (re-search-forward org-priority-regexp nil t)
  3746. (setq h (or (get-char-property (point) 'org-priority-highest)
  3747. org-priority-highest)
  3748. l (or (get-char-property (point) 'org-priority-lowest)
  3749. org-priority-lowest)
  3750. p (string-to-char (match-string 2))
  3751. b (match-beginning 1)
  3752. e (if (eq org-agenda-fontify-priorities 'cookies)
  3753. (1+ (match-end 2))
  3754. (line-end-position))
  3755. ov (make-overlay b e))
  3756. (overlay-put
  3757. ov 'face
  3758. (let ((special-face
  3759. (cond ((org-face-from-face-or-color
  3760. 'priority 'org-priority
  3761. (cdr (assoc p org-priority-faces))))
  3762. ((and (listp org-agenda-fontify-priorities)
  3763. (org-face-from-face-or-color
  3764. 'priority 'org-priority
  3765. (cdr (assoc p org-agenda-fontify-priorities)))))
  3766. ((equal p l) 'italic)
  3767. ((equal p h) 'bold))))
  3768. (if special-face (list special-face 'org-priority) 'org-priority)))
  3769. (overlay-put ov 'org-type 'org-priority)))))
  3770. (defvar org-depend-tag-blocked)
  3771. (defun org-agenda-dim-blocked-tasks (&optional _invisible)
  3772. "Dim currently blocked TODOs in the agenda display.
  3773. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3774. dimming them." ;FIXME: The arg isn't used, actually!
  3775. (interactive "P")
  3776. (when (called-interactively-p 'interactive)
  3777. (message "Dim or hide blocked tasks..."))
  3778. (dolist (o (overlays-in (point-min) (point-max)))
  3779. (when (eq (overlay-get o 'face) 'org-agenda-dimmed-todo-face)
  3780. (delete-overlay o)))
  3781. (save-excursion
  3782. (let ((inhibit-read-only t))
  3783. (goto-char (point-min))
  3784. (while (let ((pos (text-property-not-all
  3785. (point) (point-max) 'org-todo-blocked nil)))
  3786. (when pos (goto-char pos)))
  3787. (let* ((invisible
  3788. (eq (org-get-at-bol 'org-todo-blocked) 'invisible))
  3789. (todo-blocked
  3790. (eq (org-get-at-bol 'org-filter-type) 'todo-blocked))
  3791. (ov (make-overlay (if invisible
  3792. (line-end-position 0)
  3793. (line-beginning-position))
  3794. (line-end-position))))
  3795. (when todo-blocked
  3796. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3797. (when invisible
  3798. (org-agenda-filter-hide-line 'todo-blocked)))
  3799. (if (= (point-max) (line-end-position))
  3800. (goto-char (point-max))
  3801. (move-beginning-of-line 2)))))
  3802. (when (called-interactively-p 'interactive)
  3803. (message "Dim or hide blocked tasks...done")))
  3804. (defun org-agenda--mark-blocked-entry (entry)
  3805. "If ENTRY is blocked, mark it for fontification or invisibility.
  3806. If the header at `org-hd-marker' is blocked according to
  3807. `org-entry-blocked-p', then if `org-agenda-dim-blocked-tasks' is
  3808. `invisible' and the header is not blocked by checkboxes, set the
  3809. text property `org-todo-blocked' to `invisible', otherwise set it
  3810. to t."
  3811. (when (get-text-property 0 'todo-state entry)
  3812. (let ((entry-marker (get-text-property 0 'org-hd-marker entry))
  3813. (org-blocked-by-checkboxes nil)
  3814. ;; Necessary so that `org-entry-blocked-p' does not change
  3815. ;; the buffer.
  3816. (org-depend-tag-blocked nil))
  3817. (when entry-marker
  3818. (let ((blocked
  3819. (with-current-buffer (marker-buffer entry-marker)
  3820. (save-excursion
  3821. (goto-char entry-marker)
  3822. (org-entry-blocked-p)))))
  3823. (when blocked
  3824. (let ((really-invisible
  3825. (and (not org-blocked-by-checkboxes)
  3826. (eq org-agenda-dim-blocked-tasks 'invisible))))
  3827. (put-text-property
  3828. 0 (length entry) 'org-todo-blocked
  3829. (if really-invisible 'invisible t)
  3830. entry)
  3831. (put-text-property
  3832. 0 (length entry) 'org-filter-type 'todo-blocked entry)))))))
  3833. entry)
  3834. (defvar org-agenda-skip-function nil
  3835. "Function to be called at each match during agenda construction.
  3836. If this function returns nil, the current match should not be skipped.
  3837. Otherwise, the function must return a position from where the search
  3838. should be continued.
  3839. This may also be a Lisp form that will be evaluated. Useful
  3840. forms include `org-agenda-skip-entry-if' and
  3841. `org-agenda-skip-subtree-if'. See the Info node `(org) Special
  3842. Agenda Views' for more details and examples.
  3843. Never set this variable using `setq' or similar, because then it
  3844. will apply to all future agenda commands. If you want a global
  3845. skipping condition, use the option `org-agenda-skip-function-global'
  3846. instead.
  3847. The correct way to use `org-agenda-skip-function' is to bind it with `let'
  3848. to scope it dynamically into the agenda-constructing command.
  3849. A good way to set it is through options in `org-agenda-custom-commands'.")
  3850. (defun org-agenda-skip (&optional element)
  3851. "Throw to `:skip' in places that should be skipped.
  3852. Also moves point to the end of the skipped region, so that search can
  3853. continue from there.
  3854. Optional argument ELEMENT contains element at point."
  3855. (when (or
  3856. (if element
  3857. (eq (org-element-type element) 'comment)
  3858. (save-excursion
  3859. (goto-char (line-beginning-position))
  3860. (looking-at comment-start-skip)))
  3861. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3862. (or (and (save-match-data (org-in-archived-heading-p nil element))
  3863. (org-end-of-subtree t element))
  3864. (and (member org-archive-tag org-file-tags)
  3865. (goto-char (point-max)))))
  3866. (and org-agenda-skip-comment-trees
  3867. (org-in-commented-heading-p nil element)
  3868. (org-end-of-subtree t element))
  3869. (let ((to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3870. (org-agenda-skip-eval org-agenda-skip-function))))
  3871. (and to (goto-char to)))
  3872. (org-in-src-block-p t element))
  3873. (throw :skip t)))
  3874. (defun org-agenda-skip-eval (form)
  3875. "If FORM is a function or a list, call (or eval) it and return the result.
  3876. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3877. and match data are returned to the previous state no matter what these
  3878. functions do."
  3879. (let (fp)
  3880. (and form
  3881. (or (setq fp (functionp form))
  3882. (consp form))
  3883. (save-excursion
  3884. (save-match-data
  3885. (if fp
  3886. (funcall form)
  3887. (eval form t)))))))
  3888. (defvar org-agenda-markers nil
  3889. "List of all currently active markers created by `org-agenda'.")
  3890. (defvar org-agenda-last-marker-time (float-time)
  3891. "Creation time of the last agenda marker.")
  3892. (defun org-agenda-new-marker (&optional pos)
  3893. "Return a new agenda marker.
  3894. Marker is at point, or at POS if non-nil. Org mode keeps a list
  3895. of these markers and resets them when they are no longer in use."
  3896. (let ((m (copy-marker (or pos (point)) t)))
  3897. (setq org-agenda-last-marker-time (float-time))
  3898. (if org-agenda-buffer
  3899. (with-current-buffer org-agenda-buffer
  3900. (push m org-agenda-markers))
  3901. (push m org-agenda-markers))
  3902. m))
  3903. (defun org-agenda-reset-markers ()
  3904. "Reset markers created by `org-agenda'."
  3905. (while org-agenda-markers
  3906. (move-marker (pop org-agenda-markers) nil)))
  3907. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3908. "Save relative positions of markers in region.
  3909. This check for agenda markers in all agenda buffers currently active."
  3910. (dolist (buf (buffer-list))
  3911. (with-current-buffer buf
  3912. (when (eq major-mode 'org-agenda-mode)
  3913. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3914. org-agenda-markers)))))
  3915. ;;; Entry text mode
  3916. (defun org-agenda-entry-text-show-here ()
  3917. "Add some text from the entry as context to the current line."
  3918. (let (m txt o)
  3919. (setq m (org-get-at-bol 'org-hd-marker))
  3920. (unless (marker-buffer m)
  3921. (error "No marker points to an entry here"))
  3922. (setq txt (concat "\n" (org-no-properties
  3923. (org-agenda-get-some-entry-text
  3924. m org-agenda-entry-text-maxlines
  3925. org-agenda-entry-text-leaders))))
  3926. (when (string-match "\\S-" txt)
  3927. (setq o (make-overlay (line-beginning-position) (line-end-position)))
  3928. (overlay-put o 'evaporate t)
  3929. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3930. (overlay-put o 'after-string txt))))
  3931. (defun org-agenda-entry-text-show ()
  3932. "Add entry context for all agenda lines."
  3933. (interactive)
  3934. (save-excursion
  3935. (goto-char (point-max))
  3936. (beginning-of-line 1)
  3937. (while (not (bobp))
  3938. (when (org-get-at-bol 'org-hd-marker)
  3939. (org-agenda-entry-text-show-here))
  3940. (beginning-of-line 0))))
  3941. (defun org-agenda-entry-text-hide ()
  3942. "Remove any shown entry context."
  3943. (mapc (lambda (o)
  3944. (when (eq (overlay-get o 'org-overlay-type)
  3945. 'agenda-entry-content)
  3946. (delete-overlay o)))
  3947. (overlays-in (point-min) (point-max))))
  3948. (defun org-agenda-get-day-face (date)
  3949. "Return the face DATE should be displayed with."
  3950. (cond ((and (functionp org-agenda-day-face-function)
  3951. (funcall org-agenda-day-face-function date)))
  3952. ((and (org-agenda-today-p date)
  3953. (memq (calendar-day-of-week date) org-agenda-weekend-days))
  3954. 'org-agenda-date-weekend-today)
  3955. ((org-agenda-today-p date) 'org-agenda-date-today)
  3956. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3957. 'org-agenda-date-weekend)
  3958. (t 'org-agenda-date)))
  3959. (defvar org-agenda-show-log-scoped)
  3960. ;;; Agenda Daily/Weekly
  3961. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3962. "Start day for the agenda view.
  3963. Custom commands can set this variable in the options section.
  3964. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3965. input allowed when reading a date through the Org calendar.
  3966. See the docstring of `org-read-date' for details.")
  3967. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3968. (defvar org-arg-loc nil) ; local variable
  3969. ;;;###autoload
  3970. (defun org-agenda-list (&optional arg start-day span with-hour)
  3971. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3972. The view will be for the current day or week, but from the overview buffer
  3973. you will be able to go to other days/weeks.
  3974. With a numeric prefix argument in an interactive call, the agenda will
  3975. span ARG days. Lisp programs should instead specify SPAN to change
  3976. the number of days. SPAN defaults to `org-agenda-span'.
  3977. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3978. given in `org-agenda-start-on-weekday'.
  3979. When WITH-HOUR is non-nil, only include scheduled and deadline
  3980. items if they have an hour specification like [h]h:mm."
  3981. (interactive "P")
  3982. (when org-agenda-overriding-arguments
  3983. (setq arg (car org-agenda-overriding-arguments)
  3984. start-day (nth 1 org-agenda-overriding-arguments)
  3985. span (nth 2 org-agenda-overriding-arguments)))
  3986. (when (and (integerp arg) (> arg 0))
  3987. (setq span arg arg nil))
  3988. (when (numberp span)
  3989. (unless (< 0 span)
  3990. (user-error "Agenda creation impossible for this span(=%d days)" span)))
  3991. (catch 'exit
  3992. (setq org-agenda-buffer-name
  3993. (org-agenda--get-buffer-name
  3994. (and org-agenda-sticky
  3995. (cond ((and org-keys (stringp org-match))
  3996. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3997. (org-keys
  3998. (format "*Org Agenda(%s)*" org-keys))
  3999. (t "*Org Agenda(a)*")))))
  4000. (org-agenda-prepare "Day/Week")
  4001. (setq start-day (or start-day org-agenda-start-day))
  4002. (when (stringp start-day)
  4003. ;; Convert to an absolute day number
  4004. (setq start-day (time-to-days (org-read-date nil t start-day))))
  4005. (org-compile-prefix-format 'agenda)
  4006. (org-set-sorting-strategy 'agenda)
  4007. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
  4008. (today (org-today))
  4009. (sd (or start-day today))
  4010. (ndays (org-agenda-span-to-ndays span sd))
  4011. (org-agenda-start-on-weekday
  4012. (and (or (eq ndays 7) (eq ndays 14))
  4013. org-agenda-start-on-weekday))
  4014. (thefiles (org-agenda-files nil 'ifmode))
  4015. (files thefiles)
  4016. (start (if (or (null org-agenda-start-on-weekday)
  4017. (< ndays 7))
  4018. sd
  4019. (let* ((nt (calendar-day-of-week
  4020. (calendar-gregorian-from-absolute sd)))
  4021. (n1 org-agenda-start-on-weekday)
  4022. (d (- nt n1)))
  4023. (- sd (+ (if (< d 0) 7 0) d)))))
  4024. (day-numbers (list start))
  4025. (day-cnt 0)
  4026. ;; FIXME: This may cause confusion when users are trying to
  4027. ;; debug agenda. The debugger will not trigger without
  4028. ;; redisplay.
  4029. (inhibit-redisplay (not debug-on-error))
  4030. (org-agenda-show-log-scoped org-agenda-show-log)
  4031. s rtn rtnall file date d start-pos end-pos todayp ;; e
  4032. clocktable-start clocktable-end) ;; filter
  4033. (setq org-agenda-redo-command
  4034. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  4035. (dotimes (_ (1- ndays))
  4036. (push (1+ (car day-numbers)) day-numbers))
  4037. (setq day-numbers (nreverse day-numbers))
  4038. (setq clocktable-start (car day-numbers)
  4039. clocktable-end (1+ (or (org-last day-numbers) 0)))
  4040. (setq-local org-starting-day (car day-numbers))
  4041. (setq-local org-arg-loc arg)
  4042. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  4043. (unless org-agenda-compact-blocks
  4044. (let* ((d1 (car day-numbers))
  4045. (d2 (org-last day-numbers))
  4046. (w1 (org-days-to-iso-week d1))
  4047. (w2 (org-days-to-iso-week d2)))
  4048. (setq s (point))
  4049. (org-agenda--insert-overriding-header
  4050. (concat (org-agenda-span-name span)
  4051. "-agenda"
  4052. (cond ((<= 350 (- d2 d1)) "")
  4053. ((= w1 w2) (format " (W%02d)" w1))
  4054. (t (format " (W%02d-W%02d)" w1 w2)))
  4055. ":\n")))
  4056. ;; Add properties if we actually inserted a header.
  4057. (when (> (point) s)
  4058. (add-text-properties s (1- (point))
  4059. (list 'face 'org-agenda-structure
  4060. 'org-date-line t))
  4061. (org-agenda-mark-header-line s)))
  4062. (while (setq d (pop day-numbers))
  4063. (setq date (calendar-gregorian-from-absolute d)
  4064. s (point))
  4065. (if (or (setq todayp (= d today))
  4066. (and (not start-pos) (= d sd)))
  4067. (setq start-pos (point))
  4068. (when (and start-pos (not end-pos))
  4069. (setq end-pos (point))))
  4070. (setq files thefiles
  4071. rtnall nil)
  4072. (while (setq file (pop files))
  4073. (catch 'nextfile
  4074. (org-check-agenda-file file)
  4075. (let ((org-agenda-entry-types org-agenda-entry-types))
  4076. ;; Starred types override non-starred equivalents
  4077. (when (member :deadline* org-agenda-entry-types)
  4078. (setq org-agenda-entry-types
  4079. (delq :deadline org-agenda-entry-types)))
  4080. (when (member :scheduled* org-agenda-entry-types)
  4081. (setq org-agenda-entry-types
  4082. (delq :scheduled org-agenda-entry-types)))
  4083. ;; Honor with-hour
  4084. (when with-hour
  4085. (when (member :deadline org-agenda-entry-types)
  4086. (setq org-agenda-entry-types
  4087. (delq :deadline org-agenda-entry-types))
  4088. (push :deadline* org-agenda-entry-types))
  4089. (when (member :scheduled org-agenda-entry-types)
  4090. (setq org-agenda-entry-types
  4091. (delq :scheduled org-agenda-entry-types))
  4092. (push :scheduled* org-agenda-entry-types)))
  4093. (unless org-agenda-include-deadlines
  4094. (setq org-agenda-entry-types
  4095. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  4096. (cond
  4097. ((memq org-agenda-show-log-scoped '(only clockcheck))
  4098. (setq rtn (org-agenda-get-day-entries
  4099. file date :closed)))
  4100. (org-agenda-show-log-scoped
  4101. (setq rtn (apply #'org-agenda-get-day-entries
  4102. file date
  4103. (append '(:closed) org-agenda-entry-types))))
  4104. (t
  4105. (setq rtn (apply #'org-agenda-get-day-entries
  4106. file date
  4107. org-agenda-entry-types)))))
  4108. (setq rtnall (append rtnall rtn)))) ;; all entries
  4109. (when org-agenda-include-diary
  4110. (let ((org-agenda-search-headline-for-time t))
  4111. (require 'diary-lib)
  4112. (setq rtn (org-get-entries-from-diary date))
  4113. (setq rtnall (append rtnall rtn))))
  4114. (when (or rtnall org-agenda-show-all-dates)
  4115. (setq day-cnt (1+ day-cnt))
  4116. (insert
  4117. (if (stringp org-agenda-format-date)
  4118. (format-time-string org-agenda-format-date
  4119. (org-time-from-absolute date))
  4120. (funcall org-agenda-format-date date))
  4121. "\n")
  4122. (put-text-property s (1- (point)) 'face
  4123. (org-agenda-get-day-face date))
  4124. (put-text-property s (1- (point)) 'org-date-line t)
  4125. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  4126. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  4127. (when todayp
  4128. (put-text-property s (1- (point)) 'org-today t))
  4129. (setq rtnall
  4130. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  4131. (when rtnall (insert ;; all entries
  4132. (org-agenda-finalize-entries rtnall 'agenda)
  4133. "\n"))
  4134. (put-text-property s (1- (point)) 'day d)
  4135. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)))
  4136. (when (and org-agenda-clockreport-mode clocktable-start)
  4137. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  4138. ;; the above line is to ensure the restricted range!
  4139. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  4140. tbl)
  4141. (setq p (org-plist-delete p :block))
  4142. (setq p (plist-put p :tstart clocktable-start))
  4143. (setq p (plist-put p :tend clocktable-end))
  4144. (setq p (plist-put p :scope 'agenda))
  4145. (setq tbl (apply #'org-clock-get-clocktable p))
  4146. (when org-agenda-clock-report-header
  4147. (insert (propertize org-agenda-clock-report-header 'face 'org-agenda-structure))
  4148. (unless (string-suffix-p "\n" org-agenda-clock-report-header)
  4149. (insert "\n")))
  4150. (insert tbl)))
  4151. (goto-char (point-min))
  4152. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4153. (unless (or (not (get-buffer-window org-agenda-buffer-name))
  4154. (and (pos-visible-in-window-p (point-min))
  4155. (pos-visible-in-window-p (point-max))))
  4156. (goto-char (1- (point-max)))
  4157. (recenter -1)
  4158. (when (not (pos-visible-in-window-p (or start-pos 1)))
  4159. (goto-char (or start-pos 1))
  4160. (recenter 1)))
  4161. (goto-char (or start-pos 1))
  4162. (add-text-properties (point-min) (point-max)
  4163. `(org-agenda-type agenda
  4164. org-last-args (,arg ,start-day ,span)
  4165. org-redo-cmd ,org-agenda-redo-command
  4166. org-series-cmd ,org-cmd))
  4167. (when (eq org-agenda-show-log-scoped 'clockcheck)
  4168. (org-agenda-show-clocking-issues))
  4169. (org-agenda-finalize)
  4170. (setq buffer-read-only t)
  4171. (message ""))))
  4172. (defun org-agenda-ndays-to-span (n)
  4173. "Return a span symbol for a span of N days, or N if none matches."
  4174. (cond ((symbolp n) n)
  4175. ((= n 1) 'day)
  4176. ((= n 7) 'week)
  4177. ((= n 14) 'fortnight)
  4178. (t n)))
  4179. (defun org-agenda-span-to-ndays (span &optional start-day)
  4180. "Return ndays from SPAN, possibly starting at START-DAY.
  4181. START-DAY is an absolute time value."
  4182. (cond ((numberp span) span)
  4183. ((eq span 'day) 1)
  4184. ((eq span 'week) 7)
  4185. ((eq span 'fortnight) 14)
  4186. ((eq span 'month)
  4187. (let ((date (calendar-gregorian-from-absolute start-day)))
  4188. (calendar-last-day-of-month (car date) (cl-caddr date))))
  4189. ((eq span 'year)
  4190. (let ((date (calendar-gregorian-from-absolute start-day)))
  4191. (if (calendar-leap-year-p (cl-caddr date)) 366 365)))))
  4192. (defun org-agenda-span-name (span)
  4193. "Return a SPAN name."
  4194. (if (null span)
  4195. ""
  4196. (if (symbolp span)
  4197. (capitalize (symbol-name span))
  4198. (format "%d days" span))))
  4199. ;;; Agenda word search
  4200. (defvar org-agenda-search-history nil)
  4201. (defvar org-search-syntax-table nil
  4202. "Special syntax table for Org search.
  4203. In this table, we have single quotes not as word constituents, to
  4204. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4205. (defvar org-mode-syntax-table) ; From org.el
  4206. (defun org-search-syntax-table ()
  4207. (unless org-search-syntax-table
  4208. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4209. (modify-syntax-entry ?' "." org-search-syntax-table)
  4210. (modify-syntax-entry ?` "." org-search-syntax-table))
  4211. org-search-syntax-table)
  4212. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4213. ;;;###autoload
  4214. (defun org-search-view (&optional todo-only string edit-at)
  4215. "Show all entries that contain a phrase or words or regular expressions.
  4216. With optional prefix argument TODO-ONLY, only consider entries that are
  4217. TODO entries. The argument STRING can be used to pass a default search
  4218. string into this function. If EDIT-AT is non-nil, it means that the
  4219. user should get a chance to edit this string, with cursor at position
  4220. EDIT-AT.
  4221. The search string can be viewed either as a phrase that should be found as
  4222. is, or it can be broken into a number of snippets, each of which must match
  4223. in a Boolean way to select an entry. The default depends on the variable
  4224. `org-agenda-search-view-always-boolean'.
  4225. Even if this is turned off (the default) you can always switch to
  4226. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4227. The default is a direct search of the whole phrase, where each space in
  4228. the search string can expand to an arbitrary amount of whitespace,
  4229. including newlines.
  4230. If using a Boolean search, the search string is split on whitespace and
  4231. each snippet is searched separately, with logical AND to select an entry.
  4232. Words prefixed with a minus must *not* occur in the entry. Words without
  4233. a prefix or prefixed with a plus must occur in the entry. Matching is
  4234. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4235. match whole words, not parts of a word) if
  4236. `org-agenda-search-view-force-full-words' is set (default is nil).
  4237. Boolean search snippets enclosed by curly braces are interpreted as
  4238. regular expressions that must or (when preceded with \"-\") must not
  4239. match in the entry. Snippets enclosed into double quotes will be taken
  4240. as a whole, to include whitespace.
  4241. - If the search string starts with an asterisk, search only in headlines.
  4242. - If (possibly after the leading star) the search string starts with an
  4243. exclamation mark, this also means to look at TODO entries only, an effect
  4244. that can also be achieved with a prefix argument.
  4245. - If (possibly after star and exclamation mark) the search string starts
  4246. with a colon, this will mean that the (non-regexp) snippets of the
  4247. Boolean search must match as full words.
  4248. This command searches the agenda files, and in addition the files
  4249. listed in `org-agenda-text-search-extra-files' unless a restriction lock
  4250. is active."
  4251. (interactive "P")
  4252. (when org-agenda-overriding-arguments
  4253. (setq todo-only (car org-agenda-overriding-arguments)
  4254. string (nth 1 org-agenda-overriding-arguments)
  4255. edit-at (nth 2 org-agenda-overriding-arguments)))
  4256. (let* ((props (list 'face nil
  4257. 'done-face 'org-agenda-done
  4258. 'org-not-done-regexp org-not-done-regexp
  4259. 'org-todo-regexp org-todo-regexp
  4260. 'org-complex-heading-regexp org-complex-heading-regexp
  4261. 'mouse-face 'highlight
  4262. 'help-echo "mouse-2 or RET jump to location"))
  4263. (full-words org-agenda-search-view-force-full-words)
  4264. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4265. regexp rtn rtnall files file pos inherited-tags
  4266. marker category level tags c neg re boolean
  4267. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4268. (unless (and (not edit-at)
  4269. (stringp string)
  4270. (string-match "\\S-" string))
  4271. (setq string (read-string
  4272. (if org-agenda-search-view-always-boolean
  4273. "[+-]Word/{Regexp} ...: "
  4274. "Phrase or [+-]Word/{Regexp} ...: ")
  4275. (cond
  4276. ((integerp edit-at) (cons string edit-at))
  4277. (edit-at string))
  4278. 'org-agenda-search-history)))
  4279. (catch 'exit
  4280. (setq org-agenda-buffer-name
  4281. (org-agenda--get-buffer-name
  4282. (and org-agenda-sticky
  4283. (if (stringp string)
  4284. (format "*Org Agenda(%s:%s)*"
  4285. (or org-keys (or (and todo-only "S") "s"))
  4286. string)
  4287. (format "*Org Agenda(%s)*"
  4288. (or (and todo-only "S") "s"))))))
  4289. (org-agenda-prepare "SEARCH")
  4290. (org-compile-prefix-format 'search)
  4291. (org-set-sorting-strategy 'search)
  4292. (setq org-agenda-redo-command
  4293. (list 'org-search-view (if todo-only t nil)
  4294. (list 'if 'current-prefix-arg nil string)))
  4295. (setq org-agenda-query-string string)
  4296. (if (equal (string-to-char string) ?*)
  4297. (setq hdl-only t
  4298. words (substring string 1))
  4299. (setq words string))
  4300. (when (equal (string-to-char words) ?!)
  4301. (setq todo-only t
  4302. words (substring words 1)))
  4303. (when (equal (string-to-char words) ?:)
  4304. (setq full-words t
  4305. words (substring words 1)))
  4306. (when (or org-agenda-search-view-always-boolean
  4307. (member (string-to-char words) '(?- ?+ ?\{)))
  4308. (setq boolean t))
  4309. (setq words (split-string words))
  4310. (let (www w)
  4311. (while (setq w (pop words))
  4312. (while (and (string-match "\\\\\\'" w) words)
  4313. (setq w (concat (substring w 0 -1) " " (pop words))))
  4314. (push w www))
  4315. (setq words (nreverse www) www nil)
  4316. (while (setq w (pop words))
  4317. (when (and (string-match "\\`[-+]?{" w)
  4318. (not (string-match "}\\'" w)))
  4319. (while (and words (not (string-match "}\\'" (car words))))
  4320. (setq w (concat w " " (pop words))))
  4321. (setq w (concat w " " (pop words))))
  4322. (push w www))
  4323. (setq words (nreverse www)))
  4324. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4325. (when boolean
  4326. (let (wds w)
  4327. (while (setq w (pop words))
  4328. (when (or (equal (substring w 0 1) "\"")
  4329. (and (> (length w) 1)
  4330. (member (substring w 0 1) '("+" "-"))
  4331. (equal (substring w 1 2) "\"")))
  4332. (while (and words (not (equal (substring w -1) "\"")))
  4333. (setq w (concat w " " (pop words)))))
  4334. (and (string-match "\\`\\([-+]?\\)\"" w)
  4335. (setq w (replace-match "\\1" nil nil w)))
  4336. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4337. (push w wds))
  4338. (setq words (nreverse wds))))
  4339. (if boolean
  4340. (mapc (lambda (w)
  4341. (setq c (string-to-char w))
  4342. (if (equal c ?-)
  4343. (setq neg t w (substring w 1))
  4344. (if (equal c ?+)
  4345. (setq neg nil w (substring w 1))
  4346. (setq neg nil)))
  4347. (if (string-match "\\`{.*}\\'" w)
  4348. (setq re (substring w 1 -1))
  4349. (if full-words
  4350. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4351. (setq re (regexp-quote (downcase w)))))
  4352. (if neg (push re regexps-) (push re regexps+)))
  4353. words)
  4354. (push (mapconcat #'regexp-quote words "\\s-+")
  4355. regexps+))
  4356. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4357. (if (not regexps+)
  4358. (setq regexp org-outline-regexp-bol)
  4359. (setq regexp (pop regexps+))
  4360. (when hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4361. regexp))))
  4362. (setq files (org-agenda-files nil 'ifmode))
  4363. ;; Add `org-agenda-text-search-extra-files' unless there is some
  4364. ;; restriction.
  4365. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4366. (pop org-agenda-text-search-extra-files)
  4367. (unless (get 'org-agenda-files 'org-restrict)
  4368. (setq files (org-add-archive-files files))))
  4369. ;; Uniquify files. However, let `org-check-agenda-file' handle
  4370. ;; non-existent ones.
  4371. (setq files (cl-remove-duplicates
  4372. (append files org-agenda-text-search-extra-files)
  4373. :test (lambda (a b)
  4374. (and (file-exists-p a)
  4375. (file-exists-p b)
  4376. (file-equal-p a b))))
  4377. rtnall nil)
  4378. (while (setq file (pop files))
  4379. (setq ee nil)
  4380. (catch 'nextfile
  4381. (org-check-agenda-file file)
  4382. (setq buffer (if (file-exists-p file)
  4383. (org-get-agenda-file-buffer file)
  4384. (error "No such file %s" file)))
  4385. (unless buffer
  4386. ;; If file does not exist, make sure an error message is sent
  4387. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4388. file))))
  4389. (with-current-buffer buffer
  4390. (with-syntax-table (org-search-syntax-table)
  4391. (unless (derived-mode-p 'org-mode)
  4392. (error "Agenda file %s is not in Org mode" file))
  4393. (let ((case-fold-search t))
  4394. (save-excursion
  4395. (save-restriction
  4396. (if (eq buffer org-agenda-restrict)
  4397. (narrow-to-region org-agenda-restrict-begin
  4398. org-agenda-restrict-end)
  4399. (widen))
  4400. (goto-char (point-min))
  4401. (unless (or (org-at-heading-p)
  4402. (outline-next-heading))
  4403. (throw 'nextfile t))
  4404. (goto-char (max (point-min) (1- (point))))
  4405. (while (re-search-forward regexp nil t)
  4406. (org-back-to-heading t)
  4407. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4408. (> (org-reduced-level (org-outline-level))
  4409. org-agenda-search-view-max-outline-level)
  4410. (forward-line -1)
  4411. (org-back-to-heading t)))
  4412. (skip-chars-forward "* ")
  4413. (setq beg (line-beginning-position)
  4414. beg1 (point)
  4415. end (progn
  4416. (outline-next-heading)
  4417. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4418. (> (org-reduced-level (org-outline-level))
  4419. org-agenda-search-view-max-outline-level)
  4420. (forward-line 1)
  4421. (outline-next-heading)))
  4422. (point)))
  4423. (catch :skip
  4424. (goto-char beg)
  4425. (org-agenda-skip)
  4426. (setq str (buffer-substring-no-properties
  4427. (line-beginning-position)
  4428. (if hdl-only (line-end-position) end)))
  4429. (mapc (lambda (wr) (when (string-match wr str)
  4430. (goto-char (1- end))
  4431. (throw :skip t)))
  4432. regexps-)
  4433. (mapc (lambda (wr) (unless (string-match wr str)
  4434. (goto-char (1- end))
  4435. (throw :skip t)))
  4436. (if todo-only
  4437. (cons (concat "^\\*+[ \t]+"
  4438. org-not-done-regexp)
  4439. regexps+)
  4440. regexps+))
  4441. (goto-char beg)
  4442. (setq marker (org-agenda-new-marker (point))
  4443. category (org-get-category)
  4444. level (make-string (org-reduced-level (org-outline-level)) ? )
  4445. inherited-tags
  4446. (or (eq org-agenda-show-inherited-tags 'always)
  4447. (and (listp org-agenda-show-inherited-tags)
  4448. (memq 'todo org-agenda-show-inherited-tags))
  4449. (and (eq org-agenda-show-inherited-tags t)
  4450. (or (eq org-agenda-use-tag-inheritance t)
  4451. (memq 'todo org-agenda-use-tag-inheritance))))
  4452. tags (org-get-tags nil (not inherited-tags))
  4453. txt (org-agenda-format-item
  4454. ""
  4455. (buffer-substring-no-properties
  4456. beg1 (line-end-position))
  4457. level category tags t))
  4458. (org-add-props txt props
  4459. 'org-marker marker 'org-hd-marker marker
  4460. 'org-todo-regexp org-todo-regexp
  4461. 'level level
  4462. 'org-complex-heading-regexp org-complex-heading-regexp
  4463. 'priority 1000
  4464. 'type "search")
  4465. (push txt ee)
  4466. (goto-char (1- end))))))))))
  4467. (setq rtn (nreverse ee))
  4468. (setq rtnall (append rtnall rtn)))
  4469. (org-agenda--insert-overriding-header
  4470. (with-temp-buffer
  4471. (insert "Search words: ")
  4472. (add-text-properties (point-min) (1- (point))
  4473. (list 'face 'org-agenda-structure))
  4474. (setq pos (point))
  4475. (insert string "\n")
  4476. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4477. (setq pos (point))
  4478. (unless org-agenda-multi
  4479. (insert (substitute-command-keys "\\<org-agenda-mode-map>\
  4480. Press `\\[org-agenda-manipulate-query-add]', \
  4481. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4482. `\\[org-agenda-manipulate-query-add-re]', \
  4483. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4484. `\\[universal-argument] \\[org-agenda-redo]' for a fresh search\n"))
  4485. (add-text-properties pos (1- (point))
  4486. (list 'face 'org-agenda-structure-secondary)))
  4487. (buffer-string)))
  4488. (org-agenda-mark-header-line (point-min))
  4489. (when rtnall
  4490. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4491. (goto-char (point-min))
  4492. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4493. (add-text-properties (point-min) (point-max)
  4494. `(org-agenda-type search
  4495. org-last-args (,todo-only ,string ,edit-at)
  4496. org-redo-cmd ,org-agenda-redo-command
  4497. org-series-cmd ,org-cmd))
  4498. (org-agenda-finalize)
  4499. (setq buffer-read-only t))))
  4500. ;;; Agenda TODO list
  4501. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4502. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4503. (concat
  4504. (if (or (equal keywords "ALL") (not keywords))
  4505. (propertize "ALL" 'face 'org-agenda-structure-filter)
  4506. (mapconcat
  4507. (lambda (kw)
  4508. (propertize kw 'face (list (org-get-todo-face kw) 'org-agenda-structure)))
  4509. (org-split-string keywords "|")
  4510. "|"))
  4511. "\n"))
  4512. (defvar org-select-this-todo-keyword nil)
  4513. (defvar org-last-arg nil)
  4514. (defvar crm-separator)
  4515. ;;;###autoload
  4516. (defun org-todo-list (&optional arg)
  4517. "Show all (not done) TODO entries from all agenda files in a single list.
  4518. The prefix arg can be used to select a specific TODO keyword and limit
  4519. the list to these. When using `\\[universal-argument]', you will be prompted
  4520. for a keyword. A numeric prefix directly selects the Nth keyword in
  4521. `org-todo-keywords-1'."
  4522. (interactive "P")
  4523. (when org-agenda-overriding-arguments
  4524. (setq arg org-agenda-overriding-arguments))
  4525. (when (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4526. (let* ((today (org-today))
  4527. (date (calendar-gregorian-from-absolute today))
  4528. (completion-ignore-case t)
  4529. kwds org-select-this-todo-keyword rtn rtnall files file pos)
  4530. (catch 'exit
  4531. (setq org-agenda-buffer-name
  4532. (org-agenda--get-buffer-name
  4533. (and org-agenda-sticky
  4534. (if (stringp org-select-this-todo-keyword)
  4535. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4536. org-select-this-todo-keyword)
  4537. (format "*Org Agenda(%s)*" (or org-keys "t"))))))
  4538. (org-agenda-prepare "TODO")
  4539. (setq kwds org-todo-keywords-for-agenda
  4540. org-select-this-todo-keyword (if (stringp arg) arg
  4541. (and (integerp arg)
  4542. (> arg 0)
  4543. (nth (1- arg) kwds))))
  4544. (when (equal arg '(4))
  4545. (setq org-select-this-todo-keyword
  4546. (mapconcat #'identity
  4547. (let ((crm-separator "|"))
  4548. (completing-read-multiple
  4549. "Keyword (or KWD1|KWD2|...): "
  4550. (mapcar #'list kwds) nil nil))
  4551. "|")))
  4552. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4553. (org-compile-prefix-format 'todo)
  4554. (org-set-sorting-strategy 'todo)
  4555. (setq org-agenda-redo-command
  4556. `(org-todo-list (or (and (numberp current-prefix-arg)
  4557. current-prefix-arg)
  4558. ,org-select-this-todo-keyword
  4559. current-prefix-arg ,arg)))
  4560. (setq files (org-agenda-files nil 'ifmode)
  4561. rtnall nil)
  4562. (while (setq file (pop files))
  4563. (catch 'nextfile
  4564. (org-check-agenda-file file)
  4565. (setq rtn (org-agenda-get-day-entries file date :todo))
  4566. (setq rtnall (append rtnall rtn))))
  4567. (org-agenda--insert-overriding-header
  4568. (with-temp-buffer
  4569. (insert "Global list of TODO items of type: ")
  4570. (add-text-properties (point-min) (1- (point))
  4571. (list 'face 'org-agenda-structure
  4572. 'short-heading
  4573. (concat "ToDo: "
  4574. (or org-select-this-todo-keyword "ALL"))))
  4575. (org-agenda-mark-header-line (point-min))
  4576. (insert (org-agenda-propertize-selected-todo-keywords
  4577. org-select-this-todo-keyword))
  4578. (setq pos (point))
  4579. (unless org-agenda-multi
  4580. (insert (substitute-command-keys "Press \
  4581. \\<org-agenda-mode-map>`N \\[org-agenda-redo]' (e.g. `0 \\[org-agenda-redo]') \
  4582. to search again: (0)[ALL]"))
  4583. (let ((n 0))
  4584. (dolist (k kwds)
  4585. (let ((s (format "(%d)%s" (cl-incf n) k)))
  4586. (when (> (+ (current-column) (string-width s) 1) (window-max-chars-per-line))
  4587. (insert "\n "))
  4588. (insert " " s))))
  4589. (insert "\n"))
  4590. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-secondary))
  4591. (buffer-string)))
  4592. (org-agenda-mark-header-line (point-min))
  4593. (when rtnall
  4594. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4595. (goto-char (point-min))
  4596. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4597. (add-text-properties (point-min) (point-max)
  4598. `(org-agenda-type todo
  4599. org-last-args ,arg
  4600. org-redo-cmd ,org-agenda-redo-command
  4601. org-series-cmd ,org-cmd))
  4602. (org-agenda-finalize)
  4603. (setq buffer-read-only t))))
  4604. ;;; Agenda tags match
  4605. ;;;###autoload
  4606. (defun org-tags-view (&optional todo-only match)
  4607. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4608. The prefix arg TODO-ONLY limits the search to TODO entries."
  4609. (interactive "P")
  4610. (when org-agenda-overriding-arguments
  4611. (setq todo-only (car org-agenda-overriding-arguments)
  4612. match (nth 1 org-agenda-overriding-arguments)))
  4613. (let* ((org-tags-match-list-sublevels
  4614. org-tags-match-list-sublevels)
  4615. (completion-ignore-case t)
  4616. (org--matcher-tags-todo-only todo-only)
  4617. rtn rtnall files file pos matcher
  4618. buffer)
  4619. (when (and (stringp match) (not (string-match "\\S-" match)))
  4620. (setq match nil))
  4621. (catch 'exit
  4622. (setq org-agenda-buffer-name
  4623. (org-agenda--get-buffer-name
  4624. (and org-agenda-sticky
  4625. (if (stringp match)
  4626. (format "*Org Agenda(%s:%s)*"
  4627. (or org-keys (or (and todo-only "M") "m"))
  4628. match)
  4629. (format "*Org Agenda(%s)*"
  4630. (or (and todo-only "M") "m"))))))
  4631. (setq matcher (org-make-tags-matcher match))
  4632. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4633. ;; expanding tags within `org-make-tags-matcher'
  4634. (org-agenda-prepare (concat "TAGS " match))
  4635. (setq match (car matcher)
  4636. matcher (cdr matcher))
  4637. (org-compile-prefix-format 'tags)
  4638. (org-set-sorting-strategy 'tags)
  4639. (setq org-agenda-query-string match)
  4640. (setq org-agenda-redo-command
  4641. (list 'org-tags-view
  4642. `(quote ,org--matcher-tags-todo-only)
  4643. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4644. (setq files (org-agenda-files nil 'ifmode)
  4645. rtnall nil)
  4646. (while (setq file (pop files))
  4647. (catch 'nextfile
  4648. (org-check-agenda-file file)
  4649. (setq buffer (if (file-exists-p file)
  4650. (org-get-agenda-file-buffer file)
  4651. (error "No such file %s" file)))
  4652. (if (not buffer)
  4653. ;; If file does not exist, error message to agenda
  4654. (setq rtn (list
  4655. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4656. rtnall (append rtnall rtn))
  4657. (with-current-buffer buffer
  4658. (unless (derived-mode-p 'org-mode)
  4659. (error "Agenda file %s is not in Org mode" file))
  4660. (save-excursion
  4661. (save-restriction
  4662. (if (eq buffer org-agenda-restrict)
  4663. (narrow-to-region org-agenda-restrict-begin
  4664. org-agenda-restrict-end)
  4665. (widen))
  4666. (setq rtn (org-scan-tags 'agenda
  4667. matcher
  4668. org--matcher-tags-todo-only))
  4669. (setq rtnall (append rtnall rtn))))))))
  4670. (org-agenda--insert-overriding-header
  4671. (with-temp-buffer
  4672. (insert "Headlines with TAGS match: ")
  4673. (add-text-properties (point-min) (1- (point))
  4674. (list 'face 'org-agenda-structure
  4675. 'short-heading
  4676. (concat "Match: " match)))
  4677. (setq pos (point))
  4678. (insert match "\n")
  4679. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4680. (setq pos (point))
  4681. (unless org-agenda-multi
  4682. (insert (substitute-command-keys
  4683. "Press \
  4684. \\<org-agenda-mode-map>`\\[universal-argument] \\[org-agenda-redo]' \
  4685. to search again\n")))
  4686. (add-text-properties pos (1- (point))
  4687. (list 'face 'org-agenda-structure-secondary))
  4688. (buffer-string)))
  4689. (org-agenda-mark-header-line (point-min))
  4690. (when rtnall
  4691. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4692. (goto-char (point-min))
  4693. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4694. (add-text-properties
  4695. (point-min) (point-max)
  4696. `(org-agenda-type tags
  4697. org-last-args (,org--matcher-tags-todo-only ,match)
  4698. org-redo-cmd ,org-agenda-redo-command
  4699. org-series-cmd ,org-cmd))
  4700. (org-agenda-finalize)
  4701. (setq buffer-read-only t))))
  4702. ;;; Agenda Finding stuck projects
  4703. (defvar org-agenda-skip-regexp nil
  4704. "Regular expression used in skipping subtrees for the agenda.
  4705. This is basically a temporary global variable that can be set and then
  4706. used by user-defined selections using `org-agenda-skip-function'.")
  4707. (defvar org-agenda-overriding-header nil
  4708. "When set during agenda, todo and tags searches it replaces the header.
  4709. If an empty string, no header will be inserted. If any other
  4710. string, it will be inserted as a header. If a function, insert
  4711. the string returned by the function as a header. If nil, a
  4712. header will be generated automatically according to the command.
  4713. This variable should not be set directly, but custom commands can
  4714. bind it in the options section.")
  4715. (defun org-agenda-skip-entry-if (&rest conditions)
  4716. "Skip entry if any of CONDITIONS is true.
  4717. See `org-agenda-skip-if' for details about CONDITIONS.
  4718. This function can be put into `org-agenda-skip-function' for the
  4719. duration of a command."
  4720. (org-agenda-skip-if nil conditions))
  4721. (defun org-agenda-skip-subtree-if (&rest conditions)
  4722. "Skip subtree if any of CONDITIONS is true.
  4723. See `org-agenda-skip-if' for details about CONDITIONS.
  4724. This function can be put into `org-agenda-skip-function' for the
  4725. duration of a command."
  4726. (org-agenda-skip-if t conditions))
  4727. (defun org-agenda-skip-if (subtree conditions)
  4728. "Check current entity for CONDITIONS.
  4729. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4730. the entry (i.e. the text before the next heading) is checked.
  4731. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4732. from different tests. Valid conditions are:
  4733. scheduled Check if there is a scheduled cookie
  4734. notscheduled Check if there is no scheduled cookie
  4735. deadline Check if there is a deadline
  4736. notdeadline Check if there is no deadline
  4737. timestamp Check if there is a timestamp (also deadline or scheduled)
  4738. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4739. regexp Check if regexp matches
  4740. notregexp Check if regexp does not match.
  4741. todo Check if TODO keyword matches
  4742. nottodo Check if TODO keyword does not match
  4743. The regexp is taken from the conditions list, and must come right
  4744. after the `regexp' or `notregexp' element.
  4745. `todo' and `nottodo' accept as an argument a list of todo
  4746. keywords, which may include \"*\" to match any todo keyword.
  4747. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4748. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4749. Instead of a list, a keyword class may be given. For example:
  4750. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4751. would skip entries that haven't been marked with any of \"DONE\"
  4752. keywords. Possible classes are: `todo', `done', `any'.
  4753. If any of these conditions is met, this function returns the end point of
  4754. the entity, causing the search to continue from there. This is a function
  4755. that can be put into `org-agenda-skip-function' for the duration of a command."
  4756. (org-back-to-heading t)
  4757. (let* (;; (beg (point))
  4758. (end (if subtree (save-excursion (org-end-of-subtree t) (point))
  4759. (org-entry-end-position)))
  4760. (planning-end (if subtree end (line-end-position 2)))
  4761. m)
  4762. (and
  4763. (or (and (memq 'scheduled conditions)
  4764. (re-search-forward org-scheduled-time-regexp planning-end t))
  4765. (and (memq 'notscheduled conditions)
  4766. (not
  4767. (save-excursion
  4768. (re-search-forward org-scheduled-time-regexp planning-end t))))
  4769. (and (memq 'deadline conditions)
  4770. (re-search-forward org-deadline-time-regexp planning-end t))
  4771. (and (memq 'notdeadline conditions)
  4772. (not
  4773. (save-excursion
  4774. (re-search-forward org-deadline-time-regexp planning-end t))))
  4775. (and (memq 'timestamp conditions)
  4776. (re-search-forward org-ts-regexp end t))
  4777. (and (memq 'nottimestamp conditions)
  4778. (not (save-excursion (re-search-forward org-ts-regexp end t))))
  4779. (and (setq m (memq 'regexp conditions))
  4780. (stringp (nth 1 m))
  4781. (re-search-forward (nth 1 m) end t))
  4782. (and (setq m (memq 'notregexp conditions))
  4783. (stringp (nth 1 m))
  4784. (not (save-excursion (re-search-forward (nth 1 m) end t))))
  4785. (and (or
  4786. (setq m (memq 'nottodo conditions))
  4787. (setq m (memq 'todo-unblocked conditions))
  4788. (setq m (memq 'nottodo-unblocked conditions))
  4789. (setq m (memq 'todo conditions)))
  4790. (org-agenda-skip-if-todo m end)))
  4791. end)))
  4792. (defun org-agenda-skip-if-todo (args end)
  4793. "Helper function for `org-agenda-skip-if', do not use it directly.
  4794. ARGS is a list with first element either `todo', `nottodo',
  4795. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4796. a list of TODO keywords, or a state symbol `todo' or `done' or
  4797. `any'."
  4798. (let ((todo-re
  4799. (concat "^\\*+[ \t]+"
  4800. (regexp-opt
  4801. (pcase args
  4802. (`(,_ todo)
  4803. (org-delete-all org-done-keywords
  4804. (copy-sequence org-todo-keywords-1)))
  4805. (`(,_ done) org-done-keywords)
  4806. (`(,_ any) org-todo-keywords-1)
  4807. (`(,_ ,(pred atom))
  4808. (error "Invalid TODO class or type: %S" args))
  4809. (`(,_ ,(pred (member "*"))) org-todo-keywords-1)
  4810. (`(,_ ,todo-list) todo-list))
  4811. 'words))))
  4812. (pcase args
  4813. (`(todo . ,_)
  4814. (let (case-fold-search) (re-search-forward todo-re end t)))
  4815. (`(nottodo . ,_)
  4816. (not (let (case-fold-search) (re-search-forward todo-re end t))))
  4817. (`(todo-unblocked . ,_)
  4818. (catch :unblocked
  4819. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4820. (when (org-entry-blocked-p) (throw :unblocked t)))
  4821. nil))
  4822. (`(nottodo-unblocked . ,_)
  4823. (catch :unblocked
  4824. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4825. (when (org-entry-blocked-p) (throw :unblocked nil)))
  4826. t))
  4827. (`(,type . ,_) (error "Unknown TODO skip type: %S" type)))))
  4828. ;;;###autoload
  4829. (defun org-agenda-list-stuck-projects (&rest _ignore)
  4830. "Create agenda view for projects that are stuck.
  4831. Stuck projects are project that have no next actions. For the definitions
  4832. of what a project is and how to check if it stuck, customize the variable
  4833. `org-stuck-projects'."
  4834. (interactive)
  4835. (let* ((org-agenda-overriding-header
  4836. (or org-agenda-overriding-header "List of stuck projects: "))
  4837. (matcher (nth 0 org-stuck-projects))
  4838. (todo (nth 1 org-stuck-projects))
  4839. (tags (nth 2 org-stuck-projects))
  4840. (gen-re (org-string-nw-p (nth 3 org-stuck-projects)))
  4841. (todo-wds
  4842. (if (not (member "*" todo)) todo
  4843. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  4844. (org-delete-all org-done-keywords-for-agenda
  4845. (copy-sequence org-todo-keywords-for-agenda))))
  4846. (todo-re (and todo
  4847. (format "^\\*+[ \t]+\\(%s\\)\\>"
  4848. (mapconcat #'identity todo-wds "\\|"))))
  4849. (tags-re (cond ((null tags) nil)
  4850. ((member "*" tags) org-tag-line-re)
  4851. (tags
  4852. (let ((other-tags (format "\\(?:%s:\\)*" org-tag-re)))
  4853. (concat org-outline-regexp-bol
  4854. ".*?[ \t]:"
  4855. other-tags
  4856. (regexp-opt tags t)
  4857. ":" other-tags "[ \t]*$")))
  4858. (t nil)))
  4859. (re-list (delq nil (list todo-re tags-re gen-re)))
  4860. (skip-re
  4861. (if (null re-list)
  4862. (error "Missing information to identify unstuck projects")
  4863. (mapconcat #'identity re-list "\\|")))
  4864. (org-agenda-skip-function
  4865. ;; Skip entry if `org-agenda-skip-regexp' matches anywhere
  4866. ;; in the subtree.
  4867. (lambda ()
  4868. (and (save-excursion
  4869. (let ((case-fold-search nil))
  4870. (re-search-forward
  4871. skip-re (save-excursion (org-end-of-subtree t)) t)))
  4872. (progn (outline-next-heading) (point))))))
  4873. (org-tags-view nil matcher)
  4874. (setq org-agenda-buffer-name (buffer-name))
  4875. (with-current-buffer org-agenda-buffer-name
  4876. (setq org-agenda-redo-command
  4877. `(org-agenda-list-stuck-projects ,current-prefix-arg))
  4878. (let ((inhibit-read-only t))
  4879. (add-text-properties
  4880. (point-min) (point-max)
  4881. `(org-redo-cmd ,org-agenda-redo-command))))))
  4882. ;;; Diary integration
  4883. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4884. (defvar diary-list-entries-hook)
  4885. (defvar diary-time-regexp)
  4886. (defvar diary-modify-entry-list-string-function)
  4887. (defvar diary-file-name-prefix)
  4888. (defvar diary-display-function)
  4889. (defun org-get-entries-from-diary (date)
  4890. "Get the (Emacs Calendar) diary entries for DATE."
  4891. (require 'diary-lib)
  4892. (declare-function diary-fancy-display "diary-lib" ())
  4893. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4894. (diary-display-function #'diary-fancy-display)
  4895. (pop-up-frames nil)
  4896. (diary-list-entries-hook
  4897. (cons 'org-diary-default-entry diary-list-entries-hook))
  4898. (diary-file-name-prefix nil) ; turn this feature off
  4899. (diary-modify-entry-list-string-function
  4900. #'org-modify-diary-entry-string)
  4901. (diary-time-regexp (concat "^" diary-time-regexp))
  4902. entries
  4903. (org-disable-agenda-to-diary t))
  4904. (save-excursion
  4905. (save-window-excursion
  4906. (diary-list-entries date 1)))
  4907. (if (not (get-buffer diary-fancy-buffer))
  4908. (setq entries nil)
  4909. (with-current-buffer diary-fancy-buffer
  4910. (setq buffer-read-only nil)
  4911. (if (zerop (buffer-size))
  4912. ;; No entries
  4913. (setq entries nil)
  4914. ;; Omit the date and other unnecessary stuff
  4915. (org-agenda-cleanup-fancy-diary)
  4916. ;; Add prefix to each line and extend the text properties
  4917. (if (zerop (buffer-size))
  4918. (setq entries nil)
  4919. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4920. (setq entries
  4921. (with-temp-buffer
  4922. (insert entries) (goto-char (point-min))
  4923. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4924. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4925. (replace-match (concat "; " (match-string 1)))))
  4926. (buffer-string)))))
  4927. (set-buffer-modified-p nil)
  4928. (kill-buffer diary-fancy-buffer)))
  4929. (when entries
  4930. (setq entries (org-split-string entries "\n"))
  4931. (setq entries
  4932. (mapcar
  4933. (lambda (x)
  4934. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4935. ;; Extend the text properties to the beginning of the line
  4936. (org-add-props x (text-properties-at (1- (length x)) x)
  4937. 'type "diary" 'date date 'face 'org-agenda-diary))
  4938. entries)))))
  4939. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4940. "Hook run when the fancy diary buffer is cleaned up.")
  4941. (defun org-agenda-cleanup-fancy-diary ()
  4942. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4943. This gets rid of the date, the underline under the date, and the
  4944. dummy entry installed by Org mode to ensure non-empty diary for
  4945. each date. It also removes lines that contain only whitespace."
  4946. (goto-char (point-min))
  4947. (if (looking-at ".*?:[ \t]*")
  4948. (progn
  4949. (replace-match "")
  4950. (re-search-forward "\n=+$" nil t)
  4951. (replace-match "")
  4952. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4953. (re-search-forward "\n=+$" nil t)
  4954. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4955. (goto-char (point-min))
  4956. (while (re-search-forward "^ +\n" nil t)
  4957. (replace-match ""))
  4958. (goto-char (point-min))
  4959. (when (re-search-forward "^Org mode dummy\n?" nil t)
  4960. (replace-match ""))
  4961. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4962. (defun org-modify-diary-entry-string (string)
  4963. "Add text properties to string, allowing Org to act on it."
  4964. (org-add-props string nil
  4965. 'mouse-face 'highlight
  4966. 'help-echo (if buffer-file-name
  4967. (format "mouse-2 or RET jump to diary file %s"
  4968. (abbreviate-file-name buffer-file-name))
  4969. "")
  4970. 'org-agenda-diary-link t
  4971. 'org-marker (org-agenda-new-marker (line-beginning-position))))
  4972. (defun org-diary-default-entry ()
  4973. "Add a dummy entry to the diary.
  4974. Needed to avoid empty dates which mess up holiday display."
  4975. ;; Catch the error if dealing with the new add-to-diary-alist
  4976. (when org-disable-agenda-to-diary
  4977. (diary-add-to-list original-date "Org mode dummy" "")))
  4978. (defvar org-diary-last-run-time nil)
  4979. ;;;###autoload
  4980. (defun org-diary (&rest args)
  4981. "Return diary information from org files.
  4982. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4983. It accesses org files and extracts information from those files to be
  4984. listed in the diary. The function accepts arguments specifying what
  4985. items should be listed. For a list of arguments allowed here, see the
  4986. variable `org-agenda-entry-types'.
  4987. The call in the diary file should look like this:
  4988. &%%(org-diary) ~/path/to/some/orgfile.org
  4989. Use a separate line for each org file to check. Or, if you omit the file name,
  4990. all files listed in `org-agenda-files' will be checked automatically:
  4991. &%%(org-diary)
  4992. If you don't give any arguments (as in the example above), the default value
  4993. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4994. So the example above may also be written as
  4995. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4996. The function expects the lisp variables `entry' and `date' to be provided
  4997. by the caller, because this is how the calendar works. Don't use this
  4998. function from a program - use `org-agenda-get-day-entries' instead."
  4999. (with-no-warnings (defvar date) (defvar entry))
  5000. (when (> (- (float-time)
  5001. org-agenda-last-marker-time)
  5002. 5)
  5003. ;; I am not sure if this works with sticky agendas, because the marker
  5004. ;; list is then no longer a global variable.
  5005. (org-agenda-reset-markers))
  5006. (org-compile-prefix-format 'agenda)
  5007. (org-set-sorting-strategy 'agenda)
  5008. (setq args (or args org-agenda-entry-types))
  5009. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  5010. (list entry)
  5011. (org-agenda-files t)))
  5012. (time (float-time))
  5013. file rtn results)
  5014. (when (or (not org-diary-last-run-time)
  5015. (> (- time
  5016. org-diary-last-run-time)
  5017. 3))
  5018. (org-agenda-prepare-buffers files))
  5019. (setq org-diary-last-run-time time)
  5020. ;; If this is called during org-agenda, don't return any entries to
  5021. ;; the calendar. Org Agenda will list these entries itself.
  5022. (when org-disable-agenda-to-diary (setq files nil))
  5023. (while (setq file (pop files))
  5024. (setq rtn (apply #'org-agenda-get-day-entries file date args))
  5025. (setq results (append results rtn)))
  5026. (when results
  5027. (setq results
  5028. (mapcar (lambda (i) (replace-regexp-in-string
  5029. org-link-bracket-re "\\2" i))
  5030. results))
  5031. (concat (org-agenda-finalize-entries results) "\n"))))
  5032. ;;; Agenda entry finders
  5033. (defun org-agenda--timestamp-to-absolute (&rest args)
  5034. "Call `org-time-string-to-absolute' with ARGS.
  5035. However, throw `:skip' whenever an error is raised."
  5036. (condition-case e
  5037. (apply #'org-time-string-to-absolute args)
  5038. (org-diary-sexp-no-match (throw :skip nil))
  5039. (error
  5040. (message "%s; Skipping entry" (error-message-string e))
  5041. (throw :skip nil))))
  5042. (defun org-agenda-get-day-entries (file date &rest args)
  5043. "Does the work for `org-diary' and `org-agenda'.
  5044. FILE is the path to a file to be checked for entries. DATE is date like
  5045. the one returned by `calendar-current-date'. ARGS are symbols indicating
  5046. which kind of entries should be extracted. For details about these, see
  5047. the documentation of `org-diary'."
  5048. (let* ((org-startup-folded nil)
  5049. (org-startup-align-all-tables nil)
  5050. (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
  5051. (error "No such file %s" file))))
  5052. (if (not buffer)
  5053. ;; If file does not exist, signal it in diary nonetheless.
  5054. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  5055. (with-current-buffer buffer
  5056. (unless (derived-mode-p 'org-mode)
  5057. (error "Agenda file %s is not in Org mode" file))
  5058. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  5059. (setf org-agenda-current-date date)
  5060. (save-excursion
  5061. (save-restriction
  5062. (if (eq buffer org-agenda-restrict)
  5063. (narrow-to-region org-agenda-restrict-begin
  5064. org-agenda-restrict-end)
  5065. (widen))
  5066. ;; Rationalize ARGS. Also make sure `:deadline' comes
  5067. ;; first in order to populate DEADLINES before passing it.
  5068. ;;
  5069. ;; We use `delq' since `org-uniquify' duplicates ARGS,
  5070. ;; guarding us from modifying `org-agenda-entry-types'.
  5071. (setf args (org-uniquify (or args org-agenda-entry-types)))
  5072. (when (and (memq :scheduled args) (memq :scheduled* args))
  5073. (setf args (delq :scheduled* args)))
  5074. (cond
  5075. ((memq :deadline args)
  5076. (setf args (cons :deadline
  5077. (delq :deadline (delq :deadline* args)))))
  5078. ((memq :deadline* args)
  5079. (setf args (cons :deadline* (delq :deadline* args)))))
  5080. ;; Collect list of headlines. Return them flattened.
  5081. (let ((case-fold-search nil) results deadlines)
  5082. (org-dlet
  5083. ((date date))
  5084. (dolist (arg args (apply #'nconc (nreverse results)))
  5085. (pcase arg
  5086. ((and :todo (guard (org-agenda-today-p date)))
  5087. (push (org-agenda-get-todos) results))
  5088. (:timestamp
  5089. (push (org-agenda-get-blocks) results)
  5090. (push (org-agenda-get-timestamps deadlines) results))
  5091. (:sexp
  5092. (push (org-agenda-get-sexps) results))
  5093. (:scheduled
  5094. (push (org-agenda-get-scheduled deadlines) results))
  5095. (:scheduled*
  5096. (push (org-agenda-get-scheduled deadlines t) results))
  5097. (:closed
  5098. (push (org-agenda-get-progress) results))
  5099. (:deadline
  5100. (setf deadlines (org-agenda-get-deadlines))
  5101. (push deadlines results))
  5102. (:deadline*
  5103. (setf deadlines (org-agenda-get-deadlines t))
  5104. (push deadlines results))))))))))))
  5105. (defsubst org-em (x y list)
  5106. "Is X or Y a member of LIST?"
  5107. (or (memq x list) (memq y list)))
  5108. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  5109. (defvar org-agenda-sorting-strategy-selected nil)
  5110. (defun org-agenda-entry-get-agenda-timestamp (pom)
  5111. "Retrieve timestamp information for sorting agenda views.
  5112. Given a point or marker POM, returns a cons cell of the timestamp
  5113. and the timestamp type relevant for the sorting strategy in
  5114. `org-agenda-sorting-strategy-selected'."
  5115. (let (ts ts-date-type)
  5116. (save-match-data
  5117. (cond ((org-em 'scheduled-up 'scheduled-down
  5118. org-agenda-sorting-strategy-selected)
  5119. (setq ts (org-entry-get pom "SCHEDULED")
  5120. ts-date-type " scheduled"))
  5121. ((org-em 'deadline-up 'deadline-down
  5122. org-agenda-sorting-strategy-selected)
  5123. (setq ts (org-entry-get pom "DEADLINE")
  5124. ts-date-type " deadline"))
  5125. ((org-em 'ts-up 'ts-down
  5126. org-agenda-sorting-strategy-selected)
  5127. (setq ts (org-entry-get pom "TIMESTAMP")
  5128. ts-date-type " timestamp"))
  5129. ((org-em 'tsia-up 'tsia-down
  5130. org-agenda-sorting-strategy-selected)
  5131. (setq ts (org-entry-get pom "TIMESTAMP_IA")
  5132. ts-date-type " timestamp_ia"))
  5133. ((org-em 'timestamp-up 'timestamp-down
  5134. org-agenda-sorting-strategy-selected)
  5135. (setq ts (or (org-entry-get pom "SCHEDULED")
  5136. (org-entry-get pom "DEADLINE")
  5137. (org-entry-get pom "TIMESTAMP")
  5138. (org-entry-get pom "TIMESTAMP_IA"))
  5139. ts-date-type ""))
  5140. (t (setq ts-date-type "")))
  5141. (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
  5142. ts-date-type))))
  5143. (defun org-agenda-get-todos ()
  5144. "Return the TODO information for agenda display."
  5145. (let* ((props (list 'face nil
  5146. 'done-face 'org-agenda-done
  5147. 'org-not-done-regexp org-not-done-regexp
  5148. 'org-todo-regexp org-todo-regexp
  5149. 'org-complex-heading-regexp org-complex-heading-regexp
  5150. 'mouse-face 'highlight
  5151. 'help-echo
  5152. (format "mouse-2 or RET jump to org file %s"
  5153. (abbreviate-file-name buffer-file-name))))
  5154. (case-fold-search nil)
  5155. (regexp (format org-heading-keyword-regexp-format
  5156. (cond
  5157. ((and org-select-this-todo-keyword
  5158. (equal org-select-this-todo-keyword "*"))
  5159. org-todo-regexp)
  5160. (org-select-this-todo-keyword
  5161. (concat "\\("
  5162. (mapconcat #'identity
  5163. (org-split-string
  5164. org-select-this-todo-keyword
  5165. "|")
  5166. "\\|")
  5167. "\\)"))
  5168. (t org-not-done-regexp))))
  5169. marker priority category level tags todo-state
  5170. ts-date ts-date-type ts-date-pair
  5171. ee txt beg end inherited-tags todo-state-end-pos
  5172. effort effort-minutes)
  5173. (goto-char (point-min))
  5174. (while (re-search-forward regexp nil t)
  5175. (catch :skip
  5176. (save-match-data
  5177. (beginning-of-line)
  5178. (org-agenda-skip)
  5179. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  5180. (unless (and (setq todo-state (org-get-todo-state))
  5181. (setq todo-state-end-pos (match-end 2)))
  5182. (goto-char end)
  5183. (throw :skip nil))
  5184. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  5185. (goto-char (1+ beg))
  5186. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  5187. (throw :skip nil)))
  5188. (goto-char (match-beginning 2))
  5189. (setq marker (org-agenda-new-marker (match-beginning 0))
  5190. category (org-get-category)
  5191. effort (save-match-data (or (get-text-property (point) 'effort)
  5192. (org-entry-get (point) org-effort-property)))
  5193. effort-minutes (when effort (save-match-data (org-duration-to-minutes effort)))
  5194. ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
  5195. ts-date (car ts-date-pair)
  5196. ts-date-type (cdr ts-date-pair)
  5197. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  5198. inherited-tags
  5199. (or (eq org-agenda-show-inherited-tags 'always)
  5200. (and (listp org-agenda-show-inherited-tags)
  5201. (memq 'todo org-agenda-show-inherited-tags))
  5202. (and (eq org-agenda-show-inherited-tags t)
  5203. (or (eq org-agenda-use-tag-inheritance t)
  5204. (memq 'todo org-agenda-use-tag-inheritance))))
  5205. tags (org-get-tags nil (not inherited-tags))
  5206. level (make-string (org-reduced-level (org-outline-level)) ? )
  5207. txt (org-agenda-format-item ""
  5208. (org-add-props txt nil
  5209. 'effort effort
  5210. 'effort-minutes effort-minutes)
  5211. level category tags t)
  5212. priority (1+ (org-get-priority txt)))
  5213. (org-add-props txt props
  5214. 'org-marker marker 'org-hd-marker marker
  5215. 'priority priority
  5216. 'effort effort 'effort-minutes effort-minutes
  5217. 'level level
  5218. 'ts-date ts-date
  5219. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  5220. (push txt ee)
  5221. (if org-agenda-todo-list-sublevels
  5222. (goto-char todo-state-end-pos)
  5223. (org-end-of-subtree 'invisible))))
  5224. (nreverse ee)))
  5225. (defun org-agenda-todo-custom-ignore-p (time n)
  5226. "Check whether timestamp is farther away than n number of days.
  5227. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5228. `org-agenda-todo-ignore-scheduled' or
  5229. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5230. (let ((days (org-time-stamp-to-now
  5231. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5232. (if (>= n 0)
  5233. (>= days n)
  5234. (<= days n))))
  5235. ;;;###autoload
  5236. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5237. (&optional end)
  5238. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5239. (when (or org-agenda-todo-ignore-with-date
  5240. org-agenda-todo-ignore-scheduled
  5241. org-agenda-todo-ignore-deadlines
  5242. org-agenda-todo-ignore-timestamp)
  5243. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5244. (save-excursion
  5245. (or (and org-agenda-todo-ignore-with-date
  5246. (re-search-forward org-ts-regexp end t))
  5247. (and org-agenda-todo-ignore-scheduled
  5248. (re-search-forward org-scheduled-time-regexp end t)
  5249. (cond
  5250. ((eq org-agenda-todo-ignore-scheduled 'future)
  5251. (> (org-time-stamp-to-now
  5252. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5253. 0))
  5254. ((eq org-agenda-todo-ignore-scheduled 'past)
  5255. (<= (org-time-stamp-to-now
  5256. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5257. 0))
  5258. ((numberp org-agenda-todo-ignore-scheduled)
  5259. (org-agenda-todo-custom-ignore-p
  5260. (match-string 1) org-agenda-todo-ignore-scheduled))
  5261. (t)))
  5262. (and org-agenda-todo-ignore-deadlines
  5263. (re-search-forward org-deadline-time-regexp end t)
  5264. (cond
  5265. ((eq org-agenda-todo-ignore-deadlines 'all) t)
  5266. ((eq org-agenda-todo-ignore-deadlines 'far)
  5267. (not (org-deadline-close-p (match-string 1))))
  5268. ((eq org-agenda-todo-ignore-deadlines 'future)
  5269. (> (org-time-stamp-to-now
  5270. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5271. 0))
  5272. ((eq org-agenda-todo-ignore-deadlines 'past)
  5273. (<= (org-time-stamp-to-now
  5274. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5275. 0))
  5276. ((numberp org-agenda-todo-ignore-deadlines)
  5277. (org-agenda-todo-custom-ignore-p
  5278. (match-string 1) org-agenda-todo-ignore-deadlines))
  5279. (t (org-deadline-close-p (match-string 1)))))
  5280. (and org-agenda-todo-ignore-timestamp
  5281. (let ((buffer (current-buffer))
  5282. (regexp
  5283. (concat
  5284. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5285. (start (point)))
  5286. ;; Copy current buffer into a temporary one
  5287. (with-temp-buffer
  5288. (insert-buffer-substring buffer start end)
  5289. (goto-char (point-min))
  5290. ;; Delete SCHEDULED and DEADLINE items
  5291. (while (re-search-forward regexp end t)
  5292. (delete-region (match-beginning 0) (match-end 0)))
  5293. (goto-char (point-min))
  5294. ;; No search for timestamp left
  5295. (when (re-search-forward org-ts-regexp nil t)
  5296. (cond
  5297. ((eq org-agenda-todo-ignore-timestamp 'future)
  5298. (> (org-time-stamp-to-now
  5299. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5300. 0))
  5301. ((eq org-agenda-todo-ignore-timestamp 'past)
  5302. (<= (org-time-stamp-to-now
  5303. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5304. 0))
  5305. ((numberp org-agenda-todo-ignore-timestamp)
  5306. (org-agenda-todo-custom-ignore-p
  5307. (match-string 1) org-agenda-todo-ignore-timestamp))
  5308. (t))))))))))
  5309. (defun org-agenda-get-timestamps (&optional deadlines)
  5310. "Return the date stamp information for agenda display.
  5311. Optional argument DEADLINES is a list of deadline items to be
  5312. displayed in agenda view."
  5313. (with-no-warnings (defvar date))
  5314. (let* ((props (list 'face 'org-agenda-calendar-event
  5315. 'org-not-done-regexp org-not-done-regexp
  5316. 'org-todo-regexp org-todo-regexp
  5317. 'org-complex-heading-regexp org-complex-heading-regexp
  5318. 'mouse-face 'highlight
  5319. 'help-echo
  5320. (format "mouse-2 or RET jump to Org file %s"
  5321. (abbreviate-file-name buffer-file-name))))
  5322. (current (calendar-absolute-from-gregorian date))
  5323. (today (org-today))
  5324. (deadline-position-alist
  5325. (mapcar (lambda (d)
  5326. (let ((m (get-text-property 0 'org-hd-marker d)))
  5327. (and m (marker-position m))))
  5328. deadlines))
  5329. ;; Match time-stamps set to current date, time-stamps with
  5330. ;; a repeater, and S-exp time-stamps.
  5331. (regexp
  5332. (concat
  5333. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5334. (regexp-quote
  5335. (substring
  5336. (format-time-string
  5337. (car org-time-stamp-formats)
  5338. (org-encode-time ; DATE bound by calendar
  5339. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5340. 1 11))
  5341. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5342. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5343. timestamp-items)
  5344. (goto-char (point-min))
  5345. (while (re-search-forward regexp nil t)
  5346. ;; Skip date ranges, scheduled and deadlines, which are handled
  5347. ;; specially. Also skip time-stamps before first headline as
  5348. ;; there would be no entry to add to the agenda. Eventually,
  5349. ;; ignore clock entries.
  5350. (catch :skip
  5351. (save-match-data
  5352. (when (or (org-at-date-range-p)
  5353. (org-at-planning-p)
  5354. (org-before-first-heading-p)
  5355. (and org-agenda-include-inactive-timestamps
  5356. (org-at-clock-log-p))
  5357. (not (org-at-timestamp-p 'agenda)))
  5358. (throw :skip nil))
  5359. (org-agenda-skip (org-element-at-point)))
  5360. (let* ((pos (match-beginning 0))
  5361. (repeat (match-string 1))
  5362. (sexp-entry (match-string 3))
  5363. (time-stamp (if (or repeat sexp-entry) (match-string 0)
  5364. (save-excursion
  5365. (goto-char pos)
  5366. (looking-at org-ts-regexp-both)
  5367. (match-string 0))))
  5368. (todo-state (org-get-todo-state))
  5369. (warntime (get-text-property (point) 'org-appt-warntime))
  5370. (done? (member todo-state org-done-keywords)))
  5371. ;; Possibly skip done tasks.
  5372. (when (and done? org-agenda-skip-timestamp-if-done)
  5373. (throw :skip t))
  5374. ;; S-exp entry doesn't match current day: skip it.
  5375. (when (and sexp-entry (not (org-diary-sexp-entry sexp-entry "" date)))
  5376. (throw :skip nil))
  5377. (when repeat
  5378. (let* ((past
  5379. ;; A repeating time stamp is shown at its base
  5380. ;; date and every repeated date up to TODAY. If
  5381. ;; `org-agenda-prefer-last-repeat' is non-nil,
  5382. ;; however, only the last repeat before today
  5383. ;; (inclusive) is shown.
  5384. (org-agenda--timestamp-to-absolute
  5385. repeat
  5386. (if (or (> current today)
  5387. (eq org-agenda-prefer-last-repeat t)
  5388. (member todo-state org-agenda-prefer-last-repeat))
  5389. today
  5390. current)
  5391. 'past (current-buffer) pos))
  5392. (future
  5393. ;; Display every repeated date past TODAY
  5394. ;; (exclusive) unless
  5395. ;; `org-agenda-show-future-repeats' is nil. If
  5396. ;; this variable is set to `next', only display
  5397. ;; the first repeated date after TODAY
  5398. ;; (exclusive).
  5399. (cond
  5400. ((<= current today) past)
  5401. ((not org-agenda-show-future-repeats) past)
  5402. (t
  5403. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5404. (1+ today)
  5405. current)))
  5406. (org-agenda--timestamp-to-absolute
  5407. repeat base 'future (current-buffer) pos))))))
  5408. (when (and (/= current past) (/= current future))
  5409. (throw :skip nil))))
  5410. (save-excursion
  5411. (re-search-backward org-outline-regexp-bol nil t)
  5412. ;; Possibly skip time-stamp when a deadline is set.
  5413. (when (and org-agenda-skip-timestamp-if-deadline-is-shown
  5414. (assq (point) deadline-position-alist))
  5415. (throw :skip nil))
  5416. (let* ((category (org-get-category pos))
  5417. (effort (org-entry-get pos org-effort-property))
  5418. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5419. (inherited-tags
  5420. (or (eq org-agenda-show-inherited-tags 'always)
  5421. (and (consp org-agenda-show-inherited-tags)
  5422. (memq 'agenda org-agenda-show-inherited-tags))
  5423. (and (eq org-agenda-show-inherited-tags t)
  5424. (or (eq org-agenda-use-tag-inheritance t)
  5425. (memq 'agenda
  5426. org-agenda-use-tag-inheritance)))))
  5427. (tags (org-get-tags nil (not inherited-tags)))
  5428. (level (make-string (org-reduced-level (org-outline-level))
  5429. ?\s))
  5430. (head (and (looking-at "\\*+[ \t]+\\(.*\\)")
  5431. (match-string 1)))
  5432. (inactive? (= (char-after pos) ?\[))
  5433. (habit? (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5434. (item
  5435. (org-agenda-format-item
  5436. (and inactive? org-agenda-inactive-leader)
  5437. (org-add-props head nil
  5438. 'effort effort
  5439. 'effort-minutes effort-minutes)
  5440. level category tags time-stamp org-ts-regexp habit?)))
  5441. (org-add-props item props
  5442. 'priority (if habit?
  5443. (org-habit-get-priority (org-habit-parse-todo))
  5444. (org-get-priority item))
  5445. 'org-marker (org-agenda-new-marker pos)
  5446. 'org-hd-marker (org-agenda-new-marker)
  5447. 'date date
  5448. 'level level
  5449. 'effort effort 'effort-minutes effort-minutes
  5450. 'ts-date (if repeat (org-agenda--timestamp-to-absolute repeat)
  5451. current)
  5452. 'todo-state todo-state
  5453. 'warntime warntime
  5454. 'type "timestamp")
  5455. (push item timestamp-items))))
  5456. (when org-agenda-skip-additional-timestamps-same-entry
  5457. (outline-next-heading))))
  5458. (nreverse timestamp-items)))
  5459. (defun org-agenda-get-sexps ()
  5460. "Return the sexp information for agenda display."
  5461. (require 'diary-lib)
  5462. (with-no-warnings (defvar date) (defvar entry))
  5463. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5464. 'mouse-face 'highlight
  5465. 'help-echo
  5466. (format "mouse-2 or RET jump to org file %s"
  5467. (abbreviate-file-name buffer-file-name))))
  5468. (regexp "^&?%%(")
  5469. ;; FIXME: Is this `entry' binding intended to be dynamic,
  5470. ;; so as to "hide" any current binding for it?
  5471. marker category extra level ee txt tags entry
  5472. result beg b sexp sexp-entry todo-state warntime inherited-tags
  5473. effort effort-minutes)
  5474. (goto-char (point-min))
  5475. (while (re-search-forward regexp nil t)
  5476. (catch :skip
  5477. ;; We do not run `org-agenda-skip' righ away because every single sexp
  5478. ;; in the buffer is matched here, unlike day-specific search
  5479. ;; in ordinary timestamps. Most of the sexps will not match
  5480. ;; the agenda day and it is quicker to run `org-agenda-skip' only for
  5481. ;; matching sexps later on.
  5482. (setq beg (match-beginning 0))
  5483. (goto-char (1- (match-end 0)))
  5484. (setq b (point))
  5485. (forward-sexp 1)
  5486. (setq sexp (buffer-substring b (point)))
  5487. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5488. (buffer-substring
  5489. (match-beginning 1)
  5490. (save-excursion
  5491. (goto-char (match-end 1))
  5492. (skip-chars-backward "[:blank:]")
  5493. (point)))
  5494. ""))
  5495. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5496. (when result
  5497. ;; Only check if entry should be skipped on matching sexps.
  5498. (org-agenda-skip (org-element-at-point))
  5499. (setq marker (org-agenda-new-marker beg)
  5500. level (make-string (org-reduced-level (org-outline-level)) ? )
  5501. category (org-get-category beg)
  5502. effort (save-match-data (or (get-text-property (point) 'effort)
  5503. (org-entry-get (point) org-effort-property)))
  5504. inherited-tags
  5505. (or (eq org-agenda-show-inherited-tags 'always)
  5506. (and (listp org-agenda-show-inherited-tags)
  5507. (memq 'agenda org-agenda-show-inherited-tags))
  5508. (and (eq org-agenda-show-inherited-tags t)
  5509. (or (eq org-agenda-use-tag-inheritance t)
  5510. (memq 'agenda org-agenda-use-tag-inheritance))))
  5511. tags (org-get-tags nil (not inherited-tags))
  5512. todo-state (org-get-todo-state)
  5513. warntime (get-text-property (point) 'org-appt-warntime)
  5514. extra nil)
  5515. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5516. (dolist (r (if (stringp result)
  5517. (list result)
  5518. result)) ;; we expect a list here
  5519. (when (and org-agenda-diary-sexp-prefix
  5520. (string-match org-agenda-diary-sexp-prefix r))
  5521. (setq extra (match-string 0 r)
  5522. r (replace-match "" nil nil r)))
  5523. (if (string-match "\\S-" r)
  5524. (setq txt r)
  5525. (setq txt "SEXP entry returned empty string"))
  5526. (setq txt (org-agenda-format-item extra
  5527. (org-add-props txt nil
  5528. 'effort effort
  5529. 'effort-minutes effort-minutes)
  5530. level category tags 'time))
  5531. (org-add-props txt props 'org-marker marker
  5532. 'date date 'todo-state todo-state
  5533. 'effort effort 'effort-minutes effort-minutes
  5534. 'level level 'type "sexp" 'warntime warntime)
  5535. (push txt ee)))))
  5536. (nreverse ee)))
  5537. ;; Calendar sanity: define some functions that are independent of
  5538. ;; `calendar-date-style'.
  5539. (defun org-anniversary (year month day &optional mark)
  5540. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5541. (with-no-warnings
  5542. (let ((calendar-date-style 'iso))
  5543. (diary-anniversary year month day mark))))
  5544. (defun org-cyclic (N year month day &optional mark)
  5545. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5546. (with-no-warnings
  5547. (let ((calendar-date-style 'iso))
  5548. (diary-cyclic N year month day mark))))
  5549. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5550. "Like `diary-block', but with fixed (ISO) order of arguments."
  5551. (with-no-warnings
  5552. (let ((calendar-date-style 'iso))
  5553. (diary-block Y1 M1 D1 Y2 M2 D2 mark))))
  5554. (defun org-date (year month day &optional mark)
  5555. "Like `diary-date', but with fixed (ISO) order of arguments."
  5556. (with-no-warnings
  5557. (let ((calendar-date-style 'iso))
  5558. (diary-date year month day mark))))
  5559. ;; Define the `org-class' function
  5560. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5561. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5562. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5563. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5564. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5565. `holidays', then any date that is known by the Emacs calendar to be a
  5566. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5567. then those holidays will be skipped."
  5568. (with-no-warnings (defvar date) (defvar entry))
  5569. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5570. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5571. (d (calendar-absolute-from-gregorian date))
  5572. (h (when skip-weeks (calendar-check-holidays date))))
  5573. (and
  5574. (<= date1 d)
  5575. (<= d date2)
  5576. (= (calendar-day-of-week date) dayname)
  5577. (or (not skip-weeks)
  5578. (progn
  5579. (require 'cal-iso)
  5580. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5581. (not (or (and h (memq 'holidays skip-weeks))
  5582. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5583. entry)))
  5584. (defalias 'org-get-closed #'org-agenda-get-progress)
  5585. (defun org-agenda-get-progress ()
  5586. "Return the logged TODO entries for agenda display."
  5587. (with-no-warnings (defvar date))
  5588. (let* ((props (list 'mouse-face 'highlight
  5589. 'org-not-done-regexp org-not-done-regexp
  5590. 'org-todo-regexp org-todo-regexp
  5591. 'org-complex-heading-regexp org-complex-heading-regexp
  5592. 'help-echo
  5593. (format "mouse-2 or RET jump to org file %s"
  5594. (abbreviate-file-name buffer-file-name))))
  5595. (items (if (consp org-agenda-show-log-scoped)
  5596. org-agenda-show-log-scoped
  5597. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5598. '(clock)
  5599. org-agenda-log-mode-items)))
  5600. (parts
  5601. (delq nil
  5602. (list
  5603. (when (memq 'closed items) (concat "\\<" org-closed-string))
  5604. (when (memq 'clock items) (concat "\\<" org-clock-string))
  5605. (when (memq 'state items)
  5606. (format "- +State \"%s\".*?" org-todo-regexp)))))
  5607. (parts-re (if parts (mapconcat #'identity parts "\\|")
  5608. (error "`org-agenda-log-mode-items' is empty")))
  5609. (regexp (concat
  5610. "\\(" parts-re "\\)"
  5611. " *\\["
  5612. (regexp-quote
  5613. (substring
  5614. (format-time-string
  5615. (car org-time-stamp-formats)
  5616. (org-encode-time ; DATE bound by calendar
  5617. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5618. 1 11))))
  5619. (org-agenda-search-headline-for-time nil)
  5620. marker hdmarker priority category level tags closedp type
  5621. statep clockp state ee txt extra timestr rest clocked inherited-tags
  5622. effort effort-minutes)
  5623. (goto-char (point-min))
  5624. (while (re-search-forward regexp nil t)
  5625. (catch :skip
  5626. (org-agenda-skip)
  5627. (setq marker (org-agenda-new-marker (match-beginning 0))
  5628. closedp (equal (match-string 1) org-closed-string)
  5629. statep (equal (string-to-char (match-string 1)) ?-)
  5630. clockp (not (or closedp statep))
  5631. state (and statep (match-string 2))
  5632. category (org-get-category (match-beginning 0))
  5633. timestr (buffer-substring (match-beginning 0) (line-end-position))
  5634. effort (save-match-data (or (get-text-property (point) 'effort)
  5635. (org-entry-get (point) org-effort-property))))
  5636. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5637. (when (string-match "\\]" timestr)
  5638. ;; substring should only run to end of time stamp
  5639. (setq rest (substring timestr (match-end 0))
  5640. timestr (substring timestr 0 (match-end 0)))
  5641. (if (and (not closedp) (not statep)
  5642. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5643. rest))
  5644. (progn (setq timestr (concat (substring timestr 0 -1)
  5645. "-" (match-string 1 rest) "]"))
  5646. (setq clocked (match-string 2 rest)))
  5647. (setq clocked "-")))
  5648. (save-excursion
  5649. (setq extra
  5650. (cond
  5651. ((not org-agenda-log-mode-add-notes) nil)
  5652. (statep
  5653. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5654. (match-string 1)))
  5655. (clockp
  5656. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5657. (match-string 1)))))
  5658. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5659. (throw :skip nil)
  5660. (goto-char (match-beginning 0))
  5661. (setq hdmarker (org-agenda-new-marker)
  5662. inherited-tags
  5663. (or (eq org-agenda-show-inherited-tags 'always)
  5664. (and (listp org-agenda-show-inherited-tags)
  5665. (memq 'todo org-agenda-show-inherited-tags))
  5666. (and (eq org-agenda-show-inherited-tags t)
  5667. (or (eq org-agenda-use-tag-inheritance t)
  5668. (memq 'todo org-agenda-use-tag-inheritance))))
  5669. tags (org-get-tags nil (not inherited-tags))
  5670. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5671. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5672. (setq txt (match-string 1))
  5673. (when extra
  5674. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5675. (setq txt (concat (substring txt 0 (match-beginning 1))
  5676. " - " extra " " (match-string 2 txt)))
  5677. (setq txt (concat txt " - " extra))))
  5678. (setq txt (org-agenda-format-item
  5679. (cond
  5680. (closedp "Closed: ")
  5681. (statep (concat "State: (" state ")"))
  5682. (t (concat "Clocked: (" clocked ")")))
  5683. (org-add-props txt nil
  5684. 'effort effort
  5685. 'effort-minutes effort-minutes)
  5686. level category tags timestr)))
  5687. (setq type (cond (closedp "closed")
  5688. (statep "state")
  5689. (t "clock")))
  5690. (setq priority 100000)
  5691. (org-add-props txt props
  5692. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5693. 'priority priority 'level level
  5694. 'effort effort 'effort-minutes effort-minutes
  5695. 'type type 'date date
  5696. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5697. (push txt ee))
  5698. (goto-char (line-end-position))))
  5699. (nreverse ee)))
  5700. (defun org-agenda-show-clocking-issues ()
  5701. "Add overlays, showing issues with clocking.
  5702. See also the user option `org-agenda-clock-consistency-checks'."
  5703. (interactive)
  5704. (let* ((pl org-agenda-clock-consistency-checks)
  5705. (re (concat "^[ \t]*"
  5706. org-clock-string
  5707. "[ \t]+"
  5708. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5709. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5710. (tlstart 0.)
  5711. (tlend 0.)
  5712. (maxtime (org-duration-to-minutes
  5713. (or (plist-get pl :max-duration) "24:00")))
  5714. (mintime (org-duration-to-minutes
  5715. (or (plist-get pl :min-duration) 0)))
  5716. (maxgap (org-duration-to-minutes
  5717. ;; default 30:00 means never complain
  5718. (or (plist-get pl :max-gap) "30:00")))
  5719. (gapok (mapcar #'org-duration-to-minutes
  5720. (plist-get pl :gap-ok-around)))
  5721. (def-face (or (plist-get pl :default-face)
  5722. '((:background "DarkRed") (:foreground "white"))))
  5723. issue face m te ts dt ov)
  5724. (goto-char (point-min))
  5725. (while (re-search-forward " Clocked: +(\\(?:-\\|\\([0-9]+:[0-9]+\\)\\))" nil t)
  5726. (setq issue nil face def-face)
  5727. (catch 'next
  5728. (setq m (org-get-at-bol 'org-marker)
  5729. te nil ts nil)
  5730. (unless (and m (markerp m))
  5731. (setq issue "No valid clock line") (throw 'next t))
  5732. (org-with-point-at m
  5733. (save-excursion
  5734. (goto-char (line-beginning-position))
  5735. (unless (looking-at re)
  5736. (error "No valid Clock line")
  5737. (throw 'next t))
  5738. (unless (match-end 3)
  5739. (setq issue
  5740. (format
  5741. "No end time: (%s)"
  5742. (org-duration-from-minutes
  5743. (floor
  5744. (- (float-time (org-current-time))
  5745. (float-time (org-time-string-to-time (match-string 1))))
  5746. 60)))
  5747. face (or (plist-get pl :no-end-time-face) face))
  5748. (throw 'next t))
  5749. (setq ts (match-string 1)
  5750. te (match-string 3)
  5751. ts (float-time (org-time-string-to-time ts))
  5752. te (float-time (org-time-string-to-time te))
  5753. dt (- te ts))))
  5754. (cond
  5755. ((> dt (* 60 maxtime))
  5756. ;; a very long clocking chunk
  5757. (setq issue (format "Clocking interval is very long: %s"
  5758. (org-duration-from-minutes (floor dt 60)))
  5759. face (or (plist-get pl :long-face) face)))
  5760. ((< dt (* 60 mintime))
  5761. ;; a very short clocking chunk
  5762. (setq issue (format "Clocking interval is very short: %s"
  5763. (org-duration-from-minutes (floor dt 60)))
  5764. face (or (plist-get pl :short-face) face)))
  5765. ((and (> tlend 0) (< ts tlend))
  5766. ;; Two clock entries are overlapping
  5767. (setq issue (format "Clocking overlap: %d minutes"
  5768. (/ (- tlend ts) 60))
  5769. face (or (plist-get pl :overlap-face) face)))
  5770. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5771. ;; There is a gap, lets see if we need to report it
  5772. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5773. (setq issue (format "Clocking gap: %d minutes"
  5774. (/ (- ts tlend) 60))
  5775. face (or (plist-get pl :gap-face) face))))
  5776. (t nil)))
  5777. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5778. (when issue
  5779. ;; OK, there was some issue, add an overlay to show the issue
  5780. (setq ov (make-overlay (line-beginning-position) (line-end-position)))
  5781. (overlay-put ov 'before-string
  5782. (concat
  5783. (org-add-props
  5784. (format "%-43s" (concat " " issue))
  5785. nil
  5786. 'face face)
  5787. "\n"))
  5788. (overlay-put ov 'evaporate t)))))
  5789. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5790. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5791. (catch 'exit
  5792. (unless ok-list
  5793. ;; there are no OK times for gaps...
  5794. (throw 'exit nil))
  5795. (when (> (- (/ t2 36000) (/ t1 36000)) 24)
  5796. ;; This is more than 24 hours, so it is OK.
  5797. ;; because we have at least one OK time, that must be in the
  5798. ;; 24 hour interval.
  5799. (throw 'exit t))
  5800. ;; We have a shorter gap.
  5801. ;; Now we have to get the minute of the day when these times are
  5802. (let* ((t1dec (decode-time t1))
  5803. (t2dec (decode-time t2))
  5804. ;; compute the minute on the day
  5805. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5806. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5807. (when (< min2 min1)
  5808. ;; if min2 is smaller than min1, this means it is on the next day.
  5809. ;; Wrap it to after midnight.
  5810. (setq min2 (+ min2 1440)))
  5811. ;; Now check if any of the OK times is in the gap
  5812. (mapc (lambda (x)
  5813. ;; Wrap the time to after midnight if necessary
  5814. (when (< x min1) (setq x (+ x 1440)))
  5815. ;; Check if in interval
  5816. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5817. ok-list)
  5818. ;; Nope, this gap is not OK
  5819. nil)))
  5820. (defun org-agenda-get-deadlines (&optional with-hour)
  5821. "Return the deadline information for agenda display.
  5822. When WITH-HOUR is non-nil, only return deadlines with an hour
  5823. specification like [h]h:mm."
  5824. (with-no-warnings (defvar date))
  5825. (let* ((props (list 'mouse-face 'highlight
  5826. 'org-not-done-regexp org-not-done-regexp
  5827. 'org-todo-regexp org-todo-regexp
  5828. 'org-complex-heading-regexp org-complex-heading-regexp
  5829. 'help-echo
  5830. (format "mouse-2 or RET jump to org file %s"
  5831. (abbreviate-file-name buffer-file-name))))
  5832. (regexp (if with-hour
  5833. org-deadline-time-hour-regexp
  5834. org-deadline-time-regexp))
  5835. (today (org-today))
  5836. (today? (org-agenda-today-p date)) ; DATE bound by calendar.
  5837. (current (calendar-absolute-from-gregorian date))
  5838. deadline-items)
  5839. (goto-char (point-min))
  5840. (if (org-element--cache-active-p)
  5841. (org-element-cache-map
  5842. (lambda (el)
  5843. (when (and (org-element-property :deadline el)
  5844. (or (not with-hour)
  5845. (org-element-property
  5846. :hour-start
  5847. (org-element-property :deadline el))
  5848. (org-element-property
  5849. :hour-end
  5850. (org-element-property :deadline el))))
  5851. (goto-char (org-element-property :contents-begin el))
  5852. (catch :skip
  5853. (org-agenda-skip el)
  5854. (let* ((s (substring (org-element-property
  5855. :raw-value
  5856. (org-element-property :deadline el))
  5857. 1 -1))
  5858. (pos (save-excursion
  5859. (goto-char (org-element-property :contents-begin el))
  5860. ;; We intentionally leave NOERROR
  5861. ;; argument in `re-search-forward' nil. If
  5862. ;; the search fails here, something went
  5863. ;; wrong and we are looking at
  5864. ;; non-matching headline.
  5865. (re-search-forward regexp (line-end-position))
  5866. (1- (match-beginning 1))))
  5867. (todo-state (org-element-property :todo-keyword el))
  5868. (done? (eq 'done (org-element-property :todo-type el)))
  5869. (sexp? (eq 'diary
  5870. (org-element-property
  5871. :type (org-element-property :deadline el))))
  5872. ;; DEADLINE is the deadline date for the entry. It is
  5873. ;; either the base date or the last repeat, according
  5874. ;; to `org-agenda-prefer-last-repeat'.
  5875. (deadline
  5876. (cond
  5877. (sexp? (org-agenda--timestamp-to-absolute s current))
  5878. ((or (eq org-agenda-prefer-last-repeat t)
  5879. (member todo-state org-agenda-prefer-last-repeat))
  5880. (org-agenda--timestamp-to-absolute
  5881. s today 'past (current-buffer) pos))
  5882. (t (org-agenda--timestamp-to-absolute s))))
  5883. ;; REPEAT is the future repeat closest from CURRENT,
  5884. ;; according to `org-agenda-show-future-repeats'. If
  5885. ;; the latter is nil, or if the time stamp has no
  5886. ;; repeat part, default to DEADLINE.
  5887. (repeat
  5888. (cond
  5889. (sexp? deadline)
  5890. ((<= current today) deadline)
  5891. ((not org-agenda-show-future-repeats) deadline)
  5892. (t
  5893. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5894. (1+ today)
  5895. current)))
  5896. (org-agenda--timestamp-to-absolute
  5897. s base 'future (current-buffer) pos)))))
  5898. (diff (- deadline current))
  5899. (suppress-prewarning
  5900. (let ((scheduled
  5901. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5902. (org-element-property
  5903. :raw-value
  5904. (org-element-property :scheduled el)))))
  5905. (cond
  5906. ((not scheduled) nil)
  5907. ;; The current item has a scheduled date, so
  5908. ;; evaluate its prewarning lead time.
  5909. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5910. ;; Use global prewarning-restart lead time.
  5911. org-agenda-skip-deadline-prewarning-if-scheduled)
  5912. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5913. 'pre-scheduled)
  5914. ;; Set pre-warning to no earlier than SCHEDULED.
  5915. (min (- deadline
  5916. (org-agenda--timestamp-to-absolute scheduled))
  5917. org-deadline-warning-days))
  5918. ;; Set pre-warning to deadline.
  5919. (t 0))))
  5920. (wdays (or suppress-prewarning (org-get-wdays s))))
  5921. (cond
  5922. ;; Only display deadlines at their base date, at future
  5923. ;; repeat occurrences or in today agenda.
  5924. ((= current deadline) nil)
  5925. ((= current repeat) nil)
  5926. ((not today?) (throw :skip nil))
  5927. ;; Upcoming deadline: display within warning period WDAYS.
  5928. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  5929. ;; Overdue deadline: warn about it for
  5930. ;; `org-deadline-past-days' duration.
  5931. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  5932. ;; Possibly skip done tasks.
  5933. (when (and done?
  5934. (or org-agenda-skip-deadline-if-done
  5935. (/= deadline current)))
  5936. (throw :skip nil))
  5937. (save-excursion
  5938. (goto-char (org-element-property :begin el))
  5939. (let* ((category (org-get-category))
  5940. (effort (save-match-data (or (get-text-property (point) 'effort)
  5941. (org-element-property (intern (concat ":" (upcase org-effort-property))) el))))
  5942. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5943. (level (make-string (org-element-property :level el)
  5944. ?\s))
  5945. (head (save-excursion
  5946. (goto-char (org-element-property :begin el))
  5947. (re-search-forward org-outline-regexp-bol)
  5948. (buffer-substring-no-properties (point) (line-end-position))))
  5949. (inherited-tags
  5950. (or (eq org-agenda-show-inherited-tags 'always)
  5951. (and (listp org-agenda-show-inherited-tags)
  5952. (memq 'agenda org-agenda-show-inherited-tags))
  5953. (and (eq org-agenda-show-inherited-tags t)
  5954. (or (eq org-agenda-use-tag-inheritance t)
  5955. (memq 'agenda
  5956. org-agenda-use-tag-inheritance)))))
  5957. (tags (org-get-tags el (not inherited-tags)))
  5958. (time
  5959. (cond
  5960. ;; No time of day designation if it is only
  5961. ;; a reminder.
  5962. ((and (/= current deadline) (/= current repeat)) nil)
  5963. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5964. (concat (substring s (match-beginning 1)) " "))
  5965. (t 'time)))
  5966. (item
  5967. (org-agenda-format-item
  5968. ;; Insert appropriate suffixes before deadlines.
  5969. ;; Those only apply to today agenda.
  5970. (pcase-let ((`(,now ,future ,past)
  5971. org-agenda-deadline-leaders))
  5972. (cond
  5973. ((and today? (< deadline today)) (format past (- diff)))
  5974. ((and today? (> deadline today)) (format future diff))
  5975. (t now)))
  5976. (org-add-props head nil
  5977. 'effort effort
  5978. 'effort-minutes effort-minutes)
  5979. level category tags time))
  5980. (face (org-agenda-deadline-face
  5981. (- 1 (/ (float diff) (max wdays 1)))))
  5982. (upcoming? (and today? (> deadline today)))
  5983. (warntime (get-text-property (point) 'org-appt-warntime)))
  5984. (org-add-props item props
  5985. 'org-marker (org-agenda-new-marker pos)
  5986. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5987. 'warntime warntime
  5988. 'level level
  5989. 'effort effort 'effort-minutes effort-minutes
  5990. 'ts-date deadline
  5991. 'priority
  5992. ;; Adjust priority to today reminders about deadlines.
  5993. ;; Overdue deadlines get the highest priority
  5994. ;; increase, then imminent deadlines and eventually
  5995. ;; more distant deadlines.
  5996. (let ((adjust (if today? (- diff) 0)))
  5997. (+ adjust (org-get-priority item)))
  5998. 'todo-state todo-state
  5999. 'type (if upcoming? "upcoming-deadline" "deadline")
  6000. 'date (if upcoming? date deadline)
  6001. 'face (if done? 'org-agenda-done face)
  6002. 'undone-face face
  6003. 'done-face 'org-agenda-done)
  6004. (push item deadline-items)))))))
  6005. :next-re regexp
  6006. :fail-re regexp
  6007. :narrow t)
  6008. (while (re-search-forward regexp nil t)
  6009. (catch :skip
  6010. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  6011. (org-agenda-skip)
  6012. (let* ((s (match-string 1))
  6013. (pos (1- (match-beginning 1)))
  6014. (todo-state (save-match-data (org-get-todo-state)))
  6015. (done? (member todo-state org-done-keywords))
  6016. (sexp? (string-prefix-p "%%" s))
  6017. ;; DEADLINE is the deadline date for the entry. It is
  6018. ;; either the base date or the last repeat, according
  6019. ;; to `org-agenda-prefer-last-repeat'.
  6020. (deadline
  6021. (cond
  6022. (sexp? (org-agenda--timestamp-to-absolute s current))
  6023. ((or (eq org-agenda-prefer-last-repeat t)
  6024. (member todo-state org-agenda-prefer-last-repeat))
  6025. (org-agenda--timestamp-to-absolute
  6026. s today 'past (current-buffer) pos))
  6027. (t (org-agenda--timestamp-to-absolute s))))
  6028. ;; REPEAT is the future repeat closest from CURRENT,
  6029. ;; according to `org-agenda-show-future-repeats'. If
  6030. ;; the latter is nil, or if the time stamp has no
  6031. ;; repeat part, default to DEADLINE.
  6032. (repeat
  6033. (cond
  6034. (sexp? deadline)
  6035. ((<= current today) deadline)
  6036. ((not org-agenda-show-future-repeats) deadline)
  6037. (t
  6038. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6039. (1+ today)
  6040. current)))
  6041. (org-agenda--timestamp-to-absolute
  6042. s base 'future (current-buffer) pos)))))
  6043. (diff (- deadline current))
  6044. (suppress-prewarning
  6045. (let ((scheduled
  6046. (and org-agenda-skip-deadline-prewarning-if-scheduled
  6047. (org-entry-get nil "SCHEDULED"))))
  6048. (cond
  6049. ((not scheduled) nil)
  6050. ;; The current item has a scheduled date, so
  6051. ;; evaluate its prewarning lead time.
  6052. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  6053. ;; Use global prewarning-restart lead time.
  6054. org-agenda-skip-deadline-prewarning-if-scheduled)
  6055. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  6056. 'pre-scheduled)
  6057. ;; Set pre-warning to no earlier than SCHEDULED.
  6058. (min (- deadline
  6059. (org-agenda--timestamp-to-absolute scheduled))
  6060. org-deadline-warning-days))
  6061. ;; Set pre-warning to deadline.
  6062. (t 0))))
  6063. (wdays (or suppress-prewarning (org-get-wdays s))))
  6064. (cond
  6065. ;; Only display deadlines at their base date, at future
  6066. ;; repeat occurrences or in today agenda.
  6067. ((= current deadline) nil)
  6068. ((= current repeat) nil)
  6069. ((not today?) (throw :skip nil))
  6070. ;; Upcoming deadline: display within warning period WDAYS.
  6071. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  6072. ;; Overdue deadline: warn about it for
  6073. ;; `org-deadline-past-days' duration.
  6074. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  6075. ;; Possibly skip done tasks.
  6076. (when (and done?
  6077. (or org-agenda-skip-deadline-if-done
  6078. (/= deadline current)))
  6079. (throw :skip nil))
  6080. (save-excursion
  6081. (re-search-backward "^\\*+[ \t]+" nil t)
  6082. (goto-char (match-end 0))
  6083. (let* ((category (org-get-category))
  6084. (effort (save-match-data (or (get-text-property (point) 'effort)
  6085. (org-entry-get (point) org-effort-property))))
  6086. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6087. (level (make-string (org-reduced-level (org-outline-level))
  6088. ?\s))
  6089. (head (buffer-substring-no-properties
  6090. (point) (line-end-position)))
  6091. (inherited-tags
  6092. (or (eq org-agenda-show-inherited-tags 'always)
  6093. (and (listp org-agenda-show-inherited-tags)
  6094. (memq 'agenda org-agenda-show-inherited-tags))
  6095. (and (eq org-agenda-show-inherited-tags t)
  6096. (or (eq org-agenda-use-tag-inheritance t)
  6097. (memq 'agenda
  6098. org-agenda-use-tag-inheritance)))))
  6099. (tags (org-get-tags nil (not inherited-tags)))
  6100. (time
  6101. (cond
  6102. ;; No time of day designation if it is only
  6103. ;; a reminder.
  6104. ((and (/= current deadline) (/= current repeat)) nil)
  6105. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6106. (concat (substring s (match-beginning 1)) " "))
  6107. (t 'time)))
  6108. (item
  6109. (org-agenda-format-item
  6110. ;; Insert appropriate suffixes before deadlines.
  6111. ;; Those only apply to today agenda.
  6112. (pcase-let ((`(,now ,future ,past)
  6113. org-agenda-deadline-leaders))
  6114. (cond
  6115. ((and today? (< deadline today)) (format past (- diff)))
  6116. ((and today? (> deadline today)) (format future diff))
  6117. (t now)))
  6118. (org-add-props head nil
  6119. 'effort effort
  6120. 'effort-minutes effort-minutes)
  6121. level category tags time))
  6122. (face (org-agenda-deadline-face
  6123. (- 1 (/ (float diff) (max wdays 1)))))
  6124. (upcoming? (and today? (> deadline today)))
  6125. (warntime (get-text-property (point) 'org-appt-warntime)))
  6126. (org-add-props item props
  6127. 'org-marker (org-agenda-new-marker pos)
  6128. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6129. 'warntime warntime
  6130. 'level level
  6131. 'effort effort 'effort-minutes effort-minutes
  6132. 'ts-date deadline
  6133. 'priority
  6134. ;; Adjust priority to today reminders about deadlines.
  6135. ;; Overdue deadlines get the highest priority
  6136. ;; increase, then imminent deadlines and eventually
  6137. ;; more distant deadlines.
  6138. (let ((adjust (if today? (- diff) 0)))
  6139. (+ adjust (org-get-priority item)))
  6140. 'todo-state todo-state
  6141. 'type (if upcoming? "upcoming-deadline" "deadline")
  6142. 'date (if upcoming? date deadline)
  6143. 'face (if done? 'org-agenda-done face)
  6144. 'undone-face face
  6145. 'done-face 'org-agenda-done)
  6146. (push item deadline-items)))))))
  6147. (nreverse deadline-items)))
  6148. (defun org-agenda-deadline-face (fraction)
  6149. "Return the face to displaying a deadline item.
  6150. FRACTION is what fraction of the head-warning time has passed."
  6151. (assoc-default fraction org-agenda-deadline-faces #'<=))
  6152. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  6153. "Return the scheduled information for agenda display.
  6154. Optional argument DEADLINES is a list of deadline items to be
  6155. displayed in agenda view. When WITH-HOUR is non-nil, only return
  6156. scheduled items with an hour specification like [h]h:mm."
  6157. (with-no-warnings (defvar date))
  6158. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  6159. 'org-todo-regexp org-todo-regexp
  6160. 'org-complex-heading-regexp org-complex-heading-regexp
  6161. 'done-face 'org-agenda-done
  6162. 'mouse-face 'highlight
  6163. 'help-echo
  6164. (format "mouse-2 or RET jump to Org file %s"
  6165. (abbreviate-file-name buffer-file-name))))
  6166. (regexp (if with-hour
  6167. org-scheduled-time-hour-regexp
  6168. org-scheduled-time-regexp))
  6169. (today (org-today))
  6170. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  6171. (current (calendar-absolute-from-gregorian date))
  6172. (deadline-pos
  6173. (mapcar (lambda (d)
  6174. (let ((m (get-text-property 0 'org-hd-marker d)))
  6175. (and m (marker-position m))))
  6176. deadlines))
  6177. scheduled-items)
  6178. (goto-char (point-min))
  6179. (if (org-element--cache-active-p)
  6180. (org-element-cache-map
  6181. (lambda (el)
  6182. (when (and (org-element-property :scheduled el)
  6183. (or (not with-hour)
  6184. (org-element-property
  6185. :hour-start
  6186. (org-element-property :scheduled el))
  6187. (org-element-property
  6188. :hour-end
  6189. (org-element-property :scheduled el))))
  6190. (goto-char (org-element-property :contents-begin el))
  6191. (catch :skip
  6192. (org-agenda-skip el)
  6193. (let* ((s (substring (org-element-property
  6194. :raw-value
  6195. (org-element-property :scheduled el))
  6196. 1 -1))
  6197. (pos (save-excursion
  6198. (goto-char (org-element-property :contents-begin el))
  6199. ;; We intentionally leave NOERROR
  6200. ;; argument in `re-search-forward' nil. If
  6201. ;; the search fails here, something went
  6202. ;; wrong and we are looking at
  6203. ;; non-matching headline.
  6204. (re-search-forward regexp (line-end-position))
  6205. (1- (match-beginning 1))))
  6206. (todo-state (org-element-property :todo-keyword el))
  6207. (donep (eq 'done (org-element-property :todo-type el)))
  6208. (sexp? (eq 'diary
  6209. (org-element-property
  6210. :type (org-element-property :scheduled el))))
  6211. ;; SCHEDULE is the scheduled date for the entry. It is
  6212. ;; either the bare date or the last repeat, according
  6213. ;; to `org-agenda-prefer-last-repeat'.
  6214. (schedule
  6215. (cond
  6216. (sexp? (org-agenda--timestamp-to-absolute s current))
  6217. ((or (eq org-agenda-prefer-last-repeat t)
  6218. (member todo-state org-agenda-prefer-last-repeat))
  6219. (org-agenda--timestamp-to-absolute
  6220. s today 'past (current-buffer) pos))
  6221. (t (org-agenda--timestamp-to-absolute s))))
  6222. ;; REPEAT is the future repeat closest from CURRENT,
  6223. ;; according to `org-agenda-show-future-repeats'. If
  6224. ;; the latter is nil, or if the time stamp has no
  6225. ;; repeat part, default to SCHEDULE.
  6226. (repeat
  6227. (cond
  6228. (sexp? schedule)
  6229. ((<= current today) schedule)
  6230. ((not org-agenda-show-future-repeats) schedule)
  6231. (t
  6232. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6233. (1+ today)
  6234. current)))
  6235. (org-agenda--timestamp-to-absolute
  6236. s base 'future (current-buffer) pos)))))
  6237. (diff (- current schedule))
  6238. (warntime (get-text-property (point) 'org-appt-warntime))
  6239. (pastschedp (< schedule today))
  6240. (futureschedp (> schedule today))
  6241. (habitp (and (fboundp 'org-is-habit-p)
  6242. (string= "habit" (org-element-property :STYLE el))))
  6243. (suppress-delay
  6244. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  6245. (org-element-property
  6246. :raw-value
  6247. (org-element-property :deadline el)))))
  6248. (cond
  6249. ((not deadline) nil)
  6250. ;; The current item has a deadline date, so
  6251. ;; evaluate its delay time.
  6252. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  6253. ;; Use global delay time.
  6254. (- org-agenda-skip-scheduled-delay-if-deadline))
  6255. ((eq org-agenda-skip-scheduled-delay-if-deadline
  6256. 'post-deadline)
  6257. ;; Set delay to no later than DEADLINE.
  6258. (min (- schedule
  6259. (org-agenda--timestamp-to-absolute deadline))
  6260. org-scheduled-delay-days))
  6261. (t 0))))
  6262. (ddays
  6263. (cond
  6264. ;; Nullify delay when a repeater triggered already
  6265. ;; and the delay is of the form --Xd.
  6266. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  6267. (> schedule (org-agenda--timestamp-to-absolute s)))
  6268. 0)
  6269. (suppress-delay
  6270. (let ((org-scheduled-delay-days suppress-delay))
  6271. (org-get-wdays s t t)))
  6272. (t (org-get-wdays s t)))))
  6273. ;; Display scheduled items at base date (SCHEDULE), today if
  6274. ;; scheduled before the current date, and at any repeat past
  6275. ;; today. However, skip delayed items and items that have
  6276. ;; been displayed for more than `org-scheduled-past-days'.
  6277. (unless (and todayp
  6278. habitp
  6279. (bound-and-true-p org-habit-show-all-today))
  6280. (when (or (and (> ddays 0) (< diff ddays))
  6281. (> diff (or (and habitp org-habit-scheduled-past-days)
  6282. org-scheduled-past-days))
  6283. (> schedule current)
  6284. (and (/= current schedule)
  6285. (/= current today)
  6286. (/= current repeat)))
  6287. (throw :skip nil)))
  6288. ;; Possibly skip done tasks.
  6289. (when (and donep
  6290. (or org-agenda-skip-scheduled-if-done
  6291. (/= schedule current)))
  6292. (throw :skip nil))
  6293. ;; Skip entry if it already appears as a deadline, per
  6294. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  6295. ;; doesn't apply to habits.
  6296. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  6297. ((guard
  6298. (or (not (memq (line-beginning-position 0) deadline-pos))
  6299. habitp))
  6300. nil)
  6301. (`repeated-after-deadline
  6302. (let ((deadline (time-to-days
  6303. (when (org-element-property :deadline el)
  6304. (org-time-string-to-time
  6305. (org-element-property :deadline el))))))
  6306. (and (<= schedule deadline) (> current deadline))))
  6307. (`not-today pastschedp)
  6308. (`t t)
  6309. (_ nil))
  6310. (throw :skip nil))
  6311. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  6312. ;; only show them for today. Also skip done habits.
  6313. (when (and habitp
  6314. (or donep
  6315. (not (bound-and-true-p org-habit-show-habits))
  6316. (and (not todayp)
  6317. (bound-and-true-p
  6318. org-habit-show-habits-only-for-today))))
  6319. (throw :skip nil))
  6320. (save-excursion
  6321. (goto-char (org-element-property :begin el))
  6322. (let* ((category (org-get-category))
  6323. (effort (save-match-data
  6324. (or (get-text-property (point) 'effort)
  6325. (org-element-property (intern (concat ":" (upcase org-effort-property))) el))))
  6326. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6327. (inherited-tags
  6328. (or (eq org-agenda-show-inherited-tags 'always)
  6329. (and (listp org-agenda-show-inherited-tags)
  6330. (memq 'agenda org-agenda-show-inherited-tags))
  6331. (and (eq org-agenda-show-inherited-tags t)
  6332. (or (eq org-agenda-use-tag-inheritance t)
  6333. (memq 'agenda
  6334. org-agenda-use-tag-inheritance)))))
  6335. (tags (org-get-tags el (not inherited-tags)))
  6336. (level (make-string (org-element-property :level el)
  6337. ?\s))
  6338. (head (save-excursion
  6339. (goto-char (org-element-property :begin el))
  6340. (re-search-forward org-outline-regexp-bol)
  6341. (buffer-substring (point) (line-end-position))))
  6342. (time
  6343. (cond
  6344. ;; No time of day designation if it is only a
  6345. ;; reminder, except for habits, which always show
  6346. ;; the time of day. Habits are an exception
  6347. ;; because if there is a time of day, that is
  6348. ;; interpreted to mean they should usually happen
  6349. ;; then, even if doing the habit was missed.
  6350. ((and
  6351. (not habitp)
  6352. (/= current schedule)
  6353. (/= current repeat))
  6354. nil)
  6355. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6356. (concat (substring s (match-beginning 1)) " "))
  6357. (t 'time)))
  6358. (item
  6359. (org-agenda-format-item
  6360. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  6361. ;; Show a reminder of a past scheduled today.
  6362. (if (and todayp pastschedp)
  6363. (format past diff)
  6364. first))
  6365. (org-add-props head nil
  6366. 'effort effort
  6367. 'effort-minutes effort-minutes)
  6368. level category tags time nil habitp))
  6369. (face (cond ((and (not habitp) pastschedp)
  6370. 'org-scheduled-previously)
  6371. ((and habitp futureschedp)
  6372. 'org-agenda-done)
  6373. (todayp 'org-scheduled-today)
  6374. (t 'org-scheduled)))
  6375. (habitp (and habitp (org-habit-parse-todo (org-element-property :begin el)))))
  6376. (org-add-props item props
  6377. 'undone-face face
  6378. 'face (if donep 'org-agenda-done face)
  6379. 'org-marker (org-agenda-new-marker pos)
  6380. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6381. 'type (if pastschedp "past-scheduled" "scheduled")
  6382. 'date (if pastschedp schedule date)
  6383. 'ts-date schedule
  6384. 'warntime warntime
  6385. 'level level
  6386. 'effort effort 'effort-minutes effort-minutes
  6387. 'priority (if habitp (org-habit-get-priority habitp)
  6388. (+ 99 diff (org-get-priority item)))
  6389. 'org-habit-p habitp
  6390. 'todo-state todo-state)
  6391. (push item scheduled-items)))))))
  6392. :next-re regexp
  6393. :fail-re regexp
  6394. :narrow t)
  6395. (while (re-search-forward regexp nil t)
  6396. (catch :skip
  6397. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  6398. (org-agenda-skip)
  6399. (let* ((s (match-string 1))
  6400. (pos (1- (match-beginning 1)))
  6401. (todo-state (save-match-data (org-get-todo-state)))
  6402. (donep (member todo-state org-done-keywords))
  6403. (sexp? (string-prefix-p "%%" s))
  6404. ;; SCHEDULE is the scheduled date for the entry. It is
  6405. ;; either the bare date or the last repeat, according
  6406. ;; to `org-agenda-prefer-last-repeat'.
  6407. (schedule
  6408. (cond
  6409. (sexp? (org-agenda--timestamp-to-absolute s current))
  6410. ((or (eq org-agenda-prefer-last-repeat t)
  6411. (member todo-state org-agenda-prefer-last-repeat))
  6412. (org-agenda--timestamp-to-absolute
  6413. s today 'past (current-buffer) pos))
  6414. (t (org-agenda--timestamp-to-absolute s))))
  6415. ;; REPEAT is the future repeat closest from CURRENT,
  6416. ;; according to `org-agenda-show-future-repeats'. If
  6417. ;; the latter is nil, or if the time stamp has no
  6418. ;; repeat part, default to SCHEDULE.
  6419. (repeat
  6420. (cond
  6421. (sexp? schedule)
  6422. ((<= current today) schedule)
  6423. ((not org-agenda-show-future-repeats) schedule)
  6424. (t
  6425. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6426. (1+ today)
  6427. current)))
  6428. (org-agenda--timestamp-to-absolute
  6429. s base 'future (current-buffer) pos)))))
  6430. (diff (- current schedule))
  6431. (warntime (get-text-property (point) 'org-appt-warntime))
  6432. (pastschedp (< schedule today))
  6433. (futureschedp (> schedule today))
  6434. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  6435. (suppress-delay
  6436. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  6437. (org-entry-get nil "DEADLINE"))))
  6438. (cond
  6439. ((not deadline) nil)
  6440. ;; The current item has a deadline date, so
  6441. ;; evaluate its delay time.
  6442. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  6443. ;; Use global delay time.
  6444. (- org-agenda-skip-scheduled-delay-if-deadline))
  6445. ((eq org-agenda-skip-scheduled-delay-if-deadline
  6446. 'post-deadline)
  6447. ;; Set delay to no later than DEADLINE.
  6448. (min (- schedule
  6449. (org-agenda--timestamp-to-absolute deadline))
  6450. org-scheduled-delay-days))
  6451. (t 0))))
  6452. (ddays
  6453. (cond
  6454. ;; Nullify delay when a repeater triggered already
  6455. ;; and the delay is of the form --Xd.
  6456. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  6457. (> schedule (org-agenda--timestamp-to-absolute s)))
  6458. 0)
  6459. (suppress-delay
  6460. (let ((org-scheduled-delay-days suppress-delay))
  6461. (org-get-wdays s t t)))
  6462. (t (org-get-wdays s t)))))
  6463. ;; Display scheduled items at base date (SCHEDULE), today if
  6464. ;; scheduled before the current date, and at any repeat past
  6465. ;; today. However, skip delayed items and items that have
  6466. ;; been displayed for more than `org-scheduled-past-days'.
  6467. (unless (and todayp
  6468. habitp
  6469. (bound-and-true-p org-habit-show-all-today))
  6470. (when (or (and (> ddays 0) (< diff ddays))
  6471. (> diff (or (and habitp org-habit-scheduled-past-days)
  6472. org-scheduled-past-days))
  6473. (> schedule current)
  6474. (and (/= current schedule)
  6475. (/= current today)
  6476. (/= current repeat)))
  6477. (throw :skip nil)))
  6478. ;; Possibly skip done tasks.
  6479. (when (and donep
  6480. (or org-agenda-skip-scheduled-if-done
  6481. (/= schedule current)))
  6482. (throw :skip nil))
  6483. ;; Skip entry if it already appears as a deadline, per
  6484. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  6485. ;; doesn't apply to habits.
  6486. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  6487. ((guard
  6488. (or (not (memq (line-beginning-position 0) deadline-pos))
  6489. habitp))
  6490. nil)
  6491. (`repeated-after-deadline
  6492. (let ((deadline (time-to-days
  6493. (org-get-deadline-time (point)))))
  6494. (and (<= schedule deadline) (> current deadline))))
  6495. (`not-today pastschedp)
  6496. (`t t)
  6497. (_ nil))
  6498. (throw :skip nil))
  6499. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  6500. ;; only show them for today. Also skip done habits.
  6501. (when (and habitp
  6502. (or donep
  6503. (not (bound-and-true-p org-habit-show-habits))
  6504. (and (not todayp)
  6505. (bound-and-true-p
  6506. org-habit-show-habits-only-for-today))))
  6507. (throw :skip nil))
  6508. (save-excursion
  6509. (re-search-backward "^\\*+[ \t]+" nil t)
  6510. (goto-char (match-end 0))
  6511. (let* ((category (org-get-category))
  6512. (effort (save-match-data (or (get-text-property (point) 'effort)
  6513. (org-entry-get (point) org-effort-property))))
  6514. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6515. (inherited-tags
  6516. (or (eq org-agenda-show-inherited-tags 'always)
  6517. (and (listp org-agenda-show-inherited-tags)
  6518. (memq 'agenda org-agenda-show-inherited-tags))
  6519. (and (eq org-agenda-show-inherited-tags t)
  6520. (or (eq org-agenda-use-tag-inheritance t)
  6521. (memq 'agenda
  6522. org-agenda-use-tag-inheritance)))))
  6523. (tags (org-get-tags nil (not inherited-tags)))
  6524. (level (make-string (org-reduced-level (org-outline-level))
  6525. ?\s))
  6526. (head (buffer-substring (point) (line-end-position)))
  6527. (time
  6528. (cond
  6529. ;; No time of day designation if it is only a
  6530. ;; reminder, except for habits, which always show
  6531. ;; the time of day. Habits are an exception
  6532. ;; because if there is a time of day, that is
  6533. ;; interpreted to mean they should usually happen
  6534. ;; then, even if doing the habit was missed.
  6535. ((and
  6536. (not habitp)
  6537. (/= current schedule)
  6538. (/= current repeat))
  6539. nil)
  6540. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6541. (concat (substring s (match-beginning 1)) " "))
  6542. (t 'time)))
  6543. (item
  6544. (org-agenda-format-item
  6545. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  6546. ;; Show a reminder of a past scheduled today.
  6547. (if (and todayp pastschedp)
  6548. (format past diff)
  6549. first))
  6550. (org-add-props head nil
  6551. 'effort effort
  6552. 'effort-minutes effort-minutes)
  6553. level category tags time nil habitp))
  6554. (face (cond ((and (not habitp) pastschedp)
  6555. 'org-scheduled-previously)
  6556. ((and habitp futureschedp)
  6557. 'org-agenda-done)
  6558. (todayp 'org-scheduled-today)
  6559. (t 'org-scheduled)))
  6560. (habitp (and habitp (org-habit-parse-todo))))
  6561. (org-add-props item props
  6562. 'undone-face face
  6563. 'face (if donep 'org-agenda-done face)
  6564. 'org-marker (org-agenda-new-marker pos)
  6565. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6566. 'type (if pastschedp "past-scheduled" "scheduled")
  6567. 'date (if pastschedp schedule date)
  6568. 'ts-date schedule
  6569. 'warntime warntime
  6570. 'level level
  6571. 'effort effort 'effort-minutes effort-minutes
  6572. 'priority (if habitp (org-habit-get-priority habitp)
  6573. (+ 99 diff (org-get-priority item)))
  6574. 'org-habit-p habitp
  6575. 'todo-state todo-state)
  6576. (push item scheduled-items)))))))
  6577. (nreverse scheduled-items)))
  6578. (defun org-agenda-get-blocks ()
  6579. "Return the date-range information for agenda display."
  6580. (with-no-warnings (defvar date))
  6581. (let* ((props (list 'face nil
  6582. 'org-not-done-regexp org-not-done-regexp
  6583. 'org-todo-regexp org-todo-regexp
  6584. 'org-complex-heading-regexp org-complex-heading-regexp
  6585. 'mouse-face 'highlight
  6586. 'help-echo
  6587. (format "mouse-2 or RET jump to org file %s"
  6588. (abbreviate-file-name buffer-file-name))))
  6589. (regexp org-tr-regexp)
  6590. (d0 (calendar-absolute-from-gregorian date))
  6591. marker hdmarker ee txt d1 d2 s1 s2 category
  6592. level todo-state tags pos head donep inherited-tags
  6593. effort effort-minutes)
  6594. (goto-char (point-min))
  6595. (while (re-search-forward regexp nil t)
  6596. (catch :skip
  6597. (org-agenda-skip)
  6598. (setq pos (point))
  6599. (let ((start-time (match-string 1))
  6600. (end-time (match-string 2)))
  6601. (setq s1 (match-string 1)
  6602. s2 (match-string 2)
  6603. d1 (time-to-days
  6604. (condition-case err
  6605. (org-time-string-to-time s1)
  6606. (error
  6607. (error
  6608. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6609. s1
  6610. pos
  6611. (current-buffer)
  6612. (error-message-string err)))))
  6613. d2 (time-to-days
  6614. (condition-case err
  6615. (org-time-string-to-time s2)
  6616. (error
  6617. (error
  6618. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6619. s2
  6620. pos
  6621. (current-buffer)
  6622. (error-message-string err))))))
  6623. (when (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  6624. ;; Only allow days between the limits, because the normal
  6625. ;; date stamps will catch the limits.
  6626. (save-excursion
  6627. (setq todo-state (org-get-todo-state))
  6628. (setq donep (member todo-state org-done-keywords))
  6629. (when (and donep org-agenda-skip-timestamp-if-done)
  6630. (throw :skip t))
  6631. (setq marker (org-agenda-new-marker (point))
  6632. category (org-get-category))
  6633. (setq effort (save-match-data (or (get-text-property (point) 'effort)
  6634. (org-entry-get (point) org-effort-property))))
  6635. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6636. (if (not (re-search-backward org-outline-regexp-bol nil t))
  6637. (throw :skip nil)
  6638. (goto-char (match-beginning 0))
  6639. (setq hdmarker (org-agenda-new-marker (point))
  6640. inherited-tags
  6641. (or (eq org-agenda-show-inherited-tags 'always)
  6642. (and (listp org-agenda-show-inherited-tags)
  6643. (memq 'agenda org-agenda-show-inherited-tags))
  6644. (and (eq org-agenda-show-inherited-tags t)
  6645. (or (eq org-agenda-use-tag-inheritance t)
  6646. (memq 'agenda org-agenda-use-tag-inheritance))))
  6647. tags (org-get-tags nil (not inherited-tags)))
  6648. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  6649. (looking-at "\\*+[ \t]+\\(.*\\)")
  6650. (setq head (match-string 1))
  6651. (let ((remove-re
  6652. (if org-agenda-remove-timeranges-from-blocks
  6653. (concat
  6654. "<" (regexp-quote s1) ".*?>"
  6655. "--"
  6656. "<" (regexp-quote s2) ".*?>")
  6657. nil)))
  6658. (setq txt (org-agenda-format-item
  6659. (format
  6660. (nth (if (= d1 d2) 0 1)
  6661. org-agenda-timerange-leaders)
  6662. (1+ (- d0 d1)) (1+ (- d2 d1)))
  6663. (org-add-props head nil
  6664. 'effort effort
  6665. 'effort-minutes effort-minutes)
  6666. level category tags
  6667. (save-match-data
  6668. (let ((hhmm1 (and (string-match org-ts-regexp1 s1)
  6669. (match-string 6 s1)))
  6670. (hhmm2 (and (string-match org-ts-regexp1 s2)
  6671. (match-string 6 s2))))
  6672. (cond ((string= hhmm1 hhmm2)
  6673. (concat "<" start-time ">--<" end-time ">"))
  6674. ((and (= d1 d0) (= d2 d0))
  6675. (concat "<" start-time ">--<" end-time ">"))
  6676. ((= d1 d0)
  6677. (concat "<" start-time ">"))
  6678. ((= d2 d0)
  6679. (concat "<" end-time ">")))))
  6680. remove-re))))
  6681. (org-add-props txt props
  6682. 'org-marker marker 'org-hd-marker hdmarker
  6683. 'type "block" 'date date
  6684. 'level level
  6685. 'effort effort 'effort-minutes effort-minutes
  6686. 'todo-state todo-state
  6687. 'priority (org-get-priority txt))
  6688. (push txt ee))))
  6689. (goto-char pos)))
  6690. ;; Sort the entries by expiration date.
  6691. (nreverse ee)))
  6692. ;;; Agenda presentation and sorting
  6693. (defvar org-prefix-has-time nil
  6694. "A flag, set by `org-compile-prefix-format'.
  6695. The flag is set if the currently compiled format contains a `%t'.")
  6696. (defvar org-prefix-has-tag nil
  6697. "A flag, set by `org-compile-prefix-format'.
  6698. The flag is set if the currently compiled format contains a `%T'.")
  6699. (defvar org-prefix-has-effort nil
  6700. "A flag, set by `org-compile-prefix-format'.
  6701. The flag is set if the currently compiled format contains a `%e'.")
  6702. (defvar org-prefix-has-breadcrumbs nil
  6703. "A flag, set by `org-compile-prefix-format'.
  6704. The flag is set if the currently compiled format contains a `%b'.")
  6705. (defvar org-prefix-category-length nil
  6706. "Used by `org-compile-prefix-format' to remember the category field width.")
  6707. (defvar org-prefix-category-max-length nil
  6708. "Used by `org-compile-prefix-format' to remember the category field width.")
  6709. (defun org-agenda-get-category-icon (category)
  6710. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  6711. (cl-dolist (entry org-agenda-category-icon-alist)
  6712. (when (string-match-p (car entry) category)
  6713. (if (listp (cadr entry))
  6714. (cl-return (cadr entry))
  6715. (cl-return (apply #'create-image (cdr entry)))))))
  6716. (defun org-agenda-format-item (extra txt &optional with-level with-category tags dotime
  6717. remove-re habitp)
  6718. "Format TXT to be inserted into the agenda buffer.
  6719. In particular, add the prefix and corresponding text properties.
  6720. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  6721. WITH-LEVEL may be a string to replace the `%l' specifier.
  6722. WITH-CATEGORY (a string, a symbol or nil) may be used to overrule the default
  6723. category taken from local variable or file name. It will replace the `%c'
  6724. specifier in the format.
  6725. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  6726. TXT for sorting of this entry, and for the `%t' specifier in the format.
  6727. When DOTIME is a string, this string is searched for a time before TXT is.
  6728. TAGS can be the tags of the headline.
  6729. Any match of REMOVE-RE will be removed from TXT."
  6730. ;; We keep the org-prefix-* variable values along with a compiled
  6731. ;; formatter, so that multiple agendas existing at the same time do
  6732. ;; not step on each other toes.
  6733. ;;
  6734. ;; It was inconvenient to make these variables buffer local in
  6735. ;; Agenda buffers, because this function expects to be called with
  6736. ;; the buffer where item comes from being current, and not agenda
  6737. ;; buffer
  6738. (let* ((bindings (car org-prefix-format-compiled))
  6739. (formatter (cadr org-prefix-format-compiled)))
  6740. (cl-loop for (var value) in bindings
  6741. do (set var value))
  6742. (save-match-data
  6743. ;; Diary entries sometimes have extra whitespace at the beginning
  6744. (setq txt (org-trim txt))
  6745. ;; Fix the tags part in txt
  6746. (setq txt (org-agenda-fix-displayed-tags
  6747. txt tags
  6748. org-agenda-show-inherited-tags
  6749. org-agenda-hide-tags-regexp))
  6750. (with-no-warnings
  6751. ;; `time', `tag', `effort' are needed for the eval of the prefix format.
  6752. ;; Based on what I see in `org-compile-prefix-format', I added
  6753. ;; a few more.
  6754. (defvar breadcrumbs) (defvar category) (defvar category-icon)
  6755. (defvar effort) (defvar extra)
  6756. (defvar level) (defvar tag) (defvar time))
  6757. (let* ((category (or with-category
  6758. (if buffer-file-name
  6759. (file-name-sans-extension
  6760. (file-name-nondirectory buffer-file-name))
  6761. "")))
  6762. (category-icon (org-agenda-get-category-icon category))
  6763. (category-icon (if category-icon
  6764. (propertize " " 'display category-icon)
  6765. ""))
  6766. (effort (and (not (string= txt ""))
  6767. (get-text-property 1 'effort txt)))
  6768. (tag (if tags (nth (1- (length tags)) tags) ""))
  6769. (time-grid-trailing-characters (nth 2 org-agenda-time-grid))
  6770. (extra (or (and (not habitp) extra) ""))
  6771. time
  6772. (ts (when dotime (concat
  6773. (if (stringp dotime) dotime "")
  6774. (and org-agenda-search-headline-for-time txt))))
  6775. (time-of-day (and dotime (org-get-time-of-day ts)))
  6776. stamp plain s0 s1 s2 rtn srp l
  6777. duration breadcrumbs)
  6778. (and (derived-mode-p 'org-mode) buffer-file-name
  6779. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6780. (when (and dotime time-of-day)
  6781. ;; Extract starting and ending time and move them to prefix
  6782. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6783. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6784. (setq s0 (match-string 0 ts)
  6785. srp (and stamp (match-end 3))
  6786. s1 (match-string (if plain 1 2) ts)
  6787. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6788. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6789. ;; them, we might want to remove them there to avoid duplication.
  6790. ;; The user can turn this off with a variable.
  6791. (when (and org-prefix-has-time
  6792. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6793. (string-match (concat (regexp-quote s0) " *") txt)
  6794. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6795. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6796. (= (match-beginning 0) 0)
  6797. t))
  6798. (setq txt (replace-match "" nil nil txt))))
  6799. ;; Normalize the time(s) to 24 hour.
  6800. (when s1 (setq s1 (org-get-time-of-day s1 t)))
  6801. (when s2 (setq s2 (org-get-time-of-day s2 t)))
  6802. ;; Try to set s2 if s1 and
  6803. ;; `org-agenda-default-appointment-duration' are set
  6804. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6805. (setq s2
  6806. (org-duration-from-minutes
  6807. (+ (org-duration-to-minutes s1 t)
  6808. org-agenda-default-appointment-duration)
  6809. nil t)))
  6810. ;; Compute the duration
  6811. (when s2
  6812. (setq duration (- (org-duration-to-minutes s2)
  6813. (org-duration-to-minutes s1))))
  6814. ;; Format S1 and S2 for display.
  6815. (when s1 (setq s1 (format "%5s" (org-get-time-of-day s1 'overtime))))
  6816. (when s2 (setq s2 (org-get-time-of-day s2 'overtime))))
  6817. (when (string-match org-tag-group-re txt)
  6818. ;; Tags are in the string
  6819. (if (or (eq org-agenda-remove-tags t)
  6820. (and org-agenda-remove-tags
  6821. org-prefix-has-tag))
  6822. (setq txt (replace-match "" t t txt))
  6823. (setq txt (replace-match
  6824. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6825. (match-string 1 txt))
  6826. t t txt))))
  6827. (when remove-re
  6828. (while (string-match remove-re txt)
  6829. (setq txt (replace-match "" t t txt))))
  6830. ;; Set org-heading property on `txt' to mark the start of the
  6831. ;; heading.
  6832. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6833. ;; Prepare the variables needed in the eval of the compiled format
  6834. (when org-prefix-has-breadcrumbs
  6835. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6836. (let ((s (org-format-outline-path (org-get-outline-path)
  6837. (1- (frame-width))
  6838. nil org-agenda-breadcrumbs-separator)))
  6839. (if (eq "" s) "" (concat s org-agenda-breadcrumbs-separator))))))
  6840. (setq time (cond (s2 (concat
  6841. (org-agenda-time-of-day-to-ampm-maybe s1)
  6842. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6843. (when org-agenda-timegrid-use-ampm " ")))
  6844. (s1 (concat
  6845. (org-agenda-time-of-day-to-ampm-maybe s1)
  6846. (if org-agenda-timegrid-use-ampm
  6847. (concat time-grid-trailing-characters " ")
  6848. time-grid-trailing-characters)))
  6849. (t ""))
  6850. category (if (symbolp category) (symbol-name category) category)
  6851. level (or with-level ""))
  6852. (if (string-match org-link-bracket-re category)
  6853. (progn
  6854. (setq l (string-width (or (match-string 2) (match-string 1))))
  6855. (when (< l (or org-prefix-category-length 0))
  6856. (setq category (copy-sequence category))
  6857. (org-add-props category nil
  6858. 'extra-space (make-string
  6859. (- org-prefix-category-length l 1) ?\ ))))
  6860. (when (and org-prefix-category-max-length
  6861. (>= (length category) org-prefix-category-max-length))
  6862. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6863. ;; Evaluate the compiled format
  6864. (setq rtn (concat (eval formatter t) txt))
  6865. ;; And finally add the text properties
  6866. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6867. (org-add-props rtn nil
  6868. 'org-category category
  6869. 'tags tags
  6870. 'org-priority-highest org-priority-highest
  6871. 'org-priority-lowest org-priority-lowest
  6872. 'time-of-day time-of-day
  6873. 'duration duration
  6874. 'breadcrumbs breadcrumbs
  6875. 'txt txt
  6876. 'level level
  6877. 'time time
  6878. 'extra extra
  6879. 'format org-prefix-format-compiled
  6880. 'dotime dotime)))))
  6881. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6882. "Remove tags string from TXT, and add a modified list of tags.
  6883. The modified list may contain inherited tags, and tags matched by
  6884. `org-agenda-hide-tags-regexp' will be removed."
  6885. (when (or add-inherited hide-re)
  6886. (when (string-match org-tag-group-re txt)
  6887. (setq txt (substring txt 0 (match-beginning 0))))
  6888. (setq tags
  6889. (delq nil
  6890. (mapcar (lambda (tg)
  6891. (if (or (and hide-re (string-match hide-re tg))
  6892. (and (not add-inherited)
  6893. (get-text-property 0 'inherited tg)))
  6894. nil
  6895. tg))
  6896. tags)))
  6897. (when tags
  6898. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6899. i)
  6900. (setq txt (concat txt " :"
  6901. (mapconcat
  6902. (lambda (x)
  6903. (setq i (get-text-property 0 'inherited x))
  6904. (if (and have-i (not i))
  6905. (progn
  6906. (setq have-i nil)
  6907. (concat ":" x))
  6908. x))
  6909. tags ":")
  6910. (if have-i "::" ":"))))))
  6911. txt)
  6912. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6913. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6914. "Add a time-grid for agenda items which need it.
  6915. LIST is the list of agenda items formatted by `org-agenda-list'.
  6916. NDAYS is the span of the current agenda view.
  6917. TODAYP is t when the current agenda view is on today."
  6918. (catch 'exit
  6919. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6920. ((and todayp (member 'today (car org-agenda-time-grid))))
  6921. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6922. ((member 'weekly (car org-agenda-time-grid)))
  6923. (t (throw 'exit list)))
  6924. (let* ((have (delq nil (mapcar
  6925. (lambda (x) (get-text-property 1 'time-of-day x))
  6926. list)))
  6927. (string (nth 3 org-agenda-time-grid))
  6928. (gridtimes (nth 1 org-agenda-time-grid))
  6929. (req (car org-agenda-time-grid))
  6930. (remove (member 'remove-match req))
  6931. new time)
  6932. (when (and (member 'require-timed req) (not have))
  6933. ;; don't show empty grid
  6934. (throw 'exit list))
  6935. (while (setq time (pop gridtimes))
  6936. (unless (and remove (member time have))
  6937. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6938. (push (org-agenda-format-item
  6939. nil string nil "" nil
  6940. (concat (substring time 0 -2) ":" (substring time -2)))
  6941. new)
  6942. (put-text-property
  6943. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6944. (when (and todayp org-agenda-show-current-time-in-grid)
  6945. (push (org-agenda-format-item
  6946. nil org-agenda-current-time-string nil "" nil
  6947. (format-time-string "%H:%M "))
  6948. new)
  6949. (put-text-property
  6950. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6951. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6952. (append new list)
  6953. (append list new)))))
  6954. (defun org-compile-prefix-format (key)
  6955. "Compile the prefix format into a Lisp form that can be evaluated.
  6956. KEY is the agenda type (see `org-agenda-prefix-format').
  6957. The resulting form and associated variable bindings is returned
  6958. and stored in the variable `org-prefix-format-compiled'."
  6959. (setq org-prefix-has-time nil
  6960. org-prefix-has-tag nil
  6961. org-prefix-category-length nil
  6962. org-prefix-has-effort nil
  6963. org-prefix-has-breadcrumbs nil)
  6964. (let ((s (cond
  6965. ((stringp org-agenda-prefix-format)
  6966. org-agenda-prefix-format)
  6967. ((assq key org-agenda-prefix-format)
  6968. (cdr (assq key org-agenda-prefix-format)))
  6969. (t " %-12:c%?-12t% s")))
  6970. (start 0)
  6971. varform vars var c f opt) ;; e
  6972. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+?)\\)"
  6973. s start)
  6974. (setq var (or (cdr (assoc (match-string 4 s)
  6975. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6976. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6977. 'eval)
  6978. c (or (match-string 3 s) "")
  6979. opt (match-beginning 1)
  6980. start (1+ (match-beginning 0)))
  6981. (cl-case var
  6982. (time (setq org-prefix-has-time t))
  6983. (tag (setq org-prefix-has-tag t))
  6984. (effort (setq org-prefix-has-effort t))
  6985. (breadcrumbs (setq org-prefix-has-breadcrumbs t)))
  6986. (setq f (concat "%" (match-string 2 s) "s"))
  6987. (when (eq var 'category)
  6988. (setq org-prefix-category-length
  6989. (floor (abs (string-to-number (match-string 2 s)))))
  6990. (setq org-prefix-category-max-length
  6991. (let ((x (match-string 2 s)))
  6992. (save-match-data
  6993. (and (string-match "\\.[0-9]+" x)
  6994. (string-to-number (substring (match-string 0 x) 1)))))))
  6995. (if (eq var 'eval)
  6996. (setq varform `(format ,f (org-eval ,(read (substring s (match-beginning 4))))))
  6997. (if opt
  6998. (setq varform
  6999. `(if (member ,var '("" nil))
  7000. ""
  7001. (format ,f (concat ,var ,c))))
  7002. (setq varform
  7003. `(format ,f (if (member ,var '("" nil)) ""
  7004. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  7005. (if (eq var 'eval)
  7006. (setf (substring s (match-beginning 0)
  7007. (+ (match-beginning 4)
  7008. (length (format "%S" (read (substring s (match-beginning 4)))))))
  7009. "%s")
  7010. (setq s (replace-match "%s" t nil s)))
  7011. (push varform vars))
  7012. (setq vars (nreverse vars))
  7013. (with-current-buffer (or org-agenda-buffer (current-buffer))
  7014. (setq org-prefix-format-compiled
  7015. (list
  7016. `((org-prefix-has-time ,org-prefix-has-time)
  7017. (org-prefix-has-tag ,org-prefix-has-tag)
  7018. (org-prefix-category-length ,org-prefix-category-length)
  7019. (org-prefix-has-effort ,org-prefix-has-effort)
  7020. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  7021. `(format ,s ,@vars))))))
  7022. (defun org-set-sorting-strategy (key)
  7023. (setq org-agenda-sorting-strategy-selected
  7024. (if (symbolp (car org-agenda-sorting-strategy))
  7025. ;; the old format
  7026. org-agenda-sorting-strategy
  7027. (or (cdr (assq key org-agenda-sorting-strategy))
  7028. (cdr (assq 'agenda org-agenda-sorting-strategy))
  7029. '(time-up category-keep priority-down)))))
  7030. (defun org-get-time-of-day (s &optional string)
  7031. "Check string S for a time of day.
  7032. If found, return it as a military time number between 0 and 2400.
  7033. If not found, return nil.
  7034. The optional STRING argument forces conversion into a 5 character wide string
  7035. HH:MM. When it is `overtime', any time above 24:00 is turned into \"+H:MM\"
  7036. where H:MM is the duration above midnight."
  7037. (let ((case-fold-search t)
  7038. (time-regexp
  7039. (rx word-start
  7040. (group (opt (any "012")) digit) ;group 1: hours
  7041. (or (and ":" (group (any "012345") digit) ;group 2: minutes
  7042. (opt (group (or "am" "pm")))) ;group 3: am/pm
  7043. ;; Special "HHam/pm" case.
  7044. (group-n 3 (or "am" "pm")))
  7045. word-end)))
  7046. (save-match-data
  7047. (when (and (string-match time-regexp s)
  7048. (not (eq 'org-link (get-text-property 1 'face s))))
  7049. (let ((hours
  7050. (let* ((ampm (and (match-end 3) (downcase (match-string 3 s))))
  7051. (am-p (equal ampm "am")))
  7052. (pcase (string-to-number (match-string 1 s))
  7053. ((and (guard (not ampm)) h) h)
  7054. (12 (if am-p 0 12))
  7055. (h (+ h (if am-p 0 12))))))
  7056. (minutes
  7057. (if (match-end 2)
  7058. (string-to-number (match-string 2 s))
  7059. 0)))
  7060. (pcase string
  7061. (`nil (+ minutes (* hours 100)))
  7062. ((and `overtime
  7063. (guard (or (> hours 24)
  7064. (and (= hours 24)
  7065. (> minutes 0)))))
  7066. (format "+%d:%02d" (- hours 24) minutes))
  7067. ((guard org-agenda-time-leading-zero)
  7068. (format "%02d:%02d" hours minutes))
  7069. (_
  7070. (format "%d:%02d" hours minutes))))))))
  7071. (defvar org-agenda-before-sorting-filter-function nil
  7072. "Function to be applied to agenda items prior to sorting.
  7073. Prior to sorting also means just before they are inserted into the agenda.
  7074. To aid sorting, you may revisit the original entries and add more text
  7075. properties which will later be used by the sorting functions.
  7076. The function should take a string argument, an agenda line.
  7077. It has access to the text properties in that line, which contain among
  7078. other things, the property `org-hd-marker' that points to the entry
  7079. where the line comes from. Note that not all lines going into the agenda
  7080. have this property, only most.
  7081. The function should return the modified string. It is probably best
  7082. to ONLY change text properties.
  7083. You can also use this function as a filter, by returning nil for lines
  7084. you don't want to have in the agenda at all. For this application, you
  7085. could bind the variable in the options section of a custom command.")
  7086. (defun org-agenda-finalize-entries (list &optional type)
  7087. "Sort, limit and concatenate the LIST of agenda items.
  7088. The optional argument TYPE tells the agenda type."
  7089. (let ((max-effort (cond ((listp org-agenda-max-effort)
  7090. (cdr (assoc type org-agenda-max-effort)))
  7091. (t org-agenda-max-effort)))
  7092. (max-todo (cond ((listp org-agenda-max-todos)
  7093. (cdr (assoc type org-agenda-max-todos)))
  7094. (t org-agenda-max-todos)))
  7095. (max-tags (cond ((listp org-agenda-max-tags)
  7096. (cdr (assoc type org-agenda-max-tags)))
  7097. (t org-agenda-max-tags)))
  7098. (max-entries (cond ((listp org-agenda-max-entries)
  7099. (cdr (assoc type org-agenda-max-entries)))
  7100. (t org-agenda-max-entries))))
  7101. (when org-agenda-before-sorting-filter-function
  7102. (setq list
  7103. (delq nil
  7104. (mapcar
  7105. org-agenda-before-sorting-filter-function list))))
  7106. (setq list (mapcar #'org-agenda-highlight-todo list)
  7107. list (mapcar #'identity (sort list #'org-entries-lessp)))
  7108. (when max-effort
  7109. (setq list (org-agenda-limit-entries
  7110. list 'effort-minutes max-effort
  7111. (lambda (e) (or e (if org-agenda-sort-noeffort-is-high
  7112. 32767 -1))))))
  7113. (when max-todo
  7114. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  7115. (when max-tags
  7116. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  7117. (when max-entries
  7118. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  7119. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  7120. (setq list (mapcar #'org-agenda--mark-blocked-entry list)))
  7121. (mapconcat #'identity list "\n")))
  7122. (defun org-agenda-limit-entries (list prop limit &optional fn)
  7123. "Limit the number of agenda entries."
  7124. (let ((include (and limit (< limit 0))))
  7125. (if limit
  7126. (let ((fun (or fn (lambda (p) (when p 1))))
  7127. (lim 0))
  7128. (delq nil
  7129. (mapcar
  7130. (lambda (e)
  7131. (let ((pval (funcall
  7132. fun (get-text-property (1- (length e))
  7133. prop e))))
  7134. (when pval (setq lim (+ lim pval)))
  7135. (cond ((and pval (<= lim (abs limit))) e)
  7136. ((and include (not pval)) e))))
  7137. list)))
  7138. list)))
  7139. (defun org-agenda-limit-interactively (remove)
  7140. "In agenda, interactively limit entries to various maximums."
  7141. (interactive "P")
  7142. (if remove
  7143. (progn (setq org-agenda-max-entries nil
  7144. org-agenda-max-todos nil
  7145. org-agenda-max-tags nil
  7146. org-agenda-max-effort nil)
  7147. (org-agenda-redo))
  7148. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  7149. (msg (cond ((= max ?E) "How many minutes? ")
  7150. ((= max ?e) "How many entries? ")
  7151. ((= max ?t) "How many TODO entries? ")
  7152. ((= max ?T) "How many tagged entries? ")
  7153. (t (user-error "Wrong input"))))
  7154. (num (string-to-number (read-from-minibuffer msg))))
  7155. (cond ((equal max ?e)
  7156. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  7157. ((equal max ?t)
  7158. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  7159. ((equal max ?T)
  7160. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  7161. ((equal max ?E)
  7162. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  7163. (org-agenda-fit-window-to-buffer))
  7164. (defun org-agenda-highlight-todo (x)
  7165. (let ((org-done-keywords org-done-keywords-for-agenda)
  7166. (case-fold-search nil)
  7167. re)
  7168. (if (eq x 'line)
  7169. (save-excursion
  7170. (beginning-of-line 1)
  7171. (setq re (org-get-at-bol 'org-todo-regexp))
  7172. (goto-char (or (text-property-any (line-beginning-position)
  7173. (line-end-position)
  7174. 'org-heading t)
  7175. (point)))
  7176. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  7177. (add-text-properties (match-beginning 0) (match-end 1)
  7178. (list 'face (org-get-todo-face 1)))
  7179. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  7180. (delete-region (match-beginning 1) (1- (match-end 0)))
  7181. (goto-char (match-beginning 1))
  7182. (insert (format org-agenda-todo-keyword-format s)))))
  7183. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  7184. (setq re (get-text-property 0 'org-todo-regexp x))
  7185. (when (and re
  7186. ;; Test `pl' because if there's no heading content,
  7187. ;; there's no point matching to highlight. Note
  7188. ;; that if we didn't test `pl' first, and there
  7189. ;; happened to be no keyword from `org-todo-regexp'
  7190. ;; on this heading line, then the `equal' comparison
  7191. ;; afterwards would spuriously succeed in the case
  7192. ;; where `pl' is nil -- causing an args-out-of-range
  7193. ;; error when we try to add text properties to text
  7194. ;; that isn't there.
  7195. pl
  7196. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  7197. x pl)
  7198. pl))
  7199. (add-text-properties
  7200. (or (match-end 1) (match-end 0)) (match-end 0)
  7201. (list 'face (org-get-todo-face (match-string 2 x)))
  7202. x)
  7203. (when (match-end 1)
  7204. (setq x
  7205. (concat
  7206. (substring x 0 (match-end 1))
  7207. (unless (string= org-agenda-todo-keyword-format "")
  7208. (format org-agenda-todo-keyword-format
  7209. (match-string 2 x)))
  7210. (unless (string= org-agenda-todo-keyword-format "")
  7211. ;; Remove `display' property as the icon could leak
  7212. ;; on the white space.
  7213. (org-add-props " " (org-plist-delete (text-properties-at 0 x)
  7214. 'display)))
  7215. (substring x (match-end 3)))))))
  7216. x)))
  7217. (defsubst org-cmp-values (a b property)
  7218. "Compare the numeric value of text PROPERTY for string A and B."
  7219. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  7220. (pb (or (get-text-property (1- (length b)) property b) 0)))
  7221. (cond ((> pa pb) +1)
  7222. ((< pa pb) -1))))
  7223. (defsubst org-cmp-effort (a b)
  7224. "Compare the effort values of string A and B."
  7225. (let* ((def (if org-agenda-sort-noeffort-is-high 32767 -1))
  7226. ;; `effort-minutes' property is not directly accessible from
  7227. ;; the strings, but is stored as a property in `txt'.
  7228. (ea (or (get-text-property
  7229. 0 'effort-minutes (get-text-property 0 'txt a))
  7230. def))
  7231. (eb (or (get-text-property
  7232. 0 'effort-minutes (get-text-property 0 'txt b))
  7233. def)))
  7234. (cond ((> ea eb) +1)
  7235. ((< ea eb) -1))))
  7236. (defsubst org-cmp-category (a b)
  7237. "Compare the string values of categories of strings A and B."
  7238. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  7239. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  7240. (cond ((string-lessp ca cb) -1)
  7241. ((string-lessp cb ca) +1))))
  7242. (defsubst org-cmp-todo-state (a b)
  7243. "Compare the todo states of strings A and B."
  7244. (let* ((ma (or (get-text-property 1 'org-marker a)
  7245. (get-text-property 1 'org-hd-marker a)))
  7246. (mb (or (get-text-property 1 'org-marker b)
  7247. (get-text-property 1 'org-hd-marker b)))
  7248. (fa (and ma (marker-buffer ma)))
  7249. (fb (and mb (marker-buffer mb)))
  7250. (todo-kwds
  7251. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  7252. (and fb (with-current-buffer fb org-todo-keywords-1))))
  7253. (ta (or (get-text-property 1 'todo-state a) ""))
  7254. (tb (or (get-text-property 1 'todo-state b) ""))
  7255. (la (- (length (member ta todo-kwds))))
  7256. (lb (- (length (member tb todo-kwds))))
  7257. (donepa (member ta org-done-keywords-for-agenda))
  7258. (donepb (member tb org-done-keywords-for-agenda)))
  7259. (cond ((and donepa (not donepb)) -1)
  7260. ((and (not donepa) donepb) +1)
  7261. ((< la lb) -1)
  7262. ((< lb la) +1))))
  7263. (defsubst org-cmp-alpha (a b)
  7264. "Compare the headlines, alphabetically."
  7265. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  7266. (plb (text-property-any 0 (length b) 'org-heading t b))
  7267. (ta (and pla (substring a pla)))
  7268. (tb (and plb (substring b plb)))
  7269. (case-fold-search nil))
  7270. (when pla
  7271. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  7272. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  7273. ta)
  7274. (setq ta (substring ta (match-end 0))))
  7275. (setq ta (downcase ta)))
  7276. (when plb
  7277. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  7278. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  7279. tb)
  7280. (setq tb (substring tb (match-end 0))))
  7281. (setq tb (downcase tb)))
  7282. (cond ((not (or ta tb)) nil)
  7283. ((not ta) +1)
  7284. ((not tb) -1)
  7285. ((string-lessp ta tb) -1)
  7286. ((string-lessp tb ta) +1))))
  7287. (defsubst org-cmp-tag (a b)
  7288. "Compare the string values of the first tags of A and B."
  7289. (let ((ta (car (last (get-text-property 1 'tags a))))
  7290. (tb (car (last (get-text-property 1 'tags b)))))
  7291. (cond ((not (or ta tb)) nil)
  7292. ((not ta) +1)
  7293. ((not tb) -1)
  7294. ((string-lessp ta tb) -1)
  7295. ((string-lessp tb ta) +1))))
  7296. (defsubst org-cmp-time (a b)
  7297. "Compare the time-of-day values of strings A and B."
  7298. (let* ((def (if org-agenda-sort-notime-is-late 9901 -1))
  7299. (ta (or (get-text-property 1 'time-of-day a) def))
  7300. (tb (or (get-text-property 1 'time-of-day b) def)))
  7301. (cond ((< ta tb) -1)
  7302. ((< tb ta) +1))))
  7303. (defsubst org-cmp-ts (a b type)
  7304. "Compare the timestamps values of entries A and B.
  7305. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  7306. \"timestamp_ia\", compare within each of these type. When TYPE
  7307. is the empty string, compare all timestamps without respect of
  7308. their type."
  7309. (let* ((def (if org-agenda-sort-notime-is-late 99999999 -1))
  7310. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  7311. (get-text-property 1 'ts-date a))
  7312. def))
  7313. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  7314. (get-text-property 1 'ts-date b))
  7315. def)))
  7316. (cond ((if ta (and tb (< ta tb)) tb) -1)
  7317. ((if tb (and ta (< tb ta)) ta) +1))))
  7318. (defsubst org-cmp-habit-p (a b)
  7319. "Compare the todo states of strings A and B."
  7320. (let ((ha (get-text-property 1 'org-habit-p a))
  7321. (hb (get-text-property 1 'org-habit-p b)))
  7322. (cond ((and ha (not hb)) -1)
  7323. ((and (not ha) hb) +1))))
  7324. (defun org-entries-lessp (a b)
  7325. "Predicate for sorting agenda entries."
  7326. ;; The following variables will be used when the form is evaluated.
  7327. ;; So even though the compiler complains, keep them.
  7328. (let ((ss org-agenda-sorting-strategy-selected))
  7329. (org-dlet
  7330. ((timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  7331. (org-cmp-ts a b "")))
  7332. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  7333. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  7334. (org-cmp-ts a b "scheduled")))
  7335. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  7336. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  7337. (org-cmp-ts a b "deadline")))
  7338. (deadline-down (if deadline-up (- deadline-up) nil))
  7339. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  7340. (org-cmp-ts a b "timestamp_ia")))
  7341. (tsia-down (if tsia-up (- tsia-up) nil))
  7342. (ts-up (and (org-em 'ts-up 'ts-down ss)
  7343. (org-cmp-ts a b "timestamp")))
  7344. (ts-down (if ts-up (- ts-up) nil))
  7345. (time-up (and (org-em 'time-up 'time-down ss)
  7346. (org-cmp-time a b)))
  7347. (time-down (if time-up (- time-up) nil))
  7348. (stats-up (and (org-em 'stats-up 'stats-down ss)
  7349. (org-cmp-values a b 'org-stats)))
  7350. (stats-down (if stats-up (- stats-up) nil))
  7351. (priority-up (and (org-em 'priority-up 'priority-down ss)
  7352. (org-cmp-values a b 'priority)))
  7353. (priority-down (if priority-up (- priority-up) nil))
  7354. (effort-up (and (org-em 'effort-up 'effort-down ss)
  7355. (org-cmp-effort a b)))
  7356. (effort-down (if effort-up (- effort-up) nil))
  7357. (category-up (and (or (org-em 'category-up 'category-down ss)
  7358. (memq 'category-keep ss))
  7359. (org-cmp-category a b)))
  7360. (category-down (if category-up (- category-up) nil))
  7361. (category-keep (if category-up +1 nil))
  7362. (tag-up (and (org-em 'tag-up 'tag-down ss)
  7363. (org-cmp-tag a b)))
  7364. (tag-down (if tag-up (- tag-up) nil))
  7365. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  7366. (org-cmp-todo-state a b)))
  7367. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  7368. (habit-up (and (org-em 'habit-up 'habit-down ss)
  7369. (org-cmp-habit-p a b)))
  7370. (habit-down (if habit-up (- habit-up) nil))
  7371. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  7372. (org-cmp-alpha a b)))
  7373. (alpha-down (if alpha-up (- alpha-up) nil))
  7374. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  7375. user-defined-up user-defined-down)
  7376. (when (and need-user-cmp org-agenda-cmp-user-defined
  7377. (functionp org-agenda-cmp-user-defined))
  7378. (setq user-defined-up
  7379. (funcall org-agenda-cmp-user-defined a b)
  7380. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  7381. (cdr (assoc
  7382. (eval (cons 'or org-agenda-sorting-strategy-selected) t)
  7383. '((-1 . t) (1 . nil) (nil . nil)))))))
  7384. ;;; Agenda restriction lock
  7385. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  7386. "Overlay to mark the headline to which agenda commands are restricted.")
  7387. (overlay-put org-agenda-restriction-lock-overlay
  7388. 'face 'org-agenda-restriction-lock)
  7389. (overlay-put org-agenda-restriction-lock-overlay
  7390. 'help-echo "Agendas are currently limited to this subtree.")
  7391. (delete-overlay org-agenda-restriction-lock-overlay)
  7392. (defun org-agenda-set-restriction-lock-from-agenda (arg)
  7393. "Set the restriction lock to the agenda item at point from within the agenda.
  7394. When called with a `\\[universal-argument]' prefix, restrict to
  7395. the file which contains the item.
  7396. Argument ARG is the prefix argument."
  7397. (interactive "P")
  7398. (unless (derived-mode-p 'org-agenda-mode)
  7399. (user-error "Not in an Org agenda buffer"))
  7400. (let* ((marker (or (org-get-at-bol 'org-marker)
  7401. (org-agenda-error)))
  7402. (buffer (marker-buffer marker))
  7403. (pos (marker-position marker)))
  7404. (with-current-buffer buffer
  7405. (goto-char pos)
  7406. (org-agenda-set-restriction-lock arg))))
  7407. ;;;###autoload
  7408. (defun org-agenda-set-restriction-lock (&optional type)
  7409. "Set restriction lock for agenda to current subtree or file.
  7410. When in a restricted subtree, remove it.
  7411. The restriction will span over the entire file if TYPE is `file',
  7412. or if TYPE is (4), or if the cursor is before the first headline
  7413. in the file. Otherwise, only apply the restriction to the current
  7414. subtree."
  7415. (interactive "P")
  7416. (if (and org-agenda-overriding-restriction
  7417. (member org-agenda-restriction-lock-overlay
  7418. (overlays-at (point)))
  7419. (equal (overlay-start org-agenda-restriction-lock-overlay)
  7420. (point)))
  7421. (org-agenda-remove-restriction-lock 'noupdate)
  7422. (org-agenda-remove-restriction-lock 'noupdate)
  7423. (and (equal type '(4)) (setq type 'file))
  7424. (setq type (cond
  7425. (type type)
  7426. ((org-at-heading-p) 'subtree)
  7427. ((condition-case nil (org-back-to-heading t) (error nil))
  7428. 'subtree)
  7429. (t 'file)))
  7430. (if (eq type 'subtree)
  7431. (progn
  7432. (setq org-agenda-restrict (current-buffer))
  7433. (setq org-agenda-overriding-restriction 'subtree)
  7434. (put 'org-agenda-files 'org-restrict
  7435. (list (buffer-file-name (buffer-base-buffer))))
  7436. (org-back-to-heading t)
  7437. (move-overlay org-agenda-restriction-lock-overlay
  7438. (point)
  7439. (if org-agenda-restriction-lock-highlight-subtree
  7440. (save-excursion (org-end-of-subtree t t) (point))
  7441. (line-end-position)))
  7442. (move-marker org-agenda-restrict-begin (point))
  7443. (move-marker org-agenda-restrict-end
  7444. (save-excursion (org-end-of-subtree t t)))
  7445. (message "Locking agenda restriction to subtree"))
  7446. (put 'org-agenda-files 'org-restrict
  7447. (list (buffer-file-name (buffer-base-buffer))))
  7448. (setq org-agenda-restrict t)
  7449. (setq org-agenda-overriding-restriction 'file)
  7450. (move-marker org-agenda-restrict-begin nil)
  7451. (move-marker org-agenda-restrict-end nil)
  7452. (message "Locking agenda restriction to file"))
  7453. (setq current-prefix-arg nil))
  7454. (org-agenda-maybe-redo))
  7455. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  7456. "Remove agenda restriction lock."
  7457. (interactive "P")
  7458. (if (not org-agenda-restrict)
  7459. (message "No agenda restriction to remove.")
  7460. (delete-overlay org-agenda-restriction-lock-overlay)
  7461. (delete-overlay org-speedbar-restriction-lock-overlay)
  7462. (setq org-agenda-overriding-restriction nil)
  7463. (setq org-agenda-restrict nil)
  7464. (put 'org-agenda-files 'org-restrict nil)
  7465. (move-marker org-agenda-restrict-begin nil)
  7466. (move-marker org-agenda-restrict-end nil)
  7467. (setq current-prefix-arg nil)
  7468. (message "Agenda restriction lock removed")
  7469. (or noupdate (org-agenda-maybe-redo))))
  7470. (defun org-agenda-maybe-redo ()
  7471. "If there is any window showing the agenda view, update it."
  7472. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  7473. org-agenda-buffer-name)
  7474. t))
  7475. (w0 (selected-window)))
  7476. (when w
  7477. (select-window w)
  7478. (org-agenda-redo)
  7479. (select-window w0)
  7480. (if org-agenda-overriding-restriction
  7481. (message "Agenda view shifted to new %s restriction"
  7482. org-agenda-overriding-restriction)
  7483. (message "Agenda restriction lock removed")))))
  7484. ;;; Agenda commands
  7485. (defun org-agenda-check-type (error &rest types)
  7486. "Check if agenda buffer or component is of allowed type.
  7487. If ERROR is non-nil, throw an error, otherwise just return nil.
  7488. Allowed types are `agenda' `todo' `tags' `search'."
  7489. (cond ((not org-agenda-type)
  7490. (error "No Org agenda currently displayed"))
  7491. ((memq org-agenda-type types) t)
  7492. (error
  7493. (error "Not allowed in '%s'-type agenda buffer or component" org-agenda-type))
  7494. (t nil)))
  7495. (defun org-agenda-Quit ()
  7496. "Exit the agenda, killing the agenda buffer.
  7497. Like `org-agenda-quit', but kill the buffer even when
  7498. `org-agenda-sticky' is non-nil."
  7499. (interactive)
  7500. (org-agenda--quit))
  7501. (defun org-agenda-quit ()
  7502. "Exit the agenda.
  7503. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  7504. instead of killing it.
  7505. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  7506. the pre-agenda window configuration.
  7507. When column view is active, exit column view instead of the
  7508. agenda."
  7509. (interactive)
  7510. (org-agenda--quit org-agenda-sticky))
  7511. (defun org-agenda--quit (&optional bury)
  7512. (if org-agenda-columns-active
  7513. (org-columns-quit)
  7514. (let ((wconf org-agenda-pre-window-conf)
  7515. (buf (current-buffer))
  7516. (org-agenda-last-indirect-window
  7517. (and (eq org-indirect-buffer-display 'other-window)
  7518. org-agenda-last-indirect-buffer
  7519. (get-buffer-window org-agenda-last-indirect-buffer))))
  7520. (cond
  7521. ((eq org-agenda-window-setup 'other-frame)
  7522. (delete-frame))
  7523. ((eq org-agenda-window-setup 'other-tab)
  7524. (if (fboundp 'tab-bar-close-tab)
  7525. (tab-bar-close-tab)
  7526. (user-error "Your version of Emacs does not have tab bar mode support")))
  7527. ((and org-agenda-restore-windows-after-quit
  7528. wconf)
  7529. ;; Maybe restore the pre-agenda window configuration. Reset
  7530. ;; `org-agenda-pre-window-conf' before running
  7531. ;; `set-window-configuration', which loses the current buffer.
  7532. (setq org-agenda-pre-window-conf nil)
  7533. (set-window-configuration wconf))
  7534. (t
  7535. (when org-agenda-last-indirect-window
  7536. (delete-window org-agenda-last-indirect-window))
  7537. (and (not (eq org-agenda-window-setup 'current-window))
  7538. (not (one-window-p))
  7539. (delete-window))))
  7540. (if bury
  7541. ;; Set the agenda buffer as the current buffer instead of
  7542. ;; passing it as an argument to `bury-buffer' so that
  7543. ;; `bury-buffer' removes it from the window.
  7544. (with-current-buffer buf
  7545. (bury-buffer))
  7546. (kill-buffer buf)
  7547. (setq org-agenda-archives-mode nil
  7548. org-agenda-buffer nil)))))
  7549. (defun org-agenda-exit ()
  7550. "Exit the agenda, killing Org buffers loaded by the agenda.
  7551. Like `org-agenda-Quit', but kill any buffers that were created by
  7552. the agenda. Org buffers visited directly by the user will not be
  7553. touched. Also, exit the agenda even if it is in column view."
  7554. (interactive)
  7555. (when org-agenda-columns-active
  7556. (org-columns-quit))
  7557. (org-release-buffers org-agenda-new-buffers)
  7558. (setq org-agenda-new-buffers nil)
  7559. (org-agenda-Quit))
  7560. (defun org-agenda-kill-all-agenda-buffers ()
  7561. "Kill all buffers in `org-agenda-mode'.
  7562. This is used when toggling sticky agendas."
  7563. (interactive)
  7564. (let (blist)
  7565. (dolist (buf (buffer-list))
  7566. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  7567. (push buf blist)))
  7568. (mapc #'kill-buffer blist)))
  7569. (defun org-agenda-execute (arg)
  7570. "Execute another agenda command, keeping same window.
  7571. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  7572. in the agenda."
  7573. (interactive "P")
  7574. (let ((org-agenda-window-setup 'current-window))
  7575. (org-agenda arg)))
  7576. (defun org-agenda-redo (&optional all)
  7577. "Rebuild possibly ALL agenda view(s) in the current buffer."
  7578. (interactive "P")
  7579. (defvar org-agenda-tag-filter-while-redo) ;FIXME: Where is this var used?
  7580. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  7581. (cpa (unless (eq all t) current-prefix-arg))
  7582. (org-agenda-doing-sticky-redo org-agenda-sticky)
  7583. (org-agenda-sticky nil)
  7584. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  7585. org-agenda-buffer-name))
  7586. (org-agenda-keep-modes t)
  7587. (tag-filter org-agenda-tag-filter)
  7588. (tag-preset (assoc-default 'tag org-agenda-filters-preset))
  7589. (top-hl-filter org-agenda-top-headline-filter)
  7590. (cat-filter org-agenda-category-filter)
  7591. (cat-preset (assoc-default 'category org-agenda-filters-preset))
  7592. (re-filter org-agenda-regexp-filter)
  7593. (re-preset (assoc-default 'regexp org-agenda-filters-preset))
  7594. (effort-filter org-agenda-effort-filter)
  7595. (effort-preset (assoc-default 'effort org-agenda-filters-preset))
  7596. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  7597. (cols org-agenda-columns-active)
  7598. (line (org-current-line))
  7599. (window-line (- line (org-current-line (window-start))))
  7600. (lprops (get-text-property p 'org-lprops))
  7601. (redo-cmd (get-text-property p 'org-redo-cmd))
  7602. (last-args (get-text-property p 'org-last-args))
  7603. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  7604. (org-agenda-overriding-cmd-arguments
  7605. (unless (eq all t)
  7606. (cond ((listp last-args)
  7607. (cons (or cpa (car last-args)) (cdr last-args)))
  7608. ((stringp last-args)
  7609. last-args))))
  7610. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  7611. (and cols (org-columns-quit))
  7612. (message "Rebuilding agenda buffer...")
  7613. (if series-redo-cmd
  7614. (eval series-redo-cmd t)
  7615. (cl-progv
  7616. (mapcar #'car lprops)
  7617. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  7618. (eval redo-cmd t))
  7619. (let ((inhibit-read-only t))
  7620. (add-text-properties (point-min) (point-max) `(org-lprops ,lprops))))
  7621. (setq org-agenda-undo-list nil
  7622. org-agenda-pending-undo-list nil
  7623. org-agenda-tag-filter tag-filter
  7624. org-agenda-category-filter cat-filter
  7625. org-agenda-regexp-filter re-filter
  7626. org-agenda-effort-filter effort-filter
  7627. org-agenda-top-headline-filter top-hl-filter)
  7628. (message "Rebuilding agenda buffer...done")
  7629. (let ((tag (or tag-filter tag-preset))
  7630. (cat (or cat-filter cat-preset))
  7631. (effort (or effort-filter effort-preset))
  7632. (re (or re-filter re-preset)))
  7633. (when tag (org-agenda-filter-apply tag 'tag t))
  7634. (when cat (org-agenda-filter-apply cat 'category))
  7635. (when effort (org-agenda-filter-apply effort 'effort))
  7636. (when re (org-agenda-filter-apply re 'regexp)))
  7637. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  7638. (and cols (called-interactively-p 'any) (org-agenda-columns))
  7639. (org-goto-line line)
  7640. (when (called-interactively-p 'any) (recenter window-line))))
  7641. (defun org-agenda-redo-all (&optional exhaustive)
  7642. "Rebuild all agenda views in the current buffer.
  7643. With a prefix argument, do so in all agenda buffers."
  7644. (interactive "P")
  7645. (if exhaustive
  7646. (dolist (buffer (buffer-list))
  7647. (with-current-buffer buffer
  7648. (when (derived-mode-p 'org-agenda-mode)
  7649. (org-agenda-redo t))))
  7650. (org-agenda-redo t)))
  7651. (defvar org-global-tags-completion-table nil)
  7652. (defvar org-agenda-filter-form nil)
  7653. (defvar org-agenda-filtered-by-category nil)
  7654. (defsubst org-agenda-get-category ()
  7655. "Return the category of the agenda line."
  7656. (org-get-at-bol 'org-category))
  7657. (defun org-agenda-filter-by-category (strip)
  7658. "Filter lines in the agenda buffer that have a specific category.
  7659. The category is that of the current line.
  7660. With a `\\[universal-argument]' prefix argument, exclude the lines of that category.
  7661. When there is already a category filter in place, this command removes the
  7662. filter."
  7663. (interactive "P")
  7664. (if (and org-agenda-filtered-by-category
  7665. org-agenda-category-filter)
  7666. (org-agenda-filter-show-all-cat)
  7667. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  7668. (cond
  7669. ((and cat strip)
  7670. (org-agenda-filter-apply
  7671. (push (concat "-" cat) org-agenda-category-filter) 'category))
  7672. (cat
  7673. (org-agenda-filter-apply
  7674. (setq org-agenda-category-filter
  7675. (list (concat "+" cat)))
  7676. 'category))
  7677. (t (error "No category at point"))))))
  7678. (defun org-find-top-headline (&optional pos)
  7679. "Find the topmost parent headline and return it.
  7680. POS when non-nil is the marker or buffer position to start the
  7681. search from."
  7682. (save-excursion
  7683. (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
  7684. (when pos (goto-char pos))
  7685. ;; Skip up to the topmost parent.
  7686. (while (org-up-heading-safe))
  7687. (ignore-errors
  7688. (replace-regexp-in-string
  7689. "^\\[[0-9]+/[0-9]+\\] *\\|^\\[%[0-9]+\\] *" ""
  7690. (nth 4 (org-heading-components)))))))
  7691. (defvar org-agenda-filtered-by-top-headline nil)
  7692. (defun org-agenda-filter-by-top-headline (strip)
  7693. "Keep only those lines that are descendants from the same top headline.
  7694. The top headline is that of the current line. With prefix arg STRIP, hide
  7695. all lines of the category at point."
  7696. (interactive "P")
  7697. (if org-agenda-filtered-by-top-headline
  7698. (progn
  7699. (setq org-agenda-filtered-by-top-headline nil
  7700. org-agenda-top-headline-filter nil)
  7701. (org-agenda-filter-show-all-top-filter))
  7702. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  7703. (if toph (org-agenda-filter-top-headline-apply toph strip)
  7704. (error "No top-level headline at point")))))
  7705. (defvar org-agenda-regexp-filter nil)
  7706. (defun org-agenda-filter-by-regexp (strip-or-accumulate)
  7707. "Filter agenda entries by a regular expressions.
  7708. You will be prompted for the regular expression, and the agenda
  7709. view will only show entries that are matched by that expression.
  7710. With one `\\[universal-argument]' prefix argument, hide entries matching the regexp.
  7711. When there is already a regexp filter active, this command removed the
  7712. filter. However, with two `\\[universal-argument]' prefix arguments, add a new condition to
  7713. an already existing regexp filter."
  7714. (interactive "P")
  7715. (let* ((strip (equal strip-or-accumulate '(4)))
  7716. (accumulate (equal strip-or-accumulate '(16))))
  7717. (cond
  7718. ((and org-agenda-regexp-filter (not accumulate))
  7719. (org-agenda-filter-show-all-re)
  7720. (message "Regexp filter removed"))
  7721. (t (let ((flt (concat (if strip "-" "+")
  7722. (read-from-minibuffer
  7723. (if strip
  7724. "Hide entries matching regexp: "
  7725. "Narrow to entries matching regexp: ")))))
  7726. (push flt org-agenda-regexp-filter)
  7727. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))))))
  7728. (defvar org-agenda-effort-filter nil)
  7729. (defun org-agenda-filter-by-effort (strip-or-accumulate)
  7730. "Filter agenda entries by effort.
  7731. With no `\\[universal-argument]' prefix argument, keep entries matching the effort condition.
  7732. With one `\\[universal-argument]' prefix argument, filter out entries matching the condition.
  7733. With two `\\[universal-argument]' prefix arguments, add a second condition to the existing filter.
  7734. This last option is in practice not very useful, but it is available for
  7735. consistency with the other filter commands."
  7736. (interactive "P")
  7737. (let* ((efforts (split-string
  7738. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7739. org-global-properties
  7740. t))
  7741. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
  7742. ;; XXX: the following handles only up to 10 different
  7743. ;; effort values.
  7744. (allowed-keys (if (null efforts) nil
  7745. (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
  7746. (number-sequence 1 (length efforts)))))
  7747. (keep (equal strip-or-accumulate '(16)))
  7748. (negative (equal strip-or-accumulate '(4)))
  7749. (current org-agenda-effort-filter)
  7750. (op nil))
  7751. (while (not (memq op '(?< ?> ?= ?_)))
  7752. (setq op (read-char-exclusive
  7753. "Effort operator? (> = or <) or press `_' again to remove filter")))
  7754. ;; Select appropriate duration. Ignore non-digit characters.
  7755. (if (eq op ?_)
  7756. (progn
  7757. (org-agenda-filter-show-all-effort)
  7758. (message "Effort filter removed"))
  7759. (let ((prompt
  7760. (apply #'format
  7761. (concat "Effort %c "
  7762. (mapconcat (lambda (s) (concat "[%d]" s))
  7763. efforts
  7764. " "))
  7765. op allowed-keys))
  7766. (eff -1))
  7767. (while (not (memq eff allowed-keys))
  7768. (message prompt)
  7769. (setq eff (- (read-char-exclusive) 48)))
  7770. (org-agenda-filter-show-all-effort)
  7771. (setq org-agenda-effort-filter
  7772. (append
  7773. (list (concat (if negative "-" "+")
  7774. (char-to-string op)
  7775. ;; Numbering is 1 2 3 ... 9 0, but we want
  7776. ;; 0 1 2 ... 8 9.
  7777. (nth (mod (1- eff) 10) efforts)))
  7778. (if keep current nil)))
  7779. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))))
  7780. (defun org-agenda-filter (&optional strip-or-accumulate)
  7781. "Prompt for a general filter string and apply it to the agenda.
  7782. The string may contain filter elements like
  7783. +category
  7784. +tag
  7785. +<effort > and = are also allowed as effort operators
  7786. +/regexp/
  7787. Instead of `+', `-' is allowed to strip the agenda of matching entries.
  7788. `+' is optional if it is not required to separate two string parts.
  7789. Multiple filter elements can be concatenated without spaces, for example
  7790. +work-John<0:10-/plot/
  7791. selects entries with category `work' and effort estimates below 10 minutes,
  7792. and deselects entries with tag `John' or matching the regexp `plot'.
  7793. During entry of the filter, completion for tags, categories and effort
  7794. values is offered. Since the syntax for categories and tags is identical
  7795. there should be no overlap between categories and tags. If there is, tags
  7796. get priority.
  7797. A single `\\[universal-argument]' prefix arg STRIP-OR-ACCUMULATE will negate the
  7798. entire filter, which can be useful in connection with the prompt history.
  7799. A double `\\[universal-argument] \\[universal-argument]' prefix arg will add the new filter elements to the
  7800. existing ones. A shortcut for this is to add an additional `+' at the
  7801. beginning of the string, like `+-John'.
  7802. With a triple prefix argument, execute the computed filtering defined in
  7803. the variable `org-agenda-auto-exclude-function'."
  7804. (interactive "P")
  7805. (if (equal strip-or-accumulate '(64))
  7806. ;; Execute the auto-exclude action
  7807. (if (not org-agenda-auto-exclude-function)
  7808. (user-error "`org-agenda-auto-exclude-function' is undefined")
  7809. (org-agenda-filter-show-all-tag)
  7810. (setq org-agenda-tag-filter nil)
  7811. (dolist (tag (org-agenda-get-represented-tags))
  7812. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7813. (when modifier
  7814. (push modifier org-agenda-tag-filter))))
  7815. (unless (null org-agenda-tag-filter)
  7816. (org-agenda-filter-apply org-agenda-tag-filter 'tag 'expand)))
  7817. ;; Prompt for a filter and act
  7818. (let* ((tag-list (org-agenda-get-represented-tags))
  7819. (category-list (org-agenda-get-represented-categories))
  7820. (negate (equal strip-or-accumulate '(4)))
  7821. (cf (mapconcat #'identity org-agenda-category-filter ""))
  7822. (tf (mapconcat #'identity org-agenda-tag-filter ""))
  7823. ;; (rpl-fn (lambda (c) (replace-regexp-in-string "^\\+" "" (or (car c) ""))))
  7824. (ef (replace-regexp-in-string "^\\+" "" (or (car org-agenda-effort-filter) "")))
  7825. (rf (replace-regexp-in-string "^\\+" "" (or (car org-agenda-regexp-filter) "")))
  7826. (ff (concat cf tf ef (when (not (equal rf "")) (concat "/" rf "/"))))
  7827. (f-string (completing-read
  7828. (concat
  7829. (if negate "Negative filter" "Filter")
  7830. " [+cat-tag<0:10-/regexp/]: ")
  7831. #'org-agenda-filter-completion-function
  7832. nil nil ff))
  7833. (keep (or (if (string-match "^\\+[+-]" f-string)
  7834. (progn (setq f-string (substring f-string 1)) t))
  7835. (equal strip-or-accumulate '(16))))
  7836. (fc (if keep org-agenda-category-filter))
  7837. (ft (if keep org-agenda-tag-filter))
  7838. (fe (if keep org-agenda-effort-filter))
  7839. (fr (if keep org-agenda-regexp-filter))
  7840. pm s)
  7841. ;; If the filter contains a double-quoted string, replace a
  7842. ;; single hyphen by the arbitrary and temporary string "~~~"
  7843. ;; to disambiguate such hyphens from syntactic ones.
  7844. (setq f-string (replace-regexp-in-string
  7845. "\"\\([^\"]*\\)-\\([^\"]*\\)\"" "\"\\1~~~\\2\"" f-string))
  7846. (while (string-match "^[ \t]*\\([-+]\\)?\\(\\([^-+<>=/ \t]+\\)\\|\\([<>=][0-9:]+\\)\\|\\(/\\([^/]+\\)/?\\)\\)" f-string)
  7847. (setq pm (if (match-beginning 1) (match-string 1 f-string) "+"))
  7848. (when negate
  7849. (setq pm (if (equal pm "+") "-" "+")))
  7850. (cond
  7851. ((match-beginning 3)
  7852. ;; category or tag
  7853. (setq s (replace-regexp-in-string ; Remove the temporary special string.
  7854. "~~~" "-" (match-string 3 f-string)))
  7855. (cond
  7856. ((member s tag-list)
  7857. (org-pushnew-to-end (concat pm s) ft))
  7858. ((member s category-list)
  7859. (org-pushnew-to-end (concat pm ; Remove temporary double quotes.
  7860. (replace-regexp-in-string "\"\\(.*\\)\"" "\\1" s))
  7861. fc))
  7862. (t (message
  7863. "`%s%s' filter ignored because tag/category is not represented"
  7864. pm s))))
  7865. ((match-beginning 4)
  7866. ;; effort
  7867. (org-pushnew-to-end (concat pm (match-string 4 f-string)) fe))
  7868. ((match-beginning 5)
  7869. ;; regexp
  7870. (org-pushnew-to-end (concat pm (match-string 6 f-string)) fr)))
  7871. (setq f-string (substring f-string (match-end 0))))
  7872. (org-agenda-filter-remove-all)
  7873. (and fc (org-agenda-filter-apply
  7874. (setq org-agenda-category-filter fc) 'category))
  7875. (and ft (org-agenda-filter-apply
  7876. (setq org-agenda-tag-filter ft) 'tag 'expand))
  7877. (and fe (org-agenda-filter-apply
  7878. (setq org-agenda-effort-filter fe) 'effort))
  7879. (and fr (org-agenda-filter-apply
  7880. (setq org-agenda-regexp-filter fr) 'regexp))
  7881. (run-hooks 'org-agenda-filter-hook))))
  7882. (defun org-agenda-filter-completion-function (string _predicate &optional flag)
  7883. "Complete a complex filter string.
  7884. FLAG specifies the type of completion operation to perform. This
  7885. function is passed as a collection function to `completing-read',
  7886. which see."
  7887. (let ((completion-ignore-case t) ;tags are case-sensitive
  7888. (confirm (lambda (x) (stringp x)))
  7889. (prefix "")
  7890. (operator "")
  7891. table)
  7892. (when (string-match "^\\(.*\\([-+<>=]\\)\\)\\([^-+<>=]*\\)$" string)
  7893. (setq prefix (match-string 1 string)
  7894. operator (match-string 2 string)
  7895. string (match-string 3 string)))
  7896. (cond
  7897. ((member operator '("+" "-" "" nil))
  7898. (setq table (append (org-agenda-get-represented-categories)
  7899. (org-agenda-get-represented-tags))))
  7900. ((member operator '("<" ">" "="))
  7901. (setq table (split-string
  7902. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7903. org-global-properties
  7904. t))
  7905. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")
  7906. " +")))
  7907. (t (setq table nil)))
  7908. (pcase flag
  7909. (`t (all-completions string table confirm))
  7910. (`lambda (assoc string table)) ;exact match?
  7911. (`nil
  7912. (pcase (try-completion string table confirm)
  7913. ((and completion (pred stringp))
  7914. (concat prefix completion))
  7915. (completion completion)))
  7916. (_ nil))))
  7917. (defun org-agenda-filter-remove-all ()
  7918. "Remove all filters from the current agenda buffer."
  7919. (interactive)
  7920. (when org-agenda-tag-filter
  7921. (org-agenda-filter-show-all-tag))
  7922. (when org-agenda-category-filter
  7923. (org-agenda-filter-show-all-cat))
  7924. (when org-agenda-regexp-filter
  7925. (org-agenda-filter-show-all-re))
  7926. (when org-agenda-top-headline-filter
  7927. (org-agenda-filter-show-all-top-filter))
  7928. (when org-agenda-effort-filter
  7929. (org-agenda-filter-show-all-effort))
  7930. (org-agenda-finalize)
  7931. (when (called-interactively-p 'interactive)
  7932. (message "All agenda filters removed")))
  7933. (defun org-agenda-filter-by-tag (strip-or-accumulate &optional char exclude)
  7934. "Keep only those lines in the agenda buffer that have a specific tag.
  7935. The tag is selected with its fast selection letter, as configured.
  7936. With a `\\[universal-argument]' prefix, apply the filter negatively, stripping all matches.
  7937. With a `\\[universal-argument] \\[universal-argument]' prefix, add the new tag to the existing filter
  7938. instead of replacing it.
  7939. With a `\\[universal-argument] \\[universal-argument] \\[universal-argument]' prefix, filter the literal tag, \
  7940. i.e. don't
  7941. filter on all its group members.
  7942. A Lisp caller can specify CHAR. EXCLUDE means that the new tag
  7943. should be used to exclude the search - the interactive user can
  7944. also press `-' or `+' to switch between filtering and excluding."
  7945. (interactive "P")
  7946. (let* ((alist org-tag-alist-for-agenda)
  7947. (seen-chars nil)
  7948. (tag-chars (mapconcat
  7949. (lambda (x) (if (and (not (symbolp (car x)))
  7950. (cdr x)
  7951. (not (member (cdr x) seen-chars)))
  7952. (progn
  7953. (push (cdr x) seen-chars)
  7954. (char-to-string (cdr x)))
  7955. ""))
  7956. org-tag-alist-for-agenda ""))
  7957. (valid-char-list (append '(?\t ?\r ?\\ ?. ?\s ?q)
  7958. (string-to-list tag-chars)))
  7959. (exclude (or exclude (equal strip-or-accumulate '(4))))
  7960. (accumulate (equal strip-or-accumulate '(16)))
  7961. (expand (not (equal strip-or-accumulate '(64))))
  7962. (inhibit-read-only t)
  7963. (current org-agenda-tag-filter)
  7964. a tag) ;; n
  7965. (unless char
  7966. (while (not (memq char valid-char-list))
  7967. (org-unlogged-message
  7968. "%s by tag%s: [%s ]tag-char [TAB]tag %s[\\]off [q]uit"
  7969. (if exclude "Exclude[+]" "Filter[-]")
  7970. (if expand "" " (no grouptag expand)")
  7971. tag-chars
  7972. (if org-agenda-auto-exclude-function "[RET] " ""))
  7973. (setq char (read-char-exclusive))
  7974. ;; Excluding or filtering down
  7975. (cond ((eq char ?-) (setq exclude t))
  7976. ((eq char ?+) (setq exclude nil)))))
  7977. (when (eq char ?\t)
  7978. (unless (local-variable-p 'org-global-tags-completion-table)
  7979. (setq-local org-global-tags-completion-table
  7980. (org-global-tags-completion-table)))
  7981. (let ((completion-ignore-case t))
  7982. (setq tag (completing-read
  7983. "Tag: " org-global-tags-completion-table nil t))))
  7984. (cond
  7985. ((eq char ?\r)
  7986. (org-agenda-filter-show-all-tag)
  7987. (when org-agenda-auto-exclude-function
  7988. (setq org-agenda-tag-filter nil)
  7989. (dolist (tag (org-agenda-get-represented-tags))
  7990. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7991. (when modifier
  7992. (push modifier org-agenda-tag-filter))))
  7993. (unless (null org-agenda-tag-filter)
  7994. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  7995. ((eq char ?\\)
  7996. (org-agenda-filter-show-all-tag)
  7997. (when (assoc-default 'tag org-agenda-filters-preset)
  7998. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  7999. ((eq char ?.)
  8000. (setq org-agenda-tag-filter
  8001. (mapcar (lambda(tag) (concat "+" tag))
  8002. (org-get-at-bol 'tags)))
  8003. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  8004. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  8005. ((or (eq char ?\s)
  8006. (setq a (rassoc char alist))
  8007. (and tag (setq a (cons tag nil))))
  8008. (org-agenda-filter-show-all-tag)
  8009. (setq tag (car a))
  8010. (setq org-agenda-tag-filter
  8011. (cons (concat (if exclude "-" "+") tag)
  8012. (if accumulate current nil)))
  8013. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  8014. (t (error "Invalid tag selection character %c" char)))))
  8015. (defun org-agenda-get-represented-categories ()
  8016. "Return a list of all categories used in this agenda buffer."
  8017. (or org-agenda-represented-categories
  8018. (when (derived-mode-p 'org-agenda-mode)
  8019. (let ((pos (point-min)) categories)
  8020. (while (and (< pos (point-max))
  8021. (setq pos (next-single-property-change
  8022. pos 'org-category nil (point-max))))
  8023. (push (get-text-property pos 'org-category) categories))
  8024. (setq org-agenda-represented-categories
  8025. ;; Enclose category names with a hyphen in double
  8026. ;; quotes to process them specially in `org-agenda-filter'.
  8027. (mapcar (lambda (s) (if (string-match-p "-" s) (format "\"%s\"" s) s))
  8028. (nreverse (org-uniquify (delq nil categories)))))))))
  8029. (defvar org-tag-groups-alist-for-agenda)
  8030. (defun org-agenda-get-represented-tags ()
  8031. "Return a list of all tags used in this agenda buffer.
  8032. These will be lower-case, for filtering."
  8033. (or org-agenda-represented-tags
  8034. (when (derived-mode-p 'org-agenda-mode)
  8035. (let ((pos (point-min)) tags-lists tt)
  8036. (while (and (< pos (point-max))
  8037. (setq pos (next-single-property-change
  8038. pos 'tags nil (point-max))))
  8039. (setq tt (get-text-property pos 'tags))
  8040. (if tt (push tt tags-lists)))
  8041. (setq tags-lists
  8042. (nreverse (org-uniquify
  8043. (delq nil (apply #'append tags-lists)))))
  8044. (dolist (tag tags-lists)
  8045. (mapc
  8046. (lambda (group)
  8047. (when (member tag group)
  8048. (push (car group) tags-lists)))
  8049. org-tag-groups-alist-for-agenda))
  8050. (setq org-agenda-represented-tags tags-lists)))))
  8051. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  8052. "Create the form that tests a line for agenda filter.
  8053. Optional argument EXPAND can be used for the TYPE tag and will
  8054. expand the tags in the FILTER if any of the tags in FILTER are
  8055. grouptags."
  8056. (let ((multi-pos-cats
  8057. (and (eq type 'category)
  8058. (string-match-p "\\+.*\\+"
  8059. (mapconcat (lambda (cat) (substring cat 0 1))
  8060. filter ""))))
  8061. f f1)
  8062. (cond
  8063. ;; Tag filter
  8064. ((eq type 'tag)
  8065. (setq filter
  8066. (delete-dups
  8067. (append (assoc-default 'tag org-agenda-filters-preset)
  8068. filter)))
  8069. (dolist (x filter)
  8070. (let ((op (string-to-char x)))
  8071. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  8072. (setq x (list x)))
  8073. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  8074. (push f1 f))))
  8075. ;; Category filter
  8076. ((eq type 'category)
  8077. (setq filter
  8078. (delete-dups
  8079. (append (assoc-default 'category org-agenda-filters-preset)
  8080. filter)))
  8081. (dolist (x filter)
  8082. (if (equal "-" (substring x 0 1))
  8083. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  8084. (setq f1 (list 'equal (substring x 1) 'cat)))
  8085. (push f1 f)))
  8086. ;; Regexp filter
  8087. ((eq type 'regexp)
  8088. (setq filter
  8089. (delete-dups
  8090. (append (assoc-default 'regexp org-agenda-filters-preset)
  8091. filter)))
  8092. (dolist (x filter)
  8093. (if (equal "-" (substring x 0 1))
  8094. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  8095. (setq f1 (list 'string-match (substring x 1) 'txt)))
  8096. (push f1 f)))
  8097. ;; Effort filter
  8098. ((eq type 'effort)
  8099. (setq filter
  8100. (delete-dups
  8101. (append (assoc-default 'effort org-agenda-filters-preset)
  8102. filter)))
  8103. (dolist (x filter)
  8104. (push (org-agenda-filter-effort-form x) f))))
  8105. (cons (if multi-pos-cats 'or 'and) (nreverse f))))
  8106. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  8107. "Return a form associated to tag-expression TAGS.
  8108. Build a form testing a line for agenda filter for
  8109. tag-expressions. OP is an operator of type CHAR that allows the
  8110. function to set the right switches in the returned form."
  8111. (let (form)
  8112. ;; Any of the expressions can match if OP is +, all must match if
  8113. ;; the operator is -.
  8114. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  8115. (let* ((tag (substring x 1))
  8116. (f (cond
  8117. ((string= "" tag) 'tags)
  8118. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  8119. ;; TAG is a regexp.
  8120. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  8121. (t (list 'member tag 'tags)))))
  8122. (push (if (eq op ?-) (list 'not f) f) form)))))
  8123. (defun org-agenda-filter-effort-form (e)
  8124. "Return the form to compare the effort of the current line with what E says.
  8125. E looks like \"+<2:25\"."
  8126. (let (op)
  8127. (setq e (substring e 1))
  8128. (setq op (string-to-char e) e (substring e 1))
  8129. (setq op (cond ((equal op ?<) '<=)
  8130. ((equal op ?>) '>=)
  8131. ((equal op ??) op)
  8132. (t '=)))
  8133. (list 'org-agenda-compare-effort (list 'quote op)
  8134. (org-duration-to-minutes e))))
  8135. (defun org-agenda-compare-effort (op value)
  8136. "Compare the effort of the current line with VALUE, using OP.
  8137. If the line does not have an effort defined, return nil."
  8138. ;; `effort-minutes' property cannot be extracted directly from
  8139. ;; current line but is stored as a property in `txt'.
  8140. (let ((effort (get-text-property 0 'effort-minutes (org-get-at-bol 'txt))))
  8141. (funcall op
  8142. (or effort (if org-agenda-sort-noeffort-is-high 32767 -1))
  8143. value)))
  8144. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  8145. "Expand group tags in FILTER for the agenda.
  8146. When NO-OPERATOR is non-nil, do not add the + operator to
  8147. returned tags."
  8148. (if org-group-tags
  8149. (let (case-fold-search rtn)
  8150. (mapc
  8151. (lambda (f)
  8152. (let (f0 dir)
  8153. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  8154. (setq dir (match-string 1 f) f0 (match-string 2 f))
  8155. (setq dir (if no-operator "" "+") f0 f))
  8156. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  8157. (org-tags-expand f0 t))
  8158. rtn))))
  8159. filter)
  8160. (reverse rtn))
  8161. filter))
  8162. (defun org-agenda-filter-apply (filter type &optional expand)
  8163. "Set FILTER as the new agenda filter and apply it.
  8164. Optional argument EXPAND can be used for the TYPE tag and will
  8165. expand the tags in the FILTER if any of the tags in FILTER are
  8166. grouptags."
  8167. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  8168. (when org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  8169. (setq org-agenda-filter-form (org-agenda-filter-make-matcher
  8170. filter type expand))
  8171. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  8172. ;; category is used as the filter:
  8173. (setq org-agenda-filtered-by-category
  8174. (and (eq type 'category)
  8175. (not (equal (substring (car filter) 0 1) "-"))))
  8176. (org-agenda-set-mode-name)
  8177. (save-excursion
  8178. (goto-char (point-min))
  8179. (while (not (eobp))
  8180. (when (or (org-get-at-bol 'org-hd-marker)
  8181. (org-get-at-bol 'org-marker))
  8182. (org-dlet
  8183. ((tags (org-get-at-bol 'tags))
  8184. (cat (org-agenda-get-category))
  8185. (txt (or (org-get-at-bol 'txt) "")))
  8186. (unless (eval org-agenda-filter-form t)
  8187. (org-agenda-filter-hide-line type))))
  8188. (beginning-of-line 2)))
  8189. (when (get-char-property (point) 'invisible)
  8190. (ignore-errors (org-agenda-previous-line))))
  8191. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  8192. "Filter by top headline HL."
  8193. (org-agenda-set-mode-name)
  8194. (save-excursion
  8195. (goto-char (point-min))
  8196. (while (not (eobp))
  8197. (let* ((pos (org-get-at-bol 'org-hd-marker))
  8198. (tophl (and pos (org-find-top-headline pos))))
  8199. (when (and tophl (funcall (if negative 'identity 'not)
  8200. (string= hl tophl)))
  8201. (org-agenda-filter-hide-line 'top-headline)))
  8202. (beginning-of-line 2)))
  8203. (when (get-char-property (point) 'invisible)
  8204. (org-agenda-previous-line))
  8205. (setq org-agenda-top-headline-filter hl
  8206. org-agenda-filtered-by-top-headline t))
  8207. (defun org-agenda-filter-hide-line (type)
  8208. "If current line is TYPE, hide it in the agenda buffer."
  8209. (let* (buffer-invisibility-spec
  8210. (beg (max (point-min) (1- (line-beginning-position))))
  8211. (end (line-end-position)))
  8212. (let ((inhibit-read-only t))
  8213. (add-text-properties
  8214. beg end `(invisible org-filtered org-filter-type ,type)))))
  8215. (defun org-agenda-remove-filter (type)
  8216. "Remove filter of type TYPE from the agenda buffer."
  8217. (interactive)
  8218. (save-excursion
  8219. (goto-char (point-min))
  8220. (let ((inhibit-read-only t) pos)
  8221. (while (setq pos (text-property-any (point) (point-max)
  8222. 'org-filter-type type))
  8223. (goto-char pos)
  8224. (remove-text-properties
  8225. (point) (next-single-property-change (point) 'org-filter-type)
  8226. `(invisible org-filtered org-filter-type ,type))))
  8227. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  8228. (setq org-agenda-filter-form nil)
  8229. (org-agenda-set-mode-name)
  8230. (org-agenda-finalize)))
  8231. (defun org-agenda-filter-show-all-tag nil
  8232. (org-agenda-remove-filter 'tag))
  8233. (defun org-agenda-filter-show-all-re nil
  8234. (org-agenda-remove-filter 'regexp))
  8235. (defun org-agenda-filter-show-all-effort nil
  8236. (org-agenda-remove-filter 'effort))
  8237. (defun org-agenda-filter-show-all-cat nil
  8238. (org-agenda-remove-filter 'category))
  8239. (defun org-agenda-filter-show-all-top-filter nil
  8240. (org-agenda-remove-filter 'top-headline))
  8241. (defun org-agenda-manipulate-query-add ()
  8242. "Manipulate the query by adding a search term with positive selection.
  8243. Positive selection means the term must be matched for selection of an entry."
  8244. (interactive)
  8245. (org-agenda-manipulate-query ?\[))
  8246. (defun org-agenda-manipulate-query-subtract ()
  8247. "Manipulate the query by adding a search term with negative selection.
  8248. Negative selection means term must not be matched for selection of an entry."
  8249. (interactive)
  8250. (org-agenda-manipulate-query ?\]))
  8251. (defun org-agenda-manipulate-query-add-re ()
  8252. "Manipulate the query by adding a search regexp with positive selection.
  8253. Positive selection means the regexp must match for selection of an entry."
  8254. (interactive)
  8255. (org-agenda-manipulate-query ?\{))
  8256. (defun org-agenda-manipulate-query-subtract-re ()
  8257. "Manipulate the query by adding a search regexp with negative selection.
  8258. Negative selection means regexp must not match for selection of an entry."
  8259. (interactive)
  8260. (org-agenda-manipulate-query ?\}))
  8261. (defun org-agenda-manipulate-query (char)
  8262. (cond
  8263. ((eq org-agenda-type 'agenda)
  8264. (let ((org-agenda-include-inactive-timestamps t))
  8265. (org-agenda-redo))
  8266. (message "Display now includes inactive timestamps as well"))
  8267. ((eq org-agenda-type 'search)
  8268. (org-add-to-string
  8269. 'org-agenda-query-string
  8270. (if org-agenda-last-search-view-search-was-boolean
  8271. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  8272. (?\{ . " +{}") (?\} . " -{}"))))
  8273. " "))
  8274. (setq org-agenda-redo-command
  8275. (list 'org-search-view
  8276. (car (get-text-property (min (1- (point-max)) (point))
  8277. 'org-last-args))
  8278. org-agenda-query-string
  8279. (+ (length org-agenda-query-string)
  8280. (if (member char '(?\{ ?\})) 0 1))))
  8281. (set-register org-agenda-query-register org-agenda-query-string)
  8282. (let ((org-agenda-overriding-arguments
  8283. (cdr org-agenda-redo-command)))
  8284. (org-agenda-redo)))
  8285. (t (error "Cannot manipulate query for %s-type agenda buffers"
  8286. org-agenda-type))))
  8287. (defun org-add-to-string (var string)
  8288. (set var (concat (symbol-value var) string)))
  8289. (defun org-agenda-goto-date (date)
  8290. "Jump to DATE in the agenda buffer.
  8291. When called interactively, prompt for the date.
  8292. When called from Lisp, DATE should be a date as returned by
  8293. `org-read-date'.
  8294. See also:
  8295. `org-agenda-earlier' (\\[org-agenda-earlier])
  8296. `org-agenda-later' (\\[org-agenda-later])
  8297. `org-agenda-goto-today' (\\[org-agenda-goto-today])"
  8298. (interactive
  8299. (list
  8300. (let ((org-read-date-prefer-future org-agenda-jump-prefer-future))
  8301. (org-read-date))))
  8302. (let* ((day (time-to-days (org-time-string-to-time date)))
  8303. (org-agenda-sticky-orig org-agenda-sticky)
  8304. (org-agenda-buffer-tmp-name (buffer-name))
  8305. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8306. (0-arg (or current-prefix-arg (car args)))
  8307. (2-arg (nth 2 args))
  8308. (with-hour-p (nth 4 org-agenda-redo-command))
  8309. (newcmd (list 'org-agenda-list 0-arg date
  8310. (org-agenda-span-to-ndays
  8311. 2-arg (org-time-string-to-absolute date))
  8312. with-hour-p))
  8313. (newargs (cdr newcmd))
  8314. (inhibit-read-only t)
  8315. org-agenda-sticky)
  8316. (if (not (org-agenda-check-type t 'agenda))
  8317. (error "Not available in non-agenda views")
  8318. (add-text-properties (point-min) (point-max)
  8319. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  8320. (org-agenda-redo)
  8321. (goto-char (point-min))
  8322. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  8323. (save-excursion (move-beginning-of-line 2) (eobp))))
  8324. (move-beginning-of-line 2))
  8325. (setq org-agenda-sticky org-agenda-sticky-orig
  8326. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  8327. (defun org-agenda-goto-today ()
  8328. "Go to today's date in the agenda buffer.
  8329. See also:
  8330. `org-agenda-later' (\\[org-agenda-later])
  8331. `org-agenda-earlier' (\\[org-agenda-earlier])
  8332. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8333. (interactive)
  8334. (org-agenda-check-type t 'agenda)
  8335. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8336. (curspan (nth 2 args))
  8337. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  8338. (cond
  8339. (tdpos (goto-char tdpos))
  8340. ((eq org-agenda-type 'agenda)
  8341. (let* ((sd (org-agenda-compute-starting-span
  8342. (org-today) (or curspan org-agenda-span)))
  8343. (org-agenda-overriding-arguments args))
  8344. (setf (nth 1 org-agenda-overriding-arguments) sd)
  8345. (org-agenda-redo)
  8346. (org-agenda-find-same-or-today-or-agenda)))
  8347. (t (error "Cannot find today")))))
  8348. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  8349. (goto-char
  8350. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  8351. (text-property-any (point-min) (point-max) 'org-today t)
  8352. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  8353. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  8354. (org-agenda-backward-block))
  8355. (point-min))))
  8356. (defun org-agenda-backward-block ()
  8357. "Move backward by one agenda block."
  8358. (interactive)
  8359. (org-agenda-forward-block 'backward))
  8360. (defun org-agenda-forward-block (&optional backward)
  8361. "Move forward by one agenda block.
  8362. When optional argument BACKWARD is set, go backward."
  8363. (interactive)
  8364. (cond ((not (derived-mode-p 'org-agenda-mode))
  8365. (user-error
  8366. "Cannot execute this command outside of org-agenda-mode buffers"))
  8367. ((looking-at (if backward "\\`" "\\'"))
  8368. (message "Already at the %s block" (if backward "first" "last")))
  8369. (t (let ((_pos (prog1 (point)
  8370. (ignore-errors (if backward (backward-char 1)
  8371. (move-end-of-line 1)))))
  8372. (f (if backward
  8373. #'previous-single-property-change
  8374. #'next-single-property-change))
  8375. moved dest)
  8376. (while (and (setq dest (funcall
  8377. f (point) 'org-agenda-structural-header))
  8378. (not (get-text-property
  8379. (point) 'org-agenda-structural-header)))
  8380. (setq moved t)
  8381. (goto-char dest))
  8382. (if moved (move-beginning-of-line 1)
  8383. (goto-char (if backward (point-min) (point-max)))
  8384. (move-beginning-of-line 1)
  8385. (message "No %s block" (if backward "previous" "further")))))))
  8386. (defun org-agenda-later (arg)
  8387. "Go forward in time by the current span in the agenda buffer.
  8388. With prefix ARG, go forward that many times the current span.
  8389. See also:
  8390. `org-agenda-earlier' (\\[org-agenda-earlier])
  8391. `org-agenda-goto-today' (\\[org-agenda-goto-today])
  8392. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8393. (interactive "p")
  8394. (org-agenda-check-type t 'agenda)
  8395. (let* ((wstart (window-start))
  8396. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8397. (span (or (nth 2 args) org-agenda-current-span))
  8398. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  8399. (greg (calendar-gregorian-from-absolute sd))
  8400. (cnt (org-get-at-bol 'org-day-cnt))
  8401. greg2)
  8402. (cond
  8403. ((numberp span)
  8404. (setq sd (+ (* span arg) sd)))
  8405. ((eq span 'day)
  8406. (setq sd (+ arg sd)))
  8407. ((eq span 'week)
  8408. (setq sd (+ (* 7 arg) sd)))
  8409. ((eq span 'fortnight)
  8410. (setq sd (+ (* 14 arg) sd)))
  8411. ((eq span 'month)
  8412. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  8413. sd (calendar-absolute-from-gregorian greg2))
  8414. (setcar greg2 (1+ (car greg2))))
  8415. ((eq span 'year)
  8416. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  8417. sd (calendar-absolute-from-gregorian greg2))
  8418. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  8419. (t
  8420. (setq sd (+ (* span arg) sd))))
  8421. (let ((org-agenda-overriding-cmd
  8422. ;; `cmd' may have been set by `org-agenda-run-series' which
  8423. ;; uses `org-agenda-overriding-cmd' to decide whether
  8424. ;; overriding is allowed for `cmd'
  8425. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  8426. (org-agenda-overriding-arguments
  8427. (list (car args) sd span)))
  8428. (org-agenda-redo)
  8429. (org-agenda-find-same-or-today-or-agenda cnt))
  8430. (set-window-start nil wstart)))
  8431. (defun org-agenda-earlier (arg)
  8432. "Go backward in time by the current span in the agenda buffer.
  8433. With prefix ARG, go backward that many times the current span.
  8434. See also:
  8435. `org-agenda-later' (\\[org-agenda-later])
  8436. `org-agenda-goto-today' (\\[org-agenda-goto-today])
  8437. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8438. (interactive "p")
  8439. (org-agenda-later (- arg)))
  8440. (defun org-agenda-view-mode-dispatch ()
  8441. "Call one of the view mode commands."
  8442. (interactive)
  8443. (org-unlogged-message
  8444. "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  8445. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  8446. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  8447. (pcase (read-char-exclusive)
  8448. (?\ (call-interactively 'org-agenda-reset-view))
  8449. (?d (call-interactively 'org-agenda-day-view))
  8450. (?w (call-interactively 'org-agenda-week-view))
  8451. (?t (call-interactively 'org-agenda-fortnight-view))
  8452. (?m (call-interactively 'org-agenda-month-view))
  8453. (?y (call-interactively 'org-agenda-year-view))
  8454. (?l (call-interactively 'org-agenda-log-mode))
  8455. (?L (org-agenda-log-mode '(4)))
  8456. (?c (org-agenda-log-mode 'clockcheck))
  8457. ((or ?F ?f) (call-interactively 'org-agenda-follow-mode))
  8458. (?a (call-interactively 'org-agenda-archives-mode))
  8459. (?A (org-agenda-archives-mode 'files))
  8460. ((or ?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  8461. ((or ?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  8462. (?G (call-interactively 'org-agenda-toggle-time-grid))
  8463. (?D (call-interactively 'org-agenda-toggle-diary))
  8464. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  8465. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  8466. (org-agenda-check-type t 'agenda)
  8467. (org-agenda-redo))
  8468. (message "Display now includes inactive timestamps as well"))
  8469. (?q (message "Abort"))
  8470. (key (user-error "Invalid key: %s" key))))
  8471. (defun org-agenda-reset-view ()
  8472. "Switch to default view for agenda."
  8473. (interactive)
  8474. (org-agenda-change-time-span org-agenda-span))
  8475. (defun org-agenda-day-view (&optional day-of-month)
  8476. "Switch to daily view for agenda.
  8477. With argument DAY-OF-MONTH, switch to that day of the month."
  8478. (interactive "P")
  8479. (org-agenda-change-time-span 'day day-of-month))
  8480. (defun org-agenda-week-view (&optional iso-week)
  8481. "Switch to weekly view for agenda.
  8482. With argument ISO-WEEK, switch to the corresponding ISO week.
  8483. If ISO-WEEK has more then 2 digits, only the last two encode
  8484. the week. Any digits before this encode a year. So 200712
  8485. means week 12 of year 2007. Years ranging from 70 years ago
  8486. to 30 years in the future can also be written as 2-digit years."
  8487. (interactive "P")
  8488. (org-agenda-change-time-span 'week iso-week))
  8489. (defun org-agenda-fortnight-view (&optional iso-week)
  8490. "Switch to fortnightly view for agenda.
  8491. With argument ISO-WEEK, switch to the corresponding ISO week.
  8492. If ISO-WEEK has more then 2 digits, only the last two encode
  8493. the week. Any digits before this encode a year. So 200712
  8494. means week 12 of year 2007. Years ranging from 70 years ago
  8495. to 30 years in the future can also be written as 2-digit years."
  8496. (interactive "P")
  8497. (org-agenda-change-time-span 'fortnight iso-week))
  8498. (defun org-agenda-month-view (&optional month)
  8499. "Switch to monthly view for agenda.
  8500. With argument MONTH, switch to that month. If MONTH has more
  8501. then 2 digits, only the last two encode the month. Any digits
  8502. before this encode a year. So 200712 means December year 2007.
  8503. Years ranging from 70 years ago to 30 years in the future can
  8504. also be written as 2-digit years."
  8505. (interactive "P")
  8506. (org-agenda-change-time-span 'month month))
  8507. (defun org-agenda-year-view (&optional year)
  8508. "Switch to yearly view for agenda.
  8509. With argument YEAR, switch to that year. Years ranging from 70
  8510. years ago to 30 years in the future can also be written as
  8511. 2-digit years."
  8512. (interactive "P")
  8513. (when year
  8514. (setq year (org-small-year-to-year year)))
  8515. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  8516. (org-agenda-change-time-span 'year year)
  8517. (error "Abort")))
  8518. (defun org-agenda-change-time-span (span &optional n)
  8519. "Change the agenda view to SPAN.
  8520. SPAN may be `day', `week', `fortnight', `month', `year'."
  8521. (org-agenda-check-type t 'agenda)
  8522. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8523. (curspan (nth 2 args)))
  8524. (when (and (not n) (equal curspan span))
  8525. (error "Viewing span is already \"%s\"" span))
  8526. (let* ((sd (or (org-get-at-bol 'day)
  8527. (nth 1 args)
  8528. org-starting-day))
  8529. (sd (org-agenda-compute-starting-span sd span n))
  8530. (org-agenda-overriding-cmd
  8531. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  8532. (org-agenda-overriding-arguments
  8533. (list (car args) sd span)))
  8534. (org-agenda-redo)
  8535. (org-agenda-find-same-or-today-or-agenda))
  8536. (org-agenda-set-mode-name)
  8537. (message "Switched to %s view" span)))
  8538. (defun org-agenda-compute-starting-span (sd span &optional n)
  8539. "Compute starting date for agenda.
  8540. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  8541. is a cons cell with the starting date and the number of days,
  8542. so that the date SD will be in that range."
  8543. (let* ((greg (calendar-gregorian-from-absolute sd))
  8544. ;; (dg (nth 1 greg))
  8545. (mg (car greg))
  8546. (yg (nth 2 greg)))
  8547. (cond
  8548. ((eq span 'day)
  8549. (when n
  8550. (setq sd (+ (calendar-absolute-from-gregorian
  8551. (list mg 1 yg))
  8552. n -1))))
  8553. ((or (eq span 'week) (eq span 'fortnight))
  8554. (let* ((nt (calendar-day-of-week
  8555. (calendar-gregorian-from-absolute sd)))
  8556. (d (if org-agenda-start-on-weekday
  8557. (- nt org-agenda-start-on-weekday)
  8558. 0))
  8559. y1)
  8560. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  8561. (when n
  8562. (require 'cal-iso)
  8563. (when (> n 99)
  8564. (setq y1 (org-small-year-to-year (/ n 100))
  8565. n (mod n 100)))
  8566. (setq sd
  8567. (calendar-iso-to-absolute
  8568. (list n 1
  8569. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  8570. ((eq span 'month)
  8571. (let (y1)
  8572. (when (and n (> n 99))
  8573. (setq y1 (org-small-year-to-year (/ n 100))
  8574. n (mod n 100)))
  8575. (setq sd (calendar-absolute-from-gregorian
  8576. (list (or n mg) 1 (or y1 yg))))))
  8577. ((eq span 'year)
  8578. (setq sd (calendar-absolute-from-gregorian
  8579. (list 1 1 (or n yg))))))
  8580. sd))
  8581. (defun org-agenda-next-date-line (&optional arg)
  8582. "Jump to the next line indicating a date in agenda buffer."
  8583. (interactive "p")
  8584. (org-agenda-check-type t 'agenda)
  8585. (beginning-of-line 1)
  8586. ;; This does not work if user makes date format that starts with a blank
  8587. (when (looking-at-p "^\\S-") (forward-char 1))
  8588. (unless (re-search-forward "^\\S-" nil t arg)
  8589. (backward-char 1)
  8590. (error "No next date after this line in this buffer"))
  8591. (goto-char (match-beginning 0)))
  8592. (defun org-agenda-previous-date-line (&optional arg)
  8593. "Jump to the previous line indicating a date in agenda buffer."
  8594. (interactive "p")
  8595. (org-agenda-check-type t 'agenda)
  8596. (beginning-of-line 1)
  8597. (unless (re-search-backward "^\\S-" nil t arg)
  8598. (error "No previous date before this line in this buffer")))
  8599. ;; Initialize the highlight
  8600. (defvar org-hl (make-overlay 1 1))
  8601. (overlay-put org-hl 'face 'highlight)
  8602. (defun org-highlight (begin end &optional buffer)
  8603. "Highlight a region with overlay."
  8604. (move-overlay org-hl begin end (or buffer (current-buffer))))
  8605. (defun org-unhighlight ()
  8606. "Detach overlay INDEX."
  8607. (delete-overlay org-hl))
  8608. (defun org-unhighlight-once ()
  8609. "Remove the highlight from its position, and this function from the hook."
  8610. (remove-hook 'pre-command-hook #'org-unhighlight-once)
  8611. (org-unhighlight))
  8612. (defvar org-agenda-pre-follow-window-conf nil)
  8613. (defun org-agenda-follow-mode ()
  8614. "Toggle follow mode in an agenda buffer."
  8615. (interactive)
  8616. (unless org-agenda-follow-mode
  8617. (setq org-agenda-pre-follow-window-conf
  8618. (current-window-configuration)))
  8619. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  8620. (unless org-agenda-follow-mode
  8621. (set-window-configuration org-agenda-pre-follow-window-conf))
  8622. (org-agenda-set-mode-name)
  8623. (org-agenda-do-context-action)
  8624. (message "Follow mode is %s"
  8625. (if org-agenda-follow-mode "on" "off")))
  8626. (defun org-agenda-entry-text-mode (&optional arg)
  8627. "Toggle entry text mode in an agenda buffer."
  8628. (interactive "P")
  8629. (if (or org-agenda-tag-filter
  8630. org-agenda-category-filter
  8631. org-agenda-regexp-filter
  8632. org-agenda-top-headline-filter)
  8633. (user-error "Can't show entry text in filtered views")
  8634. (setq org-agenda-entry-text-mode (or (integerp arg)
  8635. (not org-agenda-entry-text-mode)))
  8636. (org-agenda-entry-text-hide)
  8637. (and org-agenda-entry-text-mode
  8638. (let ((org-agenda-entry-text-maxlines
  8639. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  8640. (org-agenda-entry-text-show)))
  8641. (org-agenda-set-mode-name)
  8642. (message "Entry text mode is %s%s"
  8643. (if org-agenda-entry-text-mode "on" "off")
  8644. (if (not org-agenda-entry-text-mode) ""
  8645. (format " (maximum number of lines is %d)"
  8646. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  8647. (defun org-agenda-clockreport-mode ()
  8648. "Toggle clocktable mode in an agenda buffer."
  8649. (interactive)
  8650. (org-agenda-check-type t 'agenda)
  8651. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  8652. (org-agenda-set-mode-name)
  8653. (org-agenda-redo)
  8654. (message "Clocktable mode is %s"
  8655. (if org-agenda-clockreport-mode "on" "off")))
  8656. (defun org-agenda-log-mode (&optional special)
  8657. "Toggle log mode in an agenda buffer.
  8658. With argument SPECIAL, show all possible log items, not only the ones
  8659. configured in `org-agenda-log-mode-items'.
  8660. With a `\\[universal-argument] \\[universal-argument]' prefix, show *only* \
  8661. log items, nothing else."
  8662. (interactive "P")
  8663. (org-agenda-check-type t 'agenda)
  8664. (setq org-agenda-show-log
  8665. (cond
  8666. ((equal special '(16)) 'only)
  8667. ((eq special 'clockcheck)
  8668. (if (eq org-agenda-show-log 'clockcheck)
  8669. nil 'clockcheck))
  8670. (special '(closed clock state))
  8671. (t (not org-agenda-show-log))))
  8672. (org-agenda-set-mode-name)
  8673. (org-agenda-redo)
  8674. (message "Log mode is %s" (if org-agenda-show-log "on" "off")))
  8675. (defun org-agenda-archives-mode (&optional with-files)
  8676. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  8677. When called with a prefix argument, include all archive files as well."
  8678. (interactive "P")
  8679. (setq org-agenda-archives-mode
  8680. (cond ((and with-files (eq org-agenda-archives-mode t)) nil)
  8681. (with-files t)
  8682. (org-agenda-archives-mode nil)
  8683. (t 'trees)))
  8684. (org-agenda-set-mode-name)
  8685. (org-agenda-redo)
  8686. (message
  8687. "%s"
  8688. (cond
  8689. ((eq org-agenda-archives-mode nil)
  8690. "No archives are included")
  8691. ((eq org-agenda-archives-mode 'trees)
  8692. (format "Trees with :%s: tag are included" org-archive-tag))
  8693. ((eq org-agenda-archives-mode t)
  8694. (format "Trees with :%s: tag and all active archive files are included"
  8695. org-archive-tag)))))
  8696. (defun org-agenda-toggle-diary ()
  8697. "Toggle diary inclusion in an agenda buffer."
  8698. (interactive)
  8699. (org-agenda-check-type t 'agenda)
  8700. (setq org-agenda-include-diary (not org-agenda-include-diary))
  8701. (org-agenda-redo)
  8702. (org-agenda-set-mode-name)
  8703. (message "Diary inclusion turned %s"
  8704. (if org-agenda-include-diary "on" "off")))
  8705. (defun org-agenda-toggle-deadlines ()
  8706. "Toggle inclusion of entries with a deadline in an agenda buffer."
  8707. (interactive)
  8708. (org-agenda-check-type t 'agenda)
  8709. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  8710. (org-agenda-redo)
  8711. (org-agenda-set-mode-name)
  8712. (message "Deadlines inclusion turned %s"
  8713. (if org-agenda-include-deadlines "on" "off")))
  8714. (defun org-agenda-toggle-time-grid ()
  8715. "Toggle time grid in an agenda buffer."
  8716. (interactive)
  8717. (org-agenda-check-type t 'agenda)
  8718. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  8719. (org-agenda-redo)
  8720. (org-agenda-set-mode-name)
  8721. (message "Time-grid turned %s"
  8722. (if org-agenda-use-time-grid "on" "off")))
  8723. (defun org-agenda-set-mode-name ()
  8724. "Set the mode name to indicate all the small mode settings."
  8725. (setq mode-name
  8726. (list "Org-Agenda"
  8727. (if (get 'org-agenda-files 'org-restrict) " []" "")
  8728. " "
  8729. '(:eval (org-agenda-span-name org-agenda-current-span))
  8730. (if org-agenda-follow-mode " Follow" "")
  8731. (if org-agenda-entry-text-mode " ETxt" "")
  8732. (if org-agenda-include-diary " Diary" "")
  8733. (if org-agenda-include-deadlines " Ddl" "")
  8734. (if org-agenda-use-time-grid " Grid" "")
  8735. (if (and (boundp 'org-habit-show-habits)
  8736. org-habit-show-habits)
  8737. " Habit" "")
  8738. (cond
  8739. ((consp org-agenda-show-log) " LogAll")
  8740. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  8741. (org-agenda-show-log " Log")
  8742. (t ""))
  8743. (if (org-agenda-filter-any) " " "")
  8744. (if (or org-agenda-category-filter
  8745. (assoc-default 'category org-agenda-filters-preset))
  8746. '(:eval (propertize
  8747. (concat "["
  8748. (mapconcat
  8749. #'identity
  8750. (append
  8751. (assoc-default 'category org-agenda-filters-preset)
  8752. org-agenda-category-filter)
  8753. "")
  8754. "]")
  8755. 'face 'org-agenda-filter-category
  8756. 'help-echo "Category used in filtering"))
  8757. "")
  8758. (if (or org-agenda-tag-filter
  8759. (assoc-default 'tag org-agenda-filters-preset))
  8760. '(:eval (propertize
  8761. (concat (mapconcat
  8762. #'identity
  8763. (append
  8764. (assoc-default 'tag org-agenda-filters-preset)
  8765. org-agenda-tag-filter)
  8766. ""))
  8767. 'face 'org-agenda-filter-tags
  8768. 'help-echo "Tags used in filtering"))
  8769. "")
  8770. (if (or org-agenda-effort-filter
  8771. (assoc-default 'effort org-agenda-filters-preset))
  8772. '(:eval (propertize
  8773. (concat (mapconcat
  8774. #'identity
  8775. (append
  8776. (assoc-default 'effort org-agenda-filters-preset)
  8777. org-agenda-effort-filter)
  8778. ""))
  8779. 'face 'org-agenda-filter-effort
  8780. 'help-echo "Effort conditions used in filtering"))
  8781. "")
  8782. (if (or org-agenda-regexp-filter
  8783. (assoc-default 'regexp org-agenda-filters-preset))
  8784. '(:eval (propertize
  8785. (concat (mapconcat
  8786. (lambda (x) (concat (substring x 0 1) "/" (substring x 1) "/"))
  8787. (append
  8788. (assoc-default 'regexp org-agenda-filters-preset)
  8789. org-agenda-regexp-filter)
  8790. ""))
  8791. 'face 'org-agenda-filter-regexp
  8792. 'help-echo "Regexp used in filtering"))
  8793. "")
  8794. (if org-agenda-archives-mode
  8795. (if (eq org-agenda-archives-mode t)
  8796. " Archives"
  8797. (format " :%s:" org-archive-tag))
  8798. "")
  8799. (if org-agenda-clockreport-mode " Clock" "")))
  8800. (force-mode-line-update))
  8801. (defun org-agenda-update-agenda-type ()
  8802. "Update the agenda type after each command."
  8803. (setq org-agenda-type
  8804. (or (get-text-property (point) 'org-agenda-type)
  8805. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  8806. (defun org-agenda-next-line ()
  8807. "Move cursor to the next line, and show if follow mode is active."
  8808. (interactive)
  8809. (call-interactively 'next-line)
  8810. (org-agenda-do-context-action))
  8811. (defun org-agenda-previous-line ()
  8812. "Move cursor to the previous line, and show if follow-mode is active."
  8813. (interactive)
  8814. (call-interactively 'previous-line)
  8815. (org-agenda-do-context-action))
  8816. (defun org-agenda-next-item (n)
  8817. "Move cursor to next agenda item."
  8818. (interactive "p")
  8819. (let ((col (current-column)))
  8820. (dotimes (_ n)
  8821. (when (next-single-property-change (line-end-position) 'org-marker)
  8822. (move-end-of-line 1)
  8823. (goto-char (next-single-property-change (point) 'org-marker))))
  8824. (org-move-to-column col))
  8825. (org-agenda-do-context-action))
  8826. (defun org-agenda-previous-item (n)
  8827. "Move cursor to next agenda item."
  8828. (interactive "p")
  8829. (dotimes (_ n)
  8830. (let ((col (current-column))
  8831. (goto (save-excursion
  8832. (move-end-of-line 0)
  8833. (previous-single-property-change (point) 'org-marker))))
  8834. (when goto (goto-char goto))
  8835. (org-move-to-column col)))
  8836. (org-agenda-do-context-action))
  8837. (defun org-agenda-do-context-action ()
  8838. "Show outline path and, maybe, follow mode window."
  8839. (let ((m (org-get-at-bol 'org-marker)))
  8840. (when (and (markerp m) (marker-buffer m))
  8841. (and org-agenda-follow-mode
  8842. (if org-agenda-follow-indirect
  8843. (org-agenda-tree-to-indirect-buffer nil)
  8844. (org-agenda-show)))
  8845. (and org-agenda-show-outline-path
  8846. (org-with-point-at m (org-display-outline-path t))))))
  8847. (defun org-agenda-show-tags ()
  8848. "Show the tags applicable to the current item."
  8849. (interactive)
  8850. (let* ((tags (org-get-at-bol 'tags)))
  8851. (if tags
  8852. (message "Tags are :%s:"
  8853. (org-no-properties (mapconcat #'identity tags ":")))
  8854. (message "No tags associated with this line"))))
  8855. (defun org-agenda-goto (&optional highlight)
  8856. "Go to the entry at point in the corresponding Org file."
  8857. (interactive)
  8858. (let* ((marker (or (org-get-at-bol 'org-marker)
  8859. (org-agenda-error)))
  8860. (buffer (marker-buffer marker))
  8861. (pos (marker-position marker)))
  8862. ;; FIXME: use `org-switch-to-buffer-other-window'?
  8863. (switch-to-buffer-other-window buffer)
  8864. (widen)
  8865. (push-mark)
  8866. (goto-char pos)
  8867. (when (derived-mode-p 'org-mode)
  8868. (org-fold-show-context 'agenda)
  8869. (recenter (/ (window-height) 2))
  8870. (org-back-to-heading t)
  8871. (let ((case-fold-search nil))
  8872. (when (re-search-forward org-complex-heading-regexp nil t)
  8873. (goto-char (match-beginning 4)))))
  8874. (run-hooks 'org-agenda-after-show-hook)
  8875. (and highlight (org-highlight (line-beginning-position)
  8876. (line-end-position)))))
  8877. (defvar org-agenda-after-show-hook nil
  8878. "Normal hook run after an item has been shown from the agenda.
  8879. Point is in the buffer where the item originated.")
  8880. ;; Defined later in org-agenda.el
  8881. (defvar org-agenda-loop-over-headlines-in-active-region nil)
  8882. (defun org-agenda-do-in-region (beg end cmd &optional arg force-arg delete)
  8883. "Between region BEG and END, call agenda command CMD.
  8884. When optional argument ARG is non-nil or FORCE-ARG is t, pass
  8885. ARG to CMD. When optional argument DELETE is non-nil, assume CMD
  8886. deletes the agenda entry and don't move to the next entry."
  8887. (save-excursion
  8888. (goto-char beg)
  8889. (let ((mend (move-marker (make-marker) end))
  8890. (all (eq org-agenda-loop-over-headlines-in-active-region t))
  8891. (match (and (stringp org-agenda-loop-over-headlines-in-active-region)
  8892. org-agenda-loop-over-headlines-in-active-region))
  8893. (level (and (eq org-agenda-loop-over-headlines-in-active-region 'start-level)
  8894. (org-get-at-bol 'level))))
  8895. (while (< (point) mend)
  8896. (let ((ov (make-overlay (point) (line-end-position))))
  8897. (if (not (or all
  8898. (and match (looking-at-p match))
  8899. (eq level (org-get-at-bol 'level))))
  8900. (org-agenda-next-item 1)
  8901. (overlay-put ov 'face 'region)
  8902. (if (or arg force-arg) (funcall cmd arg) (funcall cmd))
  8903. (when (not delete) (org-agenda-next-item 1))
  8904. (delete-overlay ov)))))))
  8905. ;; org-agenda-[schedule,deadline,date-prompt,todo,[toggle]archive*,
  8906. ;; kill,set-property,set-effort] commands may loop over agenda
  8907. ;; entries. Commands `org-agenda-set-tags' and `org-agenda-bulk-mark'
  8908. ;; use their own mechanisms on active regions.
  8909. (defmacro org-agenda-maybe-loop (cmd arg force-arg delete &rest body)
  8910. "Maybe loop over agenda entries and perform CMD.
  8911. Pass ARG, FORCE-ARG, DELETE and BODY to `org-agenda-do-in-region'."
  8912. (declare (debug t))
  8913. `(if (and (called-interactively-p 'any)
  8914. org-agenda-loop-over-headlines-in-active-region
  8915. (org-region-active-p))
  8916. (org-agenda-do-in-region
  8917. (region-beginning) (region-end) ,cmd ,arg ,force-arg ,delete)
  8918. ,@body))
  8919. (defun org-agenda-kill ()
  8920. "Kill the entry or subtree belonging to the current agenda entry."
  8921. (interactive)
  8922. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8923. (org-agenda-maybe-loop
  8924. #'org-agenda-kill nil nil t
  8925. (let* ((bufname-orig (buffer-name))
  8926. (marker (or (org-get-at-bol 'org-marker)
  8927. (org-agenda-error)))
  8928. (buffer (marker-buffer marker))
  8929. (pos (marker-position marker))
  8930. (type (org-get-at-bol 'type))
  8931. dbeg dend (n 0))
  8932. (org-with-remote-undo buffer
  8933. (with-current-buffer buffer
  8934. (save-excursion
  8935. (goto-char pos)
  8936. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  8937. (setq dbeg (progn (org-back-to-heading t) (point))
  8938. dend (org-end-of-subtree t t))
  8939. (setq dbeg (line-beginning-position)
  8940. dend (min (point-max) (1+ (line-end-position)))))
  8941. (goto-char dbeg)
  8942. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  8943. (when (or (eq t org-agenda-confirm-kill)
  8944. (and (numberp org-agenda-confirm-kill)
  8945. (> n org-agenda-confirm-kill)))
  8946. (let ((win-conf (current-window-configuration)))
  8947. (unwind-protect
  8948. (and
  8949. (prog2
  8950. (org-agenda-tree-to-indirect-buffer nil)
  8951. (not (y-or-n-p
  8952. (format "Delete entry with %d lines in buffer \"%s\"? "
  8953. n (buffer-name buffer))))
  8954. (kill-buffer org-last-indirect-buffer))
  8955. (error "Abort"))
  8956. (set-window-configuration win-conf))))
  8957. (let ((org-agenda-buffer-name bufname-orig))
  8958. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  8959. (with-current-buffer buffer (delete-region dbeg dend))
  8960. (message "Agenda item and source killed")))))
  8961. (defvar org-archive-default-command) ; defined in org-archive.el
  8962. (defun org-agenda-archive-default ()
  8963. "Archive the entry or subtree belonging to the current agenda entry."
  8964. (interactive)
  8965. (require 'org-archive)
  8966. (funcall-interactively
  8967. #'org-agenda-archive-with org-archive-default-command))
  8968. (defun org-agenda-archive-default-with-confirmation ()
  8969. "Archive the entry or subtree belonging to the current agenda entry."
  8970. (interactive)
  8971. (require 'org-archive)
  8972. (funcall-interactively
  8973. #'org-agenda-archive-with org-archive-default-command 'confirm))
  8974. (defun org-agenda-archive ()
  8975. "Archive the entry or subtree belonging to the current agenda entry."
  8976. (interactive)
  8977. (funcall-interactively
  8978. #'org-agenda-archive-with 'org-archive-subtree))
  8979. (defun org-agenda-archive-to-archive-sibling ()
  8980. "Move the entry to the archive sibling."
  8981. (interactive)
  8982. (funcall-interactively
  8983. #'org-agenda-archive-with 'org-archive-to-archive-sibling))
  8984. (defvar org-archive-from-agenda)
  8985. (defun org-agenda-archive-with (cmd &optional confirm)
  8986. "Move the entry to the archive sibling."
  8987. (interactive)
  8988. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8989. (org-agenda-maybe-loop
  8990. #'org-agenda-archive-with cmd nil t
  8991. (let* ((bufname-orig (buffer-name))
  8992. (marker (or (org-get-at-bol 'org-marker)
  8993. (org-agenda-error)))
  8994. (buffer (marker-buffer marker))
  8995. (pos (marker-position marker)))
  8996. (org-with-remote-undo buffer
  8997. (with-current-buffer buffer
  8998. (if (derived-mode-p 'org-mode)
  8999. (if (and confirm
  9000. (not (y-or-n-p "Archive this subtree or entry? ")))
  9001. (error "Abort")
  9002. (save-window-excursion
  9003. (goto-char pos)
  9004. (let ((org-agenda-buffer-name bufname-orig))
  9005. (org-remove-subtree-entries-from-agenda))
  9006. (org-back-to-heading t)
  9007. (let ((org-archive-from-agenda t))
  9008. (funcall cmd))))
  9009. (error "Archiving works only in Org files")))))))
  9010. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  9011. "Remove all lines in the agenda that correspond to a given subtree.
  9012. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  9013. If this information is not given, the function uses the tree at point."
  9014. (let ((buf (or buf (current-buffer))) m p)
  9015. (save-excursion
  9016. (unless (and beg end)
  9017. (org-back-to-heading t)
  9018. (setq beg (point))
  9019. (org-end-of-subtree t)
  9020. (setq end (point)))
  9021. (set-buffer (get-buffer org-agenda-buffer-name))
  9022. (save-excursion
  9023. (goto-char (point-max))
  9024. (beginning-of-line 1)
  9025. (while (not (bobp))
  9026. (when (and (setq m (org-get-at-bol 'org-marker))
  9027. (equal buf (marker-buffer m))
  9028. (setq p (marker-position m))
  9029. (>= p beg)
  9030. (< p end))
  9031. (let ((inhibit-read-only t))
  9032. (delete-region (line-beginning-position)
  9033. (1+ (line-end-position)))))
  9034. (beginning-of-line 0))))))
  9035. (defun org-agenda-refile (&optional goto rfloc no-update)
  9036. "Refile the item at point.
  9037. When called with `\\[universal-argument] \\[universal-argument]', \
  9038. go to the location of the last
  9039. refiled item.
  9040. When called with `\\[universal-argument] \\[universal-argument] \
  9041. \\[universal-argument]' prefix or when GOTO is 0, clear
  9042. the refile cache.
  9043. RFLOC can be a refile location obtained in a different way.
  9044. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  9045. (interactive "P")
  9046. (cond
  9047. ((member goto '(0 (64)))
  9048. (org-refile-cache-clear))
  9049. ((equal goto '(16))
  9050. (org-refile-goto-last-stored))
  9051. (t
  9052. (let* ((buffer-orig (buffer-name))
  9053. (marker (or (org-get-at-bol 'org-hd-marker)
  9054. (org-agenda-error)))
  9055. (buffer (marker-buffer marker))
  9056. ;; (pos (marker-position marker))
  9057. (rfloc (or rfloc
  9058. (org-refile-get-location
  9059. (if goto "Goto" "Refile to") buffer
  9060. org-refile-allow-creating-parent-nodes))))
  9061. (with-current-buffer buffer
  9062. (org-with-wide-buffer
  9063. (goto-char marker)
  9064. (let ((org-agenda-buffer-name buffer-orig))
  9065. (org-remove-subtree-entries-from-agenda))
  9066. (org-refile goto buffer rfloc))))
  9067. (unless no-update (org-agenda-redo)))))
  9068. (defun org-agenda-open-link (&optional arg)
  9069. "Open the link(s) in the current entry, if any.
  9070. This looks for a link in the displayed line in the agenda.
  9071. It also looks at the text of the entry itself."
  9072. (interactive "P")
  9073. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  9074. (org-get-at-bol 'org-marker)))
  9075. (buffer (and marker (marker-buffer marker)))
  9076. (prefix (buffer-substring (line-beginning-position)
  9077. (line-end-position)))
  9078. (lkall (and buffer (org-offer-links-in-entry
  9079. buffer marker arg prefix)))
  9080. (lk0 (car lkall))
  9081. (lk (if (stringp lk0) (list lk0) lk0))
  9082. (lkend (cdr lkall))
  9083. trg)
  9084. (cond
  9085. ((and buffer lk)
  9086. (mapcar (lambda(l)
  9087. (with-current-buffer buffer
  9088. (setq trg (and (string-match org-link-bracket-re l)
  9089. (match-string 1 l)))
  9090. (if (or (not trg) (string-match org-link-any-re trg))
  9091. ;; Don't use `org-with-wide-buffer' here as
  9092. ;; opening the link may result in moving the point
  9093. (save-restriction
  9094. (widen)
  9095. (goto-char marker)
  9096. (when (search-forward l nil lkend)
  9097. (goto-char (match-beginning 0))
  9098. (org-open-at-point)))
  9099. ;; This is an internal link, widen the buffer
  9100. ;; FIXME: use `org-switch-to-buffer-other-window'?
  9101. (switch-to-buffer-other-window buffer)
  9102. (widen)
  9103. (goto-char marker)
  9104. (when (search-forward l nil lkend)
  9105. (goto-char (match-beginning 0))
  9106. (org-open-at-point)))))
  9107. lk))
  9108. ((or (org-in-regexp (concat "\\(" org-link-bracket-re "\\)"))
  9109. (save-excursion
  9110. (beginning-of-line 1)
  9111. (looking-at (concat ".*?\\(" org-link-bracket-re "\\)"))))
  9112. (org-link-open-from-string (match-string 1)))
  9113. (t (message "No link to open here")))))
  9114. (defun org-agenda-copy-local-variable (var)
  9115. "Get a variable from a referenced buffer and install it here."
  9116. (let ((m (org-get-at-bol 'org-marker)))
  9117. (when (and m (buffer-live-p (marker-buffer m)))
  9118. (set (make-local-variable var)
  9119. (with-current-buffer (marker-buffer m)
  9120. (symbol-value var))))))
  9121. (defun org-agenda-switch-to (&optional delete-other-windows)
  9122. "Go to the Org mode file which contains the item at point.
  9123. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  9124. displayed Org file fills the frame."
  9125. (interactive)
  9126. (if (and org-return-follows-link
  9127. (not (org-get-at-bol 'org-marker))
  9128. (org-in-regexp org-link-bracket-re))
  9129. (org-link-open-from-string (match-string 0))
  9130. (let* ((marker (or (org-get-at-bol 'org-marker)
  9131. (org-agenda-error)))
  9132. (buffer (marker-buffer marker))
  9133. (pos (marker-position marker)))
  9134. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  9135. (pop-to-buffer-same-window buffer)
  9136. (when delete-other-windows (delete-other-windows))
  9137. (widen)
  9138. (goto-char pos)
  9139. (when (derived-mode-p 'org-mode)
  9140. (org-fold-show-context 'agenda)
  9141. (run-hooks 'org-agenda-after-show-hook)))))
  9142. (defun org-agenda-goto-mouse (ev)
  9143. "Go to the Org file which contains the item at the mouse click."
  9144. (interactive "e")
  9145. (mouse-set-point ev)
  9146. (org-agenda-goto))
  9147. (defun org-agenda-show (&optional full-entry)
  9148. "Display the Org file which contains the item at point.
  9149. With prefix argument FULL-ENTRY, make the entire entry visible
  9150. if it was hidden in the outline."
  9151. (interactive "P")
  9152. (let ((win (selected-window)))
  9153. (org-agenda-goto t)
  9154. (when full-entry (org-fold-show-entry 'hide-drawers))
  9155. (select-window win)))
  9156. (defvar org-agenda-show-window nil)
  9157. (defun org-agenda-show-and-scroll-up (&optional arg)
  9158. "Display the Org file which contains the item at point.
  9159. When called repeatedly, scroll the window that is displaying the buffer.
  9160. With a `\\[universal-argument]' prefix argument, display the item, but \
  9161. fold drawers."
  9162. (interactive "P")
  9163. (let ((win (selected-window)))
  9164. (if (and (window-live-p org-agenda-show-window)
  9165. (eq this-command last-command))
  9166. (progn
  9167. (select-window org-agenda-show-window)
  9168. (ignore-errors (scroll-up)))
  9169. (org-agenda-goto t)
  9170. (org-fold-show-entry 'hide-drawers)
  9171. (if arg (org-cycle-hide-drawers 'children)
  9172. (org-with-wide-buffer
  9173. (narrow-to-region (org-entry-beginning-position)
  9174. (org-entry-end-position))
  9175. (org-fold-show-all '(drawers))))
  9176. (setq org-agenda-show-window (selected-window)))
  9177. (select-window win)))
  9178. (defun org-agenda-show-scroll-down ()
  9179. "Scroll down the window showing the agenda."
  9180. (interactive)
  9181. (let ((win (selected-window)))
  9182. (when (window-live-p org-agenda-show-window)
  9183. (select-window org-agenda-show-window)
  9184. (ignore-errors (scroll-down))
  9185. (select-window win))))
  9186. (defun org-agenda-show-1 (&optional more)
  9187. "Display the Org file which contains the item at point.
  9188. The prefix arg selects the amount of information to display:
  9189. 0 hide the subtree
  9190. 1 just show the entry according to defaults.
  9191. 2 show the children view
  9192. 3 show the subtree view
  9193. 4 show the entire subtree and any drawers
  9194. With prefix argument FULL-ENTRY, make the entire entry visible
  9195. if it was hidden in the outline."
  9196. (interactive "p")
  9197. (let ((win (selected-window)))
  9198. (org-agenda-goto t)
  9199. (org-back-to-heading)
  9200. (set-window-start (selected-window) (line-beginning-position))
  9201. (cond
  9202. ((= more 0)
  9203. (org-fold-subtree t)
  9204. (save-excursion
  9205. (org-back-to-heading)
  9206. (run-hook-with-args 'org-cycle-hook 'folded))
  9207. (message "Remote: FOLDED"))
  9208. ((and (called-interactively-p 'any) (= more 1))
  9209. (message "Remote: show with default settings"))
  9210. ((= more 2)
  9211. (org-fold-show-entry 'hide-drawers)
  9212. (org-fold-show-children)
  9213. (save-excursion
  9214. (org-back-to-heading)
  9215. (run-hook-with-args 'org-cycle-hook 'children))
  9216. (message "Remote: CHILDREN"))
  9217. ((= more 3)
  9218. (org-fold-show-subtree)
  9219. (save-excursion
  9220. (org-back-to-heading)
  9221. (run-hook-with-args 'org-cycle-hook 'subtree))
  9222. (message "Remote: SUBTREE"))
  9223. ((> more 3)
  9224. (org-fold-show-subtree)
  9225. (message "Remote: SUBTREE AND ALL DRAWERS")))
  9226. (select-window win)))
  9227. (defvar org-agenda-cycle-counter nil)
  9228. (defun org-agenda-cycle-show (&optional n)
  9229. "Show the current entry in another window, with default settings.
  9230. Default settings are taken from `org-show-context-detail'. When
  9231. use repeatedly in immediate succession, the remote entry will
  9232. cycle through visibility
  9233. children -> subtree -> folded
  9234. When called with a numeric prefix arg, that arg will be passed through to
  9235. `org-agenda-show-1'. For the interpretation of that argument, see the
  9236. docstring of `org-agenda-show-1'."
  9237. (interactive "P")
  9238. (if (integerp n)
  9239. (setq org-agenda-cycle-counter n)
  9240. (if (not (eq last-command this-command))
  9241. (setq org-agenda-cycle-counter 1)
  9242. (if (equal org-agenda-cycle-counter 0)
  9243. (setq org-agenda-cycle-counter 2)
  9244. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  9245. (when (> org-agenda-cycle-counter 3)
  9246. (setq org-agenda-cycle-counter 0)))))
  9247. (org-agenda-show-1 org-agenda-cycle-counter))
  9248. (defun org-agenda-recenter (arg)
  9249. "Display the Org file which contains the item at point and recenter."
  9250. (interactive "P")
  9251. (let ((win (selected-window)))
  9252. (org-agenda-goto t)
  9253. (recenter arg)
  9254. (select-window win)))
  9255. (defun org-agenda-show-mouse (ev)
  9256. "Display the Org file which contains the item at the mouse click."
  9257. (interactive "e")
  9258. (mouse-set-point ev)
  9259. (org-agenda-show))
  9260. (defun org-agenda-check-no-diary ()
  9261. "Check if the entry is a diary link and abort if yes."
  9262. (when (org-get-at-bol 'org-agenda-diary-link)
  9263. (org-agenda-error)))
  9264. (defun org-agenda-error ()
  9265. "Throw an error when a command is not allowed in the agenda."
  9266. (user-error "Command not allowed in this line"))
  9267. (defun org-agenda-tree-to-indirect-buffer (arg)
  9268. "Show the subtree corresponding to the current entry in an indirect buffer.
  9269. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  9270. With a numerical prefix ARG, go up to this level and then take that tree.
  9271. With a negative numeric ARG, go up by this number of levels.
  9272. With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
  9273. i.e. don't use
  9274. the dedicated frame."
  9275. (interactive "P")
  9276. (if current-prefix-arg
  9277. (org-agenda-do-tree-to-indirect-buffer arg)
  9278. (let ((agenda-buffer (buffer-name))
  9279. (agenda-window (selected-window))
  9280. (indirect-window
  9281. (and org-last-indirect-buffer
  9282. (get-buffer-window org-last-indirect-buffer))))
  9283. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  9284. (unless (or (eq org-indirect-buffer-display 'new-frame)
  9285. (eq org-indirect-buffer-display 'dedicated-frame))
  9286. (unwind-protect
  9287. (unless (and indirect-window (window-live-p indirect-window))
  9288. (setq indirect-window (split-window agenda-window)))
  9289. (and indirect-window (select-window indirect-window))
  9290. (switch-to-buffer org-last-indirect-buffer :norecord)
  9291. (fit-window-to-buffer indirect-window)))
  9292. (select-window (get-buffer-window agenda-buffer))
  9293. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  9294. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  9295. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  9296. (org-agenda-check-no-diary)
  9297. (let* ((marker (or (org-get-at-bol 'org-marker)
  9298. (org-agenda-error)))
  9299. (buffer (marker-buffer marker))
  9300. (pos (marker-position marker)))
  9301. (with-current-buffer buffer
  9302. (save-excursion
  9303. (goto-char pos)
  9304. (org-tree-to-indirect-buffer arg)))))
  9305. (defvar org-last-heading-marker (make-marker)
  9306. "Marker pointing to the headline that last changed its TODO state
  9307. by a remote command from the agenda.")
  9308. (defun org-agenda-todo-nextset ()
  9309. "Switch TODO entry to next sequence."
  9310. (interactive)
  9311. (org-agenda-todo 'nextset))
  9312. (defun org-agenda-todo-previousset ()
  9313. "Switch TODO entry to previous sequence."
  9314. (interactive)
  9315. (org-agenda-todo 'previousset))
  9316. (defvar org-agenda-headline-snapshot-before-repeat)
  9317. (defun org-agenda-todo (&optional arg)
  9318. "Cycle TODO state of line at point, also in Org file.
  9319. This changes the line at point, all other lines in the agenda referring to
  9320. the same tree node, and the headline of the tree node in the Org file."
  9321. (interactive "P")
  9322. (org-agenda-check-no-diary)
  9323. (org-agenda-maybe-loop
  9324. #'org-agenda-todo arg nil nil
  9325. (let* ((col (current-column))
  9326. (marker (or (org-get-at-bol 'org-marker)
  9327. (org-agenda-error)))
  9328. (buffer (marker-buffer marker))
  9329. (pos (marker-position marker))
  9330. (hdmarker (org-get-at-bol 'org-hd-marker))
  9331. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  9332. (inhibit-read-only t)
  9333. org-loop-over-headlines-in-active-region
  9334. org-agenda-headline-snapshot-before-repeat newhead just-one)
  9335. (org-with-remote-undo buffer
  9336. (with-current-buffer buffer
  9337. (widen)
  9338. (goto-char pos)
  9339. (org-fold-show-context 'agenda)
  9340. (let ((current-prefix-arg arg))
  9341. (call-interactively 'org-todo)
  9342. ;; Make sure that log is recorded in current undo.
  9343. (when (and org-log-setup
  9344. (not (eq org-log-note-how 'note)))
  9345. (org-add-log-note)))
  9346. (and (bolp) (forward-char 1))
  9347. (setq newhead (org-get-heading))
  9348. (when (and org-agenda-headline-snapshot-before-repeat
  9349. (not (equal org-agenda-headline-snapshot-before-repeat
  9350. newhead))
  9351. todayp)
  9352. (setq newhead org-agenda-headline-snapshot-before-repeat
  9353. just-one t))
  9354. (save-excursion
  9355. (org-back-to-heading)
  9356. (move-marker org-last-heading-marker (point))))
  9357. (beginning-of-line 1)
  9358. (save-window-excursion
  9359. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  9360. (when (bound-and-true-p org-clock-out-when-done)
  9361. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  9362. newhead)
  9363. (org-agenda-unmark-clocking-task))
  9364. (org-move-to-column col)
  9365. (org-agenda-mark-clocking-task)))))
  9366. (defun org-agenda-add-note (&optional _arg)
  9367. "Add a time-stamped note to the entry at point."
  9368. (interactive) ;; "P"
  9369. (org-agenda-check-no-diary)
  9370. (let* ((marker (or (org-get-at-bol 'org-marker)
  9371. (org-agenda-error)))
  9372. (buffer (marker-buffer marker))
  9373. (pos (marker-position marker))
  9374. (_hdmarker (org-get-at-bol 'org-hd-marker))
  9375. (inhibit-read-only t))
  9376. (with-current-buffer buffer
  9377. (widen)
  9378. (goto-char pos)
  9379. (org-fold-show-context 'agenda)
  9380. (org-add-note))))
  9381. (defun org-agenda-change-all-lines (newhead hdmarker
  9382. &optional fixface just-this)
  9383. "Change all lines in the agenda buffer which match HDMARKER.
  9384. The new content of the line will be NEWHEAD (as modified by
  9385. `org-agenda-format-item'). HDMARKER is checked with
  9386. `equal' against all `org-hd-marker' text properties in the file.
  9387. If FIXFACE is non-nil, the face of each item is modified according to
  9388. the new TODO state.
  9389. If JUST-THIS is non-nil, change just the current line, not all.
  9390. If FORCE-TAGS is non-nil, the car of it returns the new tags."
  9391. (let* ((inhibit-read-only t)
  9392. (line (org-current-line))
  9393. (org-agenda-buffer (current-buffer))
  9394. (thetags (with-current-buffer (marker-buffer hdmarker)
  9395. (org-get-tags hdmarker)))
  9396. props m undone-face done-face finish new dotime level cat tags
  9397. effort effort-minutes) ;; pl
  9398. (save-excursion
  9399. (goto-char (point-max))
  9400. (beginning-of-line 1)
  9401. (while (not finish)
  9402. (setq finish (bobp))
  9403. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  9404. (or (not just-this) (= (org-current-line) line))
  9405. (equal m hdmarker))
  9406. (setq props (text-properties-at (point))
  9407. dotime (org-get-at-bol 'dotime)
  9408. cat (org-agenda-get-category)
  9409. level (org-get-at-bol 'level)
  9410. tags thetags
  9411. effort (org-get-at-bol 'effort)
  9412. effort-minutes (org-get-at-bol 'effort-minutes)
  9413. new
  9414. (let ((org-prefix-format-compiled
  9415. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  9416. org-prefix-format-compiled))
  9417. (extra (org-get-at-bol 'extra)))
  9418. (with-current-buffer (marker-buffer hdmarker)
  9419. (org-with-wide-buffer
  9420. (org-agenda-format-item extra
  9421. (org-add-props newhead nil
  9422. 'effort effort
  9423. 'effort-minutes effort-minutes)
  9424. level cat tags dotime))))
  9425. ;; pl (text-property-any (line-beginning-position)
  9426. ;; (line-end-position) 'org-heading t)
  9427. undone-face (org-get-at-bol 'undone-face)
  9428. done-face (org-get-at-bol 'done-face))
  9429. (beginning-of-line 1)
  9430. (cond
  9431. ((equal new "") (delete-region (point) (line-beginning-position 2)))
  9432. ((looking-at ".*")
  9433. ;; When replacing the whole line, preserve bulk mark
  9434. ;; overlay, if any.
  9435. (let ((mark (catch :overlay
  9436. (dolist (o (overlays-in (point) (+ 2 (point))))
  9437. (when (eq (overlay-get o 'type)
  9438. 'org-marked-entry-overlay)
  9439. (throw :overlay o))))))
  9440. (replace-match new t t)
  9441. (beginning-of-line)
  9442. (when mark (move-overlay mark (point) (+ 2 (point)))))
  9443. (add-text-properties (line-beginning-position)
  9444. (line-end-position) props)
  9445. (when fixface
  9446. (add-text-properties
  9447. (line-beginning-position) (line-end-position)
  9448. (list 'face
  9449. (if org-last-todo-state-is-todo
  9450. undone-face done-face))))
  9451. (org-agenda-highlight-todo 'line)
  9452. (beginning-of-line 1))
  9453. (t (error "Line update did not work")))
  9454. (save-restriction
  9455. (narrow-to-region (line-beginning-position) (line-end-position))
  9456. (org-agenda-finalize)))
  9457. (beginning-of-line 0)))))
  9458. (defun org-agenda-align-tags (&optional line)
  9459. "Align all tags in agenda items to `org-agenda-tags-column'.
  9460. When optional argument LINE is non-nil, align tags only on the
  9461. current line."
  9462. (let ((inhibit-read-only t)
  9463. (org-agenda-tags-column (if (eq 'auto org-agenda-tags-column)
  9464. (- (window-max-chars-per-line))
  9465. org-agenda-tags-column))
  9466. (end (and line (line-end-position)))
  9467. l c)
  9468. (org-fold-core-ignore-modifications
  9469. (save-excursion
  9470. (goto-char (if line (line-beginning-position) (point-min)))
  9471. (while (re-search-forward org-tag-group-re end t)
  9472. (add-text-properties
  9473. (match-beginning 1) (match-end 1)
  9474. (list 'face (delq nil (let ((prop (get-text-property
  9475. (match-beginning 1) 'face)))
  9476. (or (listp prop) (setq prop (list prop)))
  9477. (if (memq 'org-tag prop)
  9478. prop
  9479. (cons 'org-tag prop))))))
  9480. (setq l (string-width (match-string 1))
  9481. c (if (< org-agenda-tags-column 0)
  9482. (- (abs org-agenda-tags-column) l)
  9483. org-agenda-tags-column))
  9484. (goto-char (match-beginning 1))
  9485. (delete-region (save-excursion (skip-chars-backward " \t") (point))
  9486. (point))
  9487. (insert (org-add-props
  9488. (make-string (max 1 (- c (current-column))) ?\s)
  9489. (plist-put (copy-sequence (text-properties-at (point)))
  9490. 'face nil))))
  9491. (goto-char (point-min))
  9492. (org-font-lock-add-tag-faces (point-max))))))
  9493. (defun org-agenda-priority-up ()
  9494. "Increase the priority of line at point, also in Org file."
  9495. (interactive)
  9496. (org-agenda-priority 'up))
  9497. (defun org-agenda-priority-down ()
  9498. "Decrease the priority of line at point, also in Org file."
  9499. (interactive)
  9500. (org-agenda-priority 'down))
  9501. (defun org-agenda-priority (&optional force-direction)
  9502. "Set the priority of line at point, also in Org file.
  9503. This changes the line at point, all other lines in the agenda
  9504. referring to the same tree node, and the headline of the tree
  9505. node in the Org file.
  9506. Called with one universal prefix arg, show the priority instead
  9507. of setting it.
  9508. When called programmatically, FORCE-DIRECTION can be `set', `up',
  9509. `down', or a character."
  9510. (interactive "P")
  9511. (unless org-priority-enable-commands
  9512. (user-error "Priority commands are disabled"))
  9513. (org-agenda-check-no-diary)
  9514. (let* ((col (current-column))
  9515. (hdmarker (org-get-at-bol 'org-hd-marker))
  9516. (buffer (marker-buffer hdmarker))
  9517. (pos (marker-position hdmarker))
  9518. (inhibit-read-only t)
  9519. newhead)
  9520. (org-with-remote-undo buffer
  9521. (with-current-buffer buffer
  9522. (widen)
  9523. (goto-char pos)
  9524. (org-fold-show-context 'agenda)
  9525. (org-priority force-direction)
  9526. (end-of-line 1)
  9527. (setq newhead (org-get-heading)))
  9528. (org-agenda-change-all-lines newhead hdmarker)
  9529. (org-move-to-column col))))
  9530. ;; FIXME: should fix the tags property of the agenda line.
  9531. (defun org-agenda-set-tags (&optional tag onoff)
  9532. "Set tags for the current headline."
  9533. (interactive)
  9534. (org-agenda-check-no-diary)
  9535. (if (and (org-region-active-p) (called-interactively-p 'any))
  9536. (call-interactively 'org-change-tag-in-region)
  9537. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9538. (org-agenda-error)))
  9539. (buffer (marker-buffer hdmarker))
  9540. (pos (marker-position hdmarker))
  9541. (inhibit-read-only t)
  9542. newhead)
  9543. (org-with-remote-undo buffer
  9544. (with-current-buffer buffer
  9545. (widen)
  9546. (goto-char pos)
  9547. (org-fold-show-context 'agenda)
  9548. (if tag
  9549. (org-toggle-tag tag onoff)
  9550. (call-interactively #'org-set-tags-command))
  9551. (end-of-line 1)
  9552. (setq newhead (org-get-heading)))
  9553. (org-agenda-change-all-lines newhead hdmarker)
  9554. (beginning-of-line 1)))))
  9555. (defun org-agenda-set-property ()
  9556. "Set a property for the current headline."
  9557. (interactive)
  9558. (org-agenda-check-no-diary)
  9559. (org-agenda-maybe-loop
  9560. #'org-agenda-set-property nil nil nil
  9561. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9562. (org-agenda-error)))
  9563. (buffer (marker-buffer hdmarker))
  9564. (pos (marker-position hdmarker))
  9565. (inhibit-read-only t)
  9566. ) ;; newhead
  9567. (org-with-remote-undo buffer
  9568. (with-current-buffer buffer
  9569. (widen)
  9570. (goto-char pos)
  9571. (org-fold-show-context 'agenda)
  9572. (call-interactively 'org-set-property))))))
  9573. (defun org-agenda-set-effort ()
  9574. "Set the effort property for the current headline."
  9575. (interactive)
  9576. (org-agenda-check-no-diary)
  9577. (org-agenda-maybe-loop
  9578. #'org-agenda-set-effort nil nil nil
  9579. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9580. (org-agenda-error)))
  9581. (buffer (marker-buffer hdmarker))
  9582. (pos (marker-position hdmarker))
  9583. (inhibit-read-only t)
  9584. newhead)
  9585. (org-with-remote-undo buffer
  9586. (with-current-buffer buffer
  9587. (widen)
  9588. (goto-char pos)
  9589. (org-fold-show-context 'agenda)
  9590. (call-interactively 'org-set-effort)
  9591. (end-of-line 1)
  9592. (setq newhead (org-get-heading)))
  9593. (org-agenda-change-all-lines newhead hdmarker)))))
  9594. (defun org-agenda-toggle-archive-tag ()
  9595. "Toggle the archive tag for the current entry."
  9596. (interactive)
  9597. (org-agenda-check-no-diary)
  9598. (org-agenda-maybe-loop
  9599. #'org-agenda-toggle-archive-tag nil nil nil
  9600. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9601. (org-agenda-error)))
  9602. (buffer (marker-buffer hdmarker))
  9603. (pos (marker-position hdmarker))
  9604. (inhibit-read-only t)
  9605. newhead)
  9606. (org-with-remote-undo buffer
  9607. (with-current-buffer buffer
  9608. (widen)
  9609. (goto-char pos)
  9610. (org-fold-show-context 'agenda)
  9611. (call-interactively 'org-toggle-archive-tag)
  9612. (end-of-line 1)
  9613. (setq newhead (org-get-heading)))
  9614. (org-agenda-change-all-lines newhead hdmarker)
  9615. (beginning-of-line 1)))))
  9616. (defun org-agenda-do-date-later (arg)
  9617. (interactive "P")
  9618. (cond
  9619. ((or (equal arg '(16))
  9620. (memq last-command
  9621. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9622. (setq this-command 'org-agenda-date-later-minutes)
  9623. (org-agenda-date-later-minutes 1))
  9624. ((or (equal arg '(4))
  9625. (memq last-command
  9626. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9627. (setq this-command 'org-agenda-date-later-hours)
  9628. (org-agenda-date-later-hours 1))
  9629. (t
  9630. (org-agenda-date-later (prefix-numeric-value arg)))))
  9631. (defun org-agenda-do-date-earlier (arg)
  9632. (interactive "P")
  9633. (cond
  9634. ((or (equal arg '(16))
  9635. (memq last-command
  9636. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9637. (setq this-command 'org-agenda-date-earlier-minutes)
  9638. (org-agenda-date-earlier-minutes 1))
  9639. ((or (equal arg '(4))
  9640. (memq last-command
  9641. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9642. (setq this-command 'org-agenda-date-earlier-hours)
  9643. (org-agenda-date-earlier-hours 1))
  9644. (t
  9645. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  9646. (defun org-agenda-date-later (arg &optional what)
  9647. "Change the date of this item to ARG day(s) later."
  9648. (interactive "p")
  9649. (org-agenda-check-type t 'agenda)
  9650. (org-agenda-check-no-diary)
  9651. (let* ((marker (or (org-get-at-bol 'org-marker)
  9652. (org-agenda-error)))
  9653. (buffer (marker-buffer marker))
  9654. (pos (marker-position marker))
  9655. cdate today)
  9656. (org-with-remote-undo buffer
  9657. (with-current-buffer buffer
  9658. (widen)
  9659. (goto-char pos)
  9660. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9661. (when (and org-agenda-move-date-from-past-immediately-to-today
  9662. (equal arg 1)
  9663. (or (not what) (eq what 'day))
  9664. (not (save-match-data (org-at-date-range-p))))
  9665. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  9666. cdate (calendar-absolute-from-gregorian
  9667. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  9668. today (org-today))
  9669. (when (> today cdate)
  9670. ;; immediately shift to today
  9671. (setq arg (- today cdate))))
  9672. (org-timestamp-change arg (or what 'day))
  9673. (when (and (org-at-date-range-p)
  9674. (re-search-backward org-tr-regexp-both
  9675. (line-beginning-position)))
  9676. (let ((end org-last-changed-timestamp))
  9677. (org-timestamp-change arg (or what 'day))
  9678. (setq org-last-changed-timestamp
  9679. (concat org-last-changed-timestamp "--" end)))))
  9680. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9681. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  9682. (defun org-agenda-date-earlier (arg &optional what)
  9683. "Change the date of this item to ARG day(s) earlier."
  9684. (interactive "p")
  9685. (org-agenda-date-later (- arg) what))
  9686. (defun org-agenda-date-later-minutes (arg)
  9687. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9688. (interactive "p")
  9689. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9690. (org-agenda-date-later arg 'minute))
  9691. (defun org-agenda-date-earlier-minutes (arg)
  9692. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9693. (interactive "p")
  9694. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9695. (org-agenda-date-earlier arg 'minute))
  9696. (defun org-agenda-date-later-hours (arg)
  9697. "Change the time of this item, in hour steps."
  9698. (interactive "p")
  9699. (org-agenda-date-later arg 'hour))
  9700. (defun org-agenda-date-earlier-hours (arg)
  9701. "Change the time of this item, in hour steps."
  9702. (interactive "p")
  9703. (org-agenda-date-earlier arg 'hour))
  9704. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  9705. "Show new date stamp via text properties."
  9706. ;; We use text properties to make this undoable
  9707. (let ((inhibit-read-only t))
  9708. (setq stamp (concat prefix " => " stamp " "))
  9709. (save-excursion
  9710. (goto-char (point-max))
  9711. (while (not (bobp))
  9712. (when (equal marker (org-get-at-bol 'org-marker))
  9713. (remove-text-properties (line-beginning-position)
  9714. (line-end-position)
  9715. '(display nil))
  9716. (org-move-to-column
  9717. (- (window-max-chars-per-line)
  9718. (length stamp))
  9719. t)
  9720. (add-text-properties
  9721. (1- (point)) (line-end-position)
  9722. (list 'display (org-add-props stamp nil
  9723. 'face '(secondary-selection default))))
  9724. (beginning-of-line 1))
  9725. (beginning-of-line 0)))))
  9726. (defun org-agenda-date-prompt (arg)
  9727. "Change the date of this item. Date is prompted for, with default today.
  9728. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  9729. be used to request time specification in the time stamp."
  9730. (interactive "P")
  9731. (org-agenda-check-type t 'agenda)
  9732. (org-agenda-check-no-diary)
  9733. (org-agenda-maybe-loop
  9734. #'org-agenda-date-prompt arg t nil
  9735. (let* ((marker (or (org-get-at-bol 'org-marker)
  9736. (org-agenda-error)))
  9737. (buffer (marker-buffer marker))
  9738. (pos (marker-position marker)))
  9739. (org-with-remote-undo buffer
  9740. (with-current-buffer buffer
  9741. (widen)
  9742. (goto-char pos)
  9743. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9744. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  9745. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9746. (message "Time stamp changed to %s" org-last-changed-timestamp))))
  9747. (defun org-agenda-schedule (arg &optional time)
  9748. "Schedule the item at point.
  9749. ARG is passed through to `org-schedule'."
  9750. (interactive "P")
  9751. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9752. (org-agenda-check-no-diary)
  9753. (org-agenda-maybe-loop
  9754. #'org-agenda-schedule arg t nil
  9755. (let* ((marker (or (org-get-at-bol 'org-marker)
  9756. (org-agenda-error)))
  9757. ;; (type (marker-insertion-type marker))
  9758. (buffer (marker-buffer marker))
  9759. (pos (marker-position marker))
  9760. ts)
  9761. (set-marker-insertion-type marker t)
  9762. (org-with-remote-undo buffer
  9763. (with-current-buffer buffer
  9764. (widen)
  9765. (goto-char pos)
  9766. (setq ts (org-schedule arg time)))
  9767. (org-agenda-show-new-time marker ts " S"))
  9768. (message "%s" ts))))
  9769. (defun org-agenda-deadline (arg &optional time)
  9770. "Schedule the item at point.
  9771. ARG is passed through to `org-deadline'."
  9772. (interactive "P")
  9773. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9774. (org-agenda-check-no-diary)
  9775. (org-agenda-maybe-loop
  9776. #'org-agenda-deadline arg t nil
  9777. (let* ((marker (or (org-get-at-bol 'org-marker)
  9778. (org-agenda-error)))
  9779. (buffer (marker-buffer marker))
  9780. (pos (marker-position marker))
  9781. ts)
  9782. (org-with-remote-undo buffer
  9783. (with-current-buffer buffer
  9784. (widen)
  9785. (goto-char pos)
  9786. (setq ts (org-deadline arg time)))
  9787. (org-agenda-show-new-time marker ts " D"))
  9788. (message "%s" ts))))
  9789. (defun org-agenda-clock-in (&optional arg)
  9790. "Start the clock on the currently selected item."
  9791. (interactive "P")
  9792. (org-agenda-check-no-diary)
  9793. (if (equal arg '(4))
  9794. (org-clock-in arg)
  9795. (let* ((marker (or (org-get-at-bol 'org-marker)
  9796. (org-agenda-error)))
  9797. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  9798. (pos (marker-position marker))
  9799. (col (current-column))
  9800. newhead)
  9801. (org-with-remote-undo (marker-buffer marker)
  9802. (with-current-buffer (marker-buffer marker)
  9803. (widen)
  9804. (goto-char pos)
  9805. (org-fold-show-context 'agenda)
  9806. (org-clock-in arg)
  9807. (setq newhead (org-get-heading)))
  9808. (org-agenda-change-all-lines newhead hdmarker))
  9809. (org-move-to-column col))))
  9810. (defun org-agenda-clock-out ()
  9811. "Stop the currently running clock."
  9812. (interactive)
  9813. (unless (marker-buffer org-clock-marker)
  9814. (user-error "No running clock"))
  9815. (let ((marker (make-marker)) (col (current-column)) newhead)
  9816. (org-with-remote-undo (marker-buffer org-clock-marker)
  9817. (with-current-buffer (marker-buffer org-clock-marker)
  9818. (org-with-wide-buffer
  9819. (goto-char org-clock-marker)
  9820. (org-back-to-heading t)
  9821. (move-marker marker (point))
  9822. (org-clock-out)
  9823. (setq newhead (org-get-heading)))))
  9824. (org-agenda-change-all-lines newhead marker)
  9825. (move-marker marker nil)
  9826. (org-move-to-column col)
  9827. (org-agenda-unmark-clocking-task)))
  9828. (defun org-agenda-clock-cancel (&optional _arg)
  9829. "Cancel the currently running clock."
  9830. (interactive) ;; "P"
  9831. (unless (marker-buffer org-clock-marker)
  9832. (user-error "No running clock"))
  9833. (org-with-remote-undo (marker-buffer org-clock-marker)
  9834. (org-clock-cancel)))
  9835. (defun org-agenda-clock-goto ()
  9836. "Jump to the currently clocked in task within the agenda.
  9837. If the currently clocked in task is not listed in the agenda
  9838. buffer, display it in another window."
  9839. (interactive)
  9840. (let (pos)
  9841. (mapc (lambda (o)
  9842. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  9843. (setq pos (overlay-start o))))
  9844. (overlays-in (point-min) (point-max)))
  9845. (cond (pos (goto-char pos))
  9846. ;; If the currently clocked entry is not in the agenda
  9847. ;; buffer, we visit it in another window:
  9848. ((bound-and-true-p org-clock-current-task)
  9849. (org-switch-to-buffer-other-window (org-clock-goto)))
  9850. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  9851. (defun org-agenda-diary-entry-in-org-file ()
  9852. "Make a diary entry in the file `org-agenda-diary-file'."
  9853. (let (d1 d2 char (text "") dp1 dp2)
  9854. (if (equal (buffer-name) "*Calendar*")
  9855. (setq d1 (calendar-cursor-to-date t)
  9856. d2 (car calendar-mark-ring))
  9857. (setq dp1 (get-text-property (line-beginning-position) 'day))
  9858. (unless dp1 (user-error "No date defined in current line"))
  9859. (setq d1 (calendar-gregorian-from-absolute dp1)
  9860. d2 (and (ignore-errors (mark))
  9861. (save-excursion
  9862. (goto-char (mark))
  9863. (setq dp2 (get-text-property (line-beginning-position) 'day)))
  9864. (calendar-gregorian-from-absolute dp2))))
  9865. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  9866. (setq char (read-char-exclusive))
  9867. (cond
  9868. ((equal char ?d)
  9869. (setq text (read-string "Day entry: "))
  9870. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  9871. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9872. ((equal char ?a)
  9873. (setq d1 (list (car d1) (nth 1 d1)
  9874. (read-number (format "Reference year [%d]: " (nth 2 d1))
  9875. (nth 2 d1))))
  9876. (setq text (read-string "Anniversary (use %d to show years): "))
  9877. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  9878. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9879. ((equal char ?b)
  9880. (setq text (read-string "Block entry: "))
  9881. (unless (and d1 d2 (not (equal d1 d2)))
  9882. (user-error "No block of days selected"))
  9883. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  9884. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9885. ((equal char ?j)
  9886. (org-switch-to-buffer-other-window
  9887. (find-file-noselect org-agenda-diary-file))
  9888. (require 'org-datetree)
  9889. (org-datetree-find-date-create d1)
  9890. (org-fold-reveal t))
  9891. (t (user-error "Invalid selection character `%c'" char)))))
  9892. (defcustom org-agenda-insert-diary-strategy 'date-tree
  9893. "Where in `org-agenda-diary-file' should new entries be added?
  9894. Valid values:
  9895. date-tree in the date tree, as first child of the date
  9896. date-tree-last in the date tree, as last child of the date
  9897. top-level as top-level entries at the end of the file."
  9898. :group 'org-agenda
  9899. :type '(choice
  9900. (const :tag "first in a date tree" date-tree)
  9901. (const :tag "last in a date tree" date-tree-last)
  9902. (const :tag "as top level at end of file" top-level)))
  9903. (defcustom org-agenda-insert-diary-extract-time nil
  9904. "Non-nil means extract any time specification from the diary entry."
  9905. :group 'org-agenda
  9906. :version "24.1"
  9907. :type 'boolean)
  9908. (defcustom org-agenda-bulk-mark-char ">"
  9909. "A single-character string to be used as the bulk mark."
  9910. :group 'org-agenda
  9911. :version "24.1"
  9912. :type 'string)
  9913. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  9914. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  9915. If TEXT is not empty, it will become the headline of the new entry, and
  9916. the resulting entry will not be shown. When TEXT is empty, switch to
  9917. `org-agenda-diary-file' and let the user finish the entry there."
  9918. (let ((cw (current-window-configuration)))
  9919. (org-switch-to-buffer-other-window
  9920. (find-file-noselect org-agenda-diary-file))
  9921. (widen)
  9922. (goto-char (point-min))
  9923. (cl-case type
  9924. (anniversary
  9925. (or (re-search-forward "^\\*[ \t]+Anniversaries" nil t)
  9926. (progn
  9927. (or (org-at-heading-p)
  9928. (progn
  9929. (outline-next-heading)
  9930. (insert "* Anniversaries\n\n")
  9931. (beginning-of-line -1)))))
  9932. (outline-next-heading)
  9933. (org-back-over-empty-lines)
  9934. (backward-char 1)
  9935. (insert "\n")
  9936. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  9937. (nth 2 d1) (car d1) (nth 1 d1) text)))
  9938. (day
  9939. (let ((org-prefix-has-time t)
  9940. (org-agenda-time-leading-zero t)
  9941. fmt time time2)
  9942. (when org-agenda-insert-diary-extract-time
  9943. ;; Use org-agenda-format-item to parse text for a time-range and
  9944. ;; remove it. FIXME: This is a hack, we should refactor
  9945. ;; that function to make time extraction available separately
  9946. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  9947. time (get-text-property 0 'time fmt)
  9948. time2 (if (> (length time) 0)
  9949. ;; split-string removes trailing ...... if
  9950. ;; no end time given. First space
  9951. ;; separates time from date.
  9952. (concat " " (car (split-string time "\\.")))
  9953. nil)
  9954. text (get-text-property 0 'txt fmt)))
  9955. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9956. (org-agenda-insert-diary-as-top-level text)
  9957. (require 'org-datetree)
  9958. (org-datetree-find-date-create d1)
  9959. (org-agenda-insert-diary-make-new-entry text))
  9960. (org-insert-time-stamp (org-time-from-absolute
  9961. (calendar-absolute-from-gregorian d1))
  9962. nil nil nil nil time2))
  9963. (end-of-line 0))
  9964. ((block) ;; Wrap this in (strictly unnecessary) parens because
  9965. ;; otherwise the indentation gets confused by the
  9966. ;; special meaning of 'block
  9967. (when (> (calendar-absolute-from-gregorian d1)
  9968. (calendar-absolute-from-gregorian d2))
  9969. (setq d1 (prog1 d2 (setq d2 d1))))
  9970. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9971. (org-agenda-insert-diary-as-top-level text)
  9972. (require 'org-datetree)
  9973. (org-datetree-find-date-create d1)
  9974. (org-agenda-insert-diary-make-new-entry text))
  9975. (org-insert-time-stamp (org-time-from-absolute
  9976. (calendar-absolute-from-gregorian d1)))
  9977. (insert "--")
  9978. (org-insert-time-stamp (org-time-from-absolute
  9979. (calendar-absolute-from-gregorian d2)))
  9980. (end-of-line 0)))
  9981. (if (string-match "\\S-" text)
  9982. (progn
  9983. (set-window-configuration cw)
  9984. (message "%s entry added to %s"
  9985. (capitalize (symbol-name type))
  9986. (abbreviate-file-name org-agenda-diary-file)))
  9987. (org-fold-reveal t)
  9988. (message "Please finish entry here"))))
  9989. (defun org-agenda-insert-diary-as-top-level (text)
  9990. "Make new entry as a top-level entry at the end of the file.
  9991. Add TEXT as headline, and position the cursor in the second line so that
  9992. a timestamp can be added there."
  9993. (widen)
  9994. (goto-char (point-max))
  9995. (unless (bolp) (insert "\n"))
  9996. (org-insert-heading nil t t)
  9997. (insert text)
  9998. (org-end-of-meta-data)
  9999. (unless (bolp) (insert "\n"))
  10000. (when org-adapt-indentation (indent-to-column 2)))
  10001. (defun org-agenda-insert-diary-make-new-entry (text)
  10002. "Make a new entry with TEXT as a child of the current subtree.
  10003. Position the point in the heading's first body line so that
  10004. a timestamp can be added there."
  10005. (cond
  10006. ((eq org-agenda-insert-diary-strategy 'date-tree-last)
  10007. (end-of-line)
  10008. (org-insert-heading '(4) t)
  10009. (org-do-demote))
  10010. (t
  10011. (outline-next-heading)
  10012. (org-back-over-empty-lines)
  10013. (unless (looking-at "[ \t]*$") (save-excursion (insert "\n")))
  10014. (org-insert-heading nil t)
  10015. (org-do-demote)))
  10016. (let ((col (current-column)))
  10017. (insert text)
  10018. (org-end-of-meta-data)
  10019. ;; Ensure point is left on a blank line, at proper indentation.
  10020. (unless (bolp) (insert "\n"))
  10021. (unless (looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
  10022. (when org-adapt-indentation (indent-to-column col)))
  10023. (org-fold-show-set-visibility 'lineage))
  10024. (defun org-agenda-diary-entry ()
  10025. "Make a diary entry, like the `i' command from the calendar.
  10026. All the standard commands work: block, weekly etc.
  10027. When `org-agenda-diary-file' points to a file,
  10028. `org-agenda-diary-entry-in-org-file' is called instead to create
  10029. entries in that Org file."
  10030. (interactive)
  10031. (if (not (eq org-agenda-diary-file 'diary-file))
  10032. (org-agenda-diary-entry-in-org-file)
  10033. (require 'diary-lib)
  10034. (let* ((char (read-char-exclusive
  10035. "Diary entry: [d]ay [w]eekly [m]onthly [y]early\
  10036. [a]nniversary [b]lock [c]yclic"))
  10037. (cmd (cdr (assoc char
  10038. '((?d . diary-insert-entry)
  10039. (?w . diary-insert-weekly-entry)
  10040. (?m . diary-insert-monthly-entry)
  10041. (?y . diary-insert-yearly-entry)
  10042. (?a . diary-insert-anniversary-entry)
  10043. (?b . diary-insert-block-entry)
  10044. (?c . diary-insert-cyclic-entry)))))
  10045. (oldf (symbol-function 'calendar-cursor-to-date))
  10046. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  10047. (point (point))
  10048. (mark (or (mark t) (point))))
  10049. (unless cmd
  10050. (user-error "No command associated with <%c>" char))
  10051. (unless (and (get-text-property point 'day)
  10052. (or (not (equal ?b char))
  10053. (get-text-property mark 'day)))
  10054. (user-error "Don't know which date to use for diary entry"))
  10055. ;; We implement this by hacking the `calendar-cursor-to-date' function
  10056. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  10057. (let ((calendar-mark-ring
  10058. (list (calendar-gregorian-from-absolute
  10059. (or (get-text-property mark 'day)
  10060. (get-text-property point 'day))))))
  10061. (unwind-protect
  10062. (progn
  10063. (fset 'calendar-cursor-to-date
  10064. (lambda (&optional _error _dummy)
  10065. (calendar-gregorian-from-absolute
  10066. (get-text-property point 'day))))
  10067. (call-interactively cmd))
  10068. (fset 'calendar-cursor-to-date oldf))))))
  10069. (defun org-agenda-execute-calendar-command (cmd)
  10070. "Execute a calendar command from the agenda with date from cursor."
  10071. (org-agenda-check-type t 'agenda)
  10072. (require 'diary-lib)
  10073. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  10074. (user-error "Don't know which date to use for the calendar command"))
  10075. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  10076. (point (point))
  10077. (date (calendar-gregorian-from-absolute
  10078. (get-text-property point 'day))))
  10079. ;; the following 2 vars are needed in the calendar
  10080. (org-dlet
  10081. ((displayed-month (car date))
  10082. (displayed-year (nth 2 date)))
  10083. (unwind-protect
  10084. (progn
  10085. (fset 'calendar-cursor-to-date
  10086. (lambda (&optional _error _dummy)
  10087. (calendar-gregorian-from-absolute
  10088. (get-text-property point 'day))))
  10089. (call-interactively cmd))
  10090. (fset 'calendar-cursor-to-date oldf)))))
  10091. (defun org-agenda-phases-of-moon ()
  10092. "Display the phases of the moon for the 3 months around the cursor date."
  10093. (interactive)
  10094. (org-agenda-execute-calendar-command 'calendar-lunar-phases))
  10095. (defun org-agenda-holidays ()
  10096. "Display the holidays for the 3 months around the cursor date."
  10097. (interactive)
  10098. (org-agenda-execute-calendar-command 'calendar-list-holidays))
  10099. (defvar calendar-longitude) ; defined in calendar.el
  10100. (defvar calendar-latitude) ; defined in calendar.el
  10101. (defvar calendar-location-name) ; defined in calendar.el
  10102. (defun org-agenda-sunrise-sunset (arg)
  10103. "Display sunrise and sunset for the cursor date.
  10104. Latitude and longitude can be specified with the variables
  10105. `calendar-latitude' and `calendar-longitude'. When called with prefix
  10106. argument, latitude and longitude will be prompted for."
  10107. (interactive "P")
  10108. (require 'solar)
  10109. (let ((calendar-longitude (if arg nil calendar-longitude))
  10110. (calendar-latitude (if arg nil calendar-latitude))
  10111. (calendar-location-name
  10112. (if arg "the given coordinates" calendar-location-name)))
  10113. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  10114. (defun org-agenda-goto-calendar ()
  10115. "Open the Emacs calendar with the date at the cursor."
  10116. (interactive)
  10117. (org-agenda-check-type t 'agenda)
  10118. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  10119. (user-error "Don't know which date to open in calendar")))
  10120. (date (calendar-gregorian-from-absolute day))
  10121. (calendar-move-hook nil)
  10122. (calendar-view-holidays-initially-flag nil)
  10123. (calendar-view-diary-initially-flag nil))
  10124. (calendar)
  10125. (calendar-goto-date date)))
  10126. ;;;###autoload
  10127. (defun org-calendar-goto-agenda ()
  10128. "Compute the Org agenda for the calendar date displayed at the cursor.
  10129. This is a command that has to be installed in `calendar-mode-map'."
  10130. (interactive)
  10131. ;; Temporarily disable sticky agenda since user clearly wants to
  10132. ;; refresh view anyway.
  10133. (let ((org-agenda-buffer-tmp-name "*Org Agenda(a)*")
  10134. (org-agenda-sticky nil))
  10135. (org-agenda-list nil (calendar-absolute-from-gregorian
  10136. (calendar-cursor-to-date))
  10137. nil)))
  10138. (defun org-agenda-convert-date ()
  10139. (interactive)
  10140. (org-agenda-check-type t 'agenda)
  10141. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  10142. date s)
  10143. (unless day
  10144. (user-error "Don't know which date to convert"))
  10145. (setq date (calendar-gregorian-from-absolute day))
  10146. (setq s (concat
  10147. "Gregorian: " (calendar-date-string date) "\n"
  10148. "ISO: " (calendar-iso-date-string date) "\n"
  10149. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  10150. "Julian: " (calendar-julian-date-string date) "\n"
  10151. "Astron. JD: " (calendar-astro-date-string date)
  10152. " (Julian date number at noon UTC)\n"
  10153. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  10154. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  10155. "French: " (calendar-french-date-string date) "\n"
  10156. "Bahá’í: " (calendar-bahai-date-string date) " (until sunset)\n"
  10157. "Mayan: " (calendar-mayan-date-string date) "\n"
  10158. "Coptic: " (calendar-coptic-date-string date) "\n"
  10159. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  10160. "Persian: " (calendar-persian-date-string date) "\n"
  10161. "Chinese: " (calendar-chinese-date-string date) "\n"))
  10162. (with-output-to-temp-buffer "*Dates*"
  10163. (princ s))
  10164. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  10165. ;;; Bulk commands
  10166. (defun org-agenda-bulk-marked-p ()
  10167. "Non-nil when current entry is marked for bulk action."
  10168. (eq (get-char-property (line-beginning-position) 'type)
  10169. 'org-marked-entry-overlay))
  10170. (defun org-agenda-bulk-mark (&optional arg)
  10171. "Mark entries for future bulk action.
  10172. When ARG is nil or one and region is not active then mark the
  10173. entry at point.
  10174. When ARG is nil or one and region is active then mark the entries
  10175. in the region.
  10176. When ARG is greater than one mark ARG lines."
  10177. (interactive "p")
  10178. (when (and (or (not arg) (= arg 1)) (use-region-p))
  10179. (setq arg (count-lines (region-beginning) (region-end)))
  10180. (goto-char (region-beginning))
  10181. (deactivate-mark))
  10182. (dotimes (_ (or arg 1))
  10183. (unless (org-get-at-bol 'org-agenda-diary-link)
  10184. (let* ((m (org-get-at-bol 'org-hd-marker))
  10185. ov)
  10186. (unless (org-agenda-bulk-marked-p)
  10187. (unless m (user-error "Nothing to mark at point"))
  10188. (push m org-agenda-bulk-marked-entries)
  10189. (setq ov (make-overlay (line-beginning-position)
  10190. (+ 2 (line-beginning-position))))
  10191. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  10192. (org-get-todo-face "TODO")
  10193. 'evaporate)
  10194. (overlay-put ov 'type 'org-marked-entry-overlay))
  10195. (end-of-line 1)
  10196. (or (ignore-errors
  10197. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  10198. (beginning-of-line 2))
  10199. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  10200. (beginning-of-line 2)))))
  10201. (message "%d entries marked for bulk action"
  10202. (length org-agenda-bulk-marked-entries)))
  10203. (defun org-agenda-bulk-mark-all ()
  10204. "Mark all entries for future agenda bulk action."
  10205. (interactive)
  10206. (org-agenda-bulk-mark-regexp "."))
  10207. (defun org-agenda-bulk-mark-regexp (regexp)
  10208. "Mark entries matching REGEXP for future agenda bulk action."
  10209. (interactive "sMark entries matching regexp: ")
  10210. (let ((entries-marked 0) txt-at-point)
  10211. (save-excursion
  10212. (goto-char (point-min))
  10213. (goto-char (next-single-property-change (point) 'org-hd-marker))
  10214. (while (and (re-search-forward regexp nil t)
  10215. (setq txt-at-point
  10216. (get-text-property (match-beginning 0) 'txt)))
  10217. (if (get-char-property (point) 'invisible)
  10218. (beginning-of-line 2)
  10219. (when (string-match-p regexp txt-at-point)
  10220. (setq entries-marked (1+ entries-marked))
  10221. (call-interactively 'org-agenda-bulk-mark)))))
  10222. (unless entries-marked
  10223. (message "No entry matching this regexp."))))
  10224. (defun org-agenda-bulk-unmark (&optional arg)
  10225. "Unmark the entry at point for future bulk action."
  10226. (interactive "P")
  10227. (if arg
  10228. (org-agenda-bulk-unmark-all)
  10229. (cond ((org-agenda-bulk-marked-p)
  10230. (org-agenda-bulk-remove-overlays
  10231. (line-beginning-position) (+ 2 (line-beginning-position)))
  10232. (setq org-agenda-bulk-marked-entries
  10233. (delete (org-get-at-bol 'org-hd-marker)
  10234. org-agenda-bulk-marked-entries))
  10235. (end-of-line 1)
  10236. (or (ignore-errors
  10237. (goto-char (next-single-property-change (point) 'txt)))
  10238. (beginning-of-line 2))
  10239. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  10240. (beginning-of-line 2))
  10241. (message "%d entries left marked for bulk action"
  10242. (length org-agenda-bulk-marked-entries)))
  10243. (t (message "No entry to unmark here")))))
  10244. (defun org-agenda-bulk-toggle-all ()
  10245. "Toggle all marks for bulk action."
  10246. (interactive)
  10247. (save-excursion
  10248. (goto-char (point-min))
  10249. (while (ignore-errors
  10250. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  10251. (org-agenda-bulk-toggle))))
  10252. (defun org-agenda-bulk-toggle ()
  10253. "Toggle the mark at point for bulk action."
  10254. (interactive)
  10255. (if (org-agenda-bulk-marked-p)
  10256. (org-agenda-bulk-unmark)
  10257. (org-agenda-bulk-mark)))
  10258. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  10259. "Remove the mark overlays between BEG and END in the agenda buffer.
  10260. BEG and END default to the buffer limits.
  10261. This only removes the overlays, it does not remove the markers
  10262. from the list in `org-agenda-bulk-marked-entries'."
  10263. (interactive)
  10264. (mapc (lambda (ov)
  10265. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  10266. (delete-overlay ov)))
  10267. (overlays-in (or beg (point-min)) (or end (point-max)))))
  10268. (defun org-agenda-bulk-unmark-all ()
  10269. "Remove all marks in the agenda buffer.
  10270. This will remove the markers and the overlays."
  10271. (interactive)
  10272. (if (null org-agenda-bulk-marked-entries)
  10273. (message "No entry to unmark")
  10274. (setq org-agenda-bulk-marked-entries nil)
  10275. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  10276. (defcustom org-agenda-persistent-marks nil
  10277. "Non-nil means marked items will stay marked after a bulk action.
  10278. You can toggle this interactively by typing `p' when prompted for a
  10279. bulk action."
  10280. :group 'org-agenda
  10281. :version "24.1"
  10282. :type 'boolean)
  10283. (defcustom org-agenda-loop-over-headlines-in-active-region t
  10284. "Shall some commands act upon headlines in the active region?
  10285. When set to t, some commands will be performed in all headlines
  10286. within the active region.
  10287. When set to `start-level', some commands will be performed in all
  10288. headlines within the active region, provided that these headlines
  10289. are of the same level than the first one.
  10290. When set to a regular expression, those commands will be
  10291. performed on the matching headlines within the active region.
  10292. The list of commands is: `org-agenda-schedule',
  10293. `org-agenda-deadline', `org-agenda-date-prompt',
  10294. `org-agenda-todo', `org-agenda-archive*', `org-agenda-kill'.
  10295. See `org-loop-over-headlines-in-active-region' for the equivalent
  10296. option for Org buffers."
  10297. :type '(choice (const :tag "Don't loop" nil)
  10298. (const :tag "All headlines in active region" t)
  10299. (const :tag "In active region, headlines at the same level than the first one" start-level)
  10300. (regexp :tag "Regular expression matcher"))
  10301. :version "27.1"
  10302. :package-version '(Org . "9.4")
  10303. :group 'org-agenda)
  10304. (defun org-agenda-bulk-action (&optional arg)
  10305. "Execute an remote-editing action on all marked entries.
  10306. The prefix arg is passed through to the command if possible."
  10307. (interactive "P")
  10308. ;; When there is no mark, act on the agenda entry at point.
  10309. (if (not org-agenda-bulk-marked-entries)
  10310. (save-excursion (org-agenda-bulk-mark)))
  10311. (dolist (m org-agenda-bulk-marked-entries)
  10312. (unless (and (markerp m)
  10313. (marker-buffer m)
  10314. (buffer-live-p (marker-buffer m))
  10315. (marker-position m))
  10316. (user-error "Marker %s for bulk command is invalid" m)))
  10317. ;; Prompt for the bulk command.
  10318. (org-unlogged-message
  10319. (concat "Bulk (" (if org-agenda-persistent-marks "" "don't ") "[p]ersist marks): "
  10320. "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  10321. "[S]catter [f]unction "
  10322. (and org-agenda-bulk-custom-functions
  10323. (format " Custom: [%s]"
  10324. (mapconcat (lambda (f) (char-to-string (car f)))
  10325. org-agenda-bulk-custom-functions
  10326. "")))))
  10327. (catch 'exit
  10328. (let* ((org-log-refile (if org-log-refile 'time nil))
  10329. (entries (reverse org-agenda-bulk-marked-entries))
  10330. (org-overriding-default-time
  10331. (and (get-text-property (point) 'org-agenda-date-header)
  10332. (org-get-cursor-date)))
  10333. redo-at-end
  10334. cmd)
  10335. (pcase (read-char-exclusive)
  10336. (?p
  10337. (let ((org-agenda-persistent-marks
  10338. (not org-agenda-persistent-marks)))
  10339. (org-agenda-bulk-action)
  10340. (throw 'exit nil)))
  10341. (?$
  10342. (setq cmd #'org-agenda-archive))
  10343. (?A
  10344. (setq cmd #'org-agenda-archive-to-archive-sibling))
  10345. ((or ?r ?w)
  10346. (let ((refile-location
  10347. (org-refile-get-location
  10348. "Refile to"
  10349. (marker-buffer (car entries))
  10350. org-refile-allow-creating-parent-nodes)))
  10351. (when (nth 3 refile-location)
  10352. (setcar (nthcdr 3 refile-location)
  10353. (move-marker
  10354. (make-marker)
  10355. (nth 3 refile-location)
  10356. (or (get-file-buffer (nth 1 refile-location))
  10357. (find-buffer-visiting (nth 1 refile-location))
  10358. (error "This should not happen")))))
  10359. (setq cmd (lambda () (org-agenda-refile nil refile-location t)))
  10360. (setq redo-at-end t)))
  10361. (?t
  10362. (let ((state (completing-read
  10363. "Todo state: "
  10364. (with-current-buffer (marker-buffer (car entries))
  10365. (mapcar #'list org-todo-keywords-1)))))
  10366. (setq cmd (lambda ()
  10367. (let ((org-inhibit-blocking t)
  10368. (org-inhibit-logging 'note))
  10369. (org-agenda-todo state))))))
  10370. ((and (or ?- ?+) action)
  10371. (let ((tag (completing-read
  10372. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  10373. (with-current-buffer (marker-buffer (car entries))
  10374. (delq nil
  10375. (mapcar (lambda (x) (and (stringp (car x)) x))
  10376. org-current-tag-alist))))))
  10377. (setq cmd
  10378. (lambda ()
  10379. (org-agenda-set-tags tag
  10380. (if (eq action ?+) 'on 'off))))))
  10381. ((and (or ?s ?d) c)
  10382. (let* ((schedule? (eq c ?s))
  10383. (prompt (if schedule? "(Re)Schedule to" "(Re)Set Deadline to"))
  10384. (time
  10385. (and (not arg)
  10386. (let ((new (org-read-date
  10387. nil nil nil prompt org-overriding-default-time)))
  10388. ;; A "double plus" answer applies to every
  10389. ;; scheduled time. Do not turn it into
  10390. ;; a fixed date yet.
  10391. (if (string-match-p "\\`[ \t]*\\+\\+"
  10392. org-read-date-final-answer)
  10393. org-read-date-final-answer
  10394. new)))))
  10395. ;; Make sure to not prompt for a note when bulk
  10396. ;; rescheduling/resetting deadline as Org cannot cope with
  10397. ;; simultaneous notes. Besides, it could be annoying
  10398. ;; depending on the number of marked items.
  10399. (setq cmd
  10400. (if schedule?
  10401. (lambda ()
  10402. (let ((org-log-reschedule
  10403. (and org-log-reschedule 'time)))
  10404. (org-agenda-schedule arg time)))
  10405. (lambda ()
  10406. (let ((org-log-redeadline (and org-log-redeadline 'time)))
  10407. (org-agenda-deadline arg time)))))))
  10408. (?S
  10409. (unless (org-agenda-check-type nil 'agenda 'todo)
  10410. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type))
  10411. (let ((days (read-number
  10412. (format "Scatter tasks across how many %sdays: "
  10413. (if arg "week" ""))
  10414. 7)))
  10415. (setq cmd
  10416. (lambda ()
  10417. (let ((distance (1+ (random days))))
  10418. (when arg
  10419. (let ((dist distance)
  10420. (day-of-week
  10421. (calendar-day-of-week
  10422. (calendar-gregorian-from-absolute (org-today)))))
  10423. (dotimes (_ (1+ dist))
  10424. (while (member day-of-week org-agenda-weekend-days)
  10425. (cl-incf distance)
  10426. (cl-incf day-of-week)
  10427. (when (= day-of-week 7)
  10428. (setq day-of-week 0)))
  10429. (cl-incf day-of-week)
  10430. (when (= day-of-week 7)
  10431. (setq day-of-week 0)))))
  10432. ;; Silently fail when try to replan a sexp entry.
  10433. (ignore-errors
  10434. (let* ((date (calendar-gregorian-from-absolute
  10435. (+ (org-today) distance)))
  10436. (time (org-encode-time
  10437. 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  10438. (org-agenda-schedule nil time))))))))
  10439. (?f
  10440. (setq cmd
  10441. (intern
  10442. (completing-read "Function: " obarray #'fboundp t nil nil))))
  10443. (action
  10444. (setq cmd
  10445. (pcase (assoc action org-agenda-bulk-custom-functions)
  10446. (`(,_ ,fn)
  10447. fn)
  10448. (`(,_ ,fn ,arg-fn)
  10449. (apply #'apply-partially fn (funcall arg-fn)))
  10450. (_
  10451. (user-error "Invalid bulk action: %c" action))))
  10452. (setq redo-at-end t)))
  10453. ;; Sort the markers, to make sure that parents are handled
  10454. ;; before children.
  10455. (setq entries (sort entries
  10456. (lambda (a b)
  10457. (cond
  10458. ((eq (marker-buffer a) (marker-buffer b))
  10459. (< (marker-position a) (marker-position b)))
  10460. (t
  10461. (string< (buffer-name (marker-buffer a))
  10462. (buffer-name (marker-buffer b))))))))
  10463. ;; Now loop over all markers and apply CMD.
  10464. (let ((processed 0)
  10465. (skipped 0))
  10466. (dolist (e entries)
  10467. (let ((pos (text-property-any (point-min) (point-max) 'org-hd-marker e)))
  10468. (if (not pos)
  10469. (progn (message "Skipping removed entry at %s" e)
  10470. (cl-incf skipped))
  10471. (goto-char pos)
  10472. (let (org-loop-over-headlines-in-active-region) (funcall cmd))
  10473. ;; `post-command-hook' is not run yet. We make sure any
  10474. ;; pending log note is processed.
  10475. (when org-log-setup (org-add-log-note))
  10476. (cl-incf processed))))
  10477. (when redo-at-end (org-agenda-redo))
  10478. (unless org-agenda-persistent-marks (org-agenda-bulk-unmark-all))
  10479. (message "Acted on %d entries%s%s"
  10480. processed
  10481. (if (= skipped 0)
  10482. ""
  10483. (format ", skipped %d (disappeared before their turn)"
  10484. skipped))
  10485. (if (not org-agenda-persistent-marks) "" " (kept marked)"))))))
  10486. (defun org-agenda-capture (&optional with-time)
  10487. "Call `org-capture' with the date at point.
  10488. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  10489. current HH:MM time."
  10490. (interactive "P")
  10491. (if (not (eq major-mode 'org-agenda-mode))
  10492. (user-error "You cannot do this outside of agenda buffers")
  10493. (let ((org-overriding-default-time
  10494. (org-get-cursor-date (equal with-time 1))))
  10495. (call-interactively 'org-capture))))
  10496. ;;; Dragging agenda lines forward/backward
  10497. (defun org-agenda-reapply-filters ()
  10498. "Re-apply all agenda filters."
  10499. (mapcar
  10500. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f) t)))
  10501. `((,org-agenda-tag-filter tag)
  10502. (,org-agenda-category-filter category)
  10503. (,org-agenda-regexp-filter regexp)
  10504. (,org-agenda-effort-filter effort)
  10505. (,(assoc-default 'tag org-agenda-filters-preset) tag)
  10506. (,(assoc-default 'category org-agenda-filters-preset) category)
  10507. (,(assoc-default 'effort org-agenda-filters-preset) effort)
  10508. (,(assoc-default 'regexp org-agenda-filters-preset) regexp))))
  10509. (defun org-agenda-drag-line-forward (arg &optional backward)
  10510. "Drag an agenda line forward by ARG lines.
  10511. When the optional argument `backward' is non-nil, move backward."
  10512. (interactive "p")
  10513. (let ((inhibit-read-only t) lst line)
  10514. (if (or (not (get-text-property (point) 'txt))
  10515. (save-excursion
  10516. (dotimes (_ arg)
  10517. (move-beginning-of-line (if backward 0 2))
  10518. (push (not (get-text-property (point) 'txt)) lst))
  10519. (delq nil lst)))
  10520. (message "Cannot move line forward")
  10521. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  10522. (move-beginning-of-line 1)
  10523. (setq line (buffer-substring (point) end))
  10524. (delete-region (point) end)
  10525. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  10526. (insert line)
  10527. (org-agenda-reapply-filters)
  10528. (org-agenda-mark-clocking-task)
  10529. (move-beginning-of-line 0)))))
  10530. (defun org-agenda-drag-line-backward (arg)
  10531. "Drag an agenda line backward by ARG lines."
  10532. (interactive "p")
  10533. (org-agenda-drag-line-forward arg t))
  10534. ;;; Flagging notes
  10535. (defun org-agenda-show-the-flagging-note ()
  10536. "Display the flagging note in the other window.
  10537. When called a second time in direct sequence, offer to remove the FLAGGING
  10538. tag and (if present) the flagging note."
  10539. (interactive)
  10540. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  10541. (win (selected-window))
  10542. note) ;; heading newhead
  10543. (unless hdmarker
  10544. (user-error "No linked entry at point"))
  10545. (if (and (eq this-command last-command)
  10546. (y-or-n-p "Unflag and remove any flagging note? "))
  10547. (progn
  10548. (org-agenda-remove-flag hdmarker)
  10549. (let ((win (get-buffer-window "*Flagging Note*")))
  10550. (and win (delete-window win)))
  10551. (message "Entry unflagged"))
  10552. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  10553. (unless note
  10554. (user-error "No flagging note"))
  10555. (org-kill-new note)
  10556. (org-switch-to-buffer-other-window "*Flagging Note*")
  10557. (erase-buffer)
  10558. (insert note)
  10559. (goto-char (point-min))
  10560. (while (re-search-forward "\\\\n" nil t)
  10561. (replace-match "\n" t t))
  10562. (goto-char (point-min))
  10563. (select-window win)
  10564. (message "%s" (substitute-command-keys "Flagging note pushed to \
  10565. kill ring. Press `\\[org-agenda-show-the-flagging-note]' again to remove \
  10566. tag and note")))))
  10567. (defun org-agenda-remove-flag (marker)
  10568. "Remove the FLAGGED tag and any flagging note in the entry."
  10569. (let ((newhead
  10570. (org-with-point-at marker
  10571. (org-toggle-tag "FLAGGED" 'off)
  10572. (org-entry-delete nil "THEFLAGGINGNOTE")
  10573. (org-get-heading))))
  10574. (org-agenda-change-all-lines newhead marker)
  10575. (message "Entry unflagged")))
  10576. (defun org-agenda-get-any-marker (&optional pos)
  10577. (or (get-text-property (or pos (line-beginning-position)) 'org-hd-marker)
  10578. (get-text-property (or pos (line-beginning-position)) 'org-marker)))
  10579. ;;; Appointment reminders
  10580. (defvar appt-time-msg-list) ; defined in appt.el
  10581. ;;;###autoload
  10582. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  10583. "Activate appointments found in `org-agenda-files'.
  10584. With a `\\[universal-argument]' prefix, refresh the list of \
  10585. appointments.
  10586. If FILTER is t, interactively prompt the user for a regular
  10587. expression, and filter out entries that don't match it.
  10588. If FILTER is a string, use this string as a regular expression
  10589. for filtering entries out.
  10590. If FILTER is a function, filter out entries against which
  10591. calling the function returns nil. This function takes one
  10592. argument: an entry from `org-agenda-get-day-entries'.
  10593. FILTER can also be an alist with the car of each cell being
  10594. either `headline' or `category'. For example:
  10595. ((headline \"IMPORTANT\")
  10596. (category \"Work\"))
  10597. will only add headlines containing IMPORTANT or headlines
  10598. belonging to the \"Work\" category.
  10599. ARGS are symbols indicating what kind of entries to consider.
  10600. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  10601. \(i.e., deadlines and scheduled items with a hh:mm specification)
  10602. and :timestamp entries. See the docstring of `org-diary' for
  10603. details and examples.
  10604. If an entry has a APPT_WARNTIME property, its value will be used
  10605. to override `appt-message-warning-time'."
  10606. (interactive "P")
  10607. (when refresh (setq appt-time-msg-list nil))
  10608. (when (eq filter t)
  10609. (setq filter (read-from-minibuffer "Regexp filter: ")))
  10610. (let* ((cnt 0) ; count added events
  10611. (scope (or args '(:deadline* :scheduled* :timestamp)))
  10612. (org-agenda-new-buffers nil)
  10613. (org-deadline-warning-days 0)
  10614. ;; Do not use `org-today' here because appt only takes
  10615. ;; time and without date as argument, so it may pass wrong
  10616. ;; information otherwise
  10617. (today (org-date-to-gregorian
  10618. (time-to-days nil)))
  10619. (org-agenda-restrict nil)
  10620. (files (org-agenda-files 'unrestricted)) entries file
  10621. (org-agenda-buffer nil))
  10622. ;; Get all entries which may contain an appt
  10623. (org-agenda-prepare-buffers files)
  10624. (while (setq file (pop files))
  10625. (setq entries
  10626. (delq nil
  10627. (append entries
  10628. (apply #'org-agenda-get-day-entries
  10629. file today scope)))))
  10630. ;; Map through entries and find if we should filter them out
  10631. (mapc
  10632. (lambda (x)
  10633. (let* ((evt (org-trim
  10634. (replace-regexp-in-string
  10635. org-link-bracket-re "\\2"
  10636. (or (get-text-property 1 'txt x) ""))))
  10637. (cat (get-text-property (1- (length x)) 'org-category x))
  10638. (tod (get-text-property 1 'time-of-day x))
  10639. (ok (or (null filter)
  10640. (and (stringp filter) (string-match filter evt))
  10641. (and (functionp filter) (funcall filter x))
  10642. (and (listp filter)
  10643. (let ((cat-filter (cadr (assq 'category filter)))
  10644. (evt-filter (cadr (assq 'headline filter))))
  10645. (or (and (stringp cat-filter)
  10646. (string-match cat-filter cat))
  10647. (and (stringp evt-filter)
  10648. (string-match evt-filter evt)))))))
  10649. (wrn (get-text-property 1 'warntime x)))
  10650. ;; FIXME: Shall we remove text-properties for the appt text?
  10651. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  10652. (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
  10653. (setq tod (concat "00" (number-to-string tod)))
  10654. (setq tod (when (string-match
  10655. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  10656. (concat (match-string 1 tod) ":"
  10657. (match-string 2 tod))))
  10658. (when (appt-add tod evt wrn)
  10659. (setq cnt (1+ cnt))))))
  10660. entries)
  10661. (org-release-buffers org-agenda-new-buffers)
  10662. (if (eq cnt 0)
  10663. (message "No event to add")
  10664. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  10665. (defun org-agenda-today-p (date)
  10666. "Non-nil when DATE means today.
  10667. DATE is either a list of the form (month day year) or a number of
  10668. days as returned by `calendar-absolute-from-gregorian' or
  10669. `org-today'. This function considers `org-extend-today-until'
  10670. when defining today."
  10671. (eq (org-today)
  10672. (if (consp date) (calendar-absolute-from-gregorian date) date)))
  10673. (defun org-agenda-todo-yesterday (&optional arg)
  10674. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  10675. (interactive "P")
  10676. (let* ((org-use-effective-time t)
  10677. (hour (nth 2 (decode-time (org-current-time))))
  10678. (org-extend-today-until (1+ hour)))
  10679. (org-agenda-todo arg)))
  10680. (defun org-agenda-ctrl-c-ctrl-c ()
  10681. "Set tags in agenda buffer."
  10682. (interactive)
  10683. (org-agenda-set-tags))
  10684. (provide 'org-agenda)
  10685. ;;; org-agenda.el ends here