org-agenda.el 447 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414
  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-habit-insert-consistency-graphs
  77. "org-habit" (&optional line))
  78. (declare-function org-is-habit-p "org-habit" (&optional pom))
  79. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  80. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  81. (declare-function org-agenda-columns "org-colview" ())
  82. (declare-function org-add-archive-files "org-archive" (files))
  83. (declare-function org-capture "org-capture" (&optional goto keys))
  84. (declare-function org-clock-modify-effort-estimate "org-clock" (&optional value))
  85. (declare-function org-element-type "org-element" (&optional element))
  86. (defvar calendar-mode-map)
  87. (defvar org-clock-current-task)
  88. (defvar org-current-tag-alist)
  89. (defvar org-mobile-force-id-on-agenda-items)
  90. (defvar org-habit-show-habits)
  91. (defvar org-habit-show-habits-only-for-today)
  92. (defvar org-habit-show-all-today)
  93. (defvar org-habit-scheduled-past-days)
  94. ;; Defined somewhere in this file, but used before definition.
  95. (defvar org-agenda-buffer-name "*Org Agenda*")
  96. (defvar org-agenda-title-append nil)
  97. (defvar org-agenda-overriding-header)
  98. ;; (with-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  99. ;; (with-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  100. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  101. (defvar org-agenda-undo-list nil
  102. "List of undoable operations in the agenda since last refresh.")
  103. (defvar org-agenda-pending-undo-list nil
  104. "In a series of undo commands, this is the list of remaining undo items.")
  105. (defcustom org-agenda-confirm-kill 1
  106. "When set, remote killing from the agenda buffer needs confirmation.
  107. When t, a confirmation is always needed. When a number N, confirmation is
  108. only needed when the text to be killed contains more than N non-white lines."
  109. :group 'org-agenda
  110. :type '(choice
  111. (const :tag "Never" nil)
  112. (const :tag "Always" t)
  113. (integer :tag "When more than N lines")))
  114. (defcustom org-agenda-compact-blocks nil
  115. "Non-nil means make the block agenda more compact.
  116. This is done globally by leaving out lines like the agenda span
  117. name and week number or the separator lines."
  118. :group 'org-agenda
  119. :type 'boolean)
  120. (defcustom org-agenda-block-separator
  121. (if (and (display-graphic-p)
  122. (char-displayable-p ?─))
  123. ?─
  124. ?=)
  125. "The separator between blocks in the agenda.
  126. If this is a string, it will be used as the separator, with a newline added.
  127. If it is a character, it will be repeated to fill the window width.
  128. If nil the separator is disabled. In `org-agenda-custom-commands' this
  129. addresses the separator between the current and the previous block."
  130. :group 'org-agenda
  131. :version "29.1"
  132. :type '(choice
  133. (const :tag "Disabled" nil)
  134. (character)
  135. (string)))
  136. (defgroup org-agenda-export nil
  137. "Options concerning exporting agenda views in Org mode."
  138. :tag "Org Agenda Export"
  139. :group 'org-agenda)
  140. (defcustom org-agenda-with-colors t
  141. "Non-nil means use colors in agenda views."
  142. :group 'org-agenda-export
  143. :type 'boolean)
  144. (defcustom org-agenda-exporter-settings nil
  145. ;; FIXME: Do we really want to evaluate those settings and thus force
  146. ;; the user to use `quote' all the time?
  147. "Alist of variable/value pairs that should be active during agenda export.
  148. This is a good place to set options for ps-print and for htmlize.
  149. Note that the way this is implemented, the values will be evaluated
  150. before assigned to the variables. So make sure to quote values you do
  151. *not* want evaluated, for example
  152. (setq org-agenda-exporter-settings
  153. \\='((ps-print-color-p \\='black-white)))"
  154. :group 'org-agenda-export
  155. :type '(repeat
  156. (list
  157. (variable)
  158. (sexp :tag "Value"))))
  159. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  160. "Hook run in a temporary buffer before writing the agenda to an export file.
  161. A useful function for this hook is `org-agenda-add-entry-text'."
  162. :group 'org-agenda-export
  163. :type 'hook
  164. :options '(org-agenda-add-entry-text))
  165. (defcustom org-agenda-add-entry-text-maxlines 0
  166. "Maximum number of entry text lines to be added to agenda.
  167. This is only relevant when `org-agenda-add-entry-text' is part of
  168. `org-agenda-before-write-hook', which is the default.
  169. When this is 0, nothing will happen. When it is greater than 0, it
  170. specifies the maximum number of lines that will be added for each entry
  171. that is listed in the agenda view.
  172. Note that this variable is not used during display, only when exporting
  173. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  174. and `org-agenda-entry-text-maxlines'."
  175. :group 'org-agenda
  176. :type 'integer)
  177. (defcustom org-agenda-add-entry-text-descriptive-links t
  178. "Non-nil means export org-links as descriptive links in agenda added text.
  179. This variable applies to the text added to the agenda when
  180. `org-agenda-add-entry-text-maxlines' is larger than 0.
  181. When this variable is nil, the URL will (also) be shown."
  182. :group 'org-agenda
  183. :type 'boolean)
  184. (defcustom org-agenda-export-html-style nil
  185. "The style specification for exported HTML Agenda files.
  186. If this variable contains a string, it will replace the default <style>
  187. section as produced by `htmlize'.
  188. Since there are different ways of setting style information, this variable
  189. needs to contain the full HTML structure to provide a style, including the
  190. surrounding HTML tags. The style specifications should include definitions
  191. the fonts used by the agenda, here is an example:
  192. <style type=\"text/css\">
  193. p { font-weight: normal; color: gray; }
  194. .org-agenda-structure {
  195. font-size: 110%;
  196. color: #003399;
  197. font-weight: 600;
  198. }
  199. .org-todo {
  200. color: #cc6666;
  201. font-weight: bold;
  202. }
  203. .org-agenda-done {
  204. color: #339933;
  205. }
  206. .org-done {
  207. color: #339933;
  208. }
  209. .title { text-align: center; }
  210. .todo, .deadline { color: red; }
  211. .done { color: green; }
  212. </style>
  213. or, if you want to keep the style in a file,
  214. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  215. As the value of this option simply gets inserted into the HTML <head> header,
  216. you can \"misuse\" it to also add other text to the header."
  217. :group 'org-agenda-export
  218. :group 'org-export-html
  219. :type '(choice
  220. (const nil)
  221. (string)))
  222. (defcustom org-agenda-persistent-filter nil
  223. "When set, keep filters from one agenda view to the next."
  224. :group 'org-agenda
  225. :type 'boolean)
  226. (defgroup org-agenda-custom-commands nil
  227. "Options concerning agenda views in Org mode."
  228. :tag "Org Agenda Custom Commands"
  229. :group 'org-agenda)
  230. (defconst org-sorting-choice
  231. '(choice
  232. (const time-up) (const time-down)
  233. (const timestamp-up) (const timestamp-down)
  234. (const scheduled-up) (const scheduled-down)
  235. (const deadline-up) (const deadline-down)
  236. (const ts-up) (const ts-down)
  237. (const tsia-up) (const tsia-down)
  238. (const category-keep) (const category-up) (const category-down)
  239. (const tag-down) (const tag-up)
  240. (const priority-up) (const priority-down)
  241. (const todo-state-up) (const todo-state-down)
  242. (const effort-up) (const effort-down)
  243. (const habit-up) (const habit-down)
  244. (const alpha-up) (const alpha-down)
  245. (const user-defined-up) (const user-defined-down))
  246. "Sorting choices.")
  247. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  248. ;; the new variable `org-agenda-tag-filter-preset'.
  249. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  250. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  251. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  252. "List of types searched for when creating the daily/weekly agenda.
  253. This variable is a list of symbols that controls the types of
  254. items that appear in the daily/weekly agenda. Allowed symbols in this
  255. list are
  256. :timestamp List items containing a date stamp or date range matching
  257. the selected date. This includes sexp entries in angular
  258. brackets.
  259. :sexp List entries resulting from plain diary-like sexps.
  260. :deadline List deadline due on that date. When the date is today,
  261. also list any deadlines past due, or due within
  262. `org-deadline-warning-days'.
  263. :deadline* Same as above, but only include the deadline if it has an
  264. hour specification as [h]h:mm.
  265. :scheduled List all items which are scheduled for the given date.
  266. The diary for *today* also contains items which were
  267. scheduled earlier and are not yet marked DONE.
  268. :scheduled* Same as above, but only include the scheduled item if it
  269. has an hour specification as [h]h:mm.
  270. By default, all four non-starred types are turned on.
  271. When :scheduled* or :deadline* are included, :schedule or :deadline
  272. will be ignored.
  273. Never set this variable globally using `setq', because then it
  274. will apply to all future agenda commands. Instead, bind it with
  275. `let' to scope it dynamically into the agenda-constructing
  276. command. A good way to set it is through options in
  277. `org-agenda-custom-commands'. For a more flexible (though
  278. somewhat less efficient) way of determining what is included in
  279. the daily/weekly agenda, see `org-agenda-skip-function'.")
  280. (defconst org-agenda-custom-commands-local-options
  281. `(repeat :tag "Local settings for this command. Remember to quote values"
  282. (choice :tag "Setting"
  283. (list :tag "Heading for this block"
  284. (const org-agenda-overriding-header)
  285. (string :tag "Headline"))
  286. (list :tag "Files to be searched"
  287. (const org-agenda-files)
  288. (list
  289. (const :format "" quote)
  290. (repeat (file))))
  291. (list :tag "Sorting strategy"
  292. (const org-agenda-sorting-strategy)
  293. (list
  294. (const :format "" quote)
  295. (repeat
  296. ,org-sorting-choice)))
  297. (list :tag "Prefix format"
  298. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  299. (string))
  300. (list :tag "Number of days in agenda"
  301. (const org-agenda-span)
  302. (list
  303. (const :format "" quote)
  304. (choice (const :tag "Day" day)
  305. (const :tag "Week" week)
  306. (const :tag "Fortnight" fortnight)
  307. (const :tag "Month" month)
  308. (const :tag "Year" year)
  309. (integer :tag "Custom"))))
  310. (list :tag "Fixed starting date"
  311. (const org-agenda-start-day)
  312. (string :value "2007-11-01"))
  313. (list :tag "Start on day of week"
  314. (const org-agenda-start-on-weekday)
  315. (choice :value 1
  316. (const :tag "Today" nil)
  317. (integer :tag "Weekday No.")))
  318. (list :tag "Include data from diary"
  319. (const org-agenda-include-diary)
  320. (boolean))
  321. (list :tag "Deadline Warning days"
  322. (const org-deadline-warning-days)
  323. (integer :value 1))
  324. (list :tag "Category filter preset"
  325. (const org-agenda-category-filter-preset)
  326. (list
  327. (const :format "" quote)
  328. (repeat
  329. (string :tag "+category or -category"))))
  330. (list :tag "Tags filter preset"
  331. (const org-agenda-tag-filter-preset)
  332. (list
  333. (const :format "" quote)
  334. (repeat
  335. (string :tag "+tag or -tag"))))
  336. (list :tag "Effort filter preset"
  337. (const org-agenda-effort-filter-preset)
  338. (list
  339. (const :format "" quote)
  340. (repeat
  341. (string :tag "+=10 or -=10 or +<10 or ->10"))))
  342. (list :tag "Regexp filter preset"
  343. (const org-agenda-regexp-filter-preset)
  344. (list
  345. (const :format "" quote)
  346. (repeat
  347. (string :tag "+regexp or -regexp"))))
  348. (list :tag "Set daily/weekly entry types"
  349. (const org-agenda-entry-types)
  350. (list
  351. (const :format "" quote)
  352. (set :greedy t :value ,org-agenda-entry-types
  353. (const :deadline)
  354. (const :scheduled)
  355. (const :deadline*)
  356. (const :scheduled*)
  357. (const :timestamp)
  358. (const :sexp))))
  359. (list :tag "Columns format"
  360. (const org-overriding-columns-format)
  361. (string :tag "Format"))
  362. (list :tag "Standard skipping condition"
  363. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  364. (const org-agenda-skip-function)
  365. (list
  366. (const :format "" quote)
  367. (list
  368. (choice
  369. :tag "Skipping range"
  370. (const :tag "Skip entry" org-agenda-skip-entry-if)
  371. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  372. (repeat :inline t :tag "Conditions for skipping"
  373. (choice
  374. :tag "Condition type"
  375. (list :tag "Regexp matches" :inline t
  376. (const :format "" regexp)
  377. (regexp))
  378. (list :tag "Regexp does not match" :inline t
  379. (const :format "" notregexp)
  380. (regexp))
  381. (list :tag "TODO state is" :inline t
  382. (const todo)
  383. (choice
  384. (const :tag "Any not-done state" todo)
  385. (const :tag "Any done state" done)
  386. (const :tag "Any state" any)
  387. (list :tag "Keyword list"
  388. (const :format "" quote)
  389. (repeat (string :tag "Keyword")))))
  390. (list :tag "TODO state is not" :inline t
  391. (const nottodo)
  392. (choice
  393. (const :tag "Any not-done state" todo)
  394. (const :tag "Any done state" done)
  395. (const :tag "Any state" any)
  396. (list :tag "Keyword list"
  397. (const :format "" quote)
  398. (repeat (string :tag "Keyword")))))
  399. (const :tag "scheduled" scheduled)
  400. (const :tag "not scheduled" notscheduled)
  401. (const :tag "deadline" deadline)
  402. (const :tag "no deadline" notdeadline)
  403. (const :tag "timestamp" timestamp)
  404. (const :tag "no timestamp" nottimestamp))))))
  405. (list :tag "Non-standard skipping condition"
  406. :value (org-agenda-skip-function)
  407. (const org-agenda-skip-function)
  408. (sexp :tag "Function or form (quoted!)"))
  409. (list :tag "Any variable"
  410. (variable :tag "Variable")
  411. (sexp :tag "Value (sexp)"))))
  412. "Selection of examples for agenda command settings.
  413. This will be spliced into the custom type of
  414. `org-agenda-custom-commands'.")
  415. (defcustom org-agenda-custom-commands
  416. '(("n" "Agenda and all TODOs" ((agenda "") (alltodo ""))))
  417. "Custom commands for the agenda.
  418. \\<org-mode-map>
  419. These commands will be offered on the splash screen displayed by the
  420. agenda dispatcher `\\[org-agenda]'. Each entry is a list like this:
  421. (key desc type match settings files)
  422. key The key (one or more characters as a string) to be associated
  423. with the command.
  424. desc A description of the command. When omitted or nil, a default
  425. description is built using MATCH.
  426. type The command type, any of the following symbols:
  427. agenda The daily/weekly agenda.
  428. agenda* Appointments for current week/day.
  429. todo Entries with a specific TODO keyword, in all agenda files.
  430. search Entries containing search words entry or headline.
  431. tags Tags/Property/TODO match in all agenda files.
  432. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  433. todo-tree Sparse tree of specific TODO keyword in *current* file.
  434. tags-tree Sparse tree with all tags matches in *current* file.
  435. occur-tree Occur sparse tree for *current* file.
  436. alltodo The global TODO list.
  437. stuck Stuck projects.
  438. ... A user-defined function.
  439. match What to search for:
  440. - a single keyword for TODO keyword searches
  441. - a tags/property/todo match expression for searches
  442. - a word search expression for text searches.
  443. - a regular expression for occur searches
  444. For all other commands, this should be the empty string.
  445. settings A list of option settings, similar to that in a let form, so like
  446. this: ((opt1 val1) (opt2 val2) ...). The values will be
  447. evaluated at the moment of execution, so quote them when needed.
  448. files A list of files to write the produced agenda buffer to with
  449. the command `org-store-agenda-views'.
  450. If a file name ends in \".html\", an HTML version of the buffer
  451. is written out. If it ends in \".ps\", a PostScript version is
  452. produced. Otherwise, only the plain text is written to the file.
  453. You can also define a set of commands, to create a composite agenda buffer.
  454. In this case, an entry looks like this:
  455. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  456. where
  457. desc A description string to be displayed in the dispatcher menu.
  458. cmd An agenda command, similar to the above. However, tree commands
  459. are not allowed. Valid commands for a set are:
  460. (agenda \"\" settings)
  461. (agenda* \"\" settings)
  462. (alltodo \"\" settings)
  463. (stuck \"\" settings)
  464. (todo \"match\" settings files)
  465. (search \"match\" settings files)
  466. (tags \"match\" settings files)
  467. (tags-todo \"match\" settings files)
  468. Each command can carry a list of options, and another set of options can be
  469. given for the whole set of commands. Individual command options take
  470. precedence over the general options.
  471. When using several characters as key to a command, the first characters
  472. are prefix commands. For the dispatcher to display useful information, you
  473. should provide a description for the prefix, like
  474. (setq org-agenda-custom-commands
  475. \\='((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  476. (\"hl\" tags \"+HOME+Lisa\")
  477. (\"hp\" tags \"+HOME+Peter\")
  478. (\"hk\" tags \"+HOME+Kim\")))
  479. See also Info node `(org) Custom Agenda Views'."
  480. :group 'org-agenda-custom-commands
  481. :type `(repeat
  482. (choice :value ("x" "Describe command here" tags "" nil)
  483. (list :tag "Single command"
  484. (string :tag "Access Key(s) ")
  485. (option (string :tag "Description"))
  486. (choice
  487. (const :tag "Agenda" agenda)
  488. (const :tag "TODO list" alltodo)
  489. (const :tag "Search words" search)
  490. (const :tag "Stuck projects" stuck)
  491. (const :tag "Tags/Property match (all agenda files)" tags)
  492. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  493. (const :tag "TODO keyword search (all agenda files)" todo)
  494. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  495. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  496. (const :tag "Occur tree (current buffer)" occur-tree)
  497. (sexp :tag "Other, user-defined function"))
  498. (string :tag "Match (only for some commands)")
  499. ,org-agenda-custom-commands-local-options
  500. (option (repeat :tag "Export" (file :tag "Export to"))))
  501. (list :tag "Command series, all agenda files"
  502. (string :tag "Access Key(s)")
  503. (string :tag "Description ")
  504. (repeat :tag "Component"
  505. (choice
  506. (list :tag "Agenda"
  507. (const :format "" agenda)
  508. (const :tag "" :format "" "")
  509. ,org-agenda-custom-commands-local-options)
  510. (list :tag "TODO list (all keywords)"
  511. (const :format "" alltodo)
  512. (const :tag "" :format "" "")
  513. ,org-agenda-custom-commands-local-options)
  514. (list :tag "Search words"
  515. (const :format "" search)
  516. (string :tag "Match")
  517. ,org-agenda-custom-commands-local-options)
  518. (list :tag "Stuck projects"
  519. (const :format "" stuck)
  520. (const :tag "" :format "" "")
  521. ,org-agenda-custom-commands-local-options)
  522. (list :tag "Tags/Property match (all agenda files)"
  523. (const :format "" tags)
  524. (string :tag "Match")
  525. ,org-agenda-custom-commands-local-options)
  526. (list :tag "Tags/Property match of TODO entries (all agenda files)"
  527. (const :format "" tags-todo)
  528. (string :tag "Match")
  529. ,org-agenda-custom-commands-local-options)
  530. (list :tag "TODO keyword search"
  531. (const :format "" todo)
  532. (string :tag "Match")
  533. ,org-agenda-custom-commands-local-options)
  534. (list :tag "Other, user-defined function"
  535. (symbol :tag "function")
  536. (string :tag "Match")
  537. ,org-agenda-custom-commands-local-options)))
  538. (repeat :tag "Settings for entire command set"
  539. (list (variable :tag "Any variable")
  540. (sexp :tag "Value")))
  541. (option (repeat :tag "Export" (file :tag "Export to"))))
  542. (cons :tag "Prefix key documentation"
  543. (string :tag "Access Key(s)")
  544. (string :tag "Description ")))))
  545. (defcustom org-agenda-query-register ?o
  546. "The register holding the current query string.
  547. The purpose of this is that if you construct a query string interactively,
  548. you can then use it to define a custom command."
  549. :group 'org-agenda-custom-commands
  550. :type 'character)
  551. (defcustom org-stuck-projects
  552. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  553. "How to identify stuck projects.
  554. This is a list of four items:
  555. 1. A tags/todo/property matcher string that is used to identify a project.
  556. See the manual for a description of tag and property searches.
  557. The entire tree below a headline matched by this is considered one project.
  558. 2. A list of TODO keywords identifying non-stuck projects.
  559. If the project subtree contains any headline with one of these todo
  560. keywords, the project is considered to be not stuck. If you specify
  561. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  562. 3. A list of tags identifying non-stuck projects.
  563. If the project subtree contains any headline with one of these tags,
  564. the project is considered to be not stuck. If you specify \"*\" as
  565. a tag, any tag will mark the project unstuck. Note that this is about
  566. the explicit presence of a tag somewhere in the subtree, inherited
  567. tags do not count here. If inherited tags make a project not stuck,
  568. use \"-TAG\" in the tags part of the matcher under (1.) above.
  569. 4. An arbitrary regular expression matching non-stuck projects.
  570. If the project turns out to be not stuck, search continues also in the
  571. subtree to see if any of the subtasks have project status.
  572. See also the variable `org-tags-match-list-sublevels' which applies
  573. to projects matched by this search as well.
  574. After defining this variable, you may use `org-agenda-list-stuck-projects'
  575. \(bound to `\\[org-agenda] #') to produce the list."
  576. :group 'org-agenda-custom-commands
  577. :type '(list
  578. (string :tag "Tags/TODO match to identify a project")
  579. (repeat :tag "Projects are *not* stuck if they have an entry with \
  580. TODO keyword any of" (string))
  581. (repeat :tag "Projects are *not* stuck if they have an entry with \
  582. TAG being any of" (string))
  583. (regexp :tag "Projects are *not* stuck if this regexp matches inside \
  584. the subtree")))
  585. (defgroup org-agenda-skip nil
  586. "Options concerning skipping parts of agenda files."
  587. :tag "Org Agenda Skip"
  588. :group 'org-agenda)
  589. (defcustom org-agenda-skip-function-global nil
  590. "Function to be called at each match during agenda construction.
  591. If this function returns nil, the current match should not be skipped.
  592. If the function decided to skip an agenda match, is must return the
  593. buffer position from which the search should be continued.
  594. This may also be a Lisp form, which will be evaluated.
  595. This variable will be applied to every agenda match, including
  596. tags/property searches and TODO lists. So try to make the test function
  597. do its checking as efficiently as possible. To implement a skipping
  598. condition just for specific agenda commands, use the variable
  599. `org-agenda-skip-function' which can be set in the options section
  600. of custom agenda commands."
  601. :group 'org-agenda-skip
  602. :type 'sexp)
  603. (defgroup org-agenda-daily/weekly nil
  604. "Options concerning the daily/weekly agenda."
  605. :tag "Org Agenda Daily/Weekly"
  606. :group 'org-agenda)
  607. (defgroup org-agenda-todo-list nil
  608. "Options concerning the global todo list agenda view."
  609. :tag "Org Agenda Todo List"
  610. :group 'org-agenda)
  611. (defgroup org-agenda-match-view nil
  612. "Options concerning the general tags/property/todo match agenda view."
  613. :tag "Org Agenda Match View"
  614. :group 'org-agenda)
  615. (defgroup org-agenda-search-view nil
  616. "Options concerning the search agenda view."
  617. :tag "Org Agenda Search View"
  618. :group 'org-agenda)
  619. (defvar org-agenda-archives-mode nil
  620. "Non-nil means the agenda will include archived items.
  621. If this is the symbol `trees', trees in the selected agenda scope
  622. that are marked with the ARCHIVE tag will be included anyway. When this is
  623. t, also all archive files associated with the current selection of agenda
  624. files will be included.")
  625. (defcustom org-agenda-restriction-lock-highlight-subtree t
  626. "Non-nil means highlight the whole subtree when restriction is active.
  627. Otherwise only highlight the headline. Highlighting the whole subtree is
  628. useful to ensure no edits happen beyond the restricted region."
  629. :group 'org-agenda
  630. :type 'boolean)
  631. (defcustom org-agenda-skip-comment-trees t
  632. "Non-nil means skip trees that start with the COMMENT keyword.
  633. When nil, these trees are also scanned by agenda commands."
  634. :group 'org-agenda-skip
  635. :type 'boolean)
  636. (defcustom org-agenda-todo-list-sublevels t
  637. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  638. When nil, the sublevels of a TODO entry are not checked, resulting in
  639. potentially much shorter TODO lists."
  640. :group 'org-agenda-skip
  641. :group 'org-agenda-todo-list
  642. :type 'boolean)
  643. (defcustom org-agenda-todo-ignore-with-date nil
  644. "Non-nil means don't show entries with a date in the global todo list.
  645. You can use this if you prefer to mark mere appointments with a TODO keyword,
  646. but don't want them to show up in the TODO list.
  647. When this is set, it also covers deadlines and scheduled items, the settings
  648. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  649. will be ignored.
  650. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  651. :group 'org-agenda-skip
  652. :group 'org-agenda-todo-list
  653. :type 'boolean)
  654. (defcustom org-agenda-todo-ignore-timestamp nil
  655. "Non-nil means don't show entries with a timestamp.
  656. This applies when creating the global todo list.
  657. Valid values are:
  658. past Don't show entries for today or in the past.
  659. future Don't show entries with a timestamp in the future.
  660. The idea behind this is that if it has a future
  661. timestamp, you don't want to think about it until the
  662. date.
  663. all Don't show any entries with a timestamp in the global todo list.
  664. The idea behind this is that by setting a timestamp, you
  665. have already \"taken care\" of this item.
  666. This variable can also have an integer as a value. If positive (N),
  667. todos with a timestamp N or more days in the future will be ignored. If
  668. negative (-N), todos with a timestamp N or more days in the past will be
  669. ignored. If 0, todos with a timestamp either today or in the future will
  670. be ignored. For example, a value of -1 will exclude todos with a
  671. timestamp in the past (yesterday or earlier), while a value of 7 will
  672. exclude todos with a timestamp a week or more in the future.
  673. See also `org-agenda-todo-ignore-with-date'.
  674. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  675. to make his option also apply to the tags-todo list."
  676. :group 'org-agenda-skip
  677. :group 'org-agenda-todo-list
  678. :version "24.1"
  679. :type '(choice
  680. (const :tag "Ignore future timestamp todos" future)
  681. (const :tag "Ignore past or present timestamp todos" past)
  682. (const :tag "Ignore all timestamp todos" all)
  683. (const :tag "Show timestamp todos" nil)
  684. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  685. (defcustom org-agenda-todo-ignore-scheduled nil
  686. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  687. This applies when creating the global todo list.
  688. Valid values are:
  689. past Don't show entries scheduled today or in the past.
  690. future Don't show entries scheduled in the future.
  691. The idea behind this is that by scheduling it, you don't want to
  692. think about it until the scheduled date.
  693. all Don't show any scheduled entries in the global todo list.
  694. The idea behind this is that by scheduling it, you have already
  695. \"taken care\" of this item.
  696. t Same as `all', for backward compatibility.
  697. This variable can also have an integer as a value. See
  698. `org-agenda-todo-ignore-timestamp' for more details.
  699. See also `org-agenda-todo-ignore-with-date'.
  700. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  701. to make his option also apply to the tags-todo list."
  702. :group 'org-agenda-skip
  703. :group 'org-agenda-todo-list
  704. :type '(choice
  705. (const :tag "Ignore future-scheduled todos" future)
  706. (const :tag "Ignore past- or present-scheduled todos" past)
  707. (const :tag "Ignore all scheduled todos" all)
  708. (const :tag "Ignore all scheduled todos (compatibility)" t)
  709. (const :tag "Show scheduled todos" nil)
  710. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  711. (defcustom org-agenda-todo-ignore-deadlines nil
  712. "Non-nil means ignore some deadline TODO items when making TODO list.
  713. There are different motivations for using different values, please think
  714. carefully when configuring this variable.
  715. This applies when creating the global TODO list.
  716. Valid values are:
  717. near Don't show near deadline entries. A deadline is near when it is
  718. closer than `org-deadline-warning-days' days. The idea behind this
  719. is that such items will appear in the agenda anyway.
  720. far Don't show TODO entries where a deadline has been defined, but
  721. is not going to happen anytime soon. This is useful if you want to use
  722. the TODO list to figure out what to do now.
  723. past Don't show entries with a deadline timestamp for today or in the past.
  724. future Don't show entries with a deadline timestamp in the future, not even
  725. when they become `near' ones. Use it with caution.
  726. all Ignore all TODO entries that do have a deadline.
  727. t Same as `near', for backward compatibility.
  728. This variable can also have an integer as a value. See
  729. `org-agenda-todo-ignore-timestamp' for more details.
  730. See also `org-agenda-todo-ignore-with-date'.
  731. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  732. to make his option also apply to the tags-todo list."
  733. :group 'org-agenda-skip
  734. :group 'org-agenda-todo-list
  735. :type '(choice
  736. (const :tag "Ignore near deadlines" near)
  737. (const :tag "Ignore near deadlines (compatibility)" t)
  738. (const :tag "Ignore far deadlines" far)
  739. (const :tag "Ignore all TODOs with a deadlines" all)
  740. (const :tag "Show all TODOs, even if they have a deadline" nil)
  741. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  742. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  743. "Time unit to use when possibly ignoring an agenda item.
  744. See the docstring of various `org-agenda-todo-ignore-*' options.
  745. The default is to compare time stamps using days. An item is thus
  746. considered to be in the future if it is at least one day after today.
  747. Non-nil means to compare time stamps using seconds. An item is then
  748. considered future if it has a time value later than current time."
  749. :group 'org-agenda-skip
  750. :group 'org-agenda-todo-list
  751. :version "24.4"
  752. :package-version '(Org . "8.0")
  753. :type '(choice
  754. (const :tag "Compare time with days" nil)
  755. (const :tag "Compare time with seconds" t)))
  756. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  757. "Non-nil means honor todo-list ignores options also in tags-todo search.
  758. The variables
  759. `org-agenda-todo-ignore-with-date',
  760. `org-agenda-todo-ignore-timestamp',
  761. `org-agenda-todo-ignore-scheduled',
  762. `org-agenda-todo-ignore-deadlines'
  763. make the global TODO list skip entries that have time stamps of certain
  764. kinds. If this option is set, the same options will also apply for the
  765. tags-todo search, which is the general tags/property matcher
  766. restricted to unfinished TODO entries only."
  767. :group 'org-agenda-skip
  768. :group 'org-agenda-todo-list
  769. :group 'org-agenda-match-view
  770. :type 'boolean)
  771. (defcustom org-agenda-skip-scheduled-if-done nil
  772. "Non-nil means don't show scheduled items in agenda when they are done.
  773. This is relevant for the daily/weekly agenda, not for the TODO list. It
  774. applies only to the actual date of the scheduling. Warnings about an item
  775. with a past scheduling dates are always turned off when the item is DONE."
  776. :group 'org-agenda-skip
  777. :group 'org-agenda-daily/weekly
  778. :type 'boolean)
  779. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  780. "Non-nil means skip scheduling line if same entry shows because of deadline.
  781. In the agenda of today, an entry can show up multiple times
  782. because it is both scheduled and has a nearby deadline, and maybe
  783. a plain time stamp as well.
  784. When this variable is nil, the entry will be shown several times.
  785. When set to t, then only the deadline is shown and the fact that
  786. the entry is scheduled today or was scheduled previously is not
  787. shown.
  788. When set to the symbol `not-today', skip scheduled previously,
  789. but not scheduled today.
  790. When set to the symbol `repeated-after-deadline', skip scheduled
  791. items if they are repeated beyond the current deadline."
  792. :group 'org-agenda-skip
  793. :group 'org-agenda-daily/weekly
  794. :type '(choice
  795. (const :tag "Never" nil)
  796. (const :tag "Always" t)
  797. (const :tag "Not when scheduled today" not-today)
  798. (const :tag "When repeated past deadline" repeated-after-deadline)))
  799. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  800. "Non-nil means skip timestamp line if same entry shows because of deadline.
  801. In the agenda of today, an entry can show up multiple times
  802. because it has both a plain timestamp and has a nearby deadline.
  803. When this variable is t, then only the deadline is shown and the
  804. fact that the entry has a timestamp for or including today is not
  805. shown. When this variable is nil, the entry will be shown
  806. several times."
  807. :group 'org-agenda-skip
  808. :group 'org-agenda-daily/weekly
  809. :version "24.1"
  810. :type '(choice
  811. (const :tag "Never" nil)
  812. (const :tag "Always" t)))
  813. (defcustom org-agenda-skip-deadline-if-done nil
  814. "Non-nil means don't show deadlines when the corresponding item is done.
  815. When nil, the deadline is still shown and should give you a happy feeling.
  816. This is relevant for the daily/weekly agenda. It applies only to the
  817. actual date of the deadline. Warnings about approaching and past-due
  818. deadlines are always turned off when the item is DONE."
  819. :group 'org-agenda-skip
  820. :group 'org-agenda-daily/weekly
  821. :type 'boolean)
  822. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  823. "Non-nil means skip deadline prewarning when entry is also scheduled.
  824. This will apply on all days where a prewarning for the deadline would
  825. be shown, but not at the day when the entry is actually due. On that day,
  826. the deadline will be shown anyway.
  827. This variable may be set to nil, t, the symbol `pre-scheduled',
  828. or a number which will then give the number of days before the actual
  829. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  830. eliminates the deadline prewarning only prior to the scheduled date.
  831. This can be used in a workflow where the first showing of the deadline will
  832. trigger you to schedule it, and then you don't want to be reminded of it
  833. because you will take care of it on the day when scheduled."
  834. :group 'org-agenda-skip
  835. :group 'org-agenda-daily/weekly
  836. :version "24.1"
  837. :type '(choice
  838. (const :tag "Always show prewarning" nil)
  839. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  840. (const :tag "Remove prewarning if entry is scheduled" t)
  841. (integer :tag "Restart prewarning N days before deadline")))
  842. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  843. "Non-nil means skip scheduled delay when entry also has a deadline.
  844. This variable may be set to nil, t, the symbol `post-deadline',
  845. or a number which will then give the number of days after the actual
  846. scheduled date when the delay should expire. The symbol `post-deadline'
  847. eliminates the schedule delay when the date is posterior to the deadline."
  848. :group 'org-agenda-skip
  849. :group 'org-agenda-daily/weekly
  850. :version "24.4"
  851. :package-version '(Org . "8.0")
  852. :type '(choice
  853. (const :tag "Always honor delay" nil)
  854. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  855. (const :tag "Ignore delay if entry has a deadline" t)
  856. (integer :tag "Honor delay up until N days after the scheduled date")))
  857. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  858. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  859. When non-nil, after the search for timestamps has matched once in an
  860. entry, the rest of the entry will not be searched."
  861. :group 'org-agenda-skip
  862. :type 'boolean)
  863. (defcustom org-agenda-skip-timestamp-if-done nil
  864. "Non-nil means don't select item by timestamp or -range if it is DONE."
  865. :group 'org-agenda-skip
  866. :group 'org-agenda-daily/weekly
  867. :type 'boolean)
  868. (defcustom org-agenda-dim-blocked-tasks t
  869. "Non-nil means dim blocked tasks in the agenda display.
  870. This causes some overhead during agenda construction, but if you
  871. have turned on `org-enforce-todo-dependencies',
  872. `org-enforce-todo-checkbox-dependencies', or any other blocking
  873. mechanism, this will create useful feedback in the agenda.
  874. Instead of t, this variable can also have the value `invisible'.
  875. Then blocked tasks will be invisible and only become visible when
  876. they become unblocked. An exemption to this behavior is when a task is
  877. blocked because of unchecked checkboxes below it. Since checkboxes do
  878. not show up in the agenda views, making this task invisible you remove any
  879. trace from agenda views that there is something to do. Therefore, a task
  880. that is blocked because of checkboxes will never be made invisible, it
  881. will only be dimmed."
  882. :group 'org-agenda-daily/weekly
  883. :group 'org-agenda-todo-list
  884. :version "24.3"
  885. :type '(choice
  886. (const :tag "Do not dim" nil)
  887. (const :tag "Dim to a gray face" t)
  888. (const :tag "Make invisible" invisible)))
  889. (defgroup org-agenda-startup nil
  890. "Options concerning initial settings in the Agenda in Org Mode."
  891. :tag "Org Agenda Startup"
  892. :group 'org-agenda)
  893. (defcustom org-agenda-menu-show-matcher t
  894. "Non-nil means show the match string in the agenda dispatcher menu.
  895. When nil, the matcher string is not shown, but is put into the help-echo
  896. property so than moving the mouse over the command shows it.
  897. Setting it to nil is good if matcher strings are very long and/or if
  898. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  899. :group 'org-agenda
  900. :version "24.1"
  901. :type 'boolean)
  902. (defcustom org-agenda-menu-two-columns nil
  903. "Non-nil means, use two columns to show custom commands in the dispatcher.
  904. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  905. to nil."
  906. :group 'org-agenda
  907. :version "24.1"
  908. :type 'boolean)
  909. (defcustom org-agenda-finalize-hook nil
  910. "Hook run just before displaying an agenda buffer.
  911. The buffer is still writable when the hook is called.
  912. You can modify some of the buffer substrings but you should be
  913. extra careful not to modify the text properties of the agenda
  914. headlines as the agenda display heavily relies on them."
  915. :group 'org-agenda-startup
  916. :type 'hook)
  917. (defcustom org-agenda-filter-hook nil
  918. "Hook run just after filtering with `org-agenda-filter'."
  919. :group 'org-agenda-startup
  920. :package-version '(Org . "9.4")
  921. :type 'hook)
  922. (defcustom org-agenda-mouse-1-follows-link nil
  923. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  924. A longer mouse click will still set point. Needs to be set
  925. before org.el is loaded."
  926. :group 'org-agenda-startup
  927. :type 'boolean)
  928. (defcustom org-agenda-start-with-follow-mode nil
  929. "The initial value of follow mode in a newly created agenda window."
  930. :group 'org-agenda-startup
  931. :type 'boolean)
  932. (defcustom org-agenda-follow-indirect nil
  933. "Non-nil means `org-agenda-follow-mode' displays only the
  934. current item's tree, in an indirect buffer."
  935. :group 'org-agenda
  936. :version "24.1"
  937. :type 'boolean)
  938. (defcustom org-agenda-show-outline-path t
  939. "Non-nil means show outline path in echo area after line motion."
  940. :group 'org-agenda-startup
  941. :type 'boolean)
  942. (defcustom org-agenda-start-with-entry-text-mode nil
  943. "The initial value of entry-text-mode in a newly created agenda window."
  944. :group 'org-agenda-startup
  945. :type 'boolean)
  946. (defcustom org-agenda-entry-text-maxlines 5
  947. "Number of text lines to be added when `E' is pressed in the agenda.
  948. Note that this variable only used during agenda display. To add entry text
  949. when exporting the agenda, configure the variable
  950. `org-agenda-add-entry-text-maxlines'."
  951. :group 'org-agenda
  952. :type 'integer)
  953. (defcustom org-agenda-entry-text-exclude-regexps nil
  954. "List of regular expressions to clean up entry text.
  955. The complete matches of all regular expressions in this list will be
  956. removed from entry text before it is shown in the agenda."
  957. :group 'org-agenda
  958. :type '(repeat (regexp)))
  959. (defcustom org-agenda-entry-text-leaders " > "
  960. "Text prepended to the entry text in agenda buffers."
  961. :version "24.4"
  962. :package-version '(Org . "8.0")
  963. :group 'org-agenda
  964. :type 'string)
  965. (defvar org-agenda-entry-text-cleanup-hook nil
  966. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  967. This cleanup is done in a temporary buffer, so the function may inspect and
  968. change the entire buffer.
  969. Some default stuff like drawers and scheduling/deadline dates will already
  970. have been removed when this is called, as will any matches for regular
  971. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  972. (defvar org-agenda-include-inactive-timestamps nil
  973. "Non-nil means include inactive time stamps in agenda.
  974. Dynamically scoped.")
  975. (defgroup org-agenda-windows nil
  976. "Options concerning the windows used by the Agenda in Org Mode."
  977. :tag "Org Agenda Windows"
  978. :group 'org-agenda)
  979. (defcustom org-agenda-window-setup 'reorganize-frame
  980. "How the agenda buffer should be displayed.
  981. Possible values for this option are:
  982. current-window Show agenda in the current window, keeping all other windows.
  983. other-window Use `switch-to-buffer-other-window' to display agenda.
  984. only-window Show agenda, deleting all other windows.
  985. reorganize-frame Show only two windows on the current frame, the current
  986. window and the agenda.
  987. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  988. Also, when exiting the agenda, kill that frame.
  989. other-tab Use `switch-to-buffer-other-tab' to display the
  990. agenda, making use of the `tab-bar-mode' introduced
  991. in Emacs version 27.1. Also, kill that tab when
  992. exiting the agenda view.
  993. See also the variable `org-agenda-restore-windows-after-quit'."
  994. :group 'org-agenda-windows
  995. :type '(choice
  996. (const current-window)
  997. (const other-frame)
  998. (const other-tab)
  999. (const other-window)
  1000. (const only-window)
  1001. (const reorganize-frame))
  1002. :package-version '(Org . "9.4"))
  1003. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  1004. "The min and max height of the agenda window as a fraction of frame height.
  1005. The value of the variable is a cons cell with two numbers between 0 and 1.
  1006. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  1007. :group 'org-agenda-windows
  1008. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  1009. (defcustom org-agenda-restore-windows-after-quit nil
  1010. "Non-nil means restore window configuration upon exiting agenda.
  1011. Before the window configuration is changed for displaying the
  1012. agenda, the current status is recorded. When the agenda is
  1013. exited with `q' or `x' and this option is set, the old state is
  1014. restored. If `org-agenda-window-setup' is `other-frame' or
  1015. `other-tab', the value of this option will be ignored."
  1016. :group 'org-agenda-windows
  1017. :type 'boolean)
  1018. (defcustom org-agenda-span 'week
  1019. "Number of days to include in overview display.
  1020. Can be day, week, month, year, or any number of days.
  1021. Custom commands can set this variable in the options section."
  1022. :group 'org-agenda-daily/weekly
  1023. :type '(choice (const :tag "Day" day)
  1024. (const :tag "Week" week)
  1025. (const :tag "Fortnight" fortnight)
  1026. (const :tag "Month" month)
  1027. (const :tag "Year" year)
  1028. (integer :tag "Custom")))
  1029. (defcustom org-agenda-start-on-weekday 1
  1030. "Non-nil means start the overview always on the specified weekday.
  1031. 0 denotes Sunday, 1 denotes Monday, etc.
  1032. When nil, always start on the current day.
  1033. Custom commands can set this variable in the options section."
  1034. :group 'org-agenda-daily/weekly
  1035. :type '(choice (const :tag "Today" nil)
  1036. (integer :tag "Weekday No.")))
  1037. (defcustom org-agenda-show-all-dates t
  1038. "Non-nil means `org-agenda' shows every day in the selected range.
  1039. When nil, only the days which actually have entries are shown."
  1040. :group 'org-agenda-daily/weekly
  1041. :type 'boolean)
  1042. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1043. "Format string for displaying dates in the agenda.
  1044. Used by the daily/weekly agenda. This should be a format string
  1045. understood by `format-time-string', or a function returning the
  1046. formatted date as a string. The function must take a single
  1047. argument, a calendar-style date list like (month day year)."
  1048. :group 'org-agenda-daily/weekly
  1049. :type '(choice
  1050. (string :tag "Format string")
  1051. (function :tag "Function")))
  1052. (defun org-agenda-end-of-line ()
  1053. "Go to the end of visible line."
  1054. (interactive)
  1055. (goto-char (line-end-position)))
  1056. (defun org-agenda-format-date-aligned (date)
  1057. "Format a DATE string for display in the daily/weekly agenda.
  1058. This function makes sure that dates are aligned for easy reading."
  1059. (require 'cal-iso)
  1060. (let* ((dayname (calendar-day-name date))
  1061. (day (cadr date))
  1062. (day-of-week (calendar-day-of-week date))
  1063. (month (car date))
  1064. (monthname (calendar-month-name month))
  1065. (year (nth 2 date))
  1066. (iso-week (org-days-to-iso-week
  1067. (calendar-absolute-from-gregorian date)))
  1068. ;; (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1069. ;; (1- year))
  1070. ;; ((and (= month 12) (<= iso-week 1))
  1071. ;; (1+ year))
  1072. ;; (t year)))
  1073. (weekstring (if (= day-of-week 1)
  1074. (format " W%02d" iso-week)
  1075. "")))
  1076. (format "%-10s %2d %s %4d%s"
  1077. dayname day monthname year weekstring)))
  1078. (defcustom org-agenda-time-leading-zero nil
  1079. "Non-nil means use leading zero for military times in agenda.
  1080. For example, 9:30am would become 09:30 rather than 9:30."
  1081. :group 'org-agenda-daily/weekly
  1082. :version "24.1"
  1083. :type 'boolean)
  1084. (defcustom org-agenda-timegrid-use-ampm nil
  1085. "When set, show AM/PM style timestamps on the timegrid."
  1086. :group 'org-agenda
  1087. :version "24.1"
  1088. :type 'boolean)
  1089. (defcustom org-agenda-clock-report-header nil
  1090. "Header inserted before the table in Org agenda clock report mode.
  1091. See Info node `(org) Agenda Commands' for more details."
  1092. :group 'org-agenda
  1093. :type '(choice
  1094. (string :tag "Header")
  1095. (const :tag "No header" nil))
  1096. :safe #'stringp
  1097. :package-version '(Org . "9.6"))
  1098. (defun org-agenda-time-of-day-to-ampm (time)
  1099. "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
  1100. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1101. (minute (substring time -2))
  1102. (ampm "am"))
  1103. (cond
  1104. ((equal hour-number 12)
  1105. (setq ampm "pm"))
  1106. ((> hour-number 12)
  1107. (setq ampm "pm")
  1108. (setq hour-number (- hour-number 12))))
  1109. (concat
  1110. (if org-agenda-time-leading-zero
  1111. (format "%02d" hour-number)
  1112. (format "%02s" (number-to-string hour-number)))
  1113. ":" minute ampm)))
  1114. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1115. "Conditionally convert TIME to AM/PM format.
  1116. This is based on `org-agenda-timegrid-use-ampm'."
  1117. (if org-agenda-timegrid-use-ampm
  1118. (org-agenda-time-of-day-to-ampm time)
  1119. time))
  1120. (defcustom org-agenda-weekend-days '(6 0)
  1121. "Which days are weekend?
  1122. These days get the special face `org-agenda-date-weekend' in the agenda."
  1123. :group 'org-agenda-daily/weekly
  1124. :type '(set :greedy t
  1125. (const :tag "Monday" 1)
  1126. (const :tag "Tuesday" 2)
  1127. (const :tag "Wednesday" 3)
  1128. (const :tag "Thursday" 4)
  1129. (const :tag "Friday" 5)
  1130. (const :tag "Saturday" 6)
  1131. (const :tag "Sunday" 0)))
  1132. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1133. "Non-nil means jump to today when moving a past date forward in time.
  1134. When using S-right in the agenda to move a date forward, and the date
  1135. stamp currently points to the past, the first key press will move it
  1136. to today. When nil, just move one day forward even if the date stays
  1137. in the past."
  1138. :group 'org-agenda-daily/weekly
  1139. :version "24.1"
  1140. :type 'boolean)
  1141. (defcustom org-agenda-diary-file 'diary-file
  1142. "File to which to add new entries with the `i' key in agenda and calendar.
  1143. When this is the symbol `diary-file', the functionality in the Emacs
  1144. calendar will be used to add entries to the `diary-file'. But when this
  1145. points to a file, `org-agenda-diary-entry' will be used instead."
  1146. :group 'org-agenda
  1147. :type '(choice
  1148. (const :tag "The standard Emacs diary file" diary-file)
  1149. (file :tag "Special Org file diary entries")))
  1150. (defcustom org-agenda-include-diary nil
  1151. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1152. Custom commands can set this variable in the options section."
  1153. :group 'org-agenda-daily/weekly
  1154. :type 'boolean)
  1155. (defcustom org-agenda-include-deadlines t
  1156. "If non-nil, include entries within their deadline warning period.
  1157. Custom commands can set this variable in the options section."
  1158. :group 'org-agenda-daily/weekly
  1159. :version "24.1"
  1160. :type 'boolean)
  1161. (defcustom org-agenda-show-future-repeats t
  1162. "Non-nil shows repeated entries in the future part of the agenda.
  1163. When set to the symbol `next' only the first future repeat is shown."
  1164. :group 'org-agenda-daily/weekly
  1165. :type '(choice
  1166. (const :tag "Show all repeated entries" t)
  1167. (const :tag "Show next repeated entry" next)
  1168. (const :tag "Do not show repeated entries" nil))
  1169. :version "26.1"
  1170. :package-version '(Org . "9.1")
  1171. :safe #'symbolp)
  1172. (defcustom org-agenda-prefer-last-repeat nil
  1173. "Non-nil sets date for repeated entries to their last repeat.
  1174. When nil, display SCHEDULED and DEADLINE dates at their base
  1175. date, and in today's agenda, as a reminder. Display plain
  1176. time-stamps, on the other hand, at every repeat date in the past
  1177. in addition to the base date.
  1178. When non-nil, show a repeated entry at its latest repeat date,
  1179. possibly being today even if it wasn't marked as done. This
  1180. setting is useful if you do not always mark repeated entries as
  1181. done and, yet, consider that reaching repeat date starts the task
  1182. anew.
  1183. When set to a list of strings, prefer last repeats only for
  1184. entries with these TODO keywords."
  1185. :group 'org-agenda-daily/weekly
  1186. :type '(choice
  1187. (const :tag "Prefer last repeat" t)
  1188. (const :tag "Prefer base date" nil)
  1189. (repeat :tag "Prefer last repeat for entries with these TODO keywords"
  1190. (string :tag "TODO keyword")))
  1191. :version "26.1"
  1192. :package-version '(Org . "9.1")
  1193. :safe (lambda (x) (or (booleanp x) (consp x))))
  1194. (defcustom org-scheduled-past-days 10000
  1195. "Number of days to continue listing scheduled items not marked DONE.
  1196. When an item is scheduled on a date, it shows up in the agenda on
  1197. this day and will be listed until it is marked done or for the
  1198. number of days given here."
  1199. :group 'org-agenda-daily/weekly
  1200. :type 'integer
  1201. :safe 'integerp)
  1202. (defcustom org-deadline-past-days 10000
  1203. "Number of days to warn about missed deadlines.
  1204. When an item has deadline on a date, it shows up in the agenda on
  1205. this day and will appear as a reminder until it is marked DONE or
  1206. for the number of days given here."
  1207. :group 'org-agenda-daily/weekly
  1208. :type 'integer
  1209. :version "26.1"
  1210. :package-version '(Org . "9.1")
  1211. :safe 'integerp)
  1212. (defcustom org-agenda-log-mode-items '(closed clock)
  1213. "List of items that should be shown in agenda log mode.
  1214. \\<org-agenda-mode-map>\
  1215. This list may contain the following symbols:
  1216. closed Show entries that have been closed on that day.
  1217. clock Show entries that have received clocked time on that day.
  1218. state Show all logged state changes.
  1219. Note that instead of changing this variable, you can also press \
  1220. `\\[universal-argument] \\[org-agenda-log-mode]' in
  1221. the agenda to display all available LOG items temporarily."
  1222. :group 'org-agenda-daily/weekly
  1223. :type '(set :greedy t (const closed) (const clock) (const state)))
  1224. (defcustom org-agenda-clock-consistency-checks
  1225. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1226. :gap-ok-around ("4:00")
  1227. :default-face ((:background "DarkRed") (:foreground "white"))
  1228. :overlap-face nil :gap-face nil :no-end-time-face nil
  1229. :long-face nil :short-face nil)
  1230. "This is a property list, with the following keys:
  1231. :max-duration Mark clocking chunks that are longer than this time.
  1232. This is a time string like \"HH:MM\", or the number
  1233. of minutes as an integer.
  1234. :min-duration Mark clocking chunks that are shorter that this.
  1235. This is a time string like \"HH:MM\", or the number
  1236. of minutes as an integer.
  1237. :max-gap Mark gaps between clocking chunks that are longer than
  1238. this duration. A number of minutes, or a string
  1239. like \"HH:MM\".
  1240. :gap-ok-around List of times during the day which are usually not working
  1241. times. When a gap is detected, but the gap contains any
  1242. of these times, the gap is *not* reported. For example,
  1243. if this is (\"4:00\" \"13:00\") then gaps that contain
  1244. 4:00 in the morning (i.e. the night) and 13:00
  1245. (i.e. a typical lunch time) do not cause a warning.
  1246. You should have at least one time during the night in this
  1247. list, or otherwise the first task each morning will trigger
  1248. a warning because it follows a long gap.
  1249. Furthermore, the following properties can be used to define faces for
  1250. issue display.
  1251. :default-face the default face, if the specific face is undefined
  1252. :overlap-face face for overlapping clocks
  1253. :gap-face face for gaps between clocks
  1254. :no-end-time-face face for incomplete clocks
  1255. :long-face face for clock intervals that are too long
  1256. :short-face face for clock intervals that are too short"
  1257. :group 'org-agenda-daily/weekly
  1258. :group 'org-clock
  1259. :version "24.1"
  1260. :type 'plist)
  1261. (defcustom org-agenda-log-mode-add-notes t
  1262. "Non-nil means add first line of notes to log entries in agenda views.
  1263. If a log item like a state change or a clock entry is associated with
  1264. notes, the first line of these notes will be added to the entry in the
  1265. agenda display."
  1266. :group 'org-agenda-daily/weekly
  1267. :type 'boolean)
  1268. (defcustom org-agenda-start-with-log-mode nil
  1269. "The initial value of log-mode in a newly created agenda window.
  1270. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1271. explanations on the possible values."
  1272. :group 'org-agenda-startup
  1273. :group 'org-agenda-daily/weekly
  1274. :type '(choice (const :tag "Don't show log items" nil)
  1275. (const :tag "Show only log items" only)
  1276. (const :tag "Show all possible log items" clockcheck)
  1277. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1278. (choice (const :tag "Show closed log items" closed)
  1279. (const :tag "Show clocked log items" clock)
  1280. (const :tag "Show all logged state changes" state)))))
  1281. (defcustom org-agenda-start-with-clockreport-mode nil
  1282. "The initial value of clockreport-mode in a newly created agenda window."
  1283. :group 'org-agenda-startup
  1284. :group 'org-agenda-daily/weekly
  1285. :type 'boolean)
  1286. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1287. "Property list with parameters for the clocktable in clockreport mode.
  1288. This is the display mode that shows a clock table in the daily/weekly
  1289. agenda, the properties for this dynamic block can be set here.
  1290. The usual clocktable parameters are allowed here, but you cannot set
  1291. the properties :name, :tstart, :tend, :block, and :scope - these will
  1292. be overwritten to make sure the content accurately reflects the
  1293. current display in the agenda."
  1294. :group 'org-agenda-daily/weekly
  1295. :type 'plist)
  1296. (defvaralias 'org-agenda-search-view-search-words-only
  1297. 'org-agenda-search-view-always-boolean)
  1298. (defcustom org-agenda-search-view-always-boolean nil
  1299. "Non-nil means the search string is interpreted as individual parts.
  1300. The search string for search view can either be interpreted as a phrase,
  1301. or as a list of snippets that define a boolean search for a number of
  1302. strings.
  1303. When this is non-nil, the string will be split on whitespace, and each
  1304. snippet will be searched individually, and all must match in order to
  1305. select an entry. A snippet is then a single string of non-white
  1306. characters, or a string in double quotes, or a regexp in {} braces.
  1307. If a snippet is preceded by \"-\", the snippet must *not* match.
  1308. \"+\" is syntactic sugar for positive selection. Each snippet may
  1309. be found as a full word or a partial word, but see the variable
  1310. `org-agenda-search-view-force-full-words'.
  1311. When this is nil, search will look for the entire search phrase as one,
  1312. with each space character matching any amount of whitespace, including
  1313. line breaks.
  1314. Even when this is nil, you can still switch to Boolean search dynamically
  1315. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1316. is a regexp marked with braces like \"{abc}\", this will also switch to
  1317. boolean search."
  1318. :group 'org-agenda-search-view
  1319. :version "24.1"
  1320. :type 'boolean)
  1321. (defcustom org-agenda-search-view-force-full-words nil
  1322. "Non-nil means, search words must be matches as complete words.
  1323. When nil, they may also match part of a word."
  1324. :group 'org-agenda-search-view
  1325. :version "24.1"
  1326. :type 'boolean)
  1327. (defcustom org-agenda-search-view-max-outline-level 0
  1328. "Maximum outline level to display in search view.
  1329. E.g. when this is set to 1, the search view will only
  1330. show headlines of level 1. When set to 0, the default
  1331. value, don't limit agenda view by outline level."
  1332. :group 'org-agenda-search-view
  1333. :version "26.1"
  1334. :package-version '(Org . "8.3")
  1335. :type 'integer)
  1336. (defgroup org-agenda-time-grid nil
  1337. "Options concerning the time grid in the Org Agenda."
  1338. :tag "Org Agenda Time Grid"
  1339. :group 'org-agenda)
  1340. (defcustom org-agenda-search-headline-for-time t
  1341. "Non-nil means search headline for a time-of-day.
  1342. If the headline contains a time-of-day in one format or another, it will
  1343. be used to sort the entry into the time sequence of items for a day.
  1344. Some people have time stamps in the headline that refer to the creation
  1345. time or so, and then this produces an unwanted side effect. If this is
  1346. the case for your, use this variable to turn off searching the headline
  1347. for a time."
  1348. :group 'org-agenda-time-grid
  1349. :type 'boolean)
  1350. (defcustom org-agenda-use-time-grid t
  1351. "Non-nil means show a time grid in the agenda schedule.
  1352. A time grid is a set of lines for specific times (like every two hours between
  1353. 8:00 and 20:00). The items scheduled for a day at specific times are
  1354. sorted in between these lines.
  1355. For details about when the grid will be shown, and what it will look like, see
  1356. the variable `org-agenda-time-grid'."
  1357. :group 'org-agenda-time-grid
  1358. :type 'boolean)
  1359. (defcustom org-agenda-time-grid
  1360. (let ((graphical (and (display-graphic-p)
  1361. (char-displayable-p ?┄))))
  1362. `((daily today require-timed)
  1363. (800 1000 1200 1400 1600 1800 2000)
  1364. ,(if graphical " ┄┄┄┄┄ " "......")
  1365. ,(if graphical "┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄" "----------------")))
  1366. "The settings for time grid for agenda display.
  1367. This is a list of four items. The first item is again a list. It contains
  1368. symbols specifying conditions when the grid should be displayed:
  1369. daily if the agenda shows a single day
  1370. weekly if the agenda shows an entire week
  1371. today show grid on current date, independent of daily/weekly display
  1372. require-timed show grid only if at least one item has a time specification
  1373. remove-match skip grid times already present in an entry
  1374. The second item is a list of integers, indicating the times that
  1375. should have a grid line.
  1376. The third item is a string which will be placed right after the
  1377. times that have a grid line.
  1378. The fourth item is a string placed after the grid times. This
  1379. will align with agenda items."
  1380. :group 'org-agenda-time-grid
  1381. :version "29.1"
  1382. :type
  1383. '(list
  1384. (set :greedy t :tag "Grid Display Options"
  1385. (const :tag "Show grid in single day agenda display" daily)
  1386. (const :tag "Show grid in weekly agenda display" weekly)
  1387. (const :tag "Always show grid for today" today)
  1388. (const :tag "Show grid only if any timed entries are present"
  1389. require-timed)
  1390. (const :tag "Skip grid times already present in an entry"
  1391. remove-match))
  1392. (repeat :tag "Grid Times" (integer :tag "Time"))
  1393. (string :tag "Grid String (after agenda times)")
  1394. (string :tag "Grid String (aligns with agenda items)")))
  1395. (defcustom org-agenda-show-current-time-in-grid t
  1396. "Non-nil means show the current time in the time grid."
  1397. :group 'org-agenda-time-grid
  1398. :version "24.1"
  1399. :type 'boolean)
  1400. (defcustom org-agenda-current-time-string
  1401. (if (and (display-graphic-p)
  1402. (char-displayable-p ?←)
  1403. (char-displayable-p ?─))
  1404. "← now ───────────────────────────────────────────────"
  1405. "now - - - - - - - - - - - - - - - - - - - - - - - - -")
  1406. "The string for the current time marker in the agenda."
  1407. :group 'org-agenda-time-grid
  1408. :version "29.1"
  1409. :type 'string)
  1410. (defgroup org-agenda-sorting nil
  1411. "Options concerning sorting in the Org Agenda."
  1412. :tag "Org Agenda Sorting"
  1413. :group 'org-agenda)
  1414. (defcustom org-agenda-sorting-strategy
  1415. '((agenda habit-down time-up priority-down category-keep)
  1416. (todo priority-down category-keep)
  1417. (tags priority-down category-keep)
  1418. (search category-keep))
  1419. "Sorting structure for the agenda items of a single day.
  1420. This is a list of symbols which will be used in sequence to determine
  1421. if an entry should be listed before another entry. The following
  1422. symbols are recognized:
  1423. time-up Put entries with time-of-day indications first, early first.
  1424. time-down Put entries with time-of-day indications first, late first.
  1425. timestamp-up Sort by any timestamp, early first.
  1426. timestamp-down Sort by any timestamp, late first.
  1427. scheduled-up Sort by scheduled timestamp, early first.
  1428. scheduled-down Sort by scheduled timestamp, late first.
  1429. deadline-up Sort by deadline timestamp, early first.
  1430. deadline-down Sort by deadline timestamp, late first.
  1431. ts-up Sort by active timestamp, early first.
  1432. ts-down Sort by active timestamp, late first.
  1433. tsia-up Sort by inactive timestamp, early first.
  1434. tsia-down Sort by inactive timestamp, late first.
  1435. category-keep Keep the default order of categories, corresponding to the
  1436. sequence in `org-agenda-files'.
  1437. category-up Sort alphabetically by category, A-Z.
  1438. category-down Sort alphabetically by category, Z-A.
  1439. tag-up Sort alphabetically by last tag, A-Z.
  1440. tag-down Sort alphabetically by last tag, Z-A.
  1441. priority-up Sort numerically by priority, high priority last.
  1442. priority-down Sort numerically by priority, high priority first.
  1443. todo-state-up Sort by todo state, tasks that are done last.
  1444. todo-state-down Sort by todo state, tasks that are done first.
  1445. effort-up Sort numerically by estimated effort, high effort last.
  1446. effort-down Sort numerically by estimated effort, high effort first.
  1447. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1448. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1449. habit-up Put entries that are habits first.
  1450. habit-down Put entries that are habits last.
  1451. alpha-up Sort headlines alphabetically.
  1452. alpha-down Sort headlines alphabetically, reversed.
  1453. The different possibilities will be tried in sequence, and testing stops
  1454. if one comparison returns a \"not-equal\". For example,
  1455. (setq org-agenda-sorting-strategy
  1456. \\='(time-up category-keep priority-down))
  1457. means: Pull out all entries having a specified time of day and sort them,
  1458. in order to make a time schedule for the current day the first thing in the
  1459. agenda listing for the day. Of the entries without a time indication, keep
  1460. the grouped in categories, don't sort the categories, but keep them in
  1461. the sequence given in `org-agenda-files'. Within each category sort by
  1462. priority.
  1463. Leaving out `category-keep' would mean that items will be sorted across
  1464. categories by priority.
  1465. Instead of a single list, this can also be a set of list for specific
  1466. contents, with a context symbol in the car of the list, any of
  1467. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1468. Custom commands can bind this variable in the options section."
  1469. :group 'org-agenda-sorting
  1470. :type `(choice
  1471. (repeat :tag "General" ,org-sorting-choice)
  1472. (list :tag "Individually"
  1473. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1474. (repeat ,org-sorting-choice))
  1475. (cons (const :tag "Strategy for TODO lists" todo)
  1476. (repeat ,org-sorting-choice))
  1477. (cons (const :tag "Strategy for Tags matches" tags)
  1478. (repeat ,org-sorting-choice))
  1479. (cons (const :tag "Strategy for search matches" search)
  1480. (repeat ,org-sorting-choice)))))
  1481. (defcustom org-agenda-cmp-user-defined nil
  1482. "A function to define the comparison `user-defined'.
  1483. This function must receive two arguments, agenda entry a and b.
  1484. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1485. the user comparison, return nil.
  1486. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1487. part of an agenda sorting strategy."
  1488. :group 'org-agenda-sorting
  1489. :type 'symbol)
  1490. (defcustom org-agenda-sort-notime-is-late t
  1491. "Non-nil means items without time are considered late.
  1492. This is only relevant for sorting. When t, items which have no explicit
  1493. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1494. do have a time. When nil, the default time is before 0:00. You can use this
  1495. option to decide if the schedule for today should come before or after timeless
  1496. agenda entries."
  1497. :group 'org-agenda-sorting
  1498. :type 'boolean)
  1499. (defcustom org-agenda-sort-noeffort-is-high t
  1500. "Non-nil means items without effort estimate are sorted as high effort.
  1501. This also applies when filtering an agenda view with respect to the
  1502. < or > effort operator. Then, tasks with no effort defined will be treated
  1503. as tasks with high effort.
  1504. When nil, such items are sorted as 0 minutes effort."
  1505. :group 'org-agenda-sorting
  1506. :type 'boolean)
  1507. (defgroup org-agenda-line-format nil
  1508. "Options concerning the entry prefix in the Org agenda display."
  1509. :tag "Org Agenda Line Format"
  1510. :group 'org-agenda)
  1511. (defcustom org-agenda-prefix-format
  1512. '((agenda . " %i %-12:c%?-12t% s")
  1513. (todo . " %i %-12:c")
  1514. (tags . " %i %-12:c")
  1515. (search . " %i %-12:c"))
  1516. "Format specifications for the prefix of items in the agenda views.
  1517. An alist with one entry per agenda type. The keys of the
  1518. sublists are `agenda', `todo', `search' and `tags'. The values
  1519. are format strings.
  1520. This format works similar to a printf format, with the following meaning:
  1521. %c the category of the item, \"Diary\" for entries from the diary,
  1522. or as given by the CATEGORY keyword or derived from the file name
  1523. %e the effort required by the item
  1524. %l the level of the item (insert X space(s) if item is of level X)
  1525. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1526. %T the last tag of the item (ignore inherited tags, which come first)
  1527. %t the HH:MM time-of-day specification if one applies to the entry
  1528. %s Scheduling/Deadline information, a short string
  1529. %b show breadcrumbs, i.e., the names of the higher levels
  1530. %(expression) Eval EXPRESSION and replace the control string
  1531. by the result
  1532. All specifiers work basically like the standard `%s' of printf, but may
  1533. contain two additional characters: a question mark just after the `%'
  1534. and a whitespace/punctuation character just before the final letter.
  1535. If the first character after `%' is a question mark, the entire field
  1536. will only be included if the corresponding value applies to the current
  1537. entry. This is useful for fields which should have fixed width when
  1538. present, but zero width when absent. For example, \"%?-12t\" will
  1539. result in a 12 character time field if a time of the day is specified,
  1540. but will completely disappear in entries which do not contain a time.
  1541. If there is punctuation or whitespace character just before the
  1542. final format letter, this character will be appended to the field
  1543. value if the value is not empty. For example, the format
  1544. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1545. the category is empty, no additional colon is inserted.
  1546. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1547. which means:
  1548. - Indent the line with two space characters
  1549. - Give the category a 12 chars wide field, padded with whitespace on
  1550. the right (because of `-'). Append a colon if there is a category
  1551. (because of `:').
  1552. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1553. time, don't put in an empty field, just skip it (because of '?').
  1554. - Finally, put the scheduling information.
  1555. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1556. `org-agenda-remove-tags'.
  1557. Custom commands can set this variable in the options section."
  1558. :type '(choice
  1559. (string :tag "General format")
  1560. (list :greedy t :tag "View dependent"
  1561. (cons (const agenda) (string :tag "Format"))
  1562. (cons (const todo) (string :tag "Format"))
  1563. (cons (const tags) (string :tag "Format"))
  1564. (cons (const search) (string :tag "Format"))))
  1565. :group 'org-agenda-line-format
  1566. :version "26.1"
  1567. :package-version '(Org . "9.1"))
  1568. (defcustom org-agenda-breadcrumbs-separator "->"
  1569. "The separator of breadcrumbs in agenda lines."
  1570. :group 'org-agenda-line-format
  1571. :package-version '(Org . "9.3")
  1572. :type 'string
  1573. :safe #'stringp)
  1574. (defvar org-prefix-format-compiled nil
  1575. "The compiled prefix format and associated variables.
  1576. This is a list where first element is a list of variable bindings, and second
  1577. element is the compiled format expression. See the variable
  1578. `org-agenda-prefix-format'.")
  1579. (defcustom org-agenda-todo-keyword-format "%-1s"
  1580. "Format for the TODO keyword in agenda lines.
  1581. Set this to something like \"%-12s\" if you want all TODO keywords
  1582. to occupy a fixed space in the agenda display."
  1583. :group 'org-agenda-line-format
  1584. :type 'string)
  1585. (defcustom org-agenda-diary-sexp-prefix nil
  1586. "A regexp that matches part of a diary sexp entry
  1587. which should be treated as scheduling/deadline information in
  1588. `org-agenda'.
  1589. For example, you can use this to extract the `diary-remind-message' from
  1590. `diary-remind' entries."
  1591. :group 'org-agenda-line-format
  1592. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1593. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1594. "Text preceding timerange entries in the agenda view.
  1595. This is a list with two strings. The first applies when the range
  1596. is entirely on one day. The second applies if the range spans several days.
  1597. The strings may have two \"%d\" format specifiers which will be filled
  1598. with the sequence number of the days, and the total number of days in the
  1599. range, respectively."
  1600. :group 'org-agenda-line-format
  1601. :type '(list
  1602. (string :tag "Deadline today ")
  1603. (choice :tag "Deadline relative"
  1604. (string :tag "Format string")
  1605. (function))))
  1606. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1607. "Text preceding scheduled items in the agenda view.
  1608. This is a list with two strings. The first applies when the item is
  1609. scheduled on the current day. The second applies when it has been scheduled
  1610. previously, it may contain a %d indicating that this is the nth time that
  1611. this item is scheduled, due to automatic rescheduling of unfinished items
  1612. for the following day. So this number is one larger than the number of days
  1613. that passed since this item was scheduled first."
  1614. :group 'org-agenda-line-format
  1615. :version "24.4"
  1616. :package-version '(Org . "8.0")
  1617. :type '(list
  1618. (string :tag "Scheduled today ")
  1619. (string :tag "Scheduled previously")))
  1620. (defcustom org-agenda-inactive-leader "["
  1621. "Text preceding item pulled into the agenda by inactive time stamps.
  1622. These entries are added to the agenda when pressing \"[\"."
  1623. :group 'org-agenda-line-format
  1624. :version "24.1"
  1625. :type 'string)
  1626. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1627. "Text preceding deadline items in the agenda view.
  1628. This is a list with three strings. The first applies when the item has its
  1629. deadline on the current day. The second applies when the deadline is in the
  1630. future, the third one when it is in the past. The strings may contain %d
  1631. to capture the number of days."
  1632. :group 'org-agenda-line-format
  1633. :version "24.4"
  1634. :package-version '(Org . "8.0")
  1635. :type '(list
  1636. (string :tag "Deadline today ")
  1637. (string :tag "Deadline in the future ")
  1638. (string :tag "Deadline in the past ")))
  1639. (defcustom org-agenda-remove-times-when-in-prefix t
  1640. "Non-nil means remove duplicate time specifications in agenda items.
  1641. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1642. time-of-day specification in a headline or diary entry is extracted and
  1643. placed into the prefix. If this option is non-nil, the original specification
  1644. \(a timestamp or -range, or just a plain time(range) specification like
  1645. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1646. cluttered.
  1647. The option can be t or nil. It may also be the symbol `beg', indicating
  1648. that the time should only be removed when it is located at the beginning of
  1649. the headline/diary entry."
  1650. :group 'org-agenda-line-format
  1651. :type '(choice
  1652. (const :tag "Always" t)
  1653. (const :tag "Never" nil)
  1654. (const :tag "When at beginning of entry" beg)))
  1655. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1656. "Non-nil means remove time ranges specifications in agenda
  1657. items that span on several days."
  1658. :group 'org-agenda-line-format
  1659. :version "24.1"
  1660. :type 'boolean)
  1661. (defcustom org-agenda-default-appointment-duration nil
  1662. "Default duration for appointments that only have a starting time.
  1663. When nil, no duration is specified in such cases.
  1664. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1665. :group 'org-agenda-line-format
  1666. :type '(choice
  1667. (integer :tag "Minutes")
  1668. (const :tag "No default duration")))
  1669. (defcustom org-agenda-show-inherited-tags t
  1670. "Non-nil means show inherited tags in each agenda line.
  1671. When this option is set to `always', it takes precedence over
  1672. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1673. in every agenda.
  1674. When this option is set to t (the default), inherited tags are
  1675. shown when they are available, i.e. when the value of
  1676. `org-agenda-use-tag-inheritance' enables tag inheritance for the
  1677. given agenda type.
  1678. This can be set to a list of agenda types in which the agenda
  1679. must display the inherited tags. Available types are `todo',
  1680. `agenda' and `search'.
  1681. When set to nil, never show inherited tags in agenda lines."
  1682. :group 'org-agenda-line-format
  1683. :group 'org-agenda
  1684. :version "24.3"
  1685. :type '(choice
  1686. (const :tag "Show inherited tags when available" t)
  1687. (const :tag "Always show inherited tags" always)
  1688. (repeat :tag "Show inherited tags only in selected agenda types"
  1689. (symbol :tag "Agenda type"))))
  1690. (defcustom org-agenda-use-tag-inheritance '(todo search agenda)
  1691. "List of agenda view types where to use tag inheritance.
  1692. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1693. controlled by `org-use-tag-inheritance'. In other agenda types,
  1694. `org-use-tag-inheritance' is not used for the selection of the
  1695. agenda entries. Still, you may want the agenda to be aware of
  1696. the inherited tags anyway, e.g. for later tag filtering.
  1697. Allowed value are `todo', `search' and `agenda'.
  1698. This variable has no effect if `org-agenda-show-inherited-tags'
  1699. is set to `always'. In that case, the agenda is aware of those
  1700. tags.
  1701. The default value sets tags in every agenda type. Setting this
  1702. option to nil will speed up non-tags agenda view a lot."
  1703. :group 'org-agenda
  1704. :version "26.1"
  1705. :package-version '(Org . "9.1")
  1706. :type '(choice
  1707. (const :tag "Use tag inheritance in all agenda types" t)
  1708. (repeat :tag "Use tag inheritance in selected agenda types"
  1709. (symbol :tag "Agenda type"))))
  1710. (defcustom org-agenda-hide-tags-regexp nil
  1711. "Regular expression used to filter away specific tags in agenda views.
  1712. This means that these tags will be present, but not be shown in the agenda
  1713. line. Secondary filtering will still work on the hidden tags.
  1714. Nil means don't hide any tags."
  1715. :group 'org-agenda-line-format
  1716. :type '(choice
  1717. (const :tag "Hide none" nil)
  1718. (regexp :tag "Regexp ")))
  1719. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1720. 'org-agenda-remove-tags)
  1721. (defcustom org-agenda-remove-tags nil
  1722. "Non-nil means remove the tags from the headline copy in the agenda.
  1723. When this is the symbol `prefix', only remove tags when
  1724. `org-agenda-prefix-format' contains a `%T' specifier."
  1725. :group 'org-agenda-line-format
  1726. :type '(choice
  1727. (const :tag "Always" t)
  1728. (const :tag "Never" nil)
  1729. (const :tag "When prefix format contains %T" prefix)))
  1730. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1731. (defcustom org-agenda-tags-column 'auto
  1732. "Shift tags in agenda items to this column.
  1733. If set to `auto', tags will be automatically aligned to the right
  1734. edge of the window.
  1735. If set to a positive number, tags will be left-aligned to that
  1736. column. If set to a negative number, tags will be right-aligned
  1737. to that column. For example, -80 works well for a normal 80
  1738. character screen."
  1739. :group 'org-agenda-line-format
  1740. :type '(choice
  1741. (const :tag "Automatically align to right edge of window" auto)
  1742. (integer :tag "Specific column" -80))
  1743. :package-version '(Org . "9.1")
  1744. :version "26.1")
  1745. (defcustom org-agenda-fontify-priorities 'cookies
  1746. "Non-nil means highlight low and high priorities in agenda.
  1747. When t, the highest priority entries are bold, lowest priority italic.
  1748. However, settings in `org-priority-faces' will overrule these faces.
  1749. When this variable is the symbol `cookies', only fontify the
  1750. cookies, not the entire task.
  1751. This may also be an association list of priority faces, whose
  1752. keys are the character values of `org-priority-highest',
  1753. `org-priority-default', and `org-priority-lowest' (the default values
  1754. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1755. color as a string, or a list like `(:background \"Red\")'.
  1756. If it is a color, the variable `org-faces-easy-properties'
  1757. determines if it is a foreground or a background color."
  1758. :group 'org-agenda-line-format
  1759. :type '(choice
  1760. (const :tag "Never" nil)
  1761. (const :tag "Defaults" t)
  1762. (const :tag "Cookies only" cookies)
  1763. (repeat :tag "Specify"
  1764. (list (character :tag "Priority" :value ?A)
  1765. (choice :tag "Face "
  1766. (string :tag "Color")
  1767. (sexp :tag "Face"))))))
  1768. (defcustom org-agenda-day-face-function nil
  1769. "Function called to determine what face should be used to display a day.
  1770. The only argument passed to that function is the day. It should
  1771. returns a face, or nil if does not want to specify a face and let
  1772. the normal rules apply."
  1773. :group 'org-agenda-line-format
  1774. :version "24.1"
  1775. :type '(choice (const nil) (function)))
  1776. (defcustom org-agenda-category-icon-alist nil
  1777. "Alist of category icon to be displayed in agenda views.
  1778. Each entry should have the following format:
  1779. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1780. Where CATEGORY-REGEXP is a regexp matching the categories where
  1781. the icon should be displayed.
  1782. FILE-OR-DATA either a file path or a string containing image data.
  1783. The other fields can be omitted safely if not needed:
  1784. TYPE indicates the image type.
  1785. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1786. image data.
  1787. PROPS are additional image attributes to assign to the image,
  1788. like, e.g. `:ascent center'.
  1789. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1790. If you want to set the display properties yourself, just put a
  1791. list as second element:
  1792. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1793. For example, to display a 16px horizontal space for Emacs
  1794. category, you can use:
  1795. (\"Emacs\" \\='(space . (:width (16))))"
  1796. :group 'org-agenda-line-format
  1797. :version "24.1"
  1798. :type '(alist :key-type (regexp :tag "Regexp matching category")
  1799. :value-type (choice (list :tag "Icon"
  1800. (string :tag "File or data")
  1801. (symbol :tag "Type")
  1802. (boolean :tag "Data?")
  1803. (repeat :tag "Extra image properties" :inline t sexp))
  1804. (list :tag "Display properties" sexp))))
  1805. (defgroup org-agenda-column-view nil
  1806. "Options concerning column view in the agenda."
  1807. :tag "Org Agenda Column View"
  1808. :group 'org-agenda)
  1809. (defcustom org-agenda-view-columns-initially nil
  1810. "When non-nil, switch to columns view right after creating the agenda."
  1811. :group 'org-agenda-column-view
  1812. :type 'boolean
  1813. :version "26.1"
  1814. :package-version '(Org . "9.0")
  1815. :safe #'booleanp)
  1816. (defcustom org-agenda-columns-show-summaries t
  1817. "Non-nil means show summaries for columns displayed in the agenda view."
  1818. :group 'org-agenda-column-view
  1819. :type 'boolean)
  1820. (defcustom org-agenda-columns-compute-summary-properties t
  1821. "Non-nil means recompute all summary properties before column view.
  1822. When column view in the agenda is listing properties that have a summary
  1823. operator, it can go to all relevant buffers and recompute the summaries
  1824. there. This can mean overhead for the agenda column view, but is necessary
  1825. to have thing up to date.
  1826. As a special case, a CLOCKSUM property also makes sure that the clock
  1827. computations are current."
  1828. :group 'org-agenda-column-view
  1829. :type 'boolean)
  1830. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1831. "Non-nil means the duration of an appointment will add to day effort.
  1832. The property to which appointment durations will be added is the one given
  1833. in the option `org-effort-property'. If an appointment does not have
  1834. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1835. is not set, an appointment without end time will not contribute to the time
  1836. estimate."
  1837. :group 'org-agenda-column-view
  1838. :type 'boolean)
  1839. (defcustom org-agenda-auto-exclude-function nil
  1840. "A function called with a tag to decide if it is filtered on \
  1841. \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
  1842. The sole argument to the function, which is called once for each
  1843. possible tag, is a string giving the name of the tag. The
  1844. function should return either nil if the tag should be included
  1845. as normal, \"-<TAG>\" to exclude the tag, or \"+<TAG>\" to exclude
  1846. lines not carrying this tag.
  1847. Note that for the purpose of tag filtering, only the lower-case version of
  1848. all tags will be considered, so that this function will only ever see
  1849. the lower-case version of all tags."
  1850. :group 'org-agenda
  1851. :type '(choice (const nil) (function)))
  1852. (defcustom org-agenda-bulk-custom-functions nil
  1853. "Alist of characters and custom functions for bulk actions.
  1854. For example, this makes those two functions available:
  1855. (setq org-agenda-bulk-custom-functions
  1856. \\='((?R set-category)
  1857. (?C bulk-cut)))
  1858. With selected entries in an agenda buffer, `B R' will call
  1859. the custom function `set-category' on the selected entries.
  1860. Note that functions in this alist don't need to be quoted.
  1861. You can also specify a function which collects arguments to be
  1862. used for each call to your bulk custom function. The argument
  1863. collecting function will be run once and should return a list of
  1864. arguments to pass to the bulk function. For example:
  1865. (setq org-agenda-bulk-custom-functions
  1866. \\='((?R set-category get-category)))
  1867. Now, `B R' will call the custom `get-category' which would prompt
  1868. the user once for a category. That category is then passed as an
  1869. argument to `set-category' for each entry it's called against."
  1870. :type
  1871. '(alist :key-type character
  1872. :value-type
  1873. (group (function :tag "Bulk Custom Function")
  1874. (choice (function :tag "Bulk Custom Argument Function")
  1875. (const :tag "No Bulk Custom Argument Function" nil))))
  1876. :package-version '(Org . "9.5")
  1877. :group 'org-agenda)
  1878. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1879. "Execute BODY with point at location given by `org-hd-marker' property.
  1880. If STRING is non-nil, the text property will be fetched from position 0
  1881. in that string. If STRING is nil, it will be fetched from the beginning
  1882. of the current line."
  1883. (declare (debug t) (indent 1))
  1884. (org-with-gensyms (marker)
  1885. `(let ((,marker (get-text-property (if ,string 0 (line-beginning-position))
  1886. 'org-hd-marker ,string)))
  1887. (with-current-buffer (marker-buffer ,marker)
  1888. (save-excursion
  1889. (goto-char ,marker)
  1890. ,@body)))))
  1891. (defun org-add-agenda-custom-command (entry)
  1892. "Replace or add a command in `org-agenda-custom-commands'.
  1893. This is mostly for hacking and trying a new command - once the command
  1894. works you probably want to add it to `org-agenda-custom-commands' for good."
  1895. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1896. (if ass
  1897. (setcdr ass (cdr entry))
  1898. (push entry org-agenda-custom-commands))))
  1899. (defmacro org-agenda--insert-overriding-header (default)
  1900. "Insert header into agenda view.
  1901. The inserted header depends on `org-agenda-overriding-header'.
  1902. If the empty string, don't insert a header. If any other string,
  1903. insert it as a header. If nil, insert DEFAULT, which should
  1904. evaluate to a string. If a function, call it and insert the
  1905. string that it returns."
  1906. (declare (debug (form)) (indent defun))
  1907. `(cond
  1908. ((not org-agenda-overriding-header) (insert ,default))
  1909. ((equal org-agenda-overriding-header "") nil)
  1910. ((stringp org-agenda-overriding-header)
  1911. (insert (propertize org-agenda-overriding-header
  1912. 'face 'org-agenda-structure)
  1913. "\n"))
  1914. ((functionp org-agenda-overriding-header)
  1915. (insert (funcall org-agenda-overriding-header)))
  1916. (t (user-error "Invalid value for `org-agenda-overriding-header': %S"
  1917. org-agenda-overriding-header))))
  1918. ;;; Define the org-agenda-mode
  1919. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1920. (defvar org-agenda-mode-map (make-sparse-keymap)
  1921. "Keymap for `org-agenda-mode'.")
  1922. (org-remap org-agenda-mode-map 'move-end-of-line 'org-agenda-end-of-line)
  1923. (defvar org-agenda-menu) ; defined later in this file.
  1924. (defvar org-agenda-restrict nil)
  1925. (defvar org-agenda-follow-mode nil)
  1926. (defvar org-agenda-entry-text-mode nil)
  1927. (defvar org-agenda-clockreport-mode nil)
  1928. (defvar org-agenda-show-log nil
  1929. "When non-nil, show the log in the agenda.
  1930. Do not set this directly; instead use
  1931. `org-agenda-start-with-log-mode', which see.")
  1932. (defvar org-agenda-redo-command nil)
  1933. (defvar org-agenda-query-string nil)
  1934. (defvar org-agenda-mode-hook nil
  1935. "Hook run after `org-agenda-mode' is turned on.
  1936. The buffer is still writable when this hook is called.")
  1937. (defvar org-agenda-type nil)
  1938. (defvar org-agenda-force-single-file nil)
  1939. (defvar org-agenda-bulk-marked-entries nil
  1940. "List of markers that refer to marked entries in the agenda.")
  1941. (defvar org-agenda-current-date nil
  1942. "Active date when building the agenda.")
  1943. ;;; Multiple agenda buffers support
  1944. (defcustom org-agenda-sticky nil
  1945. "Non-nil means agenda q key will bury agenda buffers.
  1946. Agenda commands will then show existing buffer instead of generating new ones.
  1947. When nil, `q' will kill the single agenda buffer."
  1948. :group 'org-agenda
  1949. :version "24.3"
  1950. :type 'boolean)
  1951. ;;;###autoload
  1952. (defun org-toggle-sticky-agenda (&optional arg)
  1953. "Toggle `org-agenda-sticky'."
  1954. (interactive "P")
  1955. (let ((new-value (if arg
  1956. (> (prefix-numeric-value arg) 0)
  1957. (not org-agenda-sticky))))
  1958. (if (equal new-value org-agenda-sticky)
  1959. (and (called-interactively-p 'interactive)
  1960. (message "Sticky agenda was already %s"
  1961. (if org-agenda-sticky "enabled" "disabled")))
  1962. (setq org-agenda-sticky new-value)
  1963. (org-agenda-kill-all-agenda-buffers)
  1964. (and (called-interactively-p 'interactive)
  1965. (message "Sticky agenda %s"
  1966. (if org-agenda-sticky "enabled" "disabled"))))))
  1967. (defvar org-agenda-buffer nil
  1968. "Agenda buffer currently being generated.")
  1969. (defvar org-agenda-last-prefix-arg nil)
  1970. (defvar org-agenda-this-buffer-name nil)
  1971. (defvar org-agenda-doing-sticky-redo nil)
  1972. (defvar org-agenda-this-buffer-is-sticky nil)
  1973. (defvar org-agenda-last-indirect-buffer nil
  1974. "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
  1975. (defconst org-agenda-local-vars
  1976. '(org-agenda-this-buffer-name
  1977. org-agenda-undo-list
  1978. org-agenda-pending-undo-list
  1979. org-agenda-follow-mode
  1980. org-agenda-entry-text-mode
  1981. org-agenda-clockreport-mode
  1982. org-agenda-show-log
  1983. org-agenda-redo-command
  1984. org-agenda-query-string
  1985. org-agenda-type
  1986. org-agenda-bulk-marked-entries
  1987. org-agenda-undo-has-started-in
  1988. org-agenda-info
  1989. org-agenda-pre-window-conf
  1990. org-agenda-columns-active
  1991. org-agenda-tag-filter
  1992. org-agenda-category-filter
  1993. org-agenda-top-headline-filter
  1994. org-agenda-regexp-filter
  1995. org-agenda-effort-filter
  1996. org-agenda-markers
  1997. org-agenda-last-search-view-search-was-boolean
  1998. org-agenda-last-indirect-buffer
  1999. org-agenda-filtered-by-category
  2000. org-agenda-filter-form
  2001. org-agenda-cycle-counter
  2002. org-agenda-last-prefix-arg)
  2003. "Variables that must be local in agenda buffers to allow multiple buffers.")
  2004. (defun org-agenda-mode ()
  2005. "Mode for time-sorted view on action items in Org files.
  2006. The following commands are available:
  2007. \\{org-agenda-mode-map}"
  2008. (interactive)
  2009. (ignore-errors (require 'face-remap))
  2010. (let ((agenda-local-vars-to-keep
  2011. '(text-scale-mode-amount
  2012. text-scale-mode
  2013. text-scale-mode-lighter
  2014. face-remapping-alist))
  2015. (save (buffer-local-variables)))
  2016. (kill-all-local-variables)
  2017. (cl-flet ((reset-saved (var-set)
  2018. "Reset variables in VAR-SET to possibly stored value in SAVE."
  2019. (dolist (elem save)
  2020. (pcase elem
  2021. (`(,var . ,val) ;ignore unbound variables
  2022. (when (and val (memq var var-set))
  2023. (set var val)))))))
  2024. (cond (org-agenda-doing-sticky-redo
  2025. ;; Refreshing sticky agenda-buffer
  2026. ;;
  2027. ;; Preserve the value of `org-agenda-local-vars' variables.
  2028. (mapc #'make-local-variable org-agenda-local-vars)
  2029. (reset-saved org-agenda-local-vars)
  2030. (setq-local org-agenda-this-buffer-is-sticky t))
  2031. (org-agenda-sticky
  2032. ;; Creating a sticky Agenda buffer for the first time
  2033. (mapc #'make-local-variable org-agenda-local-vars)
  2034. (setq-local org-agenda-this-buffer-is-sticky t))
  2035. (t
  2036. ;; Creating a non-sticky agenda buffer
  2037. (setq-local org-agenda-this-buffer-is-sticky nil)))
  2038. (mapc #'make-local-variable agenda-local-vars-to-keep)
  2039. (reset-saved agenda-local-vars-to-keep)))
  2040. (setq org-agenda-undo-list nil
  2041. org-agenda-pending-undo-list nil
  2042. org-agenda-bulk-marked-entries nil)
  2043. (setq major-mode 'org-agenda-mode)
  2044. ;; Keep global-font-lock-mode from turning on font-lock-mode
  2045. (setq-local font-lock-global-modes (list 'not major-mode))
  2046. (setq mode-name "Org-Agenda")
  2047. (setq indent-tabs-mode nil)
  2048. (use-local-map org-agenda-mode-map)
  2049. (when org-startup-truncated (setq truncate-lines t))
  2050. (setq-local line-move-visual nil)
  2051. (add-hook 'post-command-hook #'org-agenda-update-agenda-type nil 'local)
  2052. (add-hook 'pre-command-hook #'org-unhighlight nil 'local)
  2053. ;; Make sure properties are removed when copying text
  2054. (if (boundp 'filter-buffer-substring-functions)
  2055. (add-hook 'filter-buffer-substring-functions
  2056. (lambda (fun start end delete)
  2057. (substring-no-properties (funcall fun start end delete)))
  2058. nil t)
  2059. ;; Emacs >= 24.4.
  2060. (add-function :filter-return (local 'filter-buffer-substring-function)
  2061. #'substring-no-properties))
  2062. (unless org-agenda-keep-modes
  2063. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  2064. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  2065. org-agenda-show-log org-agenda-start-with-log-mode
  2066. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode))
  2067. (add-to-invisibility-spec '(org-filtered))
  2068. (org-fold-core-initialize `(,org-link--description-folding-spec
  2069. ,org-link--link-folding-spec))
  2070. (easy-menu-change
  2071. '("Agenda") "Agenda Files"
  2072. (append
  2073. (list
  2074. (vector
  2075. (if (get 'org-agenda-files 'org-restrict)
  2076. "Restricted to single file"
  2077. "Edit File List")
  2078. '(org-edit-agenda-file-list)
  2079. (not (get 'org-agenda-files 'org-restrict)))
  2080. "--")
  2081. (mapcar #'org-file-menu-entry (org-agenda-files))))
  2082. (org-agenda-set-mode-name)
  2083. (run-mode-hooks 'org-agenda-mode-hook))
  2084. (substitute-key-definition #'undo #'org-agenda-undo
  2085. org-agenda-mode-map global-map)
  2086. (org-defkey org-agenda-mode-map "\C-i" #'org-agenda-goto)
  2087. (org-defkey org-agenda-mode-map [(tab)] #'org-agenda-goto)
  2088. (org-defkey org-agenda-mode-map "\C-m" #'org-agenda-switch-to)
  2089. (org-defkey org-agenda-mode-map "\C-k" #'org-agenda-kill)
  2090. (org-defkey org-agenda-mode-map "\C-c\C-w" #'org-agenda-refile)
  2091. (org-defkey org-agenda-mode-map [(meta down)] #'org-agenda-drag-line-forward)
  2092. (org-defkey org-agenda-mode-map [(meta up)] #'org-agenda-drag-line-backward)
  2093. (org-defkey org-agenda-mode-map "m" #'org-agenda-bulk-mark)
  2094. (org-defkey org-agenda-mode-map "\M-m" #'org-agenda-bulk-toggle)
  2095. (org-defkey org-agenda-mode-map "*" #'org-agenda-bulk-mark-all)
  2096. (org-defkey org-agenda-mode-map "\M-*" #'org-agenda-bulk-toggle-all)
  2097. (org-defkey org-agenda-mode-map "#" #'org-agenda-dim-blocked-tasks)
  2098. (org-defkey org-agenda-mode-map "%" #'org-agenda-bulk-mark-regexp)
  2099. (org-defkey org-agenda-mode-map "u" #'org-agenda-bulk-unmark)
  2100. (org-defkey org-agenda-mode-map "U" #'org-agenda-bulk-unmark-all)
  2101. (org-defkey org-agenda-mode-map "B" #'org-agenda-bulk-action)
  2102. (org-defkey org-agenda-mode-map "k" #'org-agenda-capture)
  2103. (org-defkey org-agenda-mode-map "A" #'org-agenda-append-agenda)
  2104. (org-defkey org-agenda-mode-map "\C-c\C-x!" #'org-reload)
  2105. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" #'org-agenda-archive-default)
  2106. (org-defkey org-agenda-mode-map "\C-c\C-xa" #'org-agenda-toggle-archive-tag)
  2107. (org-defkey org-agenda-mode-map "\C-c\C-xA" #'org-agenda-archive-to-archive-sibling)
  2108. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" #'org-agenda-archive)
  2109. (org-defkey org-agenda-mode-map "\C-c$" #'org-agenda-archive)
  2110. (org-defkey org-agenda-mode-map "$" #'org-agenda-archive)
  2111. (org-defkey org-agenda-mode-map "\C-c\C-o" #'org-agenda-open-link)
  2112. (org-defkey org-agenda-mode-map " " #'org-agenda-show-and-scroll-up)
  2113. (org-defkey org-agenda-mode-map [backspace] #'org-agenda-show-scroll-down)
  2114. (org-defkey org-agenda-mode-map "\d" #'org-agenda-show-scroll-down)
  2115. (org-defkey org-agenda-mode-map [(control shift right)] #'org-agenda-todo-nextset)
  2116. (org-defkey org-agenda-mode-map [(control shift left)] #'org-agenda-todo-previousset)
  2117. (org-defkey org-agenda-mode-map "\C-c\C-xb" #'org-agenda-tree-to-indirect-buffer)
  2118. (org-defkey org-agenda-mode-map "o" #'delete-other-windows)
  2119. (org-defkey org-agenda-mode-map "L" #'org-agenda-recenter)
  2120. (org-defkey org-agenda-mode-map "\C-c\C-t" #'org-agenda-todo)
  2121. (org-defkey org-agenda-mode-map "t" #'org-agenda-todo)
  2122. (org-defkey org-agenda-mode-map "a" #'org-agenda-archive-default-with-confirmation)
  2123. (org-defkey org-agenda-mode-map ":" #'org-agenda-set-tags)
  2124. (org-defkey org-agenda-mode-map "\C-c\C-q" #'org-agenda-set-tags)
  2125. (org-defkey org-agenda-mode-map "." #'org-agenda-goto-today)
  2126. (org-defkey org-agenda-mode-map "j" #'org-agenda-goto-date)
  2127. (org-defkey org-agenda-mode-map "d" #'org-agenda-day-view)
  2128. (org-defkey org-agenda-mode-map "w" #'org-agenda-week-view)
  2129. (org-defkey org-agenda-mode-map "y" #'org-agenda-year-view)
  2130. (org-defkey org-agenda-mode-map "\C-c\C-z" #'org-agenda-add-note)
  2131. (org-defkey org-agenda-mode-map "z" #'org-agenda-add-note)
  2132. (org-defkey org-agenda-mode-map [(shift right)] #'org-agenda-do-date-later)
  2133. (org-defkey org-agenda-mode-map [(shift left)] #'org-agenda-do-date-earlier)
  2134. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] #'org-agenda-do-date-later)
  2135. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] #'org-agenda-do-date-earlier)
  2136. (org-defkey org-agenda-mode-map ">" #'org-agenda-date-prompt)
  2137. (org-defkey org-agenda-mode-map "\C-c\C-s" #'org-agenda-schedule)
  2138. (org-defkey org-agenda-mode-map "\C-c\C-d" #'org-agenda-deadline)
  2139. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  2140. (while l (org-defkey org-agenda-mode-map
  2141. (number-to-string (pop l)) #'digit-argument)))
  2142. (org-defkey org-agenda-mode-map "F" #'org-agenda-follow-mode)
  2143. (org-defkey org-agenda-mode-map "R" #'org-agenda-clockreport-mode)
  2144. (org-defkey org-agenda-mode-map "E" #'org-agenda-entry-text-mode)
  2145. (org-defkey org-agenda-mode-map "l" #'org-agenda-log-mode)
  2146. (org-defkey org-agenda-mode-map "v" #'org-agenda-view-mode-dispatch)
  2147. (org-defkey org-agenda-mode-map "D" #'org-agenda-toggle-diary)
  2148. (org-defkey org-agenda-mode-map "!" #'org-agenda-toggle-deadlines)
  2149. (org-defkey org-agenda-mode-map "G" #'org-agenda-toggle-time-grid)
  2150. (org-defkey org-agenda-mode-map "r" #'org-agenda-redo)
  2151. (org-defkey org-agenda-mode-map "g" #'org-agenda-redo-all)
  2152. (org-defkey org-agenda-mode-map "e" #'org-agenda-set-effort)
  2153. (org-defkey org-agenda-mode-map "\C-c\C-xe" #'org-agenda-set-effort)
  2154. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  2155. #'org-clock-modify-effort-estimate)
  2156. (org-defkey org-agenda-mode-map "\C-c\C-xp" #'org-agenda-set-property)
  2157. (org-defkey org-agenda-mode-map "q" #'org-agenda-quit)
  2158. (org-defkey org-agenda-mode-map "Q" #'org-agenda-Quit)
  2159. (org-defkey org-agenda-mode-map "x" #'org-agenda-exit)
  2160. (org-defkey org-agenda-mode-map "\C-x\C-w" #'org-agenda-write)
  2161. (org-defkey org-agenda-mode-map "\C-x\C-s" #'org-save-all-org-buffers)
  2162. (org-defkey org-agenda-mode-map "s" #'org-save-all-org-buffers)
  2163. (org-defkey org-agenda-mode-map "T" #'org-agenda-show-tags)
  2164. (org-defkey org-agenda-mode-map "n" #'org-agenda-next-line)
  2165. (org-defkey org-agenda-mode-map "p" #'org-agenda-previous-line)
  2166. (org-defkey org-agenda-mode-map "N" #'org-agenda-next-item)
  2167. (org-defkey org-agenda-mode-map "P" #'org-agenda-previous-item)
  2168. (substitute-key-definition #'next-line #'org-agenda-next-line
  2169. org-agenda-mode-map global-map)
  2170. (substitute-key-definition #'previous-line #'org-agenda-previous-line
  2171. org-agenda-mode-map global-map)
  2172. (org-defkey org-agenda-mode-map "\C-c\C-a" #'org-attach)
  2173. (org-defkey org-agenda-mode-map "\C-c\C-n" #'org-agenda-next-date-line)
  2174. (org-defkey org-agenda-mode-map "\C-c\C-p" #'org-agenda-previous-date-line)
  2175. (org-defkey org-agenda-mode-map "\C-c," #'org-agenda-priority)
  2176. (org-defkey org-agenda-mode-map "," #'org-agenda-priority)
  2177. (org-defkey org-agenda-mode-map "i" #'org-agenda-diary-entry)
  2178. (org-defkey org-agenda-mode-map "c" #'org-agenda-goto-calendar)
  2179. (org-defkey org-agenda-mode-map "C" #'org-agenda-convert-date)
  2180. (org-defkey org-agenda-mode-map "M" #'org-agenda-phases-of-moon)
  2181. (org-defkey org-agenda-mode-map "S" #'org-agenda-sunrise-sunset)
  2182. (org-defkey org-agenda-mode-map "h" #'org-agenda-holidays)
  2183. (org-defkey org-agenda-mode-map "H" #'org-agenda-holidays)
  2184. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" #'org-agenda-clock-in)
  2185. (org-defkey org-agenda-mode-map "I" #'org-agenda-clock-in)
  2186. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" #'org-agenda-clock-out)
  2187. (org-defkey org-agenda-mode-map "O" #'org-agenda-clock-out)
  2188. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" #'org-agenda-clock-cancel)
  2189. (org-defkey org-agenda-mode-map "X" #'org-agenda-clock-cancel)
  2190. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" #'org-clock-goto)
  2191. (org-defkey org-agenda-mode-map "J" #'org-agenda-clock-goto)
  2192. (org-defkey org-agenda-mode-map "+" #'org-agenda-priority-up)
  2193. (org-defkey org-agenda-mode-map "-" #'org-agenda-priority-down)
  2194. (org-defkey org-agenda-mode-map [(shift up)] #'org-agenda-priority-up)
  2195. (org-defkey org-agenda-mode-map [(shift down)] #'org-agenda-priority-down)
  2196. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] #'org-agenda-priority-up)
  2197. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] #'org-agenda-priority-down)
  2198. (org-defkey org-agenda-mode-map "f" #'org-agenda-later)
  2199. (org-defkey org-agenda-mode-map "b" #'org-agenda-earlier)
  2200. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" #'org-agenda-columns)
  2201. (org-defkey org-agenda-mode-map "\C-c\C-x>" #'org-agenda-remove-restriction-lock)
  2202. (org-defkey org-agenda-mode-map "\C-c\C-x<" #'org-agenda-set-restriction-lock-from-agenda)
  2203. (org-defkey org-agenda-mode-map "[" #'org-agenda-manipulate-query-add)
  2204. (org-defkey org-agenda-mode-map "]" #'org-agenda-manipulate-query-subtract)
  2205. (org-defkey org-agenda-mode-map "{" #'org-agenda-manipulate-query-add-re)
  2206. (org-defkey org-agenda-mode-map "}" #'org-agenda-manipulate-query-subtract-re)
  2207. (org-defkey org-agenda-mode-map "\\" #'org-agenda-filter-by-tag)
  2208. (org-defkey org-agenda-mode-map "_" #'org-agenda-filter-by-effort)
  2209. (org-defkey org-agenda-mode-map "=" #'org-agenda-filter-by-regexp)
  2210. (org-defkey org-agenda-mode-map "/" #'org-agenda-filter)
  2211. (org-defkey org-agenda-mode-map "|" #'org-agenda-filter-remove-all)
  2212. (org-defkey org-agenda-mode-map "~" #'org-agenda-limit-interactively)
  2213. (org-defkey org-agenda-mode-map "<" #'org-agenda-filter-by-category)
  2214. (org-defkey org-agenda-mode-map "^" #'org-agenda-filter-by-top-headline)
  2215. (org-defkey org-agenda-mode-map ";" #'org-timer-set-timer)
  2216. (org-defkey org-agenda-mode-map "\C-c\C-x_" #'org-timer-stop)
  2217. (org-defkey org-agenda-mode-map "?" #'org-agenda-show-the-flagging-note)
  2218. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" #'org-mobile-pull)
  2219. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" #'org-mobile-push)
  2220. (org-defkey org-agenda-mode-map "\C-c\C-xI" #'org-info-find-node)
  2221. (org-defkey org-agenda-mode-map [mouse-2] #'org-agenda-goto-mouse)
  2222. (org-defkey org-agenda-mode-map [mouse-3] #'org-agenda-show-mouse)
  2223. (org-defkey org-agenda-mode-map [remap forward-paragraph] #'org-agenda-forward-block)
  2224. (org-defkey org-agenda-mode-map [remap backward-paragraph] #'org-agenda-backward-block)
  2225. (org-defkey org-agenda-mode-map "\C-c\C-c" #'org-agenda-ctrl-c-ctrl-c)
  2226. (when org-agenda-mouse-1-follows-link
  2227. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2228. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu."
  2229. '("Agenda"
  2230. ("Agenda Files")
  2231. "--"
  2232. ("Agenda Dates"
  2233. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda)]
  2234. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2235. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2236. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2237. "--"
  2238. ("View"
  2239. ["Day View" org-agenda-day-view
  2240. :active (org-agenda-check-type nil 'agenda)
  2241. :style radio :selected (eq org-agenda-current-span 'day)
  2242. :keys "v d (or just d)"]
  2243. ["Week View" org-agenda-week-view
  2244. :active (org-agenda-check-type nil 'agenda)
  2245. :style radio :selected (eq org-agenda-current-span 'week)
  2246. :keys "v w"]
  2247. ["Fortnight View" org-agenda-fortnight-view
  2248. :active (org-agenda-check-type nil 'agenda)
  2249. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2250. :keys "v t"]
  2251. ["Month View" org-agenda-month-view
  2252. :active (org-agenda-check-type nil 'agenda)
  2253. :style radio :selected (eq org-agenda-current-span 'month)
  2254. :keys "v m"]
  2255. ["Year View" org-agenda-year-view
  2256. :active (org-agenda-check-type nil 'agenda)
  2257. :style radio :selected (eq org-agenda-current-span 'year)
  2258. :keys "v y"]
  2259. "--"
  2260. ["Include Diary" org-agenda-toggle-diary
  2261. :style toggle :selected org-agenda-include-diary
  2262. :active (org-agenda-check-type nil 'agenda)]
  2263. ["Include Deadlines" org-agenda-toggle-deadlines
  2264. :style toggle :selected org-agenda-include-deadlines
  2265. :active (org-agenda-check-type nil 'agenda)]
  2266. ["Use Time Grid" org-agenda-toggle-time-grid
  2267. :style toggle :selected org-agenda-use-time-grid
  2268. :active (org-agenda-check-type nil 'agenda)]
  2269. "--"
  2270. ["Show clock report" org-agenda-clockreport-mode
  2271. :style toggle :selected org-agenda-clockreport-mode
  2272. :active (org-agenda-check-type nil 'agenda)]
  2273. ["Show some entry text" org-agenda-entry-text-mode
  2274. :style toggle :selected org-agenda-entry-text-mode
  2275. :active t]
  2276. "--"
  2277. ["Show Logbook entries" org-agenda-log-mode
  2278. :style toggle :selected org-agenda-show-log
  2279. :active (org-agenda-check-type nil 'agenda)
  2280. :keys "v l (or just l)"]
  2281. ["Include archived trees" org-agenda-archives-mode
  2282. :style toggle :selected org-agenda-archives-mode :active t
  2283. :keys "v a"]
  2284. ["Include archive files" (org-agenda-archives-mode t)
  2285. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2286. :keys "v A"]
  2287. "--"
  2288. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2289. ("Filter current view"
  2290. ["with generic interface" org-agenda-filter t]
  2291. "--"
  2292. ["by category at cursor" org-agenda-filter-by-category t]
  2293. ["by tag" org-agenda-filter-by-tag t]
  2294. ["by effort" org-agenda-filter-by-effort t]
  2295. ["by regexp" org-agenda-filter-by-regexp t]
  2296. ["by top-level headline" org-agenda-filter-by-top-headline t]
  2297. "--"
  2298. ["Remove all filtering" org-agenda-filter-remove-all t]
  2299. "--"
  2300. ["limit" org-agenda-limit-interactively t])
  2301. ["Rebuild buffer" org-agenda-redo t]
  2302. ["Write view to file" org-agenda-write t]
  2303. ["Save all Org buffers" org-save-all-org-buffers t]
  2304. "--"
  2305. ["Show original entry" org-agenda-show t]
  2306. ["Go To (other window)" org-agenda-goto t]
  2307. ["Go To (this window)" org-agenda-switch-to t]
  2308. ["Capture with cursor date" org-agenda-capture t]
  2309. ["Follow Mode" org-agenda-follow-mode
  2310. :style toggle :selected org-agenda-follow-mode :active t]
  2311. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2312. "--"
  2313. ("TODO"
  2314. ["Cycle TODO" org-agenda-todo t]
  2315. ["Next TODO set" org-agenda-todo-nextset t]
  2316. ["Previous TODO set" org-agenda-todo-previousset t]
  2317. ["Add note" org-agenda-add-note t])
  2318. ("Archive/Refile/Delete"
  2319. ["Archive default" org-agenda-archive-default t]
  2320. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2321. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2322. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2323. ["Archive subtree" org-agenda-archive t]
  2324. "--"
  2325. ["Refile" org-agenda-refile t]
  2326. "--"
  2327. ["Delete subtree" org-agenda-kill t])
  2328. ("Bulk action"
  2329. ["Mark entry" org-agenda-bulk-mark t]
  2330. ["Mark all" org-agenda-bulk-mark-all t]
  2331. ["Unmark entry" org-agenda-bulk-unmark t]
  2332. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2333. ["Toggle mark" org-agenda-bulk-toggle t]
  2334. ["Toggle all" org-agenda-bulk-toggle-all t]
  2335. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2336. ["Act on all marked" org-agenda-bulk-action t]
  2337. "--"
  2338. ("Tags and Properties"
  2339. ["Show all Tags" org-agenda-show-tags t]
  2340. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2341. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2342. "--"
  2343. ["Column View" org-columns t])
  2344. ("Deadline/Schedule"
  2345. ["Schedule" org-agenda-schedule t]
  2346. ["Set Deadline" org-agenda-deadline t]
  2347. "--"
  2348. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda)]
  2349. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda)]
  2350. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u S-right"]
  2351. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u S-left"]
  2352. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-right"]
  2353. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-left"]
  2354. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda)])
  2355. ("Clock and Effort"
  2356. ["Clock in" org-agenda-clock-in t]
  2357. ["Clock out" org-agenda-clock-out t]
  2358. ["Clock cancel" org-agenda-clock-cancel t]
  2359. ["Goto running clock" org-clock-goto t]
  2360. "--"
  2361. ["Set Effort" org-agenda-set-effort t]
  2362. ["Change clocked effort" org-clock-modify-effort-estimate
  2363. (org-clock-is-active)])
  2364. ("Priority"
  2365. ["Set Priority" org-agenda-priority t]
  2366. ["Increase Priority" org-agenda-priority-up t]
  2367. ["Decrease Priority" org-agenda-priority-down t]
  2368. ["Show Priority" org-priority-show t])
  2369. ("Calendar/Diary"
  2370. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda)]
  2371. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda)]
  2372. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda)]
  2373. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda)]
  2374. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda)]
  2375. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda)]
  2376. "--"
  2377. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2378. "--"
  2379. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2380. "--"
  2381. ("MobileOrg"
  2382. ["Push Files and Views" org-mobile-push t]
  2383. ["Get Captured and Flagged" org-mobile-pull t]
  2384. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "\\[org-agenda] ?"]
  2385. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2386. "--"
  2387. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2388. "--"
  2389. ["Quit" org-agenda-quit t]
  2390. ["Exit and Release Buffers" org-agenda-exit t]
  2391. ))
  2392. ;;; Agenda undo
  2393. (defvar org-agenda-allow-remote-undo t
  2394. "Non-nil means allow remote undo from the agenda buffer.")
  2395. (defvar org-agenda-undo-has-started-in nil
  2396. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2397. (defun org-agenda-undo ()
  2398. "Undo a remote editing step in the agenda.
  2399. This undoes changes both in the agenda buffer and in the remote buffer
  2400. that have been changed along."
  2401. (interactive)
  2402. (or org-agenda-allow-remote-undo
  2403. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2404. (when (not (eq this-command last-command))
  2405. (setq org-agenda-undo-has-started-in nil
  2406. org-agenda-pending-undo-list org-agenda-undo-list))
  2407. (when (not org-agenda-pending-undo-list)
  2408. (user-error "No further undo information"))
  2409. (let* ((entry (pop org-agenda-pending-undo-list))
  2410. buf line cmd rembuf)
  2411. (setq cmd (pop entry) line (pop entry))
  2412. (setq rembuf (nth 2 entry))
  2413. (org-with-remote-undo rembuf
  2414. (while (bufferp (setq buf (pop entry)))
  2415. (when (pop entry)
  2416. (with-current-buffer buf
  2417. (let (;; (last-undo-buffer buf)
  2418. (inhibit-read-only t))
  2419. (unless (memq buf org-agenda-undo-has-started-in)
  2420. (push buf org-agenda-undo-has-started-in)
  2421. (make-local-variable 'pending-undo-list)
  2422. (undo-start))
  2423. (while (and pending-undo-list
  2424. (listp pending-undo-list)
  2425. (not (car pending-undo-list)))
  2426. (pop pending-undo-list))
  2427. (undo-more 1))))))
  2428. (org-goto-line line)
  2429. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2430. (defun org-verify-change-for-undo (l1 l2)
  2431. "Verify that a real change occurred between the undo lists L1 and L2."
  2432. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2433. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2434. (not (eq l1 l2)))
  2435. ;;; Agenda dispatch
  2436. (defvar org-agenda-restrict-begin (make-marker))
  2437. (defvar org-agenda-restrict-end (make-marker))
  2438. (defvar org-agenda-last-dispatch-buffer nil)
  2439. (defvar org-agenda-overriding-restriction nil)
  2440. (defcustom org-agenda-custom-commands-contexts nil
  2441. "Alist of custom agenda keys and contextual rules.
  2442. For example, if you have a custom agenda command \"p\" and you
  2443. want this command to be accessible only from plain text files,
  2444. use this:
  2445. (setq org-agenda-custom-commands-contexts
  2446. \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\")))))
  2447. Here are the available contexts definitions:
  2448. in-file: command displayed only in matching files
  2449. in-mode: command displayed only in matching modes
  2450. not-in-file: command not displayed in matching files
  2451. not-in-mode: command not displayed in matching modes
  2452. in-buffer: command displayed only in matching buffers
  2453. not-in-buffer: command not displayed in matching buffers
  2454. [function]: a custom function taking no argument
  2455. If you define several checks, the agenda command will be
  2456. accessible if there is at least one valid check.
  2457. You can also bind a key to another agenda custom command
  2458. depending on contextual rules.
  2459. (setq org-agenda-custom-commands-contexts
  2460. \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\")))))
  2461. Here it means: in .txt files, use \"p\" as the key for the
  2462. agenda command otherwise associated with \"q\". (The command
  2463. originally associated with \"q\" is not displayed to avoid
  2464. duplicates.)"
  2465. :version "24.3"
  2466. :group 'org-agenda-custom-commands
  2467. :type '(repeat (list :tag "Rule"
  2468. (string :tag " Agenda key")
  2469. (string :tag "Replace by command")
  2470. (repeat :tag "Available when"
  2471. (choice
  2472. (cons :tag "Condition"
  2473. (choice
  2474. (const :tag "In file" in-file)
  2475. (const :tag "Not in file" not-in-file)
  2476. (const :tag "In buffer" in-buffer)
  2477. (const :tag "Not in buffer" not-in-buffer)
  2478. (const :tag "In mode" in-mode)
  2479. (const :tag "Not in mode" not-in-mode))
  2480. (regexp))
  2481. (function :tag "Custom function"))))))
  2482. (defcustom org-agenda-max-entries nil
  2483. "Maximum number of entries to display in an agenda.
  2484. This can be nil (no limit) or an integer or an alist of agenda
  2485. types with an associated number of entries to display in this
  2486. type."
  2487. :version "24.4"
  2488. :package-version '(Org . "8.0")
  2489. :group 'org-agenda-custom-commands
  2490. :type '(choice (symbol :tag "No limit" nil)
  2491. (integer :tag "Max number of entries")
  2492. (repeat
  2493. (cons (choice :tag "Agenda type"
  2494. (const agenda)
  2495. (const todo)
  2496. (const tags)
  2497. (const search))
  2498. (integer :tag "Max number of entries")))))
  2499. (defcustom org-agenda-max-todos nil
  2500. "Maximum number of TODOs to display in an agenda.
  2501. This can be nil (no limit) or an integer or an alist of agenda
  2502. types with an associated number of entries to display in this
  2503. type."
  2504. :version "24.4"
  2505. :package-version '(Org . "8.0")
  2506. :group 'org-agenda-custom-commands
  2507. :type '(choice (symbol :tag "No limit" nil)
  2508. (integer :tag "Max number of TODOs")
  2509. (repeat
  2510. (cons (choice :tag "Agenda type"
  2511. (const agenda)
  2512. (const todo)
  2513. (const tags)
  2514. (const search))
  2515. (integer :tag "Max number of TODOs")))))
  2516. (defcustom org-agenda-max-tags nil
  2517. "Maximum number of tagged entries to display in an agenda.
  2518. This can be nil (no limit) or an integer or an alist of agenda
  2519. types with an associated number of entries to display in this
  2520. type."
  2521. :version "24.4"
  2522. :package-version '(Org . "8.0")
  2523. :group 'org-agenda-custom-commands
  2524. :type '(choice (symbol :tag "No limit" nil)
  2525. (integer :tag "Max number of tagged entries")
  2526. (repeat
  2527. (cons (choice :tag "Agenda type"
  2528. (const agenda)
  2529. (const todo)
  2530. (const tags)
  2531. (const search))
  2532. (integer :tag "Max number of tagged entries")))))
  2533. (defcustom org-agenda-max-effort nil
  2534. "Maximum cumulated effort duration for the agenda.
  2535. This can be nil (no limit) or a number of minutes (as an integer)
  2536. or an alist of agenda types with an associated number of minutes
  2537. to limit entries to in this type."
  2538. :version "24.4"
  2539. :package-version '(Org . "8.0")
  2540. :group 'org-agenda-custom-commands
  2541. :type '(choice (symbol :tag "No limit" nil)
  2542. (integer :tag "Max number of minutes")
  2543. (repeat
  2544. (cons (choice :tag "Agenda type"
  2545. (const agenda)
  2546. (const todo)
  2547. (const tags)
  2548. (const search))
  2549. (integer :tag "Max number of minutes")))))
  2550. (defvar org-agenda-keep-restricted-file-list nil)
  2551. (defvar org-keys nil)
  2552. (defvar org-match nil)
  2553. ;;;###autoload
  2554. (defun org-agenda (&optional arg keys restriction)
  2555. "Dispatch agenda commands to collect entries to the agenda buffer.
  2556. Prompts for a command to execute. Any prefix arg will be passed
  2557. on to the selected command. The default selections are:
  2558. a Call `org-agenda-list' to display the agenda for current day or week.
  2559. t Call `org-todo-list' to display the global todo list.
  2560. T Call `org-todo-list' to display the global todo list, select only
  2561. entries with a specific TODO keyword (the user gets a prompt).
  2562. m Call `org-tags-view' to display headlines with tags matching
  2563. a condition (the user is prompted for the condition).
  2564. M Like `m', but select only TODO entries, no ordinary headlines.
  2565. e Export views to associated files.
  2566. s Search entries for keywords.
  2567. S Search entries for keywords, only with TODO keywords.
  2568. / Multi occur across all agenda files and also files listed
  2569. in `org-agenda-text-search-extra-files'.
  2570. < Restrict agenda commands to buffer, subtree, or region.
  2571. Press several times to get the desired effect.
  2572. > Remove a previous restriction.
  2573. # List \"stuck\" projects.
  2574. ! Configure what \"stuck\" means.
  2575. C Configure custom agenda commands.
  2576. More commands can be added by configuring the variable
  2577. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2578. searches can be pre-defined in this way.
  2579. If the current buffer is in Org mode and visiting a file, you can also
  2580. first press `<' once to indicate that the agenda should be temporarily
  2581. \(until the next use of `\\[org-agenda]') restricted to the current file.
  2582. Pressing `<' twice means to restrict to the current subtree or region
  2583. \(if active)."
  2584. (interactive "P")
  2585. (catch 'exit
  2586. (let* ((org-keys keys)
  2587. (prefix-descriptions nil)
  2588. (org-agenda-buffer-name org-agenda-buffer-name)
  2589. (org-agenda-window-setup (if (equal (buffer-name)
  2590. org-agenda-buffer-name)
  2591. 'current-window
  2592. org-agenda-window-setup))
  2593. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2594. (org-agenda-custom-commands
  2595. ;; normalize different versions
  2596. (delq nil
  2597. (mapcar
  2598. (lambda (x)
  2599. (cond ((stringp (cdr x))
  2600. (push x prefix-descriptions)
  2601. nil)
  2602. ((stringp (nth 1 x)) x)
  2603. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2604. (t (cons (car x) (cons "" (cdr x))))))
  2605. org-agenda-custom-commands)))
  2606. (org-agenda-custom-commands
  2607. (org-contextualize-keys
  2608. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2609. ;; (buf (current-buffer))
  2610. (bfn (buffer-file-name (buffer-base-buffer)))
  2611. entry type org-match lprops ans) ;; key
  2612. ;; Turn off restriction unless there is an overriding one,
  2613. (unless org-agenda-overriding-restriction
  2614. (unless org-agenda-keep-restricted-file-list
  2615. ;; There is a request to keep the file list in place
  2616. (put 'org-agenda-files 'org-restrict nil))
  2617. (setq org-agenda-restrict nil)
  2618. (move-marker org-agenda-restrict-begin nil)
  2619. (move-marker org-agenda-restrict-end nil))
  2620. ;; Delete old local properties
  2621. (put 'org-agenda-redo-command 'org-lprops nil)
  2622. ;; Delete previously set last-arguments
  2623. (put 'org-agenda-redo-command 'last-args nil)
  2624. ;; Remember where this call originated
  2625. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2626. (unless org-keys
  2627. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2628. org-keys (car ans)
  2629. restriction (cdr ans)))
  2630. ;; If we have sticky agenda buffers, set a name for the buffer,
  2631. ;; depending on the invoking keys. The user may still set this
  2632. ;; as a command option, which will overwrite what we do here.
  2633. (when org-agenda-sticky
  2634. (setq org-agenda-buffer-name
  2635. (format "*Org Agenda(%s)*" org-keys)))
  2636. ;; Establish the restriction, if any
  2637. (when (and (not org-agenda-overriding-restriction) restriction)
  2638. (put 'org-agenda-files 'org-restrict (list bfn))
  2639. (cond
  2640. ((eq restriction 'region)
  2641. (setq org-agenda-restrict (current-buffer))
  2642. (move-marker org-agenda-restrict-begin (region-beginning))
  2643. (move-marker org-agenda-restrict-end (region-end)))
  2644. ((eq restriction 'subtree)
  2645. (save-excursion
  2646. (setq org-agenda-restrict (current-buffer))
  2647. (org-back-to-heading t)
  2648. (move-marker org-agenda-restrict-begin (point))
  2649. (move-marker org-agenda-restrict-end
  2650. (progn (org-end-of-subtree t)))))
  2651. ((and (eq restriction 'buffer)
  2652. (or (< 1 (point-min))
  2653. (< (point-max) (1+ (buffer-size)))))
  2654. (setq org-agenda-restrict (current-buffer))
  2655. (move-marker org-agenda-restrict-begin (point-min))
  2656. (move-marker org-agenda-restrict-end (point-max)))))
  2657. ;; For example the todo list should not need it (but does...)
  2658. (cond
  2659. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2660. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2661. (progn
  2662. ;; FIXME: Is (nth 3 entry) supposed to have access (via dynvars)
  2663. ;; to some of the local variables? There's no doc about
  2664. ;; that for `org-agenda-custom-commands'.
  2665. (setq type (nth 2 entry) org-match (eval (nth 3 entry) t)
  2666. lprops (nth 4 entry))
  2667. (when org-agenda-sticky
  2668. (setq org-agenda-buffer-name
  2669. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2670. (format "*Org Agenda(%s)*" org-keys))))
  2671. (put 'org-agenda-redo-command 'org-lprops lprops)
  2672. (cl-progv
  2673. (mapcar #'car lprops)
  2674. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  2675. (pcase type
  2676. (`agenda
  2677. (org-agenda-list arg))
  2678. (`agenda*
  2679. (org-agenda-list arg nil nil t))
  2680. (`alltodo
  2681. (org-todo-list arg))
  2682. (`search
  2683. (org-search-view arg org-match nil))
  2684. (`stuck
  2685. (org-agenda-list-stuck-projects arg))
  2686. (`tags
  2687. (org-tags-view arg org-match))
  2688. (`tags-todo
  2689. (org-tags-view '(4) org-match))
  2690. (`todo
  2691. (org-todo-list org-match))
  2692. (`tags-tree
  2693. (org-check-for-org-mode)
  2694. (org-match-sparse-tree arg org-match))
  2695. (`todo-tree
  2696. (org-check-for-org-mode)
  2697. (org-occur (concat "^" org-outline-regexp "[ \t]*"
  2698. (regexp-quote org-match) "\\>")))
  2699. (`occur-tree
  2700. (org-check-for-org-mode)
  2701. (org-occur org-match))
  2702. ((pred functionp)
  2703. (funcall type org-match))
  2704. ;; FIXME: Will signal an error since it's not `functionp'!
  2705. ((pred fboundp) (funcall type org-match))
  2706. (_ (user-error "Invalid custom agenda command type %s" type)))))
  2707. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2708. ((equal org-keys "C")
  2709. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2710. (customize-variable 'org-agenda-custom-commands))
  2711. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2712. ((equal org-keys "s") (call-interactively 'org-search-view))
  2713. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2714. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2715. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2716. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2717. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2718. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2719. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2720. (add-hook
  2721. 'post-command-hook
  2722. (lambda ()
  2723. (unless (current-message)
  2724. (let* ((m (org-agenda-get-any-marker))
  2725. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2726. (when note
  2727. (message "FLAGGING-NOTE ([?] for more info): %s"
  2728. (org-add-props
  2729. (replace-regexp-in-string
  2730. "\\\\n" "//"
  2731. (copy-sequence note))
  2732. nil 'face 'org-warning))))))
  2733. t t))
  2734. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2735. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2736. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2737. (t (user-error "Invalid agenda key"))))))
  2738. (defvar org-agenda-multi)
  2739. (defun org-agenda-append-agenda ()
  2740. "Append another agenda view to the current one.
  2741. This function allows interactive building of block agendas.
  2742. Agenda views are separated by `org-agenda-block-separator'."
  2743. (interactive)
  2744. (unless (derived-mode-p 'org-agenda-mode)
  2745. (user-error "Can only append from within agenda buffer"))
  2746. (let ((org-agenda-multi t))
  2747. (org-agenda)
  2748. (widen)
  2749. (org-agenda-finalize)
  2750. (setq buffer-read-only t)
  2751. (org-agenda-fit-window-to-buffer)))
  2752. (defun org-agenda-normalize-custom-commands (cmds)
  2753. "Normalize custom commands CMDS."
  2754. (delq nil
  2755. (mapcar
  2756. (lambda (x)
  2757. (cond ((stringp (cdr x)) nil)
  2758. ((stringp (nth 1 x)) x)
  2759. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2760. (t (cons (car x) (cons "" (cdr x))))))
  2761. cmds)))
  2762. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2763. "The user interface for selecting an agenda command."
  2764. (catch 'exit
  2765. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2766. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2767. (region-p (org-region-active-p))
  2768. (custom org-agenda-custom-commands)
  2769. (selstring "")
  2770. restriction second-time
  2771. c entry key type match prefixes rmheader header-end custom1 desc
  2772. line lines left right n n1)
  2773. (save-window-excursion
  2774. (delete-other-windows)
  2775. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2776. (erase-buffer)
  2777. (insert (eval-when-compile
  2778. (let ((header
  2779. (copy-sequence
  2780. "Press key for an agenda command:
  2781. -------------------------------- < Buffer, subtree/region restriction
  2782. a Agenda for current week or day > Remove restriction
  2783. t List of all TODO entries e Export agenda views
  2784. m Match a TAGS/PROP/TODO query T Entries with special TODO kwd
  2785. s Search for keywords M Like m, but only TODO entries
  2786. / Multi-occur S Like s, but only TODO entries
  2787. ? Find :FLAGGED: entries C Configure custom agenda commands
  2788. * Toggle sticky agenda views # List stuck projects (!=configure)
  2789. "))
  2790. (start 0))
  2791. (while (string-match
  2792. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2793. header start)
  2794. (setq start (match-end 0))
  2795. (add-text-properties (match-beginning 2) (match-end 2)
  2796. '(face bold) header))
  2797. header)))
  2798. (setq header-end (point-marker))
  2799. (while t
  2800. (setq custom1 custom)
  2801. (when (eq rmheader t)
  2802. (org-goto-line 1)
  2803. (re-search-forward ":" nil t)
  2804. (delete-region (match-end 0) (line-end-position))
  2805. (forward-char 1)
  2806. (looking-at "-+")
  2807. (delete-region (match-end 0) (line-end-position))
  2808. (move-marker header-end (match-end 0)))
  2809. (goto-char header-end)
  2810. (delete-region (point) (point-max))
  2811. ;; Produce all the lines that describe custom commands and prefixes
  2812. (setq lines nil)
  2813. (while (setq entry (pop custom1))
  2814. (setq key (car entry) desc (nth 1 entry)
  2815. type (nth 2 entry)
  2816. match (nth 3 entry))
  2817. (if (> (length key) 1)
  2818. (cl-pushnew (string-to-char key) prefixes :test #'equal)
  2819. (setq line
  2820. (format
  2821. "%-4s%-14s"
  2822. (org-add-props (copy-sequence key)
  2823. '(face bold))
  2824. (cond
  2825. ((string-match "\\S-" desc) desc)
  2826. ((eq type 'agenda) "Agenda for current week or day")
  2827. ((eq type 'agenda*) "Appointments for current week or day")
  2828. ((eq type 'alltodo) "List of all TODO entries")
  2829. ((eq type 'search) "Word search")
  2830. ((eq type 'stuck) "List of stuck projects")
  2831. ((eq type 'todo) "TODO keyword")
  2832. ((eq type 'tags) "Tags query")
  2833. ((eq type 'tags-todo) "Tags (TODO)")
  2834. ((eq type 'tags-tree) "Tags tree")
  2835. ((eq type 'todo-tree) "TODO kwd tree")
  2836. ((eq type 'occur-tree) "Occur tree")
  2837. ((functionp type) (if (symbolp type)
  2838. (symbol-name type)
  2839. "Lambda expression"))
  2840. (t "???"))))
  2841. (cond
  2842. ((not (org-string-nw-p match)) nil)
  2843. (org-agenda-menu-show-matcher
  2844. (setq line
  2845. (concat line ": "
  2846. (cond
  2847. ((stringp match)
  2848. (propertize match 'face 'org-warning))
  2849. ((listp type)
  2850. (format "set of %d commands" (length type)))))))
  2851. (t
  2852. (org-add-props line nil 'help-echo (concat "Matcher: " match))))
  2853. (push line lines)))
  2854. (setq lines (nreverse lines))
  2855. (when prefixes
  2856. (mapc (lambda (x)
  2857. (push
  2858. (format "%s %s"
  2859. (org-add-props (char-to-string x)
  2860. nil 'face 'bold)
  2861. (or (cdr (assoc (concat selstring
  2862. (char-to-string x))
  2863. prefix-descriptions))
  2864. "Prefix key"))
  2865. lines))
  2866. prefixes))
  2867. ;; Check if we should display in two columns
  2868. (if org-agenda-menu-two-columns
  2869. (progn
  2870. (setq n (length lines)
  2871. n1 (+ (/ n 2) (mod n 2))
  2872. right (nthcdr n1 lines)
  2873. left (copy-sequence lines))
  2874. (setcdr (nthcdr (1- n1) left) nil))
  2875. (setq left lines right nil))
  2876. (while left
  2877. (insert "\n" (pop left))
  2878. (when right
  2879. (if (< (current-column) 40)
  2880. (move-to-column 40 t)
  2881. (insert " "))
  2882. (insert (pop right))))
  2883. ;; Make the window the right size
  2884. (goto-char (point-min))
  2885. (if second-time
  2886. (when (not (pos-visible-in-window-p (point-max)))
  2887. (org-fit-window-to-buffer))
  2888. (setq second-time t)
  2889. (org-fit-window-to-buffer))
  2890. ;; Hint to navigation if window too small for all information
  2891. (setq header-line-format
  2892. (when (not (pos-visible-in-window-p (point-max)))
  2893. "Use C-v, M-v, C-n or C-p to navigate."))
  2894. ;; Ask for selection
  2895. (cl-loop
  2896. do (progn
  2897. (message "Press key for agenda command%s:"
  2898. (if (or restrict-ok org-agenda-overriding-restriction)
  2899. (if org-agenda-overriding-restriction
  2900. " (restriction lock active)"
  2901. (if restriction
  2902. (format " (restricted to %s)" restriction)
  2903. " (unrestricted)"))
  2904. ""))
  2905. (setq c (read-char-exclusive)))
  2906. until (not (memq c '(14 16 22 134217846)))
  2907. do (org-scroll c))
  2908. (message "")
  2909. (cond
  2910. ((assoc (char-to-string c) custom)
  2911. (setq selstring (concat selstring (char-to-string c)))
  2912. (throw 'exit (cons selstring restriction)))
  2913. ((memq c prefixes)
  2914. (setq selstring (concat selstring (char-to-string c))
  2915. prefixes nil
  2916. rmheader (or rmheader t)
  2917. custom (delq nil (mapcar
  2918. (lambda (x)
  2919. (if (or (= (length (car x)) 1)
  2920. (/= (string-to-char (car x)) c))
  2921. nil
  2922. (cons (substring (car x) 1) (cdr x))))
  2923. custom))))
  2924. ((eq c ?*)
  2925. (call-interactively 'org-toggle-sticky-agenda)
  2926. (sit-for 2))
  2927. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2928. (message "Restriction is only possible in Org buffers")
  2929. (ding) (sit-for 1))
  2930. ((eq c ?1)
  2931. (org-agenda-remove-restriction-lock 'noupdate)
  2932. (setq restriction 'buffer))
  2933. ((eq c ?0)
  2934. (org-agenda-remove-restriction-lock 'noupdate)
  2935. (setq restriction (if region-p 'region 'subtree)))
  2936. ((eq c ?<)
  2937. (org-agenda-remove-restriction-lock 'noupdate)
  2938. (setq restriction
  2939. (cond
  2940. ((eq restriction 'buffer)
  2941. (if region-p 'region 'subtree))
  2942. ((memq restriction '(subtree region))
  2943. nil)
  2944. (t 'buffer))))
  2945. ((eq c ?>)
  2946. (org-agenda-remove-restriction-lock 'noupdate)
  2947. (setq restriction nil))
  2948. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2949. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2950. ((and (> (length selstring) 0) (eq c ?\d))
  2951. (delete-window)
  2952. (org-agenda-get-restriction-and-command prefix-descriptions))
  2953. ((equal c ?q) (user-error "Abort"))
  2954. (t (user-error "Invalid key %c" c))))))))
  2955. (defun org-agenda-fit-window-to-buffer ()
  2956. "Fit the window to the buffer size."
  2957. (and (memq org-agenda-window-setup '(reorganize-frame))
  2958. (fboundp 'fit-window-to-buffer)
  2959. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2960. (= (car org-agenda-window-frame-fractions) 1.0))
  2961. (delete-other-windows)
  2962. (org-fit-window-to-buffer
  2963. nil
  2964. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2965. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2966. (defvar org-cmd nil)
  2967. (defvar org-agenda-overriding-cmd nil)
  2968. (defvar org-agenda-overriding-arguments nil)
  2969. (defvar org-agenda-overriding-cmd-arguments nil)
  2970. (defun org-let (list &rest body) ;FIXME: So many kittens are suffering here.
  2971. (declare (indent 1) (obsolete cl-progv "2021"))
  2972. (eval (cons 'let (cons list body))))
  2973. (defun org-let2 (list1 list2 &rest body) ;FIXME: Where did our karma go?
  2974. (declare (indent 2) (obsolete cl-progv "2021"))
  2975. (eval (cons 'let (cons list1 (list (cons 'let (cons list2 body)))))))
  2976. (defun org-agenda-run-series (name series)
  2977. "Run agenda NAME as a SERIES of agenda commands."
  2978. (let* ((gprops (nth 1 series))
  2979. (gvars (mapcar #'car gprops))
  2980. (gvals (mapcar (lambda (binding) (eval (cadr binding) t)) gprops)))
  2981. (cl-progv gvars gvals (org-agenda-prepare name))
  2982. ;; We need to reset agenda markers here, because when constructing a
  2983. ;; block agenda, the individual blocks do not do that.
  2984. (org-agenda-reset-markers)
  2985. (with-no-warnings
  2986. (defvar match)) ;Used via the `eval' below.
  2987. (let* ((org-agenda-multi t)
  2988. ;; FIXME: Redo should contain lists of (FUNS . ARGS) rather
  2989. ;; than expressions, so you don't need to `quote' the args
  2990. ;; and you just need to `apply' instead of `eval' when using it.
  2991. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2992. (cmds (car series))
  2993. match
  2994. org-cmd type lprops)
  2995. (while (setq org-cmd (pop cmds))
  2996. (setq type (car org-cmd))
  2997. (setq match (eval (nth 1 org-cmd) t))
  2998. (setq lprops (nth 2 org-cmd))
  2999. (let ((org-agenda-overriding-arguments
  3000. (if (eq org-agenda-overriding-cmd org-cmd)
  3001. (or org-agenda-overriding-arguments
  3002. org-agenda-overriding-cmd-arguments)))
  3003. (lvars (mapcar #'car lprops))
  3004. (lvals (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)))
  3005. (cl-progv (append gvars lvars) (append gvals lvals)
  3006. (pcase type
  3007. (`agenda
  3008. (call-interactively 'org-agenda-list))
  3009. (`agenda*
  3010. (funcall 'org-agenda-list nil nil t))
  3011. (`alltodo
  3012. (call-interactively 'org-todo-list))
  3013. (`search
  3014. (org-search-view current-prefix-arg match nil))
  3015. (`stuck
  3016. (call-interactively 'org-agenda-list-stuck-projects))
  3017. (`tags
  3018. (org-tags-view current-prefix-arg match))
  3019. (`tags-todo
  3020. (org-tags-view '(4) match))
  3021. (`todo
  3022. (org-todo-list match))
  3023. ((pred fboundp)
  3024. (funcall type match))
  3025. (_ (error "Invalid type in command series"))))))
  3026. (widen)
  3027. (let ((inhibit-read-only t))
  3028. (add-text-properties (point-min) (point-max)
  3029. `(org-series t org-series-redo-cmd ,redo)))
  3030. (setq org-agenda-redo-command redo)
  3031. (goto-char (point-min)))
  3032. (org-agenda-fit-window-to-buffer)
  3033. (cl-progv gvars gvals (org-agenda-finalize))))
  3034. (defun org-agenda--split-plist (plist)
  3035. ;; We could/should arguably use `map-keys' and `map-values'.
  3036. (let (keys vals)
  3037. (while plist
  3038. (push (pop plist) keys)
  3039. (push (pop plist) vals))
  3040. (cons (nreverse keys) (nreverse vals))))
  3041. ;;;###autoload
  3042. (defmacro org-batch-agenda (cmd-key &rest parameters)
  3043. "Run an agenda command in batch mode and send the result to STDOUT.
  3044. If CMD-KEY is a string of length 1, it is used as a key in
  3045. `org-agenda-custom-commands' and triggers this command. If it is a
  3046. longer string it is used as a tags/todo match string.
  3047. Parameters are alternating variable names and values that will be bound
  3048. before running the agenda command."
  3049. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3050. `(org--batch-agenda ,cmd-key ',vars (list ,@exps))))
  3051. (defun org--batch-agenda (cmd-key vars vals)
  3052. ;; `org-batch-agenda' is a macro because every other "parameter" is
  3053. ;; a variable name rather than an expression to evaluate. Yuck!
  3054. (cl-progv vars vals
  3055. (let (org-agenda-sticky)
  3056. (if (> (length cmd-key) 1)
  3057. (org-tags-view nil cmd-key)
  3058. (org-agenda nil cmd-key))))
  3059. (set-buffer org-agenda-buffer-name)
  3060. (princ (buffer-string)))
  3061. (defvar org-agenda-info nil)
  3062. ;;;###autoload
  3063. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  3064. "Run an agenda command in batch mode and send the result to STDOUT.
  3065. If CMD-KEY is a string of length 1, it is used as a key in
  3066. `org-agenda-custom-commands' and triggers this command. If it is a
  3067. longer string it is used as a tags/todo match string.
  3068. Parameters are alternating variable names and values that will be bound
  3069. before running the agenda command.
  3070. The output gives a line for each selected agenda item. Each
  3071. item is a list of comma-separated values, like this:
  3072. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  3073. category The category of the item
  3074. head The headline, without TODO kwd, TAGS and PRIORITY
  3075. type The type of the agenda entry, can be
  3076. todo selected in TODO match
  3077. tagsmatch selected in tags match
  3078. diary imported from diary
  3079. deadline a deadline on given date
  3080. scheduled scheduled on given date
  3081. timestamp entry has timestamp on given date
  3082. closed entry was closed on given date
  3083. upcoming-deadline warning about deadline
  3084. past-scheduled forwarded scheduled item
  3085. block entry has date block including g. date
  3086. todo The todo keyword, if any
  3087. tags All tags including inherited ones, separated by colons
  3088. date The relevant date, like 2007-2-14
  3089. time The time, like 15:00-16:50
  3090. extra String with extra planning info
  3091. priority-l The priority letter if any was given
  3092. priority-n The computed numerical priority
  3093. agenda-day The day in the agenda where this is listed"
  3094. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3095. `(org--batch-agenda-csv ,cmd-key ',vars (list ,@exps))))
  3096. (defun org--batch-agenda-csv (cmd-key vars vals)
  3097. ;; `org-batch-agenda-csv' is a macro because every other "parameter" is
  3098. ;; a variable name rather than an expression to evaluate. Yuck!
  3099. (let ((org-agenda-remove-tags t))
  3100. (cl-progv vars vals
  3101. ;; FIXME: Shouldn't this be 1 (see commit 10173ad6d610b)?
  3102. (if (> (length cmd-key) 2)
  3103. (org-tags-view nil cmd-key)
  3104. (org-agenda nil cmd-key))))
  3105. (set-buffer org-agenda-buffer-name)
  3106. (let ((lines (org-split-string (buffer-string) "\n")))
  3107. (dolist (line lines)
  3108. (when (get-text-property 0 'org-category line)
  3109. (setq org-agenda-info
  3110. (org-fix-agenda-info (text-properties-at 0 line)))
  3111. (princ
  3112. (mapconcat #'org-agenda-export-csv-mapper
  3113. '(org-category txt type todo tags date time extra
  3114. priority-letter priority agenda-day)
  3115. ","))
  3116. (princ "\n")))))
  3117. (defun org-fix-agenda-info (props)
  3118. "Make sure all properties on an agenda item have a canonical form.
  3119. This ensures the export commands can easily use it."
  3120. (let (tmp re)
  3121. (when (setq tmp (plist-get props 'tags))
  3122. (setq props (plist-put props 'tags (mapconcat #'identity tmp ":"))))
  3123. (when (setq tmp (plist-get props 'date))
  3124. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3125. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3126. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  3127. (setq tmp (calendar-date-string tmp)))
  3128. (setq props (plist-put props 'date tmp)))
  3129. (when (setq tmp (plist-get props 'day))
  3130. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3131. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3132. (setq tmp (calendar-date-string tmp)))
  3133. (setq props (plist-put props 'day tmp))
  3134. (setq props (plist-put props 'agenda-day tmp)))
  3135. (when (setq tmp (plist-get props 'txt))
  3136. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  3137. (plist-put props 'priority-letter (match-string 1 tmp))
  3138. (setq tmp (replace-match "" t t tmp)))
  3139. (when (and (setq re (plist-get props 'org-todo-regexp))
  3140. (setq re (concat "\\`\\.*" re " ?"))
  3141. (let ((case-fold-search nil)) (string-match re tmp)))
  3142. (plist-put props 'todo (match-string 1 tmp))
  3143. (setq tmp (replace-match "" t t tmp)))
  3144. (plist-put props 'txt tmp)))
  3145. props)
  3146. (defun org-agenda-export-csv-mapper (prop)
  3147. (let ((res (plist-get org-agenda-info prop)))
  3148. (setq res
  3149. (cond
  3150. ((not res) "")
  3151. ((stringp res) res)
  3152. (t (prin1-to-string res))))
  3153. (org-trim (replace-regexp-in-string "," ";" res nil t))))
  3154. ;;;###autoload
  3155. (defun org-store-agenda-views (&rest _parameters)
  3156. "Store agenda views."
  3157. (interactive)
  3158. (org--batch-store-agenda-views nil nil))
  3159. ;;;###autoload
  3160. (defmacro org-batch-store-agenda-views (&rest parameters)
  3161. "Run all custom agenda commands that have a file argument."
  3162. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3163. `(org--batch-store-agenda-views ',vars (list ,@exps))))
  3164. (defun org--batch-store-agenda-views (vars vals)
  3165. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  3166. (pop-up-frames nil)
  3167. (dir default-directory)
  3168. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  3169. (save-window-excursion
  3170. (while cmds
  3171. (setq cmd (pop cmds)
  3172. thiscmdkey (car cmd)
  3173. thiscmdcmd (cdr cmd)
  3174. match (nth 2 thiscmdcmd)
  3175. bufname (if org-agenda-sticky
  3176. (or (and (stringp match)
  3177. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  3178. (format "*Org Agenda(%s)*" thiscmdkey))
  3179. org-agenda-buffer-name)
  3180. cmd-or-set (nth 2 cmd)
  3181. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  3182. files (nth (if (listp cmd-or-set) 4 5) cmd))
  3183. (if (stringp files) (setq files (list files)))
  3184. (when files
  3185. (let* ((opts (append org-agenda-exporter-settings opts))
  3186. (vars (append (mapcar #'car opts) vars))
  3187. (vals (append (mapcar (lambda (binding) (eval (cadr binding) t))
  3188. opts)
  3189. vals)))
  3190. (cl-progv vars vals
  3191. (org-agenda nil thiscmdkey))
  3192. (set-buffer bufname)
  3193. (while files
  3194. (cl-progv vars vals
  3195. (org-agenda-write (expand-file-name (pop files) dir)
  3196. nil t bufname))))
  3197. (and (get-buffer bufname)
  3198. (kill-buffer bufname)))))))
  3199. (defvar org-agenda-current-span nil
  3200. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3201. (defun org-agenda-mark-header-line (pos)
  3202. "Mark the line at POS as an agenda structure header."
  3203. (save-excursion
  3204. (goto-char pos)
  3205. (put-text-property (line-beginning-position) (line-end-position)
  3206. 'org-agenda-structural-header t)
  3207. (when org-agenda-title-append
  3208. (put-text-property (line-beginning-position) (line-end-position)
  3209. 'org-agenda-title-append org-agenda-title-append))))
  3210. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  3211. (defvar org-agenda-write-buffer-name "Agenda View")
  3212. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  3213. "Write the current buffer (an agenda view) as a file.
  3214. Depending on the extension of the file name, plain text (.txt),
  3215. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  3216. If the extension is .ics, translate visible agenda into iCalendar
  3217. format. If the extension is .org, collect all subtrees
  3218. corresponding to the agenda entries and add them in an .org file.
  3219. With prefix argument OPEN, open the new file immediately. If
  3220. NOSETTINGS is given, do not scope the settings of
  3221. `org-agenda-exporter-settings' into the export commands. This is
  3222. used when the settings have already been scoped and we do not
  3223. wish to overrule other, higher priority settings. If
  3224. AGENDA-BUFFER-NAME is provided, use this as the buffer name for
  3225. the agenda to write."
  3226. (interactive "FWrite agenda to file: \nP")
  3227. (if (or (not (file-writable-p file))
  3228. (and (file-exists-p file)
  3229. (if (called-interactively-p 'any)
  3230. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3231. (user-error "Cannot write agenda to file %s" file))
  3232. (cl-progv
  3233. (if nosettings nil (mapcar #'car org-agenda-exporter-settings))
  3234. (if nosettings nil (mapcar (lambda (binding) (eval (cadr binding) t))
  3235. org-agenda-exporter-settings))
  3236. (save-excursion
  3237. (save-window-excursion
  3238. (let ((bs (copy-sequence (buffer-string)))
  3239. (extension (file-name-extension file))
  3240. (default-directory (file-name-directory file))
  3241. ) ;; beg content
  3242. (with-temp-buffer
  3243. (rename-buffer org-agenda-write-buffer-name t)
  3244. (set-buffer-modified-p nil)
  3245. (insert bs)
  3246. (org-agenda-remove-marked-text 'invisible 'org-filtered)
  3247. (run-hooks 'org-agenda-before-write-hook)
  3248. (cond
  3249. ((bound-and-true-p org-mobile-creating-agendas)
  3250. (org-mobile-write-agenda-for-mobile file))
  3251. ((string= "org" extension)
  3252. (let (content p m message-log-max)
  3253. (goto-char (point-min))
  3254. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3255. (goto-char p)
  3256. (setq m (get-text-property (point) 'org-hd-marker))
  3257. (when m
  3258. (push (with-current-buffer (marker-buffer m)
  3259. (goto-char m)
  3260. (org-copy-subtree 1 nil t t)
  3261. org-subtree-clip)
  3262. content)))
  3263. (find-file file)
  3264. (erase-buffer)
  3265. (dolist (s content) (org-paste-subtree 1 s))
  3266. (write-file file)
  3267. (kill-buffer (current-buffer))
  3268. (message "Org file written to %s" file)))
  3269. ((member extension '("html" "htm"))
  3270. (or (require 'htmlize nil t)
  3271. (error "Please install htmlize from https://github.com/hniksic/emacs-htmlize"))
  3272. (declare-function htmlize-buffer "htmlize" (&optional buffer))
  3273. (set-buffer (htmlize-buffer (current-buffer)))
  3274. (when org-agenda-export-html-style
  3275. ;; replace <style> section with org-agenda-export-html-style
  3276. (goto-char (point-min))
  3277. (kill-region (- (search-forward "<style") 6)
  3278. (search-forward "</style>"))
  3279. (insert org-agenda-export-html-style))
  3280. (write-file file)
  3281. (kill-buffer (current-buffer))
  3282. (message "HTML written to %s" file))
  3283. ((string= "ps" extension)
  3284. (require 'ps-print)
  3285. (ps-print-buffer-with-faces file)
  3286. (message "Postscript written to %s" file))
  3287. ((string= "pdf" extension)
  3288. (require 'ps-print)
  3289. (ps-print-buffer-with-faces
  3290. (concat (file-name-sans-extension file) ".ps"))
  3291. (call-process "ps2pdf" nil nil nil
  3292. (expand-file-name
  3293. (concat (file-name-sans-extension file) ".ps"))
  3294. (expand-file-name file))
  3295. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3296. (message "PDF written to %s" file))
  3297. ((string= "ics" extension)
  3298. (require 'ox-icalendar)
  3299. (declare-function org-icalendar-export-current-agenda
  3300. "ox-icalendar" (file))
  3301. (org-icalendar-export-current-agenda (expand-file-name file)))
  3302. (t
  3303. (let ((bs (buffer-string)))
  3304. (find-file file)
  3305. (erase-buffer)
  3306. (insert bs)
  3307. (save-buffer 0)
  3308. (kill-buffer (current-buffer))
  3309. (message "Plain text written to %s" file))))))))
  3310. (set-buffer (or agenda-bufname
  3311. ;; FIXME: I'm pretty sure called-interactively-p
  3312. ;; doesn't do what we want here!
  3313. (and (called-interactively-p 'any) (buffer-name))
  3314. org-agenda-buffer-name)))
  3315. (when open (org-open-file file)))
  3316. (defun org-agenda-remove-marked-text (property &optional value)
  3317. "Delete all text marked with VALUE of PROPERTY.
  3318. VALUE defaults to t."
  3319. (let (beg)
  3320. (setq value (or value t))
  3321. (while (setq beg (text-property-any (point-min) (point-max)
  3322. property value))
  3323. (delete-region
  3324. beg (or (next-single-property-change beg property)
  3325. (point-max))))))
  3326. (defun org-agenda-add-entry-text ()
  3327. "Add entry text to agenda lines.
  3328. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3329. entry text following headings shown in the agenda.
  3330. Drawers will be excluded, also the line with scheduling/deadline info."
  3331. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3332. (not (bound-and-true-p org-mobile-creating-agendas)))
  3333. (let (m txt)
  3334. (goto-char (point-min))
  3335. (while (not (eobp))
  3336. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3337. (beginning-of-line 2)
  3338. (setq txt (org-agenda-get-some-entry-text
  3339. m org-agenda-add-entry-text-maxlines " > "))
  3340. (end-of-line 1)
  3341. (if (string-match "\\S-" txt)
  3342. (insert "\n" txt)
  3343. (or (eobp) (forward-char 1))))))))
  3344. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3345. &rest keep)
  3346. "Extract entry text from MARKER, at most N-LINES lines.
  3347. This will ignore drawers etc, just get the text.
  3348. If INDENT is given, prefix every line with this string. If KEEP is
  3349. given, it is a list of symbols, defining stuff that should not be
  3350. removed from the entry content. Currently only `planning' is allowed here."
  3351. (let (txt drawer-re kwd-time-re ind)
  3352. (save-excursion
  3353. (with-current-buffer (marker-buffer marker)
  3354. (if (not (derived-mode-p 'org-mode))
  3355. (setq txt "")
  3356. (org-with-wide-buffer
  3357. (goto-char marker)
  3358. (end-of-line 1)
  3359. (setq txt (buffer-substring
  3360. (min (1+ (point)) (point-max))
  3361. (progn (outline-next-heading) (point)))
  3362. drawer-re org-drawer-regexp
  3363. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3364. ".*\n?"))
  3365. (with-temp-buffer
  3366. (insert txt)
  3367. (when org-agenda-add-entry-text-descriptive-links
  3368. (goto-char (point-min))
  3369. (while (org-activate-links (point-max))
  3370. (goto-char (match-end 0))))
  3371. (goto-char (point-min))
  3372. (while (re-search-forward org-link-bracket-re (point-max) t)
  3373. (set-text-properties (match-beginning 0) (match-end 0)
  3374. nil))
  3375. (goto-char (point-min))
  3376. (while (re-search-forward drawer-re nil t)
  3377. (delete-region
  3378. (match-beginning 0)
  3379. (progn (re-search-forward
  3380. "^[ \t]*:END:.*\n?" nil 'move)
  3381. (point))))
  3382. (unless (member 'planning keep)
  3383. (goto-char (point-min))
  3384. (while (re-search-forward kwd-time-re nil t)
  3385. (replace-match "")))
  3386. (goto-char (point-min))
  3387. (when org-agenda-entry-text-exclude-regexps
  3388. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3389. (while (setq re (pop re-list))
  3390. (goto-char (point-min))
  3391. (while (re-search-forward re nil t)
  3392. (replace-match "")))))
  3393. (goto-char (point-max))
  3394. (skip-chars-backward " \t\n")
  3395. (when (looking-at "[ \t\n]+\\'") (replace-match ""))
  3396. ;; find and remove min common indentation
  3397. (goto-char (point-min))
  3398. (untabify (point-min) (point-max))
  3399. (setq ind (current-indentation))
  3400. (while (not (eobp))
  3401. (unless (looking-at "[ \t]*$")
  3402. (setq ind (min ind (current-indentation))))
  3403. (beginning-of-line 2))
  3404. (goto-char (point-min))
  3405. (while (not (eobp))
  3406. (unless (looking-at "[ \t]*$")
  3407. (move-to-column ind)
  3408. (delete-region (line-beginning-position) (point)))
  3409. (beginning-of-line 2))
  3410. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3411. (goto-char (point-min))
  3412. (when indent
  3413. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3414. (replace-match indent t t)))
  3415. (goto-char (point-min))
  3416. (while (looking-at "[ \t]*\n") (replace-match ""))
  3417. (goto-char (point-max))
  3418. (when (> (org-current-line)
  3419. n-lines)
  3420. (org-goto-line (1+ n-lines))
  3421. (backward-char 1))
  3422. (setq txt (buffer-substring (point-min) (point))))))))
  3423. txt))
  3424. (defun org-check-for-org-mode ()
  3425. "Make sure current buffer is in Org mode. Error if not."
  3426. (or (derived-mode-p 'org-mode)
  3427. (error "Cannot execute Org agenda command on buffer in %s"
  3428. major-mode)))
  3429. ;;; Agenda prepare and finalize
  3430. (defvar org-agenda-multi nil) ; dynamically scoped
  3431. (defvar org-agenda-pre-window-conf nil)
  3432. (defvar org-agenda-columns-active nil)
  3433. (defvar org-agenda-name nil)
  3434. (defvar org-agenda-tag-filter nil)
  3435. (defvar org-agenda-category-filter nil)
  3436. (defvar org-agenda-regexp-filter nil)
  3437. (defvar org-agenda-effort-filter nil)
  3438. (defvar org-agenda-top-headline-filter nil)
  3439. (defvar org-agenda-represented-categories nil
  3440. "Cache for the list of all categories in the agenda.")
  3441. (defvar org-agenda-represented-tags nil
  3442. "Cache for the list of all categories in the agenda.")
  3443. (defvar org-agenda-tag-filter-preset nil
  3444. "A preset of the tags filter used for secondary agenda filtering.
  3445. This must be a list of strings, each string must be a single tag preceded
  3446. by \"+\" or \"-\".
  3447. This variable should not be set directly, but agenda custom commands can
  3448. bind it in the options section. The preset filter is a global property of
  3449. the entire agenda view. In a block agenda, it will not work reliably to
  3450. define a filter for one of the individual blocks. You need to set it in
  3451. the global options and expect it to be applied to the entire view.")
  3452. (defconst org-agenda-filter-variables
  3453. '((category . org-agenda-category-filter)
  3454. (tag . org-agenda-tag-filter)
  3455. (effort . org-agenda-effort-filter)
  3456. (regexp . org-agenda-regexp-filter))
  3457. "Alist of filter types and associated variables.")
  3458. (defun org-agenda-filter-any ()
  3459. "Is any filter active?"
  3460. (cl-some (lambda (x)
  3461. (or (symbol-value (cdr x))
  3462. (get :preset-filter x)))
  3463. org-agenda-filter-variables))
  3464. (defvar org-agenda-category-filter-preset nil
  3465. "A preset of the category filter used for secondary agenda filtering.
  3466. This must be a list of strings, each string must be a single category
  3467. preceded by \"+\" or \"-\".
  3468. This variable should not be set directly, but agenda custom commands can
  3469. bind it in the options section. The preset filter is a global property of
  3470. the entire agenda view. In a block agenda, it will not work reliably to
  3471. define a filter for one of the individual blocks. You need to set it in
  3472. the global options and expect it to be applied to the entire view.")
  3473. (defvar org-agenda-regexp-filter-preset nil
  3474. "A preset of the regexp filter used for secondary agenda filtering.
  3475. This must be a list of strings, each string must be a single regexp
  3476. preceded by \"+\" or \"-\".
  3477. This variable should not be set directly, but agenda custom commands can
  3478. bind it in the options section. The preset filter is a global property of
  3479. the entire agenda view. In a block agenda, it will not work reliably to
  3480. define a filter for one of the individual blocks. You need to set it in
  3481. the global options and expect it to be applied to the entire view.")
  3482. (defvar org-agenda-effort-filter-preset nil
  3483. "A preset of the effort condition used for secondary agenda filtering.
  3484. This must be a list of strings, each string must be a single regexp
  3485. preceded by \"+\" or \"-\".
  3486. This variable should not be set directly, but agenda custom commands can
  3487. bind it in the options section. The preset filter is a global property of
  3488. the entire agenda view. In a block agenda, it will not work reliably to
  3489. define a filter for one of the individual blocks. You need to set it in
  3490. the global options and expect it to be applied to the entire view.")
  3491. (defun org-agenda-use-sticky-p ()
  3492. "Return non-nil if an agenda buffer named
  3493. `org-agenda-buffer-name' exists and should be shown instead of
  3494. generating a new one."
  3495. (and
  3496. ;; turned off by user
  3497. org-agenda-sticky
  3498. ;; For multi-agenda buffer already exists
  3499. (not org-agenda-multi)
  3500. ;; buffer found
  3501. (get-buffer org-agenda-buffer-name)
  3502. ;; C-u parameter is same as last call
  3503. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3504. (and
  3505. (equal current-prefix-arg
  3506. org-agenda-last-prefix-arg)
  3507. ;; In case user turned stickiness on, while having existing
  3508. ;; Agenda buffer active, don't reuse that buffer, because it
  3509. ;; does not have org variables local
  3510. org-agenda-this-buffer-is-sticky))))
  3511. (defvar org-agenda-buffer-tmp-name nil)
  3512. (defun org-agenda--get-buffer-name (sticky-name)
  3513. (or org-agenda-buffer-tmp-name
  3514. (and org-agenda-doing-sticky-redo org-agenda-buffer-name)
  3515. sticky-name
  3516. "*Org Agenda*"))
  3517. (defun org-agenda-prepare-window (abuf filter-alist)
  3518. "Setup agenda buffer in the window.
  3519. ABUF is the buffer for the agenda window.
  3520. FILTER-ALIST is an alist of filters we need to apply when
  3521. `org-agenda-persistent-filter' is non-nil."
  3522. (let* ((awin (get-buffer-window abuf)) wconf)
  3523. (cond
  3524. ((equal (current-buffer) abuf) nil)
  3525. (awin (select-window awin))
  3526. ((not (setq wconf (current-window-configuration))))
  3527. ((eq org-agenda-window-setup 'current-window)
  3528. (pop-to-buffer-same-window abuf))
  3529. ((eq org-agenda-window-setup 'other-window)
  3530. (org-switch-to-buffer-other-window abuf))
  3531. ((eq org-agenda-window-setup 'other-frame)
  3532. (switch-to-buffer-other-frame abuf))
  3533. ((eq org-agenda-window-setup 'other-tab)
  3534. (if (fboundp 'switch-to-buffer-other-tab)
  3535. (switch-to-buffer-other-tab abuf)
  3536. (user-error "Your version of Emacs does not have tab bar support")))
  3537. ((eq org-agenda-window-setup 'only-window)
  3538. (delete-other-windows)
  3539. (pop-to-buffer-same-window abuf))
  3540. ((eq org-agenda-window-setup 'reorganize-frame)
  3541. (delete-other-windows)
  3542. (org-switch-to-buffer-other-window abuf)))
  3543. (setq org-agenda-tag-filter (cdr (assq 'tag filter-alist)))
  3544. (setq org-agenda-category-filter (cdr (assq 'cat filter-alist)))
  3545. (setq org-agenda-effort-filter (cdr (assq 'effort filter-alist)))
  3546. (setq org-agenda-regexp-filter (cdr (assq 're filter-alist)))
  3547. ;; Additional test in case agenda is invoked from within agenda
  3548. ;; buffer via elisp link.
  3549. (unless (equal (current-buffer) abuf)
  3550. (pop-to-buffer-same-window abuf))
  3551. (setq org-agenda-pre-window-conf
  3552. (or wconf org-agenda-pre-window-conf))))
  3553. (defun org-agenda-prepare (&optional name)
  3554. (let ((filter-alist (when org-agenda-persistent-filter
  3555. (with-current-buffer
  3556. (get-buffer-create org-agenda-buffer-name)
  3557. `((tag . ,org-agenda-tag-filter)
  3558. (re . ,org-agenda-regexp-filter)
  3559. (effort . ,org-agenda-effort-filter)
  3560. (cat . ,org-agenda-category-filter))))))
  3561. (if (org-agenda-use-sticky-p)
  3562. (progn
  3563. (put 'org-agenda-tag-filter :preset-filter nil)
  3564. (put 'org-agenda-category-filter :preset-filter nil)
  3565. (put 'org-agenda-regexp-filter :preset-filter nil)
  3566. (put 'org-agenda-effort-filter :preset-filter nil)
  3567. ;; Popup existing buffer
  3568. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3569. filter-alist)
  3570. (message "Sticky Agenda buffer, use `r' to refresh")
  3571. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3572. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3573. (setq org-todo-keywords-for-agenda nil)
  3574. (put 'org-agenda-tag-filter :preset-filter
  3575. org-agenda-tag-filter-preset)
  3576. (put 'org-agenda-category-filter :preset-filter
  3577. org-agenda-category-filter-preset)
  3578. (put 'org-agenda-regexp-filter :preset-filter
  3579. org-agenda-regexp-filter-preset)
  3580. (put 'org-agenda-effort-filter :preset-filter
  3581. org-agenda-effort-filter-preset)
  3582. (if org-agenda-multi
  3583. (progn
  3584. (setq buffer-read-only nil)
  3585. (goto-char (point-max))
  3586. (unless (or (bobp) org-agenda-compact-blocks
  3587. (not org-agenda-block-separator))
  3588. (insert "\n"
  3589. (if (stringp org-agenda-block-separator)
  3590. org-agenda-block-separator
  3591. (make-string (window-max-chars-per-line) org-agenda-block-separator))
  3592. "\n"))
  3593. (narrow-to-region (point) (point-max)))
  3594. (setq org-done-keywords-for-agenda nil)
  3595. ;; Setting any org variables that are in org-agenda-local-vars
  3596. ;; list need to be done after the prepare call
  3597. (org-agenda-prepare-window
  3598. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3599. (setq buffer-read-only nil)
  3600. (org-agenda-reset-markers)
  3601. (let ((inhibit-read-only t)) (erase-buffer))
  3602. (org-agenda-mode)
  3603. (setq org-agenda-buffer (current-buffer))
  3604. (setq org-agenda-contributing-files nil)
  3605. (setq org-agenda-columns-active nil)
  3606. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3607. (setq org-todo-keywords-for-agenda
  3608. (org-uniquify org-todo-keywords-for-agenda))
  3609. (setq org-done-keywords-for-agenda
  3610. (org-uniquify org-done-keywords-for-agenda))
  3611. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3612. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3613. (and name (not org-agenda-name)
  3614. (setq-local org-agenda-name name)))
  3615. (setq buffer-read-only nil))))
  3616. (defvar org-overriding-columns-format)
  3617. (defvar org-local-columns-format)
  3618. (defun org-agenda-finalize ()
  3619. "Finishing touch for the agenda buffer.
  3620. This function is called just before displaying the agenda. If
  3621. you want to add your own functions to the finalization of the
  3622. agenda display, configure `org-agenda-finalize-hook'."
  3623. (unless org-agenda-multi
  3624. (let ((inhibit-read-only t))
  3625. (save-excursion
  3626. (goto-char (point-min))
  3627. (save-excursion
  3628. (while (org-activate-links (point-max))
  3629. (goto-char (match-end 0))))
  3630. (unless (eq org-agenda-remove-tags t)
  3631. (org-agenda-align-tags))
  3632. (unless org-agenda-with-colors
  3633. (remove-text-properties (point-min) (point-max) '(face nil)))
  3634. (when (bound-and-true-p org-overriding-columns-format)
  3635. (setq-local org-local-columns-format
  3636. org-overriding-columns-format))
  3637. (when org-agenda-view-columns-initially
  3638. (org-agenda-columns))
  3639. (when org-agenda-fontify-priorities
  3640. (org-agenda-fontify-priorities))
  3641. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3642. (org-agenda-dim-blocked-tasks))
  3643. (org-agenda-mark-clocking-task)
  3644. (when org-agenda-entry-text-mode
  3645. (org-agenda-entry-text-hide)
  3646. (org-agenda-entry-text-show))
  3647. (when (and (featurep 'org-habit)
  3648. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3649. (org-habit-insert-consistency-graphs))
  3650. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3651. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3652. (and (listp org-agenda-show-inherited-tags)
  3653. (memq org-agenda-type org-agenda-show-inherited-tags))
  3654. (and (eq org-agenda-show-inherited-tags t)
  3655. (or (eq org-agenda-use-tag-inheritance t)
  3656. (and (listp org-agenda-use-tag-inheritance)
  3657. (not (memq org-agenda-type
  3658. org-agenda-use-tag-inheritance))))))
  3659. (let (mrk)
  3660. (save-excursion
  3661. (goto-char (point-min))
  3662. (while (equal (forward-line) 0)
  3663. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3664. (put-text-property (line-beginning-position) (line-end-position)
  3665. 'tags
  3666. (org-with-point-at mrk
  3667. (org-get-tags))))))))
  3668. (setq org-agenda-represented-tags nil
  3669. org-agenda-represented-categories nil)
  3670. (when org-agenda-top-headline-filter
  3671. (org-agenda-filter-top-headline-apply
  3672. org-agenda-top-headline-filter))
  3673. (when org-agenda-tag-filter
  3674. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3675. (when (get 'org-agenda-tag-filter :preset-filter)
  3676. (org-agenda-filter-apply
  3677. (get 'org-agenda-tag-filter :preset-filter) 'tag t))
  3678. (when org-agenda-category-filter
  3679. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3680. (when (get 'org-agenda-category-filter :preset-filter)
  3681. (org-agenda-filter-apply
  3682. (get 'org-agenda-category-filter :preset-filter) 'category))
  3683. (when org-agenda-regexp-filter
  3684. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3685. (when (get 'org-agenda-regexp-filter :preset-filter)
  3686. (org-agenda-filter-apply
  3687. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3688. (when org-agenda-effort-filter
  3689. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3690. (when (get 'org-agenda-effort-filter :preset-filter)
  3691. (org-agenda-filter-apply
  3692. (get 'org-agenda-effort-filter :preset-filter) 'effort))
  3693. (add-hook 'kill-buffer-hook #'org-agenda-reset-markers 'append 'local))
  3694. (run-hooks 'org-agenda-finalize-hook))))
  3695. (defun org-agenda-mark-clocking-task ()
  3696. "Mark the current clock entry in the agenda if it is present."
  3697. ;; We need to widen when `org-agenda-finalize' is called from
  3698. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in').
  3699. (when (bound-and-true-p org-clock-current-task)
  3700. (save-restriction
  3701. (widen)
  3702. (org-agenda-unmark-clocking-task)
  3703. (when (marker-buffer org-clock-hd-marker)
  3704. (save-excursion
  3705. (goto-char (point-min))
  3706. (let (s ov)
  3707. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3708. (goto-char s)
  3709. (when (equal (org-get-at-bol 'org-hd-marker)
  3710. org-clock-hd-marker)
  3711. (setq ov (make-overlay (line-beginning-position) (1+ (line-end-position))))
  3712. (overlay-put ov 'type 'org-agenda-clocking)
  3713. (overlay-put ov 'face 'org-agenda-clocking)
  3714. (overlay-put ov 'help-echo
  3715. "The clock is running in this item")))))))))
  3716. (defun org-agenda-unmark-clocking-task ()
  3717. "Unmark the current clocking task."
  3718. (mapc (lambda (o)
  3719. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  3720. (delete-overlay o)))
  3721. (overlays-in (point-min) (point-max))))
  3722. (defun org-agenda-fontify-priorities ()
  3723. "Make highest priority lines bold, and lowest italic."
  3724. (interactive)
  3725. (mapc (lambda (o) (when (eq (overlay-get o 'org-type) 'org-priority)
  3726. (delete-overlay o)))
  3727. (overlays-in (point-min) (point-max)))
  3728. (save-excursion
  3729. (let (b e p ov h l)
  3730. (goto-char (point-min))
  3731. (while (re-search-forward org-priority-regexp nil t)
  3732. (setq h (or (get-char-property (point) 'org-priority-highest)
  3733. org-priority-highest)
  3734. l (or (get-char-property (point) 'org-priority-lowest)
  3735. org-priority-lowest)
  3736. p (string-to-char (match-string 2))
  3737. b (match-beginning 1)
  3738. e (if (eq org-agenda-fontify-priorities 'cookies)
  3739. (1+ (match-end 2))
  3740. (line-end-position))
  3741. ov (make-overlay b e))
  3742. (overlay-put
  3743. ov 'face
  3744. (let ((special-face
  3745. (cond ((org-face-from-face-or-color
  3746. 'priority 'org-priority
  3747. (cdr (assoc p org-priority-faces))))
  3748. ((and (listp org-agenda-fontify-priorities)
  3749. (org-face-from-face-or-color
  3750. 'priority 'org-priority
  3751. (cdr (assoc p org-agenda-fontify-priorities)))))
  3752. ((equal p l) 'italic)
  3753. ((equal p h) 'bold))))
  3754. (if special-face (list special-face 'org-priority) 'org-priority)))
  3755. (overlay-put ov 'org-type 'org-priority)))))
  3756. (defvar org-depend-tag-blocked)
  3757. (defun org-agenda-dim-blocked-tasks (&optional _invisible)
  3758. "Dim currently blocked TODOs in the agenda display.
  3759. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3760. dimming them." ;FIXME: The arg isn't used, actually!
  3761. (interactive "P")
  3762. (when (called-interactively-p 'interactive)
  3763. (message "Dim or hide blocked tasks..."))
  3764. (dolist (o (overlays-in (point-min) (point-max)))
  3765. (when (eq (overlay-get o 'face) 'org-agenda-dimmed-todo-face)
  3766. (delete-overlay o)))
  3767. (save-excursion
  3768. (let ((inhibit-read-only t))
  3769. (goto-char (point-min))
  3770. (while (let ((pos (text-property-not-all
  3771. (point) (point-max) 'org-todo-blocked nil)))
  3772. (when pos (goto-char pos)))
  3773. (let* ((invisible
  3774. (eq (org-get-at-bol 'org-todo-blocked) 'invisible))
  3775. (todo-blocked
  3776. (eq (org-get-at-bol 'org-filter-type) 'todo-blocked))
  3777. (ov (make-overlay (if invisible
  3778. (line-end-position 0)
  3779. (line-beginning-position))
  3780. (line-end-position))))
  3781. (when todo-blocked
  3782. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3783. (when invisible
  3784. (org-agenda-filter-hide-line 'todo-blocked)))
  3785. (if (= (point-max) (line-end-position))
  3786. (goto-char (point-max))
  3787. (move-beginning-of-line 2)))))
  3788. (when (called-interactively-p 'interactive)
  3789. (message "Dim or hide blocked tasks...done")))
  3790. (defun org-agenda--mark-blocked-entry (entry)
  3791. "If ENTRY is blocked, mark it for fontification or invisibility.
  3792. If the header at `org-hd-marker' is blocked according to
  3793. `org-entry-blocked-p', then if `org-agenda-dim-blocked-tasks' is
  3794. `invisible' and the header is not blocked by checkboxes, set the
  3795. text property `org-todo-blocked' to `invisible', otherwise set it
  3796. to t."
  3797. (when (get-text-property 0 'todo-state entry)
  3798. (let ((entry-marker (get-text-property 0 'org-hd-marker entry))
  3799. (org-blocked-by-checkboxes nil)
  3800. ;; Necessary so that `org-entry-blocked-p' does not change
  3801. ;; the buffer.
  3802. (org-depend-tag-blocked nil))
  3803. (when entry-marker
  3804. (let ((blocked
  3805. (with-current-buffer (marker-buffer entry-marker)
  3806. (save-excursion
  3807. (goto-char entry-marker)
  3808. (org-entry-blocked-p)))))
  3809. (when blocked
  3810. (let ((really-invisible
  3811. (and (not org-blocked-by-checkboxes)
  3812. (eq org-agenda-dim-blocked-tasks 'invisible))))
  3813. (put-text-property
  3814. 0 (length entry) 'org-todo-blocked
  3815. (if really-invisible 'invisible t)
  3816. entry)
  3817. (put-text-property
  3818. 0 (length entry) 'org-filter-type 'todo-blocked entry)))))))
  3819. entry)
  3820. (defvar org-agenda-skip-function nil
  3821. "Function to be called at each match during agenda construction.
  3822. If this function returns nil, the current match should not be skipped.
  3823. Otherwise, the function must return a position from where the search
  3824. should be continued.
  3825. This may also be a Lisp form, it will be evaluated.
  3826. Never set this variable using `setq' or so, because then it will apply
  3827. to all future agenda commands. If you do want a global skipping condition,
  3828. use the option `org-agenda-skip-function-global' instead.
  3829. The correct usage for `org-agenda-skip-function' is to bind it with
  3830. `let' to scope it dynamically into the agenda-constructing command.
  3831. A good way to set it is through options in `org-agenda-custom-commands'.")
  3832. (defun org-agenda-skip (&optional element)
  3833. "Throw to `:skip' in places that should be skipped.
  3834. Also moves point to the end of the skipped region, so that search can
  3835. continue from there.
  3836. Optional argument ELEMENT contains element at point."
  3837. (let ((p (line-beginning-position)) to)
  3838. (when (or
  3839. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3840. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3841. (or (and (save-match-data (org-in-archived-heading-p nil element))
  3842. (org-end-of-subtree t element))
  3843. (and (member org-archive-tag org-file-tags)
  3844. (goto-char (point-max)))))
  3845. (and org-agenda-skip-comment-trees
  3846. (org-in-commented-heading-p nil element)
  3847. (org-end-of-subtree t element))
  3848. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3849. (org-agenda-skip-eval org-agenda-skip-function)))
  3850. (goto-char to))
  3851. (org-in-src-block-p t))
  3852. (throw :skip t))))
  3853. (defun org-agenda-skip-eval (form)
  3854. "If FORM is a function or a list, call (or eval) it and return the result.
  3855. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3856. and match data are returned to the previous state no matter what these
  3857. functions do."
  3858. (let (fp)
  3859. (and form
  3860. (or (setq fp (functionp form))
  3861. (consp form))
  3862. (save-excursion
  3863. (save-match-data
  3864. (if fp
  3865. (funcall form)
  3866. (eval form t)))))))
  3867. (defvar org-agenda-markers nil
  3868. "List of all currently active markers created by `org-agenda'.")
  3869. (defvar org-agenda-last-marker-time (float-time)
  3870. "Creation time of the last agenda marker.")
  3871. (defun org-agenda-new-marker (&optional pos)
  3872. "Return a new agenda marker.
  3873. Marker is at point, or at POS if non-nil. Org mode keeps a list
  3874. of these markers and resets them when they are no longer in use."
  3875. (let ((m (copy-marker (or pos (point)) t)))
  3876. (setq org-agenda-last-marker-time (float-time))
  3877. (if org-agenda-buffer
  3878. (with-current-buffer org-agenda-buffer
  3879. (push m org-agenda-markers))
  3880. (push m org-agenda-markers))
  3881. m))
  3882. (defun org-agenda-reset-markers ()
  3883. "Reset markers created by `org-agenda'."
  3884. (while org-agenda-markers
  3885. (move-marker (pop org-agenda-markers) nil)))
  3886. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3887. "Save relative positions of markers in region.
  3888. This check for agenda markers in all agenda buffers currently active."
  3889. (dolist (buf (buffer-list))
  3890. (with-current-buffer buf
  3891. (when (eq major-mode 'org-agenda-mode)
  3892. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3893. org-agenda-markers)))))
  3894. ;;; Entry text mode
  3895. (defun org-agenda-entry-text-show-here ()
  3896. "Add some text from the entry as context to the current line."
  3897. (let (m txt o)
  3898. (setq m (org-get-at-bol 'org-hd-marker))
  3899. (unless (marker-buffer m)
  3900. (error "No marker points to an entry here"))
  3901. (setq txt (concat "\n" (org-no-properties
  3902. (org-agenda-get-some-entry-text
  3903. m org-agenda-entry-text-maxlines
  3904. org-agenda-entry-text-leaders))))
  3905. (when (string-match "\\S-" txt)
  3906. (setq o (make-overlay (line-beginning-position) (line-end-position)))
  3907. (overlay-put o 'evaporate t)
  3908. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3909. (overlay-put o 'after-string txt))))
  3910. (defun org-agenda-entry-text-show ()
  3911. "Add entry context for all agenda lines."
  3912. (interactive)
  3913. (save-excursion
  3914. (goto-char (point-max))
  3915. (beginning-of-line 1)
  3916. (while (not (bobp))
  3917. (when (org-get-at-bol 'org-hd-marker)
  3918. (org-agenda-entry-text-show-here))
  3919. (beginning-of-line 0))))
  3920. (defun org-agenda-entry-text-hide ()
  3921. "Remove any shown entry context."
  3922. (mapc (lambda (o)
  3923. (when (eq (overlay-get o 'org-overlay-type)
  3924. 'agenda-entry-content)
  3925. (delete-overlay o)))
  3926. (overlays-in (point-min) (point-max))))
  3927. (defun org-agenda-get-day-face (date)
  3928. "Return the face DATE should be displayed with."
  3929. (cond ((and (functionp org-agenda-day-face-function)
  3930. (funcall org-agenda-day-face-function date)))
  3931. ((and (org-agenda-today-p date)
  3932. (memq (calendar-day-of-week date) org-agenda-weekend-days))
  3933. 'org-agenda-date-weekend-today)
  3934. ((org-agenda-today-p date) 'org-agenda-date-today)
  3935. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3936. 'org-agenda-date-weekend)
  3937. (t 'org-agenda-date)))
  3938. (defvar org-agenda-show-log-scoped)
  3939. ;;; Agenda Daily/Weekly
  3940. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3941. "Start day for the agenda view.
  3942. Custom commands can set this variable in the options section.
  3943. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3944. input allowed when reading a date through the Org calendar.
  3945. See the docstring of `org-read-date' for details.")
  3946. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3947. (defvar org-arg-loc nil) ; local variable
  3948. ;;;###autoload
  3949. (defun org-agenda-list (&optional arg start-day span with-hour)
  3950. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3951. The view will be for the current day or week, but from the overview buffer
  3952. you will be able to go to other days/weeks.
  3953. With a numeric prefix argument in an interactive call, the agenda will
  3954. span ARG days. Lisp programs should instead specify SPAN to change
  3955. the number of days. SPAN defaults to `org-agenda-span'.
  3956. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3957. given in `org-agenda-start-on-weekday'.
  3958. When WITH-HOUR is non-nil, only include scheduled and deadline
  3959. items if they have an hour specification like [h]h:mm."
  3960. (interactive "P")
  3961. (when org-agenda-overriding-arguments
  3962. (setq arg (car org-agenda-overriding-arguments)
  3963. start-day (nth 1 org-agenda-overriding-arguments)
  3964. span (nth 2 org-agenda-overriding-arguments)))
  3965. (when (and (integerp arg) (> arg 0))
  3966. (setq span arg arg nil))
  3967. (when (numberp span)
  3968. (unless (< 0 span)
  3969. (user-error "Agenda creation impossible for this span(=%d days)" span)))
  3970. (catch 'exit
  3971. (setq org-agenda-buffer-name
  3972. (org-agenda--get-buffer-name
  3973. (and org-agenda-sticky
  3974. (cond ((and org-keys (stringp org-match))
  3975. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3976. (org-keys
  3977. (format "*Org Agenda(%s)*" org-keys))
  3978. (t "*Org Agenda(a)*")))))
  3979. (org-agenda-prepare "Day/Week")
  3980. (setq start-day (or start-day org-agenda-start-day))
  3981. (when (stringp start-day)
  3982. ;; Convert to an absolute day number
  3983. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3984. (org-compile-prefix-format 'agenda)
  3985. (org-set-sorting-strategy 'agenda)
  3986. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
  3987. (today (org-today))
  3988. (sd (or start-day today))
  3989. (ndays (org-agenda-span-to-ndays span sd))
  3990. (org-agenda-start-on-weekday
  3991. (and (or (eq ndays 7) (eq ndays 14))
  3992. org-agenda-start-on-weekday))
  3993. (thefiles (org-agenda-files nil 'ifmode))
  3994. (files thefiles)
  3995. (start (if (or (null org-agenda-start-on-weekday)
  3996. (< ndays 7))
  3997. sd
  3998. (let* ((nt (calendar-day-of-week
  3999. (calendar-gregorian-from-absolute sd)))
  4000. (n1 org-agenda-start-on-weekday)
  4001. (d (- nt n1)))
  4002. (- sd (+ (if (< d 0) 7 0) d)))))
  4003. (day-numbers (list start))
  4004. (day-cnt 0)
  4005. (inhibit-redisplay (not debug-on-error))
  4006. (org-agenda-show-log-scoped org-agenda-show-log)
  4007. s rtn rtnall file date d start-pos end-pos todayp ;; e
  4008. clocktable-start clocktable-end) ;; filter
  4009. (setq org-agenda-redo-command
  4010. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  4011. (dotimes (_ (1- ndays))
  4012. (push (1+ (car day-numbers)) day-numbers))
  4013. (setq day-numbers (nreverse day-numbers))
  4014. (setq clocktable-start (car day-numbers)
  4015. clocktable-end (1+ (or (org-last day-numbers) 0)))
  4016. (setq-local org-starting-day (car day-numbers))
  4017. (setq-local org-arg-loc arg)
  4018. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  4019. (unless org-agenda-compact-blocks
  4020. (let* ((d1 (car day-numbers))
  4021. (d2 (org-last day-numbers))
  4022. (w1 (org-days-to-iso-week d1))
  4023. (w2 (org-days-to-iso-week d2)))
  4024. (setq s (point))
  4025. (org-agenda--insert-overriding-header
  4026. (concat (org-agenda-span-name span)
  4027. "-agenda"
  4028. (cond ((<= 350 (- d2 d1)) "")
  4029. ((= w1 w2) (format " (W%02d)" w1))
  4030. (t (format " (W%02d-W%02d)" w1 w2)))
  4031. ":\n")))
  4032. ;; Add properties if we actually inserted a header.
  4033. (when (> (point) s)
  4034. (add-text-properties s (1- (point))
  4035. (list 'face 'org-agenda-structure
  4036. 'org-date-line t))
  4037. (org-agenda-mark-header-line s)))
  4038. (while (setq d (pop day-numbers))
  4039. (setq date (calendar-gregorian-from-absolute d)
  4040. s (point))
  4041. (if (or (setq todayp (= d today))
  4042. (and (not start-pos) (= d sd)))
  4043. (setq start-pos (point))
  4044. (when (and start-pos (not end-pos))
  4045. (setq end-pos (point))))
  4046. (setq files thefiles
  4047. rtnall nil)
  4048. (while (setq file (pop files))
  4049. (catch 'nextfile
  4050. (org-check-agenda-file file)
  4051. (let ((org-agenda-entry-types org-agenda-entry-types))
  4052. ;; Starred types override non-starred equivalents
  4053. (when (member :deadline* org-agenda-entry-types)
  4054. (setq org-agenda-entry-types
  4055. (delq :deadline org-agenda-entry-types)))
  4056. (when (member :scheduled* org-agenda-entry-types)
  4057. (setq org-agenda-entry-types
  4058. (delq :scheduled org-agenda-entry-types)))
  4059. ;; Honor with-hour
  4060. (when with-hour
  4061. (when (member :deadline org-agenda-entry-types)
  4062. (setq org-agenda-entry-types
  4063. (delq :deadline org-agenda-entry-types))
  4064. (push :deadline* org-agenda-entry-types))
  4065. (when (member :scheduled org-agenda-entry-types)
  4066. (setq org-agenda-entry-types
  4067. (delq :scheduled org-agenda-entry-types))
  4068. (push :scheduled* org-agenda-entry-types)))
  4069. (unless org-agenda-include-deadlines
  4070. (setq org-agenda-entry-types
  4071. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  4072. (cond
  4073. ((memq org-agenda-show-log-scoped '(only clockcheck))
  4074. (setq rtn (org-agenda-get-day-entries
  4075. file date :closed)))
  4076. (org-agenda-show-log-scoped
  4077. (setq rtn (apply #'org-agenda-get-day-entries
  4078. file date
  4079. (append '(:closed) org-agenda-entry-types))))
  4080. (t
  4081. (setq rtn (apply #'org-agenda-get-day-entries
  4082. file date
  4083. org-agenda-entry-types)))))
  4084. (setq rtnall (append rtnall rtn)))) ;; all entries
  4085. (when org-agenda-include-diary
  4086. (let ((org-agenda-search-headline-for-time t))
  4087. (require 'diary-lib)
  4088. (setq rtn (org-get-entries-from-diary date))
  4089. (setq rtnall (append rtnall rtn))))
  4090. (when (or rtnall org-agenda-show-all-dates)
  4091. (setq day-cnt (1+ day-cnt))
  4092. (insert
  4093. (if (stringp org-agenda-format-date)
  4094. (format-time-string org-agenda-format-date
  4095. (org-time-from-absolute date))
  4096. (funcall org-agenda-format-date date))
  4097. "\n")
  4098. (put-text-property s (1- (point)) 'face
  4099. (org-agenda-get-day-face date))
  4100. (put-text-property s (1- (point)) 'org-date-line t)
  4101. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  4102. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  4103. (when todayp
  4104. (put-text-property s (1- (point)) 'org-today t))
  4105. (setq rtnall
  4106. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  4107. (when rtnall (insert ;; all entries
  4108. (org-agenda-finalize-entries rtnall 'agenda)
  4109. "\n"))
  4110. (put-text-property s (1- (point)) 'day d)
  4111. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)))
  4112. (when (and org-agenda-clockreport-mode clocktable-start)
  4113. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  4114. ;; the above line is to ensure the restricted range!
  4115. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  4116. tbl)
  4117. (setq p (org-plist-delete p :block))
  4118. (setq p (plist-put p :tstart clocktable-start))
  4119. (setq p (plist-put p :tend clocktable-end))
  4120. (setq p (plist-put p :scope 'agenda))
  4121. (setq tbl (apply #'org-clock-get-clocktable p))
  4122. (when org-agenda-clock-report-header
  4123. (insert (propertize org-agenda-clock-report-header 'face 'org-agenda-structure))
  4124. (unless (string-suffix-p "\n" org-agenda-clock-report-header)
  4125. (insert "\n")))
  4126. (insert tbl)))
  4127. (goto-char (point-min))
  4128. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4129. (unless (or (not (get-buffer-window org-agenda-buffer-name))
  4130. (and (pos-visible-in-window-p (point-min))
  4131. (pos-visible-in-window-p (point-max))))
  4132. (goto-char (1- (point-max)))
  4133. (recenter -1)
  4134. (when (not (pos-visible-in-window-p (or start-pos 1)))
  4135. (goto-char (or start-pos 1))
  4136. (recenter 1)))
  4137. (goto-char (or start-pos 1))
  4138. (add-text-properties (point-min) (point-max)
  4139. `(org-agenda-type agenda
  4140. org-last-args (,arg ,start-day ,span)
  4141. org-redo-cmd ,org-agenda-redo-command
  4142. org-series-cmd ,org-cmd))
  4143. (when (eq org-agenda-show-log-scoped 'clockcheck)
  4144. (org-agenda-show-clocking-issues))
  4145. (org-agenda-finalize)
  4146. (setq buffer-read-only t)
  4147. (message ""))))
  4148. (defun org-agenda-ndays-to-span (n)
  4149. "Return a span symbol for a span of N days, or N if none matches."
  4150. (cond ((symbolp n) n)
  4151. ((= n 1) 'day)
  4152. ((= n 7) 'week)
  4153. ((= n 14) 'fortnight)
  4154. (t n)))
  4155. (defun org-agenda-span-to-ndays (span &optional start-day)
  4156. "Return ndays from SPAN, possibly starting at START-DAY.
  4157. START-DAY is an absolute time value."
  4158. (cond ((numberp span) span)
  4159. ((eq span 'day) 1)
  4160. ((eq span 'week) 7)
  4161. ((eq span 'fortnight) 14)
  4162. ((eq span 'month)
  4163. (let ((date (calendar-gregorian-from-absolute start-day)))
  4164. (calendar-last-day-of-month (car date) (cl-caddr date))))
  4165. ((eq span 'year)
  4166. (let ((date (calendar-gregorian-from-absolute start-day)))
  4167. (if (calendar-leap-year-p (cl-caddr date)) 366 365)))))
  4168. (defun org-agenda-span-name (span)
  4169. "Return a SPAN name."
  4170. (if (null span)
  4171. ""
  4172. (if (symbolp span)
  4173. (capitalize (symbol-name span))
  4174. (format "%d days" span))))
  4175. ;;; Agenda word search
  4176. (defvar org-agenda-search-history nil)
  4177. (defvar org-search-syntax-table nil
  4178. "Special syntax table for Org search.
  4179. In this table, we have single quotes not as word constituents, to
  4180. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4181. (defvar org-mode-syntax-table) ; From org.el
  4182. (defun org-search-syntax-table ()
  4183. (unless org-search-syntax-table
  4184. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4185. (modify-syntax-entry ?' "." org-search-syntax-table)
  4186. (modify-syntax-entry ?` "." org-search-syntax-table))
  4187. org-search-syntax-table)
  4188. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4189. ;;;###autoload
  4190. (defun org-search-view (&optional todo-only string edit-at)
  4191. "Show all entries that contain a phrase or words or regular expressions.
  4192. With optional prefix argument TODO-ONLY, only consider entries that are
  4193. TODO entries. The argument STRING can be used to pass a default search
  4194. string into this function. If EDIT-AT is non-nil, it means that the
  4195. user should get a chance to edit this string, with cursor at position
  4196. EDIT-AT.
  4197. The search string can be viewed either as a phrase that should be found as
  4198. is, or it can be broken into a number of snippets, each of which must match
  4199. in a Boolean way to select an entry. The default depends on the variable
  4200. `org-agenda-search-view-always-boolean'.
  4201. Even if this is turned off (the default) you can always switch to
  4202. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4203. The default is a direct search of the whole phrase, where each space in
  4204. the search string can expand to an arbitrary amount of whitespace,
  4205. including newlines.
  4206. If using a Boolean search, the search string is split on whitespace and
  4207. each snippet is searched separately, with logical AND to select an entry.
  4208. Words prefixed with a minus must *not* occur in the entry. Words without
  4209. a prefix or prefixed with a plus must occur in the entry. Matching is
  4210. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4211. match whole words, not parts of a word) if
  4212. `org-agenda-search-view-force-full-words' is set (default is nil).
  4213. Boolean search snippets enclosed by curly braces are interpreted as
  4214. regular expressions that must or (when preceded with \"-\") must not
  4215. match in the entry. Snippets enclosed into double quotes will be taken
  4216. as a whole, to include whitespace.
  4217. - If the search string starts with an asterisk, search only in headlines.
  4218. - If (possibly after the leading star) the search string starts with an
  4219. exclamation mark, this also means to look at TODO entries only, an effect
  4220. that can also be achieved with a prefix argument.
  4221. - If (possibly after star and exclamation mark) the search string starts
  4222. with a colon, this will mean that the (non-regexp) snippets of the
  4223. Boolean search must match as full words.
  4224. This command searches the agenda files, and in addition the files
  4225. listed in `org-agenda-text-search-extra-files' unless a restriction lock
  4226. is active."
  4227. (interactive "P")
  4228. (when org-agenda-overriding-arguments
  4229. (setq todo-only (car org-agenda-overriding-arguments)
  4230. string (nth 1 org-agenda-overriding-arguments)
  4231. edit-at (nth 2 org-agenda-overriding-arguments)))
  4232. (let* ((props (list 'face nil
  4233. 'done-face 'org-agenda-done
  4234. 'org-not-done-regexp org-not-done-regexp
  4235. 'org-todo-regexp org-todo-regexp
  4236. 'org-complex-heading-regexp org-complex-heading-regexp
  4237. 'mouse-face 'highlight
  4238. 'help-echo "mouse-2 or RET jump to location"))
  4239. (full-words org-agenda-search-view-force-full-words)
  4240. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4241. regexp rtn rtnall files file pos inherited-tags
  4242. marker category level tags c neg re boolean
  4243. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4244. (unless (and (not edit-at)
  4245. (stringp string)
  4246. (string-match "\\S-" string))
  4247. (setq string (read-string
  4248. (if org-agenda-search-view-always-boolean
  4249. "[+-]Word/{Regexp} ...: "
  4250. "Phrase or [+-]Word/{Regexp} ...: ")
  4251. (cond
  4252. ((integerp edit-at) (cons string edit-at))
  4253. (edit-at string))
  4254. 'org-agenda-search-history)))
  4255. (catch 'exit
  4256. (setq org-agenda-buffer-name
  4257. (org-agenda--get-buffer-name
  4258. (and org-agenda-sticky
  4259. (if (stringp string)
  4260. (format "*Org Agenda(%s:%s)*"
  4261. (or org-keys (or (and todo-only "S") "s"))
  4262. string)
  4263. (format "*Org Agenda(%s)*"
  4264. (or (and todo-only "S") "s"))))))
  4265. (org-agenda-prepare "SEARCH")
  4266. (org-compile-prefix-format 'search)
  4267. (org-set-sorting-strategy 'search)
  4268. (setq org-agenda-redo-command
  4269. (list 'org-search-view (if todo-only t nil)
  4270. (list 'if 'current-prefix-arg nil string)))
  4271. (setq org-agenda-query-string string)
  4272. (if (equal (string-to-char string) ?*)
  4273. (setq hdl-only t
  4274. words (substring string 1))
  4275. (setq words string))
  4276. (when (equal (string-to-char words) ?!)
  4277. (setq todo-only t
  4278. words (substring words 1)))
  4279. (when (equal (string-to-char words) ?:)
  4280. (setq full-words t
  4281. words (substring words 1)))
  4282. (when (or org-agenda-search-view-always-boolean
  4283. (member (string-to-char words) '(?- ?+ ?\{)))
  4284. (setq boolean t))
  4285. (setq words (split-string words))
  4286. (let (www w)
  4287. (while (setq w (pop words))
  4288. (while (and (string-match "\\\\\\'" w) words)
  4289. (setq w (concat (substring w 0 -1) " " (pop words))))
  4290. (push w www))
  4291. (setq words (nreverse www) www nil)
  4292. (while (setq w (pop words))
  4293. (when (and (string-match "\\`[-+]?{" w)
  4294. (not (string-match "}\\'" w)))
  4295. (while (and words (not (string-match "}\\'" (car words))))
  4296. (setq w (concat w " " (pop words))))
  4297. (setq w (concat w " " (pop words))))
  4298. (push w www))
  4299. (setq words (nreverse www)))
  4300. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4301. (when boolean
  4302. (let (wds w)
  4303. (while (setq w (pop words))
  4304. (when (or (equal (substring w 0 1) "\"")
  4305. (and (> (length w) 1)
  4306. (member (substring w 0 1) '("+" "-"))
  4307. (equal (substring w 1 2) "\"")))
  4308. (while (and words (not (equal (substring w -1) "\"")))
  4309. (setq w (concat w " " (pop words)))))
  4310. (and (string-match "\\`\\([-+]?\\)\"" w)
  4311. (setq w (replace-match "\\1" nil nil w)))
  4312. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4313. (push w wds))
  4314. (setq words (nreverse wds))))
  4315. (if boolean
  4316. (mapc (lambda (w)
  4317. (setq c (string-to-char w))
  4318. (if (equal c ?-)
  4319. (setq neg t w (substring w 1))
  4320. (if (equal c ?+)
  4321. (setq neg nil w (substring w 1))
  4322. (setq neg nil)))
  4323. (if (string-match "\\`{.*}\\'" w)
  4324. (setq re (substring w 1 -1))
  4325. (if full-words
  4326. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4327. (setq re (regexp-quote (downcase w)))))
  4328. (if neg (push re regexps-) (push re regexps+)))
  4329. words)
  4330. (push (mapconcat #'regexp-quote words "\\s-+")
  4331. regexps+))
  4332. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4333. (if (not regexps+)
  4334. (setq regexp org-outline-regexp-bol)
  4335. (setq regexp (pop regexps+))
  4336. (when hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4337. regexp))))
  4338. (setq files (org-agenda-files nil 'ifmode))
  4339. ;; Add `org-agenda-text-search-extra-files' unless there is some
  4340. ;; restriction.
  4341. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4342. (pop org-agenda-text-search-extra-files)
  4343. (unless (get 'org-agenda-files 'org-restrict)
  4344. (setq files (org-add-archive-files files))))
  4345. ;; Uniquify files. However, let `org-check-agenda-file' handle
  4346. ;; non-existent ones.
  4347. (setq files (cl-remove-duplicates
  4348. (append files org-agenda-text-search-extra-files)
  4349. :test (lambda (a b)
  4350. (and (file-exists-p a)
  4351. (file-exists-p b)
  4352. (file-equal-p a b))))
  4353. rtnall nil)
  4354. (while (setq file (pop files))
  4355. (setq ee nil)
  4356. (catch 'nextfile
  4357. (org-check-agenda-file file)
  4358. (setq buffer (if (file-exists-p file)
  4359. (org-get-agenda-file-buffer file)
  4360. (error "No such file %s" file)))
  4361. (unless buffer
  4362. ;; If file does not exist, make sure an error message is sent
  4363. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4364. file))))
  4365. (with-current-buffer buffer
  4366. (with-syntax-table (org-search-syntax-table)
  4367. (unless (derived-mode-p 'org-mode)
  4368. (error "Agenda file %s is not in Org mode" file))
  4369. (let ((case-fold-search t))
  4370. (save-excursion
  4371. (save-restriction
  4372. (if (eq buffer org-agenda-restrict)
  4373. (narrow-to-region org-agenda-restrict-begin
  4374. org-agenda-restrict-end)
  4375. (widen))
  4376. (goto-char (point-min))
  4377. (unless (or (org-at-heading-p)
  4378. (outline-next-heading))
  4379. (throw 'nextfile t))
  4380. (goto-char (max (point-min) (1- (point))))
  4381. (while (re-search-forward regexp nil t)
  4382. (org-back-to-heading t)
  4383. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4384. (> (org-reduced-level (org-outline-level))
  4385. org-agenda-search-view-max-outline-level)
  4386. (forward-line -1)
  4387. (org-back-to-heading t)))
  4388. (skip-chars-forward "* ")
  4389. (setq beg (line-beginning-position)
  4390. beg1 (point)
  4391. end (progn
  4392. (outline-next-heading)
  4393. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4394. (> (org-reduced-level (org-outline-level))
  4395. org-agenda-search-view-max-outline-level)
  4396. (forward-line 1)
  4397. (outline-next-heading)))
  4398. (point)))
  4399. (catch :skip
  4400. (goto-char beg)
  4401. (org-agenda-skip)
  4402. (setq str (buffer-substring-no-properties
  4403. (line-beginning-position)
  4404. (if hdl-only (line-end-position) end)))
  4405. (mapc (lambda (wr) (when (string-match wr str)
  4406. (goto-char (1- end))
  4407. (throw :skip t)))
  4408. regexps-)
  4409. (mapc (lambda (wr) (unless (string-match wr str)
  4410. (goto-char (1- end))
  4411. (throw :skip t)))
  4412. (if todo-only
  4413. (cons (concat "^\\*+[ \t]+"
  4414. org-not-done-regexp)
  4415. regexps+)
  4416. regexps+))
  4417. (goto-char beg)
  4418. (setq marker (org-agenda-new-marker (point))
  4419. category (org-get-category)
  4420. level (make-string (org-reduced-level (org-outline-level)) ? )
  4421. inherited-tags
  4422. (or (eq org-agenda-show-inherited-tags 'always)
  4423. (and (listp org-agenda-show-inherited-tags)
  4424. (memq 'todo org-agenda-show-inherited-tags))
  4425. (and (eq org-agenda-show-inherited-tags t)
  4426. (or (eq org-agenda-use-tag-inheritance t)
  4427. (memq 'todo org-agenda-use-tag-inheritance))))
  4428. tags (org-get-tags nil (not inherited-tags))
  4429. txt (org-agenda-format-item
  4430. ""
  4431. (buffer-substring-no-properties
  4432. beg1 (line-end-position))
  4433. level category tags t))
  4434. (org-add-props txt props
  4435. 'org-marker marker 'org-hd-marker marker
  4436. 'org-todo-regexp org-todo-regexp
  4437. 'level level
  4438. 'org-complex-heading-regexp org-complex-heading-regexp
  4439. 'priority 1000
  4440. 'type "search")
  4441. (push txt ee)
  4442. (goto-char (1- end))))))))))
  4443. (setq rtn (nreverse ee))
  4444. (setq rtnall (append rtnall rtn)))
  4445. (org-agenda--insert-overriding-header
  4446. (with-temp-buffer
  4447. (insert "Search words: ")
  4448. (add-text-properties (point-min) (1- (point))
  4449. (list 'face 'org-agenda-structure))
  4450. (setq pos (point))
  4451. (insert string "\n")
  4452. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4453. (setq pos (point))
  4454. (unless org-agenda-multi
  4455. (insert (substitute-command-keys "\\<org-agenda-mode-map>\
  4456. Press `\\[org-agenda-manipulate-query-add]', \
  4457. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4458. `\\[org-agenda-manipulate-query-add-re]', \
  4459. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4460. `\\[universal-argument] \\[org-agenda-redo]' for a fresh search\n"))
  4461. (add-text-properties pos (1- (point))
  4462. (list 'face 'org-agenda-structure-secondary)))
  4463. (buffer-string)))
  4464. (org-agenda-mark-header-line (point-min))
  4465. (when rtnall
  4466. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4467. (goto-char (point-min))
  4468. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4469. (add-text-properties (point-min) (point-max)
  4470. `(org-agenda-type search
  4471. org-last-args (,todo-only ,string ,edit-at)
  4472. org-redo-cmd ,org-agenda-redo-command
  4473. org-series-cmd ,org-cmd))
  4474. (org-agenda-finalize)
  4475. (setq buffer-read-only t))))
  4476. ;;; Agenda TODO list
  4477. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4478. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4479. (concat
  4480. (if (or (equal keywords "ALL") (not keywords))
  4481. (propertize "ALL" 'face 'org-agenda-structure-filter)
  4482. (mapconcat
  4483. (lambda (kw)
  4484. (propertize kw 'face (list (org-get-todo-face kw) 'org-agenda-structure)))
  4485. (org-split-string keywords "|")
  4486. "|"))
  4487. "\n"))
  4488. (defvar org-select-this-todo-keyword nil)
  4489. (defvar org-last-arg nil)
  4490. (defvar crm-separator)
  4491. ;;;###autoload
  4492. (defun org-todo-list (&optional arg)
  4493. "Show all (not done) TODO entries from all agenda files in a single list.
  4494. The prefix arg can be used to select a specific TODO keyword and limit
  4495. the list to these. When using `\\[universal-argument]', you will be prompted
  4496. for a keyword. A numeric prefix directly selects the Nth keyword in
  4497. `org-todo-keywords-1'."
  4498. (interactive "P")
  4499. (when org-agenda-overriding-arguments
  4500. (setq arg org-agenda-overriding-arguments))
  4501. (when (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4502. (let* ((today (org-today))
  4503. (date (calendar-gregorian-from-absolute today))
  4504. (completion-ignore-case t)
  4505. kwds org-select-this-todo-keyword rtn rtnall files file pos)
  4506. (catch 'exit
  4507. (setq org-agenda-buffer-name
  4508. (org-agenda--get-buffer-name
  4509. (and org-agenda-sticky
  4510. (if (stringp org-select-this-todo-keyword)
  4511. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4512. org-select-this-todo-keyword)
  4513. (format "*Org Agenda(%s)*" (or org-keys "t"))))))
  4514. (org-agenda-prepare "TODO")
  4515. (setq kwds org-todo-keywords-for-agenda
  4516. org-select-this-todo-keyword (if (stringp arg) arg
  4517. (and (integerp arg)
  4518. (> arg 0)
  4519. (nth (1- arg) kwds))))
  4520. (when (equal arg '(4))
  4521. (setq org-select-this-todo-keyword
  4522. (mapconcat #'identity
  4523. (let ((crm-separator "|"))
  4524. (completing-read-multiple
  4525. "Keyword (or KWD1|KWD2|...): "
  4526. (mapcar #'list kwds) nil nil))
  4527. "|")))
  4528. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4529. (org-compile-prefix-format 'todo)
  4530. (org-set-sorting-strategy 'todo)
  4531. (setq org-agenda-redo-command
  4532. `(org-todo-list (or (and (numberp current-prefix-arg)
  4533. current-prefix-arg)
  4534. ,org-select-this-todo-keyword
  4535. current-prefix-arg ,arg)))
  4536. (setq files (org-agenda-files nil 'ifmode)
  4537. rtnall nil)
  4538. (while (setq file (pop files))
  4539. (catch 'nextfile
  4540. (org-check-agenda-file file)
  4541. (setq rtn (org-agenda-get-day-entries file date :todo))
  4542. (setq rtnall (append rtnall rtn))))
  4543. (org-agenda--insert-overriding-header
  4544. (with-temp-buffer
  4545. (insert "Global list of TODO items of type: ")
  4546. (add-text-properties (point-min) (1- (point))
  4547. (list 'face 'org-agenda-structure
  4548. 'short-heading
  4549. (concat "ToDo: "
  4550. (or org-select-this-todo-keyword "ALL"))))
  4551. (org-agenda-mark-header-line (point-min))
  4552. (insert (org-agenda-propertize-selected-todo-keywords
  4553. org-select-this-todo-keyword))
  4554. (setq pos (point))
  4555. (unless org-agenda-multi
  4556. (insert (substitute-command-keys "Press \
  4557. \\<org-agenda-mode-map>`N \\[org-agenda-redo]' (e.g. `0 \\[org-agenda-redo]') \
  4558. to search again: (0)[ALL]"))
  4559. (let ((n 0))
  4560. (dolist (k kwds)
  4561. (let ((s (format "(%d)%s" (cl-incf n) k)))
  4562. (when (> (+ (current-column) (string-width s) 1) (window-max-chars-per-line))
  4563. (insert "\n "))
  4564. (insert " " s))))
  4565. (insert "\n"))
  4566. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-secondary))
  4567. (buffer-string)))
  4568. (org-agenda-mark-header-line (point-min))
  4569. (when rtnall
  4570. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4571. (goto-char (point-min))
  4572. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4573. (add-text-properties (point-min) (point-max)
  4574. `(org-agenda-type todo
  4575. org-last-args ,arg
  4576. org-redo-cmd ,org-agenda-redo-command
  4577. org-series-cmd ,org-cmd))
  4578. (org-agenda-finalize)
  4579. (setq buffer-read-only t))))
  4580. ;;; Agenda tags match
  4581. ;;;###autoload
  4582. (defun org-tags-view (&optional todo-only match)
  4583. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4584. The prefix arg TODO-ONLY limits the search to TODO entries."
  4585. (interactive "P")
  4586. (when org-agenda-overriding-arguments
  4587. (setq todo-only (car org-agenda-overriding-arguments)
  4588. match (nth 1 org-agenda-overriding-arguments)))
  4589. (let* ((org-tags-match-list-sublevels
  4590. org-tags-match-list-sublevels)
  4591. (completion-ignore-case t)
  4592. (org--matcher-tags-todo-only todo-only)
  4593. rtn rtnall files file pos matcher
  4594. buffer)
  4595. (when (and (stringp match) (not (string-match "\\S-" match)))
  4596. (setq match nil))
  4597. (catch 'exit
  4598. (setq org-agenda-buffer-name
  4599. (org-agenda--get-buffer-name
  4600. (and org-agenda-sticky
  4601. (if (stringp match)
  4602. (format "*Org Agenda(%s:%s)*"
  4603. (or org-keys (or (and todo-only "M") "m"))
  4604. match)
  4605. (format "*Org Agenda(%s)*"
  4606. (or (and todo-only "M") "m"))))))
  4607. (setq matcher (org-make-tags-matcher match))
  4608. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4609. ;; expanding tags within `org-make-tags-matcher'
  4610. (org-agenda-prepare (concat "TAGS " match))
  4611. (setq match (car matcher)
  4612. matcher (cdr matcher))
  4613. (org-compile-prefix-format 'tags)
  4614. (org-set-sorting-strategy 'tags)
  4615. (setq org-agenda-query-string match)
  4616. (setq org-agenda-redo-command
  4617. (list 'org-tags-view
  4618. `(quote ,org--matcher-tags-todo-only)
  4619. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4620. (setq files (org-agenda-files nil 'ifmode)
  4621. rtnall nil)
  4622. (while (setq file (pop files))
  4623. (catch 'nextfile
  4624. (org-check-agenda-file file)
  4625. (setq buffer (if (file-exists-p file)
  4626. (org-get-agenda-file-buffer file)
  4627. (error "No such file %s" file)))
  4628. (if (not buffer)
  4629. ;; If file does not exist, error message to agenda
  4630. (setq rtn (list
  4631. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4632. rtnall (append rtnall rtn))
  4633. (with-current-buffer buffer
  4634. (unless (derived-mode-p 'org-mode)
  4635. (error "Agenda file %s is not in Org mode" file))
  4636. (save-excursion
  4637. (save-restriction
  4638. (if (eq buffer org-agenda-restrict)
  4639. (narrow-to-region org-agenda-restrict-begin
  4640. org-agenda-restrict-end)
  4641. (widen))
  4642. (setq rtn (org-scan-tags 'agenda
  4643. matcher
  4644. org--matcher-tags-todo-only))
  4645. (setq rtnall (append rtnall rtn))))))))
  4646. (org-agenda--insert-overriding-header
  4647. (with-temp-buffer
  4648. (insert "Headlines with TAGS match: ")
  4649. (add-text-properties (point-min) (1- (point))
  4650. (list 'face 'org-agenda-structure
  4651. 'short-heading
  4652. (concat "Match: " match)))
  4653. (setq pos (point))
  4654. (insert match "\n")
  4655. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4656. (setq pos (point))
  4657. (unless org-agenda-multi
  4658. (insert (substitute-command-keys
  4659. "Press \
  4660. \\<org-agenda-mode-map>`\\[universal-argument] \\[org-agenda-redo]' \
  4661. to search again\n")))
  4662. (add-text-properties pos (1- (point))
  4663. (list 'face 'org-agenda-structure-secondary))
  4664. (buffer-string)))
  4665. (org-agenda-mark-header-line (point-min))
  4666. (when rtnall
  4667. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4668. (goto-char (point-min))
  4669. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4670. (add-text-properties
  4671. (point-min) (point-max)
  4672. `(org-agenda-type tags
  4673. org-last-args (,org--matcher-tags-todo-only ,match)
  4674. org-redo-cmd ,org-agenda-redo-command
  4675. org-series-cmd ,org-cmd))
  4676. (org-agenda-finalize)
  4677. (setq buffer-read-only t))))
  4678. ;;; Agenda Finding stuck projects
  4679. (defvar org-agenda-skip-regexp nil
  4680. "Regular expression used in skipping subtrees for the agenda.
  4681. This is basically a temporary global variable that can be set and then
  4682. used by user-defined selections using `org-agenda-skip-function'.")
  4683. (defvar org-agenda-overriding-header nil
  4684. "When set during agenda, todo and tags searches it replaces the header.
  4685. If an empty string, no header will be inserted. If any other
  4686. string, it will be inserted as a header. If a function, insert
  4687. the string returned by the function as a header. If nil, a
  4688. header will be generated automatically according to the command.
  4689. This variable should not be set directly, but custom commands can
  4690. bind it in the options section.")
  4691. (defun org-agenda-skip-entry-if (&rest conditions)
  4692. "Skip entry if any of CONDITIONS is true.
  4693. See `org-agenda-skip-if' for details."
  4694. (org-agenda-skip-if nil conditions))
  4695. (defun org-agenda-skip-subtree-if (&rest conditions)
  4696. "Skip subtree if any of CONDITIONS is true.
  4697. See `org-agenda-skip-if' for details."
  4698. (org-agenda-skip-if t conditions))
  4699. (defun org-agenda-skip-if (subtree conditions)
  4700. "Check current entity for CONDITIONS.
  4701. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4702. the entry (i.e. the text before the next heading) is checked.
  4703. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4704. from different tests. Valid conditions are:
  4705. scheduled Check if there is a scheduled cookie
  4706. notscheduled Check if there is no scheduled cookie
  4707. deadline Check if there is a deadline
  4708. notdeadline Check if there is no deadline
  4709. timestamp Check if there is a timestamp (also deadline or scheduled)
  4710. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4711. regexp Check if regexp matches
  4712. notregexp Check if regexp does not match.
  4713. todo Check if TODO keyword matches
  4714. nottodo Check if TODO keyword does not match
  4715. The regexp is taken from the conditions list, it must come right after
  4716. the `regexp' or `notregexp' element.
  4717. `todo' and `nottodo' accept as an argument a list of todo
  4718. keywords, which may include \"*\" to match any todo keyword.
  4719. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4720. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4721. Instead of a list, a keyword class may be given. For example:
  4722. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4723. would skip entries that haven't been marked with any of \"DONE\"
  4724. keywords. Possible classes are: `todo', `done', `any'.
  4725. If any of these conditions is met, this function returns the end point of
  4726. the entity, causing the search to continue from there. This is a function
  4727. that can be put into `org-agenda-skip-function' for the duration of a command."
  4728. (org-back-to-heading t)
  4729. (let* (;; (beg (point))
  4730. (end (if subtree (save-excursion (org-end-of-subtree t) (point))
  4731. (org-entry-end-position)))
  4732. (planning-end (if subtree end (line-end-position 2)))
  4733. m)
  4734. (and
  4735. (or (and (memq 'scheduled conditions)
  4736. (re-search-forward org-scheduled-time-regexp planning-end t))
  4737. (and (memq 'notscheduled conditions)
  4738. (not
  4739. (save-excursion
  4740. (re-search-forward org-scheduled-time-regexp planning-end t))))
  4741. (and (memq 'deadline conditions)
  4742. (re-search-forward org-deadline-time-regexp planning-end t))
  4743. (and (memq 'notdeadline conditions)
  4744. (not
  4745. (save-excursion
  4746. (re-search-forward org-deadline-time-regexp planning-end t))))
  4747. (and (memq 'timestamp conditions)
  4748. (re-search-forward org-ts-regexp end t))
  4749. (and (memq 'nottimestamp conditions)
  4750. (not (save-excursion (re-search-forward org-ts-regexp end t))))
  4751. (and (setq m (memq 'regexp conditions))
  4752. (stringp (nth 1 m))
  4753. (re-search-forward (nth 1 m) end t))
  4754. (and (setq m (memq 'notregexp conditions))
  4755. (stringp (nth 1 m))
  4756. (not (save-excursion (re-search-forward (nth 1 m) end t))))
  4757. (and (or
  4758. (setq m (memq 'nottodo conditions))
  4759. (setq m (memq 'todo-unblocked conditions))
  4760. (setq m (memq 'nottodo-unblocked conditions))
  4761. (setq m (memq 'todo conditions)))
  4762. (org-agenda-skip-if-todo m end)))
  4763. end)))
  4764. (defun org-agenda-skip-if-todo (args end)
  4765. "Helper function for `org-agenda-skip-if', do not use it directly.
  4766. ARGS is a list with first element either `todo', `nottodo',
  4767. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4768. a list of TODO keywords, or a state symbol `todo' or `done' or
  4769. `any'."
  4770. (let ((todo-re
  4771. (concat "^\\*+[ \t]+"
  4772. (regexp-opt
  4773. (pcase args
  4774. (`(,_ todo)
  4775. (org-delete-all org-done-keywords
  4776. (copy-sequence org-todo-keywords-1)))
  4777. (`(,_ done) org-done-keywords)
  4778. (`(,_ any) org-todo-keywords-1)
  4779. (`(,_ ,(pred atom))
  4780. (error "Invalid TODO class or type: %S" args))
  4781. (`(,_ ,(pred (member "*"))) org-todo-keywords-1)
  4782. (`(,_ ,todo-list) todo-list))
  4783. 'words))))
  4784. (pcase args
  4785. (`(todo . ,_)
  4786. (let (case-fold-search) (re-search-forward todo-re end t)))
  4787. (`(nottodo . ,_)
  4788. (not (let (case-fold-search) (re-search-forward todo-re end t))))
  4789. (`(todo-unblocked . ,_)
  4790. (catch :unblocked
  4791. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4792. (when (org-entry-blocked-p) (throw :unblocked t)))
  4793. nil))
  4794. (`(nottodo-unblocked . ,_)
  4795. (catch :unblocked
  4796. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4797. (when (org-entry-blocked-p) (throw :unblocked nil)))
  4798. t))
  4799. (`(,type . ,_) (error "Unknown TODO skip type: %S" type)))))
  4800. ;;;###autoload
  4801. (defun org-agenda-list-stuck-projects (&rest _ignore)
  4802. "Create agenda view for projects that are stuck.
  4803. Stuck projects are project that have no next actions. For the definitions
  4804. of what a project is and how to check if it stuck, customize the variable
  4805. `org-stuck-projects'."
  4806. (interactive)
  4807. (let* ((org-agenda-overriding-header
  4808. (or org-agenda-overriding-header "List of stuck projects: "))
  4809. (matcher (nth 0 org-stuck-projects))
  4810. (todo (nth 1 org-stuck-projects))
  4811. (tags (nth 2 org-stuck-projects))
  4812. (gen-re (org-string-nw-p (nth 3 org-stuck-projects)))
  4813. (todo-wds
  4814. (if (not (member "*" todo)) todo
  4815. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  4816. (org-delete-all org-done-keywords-for-agenda
  4817. (copy-sequence org-todo-keywords-for-agenda))))
  4818. (todo-re (and todo
  4819. (format "^\\*+[ \t]+\\(%s\\)\\>"
  4820. (mapconcat #'identity todo-wds "\\|"))))
  4821. (tags-re (cond ((null tags) nil)
  4822. ((member "*" tags) org-tag-line-re)
  4823. (tags
  4824. (let ((other-tags (format "\\(?:%s:\\)*" org-tag-re)))
  4825. (concat org-outline-regexp-bol
  4826. ".*?[ \t]:"
  4827. other-tags
  4828. (regexp-opt tags t)
  4829. ":" other-tags "[ \t]*$")))
  4830. (t nil)))
  4831. (re-list (delq nil (list todo-re tags-re gen-re)))
  4832. (skip-re
  4833. (if (null re-list)
  4834. (error "Missing information to identify unstuck projects")
  4835. (mapconcat #'identity re-list "\\|")))
  4836. (org-agenda-skip-function
  4837. ;; Skip entry if `org-agenda-skip-regexp' matches anywhere
  4838. ;; in the subtree.
  4839. (lambda ()
  4840. (and (save-excursion
  4841. (let ((case-fold-search nil))
  4842. (re-search-forward
  4843. skip-re (save-excursion (org-end-of-subtree t)) t)))
  4844. (progn (outline-next-heading) (point))))))
  4845. (org-tags-view nil matcher)
  4846. (setq org-agenda-buffer-name (buffer-name))
  4847. (with-current-buffer org-agenda-buffer-name
  4848. (setq org-agenda-redo-command
  4849. `(org-agenda-list-stuck-projects ,current-prefix-arg))
  4850. (let ((inhibit-read-only t))
  4851. (add-text-properties
  4852. (point-min) (point-max)
  4853. `(org-redo-cmd ,org-agenda-redo-command))))))
  4854. ;;; Diary integration
  4855. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4856. (defvar diary-list-entries-hook)
  4857. (defvar diary-time-regexp)
  4858. (defvar diary-modify-entry-list-string-function)
  4859. (defvar diary-file-name-prefix)
  4860. (defvar diary-display-function)
  4861. (defun org-get-entries-from-diary (date)
  4862. "Get the (Emacs Calendar) diary entries for DATE."
  4863. (require 'diary-lib)
  4864. (declare-function diary-fancy-display "diary-lib" ())
  4865. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4866. (diary-display-function #'diary-fancy-display)
  4867. (pop-up-frames nil)
  4868. (diary-list-entries-hook
  4869. (cons 'org-diary-default-entry diary-list-entries-hook))
  4870. (diary-file-name-prefix nil) ; turn this feature off
  4871. (diary-modify-entry-list-string-function
  4872. #'org-modify-diary-entry-string)
  4873. (diary-time-regexp (concat "^" diary-time-regexp))
  4874. entries
  4875. (org-disable-agenda-to-diary t))
  4876. (save-excursion
  4877. (save-window-excursion
  4878. (diary-list-entries date 1)))
  4879. (if (not (get-buffer diary-fancy-buffer))
  4880. (setq entries nil)
  4881. (with-current-buffer diary-fancy-buffer
  4882. (setq buffer-read-only nil)
  4883. (if (zerop (buffer-size))
  4884. ;; No entries
  4885. (setq entries nil)
  4886. ;; Omit the date and other unnecessary stuff
  4887. (org-agenda-cleanup-fancy-diary)
  4888. ;; Add prefix to each line and extend the text properties
  4889. (if (zerop (buffer-size))
  4890. (setq entries nil)
  4891. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4892. (setq entries
  4893. (with-temp-buffer
  4894. (insert entries) (goto-char (point-min))
  4895. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4896. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4897. (replace-match (concat "; " (match-string 1)))))
  4898. (buffer-string)))))
  4899. (set-buffer-modified-p nil)
  4900. (kill-buffer diary-fancy-buffer)))
  4901. (when entries
  4902. (setq entries (org-split-string entries "\n"))
  4903. (setq entries
  4904. (mapcar
  4905. (lambda (x)
  4906. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4907. ;; Extend the text properties to the beginning of the line
  4908. (org-add-props x (text-properties-at (1- (length x)) x)
  4909. 'type "diary" 'date date 'face 'org-agenda-diary))
  4910. entries)))))
  4911. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4912. "Hook run when the fancy diary buffer is cleaned up.")
  4913. (defun org-agenda-cleanup-fancy-diary ()
  4914. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4915. This gets rid of the date, the underline under the date, and the
  4916. dummy entry installed by Org mode to ensure non-empty diary for
  4917. each date. It also removes lines that contain only whitespace."
  4918. (goto-char (point-min))
  4919. (if (looking-at ".*?:[ \t]*")
  4920. (progn
  4921. (replace-match "")
  4922. (re-search-forward "\n=+$" nil t)
  4923. (replace-match "")
  4924. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4925. (re-search-forward "\n=+$" nil t)
  4926. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4927. (goto-char (point-min))
  4928. (while (re-search-forward "^ +\n" nil t)
  4929. (replace-match ""))
  4930. (goto-char (point-min))
  4931. (when (re-search-forward "^Org mode dummy\n?" nil t)
  4932. (replace-match ""))
  4933. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4934. (defun org-modify-diary-entry-string (string)
  4935. "Add text properties to string, allowing Org to act on it."
  4936. (org-add-props string nil
  4937. 'mouse-face 'highlight
  4938. 'help-echo (if buffer-file-name
  4939. (format "mouse-2 or RET jump to diary file %s"
  4940. (abbreviate-file-name buffer-file-name))
  4941. "")
  4942. 'org-agenda-diary-link t
  4943. 'org-marker (org-agenda-new-marker (line-beginning-position))))
  4944. (defun org-diary-default-entry ()
  4945. "Add a dummy entry to the diary.
  4946. Needed to avoid empty dates which mess up holiday display."
  4947. ;; Catch the error if dealing with the new add-to-diary-alist
  4948. (when org-disable-agenda-to-diary
  4949. (diary-add-to-list original-date "Org mode dummy" "")))
  4950. (defvar org-diary-last-run-time nil)
  4951. ;;;###autoload
  4952. (defun org-diary (&rest args)
  4953. "Return diary information from org files.
  4954. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4955. It accesses org files and extracts information from those files to be
  4956. listed in the diary. The function accepts arguments specifying what
  4957. items should be listed. For a list of arguments allowed here, see the
  4958. variable `org-agenda-entry-types'.
  4959. The call in the diary file should look like this:
  4960. &%%(org-diary) ~/path/to/some/orgfile.org
  4961. Use a separate line for each org file to check. Or, if you omit the file name,
  4962. all files listed in `org-agenda-files' will be checked automatically:
  4963. &%%(org-diary)
  4964. If you don't give any arguments (as in the example above), the default value
  4965. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4966. So the example above may also be written as
  4967. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4968. The function expects the lisp variables `entry' and `date' to be provided
  4969. by the caller, because this is how the calendar works. Don't use this
  4970. function from a program - use `org-agenda-get-day-entries' instead."
  4971. (with-no-warnings (defvar date) (defvar entry))
  4972. (when (> (- (float-time)
  4973. org-agenda-last-marker-time)
  4974. 5)
  4975. ;; I am not sure if this works with sticky agendas, because the marker
  4976. ;; list is then no longer a global variable.
  4977. (org-agenda-reset-markers))
  4978. (org-compile-prefix-format 'agenda)
  4979. (org-set-sorting-strategy 'agenda)
  4980. (setq args (or args org-agenda-entry-types))
  4981. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4982. (list entry)
  4983. (org-agenda-files t)))
  4984. (time (float-time))
  4985. file rtn results)
  4986. (when (or (not org-diary-last-run-time)
  4987. (> (- time
  4988. org-diary-last-run-time)
  4989. 3))
  4990. (org-agenda-prepare-buffers files))
  4991. (setq org-diary-last-run-time time)
  4992. ;; If this is called during org-agenda, don't return any entries to
  4993. ;; the calendar. Org Agenda will list these entries itself.
  4994. (when org-disable-agenda-to-diary (setq files nil))
  4995. (while (setq file (pop files))
  4996. (setq rtn (apply #'org-agenda-get-day-entries file date args))
  4997. (setq results (append results rtn)))
  4998. (when results
  4999. (setq results
  5000. (mapcar (lambda (i) (replace-regexp-in-string
  5001. org-link-bracket-re "\\2" i))
  5002. results))
  5003. (concat (org-agenda-finalize-entries results) "\n"))))
  5004. ;;; Agenda entry finders
  5005. (defun org-agenda--timestamp-to-absolute (&rest args)
  5006. "Call `org-time-string-to-absolute' with ARGS.
  5007. However, throw `:skip' whenever an error is raised."
  5008. (condition-case e
  5009. (apply #'org-time-string-to-absolute args)
  5010. (org-diary-sexp-no-match (throw :skip nil))
  5011. (error
  5012. (message "%s; Skipping entry" (error-message-string e))
  5013. (throw :skip nil))))
  5014. (defun org-agenda-get-day-entries (file date &rest args)
  5015. "Does the work for `org-diary' and `org-agenda'.
  5016. FILE is the path to a file to be checked for entries. DATE is date like
  5017. the one returned by `calendar-current-date'. ARGS are symbols indicating
  5018. which kind of entries should be extracted. For details about these, see
  5019. the documentation of `org-diary'."
  5020. (let* ((org-startup-folded nil)
  5021. (org-startup-align-all-tables nil)
  5022. (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
  5023. (error "No such file %s" file))))
  5024. (if (not buffer)
  5025. ;; If file does not exist, signal it in diary nonetheless.
  5026. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  5027. (with-current-buffer buffer
  5028. (unless (derived-mode-p 'org-mode)
  5029. (error "Agenda file %s is not in Org mode" file))
  5030. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  5031. (setf org-agenda-current-date date)
  5032. (save-excursion
  5033. (save-restriction
  5034. (if (eq buffer org-agenda-restrict)
  5035. (narrow-to-region org-agenda-restrict-begin
  5036. org-agenda-restrict-end)
  5037. (widen))
  5038. ;; Rationalize ARGS. Also make sure `:deadline' comes
  5039. ;; first in order to populate DEADLINES before passing it.
  5040. ;;
  5041. ;; We use `delq' since `org-uniquify' duplicates ARGS,
  5042. ;; guarding us from modifying `org-agenda-entry-types'.
  5043. (setf args (org-uniquify (or args org-agenda-entry-types)))
  5044. (when (and (memq :scheduled args) (memq :scheduled* args))
  5045. (setf args (delq :scheduled* args)))
  5046. (cond
  5047. ((memq :deadline args)
  5048. (setf args (cons :deadline
  5049. (delq :deadline (delq :deadline* args)))))
  5050. ((memq :deadline* args)
  5051. (setf args (cons :deadline* (delq :deadline* args)))))
  5052. ;; Collect list of headlines. Return them flattened.
  5053. (let ((case-fold-search nil) results deadlines)
  5054. (org-dlet
  5055. ((date date))
  5056. (dolist (arg args (apply #'nconc (nreverse results)))
  5057. (pcase arg
  5058. ((and :todo (guard (org-agenda-today-p date)))
  5059. (push (org-agenda-get-todos) results))
  5060. (:timestamp
  5061. (push (org-agenda-get-blocks) results)
  5062. (push (org-agenda-get-timestamps deadlines) results))
  5063. (:sexp
  5064. (push (org-agenda-get-sexps) results))
  5065. (:scheduled
  5066. (push (org-agenda-get-scheduled deadlines) results))
  5067. (:scheduled*
  5068. (push (org-agenda-get-scheduled deadlines t) results))
  5069. (:closed
  5070. (push (org-agenda-get-progress) results))
  5071. (:deadline
  5072. (setf deadlines (org-agenda-get-deadlines))
  5073. (push deadlines results))
  5074. (:deadline*
  5075. (setf deadlines (org-agenda-get-deadlines t))
  5076. (push deadlines results))))))))))))
  5077. (defsubst org-em (x y list)
  5078. "Is X or Y a member of LIST?"
  5079. (or (memq x list) (memq y list)))
  5080. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  5081. (defvar org-agenda-sorting-strategy-selected nil)
  5082. (defun org-agenda-entry-get-agenda-timestamp (pom)
  5083. "Retrieve timestamp information for sorting agenda views.
  5084. Given a point or marker POM, returns a cons cell of the timestamp
  5085. and the timestamp type relevant for the sorting strategy in
  5086. `org-agenda-sorting-strategy-selected'."
  5087. (let (ts ts-date-type)
  5088. (save-match-data
  5089. (cond ((org-em 'scheduled-up 'scheduled-down
  5090. org-agenda-sorting-strategy-selected)
  5091. (setq ts (org-entry-get pom "SCHEDULED")
  5092. ts-date-type " scheduled"))
  5093. ((org-em 'deadline-up 'deadline-down
  5094. org-agenda-sorting-strategy-selected)
  5095. (setq ts (org-entry-get pom "DEADLINE")
  5096. ts-date-type " deadline"))
  5097. ((org-em 'ts-up 'ts-down
  5098. org-agenda-sorting-strategy-selected)
  5099. (setq ts (org-entry-get pom "TIMESTAMP")
  5100. ts-date-type " timestamp"))
  5101. ((org-em 'tsia-up 'tsia-down
  5102. org-agenda-sorting-strategy-selected)
  5103. (setq ts (org-entry-get pom "TIMESTAMP_IA")
  5104. ts-date-type " timestamp_ia"))
  5105. ((org-em 'timestamp-up 'timestamp-down
  5106. org-agenda-sorting-strategy-selected)
  5107. (setq ts (or (org-entry-get pom "SCHEDULED")
  5108. (org-entry-get pom "DEADLINE")
  5109. (org-entry-get pom "TIMESTAMP")
  5110. (org-entry-get pom "TIMESTAMP_IA"))
  5111. ts-date-type ""))
  5112. (t (setq ts-date-type "")))
  5113. (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
  5114. ts-date-type))))
  5115. (defun org-agenda-get-todos ()
  5116. "Return the TODO information for agenda display."
  5117. (let* ((props (list 'face nil
  5118. 'done-face 'org-agenda-done
  5119. 'org-not-done-regexp org-not-done-regexp
  5120. 'org-todo-regexp org-todo-regexp
  5121. 'org-complex-heading-regexp org-complex-heading-regexp
  5122. 'mouse-face 'highlight
  5123. 'help-echo
  5124. (format "mouse-2 or RET jump to org file %s"
  5125. (abbreviate-file-name buffer-file-name))))
  5126. (case-fold-search nil)
  5127. (regexp (format org-heading-keyword-regexp-format
  5128. (cond
  5129. ((and org-select-this-todo-keyword
  5130. (equal org-select-this-todo-keyword "*"))
  5131. org-todo-regexp)
  5132. (org-select-this-todo-keyword
  5133. (concat "\\("
  5134. (mapconcat #'identity
  5135. (org-split-string
  5136. org-select-this-todo-keyword
  5137. "|")
  5138. "\\|")
  5139. "\\)"))
  5140. (t org-not-done-regexp))))
  5141. marker priority category level tags todo-state
  5142. ts-date ts-date-type ts-date-pair
  5143. ee txt beg end inherited-tags todo-state-end-pos
  5144. effort effort-minutes)
  5145. (goto-char (point-min))
  5146. (while (re-search-forward regexp nil t)
  5147. (catch :skip
  5148. (save-match-data
  5149. (beginning-of-line)
  5150. (org-agenda-skip)
  5151. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  5152. (unless (and (setq todo-state (org-get-todo-state))
  5153. (setq todo-state-end-pos (match-end 2)))
  5154. (goto-char end)
  5155. (throw :skip nil))
  5156. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  5157. (goto-char (1+ beg))
  5158. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  5159. (throw :skip nil)))
  5160. (goto-char (match-beginning 2))
  5161. (setq marker (org-agenda-new-marker (match-beginning 0))
  5162. category (org-get-category)
  5163. effort (save-match-data (or (get-text-property (point) 'effort)
  5164. (org-entry-get (point) org-effort-property)))
  5165. effort-minutes (when effort (save-match-data (org-duration-to-minutes effort)))
  5166. ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
  5167. ts-date (car ts-date-pair)
  5168. ts-date-type (cdr ts-date-pair)
  5169. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  5170. inherited-tags
  5171. (or (eq org-agenda-show-inherited-tags 'always)
  5172. (and (listp org-agenda-show-inherited-tags)
  5173. (memq 'todo org-agenda-show-inherited-tags))
  5174. (and (eq org-agenda-show-inherited-tags t)
  5175. (or (eq org-agenda-use-tag-inheritance t)
  5176. (memq 'todo org-agenda-use-tag-inheritance))))
  5177. tags (org-get-tags nil (not inherited-tags))
  5178. level (make-string (org-reduced-level (org-outline-level)) ? )
  5179. txt (org-agenda-format-item ""
  5180. (org-add-props txt nil
  5181. 'effort effort
  5182. 'effort-minutes effort-minutes)
  5183. level category tags t)
  5184. priority (1+ (org-get-priority txt)))
  5185. (org-add-props txt props
  5186. 'org-marker marker 'org-hd-marker marker
  5187. 'priority priority
  5188. 'effort effort 'effort-minutes effort-minutes
  5189. 'level level
  5190. 'ts-date ts-date
  5191. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  5192. (push txt ee)
  5193. (if org-agenda-todo-list-sublevels
  5194. (goto-char todo-state-end-pos)
  5195. (org-end-of-subtree 'invisible))))
  5196. (nreverse ee)))
  5197. (defun org-agenda-todo-custom-ignore-p (time n)
  5198. "Check whether timestamp is farther away than n number of days.
  5199. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5200. `org-agenda-todo-ignore-scheduled' or
  5201. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5202. (let ((days (org-time-stamp-to-now
  5203. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5204. (if (>= n 0)
  5205. (>= days n)
  5206. (<= days n))))
  5207. ;;;###autoload
  5208. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5209. (&optional end)
  5210. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5211. (when (or org-agenda-todo-ignore-with-date
  5212. org-agenda-todo-ignore-scheduled
  5213. org-agenda-todo-ignore-deadlines
  5214. org-agenda-todo-ignore-timestamp)
  5215. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5216. (save-excursion
  5217. (or (and org-agenda-todo-ignore-with-date
  5218. (re-search-forward org-ts-regexp end t))
  5219. (and org-agenda-todo-ignore-scheduled
  5220. (re-search-forward org-scheduled-time-regexp end t)
  5221. (cond
  5222. ((eq org-agenda-todo-ignore-scheduled 'future)
  5223. (> (org-time-stamp-to-now
  5224. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5225. 0))
  5226. ((eq org-agenda-todo-ignore-scheduled 'past)
  5227. (<= (org-time-stamp-to-now
  5228. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5229. 0))
  5230. ((numberp org-agenda-todo-ignore-scheduled)
  5231. (org-agenda-todo-custom-ignore-p
  5232. (match-string 1) org-agenda-todo-ignore-scheduled))
  5233. (t)))
  5234. (and org-agenda-todo-ignore-deadlines
  5235. (re-search-forward org-deadline-time-regexp end t)
  5236. (cond
  5237. ((eq org-agenda-todo-ignore-deadlines 'all) t)
  5238. ((eq org-agenda-todo-ignore-deadlines 'far)
  5239. (not (org-deadline-close-p (match-string 1))))
  5240. ((eq org-agenda-todo-ignore-deadlines 'future)
  5241. (> (org-time-stamp-to-now
  5242. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5243. 0))
  5244. ((eq org-agenda-todo-ignore-deadlines 'past)
  5245. (<= (org-time-stamp-to-now
  5246. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5247. 0))
  5248. ((numberp org-agenda-todo-ignore-deadlines)
  5249. (org-agenda-todo-custom-ignore-p
  5250. (match-string 1) org-agenda-todo-ignore-deadlines))
  5251. (t (org-deadline-close-p (match-string 1)))))
  5252. (and org-agenda-todo-ignore-timestamp
  5253. (let ((buffer (current-buffer))
  5254. (regexp
  5255. (concat
  5256. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5257. (start (point)))
  5258. ;; Copy current buffer into a temporary one
  5259. (with-temp-buffer
  5260. (insert-buffer-substring buffer start end)
  5261. (goto-char (point-min))
  5262. ;; Delete SCHEDULED and DEADLINE items
  5263. (while (re-search-forward regexp end t)
  5264. (delete-region (match-beginning 0) (match-end 0)))
  5265. (goto-char (point-min))
  5266. ;; No search for timestamp left
  5267. (when (re-search-forward org-ts-regexp nil t)
  5268. (cond
  5269. ((eq org-agenda-todo-ignore-timestamp 'future)
  5270. (> (org-time-stamp-to-now
  5271. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5272. 0))
  5273. ((eq org-agenda-todo-ignore-timestamp 'past)
  5274. (<= (org-time-stamp-to-now
  5275. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5276. 0))
  5277. ((numberp org-agenda-todo-ignore-timestamp)
  5278. (org-agenda-todo-custom-ignore-p
  5279. (match-string 1) org-agenda-todo-ignore-timestamp))
  5280. (t))))))))))
  5281. (defun org-agenda-get-timestamps (&optional deadlines)
  5282. "Return the date stamp information for agenda display.
  5283. Optional argument DEADLINES is a list of deadline items to be
  5284. displayed in agenda view."
  5285. (with-no-warnings (defvar date))
  5286. (let* ((props (list 'face 'org-agenda-calendar-event
  5287. 'org-not-done-regexp org-not-done-regexp
  5288. 'org-todo-regexp org-todo-regexp
  5289. 'org-complex-heading-regexp org-complex-heading-regexp
  5290. 'mouse-face 'highlight
  5291. 'help-echo
  5292. (format "mouse-2 or RET jump to Org file %s"
  5293. (abbreviate-file-name buffer-file-name))))
  5294. (current (calendar-absolute-from-gregorian date))
  5295. (today (org-today))
  5296. (deadline-position-alist
  5297. (mapcar (lambda (d)
  5298. (let ((m (get-text-property 0 'org-hd-marker d)))
  5299. (and m (marker-position m))))
  5300. deadlines))
  5301. ;; Match time-stamps set to current date, time-stamps with
  5302. ;; a repeater, and S-exp time-stamps.
  5303. (regexp
  5304. (concat
  5305. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5306. (regexp-quote
  5307. (substring
  5308. (format-time-string
  5309. (car org-time-stamp-formats)
  5310. (org-encode-time ; DATE bound by calendar
  5311. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5312. 1 11))
  5313. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5314. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5315. timestamp-items)
  5316. (goto-char (point-min))
  5317. (while (re-search-forward regexp nil t)
  5318. ;; Skip date ranges, scheduled and deadlines, which are handled
  5319. ;; specially. Also skip time-stamps before first headline as
  5320. ;; there would be no entry to add to the agenda. Eventually,
  5321. ;; ignore clock entries.
  5322. (catch :skip
  5323. (save-match-data
  5324. (when (or (org-at-date-range-p)
  5325. (org-at-planning-p)
  5326. (org-before-first-heading-p)
  5327. (and org-agenda-include-inactive-timestamps
  5328. (org-at-clock-log-p))
  5329. (not (org-at-timestamp-p 'agenda)))
  5330. (throw :skip nil))
  5331. (org-agenda-skip))
  5332. (let* ((pos (match-beginning 0))
  5333. (repeat (match-string 1))
  5334. (sexp-entry (match-string 3))
  5335. (time-stamp (if (or repeat sexp-entry) (match-string 0)
  5336. (save-excursion
  5337. (goto-char pos)
  5338. (looking-at org-ts-regexp-both)
  5339. (match-string 0))))
  5340. (todo-state (org-get-todo-state))
  5341. (warntime (get-text-property (point) 'org-appt-warntime))
  5342. (done? (member todo-state org-done-keywords)))
  5343. ;; Possibly skip done tasks.
  5344. (when (and done? org-agenda-skip-timestamp-if-done)
  5345. (throw :skip t))
  5346. ;; S-exp entry doesn't match current day: skip it.
  5347. (when (and sexp-entry (not (org-diary-sexp-entry sexp-entry "" date)))
  5348. (throw :skip nil))
  5349. (when repeat
  5350. (let* ((past
  5351. ;; A repeating time stamp is shown at its base
  5352. ;; date and every repeated date up to TODAY. If
  5353. ;; `org-agenda-prefer-last-repeat' is non-nil,
  5354. ;; however, only the last repeat before today
  5355. ;; (inclusive) is shown.
  5356. (org-agenda--timestamp-to-absolute
  5357. repeat
  5358. (if (or (> current today)
  5359. (eq org-agenda-prefer-last-repeat t)
  5360. (member todo-state org-agenda-prefer-last-repeat))
  5361. today
  5362. current)
  5363. 'past (current-buffer) pos))
  5364. (future
  5365. ;; Display every repeated date past TODAY
  5366. ;; (exclusive) unless
  5367. ;; `org-agenda-show-future-repeats' is nil. If
  5368. ;; this variable is set to `next', only display
  5369. ;; the first repeated date after TODAY
  5370. ;; (exclusive).
  5371. (cond
  5372. ((<= current today) past)
  5373. ((not org-agenda-show-future-repeats) past)
  5374. (t
  5375. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5376. (1+ today)
  5377. current)))
  5378. (org-agenda--timestamp-to-absolute
  5379. repeat base 'future (current-buffer) pos))))))
  5380. (when (and (/= current past) (/= current future))
  5381. (throw :skip nil))))
  5382. (save-excursion
  5383. (re-search-backward org-outline-regexp-bol nil t)
  5384. ;; Possibly skip time-stamp when a deadline is set.
  5385. (when (and org-agenda-skip-timestamp-if-deadline-is-shown
  5386. (assq (point) deadline-position-alist))
  5387. (throw :skip nil))
  5388. (let* ((category (org-get-category pos))
  5389. (effort (org-entry-get pos org-effort-property))
  5390. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5391. (inherited-tags
  5392. (or (eq org-agenda-show-inherited-tags 'always)
  5393. (and (consp org-agenda-show-inherited-tags)
  5394. (memq 'agenda org-agenda-show-inherited-tags))
  5395. (and (eq org-agenda-show-inherited-tags t)
  5396. (or (eq org-agenda-use-tag-inheritance t)
  5397. (memq 'agenda
  5398. org-agenda-use-tag-inheritance)))))
  5399. (tags (org-get-tags nil (not inherited-tags)))
  5400. (level (make-string (org-reduced-level (org-outline-level))
  5401. ?\s))
  5402. (head (and (looking-at "\\*+[ \t]+\\(.*\\)")
  5403. (match-string 1)))
  5404. (inactive? (= (char-after pos) ?\[))
  5405. (habit? (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5406. (item
  5407. (org-agenda-format-item
  5408. (and inactive? org-agenda-inactive-leader)
  5409. (org-add-props head nil
  5410. 'effort effort
  5411. 'effort-minutes effort-minutes)
  5412. level category tags time-stamp org-ts-regexp habit?)))
  5413. (org-add-props item props
  5414. 'priority (if habit?
  5415. (org-habit-get-priority (org-habit-parse-todo))
  5416. (org-get-priority item))
  5417. 'org-marker (org-agenda-new-marker pos)
  5418. 'org-hd-marker (org-agenda-new-marker)
  5419. 'date date
  5420. 'level level
  5421. 'effort effort 'effort-minutes effort-minutes
  5422. 'ts-date (if repeat (org-agenda--timestamp-to-absolute repeat)
  5423. current)
  5424. 'todo-state todo-state
  5425. 'warntime warntime
  5426. 'type "timestamp")
  5427. (push item timestamp-items))))
  5428. (when org-agenda-skip-additional-timestamps-same-entry
  5429. (outline-next-heading))))
  5430. (nreverse timestamp-items)))
  5431. (defun org-agenda-get-sexps ()
  5432. "Return the sexp information for agenda display."
  5433. (require 'diary-lib)
  5434. (with-no-warnings (defvar date) (defvar entry))
  5435. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5436. 'mouse-face 'highlight
  5437. 'help-echo
  5438. (format "mouse-2 or RET jump to org file %s"
  5439. (abbreviate-file-name buffer-file-name))))
  5440. (regexp "^&?%%(")
  5441. ;; FIXME: Is this `entry' binding intended to be dynamic,
  5442. ;; so as to "hide" any current binding for it?
  5443. marker category extra level ee txt tags entry
  5444. result beg b sexp sexp-entry todo-state warntime inherited-tags
  5445. effort effort-minutes)
  5446. (goto-char (point-min))
  5447. (while (re-search-forward regexp nil t)
  5448. (catch :skip
  5449. (org-agenda-skip (org-element-lineage (org-element-at-point) '(headline inlinetask) 'with-self))
  5450. (setq beg (match-beginning 0))
  5451. (goto-char (1- (match-end 0)))
  5452. (setq b (point))
  5453. (forward-sexp 1)
  5454. (setq sexp (buffer-substring b (point)))
  5455. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5456. (org-trim (match-string 1))
  5457. ""))
  5458. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5459. (when result
  5460. (setq marker (org-agenda-new-marker beg)
  5461. level (make-string (org-reduced-level (org-outline-level)) ? )
  5462. category (org-get-category beg)
  5463. effort (save-match-data (or (get-text-property (point) 'effort)
  5464. (org-entry-get (point) org-effort-property)))
  5465. inherited-tags
  5466. (or (eq org-agenda-show-inherited-tags 'always)
  5467. (and (listp org-agenda-show-inherited-tags)
  5468. (memq 'agenda org-agenda-show-inherited-tags))
  5469. (and (eq org-agenda-show-inherited-tags t)
  5470. (or (eq org-agenda-use-tag-inheritance t)
  5471. (memq 'agenda org-agenda-use-tag-inheritance))))
  5472. tags (org-get-tags nil (not inherited-tags))
  5473. todo-state (org-get-todo-state)
  5474. warntime (get-text-property (point) 'org-appt-warntime)
  5475. extra nil)
  5476. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5477. (dolist (r (if (stringp result)
  5478. (list result)
  5479. result)) ;; we expect a list here
  5480. (when (and org-agenda-diary-sexp-prefix
  5481. (string-match org-agenda-diary-sexp-prefix r))
  5482. (setq extra (match-string 0 r)
  5483. r (replace-match "" nil nil r)))
  5484. (if (string-match "\\S-" r)
  5485. (setq txt r)
  5486. (setq txt "SEXP entry returned empty string"))
  5487. (setq txt (org-agenda-format-item extra
  5488. (org-add-props txt nil
  5489. 'effort effort
  5490. 'effort-minutes effort-minutes)
  5491. level category tags 'time))
  5492. (org-add-props txt props 'org-marker marker
  5493. 'date date 'todo-state todo-state
  5494. 'effort effort 'effort-minutes effort-minutes
  5495. 'level level 'type "sexp" 'warntime warntime)
  5496. (push txt ee)))))
  5497. (nreverse ee)))
  5498. ;; Calendar sanity: define some functions that are independent of
  5499. ;; `calendar-date-style'.
  5500. (defun org-anniversary (year month day &optional mark)
  5501. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5502. (with-no-warnings
  5503. (let ((calendar-date-style 'iso))
  5504. (diary-anniversary year month day mark))))
  5505. (defun org-cyclic (N year month day &optional mark)
  5506. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5507. (with-no-warnings
  5508. (let ((calendar-date-style 'iso))
  5509. (diary-cyclic N year month day mark))))
  5510. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5511. "Like `diary-block', but with fixed (ISO) order of arguments."
  5512. (with-no-warnings
  5513. (let ((calendar-date-style 'iso))
  5514. (diary-block Y1 M1 D1 Y2 M2 D2 mark))))
  5515. (defun org-date (year month day &optional mark)
  5516. "Like `diary-date', but with fixed (ISO) order of arguments."
  5517. (with-no-warnings
  5518. (let ((calendar-date-style 'iso))
  5519. (diary-date year month day mark))))
  5520. ;; Define the `org-class' function
  5521. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5522. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5523. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5524. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5525. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5526. `holidays', then any date that is known by the Emacs calendar to be a
  5527. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5528. then those holidays will be skipped."
  5529. (with-no-warnings (defvar date) (defvar entry))
  5530. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5531. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5532. (d (calendar-absolute-from-gregorian date))
  5533. (h (when skip-weeks (calendar-check-holidays date))))
  5534. (and
  5535. (<= date1 d)
  5536. (<= d date2)
  5537. (= (calendar-day-of-week date) dayname)
  5538. (or (not skip-weeks)
  5539. (progn
  5540. (require 'cal-iso)
  5541. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5542. (not (or (and h (memq 'holidays skip-weeks))
  5543. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5544. entry)))
  5545. (defalias 'org-get-closed #'org-agenda-get-progress)
  5546. (defun org-agenda-get-progress ()
  5547. "Return the logged TODO entries for agenda display."
  5548. (with-no-warnings (defvar date))
  5549. (let* ((props (list 'mouse-face 'highlight
  5550. 'org-not-done-regexp org-not-done-regexp
  5551. 'org-todo-regexp org-todo-regexp
  5552. 'org-complex-heading-regexp org-complex-heading-regexp
  5553. 'help-echo
  5554. (format "mouse-2 or RET jump to org file %s"
  5555. (abbreviate-file-name buffer-file-name))))
  5556. (items (if (consp org-agenda-show-log-scoped)
  5557. org-agenda-show-log-scoped
  5558. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5559. '(clock)
  5560. org-agenda-log-mode-items)))
  5561. (parts
  5562. (delq nil
  5563. (list
  5564. (when (memq 'closed items) (concat "\\<" org-closed-string))
  5565. (when (memq 'clock items) (concat "\\<" org-clock-string))
  5566. (when (memq 'state items)
  5567. (format "- +State \"%s\".*?" org-todo-regexp)))))
  5568. (parts-re (if parts (mapconcat #'identity parts "\\|")
  5569. (error "`org-agenda-log-mode-items' is empty")))
  5570. (regexp (concat
  5571. "\\(" parts-re "\\)"
  5572. " *\\["
  5573. (regexp-quote
  5574. (substring
  5575. (format-time-string
  5576. (car org-time-stamp-formats)
  5577. (org-encode-time ; DATE bound by calendar
  5578. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5579. 1 11))))
  5580. (org-agenda-search-headline-for-time nil)
  5581. marker hdmarker priority category level tags closedp type
  5582. statep clockp state ee txt extra timestr rest clocked inherited-tags
  5583. effort effort-minutes)
  5584. (goto-char (point-min))
  5585. (while (re-search-forward regexp nil t)
  5586. (catch :skip
  5587. (org-agenda-skip)
  5588. (setq marker (org-agenda-new-marker (match-beginning 0))
  5589. closedp (equal (match-string 1) org-closed-string)
  5590. statep (equal (string-to-char (match-string 1)) ?-)
  5591. clockp (not (or closedp statep))
  5592. state (and statep (match-string 2))
  5593. category (org-get-category (match-beginning 0))
  5594. timestr (buffer-substring (match-beginning 0) (line-end-position))
  5595. effort (save-match-data (or (get-text-property (point) 'effort)
  5596. (org-entry-get (point) org-effort-property))))
  5597. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5598. (when (string-match "\\]" timestr)
  5599. ;; substring should only run to end of time stamp
  5600. (setq rest (substring timestr (match-end 0))
  5601. timestr (substring timestr 0 (match-end 0)))
  5602. (if (and (not closedp) (not statep)
  5603. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5604. rest))
  5605. (progn (setq timestr (concat (substring timestr 0 -1)
  5606. "-" (match-string 1 rest) "]"))
  5607. (setq clocked (match-string 2 rest)))
  5608. (setq clocked "-")))
  5609. (save-excursion
  5610. (setq extra
  5611. (cond
  5612. ((not org-agenda-log-mode-add-notes) nil)
  5613. (statep
  5614. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5615. (match-string 1)))
  5616. (clockp
  5617. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5618. (match-string 1)))))
  5619. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5620. (throw :skip nil)
  5621. (goto-char (match-beginning 0))
  5622. (setq hdmarker (org-agenda-new-marker)
  5623. inherited-tags
  5624. (or (eq org-agenda-show-inherited-tags 'always)
  5625. (and (listp org-agenda-show-inherited-tags)
  5626. (memq 'todo org-agenda-show-inherited-tags))
  5627. (and (eq org-agenda-show-inherited-tags t)
  5628. (or (eq org-agenda-use-tag-inheritance t)
  5629. (memq 'todo org-agenda-use-tag-inheritance))))
  5630. tags (org-get-tags nil (not inherited-tags))
  5631. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5632. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5633. (setq txt (match-string 1))
  5634. (when extra
  5635. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5636. (setq txt (concat (substring txt 0 (match-beginning 1))
  5637. " - " extra " " (match-string 2 txt)))
  5638. (setq txt (concat txt " - " extra))))
  5639. (setq txt (org-agenda-format-item
  5640. (cond
  5641. (closedp "Closed: ")
  5642. (statep (concat "State: (" state ")"))
  5643. (t (concat "Clocked: (" clocked ")")))
  5644. (org-add-props txt nil
  5645. 'effort effort
  5646. 'effort-minutes effort-minutes)
  5647. level category tags timestr)))
  5648. (setq type (cond (closedp "closed")
  5649. (statep "state")
  5650. (t "clock")))
  5651. (setq priority 100000)
  5652. (org-add-props txt props
  5653. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5654. 'priority priority 'level level
  5655. 'effort effort 'effort-minutes effort-minutes
  5656. 'type type 'date date
  5657. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5658. (push txt ee))
  5659. (goto-char (line-end-position))))
  5660. (nreverse ee)))
  5661. (defun org-agenda-show-clocking-issues ()
  5662. "Add overlays, showing issues with clocking.
  5663. See also the user option `org-agenda-clock-consistency-checks'."
  5664. (interactive)
  5665. (let* ((pl org-agenda-clock-consistency-checks)
  5666. (re (concat "^[ \t]*"
  5667. org-clock-string
  5668. "[ \t]+"
  5669. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5670. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5671. (tlstart 0.)
  5672. (tlend 0.)
  5673. (maxtime (org-duration-to-minutes
  5674. (or (plist-get pl :max-duration) "24:00")))
  5675. (mintime (org-duration-to-minutes
  5676. (or (plist-get pl :min-duration) 0)))
  5677. (maxgap (org-duration-to-minutes
  5678. ;; default 30:00 means never complain
  5679. (or (plist-get pl :max-gap) "30:00")))
  5680. (gapok (mapcar #'org-duration-to-minutes
  5681. (plist-get pl :gap-ok-around)))
  5682. (def-face (or (plist-get pl :default-face)
  5683. '((:background "DarkRed") (:foreground "white"))))
  5684. issue face m te ts dt ov)
  5685. (goto-char (point-min))
  5686. (while (re-search-forward " Clocked: +(\\(?:-\\|\\([0-9]+:[0-9]+\\)\\))" nil t)
  5687. (setq issue nil face def-face)
  5688. (catch 'next
  5689. (setq m (org-get-at-bol 'org-marker)
  5690. te nil ts nil)
  5691. (unless (and m (markerp m))
  5692. (setq issue "No valid clock line") (throw 'next t))
  5693. (org-with-point-at m
  5694. (save-excursion
  5695. (goto-char (line-beginning-position))
  5696. (unless (looking-at re)
  5697. (error "No valid Clock line")
  5698. (throw 'next t))
  5699. (unless (match-end 3)
  5700. (setq issue
  5701. (format
  5702. "No end time: (%s)"
  5703. (org-duration-from-minutes
  5704. (floor
  5705. (- (float-time (org-current-time))
  5706. (float-time (org-time-string-to-time (match-string 1))))
  5707. 60)))
  5708. face (or (plist-get pl :no-end-time-face) face))
  5709. (throw 'next t))
  5710. (setq ts (match-string 1)
  5711. te (match-string 3)
  5712. ts (float-time (org-time-string-to-time ts))
  5713. te (float-time (org-time-string-to-time te))
  5714. dt (- te ts))))
  5715. (cond
  5716. ((> dt (* 60 maxtime))
  5717. ;; a very long clocking chunk
  5718. (setq issue (format "Clocking interval is very long: %s"
  5719. (org-duration-from-minutes (floor dt 60)))
  5720. face (or (plist-get pl :long-face) face)))
  5721. ((< dt (* 60 mintime))
  5722. ;; a very short clocking chunk
  5723. (setq issue (format "Clocking interval is very short: %s"
  5724. (org-duration-from-minutes (floor dt 60)))
  5725. face (or (plist-get pl :short-face) face)))
  5726. ((and (> tlend 0) (< ts tlend))
  5727. ;; Two clock entries are overlapping
  5728. (setq issue (format "Clocking overlap: %d minutes"
  5729. (/ (- tlend ts) 60))
  5730. face (or (plist-get pl :overlap-face) face)))
  5731. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5732. ;; There is a gap, lets see if we need to report it
  5733. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5734. (setq issue (format "Clocking gap: %d minutes"
  5735. (/ (- ts tlend) 60))
  5736. face (or (plist-get pl :gap-face) face))))
  5737. (t nil)))
  5738. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5739. (when issue
  5740. ;; OK, there was some issue, add an overlay to show the issue
  5741. (setq ov (make-overlay (line-beginning-position) (line-end-position)))
  5742. (overlay-put ov 'before-string
  5743. (concat
  5744. (org-add-props
  5745. (format "%-43s" (concat " " issue))
  5746. nil
  5747. 'face face)
  5748. "\n"))
  5749. (overlay-put ov 'evaporate t)))))
  5750. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5751. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5752. (catch 'exit
  5753. (unless ok-list
  5754. ;; there are no OK times for gaps...
  5755. (throw 'exit nil))
  5756. (when (> (- (/ t2 36000) (/ t1 36000)) 24)
  5757. ;; This is more than 24 hours, so it is OK.
  5758. ;; because we have at least one OK time, that must be in the
  5759. ;; 24 hour interval.
  5760. (throw 'exit t))
  5761. ;; We have a shorter gap.
  5762. ;; Now we have to get the minute of the day when these times are
  5763. (let* ((t1dec (decode-time t1))
  5764. (t2dec (decode-time t2))
  5765. ;; compute the minute on the day
  5766. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5767. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5768. (when (< min2 min1)
  5769. ;; if min2 is smaller than min1, this means it is on the next day.
  5770. ;; Wrap it to after midnight.
  5771. (setq min2 (+ min2 1440)))
  5772. ;; Now check if any of the OK times is in the gap
  5773. (mapc (lambda (x)
  5774. ;; Wrap the time to after midnight if necessary
  5775. (when (< x min1) (setq x (+ x 1440)))
  5776. ;; Check if in interval
  5777. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5778. ok-list)
  5779. ;; Nope, this gap is not OK
  5780. nil)))
  5781. (defun org-agenda-get-deadlines (&optional with-hour)
  5782. "Return the deadline information for agenda display.
  5783. When WITH-HOUR is non-nil, only return deadlines with an hour
  5784. specification like [h]h:mm."
  5785. (with-no-warnings (defvar date))
  5786. (let* ((props (list 'mouse-face 'highlight
  5787. 'org-not-done-regexp org-not-done-regexp
  5788. 'org-todo-regexp org-todo-regexp
  5789. 'org-complex-heading-regexp org-complex-heading-regexp
  5790. 'help-echo
  5791. (format "mouse-2 or RET jump to org file %s"
  5792. (abbreviate-file-name buffer-file-name))))
  5793. (regexp (if with-hour
  5794. org-deadline-time-hour-regexp
  5795. org-deadline-time-regexp))
  5796. (today (org-today))
  5797. (today? (org-agenda-today-p date)) ; DATE bound by calendar.
  5798. (current (calendar-absolute-from-gregorian date))
  5799. deadline-items)
  5800. (goto-char (point-min))
  5801. (if (org-element--cache-active-p)
  5802. (org-element-cache-map
  5803. (lambda (el)
  5804. (when (and (org-element-property :deadline el)
  5805. (or (not with-hour)
  5806. (org-element-property
  5807. :hour-start
  5808. (org-element-property :deadline el))
  5809. (org-element-property
  5810. :hour-end
  5811. (org-element-property :deadline el))))
  5812. (goto-char (org-element-property :contents-begin el))
  5813. (catch :skip
  5814. (org-agenda-skip el)
  5815. (let* ((s (substring (org-element-property
  5816. :raw-value
  5817. (org-element-property :deadline el))
  5818. 1 -1))
  5819. (pos (save-excursion
  5820. (goto-char (org-element-property :contents-begin el))
  5821. ;; We intentionally leave NOERROR
  5822. ;; argument in `re-search-forward' nil. If
  5823. ;; the search fails here, something went
  5824. ;; wrong and we are looking at
  5825. ;; non-matching headline.
  5826. (re-search-forward regexp (line-end-position))
  5827. (1- (match-beginning 1))))
  5828. (todo-state (org-element-property :todo-keyword el))
  5829. (done? (eq 'done (org-element-property :todo-type el)))
  5830. (sexp? (eq 'diary
  5831. (org-element-property
  5832. :type (org-element-property :deadline el))))
  5833. ;; DEADLINE is the deadline date for the entry. It is
  5834. ;; either the base date or the last repeat, according
  5835. ;; to `org-agenda-prefer-last-repeat'.
  5836. (deadline
  5837. (cond
  5838. (sexp? (org-agenda--timestamp-to-absolute s current))
  5839. ((or (eq org-agenda-prefer-last-repeat t)
  5840. (member todo-state org-agenda-prefer-last-repeat))
  5841. (org-agenda--timestamp-to-absolute
  5842. s today 'past (current-buffer) pos))
  5843. (t (org-agenda--timestamp-to-absolute s))))
  5844. ;; REPEAT is the future repeat closest from CURRENT,
  5845. ;; according to `org-agenda-show-future-repeats'. If
  5846. ;; the latter is nil, or if the time stamp has no
  5847. ;; repeat part, default to DEADLINE.
  5848. (repeat
  5849. (cond
  5850. (sexp? deadline)
  5851. ((<= current today) deadline)
  5852. ((not org-agenda-show-future-repeats) deadline)
  5853. (t
  5854. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5855. (1+ today)
  5856. current)))
  5857. (org-agenda--timestamp-to-absolute
  5858. s base 'future (current-buffer) pos)))))
  5859. (diff (- deadline current))
  5860. (suppress-prewarning
  5861. (let ((scheduled
  5862. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5863. (org-element-property
  5864. :raw-value
  5865. (org-element-property :scheduled el)))))
  5866. (cond
  5867. ((not scheduled) nil)
  5868. ;; The current item has a scheduled date, so
  5869. ;; evaluate its prewarning lead time.
  5870. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5871. ;; Use global prewarning-restart lead time.
  5872. org-agenda-skip-deadline-prewarning-if-scheduled)
  5873. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5874. 'pre-scheduled)
  5875. ;; Set pre-warning to no earlier than SCHEDULED.
  5876. (min (- deadline
  5877. (org-agenda--timestamp-to-absolute scheduled))
  5878. org-deadline-warning-days))
  5879. ;; Set pre-warning to deadline.
  5880. (t 0))))
  5881. (wdays (or suppress-prewarning (org-get-wdays s))))
  5882. (cond
  5883. ;; Only display deadlines at their base date, at future
  5884. ;; repeat occurrences or in today agenda.
  5885. ((= current deadline) nil)
  5886. ((= current repeat) nil)
  5887. ((not today?) (throw :skip nil))
  5888. ;; Upcoming deadline: display within warning period WDAYS.
  5889. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  5890. ;; Overdue deadline: warn about it for
  5891. ;; `org-deadline-past-days' duration.
  5892. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  5893. ;; Possibly skip done tasks.
  5894. (when (and done?
  5895. (or org-agenda-skip-deadline-if-done
  5896. (/= deadline current)))
  5897. (throw :skip nil))
  5898. (save-excursion
  5899. (goto-char (org-element-property :begin el))
  5900. (let* ((category (org-get-category))
  5901. (effort (save-match-data (or (get-text-property (point) 'effort)
  5902. (org-element-property (intern (concat ":" (upcase org-effort-property))) el))))
  5903. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5904. (level (make-string (org-element-property :level el)
  5905. ?\s))
  5906. (head (save-excursion
  5907. (goto-char (org-element-property :begin el))
  5908. (re-search-forward org-outline-regexp-bol)
  5909. (buffer-substring-no-properties (point) (line-end-position))))
  5910. (inherited-tags
  5911. (or (eq org-agenda-show-inherited-tags 'always)
  5912. (and (listp org-agenda-show-inherited-tags)
  5913. (memq 'agenda org-agenda-show-inherited-tags))
  5914. (and (eq org-agenda-show-inherited-tags t)
  5915. (or (eq org-agenda-use-tag-inheritance t)
  5916. (memq 'agenda
  5917. org-agenda-use-tag-inheritance)))))
  5918. (tags (org-get-tags el (not inherited-tags)))
  5919. (time
  5920. (cond
  5921. ;; No time of day designation if it is only
  5922. ;; a reminder.
  5923. ((and (/= current deadline) (/= current repeat)) nil)
  5924. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5925. (concat (substring s (match-beginning 1)) " "))
  5926. (t 'time)))
  5927. (item
  5928. (org-agenda-format-item
  5929. ;; Insert appropriate suffixes before deadlines.
  5930. ;; Those only apply to today agenda.
  5931. (pcase-let ((`(,now ,future ,past)
  5932. org-agenda-deadline-leaders))
  5933. (cond
  5934. ((and today? (< deadline today)) (format past (- diff)))
  5935. ((and today? (> deadline today)) (format future diff))
  5936. (t now)))
  5937. (org-add-props head nil
  5938. 'effort effort
  5939. 'effort-minutes effort-minutes)
  5940. level category tags time))
  5941. (face (org-agenda-deadline-face
  5942. (- 1 (/ (float diff) (max wdays 1)))))
  5943. (upcoming? (and today? (> deadline today)))
  5944. (warntime (get-text-property (point) 'org-appt-warntime)))
  5945. (org-add-props item props
  5946. 'org-marker (org-agenda-new-marker pos)
  5947. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5948. 'warntime warntime
  5949. 'level level
  5950. 'effort effort 'effort-minutes effort-minutes
  5951. 'ts-date deadline
  5952. 'priority
  5953. ;; Adjust priority to today reminders about deadlines.
  5954. ;; Overdue deadlines get the highest priority
  5955. ;; increase, then imminent deadlines and eventually
  5956. ;; more distant deadlines.
  5957. (let ((adjust (if today? (- diff) 0)))
  5958. (+ adjust (org-get-priority item)))
  5959. 'todo-state todo-state
  5960. 'type (if upcoming? "upcoming-deadline" "deadline")
  5961. 'date (if upcoming? date deadline)
  5962. 'face (if done? 'org-agenda-done face)
  5963. 'undone-face face
  5964. 'done-face 'org-agenda-done)
  5965. (push item deadline-items)))))))
  5966. :next-re regexp
  5967. :fail-re regexp
  5968. :narrow t)
  5969. (while (re-search-forward regexp nil t)
  5970. (catch :skip
  5971. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5972. (org-agenda-skip)
  5973. (let* ((s (match-string 1))
  5974. (pos (1- (match-beginning 1)))
  5975. (todo-state (save-match-data (org-get-todo-state)))
  5976. (done? (member todo-state org-done-keywords))
  5977. (sexp? (string-prefix-p "%%" s))
  5978. ;; DEADLINE is the deadline date for the entry. It is
  5979. ;; either the base date or the last repeat, according
  5980. ;; to `org-agenda-prefer-last-repeat'.
  5981. (deadline
  5982. (cond
  5983. (sexp? (org-agenda--timestamp-to-absolute s current))
  5984. ((or (eq org-agenda-prefer-last-repeat t)
  5985. (member todo-state org-agenda-prefer-last-repeat))
  5986. (org-agenda--timestamp-to-absolute
  5987. s today 'past (current-buffer) pos))
  5988. (t (org-agenda--timestamp-to-absolute s))))
  5989. ;; REPEAT is the future repeat closest from CURRENT,
  5990. ;; according to `org-agenda-show-future-repeats'. If
  5991. ;; the latter is nil, or if the time stamp has no
  5992. ;; repeat part, default to DEADLINE.
  5993. (repeat
  5994. (cond
  5995. (sexp? deadline)
  5996. ((<= current today) deadline)
  5997. ((not org-agenda-show-future-repeats) deadline)
  5998. (t
  5999. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6000. (1+ today)
  6001. current)))
  6002. (org-agenda--timestamp-to-absolute
  6003. s base 'future (current-buffer) pos)))))
  6004. (diff (- deadline current))
  6005. (suppress-prewarning
  6006. (let ((scheduled
  6007. (and org-agenda-skip-deadline-prewarning-if-scheduled
  6008. (org-entry-get nil "SCHEDULED"))))
  6009. (cond
  6010. ((not scheduled) nil)
  6011. ;; The current item has a scheduled date, so
  6012. ;; evaluate its prewarning lead time.
  6013. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  6014. ;; Use global prewarning-restart lead time.
  6015. org-agenda-skip-deadline-prewarning-if-scheduled)
  6016. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  6017. 'pre-scheduled)
  6018. ;; Set pre-warning to no earlier than SCHEDULED.
  6019. (min (- deadline
  6020. (org-agenda--timestamp-to-absolute scheduled))
  6021. org-deadline-warning-days))
  6022. ;; Set pre-warning to deadline.
  6023. (t 0))))
  6024. (wdays (or suppress-prewarning (org-get-wdays s))))
  6025. (cond
  6026. ;; Only display deadlines at their base date, at future
  6027. ;; repeat occurrences or in today agenda.
  6028. ((= current deadline) nil)
  6029. ((= current repeat) nil)
  6030. ((not today?) (throw :skip nil))
  6031. ;; Upcoming deadline: display within warning period WDAYS.
  6032. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  6033. ;; Overdue deadline: warn about it for
  6034. ;; `org-deadline-past-days' duration.
  6035. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  6036. ;; Possibly skip done tasks.
  6037. (when (and done?
  6038. (or org-agenda-skip-deadline-if-done
  6039. (/= deadline current)))
  6040. (throw :skip nil))
  6041. (save-excursion
  6042. (re-search-backward "^\\*+[ \t]+" nil t)
  6043. (goto-char (match-end 0))
  6044. (let* ((category (org-get-category))
  6045. (effort (save-match-data (or (get-text-property (point) 'effort)
  6046. (org-entry-get (point) org-effort-property))))
  6047. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6048. (level (make-string (org-reduced-level (org-outline-level))
  6049. ?\s))
  6050. (head (buffer-substring-no-properties
  6051. (point) (line-end-position)))
  6052. (inherited-tags
  6053. (or (eq org-agenda-show-inherited-tags 'always)
  6054. (and (listp org-agenda-show-inherited-tags)
  6055. (memq 'agenda org-agenda-show-inherited-tags))
  6056. (and (eq org-agenda-show-inherited-tags t)
  6057. (or (eq org-agenda-use-tag-inheritance t)
  6058. (memq 'agenda
  6059. org-agenda-use-tag-inheritance)))))
  6060. (tags (org-get-tags nil (not inherited-tags)))
  6061. (time
  6062. (cond
  6063. ;; No time of day designation if it is only
  6064. ;; a reminder.
  6065. ((and (/= current deadline) (/= current repeat)) nil)
  6066. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6067. (concat (substring s (match-beginning 1)) " "))
  6068. (t 'time)))
  6069. (item
  6070. (org-agenda-format-item
  6071. ;; Insert appropriate suffixes before deadlines.
  6072. ;; Those only apply to today agenda.
  6073. (pcase-let ((`(,now ,future ,past)
  6074. org-agenda-deadline-leaders))
  6075. (cond
  6076. ((and today? (< deadline today)) (format past (- diff)))
  6077. ((and today? (> deadline today)) (format future diff))
  6078. (t now)))
  6079. (org-add-props head nil
  6080. 'effort effort
  6081. 'effort-minutes effort-minutes)
  6082. level category tags time))
  6083. (face (org-agenda-deadline-face
  6084. (- 1 (/ (float diff) (max wdays 1)))))
  6085. (upcoming? (and today? (> deadline today)))
  6086. (warntime (get-text-property (point) 'org-appt-warntime)))
  6087. (org-add-props item props
  6088. 'org-marker (org-agenda-new-marker pos)
  6089. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6090. 'warntime warntime
  6091. 'level level
  6092. 'effort effort 'effort-minutes effort-minutes
  6093. 'ts-date deadline
  6094. 'priority
  6095. ;; Adjust priority to today reminders about deadlines.
  6096. ;; Overdue deadlines get the highest priority
  6097. ;; increase, then imminent deadlines and eventually
  6098. ;; more distant deadlines.
  6099. (let ((adjust (if today? (- diff) 0)))
  6100. (+ adjust (org-get-priority item)))
  6101. 'todo-state todo-state
  6102. 'type (if upcoming? "upcoming-deadline" "deadline")
  6103. 'date (if upcoming? date deadline)
  6104. 'face (if done? 'org-agenda-done face)
  6105. 'undone-face face
  6106. 'done-face 'org-agenda-done)
  6107. (push item deadline-items)))))))
  6108. (nreverse deadline-items)))
  6109. (defun org-agenda-deadline-face (fraction)
  6110. "Return the face to displaying a deadline item.
  6111. FRACTION is what fraction of the head-warning time has passed."
  6112. (assoc-default fraction org-agenda-deadline-faces #'<=))
  6113. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  6114. "Return the scheduled information for agenda display.
  6115. Optional argument DEADLINES is a list of deadline items to be
  6116. displayed in agenda view. When WITH-HOUR is non-nil, only return
  6117. scheduled items with an hour specification like [h]h:mm."
  6118. (with-no-warnings (defvar date))
  6119. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  6120. 'org-todo-regexp org-todo-regexp
  6121. 'org-complex-heading-regexp org-complex-heading-regexp
  6122. 'done-face 'org-agenda-done
  6123. 'mouse-face 'highlight
  6124. 'help-echo
  6125. (format "mouse-2 or RET jump to Org file %s"
  6126. (abbreviate-file-name buffer-file-name))))
  6127. (regexp (if with-hour
  6128. org-scheduled-time-hour-regexp
  6129. org-scheduled-time-regexp))
  6130. (today (org-today))
  6131. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  6132. (current (calendar-absolute-from-gregorian date))
  6133. (deadline-pos
  6134. (mapcar (lambda (d)
  6135. (let ((m (get-text-property 0 'org-hd-marker d)))
  6136. (and m (marker-position m))))
  6137. deadlines))
  6138. scheduled-items)
  6139. (goto-char (point-min))
  6140. (if (org-element--cache-active-p)
  6141. (org-element-cache-map
  6142. (lambda (el)
  6143. (when (and (org-element-property :scheduled el)
  6144. (or (not with-hour)
  6145. (org-element-property
  6146. :hour-start
  6147. (org-element-property :scheduled el))
  6148. (org-element-property
  6149. :hour-end
  6150. (org-element-property :scheduled el))))
  6151. (goto-char (org-element-property :contents-begin el))
  6152. (catch :skip
  6153. (org-agenda-skip el)
  6154. (let* ((s (substring (org-element-property
  6155. :raw-value
  6156. (org-element-property :scheduled el))
  6157. 1 -1))
  6158. (pos (save-excursion
  6159. (goto-char (org-element-property :contents-begin el))
  6160. ;; We intentionally leave NOERROR
  6161. ;; argument in `re-search-forward' nil. If
  6162. ;; the search fails here, something went
  6163. ;; wrong and we are looking at
  6164. ;; non-matching headline.
  6165. (re-search-forward regexp (line-end-position))
  6166. (1- (match-beginning 1))))
  6167. (todo-state (org-element-property :todo-keyword el))
  6168. (donep (eq 'done (org-element-property :todo-type el)))
  6169. (sexp? (eq 'diary
  6170. (org-element-property
  6171. :type (org-element-property :scheduled el))))
  6172. ;; SCHEDULE is the scheduled date for the entry. It is
  6173. ;; either the bare date or the last repeat, according
  6174. ;; to `org-agenda-prefer-last-repeat'.
  6175. (schedule
  6176. (cond
  6177. (sexp? (org-agenda--timestamp-to-absolute s current))
  6178. ((or (eq org-agenda-prefer-last-repeat t)
  6179. (member todo-state org-agenda-prefer-last-repeat))
  6180. (org-agenda--timestamp-to-absolute
  6181. s today 'past (current-buffer) pos))
  6182. (t (org-agenda--timestamp-to-absolute s))))
  6183. ;; REPEAT is the future repeat closest from CURRENT,
  6184. ;; according to `org-agenda-show-future-repeats'. If
  6185. ;; the latter is nil, or if the time stamp has no
  6186. ;; repeat part, default to SCHEDULE.
  6187. (repeat
  6188. (cond
  6189. (sexp? schedule)
  6190. ((<= current today) schedule)
  6191. ((not org-agenda-show-future-repeats) schedule)
  6192. (t
  6193. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6194. (1+ today)
  6195. current)))
  6196. (org-agenda--timestamp-to-absolute
  6197. s base 'future (current-buffer) pos)))))
  6198. (diff (- current schedule))
  6199. (warntime (get-text-property (point) 'org-appt-warntime))
  6200. (pastschedp (< schedule today))
  6201. (futureschedp (> schedule today))
  6202. (habitp (and (fboundp 'org-is-habit-p)
  6203. (string= "habit" (org-element-property :STYLE el))))
  6204. (suppress-delay
  6205. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  6206. (org-element-property
  6207. :raw-value
  6208. (org-element-property :deadline el)))))
  6209. (cond
  6210. ((not deadline) nil)
  6211. ;; The current item has a deadline date, so
  6212. ;; evaluate its delay time.
  6213. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  6214. ;; Use global delay time.
  6215. (- org-agenda-skip-scheduled-delay-if-deadline))
  6216. ((eq org-agenda-skip-scheduled-delay-if-deadline
  6217. 'post-deadline)
  6218. ;; Set delay to no later than DEADLINE.
  6219. (min (- schedule
  6220. (org-agenda--timestamp-to-absolute deadline))
  6221. org-scheduled-delay-days))
  6222. (t 0))))
  6223. (ddays
  6224. (cond
  6225. ;; Nullify delay when a repeater triggered already
  6226. ;; and the delay is of the form --Xd.
  6227. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  6228. (> schedule (org-agenda--timestamp-to-absolute s)))
  6229. 0)
  6230. (suppress-delay
  6231. (let ((org-scheduled-delay-days suppress-delay))
  6232. (org-get-wdays s t t)))
  6233. (t (org-get-wdays s t)))))
  6234. ;; Display scheduled items at base date (SCHEDULE), today if
  6235. ;; scheduled before the current date, and at any repeat past
  6236. ;; today. However, skip delayed items and items that have
  6237. ;; been displayed for more than `org-scheduled-past-days'.
  6238. (unless (and todayp
  6239. habitp
  6240. (bound-and-true-p org-habit-show-all-today))
  6241. (when (or (and (> ddays 0) (< diff ddays))
  6242. (> diff (or (and habitp org-habit-scheduled-past-days)
  6243. org-scheduled-past-days))
  6244. (> schedule current)
  6245. (and (/= current schedule)
  6246. (/= current today)
  6247. (/= current repeat)))
  6248. (throw :skip nil)))
  6249. ;; Possibly skip done tasks.
  6250. (when (and donep
  6251. (or org-agenda-skip-scheduled-if-done
  6252. (/= schedule current)))
  6253. (throw :skip nil))
  6254. ;; Skip entry if it already appears as a deadline, per
  6255. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  6256. ;; doesn't apply to habits.
  6257. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  6258. ((guard
  6259. (or (not (memq (line-beginning-position 0) deadline-pos))
  6260. habitp))
  6261. nil)
  6262. (`repeated-after-deadline
  6263. (let ((deadline (time-to-days
  6264. (when (org-element-property :deadline el)
  6265. (org-time-string-to-time
  6266. (org-element-property :deadline el))))))
  6267. (and (<= schedule deadline) (> current deadline))))
  6268. (`not-today pastschedp)
  6269. (`t t)
  6270. (_ nil))
  6271. (throw :skip nil))
  6272. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  6273. ;; only show them for today. Also skip done habits.
  6274. (when (and habitp
  6275. (or donep
  6276. (not (bound-and-true-p org-habit-show-habits))
  6277. (and (not todayp)
  6278. (bound-and-true-p
  6279. org-habit-show-habits-only-for-today))))
  6280. (throw :skip nil))
  6281. (save-excursion
  6282. (goto-char (org-element-property :begin el))
  6283. (let* ((category (org-get-category))
  6284. (effort (save-match-data
  6285. (or (get-text-property (point) 'effort)
  6286. (org-element-property (intern (concat ":" (upcase org-effort-property))) el))))
  6287. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6288. (inherited-tags
  6289. (or (eq org-agenda-show-inherited-tags 'always)
  6290. (and (listp org-agenda-show-inherited-tags)
  6291. (memq 'agenda org-agenda-show-inherited-tags))
  6292. (and (eq org-agenda-show-inherited-tags t)
  6293. (or (eq org-agenda-use-tag-inheritance t)
  6294. (memq 'agenda
  6295. org-agenda-use-tag-inheritance)))))
  6296. (tags (org-get-tags el (not inherited-tags)))
  6297. (level (make-string (org-element-property :level el)
  6298. ?\s))
  6299. (head (save-excursion
  6300. (goto-char (org-element-property :begin el))
  6301. (re-search-forward org-outline-regexp-bol)
  6302. (buffer-substring (point) (line-end-position))))
  6303. (time
  6304. (cond
  6305. ;; No time of day designation if it is only a
  6306. ;; reminder, except for habits, which always show
  6307. ;; the time of day. Habits are an exception
  6308. ;; because if there is a time of day, that is
  6309. ;; interpreted to mean they should usually happen
  6310. ;; then, even if doing the habit was missed.
  6311. ((and
  6312. (not habitp)
  6313. (/= current schedule)
  6314. (/= current repeat))
  6315. nil)
  6316. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6317. (concat (substring s (match-beginning 1)) " "))
  6318. (t 'time)))
  6319. (item
  6320. (org-agenda-format-item
  6321. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  6322. ;; Show a reminder of a past scheduled today.
  6323. (if (and todayp pastschedp)
  6324. (format past diff)
  6325. first))
  6326. (org-add-props head nil
  6327. 'effort effort
  6328. 'effort-minutes effort-minutes)
  6329. level category tags time nil habitp))
  6330. (face (cond ((and (not habitp) pastschedp)
  6331. 'org-scheduled-previously)
  6332. ((and habitp futureschedp)
  6333. 'org-agenda-done)
  6334. (todayp 'org-scheduled-today)
  6335. (t 'org-scheduled)))
  6336. (habitp (and habitp (org-habit-parse-todo (org-element-property :begin el)))))
  6337. (org-add-props item props
  6338. 'undone-face face
  6339. 'face (if donep 'org-agenda-done face)
  6340. 'org-marker (org-agenda-new-marker pos)
  6341. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6342. 'type (if pastschedp "past-scheduled" "scheduled")
  6343. 'date (if pastschedp schedule date)
  6344. 'ts-date schedule
  6345. 'warntime warntime
  6346. 'level level
  6347. 'effort effort 'effort-minutes effort-minutes
  6348. 'priority (if habitp (org-habit-get-priority habitp)
  6349. (+ 99 diff (org-get-priority item)))
  6350. 'org-habit-p habitp
  6351. 'todo-state todo-state)
  6352. (push item scheduled-items)))))))
  6353. :next-re regexp
  6354. :fail-re regexp
  6355. :narrow t)
  6356. (while (re-search-forward regexp nil t)
  6357. (catch :skip
  6358. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  6359. (org-agenda-skip)
  6360. (let* ((s (match-string 1))
  6361. (pos (1- (match-beginning 1)))
  6362. (todo-state (save-match-data (org-get-todo-state)))
  6363. (donep (member todo-state org-done-keywords))
  6364. (sexp? (string-prefix-p "%%" s))
  6365. ;; SCHEDULE is the scheduled date for the entry. It is
  6366. ;; either the bare date or the last repeat, according
  6367. ;; to `org-agenda-prefer-last-repeat'.
  6368. (schedule
  6369. (cond
  6370. (sexp? (org-agenda--timestamp-to-absolute s current))
  6371. ((or (eq org-agenda-prefer-last-repeat t)
  6372. (member todo-state org-agenda-prefer-last-repeat))
  6373. (org-agenda--timestamp-to-absolute
  6374. s today 'past (current-buffer) pos))
  6375. (t (org-agenda--timestamp-to-absolute s))))
  6376. ;; REPEAT is the future repeat closest from CURRENT,
  6377. ;; according to `org-agenda-show-future-repeats'. If
  6378. ;; the latter is nil, or if the time stamp has no
  6379. ;; repeat part, default to SCHEDULE.
  6380. (repeat
  6381. (cond
  6382. (sexp? schedule)
  6383. ((<= current today) schedule)
  6384. ((not org-agenda-show-future-repeats) schedule)
  6385. (t
  6386. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6387. (1+ today)
  6388. current)))
  6389. (org-agenda--timestamp-to-absolute
  6390. s base 'future (current-buffer) pos)))))
  6391. (diff (- current schedule))
  6392. (warntime (get-text-property (point) 'org-appt-warntime))
  6393. (pastschedp (< schedule today))
  6394. (futureschedp (> schedule today))
  6395. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  6396. (suppress-delay
  6397. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  6398. (org-entry-get nil "DEADLINE"))))
  6399. (cond
  6400. ((not deadline) nil)
  6401. ;; The current item has a deadline date, so
  6402. ;; evaluate its delay time.
  6403. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  6404. ;; Use global delay time.
  6405. (- org-agenda-skip-scheduled-delay-if-deadline))
  6406. ((eq org-agenda-skip-scheduled-delay-if-deadline
  6407. 'post-deadline)
  6408. ;; Set delay to no later than DEADLINE.
  6409. (min (- schedule
  6410. (org-agenda--timestamp-to-absolute deadline))
  6411. org-scheduled-delay-days))
  6412. (t 0))))
  6413. (ddays
  6414. (cond
  6415. ;; Nullify delay when a repeater triggered already
  6416. ;; and the delay is of the form --Xd.
  6417. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  6418. (> schedule (org-agenda--timestamp-to-absolute s)))
  6419. 0)
  6420. (suppress-delay
  6421. (let ((org-scheduled-delay-days suppress-delay))
  6422. (org-get-wdays s t t)))
  6423. (t (org-get-wdays s t)))))
  6424. ;; Display scheduled items at base date (SCHEDULE), today if
  6425. ;; scheduled before the current date, and at any repeat past
  6426. ;; today. However, skip delayed items and items that have
  6427. ;; been displayed for more than `org-scheduled-past-days'.
  6428. (unless (and todayp
  6429. habitp
  6430. (bound-and-true-p org-habit-show-all-today))
  6431. (when (or (and (> ddays 0) (< diff ddays))
  6432. (> diff (or (and habitp org-habit-scheduled-past-days)
  6433. org-scheduled-past-days))
  6434. (> schedule current)
  6435. (and (/= current schedule)
  6436. (/= current today)
  6437. (/= current repeat)))
  6438. (throw :skip nil)))
  6439. ;; Possibly skip done tasks.
  6440. (when (and donep
  6441. (or org-agenda-skip-scheduled-if-done
  6442. (/= schedule current)))
  6443. (throw :skip nil))
  6444. ;; Skip entry if it already appears as a deadline, per
  6445. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  6446. ;; doesn't apply to habits.
  6447. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  6448. ((guard
  6449. (or (not (memq (line-beginning-position 0) deadline-pos))
  6450. habitp))
  6451. nil)
  6452. (`repeated-after-deadline
  6453. (let ((deadline (time-to-days
  6454. (org-get-deadline-time (point)))))
  6455. (and (<= schedule deadline) (> current deadline))))
  6456. (`not-today pastschedp)
  6457. (`t t)
  6458. (_ nil))
  6459. (throw :skip nil))
  6460. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  6461. ;; only show them for today. Also skip done habits.
  6462. (when (and habitp
  6463. (or donep
  6464. (not (bound-and-true-p org-habit-show-habits))
  6465. (and (not todayp)
  6466. (bound-and-true-p
  6467. org-habit-show-habits-only-for-today))))
  6468. (throw :skip nil))
  6469. (save-excursion
  6470. (re-search-backward "^\\*+[ \t]+" nil t)
  6471. (goto-char (match-end 0))
  6472. (let* ((category (org-get-category))
  6473. (effort (save-match-data (or (get-text-property (point) 'effort)
  6474. (org-entry-get (point) org-effort-property))))
  6475. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6476. (inherited-tags
  6477. (or (eq org-agenda-show-inherited-tags 'always)
  6478. (and (listp org-agenda-show-inherited-tags)
  6479. (memq 'agenda org-agenda-show-inherited-tags))
  6480. (and (eq org-agenda-show-inherited-tags t)
  6481. (or (eq org-agenda-use-tag-inheritance t)
  6482. (memq 'agenda
  6483. org-agenda-use-tag-inheritance)))))
  6484. (tags (org-get-tags nil (not inherited-tags)))
  6485. (level (make-string (org-reduced-level (org-outline-level))
  6486. ?\s))
  6487. (head (buffer-substring (point) (line-end-position)))
  6488. (time
  6489. (cond
  6490. ;; No time of day designation if it is only a
  6491. ;; reminder, except for habits, which always show
  6492. ;; the time of day. Habits are an exception
  6493. ;; because if there is a time of day, that is
  6494. ;; interpreted to mean they should usually happen
  6495. ;; then, even if doing the habit was missed.
  6496. ((and
  6497. (not habitp)
  6498. (/= current schedule)
  6499. (/= current repeat))
  6500. nil)
  6501. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6502. (concat (substring s (match-beginning 1)) " "))
  6503. (t 'time)))
  6504. (item
  6505. (org-agenda-format-item
  6506. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  6507. ;; Show a reminder of a past scheduled today.
  6508. (if (and todayp pastschedp)
  6509. (format past diff)
  6510. first))
  6511. (org-add-props head nil
  6512. 'effort effort
  6513. 'effort-minutes effort-minutes)
  6514. level category tags time nil habitp))
  6515. (face (cond ((and (not habitp) pastschedp)
  6516. 'org-scheduled-previously)
  6517. ((and habitp futureschedp)
  6518. 'org-agenda-done)
  6519. (todayp 'org-scheduled-today)
  6520. (t 'org-scheduled)))
  6521. (habitp (and habitp (org-habit-parse-todo))))
  6522. (org-add-props item props
  6523. 'undone-face face
  6524. 'face (if donep 'org-agenda-done face)
  6525. 'org-marker (org-agenda-new-marker pos)
  6526. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6527. 'type (if pastschedp "past-scheduled" "scheduled")
  6528. 'date (if pastschedp schedule date)
  6529. 'ts-date schedule
  6530. 'warntime warntime
  6531. 'level level
  6532. 'effort effort 'effort-minutes effort-minutes
  6533. 'priority (if habitp (org-habit-get-priority habitp)
  6534. (+ 99 diff (org-get-priority item)))
  6535. 'org-habit-p habitp
  6536. 'todo-state todo-state)
  6537. (push item scheduled-items)))))))
  6538. (nreverse scheduled-items)))
  6539. (defun org-agenda-get-blocks ()
  6540. "Return the date-range information for agenda display."
  6541. (with-no-warnings (defvar date))
  6542. (let* ((props (list 'face nil
  6543. 'org-not-done-regexp org-not-done-regexp
  6544. 'org-todo-regexp org-todo-regexp
  6545. 'org-complex-heading-regexp org-complex-heading-regexp
  6546. 'mouse-face 'highlight
  6547. 'help-echo
  6548. (format "mouse-2 or RET jump to org file %s"
  6549. (abbreviate-file-name buffer-file-name))))
  6550. (regexp org-tr-regexp)
  6551. (d0 (calendar-absolute-from-gregorian date))
  6552. marker hdmarker ee txt d1 d2 s1 s2 category
  6553. level todo-state tags pos head donep inherited-tags
  6554. effort effort-minutes)
  6555. (goto-char (point-min))
  6556. (while (re-search-forward regexp nil t)
  6557. (catch :skip
  6558. (org-agenda-skip)
  6559. (setq pos (point))
  6560. (let ((start-time (match-string 1))
  6561. (end-time (match-string 2)))
  6562. (setq s1 (match-string 1)
  6563. s2 (match-string 2)
  6564. d1 (time-to-days
  6565. (condition-case err
  6566. (org-time-string-to-time s1)
  6567. (error
  6568. (error
  6569. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6570. s1
  6571. pos
  6572. (current-buffer)
  6573. (error-message-string err)))))
  6574. d2 (time-to-days
  6575. (condition-case err
  6576. (org-time-string-to-time s2)
  6577. (error
  6578. (error
  6579. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6580. s2
  6581. pos
  6582. (current-buffer)
  6583. (error-message-string err))))))
  6584. (when (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  6585. ;; Only allow days between the limits, because the normal
  6586. ;; date stamps will catch the limits.
  6587. (save-excursion
  6588. (setq todo-state (org-get-todo-state))
  6589. (setq donep (member todo-state org-done-keywords))
  6590. (when (and donep org-agenda-skip-timestamp-if-done)
  6591. (throw :skip t))
  6592. (setq marker (org-agenda-new-marker (point))
  6593. category (org-get-category))
  6594. (setq effort (save-match-data (or (get-text-property (point) 'effort)
  6595. (org-entry-get (point) org-effort-property))))
  6596. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6597. (if (not (re-search-backward org-outline-regexp-bol nil t))
  6598. (throw :skip nil)
  6599. (goto-char (match-beginning 0))
  6600. (setq hdmarker (org-agenda-new-marker (point))
  6601. inherited-tags
  6602. (or (eq org-agenda-show-inherited-tags 'always)
  6603. (and (listp org-agenda-show-inherited-tags)
  6604. (memq 'agenda org-agenda-show-inherited-tags))
  6605. (and (eq org-agenda-show-inherited-tags t)
  6606. (or (eq org-agenda-use-tag-inheritance t)
  6607. (memq 'agenda org-agenda-use-tag-inheritance))))
  6608. tags (org-get-tags nil (not inherited-tags)))
  6609. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  6610. (looking-at "\\*+[ \t]+\\(.*\\)")
  6611. (setq head (match-string 1))
  6612. (let ((remove-re
  6613. (if org-agenda-remove-timeranges-from-blocks
  6614. (concat
  6615. "<" (regexp-quote s1) ".*?>"
  6616. "--"
  6617. "<" (regexp-quote s2) ".*?>")
  6618. nil)))
  6619. (setq txt (org-agenda-format-item
  6620. (format
  6621. (nth (if (= d1 d2) 0 1)
  6622. org-agenda-timerange-leaders)
  6623. (1+ (- d0 d1)) (1+ (- d2 d1)))
  6624. (org-add-props head nil
  6625. 'effort effort
  6626. 'effort-minutes effort-minutes)
  6627. level category tags
  6628. (save-match-data
  6629. (let ((hhmm1 (and (string-match org-ts-regexp1 s1)
  6630. (match-string 6 s1)))
  6631. (hhmm2 (and (string-match org-ts-regexp1 s2)
  6632. (match-string 6 s2))))
  6633. (cond ((string= hhmm1 hhmm2)
  6634. (concat "<" start-time ">--<" end-time ">"))
  6635. ((and (= d1 d0) (= d2 d0))
  6636. (concat "<" start-time ">--<" end-time ">"))
  6637. ((= d1 d0)
  6638. (concat "<" start-time ">"))
  6639. ((= d2 d0)
  6640. (concat "<" end-time ">")))))
  6641. remove-re))))
  6642. (org-add-props txt props
  6643. 'org-marker marker 'org-hd-marker hdmarker
  6644. 'type "block" 'date date
  6645. 'level level
  6646. 'effort effort 'effort-minutes effort-minutes
  6647. 'todo-state todo-state
  6648. 'priority (org-get-priority txt))
  6649. (push txt ee))))
  6650. (goto-char pos)))
  6651. ;; Sort the entries by expiration date.
  6652. (nreverse ee)))
  6653. ;;; Agenda presentation and sorting
  6654. (defvar org-prefix-has-time nil
  6655. "A flag, set by `org-compile-prefix-format'.
  6656. The flag is set if the currently compiled format contains a `%t'.")
  6657. (defvar org-prefix-has-tag nil
  6658. "A flag, set by `org-compile-prefix-format'.
  6659. The flag is set if the currently compiled format contains a `%T'.")
  6660. (defvar org-prefix-has-effort nil
  6661. "A flag, set by `org-compile-prefix-format'.
  6662. The flag is set if the currently compiled format contains a `%e'.")
  6663. (defvar org-prefix-has-breadcrumbs nil
  6664. "A flag, set by `org-compile-prefix-format'.
  6665. The flag is set if the currently compiled format contains a `%b'.")
  6666. (defvar org-prefix-category-length nil
  6667. "Used by `org-compile-prefix-format' to remember the category field width.")
  6668. (defvar org-prefix-category-max-length nil
  6669. "Used by `org-compile-prefix-format' to remember the category field width.")
  6670. (defun org-agenda-get-category-icon (category)
  6671. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  6672. (cl-dolist (entry org-agenda-category-icon-alist)
  6673. (when (string-match-p (car entry) category)
  6674. (if (listp (cadr entry))
  6675. (cl-return (cadr entry))
  6676. (cl-return (apply #'create-image (cdr entry)))))))
  6677. (defun org-agenda-format-item (extra txt &optional with-level with-category tags dotime
  6678. remove-re habitp)
  6679. "Format TXT to be inserted into the agenda buffer.
  6680. In particular, add the prefix and corresponding text properties.
  6681. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  6682. WITH-LEVEL may be a string to replace the `%l' specifier.
  6683. WITH-CATEGORY (a string, a symbol or nil) may be used to overrule the default
  6684. category taken from local variable or file name. It will replace the `%c'
  6685. specifier in the format.
  6686. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  6687. TXT for sorting of this entry, and for the `%t' specifier in the format.
  6688. When DOTIME is a string, this string is searched for a time before TXT is.
  6689. TAGS can be the tags of the headline.
  6690. Any match of REMOVE-RE will be removed from TXT."
  6691. ;; We keep the org-prefix-* variable values along with a compiled
  6692. ;; formatter, so that multiple agendas existing at the same time do
  6693. ;; not step on each other toes.
  6694. ;;
  6695. ;; It was inconvenient to make these variables buffer local in
  6696. ;; Agenda buffers, because this function expects to be called with
  6697. ;; the buffer where item comes from being current, and not agenda
  6698. ;; buffer
  6699. (let* ((bindings (car org-prefix-format-compiled))
  6700. (formatter (cadr org-prefix-format-compiled)))
  6701. (cl-loop for (var value) in bindings
  6702. do (set var value))
  6703. (save-match-data
  6704. ;; Diary entries sometimes have extra whitespace at the beginning
  6705. (setq txt (org-trim txt))
  6706. ;; Fix the tags part in txt
  6707. (setq txt (org-agenda-fix-displayed-tags
  6708. txt tags
  6709. org-agenda-show-inherited-tags
  6710. org-agenda-hide-tags-regexp))
  6711. (with-no-warnings
  6712. ;; `time', `tag', `effort' are needed for the eval of the prefix format.
  6713. ;; Based on what I see in `org-compile-prefix-format', I added
  6714. ;; a few more.
  6715. (defvar breadcrumbs) (defvar category) (defvar category-icon)
  6716. (defvar effort) (defvar extra)
  6717. (defvar level) (defvar tag) (defvar time))
  6718. (let* ((category (or with-category
  6719. (if buffer-file-name
  6720. (file-name-sans-extension
  6721. (file-name-nondirectory buffer-file-name))
  6722. "")))
  6723. (category-icon (org-agenda-get-category-icon category))
  6724. (category-icon (if category-icon
  6725. (propertize " " 'display category-icon)
  6726. ""))
  6727. (effort (and (not (string= txt ""))
  6728. (get-text-property 1 'effort txt)))
  6729. (tag (if tags (nth (1- (length tags)) tags) ""))
  6730. (time-grid-trailing-characters (nth 2 org-agenda-time-grid))
  6731. (extra (or (and (not habitp) extra) ""))
  6732. time
  6733. (ts (when dotime (concat
  6734. (if (stringp dotime) dotime "")
  6735. (and org-agenda-search-headline-for-time txt))))
  6736. (time-of-day (and dotime (org-get-time-of-day ts)))
  6737. stamp plain s0 s1 s2 rtn srp l
  6738. duration breadcrumbs)
  6739. (and (derived-mode-p 'org-mode) buffer-file-name
  6740. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6741. (when (and dotime time-of-day)
  6742. ;; Extract starting and ending time and move them to prefix
  6743. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6744. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6745. (setq s0 (match-string 0 ts)
  6746. srp (and stamp (match-end 3))
  6747. s1 (match-string (if plain 1 2) ts)
  6748. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6749. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6750. ;; them, we might want to remove them there to avoid duplication.
  6751. ;; The user can turn this off with a variable.
  6752. (when (and org-prefix-has-time
  6753. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6754. (string-match (concat (regexp-quote s0) " *") txt)
  6755. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6756. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6757. (= (match-beginning 0) 0)
  6758. t))
  6759. (setq txt (replace-match "" nil nil txt))))
  6760. ;; Normalize the time(s) to 24 hour.
  6761. (when s1 (setq s1 (org-get-time-of-day s1 t)))
  6762. (when s2 (setq s2 (org-get-time-of-day s2 t)))
  6763. ;; Try to set s2 if s1 and
  6764. ;; `org-agenda-default-appointment-duration' are set
  6765. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6766. (setq s2
  6767. (org-duration-from-minutes
  6768. (+ (org-duration-to-minutes s1 t)
  6769. org-agenda-default-appointment-duration)
  6770. nil t)))
  6771. ;; Compute the duration
  6772. (when s2
  6773. (setq duration (- (org-duration-to-minutes s2)
  6774. (org-duration-to-minutes s1))))
  6775. ;; Format S1 and S2 for display.
  6776. (when s1 (setq s1 (format "%5s" (org-get-time-of-day s1 'overtime))))
  6777. (when s2 (setq s2 (org-get-time-of-day s2 'overtime))))
  6778. (when (string-match org-tag-group-re txt)
  6779. ;; Tags are in the string
  6780. (if (or (eq org-agenda-remove-tags t)
  6781. (and org-agenda-remove-tags
  6782. org-prefix-has-tag))
  6783. (setq txt (replace-match "" t t txt))
  6784. (setq txt (replace-match
  6785. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6786. (match-string 1 txt))
  6787. t t txt))))
  6788. (when remove-re
  6789. (while (string-match remove-re txt)
  6790. (setq txt (replace-match "" t t txt))))
  6791. ;; Set org-heading property on `txt' to mark the start of the
  6792. ;; heading.
  6793. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6794. ;; Prepare the variables needed in the eval of the compiled format
  6795. (when org-prefix-has-breadcrumbs
  6796. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6797. (let ((s (org-format-outline-path (org-get-outline-path)
  6798. (1- (frame-width))
  6799. nil org-agenda-breadcrumbs-separator)))
  6800. (if (eq "" s) "" (concat s org-agenda-breadcrumbs-separator))))))
  6801. (setq time (cond (s2 (concat
  6802. (org-agenda-time-of-day-to-ampm-maybe s1)
  6803. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6804. (when org-agenda-timegrid-use-ampm " ")))
  6805. (s1 (concat
  6806. (org-agenda-time-of-day-to-ampm-maybe s1)
  6807. (if org-agenda-timegrid-use-ampm
  6808. (concat time-grid-trailing-characters " ")
  6809. time-grid-trailing-characters)))
  6810. (t ""))
  6811. category (if (symbolp category) (symbol-name category) category)
  6812. level (or with-level ""))
  6813. (if (string-match org-link-bracket-re category)
  6814. (progn
  6815. (setq l (string-width (or (match-string 2) (match-string 1))))
  6816. (when (< l (or org-prefix-category-length 0))
  6817. (setq category (copy-sequence category))
  6818. (org-add-props category nil
  6819. 'extra-space (make-string
  6820. (- org-prefix-category-length l 1) ?\ ))))
  6821. (when (and org-prefix-category-max-length
  6822. (>= (length category) org-prefix-category-max-length))
  6823. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6824. ;; Evaluate the compiled format
  6825. (setq rtn (concat (eval formatter t) txt))
  6826. ;; And finally add the text properties
  6827. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6828. (org-add-props rtn nil
  6829. 'org-category category
  6830. 'tags tags
  6831. 'org-priority-highest org-priority-highest
  6832. 'org-priority-lowest org-priority-lowest
  6833. 'time-of-day time-of-day
  6834. 'duration duration
  6835. 'breadcrumbs breadcrumbs
  6836. 'txt txt
  6837. 'level level
  6838. 'time time
  6839. 'extra extra
  6840. 'format org-prefix-format-compiled
  6841. 'dotime dotime)))))
  6842. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6843. "Remove tags string from TXT, and add a modified list of tags.
  6844. The modified list may contain inherited tags, and tags matched by
  6845. `org-agenda-hide-tags-regexp' will be removed."
  6846. (when (or add-inherited hide-re)
  6847. (when (string-match org-tag-group-re txt)
  6848. (setq txt (substring txt 0 (match-beginning 0))))
  6849. (setq tags
  6850. (delq nil
  6851. (mapcar (lambda (tg)
  6852. (if (or (and hide-re (string-match hide-re tg))
  6853. (and (not add-inherited)
  6854. (get-text-property 0 'inherited tg)))
  6855. nil
  6856. tg))
  6857. tags)))
  6858. (when tags
  6859. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6860. i)
  6861. (setq txt (concat txt " :"
  6862. (mapconcat
  6863. (lambda (x)
  6864. (setq i (get-text-property 0 'inherited x))
  6865. (if (and have-i (not i))
  6866. (progn
  6867. (setq have-i nil)
  6868. (concat ":" x))
  6869. x))
  6870. tags ":")
  6871. (if have-i "::" ":"))))))
  6872. txt)
  6873. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6874. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6875. "Add a time-grid for agenda items which need it.
  6876. LIST is the list of agenda items formatted by `org-agenda-list'.
  6877. NDAYS is the span of the current agenda view.
  6878. TODAYP is t when the current agenda view is on today."
  6879. (catch 'exit
  6880. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6881. ((and todayp (member 'today (car org-agenda-time-grid))))
  6882. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6883. ((member 'weekly (car org-agenda-time-grid)))
  6884. (t (throw 'exit list)))
  6885. (let* ((have (delq nil (mapcar
  6886. (lambda (x) (get-text-property 1 'time-of-day x))
  6887. list)))
  6888. (string (nth 3 org-agenda-time-grid))
  6889. (gridtimes (nth 1 org-agenda-time-grid))
  6890. (req (car org-agenda-time-grid))
  6891. (remove (member 'remove-match req))
  6892. new time)
  6893. (when (and (member 'require-timed req) (not have))
  6894. ;; don't show empty grid
  6895. (throw 'exit list))
  6896. (while (setq time (pop gridtimes))
  6897. (unless (and remove (member time have))
  6898. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6899. (push (org-agenda-format-item
  6900. nil string nil "" nil
  6901. (concat (substring time 0 -2) ":" (substring time -2)))
  6902. new)
  6903. (put-text-property
  6904. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6905. (when (and todayp org-agenda-show-current-time-in-grid)
  6906. (push (org-agenda-format-item
  6907. nil org-agenda-current-time-string nil "" nil
  6908. (format-time-string "%H:%M "))
  6909. new)
  6910. (put-text-property
  6911. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6912. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6913. (append new list)
  6914. (append list new)))))
  6915. (defun org-compile-prefix-format (key)
  6916. "Compile the prefix format into a Lisp form that can be evaluated.
  6917. KEY is the agenda type (see `org-agenda-prefix-format').
  6918. The resulting form and associated variable bindings is returned
  6919. and stored in the variable `org-prefix-format-compiled'."
  6920. (setq org-prefix-has-time nil
  6921. org-prefix-has-tag nil
  6922. org-prefix-category-length nil
  6923. org-prefix-has-effort nil
  6924. org-prefix-has-breadcrumbs nil)
  6925. (let ((s (cond
  6926. ((stringp org-agenda-prefix-format)
  6927. org-agenda-prefix-format)
  6928. ((assq key org-agenda-prefix-format)
  6929. (cdr (assq key org-agenda-prefix-format)))
  6930. (t " %-12:c%?-12t% s")))
  6931. (start 0)
  6932. varform vars var c f opt) ;; e
  6933. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+?)\\)"
  6934. s start)
  6935. (setq var (or (cdr (assoc (match-string 4 s)
  6936. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6937. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6938. 'eval)
  6939. c (or (match-string 3 s) "")
  6940. opt (match-beginning 1)
  6941. start (1+ (match-beginning 0)))
  6942. (cl-case var
  6943. (time (setq org-prefix-has-time t))
  6944. (tag (setq org-prefix-has-tag t))
  6945. (effort (setq org-prefix-has-effort t))
  6946. (breadcrumbs (setq org-prefix-has-breadcrumbs t)))
  6947. (setq f (concat "%" (match-string 2 s) "s"))
  6948. (when (eq var 'category)
  6949. (setq org-prefix-category-length
  6950. (floor (abs (string-to-number (match-string 2 s)))))
  6951. (setq org-prefix-category-max-length
  6952. (let ((x (match-string 2 s)))
  6953. (save-match-data
  6954. (and (string-match "\\.[0-9]+" x)
  6955. (string-to-number (substring (match-string 0 x) 1)))))))
  6956. (if (eq var 'eval)
  6957. (setq varform `(format ,f (org-eval ,(read (substring s (match-beginning 4))))))
  6958. (if opt
  6959. (setq varform
  6960. `(if (member ,var '("" nil))
  6961. ""
  6962. (format ,f (concat ,var ,c))))
  6963. (setq varform
  6964. `(format ,f (if (member ,var '("" nil)) ""
  6965. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6966. (if (eq var 'eval)
  6967. (setf (substring s (match-beginning 0)
  6968. (+ (match-beginning 4)
  6969. (length (format "%S" (read (substring s (match-beginning 4)))))))
  6970. "%s")
  6971. (setq s (replace-match "%s" t nil s)))
  6972. (push varform vars))
  6973. (setq vars (nreverse vars))
  6974. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6975. (setq org-prefix-format-compiled
  6976. (list
  6977. `((org-prefix-has-time ,org-prefix-has-time)
  6978. (org-prefix-has-tag ,org-prefix-has-tag)
  6979. (org-prefix-category-length ,org-prefix-category-length)
  6980. (org-prefix-has-effort ,org-prefix-has-effort)
  6981. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6982. `(format ,s ,@vars))))))
  6983. (defun org-set-sorting-strategy (key)
  6984. (setq org-agenda-sorting-strategy-selected
  6985. (if (symbolp (car org-agenda-sorting-strategy))
  6986. ;; the old format
  6987. org-agenda-sorting-strategy
  6988. (or (cdr (assq key org-agenda-sorting-strategy))
  6989. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6990. '(time-up category-keep priority-down)))))
  6991. (defun org-get-time-of-day (s &optional string)
  6992. "Check string S for a time of day.
  6993. If found, return it as a military time number between 0 and 2400.
  6994. If not found, return nil.
  6995. The optional STRING argument forces conversion into a 5 character wide string
  6996. HH:MM. When it is `overtime', any time above 24:00 is turned into \"+H:MM\"
  6997. where H:MM is the duration above midnight."
  6998. (let ((case-fold-search t)
  6999. (time-regexp
  7000. (rx word-start
  7001. (group (opt (any "012")) digit) ;group 1: hours
  7002. (or (and ":" (group (any "012345") digit) ;group 2: minutes
  7003. (opt (group (or "am" "pm")))) ;group 3: am/pm
  7004. ;; Special "HHam/pm" case.
  7005. (group-n 3 (or "am" "pm")))
  7006. word-end)))
  7007. (save-match-data
  7008. (when (and (string-match time-regexp s)
  7009. (not (eq 'org-link (get-text-property 1 'face s))))
  7010. (let ((hours
  7011. (let* ((ampm (and (match-end 3) (downcase (match-string 3 s))))
  7012. (am-p (equal ampm "am")))
  7013. (pcase (string-to-number (match-string 1 s))
  7014. ((and (guard (not ampm)) h) h)
  7015. (12 (if am-p 0 12))
  7016. (h (+ h (if am-p 0 12))))))
  7017. (minutes
  7018. (if (match-end 2)
  7019. (string-to-number (match-string 2 s))
  7020. 0)))
  7021. (pcase string
  7022. (`nil (+ minutes (* hours 100)))
  7023. ((and `overtime
  7024. (guard (or (> hours 24)
  7025. (and (= hours 24)
  7026. (> minutes 0)))))
  7027. (format "+%d:%02d" (- hours 24) minutes))
  7028. ((guard org-agenda-time-leading-zero)
  7029. (format "%02d:%02d" hours minutes))
  7030. (_
  7031. (format "%d:%02d" hours minutes))))))))
  7032. (defvar org-agenda-before-sorting-filter-function nil
  7033. "Function to be applied to agenda items prior to sorting.
  7034. Prior to sorting also means just before they are inserted into the agenda.
  7035. To aid sorting, you may revisit the original entries and add more text
  7036. properties which will later be used by the sorting functions.
  7037. The function should take a string argument, an agenda line.
  7038. It has access to the text properties in that line, which contain among
  7039. other things, the property `org-hd-marker' that points to the entry
  7040. where the line comes from. Note that not all lines going into the agenda
  7041. have this property, only most.
  7042. The function should return the modified string. It is probably best
  7043. to ONLY change text properties.
  7044. You can also use this function as a filter, by returning nil for lines
  7045. you don't want to have in the agenda at all. For this application, you
  7046. could bind the variable in the options section of a custom command.")
  7047. (defun org-agenda-finalize-entries (list &optional type)
  7048. "Sort, limit and concatenate the LIST of agenda items.
  7049. The optional argument TYPE tells the agenda type."
  7050. (let ((max-effort (cond ((listp org-agenda-max-effort)
  7051. (cdr (assoc type org-agenda-max-effort)))
  7052. (t org-agenda-max-effort)))
  7053. (max-todo (cond ((listp org-agenda-max-todos)
  7054. (cdr (assoc type org-agenda-max-todos)))
  7055. (t org-agenda-max-todos)))
  7056. (max-tags (cond ((listp org-agenda-max-tags)
  7057. (cdr (assoc type org-agenda-max-tags)))
  7058. (t org-agenda-max-tags)))
  7059. (max-entries (cond ((listp org-agenda-max-entries)
  7060. (cdr (assoc type org-agenda-max-entries)))
  7061. (t org-agenda-max-entries))))
  7062. (when org-agenda-before-sorting-filter-function
  7063. (setq list
  7064. (delq nil
  7065. (mapcar
  7066. org-agenda-before-sorting-filter-function list))))
  7067. (setq list (mapcar #'org-agenda-highlight-todo list)
  7068. list (mapcar #'identity (sort list #'org-entries-lessp)))
  7069. (when max-effort
  7070. (setq list (org-agenda-limit-entries
  7071. list 'effort-minutes max-effort
  7072. (lambda (e) (or e (if org-agenda-sort-noeffort-is-high
  7073. 32767 -1))))))
  7074. (when max-todo
  7075. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  7076. (when max-tags
  7077. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  7078. (when max-entries
  7079. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  7080. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  7081. (setq list (mapcar #'org-agenda--mark-blocked-entry list)))
  7082. (mapconcat #'identity list "\n")))
  7083. (defun org-agenda-limit-entries (list prop limit &optional fn)
  7084. "Limit the number of agenda entries."
  7085. (let ((include (and limit (< limit 0))))
  7086. (if limit
  7087. (let ((fun (or fn (lambda (p) (when p 1))))
  7088. (lim 0))
  7089. (delq nil
  7090. (mapcar
  7091. (lambda (e)
  7092. (let ((pval (funcall
  7093. fun (get-text-property (1- (length e))
  7094. prop e))))
  7095. (when pval (setq lim (+ lim pval)))
  7096. (cond ((and pval (<= lim (abs limit))) e)
  7097. ((and include (not pval)) e))))
  7098. list)))
  7099. list)))
  7100. (defun org-agenda-limit-interactively (remove)
  7101. "In agenda, interactively limit entries to various maximums."
  7102. (interactive "P")
  7103. (if remove
  7104. (progn (setq org-agenda-max-entries nil
  7105. org-agenda-max-todos nil
  7106. org-agenda-max-tags nil
  7107. org-agenda-max-effort nil)
  7108. (org-agenda-redo))
  7109. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  7110. (msg (cond ((= max ?E) "How many minutes? ")
  7111. ((= max ?e) "How many entries? ")
  7112. ((= max ?t) "How many TODO entries? ")
  7113. ((= max ?T) "How many tagged entries? ")
  7114. (t (user-error "Wrong input"))))
  7115. (num (string-to-number (read-from-minibuffer msg))))
  7116. (cond ((equal max ?e)
  7117. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  7118. ((equal max ?t)
  7119. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  7120. ((equal max ?T)
  7121. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  7122. ((equal max ?E)
  7123. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  7124. (org-agenda-fit-window-to-buffer))
  7125. (defun org-agenda-highlight-todo (x)
  7126. (let ((org-done-keywords org-done-keywords-for-agenda)
  7127. (case-fold-search nil)
  7128. re)
  7129. (if (eq x 'line)
  7130. (save-excursion
  7131. (beginning-of-line 1)
  7132. (setq re (org-get-at-bol 'org-todo-regexp))
  7133. (goto-char (or (text-property-any (line-beginning-position) (line-end-position) 'org-heading t) (point)))
  7134. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  7135. (add-text-properties (match-beginning 0) (match-end 1)
  7136. (list 'face (org-get-todo-face 1)))
  7137. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  7138. (delete-region (match-beginning 1) (1- (match-end 0)))
  7139. (goto-char (match-beginning 1))
  7140. (insert (format org-agenda-todo-keyword-format s)))))
  7141. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  7142. (setq re (get-text-property 0 'org-todo-regexp x))
  7143. (when (and re
  7144. ;; Test `pl' because if there's no heading content,
  7145. ;; there's no point matching to highlight. Note
  7146. ;; that if we didn't test `pl' first, and there
  7147. ;; happened to be no keyword from `org-todo-regexp'
  7148. ;; on this heading line, then the `equal' comparison
  7149. ;; afterwards would spuriously succeed in the case
  7150. ;; where `pl' is nil -- causing an args-out-of-range
  7151. ;; error when we try to add text properties to text
  7152. ;; that isn't there.
  7153. pl
  7154. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  7155. x pl)
  7156. pl))
  7157. (add-text-properties
  7158. (or (match-end 1) (match-end 0)) (match-end 0)
  7159. (list 'face (org-get-todo-face (match-string 2 x)))
  7160. x)
  7161. (when (match-end 1)
  7162. (setq x
  7163. (concat
  7164. (substring x 0 (match-end 1))
  7165. (unless (string= org-agenda-todo-keyword-format "")
  7166. (format org-agenda-todo-keyword-format
  7167. (match-string 2 x)))
  7168. (unless (string= org-agenda-todo-keyword-format "")
  7169. ;; Remove `display' property as the icon could leak
  7170. ;; on the white space.
  7171. (org-add-props " " (org-plist-delete (text-properties-at 0 x)
  7172. 'display)))
  7173. (substring x (match-end 3)))))))
  7174. x)))
  7175. (defsubst org-cmp-values (a b property)
  7176. "Compare the numeric value of text PROPERTY for string A and B."
  7177. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  7178. (pb (or (get-text-property (1- (length b)) property b) 0)))
  7179. (cond ((> pa pb) +1)
  7180. ((< pa pb) -1))))
  7181. (defsubst org-cmp-effort (a b)
  7182. "Compare the effort values of string A and B."
  7183. (let* ((def (if org-agenda-sort-noeffort-is-high 32767 -1))
  7184. ;; `effort-minutes' property is not directly accessible from
  7185. ;; the strings, but is stored as a property in `txt'.
  7186. (ea (or (get-text-property
  7187. 0 'effort-minutes (get-text-property 0 'txt a))
  7188. def))
  7189. (eb (or (get-text-property
  7190. 0 'effort-minutes (get-text-property 0 'txt b))
  7191. def)))
  7192. (cond ((> ea eb) +1)
  7193. ((< ea eb) -1))))
  7194. (defsubst org-cmp-category (a b)
  7195. "Compare the string values of categories of strings A and B."
  7196. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  7197. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  7198. (cond ((string-lessp ca cb) -1)
  7199. ((string-lessp cb ca) +1))))
  7200. (defsubst org-cmp-todo-state (a b)
  7201. "Compare the todo states of strings A and B."
  7202. (let* ((ma (or (get-text-property 1 'org-marker a)
  7203. (get-text-property 1 'org-hd-marker a)))
  7204. (mb (or (get-text-property 1 'org-marker b)
  7205. (get-text-property 1 'org-hd-marker b)))
  7206. (fa (and ma (marker-buffer ma)))
  7207. (fb (and mb (marker-buffer mb)))
  7208. (todo-kwds
  7209. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  7210. (and fb (with-current-buffer fb org-todo-keywords-1))))
  7211. (ta (or (get-text-property 1 'todo-state a) ""))
  7212. (tb (or (get-text-property 1 'todo-state b) ""))
  7213. (la (- (length (member ta todo-kwds))))
  7214. (lb (- (length (member tb todo-kwds))))
  7215. (donepa (member ta org-done-keywords-for-agenda))
  7216. (donepb (member tb org-done-keywords-for-agenda)))
  7217. (cond ((and donepa (not donepb)) -1)
  7218. ((and (not donepa) donepb) +1)
  7219. ((< la lb) -1)
  7220. ((< lb la) +1))))
  7221. (defsubst org-cmp-alpha (a b)
  7222. "Compare the headlines, alphabetically."
  7223. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  7224. (plb (text-property-any 0 (length b) 'org-heading t b))
  7225. (ta (and pla (substring a pla)))
  7226. (tb (and plb (substring b plb)))
  7227. (case-fold-search nil))
  7228. (when pla
  7229. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  7230. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  7231. ta)
  7232. (setq ta (substring ta (match-end 0))))
  7233. (setq ta (downcase ta)))
  7234. (when plb
  7235. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  7236. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  7237. tb)
  7238. (setq tb (substring tb (match-end 0))))
  7239. (setq tb (downcase tb)))
  7240. (cond ((not (or ta tb)) nil)
  7241. ((not ta) +1)
  7242. ((not tb) -1)
  7243. ((string-lessp ta tb) -1)
  7244. ((string-lessp tb ta) +1))))
  7245. (defsubst org-cmp-tag (a b)
  7246. "Compare the string values of the first tags of A and B."
  7247. (let ((ta (car (last (get-text-property 1 'tags a))))
  7248. (tb (car (last (get-text-property 1 'tags b)))))
  7249. (cond ((not (or ta tb)) nil)
  7250. ((not ta) +1)
  7251. ((not tb) -1)
  7252. ((string-lessp ta tb) -1)
  7253. ((string-lessp tb ta) +1))))
  7254. (defsubst org-cmp-time (a b)
  7255. "Compare the time-of-day values of strings A and B."
  7256. (let* ((def (if org-agenda-sort-notime-is-late 9901 -1))
  7257. (ta (or (get-text-property 1 'time-of-day a) def))
  7258. (tb (or (get-text-property 1 'time-of-day b) def)))
  7259. (cond ((< ta tb) -1)
  7260. ((< tb ta) +1))))
  7261. (defsubst org-cmp-ts (a b type)
  7262. "Compare the timestamps values of entries A and B.
  7263. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  7264. \"timestamp_ia\", compare within each of these type. When TYPE
  7265. is the empty string, compare all timestamps without respect of
  7266. their type."
  7267. (let* ((def (if org-agenda-sort-notime-is-late 99999999 -1))
  7268. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  7269. (get-text-property 1 'ts-date a))
  7270. def))
  7271. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  7272. (get-text-property 1 'ts-date b))
  7273. def)))
  7274. (cond ((if ta (and tb (< ta tb)) tb) -1)
  7275. ((if tb (and ta (< tb ta)) ta) +1))))
  7276. (defsubst org-cmp-habit-p (a b)
  7277. "Compare the todo states of strings A and B."
  7278. (let ((ha (get-text-property 1 'org-habit-p a))
  7279. (hb (get-text-property 1 'org-habit-p b)))
  7280. (cond ((and ha (not hb)) -1)
  7281. ((and (not ha) hb) +1))))
  7282. (defun org-entries-lessp (a b)
  7283. "Predicate for sorting agenda entries."
  7284. ;; The following variables will be used when the form is evaluated.
  7285. ;; So even though the compiler complains, keep them.
  7286. (let ((ss org-agenda-sorting-strategy-selected))
  7287. (org-dlet
  7288. ((timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  7289. (org-cmp-ts a b "")))
  7290. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  7291. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  7292. (org-cmp-ts a b "scheduled")))
  7293. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  7294. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  7295. (org-cmp-ts a b "deadline")))
  7296. (deadline-down (if deadline-up (- deadline-up) nil))
  7297. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  7298. (org-cmp-ts a b "timestamp_ia")))
  7299. (tsia-down (if tsia-up (- tsia-up) nil))
  7300. (ts-up (and (org-em 'ts-up 'ts-down ss)
  7301. (org-cmp-ts a b "timestamp")))
  7302. (ts-down (if ts-up (- ts-up) nil))
  7303. (time-up (and (org-em 'time-up 'time-down ss)
  7304. (org-cmp-time a b)))
  7305. (time-down (if time-up (- time-up) nil))
  7306. (stats-up (and (org-em 'stats-up 'stats-down ss)
  7307. (org-cmp-values a b 'org-stats)))
  7308. (stats-down (if stats-up (- stats-up) nil))
  7309. (priority-up (and (org-em 'priority-up 'priority-down ss)
  7310. (org-cmp-values a b 'priority)))
  7311. (priority-down (if priority-up (- priority-up) nil))
  7312. (effort-up (and (org-em 'effort-up 'effort-down ss)
  7313. (org-cmp-effort a b)))
  7314. (effort-down (if effort-up (- effort-up) nil))
  7315. (category-up (and (or (org-em 'category-up 'category-down ss)
  7316. (memq 'category-keep ss))
  7317. (org-cmp-category a b)))
  7318. (category-down (if category-up (- category-up) nil))
  7319. (category-keep (if category-up +1 nil))
  7320. (tag-up (and (org-em 'tag-up 'tag-down ss)
  7321. (org-cmp-tag a b)))
  7322. (tag-down (if tag-up (- tag-up) nil))
  7323. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  7324. (org-cmp-todo-state a b)))
  7325. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  7326. (habit-up (and (org-em 'habit-up 'habit-down ss)
  7327. (org-cmp-habit-p a b)))
  7328. (habit-down (if habit-up (- habit-up) nil))
  7329. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  7330. (org-cmp-alpha a b)))
  7331. (alpha-down (if alpha-up (- alpha-up) nil))
  7332. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  7333. user-defined-up user-defined-down)
  7334. (when (and need-user-cmp org-agenda-cmp-user-defined
  7335. (functionp org-agenda-cmp-user-defined))
  7336. (setq user-defined-up
  7337. (funcall org-agenda-cmp-user-defined a b)
  7338. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  7339. (cdr (assoc
  7340. (eval (cons 'or org-agenda-sorting-strategy-selected) t)
  7341. '((-1 . t) (1 . nil) (nil . nil)))))))
  7342. ;;; Agenda restriction lock
  7343. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  7344. "Overlay to mark the headline to which agenda commands are restricted.")
  7345. (overlay-put org-agenda-restriction-lock-overlay
  7346. 'face 'org-agenda-restriction-lock)
  7347. (overlay-put org-agenda-restriction-lock-overlay
  7348. 'help-echo "Agendas are currently limited to this subtree.")
  7349. (delete-overlay org-agenda-restriction-lock-overlay)
  7350. (defun org-agenda-set-restriction-lock-from-agenda (arg)
  7351. "Set the restriction lock to the agenda item at point from within the agenda.
  7352. When called with a `\\[universal-argument]' prefix, restrict to
  7353. the file which contains the item.
  7354. Argument ARG is the prefix argument."
  7355. (interactive "P")
  7356. (unless (derived-mode-p 'org-agenda-mode)
  7357. (user-error "Not in an Org agenda buffer"))
  7358. (let* ((marker (or (org-get-at-bol 'org-marker)
  7359. (org-agenda-error)))
  7360. (buffer (marker-buffer marker))
  7361. (pos (marker-position marker)))
  7362. (with-current-buffer buffer
  7363. (goto-char pos)
  7364. (org-agenda-set-restriction-lock arg))))
  7365. ;;;###autoload
  7366. (defun org-agenda-set-restriction-lock (&optional type)
  7367. "Set restriction lock for agenda to current subtree or file.
  7368. When in a restricted subtree, remove it.
  7369. The restriction will span over the entire file if TYPE is `file',
  7370. or if TYPE is (4), or if the cursor is before the first headline
  7371. in the file. Otherwise, only apply the restriction to the current
  7372. subtree."
  7373. (interactive "P")
  7374. (if (and org-agenda-overriding-restriction
  7375. (member org-agenda-restriction-lock-overlay
  7376. (overlays-at (point)))
  7377. (equal (overlay-start org-agenda-restriction-lock-overlay)
  7378. (point)))
  7379. (org-agenda-remove-restriction-lock 'noupdate)
  7380. (org-agenda-remove-restriction-lock 'noupdate)
  7381. (and (equal type '(4)) (setq type 'file))
  7382. (setq type (cond
  7383. (type type)
  7384. ((org-at-heading-p) 'subtree)
  7385. ((condition-case nil (org-back-to-heading t) (error nil))
  7386. 'subtree)
  7387. (t 'file)))
  7388. (if (eq type 'subtree)
  7389. (progn
  7390. (setq org-agenda-restrict (current-buffer))
  7391. (setq org-agenda-overriding-restriction 'subtree)
  7392. (put 'org-agenda-files 'org-restrict
  7393. (list (buffer-file-name (buffer-base-buffer))))
  7394. (org-back-to-heading t)
  7395. (move-overlay org-agenda-restriction-lock-overlay
  7396. (point)
  7397. (if org-agenda-restriction-lock-highlight-subtree
  7398. (save-excursion (org-end-of-subtree t t) (point))
  7399. (line-end-position)))
  7400. (move-marker org-agenda-restrict-begin (point))
  7401. (move-marker org-agenda-restrict-end
  7402. (save-excursion (org-end-of-subtree t t)))
  7403. (message "Locking agenda restriction to subtree"))
  7404. (put 'org-agenda-files 'org-restrict
  7405. (list (buffer-file-name (buffer-base-buffer))))
  7406. (setq org-agenda-restrict nil)
  7407. (setq org-agenda-overriding-restriction 'file)
  7408. (move-marker org-agenda-restrict-begin nil)
  7409. (move-marker org-agenda-restrict-end nil)
  7410. (message "Locking agenda restriction to file"))
  7411. (setq current-prefix-arg nil))
  7412. (org-agenda-maybe-redo))
  7413. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  7414. "Remove agenda restriction lock."
  7415. (interactive "P")
  7416. (if (not (or org-agenda-restrict org-agenda-overriding-restriction))
  7417. (message "No agenda restriction to remove.")
  7418. (delete-overlay org-agenda-restriction-lock-overlay)
  7419. (delete-overlay org-speedbar-restriction-lock-overlay)
  7420. (setq org-agenda-overriding-restriction nil)
  7421. (unless org-agenda-keep-restricted-file-list
  7422. ;; There is a request to keep the file list in place
  7423. (put 'org-agenda-files 'org-restrict nil))
  7424. (setq org-agenda-restrict nil)
  7425. (put 'org-agenda-files 'org-restrict nil)
  7426. (move-marker org-agenda-restrict-begin nil)
  7427. (move-marker org-agenda-restrict-end nil)
  7428. (setq current-prefix-arg nil)
  7429. (message "Agenda restriction lock removed")
  7430. (or noupdate (org-agenda-maybe-redo))))
  7431. (defun org-agenda-maybe-redo ()
  7432. "If there is any window showing the agenda view, update it."
  7433. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  7434. org-agenda-buffer-name)
  7435. t))
  7436. (w0 (selected-window)))
  7437. (when w
  7438. (select-window w)
  7439. (org-agenda-redo)
  7440. (select-window w0)
  7441. (if org-agenda-overriding-restriction
  7442. (message "Agenda view shifted to new %s restriction"
  7443. org-agenda-overriding-restriction)
  7444. (message "Agenda restriction lock removed")))))
  7445. ;;; Agenda commands
  7446. (defun org-agenda-check-type (error &rest types)
  7447. "Check if agenda buffer or component is of allowed type.
  7448. If ERROR is non-nil, throw an error, otherwise just return nil.
  7449. Allowed types are `agenda' `todo' `tags' `search'."
  7450. (cond ((not org-agenda-type)
  7451. (error "No Org agenda currently displayed"))
  7452. ((memq org-agenda-type types) t)
  7453. (error
  7454. (error "Not allowed in '%s'-type agenda buffer or component" org-agenda-type))
  7455. (t nil)))
  7456. (defun org-agenda-Quit ()
  7457. "Exit the agenda, killing the agenda buffer.
  7458. Like `org-agenda-quit', but kill the buffer even when
  7459. `org-agenda-sticky' is non-nil."
  7460. (interactive)
  7461. (org-agenda--quit))
  7462. (defun org-agenda-quit ()
  7463. "Exit the agenda.
  7464. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  7465. instead of killing it.
  7466. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  7467. the pre-agenda window configuration.
  7468. When column view is active, exit column view instead of the
  7469. agenda."
  7470. (interactive)
  7471. (org-agenda--quit org-agenda-sticky))
  7472. (defun org-agenda--quit (&optional bury)
  7473. (if org-agenda-columns-active
  7474. (org-columns-quit)
  7475. (let ((wconf org-agenda-pre-window-conf)
  7476. (buf (current-buffer))
  7477. (org-agenda-last-indirect-window
  7478. (and (eq org-indirect-buffer-display 'other-window)
  7479. org-agenda-last-indirect-buffer
  7480. (get-buffer-window org-agenda-last-indirect-buffer))))
  7481. (cond
  7482. ((eq org-agenda-window-setup 'other-frame)
  7483. (delete-frame))
  7484. ((eq org-agenda-window-setup 'other-tab)
  7485. (if (fboundp 'tab-bar-close-tab)
  7486. (tab-bar-close-tab)
  7487. (user-error "Your version of Emacs does not have tab bar mode support")))
  7488. ((and org-agenda-restore-windows-after-quit
  7489. wconf)
  7490. ;; Maybe restore the pre-agenda window configuration. Reset
  7491. ;; `org-agenda-pre-window-conf' before running
  7492. ;; `set-window-configuration', which loses the current buffer.
  7493. (setq org-agenda-pre-window-conf nil)
  7494. (set-window-configuration wconf))
  7495. (t
  7496. (when org-agenda-last-indirect-window
  7497. (delete-window org-agenda-last-indirect-window))
  7498. (and (not (eq org-agenda-window-setup 'current-window))
  7499. (not (one-window-p))
  7500. (delete-window))))
  7501. (if bury
  7502. ;; Set the agenda buffer as the current buffer instead of
  7503. ;; passing it as an argument to `bury-buffer' so that
  7504. ;; `bury-buffer' removes it from the window.
  7505. (with-current-buffer buf
  7506. (bury-buffer))
  7507. (kill-buffer buf)
  7508. (setq org-agenda-archives-mode nil
  7509. org-agenda-buffer nil)))))
  7510. (defun org-agenda-exit ()
  7511. "Exit the agenda, killing Org buffers loaded by the agenda.
  7512. Like `org-agenda-Quit', but kill any buffers that were created by
  7513. the agenda. Org buffers visited directly by the user will not be
  7514. touched. Also, exit the agenda even if it is in column view."
  7515. (interactive)
  7516. (when org-agenda-columns-active
  7517. (org-columns-quit))
  7518. (org-release-buffers org-agenda-new-buffers)
  7519. (setq org-agenda-new-buffers nil)
  7520. (org-agenda-Quit))
  7521. (defun org-agenda-kill-all-agenda-buffers ()
  7522. "Kill all buffers in `org-agenda-mode'.
  7523. This is used when toggling sticky agendas."
  7524. (interactive)
  7525. (let (blist)
  7526. (dolist (buf (buffer-list))
  7527. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  7528. (push buf blist)))
  7529. (mapc #'kill-buffer blist)))
  7530. (defun org-agenda-execute (arg)
  7531. "Execute another agenda command, keeping same window.
  7532. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  7533. in the agenda."
  7534. (interactive "P")
  7535. (let ((org-agenda-window-setup 'current-window))
  7536. (org-agenda arg)))
  7537. (defun org-agenda-redo (&optional all)
  7538. "Rebuild possibly ALL agenda view(s) in the current buffer."
  7539. (interactive "P")
  7540. (defvar org-agenda-tag-filter-while-redo) ;FIXME: Where is this var used?
  7541. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  7542. (cpa (unless (eq all t) current-prefix-arg))
  7543. (org-agenda-doing-sticky-redo org-agenda-sticky)
  7544. (org-agenda-sticky nil)
  7545. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  7546. org-agenda-buffer-name))
  7547. (org-agenda-keep-modes t)
  7548. (tag-filter org-agenda-tag-filter)
  7549. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  7550. (top-hl-filter org-agenda-top-headline-filter)
  7551. (cat-filter org-agenda-category-filter)
  7552. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  7553. (re-filter org-agenda-regexp-filter)
  7554. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  7555. (effort-filter org-agenda-effort-filter)
  7556. (effort-preset (get 'org-agenda-effort-filter :preset-filter))
  7557. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  7558. (cols org-agenda-columns-active)
  7559. (line (org-current-line))
  7560. (window-line (- line (org-current-line (window-start))))
  7561. (lprops (get 'org-agenda-redo-command 'org-lprops))
  7562. (redo-cmd (get-text-property p 'org-redo-cmd))
  7563. (last-args (get-text-property p 'org-last-args))
  7564. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  7565. (org-agenda-overriding-cmd-arguments
  7566. (unless (eq all t)
  7567. (cond ((listp last-args)
  7568. (cons (or cpa (car last-args)) (cdr last-args)))
  7569. ((stringp last-args)
  7570. last-args))))
  7571. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  7572. (put 'org-agenda-tag-filter :preset-filter nil)
  7573. (put 'org-agenda-category-filter :preset-filter nil)
  7574. (put 'org-agenda-regexp-filter :preset-filter nil)
  7575. (put 'org-agenda-effort-filter :preset-filter nil)
  7576. (and cols (org-columns-quit))
  7577. (message "Rebuilding agenda buffer...")
  7578. (if series-redo-cmd
  7579. (eval series-redo-cmd t)
  7580. (cl-progv
  7581. (mapcar #'car lprops)
  7582. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  7583. (eval redo-cmd t)))
  7584. (setq org-agenda-undo-list nil
  7585. org-agenda-pending-undo-list nil
  7586. org-agenda-tag-filter tag-filter
  7587. org-agenda-category-filter cat-filter
  7588. org-agenda-regexp-filter re-filter
  7589. org-agenda-effort-filter effort-filter
  7590. org-agenda-top-headline-filter top-hl-filter)
  7591. (message "Rebuilding agenda buffer...done")
  7592. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  7593. (put 'org-agenda-category-filter :preset-filter cat-preset)
  7594. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  7595. (put 'org-agenda-effort-filter :preset-filter effort-preset)
  7596. (let ((tag (or tag-filter tag-preset))
  7597. (cat (or cat-filter cat-preset))
  7598. (effort (or effort-filter effort-preset))
  7599. (re (or re-filter re-preset)))
  7600. (when tag (org-agenda-filter-apply tag 'tag t))
  7601. (when cat (org-agenda-filter-apply cat 'category))
  7602. (when effort (org-agenda-filter-apply effort 'effort))
  7603. (when re (org-agenda-filter-apply re 'regexp)))
  7604. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  7605. (and cols (called-interactively-p 'any) (org-agenda-columns))
  7606. (org-goto-line line)
  7607. (when (called-interactively-p 'any) (recenter window-line))))
  7608. (defun org-agenda-redo-all (&optional exhaustive)
  7609. "Rebuild all agenda views in the current buffer.
  7610. With a prefix argument, do so in all agenda buffers."
  7611. (interactive "P")
  7612. (if exhaustive
  7613. (dolist (buffer (buffer-list))
  7614. (with-current-buffer buffer
  7615. (when (derived-mode-p 'org-agenda-mode)
  7616. (org-agenda-redo t))))
  7617. (org-agenda-redo t)))
  7618. (defvar org-global-tags-completion-table nil)
  7619. (defvar org-agenda-filter-form nil)
  7620. (defvar org-agenda-filtered-by-category nil)
  7621. (defsubst org-agenda-get-category ()
  7622. "Return the category of the agenda line."
  7623. (org-get-at-bol 'org-category))
  7624. (defun org-agenda-filter-by-category (strip)
  7625. "Filter lines in the agenda buffer that have a specific category.
  7626. The category is that of the current line.
  7627. With a `\\[universal-argument]' prefix argument, exclude the lines of that category.
  7628. When there is already a category filter in place, this command removes the
  7629. filter."
  7630. (interactive "P")
  7631. (if (and org-agenda-filtered-by-category
  7632. org-agenda-category-filter)
  7633. (org-agenda-filter-show-all-cat)
  7634. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  7635. (cond
  7636. ((and cat strip)
  7637. (org-agenda-filter-apply
  7638. (push (concat "-" cat) org-agenda-category-filter) 'category))
  7639. (cat
  7640. (org-agenda-filter-apply
  7641. (setq org-agenda-category-filter
  7642. (list (concat "+" cat)))
  7643. 'category))
  7644. (t (error "No category at point"))))))
  7645. (defun org-find-top-headline (&optional pos)
  7646. "Find the topmost parent headline and return it.
  7647. POS when non-nil is the marker or buffer position to start the
  7648. search from."
  7649. (save-excursion
  7650. (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
  7651. (when pos (goto-char pos))
  7652. ;; Skip up to the topmost parent.
  7653. (while (org-up-heading-safe))
  7654. (ignore-errors
  7655. (replace-regexp-in-string
  7656. "^\\[[0-9]+/[0-9]+\\] *\\|^\\[%[0-9]+\\] *" ""
  7657. (nth 4 (org-heading-components)))))))
  7658. (defvar org-agenda-filtered-by-top-headline nil)
  7659. (defun org-agenda-filter-by-top-headline (strip)
  7660. "Keep only those lines that are descendants from the same top headline.
  7661. The top headline is that of the current line. With prefix arg STRIP, hide
  7662. all lines of the category at point."
  7663. (interactive "P")
  7664. (if org-agenda-filtered-by-top-headline
  7665. (progn
  7666. (setq org-agenda-filtered-by-top-headline nil
  7667. org-agenda-top-headline-filter nil)
  7668. (org-agenda-filter-show-all-top-filter))
  7669. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  7670. (if toph (org-agenda-filter-top-headline-apply toph strip)
  7671. (error "No top-level headline at point")))))
  7672. (defvar org-agenda-regexp-filter nil)
  7673. (defun org-agenda-filter-by-regexp (strip-or-accumulate)
  7674. "Filter agenda entries by a regular expressions.
  7675. You will be prompted for the regular expression, and the agenda
  7676. view will only show entries that are matched by that expression.
  7677. With one `\\[universal-argument]' prefix argument, hide entries matching the regexp.
  7678. When there is already a regexp filter active, this command removed the
  7679. filter. However, with two `\\[universal-argument]' prefix arguments, add a new condition to
  7680. an already existing regexp filter."
  7681. (interactive "P")
  7682. (let* ((strip (equal strip-or-accumulate '(4)))
  7683. (accumulate (equal strip-or-accumulate '(16))))
  7684. (cond
  7685. ((and org-agenda-regexp-filter (not accumulate))
  7686. (org-agenda-filter-show-all-re)
  7687. (message "Regexp filter removed"))
  7688. (t (let ((flt (concat (if strip "-" "+")
  7689. (read-from-minibuffer
  7690. (if strip
  7691. "Hide entries matching regexp: "
  7692. "Narrow to entries matching regexp: ")))))
  7693. (push flt org-agenda-regexp-filter)
  7694. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))))))
  7695. (defvar org-agenda-effort-filter nil)
  7696. (defun org-agenda-filter-by-effort (strip-or-accumulate)
  7697. "Filter agenda entries by effort.
  7698. With no `\\[universal-argument]' prefix argument, keep entries matching the effort condition.
  7699. With one `\\[universal-argument]' prefix argument, filter out entries matching the condition.
  7700. With two `\\[universal-argument]' prefix arguments, add a second condition to the existing filter.
  7701. This last option is in practice not very useful, but it is available for
  7702. consistency with the other filter commands."
  7703. (interactive "P")
  7704. (let* ((efforts (split-string
  7705. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7706. org-global-properties
  7707. t))
  7708. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
  7709. ;; XXX: the following handles only up to 10 different
  7710. ;; effort values.
  7711. (allowed-keys (if (null efforts) nil
  7712. (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
  7713. (number-sequence 1 (length efforts)))))
  7714. (keep (equal strip-or-accumulate '(16)))
  7715. (negative (equal strip-or-accumulate '(4)))
  7716. (current org-agenda-effort-filter)
  7717. (op nil))
  7718. (while (not (memq op '(?< ?> ?= ?_)))
  7719. (setq op (read-char-exclusive
  7720. "Effort operator? (> = or <) or press `_' again to remove filter")))
  7721. ;; Select appropriate duration. Ignore non-digit characters.
  7722. (if (eq op ?_)
  7723. (progn
  7724. (org-agenda-filter-show-all-effort)
  7725. (message "Effort filter removed"))
  7726. (let ((prompt
  7727. (apply #'format
  7728. (concat "Effort %c "
  7729. (mapconcat (lambda (s) (concat "[%d]" s))
  7730. efforts
  7731. " "))
  7732. op allowed-keys))
  7733. (eff -1))
  7734. (while (not (memq eff allowed-keys))
  7735. (message prompt)
  7736. (setq eff (- (read-char-exclusive) 48)))
  7737. (org-agenda-filter-show-all-effort)
  7738. (setq org-agenda-effort-filter
  7739. (append
  7740. (list (concat (if negative "-" "+")
  7741. (char-to-string op)
  7742. ;; Numbering is 1 2 3 ... 9 0, but we want
  7743. ;; 0 1 2 ... 8 9.
  7744. (nth (mod (1- eff) 10) efforts)))
  7745. (if keep current nil)))
  7746. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))))
  7747. (defun org-agenda-filter (&optional strip-or-accumulate)
  7748. "Prompt for a general filter string and apply it to the agenda.
  7749. The string may contain filter elements like
  7750. +category
  7751. +tag
  7752. +<effort > and = are also allowed as effort operators
  7753. +/regexp/
  7754. Instead of `+', `-' is allowed to strip the agenda of matching entries.
  7755. `+' is optional if it is not required to separate two string parts.
  7756. Multiple filter elements can be concatenated without spaces, for example
  7757. +work-John<0:10-/plot/
  7758. selects entries with category `work' and effort estimates below 10 minutes,
  7759. and deselects entries with tag `John' or matching the regexp `plot'.
  7760. During entry of the filter, completion for tags, categories and effort
  7761. values is offered. Since the syntax for categories and tags is identical
  7762. there should be no overlap between categories and tags. If there is, tags
  7763. get priority.
  7764. A single `\\[universal-argument]' prefix arg STRIP-OR-ACCUMULATE will negate the
  7765. entire filter, which can be useful in connection with the prompt history.
  7766. A double `\\[universal-argument] \\[universal-argument]' prefix arg will add the new filter elements to the
  7767. existing ones. A shortcut for this is to add an additional `+' at the
  7768. beginning of the string, like `+-John'.
  7769. With a triple prefix argument, execute the computed filtering defined in
  7770. the variable `org-agenda-auto-exclude-function'."
  7771. (interactive "P")
  7772. (if (equal strip-or-accumulate '(64))
  7773. ;; Execute the auto-exclude action
  7774. (if (not org-agenda-auto-exclude-function)
  7775. (user-error "`org-agenda-auto-exclude-function' is undefined")
  7776. (org-agenda-filter-show-all-tag)
  7777. (setq org-agenda-tag-filter nil)
  7778. (dolist (tag (org-agenda-get-represented-tags))
  7779. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7780. (when modifier
  7781. (push modifier org-agenda-tag-filter))))
  7782. (unless (null org-agenda-tag-filter)
  7783. (org-agenda-filter-apply org-agenda-tag-filter 'tag 'expand)))
  7784. ;; Prompt for a filter and act
  7785. (let* ((tag-list (org-agenda-get-represented-tags))
  7786. (category-list (org-agenda-get-represented-categories))
  7787. (negate (equal strip-or-accumulate '(4)))
  7788. (cf (mapconcat #'identity org-agenda-category-filter ""))
  7789. (tf (mapconcat #'identity org-agenda-tag-filter ""))
  7790. ;; (rpl-fn (lambda (c) (replace-regexp-in-string "^\\+" "" (or (car c) ""))))
  7791. (ef (replace-regexp-in-string "^\\+" "" (or (car org-agenda-effort-filter) "")))
  7792. (rf (replace-regexp-in-string "^\\+" "" (or (car org-agenda-regexp-filter) "")))
  7793. (ff (concat cf tf ef (when (not (equal rf "")) (concat "/" rf "/"))))
  7794. (f-string (completing-read
  7795. (concat
  7796. (if negate "Negative filter" "Filter")
  7797. " [+cat-tag<0:10-/regexp/]: ")
  7798. #'org-agenda-filter-completion-function
  7799. nil nil ff))
  7800. (keep (or (if (string-match "^\\+[+-]" f-string)
  7801. (progn (setq f-string (substring f-string 1)) t))
  7802. (equal strip-or-accumulate '(16))))
  7803. (fc (if keep org-agenda-category-filter))
  7804. (ft (if keep org-agenda-tag-filter))
  7805. (fe (if keep org-agenda-effort-filter))
  7806. (fr (if keep org-agenda-regexp-filter))
  7807. pm s)
  7808. ;; If the filter contains a double-quoted string, replace a
  7809. ;; single hyphen by the arbitrary and temporary string "~~~"
  7810. ;; to disambiguate such hyphens from syntactic ones.
  7811. (setq f-string (replace-regexp-in-string
  7812. "\"\\([^\"]*\\)-\\([^\"]*\\)\"" "\"\\1~~~\\2\"" f-string))
  7813. (while (string-match "^[ \t]*\\([-+]\\)?\\(\\([^-+<>=/ \t]+\\)\\|\\([<>=][0-9:]+\\)\\|\\(/\\([^/]+\\)/?\\)\\)" f-string)
  7814. (setq pm (if (match-beginning 1) (match-string 1 f-string) "+"))
  7815. (when negate
  7816. (setq pm (if (equal pm "+") "-" "+")))
  7817. (cond
  7818. ((match-beginning 3)
  7819. ;; category or tag
  7820. (setq s (replace-regexp-in-string ; Remove the temporary special string.
  7821. "~~~" "-" (match-string 3 f-string)))
  7822. (cond
  7823. ((member s tag-list)
  7824. (org-pushnew-to-end (concat pm s) ft))
  7825. ((member s category-list)
  7826. (org-pushnew-to-end (concat pm ; Remove temporary double quotes.
  7827. (replace-regexp-in-string "\"\\(.*\\)\"" "\\1" s))
  7828. fc))
  7829. (t (message
  7830. "`%s%s' filter ignored because tag/category is not represented"
  7831. pm s))))
  7832. ((match-beginning 4)
  7833. ;; effort
  7834. (org-pushnew-to-end (concat pm (match-string 4 f-string)) fe))
  7835. ((match-beginning 5)
  7836. ;; regexp
  7837. (org-pushnew-to-end (concat pm (match-string 6 f-string)) fr)))
  7838. (setq f-string (substring f-string (match-end 0))))
  7839. (org-agenda-filter-remove-all)
  7840. (and fc (org-agenda-filter-apply
  7841. (setq org-agenda-category-filter fc) 'category))
  7842. (and ft (org-agenda-filter-apply
  7843. (setq org-agenda-tag-filter ft) 'tag 'expand))
  7844. (and fe (org-agenda-filter-apply
  7845. (setq org-agenda-effort-filter fe) 'effort))
  7846. (and fr (org-agenda-filter-apply
  7847. (setq org-agenda-regexp-filter fr) 'regexp))
  7848. (run-hooks 'org-agenda-filter-hook))))
  7849. (defun org-agenda-filter-completion-function (string _predicate &optional flag)
  7850. "Complete a complex filter string.
  7851. FLAG specifies the type of completion operation to perform. This
  7852. function is passed as a collection function to `completing-read',
  7853. which see."
  7854. (let ((completion-ignore-case t) ;tags are case-sensitive
  7855. (confirm (lambda (x) (stringp x)))
  7856. (prefix "")
  7857. (operator "")
  7858. table)
  7859. (when (string-match "^\\(.*\\([-+<>=]\\)\\)\\([^-+<>=]*\\)$" string)
  7860. (setq prefix (match-string 1 string)
  7861. operator (match-string 2 string)
  7862. string (match-string 3 string)))
  7863. (cond
  7864. ((member operator '("+" "-" "" nil))
  7865. (setq table (append (org-agenda-get-represented-categories)
  7866. (org-agenda-get-represented-tags))))
  7867. ((member operator '("<" ">" "="))
  7868. (setq table (split-string
  7869. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7870. org-global-properties
  7871. t))
  7872. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")
  7873. " +")))
  7874. (t (setq table nil)))
  7875. (pcase flag
  7876. (`t (all-completions string table confirm))
  7877. (`lambda (assoc string table)) ;exact match?
  7878. (`nil
  7879. (pcase (try-completion string table confirm)
  7880. ((and completion (pred stringp))
  7881. (concat prefix completion))
  7882. (completion completion)))
  7883. (_ nil))))
  7884. (defun org-agenda-filter-remove-all ()
  7885. "Remove all filters from the current agenda buffer."
  7886. (interactive)
  7887. (when org-agenda-tag-filter
  7888. (org-agenda-filter-show-all-tag))
  7889. (when org-agenda-category-filter
  7890. (org-agenda-filter-show-all-cat))
  7891. (when org-agenda-regexp-filter
  7892. (org-agenda-filter-show-all-re))
  7893. (when org-agenda-top-headline-filter
  7894. (org-agenda-filter-show-all-top-filter))
  7895. (when org-agenda-effort-filter
  7896. (org-agenda-filter-show-all-effort))
  7897. (org-agenda-finalize)
  7898. (when (called-interactively-p 'interactive)
  7899. (message "All agenda filters removed")))
  7900. (defun org-agenda-filter-by-tag (strip-or-accumulate &optional char exclude)
  7901. "Keep only those lines in the agenda buffer that have a specific tag.
  7902. The tag is selected with its fast selection letter, as configured.
  7903. With a `\\[universal-argument]' prefix, apply the filter negatively, stripping all matches.
  7904. With a `\\[universal-argument] \\[universal-argument]' prefix, add the new tag to the existing filter
  7905. instead of replacing it.
  7906. With a `\\[universal-argument] \\[universal-argument] \\[universal-argument]' prefix, filter the literal tag, \
  7907. i.e. don't
  7908. filter on all its group members.
  7909. A Lisp caller can specify CHAR. EXCLUDE means that the new tag
  7910. should be used to exclude the search - the interactive user can
  7911. also press `-' or `+' to switch between filtering and excluding."
  7912. (interactive "P")
  7913. (let* ((alist org-tag-alist-for-agenda)
  7914. (seen-chars nil)
  7915. (tag-chars (mapconcat
  7916. (lambda (x) (if (and (not (symbolp (car x)))
  7917. (cdr x)
  7918. (not (member (cdr x) seen-chars)))
  7919. (progn
  7920. (push (cdr x) seen-chars)
  7921. (char-to-string (cdr x)))
  7922. ""))
  7923. org-tag-alist-for-agenda ""))
  7924. (valid-char-list (append '(?\t ?\r ?\\ ?. ?\s ?q)
  7925. (string-to-list tag-chars)))
  7926. (exclude (or exclude (equal strip-or-accumulate '(4))))
  7927. (accumulate (equal strip-or-accumulate '(16)))
  7928. (expand (not (equal strip-or-accumulate '(64))))
  7929. (inhibit-read-only t)
  7930. (current org-agenda-tag-filter)
  7931. a tag) ;; n
  7932. (unless char
  7933. (while (not (memq char valid-char-list))
  7934. (org-unlogged-message
  7935. "%s by tag%s: [%s ]tag-char [TAB]tag %s[\\]off [q]uit"
  7936. (if exclude "Exclude[+]" "Filter[-]")
  7937. (if expand "" " (no grouptag expand)")
  7938. tag-chars
  7939. (if org-agenda-auto-exclude-function "[RET] " ""))
  7940. (setq char (read-char-exclusive))
  7941. ;; Excluding or filtering down
  7942. (cond ((eq char ?-) (setq exclude t))
  7943. ((eq char ?+) (setq exclude nil)))))
  7944. (when (eq char ?\t)
  7945. (unless (local-variable-p 'org-global-tags-completion-table)
  7946. (setq-local org-global-tags-completion-table
  7947. (org-global-tags-completion-table)))
  7948. (let ((completion-ignore-case t))
  7949. (setq tag (completing-read
  7950. "Tag: " org-global-tags-completion-table nil t))))
  7951. (cond
  7952. ((eq char ?\r)
  7953. (org-agenda-filter-show-all-tag)
  7954. (when org-agenda-auto-exclude-function
  7955. (setq org-agenda-tag-filter nil)
  7956. (dolist (tag (org-agenda-get-represented-tags))
  7957. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7958. (when modifier
  7959. (push modifier org-agenda-tag-filter))))
  7960. (unless (null org-agenda-tag-filter)
  7961. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  7962. ((eq char ?\\)
  7963. (org-agenda-filter-show-all-tag)
  7964. (when (get 'org-agenda-tag-filter :preset-filter)
  7965. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  7966. ((eq char ?.)
  7967. (setq org-agenda-tag-filter
  7968. (mapcar (lambda(tag) (concat "+" tag))
  7969. (org-get-at-bol 'tags)))
  7970. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7971. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  7972. ((or (eq char ?\s)
  7973. (setq a (rassoc char alist))
  7974. (and tag (setq a (cons tag nil))))
  7975. (org-agenda-filter-show-all-tag)
  7976. (setq tag (car a))
  7977. (setq org-agenda-tag-filter
  7978. (cons (concat (if exclude "-" "+") tag)
  7979. (if accumulate current nil)))
  7980. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7981. (t (error "Invalid tag selection character %c" char)))))
  7982. (defun org-agenda-get-represented-categories ()
  7983. "Return a list of all categories used in this agenda buffer."
  7984. (or org-agenda-represented-categories
  7985. (when (derived-mode-p 'org-agenda-mode)
  7986. (let ((pos (point-min)) categories)
  7987. (while (and (< pos (point-max))
  7988. (setq pos (next-single-property-change
  7989. pos 'org-category nil (point-max))))
  7990. (push (get-text-property pos 'org-category) categories))
  7991. (setq org-agenda-represented-categories
  7992. ;; Enclose category names with a hyphen in double
  7993. ;; quotes to process them specially in `org-agenda-filter'.
  7994. (mapcar (lambda (s) (if (string-match-p "-" s) (format "\"%s\"" s) s))
  7995. (nreverse (org-uniquify (delq nil categories)))))))))
  7996. (defvar org-tag-groups-alist-for-agenda)
  7997. (defun org-agenda-get-represented-tags ()
  7998. "Return a list of all tags used in this agenda buffer.
  7999. These will be lower-case, for filtering."
  8000. (or org-agenda-represented-tags
  8001. (when (derived-mode-p 'org-agenda-mode)
  8002. (let ((pos (point-min)) tags-lists tt)
  8003. (while (and (< pos (point-max))
  8004. (setq pos (next-single-property-change
  8005. pos 'tags nil (point-max))))
  8006. (setq tt (get-text-property pos 'tags))
  8007. (if tt (push tt tags-lists)))
  8008. (setq tags-lists
  8009. (nreverse (org-uniquify
  8010. (delq nil (apply #'append tags-lists)))))
  8011. (dolist (tag tags-lists)
  8012. (mapc
  8013. (lambda (group)
  8014. (when (member tag group)
  8015. (push (car group) tags-lists)))
  8016. org-tag-groups-alist-for-agenda))
  8017. (setq org-agenda-represented-tags tags-lists)))))
  8018. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  8019. "Create the form that tests a line for agenda filter.
  8020. Optional argument EXPAND can be used for the TYPE tag and will
  8021. expand the tags in the FILTER if any of the tags in FILTER are
  8022. grouptags."
  8023. (let ((multi-pos-cats
  8024. (and (eq type 'category)
  8025. (string-match-p "\\+.*\\+"
  8026. (mapconcat (lambda (cat) (substring cat 0 1))
  8027. filter ""))))
  8028. f f1)
  8029. (cond
  8030. ;; Tag filter
  8031. ((eq type 'tag)
  8032. (setq filter
  8033. (delete-dups
  8034. (append (get 'org-agenda-tag-filter :preset-filter)
  8035. filter)))
  8036. (dolist (x filter)
  8037. (let ((op (string-to-char x)))
  8038. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  8039. (setq x (list x)))
  8040. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  8041. (push f1 f))))
  8042. ;; Category filter
  8043. ((eq type 'category)
  8044. (setq filter
  8045. (delete-dups
  8046. (append (get 'org-agenda-category-filter :preset-filter)
  8047. filter)))
  8048. (dolist (x filter)
  8049. (if (equal "-" (substring x 0 1))
  8050. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  8051. (setq f1 (list 'equal (substring x 1) 'cat)))
  8052. (push f1 f)))
  8053. ;; Regexp filter
  8054. ((eq type 'regexp)
  8055. (setq filter
  8056. (delete-dups
  8057. (append (get 'org-agenda-regexp-filter :preset-filter)
  8058. filter)))
  8059. (dolist (x filter)
  8060. (if (equal "-" (substring x 0 1))
  8061. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  8062. (setq f1 (list 'string-match (substring x 1) 'txt)))
  8063. (push f1 f)))
  8064. ;; Effort filter
  8065. ((eq type 'effort)
  8066. (setq filter
  8067. (delete-dups
  8068. (append (get 'org-agenda-effort-filter :preset-filter)
  8069. filter)))
  8070. (dolist (x filter)
  8071. (push (org-agenda-filter-effort-form x) f))))
  8072. (cons (if multi-pos-cats 'or 'and) (nreverse f))))
  8073. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  8074. "Return a form associated to tag-expression TAGS.
  8075. Build a form testing a line for agenda filter for
  8076. tag-expressions. OP is an operator of type CHAR that allows the
  8077. function to set the right switches in the returned form."
  8078. (let (form)
  8079. ;; Any of the expressions can match if OP is +, all must match if
  8080. ;; the operator is -.
  8081. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  8082. (let* ((tag (substring x 1))
  8083. (f (cond
  8084. ((string= "" tag) 'tags)
  8085. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  8086. ;; TAG is a regexp.
  8087. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  8088. (t (list 'member tag 'tags)))))
  8089. (push (if (eq op ?-) (list 'not f) f) form)))))
  8090. (defun org-agenda-filter-effort-form (e)
  8091. "Return the form to compare the effort of the current line with what E says.
  8092. E looks like \"+<2:25\"."
  8093. (let (op)
  8094. (setq e (substring e 1))
  8095. (setq op (string-to-char e) e (substring e 1))
  8096. (setq op (cond ((equal op ?<) '<=)
  8097. ((equal op ?>) '>=)
  8098. ((equal op ??) op)
  8099. (t '=)))
  8100. (list 'org-agenda-compare-effort (list 'quote op)
  8101. (org-duration-to-minutes e))))
  8102. (defun org-agenda-compare-effort (op value)
  8103. "Compare the effort of the current line with VALUE, using OP.
  8104. If the line does not have an effort defined, return nil."
  8105. ;; `effort-minutes' property cannot be extracted directly from
  8106. ;; current line but is stored as a property in `txt'.
  8107. (let ((effort (get-text-property 0 'effort-minutes (org-get-at-bol 'txt))))
  8108. (funcall op
  8109. (or effort (if org-agenda-sort-noeffort-is-high 32767 -1))
  8110. value)))
  8111. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  8112. "Expand group tags in FILTER for the agenda.
  8113. When NO-OPERATOR is non-nil, do not add the + operator to
  8114. returned tags."
  8115. (if org-group-tags
  8116. (let (case-fold-search rtn)
  8117. (mapc
  8118. (lambda (f)
  8119. (let (f0 dir)
  8120. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  8121. (setq dir (match-string 1 f) f0 (match-string 2 f))
  8122. (setq dir (if no-operator "" "+") f0 f))
  8123. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  8124. (org-tags-expand f0 t))
  8125. rtn))))
  8126. filter)
  8127. (reverse rtn))
  8128. filter))
  8129. (defun org-agenda-filter-apply (filter type &optional expand)
  8130. "Set FILTER as the new agenda filter and apply it.
  8131. Optional argument EXPAND can be used for the TYPE tag and will
  8132. expand the tags in the FILTER if any of the tags in FILTER are
  8133. grouptags."
  8134. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  8135. (when org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  8136. (setq org-agenda-filter-form (org-agenda-filter-make-matcher
  8137. filter type expand))
  8138. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  8139. ;; category is used as the filter:
  8140. (setq org-agenda-filtered-by-category
  8141. (and (eq type 'category)
  8142. (not (equal (substring (car filter) 0 1) "-"))))
  8143. (org-agenda-set-mode-name)
  8144. (save-excursion
  8145. (goto-char (point-min))
  8146. (while (not (eobp))
  8147. (when (or (org-get-at-bol 'org-hd-marker)
  8148. (org-get-at-bol 'org-marker))
  8149. (org-dlet
  8150. ((tags (org-get-at-bol 'tags))
  8151. (cat (org-agenda-get-category))
  8152. (txt (or (org-get-at-bol 'txt) "")))
  8153. (unless (eval org-agenda-filter-form t)
  8154. (org-agenda-filter-hide-line type))))
  8155. (beginning-of-line 2)))
  8156. (when (get-char-property (point) 'invisible)
  8157. (ignore-errors (org-agenda-previous-line))))
  8158. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  8159. "Filter by top headline HL."
  8160. (org-agenda-set-mode-name)
  8161. (save-excursion
  8162. (goto-char (point-min))
  8163. (while (not (eobp))
  8164. (let* ((pos (org-get-at-bol 'org-hd-marker))
  8165. (tophl (and pos (org-find-top-headline pos))))
  8166. (when (and tophl (funcall (if negative 'identity 'not)
  8167. (string= hl tophl)))
  8168. (org-agenda-filter-hide-line 'top-headline)))
  8169. (beginning-of-line 2)))
  8170. (when (get-char-property (point) 'invisible)
  8171. (org-agenda-previous-line))
  8172. (setq org-agenda-top-headline-filter hl
  8173. org-agenda-filtered-by-top-headline t))
  8174. (defun org-agenda-filter-hide-line (type)
  8175. "If current line is TYPE, hide it in the agenda buffer."
  8176. (let* (buffer-invisibility-spec
  8177. (beg (max (point-min) (1- (line-beginning-position))))
  8178. (end (line-end-position)))
  8179. (let ((inhibit-read-only t))
  8180. (add-text-properties
  8181. beg end `(invisible org-filtered org-filter-type ,type)))))
  8182. (defun org-agenda-remove-filter (type)
  8183. "Remove filter of type TYPE from the agenda buffer."
  8184. (interactive)
  8185. (save-excursion
  8186. (goto-char (point-min))
  8187. (let ((inhibit-read-only t) pos)
  8188. (while (setq pos (text-property-any (point) (point-max)
  8189. 'org-filter-type type))
  8190. (goto-char pos)
  8191. (remove-text-properties
  8192. (point) (next-single-property-change (point) 'org-filter-type)
  8193. `(invisible org-filtered org-filter-type ,type))))
  8194. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  8195. (setq org-agenda-filter-form nil)
  8196. (org-agenda-set-mode-name)
  8197. (org-agenda-finalize)))
  8198. (defun org-agenda-filter-show-all-tag nil
  8199. (org-agenda-remove-filter 'tag))
  8200. (defun org-agenda-filter-show-all-re nil
  8201. (org-agenda-remove-filter 'regexp))
  8202. (defun org-agenda-filter-show-all-effort nil
  8203. (org-agenda-remove-filter 'effort))
  8204. (defun org-agenda-filter-show-all-cat nil
  8205. (org-agenda-remove-filter 'category))
  8206. (defun org-agenda-filter-show-all-top-filter nil
  8207. (org-agenda-remove-filter 'top-headline))
  8208. (defun org-agenda-manipulate-query-add ()
  8209. "Manipulate the query by adding a search term with positive selection.
  8210. Positive selection means the term must be matched for selection of an entry."
  8211. (interactive)
  8212. (org-agenda-manipulate-query ?\[))
  8213. (defun org-agenda-manipulate-query-subtract ()
  8214. "Manipulate the query by adding a search term with negative selection.
  8215. Negative selection means term must not be matched for selection of an entry."
  8216. (interactive)
  8217. (org-agenda-manipulate-query ?\]))
  8218. (defun org-agenda-manipulate-query-add-re ()
  8219. "Manipulate the query by adding a search regexp with positive selection.
  8220. Positive selection means the regexp must match for selection of an entry."
  8221. (interactive)
  8222. (org-agenda-manipulate-query ?\{))
  8223. (defun org-agenda-manipulate-query-subtract-re ()
  8224. "Manipulate the query by adding a search regexp with negative selection.
  8225. Negative selection means regexp must not match for selection of an entry."
  8226. (interactive)
  8227. (org-agenda-manipulate-query ?\}))
  8228. (defun org-agenda-manipulate-query (char)
  8229. (cond
  8230. ((eq org-agenda-type 'agenda)
  8231. (let ((org-agenda-include-inactive-timestamps t))
  8232. (org-agenda-redo))
  8233. (message "Display now includes inactive timestamps as well"))
  8234. ((eq org-agenda-type 'search)
  8235. (org-add-to-string
  8236. 'org-agenda-query-string
  8237. (if org-agenda-last-search-view-search-was-boolean
  8238. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  8239. (?\{ . " +{}") (?\} . " -{}"))))
  8240. " "))
  8241. (setq org-agenda-redo-command
  8242. (list 'org-search-view
  8243. (car (get-text-property (min (1- (point-max)) (point))
  8244. 'org-last-args))
  8245. org-agenda-query-string
  8246. (+ (length org-agenda-query-string)
  8247. (if (member char '(?\{ ?\})) 0 1))))
  8248. (set-register org-agenda-query-register org-agenda-query-string)
  8249. (let ((org-agenda-overriding-arguments
  8250. (cdr org-agenda-redo-command)))
  8251. (org-agenda-redo)))
  8252. (t (error "Cannot manipulate query for %s-type agenda buffers"
  8253. org-agenda-type))))
  8254. (defun org-add-to-string (var string)
  8255. (set var (concat (symbol-value var) string)))
  8256. (defun org-agenda-goto-date (date)
  8257. "Jump to DATE in the agenda buffer.
  8258. When called interactively, prompt for the date.
  8259. When called from Lisp, DATE should be a date as returned by
  8260. `org-read-date'.
  8261. See also:
  8262. `org-agenda-earlier' (\\[org-agenda-earlier])
  8263. `org-agenda-later' (\\[org-agenda-later])
  8264. `org-agenda-goto-today' (\\[org-agenda-goto-today])"
  8265. (interactive
  8266. (list
  8267. (let ((org-read-date-prefer-future org-agenda-jump-prefer-future))
  8268. (org-read-date))))
  8269. (let* ((day (time-to-days (org-time-string-to-time date)))
  8270. (org-agenda-sticky-orig org-agenda-sticky)
  8271. (org-agenda-buffer-tmp-name (buffer-name))
  8272. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8273. (0-arg (or current-prefix-arg (car args)))
  8274. (2-arg (nth 2 args))
  8275. (with-hour-p (nth 4 org-agenda-redo-command))
  8276. (newcmd (list 'org-agenda-list 0-arg date
  8277. (org-agenda-span-to-ndays
  8278. 2-arg (org-time-string-to-absolute date))
  8279. with-hour-p))
  8280. (newargs (cdr newcmd))
  8281. (inhibit-read-only t)
  8282. org-agenda-sticky)
  8283. (if (not (org-agenda-check-type t 'agenda))
  8284. (error "Not available in non-agenda views")
  8285. (add-text-properties (point-min) (point-max)
  8286. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  8287. (org-agenda-redo)
  8288. (goto-char (point-min))
  8289. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  8290. (save-excursion (move-beginning-of-line 2) (eobp))))
  8291. (move-beginning-of-line 2))
  8292. (setq org-agenda-sticky org-agenda-sticky-orig
  8293. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  8294. (defun org-agenda-goto-today ()
  8295. "Go to today's date in the agenda buffer.
  8296. See also:
  8297. `org-agenda-later' (\\[org-agenda-later])
  8298. `org-agenda-earlier' (\\[org-agenda-earlier])
  8299. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8300. (interactive)
  8301. (org-agenda-check-type t 'agenda)
  8302. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8303. (curspan (nth 2 args))
  8304. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  8305. (cond
  8306. (tdpos (goto-char tdpos))
  8307. ((eq org-agenda-type 'agenda)
  8308. (let* ((sd (org-agenda-compute-starting-span
  8309. (org-today) (or curspan org-agenda-span)))
  8310. (org-agenda-overriding-arguments args))
  8311. (setf (nth 1 org-agenda-overriding-arguments) sd)
  8312. (org-agenda-redo)
  8313. (org-agenda-find-same-or-today-or-agenda)))
  8314. (t (error "Cannot find today")))))
  8315. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  8316. (goto-char
  8317. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  8318. (text-property-any (point-min) (point-max) 'org-today t)
  8319. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  8320. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  8321. (org-agenda-backward-block))
  8322. (point-min))))
  8323. (defun org-agenda-backward-block ()
  8324. "Move backward by one agenda block."
  8325. (interactive)
  8326. (org-agenda-forward-block 'backward))
  8327. (defun org-agenda-forward-block (&optional backward)
  8328. "Move forward by one agenda block.
  8329. When optional argument BACKWARD is set, go backward."
  8330. (interactive)
  8331. (cond ((not (derived-mode-p 'org-agenda-mode))
  8332. (user-error
  8333. "Cannot execute this command outside of org-agenda-mode buffers"))
  8334. ((looking-at (if backward "\\`" "\\'"))
  8335. (message "Already at the %s block" (if backward "first" "last")))
  8336. (t (let ((_pos (prog1 (point)
  8337. (ignore-errors (if backward (backward-char 1)
  8338. (move-end-of-line 1)))))
  8339. (f (if backward
  8340. #'previous-single-property-change
  8341. #'next-single-property-change))
  8342. moved dest)
  8343. (while (and (setq dest (funcall
  8344. f (point) 'org-agenda-structural-header))
  8345. (not (get-text-property
  8346. (point) 'org-agenda-structural-header)))
  8347. (setq moved t)
  8348. (goto-char dest))
  8349. (if moved (move-beginning-of-line 1)
  8350. (goto-char (if backward (point-min) (point-max)))
  8351. (move-beginning-of-line 1)
  8352. (message "No %s block" (if backward "previous" "further")))))))
  8353. (defun org-agenda-later (arg)
  8354. "Go forward in time by the current span in the agenda buffer.
  8355. With prefix ARG, go forward that many times the current span.
  8356. See also:
  8357. `org-agenda-earlier' (\\[org-agenda-earlier])
  8358. `org-agenda-goto-today' (\\[org-agenda-goto-today])
  8359. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8360. (interactive "p")
  8361. (org-agenda-check-type t 'agenda)
  8362. (let* ((wstart (window-start))
  8363. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8364. (span (or (nth 2 args) org-agenda-current-span))
  8365. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  8366. (greg (calendar-gregorian-from-absolute sd))
  8367. (cnt (org-get-at-bol 'org-day-cnt))
  8368. greg2)
  8369. (cond
  8370. ((numberp span)
  8371. (setq sd (+ (* span arg) sd)))
  8372. ((eq span 'day)
  8373. (setq sd (+ arg sd)))
  8374. ((eq span 'week)
  8375. (setq sd (+ (* 7 arg) sd)))
  8376. ((eq span 'fortnight)
  8377. (setq sd (+ (* 14 arg) sd)))
  8378. ((eq span 'month)
  8379. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  8380. sd (calendar-absolute-from-gregorian greg2))
  8381. (setcar greg2 (1+ (car greg2))))
  8382. ((eq span 'year)
  8383. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  8384. sd (calendar-absolute-from-gregorian greg2))
  8385. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  8386. (t
  8387. (setq sd (+ (* span arg) sd))))
  8388. (let ((org-agenda-overriding-cmd
  8389. ;; `cmd' may have been set by `org-agenda-run-series' which
  8390. ;; uses `org-agenda-overriding-cmd' to decide whether
  8391. ;; overriding is allowed for `cmd'
  8392. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  8393. (org-agenda-overriding-arguments
  8394. (list (car args) sd span)))
  8395. (org-agenda-redo)
  8396. (org-agenda-find-same-or-today-or-agenda cnt))
  8397. (set-window-start nil wstart)))
  8398. (defun org-agenda-earlier (arg)
  8399. "Go backward in time by the current span in the agenda buffer.
  8400. With prefix ARG, go backward that many times the current span.
  8401. See also:
  8402. `org-agenda-later' (\\[org-agenda-later])
  8403. `org-agenda-goto-today' (\\[org-agenda-goto-today])
  8404. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8405. (interactive "p")
  8406. (org-agenda-later (- arg)))
  8407. (defun org-agenda-view-mode-dispatch ()
  8408. "Call one of the view mode commands."
  8409. (interactive)
  8410. (org-unlogged-message
  8411. "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  8412. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  8413. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  8414. (pcase (read-char-exclusive)
  8415. (?\ (call-interactively 'org-agenda-reset-view))
  8416. (?d (call-interactively 'org-agenda-day-view))
  8417. (?w (call-interactively 'org-agenda-week-view))
  8418. (?t (call-interactively 'org-agenda-fortnight-view))
  8419. (?m (call-interactively 'org-agenda-month-view))
  8420. (?y (call-interactively 'org-agenda-year-view))
  8421. (?l (call-interactively 'org-agenda-log-mode))
  8422. (?L (org-agenda-log-mode '(4)))
  8423. (?c (org-agenda-log-mode 'clockcheck))
  8424. ((or ?F ?f) (call-interactively 'org-agenda-follow-mode))
  8425. (?a (call-interactively 'org-agenda-archives-mode))
  8426. (?A (org-agenda-archives-mode 'files))
  8427. ((or ?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  8428. ((or ?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  8429. (?G (call-interactively 'org-agenda-toggle-time-grid))
  8430. (?D (call-interactively 'org-agenda-toggle-diary))
  8431. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  8432. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  8433. (org-agenda-check-type t 'agenda)
  8434. (org-agenda-redo))
  8435. (message "Display now includes inactive timestamps as well"))
  8436. (?q (message "Abort"))
  8437. (key (user-error "Invalid key: %s" key))))
  8438. (defun org-agenda-reset-view ()
  8439. "Switch to default view for agenda."
  8440. (interactive)
  8441. (org-agenda-change-time-span org-agenda-span))
  8442. (defun org-agenda-day-view (&optional day-of-month)
  8443. "Switch to daily view for agenda.
  8444. With argument DAY-OF-MONTH, switch to that day of the month."
  8445. (interactive "P")
  8446. (org-agenda-change-time-span 'day day-of-month))
  8447. (defun org-agenda-week-view (&optional iso-week)
  8448. "Switch to weekly view for agenda.
  8449. With argument ISO-WEEK, switch to the corresponding ISO week.
  8450. If ISO-WEEK has more then 2 digits, only the last two encode
  8451. the week. Any digits before this encode a year. So 200712
  8452. means week 12 of year 2007. Years ranging from 70 years ago
  8453. to 30 years in the future can also be written as 2-digit years."
  8454. (interactive "P")
  8455. (org-agenda-change-time-span 'week iso-week))
  8456. (defun org-agenda-fortnight-view (&optional iso-week)
  8457. "Switch to fortnightly view for agenda.
  8458. With argument ISO-WEEK, switch to the corresponding ISO week.
  8459. If ISO-WEEK has more then 2 digits, only the last two encode
  8460. the week. Any digits before this encode a year. So 200712
  8461. means week 12 of year 2007. Years ranging from 70 years ago
  8462. to 30 years in the future can also be written as 2-digit years."
  8463. (interactive "P")
  8464. (org-agenda-change-time-span 'fortnight iso-week))
  8465. (defun org-agenda-month-view (&optional month)
  8466. "Switch to monthly view for agenda.
  8467. With argument MONTH, switch to that month. If MONTH has more
  8468. then 2 digits, only the last two encode the month. Any digits
  8469. before this encode a year. So 200712 means December year 2007.
  8470. Years ranging from 70 years ago to 30 years in the future can
  8471. also be written as 2-digit years."
  8472. (interactive "P")
  8473. (org-agenda-change-time-span 'month month))
  8474. (defun org-agenda-year-view (&optional year)
  8475. "Switch to yearly view for agenda.
  8476. With argument YEAR, switch to that year. Years ranging from 70
  8477. years ago to 30 years in the future can also be written as
  8478. 2-digit years."
  8479. (interactive "P")
  8480. (when year
  8481. (setq year (org-small-year-to-year year)))
  8482. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  8483. (org-agenda-change-time-span 'year year)
  8484. (error "Abort")))
  8485. (defun org-agenda-change-time-span (span &optional n)
  8486. "Change the agenda view to SPAN.
  8487. SPAN may be `day', `week', `fortnight', `month', `year'."
  8488. (org-agenda-check-type t 'agenda)
  8489. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8490. (curspan (nth 2 args)))
  8491. (when (and (not n) (equal curspan span))
  8492. (error "Viewing span is already \"%s\"" span))
  8493. (let* ((sd (or (org-get-at-bol 'day)
  8494. (nth 1 args)
  8495. org-starting-day))
  8496. (sd (org-agenda-compute-starting-span sd span n))
  8497. (org-agenda-overriding-cmd
  8498. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  8499. (org-agenda-overriding-arguments
  8500. (list (car args) sd span)))
  8501. (org-agenda-redo)
  8502. (org-agenda-find-same-or-today-or-agenda))
  8503. (org-agenda-set-mode-name)
  8504. (message "Switched to %s view" span)))
  8505. (defun org-agenda-compute-starting-span (sd span &optional n)
  8506. "Compute starting date for agenda.
  8507. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  8508. is a cons cell with the starting date and the number of days,
  8509. so that the date SD will be in that range."
  8510. (let* ((greg (calendar-gregorian-from-absolute sd))
  8511. ;; (dg (nth 1 greg))
  8512. (mg (car greg))
  8513. (yg (nth 2 greg)))
  8514. (cond
  8515. ((eq span 'day)
  8516. (when n
  8517. (setq sd (+ (calendar-absolute-from-gregorian
  8518. (list mg 1 yg))
  8519. n -1))))
  8520. ((or (eq span 'week) (eq span 'fortnight))
  8521. (let* ((nt (calendar-day-of-week
  8522. (calendar-gregorian-from-absolute sd)))
  8523. (d (if org-agenda-start-on-weekday
  8524. (- nt org-agenda-start-on-weekday)
  8525. 0))
  8526. y1)
  8527. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  8528. (when n
  8529. (require 'cal-iso)
  8530. (when (> n 99)
  8531. (setq y1 (org-small-year-to-year (/ n 100))
  8532. n (mod n 100)))
  8533. (setq sd
  8534. (calendar-iso-to-absolute
  8535. (list n 1
  8536. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  8537. ((eq span 'month)
  8538. (let (y1)
  8539. (when (and n (> n 99))
  8540. (setq y1 (org-small-year-to-year (/ n 100))
  8541. n (mod n 100)))
  8542. (setq sd (calendar-absolute-from-gregorian
  8543. (list (or n mg) 1 (or y1 yg))))))
  8544. ((eq span 'year)
  8545. (setq sd (calendar-absolute-from-gregorian
  8546. (list 1 1 (or n yg))))))
  8547. sd))
  8548. (defun org-agenda-next-date-line (&optional arg)
  8549. "Jump to the next line indicating a date in agenda buffer."
  8550. (interactive "p")
  8551. (org-agenda-check-type t 'agenda)
  8552. (beginning-of-line 1)
  8553. ;; This does not work if user makes date format that starts with a blank
  8554. (when (looking-at-p "^\\S-") (forward-char 1))
  8555. (unless (re-search-forward "^\\S-" nil t arg)
  8556. (backward-char 1)
  8557. (error "No next date after this line in this buffer"))
  8558. (goto-char (match-beginning 0)))
  8559. (defun org-agenda-previous-date-line (&optional arg)
  8560. "Jump to the previous line indicating a date in agenda buffer."
  8561. (interactive "p")
  8562. (org-agenda-check-type t 'agenda)
  8563. (beginning-of-line 1)
  8564. (unless (re-search-backward "^\\S-" nil t arg)
  8565. (error "No previous date before this line in this buffer")))
  8566. ;; Initialize the highlight
  8567. (defvar org-hl (make-overlay 1 1))
  8568. (overlay-put org-hl 'face 'highlight)
  8569. (defun org-highlight (begin end &optional buffer)
  8570. "Highlight a region with overlay."
  8571. (move-overlay org-hl begin end (or buffer (current-buffer))))
  8572. (defun org-unhighlight ()
  8573. "Detach overlay INDEX."
  8574. (delete-overlay org-hl))
  8575. (defun org-unhighlight-once ()
  8576. "Remove the highlight from its position, and this function from the hook."
  8577. (remove-hook 'pre-command-hook #'org-unhighlight-once)
  8578. (org-unhighlight))
  8579. (defvar org-agenda-pre-follow-window-conf nil)
  8580. (defun org-agenda-follow-mode ()
  8581. "Toggle follow mode in an agenda buffer."
  8582. (interactive)
  8583. (unless org-agenda-follow-mode
  8584. (setq org-agenda-pre-follow-window-conf
  8585. (current-window-configuration)))
  8586. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  8587. (unless org-agenda-follow-mode
  8588. (set-window-configuration org-agenda-pre-follow-window-conf))
  8589. (org-agenda-set-mode-name)
  8590. (org-agenda-do-context-action)
  8591. (message "Follow mode is %s"
  8592. (if org-agenda-follow-mode "on" "off")))
  8593. (defun org-agenda-entry-text-mode (&optional arg)
  8594. "Toggle entry text mode in an agenda buffer."
  8595. (interactive "P")
  8596. (if (or org-agenda-tag-filter
  8597. org-agenda-category-filter
  8598. org-agenda-regexp-filter
  8599. org-agenda-top-headline-filter)
  8600. (user-error "Can't show entry text in filtered views")
  8601. (setq org-agenda-entry-text-mode (or (integerp arg)
  8602. (not org-agenda-entry-text-mode)))
  8603. (org-agenda-entry-text-hide)
  8604. (and org-agenda-entry-text-mode
  8605. (let ((org-agenda-entry-text-maxlines
  8606. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  8607. (org-agenda-entry-text-show)))
  8608. (org-agenda-set-mode-name)
  8609. (message "Entry text mode is %s%s"
  8610. (if org-agenda-entry-text-mode "on" "off")
  8611. (if (not org-agenda-entry-text-mode) ""
  8612. (format " (maximum number of lines is %d)"
  8613. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  8614. (defun org-agenda-clockreport-mode ()
  8615. "Toggle clocktable mode in an agenda buffer."
  8616. (interactive)
  8617. (org-agenda-check-type t 'agenda)
  8618. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  8619. (org-agenda-set-mode-name)
  8620. (org-agenda-redo)
  8621. (message "Clocktable mode is %s"
  8622. (if org-agenda-clockreport-mode "on" "off")))
  8623. (defun org-agenda-log-mode (&optional special)
  8624. "Toggle log mode in an agenda buffer.
  8625. With argument SPECIAL, show all possible log items, not only the ones
  8626. configured in `org-agenda-log-mode-items'.
  8627. With a `\\[universal-argument] \\[universal-argument]' prefix, show *only* \
  8628. log items, nothing else."
  8629. (interactive "P")
  8630. (org-agenda-check-type t 'agenda)
  8631. (setq org-agenda-show-log
  8632. (cond
  8633. ((equal special '(16)) 'only)
  8634. ((eq special 'clockcheck)
  8635. (if (eq org-agenda-show-log 'clockcheck)
  8636. nil 'clockcheck))
  8637. (special '(closed clock state))
  8638. (t (not org-agenda-show-log))))
  8639. (org-agenda-set-mode-name)
  8640. (org-agenda-redo)
  8641. (message "Log mode is %s" (if org-agenda-show-log "on" "off")))
  8642. (defun org-agenda-archives-mode (&optional with-files)
  8643. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  8644. When called with a prefix argument, include all archive files as well."
  8645. (interactive "P")
  8646. (setq org-agenda-archives-mode
  8647. (cond ((and with-files (eq org-agenda-archives-mode t)) nil)
  8648. (with-files t)
  8649. (org-agenda-archives-mode nil)
  8650. (t 'trees)))
  8651. (org-agenda-set-mode-name)
  8652. (org-agenda-redo)
  8653. (message
  8654. "%s"
  8655. (cond
  8656. ((eq org-agenda-archives-mode nil)
  8657. "No archives are included")
  8658. ((eq org-agenda-archives-mode 'trees)
  8659. (format "Trees with :%s: tag are included" org-archive-tag))
  8660. ((eq org-agenda-archives-mode t)
  8661. (format "Trees with :%s: tag and all active archive files are included"
  8662. org-archive-tag)))))
  8663. (defun org-agenda-toggle-diary ()
  8664. "Toggle diary inclusion in an agenda buffer."
  8665. (interactive)
  8666. (org-agenda-check-type t 'agenda)
  8667. (setq org-agenda-include-diary (not org-agenda-include-diary))
  8668. (org-agenda-redo)
  8669. (org-agenda-set-mode-name)
  8670. (message "Diary inclusion turned %s"
  8671. (if org-agenda-include-diary "on" "off")))
  8672. (defun org-agenda-toggle-deadlines ()
  8673. "Toggle inclusion of entries with a deadline in an agenda buffer."
  8674. (interactive)
  8675. (org-agenda-check-type t 'agenda)
  8676. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  8677. (org-agenda-redo)
  8678. (org-agenda-set-mode-name)
  8679. (message "Deadlines inclusion turned %s"
  8680. (if org-agenda-include-deadlines "on" "off")))
  8681. (defun org-agenda-toggle-time-grid ()
  8682. "Toggle time grid in an agenda buffer."
  8683. (interactive)
  8684. (org-agenda-check-type t 'agenda)
  8685. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  8686. (org-agenda-redo)
  8687. (org-agenda-set-mode-name)
  8688. (message "Time-grid turned %s"
  8689. (if org-agenda-use-time-grid "on" "off")))
  8690. (defun org-agenda-set-mode-name ()
  8691. "Set the mode name to indicate all the small mode settings."
  8692. (setq mode-name
  8693. (list "Org-Agenda"
  8694. (if (get 'org-agenda-files 'org-restrict) " []" "")
  8695. " "
  8696. '(:eval (org-agenda-span-name org-agenda-current-span))
  8697. (if org-agenda-follow-mode " Follow" "")
  8698. (if org-agenda-entry-text-mode " ETxt" "")
  8699. (if org-agenda-include-diary " Diary" "")
  8700. (if org-agenda-include-deadlines " Ddl" "")
  8701. (if org-agenda-use-time-grid " Grid" "")
  8702. (if (and (boundp 'org-habit-show-habits)
  8703. org-habit-show-habits)
  8704. " Habit" "")
  8705. (cond
  8706. ((consp org-agenda-show-log) " LogAll")
  8707. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  8708. (org-agenda-show-log " Log")
  8709. (t ""))
  8710. (if (org-agenda-filter-any) " " "")
  8711. (if (or org-agenda-category-filter
  8712. (get 'org-agenda-category-filter :preset-filter))
  8713. '(:eval (propertize
  8714. (concat "["
  8715. (mapconcat
  8716. #'identity
  8717. (append
  8718. (get 'org-agenda-category-filter :preset-filter)
  8719. org-agenda-category-filter)
  8720. "")
  8721. "]")
  8722. 'face 'org-agenda-filter-category
  8723. 'help-echo "Category used in filtering"))
  8724. "")
  8725. (if (or org-agenda-tag-filter
  8726. (get 'org-agenda-tag-filter :preset-filter))
  8727. '(:eval (propertize
  8728. (concat (mapconcat
  8729. #'identity
  8730. (append
  8731. (get 'org-agenda-tag-filter :preset-filter)
  8732. org-agenda-tag-filter)
  8733. ""))
  8734. 'face 'org-agenda-filter-tags
  8735. 'help-echo "Tags used in filtering"))
  8736. "")
  8737. (if (or org-agenda-effort-filter
  8738. (get 'org-agenda-effort-filter :preset-filter))
  8739. '(:eval (propertize
  8740. (concat (mapconcat
  8741. #'identity
  8742. (append
  8743. (get 'org-agenda-effort-filter :preset-filter)
  8744. org-agenda-effort-filter)
  8745. ""))
  8746. 'face 'org-agenda-filter-effort
  8747. 'help-echo "Effort conditions used in filtering"))
  8748. "")
  8749. (if (or org-agenda-regexp-filter
  8750. (get 'org-agenda-regexp-filter :preset-filter))
  8751. '(:eval (propertize
  8752. (concat (mapconcat
  8753. (lambda (x) (concat (substring x 0 1) "/" (substring x 1) "/"))
  8754. (append
  8755. (get 'org-agenda-regexp-filter :preset-filter)
  8756. org-agenda-regexp-filter)
  8757. ""))
  8758. 'face 'org-agenda-filter-regexp
  8759. 'help-echo "Regexp used in filtering"))
  8760. "")
  8761. (if org-agenda-archives-mode
  8762. (if (eq org-agenda-archives-mode t)
  8763. " Archives"
  8764. (format " :%s:" org-archive-tag))
  8765. "")
  8766. (if org-agenda-clockreport-mode " Clock" "")))
  8767. (force-mode-line-update))
  8768. (defun org-agenda-update-agenda-type ()
  8769. "Update the agenda type after each command."
  8770. (setq org-agenda-type
  8771. (or (get-text-property (point) 'org-agenda-type)
  8772. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  8773. (defun org-agenda-next-line ()
  8774. "Move cursor to the next line, and show if follow mode is active."
  8775. (interactive)
  8776. (call-interactively 'next-line)
  8777. (org-agenda-do-context-action))
  8778. (defun org-agenda-previous-line ()
  8779. "Move cursor to the previous line, and show if follow-mode is active."
  8780. (interactive)
  8781. (call-interactively 'previous-line)
  8782. (org-agenda-do-context-action))
  8783. (defun org-agenda-next-item (n)
  8784. "Move cursor to next agenda item."
  8785. (interactive "p")
  8786. (let ((col (current-column)))
  8787. (dotimes (_ n)
  8788. (when (next-single-property-change (line-end-position) 'org-marker)
  8789. (move-end-of-line 1)
  8790. (goto-char (next-single-property-change (point) 'org-marker))))
  8791. (org-move-to-column col))
  8792. (org-agenda-do-context-action))
  8793. (defun org-agenda-previous-item (n)
  8794. "Move cursor to next agenda item."
  8795. (interactive "p")
  8796. (dotimes (_ n)
  8797. (let ((col (current-column))
  8798. (goto (save-excursion
  8799. (move-end-of-line 0)
  8800. (previous-single-property-change (point) 'org-marker))))
  8801. (when goto (goto-char goto))
  8802. (org-move-to-column col)))
  8803. (org-agenda-do-context-action))
  8804. (defun org-agenda-do-context-action ()
  8805. "Show outline path and, maybe, follow mode window."
  8806. (let ((m (org-get-at-bol 'org-marker)))
  8807. (when (and (markerp m) (marker-buffer m))
  8808. (and org-agenda-follow-mode
  8809. (if org-agenda-follow-indirect
  8810. (org-agenda-tree-to-indirect-buffer nil)
  8811. (org-agenda-show)))
  8812. (and org-agenda-show-outline-path
  8813. (org-with-point-at m (org-display-outline-path t))))))
  8814. (defun org-agenda-show-tags ()
  8815. "Show the tags applicable to the current item."
  8816. (interactive)
  8817. (let* ((tags (org-get-at-bol 'tags)))
  8818. (if tags
  8819. (message "Tags are :%s:"
  8820. (org-no-properties (mapconcat #'identity tags ":")))
  8821. (message "No tags associated with this line"))))
  8822. (defun org-agenda-goto (&optional highlight)
  8823. "Go to the entry at point in the corresponding Org file."
  8824. (interactive)
  8825. (let* ((marker (or (org-get-at-bol 'org-marker)
  8826. (org-agenda-error)))
  8827. (buffer (marker-buffer marker))
  8828. (pos (marker-position marker)))
  8829. ;; FIXME: use `org-switch-to-buffer-other-window'?
  8830. (switch-to-buffer-other-window buffer)
  8831. (widen)
  8832. (push-mark)
  8833. (goto-char pos)
  8834. (when (derived-mode-p 'org-mode)
  8835. (org-fold-show-context 'agenda)
  8836. (recenter (/ (window-height) 2))
  8837. (org-back-to-heading t)
  8838. (let ((case-fold-search nil))
  8839. (when (re-search-forward org-complex-heading-regexp nil t)
  8840. (goto-char (match-beginning 4)))))
  8841. (run-hooks 'org-agenda-after-show-hook)
  8842. (and highlight (org-highlight (line-beginning-position) (line-end-position)))))
  8843. (defvar org-agenda-after-show-hook nil
  8844. "Normal hook run after an item has been shown from the agenda.
  8845. Point is in the buffer where the item originated.")
  8846. ;; Defined later in org-agenda.el
  8847. (defvar org-agenda-loop-over-headlines-in-active-region nil)
  8848. (defun org-agenda-do-in-region (beg end cmd &optional arg force-arg delete)
  8849. "Between region BEG and END, call agenda command CMD.
  8850. When optional argument ARG is non-nil or FORCE-ARG is t, pass
  8851. ARG to CMD. When optional argument DELETE is non-nil, assume CMD
  8852. deletes the agenda entry and don't move to the next entry."
  8853. (save-excursion
  8854. (goto-char beg)
  8855. (let ((mend (move-marker (make-marker) end))
  8856. (all (eq org-agenda-loop-over-headlines-in-active-region t))
  8857. (match (and (stringp org-agenda-loop-over-headlines-in-active-region)
  8858. org-agenda-loop-over-headlines-in-active-region))
  8859. (level (and (eq org-agenda-loop-over-headlines-in-active-region 'start-level)
  8860. (org-get-at-bol 'level))))
  8861. (while (< (point) mend)
  8862. (let ((ov (make-overlay (point) (line-end-position))))
  8863. (if (not (or all
  8864. (and match (looking-at-p match))
  8865. (eq level (org-get-at-bol 'level))))
  8866. (org-agenda-next-item 1)
  8867. (overlay-put ov 'face 'region)
  8868. (if (or arg force-arg) (funcall cmd arg) (funcall cmd))
  8869. (when (not delete) (org-agenda-next-item 1))
  8870. (delete-overlay ov)))))))
  8871. ;; org-agenda-[schedule,deadline,date-prompt,todo,[toggle]archive*,
  8872. ;; kill,set-property,set-effort] commands may loop over agenda
  8873. ;; entries. Commands `org-agenda-set-tags' and `org-agenda-bulk-mark'
  8874. ;; use their own mechanisms on active regions.
  8875. (defmacro org-agenda-maybe-loop (cmd arg force-arg delete &rest body)
  8876. "Maybe loop over agenda entries and perform CMD.
  8877. Pass ARG, FORCE-ARG, DELETE and BODY to `org-agenda-do-in-region'."
  8878. (declare (debug t))
  8879. `(if (and (called-interactively-p 'any)
  8880. org-agenda-loop-over-headlines-in-active-region
  8881. (org-region-active-p))
  8882. (org-agenda-do-in-region
  8883. (region-beginning) (region-end) ,cmd ,arg ,force-arg ,delete)
  8884. ,@body))
  8885. (defun org-agenda-kill ()
  8886. "Kill the entry or subtree belonging to the current agenda entry."
  8887. (interactive)
  8888. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8889. (org-agenda-maybe-loop
  8890. #'org-agenda-kill nil nil t
  8891. (let* ((bufname-orig (buffer-name))
  8892. (marker (or (org-get-at-bol 'org-marker)
  8893. (org-agenda-error)))
  8894. (buffer (marker-buffer marker))
  8895. (pos (marker-position marker))
  8896. (type (org-get-at-bol 'type))
  8897. dbeg dend (n 0))
  8898. (org-with-remote-undo buffer
  8899. (with-current-buffer buffer
  8900. (save-excursion
  8901. (goto-char pos)
  8902. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  8903. (setq dbeg (progn (org-back-to-heading t) (point))
  8904. dend (org-end-of-subtree t t))
  8905. (setq dbeg (line-beginning-position)
  8906. dend (min (point-max) (1+ (line-end-position)))))
  8907. (goto-char dbeg)
  8908. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  8909. (when (or (eq t org-agenda-confirm-kill)
  8910. (and (numberp org-agenda-confirm-kill)
  8911. (> n org-agenda-confirm-kill)))
  8912. (let ((win-conf (current-window-configuration)))
  8913. (unwind-protect
  8914. (and
  8915. (prog2
  8916. (org-agenda-tree-to-indirect-buffer nil)
  8917. (not (y-or-n-p
  8918. (format "Delete entry with %d lines in buffer \"%s\"? "
  8919. n (buffer-name buffer))))
  8920. (kill-buffer org-last-indirect-buffer))
  8921. (error "Abort"))
  8922. (set-window-configuration win-conf))))
  8923. (let ((org-agenda-buffer-name bufname-orig))
  8924. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  8925. (with-current-buffer buffer (delete-region dbeg dend))
  8926. (message "Agenda item and source killed")))))
  8927. (defvar org-archive-default-command) ; defined in org-archive.el
  8928. (defun org-agenda-archive-default ()
  8929. "Archive the entry or subtree belonging to the current agenda entry."
  8930. (interactive)
  8931. (require 'org-archive)
  8932. (funcall-interactively
  8933. #'org-agenda-archive-with org-archive-default-command))
  8934. (defun org-agenda-archive-default-with-confirmation ()
  8935. "Archive the entry or subtree belonging to the current agenda entry."
  8936. (interactive)
  8937. (require 'org-archive)
  8938. (funcall-interactively
  8939. #'org-agenda-archive-with org-archive-default-command 'confirm))
  8940. (defun org-agenda-archive ()
  8941. "Archive the entry or subtree belonging to the current agenda entry."
  8942. (interactive)
  8943. (funcall-interactively
  8944. #'org-agenda-archive-with 'org-archive-subtree))
  8945. (defun org-agenda-archive-to-archive-sibling ()
  8946. "Move the entry to the archive sibling."
  8947. (interactive)
  8948. (funcall-interactively
  8949. #'org-agenda-archive-with 'org-archive-to-archive-sibling))
  8950. (defvar org-archive-from-agenda)
  8951. (defun org-agenda-archive-with (cmd &optional confirm)
  8952. "Move the entry to the archive sibling."
  8953. (interactive)
  8954. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8955. (org-agenda-maybe-loop
  8956. #'org-agenda-archive-with cmd nil t
  8957. (let* ((bufname-orig (buffer-name))
  8958. (marker (or (org-get-at-bol 'org-marker)
  8959. (org-agenda-error)))
  8960. (buffer (marker-buffer marker))
  8961. (pos (marker-position marker)))
  8962. (org-with-remote-undo buffer
  8963. (with-current-buffer buffer
  8964. (if (derived-mode-p 'org-mode)
  8965. (if (and confirm
  8966. (not (y-or-n-p "Archive this subtree or entry? ")))
  8967. (error "Abort")
  8968. (save-window-excursion
  8969. (goto-char pos)
  8970. (let ((org-agenda-buffer-name bufname-orig))
  8971. (org-remove-subtree-entries-from-agenda))
  8972. (org-back-to-heading t)
  8973. (let ((org-archive-from-agenda t))
  8974. (funcall cmd))))
  8975. (error "Archiving works only in Org files")))))))
  8976. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  8977. "Remove all lines in the agenda that correspond to a given subtree.
  8978. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  8979. If this information is not given, the function uses the tree at point."
  8980. (let ((buf (or buf (current-buffer))) m p)
  8981. (save-excursion
  8982. (unless (and beg end)
  8983. (org-back-to-heading t)
  8984. (setq beg (point))
  8985. (org-end-of-subtree t)
  8986. (setq end (point)))
  8987. (set-buffer (get-buffer org-agenda-buffer-name))
  8988. (save-excursion
  8989. (goto-char (point-max))
  8990. (beginning-of-line 1)
  8991. (while (not (bobp))
  8992. (when (and (setq m (org-get-at-bol 'org-marker))
  8993. (equal buf (marker-buffer m))
  8994. (setq p (marker-position m))
  8995. (>= p beg)
  8996. (< p end))
  8997. (let ((inhibit-read-only t))
  8998. (delete-region (line-beginning-position) (1+ (line-end-position)))))
  8999. (beginning-of-line 0))))))
  9000. (defun org-agenda-refile (&optional goto rfloc no-update)
  9001. "Refile the item at point.
  9002. When called with `\\[universal-argument] \\[universal-argument]', \
  9003. go to the location of the last
  9004. refiled item.
  9005. When called with `\\[universal-argument] \\[universal-argument] \
  9006. \\[universal-argument]' prefix or when GOTO is 0, clear
  9007. the refile cache.
  9008. RFLOC can be a refile location obtained in a different way.
  9009. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  9010. (interactive "P")
  9011. (cond
  9012. ((member goto '(0 (64)))
  9013. (org-refile-cache-clear))
  9014. ((equal goto '(16))
  9015. (org-refile-goto-last-stored))
  9016. (t
  9017. (let* ((buffer-orig (buffer-name))
  9018. (marker (or (org-get-at-bol 'org-hd-marker)
  9019. (org-agenda-error)))
  9020. (buffer (marker-buffer marker))
  9021. ;; (pos (marker-position marker))
  9022. (rfloc (or rfloc
  9023. (org-refile-get-location
  9024. (if goto "Goto" "Refile to") buffer
  9025. org-refile-allow-creating-parent-nodes))))
  9026. (with-current-buffer buffer
  9027. (org-with-wide-buffer
  9028. (goto-char marker)
  9029. (let ((org-agenda-buffer-name buffer-orig))
  9030. (org-remove-subtree-entries-from-agenda))
  9031. (org-refile goto buffer rfloc))))
  9032. (unless no-update (org-agenda-redo)))))
  9033. (defun org-agenda-open-link (&optional arg)
  9034. "Open the link(s) in the current entry, if any.
  9035. This looks for a link in the displayed line in the agenda.
  9036. It also looks at the text of the entry itself."
  9037. (interactive "P")
  9038. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  9039. (org-get-at-bol 'org-marker)))
  9040. (buffer (and marker (marker-buffer marker)))
  9041. (prefix (buffer-substring (line-beginning-position) (line-end-position)))
  9042. (lkall (and buffer (org-offer-links-in-entry
  9043. buffer marker arg prefix)))
  9044. (lk0 (car lkall))
  9045. (lk (if (stringp lk0) (list lk0) lk0))
  9046. (lkend (cdr lkall))
  9047. trg)
  9048. (cond
  9049. ((and buffer lk)
  9050. (mapcar (lambda(l)
  9051. (with-current-buffer buffer
  9052. (setq trg (and (string-match org-link-bracket-re l)
  9053. (match-string 1 l)))
  9054. (if (or (not trg) (string-match org-link-any-re trg))
  9055. ;; Don't use `org-with-wide-buffer' here as
  9056. ;; opening the link may result in moving the point
  9057. (save-restriction
  9058. (widen)
  9059. (goto-char marker)
  9060. (when (search-forward l nil lkend)
  9061. (goto-char (match-beginning 0))
  9062. (org-open-at-point)))
  9063. ;; This is an internal link, widen the buffer
  9064. ;; FIXME: use `org-switch-to-buffer-other-window'?
  9065. (switch-to-buffer-other-window buffer)
  9066. (widen)
  9067. (goto-char marker)
  9068. (when (search-forward l nil lkend)
  9069. (goto-char (match-beginning 0))
  9070. (org-open-at-point)))))
  9071. lk))
  9072. ((or (org-in-regexp (concat "\\(" org-link-bracket-re "\\)"))
  9073. (save-excursion
  9074. (beginning-of-line 1)
  9075. (looking-at (concat ".*?\\(" org-link-bracket-re "\\)"))))
  9076. (org-link-open-from-string (match-string 1)))
  9077. (t (message "No link to open here")))))
  9078. (defun org-agenda-copy-local-variable (var)
  9079. "Get a variable from a referenced buffer and install it here."
  9080. (let ((m (org-get-at-bol 'org-marker)))
  9081. (when (and m (buffer-live-p (marker-buffer m)))
  9082. (set (make-local-variable var)
  9083. (with-current-buffer (marker-buffer m)
  9084. (symbol-value var))))))
  9085. (defun org-agenda-switch-to (&optional delete-other-windows)
  9086. "Go to the Org mode file which contains the item at point.
  9087. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  9088. displayed Org file fills the frame."
  9089. (interactive)
  9090. (if (and org-return-follows-link
  9091. (not (org-get-at-bol 'org-marker))
  9092. (org-in-regexp org-link-bracket-re))
  9093. (org-link-open-from-string (match-string 0))
  9094. (let* ((marker (or (org-get-at-bol 'org-marker)
  9095. (org-agenda-error)))
  9096. (buffer (marker-buffer marker))
  9097. (pos (marker-position marker)))
  9098. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  9099. (pop-to-buffer-same-window buffer)
  9100. (when delete-other-windows (delete-other-windows))
  9101. (widen)
  9102. (goto-char pos)
  9103. (when (derived-mode-p 'org-mode)
  9104. (org-fold-show-context 'agenda)
  9105. (run-hooks 'org-agenda-after-show-hook)))))
  9106. (defun org-agenda-goto-mouse (ev)
  9107. "Go to the Org file which contains the item at the mouse click."
  9108. (interactive "e")
  9109. (mouse-set-point ev)
  9110. (org-agenda-goto))
  9111. (defun org-agenda-show (&optional full-entry)
  9112. "Display the Org file which contains the item at point.
  9113. With prefix argument FULL-ENTRY, make the entire entry visible
  9114. if it was hidden in the outline."
  9115. (interactive "P")
  9116. (let ((win (selected-window)))
  9117. (org-agenda-goto t)
  9118. (when full-entry (org-fold-show-entry 'hide-drawers))
  9119. (select-window win)))
  9120. (defvar org-agenda-show-window nil)
  9121. (defun org-agenda-show-and-scroll-up (&optional arg)
  9122. "Display the Org file which contains the item at point.
  9123. When called repeatedly, scroll the window that is displaying the buffer.
  9124. With a `\\[universal-argument]' prefix argument, display the item, but \
  9125. fold drawers."
  9126. (interactive "P")
  9127. (let ((win (selected-window)))
  9128. (if (and (window-live-p org-agenda-show-window)
  9129. (eq this-command last-command))
  9130. (progn
  9131. (select-window org-agenda-show-window)
  9132. (ignore-errors (scroll-up)))
  9133. (org-agenda-goto t)
  9134. (org-fold-show-entry 'hide-drawers)
  9135. (if arg (org-cycle-hide-drawers 'children)
  9136. (org-with-wide-buffer
  9137. (narrow-to-region (org-entry-beginning-position)
  9138. (org-entry-end-position))
  9139. (org-fold-show-all '(drawers))))
  9140. (setq org-agenda-show-window (selected-window)))
  9141. (select-window win)))
  9142. (defun org-agenda-show-scroll-down ()
  9143. "Scroll down the window showing the agenda."
  9144. (interactive)
  9145. (let ((win (selected-window)))
  9146. (when (window-live-p org-agenda-show-window)
  9147. (select-window org-agenda-show-window)
  9148. (ignore-errors (scroll-down))
  9149. (select-window win))))
  9150. (defun org-agenda-show-1 (&optional more)
  9151. "Display the Org file which contains the item at point.
  9152. The prefix arg selects the amount of information to display:
  9153. 0 hide the subtree
  9154. 1 just show the entry according to defaults.
  9155. 2 show the children view
  9156. 3 show the subtree view
  9157. 4 show the entire subtree and any drawers
  9158. With prefix argument FULL-ENTRY, make the entire entry visible
  9159. if it was hidden in the outline."
  9160. (interactive "p")
  9161. (let ((win (selected-window)))
  9162. (org-agenda-goto t)
  9163. (org-back-to-heading)
  9164. (set-window-start (selected-window) (line-beginning-position))
  9165. (cond
  9166. ((= more 0)
  9167. (org-fold-subtree t)
  9168. (save-excursion
  9169. (org-back-to-heading)
  9170. (run-hook-with-args 'org-cycle-hook 'folded))
  9171. (message "Remote: FOLDED"))
  9172. ((and (called-interactively-p 'any) (= more 1))
  9173. (message "Remote: show with default settings"))
  9174. ((= more 2)
  9175. (org-fold-show-entry 'hide-drawers)
  9176. (org-fold-show-children)
  9177. (save-excursion
  9178. (org-back-to-heading)
  9179. (run-hook-with-args 'org-cycle-hook 'children))
  9180. (message "Remote: CHILDREN"))
  9181. ((= more 3)
  9182. (org-fold-show-subtree)
  9183. (save-excursion
  9184. (org-back-to-heading)
  9185. (run-hook-with-args 'org-cycle-hook 'subtree))
  9186. (message "Remote: SUBTREE"))
  9187. ((> more 3)
  9188. (org-fold-show-subtree)
  9189. (message "Remote: SUBTREE AND ALL DRAWERS")))
  9190. (select-window win)))
  9191. (defvar org-agenda-cycle-counter nil)
  9192. (defun org-agenda-cycle-show (&optional n)
  9193. "Show the current entry in another window, with default settings.
  9194. Default settings are taken from `org-show-context-detail'. When
  9195. use repeatedly in immediate succession, the remote entry will
  9196. cycle through visibility
  9197. children -> subtree -> folded
  9198. When called with a numeric prefix arg, that arg will be passed through to
  9199. `org-agenda-show-1'. For the interpretation of that argument, see the
  9200. docstring of `org-agenda-show-1'."
  9201. (interactive "P")
  9202. (if (integerp n)
  9203. (setq org-agenda-cycle-counter n)
  9204. (if (not (eq last-command this-command))
  9205. (setq org-agenda-cycle-counter 1)
  9206. (if (equal org-agenda-cycle-counter 0)
  9207. (setq org-agenda-cycle-counter 2)
  9208. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  9209. (when (> org-agenda-cycle-counter 3)
  9210. (setq org-agenda-cycle-counter 0)))))
  9211. (org-agenda-show-1 org-agenda-cycle-counter))
  9212. (defun org-agenda-recenter (arg)
  9213. "Display the Org file which contains the item at point and recenter."
  9214. (interactive "P")
  9215. (let ((win (selected-window)))
  9216. (org-agenda-goto t)
  9217. (recenter arg)
  9218. (select-window win)))
  9219. (defun org-agenda-show-mouse (ev)
  9220. "Display the Org file which contains the item at the mouse click."
  9221. (interactive "e")
  9222. (mouse-set-point ev)
  9223. (org-agenda-show))
  9224. (defun org-agenda-check-no-diary ()
  9225. "Check if the entry is a diary link and abort if yes."
  9226. (when (org-get-at-bol 'org-agenda-diary-link)
  9227. (org-agenda-error)))
  9228. (defun org-agenda-error ()
  9229. "Throw an error when a command is not allowed in the agenda."
  9230. (user-error "Command not allowed in this line"))
  9231. (defun org-agenda-tree-to-indirect-buffer (arg)
  9232. "Show the subtree corresponding to the current entry in an indirect buffer.
  9233. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  9234. With a numerical prefix ARG, go up to this level and then take that tree.
  9235. With a negative numeric ARG, go up by this number of levels.
  9236. With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
  9237. i.e. don't use
  9238. the dedicated frame."
  9239. (interactive "P")
  9240. (if current-prefix-arg
  9241. (org-agenda-do-tree-to-indirect-buffer arg)
  9242. (let ((agenda-buffer (buffer-name))
  9243. (agenda-window (selected-window))
  9244. (indirect-window
  9245. (and org-last-indirect-buffer
  9246. (get-buffer-window org-last-indirect-buffer))))
  9247. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  9248. (unless (or (eq org-indirect-buffer-display 'new-frame)
  9249. (eq org-indirect-buffer-display 'dedicated-frame))
  9250. (unwind-protect
  9251. (unless (and indirect-window (window-live-p indirect-window))
  9252. (setq indirect-window (split-window agenda-window)))
  9253. (and indirect-window (select-window indirect-window))
  9254. (switch-to-buffer org-last-indirect-buffer :norecord)
  9255. (fit-window-to-buffer indirect-window)))
  9256. (select-window (get-buffer-window agenda-buffer))
  9257. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  9258. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  9259. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  9260. (org-agenda-check-no-diary)
  9261. (let* ((marker (or (org-get-at-bol 'org-marker)
  9262. (org-agenda-error)))
  9263. (buffer (marker-buffer marker))
  9264. (pos (marker-position marker)))
  9265. (with-current-buffer buffer
  9266. (save-excursion
  9267. (goto-char pos)
  9268. (org-tree-to-indirect-buffer arg)))))
  9269. (defvar org-last-heading-marker (make-marker)
  9270. "Marker pointing to the headline that last changed its TODO state
  9271. by a remote command from the agenda.")
  9272. (defun org-agenda-todo-nextset ()
  9273. "Switch TODO entry to next sequence."
  9274. (interactive)
  9275. (org-agenda-todo 'nextset))
  9276. (defun org-agenda-todo-previousset ()
  9277. "Switch TODO entry to previous sequence."
  9278. (interactive)
  9279. (org-agenda-todo 'previousset))
  9280. (defvar org-agenda-headline-snapshot-before-repeat)
  9281. (defun org-agenda-todo (&optional arg)
  9282. "Cycle TODO state of line at point, also in Org file.
  9283. This changes the line at point, all other lines in the agenda referring to
  9284. the same tree node, and the headline of the tree node in the Org file."
  9285. (interactive "P")
  9286. (org-agenda-check-no-diary)
  9287. (org-agenda-maybe-loop
  9288. #'org-agenda-todo arg nil nil
  9289. (let* ((col (current-column))
  9290. (marker (or (org-get-at-bol 'org-marker)
  9291. (org-agenda-error)))
  9292. (buffer (marker-buffer marker))
  9293. (pos (marker-position marker))
  9294. (hdmarker (org-get-at-bol 'org-hd-marker))
  9295. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  9296. (inhibit-read-only t)
  9297. org-loop-over-headlines-in-active-region
  9298. org-agenda-headline-snapshot-before-repeat newhead just-one)
  9299. (org-with-remote-undo buffer
  9300. (with-current-buffer buffer
  9301. (widen)
  9302. (goto-char pos)
  9303. (org-fold-show-context 'agenda)
  9304. (let ((current-prefix-arg arg))
  9305. (call-interactively 'org-todo)
  9306. ;; Make sure that log is recorded in current undo.
  9307. (when (and org-log-setup
  9308. (not (eq org-log-note-how 'note)))
  9309. (org-add-log-note)))
  9310. (and (bolp) (forward-char 1))
  9311. (setq newhead (org-get-heading))
  9312. (when (and org-agenda-headline-snapshot-before-repeat
  9313. (not (equal org-agenda-headline-snapshot-before-repeat
  9314. newhead))
  9315. todayp)
  9316. (setq newhead org-agenda-headline-snapshot-before-repeat
  9317. just-one t))
  9318. (save-excursion
  9319. (org-back-to-heading)
  9320. (move-marker org-last-heading-marker (point))))
  9321. (beginning-of-line 1)
  9322. (save-window-excursion
  9323. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  9324. (when (bound-and-true-p org-clock-out-when-done)
  9325. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  9326. newhead)
  9327. (org-agenda-unmark-clocking-task))
  9328. (org-move-to-column col)
  9329. (org-agenda-mark-clocking-task)))))
  9330. (defun org-agenda-add-note (&optional _arg)
  9331. "Add a time-stamped note to the entry at point."
  9332. (interactive) ;; "P"
  9333. (org-agenda-check-no-diary)
  9334. (let* ((marker (or (org-get-at-bol 'org-marker)
  9335. (org-agenda-error)))
  9336. (buffer (marker-buffer marker))
  9337. (pos (marker-position marker))
  9338. (_hdmarker (org-get-at-bol 'org-hd-marker))
  9339. (inhibit-read-only t))
  9340. (with-current-buffer buffer
  9341. (widen)
  9342. (goto-char pos)
  9343. (org-fold-show-context 'agenda)
  9344. (org-add-note))))
  9345. (defun org-agenda-change-all-lines (newhead hdmarker
  9346. &optional fixface just-this)
  9347. "Change all lines in the agenda buffer which match HDMARKER.
  9348. The new content of the line will be NEWHEAD (as modified by
  9349. `org-agenda-format-item'). HDMARKER is checked with
  9350. `equal' against all `org-hd-marker' text properties in the file.
  9351. If FIXFACE is non-nil, the face of each item is modified according to
  9352. the new TODO state.
  9353. If JUST-THIS is non-nil, change just the current line, not all.
  9354. If FORCE-TAGS is non-nil, the car of it returns the new tags."
  9355. (let* ((inhibit-read-only t)
  9356. (line (org-current-line))
  9357. (org-agenda-buffer (current-buffer))
  9358. (thetags (with-current-buffer (marker-buffer hdmarker)
  9359. (org-get-tags hdmarker)))
  9360. props m undone-face done-face finish new dotime level cat tags
  9361. effort effort-minutes) ;; pl
  9362. (save-excursion
  9363. (goto-char (point-max))
  9364. (beginning-of-line 1)
  9365. (while (not finish)
  9366. (setq finish (bobp))
  9367. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  9368. (or (not just-this) (= (org-current-line) line))
  9369. (equal m hdmarker))
  9370. (setq props (text-properties-at (point))
  9371. dotime (org-get-at-bol 'dotime)
  9372. cat (org-agenda-get-category)
  9373. level (org-get-at-bol 'level)
  9374. tags thetags
  9375. effort (org-get-at-bol 'effort)
  9376. effort-minutes (org-get-at-bol 'effort-minutes)
  9377. new
  9378. (let ((org-prefix-format-compiled
  9379. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  9380. org-prefix-format-compiled))
  9381. (extra (org-get-at-bol 'extra)))
  9382. (with-current-buffer (marker-buffer hdmarker)
  9383. (org-with-wide-buffer
  9384. (org-agenda-format-item extra
  9385. (org-add-props newhead nil
  9386. 'effort effort
  9387. 'effort-minutes effort-minutes)
  9388. level cat tags dotime))))
  9389. ;; pl (text-property-any (line-beginning-position) (line-end-position) 'org-heading t)
  9390. undone-face (org-get-at-bol 'undone-face)
  9391. done-face (org-get-at-bol 'done-face))
  9392. (beginning-of-line 1)
  9393. (cond
  9394. ((equal new "") (delete-region (point) (line-beginning-position 2)))
  9395. ((looking-at ".*")
  9396. ;; When replacing the whole line, preserve bulk mark
  9397. ;; overlay, if any.
  9398. (let ((mark (catch :overlay
  9399. (dolist (o (overlays-in (point) (+ 2 (point))))
  9400. (when (eq (overlay-get o 'type)
  9401. 'org-marked-entry-overlay)
  9402. (throw :overlay o))))))
  9403. (replace-match new t t)
  9404. (beginning-of-line)
  9405. (when mark (move-overlay mark (point) (+ 2 (point)))))
  9406. (add-text-properties (line-beginning-position) (line-end-position) props)
  9407. (when fixface
  9408. (add-text-properties
  9409. (line-beginning-position) (line-end-position)
  9410. (list 'face
  9411. (if org-last-todo-state-is-todo
  9412. undone-face done-face))))
  9413. (org-agenda-highlight-todo 'line)
  9414. (beginning-of-line 1))
  9415. (t (error "Line update did not work")))
  9416. (save-restriction
  9417. (narrow-to-region (line-beginning-position) (line-end-position))
  9418. (org-agenda-finalize)))
  9419. (beginning-of-line 0)))))
  9420. (defun org-agenda-align-tags (&optional line)
  9421. "Align all tags in agenda items to `org-agenda-tags-column'.
  9422. When optional argument LINE is non-nil, align tags only on the
  9423. current line."
  9424. (let ((inhibit-read-only t)
  9425. (org-agenda-tags-column (if (eq 'auto org-agenda-tags-column)
  9426. (- (window-max-chars-per-line))
  9427. org-agenda-tags-column))
  9428. (end (and line (line-end-position)))
  9429. l c)
  9430. (org-fold-core-ignore-modifications
  9431. (save-excursion
  9432. (goto-char (if line (line-beginning-position) (point-min)))
  9433. (while (re-search-forward org-tag-group-re end t)
  9434. (add-text-properties
  9435. (match-beginning 1) (match-end 1)
  9436. (list 'face (delq nil (let ((prop (get-text-property
  9437. (match-beginning 1) 'face)))
  9438. (or (listp prop) (setq prop (list prop)))
  9439. (if (memq 'org-tag prop)
  9440. prop
  9441. (cons 'org-tag prop))))))
  9442. (setq l (string-width (match-string 1))
  9443. c (if (< org-agenda-tags-column 0)
  9444. (- (abs org-agenda-tags-column) l)
  9445. org-agenda-tags-column))
  9446. (goto-char (match-beginning 1))
  9447. (delete-region (save-excursion (skip-chars-backward " \t") (point))
  9448. (point))
  9449. (insert (org-add-props
  9450. (make-string (max 1 (- c (current-column))) ?\s)
  9451. (plist-put (copy-sequence (text-properties-at (point)))
  9452. 'face nil))))
  9453. (goto-char (point-min))
  9454. (org-font-lock-add-tag-faces (point-max))))))
  9455. (defun org-agenda-priority-up ()
  9456. "Increase the priority of line at point, also in Org file."
  9457. (interactive)
  9458. (org-agenda-priority 'up))
  9459. (defun org-agenda-priority-down ()
  9460. "Decrease the priority of line at point, also in Org file."
  9461. (interactive)
  9462. (org-agenda-priority 'down))
  9463. (defun org-agenda-priority (&optional force-direction)
  9464. "Set the priority of line at point, also in Org file.
  9465. This changes the line at point, all other lines in the agenda
  9466. referring to the same tree node, and the headline of the tree
  9467. node in the Org file.
  9468. Called with one universal prefix arg, show the priority instead
  9469. of setting it.
  9470. When called programmatically, FORCE-DIRECTION can be `set', `up',
  9471. `down', or a character."
  9472. (interactive "P")
  9473. (unless org-priority-enable-commands
  9474. (user-error "Priority commands are disabled"))
  9475. (org-agenda-check-no-diary)
  9476. (let* ((col (current-column))
  9477. (hdmarker (org-get-at-bol 'org-hd-marker))
  9478. (buffer (marker-buffer hdmarker))
  9479. (pos (marker-position hdmarker))
  9480. (inhibit-read-only t)
  9481. newhead)
  9482. (org-with-remote-undo buffer
  9483. (with-current-buffer buffer
  9484. (widen)
  9485. (goto-char pos)
  9486. (org-fold-show-context 'agenda)
  9487. (org-priority force-direction)
  9488. (end-of-line 1)
  9489. (setq newhead (org-get-heading)))
  9490. (org-agenda-change-all-lines newhead hdmarker)
  9491. (org-move-to-column col))))
  9492. ;; FIXME: should fix the tags property of the agenda line.
  9493. (defun org-agenda-set-tags (&optional tag onoff)
  9494. "Set tags for the current headline."
  9495. (interactive)
  9496. (org-agenda-check-no-diary)
  9497. (if (and (org-region-active-p) (called-interactively-p 'any))
  9498. (call-interactively 'org-change-tag-in-region)
  9499. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9500. (org-agenda-error)))
  9501. (buffer (marker-buffer hdmarker))
  9502. (pos (marker-position hdmarker))
  9503. (inhibit-read-only t)
  9504. newhead)
  9505. (org-with-remote-undo buffer
  9506. (with-current-buffer buffer
  9507. (widen)
  9508. (goto-char pos)
  9509. (org-fold-show-context 'agenda)
  9510. (if tag
  9511. (org-toggle-tag tag onoff)
  9512. (call-interactively #'org-set-tags-command))
  9513. (end-of-line 1)
  9514. (setq newhead (org-get-heading)))
  9515. (org-agenda-change-all-lines newhead hdmarker)
  9516. (beginning-of-line 1)))))
  9517. (defun org-agenda-set-property ()
  9518. "Set a property for the current headline."
  9519. (interactive)
  9520. (org-agenda-check-no-diary)
  9521. (org-agenda-maybe-loop
  9522. #'org-agenda-set-property nil nil nil
  9523. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9524. (org-agenda-error)))
  9525. (buffer (marker-buffer hdmarker))
  9526. (pos (marker-position hdmarker))
  9527. (inhibit-read-only t)
  9528. ) ;; newhead
  9529. (org-with-remote-undo buffer
  9530. (with-current-buffer buffer
  9531. (widen)
  9532. (goto-char pos)
  9533. (org-fold-show-context 'agenda)
  9534. (call-interactively 'org-set-property))))))
  9535. (defun org-agenda-set-effort ()
  9536. "Set the effort property for the current headline."
  9537. (interactive)
  9538. (org-agenda-check-no-diary)
  9539. (org-agenda-maybe-loop
  9540. #'org-agenda-set-effort nil nil nil
  9541. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9542. (org-agenda-error)))
  9543. (buffer (marker-buffer hdmarker))
  9544. (pos (marker-position hdmarker))
  9545. (inhibit-read-only t)
  9546. newhead)
  9547. (org-with-remote-undo buffer
  9548. (with-current-buffer buffer
  9549. (widen)
  9550. (goto-char pos)
  9551. (org-fold-show-context 'agenda)
  9552. (call-interactively 'org-set-effort)
  9553. (end-of-line 1)
  9554. (setq newhead (org-get-heading)))
  9555. (org-agenda-change-all-lines newhead hdmarker)))))
  9556. (defun org-agenda-toggle-archive-tag ()
  9557. "Toggle the archive tag for the current entry."
  9558. (interactive)
  9559. (org-agenda-check-no-diary)
  9560. (org-agenda-maybe-loop
  9561. #'org-agenda-toggle-archive-tag nil nil nil
  9562. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9563. (org-agenda-error)))
  9564. (buffer (marker-buffer hdmarker))
  9565. (pos (marker-position hdmarker))
  9566. (inhibit-read-only t)
  9567. newhead)
  9568. (org-with-remote-undo buffer
  9569. (with-current-buffer buffer
  9570. (widen)
  9571. (goto-char pos)
  9572. (org-fold-show-context 'agenda)
  9573. (call-interactively 'org-toggle-archive-tag)
  9574. (end-of-line 1)
  9575. (setq newhead (org-get-heading)))
  9576. (org-agenda-change-all-lines newhead hdmarker)
  9577. (beginning-of-line 1)))))
  9578. (defun org-agenda-do-date-later (arg)
  9579. (interactive "P")
  9580. (cond
  9581. ((or (equal arg '(16))
  9582. (memq last-command
  9583. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9584. (setq this-command 'org-agenda-date-later-minutes)
  9585. (org-agenda-date-later-minutes 1))
  9586. ((or (equal arg '(4))
  9587. (memq last-command
  9588. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9589. (setq this-command 'org-agenda-date-later-hours)
  9590. (org-agenda-date-later-hours 1))
  9591. (t
  9592. (org-agenda-date-later (prefix-numeric-value arg)))))
  9593. (defun org-agenda-do-date-earlier (arg)
  9594. (interactive "P")
  9595. (cond
  9596. ((or (equal arg '(16))
  9597. (memq last-command
  9598. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9599. (setq this-command 'org-agenda-date-earlier-minutes)
  9600. (org-agenda-date-earlier-minutes 1))
  9601. ((or (equal arg '(4))
  9602. (memq last-command
  9603. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9604. (setq this-command 'org-agenda-date-earlier-hours)
  9605. (org-agenda-date-earlier-hours 1))
  9606. (t
  9607. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  9608. (defun org-agenda-date-later (arg &optional what)
  9609. "Change the date of this item to ARG day(s) later."
  9610. (interactive "p")
  9611. (org-agenda-check-type t 'agenda)
  9612. (org-agenda-check-no-diary)
  9613. (let* ((marker (or (org-get-at-bol 'org-marker)
  9614. (org-agenda-error)))
  9615. (buffer (marker-buffer marker))
  9616. (pos (marker-position marker))
  9617. cdate today)
  9618. (org-with-remote-undo buffer
  9619. (with-current-buffer buffer
  9620. (widen)
  9621. (goto-char pos)
  9622. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9623. (when (and org-agenda-move-date-from-past-immediately-to-today
  9624. (equal arg 1)
  9625. (or (not what) (eq what 'day))
  9626. (not (save-match-data (org-at-date-range-p))))
  9627. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  9628. cdate (calendar-absolute-from-gregorian
  9629. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  9630. today (org-today))
  9631. (when (> today cdate)
  9632. ;; immediately shift to today
  9633. (setq arg (- today cdate))))
  9634. (org-timestamp-change arg (or what 'day))
  9635. (when (and (org-at-date-range-p)
  9636. (re-search-backward org-tr-regexp-both (line-beginning-position)))
  9637. (let ((end org-last-changed-timestamp))
  9638. (org-timestamp-change arg (or what 'day))
  9639. (setq org-last-changed-timestamp
  9640. (concat org-last-changed-timestamp "--" end)))))
  9641. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9642. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  9643. (defun org-agenda-date-earlier (arg &optional what)
  9644. "Change the date of this item to ARG day(s) earlier."
  9645. (interactive "p")
  9646. (org-agenda-date-later (- arg) what))
  9647. (defun org-agenda-date-later-minutes (arg)
  9648. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9649. (interactive "p")
  9650. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9651. (org-agenda-date-later arg 'minute))
  9652. (defun org-agenda-date-earlier-minutes (arg)
  9653. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9654. (interactive "p")
  9655. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9656. (org-agenda-date-earlier arg 'minute))
  9657. (defun org-agenda-date-later-hours (arg)
  9658. "Change the time of this item, in hour steps."
  9659. (interactive "p")
  9660. (org-agenda-date-later arg 'hour))
  9661. (defun org-agenda-date-earlier-hours (arg)
  9662. "Change the time of this item, in hour steps."
  9663. (interactive "p")
  9664. (org-agenda-date-earlier arg 'hour))
  9665. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  9666. "Show new date stamp via text properties."
  9667. ;; We use text properties to make this undoable
  9668. (let ((inhibit-read-only t))
  9669. (setq stamp (concat prefix " => " stamp " "))
  9670. (save-excursion
  9671. (goto-char (point-max))
  9672. (while (not (bobp))
  9673. (when (equal marker (org-get-at-bol 'org-marker))
  9674. (remove-text-properties (line-beginning-position)
  9675. (line-end-position)
  9676. '(display nil))
  9677. (org-move-to-column
  9678. (- (window-max-chars-per-line)
  9679. (length stamp))
  9680. t)
  9681. (add-text-properties
  9682. (1- (point)) (line-end-position)
  9683. (list 'display (org-add-props stamp nil
  9684. 'face '(secondary-selection default))))
  9685. (beginning-of-line 1))
  9686. (beginning-of-line 0)))))
  9687. (defun org-agenda-date-prompt (arg)
  9688. "Change the date of this item. Date is prompted for, with default today.
  9689. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  9690. be used to request time specification in the time stamp."
  9691. (interactive "P")
  9692. (org-agenda-check-type t 'agenda)
  9693. (org-agenda-check-no-diary)
  9694. (org-agenda-maybe-loop
  9695. #'org-agenda-date-prompt arg t nil
  9696. (let* ((marker (or (org-get-at-bol 'org-marker)
  9697. (org-agenda-error)))
  9698. (buffer (marker-buffer marker))
  9699. (pos (marker-position marker)))
  9700. (org-with-remote-undo buffer
  9701. (with-current-buffer buffer
  9702. (widen)
  9703. (goto-char pos)
  9704. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9705. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  9706. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9707. (message "Time stamp changed to %s" org-last-changed-timestamp))))
  9708. (defun org-agenda-schedule (arg &optional time)
  9709. "Schedule the item at point.
  9710. ARG is passed through to `org-schedule'."
  9711. (interactive "P")
  9712. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9713. (org-agenda-check-no-diary)
  9714. (org-agenda-maybe-loop
  9715. #'org-agenda-schedule arg t nil
  9716. (let* ((marker (or (org-get-at-bol 'org-marker)
  9717. (org-agenda-error)))
  9718. ;; (type (marker-insertion-type marker))
  9719. (buffer (marker-buffer marker))
  9720. (pos (marker-position marker))
  9721. ts)
  9722. (set-marker-insertion-type marker t)
  9723. (org-with-remote-undo buffer
  9724. (with-current-buffer buffer
  9725. (widen)
  9726. (goto-char pos)
  9727. (setq ts (org-schedule arg time)))
  9728. (org-agenda-show-new-time marker ts " S"))
  9729. (message "%s" ts))))
  9730. (defun org-agenda-deadline (arg &optional time)
  9731. "Schedule the item at point.
  9732. ARG is passed through to `org-deadline'."
  9733. (interactive "P")
  9734. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9735. (org-agenda-check-no-diary)
  9736. (org-agenda-maybe-loop
  9737. #'org-agenda-deadline arg t nil
  9738. (let* ((marker (or (org-get-at-bol 'org-marker)
  9739. (org-agenda-error)))
  9740. (buffer (marker-buffer marker))
  9741. (pos (marker-position marker))
  9742. ts)
  9743. (org-with-remote-undo buffer
  9744. (with-current-buffer buffer
  9745. (widen)
  9746. (goto-char pos)
  9747. (setq ts (org-deadline arg time)))
  9748. (org-agenda-show-new-time marker ts " D"))
  9749. (message "%s" ts))))
  9750. (defun org-agenda-clock-in (&optional arg)
  9751. "Start the clock on the currently selected item."
  9752. (interactive "P")
  9753. (org-agenda-check-no-diary)
  9754. (if (equal arg '(4))
  9755. (org-clock-in arg)
  9756. (let* ((marker (or (org-get-at-bol 'org-marker)
  9757. (org-agenda-error)))
  9758. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  9759. (pos (marker-position marker))
  9760. (col (current-column))
  9761. newhead)
  9762. (org-with-remote-undo (marker-buffer marker)
  9763. (with-current-buffer (marker-buffer marker)
  9764. (widen)
  9765. (goto-char pos)
  9766. (org-fold-show-context 'agenda)
  9767. (org-clock-in arg)
  9768. (setq newhead (org-get-heading)))
  9769. (org-agenda-change-all-lines newhead hdmarker))
  9770. (org-move-to-column col))))
  9771. (defun org-agenda-clock-out ()
  9772. "Stop the currently running clock."
  9773. (interactive)
  9774. (unless (marker-buffer org-clock-marker)
  9775. (user-error "No running clock"))
  9776. (let ((marker (make-marker)) (col (current-column)) newhead)
  9777. (org-with-remote-undo (marker-buffer org-clock-marker)
  9778. (with-current-buffer (marker-buffer org-clock-marker)
  9779. (org-with-wide-buffer
  9780. (goto-char org-clock-marker)
  9781. (org-back-to-heading t)
  9782. (move-marker marker (point))
  9783. (org-clock-out)
  9784. (setq newhead (org-get-heading)))))
  9785. (org-agenda-change-all-lines newhead marker)
  9786. (move-marker marker nil)
  9787. (org-move-to-column col)
  9788. (org-agenda-unmark-clocking-task)))
  9789. (defun org-agenda-clock-cancel (&optional _arg)
  9790. "Cancel the currently running clock."
  9791. (interactive) ;; "P"
  9792. (unless (marker-buffer org-clock-marker)
  9793. (user-error "No running clock"))
  9794. (org-with-remote-undo (marker-buffer org-clock-marker)
  9795. (org-clock-cancel)))
  9796. (defun org-agenda-clock-goto ()
  9797. "Jump to the currently clocked in task within the agenda.
  9798. If the currently clocked in task is not listed in the agenda
  9799. buffer, display it in another window."
  9800. (interactive)
  9801. (let (pos)
  9802. (mapc (lambda (o)
  9803. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  9804. (setq pos (overlay-start o))))
  9805. (overlays-in (point-min) (point-max)))
  9806. (cond (pos (goto-char pos))
  9807. ;; If the currently clocked entry is not in the agenda
  9808. ;; buffer, we visit it in another window:
  9809. ((bound-and-true-p org-clock-current-task)
  9810. (org-switch-to-buffer-other-window (org-clock-goto)))
  9811. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  9812. (defun org-agenda-diary-entry-in-org-file ()
  9813. "Make a diary entry in the file `org-agenda-diary-file'."
  9814. (let (d1 d2 char (text "") dp1 dp2)
  9815. (if (equal (buffer-name) "*Calendar*")
  9816. (setq d1 (calendar-cursor-to-date t)
  9817. d2 (car calendar-mark-ring))
  9818. (setq dp1 (get-text-property (line-beginning-position) 'day))
  9819. (unless dp1 (user-error "No date defined in current line"))
  9820. (setq d1 (calendar-gregorian-from-absolute dp1)
  9821. d2 (and (ignore-errors (mark))
  9822. (save-excursion
  9823. (goto-char (mark))
  9824. (setq dp2 (get-text-property (line-beginning-position) 'day)))
  9825. (calendar-gregorian-from-absolute dp2))))
  9826. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  9827. (setq char (read-char-exclusive))
  9828. (cond
  9829. ((equal char ?d)
  9830. (setq text (read-string "Day entry: "))
  9831. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  9832. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9833. ((equal char ?a)
  9834. (setq d1 (list (car d1) (nth 1 d1)
  9835. (read-number (format "Reference year [%d]: " (nth 2 d1))
  9836. (nth 2 d1))))
  9837. (setq text (read-string "Anniversary (use %d to show years): "))
  9838. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  9839. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9840. ((equal char ?b)
  9841. (setq text (read-string "Block entry: "))
  9842. (unless (and d1 d2 (not (equal d1 d2)))
  9843. (user-error "No block of days selected"))
  9844. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  9845. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9846. ((equal char ?j)
  9847. (org-switch-to-buffer-other-window
  9848. (find-file-noselect org-agenda-diary-file))
  9849. (require 'org-datetree)
  9850. (org-datetree-find-date-create d1)
  9851. (org-fold-reveal t))
  9852. (t (user-error "Invalid selection character `%c'" char)))))
  9853. (defcustom org-agenda-insert-diary-strategy 'date-tree
  9854. "Where in `org-agenda-diary-file' should new entries be added?
  9855. Valid values:
  9856. date-tree in the date tree, as first child of the date
  9857. date-tree-last in the date tree, as last child of the date
  9858. top-level as top-level entries at the end of the file."
  9859. :group 'org-agenda
  9860. :type '(choice
  9861. (const :tag "first in a date tree" date-tree)
  9862. (const :tag "last in a date tree" date-tree-last)
  9863. (const :tag "as top level at end of file" top-level)))
  9864. (defcustom org-agenda-insert-diary-extract-time nil
  9865. "Non-nil means extract any time specification from the diary entry."
  9866. :group 'org-agenda
  9867. :version "24.1"
  9868. :type 'boolean)
  9869. (defcustom org-agenda-bulk-mark-char ">"
  9870. "A single-character string to be used as the bulk mark."
  9871. :group 'org-agenda
  9872. :version "24.1"
  9873. :type 'string)
  9874. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  9875. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  9876. If TEXT is not empty, it will become the headline of the new entry, and
  9877. the resulting entry will not be shown. When TEXT is empty, switch to
  9878. `org-agenda-diary-file' and let the user finish the entry there."
  9879. (let ((cw (current-window-configuration)))
  9880. (org-switch-to-buffer-other-window
  9881. (find-file-noselect org-agenda-diary-file))
  9882. (widen)
  9883. (goto-char (point-min))
  9884. (cl-case type
  9885. (anniversary
  9886. (or (re-search-forward "^\\*[ \t]+Anniversaries" nil t)
  9887. (progn
  9888. (or (org-at-heading-p)
  9889. (progn
  9890. (outline-next-heading)
  9891. (insert "* Anniversaries\n\n")
  9892. (beginning-of-line -1)))))
  9893. (outline-next-heading)
  9894. (org-back-over-empty-lines)
  9895. (backward-char 1)
  9896. (insert "\n")
  9897. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  9898. (nth 2 d1) (car d1) (nth 1 d1) text)))
  9899. (day
  9900. (let ((org-prefix-has-time t)
  9901. (org-agenda-time-leading-zero t)
  9902. fmt time time2)
  9903. (when org-agenda-insert-diary-extract-time
  9904. ;; Use org-agenda-format-item to parse text for a time-range and
  9905. ;; remove it. FIXME: This is a hack, we should refactor
  9906. ;; that function to make time extraction available separately
  9907. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  9908. time (get-text-property 0 'time fmt)
  9909. time2 (if (> (length time) 0)
  9910. ;; split-string removes trailing ...... if
  9911. ;; no end time given. First space
  9912. ;; separates time from date.
  9913. (concat " " (car (split-string time "\\.")))
  9914. nil)
  9915. text (get-text-property 0 'txt fmt)))
  9916. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9917. (org-agenda-insert-diary-as-top-level text)
  9918. (require 'org-datetree)
  9919. (org-datetree-find-date-create d1)
  9920. (org-agenda-insert-diary-make-new-entry text))
  9921. (org-insert-time-stamp (org-time-from-absolute
  9922. (calendar-absolute-from-gregorian d1))
  9923. nil nil nil nil time2))
  9924. (end-of-line 0))
  9925. ((block) ;; Wrap this in (strictly unnecessary) parens because
  9926. ;; otherwise the indentation gets confused by the
  9927. ;; special meaning of 'block
  9928. (when (> (calendar-absolute-from-gregorian d1)
  9929. (calendar-absolute-from-gregorian d2))
  9930. (setq d1 (prog1 d2 (setq d2 d1))))
  9931. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9932. (org-agenda-insert-diary-as-top-level text)
  9933. (require 'org-datetree)
  9934. (org-datetree-find-date-create d1)
  9935. (org-agenda-insert-diary-make-new-entry text))
  9936. (org-insert-time-stamp (org-time-from-absolute
  9937. (calendar-absolute-from-gregorian d1)))
  9938. (insert "--")
  9939. (org-insert-time-stamp (org-time-from-absolute
  9940. (calendar-absolute-from-gregorian d2)))
  9941. (end-of-line 0)))
  9942. (if (string-match "\\S-" text)
  9943. (progn
  9944. (set-window-configuration cw)
  9945. (message "%s entry added to %s"
  9946. (capitalize (symbol-name type))
  9947. (abbreviate-file-name org-agenda-diary-file)))
  9948. (org-fold-reveal t)
  9949. (message "Please finish entry here"))))
  9950. (defun org-agenda-insert-diary-as-top-level (text)
  9951. "Make new entry as a top-level entry at the end of the file.
  9952. Add TEXT as headline, and position the cursor in the second line so that
  9953. a timestamp can be added there."
  9954. (widen)
  9955. (goto-char (point-max))
  9956. (unless (bolp) (insert "\n"))
  9957. (org-insert-heading nil t t)
  9958. (insert text)
  9959. (org-end-of-meta-data)
  9960. (unless (bolp) (insert "\n"))
  9961. (when org-adapt-indentation (indent-to-column 2)))
  9962. (defun org-agenda-insert-diary-make-new-entry (text)
  9963. "Make a new entry with TEXT as a child of the current subtree.
  9964. Position the point in the heading's first body line so that
  9965. a timestamp can be added there."
  9966. (cond
  9967. ((eq org-agenda-insert-diary-strategy 'date-tree-last)
  9968. (end-of-line)
  9969. (org-insert-heading '(4) t)
  9970. (org-do-demote))
  9971. (t
  9972. (outline-next-heading)
  9973. (org-back-over-empty-lines)
  9974. (unless (looking-at "[ \t]*$") (save-excursion (insert "\n")))
  9975. (org-insert-heading nil t)
  9976. (org-do-demote)))
  9977. (let ((col (current-column)))
  9978. (insert text)
  9979. (org-end-of-meta-data)
  9980. ;; Ensure point is left on a blank line, at proper indentation.
  9981. (unless (bolp) (insert "\n"))
  9982. (unless (looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
  9983. (when org-adapt-indentation (indent-to-column col)))
  9984. (org-fold-show-set-visibility 'lineage))
  9985. (defun org-agenda-diary-entry ()
  9986. "Make a diary entry, like the `i' command from the calendar.
  9987. All the standard commands work: block, weekly etc.
  9988. When `org-agenda-diary-file' points to a file,
  9989. `org-agenda-diary-entry-in-org-file' is called instead to create
  9990. entries in that Org file."
  9991. (interactive)
  9992. (if (not (eq org-agenda-diary-file 'diary-file))
  9993. (org-agenda-diary-entry-in-org-file)
  9994. (require 'diary-lib)
  9995. (let* ((char (read-char-exclusive
  9996. "Diary entry: [d]ay [w]eekly [m]onthly [y]early\
  9997. [a]nniversary [b]lock [c]yclic"))
  9998. (cmd (cdr (assoc char
  9999. '((?d . diary-insert-entry)
  10000. (?w . diary-insert-weekly-entry)
  10001. (?m . diary-insert-monthly-entry)
  10002. (?y . diary-insert-yearly-entry)
  10003. (?a . diary-insert-anniversary-entry)
  10004. (?b . diary-insert-block-entry)
  10005. (?c . diary-insert-cyclic-entry)))))
  10006. (oldf (symbol-function 'calendar-cursor-to-date))
  10007. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  10008. (point (point))
  10009. (mark (or (mark t) (point))))
  10010. (unless cmd
  10011. (user-error "No command associated with <%c>" char))
  10012. (unless (and (get-text-property point 'day)
  10013. (or (not (equal ?b char))
  10014. (get-text-property mark 'day)))
  10015. (user-error "Don't know which date to use for diary entry"))
  10016. ;; We implement this by hacking the `calendar-cursor-to-date' function
  10017. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  10018. (let ((calendar-mark-ring
  10019. (list (calendar-gregorian-from-absolute
  10020. (or (get-text-property mark 'day)
  10021. (get-text-property point 'day))))))
  10022. (unwind-protect
  10023. (progn
  10024. (fset 'calendar-cursor-to-date
  10025. (lambda (&optional _error _dummy)
  10026. (calendar-gregorian-from-absolute
  10027. (get-text-property point 'day))))
  10028. (call-interactively cmd))
  10029. (fset 'calendar-cursor-to-date oldf))))))
  10030. (defun org-agenda-execute-calendar-command (cmd)
  10031. "Execute a calendar command from the agenda with date from cursor."
  10032. (org-agenda-check-type t 'agenda)
  10033. (require 'diary-lib)
  10034. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  10035. (user-error "Don't know which date to use for the calendar command"))
  10036. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  10037. (point (point))
  10038. (date (calendar-gregorian-from-absolute
  10039. (get-text-property point 'day))))
  10040. ;; the following 2 vars are needed in the calendar
  10041. (org-dlet
  10042. ((displayed-month (car date))
  10043. (displayed-year (nth 2 date)))
  10044. (unwind-protect
  10045. (progn
  10046. (fset 'calendar-cursor-to-date
  10047. (lambda (&optional _error _dummy)
  10048. (calendar-gregorian-from-absolute
  10049. (get-text-property point 'day))))
  10050. (call-interactively cmd))
  10051. (fset 'calendar-cursor-to-date oldf)))))
  10052. (defun org-agenda-phases-of-moon ()
  10053. "Display the phases of the moon for the 3 months around the cursor date."
  10054. (interactive)
  10055. (org-agenda-execute-calendar-command 'calendar-lunar-phases))
  10056. (defun org-agenda-holidays ()
  10057. "Display the holidays for the 3 months around the cursor date."
  10058. (interactive)
  10059. (org-agenda-execute-calendar-command 'calendar-list-holidays))
  10060. (defvar calendar-longitude) ; defined in calendar.el
  10061. (defvar calendar-latitude) ; defined in calendar.el
  10062. (defvar calendar-location-name) ; defined in calendar.el
  10063. (defun org-agenda-sunrise-sunset (arg)
  10064. "Display sunrise and sunset for the cursor date.
  10065. Latitude and longitude can be specified with the variables
  10066. `calendar-latitude' and `calendar-longitude'. When called with prefix
  10067. argument, latitude and longitude will be prompted for."
  10068. (interactive "P")
  10069. (require 'solar)
  10070. (let ((calendar-longitude (if arg nil calendar-longitude))
  10071. (calendar-latitude (if arg nil calendar-latitude))
  10072. (calendar-location-name
  10073. (if arg "the given coordinates" calendar-location-name)))
  10074. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  10075. (defun org-agenda-goto-calendar ()
  10076. "Open the Emacs calendar with the date at the cursor."
  10077. (interactive)
  10078. (org-agenda-check-type t 'agenda)
  10079. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  10080. (user-error "Don't know which date to open in calendar")))
  10081. (date (calendar-gregorian-from-absolute day))
  10082. (calendar-move-hook nil)
  10083. (calendar-view-holidays-initially-flag nil)
  10084. (calendar-view-diary-initially-flag nil))
  10085. (calendar)
  10086. (calendar-goto-date date)))
  10087. ;;;###autoload
  10088. (defun org-calendar-goto-agenda ()
  10089. "Compute the Org agenda for the calendar date displayed at the cursor.
  10090. This is a command that has to be installed in `calendar-mode-map'."
  10091. (interactive)
  10092. ;; Temporarily disable sticky agenda since user clearly wants to
  10093. ;; refresh view anyway.
  10094. (let ((org-agenda-buffer-tmp-name "*Org Agenda(a)*")
  10095. (org-agenda-sticky nil))
  10096. (org-agenda-list nil (calendar-absolute-from-gregorian
  10097. (calendar-cursor-to-date))
  10098. nil)))
  10099. (defun org-agenda-convert-date ()
  10100. (interactive)
  10101. (org-agenda-check-type t 'agenda)
  10102. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  10103. date s)
  10104. (unless day
  10105. (user-error "Don't know which date to convert"))
  10106. (setq date (calendar-gregorian-from-absolute day))
  10107. (setq s (concat
  10108. "Gregorian: " (calendar-date-string date) "\n"
  10109. "ISO: " (calendar-iso-date-string date) "\n"
  10110. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  10111. "Julian: " (calendar-julian-date-string date) "\n"
  10112. "Astron. JD: " (calendar-astro-date-string date)
  10113. " (Julian date number at noon UTC)\n"
  10114. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  10115. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  10116. "French: " (calendar-french-date-string date) "\n"
  10117. "Bahá’í: " (calendar-bahai-date-string date) " (until sunset)\n"
  10118. "Mayan: " (calendar-mayan-date-string date) "\n"
  10119. "Coptic: " (calendar-coptic-date-string date) "\n"
  10120. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  10121. "Persian: " (calendar-persian-date-string date) "\n"
  10122. "Chinese: " (calendar-chinese-date-string date) "\n"))
  10123. (with-output-to-temp-buffer "*Dates*"
  10124. (princ s))
  10125. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  10126. ;;; Bulk commands
  10127. (defun org-agenda-bulk-marked-p ()
  10128. "Non-nil when current entry is marked for bulk action."
  10129. (eq (get-char-property (line-beginning-position) 'type)
  10130. 'org-marked-entry-overlay))
  10131. (defun org-agenda-bulk-mark (&optional arg)
  10132. "Mark entries for future bulk action.
  10133. When ARG is nil or one and region is not active then mark the
  10134. entry at point.
  10135. When ARG is nil or one and region is active then mark the entries
  10136. in the region.
  10137. When ARG is greater than one mark ARG lines."
  10138. (interactive "p")
  10139. (when (and (or (not arg) (= arg 1)) (use-region-p))
  10140. (setq arg (count-lines (region-beginning) (region-end)))
  10141. (goto-char (region-beginning))
  10142. (deactivate-mark))
  10143. (dotimes (_ (or arg 1))
  10144. (unless (org-get-at-bol 'org-agenda-diary-link)
  10145. (let* ((m (org-get-at-bol 'org-hd-marker))
  10146. ov)
  10147. (unless (org-agenda-bulk-marked-p)
  10148. (unless m (user-error "Nothing to mark at point"))
  10149. (push m org-agenda-bulk-marked-entries)
  10150. (setq ov (make-overlay (line-beginning-position) (+ 2 (line-beginning-position))))
  10151. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  10152. (org-get-todo-face "TODO")
  10153. 'evaporate)
  10154. (overlay-put ov 'type 'org-marked-entry-overlay))
  10155. (end-of-line 1)
  10156. (or (ignore-errors
  10157. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  10158. (beginning-of-line 2))
  10159. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  10160. (beginning-of-line 2)))))
  10161. (message "%d entries marked for bulk action"
  10162. (length org-agenda-bulk-marked-entries)))
  10163. (defun org-agenda-bulk-mark-all ()
  10164. "Mark all entries for future agenda bulk action."
  10165. (interactive)
  10166. (org-agenda-bulk-mark-regexp "."))
  10167. (defun org-agenda-bulk-mark-regexp (regexp)
  10168. "Mark entries matching REGEXP for future agenda bulk action."
  10169. (interactive "sMark entries matching regexp: ")
  10170. (let ((entries-marked 0) txt-at-point)
  10171. (save-excursion
  10172. (goto-char (point-min))
  10173. (goto-char (next-single-property-change (point) 'org-hd-marker))
  10174. (while (and (re-search-forward regexp nil t)
  10175. (setq txt-at-point
  10176. (get-text-property (match-beginning 0) 'txt)))
  10177. (if (get-char-property (point) 'invisible)
  10178. (beginning-of-line 2)
  10179. (when (string-match-p regexp txt-at-point)
  10180. (setq entries-marked (1+ entries-marked))
  10181. (call-interactively 'org-agenda-bulk-mark)))))
  10182. (unless entries-marked
  10183. (message "No entry matching this regexp."))))
  10184. (defun org-agenda-bulk-unmark (&optional arg)
  10185. "Unmark the entry at point for future bulk action."
  10186. (interactive "P")
  10187. (if arg
  10188. (org-agenda-bulk-unmark-all)
  10189. (cond ((org-agenda-bulk-marked-p)
  10190. (org-agenda-bulk-remove-overlays
  10191. (line-beginning-position) (+ 2 (line-beginning-position)))
  10192. (setq org-agenda-bulk-marked-entries
  10193. (delete (org-get-at-bol 'org-hd-marker)
  10194. org-agenda-bulk-marked-entries))
  10195. (end-of-line 1)
  10196. (or (ignore-errors
  10197. (goto-char (next-single-property-change (point) 'txt)))
  10198. (beginning-of-line 2))
  10199. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  10200. (beginning-of-line 2))
  10201. (message "%d entries left marked for bulk action"
  10202. (length org-agenda-bulk-marked-entries)))
  10203. (t (message "No entry to unmark here")))))
  10204. (defun org-agenda-bulk-toggle-all ()
  10205. "Toggle all marks for bulk action."
  10206. (interactive)
  10207. (save-excursion
  10208. (goto-char (point-min))
  10209. (while (ignore-errors
  10210. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  10211. (org-agenda-bulk-toggle))))
  10212. (defun org-agenda-bulk-toggle ()
  10213. "Toggle the mark at point for bulk action."
  10214. (interactive)
  10215. (if (org-agenda-bulk-marked-p)
  10216. (org-agenda-bulk-unmark)
  10217. (org-agenda-bulk-mark)))
  10218. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  10219. "Remove the mark overlays between BEG and END in the agenda buffer.
  10220. BEG and END default to the buffer limits.
  10221. This only removes the overlays, it does not remove the markers
  10222. from the list in `org-agenda-bulk-marked-entries'."
  10223. (interactive)
  10224. (mapc (lambda (ov)
  10225. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  10226. (delete-overlay ov)))
  10227. (overlays-in (or beg (point-min)) (or end (point-max)))))
  10228. (defun org-agenda-bulk-unmark-all ()
  10229. "Remove all marks in the agenda buffer.
  10230. This will remove the markers and the overlays."
  10231. (interactive)
  10232. (if (null org-agenda-bulk-marked-entries)
  10233. (message "No entry to unmark")
  10234. (setq org-agenda-bulk-marked-entries nil)
  10235. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  10236. (defcustom org-agenda-persistent-marks nil
  10237. "Non-nil means marked items will stay marked after a bulk action.
  10238. You can toggle this interactively by typing `p' when prompted for a
  10239. bulk action."
  10240. :group 'org-agenda
  10241. :version "24.1"
  10242. :type 'boolean)
  10243. (defcustom org-agenda-loop-over-headlines-in-active-region t
  10244. "Shall some commands act upon headlines in the active region?
  10245. When set to t, some commands will be performed in all headlines
  10246. within the active region.
  10247. When set to `start-level', some commands will be performed in all
  10248. headlines within the active region, provided that these headlines
  10249. are of the same level than the first one.
  10250. When set to a regular expression, those commands will be
  10251. performed on the matching headlines within the active region.
  10252. The list of commands is: `org-agenda-schedule',
  10253. `org-agenda-deadline', `org-agenda-date-prompt',
  10254. `org-agenda-todo', `org-agenda-archive*', `org-agenda-kill'.
  10255. See `org-loop-over-headlines-in-active-region' for the equivalent
  10256. option for Org buffers."
  10257. :type '(choice (const :tag "Don't loop" nil)
  10258. (const :tag "All headlines in active region" t)
  10259. (const :tag "In active region, headlines at the same level than the first one" start-level)
  10260. (regexp :tag "Regular expression matcher"))
  10261. :version "27.1"
  10262. :package-version '(Org . "9.4")
  10263. :group 'org-agenda)
  10264. (defun org-agenda-bulk-action (&optional arg)
  10265. "Execute an remote-editing action on all marked entries.
  10266. The prefix arg is passed through to the command if possible."
  10267. (interactive "P")
  10268. ;; When there is no mark, act on the agenda entry at point.
  10269. (if (not org-agenda-bulk-marked-entries)
  10270. (save-excursion (org-agenda-bulk-mark)))
  10271. (dolist (m org-agenda-bulk-marked-entries)
  10272. (unless (and (markerp m)
  10273. (marker-buffer m)
  10274. (buffer-live-p (marker-buffer m))
  10275. (marker-position m))
  10276. (user-error "Marker %s for bulk command is invalid" m)))
  10277. ;; Prompt for the bulk command.
  10278. (org-unlogged-message
  10279. (concat "Bulk (" (if org-agenda-persistent-marks "" "don't ") "[p]ersist marks): "
  10280. "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  10281. "[S]catter [f]unction "
  10282. (and org-agenda-bulk-custom-functions
  10283. (format " Custom: [%s]"
  10284. (mapconcat (lambda (f) (char-to-string (car f)))
  10285. org-agenda-bulk-custom-functions
  10286. "")))))
  10287. (catch 'exit
  10288. (let* ((org-log-refile (if org-log-refile 'time nil))
  10289. (entries (reverse org-agenda-bulk-marked-entries))
  10290. (org-overriding-default-time
  10291. (and (get-text-property (point) 'org-agenda-date-header)
  10292. (org-get-cursor-date)))
  10293. redo-at-end
  10294. cmd)
  10295. (pcase (read-char-exclusive)
  10296. (?p
  10297. (let ((org-agenda-persistent-marks
  10298. (not org-agenda-persistent-marks)))
  10299. (org-agenda-bulk-action)
  10300. (throw 'exit nil)))
  10301. (?$
  10302. (setq cmd #'org-agenda-archive))
  10303. (?A
  10304. (setq cmd #'org-agenda-archive-to-archive-sibling))
  10305. ((or ?r ?w)
  10306. (let ((refile-location
  10307. (org-refile-get-location
  10308. "Refile to"
  10309. (marker-buffer (car entries))
  10310. org-refile-allow-creating-parent-nodes)))
  10311. (when (nth 3 refile-location)
  10312. (setcar (nthcdr 3 refile-location)
  10313. (move-marker
  10314. (make-marker)
  10315. (nth 3 refile-location)
  10316. (or (get-file-buffer (nth 1 refile-location))
  10317. (find-buffer-visiting (nth 1 refile-location))
  10318. (error "This should not happen")))))
  10319. (setq cmd (lambda () (org-agenda-refile nil refile-location t)))
  10320. (setq redo-at-end t)))
  10321. (?t
  10322. (let ((state (completing-read
  10323. "Todo state: "
  10324. (with-current-buffer (marker-buffer (car entries))
  10325. (mapcar #'list org-todo-keywords-1)))))
  10326. (setq cmd (lambda ()
  10327. (let ((org-inhibit-blocking t)
  10328. (org-inhibit-logging 'note))
  10329. (org-agenda-todo state))))))
  10330. ((and (or ?- ?+) action)
  10331. (let ((tag (completing-read
  10332. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  10333. (with-current-buffer (marker-buffer (car entries))
  10334. (delq nil
  10335. (mapcar (lambda (x) (and (stringp (car x)) x))
  10336. org-current-tag-alist))))))
  10337. (setq cmd
  10338. (lambda ()
  10339. (org-agenda-set-tags tag
  10340. (if (eq action ?+) 'on 'off))))))
  10341. ((and (or ?s ?d) c)
  10342. (let* ((schedule? (eq c ?s))
  10343. (prompt (if schedule? "(Re)Schedule to" "(Re)Set Deadline to"))
  10344. (time
  10345. (and (not arg)
  10346. (let ((new (org-read-date
  10347. nil nil nil prompt org-overriding-default-time)))
  10348. ;; A "double plus" answer applies to every
  10349. ;; scheduled time. Do not turn it into
  10350. ;; a fixed date yet.
  10351. (if (string-match-p "\\`[ \t]*\\+\\+"
  10352. org-read-date-final-answer)
  10353. org-read-date-final-answer
  10354. new)))))
  10355. ;; Make sure to not prompt for a note when bulk
  10356. ;; rescheduling/resetting deadline as Org cannot cope with
  10357. ;; simultaneous notes. Besides, it could be annoying
  10358. ;; depending on the number of marked items.
  10359. (setq cmd
  10360. (if schedule?
  10361. (lambda ()
  10362. (let ((org-log-reschedule
  10363. (and org-log-reschedule 'time)))
  10364. (org-agenda-schedule arg time)))
  10365. (lambda ()
  10366. (let ((org-log-redeadline (and org-log-redeadline 'time)))
  10367. (org-agenda-deadline arg time)))))))
  10368. (?S
  10369. (unless (org-agenda-check-type nil 'agenda 'todo)
  10370. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type))
  10371. (let ((days (read-number
  10372. (format "Scatter tasks across how many %sdays: "
  10373. (if arg "week" ""))
  10374. 7)))
  10375. (setq cmd
  10376. (lambda ()
  10377. (let ((distance (1+ (random days))))
  10378. (when arg
  10379. (let ((dist distance)
  10380. (day-of-week
  10381. (calendar-day-of-week
  10382. (calendar-gregorian-from-absolute (org-today)))))
  10383. (dotimes (_ (1+ dist))
  10384. (while (member day-of-week org-agenda-weekend-days)
  10385. (cl-incf distance)
  10386. (cl-incf day-of-week)
  10387. (when (= day-of-week 7)
  10388. (setq day-of-week 0)))
  10389. (cl-incf day-of-week)
  10390. (when (= day-of-week 7)
  10391. (setq day-of-week 0)))))
  10392. ;; Silently fail when try to replan a sexp entry.
  10393. (ignore-errors
  10394. (let* ((date (calendar-gregorian-from-absolute
  10395. (+ (org-today) distance)))
  10396. (time (org-encode-time
  10397. 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  10398. (org-agenda-schedule nil time))))))))
  10399. (?f
  10400. (setq cmd
  10401. (intern
  10402. (completing-read "Function: " obarray #'fboundp t nil nil))))
  10403. (action
  10404. (setq cmd
  10405. (pcase (assoc action org-agenda-bulk-custom-functions)
  10406. (`(,_ ,fn)
  10407. fn)
  10408. (`(,_ ,fn ,arg-fn)
  10409. (apply #'apply-partially fn (funcall arg-fn)))
  10410. (_
  10411. (user-error "Invalid bulk action: %c" action))))
  10412. (setq redo-at-end t)))
  10413. ;; Sort the markers, to make sure that parents are handled
  10414. ;; before children.
  10415. (setq entries (sort entries
  10416. (lambda (a b)
  10417. (cond
  10418. ((eq (marker-buffer a) (marker-buffer b))
  10419. (< (marker-position a) (marker-position b)))
  10420. (t
  10421. (string< (buffer-name (marker-buffer a))
  10422. (buffer-name (marker-buffer b))))))))
  10423. ;; Now loop over all markers and apply CMD.
  10424. (let ((processed 0)
  10425. (skipped 0))
  10426. (dolist (e entries)
  10427. (let ((pos (text-property-any (point-min) (point-max) 'org-hd-marker e)))
  10428. (if (not pos)
  10429. (progn (message "Skipping removed entry at %s" e)
  10430. (cl-incf skipped))
  10431. (goto-char pos)
  10432. (let (org-loop-over-headlines-in-active-region) (funcall cmd))
  10433. ;; `post-command-hook' is not run yet. We make sure any
  10434. ;; pending log note is processed.
  10435. (when org-log-setup (org-add-log-note))
  10436. (cl-incf processed))))
  10437. (when redo-at-end (org-agenda-redo))
  10438. (unless org-agenda-persistent-marks (org-agenda-bulk-unmark-all))
  10439. (message "Acted on %d entries%s%s"
  10440. processed
  10441. (if (= skipped 0)
  10442. ""
  10443. (format ", skipped %d (disappeared before their turn)"
  10444. skipped))
  10445. (if (not org-agenda-persistent-marks) "" " (kept marked)"))))))
  10446. (defun org-agenda-capture (&optional with-time)
  10447. "Call `org-capture' with the date at point.
  10448. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  10449. current HH:MM time."
  10450. (interactive "P")
  10451. (if (not (eq major-mode 'org-agenda-mode))
  10452. (user-error "You cannot do this outside of agenda buffers")
  10453. (let ((org-overriding-default-time
  10454. (org-get-cursor-date (equal with-time 1))))
  10455. (call-interactively 'org-capture))))
  10456. ;;; Dragging agenda lines forward/backward
  10457. (defun org-agenda-reapply-filters ()
  10458. "Re-apply all agenda filters."
  10459. (mapcar
  10460. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f) t)))
  10461. `((,org-agenda-tag-filter tag)
  10462. (,org-agenda-category-filter category)
  10463. (,org-agenda-regexp-filter regexp)
  10464. (,org-agenda-effort-filter effort)
  10465. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  10466. (,(get 'org-agenda-category-filter :preset-filter) category)
  10467. (,(get 'org-agenda-effort-filter :preset-filter) effort)
  10468. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  10469. (defun org-agenda-drag-line-forward (arg &optional backward)
  10470. "Drag an agenda line forward by ARG lines.
  10471. When the optional argument `backward' is non-nil, move backward."
  10472. (interactive "p")
  10473. (let ((inhibit-read-only t) lst line)
  10474. (if (or (not (get-text-property (point) 'txt))
  10475. (save-excursion
  10476. (dotimes (_ arg)
  10477. (move-beginning-of-line (if backward 0 2))
  10478. (push (not (get-text-property (point) 'txt)) lst))
  10479. (delq nil lst)))
  10480. (message "Cannot move line forward")
  10481. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  10482. (move-beginning-of-line 1)
  10483. (setq line (buffer-substring (point) end))
  10484. (delete-region (point) end)
  10485. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  10486. (insert line)
  10487. (org-agenda-reapply-filters)
  10488. (org-agenda-mark-clocking-task)
  10489. (move-beginning-of-line 0)))))
  10490. (defun org-agenda-drag-line-backward (arg)
  10491. "Drag an agenda line backward by ARG lines."
  10492. (interactive "p")
  10493. (org-agenda-drag-line-forward arg t))
  10494. ;;; Flagging notes
  10495. (defun org-agenda-show-the-flagging-note ()
  10496. "Display the flagging note in the other window.
  10497. When called a second time in direct sequence, offer to remove the FLAGGING
  10498. tag and (if present) the flagging note."
  10499. (interactive)
  10500. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  10501. (win (selected-window))
  10502. note) ;; heading newhead
  10503. (unless hdmarker
  10504. (user-error "No linked entry at point"))
  10505. (if (and (eq this-command last-command)
  10506. (y-or-n-p "Unflag and remove any flagging note? "))
  10507. (progn
  10508. (org-agenda-remove-flag hdmarker)
  10509. (let ((win (get-buffer-window "*Flagging Note*")))
  10510. (and win (delete-window win)))
  10511. (message "Entry unflagged"))
  10512. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  10513. (unless note
  10514. (user-error "No flagging note"))
  10515. (org-kill-new note)
  10516. (org-switch-to-buffer-other-window "*Flagging Note*")
  10517. (erase-buffer)
  10518. (insert note)
  10519. (goto-char (point-min))
  10520. (while (re-search-forward "\\\\n" nil t)
  10521. (replace-match "\n" t t))
  10522. (goto-char (point-min))
  10523. (select-window win)
  10524. (message "%s" (substitute-command-keys "Flagging note pushed to \
  10525. kill ring. Press `\\[org-agenda-show-the-flagging-note]' again to remove \
  10526. tag and note")))))
  10527. (defun org-agenda-remove-flag (marker)
  10528. "Remove the FLAGGED tag and any flagging note in the entry."
  10529. (let ((newhead
  10530. (org-with-point-at marker
  10531. (org-toggle-tag "FLAGGED" 'off)
  10532. (org-entry-delete nil "THEFLAGGINGNOTE")
  10533. (org-get-heading))))
  10534. (org-agenda-change-all-lines newhead marker)
  10535. (message "Entry unflagged")))
  10536. (defun org-agenda-get-any-marker (&optional pos)
  10537. (or (get-text-property (or pos (line-beginning-position)) 'org-hd-marker)
  10538. (get-text-property (or pos (line-beginning-position)) 'org-marker)))
  10539. ;;; Appointment reminders
  10540. (defvar appt-time-msg-list) ; defined in appt.el
  10541. ;;;###autoload
  10542. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  10543. "Activate appointments found in `org-agenda-files'.
  10544. With a `\\[universal-argument]' prefix, refresh the list of \
  10545. appointments.
  10546. If FILTER is t, interactively prompt the user for a regular
  10547. expression, and filter out entries that don't match it.
  10548. If FILTER is a string, use this string as a regular expression
  10549. for filtering entries out.
  10550. If FILTER is a function, filter out entries against which
  10551. calling the function returns nil. This function takes one
  10552. argument: an entry from `org-agenda-get-day-entries'.
  10553. FILTER can also be an alist with the car of each cell being
  10554. either `headline' or `category'. For example:
  10555. ((headline \"IMPORTANT\")
  10556. (category \"Work\"))
  10557. will only add headlines containing IMPORTANT or headlines
  10558. belonging to the \"Work\" category.
  10559. ARGS are symbols indicating what kind of entries to consider.
  10560. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  10561. \(i.e., deadlines and scheduled items with a hh:mm specification)
  10562. and :timestamp entries. See the docstring of `org-diary' for
  10563. details and examples.
  10564. If an entry has a APPT_WARNTIME property, its value will be used
  10565. to override `appt-message-warning-time'."
  10566. (interactive "P")
  10567. (when refresh (setq appt-time-msg-list nil))
  10568. (when (eq filter t)
  10569. (setq filter (read-from-minibuffer "Regexp filter: ")))
  10570. (let* ((cnt 0) ; count added events
  10571. (scope (or args '(:deadline* :scheduled* :timestamp)))
  10572. (org-agenda-new-buffers nil)
  10573. (org-deadline-warning-days 0)
  10574. ;; Do not use `org-today' here because appt only takes
  10575. ;; time and without date as argument, so it may pass wrong
  10576. ;; information otherwise
  10577. (today (org-date-to-gregorian
  10578. (time-to-days nil)))
  10579. (org-agenda-restrict nil)
  10580. (files (org-agenda-files 'unrestricted)) entries file
  10581. (org-agenda-buffer nil))
  10582. ;; Get all entries which may contain an appt
  10583. (org-agenda-prepare-buffers files)
  10584. (while (setq file (pop files))
  10585. (setq entries
  10586. (delq nil
  10587. (append entries
  10588. (apply #'org-agenda-get-day-entries
  10589. file today scope)))))
  10590. ;; Map through entries and find if we should filter them out
  10591. (mapc
  10592. (lambda (x)
  10593. (let* ((evt (org-trim
  10594. (replace-regexp-in-string
  10595. org-link-bracket-re "\\2"
  10596. (or (get-text-property 1 'txt x) ""))))
  10597. (cat (get-text-property (1- (length x)) 'org-category x))
  10598. (tod (get-text-property 1 'time-of-day x))
  10599. (ok (or (null filter)
  10600. (and (stringp filter) (string-match filter evt))
  10601. (and (functionp filter) (funcall filter x))
  10602. (and (listp filter)
  10603. (let ((cat-filter (cadr (assq 'category filter)))
  10604. (evt-filter (cadr (assq 'headline filter))))
  10605. (or (and (stringp cat-filter)
  10606. (string-match cat-filter cat))
  10607. (and (stringp evt-filter)
  10608. (string-match evt-filter evt)))))))
  10609. (wrn (get-text-property 1 'warntime x)))
  10610. ;; FIXME: Shall we remove text-properties for the appt text?
  10611. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  10612. (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
  10613. (setq tod (concat "00" (number-to-string tod)))
  10614. (setq tod (when (string-match
  10615. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  10616. (concat (match-string 1 tod) ":"
  10617. (match-string 2 tod))))
  10618. (when (appt-add tod evt wrn)
  10619. (setq cnt (1+ cnt))))))
  10620. entries)
  10621. (org-release-buffers org-agenda-new-buffers)
  10622. (if (eq cnt 0)
  10623. (message "No event to add")
  10624. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  10625. (defun org-agenda-today-p (date)
  10626. "Non-nil when DATE means today.
  10627. DATE is either a list of the form (month day year) or a number of
  10628. days as returned by `calendar-absolute-from-gregorian' or
  10629. `org-today'. This function considers `org-extend-today-until'
  10630. when defining today."
  10631. (eq (org-today)
  10632. (if (consp date) (calendar-absolute-from-gregorian date) date)))
  10633. (defun org-agenda-todo-yesterday (&optional arg)
  10634. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  10635. (interactive "P")
  10636. (let* ((org-use-effective-time t)
  10637. (hour (nth 2 (decode-time (org-current-time))))
  10638. (org-extend-today-until (1+ hour)))
  10639. (org-agenda-todo arg)))
  10640. (defun org-agenda-ctrl-c-ctrl-c ()
  10641. "Set tags in agenda buffer."
  10642. (interactive)
  10643. (org-agenda-set-tags))
  10644. (provide 'org-agenda)
  10645. ;;; org-agenda.el ends here