org-agenda.el 449 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441
  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 the manual for a description of tag and property searches.
  559. The entire tree below a headline matched by this is considered one project.
  560. 2. A list of TODO keywords identifying non-stuck projects.
  561. If the project subtree contains any headline with one of these todo
  562. keywords, the project is considered to be not stuck. If you specify
  563. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  564. 3. A list of tags identifying non-stuck projects.
  565. If the project subtree contains any headline with one of these tags,
  566. the project is considered to be not stuck. If you specify \"*\" as
  567. a tag, any tag will mark the project unstuck. Note that this is about
  568. the explicit presence of a tag somewhere in the subtree, inherited
  569. tags do not count here. If inherited tags make a project not stuck,
  570. use \"-TAG\" in the tags part of the matcher under (1.) above.
  571. 4. An arbitrary regular expression matching non-stuck projects.
  572. If the project turns out to be not stuck, search continues also in the
  573. subtree to see if any of the subtasks have project status.
  574. See also the variable `org-tags-match-list-sublevels' which applies
  575. to projects matched by this search as well.
  576. After defining this variable, you may use `org-agenda-list-stuck-projects'
  577. \(bound to `\\[org-agenda] #') to produce the list."
  578. :group 'org-agenda-custom-commands
  579. :type '(list
  580. (string :tag "Tags/TODO match to identify a project")
  581. (repeat :tag "Projects are *not* stuck if they have an entry with \
  582. TODO keyword any of" (string))
  583. (repeat :tag "Projects are *not* stuck if they have an entry with \
  584. TAG being any of" (string))
  585. (regexp :tag "Projects are *not* stuck if this regexp matches inside \
  586. the subtree")))
  587. (defgroup org-agenda-skip nil
  588. "Options concerning skipping parts of agenda files."
  589. :tag "Org Agenda Skip"
  590. :group 'org-agenda)
  591. (defcustom org-agenda-skip-function-global nil
  592. "Function to be called at each match during agenda construction.
  593. If this function returns nil, the current match should not be skipped.
  594. If the function decided to skip an agenda match, is must return the
  595. buffer position from which the search should be continued.
  596. This may also be a Lisp form, which will be evaluated.
  597. This variable will be applied to every agenda match, including
  598. tags/property searches and TODO lists. So try to make the test function
  599. do its checking as efficiently as possible. To implement a skipping
  600. condition just for specific agenda commands, use the variable
  601. `org-agenda-skip-function' which can be set in the options section
  602. of custom agenda commands."
  603. :group 'org-agenda-skip
  604. :type 'sexp)
  605. (defgroup org-agenda-daily/weekly nil
  606. "Options concerning the daily/weekly agenda."
  607. :tag "Org Agenda Daily/Weekly"
  608. :group 'org-agenda)
  609. (defgroup org-agenda-todo-list nil
  610. "Options concerning the global todo list agenda view."
  611. :tag "Org Agenda Todo List"
  612. :group 'org-agenda)
  613. (defgroup org-agenda-match-view nil
  614. "Options concerning the general tags/property/todo match agenda view."
  615. :tag "Org Agenda Match View"
  616. :group 'org-agenda)
  617. (defgroup org-agenda-search-view nil
  618. "Options concerning the search agenda view."
  619. :tag "Org Agenda Search View"
  620. :group 'org-agenda)
  621. (defvar org-agenda-archives-mode nil
  622. "Non-nil means the agenda will include archived items.
  623. If this is the symbol `trees', trees in the selected agenda scope
  624. that are marked with the ARCHIVE tag will be included anyway. When this is
  625. t, also all archive files associated with the current selection of agenda
  626. files will be included.")
  627. (defcustom org-agenda-restriction-lock-highlight-subtree t
  628. "Non-nil means highlight the whole subtree when restriction is active.
  629. Otherwise only highlight the headline. Highlighting the whole subtree is
  630. useful to ensure no edits happen beyond the restricted region."
  631. :group 'org-agenda
  632. :type 'boolean)
  633. (defcustom org-agenda-skip-comment-trees t
  634. "Non-nil means skip trees that start with the COMMENT keyword.
  635. When nil, these trees are also scanned by agenda commands."
  636. :group 'org-agenda-skip
  637. :type 'boolean)
  638. (defcustom org-agenda-todo-list-sublevels t
  639. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  640. When nil, the sublevels of a TODO entry are not checked, resulting in
  641. potentially much shorter TODO lists."
  642. :group 'org-agenda-skip
  643. :group 'org-agenda-todo-list
  644. :type 'boolean)
  645. (defcustom org-agenda-todo-ignore-with-date nil
  646. "Non-nil means don't show entries with a date in the global todo list.
  647. You can use this if you prefer to mark mere appointments with a TODO keyword,
  648. but don't want them to show up in the TODO list.
  649. When this is set, it also covers deadlines and scheduled items, the settings
  650. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  651. will be ignored.
  652. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  653. :group 'org-agenda-skip
  654. :group 'org-agenda-todo-list
  655. :type 'boolean)
  656. (defcustom org-agenda-todo-ignore-timestamp nil
  657. "Non-nil means don't show entries with a timestamp.
  658. This applies when creating the global todo list.
  659. Valid values are:
  660. past Don't show entries for today or in the past.
  661. future Don't show entries with a timestamp in the future.
  662. The idea behind this is that if it has a future
  663. timestamp, you don't want to think about it until the
  664. date.
  665. all Don't show any entries with a timestamp in the global todo list.
  666. The idea behind this is that by setting a timestamp, you
  667. have already \"taken care\" of this item.
  668. This variable can also have an integer as a value. If positive (N),
  669. todos with a timestamp N or more days in the future will be ignored. If
  670. negative (-N), todos with a timestamp N or more days in the past will be
  671. ignored. If 0, todos with a timestamp either today or in the future will
  672. be ignored. For example, a value of -1 will exclude todos with a
  673. timestamp in the past (yesterday or earlier), while a value of 7 will
  674. exclude todos with a timestamp a week or more in the future.
  675. See also `org-agenda-todo-ignore-with-date'.
  676. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  677. to make his option also apply to the tags-todo list."
  678. :group 'org-agenda-skip
  679. :group 'org-agenda-todo-list
  680. :version "24.1"
  681. :type '(choice
  682. (const :tag "Ignore future timestamp todos" future)
  683. (const :tag "Ignore past or present timestamp todos" past)
  684. (const :tag "Ignore all timestamp todos" all)
  685. (const :tag "Show timestamp todos" nil)
  686. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  687. (defcustom org-agenda-todo-ignore-scheduled nil
  688. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  689. This applies when creating the global todo list.
  690. Valid values are:
  691. past Don't show entries scheduled today or in the past.
  692. future Don't show entries scheduled in the future.
  693. The idea behind this is that by scheduling it, you don't want to
  694. think about it until the scheduled date.
  695. all Don't show any scheduled entries in the global todo list.
  696. The idea behind this is that by scheduling it, you have already
  697. \"taken care\" of this item.
  698. t Same as `all', for backward compatibility.
  699. This variable can also have an integer as a value. See
  700. `org-agenda-todo-ignore-timestamp' for more details.
  701. See also `org-agenda-todo-ignore-with-date'.
  702. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  703. to make his option also apply to the tags-todo list."
  704. :group 'org-agenda-skip
  705. :group 'org-agenda-todo-list
  706. :type '(choice
  707. (const :tag "Ignore future-scheduled todos" future)
  708. (const :tag "Ignore past- or present-scheduled todos" past)
  709. (const :tag "Ignore all scheduled todos" all)
  710. (const :tag "Ignore all scheduled todos (compatibility)" t)
  711. (const :tag "Show scheduled todos" nil)
  712. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  713. (defcustom org-agenda-todo-ignore-deadlines nil
  714. "Non-nil means ignore some deadline TODO items when making TODO list.
  715. There are different motivations for using different values, please think
  716. carefully when configuring this variable.
  717. This applies when creating the global TODO list.
  718. Valid values are:
  719. near Don't show near deadline entries. A deadline is near when it is
  720. closer than `org-deadline-warning-days' days. The idea behind this
  721. is that such items will appear in the agenda anyway.
  722. far Don't show TODO entries where a deadline has been defined, but
  723. is not going to happen anytime soon. This is useful if you want to use
  724. the TODO list to figure out what to do now.
  725. past Don't show entries with a deadline timestamp for today or in the past.
  726. future Don't show entries with a deadline timestamp in the future, not even
  727. when they become `near' ones. Use it with caution.
  728. all Ignore all TODO entries that do have a deadline.
  729. t Same as `near', for backward compatibility.
  730. This variable can also have an integer as a value. See
  731. `org-agenda-todo-ignore-timestamp' for more details.
  732. See also `org-agenda-todo-ignore-with-date'.
  733. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  734. to make his option also apply to the tags-todo list."
  735. :group 'org-agenda-skip
  736. :group 'org-agenda-todo-list
  737. :type '(choice
  738. (const :tag "Ignore near deadlines" near)
  739. (const :tag "Ignore near deadlines (compatibility)" t)
  740. (const :tag "Ignore far deadlines" far)
  741. (const :tag "Ignore all TODOs with a deadlines" all)
  742. (const :tag "Show all TODOs, even if they have a deadline" nil)
  743. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  744. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  745. "Time unit to use when possibly ignoring an agenda item.
  746. See the docstring of various `org-agenda-todo-ignore-*' options.
  747. The default is to compare time stamps using days. An item is thus
  748. considered to be in the future if it is at least one day after today.
  749. Non-nil means to compare time stamps using seconds. An item is then
  750. considered future if it has a time value later than current time."
  751. :group 'org-agenda-skip
  752. :group 'org-agenda-todo-list
  753. :version "24.4"
  754. :package-version '(Org . "8.0")
  755. :type '(choice
  756. (const :tag "Compare time with days" nil)
  757. (const :tag "Compare time with seconds" t)))
  758. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  759. "Non-nil means honor todo-list ignores options also in tags-todo search.
  760. The variables
  761. `org-agenda-todo-ignore-with-date',
  762. `org-agenda-todo-ignore-timestamp',
  763. `org-agenda-todo-ignore-scheduled',
  764. `org-agenda-todo-ignore-deadlines'
  765. make the global TODO list skip entries that have time stamps of certain
  766. kinds. If this option is set, the same options will also apply for the
  767. tags-todo search, which is the general tags/property matcher
  768. restricted to unfinished TODO entries only."
  769. :group 'org-agenda-skip
  770. :group 'org-agenda-todo-list
  771. :group 'org-agenda-match-view
  772. :type 'boolean)
  773. (defcustom org-agenda-skip-scheduled-if-done nil
  774. "Non-nil means don't show scheduled items in agenda when they are done.
  775. This is relevant for the daily/weekly agenda, not for the TODO list. It
  776. applies only to the actual date of the scheduling. Warnings about an item
  777. with a past scheduling dates are always turned off when the item is DONE."
  778. :group 'org-agenda-skip
  779. :group 'org-agenda-daily/weekly
  780. :type 'boolean)
  781. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  782. "Non-nil means skip scheduling line if same entry shows because of deadline.
  783. In the agenda of today, an entry can show up multiple times
  784. because it is both scheduled and has a nearby deadline, and maybe
  785. a plain time stamp as well.
  786. When this variable is nil, the entry will be shown several times.
  787. When set to t, then only the deadline is shown and the fact that
  788. the entry is scheduled today or was scheduled previously is not
  789. shown.
  790. When set to the symbol `not-today', skip scheduled previously,
  791. but not scheduled today.
  792. When set to the symbol `repeated-after-deadline', skip scheduled
  793. items if they are repeated beyond the current deadline."
  794. :group 'org-agenda-skip
  795. :group 'org-agenda-daily/weekly
  796. :type '(choice
  797. (const :tag "Never" nil)
  798. (const :tag "Always" t)
  799. (const :tag "Not when scheduled today" not-today)
  800. (const :tag "When repeated past deadline" repeated-after-deadline)))
  801. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  802. "Non-nil means skip timestamp line if same entry shows because of deadline.
  803. In the agenda of today, an entry can show up multiple times
  804. because it has both a plain timestamp and has a nearby deadline.
  805. When this variable is t, then only the deadline is shown and the
  806. fact that the entry has a timestamp for or including today is not
  807. shown. When this variable is nil, the entry will be shown
  808. several times."
  809. :group 'org-agenda-skip
  810. :group 'org-agenda-daily/weekly
  811. :version "24.1"
  812. :type '(choice
  813. (const :tag "Never" nil)
  814. (const :tag "Always" t)))
  815. (defcustom org-agenda-skip-deadline-if-done nil
  816. "Non-nil means don't show deadlines when the corresponding item is done.
  817. When nil, the deadline is still shown and should give you a happy feeling.
  818. This is relevant for the daily/weekly agenda. It applies only to the
  819. actual date of the deadline. Warnings about approaching and past-due
  820. deadlines are always turned off when the item is DONE."
  821. :group 'org-agenda-skip
  822. :group 'org-agenda-daily/weekly
  823. :type 'boolean)
  824. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  825. "Non-nil means skip deadline prewarning when entry is also scheduled.
  826. This will apply on all days where a prewarning for the deadline would
  827. be shown, but not at the day when the entry is actually due. On that day,
  828. the deadline will be shown anyway.
  829. This variable may be set to nil, t, the symbol `pre-scheduled',
  830. or a number which will then give the number of days before the actual
  831. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  832. eliminates the deadline prewarning only prior to the scheduled date.
  833. This can be used in a workflow where the first showing of the deadline will
  834. trigger you to schedule it, and then you don't want to be reminded of it
  835. because you will take care of it on the day when scheduled."
  836. :group 'org-agenda-skip
  837. :group 'org-agenda-daily/weekly
  838. :version "24.1"
  839. :type '(choice
  840. (const :tag "Always show prewarning" nil)
  841. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  842. (const :tag "Remove prewarning if entry is scheduled" t)
  843. (integer :tag "Restart prewarning N days before deadline")))
  844. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  845. "Non-nil means skip scheduled delay when entry also has a deadline.
  846. This variable may be set to nil, t, the symbol `post-deadline',
  847. or a number which will then give the number of days after the actual
  848. scheduled date when the delay should expire. The symbol `post-deadline'
  849. eliminates the schedule delay when the date is posterior to the deadline."
  850. :group 'org-agenda-skip
  851. :group 'org-agenda-daily/weekly
  852. :version "24.4"
  853. :package-version '(Org . "8.0")
  854. :type '(choice
  855. (const :tag "Always honor delay" nil)
  856. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  857. (const :tag "Ignore delay if entry has a deadline" t)
  858. (integer :tag "Honor delay up until N days after the scheduled date")))
  859. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  860. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  861. When non-nil, after the search for timestamps has matched once in an
  862. entry, the rest of the entry will not be searched."
  863. :group 'org-agenda-skip
  864. :type 'boolean)
  865. (defcustom org-agenda-skip-timestamp-if-done nil
  866. "Non-nil means don't select item by timestamp or -range if it is DONE."
  867. :group 'org-agenda-skip
  868. :group 'org-agenda-daily/weekly
  869. :type 'boolean)
  870. (defcustom org-agenda-dim-blocked-tasks t
  871. "Non-nil means dim blocked tasks in the agenda display.
  872. This causes some overhead during agenda construction, but if you
  873. have turned on `org-enforce-todo-dependencies',
  874. `org-enforce-todo-checkbox-dependencies', or any other blocking
  875. mechanism, this will create useful feedback in the agenda.
  876. Instead of t, this variable can also have the value `invisible'.
  877. Then blocked tasks will be invisible and only become visible when
  878. they become unblocked. An exemption to this behavior is when a task is
  879. blocked because of unchecked checkboxes below it. Since checkboxes do
  880. not show up in the agenda views, making this task invisible you remove any
  881. trace from agenda views that there is something to do. Therefore, a task
  882. that is blocked because of checkboxes will never be made invisible, it
  883. will only be dimmed."
  884. :group 'org-agenda-daily/weekly
  885. :group 'org-agenda-todo-list
  886. :version "24.3"
  887. :type '(choice
  888. (const :tag "Do not dim" nil)
  889. (const :tag "Dim to a gray face" t)
  890. (const :tag "Make invisible" invisible)))
  891. (defgroup org-agenda-startup nil
  892. "Options concerning initial settings in the Agenda in Org Mode."
  893. :tag "Org Agenda Startup"
  894. :group 'org-agenda)
  895. (defcustom org-agenda-menu-show-matcher t
  896. "Non-nil means show the match string in the agenda dispatcher menu.
  897. When nil, the matcher string is not shown, but is put into the help-echo
  898. property so than moving the mouse over the command shows it.
  899. Setting it to nil is good if matcher strings are very long and/or if
  900. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  901. :group 'org-agenda
  902. :version "24.1"
  903. :type 'boolean)
  904. (defcustom org-agenda-menu-two-columns nil
  905. "Non-nil means, use two columns to show custom commands in the dispatcher.
  906. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  907. to nil."
  908. :group 'org-agenda
  909. :version "24.1"
  910. :type 'boolean)
  911. (defcustom org-agenda-finalize-hook nil
  912. "Hook run just before displaying an agenda buffer.
  913. The buffer is still writable when the hook is called.
  914. You can modify some of the buffer substrings but you should be
  915. extra careful not to modify the text properties of the agenda
  916. headlines as the agenda display heavily relies on them."
  917. :group 'org-agenda-startup
  918. :type 'hook)
  919. (defcustom org-agenda-filter-hook nil
  920. "Hook run just after filtering with `org-agenda-filter'."
  921. :group 'org-agenda-startup
  922. :package-version '(Org . "9.4")
  923. :type 'hook)
  924. (defcustom org-agenda-mouse-1-follows-link nil
  925. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  926. A longer mouse click will still set point. Needs to be set
  927. before org.el is loaded."
  928. :group 'org-agenda-startup
  929. :type 'boolean)
  930. (defcustom org-agenda-start-with-follow-mode nil
  931. "The initial value of follow mode in a newly created agenda window."
  932. :group 'org-agenda-startup
  933. :type 'boolean)
  934. (defcustom org-agenda-follow-indirect nil
  935. "Non-nil means `org-agenda-follow-mode' displays only the
  936. current item's tree, in an indirect buffer."
  937. :group 'org-agenda
  938. :version "24.1"
  939. :type 'boolean)
  940. (defcustom org-agenda-show-outline-path t
  941. "Non-nil means show outline path in echo area after line motion."
  942. :group 'org-agenda-startup
  943. :type 'boolean)
  944. (defcustom org-agenda-start-with-entry-text-mode nil
  945. "The initial value of entry-text-mode in a newly created agenda window."
  946. :group 'org-agenda-startup
  947. :type 'boolean)
  948. (defcustom org-agenda-entry-text-maxlines 5
  949. "Number of text lines to be added when `E' is pressed in the agenda.
  950. Note that this variable only used during agenda display. To add entry text
  951. when exporting the agenda, configure the variable
  952. `org-agenda-add-entry-text-maxlines'."
  953. :group 'org-agenda
  954. :type 'integer)
  955. (defcustom org-agenda-entry-text-exclude-regexps nil
  956. "List of regular expressions to clean up entry text.
  957. The complete matches of all regular expressions in this list will be
  958. removed from entry text before it is shown in the agenda."
  959. :group 'org-agenda
  960. :type '(repeat (regexp)))
  961. (defcustom org-agenda-entry-text-leaders " > "
  962. "Text prepended to the entry text in agenda buffers."
  963. :version "24.4"
  964. :package-version '(Org . "8.0")
  965. :group 'org-agenda
  966. :type 'string)
  967. (defvar org-agenda-entry-text-cleanup-hook nil
  968. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  969. This cleanup is done in a temporary buffer, so the function may inspect and
  970. change the entire buffer.
  971. Some default stuff like drawers and scheduling/deadline dates will already
  972. have been removed when this is called, as will any matches for regular
  973. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  974. (defvar org-agenda-include-inactive-timestamps nil
  975. "Non-nil means include inactive time stamps in agenda.
  976. Dynamically scoped.")
  977. (defgroup org-agenda-windows nil
  978. "Options concerning the windows used by the Agenda in Org Mode."
  979. :tag "Org Agenda Windows"
  980. :group 'org-agenda)
  981. (defcustom org-agenda-window-setup 'reorganize-frame
  982. "How the agenda buffer should be displayed.
  983. Possible values for this option are:
  984. current-window Show agenda in the current window, keeping all other windows.
  985. other-window Use `switch-to-buffer-other-window' to display agenda.
  986. only-window Show agenda, deleting all other windows.
  987. reorganize-frame Show only two windows on the current frame, the current
  988. window and the agenda.
  989. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  990. Also, when exiting the agenda, kill that frame.
  991. other-tab Use `switch-to-buffer-other-tab' to display the
  992. agenda, making use of the `tab-bar-mode' introduced
  993. in Emacs version 27.1. Also, kill that tab when
  994. exiting the agenda view.
  995. See also the variable `org-agenda-restore-windows-after-quit'."
  996. :group 'org-agenda-windows
  997. :type '(choice
  998. (const current-window)
  999. (const other-frame)
  1000. (const other-tab)
  1001. (const other-window)
  1002. (const only-window)
  1003. (const reorganize-frame))
  1004. :package-version '(Org . "9.4"))
  1005. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  1006. "The min and max height of the agenda window as a fraction of frame height.
  1007. The value of the variable is a cons cell with two numbers between 0 and 1.
  1008. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  1009. :group 'org-agenda-windows
  1010. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  1011. (defcustom org-agenda-restore-windows-after-quit nil
  1012. "Non-nil means restore window configuration upon exiting agenda.
  1013. Before the window configuration is changed for displaying the
  1014. agenda, the current status is recorded. When the agenda is
  1015. exited with `q' or `x' and this option is set, the old state is
  1016. restored. If `org-agenda-window-setup' is `other-frame' or
  1017. `other-tab', the value of this option will be ignored."
  1018. :group 'org-agenda-windows
  1019. :type 'boolean)
  1020. (defcustom org-agenda-span 'week
  1021. "Number of days to include in overview display.
  1022. Can be day, week, month, year, or any number of days.
  1023. Custom commands can set this variable in the options section."
  1024. :group 'org-agenda-daily/weekly
  1025. :type '(choice (const :tag "Day" day)
  1026. (const :tag "Week" week)
  1027. (const :tag "Fortnight" fortnight)
  1028. (const :tag "Month" month)
  1029. (const :tag "Year" year)
  1030. (integer :tag "Custom")))
  1031. (defcustom org-agenda-start-on-weekday 1
  1032. "Non-nil means start the overview always on the specified weekday.
  1033. 0 denotes Sunday, 1 denotes Monday, etc.
  1034. When nil, always start on the current day.
  1035. Custom commands can set this variable in the options section."
  1036. :group 'org-agenda-daily/weekly
  1037. :type '(choice (const :tag "Today" nil)
  1038. (integer :tag "Weekday No.")))
  1039. (defcustom org-agenda-show-all-dates t
  1040. "Non-nil means `org-agenda' shows every day in the selected range.
  1041. When nil, only the days which actually have entries are shown."
  1042. :group 'org-agenda-daily/weekly
  1043. :type 'boolean)
  1044. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1045. "Format string for displaying dates in the agenda.
  1046. Used by the daily/weekly agenda. This should be a format string
  1047. understood by `format-time-string', or a function returning the
  1048. formatted date as a string. The function must take a single
  1049. argument, a calendar-style date list like (month day year)."
  1050. :group 'org-agenda-daily/weekly
  1051. :type '(choice
  1052. (string :tag "Format string")
  1053. (function :tag "Function")))
  1054. (defun org-agenda-end-of-line ()
  1055. "Go to the end of visible line."
  1056. (interactive)
  1057. (goto-char (line-end-position)))
  1058. (defun org-agenda-format-date-aligned (date)
  1059. "Format a DATE string for display in the daily/weekly agenda.
  1060. This function makes sure that dates are aligned for easy reading."
  1061. (require 'cal-iso)
  1062. (let* ((dayname (calendar-day-name date))
  1063. (day (cadr date))
  1064. (day-of-week (calendar-day-of-week date))
  1065. (month (car date))
  1066. (monthname (calendar-month-name month))
  1067. (year (nth 2 date))
  1068. (iso-week (org-days-to-iso-week
  1069. (calendar-absolute-from-gregorian date)))
  1070. ;; (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1071. ;; (1- year))
  1072. ;; ((and (= month 12) (<= iso-week 1))
  1073. ;; (1+ year))
  1074. ;; (t year)))
  1075. (weekstring (if (= day-of-week 1)
  1076. (format " W%02d" iso-week)
  1077. "")))
  1078. (format "%-10s %2d %s %4d%s"
  1079. dayname day monthname year weekstring)))
  1080. (defcustom org-agenda-time-leading-zero nil
  1081. "Non-nil means use leading zero for military times in agenda.
  1082. For example, 9:30am would become 09:30 rather than 9:30."
  1083. :group 'org-agenda-daily/weekly
  1084. :version "24.1"
  1085. :type 'boolean)
  1086. (defcustom org-agenda-timegrid-use-ampm nil
  1087. "When set, show AM/PM style timestamps on the timegrid."
  1088. :group 'org-agenda
  1089. :version "24.1"
  1090. :type 'boolean)
  1091. (defcustom org-agenda-clock-report-header nil
  1092. "Header inserted before the table in Org agenda clock report mode.
  1093. See Info node `(org) Agenda Commands' for more details."
  1094. :group 'org-agenda
  1095. :type '(choice
  1096. (string :tag "Header")
  1097. (const :tag "No header" nil))
  1098. :safe #'stringp
  1099. :package-version '(Org . "9.6"))
  1100. (defun org-agenda-time-of-day-to-ampm (time)
  1101. "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
  1102. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1103. (minute (substring time -2))
  1104. (ampm "am"))
  1105. (cond
  1106. ((equal hour-number 12)
  1107. (setq ampm "pm"))
  1108. ((> hour-number 12)
  1109. (setq ampm "pm")
  1110. (setq hour-number (- hour-number 12))))
  1111. (concat
  1112. (if org-agenda-time-leading-zero
  1113. (format "%02d" hour-number)
  1114. (format "%02s" (number-to-string hour-number)))
  1115. ":" minute ampm)))
  1116. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1117. "Conditionally convert TIME to AM/PM format.
  1118. This is based on `org-agenda-timegrid-use-ampm'."
  1119. (if org-agenda-timegrid-use-ampm
  1120. (org-agenda-time-of-day-to-ampm time)
  1121. time))
  1122. (defcustom org-agenda-weekend-days '(6 0)
  1123. "Which days are weekend?
  1124. These days get the special face `org-agenda-date-weekend' in the agenda."
  1125. :group 'org-agenda-daily/weekly
  1126. :type '(set :greedy t
  1127. (const :tag "Monday" 1)
  1128. (const :tag "Tuesday" 2)
  1129. (const :tag "Wednesday" 3)
  1130. (const :tag "Thursday" 4)
  1131. (const :tag "Friday" 5)
  1132. (const :tag "Saturday" 6)
  1133. (const :tag "Sunday" 0)))
  1134. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1135. "Non-nil means jump to today when moving a past date forward in time.
  1136. When using S-right in the agenda to move a date forward, and the date
  1137. stamp currently points to the past, the first key press will move it
  1138. to today. When nil, just move one day forward even if the date stays
  1139. in the past."
  1140. :group 'org-agenda-daily/weekly
  1141. :version "24.1"
  1142. :type 'boolean)
  1143. (defcustom org-agenda-diary-file 'diary-file
  1144. "File to which to add new entries with the `i' key in agenda and calendar.
  1145. When this is the symbol `diary-file', the functionality in the Emacs
  1146. calendar will be used to add entries to the `diary-file'. But when this
  1147. points to a file, `org-agenda-diary-entry' will be used instead."
  1148. :group 'org-agenda
  1149. :type '(choice
  1150. (const :tag "The standard Emacs diary file" diary-file)
  1151. (file :tag "Special Org file diary entries")))
  1152. (defcustom org-agenda-include-diary nil
  1153. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1154. Custom commands can set this variable in the options section."
  1155. :group 'org-agenda-daily/weekly
  1156. :type 'boolean)
  1157. (defcustom org-agenda-include-deadlines t
  1158. "If non-nil, include entries within their deadline warning period.
  1159. Custom commands can set this variable in the options section."
  1160. :group 'org-agenda-daily/weekly
  1161. :version "24.1"
  1162. :type 'boolean)
  1163. (defcustom org-agenda-show-future-repeats t
  1164. "Non-nil shows repeated entries in the future part of the agenda.
  1165. When set to the symbol `next' only the first future repeat is shown."
  1166. :group 'org-agenda-daily/weekly
  1167. :type '(choice
  1168. (const :tag "Show all repeated entries" t)
  1169. (const :tag "Show next repeated entry" next)
  1170. (const :tag "Do not show repeated entries" nil))
  1171. :version "26.1"
  1172. :package-version '(Org . "9.1")
  1173. :safe #'symbolp)
  1174. (defcustom org-agenda-prefer-last-repeat nil
  1175. "Non-nil sets date for repeated entries to their last repeat.
  1176. When nil, display SCHEDULED and DEADLINE dates at their base
  1177. date, and in today's agenda, as a reminder. Display plain
  1178. time-stamps, on the other hand, at every repeat date in the past
  1179. in addition to the base date.
  1180. When non-nil, show a repeated entry at its latest repeat date,
  1181. possibly being today even if it wasn't marked as done. This
  1182. setting is useful if you do not always mark repeated entries as
  1183. done and, yet, consider that reaching repeat date starts the task
  1184. anew.
  1185. When set to a list of strings, prefer last repeats only for
  1186. entries with these TODO keywords."
  1187. :group 'org-agenda-daily/weekly
  1188. :type '(choice
  1189. (const :tag "Prefer last repeat" t)
  1190. (const :tag "Prefer base date" nil)
  1191. (repeat :tag "Prefer last repeat for entries with these TODO keywords"
  1192. (string :tag "TODO keyword")))
  1193. :version "26.1"
  1194. :package-version '(Org . "9.1")
  1195. :safe (lambda (x) (or (booleanp x) (consp x))))
  1196. (defcustom org-scheduled-past-days 10000
  1197. "Number of days to continue listing scheduled items not marked DONE.
  1198. When an item is scheduled on a date, it shows up in the agenda on
  1199. this day and will be listed until it is marked done or for the
  1200. number of days given here."
  1201. :group 'org-agenda-daily/weekly
  1202. :type 'integer
  1203. :safe 'integerp)
  1204. (defcustom org-deadline-past-days 10000
  1205. "Number of days to warn about missed deadlines.
  1206. When an item has deadline on a date, it shows up in the agenda on
  1207. this day and will appear as a reminder until it is marked DONE or
  1208. for the number of days given here."
  1209. :group 'org-agenda-daily/weekly
  1210. :type 'integer
  1211. :version "26.1"
  1212. :package-version '(Org . "9.1")
  1213. :safe 'integerp)
  1214. (defcustom org-agenda-log-mode-items '(closed clock)
  1215. "List of items that should be shown in agenda log mode.
  1216. \\<org-agenda-mode-map>\
  1217. This list may contain the following symbols:
  1218. closed Show entries that have been closed on that day.
  1219. clock Show entries that have received clocked time on that day.
  1220. state Show all logged state changes.
  1221. Note that instead of changing this variable, you can also press \
  1222. `\\[universal-argument] \\[org-agenda-log-mode]' in
  1223. the agenda to display all available LOG items temporarily."
  1224. :group 'org-agenda-daily/weekly
  1225. :type '(set :greedy t (const closed) (const clock) (const state)))
  1226. (defcustom org-agenda-clock-consistency-checks
  1227. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1228. :gap-ok-around ("4:00")
  1229. :default-face ((:background "DarkRed") (:foreground "white"))
  1230. :overlap-face nil :gap-face nil :no-end-time-face nil
  1231. :long-face nil :short-face nil)
  1232. "This is a property list, with the following keys:
  1233. :max-duration Mark clocking chunks that are longer than this time.
  1234. This is a time string like \"HH:MM\", or the number
  1235. of minutes as an integer.
  1236. :min-duration Mark clocking chunks that are shorter that this.
  1237. This is a time string like \"HH:MM\", or the number
  1238. of minutes as an integer.
  1239. :max-gap Mark gaps between clocking chunks that are longer than
  1240. this duration. A number of minutes, or a string
  1241. like \"HH:MM\".
  1242. :gap-ok-around List of times during the day which are usually not working
  1243. times. When a gap is detected, but the gap contains any
  1244. of these times, the gap is *not* reported. For example,
  1245. if this is (\"4:00\" \"13:00\") then gaps that contain
  1246. 4:00 in the morning (i.e. the night) and 13:00
  1247. (i.e. a typical lunch time) do not cause a warning.
  1248. You should have at least one time during the night in this
  1249. list, or otherwise the first task each morning will trigger
  1250. a warning because it follows a long gap.
  1251. Furthermore, the following properties can be used to define faces for
  1252. issue display.
  1253. :default-face the default face, if the specific face is undefined
  1254. :overlap-face face for overlapping clocks
  1255. :gap-face face for gaps between clocks
  1256. :no-end-time-face face for incomplete clocks
  1257. :long-face face for clock intervals that are too long
  1258. :short-face face for clock intervals that are too short"
  1259. :group 'org-agenda-daily/weekly
  1260. :group 'org-clock
  1261. :version "24.1"
  1262. :type 'plist)
  1263. (defcustom org-agenda-log-mode-add-notes t
  1264. "Non-nil means add first line of notes to log entries in agenda views.
  1265. If a log item like a state change or a clock entry is associated with
  1266. notes, the first line of these notes will be added to the entry in the
  1267. agenda display."
  1268. :group 'org-agenda-daily/weekly
  1269. :type 'boolean)
  1270. (defcustom org-agenda-start-with-log-mode nil
  1271. "The initial value of log-mode in a newly created agenda window.
  1272. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1273. explanations on the possible values."
  1274. :group 'org-agenda-startup
  1275. :group 'org-agenda-daily/weekly
  1276. :type '(choice (const :tag "Don't show log items" nil)
  1277. (const :tag "Show only log items" only)
  1278. (const :tag "Show all possible log items" clockcheck)
  1279. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1280. (choice (const :tag "Show closed log items" closed)
  1281. (const :tag "Show clocked log items" clock)
  1282. (const :tag "Show all logged state changes" state)))))
  1283. (defcustom org-agenda-start-with-clockreport-mode nil
  1284. "The initial value of clockreport-mode in a newly created agenda window."
  1285. :group 'org-agenda-startup
  1286. :group 'org-agenda-daily/weekly
  1287. :type 'boolean)
  1288. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1289. "Property list with parameters for the clocktable in clockreport mode.
  1290. This is the display mode that shows a clock table in the daily/weekly
  1291. agenda, the properties for this dynamic block can be set here.
  1292. The usual clocktable parameters are allowed here, but you cannot set
  1293. the properties :name, :tstart, :tend, :block, and :scope - these will
  1294. be overwritten to make sure the content accurately reflects the
  1295. current display in the agenda."
  1296. :group 'org-agenda-daily/weekly
  1297. :type 'plist)
  1298. (defvaralias 'org-agenda-search-view-search-words-only
  1299. 'org-agenda-search-view-always-boolean)
  1300. (defcustom org-agenda-search-view-always-boolean nil
  1301. "Non-nil means the search string is interpreted as individual parts.
  1302. The search string for search view can either be interpreted as a phrase,
  1303. or as a list of snippets that define a boolean search for a number of
  1304. strings.
  1305. When this is non-nil, the string will be split on whitespace, and each
  1306. snippet will be searched individually, and all must match in order to
  1307. select an entry. A snippet is then a single string of non-white
  1308. characters, or a string in double quotes, or a regexp in {} braces.
  1309. If a snippet is preceded by \"-\", the snippet must *not* match.
  1310. \"+\" is syntactic sugar for positive selection. Each snippet may
  1311. be found as a full word or a partial word, but see the variable
  1312. `org-agenda-search-view-force-full-words'.
  1313. When this is nil, search will look for the entire search phrase as one,
  1314. with each space character matching any amount of whitespace, including
  1315. line breaks.
  1316. Even when this is nil, you can still switch to Boolean search dynamically
  1317. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1318. is a regexp marked with braces like \"{abc}\", this will also switch to
  1319. boolean search."
  1320. :group 'org-agenda-search-view
  1321. :version "24.1"
  1322. :type 'boolean)
  1323. (defcustom org-agenda-search-view-force-full-words nil
  1324. "Non-nil means, search words must be matches as complete words.
  1325. When nil, they may also match part of a word."
  1326. :group 'org-agenda-search-view
  1327. :version "24.1"
  1328. :type 'boolean)
  1329. (defcustom org-agenda-search-view-max-outline-level 0
  1330. "Maximum outline level to display in search view.
  1331. E.g. when this is set to 1, the search view will only
  1332. show headlines of level 1. When set to 0, the default
  1333. value, don't limit agenda view by outline level."
  1334. :group 'org-agenda-search-view
  1335. :version "26.1"
  1336. :package-version '(Org . "8.3")
  1337. :type 'integer)
  1338. (defgroup org-agenda-time-grid nil
  1339. "Options concerning the time grid in the Org Agenda."
  1340. :tag "Org Agenda Time Grid"
  1341. :group 'org-agenda)
  1342. (defcustom org-agenda-search-headline-for-time t
  1343. "Non-nil means search headline for a time-of-day.
  1344. If the headline contains a time-of-day in one format or another, it will
  1345. be used to sort the entry into the time sequence of items for a day.
  1346. Some people have time stamps in the headline that refer to the creation
  1347. time or so, and then this produces an unwanted side effect. If this is
  1348. the case for your, use this variable to turn off searching the headline
  1349. for a time."
  1350. :group 'org-agenda-time-grid
  1351. :type 'boolean)
  1352. (defcustom org-agenda-use-time-grid t
  1353. "Non-nil means show a time grid in the agenda schedule.
  1354. A time grid is a set of lines for specific times (like every two hours between
  1355. 8:00 and 20:00). The items scheduled for a day at specific times are
  1356. sorted in between these lines.
  1357. For details about when the grid will be shown, and what it will look like, see
  1358. the variable `org-agenda-time-grid'."
  1359. :group 'org-agenda-time-grid
  1360. :type 'boolean)
  1361. (defcustom org-agenda-time-grid
  1362. (let ((graphical (and (display-graphic-p)
  1363. (char-displayable-p ?┄))))
  1364. `((daily today require-timed)
  1365. (800 1000 1200 1400 1600 1800 2000)
  1366. ,(if graphical " ┄┄┄┄┄ " "......")
  1367. ,(if graphical "┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄" "----------------")))
  1368. "The settings for time grid for agenda display.
  1369. This is a list of four items. The first item is again a list. It contains
  1370. symbols specifying conditions when the grid should be displayed:
  1371. daily if the agenda shows a single day
  1372. weekly if the agenda shows an entire week
  1373. today show grid on current date, independent of daily/weekly display
  1374. require-timed show grid only if at least one item has a time specification
  1375. remove-match skip grid times already present in an entry
  1376. The second item is a list of integers, indicating the times that
  1377. should have a grid line.
  1378. The third item is a string which will be placed right after the
  1379. times that have a grid line.
  1380. The fourth item is a string placed after the grid times. This
  1381. will align with agenda items."
  1382. :group 'org-agenda-time-grid
  1383. :package-version '(Org . "9.6")
  1384. :type
  1385. '(list
  1386. (set :greedy t :tag "Grid Display Options"
  1387. (const :tag "Show grid in single day agenda display" daily)
  1388. (const :tag "Show grid in weekly agenda display" weekly)
  1389. (const :tag "Always show grid for today" today)
  1390. (const :tag "Show grid only if any timed entries are present"
  1391. require-timed)
  1392. (const :tag "Skip grid times already present in an entry"
  1393. remove-match))
  1394. (repeat :tag "Grid Times" (integer :tag "Time"))
  1395. (string :tag "Grid String (after agenda times)")
  1396. (string :tag "Grid String (aligns with agenda items)")))
  1397. (defcustom org-agenda-show-current-time-in-grid t
  1398. "Non-nil means show the current time in the time grid."
  1399. :group 'org-agenda-time-grid
  1400. :version "24.1"
  1401. :type 'boolean)
  1402. (defcustom org-agenda-current-time-string
  1403. (if (and (display-graphic-p)
  1404. (char-displayable-p ?←)
  1405. (char-displayable-p ?─))
  1406. "← now ───────────────────────────────────────────────"
  1407. "now - - - - - - - - - - - - - - - - - - - - - - - - -")
  1408. "The string for the current time marker in the agenda."
  1409. :group 'org-agenda-time-grid
  1410. :package-version '(Org . "9.6")
  1411. :type 'string)
  1412. (defgroup org-agenda-sorting nil
  1413. "Options concerning sorting in the Org Agenda."
  1414. :tag "Org Agenda Sorting"
  1415. :group 'org-agenda)
  1416. (defcustom org-agenda-sorting-strategy
  1417. '((agenda habit-down time-up priority-down category-keep)
  1418. (todo priority-down category-keep)
  1419. (tags priority-down category-keep)
  1420. (search category-keep))
  1421. "Sorting structure for the agenda items of a single day.
  1422. This is a list of symbols which will be used in sequence to determine
  1423. if an entry should be listed before another entry. The following
  1424. symbols are recognized:
  1425. time-up Put entries with time-of-day indications first, early first.
  1426. time-down Put entries with time-of-day indications first, late first.
  1427. timestamp-up Sort by any timestamp, early first.
  1428. timestamp-down Sort by any timestamp, late first.
  1429. scheduled-up Sort by scheduled timestamp, early first.
  1430. scheduled-down Sort by scheduled timestamp, late first.
  1431. deadline-up Sort by deadline timestamp, early first.
  1432. deadline-down Sort by deadline timestamp, late first.
  1433. ts-up Sort by active timestamp, early first.
  1434. ts-down Sort by active timestamp, late first.
  1435. tsia-up Sort by inactive timestamp, early first.
  1436. tsia-down Sort by inactive timestamp, late first.
  1437. category-keep Keep the default order of categories, corresponding to the
  1438. sequence in `org-agenda-files'.
  1439. category-up Sort alphabetically by category, A-Z.
  1440. category-down Sort alphabetically by category, Z-A.
  1441. tag-up Sort alphabetically by last tag, A-Z.
  1442. tag-down Sort alphabetically by last tag, Z-A.
  1443. priority-up Sort numerically by priority, high priority last.
  1444. priority-down Sort numerically by priority, high priority first.
  1445. todo-state-up Sort by todo state, tasks that are done last.
  1446. todo-state-down Sort by todo state, tasks that are done first.
  1447. effort-up Sort numerically by estimated effort, high effort last.
  1448. effort-down Sort numerically by estimated effort, high effort first.
  1449. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1450. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1451. habit-up Put entries that are habits first.
  1452. habit-down Put entries that are habits last.
  1453. alpha-up Sort headlines alphabetically.
  1454. alpha-down Sort headlines alphabetically, reversed.
  1455. The different possibilities will be tried in sequence, and testing stops
  1456. if one comparison returns a \"not-equal\". For example,
  1457. (setq org-agenda-sorting-strategy
  1458. \\='(time-up category-keep priority-down))
  1459. means: Pull out all entries having a specified time of day and sort them,
  1460. in order to make a time schedule for the current day the first thing in the
  1461. agenda listing for the day. Of the entries without a time indication, keep
  1462. the grouped in categories, don't sort the categories, but keep them in
  1463. the sequence given in `org-agenda-files'. Within each category sort by
  1464. priority.
  1465. Leaving out `category-keep' would mean that items will be sorted across
  1466. categories by priority.
  1467. Instead of a single list, this can also be a set of list for specific
  1468. contents, with a context symbol in the car of the list, any of
  1469. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1470. Custom commands can bind this variable in the options section."
  1471. :group 'org-agenda-sorting
  1472. :type `(choice
  1473. (repeat :tag "General" ,org-sorting-choice)
  1474. (list :tag "Individually"
  1475. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1476. (repeat ,org-sorting-choice))
  1477. (cons (const :tag "Strategy for TODO lists" todo)
  1478. (repeat ,org-sorting-choice))
  1479. (cons (const :tag "Strategy for Tags matches" tags)
  1480. (repeat ,org-sorting-choice))
  1481. (cons (const :tag "Strategy for search matches" search)
  1482. (repeat ,org-sorting-choice)))))
  1483. (defcustom org-agenda-cmp-user-defined nil
  1484. "A function to define the comparison `user-defined'.
  1485. This function must receive two arguments, agenda entry a and b.
  1486. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1487. the user comparison, return nil.
  1488. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1489. part of an agenda sorting strategy."
  1490. :group 'org-agenda-sorting
  1491. :type 'symbol)
  1492. (defcustom org-agenda-sort-notime-is-late t
  1493. "Non-nil means items without time are considered late.
  1494. This is only relevant for sorting. When t, items which have no explicit
  1495. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1496. do have a time. When nil, the default time is before 0:00. You can use this
  1497. option to decide if the schedule for today should come before or after timeless
  1498. agenda entries."
  1499. :group 'org-agenda-sorting
  1500. :type 'boolean)
  1501. (defcustom org-agenda-sort-noeffort-is-high t
  1502. "Non-nil means items without effort estimate are sorted as high effort.
  1503. This also applies when filtering an agenda view with respect to the
  1504. < or > effort operator. Then, tasks with no effort defined will be treated
  1505. as tasks with high effort.
  1506. When nil, such items are sorted as 0 minutes effort."
  1507. :group 'org-agenda-sorting
  1508. :type 'boolean)
  1509. (defgroup org-agenda-line-format nil
  1510. "Options concerning the entry prefix in the Org agenda display."
  1511. :tag "Org Agenda Line Format"
  1512. :group 'org-agenda)
  1513. (defcustom org-agenda-prefix-format
  1514. '((agenda . " %i %-12:c%?-12t% s")
  1515. (todo . " %i %-12:c")
  1516. (tags . " %i %-12:c")
  1517. (search . " %i %-12:c"))
  1518. "Format specifications for the prefix of items in the agenda views.
  1519. An alist with one entry per agenda type. The keys of the
  1520. sublists are `agenda', `todo', `search' and `tags'. The values
  1521. are format strings.
  1522. This format works similar to a printf format, with the following meaning:
  1523. %c the category of the item, \"Diary\" for entries from the diary,
  1524. or as given by the CATEGORY keyword or derived from the file name
  1525. %e the effort required by the item
  1526. %l the level of the item (insert X space(s) if item is of level X)
  1527. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1528. %T the last tag of the item (ignore inherited tags, which come first)
  1529. %t the HH:MM time-of-day specification if one applies to the entry
  1530. %s Scheduling/Deadline information, a short string
  1531. %b show breadcrumbs, i.e., the names of the higher levels
  1532. %(expression) Eval EXPRESSION and replace the control string
  1533. by the result
  1534. All specifiers work basically like the standard `%s' of printf, but may
  1535. contain two additional characters: a question mark just after the `%'
  1536. and a whitespace/punctuation character just before the final letter.
  1537. If the first character after `%' is a question mark, the entire field
  1538. will only be included if the corresponding value applies to the current
  1539. entry. This is useful for fields which should have fixed width when
  1540. present, but zero width when absent. For example, \"%?-12t\" will
  1541. result in a 12 character time field if a time of the day is specified,
  1542. but will completely disappear in entries which do not contain a time.
  1543. If there is punctuation or whitespace character just before the
  1544. final format letter, this character will be appended to the field
  1545. value if the value is not empty. For example, the format
  1546. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1547. the category is empty, no additional colon is inserted.
  1548. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1549. which means:
  1550. - Indent the line with two space characters
  1551. - Give the category a 12 chars wide field, padded with whitespace on
  1552. the right (because of `-'). Append a colon if there is a category
  1553. (because of `:').
  1554. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1555. time, don't put in an empty field, just skip it (because of '?').
  1556. - Finally, put the scheduling information.
  1557. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1558. `org-agenda-remove-tags'.
  1559. Custom commands can set this variable in the options section."
  1560. :type '(choice
  1561. (string :tag "General format")
  1562. (list :greedy t :tag "View dependent"
  1563. (cons (const agenda) (string :tag "Format"))
  1564. (cons (const todo) (string :tag "Format"))
  1565. (cons (const tags) (string :tag "Format"))
  1566. (cons (const search) (string :tag "Format"))))
  1567. :group 'org-agenda-line-format
  1568. :version "26.1"
  1569. :package-version '(Org . "9.1"))
  1570. (defcustom org-agenda-breadcrumbs-separator "->"
  1571. "The separator of breadcrumbs in agenda lines."
  1572. :group 'org-agenda-line-format
  1573. :package-version '(Org . "9.3")
  1574. :type 'string
  1575. :safe #'stringp)
  1576. (defvar org-prefix-format-compiled nil
  1577. "The compiled prefix format and associated variables.
  1578. This is a list where first element is a list of variable bindings, and second
  1579. element is the compiled format expression. See the variable
  1580. `org-agenda-prefix-format'.")
  1581. (defcustom org-agenda-todo-keyword-format "%-1s"
  1582. "Format for the TODO keyword in agenda lines.
  1583. Set this to something like \"%-12s\" if you want all TODO keywords
  1584. to occupy a fixed space in the agenda display."
  1585. :group 'org-agenda-line-format
  1586. :type 'string)
  1587. (defcustom org-agenda-diary-sexp-prefix nil
  1588. "A regexp that matches part of a diary sexp entry
  1589. which should be treated as scheduling/deadline information in
  1590. `org-agenda'.
  1591. For example, you can use this to extract the `diary-remind-message' from
  1592. `diary-remind' entries."
  1593. :group 'org-agenda-line-format
  1594. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1595. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1596. "Text preceding timerange entries in the agenda view.
  1597. This is a list with two strings. The first applies when the range
  1598. is entirely on one day. The second applies if the range spans several days.
  1599. The strings may have two \"%d\" format specifiers which will be filled
  1600. with the sequence number of the days, and the total number of days in the
  1601. range, respectively."
  1602. :group 'org-agenda-line-format
  1603. :type '(list
  1604. (string :tag "Deadline today ")
  1605. (choice :tag "Deadline relative"
  1606. (string :tag "Format string")
  1607. (function))))
  1608. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1609. "Text preceding scheduled items in the agenda view.
  1610. This is a list with two strings. The first applies when the item is
  1611. scheduled on the current day. The second applies when it has been scheduled
  1612. previously, it may contain a %d indicating that this is the nth time that
  1613. this item is scheduled, due to automatic rescheduling of unfinished items
  1614. for the following day. So this number is one larger than the number of days
  1615. that passed since this item was scheduled first."
  1616. :group 'org-agenda-line-format
  1617. :version "24.4"
  1618. :package-version '(Org . "8.0")
  1619. :type '(list
  1620. (string :tag "Scheduled today ")
  1621. (string :tag "Scheduled previously")))
  1622. (defcustom org-agenda-inactive-leader "["
  1623. "Text preceding item pulled into the agenda by inactive time stamps.
  1624. These entries are added to the agenda when pressing \"[\"."
  1625. :group 'org-agenda-line-format
  1626. :version "24.1"
  1627. :type 'string)
  1628. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1629. "Text preceding deadline items in the agenda view.
  1630. This is a list with three strings. The first applies when the item has its
  1631. deadline on the current day. The second applies when the deadline is in the
  1632. future, the third one when it is in the past. The strings may contain %d
  1633. to capture the number of days."
  1634. :group 'org-agenda-line-format
  1635. :version "24.4"
  1636. :package-version '(Org . "8.0")
  1637. :type '(list
  1638. (string :tag "Deadline today ")
  1639. (string :tag "Deadline in the future ")
  1640. (string :tag "Deadline in the past ")))
  1641. (defcustom org-agenda-remove-times-when-in-prefix t
  1642. "Non-nil means remove duplicate time specifications in agenda items.
  1643. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1644. time-of-day specification in a headline or diary entry is extracted and
  1645. placed into the prefix. If this option is non-nil, the original specification
  1646. \(a timestamp or -range, or just a plain time(range) specification like
  1647. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1648. cluttered.
  1649. The option can be t or nil. It may also be the symbol `beg', indicating
  1650. that the time should only be removed when it is located at the beginning of
  1651. the headline/diary entry."
  1652. :group 'org-agenda-line-format
  1653. :type '(choice
  1654. (const :tag "Always" t)
  1655. (const :tag "Never" nil)
  1656. (const :tag "When at beginning of entry" beg)))
  1657. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1658. "Non-nil means remove time ranges specifications in agenda
  1659. items that span on several days."
  1660. :group 'org-agenda-line-format
  1661. :version "24.1"
  1662. :type 'boolean)
  1663. (defcustom org-agenda-default-appointment-duration nil
  1664. "Default duration for appointments that only have a starting time.
  1665. When nil, no duration is specified in such cases.
  1666. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1667. :group 'org-agenda-line-format
  1668. :type '(choice
  1669. (integer :tag "Minutes")
  1670. (const :tag "No default duration")))
  1671. (defcustom org-agenda-show-inherited-tags t
  1672. "Non-nil means show inherited tags in each agenda line.
  1673. When this option is set to `always', it takes precedence over
  1674. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1675. in every agenda.
  1676. When this option is set to t (the default), inherited tags are
  1677. shown when they are available, i.e. when the value of
  1678. `org-agenda-use-tag-inheritance' enables tag inheritance for the
  1679. given agenda type.
  1680. This can be set to a list of agenda types in which the agenda
  1681. must display the inherited tags. Available types are `todo',
  1682. `agenda' and `search'.
  1683. When set to nil, never show inherited tags in agenda lines."
  1684. :group 'org-agenda-line-format
  1685. :group 'org-agenda
  1686. :version "24.3"
  1687. :type '(choice
  1688. (const :tag "Show inherited tags when available" t)
  1689. (const :tag "Always show inherited tags" always)
  1690. (repeat :tag "Show inherited tags only in selected agenda types"
  1691. (symbol :tag "Agenda type"))))
  1692. (defcustom org-agenda-use-tag-inheritance '(todo search agenda)
  1693. "List of agenda view types where to use tag inheritance.
  1694. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1695. controlled by `org-use-tag-inheritance'. In other agenda types,
  1696. `org-use-tag-inheritance' is not used for the selection of the
  1697. agenda entries. Still, you may want the agenda to be aware of
  1698. the inherited tags anyway, e.g. for later tag filtering.
  1699. Allowed value are `todo', `search' and `agenda'.
  1700. This variable has no effect if `org-agenda-show-inherited-tags'
  1701. is set to `always'. In that case, the agenda is aware of those
  1702. tags.
  1703. The default value sets tags in every agenda type. Setting this
  1704. option to nil will speed up non-tags agenda view a lot."
  1705. :group 'org-agenda
  1706. :version "26.1"
  1707. :package-version '(Org . "9.1")
  1708. :type '(choice
  1709. (const :tag "Use tag inheritance in all agenda types" t)
  1710. (repeat :tag "Use tag inheritance in selected agenda types"
  1711. (symbol :tag "Agenda type"))))
  1712. (defcustom org-agenda-hide-tags-regexp nil
  1713. "Regular expression used to filter away specific tags in agenda views.
  1714. This means that these tags will be present, but not be shown in the agenda
  1715. line. Secondary filtering will still work on the hidden tags.
  1716. Nil means don't hide any tags."
  1717. :group 'org-agenda-line-format
  1718. :type '(choice
  1719. (const :tag "Hide none" nil)
  1720. (regexp :tag "Regexp ")))
  1721. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1722. 'org-agenda-remove-tags)
  1723. (defcustom org-agenda-remove-tags nil
  1724. "Non-nil means remove the tags from the headline copy in the agenda.
  1725. When this is the symbol `prefix', only remove tags when
  1726. `org-agenda-prefix-format' contains a `%T' specifier."
  1727. :group 'org-agenda-line-format
  1728. :type '(choice
  1729. (const :tag "Always" t)
  1730. (const :tag "Never" nil)
  1731. (const :tag "When prefix format contains %T" prefix)))
  1732. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1733. (defcustom org-agenda-tags-column 'auto
  1734. "Shift tags in agenda items to this column.
  1735. If set to `auto', tags will be automatically aligned to the right
  1736. edge of the window.
  1737. If set to a positive number, tags will be left-aligned to that
  1738. column. If set to a negative number, tags will be right-aligned
  1739. to that column. For example, -80 works well for a normal 80
  1740. character screen."
  1741. :group 'org-agenda-line-format
  1742. :type '(choice
  1743. (const :tag "Automatically align to right edge of window" auto)
  1744. (integer :tag "Specific column" -80))
  1745. :package-version '(Org . "9.1")
  1746. :version "26.1")
  1747. (defcustom org-agenda-fontify-priorities 'cookies
  1748. "Non-nil means highlight low and high priorities in agenda.
  1749. When t, the highest priority entries are bold, lowest priority italic.
  1750. However, settings in `org-priority-faces' will overrule these faces.
  1751. When this variable is the symbol `cookies', only fontify the
  1752. cookies, not the entire task.
  1753. This may also be an association list of priority faces, whose
  1754. keys are the character values of `org-priority-highest',
  1755. `org-priority-default', and `org-priority-lowest' (the default values
  1756. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1757. color as a string, or a list like `(:background \"Red\")'.
  1758. If it is a color, the variable `org-faces-easy-properties'
  1759. determines if it is a foreground or a background color."
  1760. :group 'org-agenda-line-format
  1761. :type '(choice
  1762. (const :tag "Never" nil)
  1763. (const :tag "Defaults" t)
  1764. (const :tag "Cookies only" cookies)
  1765. (repeat :tag "Specify"
  1766. (list (character :tag "Priority" :value ?A)
  1767. (choice :tag "Face "
  1768. (string :tag "Color")
  1769. (sexp :tag "Face"))))))
  1770. (defcustom org-agenda-day-face-function nil
  1771. "Function called to determine what face should be used to display a day.
  1772. The only argument passed to that function is the day. It should
  1773. returns a face, or nil if does not want to specify a face and let
  1774. the normal rules apply."
  1775. :group 'org-agenda-line-format
  1776. :version "24.1"
  1777. :type '(choice (const nil) (function)))
  1778. (defcustom org-agenda-category-icon-alist nil
  1779. "Alist of category icon to be displayed in agenda views.
  1780. Each entry should have the following format:
  1781. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1782. Where CATEGORY-REGEXP is a regexp matching the categories where
  1783. the icon should be displayed.
  1784. FILE-OR-DATA either a file path or a string containing image data.
  1785. The other fields can be omitted safely if not needed:
  1786. TYPE indicates the image type.
  1787. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1788. image data.
  1789. PROPS are additional image attributes to assign to the image,
  1790. like, e.g. `:ascent center'.
  1791. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1792. If you want to set the display properties yourself, just put a
  1793. list as second element:
  1794. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1795. For example, to display a 16px horizontal space for Emacs
  1796. category, you can use:
  1797. (\"Emacs\" \\='(space . (:width (16))))"
  1798. :group 'org-agenda-line-format
  1799. :version "24.1"
  1800. :type '(alist :key-type (regexp :tag "Regexp matching category")
  1801. :value-type (choice (list :tag "Icon"
  1802. (string :tag "File or data")
  1803. (symbol :tag "Type")
  1804. (boolean :tag "Data?")
  1805. (repeat :tag "Extra image properties" :inline t sexp))
  1806. (list :tag "Display properties" sexp))))
  1807. (defgroup org-agenda-column-view nil
  1808. "Options concerning column view in the agenda."
  1809. :tag "Org Agenda Column View"
  1810. :group 'org-agenda)
  1811. (defcustom org-agenda-view-columns-initially nil
  1812. "When non-nil, switch to columns view right after creating the agenda."
  1813. :group 'org-agenda-column-view
  1814. :type 'boolean
  1815. :version "26.1"
  1816. :package-version '(Org . "9.0")
  1817. :safe #'booleanp)
  1818. (defcustom org-agenda-columns-show-summaries t
  1819. "Non-nil means show summaries for columns displayed in the agenda view."
  1820. :group 'org-agenda-column-view
  1821. :type 'boolean)
  1822. (defcustom org-agenda-columns-compute-summary-properties t
  1823. "Non-nil means recompute all summary properties before column view.
  1824. When column view in the agenda is listing properties that have a summary
  1825. operator, it can go to all relevant buffers and recompute the summaries
  1826. there. This can mean overhead for the agenda column view, but is necessary
  1827. to have thing up to date.
  1828. As a special case, a CLOCKSUM property also makes sure that the clock
  1829. computations are current."
  1830. :group 'org-agenda-column-view
  1831. :type 'boolean)
  1832. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1833. "Non-nil means the duration of an appointment will add to day effort.
  1834. The property to which appointment durations will be added is the one given
  1835. in the option `org-effort-property'. If an appointment does not have
  1836. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1837. is not set, an appointment without end time will not contribute to the time
  1838. estimate."
  1839. :group 'org-agenda-column-view
  1840. :type 'boolean)
  1841. (defcustom org-agenda-auto-exclude-function nil
  1842. "A function called with a tag to decide if it is filtered on \
  1843. \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
  1844. The sole argument to the function, which is called once for each
  1845. possible tag, is a string giving the name of the tag. The
  1846. function should return either nil if the tag should be included
  1847. as normal, \"-<TAG>\" to exclude the tag, or \"+<TAG>\" to exclude
  1848. lines not carrying this tag.
  1849. Note that for the purpose of tag filtering, only the lower-case version of
  1850. all tags will be considered, so that this function will only ever see
  1851. the lower-case version of all tags."
  1852. :group 'org-agenda
  1853. :type '(choice (const nil) (function)))
  1854. (defcustom org-agenda-bulk-custom-functions nil
  1855. "Alist of characters and custom functions for bulk actions.
  1856. For example, this makes those two functions available:
  1857. (setq org-agenda-bulk-custom-functions
  1858. \\='((?R set-category)
  1859. (?C bulk-cut)))
  1860. With selected entries in an agenda buffer, `B R' will call
  1861. the custom function `set-category' on the selected entries.
  1862. Note that functions in this alist don't need to be quoted.
  1863. You can also specify a function which collects arguments to be
  1864. used for each call to your bulk custom function. The argument
  1865. collecting function will be run once and should return a list of
  1866. arguments to pass to the bulk function. For example:
  1867. (setq org-agenda-bulk-custom-functions
  1868. \\='((?R set-category get-category)))
  1869. Now, `B R' will call the custom `get-category' which would prompt
  1870. the user once for a category. That category is then passed as an
  1871. argument to `set-category' for each entry it's called against."
  1872. :type
  1873. '(alist :key-type character
  1874. :value-type
  1875. (group (function :tag "Bulk Custom Function")
  1876. (choice (function :tag "Bulk Custom Argument Function")
  1877. (const :tag "No Bulk Custom Argument Function" nil))))
  1878. :package-version '(Org . "9.5")
  1879. :group 'org-agenda)
  1880. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1881. "Execute BODY with point at location given by `org-hd-marker' property.
  1882. If STRING is non-nil, the text property will be fetched from position 0
  1883. in that string. If STRING is nil, it will be fetched from the beginning
  1884. of the current line."
  1885. (declare (debug t) (indent 1))
  1886. (org-with-gensyms (marker)
  1887. `(let ((,marker (get-text-property (if ,string 0 (line-beginning-position))
  1888. 'org-hd-marker ,string)))
  1889. (with-current-buffer (marker-buffer ,marker)
  1890. (save-excursion
  1891. (goto-char ,marker)
  1892. ,@body)))))
  1893. (defun org-add-agenda-custom-command (entry)
  1894. "Replace or add a command in `org-agenda-custom-commands'.
  1895. This is mostly for hacking and trying a new command - once the command
  1896. works you probably want to add it to `org-agenda-custom-commands' for good."
  1897. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1898. (if ass
  1899. (setcdr ass (cdr entry))
  1900. (push entry org-agenda-custom-commands))))
  1901. (defmacro org-agenda--insert-overriding-header (default)
  1902. "Insert header into agenda view.
  1903. The inserted header depends on `org-agenda-overriding-header'.
  1904. If the empty string, don't insert a header. If any other string,
  1905. insert it as a header. If nil, insert DEFAULT, which should
  1906. evaluate to a string. If a function, call it and insert the
  1907. string that it returns."
  1908. (declare (debug (form)) (indent defun))
  1909. `(cond
  1910. ((not org-agenda-overriding-header) (insert ,default))
  1911. ((equal org-agenda-overriding-header "") nil)
  1912. ((stringp org-agenda-overriding-header)
  1913. (insert (propertize org-agenda-overriding-header
  1914. 'face 'org-agenda-structure)
  1915. "\n"))
  1916. ((functionp org-agenda-overriding-header)
  1917. (insert (funcall org-agenda-overriding-header)))
  1918. (t (user-error "Invalid value for `org-agenda-overriding-header': %S"
  1919. org-agenda-overriding-header))))
  1920. ;;; Define the org-agenda-mode
  1921. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1922. (defvar org-agenda-mode-map (make-sparse-keymap)
  1923. "Keymap for `org-agenda-mode'.")
  1924. (org-remap org-agenda-mode-map 'move-end-of-line 'org-agenda-end-of-line)
  1925. (defvar org-agenda-menu) ; defined later in this file.
  1926. (defvar org-agenda-restrict nil)
  1927. (defvar org-agenda-follow-mode nil)
  1928. (defvar org-agenda-entry-text-mode nil)
  1929. (defvar org-agenda-clockreport-mode nil)
  1930. (defvar org-agenda-show-log nil
  1931. "When non-nil, show the log in the agenda.
  1932. Do not set this directly; instead use
  1933. `org-agenda-start-with-log-mode', which see.")
  1934. (defvar org-agenda-redo-command nil)
  1935. (defvar org-agenda-query-string nil)
  1936. (defvar org-agenda-mode-hook nil
  1937. "Hook run after `org-agenda-mode' is turned on.
  1938. The buffer is still writable when this hook is called.")
  1939. (defvar org-agenda-type nil)
  1940. (defvar org-agenda-force-single-file nil)
  1941. (defvar org-agenda-bulk-marked-entries nil
  1942. "List of markers that refer to marked entries in the agenda.")
  1943. (defvar org-agenda-current-date nil
  1944. "Active date when building the agenda.")
  1945. ;;; Multiple agenda buffers support
  1946. (defcustom org-agenda-sticky nil
  1947. "Non-nil means agenda q key will bury agenda buffers.
  1948. Agenda commands will then show existing buffer instead of generating new ones.
  1949. When nil, `q' will kill the single agenda buffer."
  1950. :group 'org-agenda
  1951. :version "24.3"
  1952. :type 'boolean)
  1953. ;;;###autoload
  1954. (defun org-toggle-sticky-agenda (&optional arg)
  1955. "Toggle `org-agenda-sticky'."
  1956. (interactive "P")
  1957. (let ((new-value (if arg
  1958. (> (prefix-numeric-value arg) 0)
  1959. (not org-agenda-sticky))))
  1960. (if (equal new-value org-agenda-sticky)
  1961. (and (called-interactively-p 'interactive)
  1962. (message "Sticky agenda was already %s"
  1963. (if org-agenda-sticky "enabled" "disabled")))
  1964. (setq org-agenda-sticky new-value)
  1965. (org-agenda-kill-all-agenda-buffers)
  1966. (and (called-interactively-p 'interactive)
  1967. (message "Sticky agenda %s"
  1968. (if org-agenda-sticky "enabled" "disabled"))))))
  1969. (defvar org-agenda-buffer nil
  1970. "Agenda buffer currently being generated.")
  1971. (defvar org-agenda-last-prefix-arg nil)
  1972. (defvar org-agenda-this-buffer-name nil)
  1973. (defvar org-agenda-doing-sticky-redo nil)
  1974. (defvar org-agenda-this-buffer-is-sticky nil)
  1975. (defvar org-agenda-last-indirect-buffer nil
  1976. "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
  1977. (defconst org-agenda-local-vars
  1978. '(org-agenda-this-buffer-name
  1979. org-agenda-undo-list
  1980. org-agenda-pending-undo-list
  1981. org-agenda-follow-mode
  1982. org-agenda-entry-text-mode
  1983. org-agenda-clockreport-mode
  1984. org-agenda-show-log
  1985. org-agenda-redo-command
  1986. org-agenda-query-string
  1987. org-agenda-type
  1988. org-agenda-bulk-marked-entries
  1989. org-agenda-undo-has-started-in
  1990. org-agenda-info
  1991. org-agenda-pre-window-conf
  1992. org-agenda-columns-active
  1993. org-agenda-tag-filter
  1994. org-agenda-category-filter
  1995. org-agenda-top-headline-filter
  1996. org-agenda-regexp-filter
  1997. org-agenda-effort-filter
  1998. org-agenda-markers
  1999. org-agenda-last-search-view-search-was-boolean
  2000. org-agenda-last-indirect-buffer
  2001. org-agenda-filtered-by-category
  2002. org-agenda-filter-form
  2003. org-agenda-cycle-counter
  2004. org-agenda-last-prefix-arg)
  2005. "Variables that must be local in agenda buffers to allow multiple buffers.")
  2006. (defun org-agenda-mode ()
  2007. "Mode for time-sorted view on action items in Org files.
  2008. The following commands are available:
  2009. \\{org-agenda-mode-map}"
  2010. (interactive)
  2011. (ignore-errors (require 'face-remap))
  2012. (let ((agenda-local-vars-to-keep
  2013. '(text-scale-mode-amount
  2014. text-scale-mode
  2015. text-scale-mode-lighter
  2016. face-remapping-alist))
  2017. (save (buffer-local-variables)))
  2018. (kill-all-local-variables)
  2019. (cl-flet ((reset-saved (var-set)
  2020. "Reset variables in VAR-SET to possibly stored value in SAVE."
  2021. (dolist (elem save)
  2022. (pcase elem
  2023. (`(,var . ,val) ;ignore unbound variables
  2024. (when (and val (memq var var-set))
  2025. (set var val)))))))
  2026. (cond (org-agenda-doing-sticky-redo
  2027. ;; Refreshing sticky agenda-buffer
  2028. ;;
  2029. ;; Preserve the value of `org-agenda-local-vars' variables.
  2030. (mapc #'make-local-variable org-agenda-local-vars)
  2031. (reset-saved org-agenda-local-vars)
  2032. (setq-local org-agenda-this-buffer-is-sticky t))
  2033. (org-agenda-sticky
  2034. ;; Creating a sticky Agenda buffer for the first time
  2035. (mapc #'make-local-variable org-agenda-local-vars)
  2036. (setq-local org-agenda-this-buffer-is-sticky t))
  2037. (t
  2038. ;; Creating a non-sticky agenda buffer
  2039. (setq-local org-agenda-this-buffer-is-sticky nil)))
  2040. (mapc #'make-local-variable agenda-local-vars-to-keep)
  2041. (reset-saved agenda-local-vars-to-keep)))
  2042. (setq org-agenda-undo-list nil
  2043. org-agenda-pending-undo-list nil
  2044. org-agenda-bulk-marked-entries nil)
  2045. (setq major-mode 'org-agenda-mode)
  2046. ;; Keep global-font-lock-mode from turning on font-lock-mode
  2047. (setq-local font-lock-global-modes (list 'not major-mode))
  2048. (setq mode-name "Org-Agenda")
  2049. (setq indent-tabs-mode nil)
  2050. (use-local-map org-agenda-mode-map)
  2051. (when org-startup-truncated (setq truncate-lines t))
  2052. (setq-local line-move-visual nil)
  2053. (add-hook 'post-command-hook #'org-agenda-update-agenda-type nil 'local)
  2054. (add-hook 'pre-command-hook #'org-unhighlight nil 'local)
  2055. ;; Make sure properties are removed when copying text
  2056. (if (boundp 'filter-buffer-substring-functions)
  2057. (add-hook 'filter-buffer-substring-functions
  2058. (lambda (fun start end delete)
  2059. (substring-no-properties (funcall fun start end delete)))
  2060. nil t)
  2061. ;; Emacs >= 24.4.
  2062. (add-function :filter-return (local 'filter-buffer-substring-function)
  2063. #'substring-no-properties))
  2064. (unless org-agenda-keep-modes
  2065. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  2066. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  2067. org-agenda-show-log org-agenda-start-with-log-mode
  2068. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode))
  2069. (add-to-invisibility-spec '(org-filtered))
  2070. (org-fold-core-initialize `(,org-link--description-folding-spec
  2071. ,org-link--link-folding-spec))
  2072. (easy-menu-change
  2073. '("Agenda") "Agenda Files"
  2074. (append
  2075. (list
  2076. (vector
  2077. (if (get 'org-agenda-files 'org-restrict)
  2078. "Restricted to single file"
  2079. "Edit File List")
  2080. '(org-edit-agenda-file-list)
  2081. (not (get 'org-agenda-files 'org-restrict)))
  2082. "--")
  2083. (mapcar #'org-file-menu-entry (org-agenda-files))))
  2084. (org-agenda-set-mode-name)
  2085. (run-mode-hooks 'org-agenda-mode-hook))
  2086. (substitute-key-definition #'undo #'org-agenda-undo
  2087. org-agenda-mode-map global-map)
  2088. (org-defkey org-agenda-mode-map "\C-i" #'org-agenda-goto)
  2089. (org-defkey org-agenda-mode-map [(tab)] #'org-agenda-goto)
  2090. (org-defkey org-agenda-mode-map "\C-m" #'org-agenda-switch-to)
  2091. (org-defkey org-agenda-mode-map "\C-k" #'org-agenda-kill)
  2092. (org-defkey org-agenda-mode-map "\C-c\C-w" #'org-agenda-refile)
  2093. (org-defkey org-agenda-mode-map [(meta down)] #'org-agenda-drag-line-forward)
  2094. (org-defkey org-agenda-mode-map [(meta up)] #'org-agenda-drag-line-backward)
  2095. (org-defkey org-agenda-mode-map "m" #'org-agenda-bulk-mark)
  2096. (org-defkey org-agenda-mode-map "\M-m" #'org-agenda-bulk-toggle)
  2097. (org-defkey org-agenda-mode-map "*" #'org-agenda-bulk-mark-all)
  2098. (org-defkey org-agenda-mode-map "\M-*" #'org-agenda-bulk-toggle-all)
  2099. (org-defkey org-agenda-mode-map "#" #'org-agenda-dim-blocked-tasks)
  2100. (org-defkey org-agenda-mode-map "%" #'org-agenda-bulk-mark-regexp)
  2101. (org-defkey org-agenda-mode-map "u" #'org-agenda-bulk-unmark)
  2102. (org-defkey org-agenda-mode-map "U" #'org-agenda-bulk-unmark-all)
  2103. (org-defkey org-agenda-mode-map "B" #'org-agenda-bulk-action)
  2104. (org-defkey org-agenda-mode-map "k" #'org-agenda-capture)
  2105. (org-defkey org-agenda-mode-map "A" #'org-agenda-append-agenda)
  2106. (org-defkey org-agenda-mode-map "\C-c\C-x!" #'org-reload)
  2107. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" #'org-agenda-archive-default)
  2108. (org-defkey org-agenda-mode-map "\C-c\C-xa" #'org-agenda-toggle-archive-tag)
  2109. (org-defkey org-agenda-mode-map "\C-c\C-xA" #'org-agenda-archive-to-archive-sibling)
  2110. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" #'org-agenda-archive)
  2111. (org-defkey org-agenda-mode-map "\C-c$" #'org-agenda-archive)
  2112. (org-defkey org-agenda-mode-map "$" #'org-agenda-archive)
  2113. (org-defkey org-agenda-mode-map "\C-c\C-o" #'org-agenda-open-link)
  2114. (org-defkey org-agenda-mode-map " " #'org-agenda-show-and-scroll-up)
  2115. (org-defkey org-agenda-mode-map [backspace] #'org-agenda-show-scroll-down)
  2116. (org-defkey org-agenda-mode-map "\d" #'org-agenda-show-scroll-down)
  2117. (org-defkey org-agenda-mode-map [(control shift right)] #'org-agenda-todo-nextset)
  2118. (org-defkey org-agenda-mode-map [(control shift left)] #'org-agenda-todo-previousset)
  2119. (org-defkey org-agenda-mode-map "\C-c\C-xb" #'org-agenda-tree-to-indirect-buffer)
  2120. (org-defkey org-agenda-mode-map "o" #'delete-other-windows)
  2121. (org-defkey org-agenda-mode-map "L" #'org-agenda-recenter)
  2122. (org-defkey org-agenda-mode-map "\C-c\C-t" #'org-agenda-todo)
  2123. (org-defkey org-agenda-mode-map "t" #'org-agenda-todo)
  2124. (org-defkey org-agenda-mode-map "a" #'org-agenda-archive-default-with-confirmation)
  2125. (org-defkey org-agenda-mode-map ":" #'org-agenda-set-tags)
  2126. (org-defkey org-agenda-mode-map "\C-c\C-q" #'org-agenda-set-tags)
  2127. (org-defkey org-agenda-mode-map "." #'org-agenda-goto-today)
  2128. (org-defkey org-agenda-mode-map "j" #'org-agenda-goto-date)
  2129. (org-defkey org-agenda-mode-map "d" #'org-agenda-day-view)
  2130. (org-defkey org-agenda-mode-map "w" #'org-agenda-week-view)
  2131. (org-defkey org-agenda-mode-map "y" #'org-agenda-year-view)
  2132. (org-defkey org-agenda-mode-map "\C-c\C-z" #'org-agenda-add-note)
  2133. (org-defkey org-agenda-mode-map "z" #'org-agenda-add-note)
  2134. (org-defkey org-agenda-mode-map [(shift right)] #'org-agenda-do-date-later)
  2135. (org-defkey org-agenda-mode-map [(shift left)] #'org-agenda-do-date-earlier)
  2136. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] #'org-agenda-do-date-later)
  2137. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] #'org-agenda-do-date-earlier)
  2138. (org-defkey org-agenda-mode-map ">" #'org-agenda-date-prompt)
  2139. (org-defkey org-agenda-mode-map "\C-c\C-s" #'org-agenda-schedule)
  2140. (org-defkey org-agenda-mode-map "\C-c\C-d" #'org-agenda-deadline)
  2141. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  2142. (while l (org-defkey org-agenda-mode-map
  2143. (number-to-string (pop l)) #'digit-argument)))
  2144. (org-defkey org-agenda-mode-map "F" #'org-agenda-follow-mode)
  2145. (org-defkey org-agenda-mode-map "R" #'org-agenda-clockreport-mode)
  2146. (org-defkey org-agenda-mode-map "E" #'org-agenda-entry-text-mode)
  2147. (org-defkey org-agenda-mode-map "l" #'org-agenda-log-mode)
  2148. (org-defkey org-agenda-mode-map "v" #'org-agenda-view-mode-dispatch)
  2149. (org-defkey org-agenda-mode-map "D" #'org-agenda-toggle-diary)
  2150. (org-defkey org-agenda-mode-map "!" #'org-agenda-toggle-deadlines)
  2151. (org-defkey org-agenda-mode-map "G" #'org-agenda-toggle-time-grid)
  2152. (org-defkey org-agenda-mode-map "r" #'org-agenda-redo)
  2153. (org-defkey org-agenda-mode-map "g" #'org-agenda-redo-all)
  2154. (org-defkey org-agenda-mode-map "e" #'org-agenda-set-effort)
  2155. (org-defkey org-agenda-mode-map "\C-c\C-xe" #'org-agenda-set-effort)
  2156. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  2157. #'org-clock-modify-effort-estimate)
  2158. (org-defkey org-agenda-mode-map "\C-c\C-xp" #'org-agenda-set-property)
  2159. (org-defkey org-agenda-mode-map "q" #'org-agenda-quit)
  2160. (org-defkey org-agenda-mode-map "Q" #'org-agenda-Quit)
  2161. (org-defkey org-agenda-mode-map "x" #'org-agenda-exit)
  2162. (org-defkey org-agenda-mode-map "\C-x\C-w" #'org-agenda-write)
  2163. (org-defkey org-agenda-mode-map "\C-x\C-s" #'org-save-all-org-buffers)
  2164. (org-defkey org-agenda-mode-map "s" #'org-save-all-org-buffers)
  2165. (org-defkey org-agenda-mode-map "T" #'org-agenda-show-tags)
  2166. (org-defkey org-agenda-mode-map "n" #'org-agenda-next-line)
  2167. (org-defkey org-agenda-mode-map "p" #'org-agenda-previous-line)
  2168. (org-defkey org-agenda-mode-map "N" #'org-agenda-next-item)
  2169. (org-defkey org-agenda-mode-map "P" #'org-agenda-previous-item)
  2170. (substitute-key-definition #'next-line #'org-agenda-next-line
  2171. org-agenda-mode-map global-map)
  2172. (substitute-key-definition #'previous-line #'org-agenda-previous-line
  2173. org-agenda-mode-map global-map)
  2174. (org-defkey org-agenda-mode-map "\C-c\C-a" #'org-attach)
  2175. (org-defkey org-agenda-mode-map "\C-c\C-n" #'org-agenda-next-date-line)
  2176. (org-defkey org-agenda-mode-map "\C-c\C-p" #'org-agenda-previous-date-line)
  2177. (org-defkey org-agenda-mode-map "\C-c," #'org-agenda-priority)
  2178. (org-defkey org-agenda-mode-map "," #'org-agenda-priority)
  2179. (org-defkey org-agenda-mode-map "i" #'org-agenda-diary-entry)
  2180. (org-defkey org-agenda-mode-map "c" #'org-agenda-goto-calendar)
  2181. (org-defkey org-agenda-mode-map "C" #'org-agenda-convert-date)
  2182. (org-defkey org-agenda-mode-map "M" #'org-agenda-phases-of-moon)
  2183. (org-defkey org-agenda-mode-map "S" #'org-agenda-sunrise-sunset)
  2184. (org-defkey org-agenda-mode-map "h" #'org-agenda-holidays)
  2185. (org-defkey org-agenda-mode-map "H" #'org-agenda-holidays)
  2186. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" #'org-agenda-clock-in)
  2187. (org-defkey org-agenda-mode-map "I" #'org-agenda-clock-in)
  2188. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" #'org-agenda-clock-out)
  2189. (org-defkey org-agenda-mode-map "O" #'org-agenda-clock-out)
  2190. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" #'org-agenda-clock-cancel)
  2191. (org-defkey org-agenda-mode-map "X" #'org-agenda-clock-cancel)
  2192. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" #'org-clock-goto)
  2193. (org-defkey org-agenda-mode-map "J" #'org-agenda-clock-goto)
  2194. (org-defkey org-agenda-mode-map "+" #'org-agenda-priority-up)
  2195. (org-defkey org-agenda-mode-map "-" #'org-agenda-priority-down)
  2196. (org-defkey org-agenda-mode-map [(shift up)] #'org-agenda-priority-up)
  2197. (org-defkey org-agenda-mode-map [(shift down)] #'org-agenda-priority-down)
  2198. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] #'org-agenda-priority-up)
  2199. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] #'org-agenda-priority-down)
  2200. (org-defkey org-agenda-mode-map "f" #'org-agenda-later)
  2201. (org-defkey org-agenda-mode-map "b" #'org-agenda-earlier)
  2202. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" #'org-agenda-columns)
  2203. (org-defkey org-agenda-mode-map "\C-c\C-x>" #'org-agenda-remove-restriction-lock)
  2204. (org-defkey org-agenda-mode-map "\C-c\C-x<" #'org-agenda-set-restriction-lock-from-agenda)
  2205. (org-defkey org-agenda-mode-map "[" #'org-agenda-manipulate-query-add)
  2206. (org-defkey org-agenda-mode-map "]" #'org-agenda-manipulate-query-subtract)
  2207. (org-defkey org-agenda-mode-map "{" #'org-agenda-manipulate-query-add-re)
  2208. (org-defkey org-agenda-mode-map "}" #'org-agenda-manipulate-query-subtract-re)
  2209. (org-defkey org-agenda-mode-map "\\" #'org-agenda-filter-by-tag)
  2210. (org-defkey org-agenda-mode-map "_" #'org-agenda-filter-by-effort)
  2211. (org-defkey org-agenda-mode-map "=" #'org-agenda-filter-by-regexp)
  2212. (org-defkey org-agenda-mode-map "/" #'org-agenda-filter)
  2213. (org-defkey org-agenda-mode-map "|" #'org-agenda-filter-remove-all)
  2214. (org-defkey org-agenda-mode-map "~" #'org-agenda-limit-interactively)
  2215. (org-defkey org-agenda-mode-map "<" #'org-agenda-filter-by-category)
  2216. (org-defkey org-agenda-mode-map "^" #'org-agenda-filter-by-top-headline)
  2217. (org-defkey org-agenda-mode-map ";" #'org-timer-set-timer)
  2218. (org-defkey org-agenda-mode-map "\C-c\C-x_" #'org-timer-stop)
  2219. (org-defkey org-agenda-mode-map "?" #'org-agenda-show-the-flagging-note)
  2220. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" #'org-mobile-pull)
  2221. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" #'org-mobile-push)
  2222. (org-defkey org-agenda-mode-map "\C-c\C-xI" #'org-info-find-node)
  2223. (org-defkey org-agenda-mode-map [mouse-2] #'org-agenda-goto-mouse)
  2224. (org-defkey org-agenda-mode-map [mouse-3] #'org-agenda-show-mouse)
  2225. (org-defkey org-agenda-mode-map [remap forward-paragraph] #'org-agenda-forward-block)
  2226. (org-defkey org-agenda-mode-map [remap backward-paragraph] #'org-agenda-backward-block)
  2227. (org-defkey org-agenda-mode-map "\C-c\C-c" #'org-agenda-ctrl-c-ctrl-c)
  2228. (when org-agenda-mouse-1-follows-link
  2229. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2230. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu."
  2231. '("Agenda"
  2232. ("Agenda Files")
  2233. "--"
  2234. ("Agenda Dates"
  2235. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda)]
  2236. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2237. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2238. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2239. "--"
  2240. ("View"
  2241. ["Day View" org-agenda-day-view
  2242. :active (org-agenda-check-type nil 'agenda)
  2243. :style radio :selected (eq org-agenda-current-span 'day)
  2244. :keys "v d (or just d)"]
  2245. ["Week View" org-agenda-week-view
  2246. :active (org-agenda-check-type nil 'agenda)
  2247. :style radio :selected (eq org-agenda-current-span 'week)
  2248. :keys "v w"]
  2249. ["Fortnight View" org-agenda-fortnight-view
  2250. :active (org-agenda-check-type nil 'agenda)
  2251. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2252. :keys "v t"]
  2253. ["Month View" org-agenda-month-view
  2254. :active (org-agenda-check-type nil 'agenda)
  2255. :style radio :selected (eq org-agenda-current-span 'month)
  2256. :keys "v m"]
  2257. ["Year View" org-agenda-year-view
  2258. :active (org-agenda-check-type nil 'agenda)
  2259. :style radio :selected (eq org-agenda-current-span 'year)
  2260. :keys "v y"]
  2261. "--"
  2262. ["Include Diary" org-agenda-toggle-diary
  2263. :style toggle :selected org-agenda-include-diary
  2264. :active (org-agenda-check-type nil 'agenda)]
  2265. ["Include Deadlines" org-agenda-toggle-deadlines
  2266. :style toggle :selected org-agenda-include-deadlines
  2267. :active (org-agenda-check-type nil 'agenda)]
  2268. ["Use Time Grid" org-agenda-toggle-time-grid
  2269. :style toggle :selected org-agenda-use-time-grid
  2270. :active (org-agenda-check-type nil 'agenda)]
  2271. "--"
  2272. ["Show clock report" org-agenda-clockreport-mode
  2273. :style toggle :selected org-agenda-clockreport-mode
  2274. :active (org-agenda-check-type nil 'agenda)]
  2275. ["Show some entry text" org-agenda-entry-text-mode
  2276. :style toggle :selected org-agenda-entry-text-mode
  2277. :active t]
  2278. "--"
  2279. ["Show Logbook entries" org-agenda-log-mode
  2280. :style toggle :selected org-agenda-show-log
  2281. :active (org-agenda-check-type nil 'agenda)
  2282. :keys "v l (or just l)"]
  2283. ["Include archived trees" org-agenda-archives-mode
  2284. :style toggle :selected org-agenda-archives-mode :active t
  2285. :keys "v a"]
  2286. ["Include archive files" (org-agenda-archives-mode t)
  2287. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2288. :keys "v A"]
  2289. "--"
  2290. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2291. ("Filter current view"
  2292. ["with generic interface" org-agenda-filter t]
  2293. "--"
  2294. ["by category at cursor" org-agenda-filter-by-category t]
  2295. ["by tag" org-agenda-filter-by-tag t]
  2296. ["by effort" org-agenda-filter-by-effort t]
  2297. ["by regexp" org-agenda-filter-by-regexp t]
  2298. ["by top-level headline" org-agenda-filter-by-top-headline t]
  2299. "--"
  2300. ["Remove all filtering" org-agenda-filter-remove-all t]
  2301. "--"
  2302. ["limit" org-agenda-limit-interactively t])
  2303. ["Rebuild buffer" org-agenda-redo t]
  2304. ["Write view to file" org-agenda-write t]
  2305. ["Save all Org buffers" org-save-all-org-buffers t]
  2306. "--"
  2307. ["Show original entry" org-agenda-show t]
  2308. ["Go To (other window)" org-agenda-goto t]
  2309. ["Go To (this window)" org-agenda-switch-to t]
  2310. ["Capture with cursor date" org-agenda-capture t]
  2311. ["Follow Mode" org-agenda-follow-mode
  2312. :style toggle :selected org-agenda-follow-mode :active t]
  2313. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2314. "--"
  2315. ("TODO"
  2316. ["Cycle TODO" org-agenda-todo t]
  2317. ["Next TODO set" org-agenda-todo-nextset t]
  2318. ["Previous TODO set" org-agenda-todo-previousset t]
  2319. ["Add note" org-agenda-add-note t])
  2320. ("Archive/Refile/Delete"
  2321. ["Archive default" org-agenda-archive-default t]
  2322. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2323. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2324. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2325. ["Archive subtree" org-agenda-archive t]
  2326. "--"
  2327. ["Refile" org-agenda-refile t]
  2328. "--"
  2329. ["Delete subtree" org-agenda-kill t])
  2330. ("Bulk action"
  2331. ["Mark entry" org-agenda-bulk-mark t]
  2332. ["Mark all" org-agenda-bulk-mark-all t]
  2333. ["Unmark entry" org-agenda-bulk-unmark t]
  2334. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2335. ["Toggle mark" org-agenda-bulk-toggle t]
  2336. ["Toggle all" org-agenda-bulk-toggle-all t]
  2337. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2338. ["Act on all marked" org-agenda-bulk-action t]
  2339. "--"
  2340. ("Tags and Properties"
  2341. ["Show all Tags" org-agenda-show-tags t]
  2342. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2343. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2344. "--"
  2345. ["Column View" org-columns t])
  2346. ("Deadline/Schedule"
  2347. ["Schedule" org-agenda-schedule t]
  2348. ["Set Deadline" org-agenda-deadline t]
  2349. "--"
  2350. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda)]
  2351. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda)]
  2352. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u S-right"]
  2353. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u S-left"]
  2354. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-right"]
  2355. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-left"]
  2356. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda)])
  2357. ("Clock and Effort"
  2358. ["Clock in" org-agenda-clock-in t]
  2359. ["Clock out" org-agenda-clock-out t]
  2360. ["Clock cancel" org-agenda-clock-cancel t]
  2361. ["Goto running clock" org-clock-goto t]
  2362. "--"
  2363. ["Set Effort" org-agenda-set-effort t]
  2364. ["Change clocked effort" org-clock-modify-effort-estimate
  2365. (org-clock-is-active)])
  2366. ("Priority"
  2367. ["Set Priority" org-agenda-priority t]
  2368. ["Increase Priority" org-agenda-priority-up t]
  2369. ["Decrease Priority" org-agenda-priority-down t]
  2370. ["Show Priority" org-priority-show t])
  2371. ("Calendar/Diary"
  2372. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda)]
  2373. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda)]
  2374. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda)]
  2375. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda)]
  2376. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda)]
  2377. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda)]
  2378. "--"
  2379. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2380. "--"
  2381. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2382. "--"
  2383. ("MobileOrg"
  2384. ["Push Files and Views" org-mobile-push t]
  2385. ["Get Captured and Flagged" org-mobile-pull t]
  2386. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "\\[org-agenda] ?"]
  2387. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2388. "--"
  2389. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2390. "--"
  2391. ["Quit" org-agenda-quit t]
  2392. ["Exit and Release Buffers" org-agenda-exit t]
  2393. ))
  2394. ;;; Agenda undo
  2395. (defvar org-agenda-allow-remote-undo t
  2396. "Non-nil means allow remote undo from the agenda buffer.")
  2397. (defvar org-agenda-undo-has-started-in nil
  2398. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2399. (defun org-agenda-undo ()
  2400. "Undo a remote editing step in the agenda.
  2401. This undoes changes both in the agenda buffer and in the remote buffer
  2402. that have been changed along."
  2403. (interactive)
  2404. (or org-agenda-allow-remote-undo
  2405. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2406. (when (not (eq this-command last-command))
  2407. (setq org-agenda-undo-has-started-in nil
  2408. org-agenda-pending-undo-list org-agenda-undo-list))
  2409. (when (not org-agenda-pending-undo-list)
  2410. (user-error "No further undo information"))
  2411. (let* ((entry (pop org-agenda-pending-undo-list))
  2412. buf line cmd rembuf)
  2413. (setq cmd (pop entry) line (pop entry))
  2414. (setq rembuf (nth 2 entry))
  2415. (org-with-remote-undo rembuf
  2416. (while (bufferp (setq buf (pop entry)))
  2417. (when (pop entry)
  2418. (with-current-buffer buf
  2419. (let (;; (last-undo-buffer buf)
  2420. (inhibit-read-only t))
  2421. (unless (memq buf org-agenda-undo-has-started-in)
  2422. (push buf org-agenda-undo-has-started-in)
  2423. (make-local-variable 'pending-undo-list)
  2424. (undo-start))
  2425. (while (and pending-undo-list
  2426. (listp pending-undo-list)
  2427. (not (car pending-undo-list)))
  2428. (pop pending-undo-list))
  2429. (undo-more 1))))))
  2430. (org-goto-line line)
  2431. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2432. (defun org-verify-change-for-undo (l1 l2)
  2433. "Verify that a real change occurred between the undo lists L1 and L2."
  2434. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2435. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2436. (not (eq l1 l2)))
  2437. ;;; Agenda dispatch
  2438. (defvar org-agenda-restrict-begin (make-marker))
  2439. (defvar org-agenda-restrict-end (make-marker))
  2440. (defvar org-agenda-last-dispatch-buffer nil)
  2441. (defvar org-agenda-overriding-restriction nil)
  2442. (defcustom org-agenda-custom-commands-contexts nil
  2443. "Alist of custom agenda keys and contextual rules.
  2444. For example, if you have a custom agenda command \"p\" and you
  2445. want this command to be accessible only from plain text files,
  2446. use this:
  2447. (setq org-agenda-custom-commands-contexts
  2448. \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\")))))
  2449. Here are the available contexts definitions:
  2450. in-file: command displayed only in matching files
  2451. in-mode: command displayed only in matching modes
  2452. not-in-file: command not displayed in matching files
  2453. not-in-mode: command not displayed in matching modes
  2454. in-buffer: command displayed only in matching buffers
  2455. not-in-buffer: command not displayed in matching buffers
  2456. [function]: a custom function taking no argument
  2457. If you define several checks, the agenda command will be
  2458. accessible if there is at least one valid check.
  2459. You can also bind a key to another agenda custom command
  2460. depending on contextual rules.
  2461. (setq org-agenda-custom-commands-contexts
  2462. \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\")))))
  2463. Here it means: in .txt files, use \"p\" as the key for the
  2464. agenda command otherwise associated with \"q\". (The command
  2465. originally associated with \"q\" is not displayed to avoid
  2466. duplicates.)"
  2467. :version "24.3"
  2468. :group 'org-agenda-custom-commands
  2469. :type '(repeat (list :tag "Rule"
  2470. (string :tag " Agenda key")
  2471. (string :tag "Replace by command")
  2472. (repeat :tag "Available when"
  2473. (choice
  2474. (cons :tag "Condition"
  2475. (choice
  2476. (const :tag "In file" in-file)
  2477. (const :tag "Not in file" not-in-file)
  2478. (const :tag "In buffer" in-buffer)
  2479. (const :tag "Not in buffer" not-in-buffer)
  2480. (const :tag "In mode" in-mode)
  2481. (const :tag "Not in mode" not-in-mode))
  2482. (regexp))
  2483. (function :tag "Custom function"))))))
  2484. (defcustom org-agenda-max-entries nil
  2485. "Maximum number of entries to display in an agenda.
  2486. This can be nil (no limit) or an integer or an alist of agenda
  2487. types with an associated number of entries to display in this
  2488. type."
  2489. :version "24.4"
  2490. :package-version '(Org . "8.0")
  2491. :group 'org-agenda-custom-commands
  2492. :type '(choice (symbol :tag "No limit" nil)
  2493. (integer :tag "Max number of entries")
  2494. (repeat
  2495. (cons (choice :tag "Agenda type"
  2496. (const agenda)
  2497. (const todo)
  2498. (const tags)
  2499. (const search))
  2500. (integer :tag "Max number of entries")))))
  2501. (defcustom org-agenda-max-todos nil
  2502. "Maximum number of TODOs 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 TODOs")
  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 TODOs")))))
  2518. (defcustom org-agenda-max-tags nil
  2519. "Maximum number of tagged entries 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 tagged entries")
  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 tagged entries")))))
  2535. (defcustom org-agenda-max-effort nil
  2536. "Maximum cumulated effort duration for the agenda.
  2537. This can be nil (no limit) or a number of minutes (as an integer)
  2538. or an alist of agenda types with an associated number of minutes
  2539. to limit entries to in this 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 minutes")
  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 minutes")))))
  2552. (defvar org-agenda-keep-restricted-file-list nil)
  2553. (defvar org-keys nil)
  2554. (defvar org-match nil)
  2555. ;;;###autoload
  2556. (defun org-agenda (&optional arg keys restriction)
  2557. "Dispatch agenda commands to collect entries to the agenda buffer.
  2558. Prompts for a command to execute. Any prefix arg will be passed
  2559. on to the selected command. The default selections are:
  2560. a Call `org-agenda-list' to display the agenda for current day or week.
  2561. t Call `org-todo-list' to display the global todo list.
  2562. T Call `org-todo-list' to display the global todo list, select only
  2563. entries with a specific TODO keyword (the user gets a prompt).
  2564. m Call `org-tags-view' to display headlines with tags matching
  2565. a condition (the user is prompted for the condition).
  2566. M Like `m', but select only TODO entries, no ordinary headlines.
  2567. e Export views to associated files.
  2568. s Search entries for keywords.
  2569. S Search entries for keywords, only with TODO keywords.
  2570. / Multi occur across all agenda files and also files listed
  2571. in `org-agenda-text-search-extra-files'.
  2572. < Restrict agenda commands to buffer, subtree, or region.
  2573. Press several times to get the desired effect.
  2574. > Remove a previous restriction.
  2575. # List \"stuck\" projects.
  2576. ! Configure what \"stuck\" means.
  2577. C Configure custom agenda commands.
  2578. More commands can be added by configuring the variable
  2579. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2580. searches can be pre-defined in this way.
  2581. If the current buffer is in Org mode and visiting a file, you can also
  2582. first press `<' once to indicate that the agenda should be temporarily
  2583. \(until the next use of `\\[org-agenda]') restricted to the current file.
  2584. Pressing `<' twice means to restrict to the current subtree or region
  2585. \(if active)."
  2586. (interactive "P")
  2587. (catch 'exit
  2588. (let* ((org-keys keys)
  2589. (prefix-descriptions nil)
  2590. (org-agenda-buffer-name org-agenda-buffer-name)
  2591. (org-agenda-window-setup (if (equal (buffer-name)
  2592. org-agenda-buffer-name)
  2593. 'current-window
  2594. org-agenda-window-setup))
  2595. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2596. (org-agenda-custom-commands
  2597. ;; normalize different versions
  2598. (delq nil
  2599. (mapcar
  2600. (lambda (x)
  2601. (cond ((stringp (cdr x))
  2602. (push x prefix-descriptions)
  2603. nil)
  2604. ((stringp (nth 1 x)) x)
  2605. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2606. (t (cons (car x) (cons "" (cdr x))))))
  2607. org-agenda-custom-commands)))
  2608. (org-agenda-custom-commands
  2609. (org-contextualize-keys
  2610. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2611. ;; (buf (current-buffer))
  2612. (bfn (buffer-file-name (buffer-base-buffer)))
  2613. entry type org-match lprops ans) ;; key
  2614. ;; Turn off restriction unless there is an overriding one,
  2615. (unless org-agenda-overriding-restriction
  2616. (unless org-agenda-keep-restricted-file-list
  2617. ;; There is a request to keep the file list in place
  2618. (put 'org-agenda-files 'org-restrict nil))
  2619. (setq org-agenda-restrict nil)
  2620. (move-marker org-agenda-restrict-begin nil)
  2621. (move-marker org-agenda-restrict-end nil))
  2622. ;; Delete old local properties
  2623. (put 'org-agenda-redo-command 'org-lprops nil)
  2624. ;; Delete previously set last-arguments
  2625. (put 'org-agenda-redo-command 'last-args nil)
  2626. ;; Remember where this call originated
  2627. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2628. (unless org-keys
  2629. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2630. org-keys (car ans)
  2631. restriction (cdr ans)))
  2632. ;; If we have sticky agenda buffers, set a name for the buffer,
  2633. ;; depending on the invoking keys. The user may still set this
  2634. ;; as a command option, which will overwrite what we do here.
  2635. (when org-agenda-sticky
  2636. (setq org-agenda-buffer-name
  2637. (format "*Org Agenda(%s)*" org-keys)))
  2638. ;; Establish the restriction, if any
  2639. (when (and (not org-agenda-overriding-restriction) restriction)
  2640. (put 'org-agenda-files 'org-restrict (list bfn))
  2641. (cond
  2642. ((eq restriction 'region)
  2643. (setq org-agenda-restrict (current-buffer))
  2644. (move-marker org-agenda-restrict-begin (region-beginning))
  2645. (move-marker org-agenda-restrict-end (region-end)))
  2646. ((eq restriction 'subtree)
  2647. (save-excursion
  2648. (setq org-agenda-restrict (current-buffer))
  2649. (org-back-to-heading t)
  2650. (move-marker org-agenda-restrict-begin (point))
  2651. (move-marker org-agenda-restrict-end
  2652. (progn (org-end-of-subtree t)))))
  2653. ((and (eq restriction 'buffer)
  2654. (or (< 1 (point-min))
  2655. (< (point-max) (1+ (buffer-size)))))
  2656. (setq org-agenda-restrict (current-buffer))
  2657. (move-marker org-agenda-restrict-begin (point-min))
  2658. (move-marker org-agenda-restrict-end (point-max)))))
  2659. ;; For example the todo list should not need it (but does...)
  2660. (cond
  2661. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2662. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2663. (progn
  2664. ;; FIXME: Is (nth 3 entry) supposed to have access (via dynvars)
  2665. ;; to some of the local variables? There's no doc about
  2666. ;; that for `org-agenda-custom-commands'.
  2667. (setq type (nth 2 entry) org-match (eval (nth 3 entry) t)
  2668. lprops (nth 4 entry))
  2669. (when org-agenda-sticky
  2670. (setq org-agenda-buffer-name
  2671. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2672. (format "*Org Agenda(%s)*" org-keys))))
  2673. (put 'org-agenda-redo-command 'org-lprops lprops)
  2674. (cl-progv
  2675. (mapcar #'car lprops)
  2676. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  2677. (pcase type
  2678. (`agenda
  2679. (org-agenda-list arg))
  2680. (`agenda*
  2681. (org-agenda-list arg nil nil t))
  2682. (`alltodo
  2683. (org-todo-list arg))
  2684. (`search
  2685. (org-search-view arg org-match nil))
  2686. (`stuck
  2687. (org-agenda-list-stuck-projects arg))
  2688. (`tags
  2689. (org-tags-view arg org-match))
  2690. (`tags-todo
  2691. (org-tags-view '(4) org-match))
  2692. (`todo
  2693. (org-todo-list org-match))
  2694. (`tags-tree
  2695. (org-check-for-org-mode)
  2696. (org-match-sparse-tree arg org-match))
  2697. (`todo-tree
  2698. (org-check-for-org-mode)
  2699. (org-occur (concat "^" org-outline-regexp "[ \t]*"
  2700. (regexp-quote org-match) "\\>")))
  2701. (`occur-tree
  2702. (org-check-for-org-mode)
  2703. (org-occur org-match))
  2704. ((pred functionp)
  2705. (funcall type org-match))
  2706. ;; FIXME: Will signal an error since it's not `functionp'!
  2707. ((pred fboundp) (funcall type org-match))
  2708. (_ (user-error "Invalid custom agenda command type %s" type)))))
  2709. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2710. ((equal org-keys "C")
  2711. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2712. (customize-variable 'org-agenda-custom-commands))
  2713. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2714. ((equal org-keys "s") (call-interactively 'org-search-view))
  2715. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2716. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2717. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2718. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2719. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2720. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2721. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2722. (add-hook
  2723. 'post-command-hook
  2724. (lambda ()
  2725. (unless (current-message)
  2726. (let* ((m (org-agenda-get-any-marker))
  2727. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2728. (when note
  2729. (message "FLAGGING-NOTE ([?] for more info): %s"
  2730. (org-add-props
  2731. (replace-regexp-in-string
  2732. "\\\\n" "//"
  2733. (copy-sequence note))
  2734. nil 'face 'org-warning))))))
  2735. t t))
  2736. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2737. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2738. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2739. (t (user-error "Invalid agenda key"))))))
  2740. (defvar org-agenda-multi)
  2741. (defun org-agenda-append-agenda ()
  2742. "Append another agenda view to the current one.
  2743. This function allows interactive building of block agendas.
  2744. Agenda views are separated by `org-agenda-block-separator'."
  2745. (interactive)
  2746. (unless (derived-mode-p 'org-agenda-mode)
  2747. (user-error "Can only append from within agenda buffer"))
  2748. (let ((org-agenda-multi t))
  2749. (org-agenda)
  2750. (widen)
  2751. (org-agenda-finalize)
  2752. (setq buffer-read-only t)
  2753. (org-agenda-fit-window-to-buffer)))
  2754. (defun org-agenda-normalize-custom-commands (cmds)
  2755. "Normalize custom commands CMDS."
  2756. (delq nil
  2757. (mapcar
  2758. (lambda (x)
  2759. (cond ((stringp (cdr x)) nil)
  2760. ((stringp (nth 1 x)) x)
  2761. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2762. (t (cons (car x) (cons "" (cdr x))))))
  2763. cmds)))
  2764. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2765. "The user interface for selecting an agenda command."
  2766. (catch 'exit
  2767. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2768. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2769. (region-p (org-region-active-p))
  2770. (custom org-agenda-custom-commands)
  2771. (selstring "")
  2772. restriction second-time
  2773. c entry key type match prefixes rmheader header-end custom1 desc
  2774. line lines left right n n1)
  2775. (save-window-excursion
  2776. (delete-other-windows)
  2777. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2778. (erase-buffer)
  2779. (insert (eval-when-compile
  2780. (let ((header
  2781. (copy-sequence
  2782. "Press key for an agenda command:
  2783. -------------------------------- < Buffer, subtree/region restriction
  2784. a Agenda for current week or day > Remove restriction
  2785. t List of all TODO entries e Export agenda views
  2786. m Match a TAGS/PROP/TODO query T Entries with special TODO kwd
  2787. s Search for keywords M Like m, but only TODO entries
  2788. / Multi-occur S Like s, but only TODO entries
  2789. ? Find :FLAGGED: entries C Configure custom agenda commands
  2790. * Toggle sticky agenda views # List stuck projects (!=configure)
  2791. "))
  2792. (start 0))
  2793. (while (string-match
  2794. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2795. header start)
  2796. (setq start (match-end 0))
  2797. (add-text-properties (match-beginning 2) (match-end 2)
  2798. '(face bold) header))
  2799. header)))
  2800. (setq header-end (point-marker))
  2801. (while t
  2802. (setq custom1 custom)
  2803. (when (eq rmheader t)
  2804. (org-goto-line 1)
  2805. (re-search-forward ":" nil t)
  2806. (delete-region (match-end 0) (line-end-position))
  2807. (forward-char 1)
  2808. (looking-at "-+")
  2809. (delete-region (match-end 0) (line-end-position))
  2810. (move-marker header-end (match-end 0)))
  2811. (goto-char header-end)
  2812. (delete-region (point) (point-max))
  2813. ;; Produce all the lines that describe custom commands and prefixes
  2814. (setq lines nil)
  2815. (while (setq entry (pop custom1))
  2816. (setq key (car entry) desc (nth 1 entry)
  2817. type (nth 2 entry)
  2818. match (nth 3 entry))
  2819. (if (> (length key) 1)
  2820. (cl-pushnew (string-to-char key) prefixes :test #'equal)
  2821. (setq line
  2822. (format
  2823. "%-4s%-14s"
  2824. (org-add-props (copy-sequence key)
  2825. '(face bold))
  2826. (cond
  2827. ((string-match "\\S-" desc) desc)
  2828. ((eq type 'agenda) "Agenda for current week or day")
  2829. ((eq type 'agenda*) "Appointments for current week or day")
  2830. ((eq type 'alltodo) "List of all TODO entries")
  2831. ((eq type 'search) "Word search")
  2832. ((eq type 'stuck) "List of stuck projects")
  2833. ((eq type 'todo) "TODO keyword")
  2834. ((eq type 'tags) "Tags query")
  2835. ((eq type 'tags-todo) "Tags (TODO)")
  2836. ((eq type 'tags-tree) "Tags tree")
  2837. ((eq type 'todo-tree) "TODO kwd tree")
  2838. ((eq type 'occur-tree) "Occur tree")
  2839. ((functionp type) (if (symbolp type)
  2840. (symbol-name type)
  2841. "Lambda expression"))
  2842. (t "???"))))
  2843. (cond
  2844. ((not (org-string-nw-p match)) nil)
  2845. (org-agenda-menu-show-matcher
  2846. (setq line
  2847. (concat line ": "
  2848. (cond
  2849. ((stringp match)
  2850. (propertize match 'face 'org-warning))
  2851. ((listp type)
  2852. (format "set of %d commands" (length type)))))))
  2853. (t
  2854. (org-add-props line nil 'help-echo (concat "Matcher: " match))))
  2855. (push line lines)))
  2856. (setq lines (nreverse lines))
  2857. (when prefixes
  2858. (mapc (lambda (x)
  2859. (push
  2860. (format "%s %s"
  2861. (org-add-props (char-to-string x)
  2862. nil 'face 'bold)
  2863. (or (cdr (assoc (concat selstring
  2864. (char-to-string x))
  2865. prefix-descriptions))
  2866. "Prefix key"))
  2867. lines))
  2868. prefixes))
  2869. ;; Check if we should display in two columns
  2870. (if org-agenda-menu-two-columns
  2871. (progn
  2872. (setq n (length lines)
  2873. n1 (+ (/ n 2) (mod n 2))
  2874. right (nthcdr n1 lines)
  2875. left (copy-sequence lines))
  2876. (setcdr (nthcdr (1- n1) left) nil))
  2877. (setq left lines right nil))
  2878. (while left
  2879. (insert "\n" (pop left))
  2880. (when right
  2881. (if (< (current-column) 40)
  2882. (move-to-column 40 t)
  2883. (insert " "))
  2884. (insert (pop right))))
  2885. ;; Make the window the right size
  2886. (goto-char (point-min))
  2887. (if second-time
  2888. (when (not (pos-visible-in-window-p (point-max)))
  2889. (org-fit-window-to-buffer))
  2890. (setq second-time t)
  2891. (org-fit-window-to-buffer))
  2892. ;; Hint to navigation if window too small for all information
  2893. (setq header-line-format
  2894. (when (not (pos-visible-in-window-p (point-max)))
  2895. "Use C-v, M-v, C-n or C-p to navigate."))
  2896. ;; Ask for selection
  2897. (cl-loop
  2898. do (progn
  2899. (message "Press key for agenda command%s:"
  2900. (if (or restrict-ok org-agenda-overriding-restriction)
  2901. (if org-agenda-overriding-restriction
  2902. " (restriction lock active)"
  2903. (if restriction
  2904. (format " (restricted to %s)" restriction)
  2905. " (unrestricted)"))
  2906. ""))
  2907. (setq c (read-char-exclusive)))
  2908. until (not (memq c '(14 16 22 134217846)))
  2909. do (org-scroll c))
  2910. (message "")
  2911. (cond
  2912. ((assoc (char-to-string c) custom)
  2913. (setq selstring (concat selstring (char-to-string c)))
  2914. (throw 'exit (cons selstring restriction)))
  2915. ((memq c prefixes)
  2916. (setq selstring (concat selstring (char-to-string c))
  2917. prefixes nil
  2918. rmheader (or rmheader t)
  2919. custom (delq nil (mapcar
  2920. (lambda (x)
  2921. (if (or (= (length (car x)) 1)
  2922. (/= (string-to-char (car x)) c))
  2923. nil
  2924. (cons (substring (car x) 1) (cdr x))))
  2925. custom))))
  2926. ((eq c ?*)
  2927. (call-interactively 'org-toggle-sticky-agenda)
  2928. (sit-for 2))
  2929. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2930. (message "Restriction is only possible in Org buffers")
  2931. (ding) (sit-for 1))
  2932. ((eq c ?1)
  2933. (org-agenda-remove-restriction-lock 'noupdate)
  2934. (setq restriction 'buffer))
  2935. ((eq c ?0)
  2936. (org-agenda-remove-restriction-lock 'noupdate)
  2937. (setq restriction (if region-p 'region 'subtree)))
  2938. ((eq c ?<)
  2939. (org-agenda-remove-restriction-lock 'noupdate)
  2940. (setq restriction
  2941. (cond
  2942. ((eq restriction 'buffer)
  2943. (if region-p 'region 'subtree))
  2944. ((memq restriction '(subtree region))
  2945. nil)
  2946. (t 'buffer))))
  2947. ((eq c ?>)
  2948. (org-agenda-remove-restriction-lock 'noupdate)
  2949. (setq restriction nil))
  2950. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2951. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2952. ((and (> (length selstring) 0) (eq c ?\d))
  2953. (delete-window)
  2954. (org-agenda-get-restriction-and-command prefix-descriptions))
  2955. ((equal c ?q) (user-error "Abort"))
  2956. (t (user-error "Invalid key %c" c))))))))
  2957. (defun org-agenda-fit-window-to-buffer ()
  2958. "Fit the window to the buffer size."
  2959. (and (memq org-agenda-window-setup '(reorganize-frame))
  2960. (fboundp 'fit-window-to-buffer)
  2961. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2962. (= (car org-agenda-window-frame-fractions) 1.0))
  2963. (delete-other-windows)
  2964. (org-fit-window-to-buffer
  2965. nil
  2966. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2967. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2968. (defvar org-cmd nil)
  2969. (defvar org-agenda-overriding-cmd nil)
  2970. (defvar org-agenda-overriding-arguments nil)
  2971. (defvar org-agenda-overriding-cmd-arguments nil)
  2972. (defun org-let (list &rest body) ;FIXME: So many kittens are suffering here.
  2973. (declare (indent 1) (obsolete cl-progv "2021"))
  2974. (eval (cons 'let (cons list body))))
  2975. (defun org-let2 (list1 list2 &rest body) ;FIXME: Where did our karma go?
  2976. (declare (indent 2) (obsolete cl-progv "2021"))
  2977. (eval (cons 'let (cons list1 (list (cons 'let (cons list2 body)))))))
  2978. (defun org-agenda-run-series (name series)
  2979. "Run agenda NAME as a SERIES of agenda commands."
  2980. (let* ((gprops (nth 1 series))
  2981. (gvars (mapcar #'car gprops))
  2982. (gvals (mapcar (lambda (binding) (eval (cadr binding) t)) gprops)))
  2983. (cl-progv gvars gvals (org-agenda-prepare name))
  2984. ;; We need to reset agenda markers here, because when constructing a
  2985. ;; block agenda, the individual blocks do not do that.
  2986. (org-agenda-reset-markers)
  2987. (with-no-warnings
  2988. (defvar match)) ;Used via the `eval' below.
  2989. (let* ((org-agenda-multi t)
  2990. ;; FIXME: Redo should contain lists of (FUNS . ARGS) rather
  2991. ;; than expressions, so you don't need to `quote' the args
  2992. ;; and you just need to `apply' instead of `eval' when using it.
  2993. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2994. (cmds (car series))
  2995. match
  2996. org-cmd type lprops)
  2997. (while (setq org-cmd (pop cmds))
  2998. (setq type (car org-cmd))
  2999. (setq match (eval (nth 1 org-cmd) t))
  3000. (setq lprops (nth 2 org-cmd))
  3001. (let ((org-agenda-overriding-arguments
  3002. (if (eq org-agenda-overriding-cmd org-cmd)
  3003. (or org-agenda-overriding-arguments
  3004. org-agenda-overriding-cmd-arguments)))
  3005. (lvars (mapcar #'car lprops))
  3006. (lvals (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)))
  3007. (cl-progv (append gvars lvars) (append gvals lvals)
  3008. (pcase type
  3009. (`agenda
  3010. (call-interactively 'org-agenda-list))
  3011. (`agenda*
  3012. (funcall 'org-agenda-list nil nil t))
  3013. (`alltodo
  3014. (call-interactively 'org-todo-list))
  3015. (`search
  3016. (org-search-view current-prefix-arg match nil))
  3017. (`stuck
  3018. (call-interactively 'org-agenda-list-stuck-projects))
  3019. (`tags
  3020. (org-tags-view current-prefix-arg match))
  3021. (`tags-todo
  3022. (org-tags-view '(4) match))
  3023. (`todo
  3024. (org-todo-list match))
  3025. ((pred fboundp)
  3026. (funcall type match))
  3027. (_ (error "Invalid type in command series"))))))
  3028. (widen)
  3029. (let ((inhibit-read-only t))
  3030. (add-text-properties (point-min) (point-max)
  3031. `(org-series t org-series-redo-cmd ,redo)))
  3032. (setq org-agenda-redo-command redo)
  3033. (goto-char (point-min)))
  3034. (org-agenda-fit-window-to-buffer)
  3035. (cl-progv gvars gvals (org-agenda-finalize))))
  3036. (defun org-agenda--split-plist (plist)
  3037. ;; We could/should arguably use `map-keys' and `map-values'.
  3038. (let (keys vals)
  3039. (while plist
  3040. (push (pop plist) keys)
  3041. (push (pop plist) vals))
  3042. (cons (nreverse keys) (nreverse vals))))
  3043. ;;;###autoload
  3044. (defmacro org-batch-agenda (cmd-key &rest parameters)
  3045. "Run an agenda command in batch mode and send the result to STDOUT.
  3046. If CMD-KEY is a string of length 1, it is used as a key in
  3047. `org-agenda-custom-commands' and triggers this command. If it is a
  3048. longer string it is used as a tags/todo match string.
  3049. Parameters are alternating variable names and values that will be bound
  3050. before running the agenda command."
  3051. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3052. `(org--batch-agenda ,cmd-key ',vars (list ,@exps))))
  3053. (defun org--batch-agenda (cmd-key vars vals)
  3054. ;; `org-batch-agenda' is a macro because every other "parameter" is
  3055. ;; a variable name rather than an expression to evaluate. Yuck!
  3056. (cl-progv vars vals
  3057. (let (org-agenda-sticky)
  3058. (if (> (length cmd-key) 1)
  3059. (org-tags-view nil cmd-key)
  3060. (org-agenda nil cmd-key))))
  3061. (set-buffer org-agenda-buffer-name)
  3062. (princ (buffer-string)))
  3063. (defvar org-agenda-info nil)
  3064. ;;;###autoload
  3065. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  3066. "Run an agenda command in batch mode and send the result to STDOUT.
  3067. If CMD-KEY is a string of length 1, it is used as a key in
  3068. `org-agenda-custom-commands' and triggers this command. If it is a
  3069. longer string it is used as a tags/todo match string.
  3070. Parameters are alternating variable names and values that will be bound
  3071. before running the agenda command.
  3072. The output gives a line for each selected agenda item. Each
  3073. item is a list of comma-separated values, like this:
  3074. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  3075. category The category of the item
  3076. head The headline, without TODO kwd, TAGS and PRIORITY
  3077. type The type of the agenda entry, can be
  3078. todo selected in TODO match
  3079. tagsmatch selected in tags match
  3080. diary imported from diary
  3081. deadline a deadline on given date
  3082. scheduled scheduled on given date
  3083. timestamp entry has timestamp on given date
  3084. closed entry was closed on given date
  3085. upcoming-deadline warning about deadline
  3086. past-scheduled forwarded scheduled item
  3087. block entry has date block including g. date
  3088. todo The todo keyword, if any
  3089. tags All tags including inherited ones, separated by colons
  3090. date The relevant date, like 2007-2-14
  3091. time The time, like 15:00-16:50
  3092. extra String with extra planning info
  3093. priority-l The priority letter if any was given
  3094. priority-n The computed numerical priority
  3095. agenda-day The day in the agenda where this is listed"
  3096. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3097. `(org--batch-agenda-csv ,cmd-key ',vars (list ,@exps))))
  3098. (defun org--batch-agenda-csv (cmd-key vars vals)
  3099. ;; `org-batch-agenda-csv' is a macro because every other "parameter" is
  3100. ;; a variable name rather than an expression to evaluate. Yuck!
  3101. (let ((org-agenda-remove-tags t))
  3102. (cl-progv vars vals
  3103. ;; FIXME: Shouldn't this be 1 (see commit 10173ad6d610b)?
  3104. (if (> (length cmd-key) 2)
  3105. (org-tags-view nil cmd-key)
  3106. (org-agenda nil cmd-key))))
  3107. (set-buffer org-agenda-buffer-name)
  3108. (let ((lines (org-split-string (buffer-string) "\n")))
  3109. (dolist (line lines)
  3110. (when (get-text-property 0 'org-category line)
  3111. (setq org-agenda-info
  3112. (org-fix-agenda-info (text-properties-at 0 line)))
  3113. (princ
  3114. (mapconcat #'org-agenda-export-csv-mapper
  3115. '(org-category txt type todo tags date time extra
  3116. priority-letter priority agenda-day)
  3117. ","))
  3118. (princ "\n")))))
  3119. (defun org-fix-agenda-info (props)
  3120. "Make sure all properties on an agenda item have a canonical form.
  3121. This ensures the export commands can easily use it."
  3122. (let (tmp re)
  3123. (when (setq tmp (plist-get props 'tags))
  3124. (setq props (plist-put props 'tags (mapconcat #'identity tmp ":"))))
  3125. (when (setq tmp (plist-get props 'date))
  3126. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3127. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3128. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  3129. (setq tmp (calendar-date-string tmp)))
  3130. (setq props (plist-put props 'date tmp)))
  3131. (when (setq tmp (plist-get props 'day))
  3132. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3133. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3134. (setq tmp (calendar-date-string tmp)))
  3135. (setq props (plist-put props 'day tmp))
  3136. (setq props (plist-put props 'agenda-day tmp)))
  3137. (when (setq tmp (plist-get props 'txt))
  3138. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  3139. (plist-put props 'priority-letter (match-string 1 tmp))
  3140. (setq tmp (replace-match "" t t tmp)))
  3141. (when (and (setq re (plist-get props 'org-todo-regexp))
  3142. (setq re (concat "\\`\\.*" re " ?"))
  3143. (let ((case-fold-search nil)) (string-match re tmp)))
  3144. (plist-put props 'todo (match-string 1 tmp))
  3145. (setq tmp (replace-match "" t t tmp)))
  3146. (plist-put props 'txt tmp)))
  3147. props)
  3148. (defun org-agenda-export-csv-mapper (prop)
  3149. (let ((res (plist-get org-agenda-info prop)))
  3150. (setq res
  3151. (cond
  3152. ((not res) "")
  3153. ((stringp res) res)
  3154. (t (prin1-to-string res))))
  3155. (org-trim (replace-regexp-in-string "," ";" res nil t))))
  3156. ;;;###autoload
  3157. (defun org-store-agenda-views (&rest _parameters)
  3158. "Store agenda views."
  3159. (interactive)
  3160. (org--batch-store-agenda-views nil nil))
  3161. ;;;###autoload
  3162. (defmacro org-batch-store-agenda-views (&rest parameters)
  3163. "Run all custom agenda commands that have a file argument."
  3164. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3165. `(org--batch-store-agenda-views ',vars (list ,@exps))))
  3166. (defun org--batch-store-agenda-views (vars vals)
  3167. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  3168. (pop-up-frames nil)
  3169. (dir default-directory)
  3170. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  3171. (save-window-excursion
  3172. (while cmds
  3173. (setq cmd (pop cmds)
  3174. thiscmdkey (car cmd)
  3175. thiscmdcmd (cdr cmd)
  3176. match (nth 2 thiscmdcmd)
  3177. bufname (if org-agenda-sticky
  3178. (or (and (stringp match)
  3179. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  3180. (format "*Org Agenda(%s)*" thiscmdkey))
  3181. org-agenda-buffer-name)
  3182. cmd-or-set (nth 2 cmd)
  3183. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  3184. files (nth (if (listp cmd-or-set) 4 5) cmd))
  3185. (if (stringp files) (setq files (list files)))
  3186. (when files
  3187. (let* ((opts (append org-agenda-exporter-settings opts))
  3188. (vars (append (mapcar #'car opts) vars))
  3189. (vals (append (mapcar (lambda (binding) (eval (cadr binding) t))
  3190. opts)
  3191. vals)))
  3192. (cl-progv vars vals
  3193. (org-agenda nil thiscmdkey))
  3194. (set-buffer bufname)
  3195. (while files
  3196. (cl-progv vars vals
  3197. (org-agenda-write (expand-file-name (pop files) dir)
  3198. nil t bufname))))
  3199. (and (get-buffer bufname)
  3200. (kill-buffer bufname)))))))
  3201. (defvar org-agenda-current-span nil
  3202. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3203. (defun org-agenda-mark-header-line (pos)
  3204. "Mark the line at POS as an agenda structure header."
  3205. (save-excursion
  3206. (goto-char pos)
  3207. (put-text-property (line-beginning-position) (line-end-position)
  3208. 'org-agenda-structural-header t)
  3209. (when org-agenda-title-append
  3210. (put-text-property (line-beginning-position) (line-end-position)
  3211. 'org-agenda-title-append org-agenda-title-append))))
  3212. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  3213. (defvar org-agenda-write-buffer-name "Agenda View")
  3214. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  3215. "Write the current buffer (an agenda view) as a file.
  3216. Depending on the extension of the file name, plain text (.txt),
  3217. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  3218. If the extension is .ics, translate visible agenda into iCalendar
  3219. format. If the extension is .org, collect all subtrees
  3220. corresponding to the agenda entries and add them in an .org file.
  3221. With prefix argument OPEN, open the new file immediately. If
  3222. NOSETTINGS is given, do not scope the settings of
  3223. `org-agenda-exporter-settings' into the export commands. This is
  3224. used when the settings have already been scoped and we do not
  3225. wish to overrule other, higher priority settings. If
  3226. AGENDA-BUFFER-NAME is provided, use this as the buffer name for
  3227. the agenda to write."
  3228. (interactive "FWrite agenda to file: \nP")
  3229. (if (or (not (file-writable-p file))
  3230. (and (file-exists-p file)
  3231. (if (called-interactively-p 'any)
  3232. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3233. (user-error "Cannot write agenda to file %s" file))
  3234. (cl-progv
  3235. (if nosettings nil (mapcar #'car org-agenda-exporter-settings))
  3236. (if nosettings nil (mapcar (lambda (binding) (eval (cadr binding) t))
  3237. org-agenda-exporter-settings))
  3238. (save-excursion
  3239. (save-window-excursion
  3240. (let ((bs (copy-sequence (buffer-string)))
  3241. (extension (file-name-extension file))
  3242. (default-directory (file-name-directory file))
  3243. ) ;; beg content
  3244. (with-temp-buffer
  3245. (rename-buffer org-agenda-write-buffer-name t)
  3246. (set-buffer-modified-p nil)
  3247. (insert bs)
  3248. (org-agenda-remove-marked-text 'invisible 'org-filtered)
  3249. (run-hooks 'org-agenda-before-write-hook)
  3250. (cond
  3251. ((bound-and-true-p org-mobile-creating-agendas)
  3252. (org-mobile-write-agenda-for-mobile file))
  3253. ((string= "org" extension)
  3254. (let (content p m message-log-max)
  3255. (goto-char (point-min))
  3256. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3257. (goto-char p)
  3258. (setq m (get-text-property (point) 'org-hd-marker))
  3259. (when m
  3260. (push (with-current-buffer (marker-buffer m)
  3261. (goto-char m)
  3262. (org-copy-subtree 1 nil t t)
  3263. org-subtree-clip)
  3264. content)))
  3265. (find-file file)
  3266. (erase-buffer)
  3267. (dolist (s content) (org-paste-subtree 1 s))
  3268. (write-file file)
  3269. (kill-buffer (current-buffer))
  3270. (message "Org file written to %s" file)))
  3271. ((member extension '("html" "htm"))
  3272. (or (require 'htmlize nil t)
  3273. (error "Please install htmlize from https://github.com/hniksic/emacs-htmlize"))
  3274. (declare-function htmlize-buffer "htmlize" (&optional buffer))
  3275. (set-buffer (htmlize-buffer (current-buffer)))
  3276. (when org-agenda-export-html-style
  3277. ;; replace <style> section with org-agenda-export-html-style
  3278. (goto-char (point-min))
  3279. (kill-region (- (search-forward "<style") 6)
  3280. (search-forward "</style>"))
  3281. (insert org-agenda-export-html-style))
  3282. (write-file file)
  3283. (kill-buffer (current-buffer))
  3284. (message "HTML written to %s" file))
  3285. ((string= "ps" extension)
  3286. (require 'ps-print)
  3287. (ps-print-buffer-with-faces file)
  3288. (message "Postscript written to %s" file))
  3289. ((string= "pdf" extension)
  3290. (require 'ps-print)
  3291. (ps-print-buffer-with-faces
  3292. (concat (file-name-sans-extension file) ".ps"))
  3293. (call-process "ps2pdf" nil nil nil
  3294. (expand-file-name
  3295. (concat (file-name-sans-extension file) ".ps"))
  3296. (expand-file-name file))
  3297. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3298. (message "PDF written to %s" file))
  3299. ((string= "ics" extension)
  3300. (require 'ox-icalendar)
  3301. (declare-function org-icalendar-export-current-agenda
  3302. "ox-icalendar" (file))
  3303. (org-icalendar-export-current-agenda (expand-file-name file)))
  3304. (t
  3305. (let ((bs (buffer-string)))
  3306. (find-file file)
  3307. (erase-buffer)
  3308. (insert bs)
  3309. (save-buffer 0)
  3310. (kill-buffer (current-buffer))
  3311. (message "Plain text written to %s" file))))))))
  3312. (set-buffer (or agenda-bufname
  3313. ;; FIXME: I'm pretty sure called-interactively-p
  3314. ;; doesn't do what we want here!
  3315. (and (called-interactively-p 'any) (buffer-name))
  3316. org-agenda-buffer-name)))
  3317. (when open (org-open-file file)))
  3318. (defun org-agenda-remove-marked-text (property &optional value)
  3319. "Delete all text marked with VALUE of PROPERTY.
  3320. VALUE defaults to t."
  3321. (let (beg)
  3322. (setq value (or value t))
  3323. (while (setq beg (text-property-any (point-min) (point-max)
  3324. property value))
  3325. (delete-region
  3326. beg (or (next-single-property-change beg property)
  3327. (point-max))))))
  3328. (defun org-agenda-add-entry-text ()
  3329. "Add entry text to agenda lines.
  3330. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3331. entry text following headings shown in the agenda.
  3332. Drawers will be excluded, also the line with scheduling/deadline info."
  3333. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3334. (not (bound-and-true-p org-mobile-creating-agendas)))
  3335. (let (m txt)
  3336. (goto-char (point-min))
  3337. (while (not (eobp))
  3338. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3339. (beginning-of-line 2)
  3340. (setq txt (org-agenda-get-some-entry-text
  3341. m org-agenda-add-entry-text-maxlines " > "))
  3342. (end-of-line 1)
  3343. (if (string-match "\\S-" txt)
  3344. (insert "\n" txt)
  3345. (or (eobp) (forward-char 1))))))))
  3346. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3347. &rest keep)
  3348. "Extract entry text from MARKER, at most N-LINES lines.
  3349. This will ignore drawers etc, just get the text.
  3350. If INDENT is given, prefix every line with this string. If KEEP is
  3351. given, it is a list of symbols, defining stuff that should not be
  3352. removed from the entry content. Currently only `planning' is allowed here."
  3353. (let (txt drawer-re kwd-time-re ind)
  3354. (save-excursion
  3355. (with-current-buffer (marker-buffer marker)
  3356. (if (not (derived-mode-p 'org-mode))
  3357. (setq txt "")
  3358. (org-with-wide-buffer
  3359. (goto-char marker)
  3360. (end-of-line 1)
  3361. (setq txt (buffer-substring
  3362. (min (1+ (point)) (point-max))
  3363. (progn (outline-next-heading) (point)))
  3364. drawer-re org-drawer-regexp
  3365. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3366. ".*\n?"))
  3367. (with-temp-buffer
  3368. (insert txt)
  3369. (when org-agenda-add-entry-text-descriptive-links
  3370. (goto-char (point-min))
  3371. (while (org-activate-links (point-max))
  3372. (goto-char (match-end 0))))
  3373. (goto-char (point-min))
  3374. (while (re-search-forward org-link-bracket-re (point-max) t)
  3375. (set-text-properties (match-beginning 0) (match-end 0)
  3376. nil))
  3377. (goto-char (point-min))
  3378. (while (re-search-forward drawer-re nil t)
  3379. (delete-region
  3380. (match-beginning 0)
  3381. (progn (re-search-forward
  3382. "^[ \t]*:END:.*\n?" nil 'move)
  3383. (point))))
  3384. (unless (member 'planning keep)
  3385. (goto-char (point-min))
  3386. (while (re-search-forward kwd-time-re nil t)
  3387. (replace-match "")))
  3388. (goto-char (point-min))
  3389. (when org-agenda-entry-text-exclude-regexps
  3390. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3391. (while (setq re (pop re-list))
  3392. (goto-char (point-min))
  3393. (while (re-search-forward re nil t)
  3394. (replace-match "")))))
  3395. (goto-char (point-max))
  3396. (skip-chars-backward " \t\n")
  3397. (when (looking-at "[ \t\n]+\\'") (replace-match ""))
  3398. ;; find and remove min common indentation
  3399. (goto-char (point-min))
  3400. (untabify (point-min) (point-max))
  3401. (setq ind (org-current-text-indentation))
  3402. (while (not (eobp))
  3403. (unless (looking-at "[ \t]*$")
  3404. (setq ind (min ind (org-current-text-indentation))))
  3405. (beginning-of-line 2))
  3406. (goto-char (point-min))
  3407. (while (not (eobp))
  3408. (unless (looking-at "[ \t]*$")
  3409. (move-to-column ind)
  3410. (delete-region (line-beginning-position) (point)))
  3411. (beginning-of-line 2))
  3412. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3413. (goto-char (point-min))
  3414. (when indent
  3415. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3416. (replace-match indent t t)))
  3417. (goto-char (point-min))
  3418. (while (looking-at "[ \t]*\n") (replace-match ""))
  3419. (goto-char (point-max))
  3420. (when (> (org-current-line)
  3421. n-lines)
  3422. (org-goto-line (1+ n-lines))
  3423. (backward-char 1))
  3424. (setq txt (buffer-substring (point-min) (point))))))))
  3425. txt))
  3426. (defun org-check-for-org-mode ()
  3427. "Make sure current buffer is in Org mode. Error if not."
  3428. (or (derived-mode-p 'org-mode)
  3429. (error "Cannot execute Org agenda command on buffer in %s"
  3430. major-mode)))
  3431. ;;; Agenda prepare and finalize
  3432. (defvar org-agenda-multi nil) ; dynamically scoped
  3433. (defvar org-agenda-pre-window-conf nil)
  3434. (defvar org-agenda-columns-active nil)
  3435. (defvar org-agenda-name nil)
  3436. (defvar org-agenda-tag-filter nil)
  3437. (defvar org-agenda-category-filter nil)
  3438. (defvar org-agenda-regexp-filter nil)
  3439. (defvar org-agenda-effort-filter nil)
  3440. (defvar org-agenda-top-headline-filter nil)
  3441. (defvar org-agenda-represented-categories nil
  3442. "Cache for the list of all categories in the agenda.")
  3443. (defvar org-agenda-represented-tags nil
  3444. "Cache for the list of all categories in the agenda.")
  3445. (defvar org-agenda-tag-filter-preset nil
  3446. "A preset of the tags filter used for secondary agenda filtering.
  3447. This must be a list of strings, each string must be a single tag preceded
  3448. by \"+\" or \"-\".
  3449. This variable should not be set directly, but agenda custom commands can
  3450. bind it in the options section. The preset filter is a global property of
  3451. the entire agenda view. In a block agenda, it will not work reliably to
  3452. define a filter for one of the individual blocks. You need to set it in
  3453. the global options and expect it to be applied to the entire view.")
  3454. (defconst org-agenda-filter-variables
  3455. '((category . org-agenda-category-filter)
  3456. (tag . org-agenda-tag-filter)
  3457. (effort . org-agenda-effort-filter)
  3458. (regexp . org-agenda-regexp-filter))
  3459. "Alist of filter types and associated variables.")
  3460. (defun org-agenda-filter-any ()
  3461. "Is any filter active?"
  3462. (cl-some (lambda (x)
  3463. (or (symbol-value (cdr x))
  3464. (get :preset-filter x)))
  3465. org-agenda-filter-variables))
  3466. (defvar org-agenda-category-filter-preset nil
  3467. "A preset of the category filter used for secondary agenda filtering.
  3468. This must be a list of strings, each string must be a single category
  3469. preceded by \"+\" or \"-\".
  3470. This variable should not be set directly, but agenda custom commands can
  3471. bind it in the options section. The preset filter is a global property of
  3472. the entire agenda view. In a block agenda, it will not work reliably to
  3473. define a filter for one of the individual blocks. You need to set it in
  3474. the global options and expect it to be applied to the entire view.")
  3475. (defvar org-agenda-regexp-filter-preset nil
  3476. "A preset of the regexp filter used for secondary agenda filtering.
  3477. This must be a list of strings, each string must be a single regexp
  3478. preceded by \"+\" or \"-\".
  3479. This variable should not be set directly, but agenda custom commands can
  3480. bind it in the options section. The preset filter is a global property of
  3481. the entire agenda view. In a block agenda, it will not work reliably to
  3482. define a filter for one of the individual blocks. You need to set it in
  3483. the global options and expect it to be applied to the entire view.")
  3484. (defvar org-agenda-effort-filter-preset nil
  3485. "A preset of the effort condition used for secondary agenda filtering.
  3486. This must be a list of strings, each string must be a single regexp
  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. (defun org-agenda-use-sticky-p ()
  3494. "Return non-nil if an agenda buffer named
  3495. `org-agenda-buffer-name' exists and should be shown instead of
  3496. generating a new one."
  3497. (and
  3498. ;; turned off by user
  3499. org-agenda-sticky
  3500. ;; For multi-agenda buffer already exists
  3501. (not org-agenda-multi)
  3502. ;; buffer found
  3503. (get-buffer org-agenda-buffer-name)
  3504. ;; C-u parameter is same as last call
  3505. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3506. (and
  3507. (equal current-prefix-arg
  3508. org-agenda-last-prefix-arg)
  3509. ;; In case user turned stickiness on, while having existing
  3510. ;; Agenda buffer active, don't reuse that buffer, because it
  3511. ;; does not have org variables local
  3512. org-agenda-this-buffer-is-sticky))))
  3513. (defvar org-agenda-buffer-tmp-name nil)
  3514. (defun org-agenda--get-buffer-name (sticky-name)
  3515. (or org-agenda-buffer-tmp-name
  3516. (and org-agenda-doing-sticky-redo org-agenda-buffer-name)
  3517. sticky-name
  3518. "*Org Agenda*"))
  3519. (defun org-agenda-prepare-window (abuf filter-alist)
  3520. "Setup agenda buffer in the window.
  3521. ABUF is the buffer for the agenda window.
  3522. FILTER-ALIST is an alist of filters we need to apply when
  3523. `org-agenda-persistent-filter' is non-nil."
  3524. (let* ((awin (get-buffer-window abuf)) wconf)
  3525. (cond
  3526. ((equal (current-buffer) abuf) nil)
  3527. (awin (select-window awin))
  3528. ((not (setq wconf (current-window-configuration))))
  3529. ((eq org-agenda-window-setup 'current-window)
  3530. (pop-to-buffer-same-window abuf))
  3531. ((eq org-agenda-window-setup 'other-window)
  3532. (org-switch-to-buffer-other-window abuf))
  3533. ((eq org-agenda-window-setup 'other-frame)
  3534. (switch-to-buffer-other-frame abuf))
  3535. ((eq org-agenda-window-setup 'other-tab)
  3536. (if (fboundp 'switch-to-buffer-other-tab)
  3537. (switch-to-buffer-other-tab abuf)
  3538. (user-error "Your version of Emacs does not have tab bar support")))
  3539. ((eq org-agenda-window-setup 'only-window)
  3540. (delete-other-windows)
  3541. (pop-to-buffer-same-window abuf))
  3542. ((eq org-agenda-window-setup 'reorganize-frame)
  3543. (delete-other-windows)
  3544. (org-switch-to-buffer-other-window abuf)))
  3545. (setq org-agenda-tag-filter (cdr (assq 'tag filter-alist)))
  3546. (setq org-agenda-category-filter (cdr (assq 'cat filter-alist)))
  3547. (setq org-agenda-effort-filter (cdr (assq 'effort filter-alist)))
  3548. (setq org-agenda-regexp-filter (cdr (assq 're filter-alist)))
  3549. ;; Additional test in case agenda is invoked from within agenda
  3550. ;; buffer via elisp link.
  3551. (unless (equal (current-buffer) abuf)
  3552. (pop-to-buffer-same-window abuf))
  3553. (setq org-agenda-pre-window-conf
  3554. (or wconf org-agenda-pre-window-conf))))
  3555. (defun org-agenda-prepare (&optional name)
  3556. (let ((filter-alist (when org-agenda-persistent-filter
  3557. (with-current-buffer
  3558. (get-buffer-create org-agenda-buffer-name)
  3559. `((tag . ,org-agenda-tag-filter)
  3560. (re . ,org-agenda-regexp-filter)
  3561. (effort . ,org-agenda-effort-filter)
  3562. (cat . ,org-agenda-category-filter))))))
  3563. (if (org-agenda-use-sticky-p)
  3564. (progn
  3565. (put 'org-agenda-tag-filter :preset-filter nil)
  3566. (put 'org-agenda-category-filter :preset-filter nil)
  3567. (put 'org-agenda-regexp-filter :preset-filter nil)
  3568. (put 'org-agenda-effort-filter :preset-filter nil)
  3569. ;; Popup existing buffer
  3570. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3571. filter-alist)
  3572. (message "Sticky Agenda buffer, use `r' to refresh")
  3573. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3574. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3575. (setq org-todo-keywords-for-agenda nil)
  3576. (put 'org-agenda-tag-filter :preset-filter
  3577. org-agenda-tag-filter-preset)
  3578. (put 'org-agenda-category-filter :preset-filter
  3579. org-agenda-category-filter-preset)
  3580. (put 'org-agenda-regexp-filter :preset-filter
  3581. org-agenda-regexp-filter-preset)
  3582. (put 'org-agenda-effort-filter :preset-filter
  3583. org-agenda-effort-filter-preset)
  3584. (if org-agenda-multi
  3585. (progn
  3586. (setq buffer-read-only nil)
  3587. (goto-char (point-max))
  3588. (unless (or (bobp) org-agenda-compact-blocks
  3589. (not org-agenda-block-separator))
  3590. (insert "\n"
  3591. (if (stringp org-agenda-block-separator)
  3592. org-agenda-block-separator
  3593. (make-string (window-max-chars-per-line) org-agenda-block-separator))
  3594. "\n"))
  3595. (narrow-to-region (point) (point-max)))
  3596. (setq org-done-keywords-for-agenda nil)
  3597. ;; Setting any org variables that are in org-agenda-local-vars
  3598. ;; list need to be done after the prepare call
  3599. (org-agenda-prepare-window
  3600. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3601. (setq buffer-read-only nil)
  3602. (org-agenda-reset-markers)
  3603. (let ((inhibit-read-only t)) (erase-buffer))
  3604. (org-agenda-mode)
  3605. (setq org-agenda-buffer (current-buffer))
  3606. (setq org-agenda-contributing-files nil)
  3607. (setq org-agenda-columns-active nil)
  3608. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3609. (setq org-todo-keywords-for-agenda
  3610. (org-uniquify org-todo-keywords-for-agenda))
  3611. (setq org-done-keywords-for-agenda
  3612. (org-uniquify org-done-keywords-for-agenda))
  3613. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3614. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3615. (and name (not org-agenda-name)
  3616. (setq-local org-agenda-name name)))
  3617. (setq buffer-read-only nil))))
  3618. (defvar org-overriding-columns-format)
  3619. (defvar org-local-columns-format)
  3620. (defun org-agenda-finalize ()
  3621. "Finishing touch for the agenda buffer.
  3622. This function is called just before displaying the agenda. If
  3623. you want to add your own functions to the finalization of the
  3624. agenda display, configure `org-agenda-finalize-hook'."
  3625. (unless org-agenda-multi
  3626. (let ((inhibit-read-only t))
  3627. (save-excursion
  3628. (goto-char (point-min))
  3629. (save-excursion
  3630. (while (org-activate-links (point-max))
  3631. (goto-char (match-end 0))))
  3632. (unless (eq org-agenda-remove-tags t)
  3633. (org-agenda-align-tags))
  3634. (unless org-agenda-with-colors
  3635. (remove-text-properties (point-min) (point-max) '(face nil)))
  3636. (when (bound-and-true-p org-overriding-columns-format)
  3637. (setq-local org-local-columns-format
  3638. org-overriding-columns-format))
  3639. (when org-agenda-view-columns-initially
  3640. (org-agenda-columns))
  3641. (when org-agenda-fontify-priorities
  3642. (org-agenda-fontify-priorities))
  3643. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3644. (org-agenda-dim-blocked-tasks))
  3645. (org-agenda-mark-clocking-task)
  3646. (when org-agenda-entry-text-mode
  3647. (org-agenda-entry-text-hide)
  3648. (org-agenda-entry-text-show))
  3649. (when (and (featurep 'org-habit)
  3650. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3651. (org-habit-insert-consistency-graphs))
  3652. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3653. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3654. (and (listp org-agenda-show-inherited-tags)
  3655. (memq org-agenda-type org-agenda-show-inherited-tags))
  3656. (and (eq org-agenda-show-inherited-tags t)
  3657. (or (eq org-agenda-use-tag-inheritance t)
  3658. (and (listp org-agenda-use-tag-inheritance)
  3659. (not (memq org-agenda-type
  3660. org-agenda-use-tag-inheritance))))))
  3661. (let (mrk)
  3662. (save-excursion
  3663. (goto-char (point-min))
  3664. (while (equal (forward-line) 0)
  3665. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3666. (put-text-property (line-beginning-position) (line-end-position)
  3667. 'tags
  3668. (org-with-point-at mrk
  3669. (org-get-tags))))))))
  3670. (setq org-agenda-represented-tags nil
  3671. org-agenda-represented-categories nil)
  3672. (when org-agenda-top-headline-filter
  3673. (org-agenda-filter-top-headline-apply
  3674. org-agenda-top-headline-filter))
  3675. (when org-agenda-tag-filter
  3676. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3677. (when (get 'org-agenda-tag-filter :preset-filter)
  3678. (org-agenda-filter-apply
  3679. (get 'org-agenda-tag-filter :preset-filter) 'tag t))
  3680. (when org-agenda-category-filter
  3681. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3682. (when (get 'org-agenda-category-filter :preset-filter)
  3683. (org-agenda-filter-apply
  3684. (get 'org-agenda-category-filter :preset-filter) 'category))
  3685. (when org-agenda-regexp-filter
  3686. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3687. (when (get 'org-agenda-regexp-filter :preset-filter)
  3688. (org-agenda-filter-apply
  3689. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3690. (when org-agenda-effort-filter
  3691. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3692. (when (get 'org-agenda-effort-filter :preset-filter)
  3693. (org-agenda-filter-apply
  3694. (get 'org-agenda-effort-filter :preset-filter) 'effort))
  3695. (add-hook 'kill-buffer-hook #'org-agenda-reset-markers 'append 'local))
  3696. (run-hooks 'org-agenda-finalize-hook))))
  3697. (defun org-agenda-mark-clocking-task ()
  3698. "Mark the current clock entry in the agenda if it is present."
  3699. ;; We need to widen when `org-agenda-finalize' is called from
  3700. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in').
  3701. (when (bound-and-true-p org-clock-current-task)
  3702. (save-restriction
  3703. (widen)
  3704. (org-agenda-unmark-clocking-task)
  3705. (when (marker-buffer org-clock-hd-marker)
  3706. (save-excursion
  3707. (goto-char (point-min))
  3708. (let (s ov)
  3709. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3710. (goto-char s)
  3711. (when (equal (org-get-at-bol 'org-hd-marker)
  3712. org-clock-hd-marker)
  3713. (setq ov (make-overlay (line-beginning-position)
  3714. (1+ (line-end-position))))
  3715. (overlay-put ov 'type 'org-agenda-clocking)
  3716. (overlay-put ov 'face 'org-agenda-clocking)
  3717. (overlay-put ov 'help-echo
  3718. "The clock is running in this item")))))))))
  3719. (defun org-agenda-unmark-clocking-task ()
  3720. "Unmark the current clocking task."
  3721. (mapc (lambda (o)
  3722. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  3723. (delete-overlay o)))
  3724. (overlays-in (point-min) (point-max))))
  3725. (defun org-agenda-fontify-priorities ()
  3726. "Make highest priority lines bold, and lowest italic."
  3727. (interactive)
  3728. (mapc (lambda (o) (when (eq (overlay-get o 'org-type) 'org-priority)
  3729. (delete-overlay o)))
  3730. (overlays-in (point-min) (point-max)))
  3731. (save-excursion
  3732. (let (b e p ov h l)
  3733. (goto-char (point-min))
  3734. (while (re-search-forward org-priority-regexp nil t)
  3735. (setq h (or (get-char-property (point) 'org-priority-highest)
  3736. org-priority-highest)
  3737. l (or (get-char-property (point) 'org-priority-lowest)
  3738. org-priority-lowest)
  3739. p (string-to-char (match-string 2))
  3740. b (match-beginning 1)
  3741. e (if (eq org-agenda-fontify-priorities 'cookies)
  3742. (1+ (match-end 2))
  3743. (line-end-position))
  3744. ov (make-overlay b e))
  3745. (overlay-put
  3746. ov 'face
  3747. (let ((special-face
  3748. (cond ((org-face-from-face-or-color
  3749. 'priority 'org-priority
  3750. (cdr (assoc p org-priority-faces))))
  3751. ((and (listp org-agenda-fontify-priorities)
  3752. (org-face-from-face-or-color
  3753. 'priority 'org-priority
  3754. (cdr (assoc p org-agenda-fontify-priorities)))))
  3755. ((equal p l) 'italic)
  3756. ((equal p h) 'bold))))
  3757. (if special-face (list special-face 'org-priority) 'org-priority)))
  3758. (overlay-put ov 'org-type 'org-priority)))))
  3759. (defvar org-depend-tag-blocked)
  3760. (defun org-agenda-dim-blocked-tasks (&optional _invisible)
  3761. "Dim currently blocked TODOs in the agenda display.
  3762. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3763. dimming them." ;FIXME: The arg isn't used, actually!
  3764. (interactive "P")
  3765. (when (called-interactively-p 'interactive)
  3766. (message "Dim or hide blocked tasks..."))
  3767. (dolist (o (overlays-in (point-min) (point-max)))
  3768. (when (eq (overlay-get o 'face) 'org-agenda-dimmed-todo-face)
  3769. (delete-overlay o)))
  3770. (save-excursion
  3771. (let ((inhibit-read-only t))
  3772. (goto-char (point-min))
  3773. (while (let ((pos (text-property-not-all
  3774. (point) (point-max) 'org-todo-blocked nil)))
  3775. (when pos (goto-char pos)))
  3776. (let* ((invisible
  3777. (eq (org-get-at-bol 'org-todo-blocked) 'invisible))
  3778. (todo-blocked
  3779. (eq (org-get-at-bol 'org-filter-type) 'todo-blocked))
  3780. (ov (make-overlay (if invisible
  3781. (line-end-position 0)
  3782. (line-beginning-position))
  3783. (line-end-position))))
  3784. (when todo-blocked
  3785. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3786. (when invisible
  3787. (org-agenda-filter-hide-line 'todo-blocked)))
  3788. (if (= (point-max) (line-end-position))
  3789. (goto-char (point-max))
  3790. (move-beginning-of-line 2)))))
  3791. (when (called-interactively-p 'interactive)
  3792. (message "Dim or hide blocked tasks...done")))
  3793. (defun org-agenda--mark-blocked-entry (entry)
  3794. "If ENTRY is blocked, mark it for fontification or invisibility.
  3795. If the header at `org-hd-marker' is blocked according to
  3796. `org-entry-blocked-p', then if `org-agenda-dim-blocked-tasks' is
  3797. `invisible' and the header is not blocked by checkboxes, set the
  3798. text property `org-todo-blocked' to `invisible', otherwise set it
  3799. to t."
  3800. (when (get-text-property 0 'todo-state entry)
  3801. (let ((entry-marker (get-text-property 0 'org-hd-marker entry))
  3802. (org-blocked-by-checkboxes nil)
  3803. ;; Necessary so that `org-entry-blocked-p' does not change
  3804. ;; the buffer.
  3805. (org-depend-tag-blocked nil))
  3806. (when entry-marker
  3807. (let ((blocked
  3808. (with-current-buffer (marker-buffer entry-marker)
  3809. (save-excursion
  3810. (goto-char entry-marker)
  3811. (org-entry-blocked-p)))))
  3812. (when blocked
  3813. (let ((really-invisible
  3814. (and (not org-blocked-by-checkboxes)
  3815. (eq org-agenda-dim-blocked-tasks 'invisible))))
  3816. (put-text-property
  3817. 0 (length entry) 'org-todo-blocked
  3818. (if really-invisible 'invisible t)
  3819. entry)
  3820. (put-text-property
  3821. 0 (length entry) 'org-filter-type 'todo-blocked entry)))))))
  3822. entry)
  3823. (defvar org-agenda-skip-function nil
  3824. "Function to be called at each match during agenda construction.
  3825. If this function returns nil, the current match should not be skipped.
  3826. Otherwise, the function must return a position from where the search
  3827. should be continued.
  3828. This may also be a Lisp form, it will be evaluated.
  3829. Never set this variable using `setq' or so, because then it will apply
  3830. to all future agenda commands. If you do want a global skipping condition,
  3831. use the option `org-agenda-skip-function-global' instead.
  3832. The correct usage for `org-agenda-skip-function' is to bind it with
  3833. `let' to scope it dynamically into the agenda-constructing command.
  3834. A good way to set it is through options in `org-agenda-custom-commands'.")
  3835. (defun org-agenda-skip (&optional element)
  3836. "Throw to `:skip' in places that should be skipped.
  3837. Also moves point to the end of the skipped region, so that search can
  3838. continue from there.
  3839. Optional argument ELEMENT contains element at point."
  3840. (when (or
  3841. (if element
  3842. (eq (org-element-type element) 'comment)
  3843. (save-excursion
  3844. (goto-char (line-beginning-position))
  3845. (looking-at comment-start-skip)))
  3846. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3847. (or (and (save-match-data (org-in-archived-heading-p nil element))
  3848. (org-end-of-subtree t element))
  3849. (and (member org-archive-tag org-file-tags)
  3850. (goto-char (point-max)))))
  3851. (and org-agenda-skip-comment-trees
  3852. (org-in-commented-heading-p nil element)
  3853. (org-end-of-subtree t element))
  3854. (let ((to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3855. (org-agenda-skip-eval org-agenda-skip-function))))
  3856. (and to (goto-char to)))
  3857. (org-in-src-block-p t element))
  3858. (throw :skip t)))
  3859. (defun org-agenda-skip-eval (form)
  3860. "If FORM is a function or a list, call (or eval) it and return the result.
  3861. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3862. and match data are returned to the previous state no matter what these
  3863. functions do."
  3864. (let (fp)
  3865. (and form
  3866. (or (setq fp (functionp form))
  3867. (consp form))
  3868. (save-excursion
  3869. (save-match-data
  3870. (if fp
  3871. (funcall form)
  3872. (eval form t)))))))
  3873. (defvar org-agenda-markers nil
  3874. "List of all currently active markers created by `org-agenda'.")
  3875. (defvar org-agenda-last-marker-time (float-time)
  3876. "Creation time of the last agenda marker.")
  3877. (defun org-agenda-new-marker (&optional pos)
  3878. "Return a new agenda marker.
  3879. Marker is at point, or at POS if non-nil. Org mode keeps a list
  3880. of these markers and resets them when they are no longer in use."
  3881. (let ((m (copy-marker (or pos (point)) t)))
  3882. (setq org-agenda-last-marker-time (float-time))
  3883. (if org-agenda-buffer
  3884. (with-current-buffer org-agenda-buffer
  3885. (push m org-agenda-markers))
  3886. (push m org-agenda-markers))
  3887. m))
  3888. (defun org-agenda-reset-markers ()
  3889. "Reset markers created by `org-agenda'."
  3890. (while org-agenda-markers
  3891. (move-marker (pop org-agenda-markers) nil)))
  3892. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3893. "Save relative positions of markers in region.
  3894. This check for agenda markers in all agenda buffers currently active."
  3895. (dolist (buf (buffer-list))
  3896. (with-current-buffer buf
  3897. (when (eq major-mode 'org-agenda-mode)
  3898. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3899. org-agenda-markers)))))
  3900. ;;; Entry text mode
  3901. (defun org-agenda-entry-text-show-here ()
  3902. "Add some text from the entry as context to the current line."
  3903. (let (m txt o)
  3904. (setq m (org-get-at-bol 'org-hd-marker))
  3905. (unless (marker-buffer m)
  3906. (error "No marker points to an entry here"))
  3907. (setq txt (concat "\n" (org-no-properties
  3908. (org-agenda-get-some-entry-text
  3909. m org-agenda-entry-text-maxlines
  3910. org-agenda-entry-text-leaders))))
  3911. (when (string-match "\\S-" txt)
  3912. (setq o (make-overlay (line-beginning-position) (line-end-position)))
  3913. (overlay-put o 'evaporate t)
  3914. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3915. (overlay-put o 'after-string txt))))
  3916. (defun org-agenda-entry-text-show ()
  3917. "Add entry context for all agenda lines."
  3918. (interactive)
  3919. (save-excursion
  3920. (goto-char (point-max))
  3921. (beginning-of-line 1)
  3922. (while (not (bobp))
  3923. (when (org-get-at-bol 'org-hd-marker)
  3924. (org-agenda-entry-text-show-here))
  3925. (beginning-of-line 0))))
  3926. (defun org-agenda-entry-text-hide ()
  3927. "Remove any shown entry context."
  3928. (mapc (lambda (o)
  3929. (when (eq (overlay-get o 'org-overlay-type)
  3930. 'agenda-entry-content)
  3931. (delete-overlay o)))
  3932. (overlays-in (point-min) (point-max))))
  3933. (defun org-agenda-get-day-face (date)
  3934. "Return the face DATE should be displayed with."
  3935. (cond ((and (functionp org-agenda-day-face-function)
  3936. (funcall org-agenda-day-face-function date)))
  3937. ((and (org-agenda-today-p date)
  3938. (memq (calendar-day-of-week date) org-agenda-weekend-days))
  3939. 'org-agenda-date-weekend-today)
  3940. ((org-agenda-today-p date) 'org-agenda-date-today)
  3941. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3942. 'org-agenda-date-weekend)
  3943. (t 'org-agenda-date)))
  3944. (defvar org-agenda-show-log-scoped)
  3945. ;;; Agenda Daily/Weekly
  3946. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3947. "Start day for the agenda view.
  3948. Custom commands can set this variable in the options section.
  3949. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3950. input allowed when reading a date through the Org calendar.
  3951. See the docstring of `org-read-date' for details.")
  3952. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3953. (defvar org-arg-loc nil) ; local variable
  3954. ;;;###autoload
  3955. (defun org-agenda-list (&optional arg start-day span with-hour)
  3956. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3957. The view will be for the current day or week, but from the overview buffer
  3958. you will be able to go to other days/weeks.
  3959. With a numeric prefix argument in an interactive call, the agenda will
  3960. span ARG days. Lisp programs should instead specify SPAN to change
  3961. the number of days. SPAN defaults to `org-agenda-span'.
  3962. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3963. given in `org-agenda-start-on-weekday'.
  3964. When WITH-HOUR is non-nil, only include scheduled and deadline
  3965. items if they have an hour specification like [h]h:mm."
  3966. (interactive "P")
  3967. (when org-agenda-overriding-arguments
  3968. (setq arg (car org-agenda-overriding-arguments)
  3969. start-day (nth 1 org-agenda-overriding-arguments)
  3970. span (nth 2 org-agenda-overriding-arguments)))
  3971. (when (and (integerp arg) (> arg 0))
  3972. (setq span arg arg nil))
  3973. (when (numberp span)
  3974. (unless (< 0 span)
  3975. (user-error "Agenda creation impossible for this span(=%d days)" span)))
  3976. (catch 'exit
  3977. (setq org-agenda-buffer-name
  3978. (org-agenda--get-buffer-name
  3979. (and org-agenda-sticky
  3980. (cond ((and org-keys (stringp org-match))
  3981. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3982. (org-keys
  3983. (format "*Org Agenda(%s)*" org-keys))
  3984. (t "*Org Agenda(a)*")))))
  3985. (org-agenda-prepare "Day/Week")
  3986. (setq start-day (or start-day org-agenda-start-day))
  3987. (when (stringp start-day)
  3988. ;; Convert to an absolute day number
  3989. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3990. (org-compile-prefix-format 'agenda)
  3991. (org-set-sorting-strategy 'agenda)
  3992. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
  3993. (today (org-today))
  3994. (sd (or start-day today))
  3995. (ndays (org-agenda-span-to-ndays span sd))
  3996. (org-agenda-start-on-weekday
  3997. (and (or (eq ndays 7) (eq ndays 14))
  3998. org-agenda-start-on-weekday))
  3999. (thefiles (org-agenda-files nil 'ifmode))
  4000. (files thefiles)
  4001. (start (if (or (null org-agenda-start-on-weekday)
  4002. (< ndays 7))
  4003. sd
  4004. (let* ((nt (calendar-day-of-week
  4005. (calendar-gregorian-from-absolute sd)))
  4006. (n1 org-agenda-start-on-weekday)
  4007. (d (- nt n1)))
  4008. (- sd (+ (if (< d 0) 7 0) d)))))
  4009. (day-numbers (list start))
  4010. (day-cnt 0)
  4011. (inhibit-redisplay (not debug-on-error))
  4012. (org-agenda-show-log-scoped org-agenda-show-log)
  4013. s rtn rtnall file date d start-pos end-pos todayp ;; e
  4014. clocktable-start clocktable-end) ;; filter
  4015. (setq org-agenda-redo-command
  4016. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  4017. (dotimes (_ (1- ndays))
  4018. (push (1+ (car day-numbers)) day-numbers))
  4019. (setq day-numbers (nreverse day-numbers))
  4020. (setq clocktable-start (car day-numbers)
  4021. clocktable-end (1+ (or (org-last day-numbers) 0)))
  4022. (setq-local org-starting-day (car day-numbers))
  4023. (setq-local org-arg-loc arg)
  4024. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  4025. (unless org-agenda-compact-blocks
  4026. (let* ((d1 (car day-numbers))
  4027. (d2 (org-last day-numbers))
  4028. (w1 (org-days-to-iso-week d1))
  4029. (w2 (org-days-to-iso-week d2)))
  4030. (setq s (point))
  4031. (org-agenda--insert-overriding-header
  4032. (concat (org-agenda-span-name span)
  4033. "-agenda"
  4034. (cond ((<= 350 (- d2 d1)) "")
  4035. ((= w1 w2) (format " (W%02d)" w1))
  4036. (t (format " (W%02d-W%02d)" w1 w2)))
  4037. ":\n")))
  4038. ;; Add properties if we actually inserted a header.
  4039. (when (> (point) s)
  4040. (add-text-properties s (1- (point))
  4041. (list 'face 'org-agenda-structure
  4042. 'org-date-line t))
  4043. (org-agenda-mark-header-line s)))
  4044. (while (setq d (pop day-numbers))
  4045. (setq date (calendar-gregorian-from-absolute d)
  4046. s (point))
  4047. (if (or (setq todayp (= d today))
  4048. (and (not start-pos) (= d sd)))
  4049. (setq start-pos (point))
  4050. (when (and start-pos (not end-pos))
  4051. (setq end-pos (point))))
  4052. (setq files thefiles
  4053. rtnall nil)
  4054. (while (setq file (pop files))
  4055. (catch 'nextfile
  4056. (org-check-agenda-file file)
  4057. (let ((org-agenda-entry-types org-agenda-entry-types))
  4058. ;; Starred types override non-starred equivalents
  4059. (when (member :deadline* org-agenda-entry-types)
  4060. (setq org-agenda-entry-types
  4061. (delq :deadline org-agenda-entry-types)))
  4062. (when (member :scheduled* org-agenda-entry-types)
  4063. (setq org-agenda-entry-types
  4064. (delq :scheduled org-agenda-entry-types)))
  4065. ;; Honor with-hour
  4066. (when with-hour
  4067. (when (member :deadline org-agenda-entry-types)
  4068. (setq org-agenda-entry-types
  4069. (delq :deadline org-agenda-entry-types))
  4070. (push :deadline* org-agenda-entry-types))
  4071. (when (member :scheduled org-agenda-entry-types)
  4072. (setq org-agenda-entry-types
  4073. (delq :scheduled org-agenda-entry-types))
  4074. (push :scheduled* org-agenda-entry-types)))
  4075. (unless org-agenda-include-deadlines
  4076. (setq org-agenda-entry-types
  4077. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  4078. (cond
  4079. ((memq org-agenda-show-log-scoped '(only clockcheck))
  4080. (setq rtn (org-agenda-get-day-entries
  4081. file date :closed)))
  4082. (org-agenda-show-log-scoped
  4083. (setq rtn (apply #'org-agenda-get-day-entries
  4084. file date
  4085. (append '(:closed) org-agenda-entry-types))))
  4086. (t
  4087. (setq rtn (apply #'org-agenda-get-day-entries
  4088. file date
  4089. org-agenda-entry-types)))))
  4090. (setq rtnall (append rtnall rtn)))) ;; all entries
  4091. (when org-agenda-include-diary
  4092. (let ((org-agenda-search-headline-for-time t))
  4093. (require 'diary-lib)
  4094. (setq rtn (org-get-entries-from-diary date))
  4095. (setq rtnall (append rtnall rtn))))
  4096. (when (or rtnall org-agenda-show-all-dates)
  4097. (setq day-cnt (1+ day-cnt))
  4098. (insert
  4099. (if (stringp org-agenda-format-date)
  4100. (format-time-string org-agenda-format-date
  4101. (org-time-from-absolute date))
  4102. (funcall org-agenda-format-date date))
  4103. "\n")
  4104. (put-text-property s (1- (point)) 'face
  4105. (org-agenda-get-day-face date))
  4106. (put-text-property s (1- (point)) 'org-date-line t)
  4107. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  4108. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  4109. (when todayp
  4110. (put-text-property s (1- (point)) 'org-today t))
  4111. (setq rtnall
  4112. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  4113. (when rtnall (insert ;; all entries
  4114. (org-agenda-finalize-entries rtnall 'agenda)
  4115. "\n"))
  4116. (put-text-property s (1- (point)) 'day d)
  4117. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)))
  4118. (when (and org-agenda-clockreport-mode clocktable-start)
  4119. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  4120. ;; the above line is to ensure the restricted range!
  4121. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  4122. tbl)
  4123. (setq p (org-plist-delete p :block))
  4124. (setq p (plist-put p :tstart clocktable-start))
  4125. (setq p (plist-put p :tend clocktable-end))
  4126. (setq p (plist-put p :scope 'agenda))
  4127. (setq tbl (apply #'org-clock-get-clocktable p))
  4128. (when org-agenda-clock-report-header
  4129. (insert (propertize org-agenda-clock-report-header 'face 'org-agenda-structure))
  4130. (unless (string-suffix-p "\n" org-agenda-clock-report-header)
  4131. (insert "\n")))
  4132. (insert tbl)))
  4133. (goto-char (point-min))
  4134. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4135. (unless (or (not (get-buffer-window org-agenda-buffer-name))
  4136. (and (pos-visible-in-window-p (point-min))
  4137. (pos-visible-in-window-p (point-max))))
  4138. (goto-char (1- (point-max)))
  4139. (recenter -1)
  4140. (when (not (pos-visible-in-window-p (or start-pos 1)))
  4141. (goto-char (or start-pos 1))
  4142. (recenter 1)))
  4143. (goto-char (or start-pos 1))
  4144. (add-text-properties (point-min) (point-max)
  4145. `(org-agenda-type agenda
  4146. org-last-args (,arg ,start-day ,span)
  4147. org-redo-cmd ,org-agenda-redo-command
  4148. org-series-cmd ,org-cmd))
  4149. (when (eq org-agenda-show-log-scoped 'clockcheck)
  4150. (org-agenda-show-clocking-issues))
  4151. (org-agenda-finalize)
  4152. (setq buffer-read-only t)
  4153. (message ""))))
  4154. (defun org-agenda-ndays-to-span (n)
  4155. "Return a span symbol for a span of N days, or N if none matches."
  4156. (cond ((symbolp n) n)
  4157. ((= n 1) 'day)
  4158. ((= n 7) 'week)
  4159. ((= n 14) 'fortnight)
  4160. (t n)))
  4161. (defun org-agenda-span-to-ndays (span &optional start-day)
  4162. "Return ndays from SPAN, possibly starting at START-DAY.
  4163. START-DAY is an absolute time value."
  4164. (cond ((numberp span) span)
  4165. ((eq span 'day) 1)
  4166. ((eq span 'week) 7)
  4167. ((eq span 'fortnight) 14)
  4168. ((eq span 'month)
  4169. (let ((date (calendar-gregorian-from-absolute start-day)))
  4170. (calendar-last-day-of-month (car date) (cl-caddr date))))
  4171. ((eq span 'year)
  4172. (let ((date (calendar-gregorian-from-absolute start-day)))
  4173. (if (calendar-leap-year-p (cl-caddr date)) 366 365)))))
  4174. (defun org-agenda-span-name (span)
  4175. "Return a SPAN name."
  4176. (if (null span)
  4177. ""
  4178. (if (symbolp span)
  4179. (capitalize (symbol-name span))
  4180. (format "%d days" span))))
  4181. ;;; Agenda word search
  4182. (defvar org-agenda-search-history nil)
  4183. (defvar org-search-syntax-table nil
  4184. "Special syntax table for Org search.
  4185. In this table, we have single quotes not as word constituents, to
  4186. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4187. (defvar org-mode-syntax-table) ; From org.el
  4188. (defun org-search-syntax-table ()
  4189. (unless org-search-syntax-table
  4190. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4191. (modify-syntax-entry ?' "." org-search-syntax-table)
  4192. (modify-syntax-entry ?` "." org-search-syntax-table))
  4193. org-search-syntax-table)
  4194. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4195. ;;;###autoload
  4196. (defun org-search-view (&optional todo-only string edit-at)
  4197. "Show all entries that contain a phrase or words or regular expressions.
  4198. With optional prefix argument TODO-ONLY, only consider entries that are
  4199. TODO entries. The argument STRING can be used to pass a default search
  4200. string into this function. If EDIT-AT is non-nil, it means that the
  4201. user should get a chance to edit this string, with cursor at position
  4202. EDIT-AT.
  4203. The search string can be viewed either as a phrase that should be found as
  4204. is, or it can be broken into a number of snippets, each of which must match
  4205. in a Boolean way to select an entry. The default depends on the variable
  4206. `org-agenda-search-view-always-boolean'.
  4207. Even if this is turned off (the default) you can always switch to
  4208. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4209. The default is a direct search of the whole phrase, where each space in
  4210. the search string can expand to an arbitrary amount of whitespace,
  4211. including newlines.
  4212. If using a Boolean search, the search string is split on whitespace and
  4213. each snippet is searched separately, with logical AND to select an entry.
  4214. Words prefixed with a minus must *not* occur in the entry. Words without
  4215. a prefix or prefixed with a plus must occur in the entry. Matching is
  4216. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4217. match whole words, not parts of a word) if
  4218. `org-agenda-search-view-force-full-words' is set (default is nil).
  4219. Boolean search snippets enclosed by curly braces are interpreted as
  4220. regular expressions that must or (when preceded with \"-\") must not
  4221. match in the entry. Snippets enclosed into double quotes will be taken
  4222. as a whole, to include whitespace.
  4223. - If the search string starts with an asterisk, search only in headlines.
  4224. - If (possibly after the leading star) the search string starts with an
  4225. exclamation mark, this also means to look at TODO entries only, an effect
  4226. that can also be achieved with a prefix argument.
  4227. - If (possibly after star and exclamation mark) the search string starts
  4228. with a colon, this will mean that the (non-regexp) snippets of the
  4229. Boolean search must match as full words.
  4230. This command searches the agenda files, and in addition the files
  4231. listed in `org-agenda-text-search-extra-files' unless a restriction lock
  4232. is active."
  4233. (interactive "P")
  4234. (when org-agenda-overriding-arguments
  4235. (setq todo-only (car org-agenda-overriding-arguments)
  4236. string (nth 1 org-agenda-overriding-arguments)
  4237. edit-at (nth 2 org-agenda-overriding-arguments)))
  4238. (let* ((props (list 'face nil
  4239. 'done-face 'org-agenda-done
  4240. 'org-not-done-regexp org-not-done-regexp
  4241. 'org-todo-regexp org-todo-regexp
  4242. 'org-complex-heading-regexp org-complex-heading-regexp
  4243. 'mouse-face 'highlight
  4244. 'help-echo "mouse-2 or RET jump to location"))
  4245. (full-words org-agenda-search-view-force-full-words)
  4246. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4247. regexp rtn rtnall files file pos inherited-tags
  4248. marker category level tags c neg re boolean
  4249. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4250. (unless (and (not edit-at)
  4251. (stringp string)
  4252. (string-match "\\S-" string))
  4253. (setq string (read-string
  4254. (if org-agenda-search-view-always-boolean
  4255. "[+-]Word/{Regexp} ...: "
  4256. "Phrase or [+-]Word/{Regexp} ...: ")
  4257. (cond
  4258. ((integerp edit-at) (cons string edit-at))
  4259. (edit-at string))
  4260. 'org-agenda-search-history)))
  4261. (catch 'exit
  4262. (setq org-agenda-buffer-name
  4263. (org-agenda--get-buffer-name
  4264. (and org-agenda-sticky
  4265. (if (stringp string)
  4266. (format "*Org Agenda(%s:%s)*"
  4267. (or org-keys (or (and todo-only "S") "s"))
  4268. string)
  4269. (format "*Org Agenda(%s)*"
  4270. (or (and todo-only "S") "s"))))))
  4271. (org-agenda-prepare "SEARCH")
  4272. (org-compile-prefix-format 'search)
  4273. (org-set-sorting-strategy 'search)
  4274. (setq org-agenda-redo-command
  4275. (list 'org-search-view (if todo-only t nil)
  4276. (list 'if 'current-prefix-arg nil string)))
  4277. (setq org-agenda-query-string string)
  4278. (if (equal (string-to-char string) ?*)
  4279. (setq hdl-only t
  4280. words (substring string 1))
  4281. (setq words string))
  4282. (when (equal (string-to-char words) ?!)
  4283. (setq todo-only t
  4284. words (substring words 1)))
  4285. (when (equal (string-to-char words) ?:)
  4286. (setq full-words t
  4287. words (substring words 1)))
  4288. (when (or org-agenda-search-view-always-boolean
  4289. (member (string-to-char words) '(?- ?+ ?\{)))
  4290. (setq boolean t))
  4291. (setq words (split-string words))
  4292. (let (www w)
  4293. (while (setq w (pop words))
  4294. (while (and (string-match "\\\\\\'" w) words)
  4295. (setq w (concat (substring w 0 -1) " " (pop words))))
  4296. (push w www))
  4297. (setq words (nreverse www) www nil)
  4298. (while (setq w (pop words))
  4299. (when (and (string-match "\\`[-+]?{" w)
  4300. (not (string-match "}\\'" w)))
  4301. (while (and words (not (string-match "}\\'" (car words))))
  4302. (setq w (concat w " " (pop words))))
  4303. (setq w (concat w " " (pop words))))
  4304. (push w www))
  4305. (setq words (nreverse www)))
  4306. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4307. (when boolean
  4308. (let (wds w)
  4309. (while (setq w (pop words))
  4310. (when (or (equal (substring w 0 1) "\"")
  4311. (and (> (length w) 1)
  4312. (member (substring w 0 1) '("+" "-"))
  4313. (equal (substring w 1 2) "\"")))
  4314. (while (and words (not (equal (substring w -1) "\"")))
  4315. (setq w (concat w " " (pop words)))))
  4316. (and (string-match "\\`\\([-+]?\\)\"" w)
  4317. (setq w (replace-match "\\1" nil nil w)))
  4318. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4319. (push w wds))
  4320. (setq words (nreverse wds))))
  4321. (if boolean
  4322. (mapc (lambda (w)
  4323. (setq c (string-to-char w))
  4324. (if (equal c ?-)
  4325. (setq neg t w (substring w 1))
  4326. (if (equal c ?+)
  4327. (setq neg nil w (substring w 1))
  4328. (setq neg nil)))
  4329. (if (string-match "\\`{.*}\\'" w)
  4330. (setq re (substring w 1 -1))
  4331. (if full-words
  4332. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4333. (setq re (regexp-quote (downcase w)))))
  4334. (if neg (push re regexps-) (push re regexps+)))
  4335. words)
  4336. (push (mapconcat #'regexp-quote words "\\s-+")
  4337. regexps+))
  4338. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4339. (if (not regexps+)
  4340. (setq regexp org-outline-regexp-bol)
  4341. (setq regexp (pop regexps+))
  4342. (when hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4343. regexp))))
  4344. (setq files (org-agenda-files nil 'ifmode))
  4345. ;; Add `org-agenda-text-search-extra-files' unless there is some
  4346. ;; restriction.
  4347. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4348. (pop org-agenda-text-search-extra-files)
  4349. (unless (get 'org-agenda-files 'org-restrict)
  4350. (setq files (org-add-archive-files files))))
  4351. ;; Uniquify files. However, let `org-check-agenda-file' handle
  4352. ;; non-existent ones.
  4353. (setq files (cl-remove-duplicates
  4354. (append files org-agenda-text-search-extra-files)
  4355. :test (lambda (a b)
  4356. (and (file-exists-p a)
  4357. (file-exists-p b)
  4358. (file-equal-p a b))))
  4359. rtnall nil)
  4360. (while (setq file (pop files))
  4361. (setq ee nil)
  4362. (catch 'nextfile
  4363. (org-check-agenda-file file)
  4364. (setq buffer (if (file-exists-p file)
  4365. (org-get-agenda-file-buffer file)
  4366. (error "No such file %s" file)))
  4367. (unless buffer
  4368. ;; If file does not exist, make sure an error message is sent
  4369. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4370. file))))
  4371. (with-current-buffer buffer
  4372. (with-syntax-table (org-search-syntax-table)
  4373. (unless (derived-mode-p 'org-mode)
  4374. (error "Agenda file %s is not in Org mode" file))
  4375. (let ((case-fold-search t))
  4376. (save-excursion
  4377. (save-restriction
  4378. (if (eq buffer org-agenda-restrict)
  4379. (narrow-to-region org-agenda-restrict-begin
  4380. org-agenda-restrict-end)
  4381. (widen))
  4382. (goto-char (point-min))
  4383. (unless (or (org-at-heading-p)
  4384. (outline-next-heading))
  4385. (throw 'nextfile t))
  4386. (goto-char (max (point-min) (1- (point))))
  4387. (while (re-search-forward regexp nil t)
  4388. (org-back-to-heading t)
  4389. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4390. (> (org-reduced-level (org-outline-level))
  4391. org-agenda-search-view-max-outline-level)
  4392. (forward-line -1)
  4393. (org-back-to-heading t)))
  4394. (skip-chars-forward "* ")
  4395. (setq beg (line-beginning-position)
  4396. beg1 (point)
  4397. end (progn
  4398. (outline-next-heading)
  4399. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4400. (> (org-reduced-level (org-outline-level))
  4401. org-agenda-search-view-max-outline-level)
  4402. (forward-line 1)
  4403. (outline-next-heading)))
  4404. (point)))
  4405. (catch :skip
  4406. (goto-char beg)
  4407. (org-agenda-skip)
  4408. (setq str (buffer-substring-no-properties
  4409. (line-beginning-position)
  4410. (if hdl-only (line-end-position) end)))
  4411. (mapc (lambda (wr) (when (string-match wr str)
  4412. (goto-char (1- end))
  4413. (throw :skip t)))
  4414. regexps-)
  4415. (mapc (lambda (wr) (unless (string-match wr str)
  4416. (goto-char (1- end))
  4417. (throw :skip t)))
  4418. (if todo-only
  4419. (cons (concat "^\\*+[ \t]+"
  4420. org-not-done-regexp)
  4421. regexps+)
  4422. regexps+))
  4423. (goto-char beg)
  4424. (setq marker (org-agenda-new-marker (point))
  4425. category (org-get-category)
  4426. level (make-string (org-reduced-level (org-outline-level)) ? )
  4427. inherited-tags
  4428. (or (eq org-agenda-show-inherited-tags 'always)
  4429. (and (listp org-agenda-show-inherited-tags)
  4430. (memq 'todo org-agenda-show-inherited-tags))
  4431. (and (eq org-agenda-show-inherited-tags t)
  4432. (or (eq org-agenda-use-tag-inheritance t)
  4433. (memq 'todo org-agenda-use-tag-inheritance))))
  4434. tags (org-get-tags nil (not inherited-tags))
  4435. txt (org-agenda-format-item
  4436. ""
  4437. (buffer-substring-no-properties
  4438. beg1 (line-end-position))
  4439. level category tags t))
  4440. (org-add-props txt props
  4441. 'org-marker marker 'org-hd-marker marker
  4442. 'org-todo-regexp org-todo-regexp
  4443. 'level level
  4444. 'org-complex-heading-regexp org-complex-heading-regexp
  4445. 'priority 1000
  4446. 'type "search")
  4447. (push txt ee)
  4448. (goto-char (1- end))))))))))
  4449. (setq rtn (nreverse ee))
  4450. (setq rtnall (append rtnall rtn)))
  4451. (org-agenda--insert-overriding-header
  4452. (with-temp-buffer
  4453. (insert "Search words: ")
  4454. (add-text-properties (point-min) (1- (point))
  4455. (list 'face 'org-agenda-structure))
  4456. (setq pos (point))
  4457. (insert string "\n")
  4458. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4459. (setq pos (point))
  4460. (unless org-agenda-multi
  4461. (insert (substitute-command-keys "\\<org-agenda-mode-map>\
  4462. Press `\\[org-agenda-manipulate-query-add]', \
  4463. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4464. `\\[org-agenda-manipulate-query-add-re]', \
  4465. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4466. `\\[universal-argument] \\[org-agenda-redo]' for a fresh search\n"))
  4467. (add-text-properties pos (1- (point))
  4468. (list 'face 'org-agenda-structure-secondary)))
  4469. (buffer-string)))
  4470. (org-agenda-mark-header-line (point-min))
  4471. (when rtnall
  4472. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4473. (goto-char (point-min))
  4474. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4475. (add-text-properties (point-min) (point-max)
  4476. `(org-agenda-type search
  4477. org-last-args (,todo-only ,string ,edit-at)
  4478. org-redo-cmd ,org-agenda-redo-command
  4479. org-series-cmd ,org-cmd))
  4480. (org-agenda-finalize)
  4481. (setq buffer-read-only t))))
  4482. ;;; Agenda TODO list
  4483. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4484. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4485. (concat
  4486. (if (or (equal keywords "ALL") (not keywords))
  4487. (propertize "ALL" 'face 'org-agenda-structure-filter)
  4488. (mapconcat
  4489. (lambda (kw)
  4490. (propertize kw 'face (list (org-get-todo-face kw) 'org-agenda-structure)))
  4491. (org-split-string keywords "|")
  4492. "|"))
  4493. "\n"))
  4494. (defvar org-select-this-todo-keyword nil)
  4495. (defvar org-last-arg nil)
  4496. (defvar crm-separator)
  4497. ;;;###autoload
  4498. (defun org-todo-list (&optional arg)
  4499. "Show all (not done) TODO entries from all agenda files in a single list.
  4500. The prefix arg can be used to select a specific TODO keyword and limit
  4501. the list to these. When using `\\[universal-argument]', you will be prompted
  4502. for a keyword. A numeric prefix directly selects the Nth keyword in
  4503. `org-todo-keywords-1'."
  4504. (interactive "P")
  4505. (when org-agenda-overriding-arguments
  4506. (setq arg org-agenda-overriding-arguments))
  4507. (when (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4508. (let* ((today (org-today))
  4509. (date (calendar-gregorian-from-absolute today))
  4510. (completion-ignore-case t)
  4511. kwds org-select-this-todo-keyword rtn rtnall files file pos)
  4512. (catch 'exit
  4513. (setq org-agenda-buffer-name
  4514. (org-agenda--get-buffer-name
  4515. (and org-agenda-sticky
  4516. (if (stringp org-select-this-todo-keyword)
  4517. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4518. org-select-this-todo-keyword)
  4519. (format "*Org Agenda(%s)*" (or org-keys "t"))))))
  4520. (org-agenda-prepare "TODO")
  4521. (setq kwds org-todo-keywords-for-agenda
  4522. org-select-this-todo-keyword (if (stringp arg) arg
  4523. (and (integerp arg)
  4524. (> arg 0)
  4525. (nth (1- arg) kwds))))
  4526. (when (equal arg '(4))
  4527. (setq org-select-this-todo-keyword
  4528. (mapconcat #'identity
  4529. (let ((crm-separator "|"))
  4530. (completing-read-multiple
  4531. "Keyword (or KWD1|KWD2|...): "
  4532. (mapcar #'list kwds) nil nil))
  4533. "|")))
  4534. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4535. (org-compile-prefix-format 'todo)
  4536. (org-set-sorting-strategy 'todo)
  4537. (setq org-agenda-redo-command
  4538. `(org-todo-list (or (and (numberp current-prefix-arg)
  4539. current-prefix-arg)
  4540. ,org-select-this-todo-keyword
  4541. current-prefix-arg ,arg)))
  4542. (setq files (org-agenda-files nil 'ifmode)
  4543. rtnall nil)
  4544. (while (setq file (pop files))
  4545. (catch 'nextfile
  4546. (org-check-agenda-file file)
  4547. (setq rtn (org-agenda-get-day-entries file date :todo))
  4548. (setq rtnall (append rtnall rtn))))
  4549. (org-agenda--insert-overriding-header
  4550. (with-temp-buffer
  4551. (insert "Global list of TODO items of type: ")
  4552. (add-text-properties (point-min) (1- (point))
  4553. (list 'face 'org-agenda-structure
  4554. 'short-heading
  4555. (concat "ToDo: "
  4556. (or org-select-this-todo-keyword "ALL"))))
  4557. (org-agenda-mark-header-line (point-min))
  4558. (insert (org-agenda-propertize-selected-todo-keywords
  4559. org-select-this-todo-keyword))
  4560. (setq pos (point))
  4561. (unless org-agenda-multi
  4562. (insert (substitute-command-keys "Press \
  4563. \\<org-agenda-mode-map>`N \\[org-agenda-redo]' (e.g. `0 \\[org-agenda-redo]') \
  4564. to search again: (0)[ALL]"))
  4565. (let ((n 0))
  4566. (dolist (k kwds)
  4567. (let ((s (format "(%d)%s" (cl-incf n) k)))
  4568. (when (> (+ (current-column) (string-width s) 1) (window-max-chars-per-line))
  4569. (insert "\n "))
  4570. (insert " " s))))
  4571. (insert "\n"))
  4572. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-secondary))
  4573. (buffer-string)))
  4574. (org-agenda-mark-header-line (point-min))
  4575. (when rtnall
  4576. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4577. (goto-char (point-min))
  4578. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4579. (add-text-properties (point-min) (point-max)
  4580. `(org-agenda-type todo
  4581. org-last-args ,arg
  4582. org-redo-cmd ,org-agenda-redo-command
  4583. org-series-cmd ,org-cmd))
  4584. (org-agenda-finalize)
  4585. (setq buffer-read-only t))))
  4586. ;;; Agenda tags match
  4587. ;;;###autoload
  4588. (defun org-tags-view (&optional todo-only match)
  4589. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4590. The prefix arg TODO-ONLY limits the search to TODO entries."
  4591. (interactive "P")
  4592. (when org-agenda-overriding-arguments
  4593. (setq todo-only (car org-agenda-overriding-arguments)
  4594. match (nth 1 org-agenda-overriding-arguments)))
  4595. (let* ((org-tags-match-list-sublevels
  4596. org-tags-match-list-sublevels)
  4597. (completion-ignore-case t)
  4598. (org--matcher-tags-todo-only todo-only)
  4599. rtn rtnall files file pos matcher
  4600. buffer)
  4601. (when (and (stringp match) (not (string-match "\\S-" match)))
  4602. (setq match nil))
  4603. (catch 'exit
  4604. (setq org-agenda-buffer-name
  4605. (org-agenda--get-buffer-name
  4606. (and org-agenda-sticky
  4607. (if (stringp match)
  4608. (format "*Org Agenda(%s:%s)*"
  4609. (or org-keys (or (and todo-only "M") "m"))
  4610. match)
  4611. (format "*Org Agenda(%s)*"
  4612. (or (and todo-only "M") "m"))))))
  4613. (setq matcher (org-make-tags-matcher match))
  4614. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4615. ;; expanding tags within `org-make-tags-matcher'
  4616. (org-agenda-prepare (concat "TAGS " match))
  4617. (setq match (car matcher)
  4618. matcher (cdr matcher))
  4619. (org-compile-prefix-format 'tags)
  4620. (org-set-sorting-strategy 'tags)
  4621. (setq org-agenda-query-string match)
  4622. (setq org-agenda-redo-command
  4623. (list 'org-tags-view
  4624. `(quote ,org--matcher-tags-todo-only)
  4625. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4626. (setq files (org-agenda-files nil 'ifmode)
  4627. rtnall nil)
  4628. (while (setq file (pop files))
  4629. (catch 'nextfile
  4630. (org-check-agenda-file file)
  4631. (setq buffer (if (file-exists-p file)
  4632. (org-get-agenda-file-buffer file)
  4633. (error "No such file %s" file)))
  4634. (if (not buffer)
  4635. ;; If file does not exist, error message to agenda
  4636. (setq rtn (list
  4637. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4638. rtnall (append rtnall rtn))
  4639. (with-current-buffer buffer
  4640. (unless (derived-mode-p 'org-mode)
  4641. (error "Agenda file %s is not in Org mode" file))
  4642. (save-excursion
  4643. (save-restriction
  4644. (if (eq buffer org-agenda-restrict)
  4645. (narrow-to-region org-agenda-restrict-begin
  4646. org-agenda-restrict-end)
  4647. (widen))
  4648. (setq rtn (org-scan-tags 'agenda
  4649. matcher
  4650. org--matcher-tags-todo-only))
  4651. (setq rtnall (append rtnall rtn))))))))
  4652. (org-agenda--insert-overriding-header
  4653. (with-temp-buffer
  4654. (insert "Headlines with TAGS match: ")
  4655. (add-text-properties (point-min) (1- (point))
  4656. (list 'face 'org-agenda-structure
  4657. 'short-heading
  4658. (concat "Match: " match)))
  4659. (setq pos (point))
  4660. (insert match "\n")
  4661. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4662. (setq pos (point))
  4663. (unless org-agenda-multi
  4664. (insert (substitute-command-keys
  4665. "Press \
  4666. \\<org-agenda-mode-map>`\\[universal-argument] \\[org-agenda-redo]' \
  4667. to search again\n")))
  4668. (add-text-properties pos (1- (point))
  4669. (list 'face 'org-agenda-structure-secondary))
  4670. (buffer-string)))
  4671. (org-agenda-mark-header-line (point-min))
  4672. (when rtnall
  4673. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4674. (goto-char (point-min))
  4675. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4676. (add-text-properties
  4677. (point-min) (point-max)
  4678. `(org-agenda-type tags
  4679. org-last-args (,org--matcher-tags-todo-only ,match)
  4680. org-redo-cmd ,org-agenda-redo-command
  4681. org-series-cmd ,org-cmd))
  4682. (org-agenda-finalize)
  4683. (setq buffer-read-only t))))
  4684. ;;; Agenda Finding stuck projects
  4685. (defvar org-agenda-skip-regexp nil
  4686. "Regular expression used in skipping subtrees for the agenda.
  4687. This is basically a temporary global variable that can be set and then
  4688. used by user-defined selections using `org-agenda-skip-function'.")
  4689. (defvar org-agenda-overriding-header nil
  4690. "When set during agenda, todo and tags searches it replaces the header.
  4691. If an empty string, no header will be inserted. If any other
  4692. string, it will be inserted as a header. If a function, insert
  4693. the string returned by the function as a header. If nil, a
  4694. header will be generated automatically according to the command.
  4695. This variable should not be set directly, but custom commands can
  4696. bind it in the options section.")
  4697. (defun org-agenda-skip-entry-if (&rest conditions)
  4698. "Skip entry if any of CONDITIONS is true.
  4699. See `org-agenda-skip-if' for details."
  4700. (org-agenda-skip-if nil conditions))
  4701. (defun org-agenda-skip-subtree-if (&rest conditions)
  4702. "Skip subtree if any of CONDITIONS is true.
  4703. See `org-agenda-skip-if' for details."
  4704. (org-agenda-skip-if t conditions))
  4705. (defun org-agenda-skip-if (subtree conditions)
  4706. "Check current entity for CONDITIONS.
  4707. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4708. the entry (i.e. the text before the next heading) is checked.
  4709. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4710. from different tests. Valid conditions are:
  4711. scheduled Check if there is a scheduled cookie
  4712. notscheduled Check if there is no scheduled cookie
  4713. deadline Check if there is a deadline
  4714. notdeadline Check if there is no deadline
  4715. timestamp Check if there is a timestamp (also deadline or scheduled)
  4716. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4717. regexp Check if regexp matches
  4718. notregexp Check if regexp does not match.
  4719. todo Check if TODO keyword matches
  4720. nottodo Check if TODO keyword does not match
  4721. The regexp is taken from the conditions list, it must come right after
  4722. the `regexp' or `notregexp' element.
  4723. `todo' and `nottodo' accept as an argument a list of todo
  4724. keywords, which may include \"*\" to match any todo keyword.
  4725. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4726. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4727. Instead of a list, a keyword class may be given. For example:
  4728. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4729. would skip entries that haven't been marked with any of \"DONE\"
  4730. keywords. Possible classes are: `todo', `done', `any'.
  4731. If any of these conditions is met, this function returns the end point of
  4732. the entity, causing the search to continue from there. This is a function
  4733. that can be put into `org-agenda-skip-function' for the duration of a command."
  4734. (org-back-to-heading t)
  4735. (let* (;; (beg (point))
  4736. (end (if subtree (save-excursion (org-end-of-subtree t) (point))
  4737. (org-entry-end-position)))
  4738. (planning-end (if subtree end (line-end-position 2)))
  4739. m)
  4740. (and
  4741. (or (and (memq 'scheduled conditions)
  4742. (re-search-forward org-scheduled-time-regexp planning-end t))
  4743. (and (memq 'notscheduled conditions)
  4744. (not
  4745. (save-excursion
  4746. (re-search-forward org-scheduled-time-regexp planning-end t))))
  4747. (and (memq 'deadline conditions)
  4748. (re-search-forward org-deadline-time-regexp planning-end t))
  4749. (and (memq 'notdeadline conditions)
  4750. (not
  4751. (save-excursion
  4752. (re-search-forward org-deadline-time-regexp planning-end t))))
  4753. (and (memq 'timestamp conditions)
  4754. (re-search-forward org-ts-regexp end t))
  4755. (and (memq 'nottimestamp conditions)
  4756. (not (save-excursion (re-search-forward org-ts-regexp end t))))
  4757. (and (setq m (memq 'regexp conditions))
  4758. (stringp (nth 1 m))
  4759. (re-search-forward (nth 1 m) end t))
  4760. (and (setq m (memq 'notregexp conditions))
  4761. (stringp (nth 1 m))
  4762. (not (save-excursion (re-search-forward (nth 1 m) end t))))
  4763. (and (or
  4764. (setq m (memq 'nottodo conditions))
  4765. (setq m (memq 'todo-unblocked conditions))
  4766. (setq m (memq 'nottodo-unblocked conditions))
  4767. (setq m (memq 'todo conditions)))
  4768. (org-agenda-skip-if-todo m end)))
  4769. end)))
  4770. (defun org-agenda-skip-if-todo (args end)
  4771. "Helper function for `org-agenda-skip-if', do not use it directly.
  4772. ARGS is a list with first element either `todo', `nottodo',
  4773. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4774. a list of TODO keywords, or a state symbol `todo' or `done' or
  4775. `any'."
  4776. (let ((todo-re
  4777. (concat "^\\*+[ \t]+"
  4778. (regexp-opt
  4779. (pcase args
  4780. (`(,_ todo)
  4781. (org-delete-all org-done-keywords
  4782. (copy-sequence org-todo-keywords-1)))
  4783. (`(,_ done) org-done-keywords)
  4784. (`(,_ any) org-todo-keywords-1)
  4785. (`(,_ ,(pred atom))
  4786. (error "Invalid TODO class or type: %S" args))
  4787. (`(,_ ,(pred (member "*"))) org-todo-keywords-1)
  4788. (`(,_ ,todo-list) todo-list))
  4789. 'words))))
  4790. (pcase args
  4791. (`(todo . ,_)
  4792. (let (case-fold-search) (re-search-forward todo-re end t)))
  4793. (`(nottodo . ,_)
  4794. (not (let (case-fold-search) (re-search-forward todo-re end t))))
  4795. (`(todo-unblocked . ,_)
  4796. (catch :unblocked
  4797. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4798. (when (org-entry-blocked-p) (throw :unblocked t)))
  4799. nil))
  4800. (`(nottodo-unblocked . ,_)
  4801. (catch :unblocked
  4802. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4803. (when (org-entry-blocked-p) (throw :unblocked nil)))
  4804. t))
  4805. (`(,type . ,_) (error "Unknown TODO skip type: %S" type)))))
  4806. ;;;###autoload
  4807. (defun org-agenda-list-stuck-projects (&rest _ignore)
  4808. "Create agenda view for projects that are stuck.
  4809. Stuck projects are project that have no next actions. For the definitions
  4810. of what a project is and how to check if it stuck, customize the variable
  4811. `org-stuck-projects'."
  4812. (interactive)
  4813. (let* ((org-agenda-overriding-header
  4814. (or org-agenda-overriding-header "List of stuck projects: "))
  4815. (matcher (nth 0 org-stuck-projects))
  4816. (todo (nth 1 org-stuck-projects))
  4817. (tags (nth 2 org-stuck-projects))
  4818. (gen-re (org-string-nw-p (nth 3 org-stuck-projects)))
  4819. (todo-wds
  4820. (if (not (member "*" todo)) todo
  4821. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  4822. (org-delete-all org-done-keywords-for-agenda
  4823. (copy-sequence org-todo-keywords-for-agenda))))
  4824. (todo-re (and todo
  4825. (format "^\\*+[ \t]+\\(%s\\)\\>"
  4826. (mapconcat #'identity todo-wds "\\|"))))
  4827. (tags-re (cond ((null tags) nil)
  4828. ((member "*" tags) org-tag-line-re)
  4829. (tags
  4830. (let ((other-tags (format "\\(?:%s:\\)*" org-tag-re)))
  4831. (concat org-outline-regexp-bol
  4832. ".*?[ \t]:"
  4833. other-tags
  4834. (regexp-opt tags t)
  4835. ":" other-tags "[ \t]*$")))
  4836. (t nil)))
  4837. (re-list (delq nil (list todo-re tags-re gen-re)))
  4838. (skip-re
  4839. (if (null re-list)
  4840. (error "Missing information to identify unstuck projects")
  4841. (mapconcat #'identity re-list "\\|")))
  4842. (org-agenda-skip-function
  4843. ;; Skip entry if `org-agenda-skip-regexp' matches anywhere
  4844. ;; in the subtree.
  4845. (lambda ()
  4846. (and (save-excursion
  4847. (let ((case-fold-search nil))
  4848. (re-search-forward
  4849. skip-re (save-excursion (org-end-of-subtree t)) t)))
  4850. (progn (outline-next-heading) (point))))))
  4851. (org-tags-view nil matcher)
  4852. (setq org-agenda-buffer-name (buffer-name))
  4853. (with-current-buffer org-agenda-buffer-name
  4854. (setq org-agenda-redo-command
  4855. `(org-agenda-list-stuck-projects ,current-prefix-arg))
  4856. (let ((inhibit-read-only t))
  4857. (add-text-properties
  4858. (point-min) (point-max)
  4859. `(org-redo-cmd ,org-agenda-redo-command))))))
  4860. ;;; Diary integration
  4861. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4862. (defvar diary-list-entries-hook)
  4863. (defvar diary-time-regexp)
  4864. (defvar diary-modify-entry-list-string-function)
  4865. (defvar diary-file-name-prefix)
  4866. (defvar diary-display-function)
  4867. (defun org-get-entries-from-diary (date)
  4868. "Get the (Emacs Calendar) diary entries for DATE."
  4869. (require 'diary-lib)
  4870. (declare-function diary-fancy-display "diary-lib" ())
  4871. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4872. (diary-display-function #'diary-fancy-display)
  4873. (pop-up-frames nil)
  4874. (diary-list-entries-hook
  4875. (cons 'org-diary-default-entry diary-list-entries-hook))
  4876. (diary-file-name-prefix nil) ; turn this feature off
  4877. (diary-modify-entry-list-string-function
  4878. #'org-modify-diary-entry-string)
  4879. (diary-time-regexp (concat "^" diary-time-regexp))
  4880. entries
  4881. (org-disable-agenda-to-diary t))
  4882. (save-excursion
  4883. (save-window-excursion
  4884. (diary-list-entries date 1)))
  4885. (if (not (get-buffer diary-fancy-buffer))
  4886. (setq entries nil)
  4887. (with-current-buffer diary-fancy-buffer
  4888. (setq buffer-read-only nil)
  4889. (if (zerop (buffer-size))
  4890. ;; No entries
  4891. (setq entries nil)
  4892. ;; Omit the date and other unnecessary stuff
  4893. (org-agenda-cleanup-fancy-diary)
  4894. ;; Add prefix to each line and extend the text properties
  4895. (if (zerop (buffer-size))
  4896. (setq entries nil)
  4897. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4898. (setq entries
  4899. (with-temp-buffer
  4900. (insert entries) (goto-char (point-min))
  4901. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4902. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4903. (replace-match (concat "; " (match-string 1)))))
  4904. (buffer-string)))))
  4905. (set-buffer-modified-p nil)
  4906. (kill-buffer diary-fancy-buffer)))
  4907. (when entries
  4908. (setq entries (org-split-string entries "\n"))
  4909. (setq entries
  4910. (mapcar
  4911. (lambda (x)
  4912. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4913. ;; Extend the text properties to the beginning of the line
  4914. (org-add-props x (text-properties-at (1- (length x)) x)
  4915. 'type "diary" 'date date 'face 'org-agenda-diary))
  4916. entries)))))
  4917. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4918. "Hook run when the fancy diary buffer is cleaned up.")
  4919. (defun org-agenda-cleanup-fancy-diary ()
  4920. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4921. This gets rid of the date, the underline under the date, and the
  4922. dummy entry installed by Org mode to ensure non-empty diary for
  4923. each date. It also removes lines that contain only whitespace."
  4924. (goto-char (point-min))
  4925. (if (looking-at ".*?:[ \t]*")
  4926. (progn
  4927. (replace-match "")
  4928. (re-search-forward "\n=+$" nil t)
  4929. (replace-match "")
  4930. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4931. (re-search-forward "\n=+$" nil t)
  4932. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4933. (goto-char (point-min))
  4934. (while (re-search-forward "^ +\n" nil t)
  4935. (replace-match ""))
  4936. (goto-char (point-min))
  4937. (when (re-search-forward "^Org mode dummy\n?" nil t)
  4938. (replace-match ""))
  4939. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4940. (defun org-modify-diary-entry-string (string)
  4941. "Add text properties to string, allowing Org to act on it."
  4942. (org-add-props string nil
  4943. 'mouse-face 'highlight
  4944. 'help-echo (if buffer-file-name
  4945. (format "mouse-2 or RET jump to diary file %s"
  4946. (abbreviate-file-name buffer-file-name))
  4947. "")
  4948. 'org-agenda-diary-link t
  4949. 'org-marker (org-agenda-new-marker (line-beginning-position))))
  4950. (defun org-diary-default-entry ()
  4951. "Add a dummy entry to the diary.
  4952. Needed to avoid empty dates which mess up holiday display."
  4953. ;; Catch the error if dealing with the new add-to-diary-alist
  4954. (when org-disable-agenda-to-diary
  4955. (diary-add-to-list original-date "Org mode dummy" "")))
  4956. (defvar org-diary-last-run-time nil)
  4957. ;;;###autoload
  4958. (defun org-diary (&rest args)
  4959. "Return diary information from org files.
  4960. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4961. It accesses org files and extracts information from those files to be
  4962. listed in the diary. The function accepts arguments specifying what
  4963. items should be listed. For a list of arguments allowed here, see the
  4964. variable `org-agenda-entry-types'.
  4965. The call in the diary file should look like this:
  4966. &%%(org-diary) ~/path/to/some/orgfile.org
  4967. Use a separate line for each org file to check. Or, if you omit the file name,
  4968. all files listed in `org-agenda-files' will be checked automatically:
  4969. &%%(org-diary)
  4970. If you don't give any arguments (as in the example above), the default value
  4971. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4972. So the example above may also be written as
  4973. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4974. The function expects the lisp variables `entry' and `date' to be provided
  4975. by the caller, because this is how the calendar works. Don't use this
  4976. function from a program - use `org-agenda-get-day-entries' instead."
  4977. (with-no-warnings (defvar date) (defvar entry))
  4978. (when (> (- (float-time)
  4979. org-agenda-last-marker-time)
  4980. 5)
  4981. ;; I am not sure if this works with sticky agendas, because the marker
  4982. ;; list is then no longer a global variable.
  4983. (org-agenda-reset-markers))
  4984. (org-compile-prefix-format 'agenda)
  4985. (org-set-sorting-strategy 'agenda)
  4986. (setq args (or args org-agenda-entry-types))
  4987. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4988. (list entry)
  4989. (org-agenda-files t)))
  4990. (time (float-time))
  4991. file rtn results)
  4992. (when (or (not org-diary-last-run-time)
  4993. (> (- time
  4994. org-diary-last-run-time)
  4995. 3))
  4996. (org-agenda-prepare-buffers files))
  4997. (setq org-diary-last-run-time time)
  4998. ;; If this is called during org-agenda, don't return any entries to
  4999. ;; the calendar. Org Agenda will list these entries itself.
  5000. (when org-disable-agenda-to-diary (setq files nil))
  5001. (while (setq file (pop files))
  5002. (setq rtn (apply #'org-agenda-get-day-entries file date args))
  5003. (setq results (append results rtn)))
  5004. (when results
  5005. (setq results
  5006. (mapcar (lambda (i) (replace-regexp-in-string
  5007. org-link-bracket-re "\\2" i))
  5008. results))
  5009. (concat (org-agenda-finalize-entries results) "\n"))))
  5010. ;;; Agenda entry finders
  5011. (defun org-agenda--timestamp-to-absolute (&rest args)
  5012. "Call `org-time-string-to-absolute' with ARGS.
  5013. However, throw `:skip' whenever an error is raised."
  5014. (condition-case e
  5015. (apply #'org-time-string-to-absolute args)
  5016. (org-diary-sexp-no-match (throw :skip nil))
  5017. (error
  5018. (message "%s; Skipping entry" (error-message-string e))
  5019. (throw :skip nil))))
  5020. (defun org-agenda-get-day-entries (file date &rest args)
  5021. "Does the work for `org-diary' and `org-agenda'.
  5022. FILE is the path to a file to be checked for entries. DATE is date like
  5023. the one returned by `calendar-current-date'. ARGS are symbols indicating
  5024. which kind of entries should be extracted. For details about these, see
  5025. the documentation of `org-diary'."
  5026. (let* ((org-startup-folded nil)
  5027. (org-startup-align-all-tables nil)
  5028. (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
  5029. (error "No such file %s" file))))
  5030. (if (not buffer)
  5031. ;; If file does not exist, signal it in diary nonetheless.
  5032. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  5033. (with-current-buffer buffer
  5034. (unless (derived-mode-p 'org-mode)
  5035. (error "Agenda file %s is not in Org mode" file))
  5036. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  5037. (setf org-agenda-current-date date)
  5038. (save-excursion
  5039. (save-restriction
  5040. (if (eq buffer org-agenda-restrict)
  5041. (narrow-to-region org-agenda-restrict-begin
  5042. org-agenda-restrict-end)
  5043. (widen))
  5044. ;; Rationalize ARGS. Also make sure `:deadline' comes
  5045. ;; first in order to populate DEADLINES before passing it.
  5046. ;;
  5047. ;; We use `delq' since `org-uniquify' duplicates ARGS,
  5048. ;; guarding us from modifying `org-agenda-entry-types'.
  5049. (setf args (org-uniquify (or args org-agenda-entry-types)))
  5050. (when (and (memq :scheduled args) (memq :scheduled* args))
  5051. (setf args (delq :scheduled* args)))
  5052. (cond
  5053. ((memq :deadline args)
  5054. (setf args (cons :deadline
  5055. (delq :deadline (delq :deadline* args)))))
  5056. ((memq :deadline* args)
  5057. (setf args (cons :deadline* (delq :deadline* args)))))
  5058. ;; Collect list of headlines. Return them flattened.
  5059. (let ((case-fold-search nil) results deadlines)
  5060. (org-dlet
  5061. ((date date))
  5062. (dolist (arg args (apply #'nconc (nreverse results)))
  5063. (pcase arg
  5064. ((and :todo (guard (org-agenda-today-p date)))
  5065. (push (org-agenda-get-todos) results))
  5066. (:timestamp
  5067. (push (org-agenda-get-blocks) results)
  5068. (push (org-agenda-get-timestamps deadlines) results))
  5069. (:sexp
  5070. (push (org-agenda-get-sexps) results))
  5071. (:scheduled
  5072. (push (org-agenda-get-scheduled deadlines) results))
  5073. (:scheduled*
  5074. (push (org-agenda-get-scheduled deadlines t) results))
  5075. (:closed
  5076. (push (org-agenda-get-progress) results))
  5077. (:deadline
  5078. (setf deadlines (org-agenda-get-deadlines))
  5079. (push deadlines results))
  5080. (:deadline*
  5081. (setf deadlines (org-agenda-get-deadlines t))
  5082. (push deadlines results))))))))))))
  5083. (defsubst org-em (x y list)
  5084. "Is X or Y a member of LIST?"
  5085. (or (memq x list) (memq y list)))
  5086. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  5087. (defvar org-agenda-sorting-strategy-selected nil)
  5088. (defun org-agenda-entry-get-agenda-timestamp (pom)
  5089. "Retrieve timestamp information for sorting agenda views.
  5090. Given a point or marker POM, returns a cons cell of the timestamp
  5091. and the timestamp type relevant for the sorting strategy in
  5092. `org-agenda-sorting-strategy-selected'."
  5093. (let (ts ts-date-type)
  5094. (save-match-data
  5095. (cond ((org-em 'scheduled-up 'scheduled-down
  5096. org-agenda-sorting-strategy-selected)
  5097. (setq ts (org-entry-get pom "SCHEDULED")
  5098. ts-date-type " scheduled"))
  5099. ((org-em 'deadline-up 'deadline-down
  5100. org-agenda-sorting-strategy-selected)
  5101. (setq ts (org-entry-get pom "DEADLINE")
  5102. ts-date-type " deadline"))
  5103. ((org-em 'ts-up 'ts-down
  5104. org-agenda-sorting-strategy-selected)
  5105. (setq ts (org-entry-get pom "TIMESTAMP")
  5106. ts-date-type " timestamp"))
  5107. ((org-em 'tsia-up 'tsia-down
  5108. org-agenda-sorting-strategy-selected)
  5109. (setq ts (org-entry-get pom "TIMESTAMP_IA")
  5110. ts-date-type " timestamp_ia"))
  5111. ((org-em 'timestamp-up 'timestamp-down
  5112. org-agenda-sorting-strategy-selected)
  5113. (setq ts (or (org-entry-get pom "SCHEDULED")
  5114. (org-entry-get pom "DEADLINE")
  5115. (org-entry-get pom "TIMESTAMP")
  5116. (org-entry-get pom "TIMESTAMP_IA"))
  5117. ts-date-type ""))
  5118. (t (setq ts-date-type "")))
  5119. (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
  5120. ts-date-type))))
  5121. (defun org-agenda-get-todos ()
  5122. "Return the TODO information for agenda display."
  5123. (let* ((props (list 'face nil
  5124. 'done-face 'org-agenda-done
  5125. 'org-not-done-regexp org-not-done-regexp
  5126. 'org-todo-regexp org-todo-regexp
  5127. 'org-complex-heading-regexp org-complex-heading-regexp
  5128. 'mouse-face 'highlight
  5129. 'help-echo
  5130. (format "mouse-2 or RET jump to org file %s"
  5131. (abbreviate-file-name buffer-file-name))))
  5132. (case-fold-search nil)
  5133. (regexp (format org-heading-keyword-regexp-format
  5134. (cond
  5135. ((and org-select-this-todo-keyword
  5136. (equal org-select-this-todo-keyword "*"))
  5137. org-todo-regexp)
  5138. (org-select-this-todo-keyword
  5139. (concat "\\("
  5140. (mapconcat #'identity
  5141. (org-split-string
  5142. org-select-this-todo-keyword
  5143. "|")
  5144. "\\|")
  5145. "\\)"))
  5146. (t org-not-done-regexp))))
  5147. marker priority category level tags todo-state
  5148. ts-date ts-date-type ts-date-pair
  5149. ee txt beg end inherited-tags todo-state-end-pos
  5150. effort effort-minutes)
  5151. (goto-char (point-min))
  5152. (while (re-search-forward regexp nil t)
  5153. (catch :skip
  5154. (save-match-data
  5155. (beginning-of-line)
  5156. (org-agenda-skip)
  5157. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  5158. (unless (and (setq todo-state (org-get-todo-state))
  5159. (setq todo-state-end-pos (match-end 2)))
  5160. (goto-char end)
  5161. (throw :skip nil))
  5162. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  5163. (goto-char (1+ beg))
  5164. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  5165. (throw :skip nil)))
  5166. (goto-char (match-beginning 2))
  5167. (setq marker (org-agenda-new-marker (match-beginning 0))
  5168. category (org-get-category)
  5169. effort (save-match-data (or (get-text-property (point) 'effort)
  5170. (org-entry-get (point) org-effort-property)))
  5171. effort-minutes (when effort (save-match-data (org-duration-to-minutes effort)))
  5172. ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
  5173. ts-date (car ts-date-pair)
  5174. ts-date-type (cdr ts-date-pair)
  5175. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  5176. inherited-tags
  5177. (or (eq org-agenda-show-inherited-tags 'always)
  5178. (and (listp org-agenda-show-inherited-tags)
  5179. (memq 'todo org-agenda-show-inherited-tags))
  5180. (and (eq org-agenda-show-inherited-tags t)
  5181. (or (eq org-agenda-use-tag-inheritance t)
  5182. (memq 'todo org-agenda-use-tag-inheritance))))
  5183. tags (org-get-tags nil (not inherited-tags))
  5184. level (make-string (org-reduced-level (org-outline-level)) ? )
  5185. txt (org-agenda-format-item ""
  5186. (org-add-props txt nil
  5187. 'effort effort
  5188. 'effort-minutes effort-minutes)
  5189. level category tags t)
  5190. priority (1+ (org-get-priority txt)))
  5191. (org-add-props txt props
  5192. 'org-marker marker 'org-hd-marker marker
  5193. 'priority priority
  5194. 'effort effort 'effort-minutes effort-minutes
  5195. 'level level
  5196. 'ts-date ts-date
  5197. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  5198. (push txt ee)
  5199. (if org-agenda-todo-list-sublevels
  5200. (goto-char todo-state-end-pos)
  5201. (org-end-of-subtree 'invisible))))
  5202. (nreverse ee)))
  5203. (defun org-agenda-todo-custom-ignore-p (time n)
  5204. "Check whether timestamp is farther away than n number of days.
  5205. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5206. `org-agenda-todo-ignore-scheduled' or
  5207. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5208. (let ((days (org-time-stamp-to-now
  5209. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5210. (if (>= n 0)
  5211. (>= days n)
  5212. (<= days n))))
  5213. ;;;###autoload
  5214. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5215. (&optional end)
  5216. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5217. (when (or org-agenda-todo-ignore-with-date
  5218. org-agenda-todo-ignore-scheduled
  5219. org-agenda-todo-ignore-deadlines
  5220. org-agenda-todo-ignore-timestamp)
  5221. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5222. (save-excursion
  5223. (or (and org-agenda-todo-ignore-with-date
  5224. (re-search-forward org-ts-regexp end t))
  5225. (and org-agenda-todo-ignore-scheduled
  5226. (re-search-forward org-scheduled-time-regexp end t)
  5227. (cond
  5228. ((eq org-agenda-todo-ignore-scheduled 'future)
  5229. (> (org-time-stamp-to-now
  5230. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5231. 0))
  5232. ((eq org-agenda-todo-ignore-scheduled 'past)
  5233. (<= (org-time-stamp-to-now
  5234. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5235. 0))
  5236. ((numberp org-agenda-todo-ignore-scheduled)
  5237. (org-agenda-todo-custom-ignore-p
  5238. (match-string 1) org-agenda-todo-ignore-scheduled))
  5239. (t)))
  5240. (and org-agenda-todo-ignore-deadlines
  5241. (re-search-forward org-deadline-time-regexp end t)
  5242. (cond
  5243. ((eq org-agenda-todo-ignore-deadlines 'all) t)
  5244. ((eq org-agenda-todo-ignore-deadlines 'far)
  5245. (not (org-deadline-close-p (match-string 1))))
  5246. ((eq org-agenda-todo-ignore-deadlines 'future)
  5247. (> (org-time-stamp-to-now
  5248. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5249. 0))
  5250. ((eq org-agenda-todo-ignore-deadlines 'past)
  5251. (<= (org-time-stamp-to-now
  5252. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5253. 0))
  5254. ((numberp org-agenda-todo-ignore-deadlines)
  5255. (org-agenda-todo-custom-ignore-p
  5256. (match-string 1) org-agenda-todo-ignore-deadlines))
  5257. (t (org-deadline-close-p (match-string 1)))))
  5258. (and org-agenda-todo-ignore-timestamp
  5259. (let ((buffer (current-buffer))
  5260. (regexp
  5261. (concat
  5262. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5263. (start (point)))
  5264. ;; Copy current buffer into a temporary one
  5265. (with-temp-buffer
  5266. (insert-buffer-substring buffer start end)
  5267. (goto-char (point-min))
  5268. ;; Delete SCHEDULED and DEADLINE items
  5269. (while (re-search-forward regexp end t)
  5270. (delete-region (match-beginning 0) (match-end 0)))
  5271. (goto-char (point-min))
  5272. ;; No search for timestamp left
  5273. (when (re-search-forward org-ts-regexp nil t)
  5274. (cond
  5275. ((eq org-agenda-todo-ignore-timestamp 'future)
  5276. (> (org-time-stamp-to-now
  5277. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5278. 0))
  5279. ((eq org-agenda-todo-ignore-timestamp 'past)
  5280. (<= (org-time-stamp-to-now
  5281. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5282. 0))
  5283. ((numberp org-agenda-todo-ignore-timestamp)
  5284. (org-agenda-todo-custom-ignore-p
  5285. (match-string 1) org-agenda-todo-ignore-timestamp))
  5286. (t))))))))))
  5287. (defun org-agenda-get-timestamps (&optional deadlines)
  5288. "Return the date stamp information for agenda display.
  5289. Optional argument DEADLINES is a list of deadline items to be
  5290. displayed in agenda view."
  5291. (with-no-warnings (defvar date))
  5292. (let* ((props (list 'face 'org-agenda-calendar-event
  5293. 'org-not-done-regexp org-not-done-regexp
  5294. 'org-todo-regexp org-todo-regexp
  5295. 'org-complex-heading-regexp org-complex-heading-regexp
  5296. 'mouse-face 'highlight
  5297. 'help-echo
  5298. (format "mouse-2 or RET jump to Org file %s"
  5299. (abbreviate-file-name buffer-file-name))))
  5300. (current (calendar-absolute-from-gregorian date))
  5301. (today (org-today))
  5302. (deadline-position-alist
  5303. (mapcar (lambda (d)
  5304. (let ((m (get-text-property 0 'org-hd-marker d)))
  5305. (and m (marker-position m))))
  5306. deadlines))
  5307. ;; Match time-stamps set to current date, time-stamps with
  5308. ;; a repeater, and S-exp time-stamps.
  5309. (regexp
  5310. (concat
  5311. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5312. (regexp-quote
  5313. (substring
  5314. (format-time-string
  5315. (car org-time-stamp-formats)
  5316. (org-encode-time ; DATE bound by calendar
  5317. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5318. 1 11))
  5319. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5320. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5321. timestamp-items)
  5322. (goto-char (point-min))
  5323. (while (re-search-forward regexp nil t)
  5324. ;; Skip date ranges, scheduled and deadlines, which are handled
  5325. ;; specially. Also skip time-stamps before first headline as
  5326. ;; there would be no entry to add to the agenda. Eventually,
  5327. ;; ignore clock entries.
  5328. (catch :skip
  5329. (save-match-data
  5330. (when (or (org-at-date-range-p)
  5331. (org-at-planning-p)
  5332. (org-before-first-heading-p)
  5333. (and org-agenda-include-inactive-timestamps
  5334. (org-at-clock-log-p))
  5335. (not (org-at-timestamp-p 'agenda)))
  5336. (throw :skip nil))
  5337. (org-agenda-skip (org-element-at-point)))
  5338. (let* ((pos (match-beginning 0))
  5339. (repeat (match-string 1))
  5340. (sexp-entry (match-string 3))
  5341. (time-stamp (if (or repeat sexp-entry) (match-string 0)
  5342. (save-excursion
  5343. (goto-char pos)
  5344. (looking-at org-ts-regexp-both)
  5345. (match-string 0))))
  5346. (todo-state (org-get-todo-state))
  5347. (warntime (get-text-property (point) 'org-appt-warntime))
  5348. (done? (member todo-state org-done-keywords)))
  5349. ;; Possibly skip done tasks.
  5350. (when (and done? org-agenda-skip-timestamp-if-done)
  5351. (throw :skip t))
  5352. ;; S-exp entry doesn't match current day: skip it.
  5353. (when (and sexp-entry (not (org-diary-sexp-entry sexp-entry "" date)))
  5354. (throw :skip nil))
  5355. (when repeat
  5356. (let* ((past
  5357. ;; A repeating time stamp is shown at its base
  5358. ;; date and every repeated date up to TODAY. If
  5359. ;; `org-agenda-prefer-last-repeat' is non-nil,
  5360. ;; however, only the last repeat before today
  5361. ;; (inclusive) is shown.
  5362. (org-agenda--timestamp-to-absolute
  5363. repeat
  5364. (if (or (> current today)
  5365. (eq org-agenda-prefer-last-repeat t)
  5366. (member todo-state org-agenda-prefer-last-repeat))
  5367. today
  5368. current)
  5369. 'past (current-buffer) pos))
  5370. (future
  5371. ;; Display every repeated date past TODAY
  5372. ;; (exclusive) unless
  5373. ;; `org-agenda-show-future-repeats' is nil. If
  5374. ;; this variable is set to `next', only display
  5375. ;; the first repeated date after TODAY
  5376. ;; (exclusive).
  5377. (cond
  5378. ((<= current today) past)
  5379. ((not org-agenda-show-future-repeats) past)
  5380. (t
  5381. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5382. (1+ today)
  5383. current)))
  5384. (org-agenda--timestamp-to-absolute
  5385. repeat base 'future (current-buffer) pos))))))
  5386. (when (and (/= current past) (/= current future))
  5387. (throw :skip nil))))
  5388. (save-excursion
  5389. (re-search-backward org-outline-regexp-bol nil t)
  5390. ;; Possibly skip time-stamp when a deadline is set.
  5391. (when (and org-agenda-skip-timestamp-if-deadline-is-shown
  5392. (assq (point) deadline-position-alist))
  5393. (throw :skip nil))
  5394. (let* ((category (org-get-category pos))
  5395. (effort (org-entry-get pos org-effort-property))
  5396. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5397. (inherited-tags
  5398. (or (eq org-agenda-show-inherited-tags 'always)
  5399. (and (consp org-agenda-show-inherited-tags)
  5400. (memq 'agenda org-agenda-show-inherited-tags))
  5401. (and (eq org-agenda-show-inherited-tags t)
  5402. (or (eq org-agenda-use-tag-inheritance t)
  5403. (memq 'agenda
  5404. org-agenda-use-tag-inheritance)))))
  5405. (tags (org-get-tags nil (not inherited-tags)))
  5406. (level (make-string (org-reduced-level (org-outline-level))
  5407. ?\s))
  5408. (head (and (looking-at "\\*+[ \t]+\\(.*\\)")
  5409. (match-string 1)))
  5410. (inactive? (= (char-after pos) ?\[))
  5411. (habit? (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5412. (item
  5413. (org-agenda-format-item
  5414. (and inactive? org-agenda-inactive-leader)
  5415. (org-add-props head nil
  5416. 'effort effort
  5417. 'effort-minutes effort-minutes)
  5418. level category tags time-stamp org-ts-regexp habit?)))
  5419. (org-add-props item props
  5420. 'priority (if habit?
  5421. (org-habit-get-priority (org-habit-parse-todo))
  5422. (org-get-priority item))
  5423. 'org-marker (org-agenda-new-marker pos)
  5424. 'org-hd-marker (org-agenda-new-marker)
  5425. 'date date
  5426. 'level level
  5427. 'effort effort 'effort-minutes effort-minutes
  5428. 'ts-date (if repeat (org-agenda--timestamp-to-absolute repeat)
  5429. current)
  5430. 'todo-state todo-state
  5431. 'warntime warntime
  5432. 'type "timestamp")
  5433. (push item timestamp-items))))
  5434. (when org-agenda-skip-additional-timestamps-same-entry
  5435. (outline-next-heading))))
  5436. (nreverse timestamp-items)))
  5437. (defun org-agenda-get-sexps ()
  5438. "Return the sexp information for agenda display."
  5439. (require 'diary-lib)
  5440. (with-no-warnings (defvar date) (defvar entry))
  5441. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5442. 'mouse-face 'highlight
  5443. 'help-echo
  5444. (format "mouse-2 or RET jump to org file %s"
  5445. (abbreviate-file-name buffer-file-name))))
  5446. (regexp "^&?%%(")
  5447. ;; FIXME: Is this `entry' binding intended to be dynamic,
  5448. ;; so as to "hide" any current binding for it?
  5449. marker category extra level ee txt tags entry
  5450. result beg b sexp sexp-entry todo-state warntime inherited-tags
  5451. effort effort-minutes)
  5452. (goto-char (point-min))
  5453. (while (re-search-forward regexp nil t)
  5454. (catch :skip
  5455. ;; We do not run `org-agenda-skip' righ away because every single sexp
  5456. ;; in the buffer is matched here, unlike day-specific search
  5457. ;; in ordinary timestamps. Most of the sexps will not match
  5458. ;; the agenda day and it is quicker to run `org-agenda-skip' only for
  5459. ;; matching sexps later on.
  5460. (setq beg (match-beginning 0))
  5461. (goto-char (1- (match-end 0)))
  5462. (setq b (point))
  5463. (forward-sexp 1)
  5464. (setq sexp (buffer-substring b (point)))
  5465. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5466. (buffer-substring
  5467. (match-beginning 1)
  5468. (save-excursion
  5469. (goto-char (match-end 1))
  5470. (skip-chars-backward "[:blank:]")
  5471. (point)))
  5472. ""))
  5473. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5474. (when result
  5475. ;; Only check if entry should be skipped on matching sexps.
  5476. (org-agenda-skip (org-element-at-point))
  5477. (setq marker (org-agenda-new-marker beg)
  5478. level (make-string (org-reduced-level (org-outline-level)) ? )
  5479. category (org-get-category beg)
  5480. effort (save-match-data (or (get-text-property (point) 'effort)
  5481. (org-entry-get (point) org-effort-property)))
  5482. inherited-tags
  5483. (or (eq org-agenda-show-inherited-tags 'always)
  5484. (and (listp org-agenda-show-inherited-tags)
  5485. (memq 'agenda org-agenda-show-inherited-tags))
  5486. (and (eq org-agenda-show-inherited-tags t)
  5487. (or (eq org-agenda-use-tag-inheritance t)
  5488. (memq 'agenda org-agenda-use-tag-inheritance))))
  5489. tags (org-get-tags nil (not inherited-tags))
  5490. todo-state (org-get-todo-state)
  5491. warntime (get-text-property (point) 'org-appt-warntime)
  5492. extra nil)
  5493. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5494. (dolist (r (if (stringp result)
  5495. (list result)
  5496. result)) ;; we expect a list here
  5497. (when (and org-agenda-diary-sexp-prefix
  5498. (string-match org-agenda-diary-sexp-prefix r))
  5499. (setq extra (match-string 0 r)
  5500. r (replace-match "" nil nil r)))
  5501. (if (string-match "\\S-" r)
  5502. (setq txt r)
  5503. (setq txt "SEXP entry returned empty string"))
  5504. (setq txt (org-agenda-format-item extra
  5505. (org-add-props txt nil
  5506. 'effort effort
  5507. 'effort-minutes effort-minutes)
  5508. level category tags 'time))
  5509. (org-add-props txt props 'org-marker marker
  5510. 'date date 'todo-state todo-state
  5511. 'effort effort 'effort-minutes effort-minutes
  5512. 'level level 'type "sexp" 'warntime warntime)
  5513. (push txt ee)))))
  5514. (nreverse ee)))
  5515. ;; Calendar sanity: define some functions that are independent of
  5516. ;; `calendar-date-style'.
  5517. (defun org-anniversary (year month day &optional mark)
  5518. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5519. (with-no-warnings
  5520. (let ((calendar-date-style 'iso))
  5521. (diary-anniversary year month day mark))))
  5522. (defun org-cyclic (N year month day &optional mark)
  5523. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5524. (with-no-warnings
  5525. (let ((calendar-date-style 'iso))
  5526. (diary-cyclic N year month day mark))))
  5527. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5528. "Like `diary-block', but with fixed (ISO) order of arguments."
  5529. (with-no-warnings
  5530. (let ((calendar-date-style 'iso))
  5531. (diary-block Y1 M1 D1 Y2 M2 D2 mark))))
  5532. (defun org-date (year month day &optional mark)
  5533. "Like `diary-date', but with fixed (ISO) order of arguments."
  5534. (with-no-warnings
  5535. (let ((calendar-date-style 'iso))
  5536. (diary-date year month day mark))))
  5537. ;; Define the `org-class' function
  5538. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5539. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5540. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5541. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5542. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5543. `holidays', then any date that is known by the Emacs calendar to be a
  5544. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5545. then those holidays will be skipped."
  5546. (with-no-warnings (defvar date) (defvar entry))
  5547. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5548. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5549. (d (calendar-absolute-from-gregorian date))
  5550. (h (when skip-weeks (calendar-check-holidays date))))
  5551. (and
  5552. (<= date1 d)
  5553. (<= d date2)
  5554. (= (calendar-day-of-week date) dayname)
  5555. (or (not skip-weeks)
  5556. (progn
  5557. (require 'cal-iso)
  5558. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5559. (not (or (and h (memq 'holidays skip-weeks))
  5560. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5561. entry)))
  5562. (defalias 'org-get-closed #'org-agenda-get-progress)
  5563. (defun org-agenda-get-progress ()
  5564. "Return the logged TODO entries for agenda display."
  5565. (with-no-warnings (defvar date))
  5566. (let* ((props (list 'mouse-face 'highlight
  5567. 'org-not-done-regexp org-not-done-regexp
  5568. 'org-todo-regexp org-todo-regexp
  5569. 'org-complex-heading-regexp org-complex-heading-regexp
  5570. 'help-echo
  5571. (format "mouse-2 or RET jump to org file %s"
  5572. (abbreviate-file-name buffer-file-name))))
  5573. (items (if (consp org-agenda-show-log-scoped)
  5574. org-agenda-show-log-scoped
  5575. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5576. '(clock)
  5577. org-agenda-log-mode-items)))
  5578. (parts
  5579. (delq nil
  5580. (list
  5581. (when (memq 'closed items) (concat "\\<" org-closed-string))
  5582. (when (memq 'clock items) (concat "\\<" org-clock-string))
  5583. (when (memq 'state items)
  5584. (format "- +State \"%s\".*?" org-todo-regexp)))))
  5585. (parts-re (if parts (mapconcat #'identity parts "\\|")
  5586. (error "`org-agenda-log-mode-items' is empty")))
  5587. (regexp (concat
  5588. "\\(" parts-re "\\)"
  5589. " *\\["
  5590. (regexp-quote
  5591. (substring
  5592. (format-time-string
  5593. (car org-time-stamp-formats)
  5594. (org-encode-time ; DATE bound by calendar
  5595. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5596. 1 11))))
  5597. (org-agenda-search-headline-for-time nil)
  5598. marker hdmarker priority category level tags closedp type
  5599. statep clockp state ee txt extra timestr rest clocked inherited-tags
  5600. effort effort-minutes)
  5601. (goto-char (point-min))
  5602. (while (re-search-forward regexp nil t)
  5603. (catch :skip
  5604. (org-agenda-skip)
  5605. (setq marker (org-agenda-new-marker (match-beginning 0))
  5606. closedp (equal (match-string 1) org-closed-string)
  5607. statep (equal (string-to-char (match-string 1)) ?-)
  5608. clockp (not (or closedp statep))
  5609. state (and statep (match-string 2))
  5610. category (org-get-category (match-beginning 0))
  5611. timestr (buffer-substring (match-beginning 0) (line-end-position))
  5612. effort (save-match-data (or (get-text-property (point) 'effort)
  5613. (org-entry-get (point) org-effort-property))))
  5614. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5615. (when (string-match "\\]" timestr)
  5616. ;; substring should only run to end of time stamp
  5617. (setq rest (substring timestr (match-end 0))
  5618. timestr (substring timestr 0 (match-end 0)))
  5619. (if (and (not closedp) (not statep)
  5620. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5621. rest))
  5622. (progn (setq timestr (concat (substring timestr 0 -1)
  5623. "-" (match-string 1 rest) "]"))
  5624. (setq clocked (match-string 2 rest)))
  5625. (setq clocked "-")))
  5626. (save-excursion
  5627. (setq extra
  5628. (cond
  5629. ((not org-agenda-log-mode-add-notes) nil)
  5630. (statep
  5631. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5632. (match-string 1)))
  5633. (clockp
  5634. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5635. (match-string 1)))))
  5636. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5637. (throw :skip nil)
  5638. (goto-char (match-beginning 0))
  5639. (setq hdmarker (org-agenda-new-marker)
  5640. inherited-tags
  5641. (or (eq org-agenda-show-inherited-tags 'always)
  5642. (and (listp org-agenda-show-inherited-tags)
  5643. (memq 'todo org-agenda-show-inherited-tags))
  5644. (and (eq org-agenda-show-inherited-tags t)
  5645. (or (eq org-agenda-use-tag-inheritance t)
  5646. (memq 'todo org-agenda-use-tag-inheritance))))
  5647. tags (org-get-tags nil (not inherited-tags))
  5648. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5649. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5650. (setq txt (match-string 1))
  5651. (when extra
  5652. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5653. (setq txt (concat (substring txt 0 (match-beginning 1))
  5654. " - " extra " " (match-string 2 txt)))
  5655. (setq txt (concat txt " - " extra))))
  5656. (setq txt (org-agenda-format-item
  5657. (cond
  5658. (closedp "Closed: ")
  5659. (statep (concat "State: (" state ")"))
  5660. (t (concat "Clocked: (" clocked ")")))
  5661. (org-add-props txt nil
  5662. 'effort effort
  5663. 'effort-minutes effort-minutes)
  5664. level category tags timestr)))
  5665. (setq type (cond (closedp "closed")
  5666. (statep "state")
  5667. (t "clock")))
  5668. (setq priority 100000)
  5669. (org-add-props txt props
  5670. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5671. 'priority priority 'level level
  5672. 'effort effort 'effort-minutes effort-minutes
  5673. 'type type 'date date
  5674. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5675. (push txt ee))
  5676. (goto-char (line-end-position))))
  5677. (nreverse ee)))
  5678. (defun org-agenda-show-clocking-issues ()
  5679. "Add overlays, showing issues with clocking.
  5680. See also the user option `org-agenda-clock-consistency-checks'."
  5681. (interactive)
  5682. (let* ((pl org-agenda-clock-consistency-checks)
  5683. (re (concat "^[ \t]*"
  5684. org-clock-string
  5685. "[ \t]+"
  5686. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5687. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5688. (tlstart 0.)
  5689. (tlend 0.)
  5690. (maxtime (org-duration-to-minutes
  5691. (or (plist-get pl :max-duration) "24:00")))
  5692. (mintime (org-duration-to-minutes
  5693. (or (plist-get pl :min-duration) 0)))
  5694. (maxgap (org-duration-to-minutes
  5695. ;; default 30:00 means never complain
  5696. (or (plist-get pl :max-gap) "30:00")))
  5697. (gapok (mapcar #'org-duration-to-minutes
  5698. (plist-get pl :gap-ok-around)))
  5699. (def-face (or (plist-get pl :default-face)
  5700. '((:background "DarkRed") (:foreground "white"))))
  5701. issue face m te ts dt ov)
  5702. (goto-char (point-min))
  5703. (while (re-search-forward " Clocked: +(\\(?:-\\|\\([0-9]+:[0-9]+\\)\\))" nil t)
  5704. (setq issue nil face def-face)
  5705. (catch 'next
  5706. (setq m (org-get-at-bol 'org-marker)
  5707. te nil ts nil)
  5708. (unless (and m (markerp m))
  5709. (setq issue "No valid clock line") (throw 'next t))
  5710. (org-with-point-at m
  5711. (save-excursion
  5712. (goto-char (line-beginning-position))
  5713. (unless (looking-at re)
  5714. (error "No valid Clock line")
  5715. (throw 'next t))
  5716. (unless (match-end 3)
  5717. (setq issue
  5718. (format
  5719. "No end time: (%s)"
  5720. (org-duration-from-minutes
  5721. (floor
  5722. (- (float-time (org-current-time))
  5723. (float-time (org-time-string-to-time (match-string 1))))
  5724. 60)))
  5725. face (or (plist-get pl :no-end-time-face) face))
  5726. (throw 'next t))
  5727. (setq ts (match-string 1)
  5728. te (match-string 3)
  5729. ts (float-time (org-time-string-to-time ts))
  5730. te (float-time (org-time-string-to-time te))
  5731. dt (- te ts))))
  5732. (cond
  5733. ((> dt (* 60 maxtime))
  5734. ;; a very long clocking chunk
  5735. (setq issue (format "Clocking interval is very long: %s"
  5736. (org-duration-from-minutes (floor dt 60)))
  5737. face (or (plist-get pl :long-face) face)))
  5738. ((< dt (* 60 mintime))
  5739. ;; a very short clocking chunk
  5740. (setq issue (format "Clocking interval is very short: %s"
  5741. (org-duration-from-minutes (floor dt 60)))
  5742. face (or (plist-get pl :short-face) face)))
  5743. ((and (> tlend 0) (< ts tlend))
  5744. ;; Two clock entries are overlapping
  5745. (setq issue (format "Clocking overlap: %d minutes"
  5746. (/ (- tlend ts) 60))
  5747. face (or (plist-get pl :overlap-face) face)))
  5748. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5749. ;; There is a gap, lets see if we need to report it
  5750. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5751. (setq issue (format "Clocking gap: %d minutes"
  5752. (/ (- ts tlend) 60))
  5753. face (or (plist-get pl :gap-face) face))))
  5754. (t nil)))
  5755. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5756. (when issue
  5757. ;; OK, there was some issue, add an overlay to show the issue
  5758. (setq ov (make-overlay (line-beginning-position) (line-end-position)))
  5759. (overlay-put ov 'before-string
  5760. (concat
  5761. (org-add-props
  5762. (format "%-43s" (concat " " issue))
  5763. nil
  5764. 'face face)
  5765. "\n"))
  5766. (overlay-put ov 'evaporate t)))))
  5767. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5768. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5769. (catch 'exit
  5770. (unless ok-list
  5771. ;; there are no OK times for gaps...
  5772. (throw 'exit nil))
  5773. (when (> (- (/ t2 36000) (/ t1 36000)) 24)
  5774. ;; This is more than 24 hours, so it is OK.
  5775. ;; because we have at least one OK time, that must be in the
  5776. ;; 24 hour interval.
  5777. (throw 'exit t))
  5778. ;; We have a shorter gap.
  5779. ;; Now we have to get the minute of the day when these times are
  5780. (let* ((t1dec (decode-time t1))
  5781. (t2dec (decode-time t2))
  5782. ;; compute the minute on the day
  5783. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5784. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5785. (when (< min2 min1)
  5786. ;; if min2 is smaller than min1, this means it is on the next day.
  5787. ;; Wrap it to after midnight.
  5788. (setq min2 (+ min2 1440)))
  5789. ;; Now check if any of the OK times is in the gap
  5790. (mapc (lambda (x)
  5791. ;; Wrap the time to after midnight if necessary
  5792. (when (< x min1) (setq x (+ x 1440)))
  5793. ;; Check if in interval
  5794. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5795. ok-list)
  5796. ;; Nope, this gap is not OK
  5797. nil)))
  5798. (defun org-agenda-get-deadlines (&optional with-hour)
  5799. "Return the deadline information for agenda display.
  5800. When WITH-HOUR is non-nil, only return deadlines with an hour
  5801. specification like [h]h:mm."
  5802. (with-no-warnings (defvar date))
  5803. (let* ((props (list 'mouse-face 'highlight
  5804. 'org-not-done-regexp org-not-done-regexp
  5805. 'org-todo-regexp org-todo-regexp
  5806. 'org-complex-heading-regexp org-complex-heading-regexp
  5807. 'help-echo
  5808. (format "mouse-2 or RET jump to org file %s"
  5809. (abbreviate-file-name buffer-file-name))))
  5810. (regexp (if with-hour
  5811. org-deadline-time-hour-regexp
  5812. org-deadline-time-regexp))
  5813. (today (org-today))
  5814. (today? (org-agenda-today-p date)) ; DATE bound by calendar.
  5815. (current (calendar-absolute-from-gregorian date))
  5816. deadline-items)
  5817. (goto-char (point-min))
  5818. (if (org-element--cache-active-p)
  5819. (org-element-cache-map
  5820. (lambda (el)
  5821. (when (and (org-element-property :deadline el)
  5822. (or (not with-hour)
  5823. (org-element-property
  5824. :hour-start
  5825. (org-element-property :deadline el))
  5826. (org-element-property
  5827. :hour-end
  5828. (org-element-property :deadline el))))
  5829. (goto-char (org-element-property :contents-begin el))
  5830. (catch :skip
  5831. (org-agenda-skip el)
  5832. (let* ((s (substring (org-element-property
  5833. :raw-value
  5834. (org-element-property :deadline el))
  5835. 1 -1))
  5836. (pos (save-excursion
  5837. (goto-char (org-element-property :contents-begin el))
  5838. ;; We intentionally leave NOERROR
  5839. ;; argument in `re-search-forward' nil. If
  5840. ;; the search fails here, something went
  5841. ;; wrong and we are looking at
  5842. ;; non-matching headline.
  5843. (re-search-forward regexp (line-end-position))
  5844. (1- (match-beginning 1))))
  5845. (todo-state (org-element-property :todo-keyword el))
  5846. (done? (eq 'done (org-element-property :todo-type el)))
  5847. (sexp? (eq 'diary
  5848. (org-element-property
  5849. :type (org-element-property :deadline el))))
  5850. ;; DEADLINE is the deadline date for the entry. It is
  5851. ;; either the base date or the last repeat, according
  5852. ;; to `org-agenda-prefer-last-repeat'.
  5853. (deadline
  5854. (cond
  5855. (sexp? (org-agenda--timestamp-to-absolute s current))
  5856. ((or (eq org-agenda-prefer-last-repeat t)
  5857. (member todo-state org-agenda-prefer-last-repeat))
  5858. (org-agenda--timestamp-to-absolute
  5859. s today 'past (current-buffer) pos))
  5860. (t (org-agenda--timestamp-to-absolute s))))
  5861. ;; REPEAT is the future repeat closest from CURRENT,
  5862. ;; according to `org-agenda-show-future-repeats'. If
  5863. ;; the latter is nil, or if the time stamp has no
  5864. ;; repeat part, default to DEADLINE.
  5865. (repeat
  5866. (cond
  5867. (sexp? deadline)
  5868. ((<= current today) deadline)
  5869. ((not org-agenda-show-future-repeats) deadline)
  5870. (t
  5871. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5872. (1+ today)
  5873. current)))
  5874. (org-agenda--timestamp-to-absolute
  5875. s base 'future (current-buffer) pos)))))
  5876. (diff (- deadline current))
  5877. (suppress-prewarning
  5878. (let ((scheduled
  5879. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5880. (org-element-property
  5881. :raw-value
  5882. (org-element-property :scheduled el)))))
  5883. (cond
  5884. ((not scheduled) nil)
  5885. ;; The current item has a scheduled date, so
  5886. ;; evaluate its prewarning lead time.
  5887. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5888. ;; Use global prewarning-restart lead time.
  5889. org-agenda-skip-deadline-prewarning-if-scheduled)
  5890. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5891. 'pre-scheduled)
  5892. ;; Set pre-warning to no earlier than SCHEDULED.
  5893. (min (- deadline
  5894. (org-agenda--timestamp-to-absolute scheduled))
  5895. org-deadline-warning-days))
  5896. ;; Set pre-warning to deadline.
  5897. (t 0))))
  5898. (wdays (or suppress-prewarning (org-get-wdays s))))
  5899. (cond
  5900. ;; Only display deadlines at their base date, at future
  5901. ;; repeat occurrences or in today agenda.
  5902. ((= current deadline) nil)
  5903. ((= current repeat) nil)
  5904. ((not today?) (throw :skip nil))
  5905. ;; Upcoming deadline: display within warning period WDAYS.
  5906. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  5907. ;; Overdue deadline: warn about it for
  5908. ;; `org-deadline-past-days' duration.
  5909. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  5910. ;; Possibly skip done tasks.
  5911. (when (and done?
  5912. (or org-agenda-skip-deadline-if-done
  5913. (/= deadline current)))
  5914. (throw :skip nil))
  5915. (save-excursion
  5916. (goto-char (org-element-property :begin el))
  5917. (let* ((category (org-get-category))
  5918. (effort (save-match-data (or (get-text-property (point) 'effort)
  5919. (org-element-property (intern (concat ":" (upcase org-effort-property))) el))))
  5920. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5921. (level (make-string (org-element-property :level el)
  5922. ?\s))
  5923. (head (save-excursion
  5924. (goto-char (org-element-property :begin el))
  5925. (re-search-forward org-outline-regexp-bol)
  5926. (buffer-substring-no-properties (point) (line-end-position))))
  5927. (inherited-tags
  5928. (or (eq org-agenda-show-inherited-tags 'always)
  5929. (and (listp org-agenda-show-inherited-tags)
  5930. (memq 'agenda org-agenda-show-inherited-tags))
  5931. (and (eq org-agenda-show-inherited-tags t)
  5932. (or (eq org-agenda-use-tag-inheritance t)
  5933. (memq 'agenda
  5934. org-agenda-use-tag-inheritance)))))
  5935. (tags (org-get-tags el (not inherited-tags)))
  5936. (time
  5937. (cond
  5938. ;; No time of day designation if it is only
  5939. ;; a reminder.
  5940. ((and (/= current deadline) (/= current repeat)) nil)
  5941. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5942. (concat (substring s (match-beginning 1)) " "))
  5943. (t 'time)))
  5944. (item
  5945. (org-agenda-format-item
  5946. ;; Insert appropriate suffixes before deadlines.
  5947. ;; Those only apply to today agenda.
  5948. (pcase-let ((`(,now ,future ,past)
  5949. org-agenda-deadline-leaders))
  5950. (cond
  5951. ((and today? (< deadline today)) (format past (- diff)))
  5952. ((and today? (> deadline today)) (format future diff))
  5953. (t now)))
  5954. (org-add-props head nil
  5955. 'effort effort
  5956. 'effort-minutes effort-minutes)
  5957. level category tags time))
  5958. (face (org-agenda-deadline-face
  5959. (- 1 (/ (float diff) (max wdays 1)))))
  5960. (upcoming? (and today? (> deadline today)))
  5961. (warntime (get-text-property (point) 'org-appt-warntime)))
  5962. (org-add-props item props
  5963. 'org-marker (org-agenda-new-marker pos)
  5964. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5965. 'warntime warntime
  5966. 'level level
  5967. 'effort effort 'effort-minutes effort-minutes
  5968. 'ts-date deadline
  5969. 'priority
  5970. ;; Adjust priority to today reminders about deadlines.
  5971. ;; Overdue deadlines get the highest priority
  5972. ;; increase, then imminent deadlines and eventually
  5973. ;; more distant deadlines.
  5974. (let ((adjust (if today? (- diff) 0)))
  5975. (+ adjust (org-get-priority item)))
  5976. 'todo-state todo-state
  5977. 'type (if upcoming? "upcoming-deadline" "deadline")
  5978. 'date (if upcoming? date deadline)
  5979. 'face (if done? 'org-agenda-done face)
  5980. 'undone-face face
  5981. 'done-face 'org-agenda-done)
  5982. (push item deadline-items)))))))
  5983. :next-re regexp
  5984. :fail-re regexp
  5985. :narrow t)
  5986. (while (re-search-forward regexp nil t)
  5987. (catch :skip
  5988. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5989. (org-agenda-skip)
  5990. (let* ((s (match-string 1))
  5991. (pos (1- (match-beginning 1)))
  5992. (todo-state (save-match-data (org-get-todo-state)))
  5993. (done? (member todo-state org-done-keywords))
  5994. (sexp? (string-prefix-p "%%" s))
  5995. ;; DEADLINE is the deadline date for the entry. It is
  5996. ;; either the base date or the last repeat, according
  5997. ;; to `org-agenda-prefer-last-repeat'.
  5998. (deadline
  5999. (cond
  6000. (sexp? (org-agenda--timestamp-to-absolute s current))
  6001. ((or (eq org-agenda-prefer-last-repeat t)
  6002. (member todo-state org-agenda-prefer-last-repeat))
  6003. (org-agenda--timestamp-to-absolute
  6004. s today 'past (current-buffer) pos))
  6005. (t (org-agenda--timestamp-to-absolute s))))
  6006. ;; REPEAT is the future repeat closest from CURRENT,
  6007. ;; according to `org-agenda-show-future-repeats'. If
  6008. ;; the latter is nil, or if the time stamp has no
  6009. ;; repeat part, default to DEADLINE.
  6010. (repeat
  6011. (cond
  6012. (sexp? deadline)
  6013. ((<= current today) deadline)
  6014. ((not org-agenda-show-future-repeats) deadline)
  6015. (t
  6016. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6017. (1+ today)
  6018. current)))
  6019. (org-agenda--timestamp-to-absolute
  6020. s base 'future (current-buffer) pos)))))
  6021. (diff (- deadline current))
  6022. (suppress-prewarning
  6023. (let ((scheduled
  6024. (and org-agenda-skip-deadline-prewarning-if-scheduled
  6025. (org-entry-get nil "SCHEDULED"))))
  6026. (cond
  6027. ((not scheduled) nil)
  6028. ;; The current item has a scheduled date, so
  6029. ;; evaluate its prewarning lead time.
  6030. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  6031. ;; Use global prewarning-restart lead time.
  6032. org-agenda-skip-deadline-prewarning-if-scheduled)
  6033. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  6034. 'pre-scheduled)
  6035. ;; Set pre-warning to no earlier than SCHEDULED.
  6036. (min (- deadline
  6037. (org-agenda--timestamp-to-absolute scheduled))
  6038. org-deadline-warning-days))
  6039. ;; Set pre-warning to deadline.
  6040. (t 0))))
  6041. (wdays (or suppress-prewarning (org-get-wdays s))))
  6042. (cond
  6043. ;; Only display deadlines at their base date, at future
  6044. ;; repeat occurrences or in today agenda.
  6045. ((= current deadline) nil)
  6046. ((= current repeat) nil)
  6047. ((not today?) (throw :skip nil))
  6048. ;; Upcoming deadline: display within warning period WDAYS.
  6049. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  6050. ;; Overdue deadline: warn about it for
  6051. ;; `org-deadline-past-days' duration.
  6052. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  6053. ;; Possibly skip done tasks.
  6054. (when (and done?
  6055. (or org-agenda-skip-deadline-if-done
  6056. (/= deadline current)))
  6057. (throw :skip nil))
  6058. (save-excursion
  6059. (re-search-backward "^\\*+[ \t]+" nil t)
  6060. (goto-char (match-end 0))
  6061. (let* ((category (org-get-category))
  6062. (effort (save-match-data (or (get-text-property (point) 'effort)
  6063. (org-entry-get (point) org-effort-property))))
  6064. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6065. (level (make-string (org-reduced-level (org-outline-level))
  6066. ?\s))
  6067. (head (buffer-substring-no-properties
  6068. (point) (line-end-position)))
  6069. (inherited-tags
  6070. (or (eq org-agenda-show-inherited-tags 'always)
  6071. (and (listp org-agenda-show-inherited-tags)
  6072. (memq 'agenda org-agenda-show-inherited-tags))
  6073. (and (eq org-agenda-show-inherited-tags t)
  6074. (or (eq org-agenda-use-tag-inheritance t)
  6075. (memq 'agenda
  6076. org-agenda-use-tag-inheritance)))))
  6077. (tags (org-get-tags nil (not inherited-tags)))
  6078. (time
  6079. (cond
  6080. ;; No time of day designation if it is only
  6081. ;; a reminder.
  6082. ((and (/= current deadline) (/= current repeat)) nil)
  6083. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6084. (concat (substring s (match-beginning 1)) " "))
  6085. (t 'time)))
  6086. (item
  6087. (org-agenda-format-item
  6088. ;; Insert appropriate suffixes before deadlines.
  6089. ;; Those only apply to today agenda.
  6090. (pcase-let ((`(,now ,future ,past)
  6091. org-agenda-deadline-leaders))
  6092. (cond
  6093. ((and today? (< deadline today)) (format past (- diff)))
  6094. ((and today? (> deadline today)) (format future diff))
  6095. (t now)))
  6096. (org-add-props head nil
  6097. 'effort effort
  6098. 'effort-minutes effort-minutes)
  6099. level category tags time))
  6100. (face (org-agenda-deadline-face
  6101. (- 1 (/ (float diff) (max wdays 1)))))
  6102. (upcoming? (and today? (> deadline today)))
  6103. (warntime (get-text-property (point) 'org-appt-warntime)))
  6104. (org-add-props item props
  6105. 'org-marker (org-agenda-new-marker pos)
  6106. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6107. 'warntime warntime
  6108. 'level level
  6109. 'effort effort 'effort-minutes effort-minutes
  6110. 'ts-date deadline
  6111. 'priority
  6112. ;; Adjust priority to today reminders about deadlines.
  6113. ;; Overdue deadlines get the highest priority
  6114. ;; increase, then imminent deadlines and eventually
  6115. ;; more distant deadlines.
  6116. (let ((adjust (if today? (- diff) 0)))
  6117. (+ adjust (org-get-priority item)))
  6118. 'todo-state todo-state
  6119. 'type (if upcoming? "upcoming-deadline" "deadline")
  6120. 'date (if upcoming? date deadline)
  6121. 'face (if done? 'org-agenda-done face)
  6122. 'undone-face face
  6123. 'done-face 'org-agenda-done)
  6124. (push item deadline-items)))))))
  6125. (nreverse deadline-items)))
  6126. (defun org-agenda-deadline-face (fraction)
  6127. "Return the face to displaying a deadline item.
  6128. FRACTION is what fraction of the head-warning time has passed."
  6129. (assoc-default fraction org-agenda-deadline-faces #'<=))
  6130. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  6131. "Return the scheduled information for agenda display.
  6132. Optional argument DEADLINES is a list of deadline items to be
  6133. displayed in agenda view. When WITH-HOUR is non-nil, only return
  6134. scheduled items with an hour specification like [h]h:mm."
  6135. (with-no-warnings (defvar date))
  6136. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  6137. 'org-todo-regexp org-todo-regexp
  6138. 'org-complex-heading-regexp org-complex-heading-regexp
  6139. 'done-face 'org-agenda-done
  6140. 'mouse-face 'highlight
  6141. 'help-echo
  6142. (format "mouse-2 or RET jump to Org file %s"
  6143. (abbreviate-file-name buffer-file-name))))
  6144. (regexp (if with-hour
  6145. org-scheduled-time-hour-regexp
  6146. org-scheduled-time-regexp))
  6147. (today (org-today))
  6148. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  6149. (current (calendar-absolute-from-gregorian date))
  6150. (deadline-pos
  6151. (mapcar (lambda (d)
  6152. (let ((m (get-text-property 0 'org-hd-marker d)))
  6153. (and m (marker-position m))))
  6154. deadlines))
  6155. scheduled-items)
  6156. (goto-char (point-min))
  6157. (if (org-element--cache-active-p)
  6158. (org-element-cache-map
  6159. (lambda (el)
  6160. (when (and (org-element-property :scheduled el)
  6161. (or (not with-hour)
  6162. (org-element-property
  6163. :hour-start
  6164. (org-element-property :scheduled el))
  6165. (org-element-property
  6166. :hour-end
  6167. (org-element-property :scheduled el))))
  6168. (goto-char (org-element-property :contents-begin el))
  6169. (catch :skip
  6170. (org-agenda-skip el)
  6171. (let* ((s (substring (org-element-property
  6172. :raw-value
  6173. (org-element-property :scheduled el))
  6174. 1 -1))
  6175. (pos (save-excursion
  6176. (goto-char (org-element-property :contents-begin el))
  6177. ;; We intentionally leave NOERROR
  6178. ;; argument in `re-search-forward' nil. If
  6179. ;; the search fails here, something went
  6180. ;; wrong and we are looking at
  6181. ;; non-matching headline.
  6182. (re-search-forward regexp (line-end-position))
  6183. (1- (match-beginning 1))))
  6184. (todo-state (org-element-property :todo-keyword el))
  6185. (donep (eq 'done (org-element-property :todo-type el)))
  6186. (sexp? (eq 'diary
  6187. (org-element-property
  6188. :type (org-element-property :scheduled el))))
  6189. ;; SCHEDULE is the scheduled date for the entry. It is
  6190. ;; either the bare date or the last repeat, according
  6191. ;; to `org-agenda-prefer-last-repeat'.
  6192. (schedule
  6193. (cond
  6194. (sexp? (org-agenda--timestamp-to-absolute s current))
  6195. ((or (eq org-agenda-prefer-last-repeat t)
  6196. (member todo-state org-agenda-prefer-last-repeat))
  6197. (org-agenda--timestamp-to-absolute
  6198. s today 'past (current-buffer) pos))
  6199. (t (org-agenda--timestamp-to-absolute s))))
  6200. ;; REPEAT is the future repeat closest from CURRENT,
  6201. ;; according to `org-agenda-show-future-repeats'. If
  6202. ;; the latter is nil, or if the time stamp has no
  6203. ;; repeat part, default to SCHEDULE.
  6204. (repeat
  6205. (cond
  6206. (sexp? schedule)
  6207. ((<= current today) schedule)
  6208. ((not org-agenda-show-future-repeats) schedule)
  6209. (t
  6210. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6211. (1+ today)
  6212. current)))
  6213. (org-agenda--timestamp-to-absolute
  6214. s base 'future (current-buffer) pos)))))
  6215. (diff (- current schedule))
  6216. (warntime (get-text-property (point) 'org-appt-warntime))
  6217. (pastschedp (< schedule today))
  6218. (futureschedp (> schedule today))
  6219. (habitp (and (fboundp 'org-is-habit-p)
  6220. (string= "habit" (org-element-property :STYLE el))))
  6221. (suppress-delay
  6222. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  6223. (org-element-property
  6224. :raw-value
  6225. (org-element-property :deadline el)))))
  6226. (cond
  6227. ((not deadline) nil)
  6228. ;; The current item has a deadline date, so
  6229. ;; evaluate its delay time.
  6230. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  6231. ;; Use global delay time.
  6232. (- org-agenda-skip-scheduled-delay-if-deadline))
  6233. ((eq org-agenda-skip-scheduled-delay-if-deadline
  6234. 'post-deadline)
  6235. ;; Set delay to no later than DEADLINE.
  6236. (min (- schedule
  6237. (org-agenda--timestamp-to-absolute deadline))
  6238. org-scheduled-delay-days))
  6239. (t 0))))
  6240. (ddays
  6241. (cond
  6242. ;; Nullify delay when a repeater triggered already
  6243. ;; and the delay is of the form --Xd.
  6244. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  6245. (> schedule (org-agenda--timestamp-to-absolute s)))
  6246. 0)
  6247. (suppress-delay
  6248. (let ((org-scheduled-delay-days suppress-delay))
  6249. (org-get-wdays s t t)))
  6250. (t (org-get-wdays s t)))))
  6251. ;; Display scheduled items at base date (SCHEDULE), today if
  6252. ;; scheduled before the current date, and at any repeat past
  6253. ;; today. However, skip delayed items and items that have
  6254. ;; been displayed for more than `org-scheduled-past-days'.
  6255. (unless (and todayp
  6256. habitp
  6257. (bound-and-true-p org-habit-show-all-today))
  6258. (when (or (and (> ddays 0) (< diff ddays))
  6259. (> diff (or (and habitp org-habit-scheduled-past-days)
  6260. org-scheduled-past-days))
  6261. (> schedule current)
  6262. (and (/= current schedule)
  6263. (/= current today)
  6264. (/= current repeat)))
  6265. (throw :skip nil)))
  6266. ;; Possibly skip done tasks.
  6267. (when (and donep
  6268. (or org-agenda-skip-scheduled-if-done
  6269. (/= schedule current)))
  6270. (throw :skip nil))
  6271. ;; Skip entry if it already appears as a deadline, per
  6272. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  6273. ;; doesn't apply to habits.
  6274. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  6275. ((guard
  6276. (or (not (memq (line-beginning-position 0) deadline-pos))
  6277. habitp))
  6278. nil)
  6279. (`repeated-after-deadline
  6280. (let ((deadline (time-to-days
  6281. (when (org-element-property :deadline el)
  6282. (org-time-string-to-time
  6283. (org-element-property :deadline el))))))
  6284. (and (<= schedule deadline) (> current deadline))))
  6285. (`not-today pastschedp)
  6286. (`t t)
  6287. (_ nil))
  6288. (throw :skip nil))
  6289. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  6290. ;; only show them for today. Also skip done habits.
  6291. (when (and habitp
  6292. (or donep
  6293. (not (bound-and-true-p org-habit-show-habits))
  6294. (and (not todayp)
  6295. (bound-and-true-p
  6296. org-habit-show-habits-only-for-today))))
  6297. (throw :skip nil))
  6298. (save-excursion
  6299. (goto-char (org-element-property :begin el))
  6300. (let* ((category (org-get-category))
  6301. (effort (save-match-data
  6302. (or (get-text-property (point) 'effort)
  6303. (org-element-property (intern (concat ":" (upcase org-effort-property))) el))))
  6304. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6305. (inherited-tags
  6306. (or (eq org-agenda-show-inherited-tags 'always)
  6307. (and (listp org-agenda-show-inherited-tags)
  6308. (memq 'agenda org-agenda-show-inherited-tags))
  6309. (and (eq org-agenda-show-inherited-tags t)
  6310. (or (eq org-agenda-use-tag-inheritance t)
  6311. (memq 'agenda
  6312. org-agenda-use-tag-inheritance)))))
  6313. (tags (org-get-tags el (not inherited-tags)))
  6314. (level (make-string (org-element-property :level el)
  6315. ?\s))
  6316. (head (save-excursion
  6317. (goto-char (org-element-property :begin el))
  6318. (re-search-forward org-outline-regexp-bol)
  6319. (buffer-substring (point) (line-end-position))))
  6320. (time
  6321. (cond
  6322. ;; No time of day designation if it is only a
  6323. ;; reminder, except for habits, which always show
  6324. ;; the time of day. Habits are an exception
  6325. ;; because if there is a time of day, that is
  6326. ;; interpreted to mean they should usually happen
  6327. ;; then, even if doing the habit was missed.
  6328. ((and
  6329. (not habitp)
  6330. (/= current schedule)
  6331. (/= current repeat))
  6332. nil)
  6333. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6334. (concat (substring s (match-beginning 1)) " "))
  6335. (t 'time)))
  6336. (item
  6337. (org-agenda-format-item
  6338. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  6339. ;; Show a reminder of a past scheduled today.
  6340. (if (and todayp pastschedp)
  6341. (format past diff)
  6342. first))
  6343. (org-add-props head nil
  6344. 'effort effort
  6345. 'effort-minutes effort-minutes)
  6346. level category tags time nil habitp))
  6347. (face (cond ((and (not habitp) pastschedp)
  6348. 'org-scheduled-previously)
  6349. ((and habitp futureschedp)
  6350. 'org-agenda-done)
  6351. (todayp 'org-scheduled-today)
  6352. (t 'org-scheduled)))
  6353. (habitp (and habitp (org-habit-parse-todo (org-element-property :begin el)))))
  6354. (org-add-props item props
  6355. 'undone-face face
  6356. 'face (if donep 'org-agenda-done face)
  6357. 'org-marker (org-agenda-new-marker pos)
  6358. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6359. 'type (if pastschedp "past-scheduled" "scheduled")
  6360. 'date (if pastschedp schedule date)
  6361. 'ts-date schedule
  6362. 'warntime warntime
  6363. 'level level
  6364. 'effort effort 'effort-minutes effort-minutes
  6365. 'priority (if habitp (org-habit-get-priority habitp)
  6366. (+ 99 diff (org-get-priority item)))
  6367. 'org-habit-p habitp
  6368. 'todo-state todo-state)
  6369. (push item scheduled-items)))))))
  6370. :next-re regexp
  6371. :fail-re regexp
  6372. :narrow t)
  6373. (while (re-search-forward regexp nil t)
  6374. (catch :skip
  6375. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  6376. (org-agenda-skip)
  6377. (let* ((s (match-string 1))
  6378. (pos (1- (match-beginning 1)))
  6379. (todo-state (save-match-data (org-get-todo-state)))
  6380. (donep (member todo-state org-done-keywords))
  6381. (sexp? (string-prefix-p "%%" s))
  6382. ;; SCHEDULE is the scheduled date for the entry. It is
  6383. ;; either the bare date or the last repeat, according
  6384. ;; to `org-agenda-prefer-last-repeat'.
  6385. (schedule
  6386. (cond
  6387. (sexp? (org-agenda--timestamp-to-absolute s current))
  6388. ((or (eq org-agenda-prefer-last-repeat t)
  6389. (member todo-state org-agenda-prefer-last-repeat))
  6390. (org-agenda--timestamp-to-absolute
  6391. s today 'past (current-buffer) pos))
  6392. (t (org-agenda--timestamp-to-absolute s))))
  6393. ;; REPEAT is the future repeat closest from CURRENT,
  6394. ;; according to `org-agenda-show-future-repeats'. If
  6395. ;; the latter is nil, or if the time stamp has no
  6396. ;; repeat part, default to SCHEDULE.
  6397. (repeat
  6398. (cond
  6399. (sexp? schedule)
  6400. ((<= current today) schedule)
  6401. ((not org-agenda-show-future-repeats) schedule)
  6402. (t
  6403. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6404. (1+ today)
  6405. current)))
  6406. (org-agenda--timestamp-to-absolute
  6407. s base 'future (current-buffer) pos)))))
  6408. (diff (- current schedule))
  6409. (warntime (get-text-property (point) 'org-appt-warntime))
  6410. (pastschedp (< schedule today))
  6411. (futureschedp (> schedule today))
  6412. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  6413. (suppress-delay
  6414. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  6415. (org-entry-get nil "DEADLINE"))))
  6416. (cond
  6417. ((not deadline) nil)
  6418. ;; The current item has a deadline date, so
  6419. ;; evaluate its delay time.
  6420. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  6421. ;; Use global delay time.
  6422. (- org-agenda-skip-scheduled-delay-if-deadline))
  6423. ((eq org-agenda-skip-scheduled-delay-if-deadline
  6424. 'post-deadline)
  6425. ;; Set delay to no later than DEADLINE.
  6426. (min (- schedule
  6427. (org-agenda--timestamp-to-absolute deadline))
  6428. org-scheduled-delay-days))
  6429. (t 0))))
  6430. (ddays
  6431. (cond
  6432. ;; Nullify delay when a repeater triggered already
  6433. ;; and the delay is of the form --Xd.
  6434. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  6435. (> schedule (org-agenda--timestamp-to-absolute s)))
  6436. 0)
  6437. (suppress-delay
  6438. (let ((org-scheduled-delay-days suppress-delay))
  6439. (org-get-wdays s t t)))
  6440. (t (org-get-wdays s t)))))
  6441. ;; Display scheduled items at base date (SCHEDULE), today if
  6442. ;; scheduled before the current date, and at any repeat past
  6443. ;; today. However, skip delayed items and items that have
  6444. ;; been displayed for more than `org-scheduled-past-days'.
  6445. (unless (and todayp
  6446. habitp
  6447. (bound-and-true-p org-habit-show-all-today))
  6448. (when (or (and (> ddays 0) (< diff ddays))
  6449. (> diff (or (and habitp org-habit-scheduled-past-days)
  6450. org-scheduled-past-days))
  6451. (> schedule current)
  6452. (and (/= current schedule)
  6453. (/= current today)
  6454. (/= current repeat)))
  6455. (throw :skip nil)))
  6456. ;; Possibly skip done tasks.
  6457. (when (and donep
  6458. (or org-agenda-skip-scheduled-if-done
  6459. (/= schedule current)))
  6460. (throw :skip nil))
  6461. ;; Skip entry if it already appears as a deadline, per
  6462. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  6463. ;; doesn't apply to habits.
  6464. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  6465. ((guard
  6466. (or (not (memq (line-beginning-position 0) deadline-pos))
  6467. habitp))
  6468. nil)
  6469. (`repeated-after-deadline
  6470. (let ((deadline (time-to-days
  6471. (org-get-deadline-time (point)))))
  6472. (and (<= schedule deadline) (> current deadline))))
  6473. (`not-today pastschedp)
  6474. (`t t)
  6475. (_ nil))
  6476. (throw :skip nil))
  6477. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  6478. ;; only show them for today. Also skip done habits.
  6479. (when (and habitp
  6480. (or donep
  6481. (not (bound-and-true-p org-habit-show-habits))
  6482. (and (not todayp)
  6483. (bound-and-true-p
  6484. org-habit-show-habits-only-for-today))))
  6485. (throw :skip nil))
  6486. (save-excursion
  6487. (re-search-backward "^\\*+[ \t]+" nil t)
  6488. (goto-char (match-end 0))
  6489. (let* ((category (org-get-category))
  6490. (effort (save-match-data (or (get-text-property (point) 'effort)
  6491. (org-entry-get (point) org-effort-property))))
  6492. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6493. (inherited-tags
  6494. (or (eq org-agenda-show-inherited-tags 'always)
  6495. (and (listp org-agenda-show-inherited-tags)
  6496. (memq 'agenda org-agenda-show-inherited-tags))
  6497. (and (eq org-agenda-show-inherited-tags t)
  6498. (or (eq org-agenda-use-tag-inheritance t)
  6499. (memq 'agenda
  6500. org-agenda-use-tag-inheritance)))))
  6501. (tags (org-get-tags nil (not inherited-tags)))
  6502. (level (make-string (org-reduced-level (org-outline-level))
  6503. ?\s))
  6504. (head (buffer-substring (point) (line-end-position)))
  6505. (time
  6506. (cond
  6507. ;; No time of day designation if it is only a
  6508. ;; reminder, except for habits, which always show
  6509. ;; the time of day. Habits are an exception
  6510. ;; because if there is a time of day, that is
  6511. ;; interpreted to mean they should usually happen
  6512. ;; then, even if doing the habit was missed.
  6513. ((and
  6514. (not habitp)
  6515. (/= current schedule)
  6516. (/= current repeat))
  6517. nil)
  6518. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6519. (concat (substring s (match-beginning 1)) " "))
  6520. (t 'time)))
  6521. (item
  6522. (org-agenda-format-item
  6523. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  6524. ;; Show a reminder of a past scheduled today.
  6525. (if (and todayp pastschedp)
  6526. (format past diff)
  6527. first))
  6528. (org-add-props head nil
  6529. 'effort effort
  6530. 'effort-minutes effort-minutes)
  6531. level category tags time nil habitp))
  6532. (face (cond ((and (not habitp) pastschedp)
  6533. 'org-scheduled-previously)
  6534. ((and habitp futureschedp)
  6535. 'org-agenda-done)
  6536. (todayp 'org-scheduled-today)
  6537. (t 'org-scheduled)))
  6538. (habitp (and habitp (org-habit-parse-todo))))
  6539. (org-add-props item props
  6540. 'undone-face face
  6541. 'face (if donep 'org-agenda-done face)
  6542. 'org-marker (org-agenda-new-marker pos)
  6543. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6544. 'type (if pastschedp "past-scheduled" "scheduled")
  6545. 'date (if pastschedp schedule date)
  6546. 'ts-date schedule
  6547. 'warntime warntime
  6548. 'level level
  6549. 'effort effort 'effort-minutes effort-minutes
  6550. 'priority (if habitp (org-habit-get-priority habitp)
  6551. (+ 99 diff (org-get-priority item)))
  6552. 'org-habit-p habitp
  6553. 'todo-state todo-state)
  6554. (push item scheduled-items)))))))
  6555. (nreverse scheduled-items)))
  6556. (defun org-agenda-get-blocks ()
  6557. "Return the date-range information for agenda display."
  6558. (with-no-warnings (defvar date))
  6559. (let* ((props (list 'face nil
  6560. 'org-not-done-regexp org-not-done-regexp
  6561. 'org-todo-regexp org-todo-regexp
  6562. 'org-complex-heading-regexp org-complex-heading-regexp
  6563. 'mouse-face 'highlight
  6564. 'help-echo
  6565. (format "mouse-2 or RET jump to org file %s"
  6566. (abbreviate-file-name buffer-file-name))))
  6567. (regexp org-tr-regexp)
  6568. (d0 (calendar-absolute-from-gregorian date))
  6569. marker hdmarker ee txt d1 d2 s1 s2 category
  6570. level todo-state tags pos head donep inherited-tags
  6571. effort effort-minutes)
  6572. (goto-char (point-min))
  6573. (while (re-search-forward regexp nil t)
  6574. (catch :skip
  6575. (org-agenda-skip)
  6576. (setq pos (point))
  6577. (let ((start-time (match-string 1))
  6578. (end-time (match-string 2)))
  6579. (setq s1 (match-string 1)
  6580. s2 (match-string 2)
  6581. d1 (time-to-days
  6582. (condition-case err
  6583. (org-time-string-to-time s1)
  6584. (error
  6585. (error
  6586. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6587. s1
  6588. pos
  6589. (current-buffer)
  6590. (error-message-string err)))))
  6591. d2 (time-to-days
  6592. (condition-case err
  6593. (org-time-string-to-time s2)
  6594. (error
  6595. (error
  6596. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6597. s2
  6598. pos
  6599. (current-buffer)
  6600. (error-message-string err))))))
  6601. (when (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  6602. ;; Only allow days between the limits, because the normal
  6603. ;; date stamps will catch the limits.
  6604. (save-excursion
  6605. (setq todo-state (org-get-todo-state))
  6606. (setq donep (member todo-state org-done-keywords))
  6607. (when (and donep org-agenda-skip-timestamp-if-done)
  6608. (throw :skip t))
  6609. (setq marker (org-agenda-new-marker (point))
  6610. category (org-get-category))
  6611. (setq effort (save-match-data (or (get-text-property (point) 'effort)
  6612. (org-entry-get (point) org-effort-property))))
  6613. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6614. (if (not (re-search-backward org-outline-regexp-bol nil t))
  6615. (throw :skip nil)
  6616. (goto-char (match-beginning 0))
  6617. (setq hdmarker (org-agenda-new-marker (point))
  6618. inherited-tags
  6619. (or (eq org-agenda-show-inherited-tags 'always)
  6620. (and (listp org-agenda-show-inherited-tags)
  6621. (memq 'agenda org-agenda-show-inherited-tags))
  6622. (and (eq org-agenda-show-inherited-tags t)
  6623. (or (eq org-agenda-use-tag-inheritance t)
  6624. (memq 'agenda org-agenda-use-tag-inheritance))))
  6625. tags (org-get-tags nil (not inherited-tags)))
  6626. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  6627. (looking-at "\\*+[ \t]+\\(.*\\)")
  6628. (setq head (match-string 1))
  6629. (let ((remove-re
  6630. (if org-agenda-remove-timeranges-from-blocks
  6631. (concat
  6632. "<" (regexp-quote s1) ".*?>"
  6633. "--"
  6634. "<" (regexp-quote s2) ".*?>")
  6635. nil)))
  6636. (setq txt (org-agenda-format-item
  6637. (format
  6638. (nth (if (= d1 d2) 0 1)
  6639. org-agenda-timerange-leaders)
  6640. (1+ (- d0 d1)) (1+ (- d2 d1)))
  6641. (org-add-props head nil
  6642. 'effort effort
  6643. 'effort-minutes effort-minutes)
  6644. level category tags
  6645. (save-match-data
  6646. (let ((hhmm1 (and (string-match org-ts-regexp1 s1)
  6647. (match-string 6 s1)))
  6648. (hhmm2 (and (string-match org-ts-regexp1 s2)
  6649. (match-string 6 s2))))
  6650. (cond ((string= hhmm1 hhmm2)
  6651. (concat "<" start-time ">--<" end-time ">"))
  6652. ((and (= d1 d0) (= d2 d0))
  6653. (concat "<" start-time ">--<" end-time ">"))
  6654. ((= d1 d0)
  6655. (concat "<" start-time ">"))
  6656. ((= d2 d0)
  6657. (concat "<" end-time ">")))))
  6658. remove-re))))
  6659. (org-add-props txt props
  6660. 'org-marker marker 'org-hd-marker hdmarker
  6661. 'type "block" 'date date
  6662. 'level level
  6663. 'effort effort 'effort-minutes effort-minutes
  6664. 'todo-state todo-state
  6665. 'priority (org-get-priority txt))
  6666. (push txt ee))))
  6667. (goto-char pos)))
  6668. ;; Sort the entries by expiration date.
  6669. (nreverse ee)))
  6670. ;;; Agenda presentation and sorting
  6671. (defvar org-prefix-has-time nil
  6672. "A flag, set by `org-compile-prefix-format'.
  6673. The flag is set if the currently compiled format contains a `%t'.")
  6674. (defvar org-prefix-has-tag nil
  6675. "A flag, set by `org-compile-prefix-format'.
  6676. The flag is set if the currently compiled format contains a `%T'.")
  6677. (defvar org-prefix-has-effort nil
  6678. "A flag, set by `org-compile-prefix-format'.
  6679. The flag is set if the currently compiled format contains a `%e'.")
  6680. (defvar org-prefix-has-breadcrumbs nil
  6681. "A flag, set by `org-compile-prefix-format'.
  6682. The flag is set if the currently compiled format contains a `%b'.")
  6683. (defvar org-prefix-category-length nil
  6684. "Used by `org-compile-prefix-format' to remember the category field width.")
  6685. (defvar org-prefix-category-max-length nil
  6686. "Used by `org-compile-prefix-format' to remember the category field width.")
  6687. (defun org-agenda-get-category-icon (category)
  6688. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  6689. (cl-dolist (entry org-agenda-category-icon-alist)
  6690. (when (string-match-p (car entry) category)
  6691. (if (listp (cadr entry))
  6692. (cl-return (cadr entry))
  6693. (cl-return (apply #'create-image (cdr entry)))))))
  6694. (defun org-agenda-format-item (extra txt &optional with-level with-category tags dotime
  6695. remove-re habitp)
  6696. "Format TXT to be inserted into the agenda buffer.
  6697. In particular, add the prefix and corresponding text properties.
  6698. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  6699. WITH-LEVEL may be a string to replace the `%l' specifier.
  6700. WITH-CATEGORY (a string, a symbol or nil) may be used to overrule the default
  6701. category taken from local variable or file name. It will replace the `%c'
  6702. specifier in the format.
  6703. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  6704. TXT for sorting of this entry, and for the `%t' specifier in the format.
  6705. When DOTIME is a string, this string is searched for a time before TXT is.
  6706. TAGS can be the tags of the headline.
  6707. Any match of REMOVE-RE will be removed from TXT."
  6708. ;; We keep the org-prefix-* variable values along with a compiled
  6709. ;; formatter, so that multiple agendas existing at the same time do
  6710. ;; not step on each other toes.
  6711. ;;
  6712. ;; It was inconvenient to make these variables buffer local in
  6713. ;; Agenda buffers, because this function expects to be called with
  6714. ;; the buffer where item comes from being current, and not agenda
  6715. ;; buffer
  6716. (let* ((bindings (car org-prefix-format-compiled))
  6717. (formatter (cadr org-prefix-format-compiled)))
  6718. (cl-loop for (var value) in bindings
  6719. do (set var value))
  6720. (save-match-data
  6721. ;; Diary entries sometimes have extra whitespace at the beginning
  6722. (setq txt (org-trim txt))
  6723. ;; Fix the tags part in txt
  6724. (setq txt (org-agenda-fix-displayed-tags
  6725. txt tags
  6726. org-agenda-show-inherited-tags
  6727. org-agenda-hide-tags-regexp))
  6728. (with-no-warnings
  6729. ;; `time', `tag', `effort' are needed for the eval of the prefix format.
  6730. ;; Based on what I see in `org-compile-prefix-format', I added
  6731. ;; a few more.
  6732. (defvar breadcrumbs) (defvar category) (defvar category-icon)
  6733. (defvar effort) (defvar extra)
  6734. (defvar level) (defvar tag) (defvar time))
  6735. (let* ((category (or with-category
  6736. (if buffer-file-name
  6737. (file-name-sans-extension
  6738. (file-name-nondirectory buffer-file-name))
  6739. "")))
  6740. (category-icon (org-agenda-get-category-icon category))
  6741. (category-icon (if category-icon
  6742. (propertize " " 'display category-icon)
  6743. ""))
  6744. (effort (and (not (string= txt ""))
  6745. (get-text-property 1 'effort txt)))
  6746. (tag (if tags (nth (1- (length tags)) tags) ""))
  6747. (time-grid-trailing-characters (nth 2 org-agenda-time-grid))
  6748. (extra (or (and (not habitp) extra) ""))
  6749. time
  6750. (ts (when dotime (concat
  6751. (if (stringp dotime) dotime "")
  6752. (and org-agenda-search-headline-for-time txt))))
  6753. (time-of-day (and dotime (org-get-time-of-day ts)))
  6754. stamp plain s0 s1 s2 rtn srp l
  6755. duration breadcrumbs)
  6756. (and (derived-mode-p 'org-mode) buffer-file-name
  6757. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6758. (when (and dotime time-of-day)
  6759. ;; Extract starting and ending time and move them to prefix
  6760. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6761. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6762. (setq s0 (match-string 0 ts)
  6763. srp (and stamp (match-end 3))
  6764. s1 (match-string (if plain 1 2) ts)
  6765. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6766. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6767. ;; them, we might want to remove them there to avoid duplication.
  6768. ;; The user can turn this off with a variable.
  6769. (when (and org-prefix-has-time
  6770. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6771. (string-match (concat (regexp-quote s0) " *") txt)
  6772. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6773. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6774. (= (match-beginning 0) 0)
  6775. t))
  6776. (setq txt (replace-match "" nil nil txt))))
  6777. ;; Normalize the time(s) to 24 hour.
  6778. (when s1 (setq s1 (org-get-time-of-day s1 t)))
  6779. (when s2 (setq s2 (org-get-time-of-day s2 t)))
  6780. ;; Try to set s2 if s1 and
  6781. ;; `org-agenda-default-appointment-duration' are set
  6782. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6783. (setq s2
  6784. (org-duration-from-minutes
  6785. (+ (org-duration-to-minutes s1 t)
  6786. org-agenda-default-appointment-duration)
  6787. nil t)))
  6788. ;; Compute the duration
  6789. (when s2
  6790. (setq duration (- (org-duration-to-minutes s2)
  6791. (org-duration-to-minutes s1))))
  6792. ;; Format S1 and S2 for display.
  6793. (when s1 (setq s1 (format "%5s" (org-get-time-of-day s1 'overtime))))
  6794. (when s2 (setq s2 (org-get-time-of-day s2 'overtime))))
  6795. (when (string-match org-tag-group-re txt)
  6796. ;; Tags are in the string
  6797. (if (or (eq org-agenda-remove-tags t)
  6798. (and org-agenda-remove-tags
  6799. org-prefix-has-tag))
  6800. (setq txt (replace-match "" t t txt))
  6801. (setq txt (replace-match
  6802. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6803. (match-string 1 txt))
  6804. t t txt))))
  6805. (when remove-re
  6806. (while (string-match remove-re txt)
  6807. (setq txt (replace-match "" t t txt))))
  6808. ;; Set org-heading property on `txt' to mark the start of the
  6809. ;; heading.
  6810. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6811. ;; Prepare the variables needed in the eval of the compiled format
  6812. (when org-prefix-has-breadcrumbs
  6813. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6814. (let ((s (org-format-outline-path (org-get-outline-path)
  6815. (1- (frame-width))
  6816. nil org-agenda-breadcrumbs-separator)))
  6817. (if (eq "" s) "" (concat s org-agenda-breadcrumbs-separator))))))
  6818. (setq time (cond (s2 (concat
  6819. (org-agenda-time-of-day-to-ampm-maybe s1)
  6820. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6821. (when org-agenda-timegrid-use-ampm " ")))
  6822. (s1 (concat
  6823. (org-agenda-time-of-day-to-ampm-maybe s1)
  6824. (if org-agenda-timegrid-use-ampm
  6825. (concat time-grid-trailing-characters " ")
  6826. time-grid-trailing-characters)))
  6827. (t ""))
  6828. category (if (symbolp category) (symbol-name category) category)
  6829. level (or with-level ""))
  6830. (if (string-match org-link-bracket-re category)
  6831. (progn
  6832. (setq l (string-width (or (match-string 2) (match-string 1))))
  6833. (when (< l (or org-prefix-category-length 0))
  6834. (setq category (copy-sequence category))
  6835. (org-add-props category nil
  6836. 'extra-space (make-string
  6837. (- org-prefix-category-length l 1) ?\ ))))
  6838. (when (and org-prefix-category-max-length
  6839. (>= (length category) org-prefix-category-max-length))
  6840. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6841. ;; Evaluate the compiled format
  6842. (setq rtn (concat (eval formatter t) txt))
  6843. ;; And finally add the text properties
  6844. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6845. (org-add-props rtn nil
  6846. 'org-category category
  6847. 'tags tags
  6848. 'org-priority-highest org-priority-highest
  6849. 'org-priority-lowest org-priority-lowest
  6850. 'time-of-day time-of-day
  6851. 'duration duration
  6852. 'breadcrumbs breadcrumbs
  6853. 'txt txt
  6854. 'level level
  6855. 'time time
  6856. 'extra extra
  6857. 'format org-prefix-format-compiled
  6858. 'dotime dotime)))))
  6859. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6860. "Remove tags string from TXT, and add a modified list of tags.
  6861. The modified list may contain inherited tags, and tags matched by
  6862. `org-agenda-hide-tags-regexp' will be removed."
  6863. (when (or add-inherited hide-re)
  6864. (when (string-match org-tag-group-re txt)
  6865. (setq txt (substring txt 0 (match-beginning 0))))
  6866. (setq tags
  6867. (delq nil
  6868. (mapcar (lambda (tg)
  6869. (if (or (and hide-re (string-match hide-re tg))
  6870. (and (not add-inherited)
  6871. (get-text-property 0 'inherited tg)))
  6872. nil
  6873. tg))
  6874. tags)))
  6875. (when tags
  6876. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6877. i)
  6878. (setq txt (concat txt " :"
  6879. (mapconcat
  6880. (lambda (x)
  6881. (setq i (get-text-property 0 'inherited x))
  6882. (if (and have-i (not i))
  6883. (progn
  6884. (setq have-i nil)
  6885. (concat ":" x))
  6886. x))
  6887. tags ":")
  6888. (if have-i "::" ":"))))))
  6889. txt)
  6890. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6891. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6892. "Add a time-grid for agenda items which need it.
  6893. LIST is the list of agenda items formatted by `org-agenda-list'.
  6894. NDAYS is the span of the current agenda view.
  6895. TODAYP is t when the current agenda view is on today."
  6896. (catch 'exit
  6897. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6898. ((and todayp (member 'today (car org-agenda-time-grid))))
  6899. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6900. ((member 'weekly (car org-agenda-time-grid)))
  6901. (t (throw 'exit list)))
  6902. (let* ((have (delq nil (mapcar
  6903. (lambda (x) (get-text-property 1 'time-of-day x))
  6904. list)))
  6905. (string (nth 3 org-agenda-time-grid))
  6906. (gridtimes (nth 1 org-agenda-time-grid))
  6907. (req (car org-agenda-time-grid))
  6908. (remove (member 'remove-match req))
  6909. new time)
  6910. (when (and (member 'require-timed req) (not have))
  6911. ;; don't show empty grid
  6912. (throw 'exit list))
  6913. (while (setq time (pop gridtimes))
  6914. (unless (and remove (member time have))
  6915. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6916. (push (org-agenda-format-item
  6917. nil string nil "" nil
  6918. (concat (substring time 0 -2) ":" (substring time -2)))
  6919. new)
  6920. (put-text-property
  6921. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6922. (when (and todayp org-agenda-show-current-time-in-grid)
  6923. (push (org-agenda-format-item
  6924. nil org-agenda-current-time-string nil "" nil
  6925. (format-time-string "%H:%M "))
  6926. new)
  6927. (put-text-property
  6928. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6929. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6930. (append new list)
  6931. (append list new)))))
  6932. (defun org-compile-prefix-format (key)
  6933. "Compile the prefix format into a Lisp form that can be evaluated.
  6934. KEY is the agenda type (see `org-agenda-prefix-format').
  6935. The resulting form and associated variable bindings is returned
  6936. and stored in the variable `org-prefix-format-compiled'."
  6937. (setq org-prefix-has-time nil
  6938. org-prefix-has-tag nil
  6939. org-prefix-category-length nil
  6940. org-prefix-has-effort nil
  6941. org-prefix-has-breadcrumbs nil)
  6942. (let ((s (cond
  6943. ((stringp org-agenda-prefix-format)
  6944. org-agenda-prefix-format)
  6945. ((assq key org-agenda-prefix-format)
  6946. (cdr (assq key org-agenda-prefix-format)))
  6947. (t " %-12:c%?-12t% s")))
  6948. (start 0)
  6949. varform vars var c f opt) ;; e
  6950. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+?)\\)"
  6951. s start)
  6952. (setq var (or (cdr (assoc (match-string 4 s)
  6953. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6954. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6955. 'eval)
  6956. c (or (match-string 3 s) "")
  6957. opt (match-beginning 1)
  6958. start (1+ (match-beginning 0)))
  6959. (cl-case var
  6960. (time (setq org-prefix-has-time t))
  6961. (tag (setq org-prefix-has-tag t))
  6962. (effort (setq org-prefix-has-effort t))
  6963. (breadcrumbs (setq org-prefix-has-breadcrumbs t)))
  6964. (setq f (concat "%" (match-string 2 s) "s"))
  6965. (when (eq var 'category)
  6966. (setq org-prefix-category-length
  6967. (floor (abs (string-to-number (match-string 2 s)))))
  6968. (setq org-prefix-category-max-length
  6969. (let ((x (match-string 2 s)))
  6970. (save-match-data
  6971. (and (string-match "\\.[0-9]+" x)
  6972. (string-to-number (substring (match-string 0 x) 1)))))))
  6973. (if (eq var 'eval)
  6974. (setq varform `(format ,f (org-eval ,(read (substring s (match-beginning 4))))))
  6975. (if opt
  6976. (setq varform
  6977. `(if (member ,var '("" nil))
  6978. ""
  6979. (format ,f (concat ,var ,c))))
  6980. (setq varform
  6981. `(format ,f (if (member ,var '("" nil)) ""
  6982. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6983. (if (eq var 'eval)
  6984. (setf (substring s (match-beginning 0)
  6985. (+ (match-beginning 4)
  6986. (length (format "%S" (read (substring s (match-beginning 4)))))))
  6987. "%s")
  6988. (setq s (replace-match "%s" t nil s)))
  6989. (push varform vars))
  6990. (setq vars (nreverse vars))
  6991. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6992. (setq org-prefix-format-compiled
  6993. (list
  6994. `((org-prefix-has-time ,org-prefix-has-time)
  6995. (org-prefix-has-tag ,org-prefix-has-tag)
  6996. (org-prefix-category-length ,org-prefix-category-length)
  6997. (org-prefix-has-effort ,org-prefix-has-effort)
  6998. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6999. `(format ,s ,@vars))))))
  7000. (defun org-set-sorting-strategy (key)
  7001. (setq org-agenda-sorting-strategy-selected
  7002. (if (symbolp (car org-agenda-sorting-strategy))
  7003. ;; the old format
  7004. org-agenda-sorting-strategy
  7005. (or (cdr (assq key org-agenda-sorting-strategy))
  7006. (cdr (assq 'agenda org-agenda-sorting-strategy))
  7007. '(time-up category-keep priority-down)))))
  7008. (defun org-get-time-of-day (s &optional string)
  7009. "Check string S for a time of day.
  7010. If found, return it as a military time number between 0 and 2400.
  7011. If not found, return nil.
  7012. The optional STRING argument forces conversion into a 5 character wide string
  7013. HH:MM. When it is `overtime', any time above 24:00 is turned into \"+H:MM\"
  7014. where H:MM is the duration above midnight."
  7015. (let ((case-fold-search t)
  7016. (time-regexp
  7017. (rx word-start
  7018. (group (opt (any "012")) digit) ;group 1: hours
  7019. (or (and ":" (group (any "012345") digit) ;group 2: minutes
  7020. (opt (group (or "am" "pm")))) ;group 3: am/pm
  7021. ;; Special "HHam/pm" case.
  7022. (group-n 3 (or "am" "pm")))
  7023. word-end)))
  7024. (save-match-data
  7025. (when (and (string-match time-regexp s)
  7026. (not (eq 'org-link (get-text-property 1 'face s))))
  7027. (let ((hours
  7028. (let* ((ampm (and (match-end 3) (downcase (match-string 3 s))))
  7029. (am-p (equal ampm "am")))
  7030. (pcase (string-to-number (match-string 1 s))
  7031. ((and (guard (not ampm)) h) h)
  7032. (12 (if am-p 0 12))
  7033. (h (+ h (if am-p 0 12))))))
  7034. (minutes
  7035. (if (match-end 2)
  7036. (string-to-number (match-string 2 s))
  7037. 0)))
  7038. (pcase string
  7039. (`nil (+ minutes (* hours 100)))
  7040. ((and `overtime
  7041. (guard (or (> hours 24)
  7042. (and (= hours 24)
  7043. (> minutes 0)))))
  7044. (format "+%d:%02d" (- hours 24) minutes))
  7045. ((guard org-agenda-time-leading-zero)
  7046. (format "%02d:%02d" hours minutes))
  7047. (_
  7048. (format "%d:%02d" hours minutes))))))))
  7049. (defvar org-agenda-before-sorting-filter-function nil
  7050. "Function to be applied to agenda items prior to sorting.
  7051. Prior to sorting also means just before they are inserted into the agenda.
  7052. To aid sorting, you may revisit the original entries and add more text
  7053. properties which will later be used by the sorting functions.
  7054. The function should take a string argument, an agenda line.
  7055. It has access to the text properties in that line, which contain among
  7056. other things, the property `org-hd-marker' that points to the entry
  7057. where the line comes from. Note that not all lines going into the agenda
  7058. have this property, only most.
  7059. The function should return the modified string. It is probably best
  7060. to ONLY change text properties.
  7061. You can also use this function as a filter, by returning nil for lines
  7062. you don't want to have in the agenda at all. For this application, you
  7063. could bind the variable in the options section of a custom command.")
  7064. (defun org-agenda-finalize-entries (list &optional type)
  7065. "Sort, limit and concatenate the LIST of agenda items.
  7066. The optional argument TYPE tells the agenda type."
  7067. (let ((max-effort (cond ((listp org-agenda-max-effort)
  7068. (cdr (assoc type org-agenda-max-effort)))
  7069. (t org-agenda-max-effort)))
  7070. (max-todo (cond ((listp org-agenda-max-todos)
  7071. (cdr (assoc type org-agenda-max-todos)))
  7072. (t org-agenda-max-todos)))
  7073. (max-tags (cond ((listp org-agenda-max-tags)
  7074. (cdr (assoc type org-agenda-max-tags)))
  7075. (t org-agenda-max-tags)))
  7076. (max-entries (cond ((listp org-agenda-max-entries)
  7077. (cdr (assoc type org-agenda-max-entries)))
  7078. (t org-agenda-max-entries))))
  7079. (when org-agenda-before-sorting-filter-function
  7080. (setq list
  7081. (delq nil
  7082. (mapcar
  7083. org-agenda-before-sorting-filter-function list))))
  7084. (setq list (mapcar #'org-agenda-highlight-todo list)
  7085. list (mapcar #'identity (sort list #'org-entries-lessp)))
  7086. (when max-effort
  7087. (setq list (org-agenda-limit-entries
  7088. list 'effort-minutes max-effort
  7089. (lambda (e) (or e (if org-agenda-sort-noeffort-is-high
  7090. 32767 -1))))))
  7091. (when max-todo
  7092. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  7093. (when max-tags
  7094. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  7095. (when max-entries
  7096. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  7097. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  7098. (setq list (mapcar #'org-agenda--mark-blocked-entry list)))
  7099. (mapconcat #'identity list "\n")))
  7100. (defun org-agenda-limit-entries (list prop limit &optional fn)
  7101. "Limit the number of agenda entries."
  7102. (let ((include (and limit (< limit 0))))
  7103. (if limit
  7104. (let ((fun (or fn (lambda (p) (when p 1))))
  7105. (lim 0))
  7106. (delq nil
  7107. (mapcar
  7108. (lambda (e)
  7109. (let ((pval (funcall
  7110. fun (get-text-property (1- (length e))
  7111. prop e))))
  7112. (when pval (setq lim (+ lim pval)))
  7113. (cond ((and pval (<= lim (abs limit))) e)
  7114. ((and include (not pval)) e))))
  7115. list)))
  7116. list)))
  7117. (defun org-agenda-limit-interactively (remove)
  7118. "In agenda, interactively limit entries to various maximums."
  7119. (interactive "P")
  7120. (if remove
  7121. (progn (setq org-agenda-max-entries nil
  7122. org-agenda-max-todos nil
  7123. org-agenda-max-tags nil
  7124. org-agenda-max-effort nil)
  7125. (org-agenda-redo))
  7126. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  7127. (msg (cond ((= max ?E) "How many minutes? ")
  7128. ((= max ?e) "How many entries? ")
  7129. ((= max ?t) "How many TODO entries? ")
  7130. ((= max ?T) "How many tagged entries? ")
  7131. (t (user-error "Wrong input"))))
  7132. (num (string-to-number (read-from-minibuffer msg))))
  7133. (cond ((equal max ?e)
  7134. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  7135. ((equal max ?t)
  7136. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  7137. ((equal max ?T)
  7138. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  7139. ((equal max ?E)
  7140. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  7141. (org-agenda-fit-window-to-buffer))
  7142. (defun org-agenda-highlight-todo (x)
  7143. (let ((org-done-keywords org-done-keywords-for-agenda)
  7144. (case-fold-search nil)
  7145. re)
  7146. (if (eq x 'line)
  7147. (save-excursion
  7148. (beginning-of-line 1)
  7149. (setq re (org-get-at-bol 'org-todo-regexp))
  7150. (goto-char (or (text-property-any (line-beginning-position)
  7151. (line-end-position)
  7152. 'org-heading t)
  7153. (point)))
  7154. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  7155. (add-text-properties (match-beginning 0) (match-end 1)
  7156. (list 'face (org-get-todo-face 1)))
  7157. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  7158. (delete-region (match-beginning 1) (1- (match-end 0)))
  7159. (goto-char (match-beginning 1))
  7160. (insert (format org-agenda-todo-keyword-format s)))))
  7161. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  7162. (setq re (get-text-property 0 'org-todo-regexp x))
  7163. (when (and re
  7164. ;; Test `pl' because if there's no heading content,
  7165. ;; there's no point matching to highlight. Note
  7166. ;; that if we didn't test `pl' first, and there
  7167. ;; happened to be no keyword from `org-todo-regexp'
  7168. ;; on this heading line, then the `equal' comparison
  7169. ;; afterwards would spuriously succeed in the case
  7170. ;; where `pl' is nil -- causing an args-out-of-range
  7171. ;; error when we try to add text properties to text
  7172. ;; that isn't there.
  7173. pl
  7174. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  7175. x pl)
  7176. pl))
  7177. (add-text-properties
  7178. (or (match-end 1) (match-end 0)) (match-end 0)
  7179. (list 'face (org-get-todo-face (match-string 2 x)))
  7180. x)
  7181. (when (match-end 1)
  7182. (setq x
  7183. (concat
  7184. (substring x 0 (match-end 1))
  7185. (unless (string= org-agenda-todo-keyword-format "")
  7186. (format org-agenda-todo-keyword-format
  7187. (match-string 2 x)))
  7188. (unless (string= org-agenda-todo-keyword-format "")
  7189. ;; Remove `display' property as the icon could leak
  7190. ;; on the white space.
  7191. (org-add-props " " (org-plist-delete (text-properties-at 0 x)
  7192. 'display)))
  7193. (substring x (match-end 3)))))))
  7194. x)))
  7195. (defsubst org-cmp-values (a b property)
  7196. "Compare the numeric value of text PROPERTY for string A and B."
  7197. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  7198. (pb (or (get-text-property (1- (length b)) property b) 0)))
  7199. (cond ((> pa pb) +1)
  7200. ((< pa pb) -1))))
  7201. (defsubst org-cmp-effort (a b)
  7202. "Compare the effort values of string A and B."
  7203. (let* ((def (if org-agenda-sort-noeffort-is-high 32767 -1))
  7204. ;; `effort-minutes' property is not directly accessible from
  7205. ;; the strings, but is stored as a property in `txt'.
  7206. (ea (or (get-text-property
  7207. 0 'effort-minutes (get-text-property 0 'txt a))
  7208. def))
  7209. (eb (or (get-text-property
  7210. 0 'effort-minutes (get-text-property 0 'txt b))
  7211. def)))
  7212. (cond ((> ea eb) +1)
  7213. ((< ea eb) -1))))
  7214. (defsubst org-cmp-category (a b)
  7215. "Compare the string values of categories of strings A and B."
  7216. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  7217. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  7218. (cond ((string-lessp ca cb) -1)
  7219. ((string-lessp cb ca) +1))))
  7220. (defsubst org-cmp-todo-state (a b)
  7221. "Compare the todo states of strings A and B."
  7222. (let* ((ma (or (get-text-property 1 'org-marker a)
  7223. (get-text-property 1 'org-hd-marker a)))
  7224. (mb (or (get-text-property 1 'org-marker b)
  7225. (get-text-property 1 'org-hd-marker b)))
  7226. (fa (and ma (marker-buffer ma)))
  7227. (fb (and mb (marker-buffer mb)))
  7228. (todo-kwds
  7229. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  7230. (and fb (with-current-buffer fb org-todo-keywords-1))))
  7231. (ta (or (get-text-property 1 'todo-state a) ""))
  7232. (tb (or (get-text-property 1 'todo-state b) ""))
  7233. (la (- (length (member ta todo-kwds))))
  7234. (lb (- (length (member tb todo-kwds))))
  7235. (donepa (member ta org-done-keywords-for-agenda))
  7236. (donepb (member tb org-done-keywords-for-agenda)))
  7237. (cond ((and donepa (not donepb)) -1)
  7238. ((and (not donepa) donepb) +1)
  7239. ((< la lb) -1)
  7240. ((< lb la) +1))))
  7241. (defsubst org-cmp-alpha (a b)
  7242. "Compare the headlines, alphabetically."
  7243. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  7244. (plb (text-property-any 0 (length b) 'org-heading t b))
  7245. (ta (and pla (substring a pla)))
  7246. (tb (and plb (substring b plb)))
  7247. (case-fold-search nil))
  7248. (when pla
  7249. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  7250. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  7251. ta)
  7252. (setq ta (substring ta (match-end 0))))
  7253. (setq ta (downcase ta)))
  7254. (when plb
  7255. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  7256. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  7257. tb)
  7258. (setq tb (substring tb (match-end 0))))
  7259. (setq tb (downcase tb)))
  7260. (cond ((not (or ta tb)) nil)
  7261. ((not ta) +1)
  7262. ((not tb) -1)
  7263. ((string-lessp ta tb) -1)
  7264. ((string-lessp tb ta) +1))))
  7265. (defsubst org-cmp-tag (a b)
  7266. "Compare the string values of the first tags of A and B."
  7267. (let ((ta (car (last (get-text-property 1 'tags a))))
  7268. (tb (car (last (get-text-property 1 'tags b)))))
  7269. (cond ((not (or ta tb)) nil)
  7270. ((not ta) +1)
  7271. ((not tb) -1)
  7272. ((string-lessp ta tb) -1)
  7273. ((string-lessp tb ta) +1))))
  7274. (defsubst org-cmp-time (a b)
  7275. "Compare the time-of-day values of strings A and B."
  7276. (let* ((def (if org-agenda-sort-notime-is-late 9901 -1))
  7277. (ta (or (get-text-property 1 'time-of-day a) def))
  7278. (tb (or (get-text-property 1 'time-of-day b) def)))
  7279. (cond ((< ta tb) -1)
  7280. ((< tb ta) +1))))
  7281. (defsubst org-cmp-ts (a b type)
  7282. "Compare the timestamps values of entries A and B.
  7283. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  7284. \"timestamp_ia\", compare within each of these type. When TYPE
  7285. is the empty string, compare all timestamps without respect of
  7286. their type."
  7287. (let* ((def (if org-agenda-sort-notime-is-late 99999999 -1))
  7288. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  7289. (get-text-property 1 'ts-date a))
  7290. def))
  7291. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  7292. (get-text-property 1 'ts-date b))
  7293. def)))
  7294. (cond ((if ta (and tb (< ta tb)) tb) -1)
  7295. ((if tb (and ta (< tb ta)) ta) +1))))
  7296. (defsubst org-cmp-habit-p (a b)
  7297. "Compare the todo states of strings A and B."
  7298. (let ((ha (get-text-property 1 'org-habit-p a))
  7299. (hb (get-text-property 1 'org-habit-p b)))
  7300. (cond ((and ha (not hb)) -1)
  7301. ((and (not ha) hb) +1))))
  7302. (defun org-entries-lessp (a b)
  7303. "Predicate for sorting agenda entries."
  7304. ;; The following variables will be used when the form is evaluated.
  7305. ;; So even though the compiler complains, keep them.
  7306. (let ((ss org-agenda-sorting-strategy-selected))
  7307. (org-dlet
  7308. ((timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  7309. (org-cmp-ts a b "")))
  7310. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  7311. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  7312. (org-cmp-ts a b "scheduled")))
  7313. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  7314. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  7315. (org-cmp-ts a b "deadline")))
  7316. (deadline-down (if deadline-up (- deadline-up) nil))
  7317. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  7318. (org-cmp-ts a b "timestamp_ia")))
  7319. (tsia-down (if tsia-up (- tsia-up) nil))
  7320. (ts-up (and (org-em 'ts-up 'ts-down ss)
  7321. (org-cmp-ts a b "timestamp")))
  7322. (ts-down (if ts-up (- ts-up) nil))
  7323. (time-up (and (org-em 'time-up 'time-down ss)
  7324. (org-cmp-time a b)))
  7325. (time-down (if time-up (- time-up) nil))
  7326. (stats-up (and (org-em 'stats-up 'stats-down ss)
  7327. (org-cmp-values a b 'org-stats)))
  7328. (stats-down (if stats-up (- stats-up) nil))
  7329. (priority-up (and (org-em 'priority-up 'priority-down ss)
  7330. (org-cmp-values a b 'priority)))
  7331. (priority-down (if priority-up (- priority-up) nil))
  7332. (effort-up (and (org-em 'effort-up 'effort-down ss)
  7333. (org-cmp-effort a b)))
  7334. (effort-down (if effort-up (- effort-up) nil))
  7335. (category-up (and (or (org-em 'category-up 'category-down ss)
  7336. (memq 'category-keep ss))
  7337. (org-cmp-category a b)))
  7338. (category-down (if category-up (- category-up) nil))
  7339. (category-keep (if category-up +1 nil))
  7340. (tag-up (and (org-em 'tag-up 'tag-down ss)
  7341. (org-cmp-tag a b)))
  7342. (tag-down (if tag-up (- tag-up) nil))
  7343. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  7344. (org-cmp-todo-state a b)))
  7345. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  7346. (habit-up (and (org-em 'habit-up 'habit-down ss)
  7347. (org-cmp-habit-p a b)))
  7348. (habit-down (if habit-up (- habit-up) nil))
  7349. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  7350. (org-cmp-alpha a b)))
  7351. (alpha-down (if alpha-up (- alpha-up) nil))
  7352. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  7353. user-defined-up user-defined-down)
  7354. (when (and need-user-cmp org-agenda-cmp-user-defined
  7355. (functionp org-agenda-cmp-user-defined))
  7356. (setq user-defined-up
  7357. (funcall org-agenda-cmp-user-defined a b)
  7358. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  7359. (cdr (assoc
  7360. (eval (cons 'or org-agenda-sorting-strategy-selected) t)
  7361. '((-1 . t) (1 . nil) (nil . nil)))))))
  7362. ;;; Agenda restriction lock
  7363. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  7364. "Overlay to mark the headline to which agenda commands are restricted.")
  7365. (overlay-put org-agenda-restriction-lock-overlay
  7366. 'face 'org-agenda-restriction-lock)
  7367. (overlay-put org-agenda-restriction-lock-overlay
  7368. 'help-echo "Agendas are currently limited to this subtree.")
  7369. (delete-overlay org-agenda-restriction-lock-overlay)
  7370. (defun org-agenda-set-restriction-lock-from-agenda (arg)
  7371. "Set the restriction lock to the agenda item at point from within the agenda.
  7372. When called with a `\\[universal-argument]' prefix, restrict to
  7373. the file which contains the item.
  7374. Argument ARG is the prefix argument."
  7375. (interactive "P")
  7376. (unless (derived-mode-p 'org-agenda-mode)
  7377. (user-error "Not in an Org agenda buffer"))
  7378. (let* ((marker (or (org-get-at-bol 'org-marker)
  7379. (org-agenda-error)))
  7380. (buffer (marker-buffer marker))
  7381. (pos (marker-position marker)))
  7382. (with-current-buffer buffer
  7383. (goto-char pos)
  7384. (org-agenda-set-restriction-lock arg))))
  7385. ;;;###autoload
  7386. (defun org-agenda-set-restriction-lock (&optional type)
  7387. "Set restriction lock for agenda to current subtree or file.
  7388. When in a restricted subtree, remove it.
  7389. The restriction will span over the entire file if TYPE is `file',
  7390. or if TYPE is (4), or if the cursor is before the first headline
  7391. in the file. Otherwise, only apply the restriction to the current
  7392. subtree."
  7393. (interactive "P")
  7394. (if (and org-agenda-overriding-restriction
  7395. (member org-agenda-restriction-lock-overlay
  7396. (overlays-at (point)))
  7397. (equal (overlay-start org-agenda-restriction-lock-overlay)
  7398. (point)))
  7399. (org-agenda-remove-restriction-lock 'noupdate)
  7400. (org-agenda-remove-restriction-lock 'noupdate)
  7401. (and (equal type '(4)) (setq type 'file))
  7402. (setq type (cond
  7403. (type type)
  7404. ((org-at-heading-p) 'subtree)
  7405. ((condition-case nil (org-back-to-heading t) (error nil))
  7406. 'subtree)
  7407. (t 'file)))
  7408. (if (eq type 'subtree)
  7409. (progn
  7410. (setq org-agenda-restrict (current-buffer))
  7411. (setq org-agenda-overriding-restriction 'subtree)
  7412. (put 'org-agenda-files 'org-restrict
  7413. (list (buffer-file-name (buffer-base-buffer))))
  7414. (org-back-to-heading t)
  7415. (move-overlay org-agenda-restriction-lock-overlay
  7416. (point)
  7417. (if org-agenda-restriction-lock-highlight-subtree
  7418. (save-excursion (org-end-of-subtree t t) (point))
  7419. (line-end-position)))
  7420. (move-marker org-agenda-restrict-begin (point))
  7421. (move-marker org-agenda-restrict-end
  7422. (save-excursion (org-end-of-subtree t t)))
  7423. (message "Locking agenda restriction to subtree"))
  7424. (put 'org-agenda-files 'org-restrict
  7425. (list (buffer-file-name (buffer-base-buffer))))
  7426. (setq org-agenda-restrict nil)
  7427. (setq org-agenda-overriding-restriction 'file)
  7428. (move-marker org-agenda-restrict-begin nil)
  7429. (move-marker org-agenda-restrict-end nil)
  7430. (message "Locking agenda restriction to file"))
  7431. (setq current-prefix-arg nil))
  7432. (org-agenda-maybe-redo))
  7433. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  7434. "Remove agenda restriction lock."
  7435. (interactive "P")
  7436. (if (not (or org-agenda-restrict org-agenda-overriding-restriction))
  7437. (message "No agenda restriction to remove.")
  7438. (delete-overlay org-agenda-restriction-lock-overlay)
  7439. (delete-overlay org-speedbar-restriction-lock-overlay)
  7440. (setq org-agenda-overriding-restriction nil)
  7441. (unless org-agenda-keep-restricted-file-list
  7442. ;; There is a request to keep the file list in place
  7443. (put 'org-agenda-files 'org-restrict nil))
  7444. (setq org-agenda-restrict nil)
  7445. (put 'org-agenda-files 'org-restrict nil)
  7446. (move-marker org-agenda-restrict-begin nil)
  7447. (move-marker org-agenda-restrict-end nil)
  7448. (setq current-prefix-arg nil)
  7449. (message "Agenda restriction lock removed")
  7450. (or noupdate (org-agenda-maybe-redo))))
  7451. (defun org-agenda-maybe-redo ()
  7452. "If there is any window showing the agenda view, update it."
  7453. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  7454. org-agenda-buffer-name)
  7455. t))
  7456. (w0 (selected-window)))
  7457. (when w
  7458. (select-window w)
  7459. (org-agenda-redo)
  7460. (select-window w0)
  7461. (if org-agenda-overriding-restriction
  7462. (message "Agenda view shifted to new %s restriction"
  7463. org-agenda-overriding-restriction)
  7464. (message "Agenda restriction lock removed")))))
  7465. ;;; Agenda commands
  7466. (defun org-agenda-check-type (error &rest types)
  7467. "Check if agenda buffer or component is of allowed type.
  7468. If ERROR is non-nil, throw an error, otherwise just return nil.
  7469. Allowed types are `agenda' `todo' `tags' `search'."
  7470. (cond ((not org-agenda-type)
  7471. (error "No Org agenda currently displayed"))
  7472. ((memq org-agenda-type types) t)
  7473. (error
  7474. (error "Not allowed in '%s'-type agenda buffer or component" org-agenda-type))
  7475. (t nil)))
  7476. (defun org-agenda-Quit ()
  7477. "Exit the agenda, killing the agenda buffer.
  7478. Like `org-agenda-quit', but kill the buffer even when
  7479. `org-agenda-sticky' is non-nil."
  7480. (interactive)
  7481. (org-agenda--quit))
  7482. (defun org-agenda-quit ()
  7483. "Exit the agenda.
  7484. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  7485. instead of killing it.
  7486. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  7487. the pre-agenda window configuration.
  7488. When column view is active, exit column view instead of the
  7489. agenda."
  7490. (interactive)
  7491. (org-agenda--quit org-agenda-sticky))
  7492. (defun org-agenda--quit (&optional bury)
  7493. (if org-agenda-columns-active
  7494. (org-columns-quit)
  7495. (let ((wconf org-agenda-pre-window-conf)
  7496. (buf (current-buffer))
  7497. (org-agenda-last-indirect-window
  7498. (and (eq org-indirect-buffer-display 'other-window)
  7499. org-agenda-last-indirect-buffer
  7500. (get-buffer-window org-agenda-last-indirect-buffer))))
  7501. (cond
  7502. ((eq org-agenda-window-setup 'other-frame)
  7503. (delete-frame))
  7504. ((eq org-agenda-window-setup 'other-tab)
  7505. (if (fboundp 'tab-bar-close-tab)
  7506. (tab-bar-close-tab)
  7507. (user-error "Your version of Emacs does not have tab bar mode support")))
  7508. ((and org-agenda-restore-windows-after-quit
  7509. wconf)
  7510. ;; Maybe restore the pre-agenda window configuration. Reset
  7511. ;; `org-agenda-pre-window-conf' before running
  7512. ;; `set-window-configuration', which loses the current buffer.
  7513. (setq org-agenda-pre-window-conf nil)
  7514. (set-window-configuration wconf))
  7515. (t
  7516. (when org-agenda-last-indirect-window
  7517. (delete-window org-agenda-last-indirect-window))
  7518. (and (not (eq org-agenda-window-setup 'current-window))
  7519. (not (one-window-p))
  7520. (delete-window))))
  7521. (if bury
  7522. ;; Set the agenda buffer as the current buffer instead of
  7523. ;; passing it as an argument to `bury-buffer' so that
  7524. ;; `bury-buffer' removes it from the window.
  7525. (with-current-buffer buf
  7526. (bury-buffer))
  7527. (kill-buffer buf)
  7528. (setq org-agenda-archives-mode nil
  7529. org-agenda-buffer nil)))))
  7530. (defun org-agenda-exit ()
  7531. "Exit the agenda, killing Org buffers loaded by the agenda.
  7532. Like `org-agenda-Quit', but kill any buffers that were created by
  7533. the agenda. Org buffers visited directly by the user will not be
  7534. touched. Also, exit the agenda even if it is in column view."
  7535. (interactive)
  7536. (when org-agenda-columns-active
  7537. (org-columns-quit))
  7538. (org-release-buffers org-agenda-new-buffers)
  7539. (setq org-agenda-new-buffers nil)
  7540. (org-agenda-Quit))
  7541. (defun org-agenda-kill-all-agenda-buffers ()
  7542. "Kill all buffers in `org-agenda-mode'.
  7543. This is used when toggling sticky agendas."
  7544. (interactive)
  7545. (let (blist)
  7546. (dolist (buf (buffer-list))
  7547. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  7548. (push buf blist)))
  7549. (mapc #'kill-buffer blist)))
  7550. (defun org-agenda-execute (arg)
  7551. "Execute another agenda command, keeping same window.
  7552. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  7553. in the agenda."
  7554. (interactive "P")
  7555. (let ((org-agenda-window-setup 'current-window))
  7556. (org-agenda arg)))
  7557. (defun org-agenda-redo (&optional all)
  7558. "Rebuild possibly ALL agenda view(s) in the current buffer."
  7559. (interactive "P")
  7560. (defvar org-agenda-tag-filter-while-redo) ;FIXME: Where is this var used?
  7561. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  7562. (cpa (unless (eq all t) current-prefix-arg))
  7563. (org-agenda-doing-sticky-redo org-agenda-sticky)
  7564. (org-agenda-sticky nil)
  7565. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  7566. org-agenda-buffer-name))
  7567. (org-agenda-keep-modes t)
  7568. (tag-filter org-agenda-tag-filter)
  7569. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  7570. (top-hl-filter org-agenda-top-headline-filter)
  7571. (cat-filter org-agenda-category-filter)
  7572. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  7573. (re-filter org-agenda-regexp-filter)
  7574. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  7575. (effort-filter org-agenda-effort-filter)
  7576. (effort-preset (get 'org-agenda-effort-filter :preset-filter))
  7577. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  7578. (cols org-agenda-columns-active)
  7579. (line (org-current-line))
  7580. (window-line (- line (org-current-line (window-start))))
  7581. (lprops (get 'org-agenda-redo-command 'org-lprops))
  7582. (redo-cmd (get-text-property p 'org-redo-cmd))
  7583. (last-args (get-text-property p 'org-last-args))
  7584. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  7585. (org-agenda-overriding-cmd-arguments
  7586. (unless (eq all t)
  7587. (cond ((listp last-args)
  7588. (cons (or cpa (car last-args)) (cdr last-args)))
  7589. ((stringp last-args)
  7590. last-args))))
  7591. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  7592. (put 'org-agenda-tag-filter :preset-filter nil)
  7593. (put 'org-agenda-category-filter :preset-filter nil)
  7594. (put 'org-agenda-regexp-filter :preset-filter nil)
  7595. (put 'org-agenda-effort-filter :preset-filter nil)
  7596. (and cols (org-columns-quit))
  7597. (message "Rebuilding agenda buffer...")
  7598. (if series-redo-cmd
  7599. (eval series-redo-cmd t)
  7600. (cl-progv
  7601. (mapcar #'car lprops)
  7602. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  7603. (eval redo-cmd t)))
  7604. (setq org-agenda-undo-list nil
  7605. org-agenda-pending-undo-list nil
  7606. org-agenda-tag-filter tag-filter
  7607. org-agenda-category-filter cat-filter
  7608. org-agenda-regexp-filter re-filter
  7609. org-agenda-effort-filter effort-filter
  7610. org-agenda-top-headline-filter top-hl-filter)
  7611. (message "Rebuilding agenda buffer...done")
  7612. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  7613. (put 'org-agenda-category-filter :preset-filter cat-preset)
  7614. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  7615. (put 'org-agenda-effort-filter :preset-filter effort-preset)
  7616. (let ((tag (or tag-filter tag-preset))
  7617. (cat (or cat-filter cat-preset))
  7618. (effort (or effort-filter effort-preset))
  7619. (re (or re-filter re-preset)))
  7620. (when tag (org-agenda-filter-apply tag 'tag t))
  7621. (when cat (org-agenda-filter-apply cat 'category))
  7622. (when effort (org-agenda-filter-apply effort 'effort))
  7623. (when re (org-agenda-filter-apply re 'regexp)))
  7624. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  7625. (and cols (called-interactively-p 'any) (org-agenda-columns))
  7626. (org-goto-line line)
  7627. (when (called-interactively-p 'any) (recenter window-line))))
  7628. (defun org-agenda-redo-all (&optional exhaustive)
  7629. "Rebuild all agenda views in the current buffer.
  7630. With a prefix argument, do so in all agenda buffers."
  7631. (interactive "P")
  7632. (if exhaustive
  7633. (dolist (buffer (buffer-list))
  7634. (with-current-buffer buffer
  7635. (when (derived-mode-p 'org-agenda-mode)
  7636. (org-agenda-redo t))))
  7637. (org-agenda-redo t)))
  7638. (defvar org-global-tags-completion-table nil)
  7639. (defvar org-agenda-filter-form nil)
  7640. (defvar org-agenda-filtered-by-category nil)
  7641. (defsubst org-agenda-get-category ()
  7642. "Return the category of the agenda line."
  7643. (org-get-at-bol 'org-category))
  7644. (defun org-agenda-filter-by-category (strip)
  7645. "Filter lines in the agenda buffer that have a specific category.
  7646. The category is that of the current line.
  7647. With a `\\[universal-argument]' prefix argument, exclude the lines of that category.
  7648. When there is already a category filter in place, this command removes the
  7649. filter."
  7650. (interactive "P")
  7651. (if (and org-agenda-filtered-by-category
  7652. org-agenda-category-filter)
  7653. (org-agenda-filter-show-all-cat)
  7654. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  7655. (cond
  7656. ((and cat strip)
  7657. (org-agenda-filter-apply
  7658. (push (concat "-" cat) org-agenda-category-filter) 'category))
  7659. (cat
  7660. (org-agenda-filter-apply
  7661. (setq org-agenda-category-filter
  7662. (list (concat "+" cat)))
  7663. 'category))
  7664. (t (error "No category at point"))))))
  7665. (defun org-find-top-headline (&optional pos)
  7666. "Find the topmost parent headline and return it.
  7667. POS when non-nil is the marker or buffer position to start the
  7668. search from."
  7669. (save-excursion
  7670. (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
  7671. (when pos (goto-char pos))
  7672. ;; Skip up to the topmost parent.
  7673. (while (org-up-heading-safe))
  7674. (ignore-errors
  7675. (replace-regexp-in-string
  7676. "^\\[[0-9]+/[0-9]+\\] *\\|^\\[%[0-9]+\\] *" ""
  7677. (nth 4 (org-heading-components)))))))
  7678. (defvar org-agenda-filtered-by-top-headline nil)
  7679. (defun org-agenda-filter-by-top-headline (strip)
  7680. "Keep only those lines that are descendants from the same top headline.
  7681. The top headline is that of the current line. With prefix arg STRIP, hide
  7682. all lines of the category at point."
  7683. (interactive "P")
  7684. (if org-agenda-filtered-by-top-headline
  7685. (progn
  7686. (setq org-agenda-filtered-by-top-headline nil
  7687. org-agenda-top-headline-filter nil)
  7688. (org-agenda-filter-show-all-top-filter))
  7689. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  7690. (if toph (org-agenda-filter-top-headline-apply toph strip)
  7691. (error "No top-level headline at point")))))
  7692. (defvar org-agenda-regexp-filter nil)
  7693. (defun org-agenda-filter-by-regexp (strip-or-accumulate)
  7694. "Filter agenda entries by a regular expressions.
  7695. You will be prompted for the regular expression, and the agenda
  7696. view will only show entries that are matched by that expression.
  7697. With one `\\[universal-argument]' prefix argument, hide entries matching the regexp.
  7698. When there is already a regexp filter active, this command removed the
  7699. filter. However, with two `\\[universal-argument]' prefix arguments, add a new condition to
  7700. an already existing regexp filter."
  7701. (interactive "P")
  7702. (let* ((strip (equal strip-or-accumulate '(4)))
  7703. (accumulate (equal strip-or-accumulate '(16))))
  7704. (cond
  7705. ((and org-agenda-regexp-filter (not accumulate))
  7706. (org-agenda-filter-show-all-re)
  7707. (message "Regexp filter removed"))
  7708. (t (let ((flt (concat (if strip "-" "+")
  7709. (read-from-minibuffer
  7710. (if strip
  7711. "Hide entries matching regexp: "
  7712. "Narrow to entries matching regexp: ")))))
  7713. (push flt org-agenda-regexp-filter)
  7714. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))))))
  7715. (defvar org-agenda-effort-filter nil)
  7716. (defun org-agenda-filter-by-effort (strip-or-accumulate)
  7717. "Filter agenda entries by effort.
  7718. With no `\\[universal-argument]' prefix argument, keep entries matching the effort condition.
  7719. With one `\\[universal-argument]' prefix argument, filter out entries matching the condition.
  7720. With two `\\[universal-argument]' prefix arguments, add a second condition to the existing filter.
  7721. This last option is in practice not very useful, but it is available for
  7722. consistency with the other filter commands."
  7723. (interactive "P")
  7724. (let* ((efforts (split-string
  7725. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7726. org-global-properties
  7727. t))
  7728. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
  7729. ;; XXX: the following handles only up to 10 different
  7730. ;; effort values.
  7731. (allowed-keys (if (null efforts) nil
  7732. (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
  7733. (number-sequence 1 (length efforts)))))
  7734. (keep (equal strip-or-accumulate '(16)))
  7735. (negative (equal strip-or-accumulate '(4)))
  7736. (current org-agenda-effort-filter)
  7737. (op nil))
  7738. (while (not (memq op '(?< ?> ?= ?_)))
  7739. (setq op (read-char-exclusive
  7740. "Effort operator? (> = or <) or press `_' again to remove filter")))
  7741. ;; Select appropriate duration. Ignore non-digit characters.
  7742. (if (eq op ?_)
  7743. (progn
  7744. (org-agenda-filter-show-all-effort)
  7745. (message "Effort filter removed"))
  7746. (let ((prompt
  7747. (apply #'format
  7748. (concat "Effort %c "
  7749. (mapconcat (lambda (s) (concat "[%d]" s))
  7750. efforts
  7751. " "))
  7752. op allowed-keys))
  7753. (eff -1))
  7754. (while (not (memq eff allowed-keys))
  7755. (message prompt)
  7756. (setq eff (- (read-char-exclusive) 48)))
  7757. (org-agenda-filter-show-all-effort)
  7758. (setq org-agenda-effort-filter
  7759. (append
  7760. (list (concat (if negative "-" "+")
  7761. (char-to-string op)
  7762. ;; Numbering is 1 2 3 ... 9 0, but we want
  7763. ;; 0 1 2 ... 8 9.
  7764. (nth (mod (1- eff) 10) efforts)))
  7765. (if keep current nil)))
  7766. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))))
  7767. (defun org-agenda-filter (&optional strip-or-accumulate)
  7768. "Prompt for a general filter string and apply it to the agenda.
  7769. The string may contain filter elements like
  7770. +category
  7771. +tag
  7772. +<effort > and = are also allowed as effort operators
  7773. +/regexp/
  7774. Instead of `+', `-' is allowed to strip the agenda of matching entries.
  7775. `+' is optional if it is not required to separate two string parts.
  7776. Multiple filter elements can be concatenated without spaces, for example
  7777. +work-John<0:10-/plot/
  7778. selects entries with category `work' and effort estimates below 10 minutes,
  7779. and deselects entries with tag `John' or matching the regexp `plot'.
  7780. During entry of the filter, completion for tags, categories and effort
  7781. values is offered. Since the syntax for categories and tags is identical
  7782. there should be no overlap between categories and tags. If there is, tags
  7783. get priority.
  7784. A single `\\[universal-argument]' prefix arg STRIP-OR-ACCUMULATE will negate the
  7785. entire filter, which can be useful in connection with the prompt history.
  7786. A double `\\[universal-argument] \\[universal-argument]' prefix arg will add the new filter elements to the
  7787. existing ones. A shortcut for this is to add an additional `+' at the
  7788. beginning of the string, like `+-John'.
  7789. With a triple prefix argument, execute the computed filtering defined in
  7790. the variable `org-agenda-auto-exclude-function'."
  7791. (interactive "P")
  7792. (if (equal strip-or-accumulate '(64))
  7793. ;; Execute the auto-exclude action
  7794. (if (not org-agenda-auto-exclude-function)
  7795. (user-error "`org-agenda-auto-exclude-function' is undefined")
  7796. (org-agenda-filter-show-all-tag)
  7797. (setq org-agenda-tag-filter nil)
  7798. (dolist (tag (org-agenda-get-represented-tags))
  7799. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7800. (when modifier
  7801. (push modifier org-agenda-tag-filter))))
  7802. (unless (null org-agenda-tag-filter)
  7803. (org-agenda-filter-apply org-agenda-tag-filter 'tag 'expand)))
  7804. ;; Prompt for a filter and act
  7805. (let* ((tag-list (org-agenda-get-represented-tags))
  7806. (category-list (org-agenda-get-represented-categories))
  7807. (negate (equal strip-or-accumulate '(4)))
  7808. (cf (mapconcat #'identity org-agenda-category-filter ""))
  7809. (tf (mapconcat #'identity org-agenda-tag-filter ""))
  7810. ;; (rpl-fn (lambda (c) (replace-regexp-in-string "^\\+" "" (or (car c) ""))))
  7811. (ef (replace-regexp-in-string "^\\+" "" (or (car org-agenda-effort-filter) "")))
  7812. (rf (replace-regexp-in-string "^\\+" "" (or (car org-agenda-regexp-filter) "")))
  7813. (ff (concat cf tf ef (when (not (equal rf "")) (concat "/" rf "/"))))
  7814. (f-string (completing-read
  7815. (concat
  7816. (if negate "Negative filter" "Filter")
  7817. " [+cat-tag<0:10-/regexp/]: ")
  7818. #'org-agenda-filter-completion-function
  7819. nil nil ff))
  7820. (keep (or (if (string-match "^\\+[+-]" f-string)
  7821. (progn (setq f-string (substring f-string 1)) t))
  7822. (equal strip-or-accumulate '(16))))
  7823. (fc (if keep org-agenda-category-filter))
  7824. (ft (if keep org-agenda-tag-filter))
  7825. (fe (if keep org-agenda-effort-filter))
  7826. (fr (if keep org-agenda-regexp-filter))
  7827. pm s)
  7828. ;; If the filter contains a double-quoted string, replace a
  7829. ;; single hyphen by the arbitrary and temporary string "~~~"
  7830. ;; to disambiguate such hyphens from syntactic ones.
  7831. (setq f-string (replace-regexp-in-string
  7832. "\"\\([^\"]*\\)-\\([^\"]*\\)\"" "\"\\1~~~\\2\"" f-string))
  7833. (while (string-match "^[ \t]*\\([-+]\\)?\\(\\([^-+<>=/ \t]+\\)\\|\\([<>=][0-9:]+\\)\\|\\(/\\([^/]+\\)/?\\)\\)" f-string)
  7834. (setq pm (if (match-beginning 1) (match-string 1 f-string) "+"))
  7835. (when negate
  7836. (setq pm (if (equal pm "+") "-" "+")))
  7837. (cond
  7838. ((match-beginning 3)
  7839. ;; category or tag
  7840. (setq s (replace-regexp-in-string ; Remove the temporary special string.
  7841. "~~~" "-" (match-string 3 f-string)))
  7842. (cond
  7843. ((member s tag-list)
  7844. (org-pushnew-to-end (concat pm s) ft))
  7845. ((member s category-list)
  7846. (org-pushnew-to-end (concat pm ; Remove temporary double quotes.
  7847. (replace-regexp-in-string "\"\\(.*\\)\"" "\\1" s))
  7848. fc))
  7849. (t (message
  7850. "`%s%s' filter ignored because tag/category is not represented"
  7851. pm s))))
  7852. ((match-beginning 4)
  7853. ;; effort
  7854. (org-pushnew-to-end (concat pm (match-string 4 f-string)) fe))
  7855. ((match-beginning 5)
  7856. ;; regexp
  7857. (org-pushnew-to-end (concat pm (match-string 6 f-string)) fr)))
  7858. (setq f-string (substring f-string (match-end 0))))
  7859. (org-agenda-filter-remove-all)
  7860. (and fc (org-agenda-filter-apply
  7861. (setq org-agenda-category-filter fc) 'category))
  7862. (and ft (org-agenda-filter-apply
  7863. (setq org-agenda-tag-filter ft) 'tag 'expand))
  7864. (and fe (org-agenda-filter-apply
  7865. (setq org-agenda-effort-filter fe) 'effort))
  7866. (and fr (org-agenda-filter-apply
  7867. (setq org-agenda-regexp-filter fr) 'regexp))
  7868. (run-hooks 'org-agenda-filter-hook))))
  7869. (defun org-agenda-filter-completion-function (string _predicate &optional flag)
  7870. "Complete a complex filter string.
  7871. FLAG specifies the type of completion operation to perform. This
  7872. function is passed as a collection function to `completing-read',
  7873. which see."
  7874. (let ((completion-ignore-case t) ;tags are case-sensitive
  7875. (confirm (lambda (x) (stringp x)))
  7876. (prefix "")
  7877. (operator "")
  7878. table)
  7879. (when (string-match "^\\(.*\\([-+<>=]\\)\\)\\([^-+<>=]*\\)$" string)
  7880. (setq prefix (match-string 1 string)
  7881. operator (match-string 2 string)
  7882. string (match-string 3 string)))
  7883. (cond
  7884. ((member operator '("+" "-" "" nil))
  7885. (setq table (append (org-agenda-get-represented-categories)
  7886. (org-agenda-get-represented-tags))))
  7887. ((member operator '("<" ">" "="))
  7888. (setq table (split-string
  7889. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7890. org-global-properties
  7891. t))
  7892. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")
  7893. " +")))
  7894. (t (setq table nil)))
  7895. (pcase flag
  7896. (`t (all-completions string table confirm))
  7897. (`lambda (assoc string table)) ;exact match?
  7898. (`nil
  7899. (pcase (try-completion string table confirm)
  7900. ((and completion (pred stringp))
  7901. (concat prefix completion))
  7902. (completion completion)))
  7903. (_ nil))))
  7904. (defun org-agenda-filter-remove-all ()
  7905. "Remove all filters from the current agenda buffer."
  7906. (interactive)
  7907. (when org-agenda-tag-filter
  7908. (org-agenda-filter-show-all-tag))
  7909. (when org-agenda-category-filter
  7910. (org-agenda-filter-show-all-cat))
  7911. (when org-agenda-regexp-filter
  7912. (org-agenda-filter-show-all-re))
  7913. (when org-agenda-top-headline-filter
  7914. (org-agenda-filter-show-all-top-filter))
  7915. (when org-agenda-effort-filter
  7916. (org-agenda-filter-show-all-effort))
  7917. (org-agenda-finalize)
  7918. (when (called-interactively-p 'interactive)
  7919. (message "All agenda filters removed")))
  7920. (defun org-agenda-filter-by-tag (strip-or-accumulate &optional char exclude)
  7921. "Keep only those lines in the agenda buffer that have a specific tag.
  7922. The tag is selected with its fast selection letter, as configured.
  7923. With a `\\[universal-argument]' prefix, apply the filter negatively, stripping all matches.
  7924. With a `\\[universal-argument] \\[universal-argument]' prefix, add the new tag to the existing filter
  7925. instead of replacing it.
  7926. With a `\\[universal-argument] \\[universal-argument] \\[universal-argument]' prefix, filter the literal tag, \
  7927. i.e. don't
  7928. filter on all its group members.
  7929. A Lisp caller can specify CHAR. EXCLUDE means that the new tag
  7930. should be used to exclude the search - the interactive user can
  7931. also press `-' or `+' to switch between filtering and excluding."
  7932. (interactive "P")
  7933. (let* ((alist org-tag-alist-for-agenda)
  7934. (seen-chars nil)
  7935. (tag-chars (mapconcat
  7936. (lambda (x) (if (and (not (symbolp (car x)))
  7937. (cdr x)
  7938. (not (member (cdr x) seen-chars)))
  7939. (progn
  7940. (push (cdr x) seen-chars)
  7941. (char-to-string (cdr x)))
  7942. ""))
  7943. org-tag-alist-for-agenda ""))
  7944. (valid-char-list (append '(?\t ?\r ?\\ ?. ?\s ?q)
  7945. (string-to-list tag-chars)))
  7946. (exclude (or exclude (equal strip-or-accumulate '(4))))
  7947. (accumulate (equal strip-or-accumulate '(16)))
  7948. (expand (not (equal strip-or-accumulate '(64))))
  7949. (inhibit-read-only t)
  7950. (current org-agenda-tag-filter)
  7951. a tag) ;; n
  7952. (unless char
  7953. (while (not (memq char valid-char-list))
  7954. (org-unlogged-message
  7955. "%s by tag%s: [%s ]tag-char [TAB]tag %s[\\]off [q]uit"
  7956. (if exclude "Exclude[+]" "Filter[-]")
  7957. (if expand "" " (no grouptag expand)")
  7958. tag-chars
  7959. (if org-agenda-auto-exclude-function "[RET] " ""))
  7960. (setq char (read-char-exclusive))
  7961. ;; Excluding or filtering down
  7962. (cond ((eq char ?-) (setq exclude t))
  7963. ((eq char ?+) (setq exclude nil)))))
  7964. (when (eq char ?\t)
  7965. (unless (local-variable-p 'org-global-tags-completion-table)
  7966. (setq-local org-global-tags-completion-table
  7967. (org-global-tags-completion-table)))
  7968. (let ((completion-ignore-case t))
  7969. (setq tag (completing-read
  7970. "Tag: " org-global-tags-completion-table nil t))))
  7971. (cond
  7972. ((eq char ?\r)
  7973. (org-agenda-filter-show-all-tag)
  7974. (when org-agenda-auto-exclude-function
  7975. (setq org-agenda-tag-filter nil)
  7976. (dolist (tag (org-agenda-get-represented-tags))
  7977. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7978. (when modifier
  7979. (push modifier org-agenda-tag-filter))))
  7980. (unless (null org-agenda-tag-filter)
  7981. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  7982. ((eq char ?\\)
  7983. (org-agenda-filter-show-all-tag)
  7984. (when (get 'org-agenda-tag-filter :preset-filter)
  7985. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  7986. ((eq char ?.)
  7987. (setq org-agenda-tag-filter
  7988. (mapcar (lambda(tag) (concat "+" tag))
  7989. (org-get-at-bol 'tags)))
  7990. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7991. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  7992. ((or (eq char ?\s)
  7993. (setq a (rassoc char alist))
  7994. (and tag (setq a (cons tag nil))))
  7995. (org-agenda-filter-show-all-tag)
  7996. (setq tag (car a))
  7997. (setq org-agenda-tag-filter
  7998. (cons (concat (if exclude "-" "+") tag)
  7999. (if accumulate current nil)))
  8000. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  8001. (t (error "Invalid tag selection character %c" char)))))
  8002. (defun org-agenda-get-represented-categories ()
  8003. "Return a list of all categories used in this agenda buffer."
  8004. (or org-agenda-represented-categories
  8005. (when (derived-mode-p 'org-agenda-mode)
  8006. (let ((pos (point-min)) categories)
  8007. (while (and (< pos (point-max))
  8008. (setq pos (next-single-property-change
  8009. pos 'org-category nil (point-max))))
  8010. (push (get-text-property pos 'org-category) categories))
  8011. (setq org-agenda-represented-categories
  8012. ;; Enclose category names with a hyphen in double
  8013. ;; quotes to process them specially in `org-agenda-filter'.
  8014. (mapcar (lambda (s) (if (string-match-p "-" s) (format "\"%s\"" s) s))
  8015. (nreverse (org-uniquify (delq nil categories)))))))))
  8016. (defvar org-tag-groups-alist-for-agenda)
  8017. (defun org-agenda-get-represented-tags ()
  8018. "Return a list of all tags used in this agenda buffer.
  8019. These will be lower-case, for filtering."
  8020. (or org-agenda-represented-tags
  8021. (when (derived-mode-p 'org-agenda-mode)
  8022. (let ((pos (point-min)) tags-lists tt)
  8023. (while (and (< pos (point-max))
  8024. (setq pos (next-single-property-change
  8025. pos 'tags nil (point-max))))
  8026. (setq tt (get-text-property pos 'tags))
  8027. (if tt (push tt tags-lists)))
  8028. (setq tags-lists
  8029. (nreverse (org-uniquify
  8030. (delq nil (apply #'append tags-lists)))))
  8031. (dolist (tag tags-lists)
  8032. (mapc
  8033. (lambda (group)
  8034. (when (member tag group)
  8035. (push (car group) tags-lists)))
  8036. org-tag-groups-alist-for-agenda))
  8037. (setq org-agenda-represented-tags tags-lists)))))
  8038. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  8039. "Create the form that tests a line for agenda filter.
  8040. Optional argument EXPAND can be used for the TYPE tag and will
  8041. expand the tags in the FILTER if any of the tags in FILTER are
  8042. grouptags."
  8043. (let ((multi-pos-cats
  8044. (and (eq type 'category)
  8045. (string-match-p "\\+.*\\+"
  8046. (mapconcat (lambda (cat) (substring cat 0 1))
  8047. filter ""))))
  8048. f f1)
  8049. (cond
  8050. ;; Tag filter
  8051. ((eq type 'tag)
  8052. (setq filter
  8053. (delete-dups
  8054. (append (get 'org-agenda-tag-filter :preset-filter)
  8055. filter)))
  8056. (dolist (x filter)
  8057. (let ((op (string-to-char x)))
  8058. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  8059. (setq x (list x)))
  8060. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  8061. (push f1 f))))
  8062. ;; Category filter
  8063. ((eq type 'category)
  8064. (setq filter
  8065. (delete-dups
  8066. (append (get 'org-agenda-category-filter :preset-filter)
  8067. filter)))
  8068. (dolist (x filter)
  8069. (if (equal "-" (substring x 0 1))
  8070. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  8071. (setq f1 (list 'equal (substring x 1) 'cat)))
  8072. (push f1 f)))
  8073. ;; Regexp filter
  8074. ((eq type 'regexp)
  8075. (setq filter
  8076. (delete-dups
  8077. (append (get 'org-agenda-regexp-filter :preset-filter)
  8078. filter)))
  8079. (dolist (x filter)
  8080. (if (equal "-" (substring x 0 1))
  8081. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  8082. (setq f1 (list 'string-match (substring x 1) 'txt)))
  8083. (push f1 f)))
  8084. ;; Effort filter
  8085. ((eq type 'effort)
  8086. (setq filter
  8087. (delete-dups
  8088. (append (get 'org-agenda-effort-filter :preset-filter)
  8089. filter)))
  8090. (dolist (x filter)
  8091. (push (org-agenda-filter-effort-form x) f))))
  8092. (cons (if multi-pos-cats 'or 'and) (nreverse f))))
  8093. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  8094. "Return a form associated to tag-expression TAGS.
  8095. Build a form testing a line for agenda filter for
  8096. tag-expressions. OP is an operator of type CHAR that allows the
  8097. function to set the right switches in the returned form."
  8098. (let (form)
  8099. ;; Any of the expressions can match if OP is +, all must match if
  8100. ;; the operator is -.
  8101. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  8102. (let* ((tag (substring x 1))
  8103. (f (cond
  8104. ((string= "" tag) 'tags)
  8105. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  8106. ;; TAG is a regexp.
  8107. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  8108. (t (list 'member tag 'tags)))))
  8109. (push (if (eq op ?-) (list 'not f) f) form)))))
  8110. (defun org-agenda-filter-effort-form (e)
  8111. "Return the form to compare the effort of the current line with what E says.
  8112. E looks like \"+<2:25\"."
  8113. (let (op)
  8114. (setq e (substring e 1))
  8115. (setq op (string-to-char e) e (substring e 1))
  8116. (setq op (cond ((equal op ?<) '<=)
  8117. ((equal op ?>) '>=)
  8118. ((equal op ??) op)
  8119. (t '=)))
  8120. (list 'org-agenda-compare-effort (list 'quote op)
  8121. (org-duration-to-minutes e))))
  8122. (defun org-agenda-compare-effort (op value)
  8123. "Compare the effort of the current line with VALUE, using OP.
  8124. If the line does not have an effort defined, return nil."
  8125. ;; `effort-minutes' property cannot be extracted directly from
  8126. ;; current line but is stored as a property in `txt'.
  8127. (let ((effort (get-text-property 0 'effort-minutes (org-get-at-bol 'txt))))
  8128. (funcall op
  8129. (or effort (if org-agenda-sort-noeffort-is-high 32767 -1))
  8130. value)))
  8131. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  8132. "Expand group tags in FILTER for the agenda.
  8133. When NO-OPERATOR is non-nil, do not add the + operator to
  8134. returned tags."
  8135. (if org-group-tags
  8136. (let (case-fold-search rtn)
  8137. (mapc
  8138. (lambda (f)
  8139. (let (f0 dir)
  8140. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  8141. (setq dir (match-string 1 f) f0 (match-string 2 f))
  8142. (setq dir (if no-operator "" "+") f0 f))
  8143. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  8144. (org-tags-expand f0 t))
  8145. rtn))))
  8146. filter)
  8147. (reverse rtn))
  8148. filter))
  8149. (defun org-agenda-filter-apply (filter type &optional expand)
  8150. "Set FILTER as the new agenda filter and apply it.
  8151. Optional argument EXPAND can be used for the TYPE tag and will
  8152. expand the tags in the FILTER if any of the tags in FILTER are
  8153. grouptags."
  8154. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  8155. (when org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  8156. (setq org-agenda-filter-form (org-agenda-filter-make-matcher
  8157. filter type expand))
  8158. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  8159. ;; category is used as the filter:
  8160. (setq org-agenda-filtered-by-category
  8161. (and (eq type 'category)
  8162. (not (equal (substring (car filter) 0 1) "-"))))
  8163. (org-agenda-set-mode-name)
  8164. (save-excursion
  8165. (goto-char (point-min))
  8166. (while (not (eobp))
  8167. (when (or (org-get-at-bol 'org-hd-marker)
  8168. (org-get-at-bol 'org-marker))
  8169. (org-dlet
  8170. ((tags (org-get-at-bol 'tags))
  8171. (cat (org-agenda-get-category))
  8172. (txt (or (org-get-at-bol 'txt) "")))
  8173. (unless (eval org-agenda-filter-form t)
  8174. (org-agenda-filter-hide-line type))))
  8175. (beginning-of-line 2)))
  8176. (when (get-char-property (point) 'invisible)
  8177. (ignore-errors (org-agenda-previous-line))))
  8178. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  8179. "Filter by top headline HL."
  8180. (org-agenda-set-mode-name)
  8181. (save-excursion
  8182. (goto-char (point-min))
  8183. (while (not (eobp))
  8184. (let* ((pos (org-get-at-bol 'org-hd-marker))
  8185. (tophl (and pos (org-find-top-headline pos))))
  8186. (when (and tophl (funcall (if negative 'identity 'not)
  8187. (string= hl tophl)))
  8188. (org-agenda-filter-hide-line 'top-headline)))
  8189. (beginning-of-line 2)))
  8190. (when (get-char-property (point) 'invisible)
  8191. (org-agenda-previous-line))
  8192. (setq org-agenda-top-headline-filter hl
  8193. org-agenda-filtered-by-top-headline t))
  8194. (defun org-agenda-filter-hide-line (type)
  8195. "If current line is TYPE, hide it in the agenda buffer."
  8196. (let* (buffer-invisibility-spec
  8197. (beg (max (point-min) (1- (line-beginning-position))))
  8198. (end (line-end-position)))
  8199. (let ((inhibit-read-only t))
  8200. (add-text-properties
  8201. beg end `(invisible org-filtered org-filter-type ,type)))))
  8202. (defun org-agenda-remove-filter (type)
  8203. "Remove filter of type TYPE from the agenda buffer."
  8204. (interactive)
  8205. (save-excursion
  8206. (goto-char (point-min))
  8207. (let ((inhibit-read-only t) pos)
  8208. (while (setq pos (text-property-any (point) (point-max)
  8209. 'org-filter-type type))
  8210. (goto-char pos)
  8211. (remove-text-properties
  8212. (point) (next-single-property-change (point) 'org-filter-type)
  8213. `(invisible org-filtered org-filter-type ,type))))
  8214. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  8215. (setq org-agenda-filter-form nil)
  8216. (org-agenda-set-mode-name)
  8217. (org-agenda-finalize)))
  8218. (defun org-agenda-filter-show-all-tag nil
  8219. (org-agenda-remove-filter 'tag))
  8220. (defun org-agenda-filter-show-all-re nil
  8221. (org-agenda-remove-filter 'regexp))
  8222. (defun org-agenda-filter-show-all-effort nil
  8223. (org-agenda-remove-filter 'effort))
  8224. (defun org-agenda-filter-show-all-cat nil
  8225. (org-agenda-remove-filter 'category))
  8226. (defun org-agenda-filter-show-all-top-filter nil
  8227. (org-agenda-remove-filter 'top-headline))
  8228. (defun org-agenda-manipulate-query-add ()
  8229. "Manipulate the query by adding a search term with positive selection.
  8230. Positive selection means the term must be matched for selection of an entry."
  8231. (interactive)
  8232. (org-agenda-manipulate-query ?\[))
  8233. (defun org-agenda-manipulate-query-subtract ()
  8234. "Manipulate the query by adding a search term with negative selection.
  8235. Negative selection means term must not be matched for selection of an entry."
  8236. (interactive)
  8237. (org-agenda-manipulate-query ?\]))
  8238. (defun org-agenda-manipulate-query-add-re ()
  8239. "Manipulate the query by adding a search regexp with positive selection.
  8240. Positive selection means the regexp must match for selection of an entry."
  8241. (interactive)
  8242. (org-agenda-manipulate-query ?\{))
  8243. (defun org-agenda-manipulate-query-subtract-re ()
  8244. "Manipulate the query by adding a search regexp with negative selection.
  8245. Negative selection means regexp must not match for selection of an entry."
  8246. (interactive)
  8247. (org-agenda-manipulate-query ?\}))
  8248. (defun org-agenda-manipulate-query (char)
  8249. (cond
  8250. ((eq org-agenda-type 'agenda)
  8251. (let ((org-agenda-include-inactive-timestamps t))
  8252. (org-agenda-redo))
  8253. (message "Display now includes inactive timestamps as well"))
  8254. ((eq org-agenda-type 'search)
  8255. (org-add-to-string
  8256. 'org-agenda-query-string
  8257. (if org-agenda-last-search-view-search-was-boolean
  8258. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  8259. (?\{ . " +{}") (?\} . " -{}"))))
  8260. " "))
  8261. (setq org-agenda-redo-command
  8262. (list 'org-search-view
  8263. (car (get-text-property (min (1- (point-max)) (point))
  8264. 'org-last-args))
  8265. org-agenda-query-string
  8266. (+ (length org-agenda-query-string)
  8267. (if (member char '(?\{ ?\})) 0 1))))
  8268. (set-register org-agenda-query-register org-agenda-query-string)
  8269. (let ((org-agenda-overriding-arguments
  8270. (cdr org-agenda-redo-command)))
  8271. (org-agenda-redo)))
  8272. (t (error "Cannot manipulate query for %s-type agenda buffers"
  8273. org-agenda-type))))
  8274. (defun org-add-to-string (var string)
  8275. (set var (concat (symbol-value var) string)))
  8276. (defun org-agenda-goto-date (date)
  8277. "Jump to DATE in the agenda buffer.
  8278. When called interactively, prompt for the date.
  8279. When called from Lisp, DATE should be a date as returned by
  8280. `org-read-date'.
  8281. See also:
  8282. `org-agenda-earlier' (\\[org-agenda-earlier])
  8283. `org-agenda-later' (\\[org-agenda-later])
  8284. `org-agenda-goto-today' (\\[org-agenda-goto-today])"
  8285. (interactive
  8286. (list
  8287. (let ((org-read-date-prefer-future org-agenda-jump-prefer-future))
  8288. (org-read-date))))
  8289. (let* ((day (time-to-days (org-time-string-to-time date)))
  8290. (org-agenda-sticky-orig org-agenda-sticky)
  8291. (org-agenda-buffer-tmp-name (buffer-name))
  8292. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8293. (0-arg (or current-prefix-arg (car args)))
  8294. (2-arg (nth 2 args))
  8295. (with-hour-p (nth 4 org-agenda-redo-command))
  8296. (newcmd (list 'org-agenda-list 0-arg date
  8297. (org-agenda-span-to-ndays
  8298. 2-arg (org-time-string-to-absolute date))
  8299. with-hour-p))
  8300. (newargs (cdr newcmd))
  8301. (inhibit-read-only t)
  8302. org-agenda-sticky)
  8303. (if (not (org-agenda-check-type t 'agenda))
  8304. (error "Not available in non-agenda views")
  8305. (add-text-properties (point-min) (point-max)
  8306. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  8307. (org-agenda-redo)
  8308. (goto-char (point-min))
  8309. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  8310. (save-excursion (move-beginning-of-line 2) (eobp))))
  8311. (move-beginning-of-line 2))
  8312. (setq org-agenda-sticky org-agenda-sticky-orig
  8313. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  8314. (defun org-agenda-goto-today ()
  8315. "Go to today's date in the agenda buffer.
  8316. See also:
  8317. `org-agenda-later' (\\[org-agenda-later])
  8318. `org-agenda-earlier' (\\[org-agenda-earlier])
  8319. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8320. (interactive)
  8321. (org-agenda-check-type t 'agenda)
  8322. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8323. (curspan (nth 2 args))
  8324. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  8325. (cond
  8326. (tdpos (goto-char tdpos))
  8327. ((eq org-agenda-type 'agenda)
  8328. (let* ((sd (org-agenda-compute-starting-span
  8329. (org-today) (or curspan org-agenda-span)))
  8330. (org-agenda-overriding-arguments args))
  8331. (setf (nth 1 org-agenda-overriding-arguments) sd)
  8332. (org-agenda-redo)
  8333. (org-agenda-find-same-or-today-or-agenda)))
  8334. (t (error "Cannot find today")))))
  8335. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  8336. (goto-char
  8337. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  8338. (text-property-any (point-min) (point-max) 'org-today t)
  8339. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  8340. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  8341. (org-agenda-backward-block))
  8342. (point-min))))
  8343. (defun org-agenda-backward-block ()
  8344. "Move backward by one agenda block."
  8345. (interactive)
  8346. (org-agenda-forward-block 'backward))
  8347. (defun org-agenda-forward-block (&optional backward)
  8348. "Move forward by one agenda block.
  8349. When optional argument BACKWARD is set, go backward."
  8350. (interactive)
  8351. (cond ((not (derived-mode-p 'org-agenda-mode))
  8352. (user-error
  8353. "Cannot execute this command outside of org-agenda-mode buffers"))
  8354. ((looking-at (if backward "\\`" "\\'"))
  8355. (message "Already at the %s block" (if backward "first" "last")))
  8356. (t (let ((_pos (prog1 (point)
  8357. (ignore-errors (if backward (backward-char 1)
  8358. (move-end-of-line 1)))))
  8359. (f (if backward
  8360. #'previous-single-property-change
  8361. #'next-single-property-change))
  8362. moved dest)
  8363. (while (and (setq dest (funcall
  8364. f (point) 'org-agenda-structural-header))
  8365. (not (get-text-property
  8366. (point) 'org-agenda-structural-header)))
  8367. (setq moved t)
  8368. (goto-char dest))
  8369. (if moved (move-beginning-of-line 1)
  8370. (goto-char (if backward (point-min) (point-max)))
  8371. (move-beginning-of-line 1)
  8372. (message "No %s block" (if backward "previous" "further")))))))
  8373. (defun org-agenda-later (arg)
  8374. "Go forward in time by the current span in the agenda buffer.
  8375. With prefix ARG, go forward that many times the current span.
  8376. See also:
  8377. `org-agenda-earlier' (\\[org-agenda-earlier])
  8378. `org-agenda-goto-today' (\\[org-agenda-goto-today])
  8379. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8380. (interactive "p")
  8381. (org-agenda-check-type t 'agenda)
  8382. (let* ((wstart (window-start))
  8383. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8384. (span (or (nth 2 args) org-agenda-current-span))
  8385. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  8386. (greg (calendar-gregorian-from-absolute sd))
  8387. (cnt (org-get-at-bol 'org-day-cnt))
  8388. greg2)
  8389. (cond
  8390. ((numberp span)
  8391. (setq sd (+ (* span arg) sd)))
  8392. ((eq span 'day)
  8393. (setq sd (+ arg sd)))
  8394. ((eq span 'week)
  8395. (setq sd (+ (* 7 arg) sd)))
  8396. ((eq span 'fortnight)
  8397. (setq sd (+ (* 14 arg) sd)))
  8398. ((eq span 'month)
  8399. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  8400. sd (calendar-absolute-from-gregorian greg2))
  8401. (setcar greg2 (1+ (car greg2))))
  8402. ((eq span 'year)
  8403. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  8404. sd (calendar-absolute-from-gregorian greg2))
  8405. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  8406. (t
  8407. (setq sd (+ (* span arg) sd))))
  8408. (let ((org-agenda-overriding-cmd
  8409. ;; `cmd' may have been set by `org-agenda-run-series' which
  8410. ;; uses `org-agenda-overriding-cmd' to decide whether
  8411. ;; overriding is allowed for `cmd'
  8412. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  8413. (org-agenda-overriding-arguments
  8414. (list (car args) sd span)))
  8415. (org-agenda-redo)
  8416. (org-agenda-find-same-or-today-or-agenda cnt))
  8417. (set-window-start nil wstart)))
  8418. (defun org-agenda-earlier (arg)
  8419. "Go backward in time by the current span in the agenda buffer.
  8420. With prefix ARG, go backward that many times the current span.
  8421. See also:
  8422. `org-agenda-later' (\\[org-agenda-later])
  8423. `org-agenda-goto-today' (\\[org-agenda-goto-today])
  8424. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8425. (interactive "p")
  8426. (org-agenda-later (- arg)))
  8427. (defun org-agenda-view-mode-dispatch ()
  8428. "Call one of the view mode commands."
  8429. (interactive)
  8430. (org-unlogged-message
  8431. "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  8432. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  8433. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  8434. (pcase (read-char-exclusive)
  8435. (?\ (call-interactively 'org-agenda-reset-view))
  8436. (?d (call-interactively 'org-agenda-day-view))
  8437. (?w (call-interactively 'org-agenda-week-view))
  8438. (?t (call-interactively 'org-agenda-fortnight-view))
  8439. (?m (call-interactively 'org-agenda-month-view))
  8440. (?y (call-interactively 'org-agenda-year-view))
  8441. (?l (call-interactively 'org-agenda-log-mode))
  8442. (?L (org-agenda-log-mode '(4)))
  8443. (?c (org-agenda-log-mode 'clockcheck))
  8444. ((or ?F ?f) (call-interactively 'org-agenda-follow-mode))
  8445. (?a (call-interactively 'org-agenda-archives-mode))
  8446. (?A (org-agenda-archives-mode 'files))
  8447. ((or ?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  8448. ((or ?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  8449. (?G (call-interactively 'org-agenda-toggle-time-grid))
  8450. (?D (call-interactively 'org-agenda-toggle-diary))
  8451. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  8452. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  8453. (org-agenda-check-type t 'agenda)
  8454. (org-agenda-redo))
  8455. (message "Display now includes inactive timestamps as well"))
  8456. (?q (message "Abort"))
  8457. (key (user-error "Invalid key: %s" key))))
  8458. (defun org-agenda-reset-view ()
  8459. "Switch to default view for agenda."
  8460. (interactive)
  8461. (org-agenda-change-time-span org-agenda-span))
  8462. (defun org-agenda-day-view (&optional day-of-month)
  8463. "Switch to daily view for agenda.
  8464. With argument DAY-OF-MONTH, switch to that day of the month."
  8465. (interactive "P")
  8466. (org-agenda-change-time-span 'day day-of-month))
  8467. (defun org-agenda-week-view (&optional iso-week)
  8468. "Switch to weekly view for agenda.
  8469. With argument ISO-WEEK, switch to the corresponding ISO week.
  8470. If ISO-WEEK has more then 2 digits, only the last two encode
  8471. the week. Any digits before this encode a year. So 200712
  8472. means week 12 of year 2007. Years ranging from 70 years ago
  8473. to 30 years in the future can also be written as 2-digit years."
  8474. (interactive "P")
  8475. (org-agenda-change-time-span 'week iso-week))
  8476. (defun org-agenda-fortnight-view (&optional iso-week)
  8477. "Switch to fortnightly view for agenda.
  8478. With argument ISO-WEEK, switch to the corresponding ISO week.
  8479. If ISO-WEEK has more then 2 digits, only the last two encode
  8480. the week. Any digits before this encode a year. So 200712
  8481. means week 12 of year 2007. Years ranging from 70 years ago
  8482. to 30 years in the future can also be written as 2-digit years."
  8483. (interactive "P")
  8484. (org-agenda-change-time-span 'fortnight iso-week))
  8485. (defun org-agenda-month-view (&optional month)
  8486. "Switch to monthly view for agenda.
  8487. With argument MONTH, switch to that month. If MONTH has more
  8488. then 2 digits, only the last two encode the month. Any digits
  8489. before this encode a year. So 200712 means December year 2007.
  8490. Years ranging from 70 years ago to 30 years in the future can
  8491. also be written as 2-digit years."
  8492. (interactive "P")
  8493. (org-agenda-change-time-span 'month month))
  8494. (defun org-agenda-year-view (&optional year)
  8495. "Switch to yearly view for agenda.
  8496. With argument YEAR, switch to that year. Years ranging from 70
  8497. years ago to 30 years in the future can also be written as
  8498. 2-digit years."
  8499. (interactive "P")
  8500. (when year
  8501. (setq year (org-small-year-to-year year)))
  8502. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  8503. (org-agenda-change-time-span 'year year)
  8504. (error "Abort")))
  8505. (defun org-agenda-change-time-span (span &optional n)
  8506. "Change the agenda view to SPAN.
  8507. SPAN may be `day', `week', `fortnight', `month', `year'."
  8508. (org-agenda-check-type t 'agenda)
  8509. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8510. (curspan (nth 2 args)))
  8511. (when (and (not n) (equal curspan span))
  8512. (error "Viewing span is already \"%s\"" span))
  8513. (let* ((sd (or (org-get-at-bol 'day)
  8514. (nth 1 args)
  8515. org-starting-day))
  8516. (sd (org-agenda-compute-starting-span sd span n))
  8517. (org-agenda-overriding-cmd
  8518. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  8519. (org-agenda-overriding-arguments
  8520. (list (car args) sd span)))
  8521. (org-agenda-redo)
  8522. (org-agenda-find-same-or-today-or-agenda))
  8523. (org-agenda-set-mode-name)
  8524. (message "Switched to %s view" span)))
  8525. (defun org-agenda-compute-starting-span (sd span &optional n)
  8526. "Compute starting date for agenda.
  8527. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  8528. is a cons cell with the starting date and the number of days,
  8529. so that the date SD will be in that range."
  8530. (let* ((greg (calendar-gregorian-from-absolute sd))
  8531. ;; (dg (nth 1 greg))
  8532. (mg (car greg))
  8533. (yg (nth 2 greg)))
  8534. (cond
  8535. ((eq span 'day)
  8536. (when n
  8537. (setq sd (+ (calendar-absolute-from-gregorian
  8538. (list mg 1 yg))
  8539. n -1))))
  8540. ((or (eq span 'week) (eq span 'fortnight))
  8541. (let* ((nt (calendar-day-of-week
  8542. (calendar-gregorian-from-absolute sd)))
  8543. (d (if org-agenda-start-on-weekday
  8544. (- nt org-agenda-start-on-weekday)
  8545. 0))
  8546. y1)
  8547. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  8548. (when n
  8549. (require 'cal-iso)
  8550. (when (> n 99)
  8551. (setq y1 (org-small-year-to-year (/ n 100))
  8552. n (mod n 100)))
  8553. (setq sd
  8554. (calendar-iso-to-absolute
  8555. (list n 1
  8556. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  8557. ((eq span 'month)
  8558. (let (y1)
  8559. (when (and n (> n 99))
  8560. (setq y1 (org-small-year-to-year (/ n 100))
  8561. n (mod n 100)))
  8562. (setq sd (calendar-absolute-from-gregorian
  8563. (list (or n mg) 1 (or y1 yg))))))
  8564. ((eq span 'year)
  8565. (setq sd (calendar-absolute-from-gregorian
  8566. (list 1 1 (or n yg))))))
  8567. sd))
  8568. (defun org-agenda-next-date-line (&optional arg)
  8569. "Jump to the next line indicating a date in agenda buffer."
  8570. (interactive "p")
  8571. (org-agenda-check-type t 'agenda)
  8572. (beginning-of-line 1)
  8573. ;; This does not work if user makes date format that starts with a blank
  8574. (when (looking-at-p "^\\S-") (forward-char 1))
  8575. (unless (re-search-forward "^\\S-" nil t arg)
  8576. (backward-char 1)
  8577. (error "No next date after this line in this buffer"))
  8578. (goto-char (match-beginning 0)))
  8579. (defun org-agenda-previous-date-line (&optional arg)
  8580. "Jump to the previous line indicating a date in agenda buffer."
  8581. (interactive "p")
  8582. (org-agenda-check-type t 'agenda)
  8583. (beginning-of-line 1)
  8584. (unless (re-search-backward "^\\S-" nil t arg)
  8585. (error "No previous date before this line in this buffer")))
  8586. ;; Initialize the highlight
  8587. (defvar org-hl (make-overlay 1 1))
  8588. (overlay-put org-hl 'face 'highlight)
  8589. (defun org-highlight (begin end &optional buffer)
  8590. "Highlight a region with overlay."
  8591. (move-overlay org-hl begin end (or buffer (current-buffer))))
  8592. (defun org-unhighlight ()
  8593. "Detach overlay INDEX."
  8594. (delete-overlay org-hl))
  8595. (defun org-unhighlight-once ()
  8596. "Remove the highlight from its position, and this function from the hook."
  8597. (remove-hook 'pre-command-hook #'org-unhighlight-once)
  8598. (org-unhighlight))
  8599. (defvar org-agenda-pre-follow-window-conf nil)
  8600. (defun org-agenda-follow-mode ()
  8601. "Toggle follow mode in an agenda buffer."
  8602. (interactive)
  8603. (unless org-agenda-follow-mode
  8604. (setq org-agenda-pre-follow-window-conf
  8605. (current-window-configuration)))
  8606. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  8607. (unless org-agenda-follow-mode
  8608. (set-window-configuration org-agenda-pre-follow-window-conf))
  8609. (org-agenda-set-mode-name)
  8610. (org-agenda-do-context-action)
  8611. (message "Follow mode is %s"
  8612. (if org-agenda-follow-mode "on" "off")))
  8613. (defun org-agenda-entry-text-mode (&optional arg)
  8614. "Toggle entry text mode in an agenda buffer."
  8615. (interactive "P")
  8616. (if (or org-agenda-tag-filter
  8617. org-agenda-category-filter
  8618. org-agenda-regexp-filter
  8619. org-agenda-top-headline-filter)
  8620. (user-error "Can't show entry text in filtered views")
  8621. (setq org-agenda-entry-text-mode (or (integerp arg)
  8622. (not org-agenda-entry-text-mode)))
  8623. (org-agenda-entry-text-hide)
  8624. (and org-agenda-entry-text-mode
  8625. (let ((org-agenda-entry-text-maxlines
  8626. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  8627. (org-agenda-entry-text-show)))
  8628. (org-agenda-set-mode-name)
  8629. (message "Entry text mode is %s%s"
  8630. (if org-agenda-entry-text-mode "on" "off")
  8631. (if (not org-agenda-entry-text-mode) ""
  8632. (format " (maximum number of lines is %d)"
  8633. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  8634. (defun org-agenda-clockreport-mode ()
  8635. "Toggle clocktable mode in an agenda buffer."
  8636. (interactive)
  8637. (org-agenda-check-type t 'agenda)
  8638. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  8639. (org-agenda-set-mode-name)
  8640. (org-agenda-redo)
  8641. (message "Clocktable mode is %s"
  8642. (if org-agenda-clockreport-mode "on" "off")))
  8643. (defun org-agenda-log-mode (&optional special)
  8644. "Toggle log mode in an agenda buffer.
  8645. With argument SPECIAL, show all possible log items, not only the ones
  8646. configured in `org-agenda-log-mode-items'.
  8647. With a `\\[universal-argument] \\[universal-argument]' prefix, show *only* \
  8648. log items, nothing else."
  8649. (interactive "P")
  8650. (org-agenda-check-type t 'agenda)
  8651. (setq org-agenda-show-log
  8652. (cond
  8653. ((equal special '(16)) 'only)
  8654. ((eq special 'clockcheck)
  8655. (if (eq org-agenda-show-log 'clockcheck)
  8656. nil 'clockcheck))
  8657. (special '(closed clock state))
  8658. (t (not org-agenda-show-log))))
  8659. (org-agenda-set-mode-name)
  8660. (org-agenda-redo)
  8661. (message "Log mode is %s" (if org-agenda-show-log "on" "off")))
  8662. (defun org-agenda-archives-mode (&optional with-files)
  8663. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  8664. When called with a prefix argument, include all archive files as well."
  8665. (interactive "P")
  8666. (setq org-agenda-archives-mode
  8667. (cond ((and with-files (eq org-agenda-archives-mode t)) nil)
  8668. (with-files t)
  8669. (org-agenda-archives-mode nil)
  8670. (t 'trees)))
  8671. (org-agenda-set-mode-name)
  8672. (org-agenda-redo)
  8673. (message
  8674. "%s"
  8675. (cond
  8676. ((eq org-agenda-archives-mode nil)
  8677. "No archives are included")
  8678. ((eq org-agenda-archives-mode 'trees)
  8679. (format "Trees with :%s: tag are included" org-archive-tag))
  8680. ((eq org-agenda-archives-mode t)
  8681. (format "Trees with :%s: tag and all active archive files are included"
  8682. org-archive-tag)))))
  8683. (defun org-agenda-toggle-diary ()
  8684. "Toggle diary inclusion in an agenda buffer."
  8685. (interactive)
  8686. (org-agenda-check-type t 'agenda)
  8687. (setq org-agenda-include-diary (not org-agenda-include-diary))
  8688. (org-agenda-redo)
  8689. (org-agenda-set-mode-name)
  8690. (message "Diary inclusion turned %s"
  8691. (if org-agenda-include-diary "on" "off")))
  8692. (defun org-agenda-toggle-deadlines ()
  8693. "Toggle inclusion of entries with a deadline in an agenda buffer."
  8694. (interactive)
  8695. (org-agenda-check-type t 'agenda)
  8696. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  8697. (org-agenda-redo)
  8698. (org-agenda-set-mode-name)
  8699. (message "Deadlines inclusion turned %s"
  8700. (if org-agenda-include-deadlines "on" "off")))
  8701. (defun org-agenda-toggle-time-grid ()
  8702. "Toggle time grid in an agenda buffer."
  8703. (interactive)
  8704. (org-agenda-check-type t 'agenda)
  8705. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  8706. (org-agenda-redo)
  8707. (org-agenda-set-mode-name)
  8708. (message "Time-grid turned %s"
  8709. (if org-agenda-use-time-grid "on" "off")))
  8710. (defun org-agenda-set-mode-name ()
  8711. "Set the mode name to indicate all the small mode settings."
  8712. (setq mode-name
  8713. (list "Org-Agenda"
  8714. (if (get 'org-agenda-files 'org-restrict) " []" "")
  8715. " "
  8716. '(:eval (org-agenda-span-name org-agenda-current-span))
  8717. (if org-agenda-follow-mode " Follow" "")
  8718. (if org-agenda-entry-text-mode " ETxt" "")
  8719. (if org-agenda-include-diary " Diary" "")
  8720. (if org-agenda-include-deadlines " Ddl" "")
  8721. (if org-agenda-use-time-grid " Grid" "")
  8722. (if (and (boundp 'org-habit-show-habits)
  8723. org-habit-show-habits)
  8724. " Habit" "")
  8725. (cond
  8726. ((consp org-agenda-show-log) " LogAll")
  8727. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  8728. (org-agenda-show-log " Log")
  8729. (t ""))
  8730. (if (org-agenda-filter-any) " " "")
  8731. (if (or org-agenda-category-filter
  8732. (get 'org-agenda-category-filter :preset-filter))
  8733. '(:eval (propertize
  8734. (concat "["
  8735. (mapconcat
  8736. #'identity
  8737. (append
  8738. (get 'org-agenda-category-filter :preset-filter)
  8739. org-agenda-category-filter)
  8740. "")
  8741. "]")
  8742. 'face 'org-agenda-filter-category
  8743. 'help-echo "Category used in filtering"))
  8744. "")
  8745. (if (or org-agenda-tag-filter
  8746. (get 'org-agenda-tag-filter :preset-filter))
  8747. '(:eval (propertize
  8748. (concat (mapconcat
  8749. #'identity
  8750. (append
  8751. (get 'org-agenda-tag-filter :preset-filter)
  8752. org-agenda-tag-filter)
  8753. ""))
  8754. 'face 'org-agenda-filter-tags
  8755. 'help-echo "Tags used in filtering"))
  8756. "")
  8757. (if (or org-agenda-effort-filter
  8758. (get 'org-agenda-effort-filter :preset-filter))
  8759. '(:eval (propertize
  8760. (concat (mapconcat
  8761. #'identity
  8762. (append
  8763. (get 'org-agenda-effort-filter :preset-filter)
  8764. org-agenda-effort-filter)
  8765. ""))
  8766. 'face 'org-agenda-filter-effort
  8767. 'help-echo "Effort conditions used in filtering"))
  8768. "")
  8769. (if (or org-agenda-regexp-filter
  8770. (get 'org-agenda-regexp-filter :preset-filter))
  8771. '(:eval (propertize
  8772. (concat (mapconcat
  8773. (lambda (x) (concat (substring x 0 1) "/" (substring x 1) "/"))
  8774. (append
  8775. (get 'org-agenda-regexp-filter :preset-filter)
  8776. org-agenda-regexp-filter)
  8777. ""))
  8778. 'face 'org-agenda-filter-regexp
  8779. 'help-echo "Regexp used in filtering"))
  8780. "")
  8781. (if org-agenda-archives-mode
  8782. (if (eq org-agenda-archives-mode t)
  8783. " Archives"
  8784. (format " :%s:" org-archive-tag))
  8785. "")
  8786. (if org-agenda-clockreport-mode " Clock" "")))
  8787. (force-mode-line-update))
  8788. (defun org-agenda-update-agenda-type ()
  8789. "Update the agenda type after each command."
  8790. (setq org-agenda-type
  8791. (or (get-text-property (point) 'org-agenda-type)
  8792. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  8793. (defun org-agenda-next-line ()
  8794. "Move cursor to the next line, and show if follow mode is active."
  8795. (interactive)
  8796. (call-interactively 'next-line)
  8797. (org-agenda-do-context-action))
  8798. (defun org-agenda-previous-line ()
  8799. "Move cursor to the previous line, and show if follow-mode is active."
  8800. (interactive)
  8801. (call-interactively 'previous-line)
  8802. (org-agenda-do-context-action))
  8803. (defun org-agenda-next-item (n)
  8804. "Move cursor to next agenda item."
  8805. (interactive "p")
  8806. (let ((col (current-column)))
  8807. (dotimes (_ n)
  8808. (when (next-single-property-change (line-end-position) 'org-marker)
  8809. (move-end-of-line 1)
  8810. (goto-char (next-single-property-change (point) 'org-marker))))
  8811. (org-move-to-column col))
  8812. (org-agenda-do-context-action))
  8813. (defun org-agenda-previous-item (n)
  8814. "Move cursor to next agenda item."
  8815. (interactive "p")
  8816. (dotimes (_ n)
  8817. (let ((col (current-column))
  8818. (goto (save-excursion
  8819. (move-end-of-line 0)
  8820. (previous-single-property-change (point) 'org-marker))))
  8821. (when goto (goto-char goto))
  8822. (org-move-to-column col)))
  8823. (org-agenda-do-context-action))
  8824. (defun org-agenda-do-context-action ()
  8825. "Show outline path and, maybe, follow mode window."
  8826. (let ((m (org-get-at-bol 'org-marker)))
  8827. (when (and (markerp m) (marker-buffer m))
  8828. (and org-agenda-follow-mode
  8829. (if org-agenda-follow-indirect
  8830. (org-agenda-tree-to-indirect-buffer nil)
  8831. (org-agenda-show)))
  8832. (and org-agenda-show-outline-path
  8833. (org-with-point-at m (org-display-outline-path t))))))
  8834. (defun org-agenda-show-tags ()
  8835. "Show the tags applicable to the current item."
  8836. (interactive)
  8837. (let* ((tags (org-get-at-bol 'tags)))
  8838. (if tags
  8839. (message "Tags are :%s:"
  8840. (org-no-properties (mapconcat #'identity tags ":")))
  8841. (message "No tags associated with this line"))))
  8842. (defun org-agenda-goto (&optional highlight)
  8843. "Go to the entry at point in the corresponding Org file."
  8844. (interactive)
  8845. (let* ((marker (or (org-get-at-bol 'org-marker)
  8846. (org-agenda-error)))
  8847. (buffer (marker-buffer marker))
  8848. (pos (marker-position marker)))
  8849. ;; FIXME: use `org-switch-to-buffer-other-window'?
  8850. (switch-to-buffer-other-window buffer)
  8851. (widen)
  8852. (push-mark)
  8853. (goto-char pos)
  8854. (when (derived-mode-p 'org-mode)
  8855. (org-fold-show-context 'agenda)
  8856. (recenter (/ (window-height) 2))
  8857. (org-back-to-heading t)
  8858. (let ((case-fold-search nil))
  8859. (when (re-search-forward org-complex-heading-regexp nil t)
  8860. (goto-char (match-beginning 4)))))
  8861. (run-hooks 'org-agenda-after-show-hook)
  8862. (and highlight (org-highlight (line-beginning-position)
  8863. (line-end-position)))))
  8864. (defvar org-agenda-after-show-hook nil
  8865. "Normal hook run after an item has been shown from the agenda.
  8866. Point is in the buffer where the item originated.")
  8867. ;; Defined later in org-agenda.el
  8868. (defvar org-agenda-loop-over-headlines-in-active-region nil)
  8869. (defun org-agenda-do-in-region (beg end cmd &optional arg force-arg delete)
  8870. "Between region BEG and END, call agenda command CMD.
  8871. When optional argument ARG is non-nil or FORCE-ARG is t, pass
  8872. ARG to CMD. When optional argument DELETE is non-nil, assume CMD
  8873. deletes the agenda entry and don't move to the next entry."
  8874. (save-excursion
  8875. (goto-char beg)
  8876. (let ((mend (move-marker (make-marker) end))
  8877. (all (eq org-agenda-loop-over-headlines-in-active-region t))
  8878. (match (and (stringp org-agenda-loop-over-headlines-in-active-region)
  8879. org-agenda-loop-over-headlines-in-active-region))
  8880. (level (and (eq org-agenda-loop-over-headlines-in-active-region 'start-level)
  8881. (org-get-at-bol 'level))))
  8882. (while (< (point) mend)
  8883. (let ((ov (make-overlay (point) (line-end-position))))
  8884. (if (not (or all
  8885. (and match (looking-at-p match))
  8886. (eq level (org-get-at-bol 'level))))
  8887. (org-agenda-next-item 1)
  8888. (overlay-put ov 'face 'region)
  8889. (if (or arg force-arg) (funcall cmd arg) (funcall cmd))
  8890. (when (not delete) (org-agenda-next-item 1))
  8891. (delete-overlay ov)))))))
  8892. ;; org-agenda-[schedule,deadline,date-prompt,todo,[toggle]archive*,
  8893. ;; kill,set-property,set-effort] commands may loop over agenda
  8894. ;; entries. Commands `org-agenda-set-tags' and `org-agenda-bulk-mark'
  8895. ;; use their own mechanisms on active regions.
  8896. (defmacro org-agenda-maybe-loop (cmd arg force-arg delete &rest body)
  8897. "Maybe loop over agenda entries and perform CMD.
  8898. Pass ARG, FORCE-ARG, DELETE and BODY to `org-agenda-do-in-region'."
  8899. (declare (debug t))
  8900. `(if (and (called-interactively-p 'any)
  8901. org-agenda-loop-over-headlines-in-active-region
  8902. (org-region-active-p))
  8903. (org-agenda-do-in-region
  8904. (region-beginning) (region-end) ,cmd ,arg ,force-arg ,delete)
  8905. ,@body))
  8906. (defun org-agenda-kill ()
  8907. "Kill the entry or subtree belonging to the current agenda entry."
  8908. (interactive)
  8909. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8910. (org-agenda-maybe-loop
  8911. #'org-agenda-kill nil nil t
  8912. (let* ((bufname-orig (buffer-name))
  8913. (marker (or (org-get-at-bol 'org-marker)
  8914. (org-agenda-error)))
  8915. (buffer (marker-buffer marker))
  8916. (pos (marker-position marker))
  8917. (type (org-get-at-bol 'type))
  8918. dbeg dend (n 0))
  8919. (org-with-remote-undo buffer
  8920. (with-current-buffer buffer
  8921. (save-excursion
  8922. (goto-char pos)
  8923. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  8924. (setq dbeg (progn (org-back-to-heading t) (point))
  8925. dend (org-end-of-subtree t t))
  8926. (setq dbeg (line-beginning-position)
  8927. dend (min (point-max) (1+ (line-end-position)))))
  8928. (goto-char dbeg)
  8929. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  8930. (when (or (eq t org-agenda-confirm-kill)
  8931. (and (numberp org-agenda-confirm-kill)
  8932. (> n org-agenda-confirm-kill)))
  8933. (let ((win-conf (current-window-configuration)))
  8934. (unwind-protect
  8935. (and
  8936. (prog2
  8937. (org-agenda-tree-to-indirect-buffer nil)
  8938. (not (y-or-n-p
  8939. (format "Delete entry with %d lines in buffer \"%s\"? "
  8940. n (buffer-name buffer))))
  8941. (kill-buffer org-last-indirect-buffer))
  8942. (error "Abort"))
  8943. (set-window-configuration win-conf))))
  8944. (let ((org-agenda-buffer-name bufname-orig))
  8945. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  8946. (with-current-buffer buffer (delete-region dbeg dend))
  8947. (message "Agenda item and source killed")))))
  8948. (defvar org-archive-default-command) ; defined in org-archive.el
  8949. (defun org-agenda-archive-default ()
  8950. "Archive the entry or subtree belonging to the current agenda entry."
  8951. (interactive)
  8952. (require 'org-archive)
  8953. (funcall-interactively
  8954. #'org-agenda-archive-with org-archive-default-command))
  8955. (defun org-agenda-archive-default-with-confirmation ()
  8956. "Archive the entry or subtree belonging to the current agenda entry."
  8957. (interactive)
  8958. (require 'org-archive)
  8959. (funcall-interactively
  8960. #'org-agenda-archive-with org-archive-default-command 'confirm))
  8961. (defun org-agenda-archive ()
  8962. "Archive the entry or subtree belonging to the current agenda entry."
  8963. (interactive)
  8964. (funcall-interactively
  8965. #'org-agenda-archive-with 'org-archive-subtree))
  8966. (defun org-agenda-archive-to-archive-sibling ()
  8967. "Move the entry to the archive sibling."
  8968. (interactive)
  8969. (funcall-interactively
  8970. #'org-agenda-archive-with 'org-archive-to-archive-sibling))
  8971. (defvar org-archive-from-agenda)
  8972. (defun org-agenda-archive-with (cmd &optional confirm)
  8973. "Move the entry to the archive sibling."
  8974. (interactive)
  8975. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8976. (org-agenda-maybe-loop
  8977. #'org-agenda-archive-with cmd nil t
  8978. (let* ((bufname-orig (buffer-name))
  8979. (marker (or (org-get-at-bol 'org-marker)
  8980. (org-agenda-error)))
  8981. (buffer (marker-buffer marker))
  8982. (pos (marker-position marker)))
  8983. (org-with-remote-undo buffer
  8984. (with-current-buffer buffer
  8985. (if (derived-mode-p 'org-mode)
  8986. (if (and confirm
  8987. (not (y-or-n-p "Archive this subtree or entry? ")))
  8988. (error "Abort")
  8989. (save-window-excursion
  8990. (goto-char pos)
  8991. (let ((org-agenda-buffer-name bufname-orig))
  8992. (org-remove-subtree-entries-from-agenda))
  8993. (org-back-to-heading t)
  8994. (let ((org-archive-from-agenda t))
  8995. (funcall cmd))))
  8996. (error "Archiving works only in Org files")))))))
  8997. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  8998. "Remove all lines in the agenda that correspond to a given subtree.
  8999. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  9000. If this information is not given, the function uses the tree at point."
  9001. (let ((buf (or buf (current-buffer))) m p)
  9002. (save-excursion
  9003. (unless (and beg end)
  9004. (org-back-to-heading t)
  9005. (setq beg (point))
  9006. (org-end-of-subtree t)
  9007. (setq end (point)))
  9008. (set-buffer (get-buffer org-agenda-buffer-name))
  9009. (save-excursion
  9010. (goto-char (point-max))
  9011. (beginning-of-line 1)
  9012. (while (not (bobp))
  9013. (when (and (setq m (org-get-at-bol 'org-marker))
  9014. (equal buf (marker-buffer m))
  9015. (setq p (marker-position m))
  9016. (>= p beg)
  9017. (< p end))
  9018. (let ((inhibit-read-only t))
  9019. (delete-region (line-beginning-position)
  9020. (1+ (line-end-position)))))
  9021. (beginning-of-line 0))))))
  9022. (defun org-agenda-refile (&optional goto rfloc no-update)
  9023. "Refile the item at point.
  9024. When called with `\\[universal-argument] \\[universal-argument]', \
  9025. go to the location of the last
  9026. refiled item.
  9027. When called with `\\[universal-argument] \\[universal-argument] \
  9028. \\[universal-argument]' prefix or when GOTO is 0, clear
  9029. the refile cache.
  9030. RFLOC can be a refile location obtained in a different way.
  9031. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  9032. (interactive "P")
  9033. (cond
  9034. ((member goto '(0 (64)))
  9035. (org-refile-cache-clear))
  9036. ((equal goto '(16))
  9037. (org-refile-goto-last-stored))
  9038. (t
  9039. (let* ((buffer-orig (buffer-name))
  9040. (marker (or (org-get-at-bol 'org-hd-marker)
  9041. (org-agenda-error)))
  9042. (buffer (marker-buffer marker))
  9043. ;; (pos (marker-position marker))
  9044. (rfloc (or rfloc
  9045. (org-refile-get-location
  9046. (if goto "Goto" "Refile to") buffer
  9047. org-refile-allow-creating-parent-nodes))))
  9048. (with-current-buffer buffer
  9049. (org-with-wide-buffer
  9050. (goto-char marker)
  9051. (let ((org-agenda-buffer-name buffer-orig))
  9052. (org-remove-subtree-entries-from-agenda))
  9053. (org-refile goto buffer rfloc))))
  9054. (unless no-update (org-agenda-redo)))))
  9055. (defun org-agenda-open-link (&optional arg)
  9056. "Open the link(s) in the current entry, if any.
  9057. This looks for a link in the displayed line in the agenda.
  9058. It also looks at the text of the entry itself."
  9059. (interactive "P")
  9060. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  9061. (org-get-at-bol 'org-marker)))
  9062. (buffer (and marker (marker-buffer marker)))
  9063. (prefix (buffer-substring (line-beginning-position)
  9064. (line-end-position)))
  9065. (lkall (and buffer (org-offer-links-in-entry
  9066. buffer marker arg prefix)))
  9067. (lk0 (car lkall))
  9068. (lk (if (stringp lk0) (list lk0) lk0))
  9069. (lkend (cdr lkall))
  9070. trg)
  9071. (cond
  9072. ((and buffer lk)
  9073. (mapcar (lambda(l)
  9074. (with-current-buffer buffer
  9075. (setq trg (and (string-match org-link-bracket-re l)
  9076. (match-string 1 l)))
  9077. (if (or (not trg) (string-match org-link-any-re trg))
  9078. ;; Don't use `org-with-wide-buffer' here as
  9079. ;; opening the link may result in moving the point
  9080. (save-restriction
  9081. (widen)
  9082. (goto-char marker)
  9083. (when (search-forward l nil lkend)
  9084. (goto-char (match-beginning 0))
  9085. (org-open-at-point)))
  9086. ;; This is an internal link, widen the buffer
  9087. ;; FIXME: use `org-switch-to-buffer-other-window'?
  9088. (switch-to-buffer-other-window buffer)
  9089. (widen)
  9090. (goto-char marker)
  9091. (when (search-forward l nil lkend)
  9092. (goto-char (match-beginning 0))
  9093. (org-open-at-point)))))
  9094. lk))
  9095. ((or (org-in-regexp (concat "\\(" org-link-bracket-re "\\)"))
  9096. (save-excursion
  9097. (beginning-of-line 1)
  9098. (looking-at (concat ".*?\\(" org-link-bracket-re "\\)"))))
  9099. (org-link-open-from-string (match-string 1)))
  9100. (t (message "No link to open here")))))
  9101. (defun org-agenda-copy-local-variable (var)
  9102. "Get a variable from a referenced buffer and install it here."
  9103. (let ((m (org-get-at-bol 'org-marker)))
  9104. (when (and m (buffer-live-p (marker-buffer m)))
  9105. (set (make-local-variable var)
  9106. (with-current-buffer (marker-buffer m)
  9107. (symbol-value var))))))
  9108. (defun org-agenda-switch-to (&optional delete-other-windows)
  9109. "Go to the Org mode file which contains the item at point.
  9110. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  9111. displayed Org file fills the frame."
  9112. (interactive)
  9113. (if (and org-return-follows-link
  9114. (not (org-get-at-bol 'org-marker))
  9115. (org-in-regexp org-link-bracket-re))
  9116. (org-link-open-from-string (match-string 0))
  9117. (let* ((marker (or (org-get-at-bol 'org-marker)
  9118. (org-agenda-error)))
  9119. (buffer (marker-buffer marker))
  9120. (pos (marker-position marker)))
  9121. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  9122. (pop-to-buffer-same-window buffer)
  9123. (when delete-other-windows (delete-other-windows))
  9124. (widen)
  9125. (goto-char pos)
  9126. (when (derived-mode-p 'org-mode)
  9127. (org-fold-show-context 'agenda)
  9128. (run-hooks 'org-agenda-after-show-hook)))))
  9129. (defun org-agenda-goto-mouse (ev)
  9130. "Go to the Org file which contains the item at the mouse click."
  9131. (interactive "e")
  9132. (mouse-set-point ev)
  9133. (org-agenda-goto))
  9134. (defun org-agenda-show (&optional full-entry)
  9135. "Display the Org file which contains the item at point.
  9136. With prefix argument FULL-ENTRY, make the entire entry visible
  9137. if it was hidden in the outline."
  9138. (interactive "P")
  9139. (let ((win (selected-window)))
  9140. (org-agenda-goto t)
  9141. (when full-entry (org-fold-show-entry 'hide-drawers))
  9142. (select-window win)))
  9143. (defvar org-agenda-show-window nil)
  9144. (defun org-agenda-show-and-scroll-up (&optional arg)
  9145. "Display the Org file which contains the item at point.
  9146. When called repeatedly, scroll the window that is displaying the buffer.
  9147. With a `\\[universal-argument]' prefix argument, display the item, but \
  9148. fold drawers."
  9149. (interactive "P")
  9150. (let ((win (selected-window)))
  9151. (if (and (window-live-p org-agenda-show-window)
  9152. (eq this-command last-command))
  9153. (progn
  9154. (select-window org-agenda-show-window)
  9155. (ignore-errors (scroll-up)))
  9156. (org-agenda-goto t)
  9157. (org-fold-show-entry 'hide-drawers)
  9158. (if arg (org-cycle-hide-drawers 'children)
  9159. (org-with-wide-buffer
  9160. (narrow-to-region (org-entry-beginning-position)
  9161. (org-entry-end-position))
  9162. (org-fold-show-all '(drawers))))
  9163. (setq org-agenda-show-window (selected-window)))
  9164. (select-window win)))
  9165. (defun org-agenda-show-scroll-down ()
  9166. "Scroll down the window showing the agenda."
  9167. (interactive)
  9168. (let ((win (selected-window)))
  9169. (when (window-live-p org-agenda-show-window)
  9170. (select-window org-agenda-show-window)
  9171. (ignore-errors (scroll-down))
  9172. (select-window win))))
  9173. (defun org-agenda-show-1 (&optional more)
  9174. "Display the Org file which contains the item at point.
  9175. The prefix arg selects the amount of information to display:
  9176. 0 hide the subtree
  9177. 1 just show the entry according to defaults.
  9178. 2 show the children view
  9179. 3 show the subtree view
  9180. 4 show the entire subtree and any drawers
  9181. With prefix argument FULL-ENTRY, make the entire entry visible
  9182. if it was hidden in the outline."
  9183. (interactive "p")
  9184. (let ((win (selected-window)))
  9185. (org-agenda-goto t)
  9186. (org-back-to-heading)
  9187. (set-window-start (selected-window) (line-beginning-position))
  9188. (cond
  9189. ((= more 0)
  9190. (org-fold-subtree t)
  9191. (save-excursion
  9192. (org-back-to-heading)
  9193. (run-hook-with-args 'org-cycle-hook 'folded))
  9194. (message "Remote: FOLDED"))
  9195. ((and (called-interactively-p 'any) (= more 1))
  9196. (message "Remote: show with default settings"))
  9197. ((= more 2)
  9198. (org-fold-show-entry 'hide-drawers)
  9199. (org-fold-show-children)
  9200. (save-excursion
  9201. (org-back-to-heading)
  9202. (run-hook-with-args 'org-cycle-hook 'children))
  9203. (message "Remote: CHILDREN"))
  9204. ((= more 3)
  9205. (org-fold-show-subtree)
  9206. (save-excursion
  9207. (org-back-to-heading)
  9208. (run-hook-with-args 'org-cycle-hook 'subtree))
  9209. (message "Remote: SUBTREE"))
  9210. ((> more 3)
  9211. (org-fold-show-subtree)
  9212. (message "Remote: SUBTREE AND ALL DRAWERS")))
  9213. (select-window win)))
  9214. (defvar org-agenda-cycle-counter nil)
  9215. (defun org-agenda-cycle-show (&optional n)
  9216. "Show the current entry in another window, with default settings.
  9217. Default settings are taken from `org-show-context-detail'. When
  9218. use repeatedly in immediate succession, the remote entry will
  9219. cycle through visibility
  9220. children -> subtree -> folded
  9221. When called with a numeric prefix arg, that arg will be passed through to
  9222. `org-agenda-show-1'. For the interpretation of that argument, see the
  9223. docstring of `org-agenda-show-1'."
  9224. (interactive "P")
  9225. (if (integerp n)
  9226. (setq org-agenda-cycle-counter n)
  9227. (if (not (eq last-command this-command))
  9228. (setq org-agenda-cycle-counter 1)
  9229. (if (equal org-agenda-cycle-counter 0)
  9230. (setq org-agenda-cycle-counter 2)
  9231. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  9232. (when (> org-agenda-cycle-counter 3)
  9233. (setq org-agenda-cycle-counter 0)))))
  9234. (org-agenda-show-1 org-agenda-cycle-counter))
  9235. (defun org-agenda-recenter (arg)
  9236. "Display the Org file which contains the item at point and recenter."
  9237. (interactive "P")
  9238. (let ((win (selected-window)))
  9239. (org-agenda-goto t)
  9240. (recenter arg)
  9241. (select-window win)))
  9242. (defun org-agenda-show-mouse (ev)
  9243. "Display the Org file which contains the item at the mouse click."
  9244. (interactive "e")
  9245. (mouse-set-point ev)
  9246. (org-agenda-show))
  9247. (defun org-agenda-check-no-diary ()
  9248. "Check if the entry is a diary link and abort if yes."
  9249. (when (org-get-at-bol 'org-agenda-diary-link)
  9250. (org-agenda-error)))
  9251. (defun org-agenda-error ()
  9252. "Throw an error when a command is not allowed in the agenda."
  9253. (user-error "Command not allowed in this line"))
  9254. (defun org-agenda-tree-to-indirect-buffer (arg)
  9255. "Show the subtree corresponding to the current entry in an indirect buffer.
  9256. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  9257. With a numerical prefix ARG, go up to this level and then take that tree.
  9258. With a negative numeric ARG, go up by this number of levels.
  9259. With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
  9260. i.e. don't use
  9261. the dedicated frame."
  9262. (interactive "P")
  9263. (if current-prefix-arg
  9264. (org-agenda-do-tree-to-indirect-buffer arg)
  9265. (let ((agenda-buffer (buffer-name))
  9266. (agenda-window (selected-window))
  9267. (indirect-window
  9268. (and org-last-indirect-buffer
  9269. (get-buffer-window org-last-indirect-buffer))))
  9270. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  9271. (unless (or (eq org-indirect-buffer-display 'new-frame)
  9272. (eq org-indirect-buffer-display 'dedicated-frame))
  9273. (unwind-protect
  9274. (unless (and indirect-window (window-live-p indirect-window))
  9275. (setq indirect-window (split-window agenda-window)))
  9276. (and indirect-window (select-window indirect-window))
  9277. (switch-to-buffer org-last-indirect-buffer :norecord)
  9278. (fit-window-to-buffer indirect-window)))
  9279. (select-window (get-buffer-window agenda-buffer))
  9280. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  9281. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  9282. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  9283. (org-agenda-check-no-diary)
  9284. (let* ((marker (or (org-get-at-bol 'org-marker)
  9285. (org-agenda-error)))
  9286. (buffer (marker-buffer marker))
  9287. (pos (marker-position marker)))
  9288. (with-current-buffer buffer
  9289. (save-excursion
  9290. (goto-char pos)
  9291. (org-tree-to-indirect-buffer arg)))))
  9292. (defvar org-last-heading-marker (make-marker)
  9293. "Marker pointing to the headline that last changed its TODO state
  9294. by a remote command from the agenda.")
  9295. (defun org-agenda-todo-nextset ()
  9296. "Switch TODO entry to next sequence."
  9297. (interactive)
  9298. (org-agenda-todo 'nextset))
  9299. (defun org-agenda-todo-previousset ()
  9300. "Switch TODO entry to previous sequence."
  9301. (interactive)
  9302. (org-agenda-todo 'previousset))
  9303. (defvar org-agenda-headline-snapshot-before-repeat)
  9304. (defun org-agenda-todo (&optional arg)
  9305. "Cycle TODO state of line at point, also in Org file.
  9306. This changes the line at point, all other lines in the agenda referring to
  9307. the same tree node, and the headline of the tree node in the Org file."
  9308. (interactive "P")
  9309. (org-agenda-check-no-diary)
  9310. (org-agenda-maybe-loop
  9311. #'org-agenda-todo arg nil nil
  9312. (let* ((col (current-column))
  9313. (marker (or (org-get-at-bol 'org-marker)
  9314. (org-agenda-error)))
  9315. (buffer (marker-buffer marker))
  9316. (pos (marker-position marker))
  9317. (hdmarker (org-get-at-bol 'org-hd-marker))
  9318. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  9319. (inhibit-read-only t)
  9320. org-loop-over-headlines-in-active-region
  9321. org-agenda-headline-snapshot-before-repeat newhead just-one)
  9322. (org-with-remote-undo buffer
  9323. (with-current-buffer buffer
  9324. (widen)
  9325. (goto-char pos)
  9326. (org-fold-show-context 'agenda)
  9327. (let ((current-prefix-arg arg))
  9328. (call-interactively 'org-todo)
  9329. ;; Make sure that log is recorded in current undo.
  9330. (when (and org-log-setup
  9331. (not (eq org-log-note-how 'note)))
  9332. (org-add-log-note)))
  9333. (and (bolp) (forward-char 1))
  9334. (setq newhead (org-get-heading))
  9335. (when (and org-agenda-headline-snapshot-before-repeat
  9336. (not (equal org-agenda-headline-snapshot-before-repeat
  9337. newhead))
  9338. todayp)
  9339. (setq newhead org-agenda-headline-snapshot-before-repeat
  9340. just-one t))
  9341. (save-excursion
  9342. (org-back-to-heading)
  9343. (move-marker org-last-heading-marker (point))))
  9344. (beginning-of-line 1)
  9345. (save-window-excursion
  9346. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  9347. (when (bound-and-true-p org-clock-out-when-done)
  9348. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  9349. newhead)
  9350. (org-agenda-unmark-clocking-task))
  9351. (org-move-to-column col)
  9352. (org-agenda-mark-clocking-task)))))
  9353. (defun org-agenda-add-note (&optional _arg)
  9354. "Add a time-stamped note to the entry at point."
  9355. (interactive) ;; "P"
  9356. (org-agenda-check-no-diary)
  9357. (let* ((marker (or (org-get-at-bol 'org-marker)
  9358. (org-agenda-error)))
  9359. (buffer (marker-buffer marker))
  9360. (pos (marker-position marker))
  9361. (_hdmarker (org-get-at-bol 'org-hd-marker))
  9362. (inhibit-read-only t))
  9363. (with-current-buffer buffer
  9364. (widen)
  9365. (goto-char pos)
  9366. (org-fold-show-context 'agenda)
  9367. (org-add-note))))
  9368. (defun org-agenda-change-all-lines (newhead hdmarker
  9369. &optional fixface just-this)
  9370. "Change all lines in the agenda buffer which match HDMARKER.
  9371. The new content of the line will be NEWHEAD (as modified by
  9372. `org-agenda-format-item'). HDMARKER is checked with
  9373. `equal' against all `org-hd-marker' text properties in the file.
  9374. If FIXFACE is non-nil, the face of each item is modified according to
  9375. the new TODO state.
  9376. If JUST-THIS is non-nil, change just the current line, not all.
  9377. If FORCE-TAGS is non-nil, the car of it returns the new tags."
  9378. (let* ((inhibit-read-only t)
  9379. (line (org-current-line))
  9380. (org-agenda-buffer (current-buffer))
  9381. (thetags (with-current-buffer (marker-buffer hdmarker)
  9382. (org-get-tags hdmarker)))
  9383. props m undone-face done-face finish new dotime level cat tags
  9384. effort effort-minutes) ;; pl
  9385. (save-excursion
  9386. (goto-char (point-max))
  9387. (beginning-of-line 1)
  9388. (while (not finish)
  9389. (setq finish (bobp))
  9390. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  9391. (or (not just-this) (= (org-current-line) line))
  9392. (equal m hdmarker))
  9393. (setq props (text-properties-at (point))
  9394. dotime (org-get-at-bol 'dotime)
  9395. cat (org-agenda-get-category)
  9396. level (org-get-at-bol 'level)
  9397. tags thetags
  9398. effort (org-get-at-bol 'effort)
  9399. effort-minutes (org-get-at-bol 'effort-minutes)
  9400. new
  9401. (let ((org-prefix-format-compiled
  9402. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  9403. org-prefix-format-compiled))
  9404. (extra (org-get-at-bol 'extra)))
  9405. (with-current-buffer (marker-buffer hdmarker)
  9406. (org-with-wide-buffer
  9407. (org-agenda-format-item extra
  9408. (org-add-props newhead nil
  9409. 'effort effort
  9410. 'effort-minutes effort-minutes)
  9411. level cat tags dotime))))
  9412. ;; pl (text-property-any (line-beginning-position)
  9413. ;; (line-end-position) 'org-heading t)
  9414. undone-face (org-get-at-bol 'undone-face)
  9415. done-face (org-get-at-bol 'done-face))
  9416. (beginning-of-line 1)
  9417. (cond
  9418. ((equal new "") (delete-region (point) (line-beginning-position 2)))
  9419. ((looking-at ".*")
  9420. ;; When replacing the whole line, preserve bulk mark
  9421. ;; overlay, if any.
  9422. (let ((mark (catch :overlay
  9423. (dolist (o (overlays-in (point) (+ 2 (point))))
  9424. (when (eq (overlay-get o 'type)
  9425. 'org-marked-entry-overlay)
  9426. (throw :overlay o))))))
  9427. (replace-match new t t)
  9428. (beginning-of-line)
  9429. (when mark (move-overlay mark (point) (+ 2 (point)))))
  9430. (add-text-properties (line-beginning-position)
  9431. (line-end-position) props)
  9432. (when fixface
  9433. (add-text-properties
  9434. (line-beginning-position) (line-end-position)
  9435. (list 'face
  9436. (if org-last-todo-state-is-todo
  9437. undone-face done-face))))
  9438. (org-agenda-highlight-todo 'line)
  9439. (beginning-of-line 1))
  9440. (t (error "Line update did not work")))
  9441. (save-restriction
  9442. (narrow-to-region (line-beginning-position) (line-end-position))
  9443. (org-agenda-finalize)))
  9444. (beginning-of-line 0)))))
  9445. (defun org-agenda-align-tags (&optional line)
  9446. "Align all tags in agenda items to `org-agenda-tags-column'.
  9447. When optional argument LINE is non-nil, align tags only on the
  9448. current line."
  9449. (let ((inhibit-read-only t)
  9450. (org-agenda-tags-column (if (eq 'auto org-agenda-tags-column)
  9451. (- (window-max-chars-per-line))
  9452. org-agenda-tags-column))
  9453. (end (and line (line-end-position)))
  9454. l c)
  9455. (org-fold-core-ignore-modifications
  9456. (save-excursion
  9457. (goto-char (if line (line-beginning-position) (point-min)))
  9458. (while (re-search-forward org-tag-group-re end t)
  9459. (add-text-properties
  9460. (match-beginning 1) (match-end 1)
  9461. (list 'face (delq nil (let ((prop (get-text-property
  9462. (match-beginning 1) 'face)))
  9463. (or (listp prop) (setq prop (list prop)))
  9464. (if (memq 'org-tag prop)
  9465. prop
  9466. (cons 'org-tag prop))))))
  9467. (setq l (string-width (match-string 1))
  9468. c (if (< org-agenda-tags-column 0)
  9469. (- (abs org-agenda-tags-column) l)
  9470. org-agenda-tags-column))
  9471. (goto-char (match-beginning 1))
  9472. (delete-region (save-excursion (skip-chars-backward " \t") (point))
  9473. (point))
  9474. (insert (org-add-props
  9475. (make-string (max 1 (- c (current-column))) ?\s)
  9476. (plist-put (copy-sequence (text-properties-at (point)))
  9477. 'face nil))))
  9478. (goto-char (point-min))
  9479. (org-font-lock-add-tag-faces (point-max))))))
  9480. (defun org-agenda-priority-up ()
  9481. "Increase the priority of line at point, also in Org file."
  9482. (interactive)
  9483. (org-agenda-priority 'up))
  9484. (defun org-agenda-priority-down ()
  9485. "Decrease the priority of line at point, also in Org file."
  9486. (interactive)
  9487. (org-agenda-priority 'down))
  9488. (defun org-agenda-priority (&optional force-direction)
  9489. "Set the priority of line at point, also in Org file.
  9490. This changes the line at point, all other lines in the agenda
  9491. referring to the same tree node, and the headline of the tree
  9492. node in the Org file.
  9493. Called with one universal prefix arg, show the priority instead
  9494. of setting it.
  9495. When called programmatically, FORCE-DIRECTION can be `set', `up',
  9496. `down', or a character."
  9497. (interactive "P")
  9498. (unless org-priority-enable-commands
  9499. (user-error "Priority commands are disabled"))
  9500. (org-agenda-check-no-diary)
  9501. (let* ((col (current-column))
  9502. (hdmarker (org-get-at-bol 'org-hd-marker))
  9503. (buffer (marker-buffer hdmarker))
  9504. (pos (marker-position hdmarker))
  9505. (inhibit-read-only t)
  9506. newhead)
  9507. (org-with-remote-undo buffer
  9508. (with-current-buffer buffer
  9509. (widen)
  9510. (goto-char pos)
  9511. (org-fold-show-context 'agenda)
  9512. (org-priority force-direction)
  9513. (end-of-line 1)
  9514. (setq newhead (org-get-heading)))
  9515. (org-agenda-change-all-lines newhead hdmarker)
  9516. (org-move-to-column col))))
  9517. ;; FIXME: should fix the tags property of the agenda line.
  9518. (defun org-agenda-set-tags (&optional tag onoff)
  9519. "Set tags for the current headline."
  9520. (interactive)
  9521. (org-agenda-check-no-diary)
  9522. (if (and (org-region-active-p) (called-interactively-p 'any))
  9523. (call-interactively 'org-change-tag-in-region)
  9524. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9525. (org-agenda-error)))
  9526. (buffer (marker-buffer hdmarker))
  9527. (pos (marker-position hdmarker))
  9528. (inhibit-read-only t)
  9529. newhead)
  9530. (org-with-remote-undo buffer
  9531. (with-current-buffer buffer
  9532. (widen)
  9533. (goto-char pos)
  9534. (org-fold-show-context 'agenda)
  9535. (if tag
  9536. (org-toggle-tag tag onoff)
  9537. (call-interactively #'org-set-tags-command))
  9538. (end-of-line 1)
  9539. (setq newhead (org-get-heading)))
  9540. (org-agenda-change-all-lines newhead hdmarker)
  9541. (beginning-of-line 1)))))
  9542. (defun org-agenda-set-property ()
  9543. "Set a property for the current headline."
  9544. (interactive)
  9545. (org-agenda-check-no-diary)
  9546. (org-agenda-maybe-loop
  9547. #'org-agenda-set-property nil nil nil
  9548. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9549. (org-agenda-error)))
  9550. (buffer (marker-buffer hdmarker))
  9551. (pos (marker-position hdmarker))
  9552. (inhibit-read-only t)
  9553. ) ;; newhead
  9554. (org-with-remote-undo buffer
  9555. (with-current-buffer buffer
  9556. (widen)
  9557. (goto-char pos)
  9558. (org-fold-show-context 'agenda)
  9559. (call-interactively 'org-set-property))))))
  9560. (defun org-agenda-set-effort ()
  9561. "Set the effort property for the current headline."
  9562. (interactive)
  9563. (org-agenda-check-no-diary)
  9564. (org-agenda-maybe-loop
  9565. #'org-agenda-set-effort nil nil nil
  9566. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9567. (org-agenda-error)))
  9568. (buffer (marker-buffer hdmarker))
  9569. (pos (marker-position hdmarker))
  9570. (inhibit-read-only t)
  9571. newhead)
  9572. (org-with-remote-undo buffer
  9573. (with-current-buffer buffer
  9574. (widen)
  9575. (goto-char pos)
  9576. (org-fold-show-context 'agenda)
  9577. (call-interactively 'org-set-effort)
  9578. (end-of-line 1)
  9579. (setq newhead (org-get-heading)))
  9580. (org-agenda-change-all-lines newhead hdmarker)))))
  9581. (defun org-agenda-toggle-archive-tag ()
  9582. "Toggle the archive tag for the current entry."
  9583. (interactive)
  9584. (org-agenda-check-no-diary)
  9585. (org-agenda-maybe-loop
  9586. #'org-agenda-toggle-archive-tag nil nil nil
  9587. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9588. (org-agenda-error)))
  9589. (buffer (marker-buffer hdmarker))
  9590. (pos (marker-position hdmarker))
  9591. (inhibit-read-only t)
  9592. newhead)
  9593. (org-with-remote-undo buffer
  9594. (with-current-buffer buffer
  9595. (widen)
  9596. (goto-char pos)
  9597. (org-fold-show-context 'agenda)
  9598. (call-interactively 'org-toggle-archive-tag)
  9599. (end-of-line 1)
  9600. (setq newhead (org-get-heading)))
  9601. (org-agenda-change-all-lines newhead hdmarker)
  9602. (beginning-of-line 1)))))
  9603. (defun org-agenda-do-date-later (arg)
  9604. (interactive "P")
  9605. (cond
  9606. ((or (equal arg '(16))
  9607. (memq last-command
  9608. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9609. (setq this-command 'org-agenda-date-later-minutes)
  9610. (org-agenda-date-later-minutes 1))
  9611. ((or (equal arg '(4))
  9612. (memq last-command
  9613. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9614. (setq this-command 'org-agenda-date-later-hours)
  9615. (org-agenda-date-later-hours 1))
  9616. (t
  9617. (org-agenda-date-later (prefix-numeric-value arg)))))
  9618. (defun org-agenda-do-date-earlier (arg)
  9619. (interactive "P")
  9620. (cond
  9621. ((or (equal arg '(16))
  9622. (memq last-command
  9623. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9624. (setq this-command 'org-agenda-date-earlier-minutes)
  9625. (org-agenda-date-earlier-minutes 1))
  9626. ((or (equal arg '(4))
  9627. (memq last-command
  9628. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9629. (setq this-command 'org-agenda-date-earlier-hours)
  9630. (org-agenda-date-earlier-hours 1))
  9631. (t
  9632. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  9633. (defun org-agenda-date-later (arg &optional what)
  9634. "Change the date of this item to ARG day(s) later."
  9635. (interactive "p")
  9636. (org-agenda-check-type t 'agenda)
  9637. (org-agenda-check-no-diary)
  9638. (let* ((marker (or (org-get-at-bol 'org-marker)
  9639. (org-agenda-error)))
  9640. (buffer (marker-buffer marker))
  9641. (pos (marker-position marker))
  9642. cdate today)
  9643. (org-with-remote-undo buffer
  9644. (with-current-buffer buffer
  9645. (widen)
  9646. (goto-char pos)
  9647. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9648. (when (and org-agenda-move-date-from-past-immediately-to-today
  9649. (equal arg 1)
  9650. (or (not what) (eq what 'day))
  9651. (not (save-match-data (org-at-date-range-p))))
  9652. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  9653. cdate (calendar-absolute-from-gregorian
  9654. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  9655. today (org-today))
  9656. (when (> today cdate)
  9657. ;; immediately shift to today
  9658. (setq arg (- today cdate))))
  9659. (org-timestamp-change arg (or what 'day))
  9660. (when (and (org-at-date-range-p)
  9661. (re-search-backward org-tr-regexp-both
  9662. (line-beginning-position)))
  9663. (let ((end org-last-changed-timestamp))
  9664. (org-timestamp-change arg (or what 'day))
  9665. (setq org-last-changed-timestamp
  9666. (concat org-last-changed-timestamp "--" end)))))
  9667. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9668. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  9669. (defun org-agenda-date-earlier (arg &optional what)
  9670. "Change the date of this item to ARG day(s) earlier."
  9671. (interactive "p")
  9672. (org-agenda-date-later (- arg) what))
  9673. (defun org-agenda-date-later-minutes (arg)
  9674. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9675. (interactive "p")
  9676. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9677. (org-agenda-date-later arg 'minute))
  9678. (defun org-agenda-date-earlier-minutes (arg)
  9679. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9680. (interactive "p")
  9681. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9682. (org-agenda-date-earlier arg 'minute))
  9683. (defun org-agenda-date-later-hours (arg)
  9684. "Change the time of this item, in hour steps."
  9685. (interactive "p")
  9686. (org-agenda-date-later arg 'hour))
  9687. (defun org-agenda-date-earlier-hours (arg)
  9688. "Change the time of this item, in hour steps."
  9689. (interactive "p")
  9690. (org-agenda-date-earlier arg 'hour))
  9691. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  9692. "Show new date stamp via text properties."
  9693. ;; We use text properties to make this undoable
  9694. (let ((inhibit-read-only t))
  9695. (setq stamp (concat prefix " => " stamp " "))
  9696. (save-excursion
  9697. (goto-char (point-max))
  9698. (while (not (bobp))
  9699. (when (equal marker (org-get-at-bol 'org-marker))
  9700. (remove-text-properties (line-beginning-position)
  9701. (line-end-position)
  9702. '(display nil))
  9703. (org-move-to-column
  9704. (- (window-max-chars-per-line)
  9705. (length stamp))
  9706. t)
  9707. (add-text-properties
  9708. (1- (point)) (line-end-position)
  9709. (list 'display (org-add-props stamp nil
  9710. 'face '(secondary-selection default))))
  9711. (beginning-of-line 1))
  9712. (beginning-of-line 0)))))
  9713. (defun org-agenda-date-prompt (arg)
  9714. "Change the date of this item. Date is prompted for, with default today.
  9715. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  9716. be used to request time specification in the time stamp."
  9717. (interactive "P")
  9718. (org-agenda-check-type t 'agenda)
  9719. (org-agenda-check-no-diary)
  9720. (org-agenda-maybe-loop
  9721. #'org-agenda-date-prompt arg t nil
  9722. (let* ((marker (or (org-get-at-bol 'org-marker)
  9723. (org-agenda-error)))
  9724. (buffer (marker-buffer marker))
  9725. (pos (marker-position marker)))
  9726. (org-with-remote-undo buffer
  9727. (with-current-buffer buffer
  9728. (widen)
  9729. (goto-char pos)
  9730. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9731. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  9732. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9733. (message "Time stamp changed to %s" org-last-changed-timestamp))))
  9734. (defun org-agenda-schedule (arg &optional time)
  9735. "Schedule the item at point.
  9736. ARG is passed through to `org-schedule'."
  9737. (interactive "P")
  9738. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9739. (org-agenda-check-no-diary)
  9740. (org-agenda-maybe-loop
  9741. #'org-agenda-schedule arg t nil
  9742. (let* ((marker (or (org-get-at-bol 'org-marker)
  9743. (org-agenda-error)))
  9744. ;; (type (marker-insertion-type marker))
  9745. (buffer (marker-buffer marker))
  9746. (pos (marker-position marker))
  9747. ts)
  9748. (set-marker-insertion-type marker t)
  9749. (org-with-remote-undo buffer
  9750. (with-current-buffer buffer
  9751. (widen)
  9752. (goto-char pos)
  9753. (setq ts (org-schedule arg time)))
  9754. (org-agenda-show-new-time marker ts " S"))
  9755. (message "%s" ts))))
  9756. (defun org-agenda-deadline (arg &optional time)
  9757. "Schedule the item at point.
  9758. ARG is passed through to `org-deadline'."
  9759. (interactive "P")
  9760. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9761. (org-agenda-check-no-diary)
  9762. (org-agenda-maybe-loop
  9763. #'org-agenda-deadline arg t nil
  9764. (let* ((marker (or (org-get-at-bol 'org-marker)
  9765. (org-agenda-error)))
  9766. (buffer (marker-buffer marker))
  9767. (pos (marker-position marker))
  9768. ts)
  9769. (org-with-remote-undo buffer
  9770. (with-current-buffer buffer
  9771. (widen)
  9772. (goto-char pos)
  9773. (setq ts (org-deadline arg time)))
  9774. (org-agenda-show-new-time marker ts " D"))
  9775. (message "%s" ts))))
  9776. (defun org-agenda-clock-in (&optional arg)
  9777. "Start the clock on the currently selected item."
  9778. (interactive "P")
  9779. (org-agenda-check-no-diary)
  9780. (if (equal arg '(4))
  9781. (org-clock-in arg)
  9782. (let* ((marker (or (org-get-at-bol 'org-marker)
  9783. (org-agenda-error)))
  9784. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  9785. (pos (marker-position marker))
  9786. (col (current-column))
  9787. newhead)
  9788. (org-with-remote-undo (marker-buffer marker)
  9789. (with-current-buffer (marker-buffer marker)
  9790. (widen)
  9791. (goto-char pos)
  9792. (org-fold-show-context 'agenda)
  9793. (org-clock-in arg)
  9794. (setq newhead (org-get-heading)))
  9795. (org-agenda-change-all-lines newhead hdmarker))
  9796. (org-move-to-column col))))
  9797. (defun org-agenda-clock-out ()
  9798. "Stop the currently running clock."
  9799. (interactive)
  9800. (unless (marker-buffer org-clock-marker)
  9801. (user-error "No running clock"))
  9802. (let ((marker (make-marker)) (col (current-column)) newhead)
  9803. (org-with-remote-undo (marker-buffer org-clock-marker)
  9804. (with-current-buffer (marker-buffer org-clock-marker)
  9805. (org-with-wide-buffer
  9806. (goto-char org-clock-marker)
  9807. (org-back-to-heading t)
  9808. (move-marker marker (point))
  9809. (org-clock-out)
  9810. (setq newhead (org-get-heading)))))
  9811. (org-agenda-change-all-lines newhead marker)
  9812. (move-marker marker nil)
  9813. (org-move-to-column col)
  9814. (org-agenda-unmark-clocking-task)))
  9815. (defun org-agenda-clock-cancel (&optional _arg)
  9816. "Cancel the currently running clock."
  9817. (interactive) ;; "P"
  9818. (unless (marker-buffer org-clock-marker)
  9819. (user-error "No running clock"))
  9820. (org-with-remote-undo (marker-buffer org-clock-marker)
  9821. (org-clock-cancel)))
  9822. (defun org-agenda-clock-goto ()
  9823. "Jump to the currently clocked in task within the agenda.
  9824. If the currently clocked in task is not listed in the agenda
  9825. buffer, display it in another window."
  9826. (interactive)
  9827. (let (pos)
  9828. (mapc (lambda (o)
  9829. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  9830. (setq pos (overlay-start o))))
  9831. (overlays-in (point-min) (point-max)))
  9832. (cond (pos (goto-char pos))
  9833. ;; If the currently clocked entry is not in the agenda
  9834. ;; buffer, we visit it in another window:
  9835. ((bound-and-true-p org-clock-current-task)
  9836. (org-switch-to-buffer-other-window (org-clock-goto)))
  9837. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  9838. (defun org-agenda-diary-entry-in-org-file ()
  9839. "Make a diary entry in the file `org-agenda-diary-file'."
  9840. (let (d1 d2 char (text "") dp1 dp2)
  9841. (if (equal (buffer-name) "*Calendar*")
  9842. (setq d1 (calendar-cursor-to-date t)
  9843. d2 (car calendar-mark-ring))
  9844. (setq dp1 (get-text-property (line-beginning-position) 'day))
  9845. (unless dp1 (user-error "No date defined in current line"))
  9846. (setq d1 (calendar-gregorian-from-absolute dp1)
  9847. d2 (and (ignore-errors (mark))
  9848. (save-excursion
  9849. (goto-char (mark))
  9850. (setq dp2 (get-text-property (line-beginning-position) 'day)))
  9851. (calendar-gregorian-from-absolute dp2))))
  9852. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  9853. (setq char (read-char-exclusive))
  9854. (cond
  9855. ((equal char ?d)
  9856. (setq text (read-string "Day entry: "))
  9857. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  9858. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9859. ((equal char ?a)
  9860. (setq d1 (list (car d1) (nth 1 d1)
  9861. (read-number (format "Reference year [%d]: " (nth 2 d1))
  9862. (nth 2 d1))))
  9863. (setq text (read-string "Anniversary (use %d to show years): "))
  9864. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  9865. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9866. ((equal char ?b)
  9867. (setq text (read-string "Block entry: "))
  9868. (unless (and d1 d2 (not (equal d1 d2)))
  9869. (user-error "No block of days selected"))
  9870. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  9871. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9872. ((equal char ?j)
  9873. (org-switch-to-buffer-other-window
  9874. (find-file-noselect org-agenda-diary-file))
  9875. (require 'org-datetree)
  9876. (org-datetree-find-date-create d1)
  9877. (org-fold-reveal t))
  9878. (t (user-error "Invalid selection character `%c'" char)))))
  9879. (defcustom org-agenda-insert-diary-strategy 'date-tree
  9880. "Where in `org-agenda-diary-file' should new entries be added?
  9881. Valid values:
  9882. date-tree in the date tree, as first child of the date
  9883. date-tree-last in the date tree, as last child of the date
  9884. top-level as top-level entries at the end of the file."
  9885. :group 'org-agenda
  9886. :type '(choice
  9887. (const :tag "first in a date tree" date-tree)
  9888. (const :tag "last in a date tree" date-tree-last)
  9889. (const :tag "as top level at end of file" top-level)))
  9890. (defcustom org-agenda-insert-diary-extract-time nil
  9891. "Non-nil means extract any time specification from the diary entry."
  9892. :group 'org-agenda
  9893. :version "24.1"
  9894. :type 'boolean)
  9895. (defcustom org-agenda-bulk-mark-char ">"
  9896. "A single-character string to be used as the bulk mark."
  9897. :group 'org-agenda
  9898. :version "24.1"
  9899. :type 'string)
  9900. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  9901. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  9902. If TEXT is not empty, it will become the headline of the new entry, and
  9903. the resulting entry will not be shown. When TEXT is empty, switch to
  9904. `org-agenda-diary-file' and let the user finish the entry there."
  9905. (let ((cw (current-window-configuration)))
  9906. (org-switch-to-buffer-other-window
  9907. (find-file-noselect org-agenda-diary-file))
  9908. (widen)
  9909. (goto-char (point-min))
  9910. (cl-case type
  9911. (anniversary
  9912. (or (re-search-forward "^\\*[ \t]+Anniversaries" nil t)
  9913. (progn
  9914. (or (org-at-heading-p)
  9915. (progn
  9916. (outline-next-heading)
  9917. (insert "* Anniversaries\n\n")
  9918. (beginning-of-line -1)))))
  9919. (outline-next-heading)
  9920. (org-back-over-empty-lines)
  9921. (backward-char 1)
  9922. (insert "\n")
  9923. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  9924. (nth 2 d1) (car d1) (nth 1 d1) text)))
  9925. (day
  9926. (let ((org-prefix-has-time t)
  9927. (org-agenda-time-leading-zero t)
  9928. fmt time time2)
  9929. (when org-agenda-insert-diary-extract-time
  9930. ;; Use org-agenda-format-item to parse text for a time-range and
  9931. ;; remove it. FIXME: This is a hack, we should refactor
  9932. ;; that function to make time extraction available separately
  9933. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  9934. time (get-text-property 0 'time fmt)
  9935. time2 (if (> (length time) 0)
  9936. ;; split-string removes trailing ...... if
  9937. ;; no end time given. First space
  9938. ;; separates time from date.
  9939. (concat " " (car (split-string time "\\.")))
  9940. nil)
  9941. text (get-text-property 0 'txt fmt)))
  9942. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9943. (org-agenda-insert-diary-as-top-level text)
  9944. (require 'org-datetree)
  9945. (org-datetree-find-date-create d1)
  9946. (org-agenda-insert-diary-make-new-entry text))
  9947. (org-insert-time-stamp (org-time-from-absolute
  9948. (calendar-absolute-from-gregorian d1))
  9949. nil nil nil nil time2))
  9950. (end-of-line 0))
  9951. ((block) ;; Wrap this in (strictly unnecessary) parens because
  9952. ;; otherwise the indentation gets confused by the
  9953. ;; special meaning of 'block
  9954. (when (> (calendar-absolute-from-gregorian d1)
  9955. (calendar-absolute-from-gregorian d2))
  9956. (setq d1 (prog1 d2 (setq d2 d1))))
  9957. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9958. (org-agenda-insert-diary-as-top-level text)
  9959. (require 'org-datetree)
  9960. (org-datetree-find-date-create d1)
  9961. (org-agenda-insert-diary-make-new-entry text))
  9962. (org-insert-time-stamp (org-time-from-absolute
  9963. (calendar-absolute-from-gregorian d1)))
  9964. (insert "--")
  9965. (org-insert-time-stamp (org-time-from-absolute
  9966. (calendar-absolute-from-gregorian d2)))
  9967. (end-of-line 0)))
  9968. (if (string-match "\\S-" text)
  9969. (progn
  9970. (set-window-configuration cw)
  9971. (message "%s entry added to %s"
  9972. (capitalize (symbol-name type))
  9973. (abbreviate-file-name org-agenda-diary-file)))
  9974. (org-fold-reveal t)
  9975. (message "Please finish entry here"))))
  9976. (defun org-agenda-insert-diary-as-top-level (text)
  9977. "Make new entry as a top-level entry at the end of the file.
  9978. Add TEXT as headline, and position the cursor in the second line so that
  9979. a timestamp can be added there."
  9980. (widen)
  9981. (goto-char (point-max))
  9982. (unless (bolp) (insert "\n"))
  9983. (org-insert-heading nil t t)
  9984. (insert text)
  9985. (org-end-of-meta-data)
  9986. (unless (bolp) (insert "\n"))
  9987. (when org-adapt-indentation (indent-to-column 2)))
  9988. (defun org-agenda-insert-diary-make-new-entry (text)
  9989. "Make a new entry with TEXT as a child of the current subtree.
  9990. Position the point in the heading's first body line so that
  9991. a timestamp can be added there."
  9992. (cond
  9993. ((eq org-agenda-insert-diary-strategy 'date-tree-last)
  9994. (end-of-line)
  9995. (org-insert-heading '(4) t)
  9996. (org-do-demote))
  9997. (t
  9998. (outline-next-heading)
  9999. (org-back-over-empty-lines)
  10000. (unless (looking-at "[ \t]*$") (save-excursion (insert "\n")))
  10001. (org-insert-heading nil t)
  10002. (org-do-demote)))
  10003. (let ((col (current-column)))
  10004. (insert text)
  10005. (org-end-of-meta-data)
  10006. ;; Ensure point is left on a blank line, at proper indentation.
  10007. (unless (bolp) (insert "\n"))
  10008. (unless (looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
  10009. (when org-adapt-indentation (indent-to-column col)))
  10010. (org-fold-show-set-visibility 'lineage))
  10011. (defun org-agenda-diary-entry ()
  10012. "Make a diary entry, like the `i' command from the calendar.
  10013. All the standard commands work: block, weekly etc.
  10014. When `org-agenda-diary-file' points to a file,
  10015. `org-agenda-diary-entry-in-org-file' is called instead to create
  10016. entries in that Org file."
  10017. (interactive)
  10018. (if (not (eq org-agenda-diary-file 'diary-file))
  10019. (org-agenda-diary-entry-in-org-file)
  10020. (require 'diary-lib)
  10021. (let* ((char (read-char-exclusive
  10022. "Diary entry: [d]ay [w]eekly [m]onthly [y]early\
  10023. [a]nniversary [b]lock [c]yclic"))
  10024. (cmd (cdr (assoc char
  10025. '((?d . diary-insert-entry)
  10026. (?w . diary-insert-weekly-entry)
  10027. (?m . diary-insert-monthly-entry)
  10028. (?y . diary-insert-yearly-entry)
  10029. (?a . diary-insert-anniversary-entry)
  10030. (?b . diary-insert-block-entry)
  10031. (?c . diary-insert-cyclic-entry)))))
  10032. (oldf (symbol-function 'calendar-cursor-to-date))
  10033. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  10034. (point (point))
  10035. (mark (or (mark t) (point))))
  10036. (unless cmd
  10037. (user-error "No command associated with <%c>" char))
  10038. (unless (and (get-text-property point 'day)
  10039. (or (not (equal ?b char))
  10040. (get-text-property mark 'day)))
  10041. (user-error "Don't know which date to use for diary entry"))
  10042. ;; We implement this by hacking the `calendar-cursor-to-date' function
  10043. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  10044. (let ((calendar-mark-ring
  10045. (list (calendar-gregorian-from-absolute
  10046. (or (get-text-property mark 'day)
  10047. (get-text-property point 'day))))))
  10048. (unwind-protect
  10049. (progn
  10050. (fset 'calendar-cursor-to-date
  10051. (lambda (&optional _error _dummy)
  10052. (calendar-gregorian-from-absolute
  10053. (get-text-property point 'day))))
  10054. (call-interactively cmd))
  10055. (fset 'calendar-cursor-to-date oldf))))))
  10056. (defun org-agenda-execute-calendar-command (cmd)
  10057. "Execute a calendar command from the agenda with date from cursor."
  10058. (org-agenda-check-type t 'agenda)
  10059. (require 'diary-lib)
  10060. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  10061. (user-error "Don't know which date to use for the calendar command"))
  10062. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  10063. (point (point))
  10064. (date (calendar-gregorian-from-absolute
  10065. (get-text-property point 'day))))
  10066. ;; the following 2 vars are needed in the calendar
  10067. (org-dlet
  10068. ((displayed-month (car date))
  10069. (displayed-year (nth 2 date)))
  10070. (unwind-protect
  10071. (progn
  10072. (fset 'calendar-cursor-to-date
  10073. (lambda (&optional _error _dummy)
  10074. (calendar-gregorian-from-absolute
  10075. (get-text-property point 'day))))
  10076. (call-interactively cmd))
  10077. (fset 'calendar-cursor-to-date oldf)))))
  10078. (defun org-agenda-phases-of-moon ()
  10079. "Display the phases of the moon for the 3 months around the cursor date."
  10080. (interactive)
  10081. (org-agenda-execute-calendar-command 'calendar-lunar-phases))
  10082. (defun org-agenda-holidays ()
  10083. "Display the holidays for the 3 months around the cursor date."
  10084. (interactive)
  10085. (org-agenda-execute-calendar-command 'calendar-list-holidays))
  10086. (defvar calendar-longitude) ; defined in calendar.el
  10087. (defvar calendar-latitude) ; defined in calendar.el
  10088. (defvar calendar-location-name) ; defined in calendar.el
  10089. (defun org-agenda-sunrise-sunset (arg)
  10090. "Display sunrise and sunset for the cursor date.
  10091. Latitude and longitude can be specified with the variables
  10092. `calendar-latitude' and `calendar-longitude'. When called with prefix
  10093. argument, latitude and longitude will be prompted for."
  10094. (interactive "P")
  10095. (require 'solar)
  10096. (let ((calendar-longitude (if arg nil calendar-longitude))
  10097. (calendar-latitude (if arg nil calendar-latitude))
  10098. (calendar-location-name
  10099. (if arg "the given coordinates" calendar-location-name)))
  10100. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  10101. (defun org-agenda-goto-calendar ()
  10102. "Open the Emacs calendar with the date at the cursor."
  10103. (interactive)
  10104. (org-agenda-check-type t 'agenda)
  10105. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  10106. (user-error "Don't know which date to open in calendar")))
  10107. (date (calendar-gregorian-from-absolute day))
  10108. (calendar-move-hook nil)
  10109. (calendar-view-holidays-initially-flag nil)
  10110. (calendar-view-diary-initially-flag nil))
  10111. (calendar)
  10112. (calendar-goto-date date)))
  10113. ;;;###autoload
  10114. (defun org-calendar-goto-agenda ()
  10115. "Compute the Org agenda for the calendar date displayed at the cursor.
  10116. This is a command that has to be installed in `calendar-mode-map'."
  10117. (interactive)
  10118. ;; Temporarily disable sticky agenda since user clearly wants to
  10119. ;; refresh view anyway.
  10120. (let ((org-agenda-buffer-tmp-name "*Org Agenda(a)*")
  10121. (org-agenda-sticky nil))
  10122. (org-agenda-list nil (calendar-absolute-from-gregorian
  10123. (calendar-cursor-to-date))
  10124. nil)))
  10125. (defun org-agenda-convert-date ()
  10126. (interactive)
  10127. (org-agenda-check-type t 'agenda)
  10128. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  10129. date s)
  10130. (unless day
  10131. (user-error "Don't know which date to convert"))
  10132. (setq date (calendar-gregorian-from-absolute day))
  10133. (setq s (concat
  10134. "Gregorian: " (calendar-date-string date) "\n"
  10135. "ISO: " (calendar-iso-date-string date) "\n"
  10136. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  10137. "Julian: " (calendar-julian-date-string date) "\n"
  10138. "Astron. JD: " (calendar-astro-date-string date)
  10139. " (Julian date number at noon UTC)\n"
  10140. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  10141. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  10142. "French: " (calendar-french-date-string date) "\n"
  10143. "Bahá’í: " (calendar-bahai-date-string date) " (until sunset)\n"
  10144. "Mayan: " (calendar-mayan-date-string date) "\n"
  10145. "Coptic: " (calendar-coptic-date-string date) "\n"
  10146. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  10147. "Persian: " (calendar-persian-date-string date) "\n"
  10148. "Chinese: " (calendar-chinese-date-string date) "\n"))
  10149. (with-output-to-temp-buffer "*Dates*"
  10150. (princ s))
  10151. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  10152. ;;; Bulk commands
  10153. (defun org-agenda-bulk-marked-p ()
  10154. "Non-nil when current entry is marked for bulk action."
  10155. (eq (get-char-property (line-beginning-position) 'type)
  10156. 'org-marked-entry-overlay))
  10157. (defun org-agenda-bulk-mark (&optional arg)
  10158. "Mark entries for future bulk action.
  10159. When ARG is nil or one and region is not active then mark the
  10160. entry at point.
  10161. When ARG is nil or one and region is active then mark the entries
  10162. in the region.
  10163. When ARG is greater than one mark ARG lines."
  10164. (interactive "p")
  10165. (when (and (or (not arg) (= arg 1)) (use-region-p))
  10166. (setq arg (count-lines (region-beginning) (region-end)))
  10167. (goto-char (region-beginning))
  10168. (deactivate-mark))
  10169. (dotimes (_ (or arg 1))
  10170. (unless (org-get-at-bol 'org-agenda-diary-link)
  10171. (let* ((m (org-get-at-bol 'org-hd-marker))
  10172. ov)
  10173. (unless (org-agenda-bulk-marked-p)
  10174. (unless m (user-error "Nothing to mark at point"))
  10175. (push m org-agenda-bulk-marked-entries)
  10176. (setq ov (make-overlay (line-beginning-position)
  10177. (+ 2 (line-beginning-position))))
  10178. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  10179. (org-get-todo-face "TODO")
  10180. 'evaporate)
  10181. (overlay-put ov 'type 'org-marked-entry-overlay))
  10182. (end-of-line 1)
  10183. (or (ignore-errors
  10184. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  10185. (beginning-of-line 2))
  10186. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  10187. (beginning-of-line 2)))))
  10188. (message "%d entries marked for bulk action"
  10189. (length org-agenda-bulk-marked-entries)))
  10190. (defun org-agenda-bulk-mark-all ()
  10191. "Mark all entries for future agenda bulk action."
  10192. (interactive)
  10193. (org-agenda-bulk-mark-regexp "."))
  10194. (defun org-agenda-bulk-mark-regexp (regexp)
  10195. "Mark entries matching REGEXP for future agenda bulk action."
  10196. (interactive "sMark entries matching regexp: ")
  10197. (let ((entries-marked 0) txt-at-point)
  10198. (save-excursion
  10199. (goto-char (point-min))
  10200. (goto-char (next-single-property-change (point) 'org-hd-marker))
  10201. (while (and (re-search-forward regexp nil t)
  10202. (setq txt-at-point
  10203. (get-text-property (match-beginning 0) 'txt)))
  10204. (if (get-char-property (point) 'invisible)
  10205. (beginning-of-line 2)
  10206. (when (string-match-p regexp txt-at-point)
  10207. (setq entries-marked (1+ entries-marked))
  10208. (call-interactively 'org-agenda-bulk-mark)))))
  10209. (unless entries-marked
  10210. (message "No entry matching this regexp."))))
  10211. (defun org-agenda-bulk-unmark (&optional arg)
  10212. "Unmark the entry at point for future bulk action."
  10213. (interactive "P")
  10214. (if arg
  10215. (org-agenda-bulk-unmark-all)
  10216. (cond ((org-agenda-bulk-marked-p)
  10217. (org-agenda-bulk-remove-overlays
  10218. (line-beginning-position) (+ 2 (line-beginning-position)))
  10219. (setq org-agenda-bulk-marked-entries
  10220. (delete (org-get-at-bol 'org-hd-marker)
  10221. org-agenda-bulk-marked-entries))
  10222. (end-of-line 1)
  10223. (or (ignore-errors
  10224. (goto-char (next-single-property-change (point) 'txt)))
  10225. (beginning-of-line 2))
  10226. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  10227. (beginning-of-line 2))
  10228. (message "%d entries left marked for bulk action"
  10229. (length org-agenda-bulk-marked-entries)))
  10230. (t (message "No entry to unmark here")))))
  10231. (defun org-agenda-bulk-toggle-all ()
  10232. "Toggle all marks for bulk action."
  10233. (interactive)
  10234. (save-excursion
  10235. (goto-char (point-min))
  10236. (while (ignore-errors
  10237. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  10238. (org-agenda-bulk-toggle))))
  10239. (defun org-agenda-bulk-toggle ()
  10240. "Toggle the mark at point for bulk action."
  10241. (interactive)
  10242. (if (org-agenda-bulk-marked-p)
  10243. (org-agenda-bulk-unmark)
  10244. (org-agenda-bulk-mark)))
  10245. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  10246. "Remove the mark overlays between BEG and END in the agenda buffer.
  10247. BEG and END default to the buffer limits.
  10248. This only removes the overlays, it does not remove the markers
  10249. from the list in `org-agenda-bulk-marked-entries'."
  10250. (interactive)
  10251. (mapc (lambda (ov)
  10252. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  10253. (delete-overlay ov)))
  10254. (overlays-in (or beg (point-min)) (or end (point-max)))))
  10255. (defun org-agenda-bulk-unmark-all ()
  10256. "Remove all marks in the agenda buffer.
  10257. This will remove the markers and the overlays."
  10258. (interactive)
  10259. (if (null org-agenda-bulk-marked-entries)
  10260. (message "No entry to unmark")
  10261. (setq org-agenda-bulk-marked-entries nil)
  10262. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  10263. (defcustom org-agenda-persistent-marks nil
  10264. "Non-nil means marked items will stay marked after a bulk action.
  10265. You can toggle this interactively by typing `p' when prompted for a
  10266. bulk action."
  10267. :group 'org-agenda
  10268. :version "24.1"
  10269. :type 'boolean)
  10270. (defcustom org-agenda-loop-over-headlines-in-active-region t
  10271. "Shall some commands act upon headlines in the active region?
  10272. When set to t, some commands will be performed in all headlines
  10273. within the active region.
  10274. When set to `start-level', some commands will be performed in all
  10275. headlines within the active region, provided that these headlines
  10276. are of the same level than the first one.
  10277. When set to a regular expression, those commands will be
  10278. performed on the matching headlines within the active region.
  10279. The list of commands is: `org-agenda-schedule',
  10280. `org-agenda-deadline', `org-agenda-date-prompt',
  10281. `org-agenda-todo', `org-agenda-archive*', `org-agenda-kill'.
  10282. See `org-loop-over-headlines-in-active-region' for the equivalent
  10283. option for Org buffers."
  10284. :type '(choice (const :tag "Don't loop" nil)
  10285. (const :tag "All headlines in active region" t)
  10286. (const :tag "In active region, headlines at the same level than the first one" start-level)
  10287. (regexp :tag "Regular expression matcher"))
  10288. :version "27.1"
  10289. :package-version '(Org . "9.4")
  10290. :group 'org-agenda)
  10291. (defun org-agenda-bulk-action (&optional arg)
  10292. "Execute an remote-editing action on all marked entries.
  10293. The prefix arg is passed through to the command if possible."
  10294. (interactive "P")
  10295. ;; When there is no mark, act on the agenda entry at point.
  10296. (if (not org-agenda-bulk-marked-entries)
  10297. (save-excursion (org-agenda-bulk-mark)))
  10298. (dolist (m org-agenda-bulk-marked-entries)
  10299. (unless (and (markerp m)
  10300. (marker-buffer m)
  10301. (buffer-live-p (marker-buffer m))
  10302. (marker-position m))
  10303. (user-error "Marker %s for bulk command is invalid" m)))
  10304. ;; Prompt for the bulk command.
  10305. (org-unlogged-message
  10306. (concat "Bulk (" (if org-agenda-persistent-marks "" "don't ") "[p]ersist marks): "
  10307. "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  10308. "[S]catter [f]unction "
  10309. (and org-agenda-bulk-custom-functions
  10310. (format " Custom: [%s]"
  10311. (mapconcat (lambda (f) (char-to-string (car f)))
  10312. org-agenda-bulk-custom-functions
  10313. "")))))
  10314. (catch 'exit
  10315. (let* ((org-log-refile (if org-log-refile 'time nil))
  10316. (entries (reverse org-agenda-bulk-marked-entries))
  10317. (org-overriding-default-time
  10318. (and (get-text-property (point) 'org-agenda-date-header)
  10319. (org-get-cursor-date)))
  10320. redo-at-end
  10321. cmd)
  10322. (pcase (read-char-exclusive)
  10323. (?p
  10324. (let ((org-agenda-persistent-marks
  10325. (not org-agenda-persistent-marks)))
  10326. (org-agenda-bulk-action)
  10327. (throw 'exit nil)))
  10328. (?$
  10329. (setq cmd #'org-agenda-archive))
  10330. (?A
  10331. (setq cmd #'org-agenda-archive-to-archive-sibling))
  10332. ((or ?r ?w)
  10333. (let ((refile-location
  10334. (org-refile-get-location
  10335. "Refile to"
  10336. (marker-buffer (car entries))
  10337. org-refile-allow-creating-parent-nodes)))
  10338. (when (nth 3 refile-location)
  10339. (setcar (nthcdr 3 refile-location)
  10340. (move-marker
  10341. (make-marker)
  10342. (nth 3 refile-location)
  10343. (or (get-file-buffer (nth 1 refile-location))
  10344. (find-buffer-visiting (nth 1 refile-location))
  10345. (error "This should not happen")))))
  10346. (setq cmd (lambda () (org-agenda-refile nil refile-location t)))
  10347. (setq redo-at-end t)))
  10348. (?t
  10349. (let ((state (completing-read
  10350. "Todo state: "
  10351. (with-current-buffer (marker-buffer (car entries))
  10352. (mapcar #'list org-todo-keywords-1)))))
  10353. (setq cmd (lambda ()
  10354. (let ((org-inhibit-blocking t)
  10355. (org-inhibit-logging 'note))
  10356. (org-agenda-todo state))))))
  10357. ((and (or ?- ?+) action)
  10358. (let ((tag (completing-read
  10359. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  10360. (with-current-buffer (marker-buffer (car entries))
  10361. (delq nil
  10362. (mapcar (lambda (x) (and (stringp (car x)) x))
  10363. org-current-tag-alist))))))
  10364. (setq cmd
  10365. (lambda ()
  10366. (org-agenda-set-tags tag
  10367. (if (eq action ?+) 'on 'off))))))
  10368. ((and (or ?s ?d) c)
  10369. (let* ((schedule? (eq c ?s))
  10370. (prompt (if schedule? "(Re)Schedule to" "(Re)Set Deadline to"))
  10371. (time
  10372. (and (not arg)
  10373. (let ((new (org-read-date
  10374. nil nil nil prompt org-overriding-default-time)))
  10375. ;; A "double plus" answer applies to every
  10376. ;; scheduled time. Do not turn it into
  10377. ;; a fixed date yet.
  10378. (if (string-match-p "\\`[ \t]*\\+\\+"
  10379. org-read-date-final-answer)
  10380. org-read-date-final-answer
  10381. new)))))
  10382. ;; Make sure to not prompt for a note when bulk
  10383. ;; rescheduling/resetting deadline as Org cannot cope with
  10384. ;; simultaneous notes. Besides, it could be annoying
  10385. ;; depending on the number of marked items.
  10386. (setq cmd
  10387. (if schedule?
  10388. (lambda ()
  10389. (let ((org-log-reschedule
  10390. (and org-log-reschedule 'time)))
  10391. (org-agenda-schedule arg time)))
  10392. (lambda ()
  10393. (let ((org-log-redeadline (and org-log-redeadline 'time)))
  10394. (org-agenda-deadline arg time)))))))
  10395. (?S
  10396. (unless (org-agenda-check-type nil 'agenda 'todo)
  10397. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type))
  10398. (let ((days (read-number
  10399. (format "Scatter tasks across how many %sdays: "
  10400. (if arg "week" ""))
  10401. 7)))
  10402. (setq cmd
  10403. (lambda ()
  10404. (let ((distance (1+ (random days))))
  10405. (when arg
  10406. (let ((dist distance)
  10407. (day-of-week
  10408. (calendar-day-of-week
  10409. (calendar-gregorian-from-absolute (org-today)))))
  10410. (dotimes (_ (1+ dist))
  10411. (while (member day-of-week org-agenda-weekend-days)
  10412. (cl-incf distance)
  10413. (cl-incf day-of-week)
  10414. (when (= day-of-week 7)
  10415. (setq day-of-week 0)))
  10416. (cl-incf day-of-week)
  10417. (when (= day-of-week 7)
  10418. (setq day-of-week 0)))))
  10419. ;; Silently fail when try to replan a sexp entry.
  10420. (ignore-errors
  10421. (let* ((date (calendar-gregorian-from-absolute
  10422. (+ (org-today) distance)))
  10423. (time (org-encode-time
  10424. 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  10425. (org-agenda-schedule nil time))))))))
  10426. (?f
  10427. (setq cmd
  10428. (intern
  10429. (completing-read "Function: " obarray #'fboundp t nil nil))))
  10430. (action
  10431. (setq cmd
  10432. (pcase (assoc action org-agenda-bulk-custom-functions)
  10433. (`(,_ ,fn)
  10434. fn)
  10435. (`(,_ ,fn ,arg-fn)
  10436. (apply #'apply-partially fn (funcall arg-fn)))
  10437. (_
  10438. (user-error "Invalid bulk action: %c" action))))
  10439. (setq redo-at-end t)))
  10440. ;; Sort the markers, to make sure that parents are handled
  10441. ;; before children.
  10442. (setq entries (sort entries
  10443. (lambda (a b)
  10444. (cond
  10445. ((eq (marker-buffer a) (marker-buffer b))
  10446. (< (marker-position a) (marker-position b)))
  10447. (t
  10448. (string< (buffer-name (marker-buffer a))
  10449. (buffer-name (marker-buffer b))))))))
  10450. ;; Now loop over all markers and apply CMD.
  10451. (let ((processed 0)
  10452. (skipped 0))
  10453. (dolist (e entries)
  10454. (let ((pos (text-property-any (point-min) (point-max) 'org-hd-marker e)))
  10455. (if (not pos)
  10456. (progn (message "Skipping removed entry at %s" e)
  10457. (cl-incf skipped))
  10458. (goto-char pos)
  10459. (let (org-loop-over-headlines-in-active-region) (funcall cmd))
  10460. ;; `post-command-hook' is not run yet. We make sure any
  10461. ;; pending log note is processed.
  10462. (when org-log-setup (org-add-log-note))
  10463. (cl-incf processed))))
  10464. (when redo-at-end (org-agenda-redo))
  10465. (unless org-agenda-persistent-marks (org-agenda-bulk-unmark-all))
  10466. (message "Acted on %d entries%s%s"
  10467. processed
  10468. (if (= skipped 0)
  10469. ""
  10470. (format ", skipped %d (disappeared before their turn)"
  10471. skipped))
  10472. (if (not org-agenda-persistent-marks) "" " (kept marked)"))))))
  10473. (defun org-agenda-capture (&optional with-time)
  10474. "Call `org-capture' with the date at point.
  10475. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  10476. current HH:MM time."
  10477. (interactive "P")
  10478. (if (not (eq major-mode 'org-agenda-mode))
  10479. (user-error "You cannot do this outside of agenda buffers")
  10480. (let ((org-overriding-default-time
  10481. (org-get-cursor-date (equal with-time 1))))
  10482. (call-interactively 'org-capture))))
  10483. ;;; Dragging agenda lines forward/backward
  10484. (defun org-agenda-reapply-filters ()
  10485. "Re-apply all agenda filters."
  10486. (mapcar
  10487. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f) t)))
  10488. `((,org-agenda-tag-filter tag)
  10489. (,org-agenda-category-filter category)
  10490. (,org-agenda-regexp-filter regexp)
  10491. (,org-agenda-effort-filter effort)
  10492. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  10493. (,(get 'org-agenda-category-filter :preset-filter) category)
  10494. (,(get 'org-agenda-effort-filter :preset-filter) effort)
  10495. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  10496. (defun org-agenda-drag-line-forward (arg &optional backward)
  10497. "Drag an agenda line forward by ARG lines.
  10498. When the optional argument `backward' is non-nil, move backward."
  10499. (interactive "p")
  10500. (let ((inhibit-read-only t) lst line)
  10501. (if (or (not (get-text-property (point) 'txt))
  10502. (save-excursion
  10503. (dotimes (_ arg)
  10504. (move-beginning-of-line (if backward 0 2))
  10505. (push (not (get-text-property (point) 'txt)) lst))
  10506. (delq nil lst)))
  10507. (message "Cannot move line forward")
  10508. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  10509. (move-beginning-of-line 1)
  10510. (setq line (buffer-substring (point) end))
  10511. (delete-region (point) end)
  10512. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  10513. (insert line)
  10514. (org-agenda-reapply-filters)
  10515. (org-agenda-mark-clocking-task)
  10516. (move-beginning-of-line 0)))))
  10517. (defun org-agenda-drag-line-backward (arg)
  10518. "Drag an agenda line backward by ARG lines."
  10519. (interactive "p")
  10520. (org-agenda-drag-line-forward arg t))
  10521. ;;; Flagging notes
  10522. (defun org-agenda-show-the-flagging-note ()
  10523. "Display the flagging note in the other window.
  10524. When called a second time in direct sequence, offer to remove the FLAGGING
  10525. tag and (if present) the flagging note."
  10526. (interactive)
  10527. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  10528. (win (selected-window))
  10529. note) ;; heading newhead
  10530. (unless hdmarker
  10531. (user-error "No linked entry at point"))
  10532. (if (and (eq this-command last-command)
  10533. (y-or-n-p "Unflag and remove any flagging note? "))
  10534. (progn
  10535. (org-agenda-remove-flag hdmarker)
  10536. (let ((win (get-buffer-window "*Flagging Note*")))
  10537. (and win (delete-window win)))
  10538. (message "Entry unflagged"))
  10539. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  10540. (unless note
  10541. (user-error "No flagging note"))
  10542. (org-kill-new note)
  10543. (org-switch-to-buffer-other-window "*Flagging Note*")
  10544. (erase-buffer)
  10545. (insert note)
  10546. (goto-char (point-min))
  10547. (while (re-search-forward "\\\\n" nil t)
  10548. (replace-match "\n" t t))
  10549. (goto-char (point-min))
  10550. (select-window win)
  10551. (message "%s" (substitute-command-keys "Flagging note pushed to \
  10552. kill ring. Press `\\[org-agenda-show-the-flagging-note]' again to remove \
  10553. tag and note")))))
  10554. (defun org-agenda-remove-flag (marker)
  10555. "Remove the FLAGGED tag and any flagging note in the entry."
  10556. (let ((newhead
  10557. (org-with-point-at marker
  10558. (org-toggle-tag "FLAGGED" 'off)
  10559. (org-entry-delete nil "THEFLAGGINGNOTE")
  10560. (org-get-heading))))
  10561. (org-agenda-change-all-lines newhead marker)
  10562. (message "Entry unflagged")))
  10563. (defun org-agenda-get-any-marker (&optional pos)
  10564. (or (get-text-property (or pos (line-beginning-position)) 'org-hd-marker)
  10565. (get-text-property (or pos (line-beginning-position)) 'org-marker)))
  10566. ;;; Appointment reminders
  10567. (defvar appt-time-msg-list) ; defined in appt.el
  10568. ;;;###autoload
  10569. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  10570. "Activate appointments found in `org-agenda-files'.
  10571. With a `\\[universal-argument]' prefix, refresh the list of \
  10572. appointments.
  10573. If FILTER is t, interactively prompt the user for a regular
  10574. expression, and filter out entries that don't match it.
  10575. If FILTER is a string, use this string as a regular expression
  10576. for filtering entries out.
  10577. If FILTER is a function, filter out entries against which
  10578. calling the function returns nil. This function takes one
  10579. argument: an entry from `org-agenda-get-day-entries'.
  10580. FILTER can also be an alist with the car of each cell being
  10581. either `headline' or `category'. For example:
  10582. ((headline \"IMPORTANT\")
  10583. (category \"Work\"))
  10584. will only add headlines containing IMPORTANT or headlines
  10585. belonging to the \"Work\" category.
  10586. ARGS are symbols indicating what kind of entries to consider.
  10587. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  10588. \(i.e., deadlines and scheduled items with a hh:mm specification)
  10589. and :timestamp entries. See the docstring of `org-diary' for
  10590. details and examples.
  10591. If an entry has a APPT_WARNTIME property, its value will be used
  10592. to override `appt-message-warning-time'."
  10593. (interactive "P")
  10594. (when refresh (setq appt-time-msg-list nil))
  10595. (when (eq filter t)
  10596. (setq filter (read-from-minibuffer "Regexp filter: ")))
  10597. (let* ((cnt 0) ; count added events
  10598. (scope (or args '(:deadline* :scheduled* :timestamp)))
  10599. (org-agenda-new-buffers nil)
  10600. (org-deadline-warning-days 0)
  10601. ;; Do not use `org-today' here because appt only takes
  10602. ;; time and without date as argument, so it may pass wrong
  10603. ;; information otherwise
  10604. (today (org-date-to-gregorian
  10605. (time-to-days nil)))
  10606. (org-agenda-restrict nil)
  10607. (files (org-agenda-files 'unrestricted)) entries file
  10608. (org-agenda-buffer nil))
  10609. ;; Get all entries which may contain an appt
  10610. (org-agenda-prepare-buffers files)
  10611. (while (setq file (pop files))
  10612. (setq entries
  10613. (delq nil
  10614. (append entries
  10615. (apply #'org-agenda-get-day-entries
  10616. file today scope)))))
  10617. ;; Map through entries and find if we should filter them out
  10618. (mapc
  10619. (lambda (x)
  10620. (let* ((evt (org-trim
  10621. (replace-regexp-in-string
  10622. org-link-bracket-re "\\2"
  10623. (or (get-text-property 1 'txt x) ""))))
  10624. (cat (get-text-property (1- (length x)) 'org-category x))
  10625. (tod (get-text-property 1 'time-of-day x))
  10626. (ok (or (null filter)
  10627. (and (stringp filter) (string-match filter evt))
  10628. (and (functionp filter) (funcall filter x))
  10629. (and (listp filter)
  10630. (let ((cat-filter (cadr (assq 'category filter)))
  10631. (evt-filter (cadr (assq 'headline filter))))
  10632. (or (and (stringp cat-filter)
  10633. (string-match cat-filter cat))
  10634. (and (stringp evt-filter)
  10635. (string-match evt-filter evt)))))))
  10636. (wrn (get-text-property 1 'warntime x)))
  10637. ;; FIXME: Shall we remove text-properties for the appt text?
  10638. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  10639. (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
  10640. (setq tod (concat "00" (number-to-string tod)))
  10641. (setq tod (when (string-match
  10642. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  10643. (concat (match-string 1 tod) ":"
  10644. (match-string 2 tod))))
  10645. (when (appt-add tod evt wrn)
  10646. (setq cnt (1+ cnt))))))
  10647. entries)
  10648. (org-release-buffers org-agenda-new-buffers)
  10649. (if (eq cnt 0)
  10650. (message "No event to add")
  10651. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  10652. (defun org-agenda-today-p (date)
  10653. "Non-nil when DATE means today.
  10654. DATE is either a list of the form (month day year) or a number of
  10655. days as returned by `calendar-absolute-from-gregorian' or
  10656. `org-today'. This function considers `org-extend-today-until'
  10657. when defining today."
  10658. (eq (org-today)
  10659. (if (consp date) (calendar-absolute-from-gregorian date) date)))
  10660. (defun org-agenda-todo-yesterday (&optional arg)
  10661. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  10662. (interactive "P")
  10663. (let* ((org-use-effective-time t)
  10664. (hour (nth 2 (decode-time (org-current-time))))
  10665. (org-extend-today-until (1+ hour)))
  10666. (org-agenda-todo arg)))
  10667. (defun org-agenda-ctrl-c-ctrl-c ()
  10668. "Set tags in agenda buffer."
  10669. (interactive)
  10670. (org-agenda-set-tags))
  10671. (provide 'org-agenda)
  10672. ;;; org-agenda.el ends here