org-agenda.el 450 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2004-2022 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten.dominik@gmail.com>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; URL: https://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'org-macs)
  42. (org-assert-version)
  43. (require 'cl-lib)
  44. (require 'ol)
  45. (require 'org-fold-core)
  46. (require 'org)
  47. (require 'org-macs)
  48. (require 'org-refile)
  49. (declare-function diary-add-to-list "diary-lib"
  50. (date string specifier &optional marker globcolor literal))
  51. (declare-function calendar-iso-to-absolute "cal-iso" (date))
  52. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  53. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  54. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  55. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  56. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  57. (declare-function calendar-french-date-string "cal-french" (&optional date))
  58. (declare-function calendar-goto-date "cal-move" (date))
  59. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  60. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  61. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  62. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  63. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  64. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  65. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  66. (declare-function calendar-check-holidays "holidays" (date))
  67. (declare-function org-columns-remove-overlays "org-colview" ())
  68. (declare-function org-datetree-find-date-create "org-datetree"
  69. (date &optional keep-restriction))
  70. (declare-function org-columns-quit "org-colview" ())
  71. (declare-function diary-date-display-form "diary-lib" (&optional type))
  72. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  73. (declare-function org-element-property "org-element" (property element))
  74. (declare-function org-element--cache-active-p "org-element"
  75. (&optional called-from-cache-change-func-p))
  76. (declare-function org-element-lineage "org-element"
  77. (datum &optional types with-self))
  78. (declare-function org-habit-insert-consistency-graphs
  79. "org-habit" (&optional line))
  80. (declare-function org-is-habit-p "org-habit" (&optional pom))
  81. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  82. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  83. (declare-function org-agenda-columns "org-colview" ())
  84. (declare-function org-add-archive-files "org-archive" (files))
  85. (declare-function org-capture "org-capture" (&optional goto keys))
  86. (declare-function org-clock-modify-effort-estimate "org-clock" (&optional value))
  87. (declare-function org-element-type "org-element" (&optional element))
  88. (defvar calendar-mode-map)
  89. (defvar org-clock-current-task)
  90. (defvar org-current-tag-alist)
  91. (defvar org-mobile-force-id-on-agenda-items)
  92. (defvar org-habit-show-habits)
  93. (defvar org-habit-show-habits-only-for-today)
  94. (defvar org-habit-show-all-today)
  95. (defvar org-habit-scheduled-past-days)
  96. ;; Defined somewhere in this file, but used before definition.
  97. (defvar org-agenda-buffer-name "*Org Agenda*")
  98. (defvar org-agenda-title-append nil)
  99. (defvar org-agenda-overriding-header)
  100. ;; (with-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  101. ;; (with-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  102. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  103. (defvar org-agenda-undo-list nil
  104. "List of undoable operations in the agenda since last refresh.")
  105. (defvar org-agenda-pending-undo-list nil
  106. "In a series of undo commands, this is the list of remaining undo items.")
  107. (defcustom org-agenda-confirm-kill 1
  108. "When set, remote killing from the agenda buffer needs confirmation.
  109. When t, a confirmation is always needed. When a number N, confirmation is
  110. only needed when the text to be killed contains more than N non-white lines."
  111. :group 'org-agenda
  112. :type '(choice
  113. (const :tag "Never" nil)
  114. (const :tag "Always" t)
  115. (integer :tag "When more than N lines")))
  116. (defcustom org-agenda-compact-blocks nil
  117. "Non-nil means make the block agenda more compact.
  118. This is done globally by leaving out lines like the agenda span
  119. name and week number or the separator lines."
  120. :group 'org-agenda
  121. :type 'boolean)
  122. (defcustom org-agenda-block-separator
  123. (if (and (display-graphic-p)
  124. (char-displayable-p ?─))
  125. ?─
  126. ?=)
  127. "The separator between blocks in the agenda.
  128. If this is a string, it will be used as the separator, with a newline added.
  129. If it is a character, it will be repeated to fill the window width.
  130. If nil the separator is disabled. In `org-agenda-custom-commands' this
  131. addresses the separator between the current and the previous block."
  132. :group 'org-agenda
  133. :package-version '(Org . "9.6")
  134. :type '(choice
  135. (const :tag "Disabled" nil)
  136. (character)
  137. (string)))
  138. (defgroup org-agenda-export nil
  139. "Options concerning exporting agenda views in Org mode."
  140. :tag "Org Agenda Export"
  141. :group 'org-agenda)
  142. (defcustom org-agenda-with-colors t
  143. "Non-nil means use colors in agenda views."
  144. :group 'org-agenda-export
  145. :type 'boolean)
  146. (defcustom org-agenda-exporter-settings nil
  147. ;; FIXME: Do we really want to evaluate those settings and thus force
  148. ;; the user to use `quote' all the time?
  149. "Alist of variable/value pairs that should be active during agenda export.
  150. This is a good place to set options for ps-print and for htmlize.
  151. Note that the way this is implemented, the values will be evaluated
  152. before assigned to the variables. So make sure to quote values you do
  153. *not* want evaluated, for example
  154. (setq org-agenda-exporter-settings
  155. \\='((ps-print-color-p \\='black-white)))"
  156. :group 'org-agenda-export
  157. :type '(repeat
  158. (list
  159. (variable)
  160. (sexp :tag "Value"))))
  161. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  162. "Hook run in a temporary buffer before writing the agenda to an export file.
  163. A useful function for this hook is `org-agenda-add-entry-text'."
  164. :group 'org-agenda-export
  165. :type 'hook
  166. :options '(org-agenda-add-entry-text))
  167. (defcustom org-agenda-add-entry-text-maxlines 0
  168. "Maximum number of entry text lines to be added to agenda.
  169. This is only relevant when `org-agenda-add-entry-text' is part of
  170. `org-agenda-before-write-hook', which is the default.
  171. When this is 0, nothing will happen. When it is greater than 0, it
  172. specifies the maximum number of lines that will be added for each entry
  173. that is listed in the agenda view.
  174. Note that this variable is not used during display, only when exporting
  175. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  176. and `org-agenda-entry-text-maxlines'."
  177. :group 'org-agenda
  178. :type 'integer)
  179. (defcustom org-agenda-add-entry-text-descriptive-links t
  180. "Non-nil means export org-links as descriptive links in agenda added text.
  181. This variable applies to the text added to the agenda when
  182. `org-agenda-add-entry-text-maxlines' is larger than 0.
  183. When this variable is nil, the URL will (also) be shown."
  184. :group 'org-agenda
  185. :type 'boolean)
  186. (defcustom org-agenda-export-html-style nil
  187. "The style specification for exported HTML Agenda files.
  188. If this variable contains a string, it will replace the default <style>
  189. section as produced by `htmlize'.
  190. Since there are different ways of setting style information, this variable
  191. needs to contain the full HTML structure to provide a style, including the
  192. surrounding HTML tags. The style specifications should include definitions
  193. the fonts used by the agenda, here is an example:
  194. <style type=\"text/css\">
  195. p { font-weight: normal; color: gray; }
  196. .org-agenda-structure {
  197. font-size: 110%;
  198. color: #003399;
  199. font-weight: 600;
  200. }
  201. .org-todo {
  202. color: #cc6666;
  203. font-weight: bold;
  204. }
  205. .org-agenda-done {
  206. color: #339933;
  207. }
  208. .org-done {
  209. color: #339933;
  210. }
  211. .title { text-align: center; }
  212. .todo, .deadline { color: red; }
  213. .done { color: green; }
  214. </style>
  215. or, if you want to keep the style in a file,
  216. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  217. As the value of this option simply gets inserted into the HTML <head> header,
  218. you can \"misuse\" it to also add other text to the header."
  219. :group 'org-agenda-export
  220. :group 'org-export-html
  221. :type '(choice
  222. (const nil)
  223. (string)))
  224. (defcustom org-agenda-persistent-filter nil
  225. "When set, keep filters from one agenda view to the next."
  226. :group 'org-agenda
  227. :type 'boolean)
  228. (defgroup org-agenda-custom-commands nil
  229. "Options concerning agenda views in Org mode."
  230. :tag "Org Agenda Custom Commands"
  231. :group 'org-agenda)
  232. (defconst org-sorting-choice
  233. '(choice
  234. (const time-up) (const time-down)
  235. (const timestamp-up) (const timestamp-down)
  236. (const scheduled-up) (const scheduled-down)
  237. (const deadline-up) (const deadline-down)
  238. (const ts-up) (const ts-down)
  239. (const tsia-up) (const tsia-down)
  240. (const category-keep) (const category-up) (const category-down)
  241. (const tag-down) (const tag-up)
  242. (const priority-up) (const priority-down)
  243. (const todo-state-up) (const todo-state-down)
  244. (const effort-up) (const effort-down)
  245. (const habit-up) (const habit-down)
  246. (const alpha-up) (const alpha-down)
  247. (const user-defined-up) (const user-defined-down))
  248. "Sorting choices.")
  249. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  250. ;; the new variable `org-agenda-tag-filter-preset'.
  251. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  252. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  253. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  254. "List of types searched for when creating the daily/weekly agenda.
  255. This variable is a list of symbols that controls the types of
  256. items that appear in the daily/weekly agenda. Allowed symbols in this
  257. list are
  258. :timestamp List items containing a date stamp or date range matching
  259. the selected date. This includes sexp entries in angular
  260. brackets.
  261. :sexp List entries resulting from plain diary-like sexps.
  262. :deadline List deadline due on that date. When the date is today,
  263. also list any deadlines past due, or due within
  264. `org-deadline-warning-days'.
  265. :deadline* Same as above, but only include the deadline if it has an
  266. hour specification as [h]h:mm.
  267. :scheduled List all items which are scheduled for the given date.
  268. The diary for *today* also contains items which were
  269. scheduled earlier and are not yet marked DONE.
  270. :scheduled* Same as above, but only include the scheduled item if it
  271. has an hour specification as [h]h:mm.
  272. By default, all four non-starred types are turned on.
  273. When :scheduled* or :deadline* are included, :schedule or :deadline
  274. will be ignored.
  275. Never set this variable globally using `setq', because then it
  276. will apply to all future agenda commands. Instead, bind it with
  277. `let' to scope it dynamically into the agenda-constructing
  278. command. A good way to set it is through options in
  279. `org-agenda-custom-commands'. For a more flexible (though
  280. somewhat less efficient) way of determining what is included in
  281. the daily/weekly agenda, see `org-agenda-skip-function'.")
  282. (defconst org-agenda-custom-commands-local-options
  283. `(repeat :tag "Local settings for this command. Remember to quote values"
  284. (choice :tag "Setting"
  285. (list :tag "Heading for this block"
  286. (const org-agenda-overriding-header)
  287. (string :tag "Headline"))
  288. (list :tag "Files to be searched"
  289. (const org-agenda-files)
  290. (list
  291. (const :format "" quote)
  292. (repeat (file))))
  293. (list :tag "Sorting strategy"
  294. (const org-agenda-sorting-strategy)
  295. (list
  296. (const :format "" quote)
  297. (repeat
  298. ,org-sorting-choice)))
  299. (list :tag "Prefix format"
  300. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  301. (string))
  302. (list :tag "Number of days in agenda"
  303. (const org-agenda-span)
  304. (list
  305. (const :format "" quote)
  306. (choice (const :tag "Day" day)
  307. (const :tag "Week" week)
  308. (const :tag "Fortnight" fortnight)
  309. (const :tag "Month" month)
  310. (const :tag "Year" year)
  311. (integer :tag "Custom"))))
  312. (list :tag "Fixed starting date"
  313. (const org-agenda-start-day)
  314. (string :value "2007-11-01"))
  315. (list :tag "Start on day of week"
  316. (const org-agenda-start-on-weekday)
  317. (choice :value 1
  318. (const :tag "Today" nil)
  319. (integer :tag "Weekday No.")))
  320. (list :tag "Include data from diary"
  321. (const org-agenda-include-diary)
  322. (boolean))
  323. (list :tag "Deadline Warning days"
  324. (const org-deadline-warning-days)
  325. (integer :value 1))
  326. (list :tag "Category filter preset"
  327. (const org-agenda-category-filter-preset)
  328. (list
  329. (const :format "" quote)
  330. (repeat
  331. (string :tag "+category or -category"))))
  332. (list :tag "Tags filter preset"
  333. (const org-agenda-tag-filter-preset)
  334. (list
  335. (const :format "" quote)
  336. (repeat
  337. (string :tag "+tag or -tag"))))
  338. (list :tag "Effort filter preset"
  339. (const org-agenda-effort-filter-preset)
  340. (list
  341. (const :format "" quote)
  342. (repeat
  343. (string :tag "+=10 or -=10 or +<10 or ->10"))))
  344. (list :tag "Regexp filter preset"
  345. (const org-agenda-regexp-filter-preset)
  346. (list
  347. (const :format "" quote)
  348. (repeat
  349. (string :tag "+regexp or -regexp"))))
  350. (list :tag "Set daily/weekly entry types"
  351. (const org-agenda-entry-types)
  352. (list
  353. (const :format "" quote)
  354. (set :greedy t :value ,org-agenda-entry-types
  355. (const :deadline)
  356. (const :scheduled)
  357. (const :deadline*)
  358. (const :scheduled*)
  359. (const :timestamp)
  360. (const :sexp))))
  361. (list :tag "Columns format"
  362. (const org-overriding-columns-format)
  363. (string :tag "Format"))
  364. (list :tag "Standard skipping condition"
  365. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  366. (const org-agenda-skip-function)
  367. (list
  368. (const :format "" quote)
  369. (list
  370. (choice
  371. :tag "Skipping range"
  372. (const :tag "Skip entry" org-agenda-skip-entry-if)
  373. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  374. (repeat :inline t :tag "Conditions for skipping"
  375. (choice
  376. :tag "Condition type"
  377. (list :tag "Regexp matches" :inline t
  378. (const :format "" regexp)
  379. (regexp))
  380. (list :tag "Regexp does not match" :inline t
  381. (const :format "" notregexp)
  382. (regexp))
  383. (list :tag "TODO state is" :inline t
  384. (const todo)
  385. (choice
  386. (const :tag "Any not-done state" todo)
  387. (const :tag "Any done state" done)
  388. (const :tag "Any state" any)
  389. (list :tag "Keyword list"
  390. (const :format "" quote)
  391. (repeat (string :tag "Keyword")))))
  392. (list :tag "TODO state is not" :inline t
  393. (const nottodo)
  394. (choice
  395. (const :tag "Any not-done state" todo)
  396. (const :tag "Any done state" done)
  397. (const :tag "Any state" any)
  398. (list :tag "Keyword list"
  399. (const :format "" quote)
  400. (repeat (string :tag "Keyword")))))
  401. (const :tag "scheduled" scheduled)
  402. (const :tag "not scheduled" notscheduled)
  403. (const :tag "deadline" deadline)
  404. (const :tag "no deadline" notdeadline)
  405. (const :tag "timestamp" timestamp)
  406. (const :tag "no timestamp" nottimestamp))))))
  407. (list :tag "Non-standard skipping condition"
  408. :value (org-agenda-skip-function)
  409. (const org-agenda-skip-function)
  410. (sexp :tag "Function or form (quoted!)"))
  411. (list :tag "Any variable"
  412. (variable :tag "Variable")
  413. (sexp :tag "Value (sexp)"))))
  414. "Selection of examples for agenda command settings.
  415. This will be spliced into the custom type of
  416. `org-agenda-custom-commands'.")
  417. (defcustom org-agenda-custom-commands
  418. '(("n" "Agenda and all TODOs" ((agenda "") (alltodo ""))))
  419. "Custom commands for the agenda.
  420. \\<org-mode-map>
  421. These commands will be offered on the splash screen displayed by the
  422. agenda dispatcher `\\[org-agenda]'. Each entry is a list like this:
  423. (key desc type match settings files)
  424. key The key (one or more characters as a string) to be associated
  425. with the command.
  426. desc A description of the command. When omitted or nil, a default
  427. description is built using MATCH.
  428. type The command type, any of the following symbols:
  429. agenda The daily/weekly agenda.
  430. agenda* Appointments for current week/day.
  431. todo Entries with a specific TODO keyword, in all agenda files.
  432. search Entries containing search words entry or headline.
  433. tags Tags/Property/TODO match in all agenda files.
  434. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  435. todo-tree Sparse tree of specific TODO keyword in *current* file.
  436. tags-tree Sparse tree with all tags matches in *current* file.
  437. occur-tree Occur sparse tree for *current* file.
  438. alltodo The global TODO list.
  439. stuck Stuck projects.
  440. ... A user-defined function.
  441. match What to search for:
  442. - a single keyword for TODO keyword searches
  443. - a tags/property/todo match expression for searches
  444. - a word search expression for text searches.
  445. - a regular expression for occur searches
  446. For all other commands, this should be the empty string.
  447. settings A list of option settings, similar to that in a let form, so like
  448. this: ((opt1 val1) (opt2 val2) ...). The values will be
  449. evaluated at the moment of execution, so quote them when needed.
  450. files A list of files to write the produced agenda buffer to with
  451. the command `org-store-agenda-views'.
  452. If a file name ends in \".html\", an HTML version of the buffer
  453. is written out. If it ends in \".ps\", a PostScript version is
  454. produced. Otherwise, only the plain text is written to the file.
  455. You can also define a set of commands, to create a composite agenda buffer.
  456. In this case, an entry looks like this:
  457. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  458. where
  459. desc A description string to be displayed in the dispatcher menu.
  460. cmd An agenda command, similar to the above. However, tree commands
  461. are not allowed. Valid commands for a set are:
  462. (agenda \"\" settings)
  463. (agenda* \"\" settings)
  464. (alltodo \"\" settings)
  465. (stuck \"\" settings)
  466. (todo \"match\" settings files)
  467. (search \"match\" settings files)
  468. (tags \"match\" settings files)
  469. (tags-todo \"match\" settings files)
  470. Each command can carry a list of options, and another set of options can be
  471. given for the whole set of commands. Individual command options take
  472. precedence over the general options.
  473. When using several characters as key to a command, the first characters
  474. are prefix commands. For the dispatcher to display useful information, you
  475. should provide a description for the prefix, like
  476. (setq org-agenda-custom-commands
  477. \\='((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  478. (\"hl\" tags \"+HOME+Lisa\")
  479. (\"hp\" tags \"+HOME+Peter\")
  480. (\"hk\" tags \"+HOME+Kim\")))
  481. See also Info node `(org) Custom Agenda Views'."
  482. :group 'org-agenda-custom-commands
  483. :type `(repeat
  484. (choice :value ("x" "Describe command here" tags "" nil)
  485. (list :tag "Single command"
  486. (string :tag "Access Key(s) ")
  487. (option (string :tag "Description"))
  488. (choice
  489. (const :tag "Agenda" agenda)
  490. (const :tag "TODO list" alltodo)
  491. (const :tag "Search words" search)
  492. (const :tag "Stuck projects" stuck)
  493. (const :tag "Tags/Property match (all agenda files)" tags)
  494. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  495. (const :tag "TODO keyword search (all agenda files)" todo)
  496. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  497. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  498. (const :tag "Occur tree (current buffer)" occur-tree)
  499. (sexp :tag "Other, user-defined function"))
  500. (string :tag "Match (only for some commands)")
  501. ,org-agenda-custom-commands-local-options
  502. (option (repeat :tag "Export" (file :tag "Export to"))))
  503. (list :tag "Command series, all agenda files"
  504. (string :tag "Access Key(s)")
  505. (string :tag "Description ")
  506. (repeat :tag "Component"
  507. (choice
  508. (list :tag "Agenda"
  509. (const :format "" agenda)
  510. (const :tag "" :format "" "")
  511. ,org-agenda-custom-commands-local-options)
  512. (list :tag "TODO list (all keywords)"
  513. (const :format "" alltodo)
  514. (const :tag "" :format "" "")
  515. ,org-agenda-custom-commands-local-options)
  516. (list :tag "Search words"
  517. (const :format "" search)
  518. (string :tag "Match")
  519. ,org-agenda-custom-commands-local-options)
  520. (list :tag "Stuck projects"
  521. (const :format "" stuck)
  522. (const :tag "" :format "" "")
  523. ,org-agenda-custom-commands-local-options)
  524. (list :tag "Tags/Property match (all agenda files)"
  525. (const :format "" tags)
  526. (string :tag "Match")
  527. ,org-agenda-custom-commands-local-options)
  528. (list :tag "Tags/Property match of TODO entries (all agenda files)"
  529. (const :format "" tags-todo)
  530. (string :tag "Match")
  531. ,org-agenda-custom-commands-local-options)
  532. (list :tag "TODO keyword search"
  533. (const :format "" todo)
  534. (string :tag "Match")
  535. ,org-agenda-custom-commands-local-options)
  536. (list :tag "Other, user-defined function"
  537. (symbol :tag "function")
  538. (string :tag "Match")
  539. ,org-agenda-custom-commands-local-options)))
  540. (repeat :tag "Settings for entire command set"
  541. (list (variable :tag "Any variable")
  542. (sexp :tag "Value")))
  543. (option (repeat :tag "Export" (file :tag "Export to"))))
  544. (cons :tag "Prefix key documentation"
  545. (string :tag "Access Key(s)")
  546. (string :tag "Description ")))))
  547. (defcustom org-agenda-query-register ?o
  548. "The register holding the current query string.
  549. The purpose of this is that if you construct a query string interactively,
  550. you can then use it to define a custom command."
  551. :group 'org-agenda-custom-commands
  552. :type 'character)
  553. (defcustom org-stuck-projects
  554. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  555. "How to identify stuck projects.
  556. This is a list of four items:
  557. 1. A tags/todo/property matcher string that is used to identify a project.
  558. See Info node `(org) Matching tags and properties' for a
  559. description of tag and property searches. The entire tree
  560. below a headline matched by this is considered one project.
  561. 2. A list of TODO keywords identifying non-stuck projects.
  562. If the project subtree contains any headline with one of these todo
  563. keywords, the project is considered to be not stuck. If you specify
  564. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  565. 3. A list of tags identifying non-stuck projects.
  566. If the project subtree contains any headline with one of these tags,
  567. the project is considered to be not stuck. If you specify \"*\" as
  568. a tag, any tag will mark the project unstuck. Note that this is about
  569. the explicit presence of a tag somewhere in the subtree, inherited
  570. tags do not count here. If inherited tags make a project not stuck,
  571. use \"-TAG\" in the tags part of the matcher under (1.) above.
  572. 4. An arbitrary regular expression matching non-stuck projects.
  573. If the project turns out to be not stuck, search continues also in the
  574. subtree to see if any of the subtasks have project status.
  575. See also the variable `org-tags-match-list-sublevels' which applies
  576. to projects matched by this search as well.
  577. After defining this variable, you may use `org-agenda-list-stuck-projects'
  578. \(bound to `\\[org-agenda] #') to produce the list."
  579. :group 'org-agenda-custom-commands
  580. :type '(list
  581. (string :tag "Tags/TODO match to identify a project")
  582. (repeat :tag "Projects are *not* stuck if they have an entry with \
  583. TODO keyword any of" (string))
  584. (repeat :tag "Projects are *not* stuck if they have an entry with \
  585. TAG being any of" (string))
  586. (regexp :tag "Projects are *not* stuck if this regexp matches inside \
  587. the subtree")))
  588. (defgroup org-agenda-skip nil
  589. "Options concerning skipping parts of agenda files."
  590. :tag "Org Agenda Skip"
  591. :group 'org-agenda)
  592. (defcustom org-agenda-skip-function-global nil
  593. "Function to be called at each match during agenda construction.
  594. If this function returns nil, the current match should not be skipped.
  595. If the function decided to skip an agenda match, is must return the
  596. buffer position from which the search should be continued.
  597. This may also be a Lisp form, which will be evaluated.
  598. This variable will be applied to every agenda match, including
  599. tags/property searches and TODO lists. So try to make the test function
  600. do its checking as efficiently as possible. To implement a skipping
  601. condition just for specific agenda commands, use the variable
  602. `org-agenda-skip-function' which can be set in the options section
  603. of custom agenda commands."
  604. :group 'org-agenda-skip
  605. :type 'sexp)
  606. (defgroup org-agenda-daily/weekly nil
  607. "Options concerning the daily/weekly agenda."
  608. :tag "Org Agenda Daily/Weekly"
  609. :group 'org-agenda)
  610. (defgroup org-agenda-todo-list nil
  611. "Options concerning the global todo list agenda view."
  612. :tag "Org Agenda Todo List"
  613. :group 'org-agenda)
  614. (defgroup org-agenda-match-view nil
  615. "Options concerning the general tags/property/todo match agenda view."
  616. :tag "Org Agenda Match View"
  617. :group 'org-agenda)
  618. (defgroup org-agenda-search-view nil
  619. "Options concerning the search agenda view."
  620. :tag "Org Agenda Search View"
  621. :group 'org-agenda)
  622. (defvar org-agenda-archives-mode nil
  623. "Non-nil means the agenda will include archived items.
  624. If this is the symbol `trees', trees in the selected agenda scope
  625. that are marked with the ARCHIVE tag will be included anyway. When this is
  626. t, also all archive files associated with the current selection of agenda
  627. files will be included.")
  628. (defcustom org-agenda-restriction-lock-highlight-subtree t
  629. "Non-nil means highlight the whole subtree when restriction is active.
  630. Otherwise only highlight the headline. Highlighting the whole subtree is
  631. useful to ensure no edits happen beyond the restricted region."
  632. :group 'org-agenda
  633. :type 'boolean)
  634. (defcustom org-agenda-skip-comment-trees t
  635. "Non-nil means skip trees that start with the COMMENT keyword.
  636. When nil, these trees are also scanned by agenda commands."
  637. :group 'org-agenda-skip
  638. :type 'boolean)
  639. (defcustom org-agenda-todo-list-sublevels t
  640. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  641. When nil, the sublevels of a TODO entry are not checked, resulting in
  642. potentially much shorter TODO lists."
  643. :group 'org-agenda-skip
  644. :group 'org-agenda-todo-list
  645. :type 'boolean)
  646. (defcustom org-agenda-todo-ignore-with-date nil
  647. "Non-nil means don't show entries with a date in the global todo list.
  648. You can use this if you prefer to mark mere appointments with a TODO keyword,
  649. but don't want them to show up in the TODO list.
  650. When this is set, it also covers deadlines and scheduled items, the settings
  651. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  652. will be ignored.
  653. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  654. :group 'org-agenda-skip
  655. :group 'org-agenda-todo-list
  656. :type 'boolean)
  657. (defcustom org-agenda-todo-ignore-timestamp nil
  658. "Non-nil means don't show entries with a timestamp.
  659. This applies when creating the global todo list.
  660. Valid values are:
  661. past Don't show entries for today or in the past.
  662. future Don't show entries with a timestamp in the future.
  663. The idea behind this is that if it has a future
  664. timestamp, you don't want to think about it until the
  665. date.
  666. all Don't show any entries with a timestamp in the global todo list.
  667. The idea behind this is that by setting a timestamp, you
  668. have already \"taken care\" of this item.
  669. This variable can also have an integer as a value. If positive (N),
  670. todos with a timestamp N or more days in the future will be ignored. If
  671. negative (-N), todos with a timestamp N or more days in the past will be
  672. ignored. If 0, todos with a timestamp either today or in the future will
  673. be ignored. For example, a value of -1 will exclude todos with a
  674. timestamp in the past (yesterday or earlier), while a value of 7 will
  675. exclude todos with a timestamp a week or more in the future.
  676. See also `org-agenda-todo-ignore-with-date'.
  677. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  678. to make his option also apply to the tags-todo list."
  679. :group 'org-agenda-skip
  680. :group 'org-agenda-todo-list
  681. :version "24.1"
  682. :type '(choice
  683. (const :tag "Ignore future timestamp todos" future)
  684. (const :tag "Ignore past or present timestamp todos" past)
  685. (const :tag "Ignore all timestamp todos" all)
  686. (const :tag "Show timestamp todos" nil)
  687. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  688. (defcustom org-agenda-todo-ignore-scheduled nil
  689. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  690. This applies when creating the global todo list.
  691. Valid values are:
  692. past Don't show entries scheduled today or in the past.
  693. future Don't show entries scheduled in the future.
  694. The idea behind this is that by scheduling it, you don't want to
  695. think about it until the scheduled date.
  696. all Don't show any scheduled entries in the global todo list.
  697. The idea behind this is that by scheduling it, you have already
  698. \"taken care\" of this item.
  699. t Same as `all', for backward compatibility.
  700. This variable can also have an integer as a value. See
  701. `org-agenda-todo-ignore-timestamp' for more details.
  702. See also `org-agenda-todo-ignore-with-date'.
  703. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  704. to make his option also apply to the tags-todo list."
  705. :group 'org-agenda-skip
  706. :group 'org-agenda-todo-list
  707. :type '(choice
  708. (const :tag "Ignore future-scheduled todos" future)
  709. (const :tag "Ignore past- or present-scheduled todos" past)
  710. (const :tag "Ignore all scheduled todos" all)
  711. (const :tag "Ignore all scheduled todos (compatibility)" t)
  712. (const :tag "Show scheduled todos" nil)
  713. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  714. (defcustom org-agenda-todo-ignore-deadlines nil
  715. "Non-nil means ignore some deadline TODO items when making TODO list.
  716. There are different motivations for using different values, please think
  717. carefully when configuring this variable.
  718. This applies when creating the global TODO list.
  719. Valid values are:
  720. near Don't show near deadline entries. A deadline is near when it is
  721. closer than `org-deadline-warning-days' days. The idea behind this
  722. is that such items will appear in the agenda anyway.
  723. far Don't show TODO entries where a deadline has been defined, but
  724. is not going to happen anytime soon. This is useful if you want to use
  725. the TODO list to figure out what to do now.
  726. past Don't show entries with a deadline timestamp for today or in the past.
  727. future Don't show entries with a deadline timestamp in the future, not even
  728. when they become `near' ones. Use it with caution.
  729. all Ignore all TODO entries that do have a deadline.
  730. t Same as `near', for backward compatibility.
  731. This variable can also have an integer as a value. See
  732. `org-agenda-todo-ignore-timestamp' for more details.
  733. See also `org-agenda-todo-ignore-with-date'.
  734. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  735. to make his option also apply to the tags-todo list."
  736. :group 'org-agenda-skip
  737. :group 'org-agenda-todo-list
  738. :type '(choice
  739. (const :tag "Ignore near deadlines" near)
  740. (const :tag "Ignore near deadlines (compatibility)" t)
  741. (const :tag "Ignore far deadlines" far)
  742. (const :tag "Ignore all TODOs with a deadlines" all)
  743. (const :tag "Show all TODOs, even if they have a deadline" nil)
  744. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  745. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  746. "Time unit to use when possibly ignoring an agenda item.
  747. See the docstring of various `org-agenda-todo-ignore-*' options.
  748. The default is to compare time stamps using days. An item is thus
  749. considered to be in the future if it is at least one day after today.
  750. Non-nil means to compare time stamps using seconds. An item is then
  751. considered future if it has a time value later than current time."
  752. :group 'org-agenda-skip
  753. :group 'org-agenda-todo-list
  754. :version "24.4"
  755. :package-version '(Org . "8.0")
  756. :type '(choice
  757. (const :tag "Compare time with days" nil)
  758. (const :tag "Compare time with seconds" t)))
  759. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  760. "Non-nil means honor todo-list ignores options also in tags-todo search.
  761. The variables
  762. `org-agenda-todo-ignore-with-date',
  763. `org-agenda-todo-ignore-timestamp',
  764. `org-agenda-todo-ignore-scheduled',
  765. `org-agenda-todo-ignore-deadlines'
  766. make the global TODO list skip entries that have time stamps of certain
  767. kinds. If this option is set, the same options will also apply for the
  768. tags-todo search, which is the general tags/property matcher
  769. restricted to unfinished TODO entries only."
  770. :group 'org-agenda-skip
  771. :group 'org-agenda-todo-list
  772. :group 'org-agenda-match-view
  773. :type 'boolean)
  774. (defcustom org-agenda-skip-scheduled-if-done nil
  775. "Non-nil means don't show scheduled items in agenda when they are done.
  776. This is relevant for the daily/weekly agenda, not for the TODO list. It
  777. applies only to the actual date of the scheduling. Warnings about an item
  778. with a past scheduling dates are always turned off when the item is DONE."
  779. :group 'org-agenda-skip
  780. :group 'org-agenda-daily/weekly
  781. :type 'boolean)
  782. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  783. "Non-nil means skip scheduling line if same entry shows because of deadline.
  784. In the agenda of today, an entry can show up multiple times
  785. because it is both scheduled and has a nearby deadline, and maybe
  786. a plain time stamp as well.
  787. When this variable is nil, the entry will be shown several times.
  788. When set to t, then only the deadline is shown and the fact that
  789. the entry is scheduled today or was scheduled previously is not
  790. shown.
  791. When set to the symbol `not-today', skip scheduled previously,
  792. but not scheduled today.
  793. When set to the symbol `repeated-after-deadline', skip scheduled
  794. items if they are repeated beyond the current deadline."
  795. :group 'org-agenda-skip
  796. :group 'org-agenda-daily/weekly
  797. :type '(choice
  798. (const :tag "Never" nil)
  799. (const :tag "Always" t)
  800. (const :tag "Not when scheduled today" not-today)
  801. (const :tag "When repeated past deadline" repeated-after-deadline)))
  802. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  803. "Non-nil means skip timestamp line if same entry shows because of deadline.
  804. In the agenda of today, an entry can show up multiple times
  805. because it has both a plain timestamp and has a nearby deadline.
  806. When this variable is t, then only the deadline is shown and the
  807. fact that the entry has a timestamp for or including today is not
  808. shown. When this variable is nil, the entry will be shown
  809. several times."
  810. :group 'org-agenda-skip
  811. :group 'org-agenda-daily/weekly
  812. :version "24.1"
  813. :type '(choice
  814. (const :tag "Never" nil)
  815. (const :tag "Always" t)))
  816. (defcustom org-agenda-skip-deadline-if-done nil
  817. "Non-nil means don't show deadlines when the corresponding item is done.
  818. When nil, the deadline is still shown and should give you a happy feeling.
  819. This is relevant for the daily/weekly agenda. It applies only to the
  820. actual date of the deadline. Warnings about approaching and past-due
  821. deadlines are always turned off when the item is DONE."
  822. :group 'org-agenda-skip
  823. :group 'org-agenda-daily/weekly
  824. :type 'boolean)
  825. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  826. "Non-nil means skip deadline prewarning when entry is also scheduled.
  827. This will apply on all days where a prewarning for the deadline would
  828. be shown, but not at the day when the entry is actually due. On that day,
  829. the deadline will be shown anyway.
  830. This variable may be set to nil, t, the symbol `pre-scheduled',
  831. or a number which will then give the number of days before the actual
  832. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  833. eliminates the deadline prewarning only prior to the scheduled date.
  834. This can be used in a workflow where the first showing of the deadline will
  835. trigger you to schedule it, and then you don't want to be reminded of it
  836. because you will take care of it on the day when scheduled."
  837. :group 'org-agenda-skip
  838. :group 'org-agenda-daily/weekly
  839. :version "24.1"
  840. :type '(choice
  841. (const :tag "Always show prewarning" nil)
  842. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  843. (const :tag "Remove prewarning if entry is scheduled" t)
  844. (integer :tag "Restart prewarning N days before deadline")))
  845. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  846. "Non-nil means skip scheduled delay when entry also has a deadline.
  847. This variable may be set to nil, t, the symbol `post-deadline',
  848. or a number which will then give the number of days after the actual
  849. scheduled date when the delay should expire. The symbol `post-deadline'
  850. eliminates the schedule delay when the date is posterior to the deadline."
  851. :group 'org-agenda-skip
  852. :group 'org-agenda-daily/weekly
  853. :version "24.4"
  854. :package-version '(Org . "8.0")
  855. :type '(choice
  856. (const :tag "Always honor delay" nil)
  857. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  858. (const :tag "Ignore delay if entry has a deadline" t)
  859. (integer :tag "Honor delay up until N days after the scheduled date")))
  860. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  861. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  862. When non-nil, after the search for timestamps has matched once in an
  863. entry, the rest of the entry will not be searched."
  864. :group 'org-agenda-skip
  865. :type 'boolean)
  866. (defcustom org-agenda-skip-timestamp-if-done nil
  867. "Non-nil means don't select item by timestamp or -range if it is DONE."
  868. :group 'org-agenda-skip
  869. :group 'org-agenda-daily/weekly
  870. :type 'boolean)
  871. (defcustom org-agenda-dim-blocked-tasks t
  872. "Non-nil means dim blocked tasks in the agenda display.
  873. This causes some overhead during agenda construction, but if you
  874. have turned on `org-enforce-todo-dependencies',
  875. `org-enforce-todo-checkbox-dependencies', or any other blocking
  876. mechanism, this will create useful feedback in the agenda.
  877. Instead of t, this variable can also have the value `invisible'.
  878. Then blocked tasks will be invisible and only become visible when
  879. they become unblocked. An exemption to this behavior is when a task is
  880. blocked because of unchecked checkboxes below it. Since checkboxes do
  881. not show up in the agenda views, making this task invisible you remove any
  882. trace from agenda views that there is something to do. Therefore, a task
  883. that is blocked because of checkboxes will never be made invisible, it
  884. will only be dimmed."
  885. :group 'org-agenda-daily/weekly
  886. :group 'org-agenda-todo-list
  887. :version "24.3"
  888. :type '(choice
  889. (const :tag "Do not dim" nil)
  890. (const :tag "Dim to a gray face" t)
  891. (const :tag "Make invisible" invisible)))
  892. (defgroup org-agenda-startup nil
  893. "Options concerning initial settings in the Agenda in Org Mode."
  894. :tag "Org Agenda Startup"
  895. :group 'org-agenda)
  896. (defcustom org-agenda-menu-show-matcher t
  897. "Non-nil means show the match string in the agenda dispatcher menu.
  898. When nil, the matcher string is not shown, but is put into the help-echo
  899. property so than moving the mouse over the command shows it.
  900. Setting it to nil is good if matcher strings are very long and/or if
  901. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  902. :group 'org-agenda
  903. :version "24.1"
  904. :type 'boolean)
  905. (defcustom org-agenda-menu-two-columns nil
  906. "Non-nil means, use two columns to show custom commands in the dispatcher.
  907. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  908. to nil."
  909. :group 'org-agenda
  910. :version "24.1"
  911. :type 'boolean)
  912. (defcustom org-agenda-finalize-hook nil
  913. "Hook run just before displaying an agenda buffer.
  914. The buffer is still writable when the hook is called.
  915. You can modify some of the buffer substrings but you should be
  916. extra careful not to modify the text properties of the agenda
  917. headlines as the agenda display heavily relies on them."
  918. :group 'org-agenda-startup
  919. :type 'hook)
  920. (defcustom org-agenda-filter-hook nil
  921. "Hook run just after filtering with `org-agenda-filter'."
  922. :group 'org-agenda-startup
  923. :package-version '(Org . "9.4")
  924. :type 'hook)
  925. (defcustom org-agenda-mouse-1-follows-link nil
  926. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  927. A longer mouse click will still set point. Needs to be set
  928. before org.el is loaded."
  929. :group 'org-agenda-startup
  930. :type 'boolean)
  931. (defcustom org-agenda-start-with-follow-mode nil
  932. "The initial value of follow mode in a newly created agenda window."
  933. :group 'org-agenda-startup
  934. :type 'boolean)
  935. (defcustom org-agenda-follow-indirect nil
  936. "Non-nil means `org-agenda-follow-mode' displays only the
  937. current item's tree, in an indirect buffer."
  938. :group 'org-agenda
  939. :version "24.1"
  940. :type 'boolean)
  941. (defcustom org-agenda-show-outline-path t
  942. "Non-nil means show outline path in echo area after line motion."
  943. :group 'org-agenda-startup
  944. :type 'boolean)
  945. (defcustom org-agenda-start-with-entry-text-mode nil
  946. "The initial value of entry-text-mode in a newly created agenda window."
  947. :group 'org-agenda-startup
  948. :type 'boolean)
  949. (defcustom org-agenda-entry-text-maxlines 5
  950. "Number of text lines to be added when `E' is pressed in the agenda.
  951. Note that this variable only used during agenda display. To add entry text
  952. when exporting the agenda, configure the variable
  953. `org-agenda-add-entry-text-maxlines'."
  954. :group 'org-agenda
  955. :type 'integer)
  956. (defcustom org-agenda-entry-text-exclude-regexps nil
  957. "List of regular expressions to clean up entry text.
  958. The complete matches of all regular expressions in this list will be
  959. removed from entry text before it is shown in the agenda."
  960. :group 'org-agenda
  961. :type '(repeat (regexp)))
  962. (defcustom org-agenda-entry-text-leaders " > "
  963. "Text prepended to the entry text in agenda buffers."
  964. :version "24.4"
  965. :package-version '(Org . "8.0")
  966. :group 'org-agenda
  967. :type 'string)
  968. (defvar org-agenda-entry-text-cleanup-hook nil
  969. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  970. This cleanup is done in a temporary buffer, so the function may inspect and
  971. change the entire buffer.
  972. Some default stuff like drawers and scheduling/deadline dates will already
  973. have been removed when this is called, as will any matches for regular
  974. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  975. (defvar org-agenda-include-inactive-timestamps nil
  976. "Non-nil means include inactive time stamps in agenda.
  977. Dynamically scoped.")
  978. (defgroup org-agenda-windows nil
  979. "Options concerning the windows used by the Agenda in Org Mode."
  980. :tag "Org Agenda Windows"
  981. :group 'org-agenda)
  982. (defcustom org-agenda-window-setup 'reorganize-frame
  983. "How the agenda buffer should be displayed.
  984. Possible values for this option are:
  985. current-window Show agenda in the current window, keeping all other windows.
  986. other-window Use `switch-to-buffer-other-window' to display agenda.
  987. only-window Show agenda, deleting all other windows.
  988. reorganize-frame Show only two windows on the current frame, the current
  989. window and the agenda.
  990. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  991. Also, when exiting the agenda, kill that frame.
  992. other-tab Use `switch-to-buffer-other-tab' to display the
  993. agenda, making use of the `tab-bar-mode' introduced
  994. in Emacs version 27.1. Also, kill that tab when
  995. exiting the agenda view.
  996. See also the variable `org-agenda-restore-windows-after-quit'."
  997. :group 'org-agenda-windows
  998. :type '(choice
  999. (const current-window)
  1000. (const other-frame)
  1001. (const other-tab)
  1002. (const other-window)
  1003. (const only-window)
  1004. (const reorganize-frame))
  1005. :package-version '(Org . "9.4"))
  1006. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  1007. "The min and max height of the agenda window as a fraction of frame height.
  1008. The value of the variable is a cons cell with two numbers between 0 and 1.
  1009. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  1010. :group 'org-agenda-windows
  1011. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  1012. (defcustom org-agenda-restore-windows-after-quit nil
  1013. "Non-nil means restore window configuration upon exiting agenda.
  1014. Before the window configuration is changed for displaying the
  1015. agenda, the current status is recorded. When the agenda is
  1016. exited with `q' or `x' and this option is set, the old state is
  1017. restored. If `org-agenda-window-setup' is `other-frame' or
  1018. `other-tab', the value of this option will be ignored."
  1019. :group 'org-agenda-windows
  1020. :type 'boolean)
  1021. (defcustom org-agenda-span 'week
  1022. "Number of days to include in overview display.
  1023. Can be day, week, month, year, or any number of days.
  1024. Custom commands can set this variable in the options section."
  1025. :group 'org-agenda-daily/weekly
  1026. :type '(choice (const :tag "Day" day)
  1027. (const :tag "Week" week)
  1028. (const :tag "Fortnight" fortnight)
  1029. (const :tag "Month" month)
  1030. (const :tag "Year" year)
  1031. (integer :tag "Custom")))
  1032. (defcustom org-agenda-start-on-weekday 1
  1033. "Non-nil means start the overview always on the specified weekday.
  1034. 0 denotes Sunday, 1 denotes Monday, etc.
  1035. When nil, always start on the current day.
  1036. Custom commands can set this variable in the options section."
  1037. :group 'org-agenda-daily/weekly
  1038. :type '(choice (const :tag "Today" nil)
  1039. (integer :tag "Weekday No.")))
  1040. (defcustom org-agenda-show-all-dates t
  1041. "Non-nil means `org-agenda' shows every day in the selected range.
  1042. When nil, only the days which actually have entries are shown."
  1043. :group 'org-agenda-daily/weekly
  1044. :type 'boolean)
  1045. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1046. "Format string for displaying dates in the agenda.
  1047. Used by the daily/weekly agenda. This should be a format string
  1048. understood by `format-time-string', or a function returning the
  1049. formatted date as a string. The function must take a single
  1050. argument, a calendar-style date list like (month day year)."
  1051. :group 'org-agenda-daily/weekly
  1052. :type '(choice
  1053. (string :tag "Format string")
  1054. (function :tag "Function")))
  1055. (defun org-agenda-end-of-line ()
  1056. "Go to the end of visible line."
  1057. (interactive)
  1058. (goto-char (line-end-position)))
  1059. (defun org-agenda-format-date-aligned (date)
  1060. "Format a DATE string for display in the daily/weekly agenda.
  1061. This function makes sure that dates are aligned for easy reading."
  1062. (require 'cal-iso)
  1063. (let* ((dayname (calendar-day-name date))
  1064. (day (cadr date))
  1065. (day-of-week (calendar-day-of-week date))
  1066. (month (car date))
  1067. (monthname (calendar-month-name month))
  1068. (year (nth 2 date))
  1069. (iso-week (org-days-to-iso-week
  1070. (calendar-absolute-from-gregorian date)))
  1071. ;; (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1072. ;; (1- year))
  1073. ;; ((and (= month 12) (<= iso-week 1))
  1074. ;; (1+ year))
  1075. ;; (t year)))
  1076. (weekstring (if (= day-of-week 1)
  1077. (format " W%02d" iso-week)
  1078. "")))
  1079. (format "%-10s %2d %s %4d%s"
  1080. dayname day monthname year weekstring)))
  1081. (defcustom org-agenda-time-leading-zero nil
  1082. "Non-nil means use leading zero for military times in agenda.
  1083. For example, 9:30am would become 09:30 rather than 9:30."
  1084. :group 'org-agenda-daily/weekly
  1085. :version "24.1"
  1086. :type 'boolean)
  1087. (defcustom org-agenda-timegrid-use-ampm nil
  1088. "When set, show AM/PM style timestamps on the timegrid."
  1089. :group 'org-agenda
  1090. :version "24.1"
  1091. :type 'boolean)
  1092. (defcustom org-agenda-clock-report-header nil
  1093. "Header inserted before the table in Org agenda clock report mode.
  1094. See Info node `(org) Agenda Commands' for more details."
  1095. :group 'org-agenda
  1096. :type '(choice
  1097. (string :tag "Header")
  1098. (const :tag "No header" nil))
  1099. :safe #'stringp
  1100. :package-version '(Org . "9.6"))
  1101. (defun org-agenda-time-of-day-to-ampm (time)
  1102. "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
  1103. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1104. (minute (substring time -2))
  1105. (ampm "am"))
  1106. (cond
  1107. ((equal hour-number 12)
  1108. (setq ampm "pm"))
  1109. ((> hour-number 12)
  1110. (setq ampm "pm")
  1111. (setq hour-number (- hour-number 12))))
  1112. (concat
  1113. (if org-agenda-time-leading-zero
  1114. (format "%02d" hour-number)
  1115. (format "%02s" (number-to-string hour-number)))
  1116. ":" minute ampm)))
  1117. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1118. "Conditionally convert TIME to AM/PM format.
  1119. This is based on `org-agenda-timegrid-use-ampm'."
  1120. (if org-agenda-timegrid-use-ampm
  1121. (org-agenda-time-of-day-to-ampm time)
  1122. time))
  1123. (defcustom org-agenda-weekend-days '(6 0)
  1124. "Which days are weekend?
  1125. These days get the special face `org-agenda-date-weekend' in the agenda."
  1126. :group 'org-agenda-daily/weekly
  1127. :type '(set :greedy t
  1128. (const :tag "Monday" 1)
  1129. (const :tag "Tuesday" 2)
  1130. (const :tag "Wednesday" 3)
  1131. (const :tag "Thursday" 4)
  1132. (const :tag "Friday" 5)
  1133. (const :tag "Saturday" 6)
  1134. (const :tag "Sunday" 0)))
  1135. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1136. "Non-nil means jump to today when moving a past date forward in time.
  1137. When using S-right in the agenda to move a date forward, and the date
  1138. stamp currently points to the past, the first key press will move it
  1139. to today. When nil, just move one day forward even if the date stays
  1140. in the past."
  1141. :group 'org-agenda-daily/weekly
  1142. :version "24.1"
  1143. :type 'boolean)
  1144. (defcustom org-agenda-diary-file 'diary-file
  1145. "File to which to add new entries with the `i' key in agenda and calendar.
  1146. When this is the symbol `diary-file', the functionality in the Emacs
  1147. calendar will be used to add entries to the `diary-file'. But when this
  1148. points to a file, `org-agenda-diary-entry' will be used instead."
  1149. :group 'org-agenda
  1150. :type '(choice
  1151. (const :tag "The standard Emacs diary file" diary-file)
  1152. (file :tag "Special Org file diary entries")))
  1153. (defcustom org-agenda-include-diary nil
  1154. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1155. Custom commands can set this variable in the options section."
  1156. :group 'org-agenda-daily/weekly
  1157. :type 'boolean)
  1158. (defcustom org-agenda-include-deadlines t
  1159. "If non-nil, include entries within their deadline warning period.
  1160. Custom commands can set this variable in the options section."
  1161. :group 'org-agenda-daily/weekly
  1162. :version "24.1"
  1163. :type 'boolean)
  1164. (defcustom org-agenda-show-future-repeats t
  1165. "Non-nil shows repeated entries in the future part of the agenda.
  1166. When set to the symbol `next' only the first future repeat is shown."
  1167. :group 'org-agenda-daily/weekly
  1168. :type '(choice
  1169. (const :tag "Show all repeated entries" t)
  1170. (const :tag "Show next repeated entry" next)
  1171. (const :tag "Do not show repeated entries" nil))
  1172. :version "26.1"
  1173. :package-version '(Org . "9.1")
  1174. :safe #'symbolp)
  1175. (defcustom org-agenda-prefer-last-repeat nil
  1176. "Non-nil sets date for repeated entries to their last repeat.
  1177. When nil, display SCHEDULED and DEADLINE dates at their base
  1178. date, and in today's agenda, as a reminder. Display plain
  1179. time-stamps, on the other hand, at every repeat date in the past
  1180. in addition to the base date.
  1181. When non-nil, show a repeated entry at its latest repeat date,
  1182. possibly being today even if it wasn't marked as done. This
  1183. setting is useful if you do not always mark repeated entries as
  1184. done and, yet, consider that reaching repeat date starts the task
  1185. anew.
  1186. When set to a list of strings, prefer last repeats only for
  1187. entries with these TODO keywords."
  1188. :group 'org-agenda-daily/weekly
  1189. :type '(choice
  1190. (const :tag "Prefer last repeat" t)
  1191. (const :tag "Prefer base date" nil)
  1192. (repeat :tag "Prefer last repeat for entries with these TODO keywords"
  1193. (string :tag "TODO keyword")))
  1194. :version "26.1"
  1195. :package-version '(Org . "9.1")
  1196. :safe (lambda (x) (or (booleanp x) (consp x))))
  1197. (defcustom org-scheduled-past-days 10000
  1198. "Number of days to continue listing scheduled items not marked DONE.
  1199. When an item is scheduled on a date, it shows up in the agenda on
  1200. this day and will be listed until it is marked done or for the
  1201. number of days given here."
  1202. :group 'org-agenda-daily/weekly
  1203. :type 'integer
  1204. :safe 'integerp)
  1205. (defcustom org-deadline-past-days 10000
  1206. "Number of days to warn about missed deadlines.
  1207. When an item has deadline on a date, it shows up in the agenda on
  1208. this day and will appear as a reminder until it is marked DONE or
  1209. for the number of days given here."
  1210. :group 'org-agenda-daily/weekly
  1211. :type 'integer
  1212. :version "26.1"
  1213. :package-version '(Org . "9.1")
  1214. :safe 'integerp)
  1215. (defcustom org-agenda-log-mode-items '(closed clock)
  1216. "List of items that should be shown in agenda log mode.
  1217. \\<org-agenda-mode-map>\
  1218. This list may contain the following symbols:
  1219. closed Show entries that have been closed on that day.
  1220. clock Show entries that have received clocked time on that day.
  1221. state Show all logged state changes.
  1222. Note that instead of changing this variable, you can also press \
  1223. `\\[universal-argument] \\[org-agenda-log-mode]' in
  1224. the agenda to display all available LOG items temporarily."
  1225. :group 'org-agenda-daily/weekly
  1226. :type '(set :greedy t (const closed) (const clock) (const state)))
  1227. (defcustom org-agenda-clock-consistency-checks
  1228. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1229. :gap-ok-around ("4:00")
  1230. :default-face ((:background "DarkRed") (:foreground "white"))
  1231. :overlap-face nil :gap-face nil :no-end-time-face nil
  1232. :long-face nil :short-face nil)
  1233. "This is a property list, with the following keys:
  1234. :max-duration Mark clocking chunks that are longer than this time.
  1235. This is a time string like \"HH:MM\", or the number
  1236. of minutes as an integer.
  1237. :min-duration Mark clocking chunks that are shorter that this.
  1238. This is a time string like \"HH:MM\", or the number
  1239. of minutes as an integer.
  1240. :max-gap Mark gaps between clocking chunks that are longer than
  1241. this duration. A number of minutes, or a string
  1242. like \"HH:MM\".
  1243. :gap-ok-around List of times during the day which are usually not working
  1244. times. When a gap is detected, but the gap contains any
  1245. of these times, the gap is *not* reported. For example,
  1246. if this is (\"4:00\" \"13:00\") then gaps that contain
  1247. 4:00 in the morning (i.e. the night) and 13:00
  1248. (i.e. a typical lunch time) do not cause a warning.
  1249. You should have at least one time during the night in this
  1250. list, or otherwise the first task each morning will trigger
  1251. a warning because it follows a long gap.
  1252. Furthermore, the following properties can be used to define faces for
  1253. issue display.
  1254. :default-face the default face, if the specific face is undefined
  1255. :overlap-face face for overlapping clocks
  1256. :gap-face face for gaps between clocks
  1257. :no-end-time-face face for incomplete clocks
  1258. :long-face face for clock intervals that are too long
  1259. :short-face face for clock intervals that are too short"
  1260. :group 'org-agenda-daily/weekly
  1261. :group 'org-clock
  1262. :version "24.1"
  1263. :type 'plist)
  1264. (defcustom org-agenda-log-mode-add-notes t
  1265. "Non-nil means add first line of notes to log entries in agenda views.
  1266. If a log item like a state change or a clock entry is associated with
  1267. notes, the first line of these notes will be added to the entry in the
  1268. agenda display."
  1269. :group 'org-agenda-daily/weekly
  1270. :type 'boolean)
  1271. (defcustom org-agenda-start-with-log-mode nil
  1272. "The initial value of log-mode in a newly created agenda window.
  1273. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1274. explanations on the possible values."
  1275. :group 'org-agenda-startup
  1276. :group 'org-agenda-daily/weekly
  1277. :type '(choice (const :tag "Don't show log items" nil)
  1278. (const :tag "Show only log items" only)
  1279. (const :tag "Show all possible log items" clockcheck)
  1280. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1281. (choice (const :tag "Show closed log items" closed)
  1282. (const :tag "Show clocked log items" clock)
  1283. (const :tag "Show all logged state changes" state)))))
  1284. (defcustom org-agenda-start-with-clockreport-mode nil
  1285. "The initial value of clockreport-mode in a newly created agenda window."
  1286. :group 'org-agenda-startup
  1287. :group 'org-agenda-daily/weekly
  1288. :type 'boolean)
  1289. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1290. "Property list with parameters for the clocktable in clockreport mode.
  1291. This is the display mode that shows a clock table in the daily/weekly
  1292. agenda, the properties for this dynamic block can be set here.
  1293. The usual clocktable parameters are allowed here, but you cannot set
  1294. the properties :name, :tstart, :tend, :block, and :scope - these will
  1295. be overwritten to make sure the content accurately reflects the
  1296. current display in the agenda."
  1297. :group 'org-agenda-daily/weekly
  1298. :type 'plist)
  1299. (defvaralias 'org-agenda-search-view-search-words-only
  1300. 'org-agenda-search-view-always-boolean)
  1301. (defcustom org-agenda-search-view-always-boolean nil
  1302. "Non-nil means the search string is interpreted as individual parts.
  1303. The search string for search view can either be interpreted as a phrase,
  1304. or as a list of snippets that define a boolean search for a number of
  1305. strings.
  1306. When this is non-nil, the string will be split on whitespace, and each
  1307. snippet will be searched individually, and all must match in order to
  1308. select an entry. A snippet is then a single string of non-white
  1309. characters, or a string in double quotes, or a regexp in {} braces.
  1310. If a snippet is preceded by \"-\", the snippet must *not* match.
  1311. \"+\" is syntactic sugar for positive selection. Each snippet may
  1312. be found as a full word or a partial word, but see the variable
  1313. `org-agenda-search-view-force-full-words'.
  1314. When this is nil, search will look for the entire search phrase as one,
  1315. with each space character matching any amount of whitespace, including
  1316. line breaks.
  1317. Even when this is nil, you can still switch to Boolean search dynamically
  1318. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1319. is a regexp marked with braces like \"{abc}\", this will also switch to
  1320. boolean search."
  1321. :group 'org-agenda-search-view
  1322. :version "24.1"
  1323. :type 'boolean)
  1324. (defcustom org-agenda-search-view-force-full-words nil
  1325. "Non-nil means, search words must be matches as complete words.
  1326. When nil, they may also match part of a word."
  1327. :group 'org-agenda-search-view
  1328. :version "24.1"
  1329. :type 'boolean)
  1330. (defcustom org-agenda-search-view-max-outline-level 0
  1331. "Maximum outline level to display in search view.
  1332. E.g. when this is set to 1, the search view will only
  1333. show headlines of level 1. When set to 0, the default
  1334. value, don't limit agenda view by outline level."
  1335. :group 'org-agenda-search-view
  1336. :version "26.1"
  1337. :package-version '(Org . "8.3")
  1338. :type 'integer)
  1339. (defgroup org-agenda-time-grid nil
  1340. "Options concerning the time grid in the Org Agenda."
  1341. :tag "Org Agenda Time Grid"
  1342. :group 'org-agenda)
  1343. (defcustom org-agenda-search-headline-for-time t
  1344. "Non-nil means search headline for a time-of-day.
  1345. If the headline contains a time-of-day in one format or another, it will
  1346. be used to sort the entry into the time sequence of items for a day.
  1347. Some people have time stamps in the headline that refer to the creation
  1348. time or so, and then this produces an unwanted side effect. If this is
  1349. the case for your, use this variable to turn off searching the headline
  1350. for a time."
  1351. :group 'org-agenda-time-grid
  1352. :type 'boolean)
  1353. (defcustom org-agenda-use-time-grid t
  1354. "Non-nil means show a time grid in the agenda schedule.
  1355. A time grid is a set of lines for specific times (like every two hours between
  1356. 8:00 and 20:00). The items scheduled for a day at specific times are
  1357. sorted in between these lines.
  1358. For details about when the grid will be shown, and what it will look like, see
  1359. the variable `org-agenda-time-grid'."
  1360. :group 'org-agenda-time-grid
  1361. :type 'boolean)
  1362. (defcustom org-agenda-time-grid
  1363. (let ((graphical (and (display-graphic-p)
  1364. (char-displayable-p ?┄))))
  1365. `((daily today require-timed)
  1366. (800 1000 1200 1400 1600 1800 2000)
  1367. ,(if graphical " ┄┄┄┄┄ " "......")
  1368. ,(if graphical "┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄" "----------------")))
  1369. "The settings for time grid for agenda display.
  1370. This is a list of four items. The first item is again a list. It contains
  1371. symbols specifying conditions when the grid should be displayed:
  1372. daily if the agenda shows a single day
  1373. weekly if the agenda shows an entire week
  1374. today show grid on current date, independent of daily/weekly display
  1375. require-timed show grid only if at least one item has a time specification
  1376. remove-match skip grid times already present in an entry
  1377. The second item is a list of integers, indicating the times that
  1378. should have a grid line.
  1379. The third item is a string which will be placed right after the
  1380. times that have a grid line.
  1381. The fourth item is a string placed after the grid times. This
  1382. will align with agenda items."
  1383. :group 'org-agenda-time-grid
  1384. :package-version '(Org . "9.6")
  1385. :type
  1386. '(list
  1387. (set :greedy t :tag "Grid Display Options"
  1388. (const :tag "Show grid in single day agenda display" daily)
  1389. (const :tag "Show grid in weekly agenda display" weekly)
  1390. (const :tag "Always show grid for today" today)
  1391. (const :tag "Show grid only if any timed entries are present"
  1392. require-timed)
  1393. (const :tag "Skip grid times already present in an entry"
  1394. remove-match))
  1395. (repeat :tag "Grid Times" (integer :tag "Time"))
  1396. (string :tag "Grid String (after agenda times)")
  1397. (string :tag "Grid String (aligns with agenda items)")))
  1398. (defcustom org-agenda-show-current-time-in-grid t
  1399. "Non-nil means show the current time in the time grid."
  1400. :group 'org-agenda-time-grid
  1401. :version "24.1"
  1402. :type 'boolean)
  1403. (defcustom org-agenda-current-time-string
  1404. (if (and (display-graphic-p)
  1405. (char-displayable-p ?←)
  1406. (char-displayable-p ?─))
  1407. "← now ───────────────────────────────────────────────"
  1408. "now - - - - - - - - - - - - - - - - - - - - - - - - -")
  1409. "The string for the current time marker in the agenda."
  1410. :group 'org-agenda-time-grid
  1411. :package-version '(Org . "9.6")
  1412. :type 'string)
  1413. (defgroup org-agenda-sorting nil
  1414. "Options concerning sorting in the Org Agenda."
  1415. :tag "Org Agenda Sorting"
  1416. :group 'org-agenda)
  1417. (defcustom org-agenda-sorting-strategy
  1418. '((agenda habit-down time-up priority-down category-keep)
  1419. (todo priority-down category-keep)
  1420. (tags priority-down category-keep)
  1421. (search category-keep))
  1422. "Sorting structure for the agenda items of a single day.
  1423. This is a list of symbols which will be used in sequence to determine
  1424. if an entry should be listed before another entry. The following
  1425. symbols are recognized:
  1426. time-up Put entries with time-of-day indications first, early first.
  1427. time-down Put entries with time-of-day indications first, late first.
  1428. timestamp-up Sort by any timestamp, early first.
  1429. timestamp-down Sort by any timestamp, late first.
  1430. scheduled-up Sort by scheduled timestamp, early first.
  1431. scheduled-down Sort by scheduled timestamp, late first.
  1432. deadline-up Sort by deadline timestamp, early first.
  1433. deadline-down Sort by deadline timestamp, late first.
  1434. ts-up Sort by active timestamp, early first.
  1435. ts-down Sort by active timestamp, late first.
  1436. tsia-up Sort by inactive timestamp, early first.
  1437. tsia-down Sort by inactive timestamp, late first.
  1438. category-keep Keep the default order of categories, corresponding to the
  1439. sequence in `org-agenda-files'.
  1440. category-up Sort alphabetically by category, A-Z.
  1441. category-down Sort alphabetically by category, Z-A.
  1442. tag-up Sort alphabetically by last tag, A-Z.
  1443. tag-down Sort alphabetically by last tag, Z-A.
  1444. priority-up Sort numerically by priority, high priority last.
  1445. priority-down Sort numerically by priority, high priority first.
  1446. todo-state-up Sort by todo state, tasks that are done last.
  1447. todo-state-down Sort by todo state, tasks that are done first.
  1448. effort-up Sort numerically by estimated effort, high effort last.
  1449. effort-down Sort numerically by estimated effort, high effort first.
  1450. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1451. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1452. habit-up Put entries that are habits first.
  1453. habit-down Put entries that are habits last.
  1454. alpha-up Sort headlines alphabetically.
  1455. alpha-down Sort headlines alphabetically, reversed.
  1456. The different possibilities will be tried in sequence, and testing stops
  1457. if one comparison returns a \"not-equal\". For example,
  1458. (setq org-agenda-sorting-strategy
  1459. \\='(time-up category-keep priority-down))
  1460. means: Pull out all entries having a specified time of day and sort them,
  1461. in order to make a time schedule for the current day the first thing in the
  1462. agenda listing for the day. Of the entries without a time indication, keep
  1463. the grouped in categories, don't sort the categories, but keep them in
  1464. the sequence given in `org-agenda-files'. Within each category sort by
  1465. priority.
  1466. Leaving out `category-keep' would mean that items will be sorted across
  1467. categories by priority.
  1468. Instead of a single list, this can also be a set of list for specific
  1469. contents, with a context symbol in the car of the list, any of
  1470. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1471. Custom commands can bind this variable in the options section."
  1472. :group 'org-agenda-sorting
  1473. :type `(choice
  1474. (repeat :tag "General" ,org-sorting-choice)
  1475. (list :tag "Individually"
  1476. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1477. (repeat ,org-sorting-choice))
  1478. (cons (const :tag "Strategy for TODO lists" todo)
  1479. (repeat ,org-sorting-choice))
  1480. (cons (const :tag "Strategy for Tags matches" tags)
  1481. (repeat ,org-sorting-choice))
  1482. (cons (const :tag "Strategy for search matches" search)
  1483. (repeat ,org-sorting-choice)))))
  1484. (defcustom org-agenda-cmp-user-defined nil
  1485. "A function to define the comparison `user-defined'.
  1486. This function must receive two arguments, agenda entry a and b.
  1487. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1488. the user comparison, return nil.
  1489. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1490. part of an agenda sorting strategy."
  1491. :group 'org-agenda-sorting
  1492. :type 'symbol)
  1493. (defcustom org-agenda-sort-notime-is-late t
  1494. "Non-nil means items without time are considered late.
  1495. This is only relevant for sorting. When t, items which have no explicit
  1496. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1497. do have a time. When nil, the default time is before 0:00. You can use this
  1498. option to decide if the schedule for today should come before or after timeless
  1499. agenda entries."
  1500. :group 'org-agenda-sorting
  1501. :type 'boolean)
  1502. (defcustom org-agenda-sort-noeffort-is-high t
  1503. "Non-nil means items without effort estimate are sorted as high effort.
  1504. This also applies when filtering an agenda view with respect to the
  1505. < or > effort operator. Then, tasks with no effort defined will be treated
  1506. as tasks with high effort.
  1507. When nil, such items are sorted as 0 minutes effort."
  1508. :group 'org-agenda-sorting
  1509. :type 'boolean)
  1510. (defgroup org-agenda-line-format nil
  1511. "Options concerning the entry prefix in the Org agenda display."
  1512. :tag "Org Agenda Line Format"
  1513. :group 'org-agenda)
  1514. (defcustom org-agenda-prefix-format
  1515. '((agenda . " %i %-12:c%?-12t% s")
  1516. (todo . " %i %-12:c")
  1517. (tags . " %i %-12:c")
  1518. (search . " %i %-12:c"))
  1519. "Format specifications for the prefix of items in the agenda views.
  1520. An alist with one entry per agenda type. The keys of the
  1521. sublists are `agenda', `todo', `search' and `tags'. The values
  1522. are format strings.
  1523. This format works similar to a printf format, with the following meaning:
  1524. %c the category of the item, \"Diary\" for entries from the diary,
  1525. or as given by the CATEGORY keyword or derived from the file name
  1526. %e the effort required by the item
  1527. %l the level of the item (insert X space(s) if item is of level X)
  1528. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1529. %T the last tag of the item (ignore inherited tags, which come first)
  1530. %t the HH:MM time-of-day specification if one applies to the entry
  1531. %s Scheduling/Deadline information, a short string
  1532. %b show breadcrumbs, i.e., the names of the higher levels
  1533. %(expression) Eval EXPRESSION and replace the control string
  1534. by the result
  1535. All specifiers work basically like the standard `%s' of printf, but may
  1536. contain two additional characters: a question mark just after the `%'
  1537. and a whitespace/punctuation character just before the final letter.
  1538. If the first character after `%' is a question mark, the entire field
  1539. will only be included if the corresponding value applies to the current
  1540. entry. This is useful for fields which should have fixed width when
  1541. present, but zero width when absent. For example, \"%?-12t\" will
  1542. result in a 12 character time field if a time of the day is specified,
  1543. but will completely disappear in entries which do not contain a time.
  1544. If there is punctuation or whitespace character just before the
  1545. final format letter, this character will be appended to the field
  1546. value if the value is not empty. For example, the format
  1547. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1548. the category is empty, no additional colon is inserted.
  1549. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1550. which means:
  1551. - Indent the line with two space characters
  1552. - Give the category a 12 chars wide field, padded with whitespace on
  1553. the right (because of `-'). Append a colon if there is a category
  1554. (because of `:').
  1555. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1556. time, don't put in an empty field, just skip it (because of '?').
  1557. - Finally, put the scheduling information.
  1558. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1559. `org-agenda-remove-tags'.
  1560. Custom commands can set this variable in the options section."
  1561. :type '(choice
  1562. (string :tag "General format")
  1563. (list :greedy t :tag "View dependent"
  1564. (cons (const agenda) (string :tag "Format"))
  1565. (cons (const todo) (string :tag "Format"))
  1566. (cons (const tags) (string :tag "Format"))
  1567. (cons (const search) (string :tag "Format"))))
  1568. :group 'org-agenda-line-format
  1569. :version "26.1"
  1570. :package-version '(Org . "9.1"))
  1571. (defcustom org-agenda-breadcrumbs-separator "->"
  1572. "The separator of breadcrumbs in agenda lines."
  1573. :group 'org-agenda-line-format
  1574. :package-version '(Org . "9.3")
  1575. :type 'string
  1576. :safe #'stringp)
  1577. (defvar org-prefix-format-compiled nil
  1578. "The compiled prefix format and associated variables.
  1579. This is a list where first element is a list of variable bindings, and second
  1580. element is the compiled format expression. See the variable
  1581. `org-agenda-prefix-format'.")
  1582. (defcustom org-agenda-todo-keyword-format "%-1s"
  1583. "Format for the TODO keyword in agenda lines.
  1584. Set this to something like \"%-12s\" if you want all TODO keywords
  1585. to occupy a fixed space in the agenda display."
  1586. :group 'org-agenda-line-format
  1587. :type 'string)
  1588. (defcustom org-agenda-diary-sexp-prefix nil
  1589. "A regexp that matches part of a diary sexp entry
  1590. which should be treated as scheduling/deadline information in
  1591. `org-agenda'.
  1592. For example, you can use this to extract the `diary-remind-message' from
  1593. `diary-remind' entries."
  1594. :group 'org-agenda-line-format
  1595. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1596. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1597. "Text preceding timerange entries in the agenda view.
  1598. This is a list with two strings. The first applies when the range
  1599. is entirely on one day. The second applies if the range spans several days.
  1600. The strings may have two \"%d\" format specifiers which will be filled
  1601. with the sequence number of the days, and the total number of days in the
  1602. range, respectively."
  1603. :group 'org-agenda-line-format
  1604. :type '(list
  1605. (string :tag "Deadline today ")
  1606. (choice :tag "Deadline relative"
  1607. (string :tag "Format string")
  1608. (function))))
  1609. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1610. "Text preceding scheduled items in the agenda view.
  1611. This is a list with two strings. The first applies when the item is
  1612. scheduled on the current day. The second applies when it has been scheduled
  1613. previously, it may contain a %d indicating that this is the nth time that
  1614. this item is scheduled, due to automatic rescheduling of unfinished items
  1615. for the following day. So this number is one larger than the number of days
  1616. that passed since this item was scheduled first."
  1617. :group 'org-agenda-line-format
  1618. :version "24.4"
  1619. :package-version '(Org . "8.0")
  1620. :type '(list
  1621. (string :tag "Scheduled today ")
  1622. (string :tag "Scheduled previously")))
  1623. (defcustom org-agenda-inactive-leader "["
  1624. "Text preceding item pulled into the agenda by inactive time stamps.
  1625. These entries are added to the agenda when pressing \"[\"."
  1626. :group 'org-agenda-line-format
  1627. :version "24.1"
  1628. :type 'string)
  1629. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1630. "Text preceding deadline items in the agenda view.
  1631. This is a list with three strings. The first applies when the item has its
  1632. deadline on the current day. The second applies when the deadline is in the
  1633. future, the third one when it is in the past. The strings may contain %d
  1634. to capture the number of days."
  1635. :group 'org-agenda-line-format
  1636. :version "24.4"
  1637. :package-version '(Org . "8.0")
  1638. :type '(list
  1639. (string :tag "Deadline today ")
  1640. (string :tag "Deadline in the future ")
  1641. (string :tag "Deadline in the past ")))
  1642. (defcustom org-agenda-remove-times-when-in-prefix t
  1643. "Non-nil means remove duplicate time specifications in agenda items.
  1644. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1645. time-of-day specification in a headline or diary entry is extracted and
  1646. placed into the prefix. If this option is non-nil, the original specification
  1647. \(a timestamp or -range, or just a plain time(range) specification like
  1648. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1649. cluttered.
  1650. The option can be t or nil. It may also be the symbol `beg', indicating
  1651. that the time should only be removed when it is located at the beginning of
  1652. the headline/diary entry."
  1653. :group 'org-agenda-line-format
  1654. :type '(choice
  1655. (const :tag "Always" t)
  1656. (const :tag "Never" nil)
  1657. (const :tag "When at beginning of entry" beg)))
  1658. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1659. "Non-nil means remove time ranges specifications in agenda
  1660. items that span on several days."
  1661. :group 'org-agenda-line-format
  1662. :version "24.1"
  1663. :type 'boolean)
  1664. (defcustom org-agenda-default-appointment-duration nil
  1665. "Default duration for appointments that only have a starting time.
  1666. When nil, no duration is specified in such cases.
  1667. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1668. :group 'org-agenda-line-format
  1669. :type '(choice
  1670. (integer :tag "Minutes")
  1671. (const :tag "No default duration")))
  1672. (defcustom org-agenda-show-inherited-tags t
  1673. "Non-nil means show inherited tags in each agenda line.
  1674. When this option is set to `always', it takes precedence over
  1675. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1676. in every agenda.
  1677. When this option is set to t (the default), inherited tags are
  1678. shown when they are available, i.e. when the value of
  1679. `org-agenda-use-tag-inheritance' enables tag inheritance for the
  1680. given agenda type.
  1681. This can be set to a list of agenda types in which the agenda
  1682. must display the inherited tags. Available types are `todo',
  1683. `agenda' and `search'.
  1684. When set to nil, never show inherited tags in agenda lines."
  1685. :group 'org-agenda-line-format
  1686. :group 'org-agenda
  1687. :version "24.3"
  1688. :type '(choice
  1689. (const :tag "Show inherited tags when available" t)
  1690. (const :tag "Always show inherited tags" always)
  1691. (repeat :tag "Show inherited tags only in selected agenda types"
  1692. (symbol :tag "Agenda type"))))
  1693. (defcustom org-agenda-use-tag-inheritance '(todo search agenda)
  1694. "List of agenda view types where to use tag inheritance.
  1695. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1696. controlled by `org-use-tag-inheritance'. In other agenda types,
  1697. `org-use-tag-inheritance' is not used for the selection of the
  1698. agenda entries. Still, you may want the agenda to be aware of
  1699. the inherited tags anyway, e.g. for later tag filtering.
  1700. Allowed value are `todo', `search' and `agenda'.
  1701. This variable has no effect if `org-agenda-show-inherited-tags'
  1702. is set to `always'. In that case, the agenda is aware of those
  1703. tags.
  1704. The default value sets tags in every agenda type. Setting this
  1705. option to nil will speed up non-tags agenda view a lot."
  1706. :group 'org-agenda
  1707. :version "26.1"
  1708. :package-version '(Org . "9.1")
  1709. :type '(choice
  1710. (const :tag "Use tag inheritance in all agenda types" t)
  1711. (repeat :tag "Use tag inheritance in selected agenda types"
  1712. (symbol :tag "Agenda type"))))
  1713. (defcustom org-agenda-hide-tags-regexp nil
  1714. "Regular expression used to filter away specific tags in agenda views.
  1715. This means that these tags will be present, but not be shown in the agenda
  1716. line. Secondary filtering will still work on the hidden tags.
  1717. Nil means don't hide any tags."
  1718. :group 'org-agenda-line-format
  1719. :type '(choice
  1720. (const :tag "Hide none" nil)
  1721. (regexp :tag "Regexp ")))
  1722. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1723. 'org-agenda-remove-tags)
  1724. (defcustom org-agenda-remove-tags nil
  1725. "Non-nil means remove the tags from the headline copy in the agenda.
  1726. When this is the symbol `prefix', only remove tags when
  1727. `org-agenda-prefix-format' contains a `%T' specifier."
  1728. :group 'org-agenda-line-format
  1729. :type '(choice
  1730. (const :tag "Always" t)
  1731. (const :tag "Never" nil)
  1732. (const :tag "When prefix format contains %T" prefix)))
  1733. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1734. (defcustom org-agenda-tags-column 'auto
  1735. "Shift tags in agenda items to this column.
  1736. If set to `auto', tags will be automatically aligned to the right
  1737. edge of the window.
  1738. If set to a positive number, tags will be left-aligned to that
  1739. column. If set to a negative number, tags will be right-aligned
  1740. to that column. For example, -80 works well for a normal 80
  1741. character screen."
  1742. :group 'org-agenda-line-format
  1743. :type '(choice
  1744. (const :tag "Automatically align to right edge of window" auto)
  1745. (integer :tag "Specific column" -80))
  1746. :package-version '(Org . "9.1")
  1747. :version "26.1")
  1748. (defcustom org-agenda-fontify-priorities 'cookies
  1749. "Non-nil means highlight low and high priorities in agenda.
  1750. When t, the highest priority entries are bold, lowest priority italic.
  1751. However, settings in `org-priority-faces' will overrule these faces.
  1752. When this variable is the symbol `cookies', only fontify the
  1753. cookies, not the entire task.
  1754. This may also be an association list of priority faces, whose
  1755. keys are the character values of `org-priority-highest',
  1756. `org-priority-default', and `org-priority-lowest' (the default values
  1757. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1758. color as a string, or a list like `(:background \"Red\")'.
  1759. If it is a color, the variable `org-faces-easy-properties'
  1760. determines if it is a foreground or a background color."
  1761. :group 'org-agenda-line-format
  1762. :type '(choice
  1763. (const :tag "Never" nil)
  1764. (const :tag "Defaults" t)
  1765. (const :tag "Cookies only" cookies)
  1766. (repeat :tag "Specify"
  1767. (list (character :tag "Priority" :value ?A)
  1768. (choice :tag "Face "
  1769. (string :tag "Color")
  1770. (sexp :tag "Face"))))))
  1771. (defcustom org-agenda-day-face-function nil
  1772. "Function called to determine what face should be used to display a day.
  1773. The only argument passed to that function is the day. It should
  1774. returns a face, or nil if does not want to specify a face and let
  1775. the normal rules apply."
  1776. :group 'org-agenda-line-format
  1777. :version "24.1"
  1778. :type '(choice (const nil) (function)))
  1779. (defcustom org-agenda-category-icon-alist nil
  1780. "Alist of category icon to be displayed in agenda views.
  1781. Each entry should have the following format:
  1782. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1783. Where CATEGORY-REGEXP is a regexp matching the categories where
  1784. the icon should be displayed.
  1785. FILE-OR-DATA either a file path or a string containing image data.
  1786. The other fields can be omitted safely if not needed:
  1787. TYPE indicates the image type.
  1788. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1789. image data.
  1790. PROPS are additional image attributes to assign to the image,
  1791. like, e.g. `:ascent center'.
  1792. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1793. If you want to set the display properties yourself, just put a
  1794. list as second element:
  1795. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1796. For example, to display a 16px horizontal space for Emacs
  1797. category, you can use:
  1798. (\"Emacs\" \\='(space . (:width (16))))"
  1799. :group 'org-agenda-line-format
  1800. :version "24.1"
  1801. :type '(alist :key-type (regexp :tag "Regexp matching category")
  1802. :value-type (choice (list :tag "Icon"
  1803. (string :tag "File or data")
  1804. (symbol :tag "Type")
  1805. (boolean :tag "Data?")
  1806. (repeat :tag "Extra image properties" :inline t sexp))
  1807. (list :tag "Display properties" sexp))))
  1808. (defgroup org-agenda-column-view nil
  1809. "Options concerning column view in the agenda."
  1810. :tag "Org Agenda Column View"
  1811. :group 'org-agenda)
  1812. (defcustom org-agenda-view-columns-initially nil
  1813. "When non-nil, switch to columns view right after creating the agenda."
  1814. :group 'org-agenda-column-view
  1815. :type 'boolean
  1816. :version "26.1"
  1817. :package-version '(Org . "9.0")
  1818. :safe #'booleanp)
  1819. (defcustom org-agenda-columns-show-summaries t
  1820. "Non-nil means show summaries for columns displayed in the agenda view."
  1821. :group 'org-agenda-column-view
  1822. :type 'boolean)
  1823. (defcustom org-agenda-columns-compute-summary-properties t
  1824. "Non-nil means recompute all summary properties before column view.
  1825. When column view in the agenda is listing properties that have a summary
  1826. operator, it can go to all relevant buffers and recompute the summaries
  1827. there. This can mean overhead for the agenda column view, but is necessary
  1828. to have thing up to date.
  1829. As a special case, a CLOCKSUM property also makes sure that the clock
  1830. computations are current."
  1831. :group 'org-agenda-column-view
  1832. :type 'boolean)
  1833. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1834. "Non-nil means the duration of an appointment will add to day effort.
  1835. The property to which appointment durations will be added is the one given
  1836. in the option `org-effort-property'. If an appointment does not have
  1837. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1838. is not set, an appointment without end time will not contribute to the time
  1839. estimate."
  1840. :group 'org-agenda-column-view
  1841. :type 'boolean)
  1842. (defcustom org-agenda-auto-exclude-function nil
  1843. "A function called with a tag to decide if it is filtered on \
  1844. \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
  1845. The sole argument to the function, which is called once for each
  1846. possible tag, is a string giving the name of the tag. The
  1847. function should return either nil if the tag should be included
  1848. as normal, \"-<TAG>\" to exclude the tag, or \"+<TAG>\" to exclude
  1849. lines not carrying this tag.
  1850. Note that for the purpose of tag filtering, only the lower-case version of
  1851. all tags will be considered, so that this function will only ever see
  1852. the lower-case version of all tags."
  1853. :group 'org-agenda
  1854. :type '(choice (const nil) (function)))
  1855. (defcustom org-agenda-bulk-custom-functions nil
  1856. "Alist of characters and custom functions for bulk actions.
  1857. For example, this makes those two functions available:
  1858. (setq org-agenda-bulk-custom-functions
  1859. \\='((?R set-category)
  1860. (?C bulk-cut)))
  1861. With selected entries in an agenda buffer, `B R' will call
  1862. the custom function `set-category' on the selected entries.
  1863. Note that functions in this alist don't need to be quoted.
  1864. You can also specify a function which collects arguments to be
  1865. used for each call to your bulk custom function. The argument
  1866. collecting function will be run once and should return a list of
  1867. arguments to pass to the bulk function. For example:
  1868. (setq org-agenda-bulk-custom-functions
  1869. \\='((?R set-category get-category)))
  1870. Now, `B R' will call the custom `get-category' which would prompt
  1871. the user once for a category. That category is then passed as an
  1872. argument to `set-category' for each entry it's called against."
  1873. :type
  1874. '(alist :key-type character
  1875. :value-type
  1876. (group (function :tag "Bulk Custom Function")
  1877. (choice (function :tag "Bulk Custom Argument Function")
  1878. (const :tag "No Bulk Custom Argument Function" nil))))
  1879. :package-version '(Org . "9.5")
  1880. :group 'org-agenda)
  1881. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1882. "Execute BODY with point at location given by `org-hd-marker' property.
  1883. If STRING is non-nil, the text property will be fetched from position 0
  1884. in that string. If STRING is nil, it will be fetched from the beginning
  1885. of the current line."
  1886. (declare (debug t) (indent 1))
  1887. (org-with-gensyms (marker)
  1888. `(let ((,marker (get-text-property (if ,string 0 (line-beginning-position))
  1889. 'org-hd-marker ,string)))
  1890. (with-current-buffer (marker-buffer ,marker)
  1891. (save-excursion
  1892. (goto-char ,marker)
  1893. ,@body)))))
  1894. (defun org-add-agenda-custom-command (entry)
  1895. "Replace or add a command in `org-agenda-custom-commands'.
  1896. This is mostly for hacking and trying a new command - once the command
  1897. works you probably want to add it to `org-agenda-custom-commands' for good."
  1898. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1899. (if ass
  1900. (setcdr ass (cdr entry))
  1901. (push entry org-agenda-custom-commands))))
  1902. (defmacro org-agenda--insert-overriding-header (default)
  1903. "Insert header into agenda view.
  1904. The inserted header depends on `org-agenda-overriding-header'.
  1905. If the empty string, don't insert a header. If any other string,
  1906. insert it as a header. If nil, insert DEFAULT, which should
  1907. evaluate to a string. If a function, call it and insert the
  1908. string that it returns."
  1909. (declare (debug (form)) (indent defun))
  1910. `(cond
  1911. ((not org-agenda-overriding-header) (insert ,default))
  1912. ((equal org-agenda-overriding-header "") nil)
  1913. ((stringp org-agenda-overriding-header)
  1914. (insert (propertize org-agenda-overriding-header
  1915. 'face 'org-agenda-structure)
  1916. "\n"))
  1917. ((functionp org-agenda-overriding-header)
  1918. (insert (funcall org-agenda-overriding-header)))
  1919. (t (user-error "Invalid value for `org-agenda-overriding-header': %S"
  1920. org-agenda-overriding-header))))
  1921. ;;; Define the org-agenda-mode
  1922. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1923. (defvar org-agenda-mode-map (make-sparse-keymap)
  1924. "Keymap for `org-agenda-mode'.")
  1925. (org-remap org-agenda-mode-map 'move-end-of-line 'org-agenda-end-of-line)
  1926. (defvar org-agenda-menu) ; defined later in this file.
  1927. (defvar org-agenda-restrict nil
  1928. "Non-nil means agenda restriction is active.
  1929. This is an internal flag indicating either temporary or extended
  1930. agenda restriction. Specifically, it is set to t if the agenda
  1931. is restricted to an entire file, and is set to the corresponding
  1932. buffer if the agenda is restricted to a part of a file, e.g. a
  1933. region or a substree. In the latter case,
  1934. `org-agenda-restrict-begin' and `org-agenda-restrict-end' are set
  1935. to the beginning and the end of the part.
  1936. See also `org-agenda-set-restriction-lock'.")
  1937. (defvar org-agenda-follow-mode nil)
  1938. (defvar org-agenda-entry-text-mode nil)
  1939. (defvar org-agenda-clockreport-mode nil)
  1940. (defvar org-agenda-show-log nil
  1941. "When non-nil, show the log in the agenda.
  1942. Do not set this directly; instead use
  1943. `org-agenda-start-with-log-mode', which see.")
  1944. (defvar org-agenda-redo-command nil)
  1945. (defvar org-agenda-query-string nil)
  1946. (defvar org-agenda-mode-hook nil
  1947. "Hook run after `org-agenda-mode' is turned on.
  1948. The buffer is still writable when this hook is called.")
  1949. (defvar org-agenda-type nil)
  1950. (defvar org-agenda-force-single-file nil)
  1951. (defvar org-agenda-bulk-marked-entries nil
  1952. "List of markers that refer to marked entries in the agenda.")
  1953. (defvar org-agenda-current-date nil
  1954. "Active date when building the agenda.")
  1955. ;;; Multiple agenda buffers support
  1956. (defcustom org-agenda-sticky nil
  1957. "Non-nil means agenda q key will bury agenda buffers.
  1958. Agenda commands will then show existing buffer instead of generating new ones.
  1959. When nil, `q' will kill the single agenda buffer."
  1960. :group 'org-agenda
  1961. :version "24.3"
  1962. :type 'boolean)
  1963. ;;;###autoload
  1964. (defun org-toggle-sticky-agenda (&optional arg)
  1965. "Toggle `org-agenda-sticky'."
  1966. (interactive "P")
  1967. (let ((new-value (if arg
  1968. (> (prefix-numeric-value arg) 0)
  1969. (not org-agenda-sticky))))
  1970. (if (equal new-value org-agenda-sticky)
  1971. (and (called-interactively-p 'interactive)
  1972. (message "Sticky agenda was already %s"
  1973. (if org-agenda-sticky "enabled" "disabled")))
  1974. (setq org-agenda-sticky new-value)
  1975. (org-agenda-kill-all-agenda-buffers)
  1976. (and (called-interactively-p 'interactive)
  1977. (message "Sticky agenda %s"
  1978. (if org-agenda-sticky "enabled" "disabled"))))))
  1979. (defvar org-agenda-buffer nil
  1980. "Agenda buffer currently being generated.")
  1981. (defvar org-agenda-last-prefix-arg nil)
  1982. (defvar org-agenda-this-buffer-name nil)
  1983. (defvar org-agenda-doing-sticky-redo nil)
  1984. (defvar org-agenda-this-buffer-is-sticky nil)
  1985. (defvar org-agenda-last-indirect-buffer nil
  1986. "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
  1987. (defconst org-agenda-local-vars
  1988. '(org-agenda-this-buffer-name
  1989. org-agenda-undo-list
  1990. org-agenda-pending-undo-list
  1991. org-agenda-follow-mode
  1992. org-agenda-entry-text-mode
  1993. org-agenda-clockreport-mode
  1994. org-agenda-show-log
  1995. org-agenda-redo-command
  1996. org-agenda-query-string
  1997. org-agenda-type
  1998. org-agenda-bulk-marked-entries
  1999. org-agenda-undo-has-started-in
  2000. org-agenda-info
  2001. org-agenda-pre-window-conf
  2002. org-agenda-columns-active
  2003. org-agenda-tag-filter
  2004. org-agenda-category-filter
  2005. org-agenda-top-headline-filter
  2006. org-agenda-regexp-filter
  2007. org-agenda-effort-filter
  2008. org-agenda-filters-preset
  2009. org-agenda-markers
  2010. org-agenda-last-search-view-search-was-boolean
  2011. org-agenda-last-indirect-buffer
  2012. org-agenda-filtered-by-category
  2013. org-agenda-filter-form
  2014. org-agenda-cycle-counter
  2015. org-agenda-last-prefix-arg)
  2016. "Variables that must be local in agenda buffers to allow multiple buffers.")
  2017. (defun org-agenda-mode ()
  2018. "Mode for time-sorted view on action items in Org files.
  2019. The following commands are available:
  2020. \\{org-agenda-mode-map}"
  2021. (interactive)
  2022. (ignore-errors (require 'face-remap))
  2023. (let ((agenda-local-vars-to-keep
  2024. '(text-scale-mode-amount
  2025. text-scale-mode
  2026. text-scale-mode-lighter
  2027. face-remapping-alist))
  2028. (save (buffer-local-variables)))
  2029. (kill-all-local-variables)
  2030. (cl-flet ((reset-saved (var-set)
  2031. "Reset variables in VAR-SET to possibly stored value in SAVE."
  2032. (dolist (elem save)
  2033. (pcase elem
  2034. (`(,var . ,val) ;ignore unbound variables
  2035. (when (and val (memq var var-set))
  2036. (set var val)))))))
  2037. (cond (org-agenda-doing-sticky-redo
  2038. ;; Refreshing sticky agenda-buffer
  2039. ;;
  2040. ;; Preserve the value of `org-agenda-local-vars' variables.
  2041. (mapc #'make-local-variable org-agenda-local-vars)
  2042. (reset-saved org-agenda-local-vars)
  2043. (setq-local org-agenda-this-buffer-is-sticky t))
  2044. (org-agenda-sticky
  2045. ;; Creating a sticky Agenda buffer for the first time
  2046. (mapc #'make-local-variable org-agenda-local-vars)
  2047. (setq-local org-agenda-this-buffer-is-sticky t))
  2048. (t
  2049. ;; Creating a non-sticky agenda buffer
  2050. (setq-local org-agenda-this-buffer-is-sticky nil)))
  2051. (mapc #'make-local-variable agenda-local-vars-to-keep)
  2052. (reset-saved agenda-local-vars-to-keep)))
  2053. (setq org-agenda-undo-list nil
  2054. org-agenda-pending-undo-list nil
  2055. org-agenda-bulk-marked-entries nil)
  2056. (setq major-mode 'org-agenda-mode)
  2057. ;; Keep global-font-lock-mode from turning on font-lock-mode
  2058. (setq-local font-lock-global-modes (list 'not major-mode))
  2059. (setq mode-name "Org-Agenda")
  2060. (setq indent-tabs-mode nil)
  2061. (use-local-map org-agenda-mode-map)
  2062. (when org-startup-truncated (setq truncate-lines t))
  2063. (setq-local line-move-visual nil)
  2064. (add-hook 'post-command-hook #'org-agenda-update-agenda-type nil 'local)
  2065. (add-hook 'pre-command-hook #'org-unhighlight nil 'local)
  2066. ;; Make sure properties are removed when copying text
  2067. (if (boundp 'filter-buffer-substring-functions)
  2068. (add-hook 'filter-buffer-substring-functions
  2069. (lambda (fun start end delete)
  2070. (substring-no-properties (funcall fun start end delete)))
  2071. nil t)
  2072. ;; Emacs >= 24.4.
  2073. (add-function :filter-return (local 'filter-buffer-substring-function)
  2074. #'substring-no-properties))
  2075. (unless org-agenda-keep-modes
  2076. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  2077. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  2078. org-agenda-show-log org-agenda-start-with-log-mode
  2079. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode))
  2080. (add-to-invisibility-spec '(org-filtered))
  2081. (org-fold-core-initialize `(,org-link--description-folding-spec
  2082. ,org-link--link-folding-spec))
  2083. (easy-menu-change
  2084. '("Agenda") "Agenda Files"
  2085. (append
  2086. (list
  2087. (vector
  2088. (if (get 'org-agenda-files 'org-restrict)
  2089. "Restricted to single file"
  2090. "Edit File List")
  2091. '(org-edit-agenda-file-list)
  2092. (not (get 'org-agenda-files 'org-restrict)))
  2093. "--")
  2094. (mapcar #'org-file-menu-entry (org-agenda-files))))
  2095. (org-agenda-set-mode-name)
  2096. (run-mode-hooks 'org-agenda-mode-hook))
  2097. (substitute-key-definition #'undo #'org-agenda-undo
  2098. org-agenda-mode-map global-map)
  2099. (org-defkey org-agenda-mode-map "\C-i" #'org-agenda-goto)
  2100. (org-defkey org-agenda-mode-map [(tab)] #'org-agenda-goto)
  2101. (org-defkey org-agenda-mode-map "\C-m" #'org-agenda-switch-to)
  2102. (org-defkey org-agenda-mode-map "\C-k" #'org-agenda-kill)
  2103. (org-defkey org-agenda-mode-map "\C-c\C-w" #'org-agenda-refile)
  2104. (org-defkey org-agenda-mode-map [(meta down)] #'org-agenda-drag-line-forward)
  2105. (org-defkey org-agenda-mode-map [(meta up)] #'org-agenda-drag-line-backward)
  2106. (org-defkey org-agenda-mode-map "m" #'org-agenda-bulk-mark)
  2107. (org-defkey org-agenda-mode-map "\M-m" #'org-agenda-bulk-toggle)
  2108. (org-defkey org-agenda-mode-map "*" #'org-agenda-bulk-mark-all)
  2109. (org-defkey org-agenda-mode-map "\M-*" #'org-agenda-bulk-toggle-all)
  2110. (org-defkey org-agenda-mode-map "#" #'org-agenda-dim-blocked-tasks)
  2111. (org-defkey org-agenda-mode-map "%" #'org-agenda-bulk-mark-regexp)
  2112. (org-defkey org-agenda-mode-map "u" #'org-agenda-bulk-unmark)
  2113. (org-defkey org-agenda-mode-map "U" #'org-agenda-bulk-unmark-all)
  2114. (org-defkey org-agenda-mode-map "B" #'org-agenda-bulk-action)
  2115. (org-defkey org-agenda-mode-map "k" #'org-agenda-capture)
  2116. (org-defkey org-agenda-mode-map "A" #'org-agenda-append-agenda)
  2117. (org-defkey org-agenda-mode-map "\C-c\C-x!" #'org-reload)
  2118. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" #'org-agenda-archive-default)
  2119. (org-defkey org-agenda-mode-map "\C-c\C-xa" #'org-agenda-toggle-archive-tag)
  2120. (org-defkey org-agenda-mode-map "\C-c\C-xA" #'org-agenda-archive-to-archive-sibling)
  2121. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" #'org-agenda-archive)
  2122. (org-defkey org-agenda-mode-map "\C-c$" #'org-agenda-archive)
  2123. (org-defkey org-agenda-mode-map "$" #'org-agenda-archive)
  2124. (org-defkey org-agenda-mode-map "\C-c\C-o" #'org-agenda-open-link)
  2125. (org-defkey org-agenda-mode-map " " #'org-agenda-show-and-scroll-up)
  2126. (org-defkey org-agenda-mode-map [backspace] #'org-agenda-show-scroll-down)
  2127. (org-defkey org-agenda-mode-map "\d" #'org-agenda-show-scroll-down)
  2128. (org-defkey org-agenda-mode-map [(control shift right)] #'org-agenda-todo-nextset)
  2129. (org-defkey org-agenda-mode-map [(control shift left)] #'org-agenda-todo-previousset)
  2130. (org-defkey org-agenda-mode-map "\C-c\C-xb" #'org-agenda-tree-to-indirect-buffer)
  2131. (org-defkey org-agenda-mode-map "o" #'delete-other-windows)
  2132. (org-defkey org-agenda-mode-map "L" #'org-agenda-recenter)
  2133. (org-defkey org-agenda-mode-map "\C-c\C-t" #'org-agenda-todo)
  2134. (org-defkey org-agenda-mode-map "t" #'org-agenda-todo)
  2135. (org-defkey org-agenda-mode-map "a" #'org-agenda-archive-default-with-confirmation)
  2136. (org-defkey org-agenda-mode-map ":" #'org-agenda-set-tags)
  2137. (org-defkey org-agenda-mode-map "\C-c\C-q" #'org-agenda-set-tags)
  2138. (org-defkey org-agenda-mode-map "." #'org-agenda-goto-today)
  2139. (org-defkey org-agenda-mode-map "j" #'org-agenda-goto-date)
  2140. (org-defkey org-agenda-mode-map "d" #'org-agenda-day-view)
  2141. (org-defkey org-agenda-mode-map "w" #'org-agenda-week-view)
  2142. (org-defkey org-agenda-mode-map "y" #'org-agenda-year-view)
  2143. (org-defkey org-agenda-mode-map "\C-c\C-z" #'org-agenda-add-note)
  2144. (org-defkey org-agenda-mode-map "z" #'org-agenda-add-note)
  2145. (org-defkey org-agenda-mode-map [(shift right)] #'org-agenda-do-date-later)
  2146. (org-defkey org-agenda-mode-map [(shift left)] #'org-agenda-do-date-earlier)
  2147. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] #'org-agenda-do-date-later)
  2148. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] #'org-agenda-do-date-earlier)
  2149. (org-defkey org-agenda-mode-map ">" #'org-agenda-date-prompt)
  2150. (org-defkey org-agenda-mode-map "\C-c\C-s" #'org-agenda-schedule)
  2151. (org-defkey org-agenda-mode-map "\C-c\C-d" #'org-agenda-deadline)
  2152. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  2153. (while l (org-defkey org-agenda-mode-map
  2154. (number-to-string (pop l)) #'digit-argument)))
  2155. (org-defkey org-agenda-mode-map "F" #'org-agenda-follow-mode)
  2156. (org-defkey org-agenda-mode-map "R" #'org-agenda-clockreport-mode)
  2157. (org-defkey org-agenda-mode-map "E" #'org-agenda-entry-text-mode)
  2158. (org-defkey org-agenda-mode-map "l" #'org-agenda-log-mode)
  2159. (org-defkey org-agenda-mode-map "v" #'org-agenda-view-mode-dispatch)
  2160. (org-defkey org-agenda-mode-map "D" #'org-agenda-toggle-diary)
  2161. (org-defkey org-agenda-mode-map "!" #'org-agenda-toggle-deadlines)
  2162. (org-defkey org-agenda-mode-map "G" #'org-agenda-toggle-time-grid)
  2163. (org-defkey org-agenda-mode-map "r" #'org-agenda-redo)
  2164. (org-defkey org-agenda-mode-map "g" #'org-agenda-redo-all)
  2165. (org-defkey org-agenda-mode-map "e" #'org-agenda-set-effort)
  2166. (org-defkey org-agenda-mode-map "\C-c\C-xe" #'org-agenda-set-effort)
  2167. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  2168. #'org-clock-modify-effort-estimate)
  2169. (org-defkey org-agenda-mode-map "\C-c\C-xp" #'org-agenda-set-property)
  2170. (org-defkey org-agenda-mode-map "q" #'org-agenda-quit)
  2171. (org-defkey org-agenda-mode-map "Q" #'org-agenda-Quit)
  2172. (org-defkey org-agenda-mode-map "x" #'org-agenda-exit)
  2173. (org-defkey org-agenda-mode-map "\C-x\C-w" #'org-agenda-write)
  2174. (org-defkey org-agenda-mode-map "\C-x\C-s" #'org-save-all-org-buffers)
  2175. (org-defkey org-agenda-mode-map "s" #'org-save-all-org-buffers)
  2176. (org-defkey org-agenda-mode-map "T" #'org-agenda-show-tags)
  2177. (org-defkey org-agenda-mode-map "n" #'org-agenda-next-line)
  2178. (org-defkey org-agenda-mode-map "p" #'org-agenda-previous-line)
  2179. (org-defkey org-agenda-mode-map "N" #'org-agenda-next-item)
  2180. (org-defkey org-agenda-mode-map "P" #'org-agenda-previous-item)
  2181. (substitute-key-definition #'next-line #'org-agenda-next-line
  2182. org-agenda-mode-map global-map)
  2183. (substitute-key-definition #'previous-line #'org-agenda-previous-line
  2184. org-agenda-mode-map global-map)
  2185. (org-defkey org-agenda-mode-map "\C-c\C-a" #'org-attach)
  2186. (org-defkey org-agenda-mode-map "\C-c\C-n" #'org-agenda-next-date-line)
  2187. (org-defkey org-agenda-mode-map "\C-c\C-p" #'org-agenda-previous-date-line)
  2188. (org-defkey org-agenda-mode-map "\C-c," #'org-agenda-priority)
  2189. (org-defkey org-agenda-mode-map "," #'org-agenda-priority)
  2190. (org-defkey org-agenda-mode-map "i" #'org-agenda-diary-entry)
  2191. (org-defkey org-agenda-mode-map "c" #'org-agenda-goto-calendar)
  2192. (org-defkey org-agenda-mode-map "C" #'org-agenda-convert-date)
  2193. (org-defkey org-agenda-mode-map "M" #'org-agenda-phases-of-moon)
  2194. (org-defkey org-agenda-mode-map "S" #'org-agenda-sunrise-sunset)
  2195. (org-defkey org-agenda-mode-map "h" #'org-agenda-holidays)
  2196. (org-defkey org-agenda-mode-map "H" #'org-agenda-holidays)
  2197. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" #'org-agenda-clock-in)
  2198. (org-defkey org-agenda-mode-map "I" #'org-agenda-clock-in)
  2199. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" #'org-agenda-clock-out)
  2200. (org-defkey org-agenda-mode-map "O" #'org-agenda-clock-out)
  2201. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" #'org-agenda-clock-cancel)
  2202. (org-defkey org-agenda-mode-map "X" #'org-agenda-clock-cancel)
  2203. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" #'org-clock-goto)
  2204. (org-defkey org-agenda-mode-map "J" #'org-agenda-clock-goto)
  2205. (org-defkey org-agenda-mode-map "+" #'org-agenda-priority-up)
  2206. (org-defkey org-agenda-mode-map "-" #'org-agenda-priority-down)
  2207. (org-defkey org-agenda-mode-map [(shift up)] #'org-agenda-priority-up)
  2208. (org-defkey org-agenda-mode-map [(shift down)] #'org-agenda-priority-down)
  2209. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] #'org-agenda-priority-up)
  2210. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] #'org-agenda-priority-down)
  2211. (org-defkey org-agenda-mode-map "f" #'org-agenda-later)
  2212. (org-defkey org-agenda-mode-map "b" #'org-agenda-earlier)
  2213. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" #'org-agenda-columns)
  2214. (org-defkey org-agenda-mode-map "\C-c\C-x>" #'org-agenda-remove-restriction-lock)
  2215. (org-defkey org-agenda-mode-map "\C-c\C-x<" #'org-agenda-set-restriction-lock-from-agenda)
  2216. (org-defkey org-agenda-mode-map "[" #'org-agenda-manipulate-query-add)
  2217. (org-defkey org-agenda-mode-map "]" #'org-agenda-manipulate-query-subtract)
  2218. (org-defkey org-agenda-mode-map "{" #'org-agenda-manipulate-query-add-re)
  2219. (org-defkey org-agenda-mode-map "}" #'org-agenda-manipulate-query-subtract-re)
  2220. (org-defkey org-agenda-mode-map "\\" #'org-agenda-filter-by-tag)
  2221. (org-defkey org-agenda-mode-map "_" #'org-agenda-filter-by-effort)
  2222. (org-defkey org-agenda-mode-map "=" #'org-agenda-filter-by-regexp)
  2223. (org-defkey org-agenda-mode-map "/" #'org-agenda-filter)
  2224. (org-defkey org-agenda-mode-map "|" #'org-agenda-filter-remove-all)
  2225. (org-defkey org-agenda-mode-map "~" #'org-agenda-limit-interactively)
  2226. (org-defkey org-agenda-mode-map "<" #'org-agenda-filter-by-category)
  2227. (org-defkey org-agenda-mode-map "^" #'org-agenda-filter-by-top-headline)
  2228. (org-defkey org-agenda-mode-map ";" #'org-timer-set-timer)
  2229. (org-defkey org-agenda-mode-map "\C-c\C-x_" #'org-timer-stop)
  2230. (org-defkey org-agenda-mode-map "?" #'org-agenda-show-the-flagging-note)
  2231. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" #'org-mobile-pull)
  2232. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" #'org-mobile-push)
  2233. (org-defkey org-agenda-mode-map "\C-c\C-xI" #'org-info-find-node)
  2234. (org-defkey org-agenda-mode-map [mouse-2] #'org-agenda-goto-mouse)
  2235. (org-defkey org-agenda-mode-map [mouse-3] #'org-agenda-show-mouse)
  2236. (org-defkey org-agenda-mode-map [remap forward-paragraph] #'org-agenda-forward-block)
  2237. (org-defkey org-agenda-mode-map [remap backward-paragraph] #'org-agenda-backward-block)
  2238. (org-defkey org-agenda-mode-map "\C-c\C-c" #'org-agenda-ctrl-c-ctrl-c)
  2239. (when org-agenda-mouse-1-follows-link
  2240. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2241. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu."
  2242. '("Agenda"
  2243. ("Agenda Files")
  2244. "--"
  2245. ("Agenda Dates"
  2246. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda)]
  2247. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2248. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2249. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2250. "--"
  2251. ("View"
  2252. ["Day View" org-agenda-day-view
  2253. :active (org-agenda-check-type nil 'agenda)
  2254. :style radio :selected (eq org-agenda-current-span 'day)
  2255. :keys "v d (or just d)"]
  2256. ["Week View" org-agenda-week-view
  2257. :active (org-agenda-check-type nil 'agenda)
  2258. :style radio :selected (eq org-agenda-current-span 'week)
  2259. :keys "v w"]
  2260. ["Fortnight View" org-agenda-fortnight-view
  2261. :active (org-agenda-check-type nil 'agenda)
  2262. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2263. :keys "v t"]
  2264. ["Month View" org-agenda-month-view
  2265. :active (org-agenda-check-type nil 'agenda)
  2266. :style radio :selected (eq org-agenda-current-span 'month)
  2267. :keys "v m"]
  2268. ["Year View" org-agenda-year-view
  2269. :active (org-agenda-check-type nil 'agenda)
  2270. :style radio :selected (eq org-agenda-current-span 'year)
  2271. :keys "v y"]
  2272. "--"
  2273. ["Include Diary" org-agenda-toggle-diary
  2274. :style toggle :selected org-agenda-include-diary
  2275. :active (org-agenda-check-type nil 'agenda)]
  2276. ["Include Deadlines" org-agenda-toggle-deadlines
  2277. :style toggle :selected org-agenda-include-deadlines
  2278. :active (org-agenda-check-type nil 'agenda)]
  2279. ["Use Time Grid" org-agenda-toggle-time-grid
  2280. :style toggle :selected org-agenda-use-time-grid
  2281. :active (org-agenda-check-type nil 'agenda)]
  2282. "--"
  2283. ["Show clock report" org-agenda-clockreport-mode
  2284. :style toggle :selected org-agenda-clockreport-mode
  2285. :active (org-agenda-check-type nil 'agenda)]
  2286. ["Show some entry text" org-agenda-entry-text-mode
  2287. :style toggle :selected org-agenda-entry-text-mode
  2288. :active t]
  2289. "--"
  2290. ["Show Logbook entries" org-agenda-log-mode
  2291. :style toggle :selected org-agenda-show-log
  2292. :active (org-agenda-check-type nil 'agenda)
  2293. :keys "v l (or just l)"]
  2294. ["Include archived trees" org-agenda-archives-mode
  2295. :style toggle :selected org-agenda-archives-mode :active t
  2296. :keys "v a"]
  2297. ["Include archive files" (org-agenda-archives-mode t)
  2298. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2299. :keys "v A"]
  2300. "--"
  2301. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2302. ("Filter current view"
  2303. ["with generic interface" org-agenda-filter t]
  2304. "--"
  2305. ["by category at cursor" org-agenda-filter-by-category t]
  2306. ["by tag" org-agenda-filter-by-tag t]
  2307. ["by effort" org-agenda-filter-by-effort t]
  2308. ["by regexp" org-agenda-filter-by-regexp t]
  2309. ["by top-level headline" org-agenda-filter-by-top-headline t]
  2310. "--"
  2311. ["Remove all filtering" org-agenda-filter-remove-all t]
  2312. "--"
  2313. ["limit" org-agenda-limit-interactively t])
  2314. ["Rebuild buffer" org-agenda-redo t]
  2315. ["Write view to file" org-agenda-write t]
  2316. ["Save all Org buffers" org-save-all-org-buffers t]
  2317. "--"
  2318. ["Show original entry" org-agenda-show t]
  2319. ["Go To (other window)" org-agenda-goto t]
  2320. ["Go To (this window)" org-agenda-switch-to t]
  2321. ["Capture with cursor date" org-agenda-capture t]
  2322. ["Follow Mode" org-agenda-follow-mode
  2323. :style toggle :selected org-agenda-follow-mode :active t]
  2324. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2325. "--"
  2326. ("TODO"
  2327. ["Cycle TODO" org-agenda-todo t]
  2328. ["Next TODO set" org-agenda-todo-nextset t]
  2329. ["Previous TODO set" org-agenda-todo-previousset t]
  2330. ["Add note" org-agenda-add-note t])
  2331. ("Archive/Refile/Delete"
  2332. ["Archive default" org-agenda-archive-default t]
  2333. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2334. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2335. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2336. ["Archive subtree" org-agenda-archive t]
  2337. "--"
  2338. ["Refile" org-agenda-refile t]
  2339. "--"
  2340. ["Delete subtree" org-agenda-kill t])
  2341. ("Bulk action"
  2342. ["Mark entry" org-agenda-bulk-mark t]
  2343. ["Mark all" org-agenda-bulk-mark-all t]
  2344. ["Unmark entry" org-agenda-bulk-unmark t]
  2345. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2346. ["Toggle mark" org-agenda-bulk-toggle t]
  2347. ["Toggle all" org-agenda-bulk-toggle-all t]
  2348. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2349. ["Act on all marked" org-agenda-bulk-action t]
  2350. "--"
  2351. ("Tags and Properties"
  2352. ["Show all Tags" org-agenda-show-tags t]
  2353. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2354. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2355. "--"
  2356. ["Column View" org-columns t])
  2357. ("Deadline/Schedule"
  2358. ["Schedule" org-agenda-schedule t]
  2359. ["Set Deadline" org-agenda-deadline t]
  2360. "--"
  2361. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda)]
  2362. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda)]
  2363. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u S-right"]
  2364. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u S-left"]
  2365. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-right"]
  2366. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-left"]
  2367. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda)])
  2368. ("Clock and Effort"
  2369. ["Clock in" org-agenda-clock-in t]
  2370. ["Clock out" org-agenda-clock-out t]
  2371. ["Clock cancel" org-agenda-clock-cancel t]
  2372. ["Goto running clock" org-clock-goto t]
  2373. "--"
  2374. ["Set Effort" org-agenda-set-effort t]
  2375. ["Change clocked effort" org-clock-modify-effort-estimate
  2376. (org-clock-is-active)])
  2377. ("Priority"
  2378. ["Set Priority" org-agenda-priority t]
  2379. ["Increase Priority" org-agenda-priority-up t]
  2380. ["Decrease Priority" org-agenda-priority-down t]
  2381. ["Show Priority" org-priority-show t])
  2382. ("Calendar/Diary"
  2383. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda)]
  2384. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda)]
  2385. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda)]
  2386. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda)]
  2387. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda)]
  2388. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda)]
  2389. "--"
  2390. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2391. "--"
  2392. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2393. "--"
  2394. ("MobileOrg"
  2395. ["Push Files and Views" org-mobile-push t]
  2396. ["Get Captured and Flagged" org-mobile-pull t]
  2397. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "\\[org-agenda] ?"]
  2398. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2399. "--"
  2400. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2401. "--"
  2402. ["Quit" org-agenda-quit t]
  2403. ["Exit and Release Buffers" org-agenda-exit t]
  2404. ))
  2405. ;;; Agenda undo
  2406. (defvar org-agenda-allow-remote-undo t
  2407. "Non-nil means allow remote undo from the agenda buffer.")
  2408. (defvar org-agenda-undo-has-started-in nil
  2409. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2410. (defun org-agenda-undo ()
  2411. "Undo a remote editing step in the agenda.
  2412. This undoes changes both in the agenda buffer and in the remote buffer
  2413. that have been changed along."
  2414. (interactive)
  2415. (or org-agenda-allow-remote-undo
  2416. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2417. (when (not (eq this-command last-command))
  2418. (setq org-agenda-undo-has-started-in nil
  2419. org-agenda-pending-undo-list org-agenda-undo-list))
  2420. (when (not org-agenda-pending-undo-list)
  2421. (user-error "No further undo information"))
  2422. (let* ((entry (pop org-agenda-pending-undo-list))
  2423. buf line cmd rembuf)
  2424. (setq cmd (pop entry) line (pop entry))
  2425. (setq rembuf (nth 2 entry))
  2426. (org-with-remote-undo rembuf
  2427. (while (bufferp (setq buf (pop entry)))
  2428. (when (pop entry)
  2429. (with-current-buffer buf
  2430. (let (;; (last-undo-buffer buf)
  2431. (inhibit-read-only t))
  2432. (unless (memq buf org-agenda-undo-has-started-in)
  2433. (push buf org-agenda-undo-has-started-in)
  2434. (make-local-variable 'pending-undo-list)
  2435. (undo-start))
  2436. (while (and pending-undo-list
  2437. (listp pending-undo-list)
  2438. (not (car pending-undo-list)))
  2439. (pop pending-undo-list))
  2440. (undo-more 1))))))
  2441. (org-goto-line line)
  2442. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2443. (defun org-verify-change-for-undo (l1 l2)
  2444. "Verify that a real change occurred between the undo lists L1 and L2."
  2445. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2446. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2447. (not (eq l1 l2)))
  2448. ;;; Agenda dispatch
  2449. (defvar org-agenda-restrict-begin (make-marker)
  2450. "Internal variable used to mark the restriction beginning.
  2451. It is only relevant when `org-agenda-restrict' is a buffer.")
  2452. (defvar org-agenda-restrict-end (make-marker)
  2453. "Internal variable used to mark the restriction end.
  2454. It is only relevant when `org-agenda-restrict' is a buffer.")
  2455. (defvar org-agenda-overriding-restriction nil
  2456. "Non-nil means extended agenda restriction is active.
  2457. This is an internal flag set by `org-agenda-set-restriction-lock'.")
  2458. (defcustom org-agenda-custom-commands-contexts nil
  2459. "Alist of custom agenda keys and contextual rules.
  2460. For example, if you have a custom agenda command \"p\" and you
  2461. want this command to be accessible only from plain text files,
  2462. use this:
  2463. (setq org-agenda-custom-commands-contexts
  2464. \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\")))))
  2465. Here are the available contexts definitions:
  2466. in-file: command displayed only in matching files
  2467. in-mode: command displayed only in matching modes
  2468. not-in-file: command not displayed in matching files
  2469. not-in-mode: command not displayed in matching modes
  2470. in-buffer: command displayed only in matching buffers
  2471. not-in-buffer: command not displayed in matching buffers
  2472. [function]: a custom function taking no argument
  2473. If you define several checks, the agenda command will be
  2474. accessible if there is at least one valid check.
  2475. You can also bind a key to another agenda custom command
  2476. depending on contextual rules.
  2477. (setq org-agenda-custom-commands-contexts
  2478. \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\")))))
  2479. Here it means: in .txt files, use \"p\" as the key for the
  2480. agenda command otherwise associated with \"q\". (The command
  2481. originally associated with \"q\" is not displayed to avoid
  2482. duplicates.)"
  2483. :version "24.3"
  2484. :group 'org-agenda-custom-commands
  2485. :type '(repeat (list :tag "Rule"
  2486. (string :tag " Agenda key")
  2487. (string :tag "Replace by command")
  2488. (repeat :tag "Available when"
  2489. (choice
  2490. (cons :tag "Condition"
  2491. (choice
  2492. (const :tag "In file" in-file)
  2493. (const :tag "Not in file" not-in-file)
  2494. (const :tag "In buffer" in-buffer)
  2495. (const :tag "Not in buffer" not-in-buffer)
  2496. (const :tag "In mode" in-mode)
  2497. (const :tag "Not in mode" not-in-mode))
  2498. (regexp))
  2499. (function :tag "Custom function"))))))
  2500. (defcustom org-agenda-max-entries nil
  2501. "Maximum number of entries to display in an agenda.
  2502. This can be nil (no limit) or an integer or an alist of agenda
  2503. types with an associated number of entries to display in this
  2504. type."
  2505. :version "24.4"
  2506. :package-version '(Org . "8.0")
  2507. :group 'org-agenda-custom-commands
  2508. :type '(choice (symbol :tag "No limit" nil)
  2509. (integer :tag "Max number of entries")
  2510. (repeat
  2511. (cons (choice :tag "Agenda type"
  2512. (const agenda)
  2513. (const todo)
  2514. (const tags)
  2515. (const search))
  2516. (integer :tag "Max number of entries")))))
  2517. (defcustom org-agenda-max-todos nil
  2518. "Maximum number of TODOs to display in an agenda.
  2519. This can be nil (no limit) or an integer or an alist of agenda
  2520. types with an associated number of entries to display in this
  2521. type."
  2522. :version "24.4"
  2523. :package-version '(Org . "8.0")
  2524. :group 'org-agenda-custom-commands
  2525. :type '(choice (symbol :tag "No limit" nil)
  2526. (integer :tag "Max number of TODOs")
  2527. (repeat
  2528. (cons (choice :tag "Agenda type"
  2529. (const agenda)
  2530. (const todo)
  2531. (const tags)
  2532. (const search))
  2533. (integer :tag "Max number of TODOs")))))
  2534. (defcustom org-agenda-max-tags nil
  2535. "Maximum number of tagged entries to display in an agenda.
  2536. This can be nil (no limit) or an integer or an alist of agenda
  2537. types with an associated number of entries to display in this
  2538. type."
  2539. :version "24.4"
  2540. :package-version '(Org . "8.0")
  2541. :group 'org-agenda-custom-commands
  2542. :type '(choice (symbol :tag "No limit" nil)
  2543. (integer :tag "Max number of tagged entries")
  2544. (repeat
  2545. (cons (choice :tag "Agenda type"
  2546. (const agenda)
  2547. (const todo)
  2548. (const tags)
  2549. (const search))
  2550. (integer :tag "Max number of tagged entries")))))
  2551. (defcustom org-agenda-max-effort nil
  2552. "Maximum cumulated effort duration for the agenda.
  2553. This can be nil (no limit) or a number of minutes (as an integer)
  2554. or an alist of agenda types with an associated number of minutes
  2555. to limit entries to in this type."
  2556. :version "24.4"
  2557. :package-version '(Org . "8.0")
  2558. :group 'org-agenda-custom-commands
  2559. :type '(choice (symbol :tag "No limit" nil)
  2560. (integer :tag "Max number of minutes")
  2561. (repeat
  2562. (cons (choice :tag "Agenda type"
  2563. (const agenda)
  2564. (const todo)
  2565. (const tags)
  2566. (const search))
  2567. (integer :tag "Max number of minutes")))))
  2568. (defvar org-agenda-keep-restricted-file-list nil)
  2569. (defvar org-keys nil)
  2570. (defvar org-match nil)
  2571. ;;;###autoload
  2572. (defun org-agenda (&optional arg keys restriction)
  2573. "Dispatch agenda commands to collect entries to the agenda buffer.
  2574. Prompts for a command to execute. Any prefix arg will be passed
  2575. on to the selected command. The default selections are:
  2576. a Call `org-agenda-list' to display the agenda for current day or week.
  2577. t Call `org-todo-list' to display the global todo list.
  2578. T Call `org-todo-list' to display the global todo list, select only
  2579. entries with a specific TODO keyword (the user gets a prompt).
  2580. m Call `org-tags-view' to display headlines with tags matching
  2581. a condition (the user is prompted for the condition).
  2582. M Like `m', but select only TODO entries, no ordinary headlines.
  2583. e Export views to associated files.
  2584. s Search entries for keywords.
  2585. S Search entries for keywords, only with TODO keywords.
  2586. / Multi occur across all agenda files and also files listed
  2587. in `org-agenda-text-search-extra-files'.
  2588. < Restrict agenda commands to buffer, subtree, or region.
  2589. Press several times to get the desired effect.
  2590. > Remove a previous restriction.
  2591. # List \"stuck\" projects.
  2592. ! Configure what \"stuck\" means.
  2593. C Configure custom agenda commands.
  2594. More commands can be added by configuring the variable
  2595. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2596. searches can be pre-defined in this way.
  2597. If the current buffer is in Org mode and visiting a file, you can also
  2598. first press `<' once to indicate that the agenda should be temporarily
  2599. \(until the next use of `\\[org-agenda]') restricted to the current file.
  2600. Pressing `<' twice means to restrict to the current subtree or region
  2601. \(if active)."
  2602. (interactive "P")
  2603. (catch 'exit
  2604. (let* ((org-keys keys)
  2605. (prefix-descriptions nil)
  2606. (org-agenda-buffer-name org-agenda-buffer-name)
  2607. (org-agenda-window-setup (if (equal (buffer-name)
  2608. org-agenda-buffer-name)
  2609. 'current-window
  2610. org-agenda-window-setup))
  2611. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2612. (org-agenda-custom-commands
  2613. ;; normalize different versions
  2614. (delq nil
  2615. (mapcar
  2616. (lambda (x)
  2617. (cond ((stringp (cdr x))
  2618. (push x prefix-descriptions)
  2619. nil)
  2620. ((stringp (nth 1 x)) x)
  2621. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2622. (t (cons (car x) (cons "" (cdr x))))))
  2623. org-agenda-custom-commands)))
  2624. (org-agenda-custom-commands
  2625. (org-contextualize-keys
  2626. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2627. ;; (buf (current-buffer))
  2628. (bfn (buffer-file-name (buffer-base-buffer)))
  2629. entry type org-match lprops ans) ;; key
  2630. ;; Turn off restriction unless there is an overriding one,
  2631. (unless org-agenda-overriding-restriction
  2632. (unless org-agenda-keep-restricted-file-list
  2633. ;; There is a request to keep the file list in place
  2634. (put 'org-agenda-files 'org-restrict nil))
  2635. (setq org-agenda-restrict nil)
  2636. (move-marker org-agenda-restrict-begin nil)
  2637. (move-marker org-agenda-restrict-end nil))
  2638. (unless org-keys
  2639. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2640. org-keys (car ans)
  2641. restriction (cdr ans)))
  2642. ;; If we have sticky agenda buffers, set a name for the buffer,
  2643. ;; depending on the invoking keys. The user may still set this
  2644. ;; as a command option, which will overwrite what we do here.
  2645. (when org-agenda-sticky
  2646. (setq org-agenda-buffer-name
  2647. (format "*Org Agenda(%s)*" org-keys)))
  2648. ;; Establish the restriction, if any
  2649. (when (and (not org-agenda-overriding-restriction) restriction)
  2650. (put 'org-agenda-files 'org-restrict (list bfn))
  2651. (cond
  2652. ((eq restriction 'region)
  2653. (setq org-agenda-restrict (current-buffer))
  2654. (move-marker org-agenda-restrict-begin (region-beginning))
  2655. (move-marker org-agenda-restrict-end (region-end)))
  2656. ((eq restriction 'subtree)
  2657. (save-excursion
  2658. (setq org-agenda-restrict (current-buffer))
  2659. (org-back-to-heading t)
  2660. (move-marker org-agenda-restrict-begin (point))
  2661. (move-marker org-agenda-restrict-end
  2662. (progn (org-end-of-subtree t)))))
  2663. ((eq restriction 'buffer)
  2664. (if (not (buffer-narrowed-p))
  2665. (setq org-agenda-restrict t)
  2666. (setq org-agenda-restrict (current-buffer))
  2667. (move-marker org-agenda-restrict-begin (point-min))
  2668. (move-marker org-agenda-restrict-end (point-max))))))
  2669. ;; For example the todo list should not need it (but does...)
  2670. (cond
  2671. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2672. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2673. (progn
  2674. ;; FIXME: Is (nth 3 entry) supposed to have access (via dynvars)
  2675. ;; to some of the local variables? There's no doc about
  2676. ;; that for `org-agenda-custom-commands'.
  2677. (setq type (nth 2 entry) org-match (eval (nth 3 entry) t)
  2678. lprops (nth 4 entry))
  2679. (when org-agenda-sticky
  2680. (setq org-agenda-buffer-name
  2681. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2682. (format "*Org Agenda(%s)*" org-keys))))
  2683. (cl-progv
  2684. (mapcar #'car lprops)
  2685. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  2686. (pcase type
  2687. (`agenda
  2688. (org-agenda-list arg))
  2689. (`agenda*
  2690. (org-agenda-list arg nil nil t))
  2691. (`alltodo
  2692. (org-todo-list arg))
  2693. (`search
  2694. (org-search-view arg org-match nil))
  2695. (`stuck
  2696. (org-agenda-list-stuck-projects arg))
  2697. (`tags
  2698. (org-tags-view arg org-match))
  2699. (`tags-todo
  2700. (org-tags-view '(4) org-match))
  2701. (`todo
  2702. (org-todo-list org-match))
  2703. (`tags-tree
  2704. (org-check-for-org-mode)
  2705. (org-match-sparse-tree arg org-match))
  2706. (`todo-tree
  2707. (org-check-for-org-mode)
  2708. (org-occur (concat "^" org-outline-regexp "[ \t]*"
  2709. (regexp-quote org-match) "\\>")))
  2710. (`occur-tree
  2711. (org-check-for-org-mode)
  2712. (org-occur org-match))
  2713. ((pred functionp)
  2714. (funcall type org-match))
  2715. ;; FIXME: Will signal an error since it's not `functionp'!
  2716. ((pred fboundp) (funcall type org-match))
  2717. (_ (user-error "Invalid custom agenda command type %s" type))))
  2718. (let ((inhibit-read-only t))
  2719. (add-text-properties (point-min) (point-max)
  2720. `(org-lprops ,lprops))))
  2721. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2722. ((equal org-keys "C")
  2723. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2724. (customize-variable 'org-agenda-custom-commands))
  2725. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2726. ((equal org-keys "s") (call-interactively 'org-search-view))
  2727. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2728. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2729. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2730. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2731. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2732. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2733. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2734. (add-hook
  2735. 'post-command-hook
  2736. (lambda ()
  2737. (unless (current-message)
  2738. (let* ((m (org-agenda-get-any-marker))
  2739. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2740. (when note
  2741. (message "FLAGGING-NOTE ([?] for more info): %s"
  2742. (org-add-props
  2743. (replace-regexp-in-string
  2744. "\\\\n" "//"
  2745. (copy-sequence note))
  2746. nil 'face 'org-warning))))))
  2747. t t))
  2748. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2749. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2750. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2751. (t (user-error "Invalid agenda key"))))))
  2752. (defvar org-agenda-multi)
  2753. (defun org-agenda-append-agenda ()
  2754. "Append another agenda view to the current one.
  2755. This function allows interactive building of block agendas.
  2756. Agenda views are separated by `org-agenda-block-separator'."
  2757. (interactive)
  2758. (unless (derived-mode-p 'org-agenda-mode)
  2759. (user-error "Can only append from within agenda buffer"))
  2760. (let ((org-agenda-multi t))
  2761. (org-agenda)
  2762. (widen)
  2763. (org-agenda-finalize)
  2764. (setq buffer-read-only t)
  2765. (org-agenda-fit-window-to-buffer)))
  2766. (defun org-agenda-normalize-custom-commands (cmds)
  2767. "Normalize custom commands CMDS."
  2768. (delq nil
  2769. (mapcar
  2770. (lambda (x)
  2771. (cond ((stringp (cdr x)) nil)
  2772. ((stringp (nth 1 x)) x)
  2773. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2774. (t (cons (car x) (cons "" (cdr x))))))
  2775. cmds)))
  2776. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2777. "The user interface for selecting an agenda command."
  2778. (catch 'exit
  2779. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2780. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2781. (region-p (org-region-active-p))
  2782. (custom org-agenda-custom-commands)
  2783. (selstring "")
  2784. restriction second-time
  2785. c entry key type match prefixes rmheader header-end custom1 desc
  2786. line lines left right n n1)
  2787. (save-window-excursion
  2788. (delete-other-windows)
  2789. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2790. (erase-buffer)
  2791. (insert (eval-when-compile
  2792. (let ((header
  2793. (copy-sequence
  2794. "Press key for an agenda command:
  2795. -------------------------------- < Buffer, subtree/region restriction
  2796. a Agenda for current week or day > Remove restriction
  2797. t List of all TODO entries e Export agenda views
  2798. m Match a TAGS/PROP/TODO query T Entries with special TODO kwd
  2799. s Search for keywords M Like m, but only TODO entries
  2800. / Multi-occur S Like s, but only TODO entries
  2801. ? Find :FLAGGED: entries C Configure custom agenda commands
  2802. * Toggle sticky agenda views # List stuck projects (!=configure)
  2803. "))
  2804. (start 0))
  2805. (while (string-match
  2806. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2807. header start)
  2808. (setq start (match-end 0))
  2809. (add-text-properties (match-beginning 2) (match-end 2)
  2810. '(face bold) header))
  2811. header)))
  2812. (setq header-end (point-marker))
  2813. (while t
  2814. (setq custom1 custom)
  2815. (when (eq rmheader t)
  2816. (org-goto-line 1)
  2817. (re-search-forward ":" nil t)
  2818. (delete-region (match-end 0) (line-end-position))
  2819. (forward-char 1)
  2820. (looking-at "-+")
  2821. (delete-region (match-end 0) (line-end-position))
  2822. (move-marker header-end (match-end 0)))
  2823. (goto-char header-end)
  2824. (delete-region (point) (point-max))
  2825. ;; Produce all the lines that describe custom commands and prefixes
  2826. (setq lines nil)
  2827. (while (setq entry (pop custom1))
  2828. (setq key (car entry) desc (nth 1 entry)
  2829. type (nth 2 entry)
  2830. match (nth 3 entry))
  2831. (if (> (length key) 1)
  2832. (cl-pushnew (string-to-char key) prefixes :test #'equal)
  2833. (setq line
  2834. (format
  2835. "%-4s%-14s"
  2836. (org-add-props (copy-sequence key)
  2837. '(face bold))
  2838. (cond
  2839. ((string-match "\\S-" desc) desc)
  2840. ((eq type 'agenda) "Agenda for current week or day")
  2841. ((eq type 'agenda*) "Appointments for current week or day")
  2842. ((eq type 'alltodo) "List of all TODO entries")
  2843. ((eq type 'search) "Word search")
  2844. ((eq type 'stuck) "List of stuck projects")
  2845. ((eq type 'todo) "TODO keyword")
  2846. ((eq type 'tags) "Tags query")
  2847. ((eq type 'tags-todo) "Tags (TODO)")
  2848. ((eq type 'tags-tree) "Tags tree")
  2849. ((eq type 'todo-tree) "TODO kwd tree")
  2850. ((eq type 'occur-tree) "Occur tree")
  2851. ((functionp type) (if (symbolp type)
  2852. (symbol-name type)
  2853. "Lambda expression"))
  2854. (t "???"))))
  2855. (cond
  2856. ((not (org-string-nw-p match)) nil)
  2857. (org-agenda-menu-show-matcher
  2858. (setq line
  2859. (concat line ": "
  2860. (cond
  2861. ((stringp match)
  2862. (propertize match 'face 'org-warning))
  2863. ((listp type)
  2864. (format "set of %d commands" (length type)))))))
  2865. (t
  2866. (org-add-props line nil 'help-echo (concat "Matcher: " match))))
  2867. (push line lines)))
  2868. (setq lines (nreverse lines))
  2869. (when prefixes
  2870. (mapc (lambda (x)
  2871. (push
  2872. (format "%s %s"
  2873. (org-add-props (char-to-string x)
  2874. nil 'face 'bold)
  2875. (or (cdr (assoc (concat selstring
  2876. (char-to-string x))
  2877. prefix-descriptions))
  2878. "Prefix key"))
  2879. lines))
  2880. prefixes))
  2881. ;; Check if we should display in two columns
  2882. (if org-agenda-menu-two-columns
  2883. (progn
  2884. (setq n (length lines)
  2885. n1 (+ (/ n 2) (mod n 2))
  2886. right (nthcdr n1 lines)
  2887. left (copy-sequence lines))
  2888. (setcdr (nthcdr (1- n1) left) nil))
  2889. (setq left lines right nil))
  2890. (while left
  2891. (insert "\n" (pop left))
  2892. (when right
  2893. (if (< (current-column) 40)
  2894. (move-to-column 40 t)
  2895. (insert " "))
  2896. (insert (pop right))))
  2897. ;; Make the window the right size
  2898. (goto-char (point-min))
  2899. (if second-time
  2900. (when (not (pos-visible-in-window-p (point-max)))
  2901. (org-fit-window-to-buffer))
  2902. (setq second-time t)
  2903. (org-fit-window-to-buffer))
  2904. ;; Hint to navigation if window too small for all information
  2905. (setq header-line-format
  2906. (when (not (pos-visible-in-window-p (point-max)))
  2907. "Use C-v, M-v, C-n or C-p to navigate."))
  2908. ;; Ask for selection
  2909. (cl-loop
  2910. do (progn
  2911. (message "Press key for agenda command%s:"
  2912. (if (or restrict-ok org-agenda-overriding-restriction)
  2913. (if org-agenda-overriding-restriction
  2914. " (restriction lock active)"
  2915. (if restriction
  2916. (format " (restricted to %s)" restriction)
  2917. " (unrestricted)"))
  2918. ""))
  2919. (setq c (read-char-exclusive)))
  2920. until (not (memq c '(14 16 22 134217846)))
  2921. do (org-scroll c))
  2922. (message "")
  2923. (cond
  2924. ((assoc (char-to-string c) custom)
  2925. (setq selstring (concat selstring (char-to-string c)))
  2926. (throw 'exit (cons selstring restriction)))
  2927. ((memq c prefixes)
  2928. (setq selstring (concat selstring (char-to-string c))
  2929. prefixes nil
  2930. rmheader (or rmheader t)
  2931. custom (delq nil (mapcar
  2932. (lambda (x)
  2933. (if (or (= (length (car x)) 1)
  2934. (/= (string-to-char (car x)) c))
  2935. nil
  2936. (cons (substring (car x) 1) (cdr x))))
  2937. custom))))
  2938. ((eq c ?*)
  2939. (call-interactively 'org-toggle-sticky-agenda)
  2940. (sit-for 2))
  2941. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2942. (message "Restriction is only possible in Org buffers")
  2943. (ding) (sit-for 1))
  2944. ((eq c ?1)
  2945. (org-agenda-remove-restriction-lock 'noupdate)
  2946. (setq restriction 'buffer))
  2947. ((eq c ?0)
  2948. (org-agenda-remove-restriction-lock 'noupdate)
  2949. (setq restriction (if region-p 'region 'subtree)))
  2950. ((eq c ?<)
  2951. (org-agenda-remove-restriction-lock 'noupdate)
  2952. (setq restriction
  2953. (cond
  2954. ((eq restriction 'buffer)
  2955. (if region-p 'region 'subtree))
  2956. ((memq restriction '(subtree region))
  2957. nil)
  2958. (t 'buffer))))
  2959. ((eq c ?>)
  2960. (org-agenda-remove-restriction-lock 'noupdate)
  2961. (setq restriction nil))
  2962. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2963. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2964. ((and (> (length selstring) 0) (eq c ?\d))
  2965. (delete-window)
  2966. (org-agenda-get-restriction-and-command prefix-descriptions))
  2967. ((equal c ?q) (user-error "Abort"))
  2968. (t (user-error "Invalid key %c" c))))))))
  2969. (defun org-agenda-fit-window-to-buffer ()
  2970. "Fit the window to the buffer size."
  2971. (and (memq org-agenda-window-setup '(reorganize-frame))
  2972. (fboundp 'fit-window-to-buffer)
  2973. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2974. (= (car org-agenda-window-frame-fractions) 1.0))
  2975. (delete-other-windows)
  2976. (org-fit-window-to-buffer
  2977. nil
  2978. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2979. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2980. (defvar org-cmd nil)
  2981. (defvar org-agenda-overriding-cmd nil)
  2982. (defvar org-agenda-overriding-arguments nil)
  2983. (defvar org-agenda-overriding-cmd-arguments nil)
  2984. (defun org-let (list &rest body) ;FIXME: So many kittens are suffering here.
  2985. (declare (indent 1) (obsolete cl-progv "2021"))
  2986. (eval (cons 'let (cons list body))))
  2987. (defun org-let2 (list1 list2 &rest body) ;FIXME: Where did our karma go?
  2988. (declare (indent 2) (obsolete cl-progv "2021"))
  2989. (eval (cons 'let (cons list1 (list (cons 'let (cons list2 body)))))))
  2990. (defun org-agenda-run-series (name series)
  2991. "Run agenda NAME as a SERIES of agenda commands."
  2992. (let* ((gprops (nth 1 series))
  2993. (gvars (mapcar #'car gprops))
  2994. (gvals (mapcar (lambda (binding) (eval (cadr binding) t)) gprops)))
  2995. (cl-progv gvars gvals (org-agenda-prepare name))
  2996. ;; We need to reset agenda markers here, because when constructing a
  2997. ;; block agenda, the individual blocks do not do that.
  2998. (org-agenda-reset-markers)
  2999. (with-no-warnings
  3000. (defvar match)) ;Used via the `eval' below.
  3001. (let* ((org-agenda-multi t)
  3002. ;; FIXME: Redo should contain lists of (FUNS . ARGS) rather
  3003. ;; than expressions, so you don't need to `quote' the args
  3004. ;; and you just need to `apply' instead of `eval' when using it.
  3005. (redo (list 'org-agenda-run-series name (list 'quote series)))
  3006. (cmds (car series))
  3007. match
  3008. org-cmd type lprops)
  3009. (while (setq org-cmd (pop cmds))
  3010. (setq type (car org-cmd))
  3011. (setq match (eval (nth 1 org-cmd) t))
  3012. (setq lprops (nth 2 org-cmd))
  3013. (let ((org-agenda-overriding-arguments
  3014. (if (eq org-agenda-overriding-cmd org-cmd)
  3015. (or org-agenda-overriding-arguments
  3016. org-agenda-overriding-cmd-arguments)))
  3017. (lvars (mapcar #'car lprops))
  3018. (lvals (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)))
  3019. (cl-progv (append gvars lvars) (append gvals lvals)
  3020. (pcase type
  3021. (`agenda
  3022. (call-interactively 'org-agenda-list))
  3023. (`agenda*
  3024. (funcall 'org-agenda-list nil nil t))
  3025. (`alltodo
  3026. (call-interactively 'org-todo-list))
  3027. (`search
  3028. (org-search-view current-prefix-arg match nil))
  3029. (`stuck
  3030. (call-interactively 'org-agenda-list-stuck-projects))
  3031. (`tags
  3032. (org-tags-view current-prefix-arg match))
  3033. (`tags-todo
  3034. (org-tags-view '(4) match))
  3035. (`todo
  3036. (org-todo-list match))
  3037. ((pred fboundp)
  3038. (funcall type match))
  3039. (_ (error "Invalid type in command series"))))))
  3040. (widen)
  3041. (let ((inhibit-read-only t))
  3042. (add-text-properties (point-min) (point-max)
  3043. `(org-series t org-series-redo-cmd ,redo)))
  3044. (setq org-agenda-redo-command redo)
  3045. (goto-char (point-min)))
  3046. (org-agenda-fit-window-to-buffer)
  3047. (cl-progv gvars gvals (org-agenda-finalize))))
  3048. (defun org-agenda--split-plist (plist)
  3049. ;; We could/should arguably use `map-keys' and `map-values'.
  3050. (let (keys vals)
  3051. (while plist
  3052. (push (pop plist) keys)
  3053. (push (pop plist) vals))
  3054. (cons (nreverse keys) (nreverse vals))))
  3055. ;;;###autoload
  3056. (defmacro org-batch-agenda (cmd-key &rest parameters)
  3057. "Run an agenda command in batch mode and send the result to STDOUT.
  3058. If CMD-KEY is a string of length 1, it is used as a key in
  3059. `org-agenda-custom-commands' and triggers this command. If it is a
  3060. longer string it is used as a tags/todo match string.
  3061. Parameters are alternating variable names and values that will be bound
  3062. before running the agenda command."
  3063. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3064. `(org--batch-agenda ,cmd-key ',vars (list ,@exps))))
  3065. (defun org--batch-agenda (cmd-key vars vals)
  3066. ;; `org-batch-agenda' is a macro because every other "parameter" is
  3067. ;; a variable name rather than an expression to evaluate. Yuck!
  3068. (cl-progv vars vals
  3069. (let (org-agenda-sticky)
  3070. (if (> (length cmd-key) 1)
  3071. (org-tags-view nil cmd-key)
  3072. (org-agenda nil cmd-key))))
  3073. (set-buffer org-agenda-buffer-name)
  3074. (princ (buffer-string)))
  3075. (defvar org-agenda-info nil)
  3076. ;;;###autoload
  3077. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  3078. "Run an agenda command in batch mode and send the result to STDOUT.
  3079. If CMD-KEY is a string of length 1, it is used as a key in
  3080. `org-agenda-custom-commands' and triggers this command. If it is a
  3081. longer string it is used as a tags/todo match string.
  3082. Parameters are alternating variable names and values that will be bound
  3083. before running the agenda command.
  3084. The output gives a line for each selected agenda item. Each
  3085. item is a list of comma-separated values, like this:
  3086. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  3087. category The category of the item
  3088. head The headline, without TODO kwd, TAGS and PRIORITY
  3089. type The type of the agenda entry, can be
  3090. todo selected in TODO match
  3091. tagsmatch selected in tags match
  3092. diary imported from diary
  3093. deadline a deadline on given date
  3094. scheduled scheduled on given date
  3095. timestamp entry has timestamp on given date
  3096. closed entry was closed on given date
  3097. upcoming-deadline warning about deadline
  3098. past-scheduled forwarded scheduled item
  3099. block entry has date block including g. date
  3100. todo The todo keyword, if any
  3101. tags All tags including inherited ones, separated by colons
  3102. date The relevant date, like 2007-2-14
  3103. time The time, like 15:00-16:50
  3104. extra String with extra planning info
  3105. priority-l The priority letter if any was given
  3106. priority-n The computed numerical priority
  3107. agenda-day The day in the agenda where this is listed"
  3108. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3109. `(org--batch-agenda-csv ,cmd-key ',vars (list ,@exps))))
  3110. (defun org--batch-agenda-csv (cmd-key vars vals)
  3111. ;; `org-batch-agenda-csv' is a macro because every other "parameter" is
  3112. ;; a variable name rather than an expression to evaluate. Yuck!
  3113. (let ((org-agenda-remove-tags t))
  3114. (cl-progv vars vals
  3115. ;; FIXME: Shouldn't this be 1 (see commit 10173ad6d610b)?
  3116. (if (> (length cmd-key) 2)
  3117. (org-tags-view nil cmd-key)
  3118. (org-agenda nil cmd-key))))
  3119. (set-buffer org-agenda-buffer-name)
  3120. (let ((lines (org-split-string (buffer-string) "\n")))
  3121. (dolist (line lines)
  3122. (when (get-text-property 0 'org-category line)
  3123. (setq org-agenda-info
  3124. (org-fix-agenda-info (text-properties-at 0 line)))
  3125. (princ
  3126. (mapconcat #'org-agenda-export-csv-mapper
  3127. '(org-category txt type todo tags date time extra
  3128. priority-letter priority agenda-day)
  3129. ","))
  3130. (princ "\n")))))
  3131. (defun org-fix-agenda-info (props)
  3132. "Make sure all properties on an agenda item have a canonical form.
  3133. This ensures the export commands can easily use it."
  3134. (let (tmp re)
  3135. (when (setq tmp (plist-get props 'tags))
  3136. (setq props (plist-put props 'tags (mapconcat #'identity tmp ":"))))
  3137. (when (setq tmp (plist-get props 'date))
  3138. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3139. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3140. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  3141. (setq tmp (calendar-date-string tmp)))
  3142. (setq props (plist-put props 'date tmp)))
  3143. (when (setq tmp (plist-get props 'day))
  3144. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3145. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3146. (setq tmp (calendar-date-string tmp)))
  3147. (setq props (plist-put props 'day tmp))
  3148. (setq props (plist-put props 'agenda-day tmp)))
  3149. (when (setq tmp (plist-get props 'txt))
  3150. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  3151. (plist-put props 'priority-letter (match-string 1 tmp))
  3152. (setq tmp (replace-match "" t t tmp)))
  3153. (when (and (setq re (plist-get props 'org-todo-regexp))
  3154. (setq re (concat "\\`\\.*" re " ?"))
  3155. (let ((case-fold-search nil)) (string-match re tmp)))
  3156. (plist-put props 'todo (match-string 1 tmp))
  3157. (setq tmp (replace-match "" t t tmp)))
  3158. (plist-put props 'txt tmp)))
  3159. props)
  3160. (defun org-agenda-export-csv-mapper (prop)
  3161. (let ((res (plist-get org-agenda-info prop)))
  3162. (setq res
  3163. (cond
  3164. ((not res) "")
  3165. ((stringp res) res)
  3166. (t (prin1-to-string res))))
  3167. (org-trim (replace-regexp-in-string "," ";" res nil t))))
  3168. ;;;###autoload
  3169. (defun org-store-agenda-views (&rest _parameters)
  3170. "Store agenda views."
  3171. (interactive)
  3172. (org--batch-store-agenda-views nil nil))
  3173. ;;;###autoload
  3174. (defmacro org-batch-store-agenda-views (&rest parameters)
  3175. "Run all custom agenda commands that have a file argument."
  3176. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3177. `(org--batch-store-agenda-views ',vars (list ,@exps))))
  3178. (defun org--batch-store-agenda-views (vars vals)
  3179. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  3180. (pop-up-frames nil)
  3181. (dir default-directory)
  3182. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  3183. (save-window-excursion
  3184. (while cmds
  3185. (setq cmd (pop cmds)
  3186. thiscmdkey (car cmd)
  3187. thiscmdcmd (cdr cmd)
  3188. match (nth 2 thiscmdcmd)
  3189. bufname (if org-agenda-sticky
  3190. (or (and (stringp match)
  3191. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  3192. (format "*Org Agenda(%s)*" thiscmdkey))
  3193. org-agenda-buffer-name)
  3194. cmd-or-set (nth 2 cmd)
  3195. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  3196. files (nth (if (listp cmd-or-set) 4 5) cmd))
  3197. (if (stringp files) (setq files (list files)))
  3198. (when files
  3199. (let* ((opts (append org-agenda-exporter-settings opts))
  3200. (vars (append (mapcar #'car opts) vars))
  3201. (vals (append (mapcar (lambda (binding) (eval (cadr binding) t))
  3202. opts)
  3203. vals)))
  3204. (cl-progv vars vals
  3205. (org-agenda nil thiscmdkey))
  3206. (set-buffer bufname)
  3207. (while files
  3208. (cl-progv vars vals
  3209. (org-agenda-write (expand-file-name (pop files) dir)
  3210. nil t bufname))))
  3211. (and (get-buffer bufname)
  3212. (kill-buffer bufname)))))))
  3213. (defvar org-agenda-current-span nil
  3214. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3215. (defun org-agenda-mark-header-line (pos)
  3216. "Mark the line at POS as an agenda structure header."
  3217. (save-excursion
  3218. (goto-char pos)
  3219. (put-text-property (line-beginning-position) (line-end-position)
  3220. 'org-agenda-structural-header t)
  3221. (when org-agenda-title-append
  3222. (put-text-property (line-beginning-position) (line-end-position)
  3223. 'org-agenda-title-append org-agenda-title-append))))
  3224. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  3225. (defvar org-agenda-write-buffer-name "Agenda View")
  3226. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  3227. "Write the current buffer (an agenda view) as a file.
  3228. Depending on the extension of the file name, plain text (.txt),
  3229. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  3230. If the extension is .ics, translate visible agenda into iCalendar
  3231. format. If the extension is .org, collect all subtrees
  3232. corresponding to the agenda entries and add them in an .org file.
  3233. With prefix argument OPEN, open the new file immediately. If
  3234. NOSETTINGS is given, do not scope the settings of
  3235. `org-agenda-exporter-settings' into the export commands. This is
  3236. used when the settings have already been scoped and we do not
  3237. wish to overrule other, higher priority settings. If
  3238. AGENDA-BUFFER-NAME is provided, use this as the buffer name for
  3239. the agenda to write."
  3240. (interactive "FWrite agenda to file: \nP")
  3241. (if (or (not (file-writable-p file))
  3242. (and (file-exists-p file)
  3243. (if (called-interactively-p 'any)
  3244. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3245. (user-error "Cannot write agenda to file %s" file))
  3246. (cl-progv
  3247. (if nosettings nil (mapcar #'car org-agenda-exporter-settings))
  3248. (if nosettings nil (mapcar (lambda (binding) (eval (cadr binding) t))
  3249. org-agenda-exporter-settings))
  3250. (save-excursion
  3251. (save-window-excursion
  3252. (let ((bs (copy-sequence (buffer-string)))
  3253. (extension (file-name-extension file))
  3254. (default-directory (file-name-directory file))
  3255. ) ;; beg content
  3256. (with-temp-buffer
  3257. (rename-buffer org-agenda-write-buffer-name t)
  3258. (set-buffer-modified-p nil)
  3259. (insert bs)
  3260. (org-agenda-remove-marked-text 'invisible 'org-filtered)
  3261. (run-hooks 'org-agenda-before-write-hook)
  3262. (cond
  3263. ((bound-and-true-p org-mobile-creating-agendas)
  3264. (org-mobile-write-agenda-for-mobile file))
  3265. ((string= "org" extension)
  3266. (let (content p m message-log-max)
  3267. (goto-char (point-min))
  3268. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3269. (goto-char p)
  3270. (setq m (get-text-property (point) 'org-hd-marker))
  3271. (when m
  3272. (push (with-current-buffer (marker-buffer m)
  3273. (goto-char m)
  3274. (org-copy-subtree 1 nil t t)
  3275. org-subtree-clip)
  3276. content)))
  3277. (find-file file)
  3278. (erase-buffer)
  3279. (dolist (s content) (org-paste-subtree 1 s))
  3280. (write-file file)
  3281. (kill-buffer (current-buffer))
  3282. (message "Org file written to %s" file)))
  3283. ((member extension '("html" "htm"))
  3284. (or (require 'htmlize nil t)
  3285. (error "Please install htmlize from https://github.com/hniksic/emacs-htmlize"))
  3286. (declare-function htmlize-buffer "htmlize" (&optional buffer))
  3287. (set-buffer (htmlize-buffer (current-buffer)))
  3288. (when org-agenda-export-html-style
  3289. ;; replace <style> section with org-agenda-export-html-style
  3290. (goto-char (point-min))
  3291. (kill-region (- (search-forward "<style") 6)
  3292. (search-forward "</style>"))
  3293. (insert org-agenda-export-html-style))
  3294. (write-file file)
  3295. (kill-buffer (current-buffer))
  3296. (message "HTML written to %s" file))
  3297. ((string= "ps" extension)
  3298. (require 'ps-print)
  3299. (ps-print-buffer-with-faces file)
  3300. (message "Postscript written to %s" file))
  3301. ((string= "pdf" extension)
  3302. (require 'ps-print)
  3303. (ps-print-buffer-with-faces
  3304. (concat (file-name-sans-extension file) ".ps"))
  3305. (call-process "ps2pdf" nil nil nil
  3306. (expand-file-name
  3307. (concat (file-name-sans-extension file) ".ps"))
  3308. (expand-file-name file))
  3309. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3310. (message "PDF written to %s" file))
  3311. ((string= "ics" extension)
  3312. (require 'ox-icalendar)
  3313. (declare-function org-icalendar-export-current-agenda
  3314. "ox-icalendar" (file))
  3315. (org-icalendar-export-current-agenda (expand-file-name file)))
  3316. (t
  3317. (let ((bs (buffer-string)))
  3318. (find-file file)
  3319. (erase-buffer)
  3320. (insert bs)
  3321. (save-buffer 0)
  3322. (kill-buffer (current-buffer))
  3323. (message "Plain text written to %s" file))))))))
  3324. (set-buffer (or agenda-bufname
  3325. ;; FIXME: I'm pretty sure called-interactively-p
  3326. ;; doesn't do what we want here!
  3327. (and (called-interactively-p 'any) (buffer-name))
  3328. org-agenda-buffer-name)))
  3329. (when open (org-open-file file)))
  3330. (defun org-agenda-remove-marked-text (property &optional value)
  3331. "Delete all text marked with VALUE of PROPERTY.
  3332. VALUE defaults to t."
  3333. (let (beg)
  3334. (setq value (or value t))
  3335. (while (setq beg (text-property-any (point-min) (point-max)
  3336. property value))
  3337. (delete-region
  3338. beg (or (next-single-property-change beg property)
  3339. (point-max))))))
  3340. (defun org-agenda-add-entry-text ()
  3341. "Add entry text to agenda lines.
  3342. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3343. entry text following headings shown in the agenda.
  3344. Drawers will be excluded, also the line with scheduling/deadline info."
  3345. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3346. (not (bound-and-true-p org-mobile-creating-agendas)))
  3347. (let (m txt)
  3348. (goto-char (point-min))
  3349. (while (not (eobp))
  3350. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3351. (beginning-of-line 2)
  3352. (setq txt (org-agenda-get-some-entry-text
  3353. m org-agenda-add-entry-text-maxlines " > "))
  3354. (end-of-line 1)
  3355. (if (string-match "\\S-" txt)
  3356. (insert "\n" txt)
  3357. (or (eobp) (forward-char 1))))))))
  3358. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3359. &rest keep)
  3360. "Extract entry text from MARKER, at most N-LINES lines.
  3361. This will ignore drawers etc, just get the text.
  3362. If INDENT is given, prefix every line with this string. If KEEP is
  3363. given, it is a list of symbols, defining stuff that should not be
  3364. removed from the entry content. Currently only `planning' is allowed here."
  3365. (let (txt drawer-re kwd-time-re ind)
  3366. (save-excursion
  3367. (with-current-buffer (marker-buffer marker)
  3368. (if (not (derived-mode-p 'org-mode))
  3369. (setq txt "")
  3370. (org-with-wide-buffer
  3371. (goto-char marker)
  3372. (end-of-line 1)
  3373. (setq txt (buffer-substring
  3374. (min (1+ (point)) (point-max))
  3375. (progn (outline-next-heading) (point)))
  3376. drawer-re org-drawer-regexp
  3377. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3378. ".*\n?"))
  3379. (with-temp-buffer
  3380. (insert txt)
  3381. (when org-agenda-add-entry-text-descriptive-links
  3382. (goto-char (point-min))
  3383. (while (org-activate-links (point-max))
  3384. (goto-char (match-end 0))))
  3385. (goto-char (point-min))
  3386. (while (re-search-forward org-link-bracket-re (point-max) t)
  3387. (set-text-properties (match-beginning 0) (match-end 0)
  3388. nil))
  3389. (goto-char (point-min))
  3390. (while (re-search-forward drawer-re nil t)
  3391. (delete-region
  3392. (match-beginning 0)
  3393. (progn (re-search-forward
  3394. "^[ \t]*:END:.*\n?" nil 'move)
  3395. (point))))
  3396. (unless (member 'planning keep)
  3397. (goto-char (point-min))
  3398. (while (re-search-forward kwd-time-re nil t)
  3399. (replace-match "")))
  3400. (goto-char (point-min))
  3401. (when org-agenda-entry-text-exclude-regexps
  3402. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3403. (while (setq re (pop re-list))
  3404. (goto-char (point-min))
  3405. (while (re-search-forward re nil t)
  3406. (replace-match "")))))
  3407. (goto-char (point-max))
  3408. (skip-chars-backward " \t\n")
  3409. (when (looking-at "[ \t\n]+\\'") (replace-match ""))
  3410. ;; find and remove min common indentation
  3411. (goto-char (point-min))
  3412. (untabify (point-min) (point-max))
  3413. (setq ind (org-current-text-indentation))
  3414. (while (not (eobp))
  3415. (unless (looking-at "[ \t]*$")
  3416. (setq ind (min ind (org-current-text-indentation))))
  3417. (beginning-of-line 2))
  3418. (goto-char (point-min))
  3419. (while (not (eobp))
  3420. (unless (looking-at "[ \t]*$")
  3421. (move-to-column ind)
  3422. (delete-region (line-beginning-position) (point)))
  3423. (beginning-of-line 2))
  3424. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3425. (goto-char (point-min))
  3426. (when indent
  3427. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3428. (replace-match indent t t)))
  3429. (goto-char (point-min))
  3430. (while (looking-at "[ \t]*\n") (replace-match ""))
  3431. (goto-char (point-max))
  3432. (when (> (org-current-line)
  3433. n-lines)
  3434. (org-goto-line (1+ n-lines))
  3435. (backward-char 1))
  3436. (setq txt (buffer-substring (point-min) (point))))))))
  3437. txt))
  3438. (defun org-check-for-org-mode ()
  3439. "Make sure current buffer is in Org mode. Error if not."
  3440. (or (derived-mode-p 'org-mode)
  3441. (error "Cannot execute Org agenda command on buffer in %s"
  3442. major-mode)))
  3443. ;;; Agenda prepare and finalize
  3444. (defvar org-agenda-multi nil) ; dynamically scoped
  3445. (defvar org-agenda-pre-window-conf nil)
  3446. (defvar org-agenda-columns-active nil)
  3447. (defvar org-agenda-name nil)
  3448. (defvar org-agenda-tag-filter nil)
  3449. (defvar org-agenda-category-filter nil)
  3450. (defvar org-agenda-regexp-filter nil)
  3451. (defvar org-agenda-effort-filter nil)
  3452. (defvar org-agenda-top-headline-filter nil)
  3453. (defvar org-agenda-represented-categories nil
  3454. "Cache for the list of all categories in the agenda.")
  3455. (defvar org-agenda-represented-tags nil
  3456. "Cache for the list of all categories in the agenda.")
  3457. (defvar org-agenda-tag-filter-preset nil
  3458. "A preset of the tags filter used for secondary agenda filtering.
  3459. This must be a list of strings, each string must be a single tag preceded
  3460. by \"+\" or \"-\".
  3461. This variable should not be set directly, but agenda custom commands can
  3462. bind it in the options section. The preset filter is a global property of
  3463. the entire agenda view. In a block agenda, it will not work reliably to
  3464. define a filter for one of the individual blocks. You need to set it in
  3465. the global options and expect it to be applied to the entire view.")
  3466. (defvar org-agenda-filters-preset nil
  3467. "Alist of filter types and associated preset of filters.
  3468. This variable is local in `org-agenda' buffers. See `org-agenda-local-vars'.")
  3469. (defconst org-agenda-filter-variables
  3470. '((category . org-agenda-category-filter)
  3471. (tag . org-agenda-tag-filter)
  3472. (effort . org-agenda-effort-filter)
  3473. (regexp . org-agenda-regexp-filter))
  3474. "Alist of filter types and associated variables.")
  3475. (defun org-agenda-filter-any ()
  3476. "Is any filter active?"
  3477. (cl-some (lambda (x)
  3478. (or (symbol-value (cdr x))
  3479. (assoc-default (car x) org-agenda-filters-preset)))
  3480. org-agenda-filter-variables))
  3481. (defvar org-agenda-category-filter-preset nil
  3482. "A preset of the category filter used for secondary agenda filtering.
  3483. This must be a list of strings, each string must be a single category
  3484. preceded by \"+\" or \"-\".
  3485. This variable should not be set directly, but agenda custom commands can
  3486. bind it in the options section. The preset filter is a global property of
  3487. the entire agenda view. In a block agenda, it will not work reliably to
  3488. define a filter for one of the individual blocks. You need to set it in
  3489. the global options and expect it to be applied to the entire view.")
  3490. (defvar org-agenda-regexp-filter-preset nil
  3491. "A preset of the regexp filter used for secondary agenda filtering.
  3492. This must be a list of strings, each string must be a single regexp
  3493. preceded by \"+\" or \"-\".
  3494. This variable should not be set directly, but agenda custom commands can
  3495. bind it in the options section. The preset filter is a global property of
  3496. the entire agenda view. In a block agenda, it will not work reliably to
  3497. define a filter for one of the individual blocks. You need to set it in
  3498. the global options and expect it to be applied to the entire view.")
  3499. (defvar org-agenda-effort-filter-preset nil
  3500. "A preset of the effort condition used for secondary agenda filtering.
  3501. This must be a list of strings, each string must be a single regexp
  3502. preceded by \"+\" or \"-\".
  3503. This variable should not be set directly, but agenda custom commands can
  3504. bind it in the options section. The preset filter is a global property of
  3505. the entire agenda view. In a block agenda, it will not work reliably to
  3506. define a filter for one of the individual blocks. You need to set it in
  3507. the global options and expect it to be applied to the entire view.")
  3508. (defun org-agenda-use-sticky-p ()
  3509. "Return non-nil if an agenda buffer named
  3510. `org-agenda-buffer-name' exists and should be shown instead of
  3511. generating a new one."
  3512. (and
  3513. ;; turned off by user
  3514. org-agenda-sticky
  3515. ;; For multi-agenda buffer already exists
  3516. (not org-agenda-multi)
  3517. ;; buffer found
  3518. (get-buffer org-agenda-buffer-name)
  3519. ;; C-u parameter is same as last call
  3520. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3521. (and
  3522. (equal current-prefix-arg
  3523. org-agenda-last-prefix-arg)
  3524. ;; In case user turned stickiness on, while having existing
  3525. ;; Agenda buffer active, don't reuse that buffer, because it
  3526. ;; does not have org variables local
  3527. org-agenda-this-buffer-is-sticky))))
  3528. (defvar org-agenda-buffer-tmp-name nil)
  3529. (defun org-agenda--get-buffer-name (sticky-name)
  3530. (or org-agenda-buffer-tmp-name
  3531. (and org-agenda-doing-sticky-redo org-agenda-buffer-name)
  3532. sticky-name
  3533. "*Org Agenda*"))
  3534. (defun org-agenda-prepare-window (abuf filter-alist)
  3535. "Setup agenda buffer in the window.
  3536. ABUF is the buffer for the agenda window.
  3537. FILTER-ALIST is an alist of filters we need to apply when
  3538. `org-agenda-persistent-filter' is non-nil."
  3539. (let* ((awin (get-buffer-window abuf)) wconf)
  3540. (cond
  3541. ((equal (current-buffer) abuf) nil)
  3542. (awin (select-window awin))
  3543. ((not (setq wconf (current-window-configuration))))
  3544. ((eq org-agenda-window-setup 'current-window)
  3545. (pop-to-buffer-same-window abuf))
  3546. ((eq org-agenda-window-setup 'other-window)
  3547. (org-switch-to-buffer-other-window abuf))
  3548. ((eq org-agenda-window-setup 'other-frame)
  3549. (switch-to-buffer-other-frame abuf))
  3550. ((eq org-agenda-window-setup 'other-tab)
  3551. (if (fboundp 'switch-to-buffer-other-tab)
  3552. (switch-to-buffer-other-tab abuf)
  3553. (user-error "Your version of Emacs does not have tab bar support")))
  3554. ((eq org-agenda-window-setup 'only-window)
  3555. (delete-other-windows)
  3556. (pop-to-buffer-same-window abuf))
  3557. ((eq org-agenda-window-setup 'reorganize-frame)
  3558. (delete-other-windows)
  3559. (org-switch-to-buffer-other-window abuf)))
  3560. (setq org-agenda-tag-filter (cdr (assq 'tag filter-alist)))
  3561. (setq org-agenda-category-filter (cdr (assq 'cat filter-alist)))
  3562. (setq org-agenda-effort-filter (cdr (assq 'effort filter-alist)))
  3563. (setq org-agenda-regexp-filter (cdr (assq 're filter-alist)))
  3564. ;; Additional test in case agenda is invoked from within agenda
  3565. ;; buffer via elisp link.
  3566. (unless (equal (current-buffer) abuf)
  3567. (pop-to-buffer-same-window abuf))
  3568. (setq org-agenda-pre-window-conf
  3569. (or wconf org-agenda-pre-window-conf))))
  3570. (defun org-agenda-prepare (&optional name)
  3571. (let ((filter-alist (when org-agenda-persistent-filter
  3572. (with-current-buffer
  3573. (get-buffer-create org-agenda-buffer-name)
  3574. `((tag . ,org-agenda-tag-filter)
  3575. (re . ,org-agenda-regexp-filter)
  3576. (effort . ,org-agenda-effort-filter)
  3577. (cat . ,org-agenda-category-filter))))))
  3578. (if (org-agenda-use-sticky-p)
  3579. (progn
  3580. ;; Popup existing buffer
  3581. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3582. filter-alist)
  3583. (message "Sticky Agenda buffer, use `r' to refresh")
  3584. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3585. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3586. (setq org-todo-keywords-for-agenda nil)
  3587. (if org-agenda-multi
  3588. (progn
  3589. (setq buffer-read-only nil)
  3590. (goto-char (point-max))
  3591. (unless (or (bobp) org-agenda-compact-blocks
  3592. (not org-agenda-block-separator))
  3593. (insert "\n"
  3594. (if (stringp org-agenda-block-separator)
  3595. org-agenda-block-separator
  3596. (make-string (window-max-chars-per-line) org-agenda-block-separator))
  3597. "\n"))
  3598. (narrow-to-region (point) (point-max)))
  3599. (setq org-done-keywords-for-agenda nil)
  3600. ;; Setting any org variables that are in org-agenda-local-vars
  3601. ;; list need to be done after the prepare call
  3602. (org-agenda-prepare-window
  3603. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3604. (setq buffer-read-only nil)
  3605. (org-agenda-reset-markers)
  3606. (let ((inhibit-read-only t)) (erase-buffer))
  3607. (org-agenda-mode)
  3608. (setq org-agenda-buffer (current-buffer))
  3609. (setq org-agenda-contributing-files nil)
  3610. (setq org-agenda-columns-active nil)
  3611. (setq org-agenda-filters-preset
  3612. `((tag . ,org-agenda-tag-filter-preset)
  3613. (category . ,org-agenda-category-filter-preset)
  3614. (regexp . ,org-agenda-regexp-filter-preset)
  3615. (effort . ,org-agenda-effort-filter-preset)))
  3616. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3617. (setq org-todo-keywords-for-agenda
  3618. (org-uniquify org-todo-keywords-for-agenda))
  3619. (setq org-done-keywords-for-agenda
  3620. (org-uniquify org-done-keywords-for-agenda))
  3621. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3622. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3623. (and name (not org-agenda-name)
  3624. (setq-local org-agenda-name name)))
  3625. (setq buffer-read-only nil))))
  3626. (defvar org-overriding-columns-format)
  3627. (defvar org-local-columns-format)
  3628. (defun org-agenda-finalize ()
  3629. "Finishing touch for the agenda buffer.
  3630. This function is called just before displaying the agenda. If
  3631. you want to add your own functions to the finalization of the
  3632. agenda display, configure `org-agenda-finalize-hook'."
  3633. (unless org-agenda-multi
  3634. (let ((inhibit-read-only t))
  3635. (save-excursion
  3636. (goto-char (point-min))
  3637. (save-excursion
  3638. (while (org-activate-links (point-max))
  3639. (goto-char (match-end 0))))
  3640. (unless (eq org-agenda-remove-tags t)
  3641. (org-agenda-align-tags))
  3642. (unless org-agenda-with-colors
  3643. (remove-text-properties (point-min) (point-max) '(face nil)))
  3644. (when (bound-and-true-p org-overriding-columns-format)
  3645. (setq-local org-local-columns-format
  3646. org-overriding-columns-format))
  3647. (when org-agenda-view-columns-initially
  3648. (org-agenda-columns))
  3649. (when org-agenda-fontify-priorities
  3650. (org-agenda-fontify-priorities))
  3651. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3652. (org-agenda-dim-blocked-tasks))
  3653. (org-agenda-mark-clocking-task)
  3654. (when org-agenda-entry-text-mode
  3655. (org-agenda-entry-text-hide)
  3656. (org-agenda-entry-text-show))
  3657. (when (and (featurep 'org-habit)
  3658. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3659. (org-habit-insert-consistency-graphs))
  3660. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3661. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3662. (and (listp org-agenda-show-inherited-tags)
  3663. (memq org-agenda-type org-agenda-show-inherited-tags))
  3664. (and (eq org-agenda-show-inherited-tags t)
  3665. (or (eq org-agenda-use-tag-inheritance t)
  3666. (and (listp org-agenda-use-tag-inheritance)
  3667. (not (memq org-agenda-type
  3668. org-agenda-use-tag-inheritance))))))
  3669. (let (mrk)
  3670. (save-excursion
  3671. (goto-char (point-min))
  3672. (while (equal (forward-line) 0)
  3673. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3674. (put-text-property (line-beginning-position) (line-end-position)
  3675. 'tags
  3676. (org-with-point-at mrk
  3677. (org-get-tags))))))))
  3678. (setq org-agenda-represented-tags nil
  3679. org-agenda-represented-categories nil)
  3680. (when org-agenda-top-headline-filter
  3681. (org-agenda-filter-top-headline-apply
  3682. org-agenda-top-headline-filter))
  3683. (when org-agenda-tag-filter
  3684. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3685. (when (assoc-default 'tag org-agenda-filters-preset)
  3686. (org-agenda-filter-apply
  3687. (assoc-default 'tag org-agenda-filters-preset) 'tag t))
  3688. (when org-agenda-category-filter
  3689. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3690. (when (assoc-default 'category org-agenda-filters-preset)
  3691. (org-agenda-filter-apply
  3692. (assoc-default 'category org-agenda-filters-preset) 'category))
  3693. (when org-agenda-regexp-filter
  3694. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3695. (when (assoc-default 'regexp org-agenda-filters-preset)
  3696. (org-agenda-filter-apply
  3697. (assoc-default 'regexp org-agenda-filters-preset) 'regexp))
  3698. (when org-agenda-effort-filter
  3699. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3700. (when (assoc-default 'effort org-agenda-filters-preset)
  3701. (org-agenda-filter-apply
  3702. (assoc-default 'effort org-agenda-filters-preset) 'effort))
  3703. (add-hook 'kill-buffer-hook #'org-agenda-reset-markers 'append 'local))
  3704. (run-hooks 'org-agenda-finalize-hook))))
  3705. (defun org-agenda-mark-clocking-task ()
  3706. "Mark the current clock entry in the agenda if it is present."
  3707. ;; We need to widen when `org-agenda-finalize' is called from
  3708. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in').
  3709. (when (bound-and-true-p org-clock-current-task)
  3710. (save-restriction
  3711. (widen)
  3712. (org-agenda-unmark-clocking-task)
  3713. (when (marker-buffer org-clock-hd-marker)
  3714. (save-excursion
  3715. (goto-char (point-min))
  3716. (let (s ov)
  3717. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3718. (goto-char s)
  3719. (when (equal (org-get-at-bol 'org-hd-marker)
  3720. org-clock-hd-marker)
  3721. (setq ov (make-overlay (line-beginning-position)
  3722. (1+ (line-end-position))))
  3723. (overlay-put ov 'type 'org-agenda-clocking)
  3724. (overlay-put ov 'face 'org-agenda-clocking)
  3725. (overlay-put ov 'help-echo
  3726. "The clock is running in this item")))))))))
  3727. (defun org-agenda-unmark-clocking-task ()
  3728. "Unmark the current clocking task."
  3729. (mapc (lambda (o)
  3730. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  3731. (delete-overlay o)))
  3732. (overlays-in (point-min) (point-max))))
  3733. (defun org-agenda-fontify-priorities ()
  3734. "Make highest priority lines bold, and lowest italic."
  3735. (interactive)
  3736. (mapc (lambda (o) (when (eq (overlay-get o 'org-type) 'org-priority)
  3737. (delete-overlay o)))
  3738. (overlays-in (point-min) (point-max)))
  3739. (save-excursion
  3740. (let (b e p ov h l)
  3741. (goto-char (point-min))
  3742. (while (re-search-forward org-priority-regexp nil t)
  3743. (setq h (or (get-char-property (point) 'org-priority-highest)
  3744. org-priority-highest)
  3745. l (or (get-char-property (point) 'org-priority-lowest)
  3746. org-priority-lowest)
  3747. p (string-to-char (match-string 2))
  3748. b (match-beginning 1)
  3749. e (if (eq org-agenda-fontify-priorities 'cookies)
  3750. (1+ (match-end 2))
  3751. (line-end-position))
  3752. ov (make-overlay b e))
  3753. (overlay-put
  3754. ov 'face
  3755. (let ((special-face
  3756. (cond ((org-face-from-face-or-color
  3757. 'priority 'org-priority
  3758. (cdr (assoc p org-priority-faces))))
  3759. ((and (listp org-agenda-fontify-priorities)
  3760. (org-face-from-face-or-color
  3761. 'priority 'org-priority
  3762. (cdr (assoc p org-agenda-fontify-priorities)))))
  3763. ((equal p l) 'italic)
  3764. ((equal p h) 'bold))))
  3765. (if special-face (list special-face 'org-priority) 'org-priority)))
  3766. (overlay-put ov 'org-type 'org-priority)))))
  3767. (defvar org-depend-tag-blocked)
  3768. (defun org-agenda-dim-blocked-tasks (&optional _invisible)
  3769. "Dim currently blocked TODOs in the agenda display.
  3770. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3771. dimming them." ;FIXME: The arg isn't used, actually!
  3772. (interactive "P")
  3773. (when (called-interactively-p 'interactive)
  3774. (message "Dim or hide blocked tasks..."))
  3775. (dolist (o (overlays-in (point-min) (point-max)))
  3776. (when (eq (overlay-get o 'face) 'org-agenda-dimmed-todo-face)
  3777. (delete-overlay o)))
  3778. (save-excursion
  3779. (let ((inhibit-read-only t))
  3780. (goto-char (point-min))
  3781. (while (let ((pos (text-property-not-all
  3782. (point) (point-max) 'org-todo-blocked nil)))
  3783. (when pos (goto-char pos)))
  3784. (let* ((invisible
  3785. (eq (org-get-at-bol 'org-todo-blocked) 'invisible))
  3786. (todo-blocked
  3787. (eq (org-get-at-bol 'org-filter-type) 'todo-blocked))
  3788. (ov (make-overlay (if invisible
  3789. (line-end-position 0)
  3790. (line-beginning-position))
  3791. (line-end-position))))
  3792. (when todo-blocked
  3793. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3794. (when invisible
  3795. (org-agenda-filter-hide-line 'todo-blocked)))
  3796. (if (= (point-max) (line-end-position))
  3797. (goto-char (point-max))
  3798. (move-beginning-of-line 2)))))
  3799. (when (called-interactively-p 'interactive)
  3800. (message "Dim or hide blocked tasks...done")))
  3801. (defun org-agenda--mark-blocked-entry (entry)
  3802. "If ENTRY is blocked, mark it for fontification or invisibility.
  3803. If the header at `org-hd-marker' is blocked according to
  3804. `org-entry-blocked-p', then if `org-agenda-dim-blocked-tasks' is
  3805. `invisible' and the header is not blocked by checkboxes, set the
  3806. text property `org-todo-blocked' to `invisible', otherwise set it
  3807. to t."
  3808. (when (get-text-property 0 'todo-state entry)
  3809. (let ((entry-marker (get-text-property 0 'org-hd-marker entry))
  3810. (org-blocked-by-checkboxes nil)
  3811. ;; Necessary so that `org-entry-blocked-p' does not change
  3812. ;; the buffer.
  3813. (org-depend-tag-blocked nil))
  3814. (when entry-marker
  3815. (let ((blocked
  3816. (with-current-buffer (marker-buffer entry-marker)
  3817. (save-excursion
  3818. (goto-char entry-marker)
  3819. (org-entry-blocked-p)))))
  3820. (when blocked
  3821. (let ((really-invisible
  3822. (and (not org-blocked-by-checkboxes)
  3823. (eq org-agenda-dim-blocked-tasks 'invisible))))
  3824. (put-text-property
  3825. 0 (length entry) 'org-todo-blocked
  3826. (if really-invisible 'invisible t)
  3827. entry)
  3828. (put-text-property
  3829. 0 (length entry) 'org-filter-type 'todo-blocked entry)))))))
  3830. entry)
  3831. (defvar org-agenda-skip-function nil
  3832. "Function to be called at each match during agenda construction.
  3833. If this function returns nil, the current match should not be skipped.
  3834. Otherwise, the function must return a position from where the search
  3835. should be continued.
  3836. This may also be a Lisp form that will be evaluated. Useful
  3837. forms include `org-agenda-skip-entry-if' and
  3838. `org-agenda-skip-subtree-if'. See the Info node `(org) Special
  3839. Agenda Views' for more details and examples.
  3840. Never set this variable using `setq' or similar, because then it
  3841. will apply to all future agenda commands. If you want a global
  3842. skipping condition, use the option `org-agenda-skip-function-global'
  3843. instead.
  3844. The correct way to use `org-agenda-skip-function' is to bind it with `let'
  3845. to scope it dynamically into the agenda-constructing command.
  3846. A good way to set it is through options in `org-agenda-custom-commands'.")
  3847. (defun org-agenda-skip (&optional element)
  3848. "Throw to `:skip' in places that should be skipped.
  3849. Also moves point to the end of the skipped region, so that search can
  3850. continue from there.
  3851. Optional argument ELEMENT contains element at point."
  3852. (when (or
  3853. (if element
  3854. (eq (org-element-type element) 'comment)
  3855. (save-excursion
  3856. (goto-char (line-beginning-position))
  3857. (looking-at comment-start-skip)))
  3858. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3859. (or (and (save-match-data (org-in-archived-heading-p nil element))
  3860. (org-end-of-subtree t element))
  3861. (and (member org-archive-tag org-file-tags)
  3862. (goto-char (point-max)))))
  3863. (and org-agenda-skip-comment-trees
  3864. (org-in-commented-heading-p nil element)
  3865. (org-end-of-subtree t element))
  3866. (let ((to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3867. (org-agenda-skip-eval org-agenda-skip-function))))
  3868. (and to (goto-char to)))
  3869. (org-in-src-block-p t element))
  3870. (throw :skip t)))
  3871. (defun org-agenda-skip-eval (form)
  3872. "If FORM is a function or a list, call (or eval) it and return the result.
  3873. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3874. and match data are returned to the previous state no matter what these
  3875. functions do."
  3876. (let (fp)
  3877. (and form
  3878. (or (setq fp (functionp form))
  3879. (consp form))
  3880. (save-excursion
  3881. (save-match-data
  3882. (if fp
  3883. (funcall form)
  3884. (eval form t)))))))
  3885. (defvar org-agenda-markers nil
  3886. "List of all currently active markers created by `org-agenda'.")
  3887. (defvar org-agenda-last-marker-time (float-time)
  3888. "Creation time of the last agenda marker.")
  3889. (defun org-agenda-new-marker (&optional pos)
  3890. "Return a new agenda marker.
  3891. Marker is at point, or at POS if non-nil. Org mode keeps a list
  3892. of these markers and resets them when they are no longer in use."
  3893. (let ((m (copy-marker (or pos (point)) t)))
  3894. (setq org-agenda-last-marker-time (float-time))
  3895. (if (and org-agenda-buffer (buffer-live-p org-agenda-buffer))
  3896. (with-current-buffer org-agenda-buffer
  3897. (push m org-agenda-markers))
  3898. (push m org-agenda-markers))
  3899. m))
  3900. (defun org-agenda-reset-markers ()
  3901. "Reset markers created by `org-agenda'."
  3902. (while org-agenda-markers
  3903. (move-marker (pop org-agenda-markers) nil)))
  3904. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3905. "Save relative positions of markers in region.
  3906. This check for agenda markers in all agenda buffers currently active."
  3907. (dolist (buf (buffer-list))
  3908. (with-current-buffer buf
  3909. (when (eq major-mode 'org-agenda-mode)
  3910. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3911. org-agenda-markers)))))
  3912. ;;; Entry text mode
  3913. (defun org-agenda-entry-text-show-here ()
  3914. "Add some text from the entry as context to the current line."
  3915. (let (m txt o)
  3916. (setq m (org-get-at-bol 'org-hd-marker))
  3917. (unless (marker-buffer m)
  3918. (error "No marker points to an entry here"))
  3919. (setq txt (concat "\n" (org-no-properties
  3920. (org-agenda-get-some-entry-text
  3921. m org-agenda-entry-text-maxlines
  3922. org-agenda-entry-text-leaders))))
  3923. (when (string-match "\\S-" txt)
  3924. (setq o (make-overlay (line-beginning-position) (line-end-position)))
  3925. (overlay-put o 'evaporate t)
  3926. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3927. (overlay-put o 'after-string txt))))
  3928. (defun org-agenda-entry-text-show ()
  3929. "Add entry context for all agenda lines."
  3930. (interactive)
  3931. (save-excursion
  3932. (goto-char (point-max))
  3933. (beginning-of-line 1)
  3934. (while (not (bobp))
  3935. (when (org-get-at-bol 'org-hd-marker)
  3936. (org-agenda-entry-text-show-here))
  3937. (beginning-of-line 0))))
  3938. (defun org-agenda-entry-text-hide ()
  3939. "Remove any shown entry context."
  3940. (mapc (lambda (o)
  3941. (when (eq (overlay-get o 'org-overlay-type)
  3942. 'agenda-entry-content)
  3943. (delete-overlay o)))
  3944. (overlays-in (point-min) (point-max))))
  3945. (defun org-agenda-get-day-face (date)
  3946. "Return the face DATE should be displayed with."
  3947. (cond ((and (functionp org-agenda-day-face-function)
  3948. (funcall org-agenda-day-face-function date)))
  3949. ((and (org-agenda-today-p date)
  3950. (memq (calendar-day-of-week date) org-agenda-weekend-days))
  3951. 'org-agenda-date-weekend-today)
  3952. ((org-agenda-today-p date) 'org-agenda-date-today)
  3953. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3954. 'org-agenda-date-weekend)
  3955. (t 'org-agenda-date)))
  3956. (defvar org-agenda-show-log-scoped)
  3957. ;;; Agenda Daily/Weekly
  3958. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3959. "Start day for the agenda view.
  3960. Custom commands can set this variable in the options section.
  3961. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3962. input allowed when reading a date through the Org calendar.
  3963. See the docstring of `org-read-date' for details.")
  3964. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3965. (defvar org-arg-loc nil) ; local variable
  3966. ;;;###autoload
  3967. (defun org-agenda-list (&optional arg start-day span with-hour)
  3968. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3969. The view will be for the current day or week, but from the overview buffer
  3970. you will be able to go to other days/weeks.
  3971. With a numeric prefix argument in an interactive call, the agenda will
  3972. span ARG days. Lisp programs should instead specify SPAN to change
  3973. the number of days. SPAN defaults to `org-agenda-span'.
  3974. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3975. given in `org-agenda-start-on-weekday'.
  3976. When WITH-HOUR is non-nil, only include scheduled and deadline
  3977. items if they have an hour specification like [h]h:mm."
  3978. (interactive "P")
  3979. (when org-agenda-overriding-arguments
  3980. (setq arg (car org-agenda-overriding-arguments)
  3981. start-day (nth 1 org-agenda-overriding-arguments)
  3982. span (nth 2 org-agenda-overriding-arguments)))
  3983. (when (and (integerp arg) (> arg 0))
  3984. (setq span arg arg nil))
  3985. (when (numberp span)
  3986. (unless (< 0 span)
  3987. (user-error "Agenda creation impossible for this span(=%d days)" span)))
  3988. (catch 'exit
  3989. (setq org-agenda-buffer-name
  3990. (org-agenda--get-buffer-name
  3991. (and org-agenda-sticky
  3992. (cond ((and org-keys (stringp org-match))
  3993. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3994. (org-keys
  3995. (format "*Org Agenda(%s)*" org-keys))
  3996. (t "*Org Agenda(a)*")))))
  3997. (org-agenda-prepare "Day/Week")
  3998. (setq start-day (or start-day org-agenda-start-day))
  3999. (when (stringp start-day)
  4000. ;; Convert to an absolute day number
  4001. (setq start-day (time-to-days (org-read-date nil t start-day))))
  4002. (org-compile-prefix-format 'agenda)
  4003. (org-set-sorting-strategy 'agenda)
  4004. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
  4005. (today (org-today))
  4006. (sd (or start-day today))
  4007. (ndays (org-agenda-span-to-ndays span sd))
  4008. (org-agenda-start-on-weekday
  4009. (and (or (eq ndays 7) (eq ndays 14))
  4010. org-agenda-start-on-weekday))
  4011. (thefiles (org-agenda-files nil 'ifmode))
  4012. (files thefiles)
  4013. (start (if (or (null org-agenda-start-on-weekday)
  4014. (< ndays 7))
  4015. sd
  4016. (let* ((nt (calendar-day-of-week
  4017. (calendar-gregorian-from-absolute sd)))
  4018. (n1 org-agenda-start-on-weekday)
  4019. (d (- nt n1)))
  4020. (- sd (+ (if (< d 0) 7 0) d)))))
  4021. (day-numbers (list start))
  4022. (day-cnt 0)
  4023. ;; FIXME: This may cause confusion when users are trying to
  4024. ;; debug agenda. The debugger will not trigger without
  4025. ;; redisplay.
  4026. (inhibit-redisplay (not debug-on-error))
  4027. (org-agenda-show-log-scoped org-agenda-show-log)
  4028. s rtn rtnall file date d start-pos end-pos todayp ;; e
  4029. clocktable-start clocktable-end) ;; filter
  4030. (setq org-agenda-redo-command
  4031. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  4032. (dotimes (_ (1- ndays))
  4033. (push (1+ (car day-numbers)) day-numbers))
  4034. (setq day-numbers (nreverse day-numbers))
  4035. (setq clocktable-start (car day-numbers)
  4036. clocktable-end (1+ (or (org-last day-numbers) 0)))
  4037. (setq-local org-starting-day (car day-numbers))
  4038. (setq-local org-arg-loc arg)
  4039. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  4040. (unless org-agenda-compact-blocks
  4041. (let* ((d1 (car day-numbers))
  4042. (d2 (org-last day-numbers))
  4043. (w1 (org-days-to-iso-week d1))
  4044. (w2 (org-days-to-iso-week d2)))
  4045. (setq s (point))
  4046. (org-agenda--insert-overriding-header
  4047. (concat (org-agenda-span-name span)
  4048. "-agenda"
  4049. (cond ((<= 350 (- d2 d1)) "")
  4050. ((= w1 w2) (format " (W%02d)" w1))
  4051. (t (format " (W%02d-W%02d)" w1 w2)))
  4052. ":\n")))
  4053. ;; Add properties if we actually inserted a header.
  4054. (when (> (point) s)
  4055. (add-text-properties s (1- (point))
  4056. (list 'face 'org-agenda-structure
  4057. 'org-date-line t))
  4058. (org-agenda-mark-header-line s)))
  4059. (while (setq d (pop day-numbers))
  4060. (setq date (calendar-gregorian-from-absolute d)
  4061. s (point))
  4062. (if (or (setq todayp (= d today))
  4063. (and (not start-pos) (= d sd)))
  4064. (setq start-pos (point))
  4065. (when (and start-pos (not end-pos))
  4066. (setq end-pos (point))))
  4067. (setq files thefiles
  4068. rtnall nil)
  4069. (while (setq file (pop files))
  4070. (catch 'nextfile
  4071. (org-check-agenda-file file)
  4072. (let ((org-agenda-entry-types org-agenda-entry-types))
  4073. ;; Starred types override non-starred equivalents
  4074. (when (member :deadline* org-agenda-entry-types)
  4075. (setq org-agenda-entry-types
  4076. (delq :deadline org-agenda-entry-types)))
  4077. (when (member :scheduled* org-agenda-entry-types)
  4078. (setq org-agenda-entry-types
  4079. (delq :scheduled org-agenda-entry-types)))
  4080. ;; Honor with-hour
  4081. (when with-hour
  4082. (when (member :deadline org-agenda-entry-types)
  4083. (setq org-agenda-entry-types
  4084. (delq :deadline org-agenda-entry-types))
  4085. (push :deadline* org-agenda-entry-types))
  4086. (when (member :scheduled org-agenda-entry-types)
  4087. (setq org-agenda-entry-types
  4088. (delq :scheduled org-agenda-entry-types))
  4089. (push :scheduled* org-agenda-entry-types)))
  4090. (unless org-agenda-include-deadlines
  4091. (setq org-agenda-entry-types
  4092. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  4093. (cond
  4094. ((memq org-agenda-show-log-scoped '(only clockcheck))
  4095. (setq rtn (org-agenda-get-day-entries
  4096. file date :closed)))
  4097. (org-agenda-show-log-scoped
  4098. (setq rtn (apply #'org-agenda-get-day-entries
  4099. file date
  4100. (append '(:closed) org-agenda-entry-types))))
  4101. (t
  4102. (setq rtn (apply #'org-agenda-get-day-entries
  4103. file date
  4104. org-agenda-entry-types)))))
  4105. (setq rtnall (append rtnall rtn)))) ;; all entries
  4106. (when org-agenda-include-diary
  4107. (let ((org-agenda-search-headline-for-time t))
  4108. (require 'diary-lib)
  4109. (setq rtn (org-get-entries-from-diary date))
  4110. (setq rtnall (append rtnall rtn))))
  4111. (when (or rtnall org-agenda-show-all-dates)
  4112. (setq day-cnt (1+ day-cnt))
  4113. (insert
  4114. (if (stringp org-agenda-format-date)
  4115. (format-time-string org-agenda-format-date
  4116. (org-time-from-absolute date))
  4117. (funcall org-agenda-format-date date))
  4118. "\n")
  4119. (put-text-property s (1- (point)) 'face
  4120. (org-agenda-get-day-face date))
  4121. (put-text-property s (1- (point)) 'org-date-line t)
  4122. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  4123. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  4124. (when todayp
  4125. (put-text-property s (1- (point)) 'org-today t))
  4126. (setq rtnall
  4127. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  4128. (when rtnall (insert ;; all entries
  4129. (org-agenda-finalize-entries rtnall 'agenda)
  4130. "\n"))
  4131. (put-text-property s (1- (point)) 'day d)
  4132. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)))
  4133. (when (and org-agenda-clockreport-mode clocktable-start)
  4134. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  4135. ;; the above line is to ensure the restricted range!
  4136. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  4137. tbl)
  4138. (setq p (org-plist-delete p :block))
  4139. (setq p (plist-put p :tstart clocktable-start))
  4140. (setq p (plist-put p :tend clocktable-end))
  4141. (setq p (plist-put p :scope 'agenda))
  4142. (setq tbl (apply #'org-clock-get-clocktable p))
  4143. (when org-agenda-clock-report-header
  4144. (insert (propertize org-agenda-clock-report-header 'face 'org-agenda-structure))
  4145. (unless (string-suffix-p "\n" org-agenda-clock-report-header)
  4146. (insert "\n")))
  4147. (insert tbl)))
  4148. (goto-char (point-min))
  4149. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4150. (unless (or (not (get-buffer-window org-agenda-buffer-name))
  4151. (and (pos-visible-in-window-p (point-min))
  4152. (pos-visible-in-window-p (point-max))))
  4153. (goto-char (1- (point-max)))
  4154. (recenter -1)
  4155. (when (not (pos-visible-in-window-p (or start-pos 1)))
  4156. (goto-char (or start-pos 1))
  4157. (recenter 1)))
  4158. (goto-char (or start-pos 1))
  4159. (add-text-properties (point-min) (point-max)
  4160. `(org-agenda-type agenda
  4161. org-last-args (,arg ,start-day ,span)
  4162. org-redo-cmd ,org-agenda-redo-command
  4163. org-series-cmd ,org-cmd))
  4164. (when (eq org-agenda-show-log-scoped 'clockcheck)
  4165. (org-agenda-show-clocking-issues))
  4166. (org-agenda-finalize)
  4167. (setq buffer-read-only t)
  4168. (message ""))))
  4169. (defun org-agenda-ndays-to-span (n)
  4170. "Return a span symbol for a span of N days, or N if none matches."
  4171. (cond ((symbolp n) n)
  4172. ((= n 1) 'day)
  4173. ((= n 7) 'week)
  4174. ((= n 14) 'fortnight)
  4175. (t n)))
  4176. (defun org-agenda-span-to-ndays (span &optional start-day)
  4177. "Return ndays from SPAN, possibly starting at START-DAY.
  4178. START-DAY is an absolute time value."
  4179. (cond ((numberp span) span)
  4180. ((eq span 'day) 1)
  4181. ((eq span 'week) 7)
  4182. ((eq span 'fortnight) 14)
  4183. ((eq span 'month)
  4184. (let ((date (calendar-gregorian-from-absolute start-day)))
  4185. (calendar-last-day-of-month (car date) (cl-caddr date))))
  4186. ((eq span 'year)
  4187. (let ((date (calendar-gregorian-from-absolute start-day)))
  4188. (if (calendar-leap-year-p (cl-caddr date)) 366 365)))))
  4189. (defun org-agenda-span-name (span)
  4190. "Return a SPAN name."
  4191. (if (null span)
  4192. ""
  4193. (if (symbolp span)
  4194. (capitalize (symbol-name span))
  4195. (format "%d days" span))))
  4196. ;;; Agenda word search
  4197. (defvar org-agenda-search-history nil)
  4198. (defvar org-search-syntax-table nil
  4199. "Special syntax table for Org search.
  4200. In this table, we have single quotes not as word constituents, to
  4201. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4202. (defvar org-mode-syntax-table) ; From org.el
  4203. (defun org-search-syntax-table ()
  4204. (unless org-search-syntax-table
  4205. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4206. (modify-syntax-entry ?' "." org-search-syntax-table)
  4207. (modify-syntax-entry ?` "." org-search-syntax-table))
  4208. org-search-syntax-table)
  4209. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4210. ;;;###autoload
  4211. (defun org-search-view (&optional todo-only string edit-at)
  4212. "Show all entries that contain a phrase or words or regular expressions.
  4213. With optional prefix argument TODO-ONLY, only consider entries that are
  4214. TODO entries. The argument STRING can be used to pass a default search
  4215. string into this function. If EDIT-AT is non-nil, it means that the
  4216. user should get a chance to edit this string, with cursor at position
  4217. EDIT-AT.
  4218. The search string can be viewed either as a phrase that should be found as
  4219. is, or it can be broken into a number of snippets, each of which must match
  4220. in a Boolean way to select an entry. The default depends on the variable
  4221. `org-agenda-search-view-always-boolean'.
  4222. Even if this is turned off (the default) you can always switch to
  4223. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4224. The default is a direct search of the whole phrase, where each space in
  4225. the search string can expand to an arbitrary amount of whitespace,
  4226. including newlines.
  4227. If using a Boolean search, the search string is split on whitespace and
  4228. each snippet is searched separately, with logical AND to select an entry.
  4229. Words prefixed with a minus must *not* occur in the entry. Words without
  4230. a prefix or prefixed with a plus must occur in the entry. Matching is
  4231. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4232. match whole words, not parts of a word) if
  4233. `org-agenda-search-view-force-full-words' is set (default is nil).
  4234. Boolean search snippets enclosed by curly braces are interpreted as
  4235. regular expressions that must or (when preceded with \"-\") must not
  4236. match in the entry. Snippets enclosed into double quotes will be taken
  4237. as a whole, to include whitespace.
  4238. - If the search string starts with an asterisk, search only in headlines.
  4239. - If (possibly after the leading star) the search string starts with an
  4240. exclamation mark, this also means to look at TODO entries only, an effect
  4241. that can also be achieved with a prefix argument.
  4242. - If (possibly after star and exclamation mark) the search string starts
  4243. with a colon, this will mean that the (non-regexp) snippets of the
  4244. Boolean search must match as full words.
  4245. This command searches the agenda files, and in addition the files
  4246. listed in `org-agenda-text-search-extra-files' unless a restriction lock
  4247. is active."
  4248. (interactive "P")
  4249. (when org-agenda-overriding-arguments
  4250. (setq todo-only (car org-agenda-overriding-arguments)
  4251. string (nth 1 org-agenda-overriding-arguments)
  4252. edit-at (nth 2 org-agenda-overriding-arguments)))
  4253. (let* ((props (list 'face nil
  4254. 'done-face 'org-agenda-done
  4255. 'org-not-done-regexp org-not-done-regexp
  4256. 'org-todo-regexp org-todo-regexp
  4257. 'org-complex-heading-regexp org-complex-heading-regexp
  4258. 'mouse-face 'highlight
  4259. 'help-echo "mouse-2 or RET jump to location"))
  4260. (full-words org-agenda-search-view-force-full-words)
  4261. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4262. regexp rtn rtnall files file pos inherited-tags
  4263. marker category level tags c neg re boolean
  4264. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4265. (unless (and (not edit-at)
  4266. (stringp string)
  4267. (string-match "\\S-" string))
  4268. (setq string (read-string
  4269. (if org-agenda-search-view-always-boolean
  4270. "[+-]Word/{Regexp} ...: "
  4271. "Phrase or [+-]Word/{Regexp} ...: ")
  4272. (cond
  4273. ((integerp edit-at) (cons string edit-at))
  4274. (edit-at string))
  4275. 'org-agenda-search-history)))
  4276. (catch 'exit
  4277. (setq org-agenda-buffer-name
  4278. (org-agenda--get-buffer-name
  4279. (and org-agenda-sticky
  4280. (if (stringp string)
  4281. (format "*Org Agenda(%s:%s)*"
  4282. (or org-keys (or (and todo-only "S") "s"))
  4283. string)
  4284. (format "*Org Agenda(%s)*"
  4285. (or (and todo-only "S") "s"))))))
  4286. (org-agenda-prepare "SEARCH")
  4287. (org-compile-prefix-format 'search)
  4288. (org-set-sorting-strategy 'search)
  4289. (setq org-agenda-redo-command
  4290. (list 'org-search-view (if todo-only t nil)
  4291. (list 'if 'current-prefix-arg nil string)))
  4292. (setq org-agenda-query-string string)
  4293. (if (equal (string-to-char string) ?*)
  4294. (setq hdl-only t
  4295. words (substring string 1))
  4296. (setq words string))
  4297. (when (equal (string-to-char words) ?!)
  4298. (setq todo-only t
  4299. words (substring words 1)))
  4300. (when (equal (string-to-char words) ?:)
  4301. (setq full-words t
  4302. words (substring words 1)))
  4303. (when (or org-agenda-search-view-always-boolean
  4304. (member (string-to-char words) '(?- ?+ ?\{)))
  4305. (setq boolean t))
  4306. (setq words (split-string words))
  4307. (let (www w)
  4308. (while (setq w (pop words))
  4309. (while (and (string-match "\\\\\\'" w) words)
  4310. (setq w (concat (substring w 0 -1) " " (pop words))))
  4311. (push w www))
  4312. (setq words (nreverse www) www nil)
  4313. (while (setq w (pop words))
  4314. (when (and (string-match "\\`[-+]?{" w)
  4315. (not (string-match "}\\'" w)))
  4316. (while (and words (not (string-match "}\\'" (car words))))
  4317. (setq w (concat w " " (pop words))))
  4318. (setq w (concat w " " (pop words))))
  4319. (push w www))
  4320. (setq words (nreverse www)))
  4321. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4322. (when boolean
  4323. (let (wds w)
  4324. (while (setq w (pop words))
  4325. (when (or (equal (substring w 0 1) "\"")
  4326. (and (> (length w) 1)
  4327. (member (substring w 0 1) '("+" "-"))
  4328. (equal (substring w 1 2) "\"")))
  4329. (while (and words (not (equal (substring w -1) "\"")))
  4330. (setq w (concat w " " (pop words)))))
  4331. (and (string-match "\\`\\([-+]?\\)\"" w)
  4332. (setq w (replace-match "\\1" nil nil w)))
  4333. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4334. (push w wds))
  4335. (setq words (nreverse wds))))
  4336. (if boolean
  4337. (mapc (lambda (w)
  4338. (setq c (string-to-char w))
  4339. (if (equal c ?-)
  4340. (setq neg t w (substring w 1))
  4341. (if (equal c ?+)
  4342. (setq neg nil w (substring w 1))
  4343. (setq neg nil)))
  4344. (if (string-match "\\`{.*}\\'" w)
  4345. (setq re (substring w 1 -1))
  4346. (if full-words
  4347. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4348. (setq re (regexp-quote (downcase w)))))
  4349. (if neg (push re regexps-) (push re regexps+)))
  4350. words)
  4351. (push (mapconcat #'regexp-quote words "\\s-+")
  4352. regexps+))
  4353. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4354. (if (not regexps+)
  4355. (setq regexp org-outline-regexp-bol)
  4356. (setq regexp (pop regexps+))
  4357. (when hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4358. regexp))))
  4359. (setq files (org-agenda-files nil 'ifmode))
  4360. ;; Add `org-agenda-text-search-extra-files' unless there is some
  4361. ;; restriction.
  4362. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4363. (pop org-agenda-text-search-extra-files)
  4364. (unless (get 'org-agenda-files 'org-restrict)
  4365. (setq files (org-add-archive-files files))))
  4366. ;; Uniquify files. However, let `org-check-agenda-file' handle
  4367. ;; non-existent ones.
  4368. (setq files (cl-remove-duplicates
  4369. (append files org-agenda-text-search-extra-files)
  4370. :test (lambda (a b)
  4371. (and (file-exists-p a)
  4372. (file-exists-p b)
  4373. (file-equal-p a b))))
  4374. rtnall nil)
  4375. (while (setq file (pop files))
  4376. (setq ee nil)
  4377. (catch 'nextfile
  4378. (org-check-agenda-file file)
  4379. (setq buffer (if (file-exists-p file)
  4380. (org-get-agenda-file-buffer file)
  4381. (error "No such file %s" file)))
  4382. (unless buffer
  4383. ;; If file does not exist, make sure an error message is sent
  4384. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4385. file))))
  4386. (with-current-buffer buffer
  4387. (with-syntax-table (org-search-syntax-table)
  4388. (unless (derived-mode-p 'org-mode)
  4389. (error "Agenda file %s is not in Org mode" file))
  4390. (let ((case-fold-search t))
  4391. (save-excursion
  4392. (save-restriction
  4393. (if (eq buffer org-agenda-restrict)
  4394. (narrow-to-region org-agenda-restrict-begin
  4395. org-agenda-restrict-end)
  4396. (widen))
  4397. (goto-char (point-min))
  4398. (unless (or (org-at-heading-p)
  4399. (outline-next-heading))
  4400. (throw 'nextfile t))
  4401. (goto-char (max (point-min) (1- (point))))
  4402. (while (re-search-forward regexp nil t)
  4403. (org-back-to-heading t)
  4404. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4405. (> (org-reduced-level (org-outline-level))
  4406. org-agenda-search-view-max-outline-level)
  4407. (forward-line -1)
  4408. (org-back-to-heading t)))
  4409. (skip-chars-forward "* ")
  4410. (setq beg (line-beginning-position)
  4411. beg1 (point)
  4412. end (progn
  4413. (outline-next-heading)
  4414. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4415. (> (org-reduced-level (org-outline-level))
  4416. org-agenda-search-view-max-outline-level)
  4417. (forward-line 1)
  4418. (outline-next-heading)))
  4419. (point)))
  4420. (catch :skip
  4421. (goto-char beg)
  4422. (org-agenda-skip)
  4423. (setq str (buffer-substring-no-properties
  4424. (line-beginning-position)
  4425. (if hdl-only (line-end-position) end)))
  4426. (mapc (lambda (wr) (when (string-match wr str)
  4427. (goto-char (1- end))
  4428. (throw :skip t)))
  4429. regexps-)
  4430. (mapc (lambda (wr) (unless (string-match wr str)
  4431. (goto-char (1- end))
  4432. (throw :skip t)))
  4433. (if todo-only
  4434. (cons (concat "^\\*+[ \t]+"
  4435. org-not-done-regexp)
  4436. regexps+)
  4437. regexps+))
  4438. (goto-char beg)
  4439. (setq marker (org-agenda-new-marker (point))
  4440. category (org-get-category)
  4441. level (make-string (org-reduced-level (org-outline-level)) ? )
  4442. inherited-tags
  4443. (or (eq org-agenda-show-inherited-tags 'always)
  4444. (and (listp org-agenda-show-inherited-tags)
  4445. (memq 'todo org-agenda-show-inherited-tags))
  4446. (and (eq org-agenda-show-inherited-tags t)
  4447. (or (eq org-agenda-use-tag-inheritance t)
  4448. (memq 'todo org-agenda-use-tag-inheritance))))
  4449. tags (org-get-tags nil (not inherited-tags))
  4450. txt (org-agenda-format-item
  4451. ""
  4452. (buffer-substring-no-properties
  4453. beg1 (line-end-position))
  4454. level category tags t))
  4455. (org-add-props txt props
  4456. 'org-marker marker 'org-hd-marker marker
  4457. 'org-todo-regexp org-todo-regexp
  4458. 'level level
  4459. 'org-complex-heading-regexp org-complex-heading-regexp
  4460. 'priority 1000
  4461. 'type "search")
  4462. (push txt ee)
  4463. (goto-char (1- end))))))))))
  4464. (setq rtn (nreverse ee))
  4465. (setq rtnall (append rtnall rtn)))
  4466. (org-agenda--insert-overriding-header
  4467. (with-temp-buffer
  4468. (insert "Search words: ")
  4469. (add-text-properties (point-min) (1- (point))
  4470. (list 'face 'org-agenda-structure))
  4471. (setq pos (point))
  4472. (insert string "\n")
  4473. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4474. (setq pos (point))
  4475. (unless org-agenda-multi
  4476. (insert (substitute-command-keys "\\<org-agenda-mode-map>\
  4477. Press `\\[org-agenda-manipulate-query-add]', \
  4478. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4479. `\\[org-agenda-manipulate-query-add-re]', \
  4480. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4481. `\\[universal-argument] \\[org-agenda-redo]' for a fresh search\n"))
  4482. (add-text-properties pos (1- (point))
  4483. (list 'face 'org-agenda-structure-secondary)))
  4484. (buffer-string)))
  4485. (org-agenda-mark-header-line (point-min))
  4486. (when rtnall
  4487. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4488. (goto-char (point-min))
  4489. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4490. (add-text-properties (point-min) (point-max)
  4491. `(org-agenda-type search
  4492. org-last-args (,todo-only ,string ,edit-at)
  4493. org-redo-cmd ,org-agenda-redo-command
  4494. org-series-cmd ,org-cmd))
  4495. (org-agenda-finalize)
  4496. (setq buffer-read-only t))))
  4497. ;;; Agenda TODO list
  4498. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4499. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4500. (concat
  4501. (if (or (equal keywords "ALL") (not keywords))
  4502. (propertize "ALL" 'face 'org-agenda-structure-filter)
  4503. (mapconcat
  4504. (lambda (kw)
  4505. (propertize kw 'face (list (org-get-todo-face kw) 'org-agenda-structure)))
  4506. (org-split-string keywords "|")
  4507. "|"))
  4508. "\n"))
  4509. (defvar org-select-this-todo-keyword nil)
  4510. (defvar org-last-arg nil)
  4511. (defvar crm-separator)
  4512. ;;;###autoload
  4513. (defun org-todo-list (&optional arg)
  4514. "Show all (not done) TODO entries from all agenda files in a single list.
  4515. The prefix arg can be used to select a specific TODO keyword and limit
  4516. the list to these. When using `\\[universal-argument]', you will be prompted
  4517. for a keyword. A numeric prefix directly selects the Nth keyword in
  4518. `org-todo-keywords-1'."
  4519. (interactive "P")
  4520. (when org-agenda-overriding-arguments
  4521. (setq arg org-agenda-overriding-arguments))
  4522. (when (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4523. (let* ((today (org-today))
  4524. (date (calendar-gregorian-from-absolute today))
  4525. (completion-ignore-case t)
  4526. kwds org-select-this-todo-keyword rtn rtnall files file pos)
  4527. (catch 'exit
  4528. (setq org-agenda-buffer-name
  4529. (org-agenda--get-buffer-name
  4530. (and org-agenda-sticky
  4531. (if (stringp org-select-this-todo-keyword)
  4532. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4533. org-select-this-todo-keyword)
  4534. (format "*Org Agenda(%s)*" (or org-keys "t"))))))
  4535. (org-agenda-prepare "TODO")
  4536. (setq kwds org-todo-keywords-for-agenda
  4537. org-select-this-todo-keyword (if (stringp arg) arg
  4538. (and (integerp arg)
  4539. (> arg 0)
  4540. (nth (1- arg) kwds))))
  4541. (when (equal arg '(4))
  4542. (setq org-select-this-todo-keyword
  4543. (mapconcat #'identity
  4544. (let ((crm-separator "|"))
  4545. (completing-read-multiple
  4546. "Keyword (or KWD1|KWD2|...): "
  4547. (mapcar #'list kwds) nil nil))
  4548. "|")))
  4549. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4550. (org-compile-prefix-format 'todo)
  4551. (org-set-sorting-strategy 'todo)
  4552. (setq org-agenda-redo-command
  4553. `(org-todo-list (or (and (numberp current-prefix-arg)
  4554. current-prefix-arg)
  4555. ,org-select-this-todo-keyword
  4556. current-prefix-arg ,arg)))
  4557. (setq files (org-agenda-files nil 'ifmode)
  4558. rtnall nil)
  4559. (while (setq file (pop files))
  4560. (catch 'nextfile
  4561. (org-check-agenda-file file)
  4562. (setq rtn (org-agenda-get-day-entries file date :todo))
  4563. (setq rtnall (append rtnall rtn))))
  4564. (org-agenda--insert-overriding-header
  4565. (with-temp-buffer
  4566. (insert "Global list of TODO items of type: ")
  4567. (add-text-properties (point-min) (1- (point))
  4568. (list 'face 'org-agenda-structure
  4569. 'short-heading
  4570. (concat "ToDo: "
  4571. (or org-select-this-todo-keyword "ALL"))))
  4572. (org-agenda-mark-header-line (point-min))
  4573. (insert (org-agenda-propertize-selected-todo-keywords
  4574. org-select-this-todo-keyword))
  4575. (setq pos (point))
  4576. (unless org-agenda-multi
  4577. (insert (substitute-command-keys "Press \
  4578. \\<org-agenda-mode-map>`N \\[org-agenda-redo]' (e.g. `0 \\[org-agenda-redo]') \
  4579. to search again: (0)[ALL]"))
  4580. (let ((n 0))
  4581. (dolist (k kwds)
  4582. (let ((s (format "(%d)%s" (cl-incf n) k)))
  4583. (when (> (+ (current-column) (string-width s) 1) (window-max-chars-per-line))
  4584. (insert "\n "))
  4585. (insert " " s))))
  4586. (insert "\n"))
  4587. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-secondary))
  4588. (buffer-string)))
  4589. (org-agenda-mark-header-line (point-min))
  4590. (when rtnall
  4591. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4592. (goto-char (point-min))
  4593. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4594. (add-text-properties (point-min) (point-max)
  4595. `(org-agenda-type todo
  4596. org-last-args ,arg
  4597. org-redo-cmd ,org-agenda-redo-command
  4598. org-series-cmd ,org-cmd))
  4599. (org-agenda-finalize)
  4600. (setq buffer-read-only t))))
  4601. ;;; Agenda tags match
  4602. ;;;###autoload
  4603. (defun org-tags-view (&optional todo-only match)
  4604. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4605. The prefix arg TODO-ONLY limits the search to TODO entries."
  4606. (interactive "P")
  4607. (when org-agenda-overriding-arguments
  4608. (setq todo-only (car org-agenda-overriding-arguments)
  4609. match (nth 1 org-agenda-overriding-arguments)))
  4610. (let* ((org-tags-match-list-sublevels
  4611. org-tags-match-list-sublevels)
  4612. (completion-ignore-case t)
  4613. (org--matcher-tags-todo-only todo-only)
  4614. rtn rtnall files file pos matcher
  4615. buffer)
  4616. (when (and (stringp match) (not (string-match "\\S-" match)))
  4617. (setq match nil))
  4618. (catch 'exit
  4619. (setq org-agenda-buffer-name
  4620. (org-agenda--get-buffer-name
  4621. (and org-agenda-sticky
  4622. (if (stringp match)
  4623. (format "*Org Agenda(%s:%s)*"
  4624. (or org-keys (or (and todo-only "M") "m"))
  4625. match)
  4626. (format "*Org Agenda(%s)*"
  4627. (or (and todo-only "M") "m"))))))
  4628. (setq matcher (org-make-tags-matcher match))
  4629. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4630. ;; expanding tags within `org-make-tags-matcher'
  4631. (org-agenda-prepare (concat "TAGS " match))
  4632. (setq match (car matcher)
  4633. matcher (cdr matcher))
  4634. (org-compile-prefix-format 'tags)
  4635. (org-set-sorting-strategy 'tags)
  4636. (setq org-agenda-query-string match)
  4637. (setq org-agenda-redo-command
  4638. (list 'org-tags-view
  4639. `(quote ,org--matcher-tags-todo-only)
  4640. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4641. (setq files (org-agenda-files nil 'ifmode)
  4642. rtnall nil)
  4643. (while (setq file (pop files))
  4644. (catch 'nextfile
  4645. (org-check-agenda-file file)
  4646. (setq buffer (if (file-exists-p file)
  4647. (org-get-agenda-file-buffer file)
  4648. (error "No such file %s" file)))
  4649. (if (not buffer)
  4650. ;; If file does not exist, error message to agenda
  4651. (setq rtn (list
  4652. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4653. rtnall (append rtnall rtn))
  4654. (with-current-buffer buffer
  4655. (unless (derived-mode-p 'org-mode)
  4656. (error "Agenda file %s is not in Org mode" file))
  4657. (save-excursion
  4658. (save-restriction
  4659. (if (eq buffer org-agenda-restrict)
  4660. (narrow-to-region org-agenda-restrict-begin
  4661. org-agenda-restrict-end)
  4662. (widen))
  4663. (setq rtn (org-scan-tags 'agenda
  4664. matcher
  4665. org--matcher-tags-todo-only))
  4666. (setq rtnall (append rtnall rtn))))))))
  4667. (org-agenda--insert-overriding-header
  4668. (with-temp-buffer
  4669. (insert "Headlines with TAGS match: ")
  4670. (add-text-properties (point-min) (1- (point))
  4671. (list 'face 'org-agenda-structure
  4672. 'short-heading
  4673. (concat "Match: " match)))
  4674. (setq pos (point))
  4675. (insert match "\n")
  4676. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4677. (setq pos (point))
  4678. (unless org-agenda-multi
  4679. (insert (substitute-command-keys
  4680. "Press \
  4681. \\<org-agenda-mode-map>`\\[universal-argument] \\[org-agenda-redo]' \
  4682. to search again\n")))
  4683. (add-text-properties pos (1- (point))
  4684. (list 'face 'org-agenda-structure-secondary))
  4685. (buffer-string)))
  4686. (org-agenda-mark-header-line (point-min))
  4687. (when rtnall
  4688. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4689. (goto-char (point-min))
  4690. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4691. (add-text-properties
  4692. (point-min) (point-max)
  4693. `(org-agenda-type tags
  4694. org-last-args (,org--matcher-tags-todo-only ,match)
  4695. org-redo-cmd ,org-agenda-redo-command
  4696. org-series-cmd ,org-cmd))
  4697. (org-agenda-finalize)
  4698. (setq buffer-read-only t))))
  4699. ;;; Agenda Finding stuck projects
  4700. (defvar org-agenda-skip-regexp nil
  4701. "Regular expression used in skipping subtrees for the agenda.
  4702. This is basically a temporary global variable that can be set and then
  4703. used by user-defined selections using `org-agenda-skip-function'.")
  4704. (defvar org-agenda-overriding-header nil
  4705. "When set during agenda, todo and tags searches it replaces the header.
  4706. If an empty string, no header will be inserted. If any other
  4707. string, it will be inserted as a header. If a function, insert
  4708. the string returned by the function as a header. If nil, a
  4709. header will be generated automatically according to the command.
  4710. This variable should not be set directly, but custom commands can
  4711. bind it in the options section.")
  4712. (defun org-agenda-skip-entry-if (&rest conditions)
  4713. "Skip entry if any of CONDITIONS is true.
  4714. See `org-agenda-skip-if' for details about CONDITIONS.
  4715. This function can be put into `org-agenda-skip-function' for the
  4716. duration of a command."
  4717. (org-agenda-skip-if nil conditions))
  4718. (defun org-agenda-skip-subtree-if (&rest conditions)
  4719. "Skip subtree if any of CONDITIONS is true.
  4720. See `org-agenda-skip-if' for details about CONDITIONS.
  4721. This function can be put into `org-agenda-skip-function' for the
  4722. duration of a command."
  4723. (org-agenda-skip-if t conditions))
  4724. (defun org-agenda-skip-if (subtree conditions)
  4725. "Check current entity for CONDITIONS.
  4726. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4727. the entry (i.e. the text before the next heading) is checked.
  4728. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4729. from different tests. Valid conditions are:
  4730. scheduled Check if there is a scheduled cookie
  4731. notscheduled Check if there is no scheduled cookie
  4732. deadline Check if there is a deadline
  4733. notdeadline Check if there is no deadline
  4734. timestamp Check if there is a timestamp (also deadline or scheduled)
  4735. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4736. regexp Check if regexp matches
  4737. notregexp Check if regexp does not match.
  4738. todo Check if TODO keyword matches
  4739. nottodo Check if TODO keyword does not match
  4740. The regexp is taken from the conditions list, and must come right
  4741. after the `regexp' or `notregexp' element.
  4742. `todo' and `nottodo' accept as an argument a list of todo
  4743. keywords, which may include \"*\" to match any todo keyword.
  4744. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4745. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4746. Instead of a list, a keyword class may be given. For example:
  4747. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4748. would skip entries that haven't been marked with any of \"DONE\"
  4749. keywords. Possible classes are: `todo', `done', `any'.
  4750. If any of these conditions is met, this function returns the end point of
  4751. the entity, causing the search to continue from there. This is a function
  4752. that can be put into `org-agenda-skip-function' for the duration of a command."
  4753. (org-back-to-heading t)
  4754. (let* (;; (beg (point))
  4755. (end (if subtree (save-excursion (org-end-of-subtree t) (point))
  4756. (org-entry-end-position)))
  4757. (planning-end (if subtree end (line-end-position 2)))
  4758. m)
  4759. (and
  4760. (or (and (memq 'scheduled conditions)
  4761. (re-search-forward org-scheduled-time-regexp planning-end t))
  4762. (and (memq 'notscheduled conditions)
  4763. (not
  4764. (save-excursion
  4765. (re-search-forward org-scheduled-time-regexp planning-end t))))
  4766. (and (memq 'deadline conditions)
  4767. (re-search-forward org-deadline-time-regexp planning-end t))
  4768. (and (memq 'notdeadline conditions)
  4769. (not
  4770. (save-excursion
  4771. (re-search-forward org-deadline-time-regexp planning-end t))))
  4772. (and (memq 'timestamp conditions)
  4773. (re-search-forward org-ts-regexp end t))
  4774. (and (memq 'nottimestamp conditions)
  4775. (not (save-excursion (re-search-forward org-ts-regexp end t))))
  4776. (and (setq m (memq 'regexp conditions))
  4777. (stringp (nth 1 m))
  4778. (re-search-forward (nth 1 m) end t))
  4779. (and (setq m (memq 'notregexp conditions))
  4780. (stringp (nth 1 m))
  4781. (not (save-excursion (re-search-forward (nth 1 m) end t))))
  4782. (and (or
  4783. (setq m (memq 'nottodo conditions))
  4784. (setq m (memq 'todo-unblocked conditions))
  4785. (setq m (memq 'nottodo-unblocked conditions))
  4786. (setq m (memq 'todo conditions)))
  4787. (org-agenda-skip-if-todo m end)))
  4788. end)))
  4789. (defun org-agenda-skip-if-todo (args end)
  4790. "Helper function for `org-agenda-skip-if', do not use it directly.
  4791. ARGS is a list with first element either `todo', `nottodo',
  4792. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4793. a list of TODO keywords, or a state symbol `todo' or `done' or
  4794. `any'."
  4795. (let ((todo-re
  4796. (concat "^\\*+[ \t]+"
  4797. (regexp-opt
  4798. (pcase args
  4799. (`(,_ todo)
  4800. (org-delete-all org-done-keywords
  4801. (copy-sequence org-todo-keywords-1)))
  4802. (`(,_ done) org-done-keywords)
  4803. (`(,_ any) org-todo-keywords-1)
  4804. (`(,_ ,(pred atom))
  4805. (error "Invalid TODO class or type: %S" args))
  4806. (`(,_ ,(pred (member "*"))) org-todo-keywords-1)
  4807. (`(,_ ,todo-list) todo-list))
  4808. 'words))))
  4809. (pcase args
  4810. (`(todo . ,_)
  4811. (let (case-fold-search) (re-search-forward todo-re end t)))
  4812. (`(nottodo . ,_)
  4813. (not (let (case-fold-search) (re-search-forward todo-re end t))))
  4814. (`(todo-unblocked . ,_)
  4815. (catch :unblocked
  4816. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4817. (when (org-entry-blocked-p) (throw :unblocked t)))
  4818. nil))
  4819. (`(nottodo-unblocked . ,_)
  4820. (catch :unblocked
  4821. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4822. (when (org-entry-blocked-p) (throw :unblocked nil)))
  4823. t))
  4824. (`(,type . ,_) (error "Unknown TODO skip type: %S" type)))))
  4825. ;;;###autoload
  4826. (defun org-agenda-list-stuck-projects (&rest _ignore)
  4827. "Create agenda view for projects that are stuck.
  4828. Stuck projects are project that have no next actions. For the definitions
  4829. of what a project is and how to check if it stuck, customize the variable
  4830. `org-stuck-projects'."
  4831. (interactive)
  4832. (let* ((org-agenda-overriding-header
  4833. (or org-agenda-overriding-header "List of stuck projects: "))
  4834. (matcher (nth 0 org-stuck-projects))
  4835. (todo (nth 1 org-stuck-projects))
  4836. (tags (nth 2 org-stuck-projects))
  4837. (gen-re (org-string-nw-p (nth 3 org-stuck-projects)))
  4838. (todo-wds
  4839. (if (not (member "*" todo)) todo
  4840. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  4841. (org-delete-all org-done-keywords-for-agenda
  4842. (copy-sequence org-todo-keywords-for-agenda))))
  4843. (todo-re (and todo
  4844. (format "^\\*+[ \t]+\\(%s\\)\\>"
  4845. (mapconcat #'identity todo-wds "\\|"))))
  4846. (tags-re (cond ((null tags) nil)
  4847. ((member "*" tags) org-tag-line-re)
  4848. (tags
  4849. (let ((other-tags (format "\\(?:%s:\\)*" org-tag-re)))
  4850. (concat org-outline-regexp-bol
  4851. ".*?[ \t]:"
  4852. other-tags
  4853. (regexp-opt tags t)
  4854. ":" other-tags "[ \t]*$")))
  4855. (t nil)))
  4856. (re-list (delq nil (list todo-re tags-re gen-re)))
  4857. (skip-re
  4858. (if (null re-list)
  4859. (error "Missing information to identify unstuck projects")
  4860. (mapconcat #'identity re-list "\\|")))
  4861. (org-agenda-skip-function
  4862. ;; Skip entry if `org-agenda-skip-regexp' matches anywhere
  4863. ;; in the subtree.
  4864. (lambda ()
  4865. (and (save-excursion
  4866. (let ((case-fold-search nil))
  4867. (re-search-forward
  4868. skip-re (save-excursion (org-end-of-subtree t)) t)))
  4869. (progn (outline-next-heading) (point))))))
  4870. (org-tags-view nil matcher)
  4871. (setq org-agenda-buffer-name (buffer-name))
  4872. (with-current-buffer org-agenda-buffer-name
  4873. (setq org-agenda-redo-command
  4874. `(org-agenda-list-stuck-projects ,current-prefix-arg))
  4875. (let ((inhibit-read-only t))
  4876. (add-text-properties
  4877. (point-min) (point-max)
  4878. `(org-redo-cmd ,org-agenda-redo-command))))))
  4879. ;;; Diary integration
  4880. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4881. (defvar diary-list-entries-hook)
  4882. (defvar diary-time-regexp)
  4883. (defvar diary-modify-entry-list-string-function)
  4884. (defvar diary-file-name-prefix)
  4885. (defvar diary-display-function)
  4886. (defun org-get-entries-from-diary (date)
  4887. "Get the (Emacs Calendar) diary entries for DATE."
  4888. (require 'diary-lib)
  4889. (declare-function diary-fancy-display "diary-lib" ())
  4890. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4891. (diary-display-function #'diary-fancy-display)
  4892. (pop-up-frames nil)
  4893. (diary-list-entries-hook
  4894. (cons 'org-diary-default-entry diary-list-entries-hook))
  4895. (diary-file-name-prefix nil) ; turn this feature off
  4896. (diary-modify-entry-list-string-function
  4897. #'org-modify-diary-entry-string)
  4898. (diary-time-regexp (concat "^" diary-time-regexp))
  4899. entries
  4900. (org-disable-agenda-to-diary t))
  4901. (save-excursion
  4902. (save-window-excursion
  4903. (diary-list-entries date 1)))
  4904. (if (not (get-buffer diary-fancy-buffer))
  4905. (setq entries nil)
  4906. (with-current-buffer diary-fancy-buffer
  4907. (setq buffer-read-only nil)
  4908. (if (zerop (buffer-size))
  4909. ;; No entries
  4910. (setq entries nil)
  4911. ;; Omit the date and other unnecessary stuff
  4912. (org-agenda-cleanup-fancy-diary)
  4913. ;; Add prefix to each line and extend the text properties
  4914. (if (zerop (buffer-size))
  4915. (setq entries nil)
  4916. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4917. (setq entries
  4918. (with-temp-buffer
  4919. (insert entries) (goto-char (point-min))
  4920. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4921. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4922. (replace-match (concat "; " (match-string 1)))))
  4923. (buffer-string)))))
  4924. (set-buffer-modified-p nil)
  4925. (kill-buffer diary-fancy-buffer)))
  4926. (when entries
  4927. (setq entries (org-split-string entries "\n"))
  4928. (setq entries
  4929. (mapcar
  4930. (lambda (x)
  4931. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4932. ;; Extend the text properties to the beginning of the line
  4933. (org-add-props x (text-properties-at (1- (length x)) x)
  4934. 'type "diary" 'date date 'face 'org-agenda-diary))
  4935. entries)))))
  4936. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4937. "Hook run when the fancy diary buffer is cleaned up.")
  4938. (defun org-agenda-cleanup-fancy-diary ()
  4939. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4940. This gets rid of the date, the underline under the date, and the
  4941. dummy entry installed by Org mode to ensure non-empty diary for
  4942. each date. It also removes lines that contain only whitespace."
  4943. (goto-char (point-min))
  4944. (if (looking-at ".*?:[ \t]*")
  4945. (progn
  4946. (replace-match "")
  4947. (re-search-forward "\n=+$" nil t)
  4948. (replace-match "")
  4949. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4950. (re-search-forward "\n=+$" nil t)
  4951. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4952. (goto-char (point-min))
  4953. (while (re-search-forward "^ +\n" nil t)
  4954. (replace-match ""))
  4955. (goto-char (point-min))
  4956. (when (re-search-forward "^Org mode dummy\n?" nil t)
  4957. (replace-match ""))
  4958. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4959. (defun org-modify-diary-entry-string (string)
  4960. "Add text properties to string, allowing Org to act on it."
  4961. (org-add-props string nil
  4962. 'mouse-face 'highlight
  4963. 'help-echo (if buffer-file-name
  4964. (format "mouse-2 or RET jump to diary file %s"
  4965. (abbreviate-file-name buffer-file-name))
  4966. "")
  4967. 'org-agenda-diary-link t
  4968. 'org-marker (org-agenda-new-marker (line-beginning-position))))
  4969. (defun org-diary-default-entry ()
  4970. "Add a dummy entry to the diary.
  4971. Needed to avoid empty dates which mess up holiday display."
  4972. ;; Catch the error if dealing with the new add-to-diary-alist
  4973. (when org-disable-agenda-to-diary
  4974. (diary-add-to-list original-date "Org mode dummy" "")))
  4975. (defvar org-diary-last-run-time nil)
  4976. ;;;###autoload
  4977. (defun org-diary (&rest args)
  4978. "Return diary information from org files.
  4979. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4980. It accesses org files and extracts information from those files to be
  4981. listed in the diary. The function accepts arguments specifying what
  4982. items should be listed. For a list of arguments allowed here, see the
  4983. variable `org-agenda-entry-types'.
  4984. The call in the diary file should look like this:
  4985. &%%(org-diary) ~/path/to/some/orgfile.org
  4986. Use a separate line for each org file to check. Or, if you omit the file name,
  4987. all files listed in `org-agenda-files' will be checked automatically:
  4988. &%%(org-diary)
  4989. If you don't give any arguments (as in the example above), the default value
  4990. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4991. So the example above may also be written as
  4992. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4993. The function expects the lisp variables `entry' and `date' to be provided
  4994. by the caller, because this is how the calendar works. Don't use this
  4995. function from a program - use `org-agenda-get-day-entries' instead."
  4996. (with-no-warnings (defvar date) (defvar entry))
  4997. (when (> (- (float-time)
  4998. org-agenda-last-marker-time)
  4999. 5)
  5000. ;; I am not sure if this works with sticky agendas, because the marker
  5001. ;; list is then no longer a global variable.
  5002. (org-agenda-reset-markers))
  5003. (org-compile-prefix-format 'agenda)
  5004. (org-set-sorting-strategy 'agenda)
  5005. (setq args (or args org-agenda-entry-types))
  5006. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  5007. (list entry)
  5008. (org-agenda-files t)))
  5009. (time (float-time))
  5010. file rtn results)
  5011. (when (or (not org-diary-last-run-time)
  5012. (> (- time
  5013. org-diary-last-run-time)
  5014. 3))
  5015. (org-agenda-prepare-buffers files))
  5016. (setq org-diary-last-run-time time)
  5017. ;; If this is called during org-agenda, don't return any entries to
  5018. ;; the calendar. Org Agenda will list these entries itself.
  5019. (when org-disable-agenda-to-diary (setq files nil))
  5020. (while (setq file (pop files))
  5021. (setq rtn (apply #'org-agenda-get-day-entries file date args))
  5022. (setq results (append results rtn)))
  5023. (when results
  5024. (setq results
  5025. (mapcar (lambda (i) (replace-regexp-in-string
  5026. org-link-bracket-re "\\2" i))
  5027. results))
  5028. (concat (org-agenda-finalize-entries results) "\n"))))
  5029. ;;; Agenda entry finders
  5030. (defun org-agenda--timestamp-to-absolute (&rest args)
  5031. "Call `org-time-string-to-absolute' with ARGS.
  5032. However, throw `:skip' whenever an error is raised."
  5033. (condition-case e
  5034. (apply #'org-time-string-to-absolute args)
  5035. (org-diary-sexp-no-match (throw :skip nil))
  5036. (error
  5037. (message "%s; Skipping entry" (error-message-string e))
  5038. (throw :skip nil))))
  5039. (defun org-agenda-get-day-entries (file date &rest args)
  5040. "Does the work for `org-diary' and `org-agenda'.
  5041. FILE is the path to a file to be checked for entries. DATE is date like
  5042. the one returned by `calendar-current-date'. ARGS are symbols indicating
  5043. which kind of entries should be extracted. For details about these, see
  5044. the documentation of `org-diary'."
  5045. (let* ((org-startup-folded nil)
  5046. (org-startup-align-all-tables nil)
  5047. (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
  5048. (error "No such file %s" file))))
  5049. (if (not buffer)
  5050. ;; If file does not exist, signal it in diary nonetheless.
  5051. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  5052. (with-current-buffer buffer
  5053. (unless (derived-mode-p 'org-mode)
  5054. (error "Agenda file %s is not in Org mode" file))
  5055. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  5056. (setf org-agenda-current-date date)
  5057. (save-excursion
  5058. (save-restriction
  5059. (if (eq buffer org-agenda-restrict)
  5060. (narrow-to-region org-agenda-restrict-begin
  5061. org-agenda-restrict-end)
  5062. (widen))
  5063. ;; Rationalize ARGS. Also make sure `:deadline' comes
  5064. ;; first in order to populate DEADLINES before passing it.
  5065. ;;
  5066. ;; We use `delq' since `org-uniquify' duplicates ARGS,
  5067. ;; guarding us from modifying `org-agenda-entry-types'.
  5068. (setf args (org-uniquify (or args org-agenda-entry-types)))
  5069. (when (and (memq :scheduled args) (memq :scheduled* args))
  5070. (setf args (delq :scheduled* args)))
  5071. (cond
  5072. ((memq :deadline args)
  5073. (setf args (cons :deadline
  5074. (delq :deadline (delq :deadline* args)))))
  5075. ((memq :deadline* args)
  5076. (setf args (cons :deadline* (delq :deadline* args)))))
  5077. ;; Collect list of headlines. Return them flattened.
  5078. (let ((case-fold-search nil) results deadlines)
  5079. (org-dlet
  5080. ((date date))
  5081. (dolist (arg args (apply #'nconc (nreverse results)))
  5082. (pcase arg
  5083. ((and :todo (guard (org-agenda-today-p date)))
  5084. (push (org-agenda-get-todos) results))
  5085. (:timestamp
  5086. (push (org-agenda-get-blocks) results)
  5087. (push (org-agenda-get-timestamps deadlines) results))
  5088. (:sexp
  5089. (push (org-agenda-get-sexps) results))
  5090. (:scheduled
  5091. (push (org-agenda-get-scheduled deadlines) results))
  5092. (:scheduled*
  5093. (push (org-agenda-get-scheduled deadlines t) results))
  5094. (:closed
  5095. (push (org-agenda-get-progress) results))
  5096. (:deadline
  5097. (setf deadlines (org-agenda-get-deadlines))
  5098. (push deadlines results))
  5099. (:deadline*
  5100. (setf deadlines (org-agenda-get-deadlines t))
  5101. (push deadlines results))))))))))))
  5102. (defsubst org-em (x y list)
  5103. "Is X or Y a member of LIST?"
  5104. (or (memq x list) (memq y list)))
  5105. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  5106. (defvar org-agenda-sorting-strategy-selected nil)
  5107. (defun org-agenda-entry-get-agenda-timestamp (pom)
  5108. "Retrieve timestamp information for sorting agenda views.
  5109. Given a point or marker POM, returns a cons cell of the timestamp
  5110. and the timestamp type relevant for the sorting strategy in
  5111. `org-agenda-sorting-strategy-selected'."
  5112. (let (ts ts-date-type)
  5113. (save-match-data
  5114. (cond ((org-em 'scheduled-up 'scheduled-down
  5115. org-agenda-sorting-strategy-selected)
  5116. (setq ts (org-entry-get pom "SCHEDULED")
  5117. ts-date-type " scheduled"))
  5118. ((org-em 'deadline-up 'deadline-down
  5119. org-agenda-sorting-strategy-selected)
  5120. (setq ts (org-entry-get pom "DEADLINE")
  5121. ts-date-type " deadline"))
  5122. ((org-em 'ts-up 'ts-down
  5123. org-agenda-sorting-strategy-selected)
  5124. (setq ts (org-entry-get pom "TIMESTAMP")
  5125. ts-date-type " timestamp"))
  5126. ((org-em 'tsia-up 'tsia-down
  5127. org-agenda-sorting-strategy-selected)
  5128. (setq ts (org-entry-get pom "TIMESTAMP_IA")
  5129. ts-date-type " timestamp_ia"))
  5130. ((org-em 'timestamp-up 'timestamp-down
  5131. org-agenda-sorting-strategy-selected)
  5132. (setq ts (or (org-entry-get pom "SCHEDULED")
  5133. (org-entry-get pom "DEADLINE")
  5134. (org-entry-get pom "TIMESTAMP")
  5135. (org-entry-get pom "TIMESTAMP_IA"))
  5136. ts-date-type ""))
  5137. (t (setq ts-date-type "")))
  5138. (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
  5139. ts-date-type))))
  5140. (defun org-agenda-get-todos ()
  5141. "Return the TODO information for agenda display."
  5142. (let* ((props (list 'face nil
  5143. 'done-face 'org-agenda-done
  5144. 'org-not-done-regexp org-not-done-regexp
  5145. 'org-todo-regexp org-todo-regexp
  5146. 'org-complex-heading-regexp org-complex-heading-regexp
  5147. 'mouse-face 'highlight
  5148. 'help-echo
  5149. (format "mouse-2 or RET jump to org file %s"
  5150. (abbreviate-file-name buffer-file-name))))
  5151. (case-fold-search nil)
  5152. (regexp (format org-heading-keyword-regexp-format
  5153. (cond
  5154. ((and org-select-this-todo-keyword
  5155. (equal org-select-this-todo-keyword "*"))
  5156. org-todo-regexp)
  5157. (org-select-this-todo-keyword
  5158. (concat "\\("
  5159. (mapconcat #'identity
  5160. (org-split-string
  5161. org-select-this-todo-keyword
  5162. "|")
  5163. "\\|")
  5164. "\\)"))
  5165. (t org-not-done-regexp))))
  5166. marker priority category level tags todo-state
  5167. ts-date ts-date-type ts-date-pair
  5168. ee txt beg end inherited-tags todo-state-end-pos
  5169. effort effort-minutes)
  5170. (goto-char (point-min))
  5171. (while (re-search-forward regexp nil t)
  5172. (catch :skip
  5173. (save-match-data
  5174. (beginning-of-line)
  5175. (org-agenda-skip)
  5176. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  5177. (unless (and (setq todo-state (org-get-todo-state))
  5178. (setq todo-state-end-pos (match-end 2)))
  5179. (goto-char end)
  5180. (throw :skip nil))
  5181. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  5182. (goto-char (1+ beg))
  5183. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  5184. (throw :skip nil)))
  5185. (goto-char (match-beginning 2))
  5186. (setq marker (org-agenda-new-marker (match-beginning 0))
  5187. category (org-get-category)
  5188. effort (save-match-data (or (get-text-property (point) 'effort)
  5189. (org-entry-get (point) org-effort-property)))
  5190. effort-minutes (when effort (save-match-data (org-duration-to-minutes effort)))
  5191. ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
  5192. ts-date (car ts-date-pair)
  5193. ts-date-type (cdr ts-date-pair)
  5194. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  5195. inherited-tags
  5196. (or (eq org-agenda-show-inherited-tags 'always)
  5197. (and (listp org-agenda-show-inherited-tags)
  5198. (memq 'todo org-agenda-show-inherited-tags))
  5199. (and (eq org-agenda-show-inherited-tags t)
  5200. (or (eq org-agenda-use-tag-inheritance t)
  5201. (memq 'todo org-agenda-use-tag-inheritance))))
  5202. tags (org-get-tags nil (not inherited-tags))
  5203. level (make-string (org-reduced-level (org-outline-level)) ? )
  5204. txt (org-agenda-format-item ""
  5205. (org-add-props txt nil
  5206. 'effort effort
  5207. 'effort-minutes effort-minutes)
  5208. level category tags t)
  5209. priority (1+ (org-get-priority txt)))
  5210. (org-add-props txt props
  5211. 'org-marker marker 'org-hd-marker marker
  5212. 'priority priority
  5213. 'effort effort 'effort-minutes effort-minutes
  5214. 'level level
  5215. 'ts-date ts-date
  5216. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  5217. (push txt ee)
  5218. (if org-agenda-todo-list-sublevels
  5219. (goto-char todo-state-end-pos)
  5220. (org-end-of-subtree 'invisible))))
  5221. (nreverse ee)))
  5222. (defun org-agenda-todo-custom-ignore-p (time n)
  5223. "Check whether timestamp is farther away than n number of days.
  5224. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5225. `org-agenda-todo-ignore-scheduled' or
  5226. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5227. (let ((days (org-time-stamp-to-now
  5228. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5229. (if (>= n 0)
  5230. (>= days n)
  5231. (<= days n))))
  5232. ;;;###autoload
  5233. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5234. (&optional end)
  5235. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5236. (when (or org-agenda-todo-ignore-with-date
  5237. org-agenda-todo-ignore-scheduled
  5238. org-agenda-todo-ignore-deadlines
  5239. org-agenda-todo-ignore-timestamp)
  5240. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5241. (save-excursion
  5242. (or (and org-agenda-todo-ignore-with-date
  5243. (re-search-forward org-ts-regexp end t))
  5244. (and org-agenda-todo-ignore-scheduled
  5245. (re-search-forward org-scheduled-time-regexp end t)
  5246. (cond
  5247. ((eq org-agenda-todo-ignore-scheduled 'future)
  5248. (> (org-time-stamp-to-now
  5249. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5250. 0))
  5251. ((eq org-agenda-todo-ignore-scheduled 'past)
  5252. (<= (org-time-stamp-to-now
  5253. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5254. 0))
  5255. ((numberp org-agenda-todo-ignore-scheduled)
  5256. (org-agenda-todo-custom-ignore-p
  5257. (match-string 1) org-agenda-todo-ignore-scheduled))
  5258. (t)))
  5259. (and org-agenda-todo-ignore-deadlines
  5260. (re-search-forward org-deadline-time-regexp end t)
  5261. (cond
  5262. ((eq org-agenda-todo-ignore-deadlines 'all) t)
  5263. ((eq org-agenda-todo-ignore-deadlines 'far)
  5264. (not (org-deadline-close-p (match-string 1))))
  5265. ((eq org-agenda-todo-ignore-deadlines 'future)
  5266. (> (org-time-stamp-to-now
  5267. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5268. 0))
  5269. ((eq org-agenda-todo-ignore-deadlines 'past)
  5270. (<= (org-time-stamp-to-now
  5271. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5272. 0))
  5273. ((numberp org-agenda-todo-ignore-deadlines)
  5274. (org-agenda-todo-custom-ignore-p
  5275. (match-string 1) org-agenda-todo-ignore-deadlines))
  5276. (t (org-deadline-close-p (match-string 1)))))
  5277. (and org-agenda-todo-ignore-timestamp
  5278. (let ((buffer (current-buffer))
  5279. (regexp
  5280. (concat
  5281. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5282. (start (point)))
  5283. ;; Copy current buffer into a temporary one
  5284. (with-temp-buffer
  5285. (insert-buffer-substring buffer start end)
  5286. (goto-char (point-min))
  5287. ;; Delete SCHEDULED and DEADLINE items
  5288. (while (re-search-forward regexp end t)
  5289. (delete-region (match-beginning 0) (match-end 0)))
  5290. (goto-char (point-min))
  5291. ;; No search for timestamp left
  5292. (when (re-search-forward org-ts-regexp nil t)
  5293. (cond
  5294. ((eq org-agenda-todo-ignore-timestamp 'future)
  5295. (> (org-time-stamp-to-now
  5296. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5297. 0))
  5298. ((eq org-agenda-todo-ignore-timestamp 'past)
  5299. (<= (org-time-stamp-to-now
  5300. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5301. 0))
  5302. ((numberp org-agenda-todo-ignore-timestamp)
  5303. (org-agenda-todo-custom-ignore-p
  5304. (match-string 1) org-agenda-todo-ignore-timestamp))
  5305. (t))))))))))
  5306. (defun org-agenda-get-timestamps (&optional deadlines)
  5307. "Return the date stamp information for agenda display.
  5308. Optional argument DEADLINES is a list of deadline items to be
  5309. displayed in agenda view."
  5310. (with-no-warnings (defvar date))
  5311. (let* ((props (list 'face 'org-agenda-calendar-event
  5312. 'org-not-done-regexp org-not-done-regexp
  5313. 'org-todo-regexp org-todo-regexp
  5314. 'org-complex-heading-regexp org-complex-heading-regexp
  5315. 'mouse-face 'highlight
  5316. 'help-echo
  5317. (format "mouse-2 or RET jump to Org file %s"
  5318. (abbreviate-file-name buffer-file-name))))
  5319. (current (calendar-absolute-from-gregorian date))
  5320. (today (org-today))
  5321. (deadline-position-alist
  5322. (mapcar (lambda (d)
  5323. (let ((m (get-text-property 0 'org-hd-marker d)))
  5324. (and m (marker-position m))))
  5325. deadlines))
  5326. ;; Match time-stamps set to current date, time-stamps with
  5327. ;; a repeater, and S-exp time-stamps.
  5328. (regexp
  5329. (concat
  5330. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5331. (regexp-quote
  5332. (substring
  5333. (format-time-string
  5334. (car org-time-stamp-formats)
  5335. (org-encode-time ; DATE bound by calendar
  5336. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5337. 1 11))
  5338. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5339. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5340. timestamp-items)
  5341. (goto-char (point-min))
  5342. (while (re-search-forward regexp nil t)
  5343. ;; Skip date ranges, scheduled and deadlines, which are handled
  5344. ;; specially. Also skip time-stamps before first headline as
  5345. ;; there would be no entry to add to the agenda. Eventually,
  5346. ;; ignore clock entries.
  5347. (catch :skip
  5348. (save-match-data
  5349. (when (or (org-at-date-range-p)
  5350. (org-at-planning-p)
  5351. (org-before-first-heading-p)
  5352. (and org-agenda-include-inactive-timestamps
  5353. (org-at-clock-log-p))
  5354. (not (org-at-timestamp-p 'agenda)))
  5355. (throw :skip nil))
  5356. (org-agenda-skip (org-element-at-point)))
  5357. (let* ((pos (match-beginning 0))
  5358. (repeat (match-string 1))
  5359. (sexp-entry (match-string 3))
  5360. (time-stamp (if (or repeat sexp-entry) (match-string 0)
  5361. (save-excursion
  5362. (goto-char pos)
  5363. (looking-at org-ts-regexp-both)
  5364. (match-string 0))))
  5365. (todo-state (org-get-todo-state))
  5366. (warntime (get-text-property (point) 'org-appt-warntime))
  5367. (done? (member todo-state org-done-keywords)))
  5368. ;; Possibly skip done tasks.
  5369. (when (and done? org-agenda-skip-timestamp-if-done)
  5370. (throw :skip t))
  5371. ;; S-exp entry doesn't match current day: skip it.
  5372. (when (and sexp-entry (not (org-diary-sexp-entry sexp-entry "" date)))
  5373. (throw :skip nil))
  5374. (when repeat
  5375. (let* ((past
  5376. ;; A repeating time stamp is shown at its base
  5377. ;; date and every repeated date up to TODAY. If
  5378. ;; `org-agenda-prefer-last-repeat' is non-nil,
  5379. ;; however, only the last repeat before today
  5380. ;; (inclusive) is shown.
  5381. (org-agenda--timestamp-to-absolute
  5382. repeat
  5383. (if (or (> current today)
  5384. (eq org-agenda-prefer-last-repeat t)
  5385. (member todo-state org-agenda-prefer-last-repeat))
  5386. today
  5387. current)
  5388. 'past (current-buffer) pos))
  5389. (future
  5390. ;; Display every repeated date past TODAY
  5391. ;; (exclusive) unless
  5392. ;; `org-agenda-show-future-repeats' is nil. If
  5393. ;; this variable is set to `next', only display
  5394. ;; the first repeated date after TODAY
  5395. ;; (exclusive).
  5396. (cond
  5397. ((<= current today) past)
  5398. ((not org-agenda-show-future-repeats) past)
  5399. (t
  5400. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5401. (1+ today)
  5402. current)))
  5403. (org-agenda--timestamp-to-absolute
  5404. repeat base 'future (current-buffer) pos))))))
  5405. (when (and (/= current past) (/= current future))
  5406. (throw :skip nil))))
  5407. (save-excursion
  5408. (re-search-backward org-outline-regexp-bol nil t)
  5409. ;; Possibly skip time-stamp when a deadline is set.
  5410. (when (and org-agenda-skip-timestamp-if-deadline-is-shown
  5411. (assq (point) deadline-position-alist))
  5412. (throw :skip nil))
  5413. (let* ((category (org-get-category pos))
  5414. (effort (org-entry-get pos org-effort-property))
  5415. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5416. (inherited-tags
  5417. (or (eq org-agenda-show-inherited-tags 'always)
  5418. (and (consp org-agenda-show-inherited-tags)
  5419. (memq 'agenda org-agenda-show-inherited-tags))
  5420. (and (eq org-agenda-show-inherited-tags t)
  5421. (or (eq org-agenda-use-tag-inheritance t)
  5422. (memq 'agenda
  5423. org-agenda-use-tag-inheritance)))))
  5424. (tags (org-get-tags nil (not inherited-tags)))
  5425. (level (make-string (org-reduced-level (org-outline-level))
  5426. ?\s))
  5427. (head (and (looking-at "\\*+[ \t]+\\(.*\\)")
  5428. (match-string 1)))
  5429. (inactive? (= (char-after pos) ?\[))
  5430. (habit? (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5431. (item
  5432. (org-agenda-format-item
  5433. (and inactive? org-agenda-inactive-leader)
  5434. (org-add-props head nil
  5435. 'effort effort
  5436. 'effort-minutes effort-minutes)
  5437. level category tags time-stamp org-ts-regexp habit?)))
  5438. (org-add-props item props
  5439. 'priority (if habit?
  5440. (org-habit-get-priority (org-habit-parse-todo))
  5441. (org-get-priority item))
  5442. 'org-marker (org-agenda-new-marker pos)
  5443. 'org-hd-marker (org-agenda-new-marker)
  5444. 'date date
  5445. 'level level
  5446. 'effort effort 'effort-minutes effort-minutes
  5447. 'ts-date (if repeat (org-agenda--timestamp-to-absolute repeat)
  5448. current)
  5449. 'todo-state todo-state
  5450. 'warntime warntime
  5451. 'type "timestamp")
  5452. (push item timestamp-items))))
  5453. (when org-agenda-skip-additional-timestamps-same-entry
  5454. (outline-next-heading))))
  5455. (nreverse timestamp-items)))
  5456. (defun org-agenda-get-sexps ()
  5457. "Return the sexp information for agenda display."
  5458. (require 'diary-lib)
  5459. (with-no-warnings (defvar date) (defvar entry))
  5460. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5461. 'mouse-face 'highlight
  5462. 'help-echo
  5463. (format "mouse-2 or RET jump to org file %s"
  5464. (abbreviate-file-name buffer-file-name))))
  5465. (regexp "^&?%%(")
  5466. ;; FIXME: Is this `entry' binding intended to be dynamic,
  5467. ;; so as to "hide" any current binding for it?
  5468. marker category extra level ee txt tags entry
  5469. result beg b sexp sexp-entry todo-state warntime inherited-tags
  5470. effort effort-minutes)
  5471. (goto-char (point-min))
  5472. (while (re-search-forward regexp nil t)
  5473. (catch :skip
  5474. ;; We do not run `org-agenda-skip' righ away because every single sexp
  5475. ;; in the buffer is matched here, unlike day-specific search
  5476. ;; in ordinary timestamps. Most of the sexps will not match
  5477. ;; the agenda day and it is quicker to run `org-agenda-skip' only for
  5478. ;; matching sexps later on.
  5479. (setq beg (match-beginning 0))
  5480. (goto-char (1- (match-end 0)))
  5481. (setq b (point))
  5482. (forward-sexp 1)
  5483. (setq sexp (buffer-substring b (point)))
  5484. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5485. (buffer-substring
  5486. (match-beginning 1)
  5487. (save-excursion
  5488. (goto-char (match-end 1))
  5489. (skip-chars-backward "[:blank:]")
  5490. (point)))
  5491. ""))
  5492. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5493. (when result
  5494. ;; Only check if entry should be skipped on matching sexps.
  5495. (org-agenda-skip (org-element-at-point))
  5496. (setq marker (org-agenda-new-marker beg)
  5497. level (make-string (org-reduced-level (org-outline-level)) ? )
  5498. category (org-get-category beg)
  5499. effort (save-match-data (or (get-text-property (point) 'effort)
  5500. (org-entry-get (point) org-effort-property)))
  5501. inherited-tags
  5502. (or (eq org-agenda-show-inherited-tags 'always)
  5503. (and (listp org-agenda-show-inherited-tags)
  5504. (memq 'agenda org-agenda-show-inherited-tags))
  5505. (and (eq org-agenda-show-inherited-tags t)
  5506. (or (eq org-agenda-use-tag-inheritance t)
  5507. (memq 'agenda org-agenda-use-tag-inheritance))))
  5508. tags (org-get-tags nil (not inherited-tags))
  5509. todo-state (org-get-todo-state)
  5510. warntime (get-text-property (point) 'org-appt-warntime)
  5511. extra nil)
  5512. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5513. (dolist (r (if (stringp result)
  5514. (list result)
  5515. result)) ;; we expect a list here
  5516. (when (and org-agenda-diary-sexp-prefix
  5517. (string-match org-agenda-diary-sexp-prefix r))
  5518. (setq extra (match-string 0 r)
  5519. r (replace-match "" nil nil r)))
  5520. (if (string-match "\\S-" r)
  5521. (setq txt r)
  5522. (setq txt "SEXP entry returned empty string"))
  5523. (setq txt (org-agenda-format-item extra
  5524. (org-add-props txt nil
  5525. 'effort effort
  5526. 'effort-minutes effort-minutes)
  5527. level category tags 'time))
  5528. (org-add-props txt props 'org-marker marker
  5529. 'date date 'todo-state todo-state
  5530. 'effort effort 'effort-minutes effort-minutes
  5531. 'level level 'type "sexp" 'warntime warntime)
  5532. (push txt ee)))))
  5533. (nreverse ee)))
  5534. ;; Calendar sanity: define some functions that are independent of
  5535. ;; `calendar-date-style'.
  5536. (defun org-anniversary (year month day &optional mark)
  5537. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5538. (with-no-warnings
  5539. (let ((calendar-date-style 'iso))
  5540. (diary-anniversary year month day mark))))
  5541. (defun org-cyclic (N year month day &optional mark)
  5542. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5543. (with-no-warnings
  5544. (let ((calendar-date-style 'iso))
  5545. (diary-cyclic N year month day mark))))
  5546. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5547. "Like `diary-block', but with fixed (ISO) order of arguments."
  5548. (with-no-warnings
  5549. (let ((calendar-date-style 'iso))
  5550. (diary-block Y1 M1 D1 Y2 M2 D2 mark))))
  5551. (defun org-date (year month day &optional mark)
  5552. "Like `diary-date', but with fixed (ISO) order of arguments."
  5553. (with-no-warnings
  5554. (let ((calendar-date-style 'iso))
  5555. (diary-date year month day mark))))
  5556. ;; Define the `org-class' function
  5557. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5558. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5559. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5560. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5561. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5562. `holidays', then any date that is known by the Emacs calendar to be a
  5563. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5564. then those holidays will be skipped."
  5565. (with-no-warnings (defvar date) (defvar entry))
  5566. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5567. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5568. (d (calendar-absolute-from-gregorian date))
  5569. (h (when skip-weeks (calendar-check-holidays date))))
  5570. (and
  5571. (<= date1 d)
  5572. (<= d date2)
  5573. (= (calendar-day-of-week date) dayname)
  5574. (or (not skip-weeks)
  5575. (progn
  5576. (require 'cal-iso)
  5577. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5578. (not (or (and h (memq 'holidays skip-weeks))
  5579. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5580. entry)))
  5581. (defalias 'org-get-closed #'org-agenda-get-progress)
  5582. (defun org-agenda-get-progress ()
  5583. "Return the logged TODO entries for agenda display."
  5584. (with-no-warnings (defvar date))
  5585. (let* ((props (list 'mouse-face 'highlight
  5586. 'org-not-done-regexp org-not-done-regexp
  5587. 'org-todo-regexp org-todo-regexp
  5588. 'org-complex-heading-regexp org-complex-heading-regexp
  5589. 'help-echo
  5590. (format "mouse-2 or RET jump to org file %s"
  5591. (abbreviate-file-name buffer-file-name))))
  5592. (items (if (consp org-agenda-show-log-scoped)
  5593. org-agenda-show-log-scoped
  5594. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5595. '(clock)
  5596. org-agenda-log-mode-items)))
  5597. (parts
  5598. (delq nil
  5599. (list
  5600. (when (memq 'closed items) (concat "\\<" org-closed-string))
  5601. (when (memq 'clock items) (concat "\\<" org-clock-string))
  5602. (when (memq 'state items)
  5603. (format "- +State \"%s\".*?" org-todo-regexp)))))
  5604. (parts-re (if parts (mapconcat #'identity parts "\\|")
  5605. (error "`org-agenda-log-mode-items' is empty")))
  5606. (regexp (concat
  5607. "\\(" parts-re "\\)"
  5608. " *\\["
  5609. (regexp-quote
  5610. (substring
  5611. (format-time-string
  5612. (car org-time-stamp-formats)
  5613. (org-encode-time ; DATE bound by calendar
  5614. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5615. 1 11))))
  5616. (org-agenda-search-headline-for-time nil)
  5617. marker hdmarker priority category level tags closedp type
  5618. statep clockp state ee txt extra timestr rest clocked inherited-tags
  5619. effort effort-minutes)
  5620. (goto-char (point-min))
  5621. (while (re-search-forward regexp nil t)
  5622. (catch :skip
  5623. (org-agenda-skip)
  5624. (setq marker (org-agenda-new-marker (match-beginning 0))
  5625. closedp (equal (match-string 1) org-closed-string)
  5626. statep (equal (string-to-char (match-string 1)) ?-)
  5627. clockp (not (or closedp statep))
  5628. state (and statep (match-string 2))
  5629. category (org-get-category (match-beginning 0))
  5630. timestr (buffer-substring (match-beginning 0) (line-end-position))
  5631. effort (save-match-data (or (get-text-property (point) 'effort)
  5632. (org-entry-get (point) org-effort-property))))
  5633. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5634. (when (string-match "\\]" timestr)
  5635. ;; substring should only run to end of time stamp
  5636. (setq rest (substring timestr (match-end 0))
  5637. timestr (substring timestr 0 (match-end 0)))
  5638. (if (and (not closedp) (not statep)
  5639. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5640. rest))
  5641. (progn (setq timestr (concat (substring timestr 0 -1)
  5642. "-" (match-string 1 rest) "]"))
  5643. (setq clocked (match-string 2 rest)))
  5644. (setq clocked "-")))
  5645. (save-excursion
  5646. (setq extra
  5647. (cond
  5648. ((not org-agenda-log-mode-add-notes) nil)
  5649. (statep
  5650. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5651. (match-string 1)))
  5652. (clockp
  5653. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5654. (match-string 1)))))
  5655. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5656. (throw :skip nil)
  5657. (goto-char (match-beginning 0))
  5658. (setq hdmarker (org-agenda-new-marker)
  5659. inherited-tags
  5660. (or (eq org-agenda-show-inherited-tags 'always)
  5661. (and (listp org-agenda-show-inherited-tags)
  5662. (memq 'todo org-agenda-show-inherited-tags))
  5663. (and (eq org-agenda-show-inherited-tags t)
  5664. (or (eq org-agenda-use-tag-inheritance t)
  5665. (memq 'todo org-agenda-use-tag-inheritance))))
  5666. tags (org-get-tags nil (not inherited-tags))
  5667. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5668. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5669. (setq txt (match-string 1))
  5670. (when extra
  5671. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5672. (setq txt (concat (substring txt 0 (match-beginning 1))
  5673. " - " extra " " (match-string 2 txt)))
  5674. (setq txt (concat txt " - " extra))))
  5675. (setq txt (org-agenda-format-item
  5676. (cond
  5677. (closedp "Closed: ")
  5678. (statep (concat "State: (" state ")"))
  5679. (t (concat "Clocked: (" clocked ")")))
  5680. (org-add-props txt nil
  5681. 'effort effort
  5682. 'effort-minutes effort-minutes)
  5683. level category tags timestr)))
  5684. (setq type (cond (closedp "closed")
  5685. (statep "state")
  5686. (t "clock")))
  5687. (setq priority 100000)
  5688. (org-add-props txt props
  5689. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5690. 'priority priority 'level level
  5691. 'effort effort 'effort-minutes effort-minutes
  5692. 'type type 'date date
  5693. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5694. (push txt ee))
  5695. (goto-char (line-end-position))))
  5696. (nreverse ee)))
  5697. (defun org-agenda-show-clocking-issues ()
  5698. "Add overlays, showing issues with clocking.
  5699. See also the user option `org-agenda-clock-consistency-checks'."
  5700. (interactive)
  5701. (let* ((pl org-agenda-clock-consistency-checks)
  5702. (re (concat "^[ \t]*"
  5703. org-clock-string
  5704. "[ \t]+"
  5705. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5706. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5707. (tlstart 0.)
  5708. (tlend 0.)
  5709. (maxtime (org-duration-to-minutes
  5710. (or (plist-get pl :max-duration) "24:00")))
  5711. (mintime (org-duration-to-minutes
  5712. (or (plist-get pl :min-duration) 0)))
  5713. (maxgap (org-duration-to-minutes
  5714. ;; default 30:00 means never complain
  5715. (or (plist-get pl :max-gap) "30:00")))
  5716. (gapok (mapcar #'org-duration-to-minutes
  5717. (plist-get pl :gap-ok-around)))
  5718. (def-face (or (plist-get pl :default-face)
  5719. '((:background "DarkRed") (:foreground "white"))))
  5720. issue face m te ts dt ov)
  5721. (goto-char (point-min))
  5722. (while (re-search-forward " Clocked: +(\\(?:-\\|\\([0-9]+:[0-9]+\\)\\))" nil t)
  5723. (setq issue nil face def-face)
  5724. (catch 'next
  5725. (setq m (org-get-at-bol 'org-marker)
  5726. te nil ts nil)
  5727. (unless (and m (markerp m))
  5728. (setq issue "No valid clock line") (throw 'next t))
  5729. (org-with-point-at m
  5730. (save-excursion
  5731. (goto-char (line-beginning-position))
  5732. (unless (looking-at re)
  5733. (error "No valid Clock line")
  5734. (throw 'next t))
  5735. (unless (match-end 3)
  5736. (setq issue
  5737. (format
  5738. "No end time: (%s)"
  5739. (org-duration-from-minutes
  5740. (floor
  5741. (- (float-time (org-current-time))
  5742. (float-time (org-time-string-to-time (match-string 1))))
  5743. 60)))
  5744. face (or (plist-get pl :no-end-time-face) face))
  5745. (throw 'next t))
  5746. (setq ts (match-string 1)
  5747. te (match-string 3)
  5748. ts (float-time (org-time-string-to-time ts))
  5749. te (float-time (org-time-string-to-time te))
  5750. dt (- te ts))))
  5751. (cond
  5752. ((> dt (* 60 maxtime))
  5753. ;; a very long clocking chunk
  5754. (setq issue (format "Clocking interval is very long: %s"
  5755. (org-duration-from-minutes (floor dt 60)))
  5756. face (or (plist-get pl :long-face) face)))
  5757. ((< dt (* 60 mintime))
  5758. ;; a very short clocking chunk
  5759. (setq issue (format "Clocking interval is very short: %s"
  5760. (org-duration-from-minutes (floor dt 60)))
  5761. face (or (plist-get pl :short-face) face)))
  5762. ((and (> tlend 0) (< ts tlend))
  5763. ;; Two clock entries are overlapping
  5764. (setq issue (format "Clocking overlap: %d minutes"
  5765. (/ (- tlend ts) 60))
  5766. face (or (plist-get pl :overlap-face) face)))
  5767. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5768. ;; There is a gap, lets see if we need to report it
  5769. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5770. (setq issue (format "Clocking gap: %d minutes"
  5771. (/ (- ts tlend) 60))
  5772. face (or (plist-get pl :gap-face) face))))
  5773. (t nil)))
  5774. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5775. (when issue
  5776. ;; OK, there was some issue, add an overlay to show the issue
  5777. (setq ov (make-overlay (line-beginning-position) (line-end-position)))
  5778. (overlay-put ov 'before-string
  5779. (concat
  5780. (org-add-props
  5781. (format "%-43s" (concat " " issue))
  5782. nil
  5783. 'face face)
  5784. "\n"))
  5785. (overlay-put ov 'evaporate t)))))
  5786. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5787. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5788. (catch 'exit
  5789. (unless ok-list
  5790. ;; there are no OK times for gaps...
  5791. (throw 'exit nil))
  5792. (when (> (- (/ t2 36000) (/ t1 36000)) 24)
  5793. ;; This is more than 24 hours, so it is OK.
  5794. ;; because we have at least one OK time, that must be in the
  5795. ;; 24 hour interval.
  5796. (throw 'exit t))
  5797. ;; We have a shorter gap.
  5798. ;; Now we have to get the minute of the day when these times are
  5799. (let* ((t1dec (decode-time t1))
  5800. (t2dec (decode-time t2))
  5801. ;; compute the minute on the day
  5802. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5803. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5804. (when (< min2 min1)
  5805. ;; if min2 is smaller than min1, this means it is on the next day.
  5806. ;; Wrap it to after midnight.
  5807. (setq min2 (+ min2 1440)))
  5808. ;; Now check if any of the OK times is in the gap
  5809. (mapc (lambda (x)
  5810. ;; Wrap the time to after midnight if necessary
  5811. (when (< x min1) (setq x (+ x 1440)))
  5812. ;; Check if in interval
  5813. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5814. ok-list)
  5815. ;; Nope, this gap is not OK
  5816. nil)))
  5817. (defun org-agenda-get-deadlines (&optional with-hour)
  5818. "Return the deadline information for agenda display.
  5819. When WITH-HOUR is non-nil, only return deadlines with an hour
  5820. specification like [h]h:mm."
  5821. (with-no-warnings (defvar date))
  5822. (let* ((props (list 'mouse-face 'highlight
  5823. 'org-not-done-regexp org-not-done-regexp
  5824. 'org-todo-regexp org-todo-regexp
  5825. 'org-complex-heading-regexp org-complex-heading-regexp
  5826. 'help-echo
  5827. (format "mouse-2 or RET jump to org file %s"
  5828. (abbreviate-file-name buffer-file-name))))
  5829. (regexp (if with-hour
  5830. org-deadline-time-hour-regexp
  5831. org-deadline-time-regexp))
  5832. (today (org-today))
  5833. (today? (org-agenda-today-p date)) ; DATE bound by calendar.
  5834. (current (calendar-absolute-from-gregorian date))
  5835. deadline-items)
  5836. (goto-char (point-min))
  5837. (if (org-element--cache-active-p)
  5838. (org-element-cache-map
  5839. (lambda (el)
  5840. (when (and (org-element-property :deadline el)
  5841. (or (not with-hour)
  5842. (org-element-property
  5843. :hour-start
  5844. (org-element-property :deadline el))
  5845. (org-element-property
  5846. :hour-end
  5847. (org-element-property :deadline el))))
  5848. (goto-char (org-element-property :contents-begin el))
  5849. (catch :skip
  5850. (org-agenda-skip el)
  5851. (let* ((s (substring (org-element-property
  5852. :raw-value
  5853. (org-element-property :deadline el))
  5854. 1 -1))
  5855. (pos (save-excursion
  5856. (goto-char (org-element-property :contents-begin el))
  5857. ;; We intentionally leave NOERROR
  5858. ;; argument in `re-search-forward' nil. If
  5859. ;; the search fails here, something went
  5860. ;; wrong and we are looking at
  5861. ;; non-matching headline.
  5862. (re-search-forward regexp (line-end-position))
  5863. (1- (match-beginning 1))))
  5864. (todo-state (org-element-property :todo-keyword el))
  5865. (done? (eq 'done (org-element-property :todo-type el)))
  5866. (sexp? (eq 'diary
  5867. (org-element-property
  5868. :type (org-element-property :deadline el))))
  5869. ;; DEADLINE is the deadline date for the entry. It is
  5870. ;; either the base date or the last repeat, according
  5871. ;; to `org-agenda-prefer-last-repeat'.
  5872. (deadline
  5873. (cond
  5874. (sexp? (org-agenda--timestamp-to-absolute s current))
  5875. ((or (eq org-agenda-prefer-last-repeat t)
  5876. (member todo-state org-agenda-prefer-last-repeat))
  5877. (org-agenda--timestamp-to-absolute
  5878. s today 'past (current-buffer) pos))
  5879. (t (org-agenda--timestamp-to-absolute s))))
  5880. ;; REPEAT is the future repeat closest from CURRENT,
  5881. ;; according to `org-agenda-show-future-repeats'. If
  5882. ;; the latter is nil, or if the time stamp has no
  5883. ;; repeat part, default to DEADLINE.
  5884. (repeat
  5885. (cond
  5886. (sexp? deadline)
  5887. ((<= current today) deadline)
  5888. ((not org-agenda-show-future-repeats) deadline)
  5889. (t
  5890. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5891. (1+ today)
  5892. current)))
  5893. (org-agenda--timestamp-to-absolute
  5894. s base 'future (current-buffer) pos)))))
  5895. (diff (- deadline current))
  5896. (suppress-prewarning
  5897. (let ((scheduled
  5898. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5899. (org-element-property
  5900. :raw-value
  5901. (org-element-property :scheduled el)))))
  5902. (cond
  5903. ((not scheduled) nil)
  5904. ;; The current item has a scheduled date, so
  5905. ;; evaluate its prewarning lead time.
  5906. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5907. ;; Use global prewarning-restart lead time.
  5908. org-agenda-skip-deadline-prewarning-if-scheduled)
  5909. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5910. 'pre-scheduled)
  5911. ;; Set pre-warning to no earlier than SCHEDULED.
  5912. (min (- deadline
  5913. (org-agenda--timestamp-to-absolute scheduled))
  5914. org-deadline-warning-days))
  5915. ;; Set pre-warning to deadline.
  5916. (t 0))))
  5917. (wdays (or suppress-prewarning (org-get-wdays s))))
  5918. (cond
  5919. ;; Only display deadlines at their base date, at future
  5920. ;; repeat occurrences or in today agenda.
  5921. ((= current deadline) nil)
  5922. ((= current repeat) nil)
  5923. ((not today?) (throw :skip nil))
  5924. ;; Upcoming deadline: display within warning period WDAYS.
  5925. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  5926. ;; Overdue deadline: warn about it for
  5927. ;; `org-deadline-past-days' duration.
  5928. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  5929. ;; Possibly skip done tasks.
  5930. (when (and done?
  5931. (or org-agenda-skip-deadline-if-done
  5932. (/= deadline current)))
  5933. (throw :skip nil))
  5934. (save-excursion
  5935. (goto-char (org-element-property :begin el))
  5936. (let* ((category (org-get-category))
  5937. (effort (save-match-data (or (get-text-property (point) 'effort)
  5938. (org-element-property (intern (concat ":" (upcase org-effort-property))) el))))
  5939. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5940. (level (make-string (org-element-property :level el)
  5941. ?\s))
  5942. (head (save-excursion
  5943. (goto-char (org-element-property :begin el))
  5944. (re-search-forward org-outline-regexp-bol)
  5945. (buffer-substring-no-properties (point) (line-end-position))))
  5946. (inherited-tags
  5947. (or (eq org-agenda-show-inherited-tags 'always)
  5948. (and (listp org-agenda-show-inherited-tags)
  5949. (memq 'agenda org-agenda-show-inherited-tags))
  5950. (and (eq org-agenda-show-inherited-tags t)
  5951. (or (eq org-agenda-use-tag-inheritance t)
  5952. (memq 'agenda
  5953. org-agenda-use-tag-inheritance)))))
  5954. (tags (org-get-tags el (not inherited-tags)))
  5955. (time
  5956. (cond
  5957. ;; No time of day designation if it is only
  5958. ;; a reminder.
  5959. ((and (/= current deadline) (/= current repeat)) nil)
  5960. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5961. (concat (substring s (match-beginning 1)) " "))
  5962. (t 'time)))
  5963. (item
  5964. (org-agenda-format-item
  5965. ;; Insert appropriate suffixes before deadlines.
  5966. ;; Those only apply to today agenda.
  5967. (pcase-let ((`(,now ,future ,past)
  5968. org-agenda-deadline-leaders))
  5969. (cond
  5970. ((and today? (< deadline today)) (format past (- diff)))
  5971. ((and today? (> deadline today)) (format future diff))
  5972. (t now)))
  5973. (org-add-props head nil
  5974. 'effort effort
  5975. 'effort-minutes effort-minutes)
  5976. level category tags time))
  5977. (face (org-agenda-deadline-face
  5978. (- 1 (/ (float diff) (max wdays 1)))))
  5979. (upcoming? (and today? (> deadline today)))
  5980. (warntime (get-text-property (point) 'org-appt-warntime)))
  5981. (org-add-props item props
  5982. 'org-marker (org-agenda-new-marker pos)
  5983. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5984. 'warntime warntime
  5985. 'level level
  5986. 'effort effort 'effort-minutes effort-minutes
  5987. 'ts-date deadline
  5988. 'priority
  5989. ;; Adjust priority to today reminders about deadlines.
  5990. ;; Overdue deadlines get the highest priority
  5991. ;; increase, then imminent deadlines and eventually
  5992. ;; more distant deadlines.
  5993. (let ((adjust (if today? (- diff) 0)))
  5994. (+ adjust (org-get-priority item)))
  5995. 'todo-state todo-state
  5996. 'type (if upcoming? "upcoming-deadline" "deadline")
  5997. 'date (if upcoming? date deadline)
  5998. 'face (if done? 'org-agenda-done face)
  5999. 'undone-face face
  6000. 'done-face 'org-agenda-done)
  6001. (push item deadline-items)))))))
  6002. :next-re regexp
  6003. :fail-re regexp
  6004. :narrow t)
  6005. (while (re-search-forward regexp nil t)
  6006. (catch :skip
  6007. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  6008. (org-agenda-skip)
  6009. (let* ((s (match-string 1))
  6010. (pos (1- (match-beginning 1)))
  6011. (todo-state (save-match-data (org-get-todo-state)))
  6012. (done? (member todo-state org-done-keywords))
  6013. (sexp? (string-prefix-p "%%" s))
  6014. ;; DEADLINE is the deadline date for the entry. It is
  6015. ;; either the base date or the last repeat, according
  6016. ;; to `org-agenda-prefer-last-repeat'.
  6017. (deadline
  6018. (cond
  6019. (sexp? (org-agenda--timestamp-to-absolute s current))
  6020. ((or (eq org-agenda-prefer-last-repeat t)
  6021. (member todo-state org-agenda-prefer-last-repeat))
  6022. (org-agenda--timestamp-to-absolute
  6023. s today 'past (current-buffer) pos))
  6024. (t (org-agenda--timestamp-to-absolute s))))
  6025. ;; REPEAT is the future repeat closest from CURRENT,
  6026. ;; according to `org-agenda-show-future-repeats'. If
  6027. ;; the latter is nil, or if the time stamp has no
  6028. ;; repeat part, default to DEADLINE.
  6029. (repeat
  6030. (cond
  6031. (sexp? deadline)
  6032. ((<= current today) deadline)
  6033. ((not org-agenda-show-future-repeats) deadline)
  6034. (t
  6035. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6036. (1+ today)
  6037. current)))
  6038. (org-agenda--timestamp-to-absolute
  6039. s base 'future (current-buffer) pos)))))
  6040. (diff (- deadline current))
  6041. (suppress-prewarning
  6042. (let ((scheduled
  6043. (and org-agenda-skip-deadline-prewarning-if-scheduled
  6044. (org-entry-get nil "SCHEDULED"))))
  6045. (cond
  6046. ((not scheduled) nil)
  6047. ;; The current item has a scheduled date, so
  6048. ;; evaluate its prewarning lead time.
  6049. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  6050. ;; Use global prewarning-restart lead time.
  6051. org-agenda-skip-deadline-prewarning-if-scheduled)
  6052. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  6053. 'pre-scheduled)
  6054. ;; Set pre-warning to no earlier than SCHEDULED.
  6055. (min (- deadline
  6056. (org-agenda--timestamp-to-absolute scheduled))
  6057. org-deadline-warning-days))
  6058. ;; Set pre-warning to deadline.
  6059. (t 0))))
  6060. (wdays (or suppress-prewarning (org-get-wdays s))))
  6061. (cond
  6062. ;; Only display deadlines at their base date, at future
  6063. ;; repeat occurrences or in today agenda.
  6064. ((= current deadline) nil)
  6065. ((= current repeat) nil)
  6066. ((not today?) (throw :skip nil))
  6067. ;; Upcoming deadline: display within warning period WDAYS.
  6068. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  6069. ;; Overdue deadline: warn about it for
  6070. ;; `org-deadline-past-days' duration.
  6071. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  6072. ;; Possibly skip done tasks.
  6073. (when (and done?
  6074. (or org-agenda-skip-deadline-if-done
  6075. (/= deadline current)))
  6076. (throw :skip nil))
  6077. (save-excursion
  6078. (re-search-backward "^\\*+[ \t]+" nil t)
  6079. (goto-char (match-end 0))
  6080. (let* ((category (org-get-category))
  6081. (effort (save-match-data (or (get-text-property (point) 'effort)
  6082. (org-entry-get (point) org-effort-property))))
  6083. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6084. (level (make-string (org-reduced-level (org-outline-level))
  6085. ?\s))
  6086. (head (buffer-substring-no-properties
  6087. (point) (line-end-position)))
  6088. (inherited-tags
  6089. (or (eq org-agenda-show-inherited-tags 'always)
  6090. (and (listp org-agenda-show-inherited-tags)
  6091. (memq 'agenda org-agenda-show-inherited-tags))
  6092. (and (eq org-agenda-show-inherited-tags t)
  6093. (or (eq org-agenda-use-tag-inheritance t)
  6094. (memq 'agenda
  6095. org-agenda-use-tag-inheritance)))))
  6096. (tags (org-get-tags nil (not inherited-tags)))
  6097. (time
  6098. (cond
  6099. ;; No time of day designation if it is only
  6100. ;; a reminder.
  6101. ((and (/= current deadline) (/= current repeat)) nil)
  6102. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6103. (concat (substring s (match-beginning 1)) " "))
  6104. (t 'time)))
  6105. (item
  6106. (org-agenda-format-item
  6107. ;; Insert appropriate suffixes before deadlines.
  6108. ;; Those only apply to today agenda.
  6109. (pcase-let ((`(,now ,future ,past)
  6110. org-agenda-deadline-leaders))
  6111. (cond
  6112. ((and today? (< deadline today)) (format past (- diff)))
  6113. ((and today? (> deadline today)) (format future diff))
  6114. (t now)))
  6115. (org-add-props head nil
  6116. 'effort effort
  6117. 'effort-minutes effort-minutes)
  6118. level category tags time))
  6119. (face (org-agenda-deadline-face
  6120. (- 1 (/ (float diff) (max wdays 1)))))
  6121. (upcoming? (and today? (> deadline today)))
  6122. (warntime (get-text-property (point) 'org-appt-warntime)))
  6123. (org-add-props item props
  6124. 'org-marker (org-agenda-new-marker pos)
  6125. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6126. 'warntime warntime
  6127. 'level level
  6128. 'effort effort 'effort-minutes effort-minutes
  6129. 'ts-date deadline
  6130. 'priority
  6131. ;; Adjust priority to today reminders about deadlines.
  6132. ;; Overdue deadlines get the highest priority
  6133. ;; increase, then imminent deadlines and eventually
  6134. ;; more distant deadlines.
  6135. (let ((adjust (if today? (- diff) 0)))
  6136. (+ adjust (org-get-priority item)))
  6137. 'todo-state todo-state
  6138. 'type (if upcoming? "upcoming-deadline" "deadline")
  6139. 'date (if upcoming? date deadline)
  6140. 'face (if done? 'org-agenda-done face)
  6141. 'undone-face face
  6142. 'done-face 'org-agenda-done)
  6143. (push item deadline-items)))))))
  6144. (nreverse deadline-items)))
  6145. (defun org-agenda-deadline-face (fraction)
  6146. "Return the face to displaying a deadline item.
  6147. FRACTION is what fraction of the head-warning time has passed."
  6148. (assoc-default fraction org-agenda-deadline-faces #'<=))
  6149. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  6150. "Return the scheduled information for agenda display.
  6151. Optional argument DEADLINES is a list of deadline items to be
  6152. displayed in agenda view. When WITH-HOUR is non-nil, only return
  6153. scheduled items with an hour specification like [h]h:mm."
  6154. (with-no-warnings (defvar date))
  6155. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  6156. 'org-todo-regexp org-todo-regexp
  6157. 'org-complex-heading-regexp org-complex-heading-regexp
  6158. 'done-face 'org-agenda-done
  6159. 'mouse-face 'highlight
  6160. 'help-echo
  6161. (format "mouse-2 or RET jump to Org file %s"
  6162. (abbreviate-file-name buffer-file-name))))
  6163. (regexp (if with-hour
  6164. org-scheduled-time-hour-regexp
  6165. org-scheduled-time-regexp))
  6166. (today (org-today))
  6167. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  6168. (current (calendar-absolute-from-gregorian date))
  6169. (deadline-pos
  6170. (mapcar (lambda (d)
  6171. (let ((m (get-text-property 0 'org-hd-marker d)))
  6172. (and m (marker-position m))))
  6173. deadlines))
  6174. scheduled-items)
  6175. (goto-char (point-min))
  6176. (if (org-element--cache-active-p)
  6177. (org-element-cache-map
  6178. (lambda (el)
  6179. (when (and (org-element-property :scheduled el)
  6180. (or (not with-hour)
  6181. (org-element-property
  6182. :hour-start
  6183. (org-element-property :scheduled el))
  6184. (org-element-property
  6185. :hour-end
  6186. (org-element-property :scheduled el))))
  6187. (goto-char (org-element-property :contents-begin el))
  6188. (catch :skip
  6189. (org-agenda-skip el)
  6190. (let* ((s (substring (org-element-property
  6191. :raw-value
  6192. (org-element-property :scheduled el))
  6193. 1 -1))
  6194. (pos (save-excursion
  6195. (goto-char (org-element-property :contents-begin el))
  6196. ;; We intentionally leave NOERROR
  6197. ;; argument in `re-search-forward' nil. If
  6198. ;; the search fails here, something went
  6199. ;; wrong and we are looking at
  6200. ;; non-matching headline.
  6201. (re-search-forward regexp (line-end-position))
  6202. (1- (match-beginning 1))))
  6203. (todo-state (org-element-property :todo-keyword el))
  6204. (donep (eq 'done (org-element-property :todo-type el)))
  6205. (sexp? (eq 'diary
  6206. (org-element-property
  6207. :type (org-element-property :scheduled el))))
  6208. ;; SCHEDULE is the scheduled date for the entry. It is
  6209. ;; either the bare date or the last repeat, according
  6210. ;; to `org-agenda-prefer-last-repeat'.
  6211. (schedule
  6212. (cond
  6213. (sexp? (org-agenda--timestamp-to-absolute s current))
  6214. ((or (eq org-agenda-prefer-last-repeat t)
  6215. (member todo-state org-agenda-prefer-last-repeat))
  6216. (org-agenda--timestamp-to-absolute
  6217. s today 'past (current-buffer) pos))
  6218. (t (org-agenda--timestamp-to-absolute s))))
  6219. ;; REPEAT is the future repeat closest from CURRENT,
  6220. ;; according to `org-agenda-show-future-repeats'. If
  6221. ;; the latter is nil, or if the time stamp has no
  6222. ;; repeat part, default to SCHEDULE.
  6223. (repeat
  6224. (cond
  6225. (sexp? schedule)
  6226. ((<= current today) schedule)
  6227. ((not org-agenda-show-future-repeats) schedule)
  6228. (t
  6229. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6230. (1+ today)
  6231. current)))
  6232. (org-agenda--timestamp-to-absolute
  6233. s base 'future (current-buffer) pos)))))
  6234. (diff (- current schedule))
  6235. (warntime (get-text-property (point) 'org-appt-warntime))
  6236. (pastschedp (< schedule today))
  6237. (futureschedp (> schedule today))
  6238. (habitp (and (fboundp 'org-is-habit-p)
  6239. (string= "habit" (org-element-property :STYLE el))))
  6240. (suppress-delay
  6241. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  6242. (org-element-property
  6243. :raw-value
  6244. (org-element-property :deadline el)))))
  6245. (cond
  6246. ((not deadline) nil)
  6247. ;; The current item has a deadline date, so
  6248. ;; evaluate its delay time.
  6249. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  6250. ;; Use global delay time.
  6251. (- org-agenda-skip-scheduled-delay-if-deadline))
  6252. ((eq org-agenda-skip-scheduled-delay-if-deadline
  6253. 'post-deadline)
  6254. ;; Set delay to no later than DEADLINE.
  6255. (min (- schedule
  6256. (org-agenda--timestamp-to-absolute deadline))
  6257. org-scheduled-delay-days))
  6258. (t 0))))
  6259. (ddays
  6260. (cond
  6261. ;; Nullify delay when a repeater triggered already
  6262. ;; and the delay is of the form --Xd.
  6263. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  6264. (> schedule (org-agenda--timestamp-to-absolute s)))
  6265. 0)
  6266. (suppress-delay
  6267. (let ((org-scheduled-delay-days suppress-delay))
  6268. (org-get-wdays s t t)))
  6269. (t (org-get-wdays s t)))))
  6270. ;; Display scheduled items at base date (SCHEDULE), today if
  6271. ;; scheduled before the current date, and at any repeat past
  6272. ;; today. However, skip delayed items and items that have
  6273. ;; been displayed for more than `org-scheduled-past-days'.
  6274. (unless (and todayp
  6275. habitp
  6276. (bound-and-true-p org-habit-show-all-today))
  6277. (when (or (and (> ddays 0) (< diff ddays))
  6278. (> diff (or (and habitp org-habit-scheduled-past-days)
  6279. org-scheduled-past-days))
  6280. (> schedule current)
  6281. (and (/= current schedule)
  6282. (/= current today)
  6283. (/= current repeat)))
  6284. (throw :skip nil)))
  6285. ;; Possibly skip done tasks.
  6286. (when (and donep
  6287. (or org-agenda-skip-scheduled-if-done
  6288. (/= schedule current)))
  6289. (throw :skip nil))
  6290. ;; Skip entry if it already appears as a deadline, per
  6291. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  6292. ;; doesn't apply to habits.
  6293. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  6294. ((guard
  6295. (or (not (memq (line-beginning-position 0) deadline-pos))
  6296. habitp))
  6297. nil)
  6298. (`repeated-after-deadline
  6299. (let ((deadline (time-to-days
  6300. (when (org-element-property :deadline el)
  6301. (org-time-string-to-time
  6302. (org-element-property :deadline el))))))
  6303. (and (<= schedule deadline) (> current deadline))))
  6304. (`not-today pastschedp)
  6305. (`t t)
  6306. (_ nil))
  6307. (throw :skip nil))
  6308. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  6309. ;; only show them for today. Also skip done habits.
  6310. (when (and habitp
  6311. (or donep
  6312. (not (bound-and-true-p org-habit-show-habits))
  6313. (and (not todayp)
  6314. (bound-and-true-p
  6315. org-habit-show-habits-only-for-today))))
  6316. (throw :skip nil))
  6317. (save-excursion
  6318. (goto-char (org-element-property :begin el))
  6319. (let* ((category (org-get-category))
  6320. (effort (save-match-data
  6321. (or (get-text-property (point) 'effort)
  6322. (org-element-property (intern (concat ":" (upcase org-effort-property))) el))))
  6323. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6324. (inherited-tags
  6325. (or (eq org-agenda-show-inherited-tags 'always)
  6326. (and (listp org-agenda-show-inherited-tags)
  6327. (memq 'agenda org-agenda-show-inherited-tags))
  6328. (and (eq org-agenda-show-inherited-tags t)
  6329. (or (eq org-agenda-use-tag-inheritance t)
  6330. (memq 'agenda
  6331. org-agenda-use-tag-inheritance)))))
  6332. (tags (org-get-tags el (not inherited-tags)))
  6333. (level (make-string (org-element-property :level el)
  6334. ?\s))
  6335. (head (save-excursion
  6336. (goto-char (org-element-property :begin el))
  6337. (re-search-forward org-outline-regexp-bol)
  6338. (buffer-substring (point) (line-end-position))))
  6339. (time
  6340. (cond
  6341. ;; No time of day designation if it is only a
  6342. ;; reminder, except for habits, which always show
  6343. ;; the time of day. Habits are an exception
  6344. ;; because if there is a time of day, that is
  6345. ;; interpreted to mean they should usually happen
  6346. ;; then, even if doing the habit was missed.
  6347. ((and
  6348. (not habitp)
  6349. (/= current schedule)
  6350. (/= current repeat))
  6351. nil)
  6352. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6353. (concat (substring s (match-beginning 1)) " "))
  6354. (t 'time)))
  6355. (item
  6356. (org-agenda-format-item
  6357. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  6358. ;; Show a reminder of a past scheduled today.
  6359. (if (and todayp pastschedp)
  6360. (format past diff)
  6361. first))
  6362. (org-add-props head nil
  6363. 'effort effort
  6364. 'effort-minutes effort-minutes)
  6365. level category tags time nil habitp))
  6366. (face (cond ((and (not habitp) pastschedp)
  6367. 'org-scheduled-previously)
  6368. ((and habitp futureschedp)
  6369. 'org-agenda-done)
  6370. (todayp 'org-scheduled-today)
  6371. (t 'org-scheduled)))
  6372. (habitp (and habitp (org-habit-parse-todo (org-element-property :begin el)))))
  6373. (org-add-props item props
  6374. 'undone-face face
  6375. 'face (if donep 'org-agenda-done face)
  6376. 'org-marker (org-agenda-new-marker pos)
  6377. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6378. 'type (if pastschedp "past-scheduled" "scheduled")
  6379. 'date (if pastschedp schedule date)
  6380. 'ts-date schedule
  6381. 'warntime warntime
  6382. 'level level
  6383. 'effort effort 'effort-minutes effort-minutes
  6384. 'priority (if habitp (org-habit-get-priority habitp)
  6385. (+ 99 diff (org-get-priority item)))
  6386. 'org-habit-p habitp
  6387. 'todo-state todo-state)
  6388. (push item scheduled-items)))))))
  6389. :next-re regexp
  6390. :fail-re regexp
  6391. :narrow t)
  6392. (while (re-search-forward regexp nil t)
  6393. (catch :skip
  6394. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  6395. (org-agenda-skip)
  6396. (let* ((s (match-string 1))
  6397. (pos (1- (match-beginning 1)))
  6398. (todo-state (save-match-data (org-get-todo-state)))
  6399. (donep (member todo-state org-done-keywords))
  6400. (sexp? (string-prefix-p "%%" s))
  6401. ;; SCHEDULE is the scheduled date for the entry. It is
  6402. ;; either the bare date or the last repeat, according
  6403. ;; to `org-agenda-prefer-last-repeat'.
  6404. (schedule
  6405. (cond
  6406. (sexp? (org-agenda--timestamp-to-absolute s current))
  6407. ((or (eq org-agenda-prefer-last-repeat t)
  6408. (member todo-state org-agenda-prefer-last-repeat))
  6409. (org-agenda--timestamp-to-absolute
  6410. s today 'past (current-buffer) pos))
  6411. (t (org-agenda--timestamp-to-absolute s))))
  6412. ;; REPEAT is the future repeat closest from CURRENT,
  6413. ;; according to `org-agenda-show-future-repeats'. If
  6414. ;; the latter is nil, or if the time stamp has no
  6415. ;; repeat part, default to SCHEDULE.
  6416. (repeat
  6417. (cond
  6418. (sexp? schedule)
  6419. ((<= current today) schedule)
  6420. ((not org-agenda-show-future-repeats) schedule)
  6421. (t
  6422. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6423. (1+ today)
  6424. current)))
  6425. (org-agenda--timestamp-to-absolute
  6426. s base 'future (current-buffer) pos)))))
  6427. (diff (- current schedule))
  6428. (warntime (get-text-property (point) 'org-appt-warntime))
  6429. (pastschedp (< schedule today))
  6430. (futureschedp (> schedule today))
  6431. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  6432. (suppress-delay
  6433. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  6434. (org-entry-get nil "DEADLINE"))))
  6435. (cond
  6436. ((not deadline) nil)
  6437. ;; The current item has a deadline date, so
  6438. ;; evaluate its delay time.
  6439. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  6440. ;; Use global delay time.
  6441. (- org-agenda-skip-scheduled-delay-if-deadline))
  6442. ((eq org-agenda-skip-scheduled-delay-if-deadline
  6443. 'post-deadline)
  6444. ;; Set delay to no later than DEADLINE.
  6445. (min (- schedule
  6446. (org-agenda--timestamp-to-absolute deadline))
  6447. org-scheduled-delay-days))
  6448. (t 0))))
  6449. (ddays
  6450. (cond
  6451. ;; Nullify delay when a repeater triggered already
  6452. ;; and the delay is of the form --Xd.
  6453. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  6454. (> schedule (org-agenda--timestamp-to-absolute s)))
  6455. 0)
  6456. (suppress-delay
  6457. (let ((org-scheduled-delay-days suppress-delay))
  6458. (org-get-wdays s t t)))
  6459. (t (org-get-wdays s t)))))
  6460. ;; Display scheduled items at base date (SCHEDULE), today if
  6461. ;; scheduled before the current date, and at any repeat past
  6462. ;; today. However, skip delayed items and items that have
  6463. ;; been displayed for more than `org-scheduled-past-days'.
  6464. (unless (and todayp
  6465. habitp
  6466. (bound-and-true-p org-habit-show-all-today))
  6467. (when (or (and (> ddays 0) (< diff ddays))
  6468. (> diff (or (and habitp org-habit-scheduled-past-days)
  6469. org-scheduled-past-days))
  6470. (> schedule current)
  6471. (and (/= current schedule)
  6472. (/= current today)
  6473. (/= current repeat)))
  6474. (throw :skip nil)))
  6475. ;; Possibly skip done tasks.
  6476. (when (and donep
  6477. (or org-agenda-skip-scheduled-if-done
  6478. (/= schedule current)))
  6479. (throw :skip nil))
  6480. ;; Skip entry if it already appears as a deadline, per
  6481. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  6482. ;; doesn't apply to habits.
  6483. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  6484. ((guard
  6485. (or (not (memq (line-beginning-position 0) deadline-pos))
  6486. habitp))
  6487. nil)
  6488. (`repeated-after-deadline
  6489. (let ((deadline (time-to-days
  6490. (org-get-deadline-time (point)))))
  6491. (and (<= schedule deadline) (> current deadline))))
  6492. (`not-today pastschedp)
  6493. (`t t)
  6494. (_ nil))
  6495. (throw :skip nil))
  6496. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  6497. ;; only show them for today. Also skip done habits.
  6498. (when (and habitp
  6499. (or donep
  6500. (not (bound-and-true-p org-habit-show-habits))
  6501. (and (not todayp)
  6502. (bound-and-true-p
  6503. org-habit-show-habits-only-for-today))))
  6504. (throw :skip nil))
  6505. (save-excursion
  6506. (re-search-backward "^\\*+[ \t]+" nil t)
  6507. (goto-char (match-end 0))
  6508. (let* ((category (org-get-category))
  6509. (effort (save-match-data (or (get-text-property (point) 'effort)
  6510. (org-entry-get (point) org-effort-property))))
  6511. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6512. (inherited-tags
  6513. (or (eq org-agenda-show-inherited-tags 'always)
  6514. (and (listp org-agenda-show-inherited-tags)
  6515. (memq 'agenda org-agenda-show-inherited-tags))
  6516. (and (eq org-agenda-show-inherited-tags t)
  6517. (or (eq org-agenda-use-tag-inheritance t)
  6518. (memq 'agenda
  6519. org-agenda-use-tag-inheritance)))))
  6520. (tags (org-get-tags nil (not inherited-tags)))
  6521. (level (make-string (org-reduced-level (org-outline-level))
  6522. ?\s))
  6523. (head (buffer-substring (point) (line-end-position)))
  6524. (time
  6525. (cond
  6526. ;; No time of day designation if it is only a
  6527. ;; reminder, except for habits, which always show
  6528. ;; the time of day. Habits are an exception
  6529. ;; because if there is a time of day, that is
  6530. ;; interpreted to mean they should usually happen
  6531. ;; then, even if doing the habit was missed.
  6532. ((and
  6533. (not habitp)
  6534. (/= current schedule)
  6535. (/= current repeat))
  6536. nil)
  6537. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6538. (concat (substring s (match-beginning 1)) " "))
  6539. (t 'time)))
  6540. (item
  6541. (org-agenda-format-item
  6542. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  6543. ;; Show a reminder of a past scheduled today.
  6544. (if (and todayp pastschedp)
  6545. (format past diff)
  6546. first))
  6547. (org-add-props head nil
  6548. 'effort effort
  6549. 'effort-minutes effort-minutes)
  6550. level category tags time nil habitp))
  6551. (face (cond ((and (not habitp) pastschedp)
  6552. 'org-scheduled-previously)
  6553. ((and habitp futureschedp)
  6554. 'org-agenda-done)
  6555. (todayp 'org-scheduled-today)
  6556. (t 'org-scheduled)))
  6557. (habitp (and habitp (org-habit-parse-todo))))
  6558. (org-add-props item props
  6559. 'undone-face face
  6560. 'face (if donep 'org-agenda-done face)
  6561. 'org-marker (org-agenda-new-marker pos)
  6562. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6563. 'type (if pastschedp "past-scheduled" "scheduled")
  6564. 'date (if pastschedp schedule date)
  6565. 'ts-date schedule
  6566. 'warntime warntime
  6567. 'level level
  6568. 'effort effort 'effort-minutes effort-minutes
  6569. 'priority (if habitp (org-habit-get-priority habitp)
  6570. (+ 99 diff (org-get-priority item)))
  6571. 'org-habit-p habitp
  6572. 'todo-state todo-state)
  6573. (push item scheduled-items)))))))
  6574. (nreverse scheduled-items)))
  6575. (defun org-agenda-get-blocks ()
  6576. "Return the date-range information for agenda display."
  6577. (with-no-warnings (defvar date))
  6578. (let* ((props (list 'face nil
  6579. 'org-not-done-regexp org-not-done-regexp
  6580. 'org-todo-regexp org-todo-regexp
  6581. 'org-complex-heading-regexp org-complex-heading-regexp
  6582. 'mouse-face 'highlight
  6583. 'help-echo
  6584. (format "mouse-2 or RET jump to org file %s"
  6585. (abbreviate-file-name buffer-file-name))))
  6586. (regexp org-tr-regexp)
  6587. (d0 (calendar-absolute-from-gregorian date))
  6588. marker hdmarker ee txt d1 d2 s1 s2 category
  6589. level todo-state tags pos head donep inherited-tags
  6590. effort effort-minutes)
  6591. (goto-char (point-min))
  6592. (while (re-search-forward regexp nil t)
  6593. (catch :skip
  6594. (org-agenda-skip)
  6595. (setq pos (point))
  6596. (let ((start-time (match-string 1))
  6597. (end-time (match-string 2)))
  6598. (setq s1 (match-string 1)
  6599. s2 (match-string 2)
  6600. d1 (time-to-days
  6601. (condition-case err
  6602. (org-time-string-to-time s1)
  6603. (error
  6604. (error
  6605. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6606. s1
  6607. pos
  6608. (current-buffer)
  6609. (error-message-string err)))))
  6610. d2 (time-to-days
  6611. (condition-case err
  6612. (org-time-string-to-time s2)
  6613. (error
  6614. (error
  6615. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6616. s2
  6617. pos
  6618. (current-buffer)
  6619. (error-message-string err))))))
  6620. (when (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  6621. ;; Only allow days between the limits, because the normal
  6622. ;; date stamps will catch the limits.
  6623. (save-excursion
  6624. (setq todo-state (org-get-todo-state))
  6625. (setq donep (member todo-state org-done-keywords))
  6626. (when (and donep org-agenda-skip-timestamp-if-done)
  6627. (throw :skip t))
  6628. (setq marker (org-agenda-new-marker (point))
  6629. category (org-get-category))
  6630. (setq effort (save-match-data (or (get-text-property (point) 'effort)
  6631. (org-entry-get (point) org-effort-property))))
  6632. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6633. (if (not (re-search-backward org-outline-regexp-bol nil t))
  6634. (throw :skip nil)
  6635. (goto-char (match-beginning 0))
  6636. (setq hdmarker (org-agenda-new-marker (point))
  6637. inherited-tags
  6638. (or (eq org-agenda-show-inherited-tags 'always)
  6639. (and (listp org-agenda-show-inherited-tags)
  6640. (memq 'agenda org-agenda-show-inherited-tags))
  6641. (and (eq org-agenda-show-inherited-tags t)
  6642. (or (eq org-agenda-use-tag-inheritance t)
  6643. (memq 'agenda org-agenda-use-tag-inheritance))))
  6644. tags (org-get-tags nil (not inherited-tags)))
  6645. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  6646. (looking-at "\\*+[ \t]+\\(.*\\)")
  6647. (setq head (match-string 1))
  6648. (let ((remove-re
  6649. (if org-agenda-remove-timeranges-from-blocks
  6650. (concat
  6651. "<" (regexp-quote s1) ".*?>"
  6652. "--"
  6653. "<" (regexp-quote s2) ".*?>")
  6654. nil)))
  6655. (setq txt (org-agenda-format-item
  6656. (format
  6657. (nth (if (= d1 d2) 0 1)
  6658. org-agenda-timerange-leaders)
  6659. (1+ (- d0 d1)) (1+ (- d2 d1)))
  6660. (org-add-props head nil
  6661. 'effort effort
  6662. 'effort-minutes effort-minutes)
  6663. level category tags
  6664. (save-match-data
  6665. (let ((hhmm1 (and (string-match org-ts-regexp1 s1)
  6666. (match-string 6 s1)))
  6667. (hhmm2 (and (string-match org-ts-regexp1 s2)
  6668. (match-string 6 s2))))
  6669. (cond ((string= hhmm1 hhmm2)
  6670. (concat "<" start-time ">--<" end-time ">"))
  6671. ((and (= d1 d0) (= d2 d0))
  6672. (concat "<" start-time ">--<" end-time ">"))
  6673. ((= d1 d0)
  6674. (concat "<" start-time ">"))
  6675. ((= d2 d0)
  6676. (concat "<" end-time ">")))))
  6677. remove-re))))
  6678. (org-add-props txt props
  6679. 'org-marker marker 'org-hd-marker hdmarker
  6680. 'type "block" 'date date
  6681. 'level level
  6682. 'effort effort 'effort-minutes effort-minutes
  6683. 'todo-state todo-state
  6684. 'priority (org-get-priority txt))
  6685. (push txt ee))))
  6686. (goto-char pos)))
  6687. ;; Sort the entries by expiration date.
  6688. (nreverse ee)))
  6689. ;;; Agenda presentation and sorting
  6690. (defvar org-prefix-has-time nil
  6691. "A flag, set by `org-compile-prefix-format'.
  6692. The flag is set if the currently compiled format contains a `%t'.")
  6693. (defvar org-prefix-has-tag nil
  6694. "A flag, set by `org-compile-prefix-format'.
  6695. The flag is set if the currently compiled format contains a `%T'.")
  6696. (defvar org-prefix-has-effort nil
  6697. "A flag, set by `org-compile-prefix-format'.
  6698. The flag is set if the currently compiled format contains a `%e'.")
  6699. (defvar org-prefix-has-breadcrumbs nil
  6700. "A flag, set by `org-compile-prefix-format'.
  6701. The flag is set if the currently compiled format contains a `%b'.")
  6702. (defvar org-prefix-category-length nil
  6703. "Used by `org-compile-prefix-format' to remember the category field width.")
  6704. (defvar org-prefix-category-max-length nil
  6705. "Used by `org-compile-prefix-format' to remember the category field width.")
  6706. (defun org-agenda-get-category-icon (category)
  6707. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  6708. (cl-dolist (entry org-agenda-category-icon-alist)
  6709. (when (string-match-p (car entry) category)
  6710. (if (listp (cadr entry))
  6711. (cl-return (cadr entry))
  6712. (cl-return (apply #'create-image (cdr entry)))))))
  6713. (defun org-agenda-format-item (extra txt &optional with-level with-category tags dotime
  6714. remove-re habitp)
  6715. "Format TXT to be inserted into the agenda buffer.
  6716. In particular, add the prefix and corresponding text properties.
  6717. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  6718. WITH-LEVEL may be a string to replace the `%l' specifier.
  6719. WITH-CATEGORY (a string, a symbol or nil) may be used to overrule the default
  6720. category taken from local variable or file name. It will replace the `%c'
  6721. specifier in the format.
  6722. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  6723. TXT for sorting of this entry, and for the `%t' specifier in the format.
  6724. When DOTIME is a string, this string is searched for a time before TXT is.
  6725. TAGS can be the tags of the headline.
  6726. Any match of REMOVE-RE will be removed from TXT."
  6727. ;; We keep the org-prefix-* variable values along with a compiled
  6728. ;; formatter, so that multiple agendas existing at the same time do
  6729. ;; not step on each other toes.
  6730. ;;
  6731. ;; It was inconvenient to make these variables buffer local in
  6732. ;; Agenda buffers, because this function expects to be called with
  6733. ;; the buffer where item comes from being current, and not agenda
  6734. ;; buffer
  6735. (let* ((bindings (car org-prefix-format-compiled))
  6736. (formatter (cadr org-prefix-format-compiled)))
  6737. (cl-loop for (var value) in bindings
  6738. do (set var value))
  6739. (save-match-data
  6740. ;; Diary entries sometimes have extra whitespace at the beginning
  6741. (setq txt (org-trim txt))
  6742. ;; Fix the tags part in txt
  6743. (setq txt (org-agenda-fix-displayed-tags
  6744. txt tags
  6745. org-agenda-show-inherited-tags
  6746. org-agenda-hide-tags-regexp))
  6747. (with-no-warnings
  6748. ;; `time', `tag', `effort' are needed for the eval of the prefix format.
  6749. ;; Based on what I see in `org-compile-prefix-format', I added
  6750. ;; a few more.
  6751. (defvar breadcrumbs) (defvar category) (defvar category-icon)
  6752. (defvar effort) (defvar extra)
  6753. (defvar level) (defvar tag) (defvar time))
  6754. (let* ((category (or with-category
  6755. (if buffer-file-name
  6756. (file-name-sans-extension
  6757. (file-name-nondirectory buffer-file-name))
  6758. "")))
  6759. (category-icon (org-agenda-get-category-icon category))
  6760. (category-icon (if category-icon
  6761. (propertize " " 'display category-icon)
  6762. ""))
  6763. (effort (and (not (string= txt ""))
  6764. (get-text-property 1 'effort txt)))
  6765. (tag (if tags (nth (1- (length tags)) tags) ""))
  6766. (time-grid-trailing-characters (nth 2 org-agenda-time-grid))
  6767. (extra (or (and (not habitp) extra) ""))
  6768. time
  6769. (ts (when dotime (concat
  6770. (if (stringp dotime) dotime "")
  6771. (and org-agenda-search-headline-for-time txt))))
  6772. (time-of-day (and dotime (org-get-time-of-day ts)))
  6773. stamp plain s0 s1 s2 rtn srp l
  6774. duration breadcrumbs)
  6775. (and (derived-mode-p 'org-mode) buffer-file-name
  6776. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6777. (when (and dotime time-of-day)
  6778. ;; Extract starting and ending time and move them to prefix
  6779. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6780. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6781. (setq s0 (match-string 0 ts)
  6782. srp (and stamp (match-end 3))
  6783. s1 (match-string (if plain 1 2) ts)
  6784. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6785. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6786. ;; them, we might want to remove them there to avoid duplication.
  6787. ;; The user can turn this off with a variable.
  6788. (when (and org-prefix-has-time
  6789. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6790. (string-match (concat (regexp-quote s0) " *") txt)
  6791. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6792. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6793. (= (match-beginning 0) 0)
  6794. t))
  6795. (setq txt (replace-match "" nil nil txt))))
  6796. ;; Normalize the time(s) to 24 hour.
  6797. (when s1 (setq s1 (org-get-time-of-day s1 t)))
  6798. (when s2 (setq s2 (org-get-time-of-day s2 t)))
  6799. ;; Try to set s2 if s1 and
  6800. ;; `org-agenda-default-appointment-duration' are set
  6801. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6802. (setq s2
  6803. (org-duration-from-minutes
  6804. (+ (org-duration-to-minutes s1 t)
  6805. org-agenda-default-appointment-duration)
  6806. nil t)))
  6807. ;; Compute the duration
  6808. (when s2
  6809. (setq duration (- (org-duration-to-minutes s2)
  6810. (org-duration-to-minutes s1))))
  6811. ;; Format S1 and S2 for display.
  6812. (when s1 (setq s1 (format "%5s" (org-get-time-of-day s1 'overtime))))
  6813. (when s2 (setq s2 (org-get-time-of-day s2 'overtime))))
  6814. (when (string-match org-tag-group-re txt)
  6815. ;; Tags are in the string
  6816. (if (or (eq org-agenda-remove-tags t)
  6817. (and org-agenda-remove-tags
  6818. org-prefix-has-tag))
  6819. (setq txt (replace-match "" t t txt))
  6820. (setq txt (replace-match
  6821. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6822. (match-string 1 txt))
  6823. t t txt))))
  6824. (when remove-re
  6825. (while (string-match remove-re txt)
  6826. (setq txt (replace-match "" t t txt))))
  6827. ;; Set org-heading property on `txt' to mark the start of the
  6828. ;; heading.
  6829. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6830. ;; Prepare the variables needed in the eval of the compiled format
  6831. (when org-prefix-has-breadcrumbs
  6832. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6833. (let ((s (org-format-outline-path (org-get-outline-path)
  6834. (1- (frame-width))
  6835. nil org-agenda-breadcrumbs-separator)))
  6836. (if (eq "" s) "" (concat s org-agenda-breadcrumbs-separator))))))
  6837. (setq time (cond (s2 (concat
  6838. (org-agenda-time-of-day-to-ampm-maybe s1)
  6839. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6840. (when org-agenda-timegrid-use-ampm " ")))
  6841. (s1 (concat
  6842. (org-agenda-time-of-day-to-ampm-maybe s1)
  6843. (if org-agenda-timegrid-use-ampm
  6844. (concat time-grid-trailing-characters " ")
  6845. time-grid-trailing-characters)))
  6846. (t ""))
  6847. category (if (symbolp category) (symbol-name category) category)
  6848. level (or with-level ""))
  6849. (if (string-match org-link-bracket-re category)
  6850. (progn
  6851. (setq l (string-width (or (match-string 2) (match-string 1))))
  6852. (when (< l (or org-prefix-category-length 0))
  6853. (setq category (copy-sequence category))
  6854. (org-add-props category nil
  6855. 'extra-space (make-string
  6856. (- org-prefix-category-length l 1) ?\ ))))
  6857. (when (and org-prefix-category-max-length
  6858. (>= (length category) org-prefix-category-max-length))
  6859. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6860. ;; Evaluate the compiled format
  6861. (setq rtn (concat (eval formatter t) txt))
  6862. ;; And finally add the text properties
  6863. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6864. (org-add-props rtn nil
  6865. 'org-category category
  6866. 'tags tags
  6867. 'org-priority-highest org-priority-highest
  6868. 'org-priority-lowest org-priority-lowest
  6869. 'time-of-day time-of-day
  6870. 'duration duration
  6871. 'breadcrumbs breadcrumbs
  6872. 'txt txt
  6873. 'level level
  6874. 'time time
  6875. 'extra extra
  6876. 'format org-prefix-format-compiled
  6877. 'dotime dotime)))))
  6878. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6879. "Remove tags string from TXT, and add a modified list of tags.
  6880. The modified list may contain inherited tags, and tags matched by
  6881. `org-agenda-hide-tags-regexp' will be removed."
  6882. (when (or add-inherited hide-re)
  6883. (when (string-match org-tag-group-re txt)
  6884. (setq txt (substring txt 0 (match-beginning 0))))
  6885. (setq tags
  6886. (delq nil
  6887. (mapcar (lambda (tg)
  6888. (if (or (and hide-re (string-match hide-re tg))
  6889. (and (not add-inherited)
  6890. (get-text-property 0 'inherited tg)))
  6891. nil
  6892. tg))
  6893. tags)))
  6894. (when tags
  6895. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6896. i)
  6897. (setq txt (concat txt " :"
  6898. (mapconcat
  6899. (lambda (x)
  6900. (setq i (get-text-property 0 'inherited x))
  6901. (if (and have-i (not i))
  6902. (progn
  6903. (setq have-i nil)
  6904. (concat ":" x))
  6905. x))
  6906. tags ":")
  6907. (if have-i "::" ":"))))))
  6908. txt)
  6909. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6910. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6911. "Add a time-grid for agenda items which need it.
  6912. LIST is the list of agenda items formatted by `org-agenda-list'.
  6913. NDAYS is the span of the current agenda view.
  6914. TODAYP is t when the current agenda view is on today."
  6915. (catch 'exit
  6916. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6917. ((and todayp (member 'today (car org-agenda-time-grid))))
  6918. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6919. ((member 'weekly (car org-agenda-time-grid)))
  6920. (t (throw 'exit list)))
  6921. (let* ((have (delq nil (mapcar
  6922. (lambda (x) (get-text-property 1 'time-of-day x))
  6923. list)))
  6924. (string (nth 3 org-agenda-time-grid))
  6925. (gridtimes (nth 1 org-agenda-time-grid))
  6926. (req (car org-agenda-time-grid))
  6927. (remove (member 'remove-match req))
  6928. new time)
  6929. (when (and (member 'require-timed req) (not have))
  6930. ;; don't show empty grid
  6931. (throw 'exit list))
  6932. (while (setq time (pop gridtimes))
  6933. (unless (and remove (member time have))
  6934. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6935. (push (org-agenda-format-item
  6936. nil string nil "" nil
  6937. (concat (substring time 0 -2) ":" (substring time -2)))
  6938. new)
  6939. (put-text-property
  6940. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6941. (when (and todayp org-agenda-show-current-time-in-grid)
  6942. (push (org-agenda-format-item
  6943. nil org-agenda-current-time-string nil "" nil
  6944. (format-time-string "%H:%M "))
  6945. new)
  6946. (put-text-property
  6947. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6948. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6949. (append new list)
  6950. (append list new)))))
  6951. (defun org-compile-prefix-format (key)
  6952. "Compile the prefix format into a Lisp form that can be evaluated.
  6953. KEY is the agenda type (see `org-agenda-prefix-format').
  6954. The resulting form and associated variable bindings is returned
  6955. and stored in the variable `org-prefix-format-compiled'."
  6956. (setq org-prefix-has-time nil
  6957. org-prefix-has-tag nil
  6958. org-prefix-category-length nil
  6959. org-prefix-has-effort nil
  6960. org-prefix-has-breadcrumbs nil)
  6961. (let ((s (cond
  6962. ((stringp org-agenda-prefix-format)
  6963. org-agenda-prefix-format)
  6964. ((assq key org-agenda-prefix-format)
  6965. (cdr (assq key org-agenda-prefix-format)))
  6966. (t " %-12:c%?-12t% s")))
  6967. (start 0)
  6968. varform vars var c f opt) ;; e
  6969. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+?)\\)"
  6970. s start)
  6971. (setq var (or (cdr (assoc (match-string 4 s)
  6972. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6973. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6974. 'eval)
  6975. c (or (match-string 3 s) "")
  6976. opt (match-beginning 1)
  6977. start (1+ (match-beginning 0)))
  6978. (cl-case var
  6979. (time (setq org-prefix-has-time t))
  6980. (tag (setq org-prefix-has-tag t))
  6981. (effort (setq org-prefix-has-effort t))
  6982. (breadcrumbs (setq org-prefix-has-breadcrumbs t)))
  6983. (setq f (concat "%" (match-string 2 s) "s"))
  6984. (when (eq var 'category)
  6985. (setq org-prefix-category-length
  6986. (floor (abs (string-to-number (match-string 2 s)))))
  6987. (setq org-prefix-category-max-length
  6988. (let ((x (match-string 2 s)))
  6989. (save-match-data
  6990. (and (string-match "\\.[0-9]+" x)
  6991. (string-to-number (substring (match-string 0 x) 1)))))))
  6992. (if (eq var 'eval)
  6993. (setq varform `(format ,f (org-eval ,(read (substring s (match-beginning 4))))))
  6994. (if opt
  6995. (setq varform
  6996. `(if (member ,var '("" nil))
  6997. ""
  6998. (format ,f (concat ,var ,c))))
  6999. (setq varform
  7000. `(format ,f (if (member ,var '("" nil)) ""
  7001. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  7002. (if (eq var 'eval)
  7003. (setf (substring s (match-beginning 0)
  7004. (+ (match-beginning 4)
  7005. (length (format "%S" (read (substring s (match-beginning 4)))))))
  7006. "%s")
  7007. (setq s (replace-match "%s" t nil s)))
  7008. (push varform vars))
  7009. (setq vars (nreverse vars))
  7010. (with-current-buffer (or org-agenda-buffer (current-buffer))
  7011. (setq org-prefix-format-compiled
  7012. (list
  7013. `((org-prefix-has-time ,org-prefix-has-time)
  7014. (org-prefix-has-tag ,org-prefix-has-tag)
  7015. (org-prefix-category-length ,org-prefix-category-length)
  7016. (org-prefix-has-effort ,org-prefix-has-effort)
  7017. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  7018. `(format ,s ,@vars))))))
  7019. (defun org-set-sorting-strategy (key)
  7020. (setq org-agenda-sorting-strategy-selected
  7021. (if (symbolp (car org-agenda-sorting-strategy))
  7022. ;; the old format
  7023. org-agenda-sorting-strategy
  7024. (or (cdr (assq key org-agenda-sorting-strategy))
  7025. (cdr (assq 'agenda org-agenda-sorting-strategy))
  7026. '(time-up category-keep priority-down)))))
  7027. (defun org-get-time-of-day (s &optional string)
  7028. "Check string S for a time of day.
  7029. If found, return it as a military time number between 0 and 2400.
  7030. If not found, return nil.
  7031. The optional STRING argument forces conversion into a 5 character wide string
  7032. HH:MM. When it is `overtime', any time above 24:00 is turned into \"+H:MM\"
  7033. where H:MM is the duration above midnight."
  7034. (let ((case-fold-search t)
  7035. (time-regexp
  7036. (rx word-start
  7037. (group (opt (any "012")) digit) ;group 1: hours
  7038. (or (and ":" (group (any "012345") digit) ;group 2: minutes
  7039. (opt (group (or "am" "pm")))) ;group 3: am/pm
  7040. ;; Special "HHam/pm" case.
  7041. (group-n 3 (or "am" "pm")))
  7042. word-end)))
  7043. (save-match-data
  7044. (when (and (string-match time-regexp s)
  7045. (not (eq 'org-link (get-text-property 1 'face s))))
  7046. (let ((hours
  7047. (let* ((ampm (and (match-end 3) (downcase (match-string 3 s))))
  7048. (am-p (equal ampm "am")))
  7049. (pcase (string-to-number (match-string 1 s))
  7050. ((and (guard (not ampm)) h) h)
  7051. (12 (if am-p 0 12))
  7052. (h (+ h (if am-p 0 12))))))
  7053. (minutes
  7054. (if (match-end 2)
  7055. (string-to-number (match-string 2 s))
  7056. 0)))
  7057. (pcase string
  7058. (`nil (+ minutes (* hours 100)))
  7059. ((and `overtime
  7060. (guard (or (> hours 24)
  7061. (and (= hours 24)
  7062. (> minutes 0)))))
  7063. (format "+%d:%02d" (- hours 24) minutes))
  7064. ((guard org-agenda-time-leading-zero)
  7065. (format "%02d:%02d" hours minutes))
  7066. (_
  7067. (format "%d:%02d" hours minutes))))))))
  7068. (defvar org-agenda-before-sorting-filter-function nil
  7069. "Function to be applied to agenda items prior to sorting.
  7070. Prior to sorting also means just before they are inserted into the agenda.
  7071. To aid sorting, you may revisit the original entries and add more text
  7072. properties which will later be used by the sorting functions.
  7073. The function should take a string argument, an agenda line.
  7074. It has access to the text properties in that line, which contain among
  7075. other things, the property `org-hd-marker' that points to the entry
  7076. where the line comes from. Note that not all lines going into the agenda
  7077. have this property, only most.
  7078. The function should return the modified string. It is probably best
  7079. to ONLY change text properties.
  7080. You can also use this function as a filter, by returning nil for lines
  7081. you don't want to have in the agenda at all. For this application, you
  7082. could bind the variable in the options section of a custom command.")
  7083. (defun org-agenda-finalize-entries (list &optional type)
  7084. "Sort, limit and concatenate the LIST of agenda items.
  7085. The optional argument TYPE tells the agenda type."
  7086. (let ((max-effort (cond ((listp org-agenda-max-effort)
  7087. (cdr (assoc type org-agenda-max-effort)))
  7088. (t org-agenda-max-effort)))
  7089. (max-todo (cond ((listp org-agenda-max-todos)
  7090. (cdr (assoc type org-agenda-max-todos)))
  7091. (t org-agenda-max-todos)))
  7092. (max-tags (cond ((listp org-agenda-max-tags)
  7093. (cdr (assoc type org-agenda-max-tags)))
  7094. (t org-agenda-max-tags)))
  7095. (max-entries (cond ((listp org-agenda-max-entries)
  7096. (cdr (assoc type org-agenda-max-entries)))
  7097. (t org-agenda-max-entries))))
  7098. (when org-agenda-before-sorting-filter-function
  7099. (setq list
  7100. (delq nil
  7101. (mapcar
  7102. org-agenda-before-sorting-filter-function list))))
  7103. (setq list (mapcar #'org-agenda-highlight-todo list)
  7104. list (mapcar #'identity (sort list #'org-entries-lessp)))
  7105. (when max-effort
  7106. (setq list (org-agenda-limit-entries
  7107. list 'effort-minutes max-effort
  7108. (lambda (e) (or e (if org-agenda-sort-noeffort-is-high
  7109. 32767 -1))))))
  7110. (when max-todo
  7111. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  7112. (when max-tags
  7113. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  7114. (when max-entries
  7115. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  7116. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  7117. (setq list (mapcar #'org-agenda--mark-blocked-entry list)))
  7118. (mapconcat #'identity list "\n")))
  7119. (defun org-agenda-limit-entries (list prop limit &optional fn)
  7120. "Limit the number of agenda entries."
  7121. (let ((include (and limit (< limit 0))))
  7122. (if limit
  7123. (let ((fun (or fn (lambda (p) (when p 1))))
  7124. (lim 0))
  7125. (delq nil
  7126. (mapcar
  7127. (lambda (e)
  7128. (let ((pval (funcall
  7129. fun (get-text-property (1- (length e))
  7130. prop e))))
  7131. (when pval (setq lim (+ lim pval)))
  7132. (cond ((and pval (<= lim (abs limit))) e)
  7133. ((and include (not pval)) e))))
  7134. list)))
  7135. list)))
  7136. (defun org-agenda-limit-interactively (remove)
  7137. "In agenda, interactively limit entries to various maximums."
  7138. (interactive "P")
  7139. (if remove
  7140. (progn (setq org-agenda-max-entries nil
  7141. org-agenda-max-todos nil
  7142. org-agenda-max-tags nil
  7143. org-agenda-max-effort nil)
  7144. (org-agenda-redo))
  7145. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  7146. (msg (cond ((= max ?E) "How many minutes? ")
  7147. ((= max ?e) "How many entries? ")
  7148. ((= max ?t) "How many TODO entries? ")
  7149. ((= max ?T) "How many tagged entries? ")
  7150. (t (user-error "Wrong input"))))
  7151. (num (string-to-number (read-from-minibuffer msg))))
  7152. (cond ((equal max ?e)
  7153. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  7154. ((equal max ?t)
  7155. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  7156. ((equal max ?T)
  7157. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  7158. ((equal max ?E)
  7159. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  7160. (org-agenda-fit-window-to-buffer))
  7161. (defun org-agenda-highlight-todo (x)
  7162. (let ((org-done-keywords org-done-keywords-for-agenda)
  7163. (case-fold-search nil)
  7164. re)
  7165. (if (eq x 'line)
  7166. (save-excursion
  7167. (beginning-of-line 1)
  7168. (setq re (org-get-at-bol 'org-todo-regexp))
  7169. (goto-char (or (text-property-any (line-beginning-position)
  7170. (line-end-position)
  7171. 'org-heading t)
  7172. (point)))
  7173. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  7174. (add-text-properties (match-beginning 0) (match-end 1)
  7175. (list 'face (org-get-todo-face 1)))
  7176. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  7177. (delete-region (match-beginning 1) (1- (match-end 0)))
  7178. (goto-char (match-beginning 1))
  7179. (insert (format org-agenda-todo-keyword-format s)))))
  7180. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  7181. (setq re (get-text-property 0 'org-todo-regexp x))
  7182. (when (and re
  7183. ;; Test `pl' because if there's no heading content,
  7184. ;; there's no point matching to highlight. Note
  7185. ;; that if we didn't test `pl' first, and there
  7186. ;; happened to be no keyword from `org-todo-regexp'
  7187. ;; on this heading line, then the `equal' comparison
  7188. ;; afterwards would spuriously succeed in the case
  7189. ;; where `pl' is nil -- causing an args-out-of-range
  7190. ;; error when we try to add text properties to text
  7191. ;; that isn't there.
  7192. pl
  7193. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  7194. x pl)
  7195. pl))
  7196. (add-text-properties
  7197. (or (match-end 1) (match-end 0)) (match-end 0)
  7198. (list 'face (org-get-todo-face (match-string 2 x)))
  7199. x)
  7200. (when (match-end 1)
  7201. (setq x
  7202. (concat
  7203. (substring x 0 (match-end 1))
  7204. (unless (string= org-agenda-todo-keyword-format "")
  7205. (format org-agenda-todo-keyword-format
  7206. (match-string 2 x)))
  7207. (unless (string= org-agenda-todo-keyword-format "")
  7208. ;; Remove `display' property as the icon could leak
  7209. ;; on the white space.
  7210. (org-add-props " " (org-plist-delete (text-properties-at 0 x)
  7211. 'display)))
  7212. (substring x (match-end 3)))))))
  7213. x)))
  7214. (defsubst org-cmp-values (a b property)
  7215. "Compare the numeric value of text PROPERTY for string A and B."
  7216. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  7217. (pb (or (get-text-property (1- (length b)) property b) 0)))
  7218. (cond ((> pa pb) +1)
  7219. ((< pa pb) -1))))
  7220. (defsubst org-cmp-effort (a b)
  7221. "Compare the effort values of string A and B."
  7222. (let* ((def (if org-agenda-sort-noeffort-is-high 32767 -1))
  7223. ;; `effort-minutes' property is not directly accessible from
  7224. ;; the strings, but is stored as a property in `txt'.
  7225. (ea (or (get-text-property
  7226. 0 'effort-minutes (get-text-property 0 'txt a))
  7227. def))
  7228. (eb (or (get-text-property
  7229. 0 'effort-minutes (get-text-property 0 'txt b))
  7230. def)))
  7231. (cond ((> ea eb) +1)
  7232. ((< ea eb) -1))))
  7233. (defsubst org-cmp-category (a b)
  7234. "Compare the string values of categories of strings A and B."
  7235. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  7236. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  7237. (cond ((string-lessp ca cb) -1)
  7238. ((string-lessp cb ca) +1))))
  7239. (defsubst org-cmp-todo-state (a b)
  7240. "Compare the todo states of strings A and B."
  7241. (let* ((ma (or (get-text-property 1 'org-marker a)
  7242. (get-text-property 1 'org-hd-marker a)))
  7243. (mb (or (get-text-property 1 'org-marker b)
  7244. (get-text-property 1 'org-hd-marker b)))
  7245. (fa (and ma (marker-buffer ma)))
  7246. (fb (and mb (marker-buffer mb)))
  7247. (todo-kwds
  7248. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  7249. (and fb (with-current-buffer fb org-todo-keywords-1))))
  7250. (ta (or (get-text-property 1 'todo-state a) ""))
  7251. (tb (or (get-text-property 1 'todo-state b) ""))
  7252. (la (- (length (member ta todo-kwds))))
  7253. (lb (- (length (member tb todo-kwds))))
  7254. (donepa (member ta org-done-keywords-for-agenda))
  7255. (donepb (member tb org-done-keywords-for-agenda)))
  7256. (cond ((and donepa (not donepb)) -1)
  7257. ((and (not donepa) donepb) +1)
  7258. ((< la lb) -1)
  7259. ((< lb la) +1))))
  7260. (defsubst org-cmp-alpha (a b)
  7261. "Compare the headlines, alphabetically."
  7262. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  7263. (plb (text-property-any 0 (length b) 'org-heading t b))
  7264. (ta (and pla (substring a pla)))
  7265. (tb (and plb (substring b plb)))
  7266. (case-fold-search nil))
  7267. (when pla
  7268. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  7269. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  7270. ta)
  7271. (setq ta (substring ta (match-end 0))))
  7272. (setq ta (downcase ta)))
  7273. (when plb
  7274. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  7275. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  7276. tb)
  7277. (setq tb (substring tb (match-end 0))))
  7278. (setq tb (downcase tb)))
  7279. (cond ((not (or ta tb)) nil)
  7280. ((not ta) +1)
  7281. ((not tb) -1)
  7282. ((string-lessp ta tb) -1)
  7283. ((string-lessp tb ta) +1))))
  7284. (defsubst org-cmp-tag (a b)
  7285. "Compare the string values of the first tags of A and B."
  7286. (let ((ta (car (last (get-text-property 1 'tags a))))
  7287. (tb (car (last (get-text-property 1 'tags b)))))
  7288. (cond ((not (or ta tb)) nil)
  7289. ((not ta) +1)
  7290. ((not tb) -1)
  7291. ((string-lessp ta tb) -1)
  7292. ((string-lessp tb ta) +1))))
  7293. (defsubst org-cmp-time (a b)
  7294. "Compare the time-of-day values of strings A and B."
  7295. (let* ((def (if org-agenda-sort-notime-is-late 9901 -1))
  7296. (ta (or (get-text-property 1 'time-of-day a) def))
  7297. (tb (or (get-text-property 1 'time-of-day b) def)))
  7298. (cond ((< ta tb) -1)
  7299. ((< tb ta) +1))))
  7300. (defsubst org-cmp-ts (a b type)
  7301. "Compare the timestamps values of entries A and B.
  7302. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  7303. \"timestamp_ia\", compare within each of these type. When TYPE
  7304. is the empty string, compare all timestamps without respect of
  7305. their type."
  7306. (let* ((def (if org-agenda-sort-notime-is-late 99999999 -1))
  7307. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  7308. (get-text-property 1 'ts-date a))
  7309. def))
  7310. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  7311. (get-text-property 1 'ts-date b))
  7312. def)))
  7313. (cond ((if ta (and tb (< ta tb)) tb) -1)
  7314. ((if tb (and ta (< tb ta)) ta) +1))))
  7315. (defsubst org-cmp-habit-p (a b)
  7316. "Compare the todo states of strings A and B."
  7317. (let ((ha (get-text-property 1 'org-habit-p a))
  7318. (hb (get-text-property 1 'org-habit-p b)))
  7319. (cond ((and ha (not hb)) -1)
  7320. ((and (not ha) hb) +1))))
  7321. (defun org-entries-lessp (a b)
  7322. "Predicate for sorting agenda entries."
  7323. ;; The following variables will be used when the form is evaluated.
  7324. ;; So even though the compiler complains, keep them.
  7325. (let ((ss org-agenda-sorting-strategy-selected))
  7326. (org-dlet
  7327. ((timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  7328. (org-cmp-ts a b "")))
  7329. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  7330. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  7331. (org-cmp-ts a b "scheduled")))
  7332. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  7333. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  7334. (org-cmp-ts a b "deadline")))
  7335. (deadline-down (if deadline-up (- deadline-up) nil))
  7336. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  7337. (org-cmp-ts a b "timestamp_ia")))
  7338. (tsia-down (if tsia-up (- tsia-up) nil))
  7339. (ts-up (and (org-em 'ts-up 'ts-down ss)
  7340. (org-cmp-ts a b "timestamp")))
  7341. (ts-down (if ts-up (- ts-up) nil))
  7342. (time-up (and (org-em 'time-up 'time-down ss)
  7343. (org-cmp-time a b)))
  7344. (time-down (if time-up (- time-up) nil))
  7345. (stats-up (and (org-em 'stats-up 'stats-down ss)
  7346. (org-cmp-values a b 'org-stats)))
  7347. (stats-down (if stats-up (- stats-up) nil))
  7348. (priority-up (and (org-em 'priority-up 'priority-down ss)
  7349. (org-cmp-values a b 'priority)))
  7350. (priority-down (if priority-up (- priority-up) nil))
  7351. (effort-up (and (org-em 'effort-up 'effort-down ss)
  7352. (org-cmp-effort a b)))
  7353. (effort-down (if effort-up (- effort-up) nil))
  7354. (category-up (and (or (org-em 'category-up 'category-down ss)
  7355. (memq 'category-keep ss))
  7356. (org-cmp-category a b)))
  7357. (category-down (if category-up (- category-up) nil))
  7358. (category-keep (if category-up +1 nil))
  7359. (tag-up (and (org-em 'tag-up 'tag-down ss)
  7360. (org-cmp-tag a b)))
  7361. (tag-down (if tag-up (- tag-up) nil))
  7362. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  7363. (org-cmp-todo-state a b)))
  7364. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  7365. (habit-up (and (org-em 'habit-up 'habit-down ss)
  7366. (org-cmp-habit-p a b)))
  7367. (habit-down (if habit-up (- habit-up) nil))
  7368. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  7369. (org-cmp-alpha a b)))
  7370. (alpha-down (if alpha-up (- alpha-up) nil))
  7371. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  7372. user-defined-up user-defined-down)
  7373. (when (and need-user-cmp org-agenda-cmp-user-defined
  7374. (functionp org-agenda-cmp-user-defined))
  7375. (setq user-defined-up
  7376. (funcall org-agenda-cmp-user-defined a b)
  7377. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  7378. (cdr (assoc
  7379. (eval (cons 'or org-agenda-sorting-strategy-selected) t)
  7380. '((-1 . t) (1 . nil) (nil . nil)))))))
  7381. ;;; Agenda restriction lock
  7382. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  7383. "Overlay to mark the headline to which agenda commands are restricted.")
  7384. (overlay-put org-agenda-restriction-lock-overlay
  7385. 'face 'org-agenda-restriction-lock)
  7386. (overlay-put org-agenda-restriction-lock-overlay
  7387. 'help-echo "Agendas are currently limited to this subtree.")
  7388. (delete-overlay org-agenda-restriction-lock-overlay)
  7389. (defun org-agenda-set-restriction-lock-from-agenda (arg)
  7390. "Set the restriction lock to the agenda item at point from within the agenda.
  7391. When called with a `\\[universal-argument]' prefix, restrict to
  7392. the file which contains the item.
  7393. Argument ARG is the prefix argument."
  7394. (interactive "P")
  7395. (unless (derived-mode-p 'org-agenda-mode)
  7396. (user-error "Not in an Org agenda buffer"))
  7397. (let* ((marker (or (org-get-at-bol 'org-marker)
  7398. (org-agenda-error)))
  7399. (buffer (marker-buffer marker))
  7400. (pos (marker-position marker)))
  7401. (with-current-buffer buffer
  7402. (goto-char pos)
  7403. (org-agenda-set-restriction-lock arg))))
  7404. ;;;###autoload
  7405. (defun org-agenda-set-restriction-lock (&optional type)
  7406. "Set restriction lock for agenda to current subtree or file.
  7407. When in a restricted subtree, remove it.
  7408. The restriction will span over the entire file if TYPE is `file',
  7409. or if TYPE is (4), or if the cursor is before the first headline
  7410. in the file. Otherwise, only apply the restriction to the current
  7411. subtree."
  7412. (interactive "P")
  7413. (if (and org-agenda-overriding-restriction
  7414. (member org-agenda-restriction-lock-overlay
  7415. (overlays-at (point)))
  7416. (equal (overlay-start org-agenda-restriction-lock-overlay)
  7417. (point)))
  7418. (org-agenda-remove-restriction-lock 'noupdate)
  7419. (org-agenda-remove-restriction-lock 'noupdate)
  7420. (and (equal type '(4)) (setq type 'file))
  7421. (setq type (cond
  7422. (type type)
  7423. ((org-at-heading-p) 'subtree)
  7424. ((condition-case nil (org-back-to-heading t) (error nil))
  7425. 'subtree)
  7426. (t 'file)))
  7427. (if (eq type 'subtree)
  7428. (progn
  7429. (setq org-agenda-restrict (current-buffer))
  7430. (setq org-agenda-overriding-restriction 'subtree)
  7431. (put 'org-agenda-files 'org-restrict
  7432. (list (buffer-file-name (buffer-base-buffer))))
  7433. (org-back-to-heading t)
  7434. (move-overlay org-agenda-restriction-lock-overlay
  7435. (point)
  7436. (if org-agenda-restriction-lock-highlight-subtree
  7437. (save-excursion (org-end-of-subtree t t) (point))
  7438. (line-end-position)))
  7439. (move-marker org-agenda-restrict-begin (point))
  7440. (move-marker org-agenda-restrict-end
  7441. (save-excursion (org-end-of-subtree t t)))
  7442. (message "Locking agenda restriction to subtree"))
  7443. (put 'org-agenda-files 'org-restrict
  7444. (list (buffer-file-name (buffer-base-buffer))))
  7445. (setq org-agenda-restrict t)
  7446. (setq org-agenda-overriding-restriction 'file)
  7447. (move-marker org-agenda-restrict-begin nil)
  7448. (move-marker org-agenda-restrict-end nil)
  7449. (message "Locking agenda restriction to file"))
  7450. (setq current-prefix-arg nil))
  7451. (org-agenda-maybe-redo))
  7452. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  7453. "Remove agenda restriction lock."
  7454. (interactive "P")
  7455. (if (not org-agenda-restrict)
  7456. (message "No agenda restriction to remove.")
  7457. (delete-overlay org-agenda-restriction-lock-overlay)
  7458. (delete-overlay org-speedbar-restriction-lock-overlay)
  7459. (setq org-agenda-overriding-restriction nil)
  7460. (setq org-agenda-restrict nil)
  7461. (put 'org-agenda-files 'org-restrict nil)
  7462. (move-marker org-agenda-restrict-begin nil)
  7463. (move-marker org-agenda-restrict-end nil)
  7464. (setq current-prefix-arg nil)
  7465. (message "Agenda restriction lock removed")
  7466. (or noupdate (org-agenda-maybe-redo))))
  7467. (defun org-agenda-maybe-redo ()
  7468. "If there is any window showing the agenda view, update it."
  7469. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  7470. org-agenda-buffer-name)
  7471. t))
  7472. (w0 (selected-window)))
  7473. (when w
  7474. (select-window w)
  7475. (org-agenda-redo)
  7476. (select-window w0)
  7477. (if org-agenda-overriding-restriction
  7478. (message "Agenda view shifted to new %s restriction"
  7479. org-agenda-overriding-restriction)
  7480. (message "Agenda restriction lock removed")))))
  7481. ;;; Agenda commands
  7482. (defun org-agenda-check-type (error &rest types)
  7483. "Check if agenda buffer or component is of allowed type.
  7484. If ERROR is non-nil, throw an error, otherwise just return nil.
  7485. Allowed types are `agenda' `todo' `tags' `search'."
  7486. (cond ((not org-agenda-type)
  7487. (error "No Org agenda currently displayed"))
  7488. ((memq org-agenda-type types) t)
  7489. (error
  7490. (error "Not allowed in '%s'-type agenda buffer or component" org-agenda-type))
  7491. (t nil)))
  7492. (defun org-agenda-Quit ()
  7493. "Exit the agenda, killing the agenda buffer.
  7494. Like `org-agenda-quit', but kill the buffer even when
  7495. `org-agenda-sticky' is non-nil."
  7496. (interactive)
  7497. (org-agenda--quit))
  7498. (defun org-agenda-quit ()
  7499. "Exit the agenda.
  7500. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  7501. instead of killing it.
  7502. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  7503. the pre-agenda window configuration.
  7504. When column view is active, exit column view instead of the
  7505. agenda."
  7506. (interactive)
  7507. (org-agenda--quit org-agenda-sticky))
  7508. (defun org-agenda--quit (&optional bury)
  7509. (if org-agenda-columns-active
  7510. (org-columns-quit)
  7511. (let ((wconf org-agenda-pre-window-conf)
  7512. (buf (current-buffer))
  7513. (org-agenda-last-indirect-window
  7514. (and (eq org-indirect-buffer-display 'other-window)
  7515. org-agenda-last-indirect-buffer
  7516. (get-buffer-window org-agenda-last-indirect-buffer))))
  7517. (cond
  7518. ((eq org-agenda-window-setup 'other-frame)
  7519. (delete-frame))
  7520. ((eq org-agenda-window-setup 'other-tab)
  7521. (if (fboundp 'tab-bar-close-tab)
  7522. (tab-bar-close-tab)
  7523. (user-error "Your version of Emacs does not have tab bar mode support")))
  7524. ((and org-agenda-restore-windows-after-quit
  7525. wconf)
  7526. ;; Maybe restore the pre-agenda window configuration. Reset
  7527. ;; `org-agenda-pre-window-conf' before running
  7528. ;; `set-window-configuration', which loses the current buffer.
  7529. (setq org-agenda-pre-window-conf nil)
  7530. (set-window-configuration wconf))
  7531. (t
  7532. (when org-agenda-last-indirect-window
  7533. (delete-window org-agenda-last-indirect-window))
  7534. (and (not (eq org-agenda-window-setup 'current-window))
  7535. (not (one-window-p))
  7536. (delete-window))))
  7537. (if bury
  7538. ;; Set the agenda buffer as the current buffer instead of
  7539. ;; passing it as an argument to `bury-buffer' so that
  7540. ;; `bury-buffer' removes it from the window.
  7541. (with-current-buffer buf
  7542. (bury-buffer))
  7543. (kill-buffer buf)
  7544. (setq org-agenda-archives-mode nil
  7545. org-agenda-buffer nil)))))
  7546. (defun org-agenda-exit ()
  7547. "Exit the agenda, killing Org buffers loaded by the agenda.
  7548. Like `org-agenda-Quit', but kill any buffers that were created by
  7549. the agenda. Org buffers visited directly by the user will not be
  7550. touched. Also, exit the agenda even if it is in column view."
  7551. (interactive)
  7552. (when org-agenda-columns-active
  7553. (org-columns-quit))
  7554. (org-release-buffers org-agenda-new-buffers)
  7555. (setq org-agenda-new-buffers nil)
  7556. (org-agenda-Quit))
  7557. (defun org-agenda-kill-all-agenda-buffers ()
  7558. "Kill all buffers in `org-agenda-mode'.
  7559. This is used when toggling sticky agendas."
  7560. (interactive)
  7561. (let (blist)
  7562. (dolist (buf (buffer-list))
  7563. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  7564. (push buf blist)))
  7565. (mapc #'kill-buffer blist)))
  7566. (defun org-agenda-execute (arg)
  7567. "Execute another agenda command, keeping same window.
  7568. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  7569. in the agenda."
  7570. (interactive "P")
  7571. (let ((org-agenda-window-setup 'current-window))
  7572. (org-agenda arg)))
  7573. (defun org-agenda-redo (&optional all)
  7574. "Rebuild possibly ALL agenda view(s) in the current buffer."
  7575. (interactive "P")
  7576. (defvar org-agenda-tag-filter-while-redo) ;FIXME: Where is this var used?
  7577. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  7578. (cpa (unless (eq all t) current-prefix-arg))
  7579. (org-agenda-doing-sticky-redo org-agenda-sticky)
  7580. (org-agenda-sticky nil)
  7581. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  7582. org-agenda-buffer-name))
  7583. (org-agenda-keep-modes t)
  7584. (tag-filter org-agenda-tag-filter)
  7585. (tag-preset (assoc-default 'tag org-agenda-filters-preset))
  7586. (top-hl-filter org-agenda-top-headline-filter)
  7587. (cat-filter org-agenda-category-filter)
  7588. (cat-preset (assoc-default 'category org-agenda-filters-preset))
  7589. (re-filter org-agenda-regexp-filter)
  7590. (re-preset (assoc-default 'regexp org-agenda-filters-preset))
  7591. (effort-filter org-agenda-effort-filter)
  7592. (effort-preset (assoc-default 'effort org-agenda-filters-preset))
  7593. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  7594. (cols org-agenda-columns-active)
  7595. (line (org-current-line))
  7596. (window-line (- line (org-current-line (window-start))))
  7597. (lprops (get-text-property p 'org-lprops))
  7598. (redo-cmd (get-text-property p 'org-redo-cmd))
  7599. (last-args (get-text-property p 'org-last-args))
  7600. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  7601. (org-agenda-overriding-cmd-arguments
  7602. (unless (eq all t)
  7603. (cond ((listp last-args)
  7604. (cons (or cpa (car last-args)) (cdr last-args)))
  7605. ((stringp last-args)
  7606. last-args))))
  7607. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  7608. (and cols (org-columns-quit))
  7609. (message "Rebuilding agenda buffer...")
  7610. (if series-redo-cmd
  7611. (eval series-redo-cmd t)
  7612. (cl-progv
  7613. (mapcar #'car lprops)
  7614. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  7615. (eval redo-cmd t))
  7616. (let ((inhibit-read-only t))
  7617. (add-text-properties (point-min) (point-max) `(org-lprops ,lprops))))
  7618. (setq org-agenda-undo-list nil
  7619. org-agenda-pending-undo-list nil
  7620. org-agenda-tag-filter tag-filter
  7621. org-agenda-category-filter cat-filter
  7622. org-agenda-regexp-filter re-filter
  7623. org-agenda-effort-filter effort-filter
  7624. org-agenda-top-headline-filter top-hl-filter)
  7625. (message "Rebuilding agenda buffer...done")
  7626. (let ((tag (or tag-filter tag-preset))
  7627. (cat (or cat-filter cat-preset))
  7628. (effort (or effort-filter effort-preset))
  7629. (re (or re-filter re-preset)))
  7630. (when tag (org-agenda-filter-apply tag 'tag t))
  7631. (when cat (org-agenda-filter-apply cat 'category))
  7632. (when effort (org-agenda-filter-apply effort 'effort))
  7633. (when re (org-agenda-filter-apply re 'regexp)))
  7634. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  7635. (and cols (called-interactively-p 'any) (org-agenda-columns))
  7636. (org-goto-line line)
  7637. (when (called-interactively-p 'any) (recenter window-line))))
  7638. (defun org-agenda-redo-all (&optional exhaustive)
  7639. "Rebuild all agenda views in the current buffer.
  7640. With a prefix argument, do so in all agenda buffers."
  7641. (interactive "P")
  7642. (if exhaustive
  7643. (dolist (buffer (buffer-list))
  7644. (with-current-buffer buffer
  7645. (when (derived-mode-p 'org-agenda-mode)
  7646. (org-agenda-redo t))))
  7647. (org-agenda-redo t)))
  7648. (defvar org-global-tags-completion-table nil)
  7649. (defvar org-agenda-filter-form nil)
  7650. (defvar org-agenda-filtered-by-category nil)
  7651. (defsubst org-agenda-get-category ()
  7652. "Return the category of the agenda line."
  7653. (org-get-at-bol 'org-category))
  7654. (defun org-agenda-filter-by-category (strip)
  7655. "Filter lines in the agenda buffer that have a specific category.
  7656. The category is that of the current line.
  7657. With a `\\[universal-argument]' prefix argument, exclude the lines of that category.
  7658. When there is already a category filter in place, this command removes the
  7659. filter."
  7660. (interactive "P")
  7661. (if (and org-agenda-filtered-by-category
  7662. org-agenda-category-filter)
  7663. (org-agenda-filter-show-all-cat)
  7664. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  7665. (cond
  7666. ((and cat strip)
  7667. (org-agenda-filter-apply
  7668. (push (concat "-" cat) org-agenda-category-filter) 'category))
  7669. (cat
  7670. (org-agenda-filter-apply
  7671. (setq org-agenda-category-filter
  7672. (list (concat "+" cat)))
  7673. 'category))
  7674. (t (error "No category at point"))))))
  7675. (defun org-find-top-headline (&optional pos)
  7676. "Find the topmost parent headline and return it.
  7677. POS when non-nil is the marker or buffer position to start the
  7678. search from."
  7679. (save-excursion
  7680. (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
  7681. (when pos (goto-char pos))
  7682. ;; Skip up to the topmost parent.
  7683. (while (org-up-heading-safe))
  7684. (ignore-errors
  7685. (replace-regexp-in-string
  7686. "^\\[[0-9]+/[0-9]+\\] *\\|^\\[%[0-9]+\\] *" ""
  7687. (nth 4 (org-heading-components)))))))
  7688. (defvar org-agenda-filtered-by-top-headline nil)
  7689. (defun org-agenda-filter-by-top-headline (strip)
  7690. "Keep only those lines that are descendants from the same top headline.
  7691. The top headline is that of the current line. With prefix arg STRIP, hide
  7692. all lines of the category at point."
  7693. (interactive "P")
  7694. (if org-agenda-filtered-by-top-headline
  7695. (progn
  7696. (setq org-agenda-filtered-by-top-headline nil
  7697. org-agenda-top-headline-filter nil)
  7698. (org-agenda-filter-show-all-top-filter))
  7699. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  7700. (if toph (org-agenda-filter-top-headline-apply toph strip)
  7701. (error "No top-level headline at point")))))
  7702. (defvar org-agenda-regexp-filter nil)
  7703. (defun org-agenda-filter-by-regexp (strip-or-accumulate)
  7704. "Filter agenda entries by a regular expressions.
  7705. You will be prompted for the regular expression, and the agenda
  7706. view will only show entries that are matched by that expression.
  7707. With one `\\[universal-argument]' prefix argument, hide entries matching the regexp.
  7708. When there is already a regexp filter active, this command removed the
  7709. filter. However, with two `\\[universal-argument]' prefix arguments, add a new condition to
  7710. an already existing regexp filter."
  7711. (interactive "P")
  7712. (let* ((strip (equal strip-or-accumulate '(4)))
  7713. (accumulate (equal strip-or-accumulate '(16))))
  7714. (cond
  7715. ((and org-agenda-regexp-filter (not accumulate))
  7716. (org-agenda-filter-show-all-re)
  7717. (message "Regexp filter removed"))
  7718. (t (let ((flt (concat (if strip "-" "+")
  7719. (read-from-minibuffer
  7720. (if strip
  7721. "Hide entries matching regexp: "
  7722. "Narrow to entries matching regexp: ")))))
  7723. (push flt org-agenda-regexp-filter)
  7724. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))))))
  7725. (defvar org-agenda-effort-filter nil)
  7726. (defun org-agenda-filter-by-effort (strip-or-accumulate)
  7727. "Filter agenda entries by effort.
  7728. With no `\\[universal-argument]' prefix argument, keep entries matching the effort condition.
  7729. With one `\\[universal-argument]' prefix argument, filter out entries matching the condition.
  7730. With two `\\[universal-argument]' prefix arguments, add a second condition to the existing filter.
  7731. This last option is in practice not very useful, but it is available for
  7732. consistency with the other filter commands."
  7733. (interactive "P")
  7734. (let* ((efforts (split-string
  7735. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7736. org-global-properties
  7737. t))
  7738. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
  7739. ;; XXX: the following handles only up to 10 different
  7740. ;; effort values.
  7741. (allowed-keys (if (null efforts) nil
  7742. (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
  7743. (number-sequence 1 (length efforts)))))
  7744. (keep (equal strip-or-accumulate '(16)))
  7745. (negative (equal strip-or-accumulate '(4)))
  7746. (current org-agenda-effort-filter)
  7747. (op nil))
  7748. (while (not (memq op '(?< ?> ?= ?_)))
  7749. (setq op (read-char-exclusive
  7750. "Effort operator? (> = or <) or press `_' again to remove filter")))
  7751. ;; Select appropriate duration. Ignore non-digit characters.
  7752. (if (eq op ?_)
  7753. (progn
  7754. (org-agenda-filter-show-all-effort)
  7755. (message "Effort filter removed"))
  7756. (let ((prompt
  7757. (apply #'format
  7758. (concat "Effort %c "
  7759. (mapconcat (lambda (s) (concat "[%d]" s))
  7760. efforts
  7761. " "))
  7762. op allowed-keys))
  7763. (eff -1))
  7764. (while (not (memq eff allowed-keys))
  7765. (message prompt)
  7766. (setq eff (- (read-char-exclusive) 48)))
  7767. (org-agenda-filter-show-all-effort)
  7768. (setq org-agenda-effort-filter
  7769. (append
  7770. (list (concat (if negative "-" "+")
  7771. (char-to-string op)
  7772. ;; Numbering is 1 2 3 ... 9 0, but we want
  7773. ;; 0 1 2 ... 8 9.
  7774. (nth (mod (1- eff) 10) efforts)))
  7775. (if keep current nil)))
  7776. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))))
  7777. (defun org-agenda-filter (&optional strip-or-accumulate)
  7778. "Prompt for a general filter string and apply it to the agenda.
  7779. The string may contain filter elements like
  7780. +category
  7781. +tag
  7782. +<effort > and = are also allowed as effort operators
  7783. +/regexp/
  7784. Instead of `+', `-' is allowed to strip the agenda of matching entries.
  7785. `+' is optional if it is not required to separate two string parts.
  7786. Multiple filter elements can be concatenated without spaces, for example
  7787. +work-John<0:10-/plot/
  7788. selects entries with category `work' and effort estimates below 10 minutes,
  7789. and deselects entries with tag `John' or matching the regexp `plot'.
  7790. During entry of the filter, completion for tags, categories and effort
  7791. values is offered. Since the syntax for categories and tags is identical
  7792. there should be no overlap between categories and tags. If there is, tags
  7793. get priority.
  7794. A single `\\[universal-argument]' prefix arg STRIP-OR-ACCUMULATE will negate the
  7795. entire filter, which can be useful in connection with the prompt history.
  7796. A double `\\[universal-argument] \\[universal-argument]' prefix arg will add the new filter elements to the
  7797. existing ones. A shortcut for this is to add an additional `+' at the
  7798. beginning of the string, like `+-John'.
  7799. With a triple prefix argument, execute the computed filtering defined in
  7800. the variable `org-agenda-auto-exclude-function'."
  7801. (interactive "P")
  7802. (if (equal strip-or-accumulate '(64))
  7803. ;; Execute the auto-exclude action
  7804. (if (not org-agenda-auto-exclude-function)
  7805. (user-error "`org-agenda-auto-exclude-function' is undefined")
  7806. (org-agenda-filter-show-all-tag)
  7807. (setq org-agenda-tag-filter nil)
  7808. (dolist (tag (org-agenda-get-represented-tags))
  7809. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7810. (when modifier
  7811. (push modifier org-agenda-tag-filter))))
  7812. (unless (null org-agenda-tag-filter)
  7813. (org-agenda-filter-apply org-agenda-tag-filter 'tag 'expand)))
  7814. ;; Prompt for a filter and act
  7815. (let* ((tag-list (org-agenda-get-represented-tags))
  7816. (category-list (org-agenda-get-represented-categories))
  7817. (negate (equal strip-or-accumulate '(4)))
  7818. (cf (mapconcat #'identity org-agenda-category-filter ""))
  7819. (tf (mapconcat #'identity org-agenda-tag-filter ""))
  7820. ;; (rpl-fn (lambda (c) (replace-regexp-in-string "^\\+" "" (or (car c) ""))))
  7821. (ef (replace-regexp-in-string "^\\+" "" (or (car org-agenda-effort-filter) "")))
  7822. (rf (replace-regexp-in-string "^\\+" "" (or (car org-agenda-regexp-filter) "")))
  7823. (ff (concat cf tf ef (when (not (equal rf "")) (concat "/" rf "/"))))
  7824. (f-string (completing-read
  7825. (concat
  7826. (if negate "Negative filter" "Filter")
  7827. " [+cat-tag<0:10-/regexp/]: ")
  7828. #'org-agenda-filter-completion-function
  7829. nil nil ff))
  7830. (keep (or (if (string-match "^\\+[+-]" f-string)
  7831. (progn (setq f-string (substring f-string 1)) t))
  7832. (equal strip-or-accumulate '(16))))
  7833. (fc (if keep org-agenda-category-filter))
  7834. (ft (if keep org-agenda-tag-filter))
  7835. (fe (if keep org-agenda-effort-filter))
  7836. (fr (if keep org-agenda-regexp-filter))
  7837. pm s)
  7838. ;; If the filter contains a double-quoted string, replace a
  7839. ;; single hyphen by the arbitrary and temporary string "~~~"
  7840. ;; to disambiguate such hyphens from syntactic ones.
  7841. (setq f-string (replace-regexp-in-string
  7842. "\"\\([^\"]*\\)-\\([^\"]*\\)\"" "\"\\1~~~\\2\"" f-string))
  7843. (while (string-match "^[ \t]*\\([-+]\\)?\\(\\([^-+<>=/ \t]+\\)\\|\\([<>=][0-9:]+\\)\\|\\(/\\([^/]+\\)/?\\)\\)" f-string)
  7844. (setq pm (if (match-beginning 1) (match-string 1 f-string) "+"))
  7845. (when negate
  7846. (setq pm (if (equal pm "+") "-" "+")))
  7847. (cond
  7848. ((match-beginning 3)
  7849. ;; category or tag
  7850. (setq s (replace-regexp-in-string ; Remove the temporary special string.
  7851. "~~~" "-" (match-string 3 f-string)))
  7852. (cond
  7853. ((member s tag-list)
  7854. (org-pushnew-to-end (concat pm s) ft))
  7855. ((member s category-list)
  7856. (org-pushnew-to-end (concat pm ; Remove temporary double quotes.
  7857. (replace-regexp-in-string "\"\\(.*\\)\"" "\\1" s))
  7858. fc))
  7859. (t (message
  7860. "`%s%s' filter ignored because tag/category is not represented"
  7861. pm s))))
  7862. ((match-beginning 4)
  7863. ;; effort
  7864. (org-pushnew-to-end (concat pm (match-string 4 f-string)) fe))
  7865. ((match-beginning 5)
  7866. ;; regexp
  7867. (org-pushnew-to-end (concat pm (match-string 6 f-string)) fr)))
  7868. (setq f-string (substring f-string (match-end 0))))
  7869. (org-agenda-filter-remove-all)
  7870. (and fc (org-agenda-filter-apply
  7871. (setq org-agenda-category-filter fc) 'category))
  7872. (and ft (org-agenda-filter-apply
  7873. (setq org-agenda-tag-filter ft) 'tag 'expand))
  7874. (and fe (org-agenda-filter-apply
  7875. (setq org-agenda-effort-filter fe) 'effort))
  7876. (and fr (org-agenda-filter-apply
  7877. (setq org-agenda-regexp-filter fr) 'regexp))
  7878. (run-hooks 'org-agenda-filter-hook))))
  7879. (defun org-agenda-filter-completion-function (string _predicate &optional flag)
  7880. "Complete a complex filter string.
  7881. FLAG specifies the type of completion operation to perform. This
  7882. function is passed as a collection function to `completing-read',
  7883. which see."
  7884. (let ((completion-ignore-case t) ;tags are case-sensitive
  7885. (confirm (lambda (x) (stringp x)))
  7886. (prefix "")
  7887. (operator "")
  7888. table)
  7889. (when (string-match "^\\(.*\\([-+<>=]\\)\\)\\([^-+<>=]*\\)$" string)
  7890. (setq prefix (match-string 1 string)
  7891. operator (match-string 2 string)
  7892. string (match-string 3 string)))
  7893. (cond
  7894. ((member operator '("+" "-" "" nil))
  7895. (setq table (append (org-agenda-get-represented-categories)
  7896. (org-agenda-get-represented-tags))))
  7897. ((member operator '("<" ">" "="))
  7898. (setq table (split-string
  7899. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7900. org-global-properties
  7901. t))
  7902. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")
  7903. " +")))
  7904. (t (setq table nil)))
  7905. (pcase flag
  7906. (`t (all-completions string table confirm))
  7907. (`lambda (assoc string table)) ;exact match?
  7908. (`nil
  7909. (pcase (try-completion string table confirm)
  7910. ((and completion (pred stringp))
  7911. (concat prefix completion))
  7912. (completion completion)))
  7913. (_ nil))))
  7914. (defun org-agenda-filter-remove-all ()
  7915. "Remove all filters from the current agenda buffer."
  7916. (interactive)
  7917. (when org-agenda-tag-filter
  7918. (org-agenda-filter-show-all-tag))
  7919. (when org-agenda-category-filter
  7920. (org-agenda-filter-show-all-cat))
  7921. (when org-agenda-regexp-filter
  7922. (org-agenda-filter-show-all-re))
  7923. (when org-agenda-top-headline-filter
  7924. (org-agenda-filter-show-all-top-filter))
  7925. (when org-agenda-effort-filter
  7926. (org-agenda-filter-show-all-effort))
  7927. (org-agenda-finalize)
  7928. (when (called-interactively-p 'interactive)
  7929. (message "All agenda filters removed")))
  7930. (defun org-agenda-filter-by-tag (strip-or-accumulate &optional char exclude)
  7931. "Keep only those lines in the agenda buffer that have a specific tag.
  7932. The tag is selected with its fast selection letter, as configured.
  7933. With a `\\[universal-argument]' prefix, apply the filter negatively, stripping all matches.
  7934. With a `\\[universal-argument] \\[universal-argument]' prefix, add the new tag to the existing filter
  7935. instead of replacing it.
  7936. With a `\\[universal-argument] \\[universal-argument] \\[universal-argument]' prefix, filter the literal tag, \
  7937. i.e. don't
  7938. filter on all its group members.
  7939. A Lisp caller can specify CHAR. EXCLUDE means that the new tag
  7940. should be used to exclude the search - the interactive user can
  7941. also press `-' or `+' to switch between filtering and excluding."
  7942. (interactive "P")
  7943. (let* ((alist org-tag-alist-for-agenda)
  7944. (seen-chars nil)
  7945. (tag-chars (mapconcat
  7946. (lambda (x) (if (and (not (symbolp (car x)))
  7947. (cdr x)
  7948. (not (member (cdr x) seen-chars)))
  7949. (progn
  7950. (push (cdr x) seen-chars)
  7951. (char-to-string (cdr x)))
  7952. ""))
  7953. org-tag-alist-for-agenda ""))
  7954. (valid-char-list (append '(?\t ?\r ?\\ ?. ?\s ?q)
  7955. (string-to-list tag-chars)))
  7956. (exclude (or exclude (equal strip-or-accumulate '(4))))
  7957. (accumulate (equal strip-or-accumulate '(16)))
  7958. (expand (not (equal strip-or-accumulate '(64))))
  7959. (inhibit-read-only t)
  7960. (current org-agenda-tag-filter)
  7961. a tag) ;; n
  7962. (unless char
  7963. (while (not (memq char valid-char-list))
  7964. (org-unlogged-message
  7965. "%s by tag%s: [%s ]tag-char [TAB]tag %s[\\]off [q]uit"
  7966. (if exclude "Exclude[+]" "Filter[-]")
  7967. (if expand "" " (no grouptag expand)")
  7968. tag-chars
  7969. (if org-agenda-auto-exclude-function "[RET] " ""))
  7970. (setq char (read-char-exclusive))
  7971. ;; Excluding or filtering down
  7972. (cond ((eq char ?-) (setq exclude t))
  7973. ((eq char ?+) (setq exclude nil)))))
  7974. (when (eq char ?\t)
  7975. (unless (local-variable-p 'org-global-tags-completion-table)
  7976. (setq-local org-global-tags-completion-table
  7977. (org-global-tags-completion-table)))
  7978. (let ((completion-ignore-case t))
  7979. (setq tag (completing-read
  7980. "Tag: " org-global-tags-completion-table nil t))))
  7981. (cond
  7982. ((eq char ?\r)
  7983. (org-agenda-filter-show-all-tag)
  7984. (when org-agenda-auto-exclude-function
  7985. (setq org-agenda-tag-filter nil)
  7986. (dolist (tag (org-agenda-get-represented-tags))
  7987. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7988. (when modifier
  7989. (push modifier org-agenda-tag-filter))))
  7990. (unless (null org-agenda-tag-filter)
  7991. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  7992. ((eq char ?\\)
  7993. (org-agenda-filter-show-all-tag)
  7994. (when (assoc-default 'tag org-agenda-filters-preset)
  7995. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  7996. ((eq char ?.)
  7997. (setq org-agenda-tag-filter
  7998. (mapcar (lambda(tag) (concat "+" tag))
  7999. (org-get-at-bol 'tags)))
  8000. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  8001. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  8002. ((or (eq char ?\s)
  8003. (setq a (rassoc char alist))
  8004. (and tag (setq a (cons tag nil))))
  8005. (org-agenda-filter-show-all-tag)
  8006. (setq tag (car a))
  8007. (setq org-agenda-tag-filter
  8008. (cons (concat (if exclude "-" "+") tag)
  8009. (if accumulate current nil)))
  8010. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  8011. (t (error "Invalid tag selection character %c" char)))))
  8012. (defun org-agenda-get-represented-categories ()
  8013. "Return a list of all categories used in this agenda buffer."
  8014. (or org-agenda-represented-categories
  8015. (when (derived-mode-p 'org-agenda-mode)
  8016. (let ((pos (point-min)) categories)
  8017. (while (and (< pos (point-max))
  8018. (setq pos (next-single-property-change
  8019. pos 'org-category nil (point-max))))
  8020. (push (get-text-property pos 'org-category) categories))
  8021. (setq org-agenda-represented-categories
  8022. ;; Enclose category names with a hyphen in double
  8023. ;; quotes to process them specially in `org-agenda-filter'.
  8024. (mapcar (lambda (s) (if (string-match-p "-" s) (format "\"%s\"" s) s))
  8025. (nreverse (org-uniquify (delq nil categories)))))))))
  8026. (defvar org-tag-groups-alist-for-agenda)
  8027. (defun org-agenda-get-represented-tags ()
  8028. "Return a list of all tags used in this agenda buffer.
  8029. These will be lower-case, for filtering."
  8030. (or org-agenda-represented-tags
  8031. (when (derived-mode-p 'org-agenda-mode)
  8032. (let ((pos (point-min)) tags-lists tt)
  8033. (while (and (< pos (point-max))
  8034. (setq pos (next-single-property-change
  8035. pos 'tags nil (point-max))))
  8036. (setq tt (get-text-property pos 'tags))
  8037. (if tt (push tt tags-lists)))
  8038. (setq tags-lists
  8039. (nreverse (org-uniquify
  8040. (delq nil (apply #'append tags-lists)))))
  8041. (dolist (tag tags-lists)
  8042. (mapc
  8043. (lambda (group)
  8044. (when (member tag group)
  8045. (push (car group) tags-lists)))
  8046. org-tag-groups-alist-for-agenda))
  8047. (setq org-agenda-represented-tags tags-lists)))))
  8048. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  8049. "Create the form that tests a line for agenda filter.
  8050. Optional argument EXPAND can be used for the TYPE tag and will
  8051. expand the tags in the FILTER if any of the tags in FILTER are
  8052. grouptags."
  8053. (let ((multi-pos-cats
  8054. (and (eq type 'category)
  8055. (string-match-p "\\+.*\\+"
  8056. (mapconcat (lambda (cat) (substring cat 0 1))
  8057. filter ""))))
  8058. f f1)
  8059. (cond
  8060. ;; Tag filter
  8061. ((eq type 'tag)
  8062. (setq filter
  8063. (delete-dups
  8064. (append (assoc-default 'tag org-agenda-filters-preset)
  8065. filter)))
  8066. (dolist (x filter)
  8067. (let ((op (string-to-char x)))
  8068. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  8069. (setq x (list x)))
  8070. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  8071. (push f1 f))))
  8072. ;; Category filter
  8073. ((eq type 'category)
  8074. (setq filter
  8075. (delete-dups
  8076. (append (assoc-default 'category org-agenda-filters-preset)
  8077. filter)))
  8078. (dolist (x filter)
  8079. (if (equal "-" (substring x 0 1))
  8080. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  8081. (setq f1 (list 'equal (substring x 1) 'cat)))
  8082. (push f1 f)))
  8083. ;; Regexp filter
  8084. ((eq type 'regexp)
  8085. (setq filter
  8086. (delete-dups
  8087. (append (assoc-default 'regexp org-agenda-filters-preset)
  8088. filter)))
  8089. (dolist (x filter)
  8090. (if (equal "-" (substring x 0 1))
  8091. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  8092. (setq f1 (list 'string-match (substring x 1) 'txt)))
  8093. (push f1 f)))
  8094. ;; Effort filter
  8095. ((eq type 'effort)
  8096. (setq filter
  8097. (delete-dups
  8098. (append (assoc-default 'effort org-agenda-filters-preset)
  8099. filter)))
  8100. (dolist (x filter)
  8101. (push (org-agenda-filter-effort-form x) f))))
  8102. (cons (if multi-pos-cats 'or 'and) (nreverse f))))
  8103. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  8104. "Return a form associated to tag-expression TAGS.
  8105. Build a form testing a line for agenda filter for
  8106. tag-expressions. OP is an operator of type CHAR that allows the
  8107. function to set the right switches in the returned form."
  8108. (let (form)
  8109. ;; Any of the expressions can match if OP is +, all must match if
  8110. ;; the operator is -.
  8111. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  8112. (let* ((tag (substring x 1))
  8113. (f (cond
  8114. ((string= "" tag) 'tags)
  8115. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  8116. ;; TAG is a regexp.
  8117. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  8118. (t (list 'member tag 'tags)))))
  8119. (push (if (eq op ?-) (list 'not f) f) form)))))
  8120. (defun org-agenda-filter-effort-form (e)
  8121. "Return the form to compare the effort of the current line with what E says.
  8122. E looks like \"+<2:25\"."
  8123. (let (op)
  8124. (setq e (substring e 1))
  8125. (setq op (string-to-char e) e (substring e 1))
  8126. (setq op (cond ((equal op ?<) '<=)
  8127. ((equal op ?>) '>=)
  8128. ((equal op ??) op)
  8129. (t '=)))
  8130. (list 'org-agenda-compare-effort (list 'quote op)
  8131. (org-duration-to-minutes e))))
  8132. (defun org-agenda-compare-effort (op value)
  8133. "Compare the effort of the current line with VALUE, using OP.
  8134. If the line does not have an effort defined, return nil."
  8135. ;; `effort-minutes' property cannot be extracted directly from
  8136. ;; current line but is stored as a property in `txt'.
  8137. (let ((effort (get-text-property 0 'effort-minutes (org-get-at-bol 'txt))))
  8138. (funcall op
  8139. (or effort (if org-agenda-sort-noeffort-is-high 32767 -1))
  8140. value)))
  8141. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  8142. "Expand group tags in FILTER for the agenda.
  8143. When NO-OPERATOR is non-nil, do not add the + operator to
  8144. returned tags."
  8145. (if org-group-tags
  8146. (let (case-fold-search rtn)
  8147. (mapc
  8148. (lambda (f)
  8149. (let (f0 dir)
  8150. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  8151. (setq dir (match-string 1 f) f0 (match-string 2 f))
  8152. (setq dir (if no-operator "" "+") f0 f))
  8153. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  8154. (org-tags-expand f0 t))
  8155. rtn))))
  8156. filter)
  8157. (reverse rtn))
  8158. filter))
  8159. (defun org-agenda-filter-apply (filter type &optional expand)
  8160. "Set FILTER as the new agenda filter and apply it.
  8161. Optional argument EXPAND can be used for the TYPE tag and will
  8162. expand the tags in the FILTER if any of the tags in FILTER are
  8163. grouptags."
  8164. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  8165. (when org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  8166. (setq org-agenda-filter-form (org-agenda-filter-make-matcher
  8167. filter type expand))
  8168. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  8169. ;; category is used as the filter:
  8170. (setq org-agenda-filtered-by-category
  8171. (and (eq type 'category)
  8172. (not (equal (substring (car filter) 0 1) "-"))))
  8173. (org-agenda-set-mode-name)
  8174. (save-excursion
  8175. (goto-char (point-min))
  8176. (while (not (eobp))
  8177. (when (or (org-get-at-bol 'org-hd-marker)
  8178. (org-get-at-bol 'org-marker))
  8179. (org-dlet
  8180. ((tags (org-get-at-bol 'tags))
  8181. (cat (org-agenda-get-category))
  8182. (txt (or (org-get-at-bol 'txt) "")))
  8183. (unless (eval org-agenda-filter-form t)
  8184. (org-agenda-filter-hide-line type))))
  8185. (beginning-of-line 2)))
  8186. (when (get-char-property (point) 'invisible)
  8187. (ignore-errors (org-agenda-previous-line))))
  8188. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  8189. "Filter by top headline HL."
  8190. (org-agenda-set-mode-name)
  8191. (save-excursion
  8192. (goto-char (point-min))
  8193. (while (not (eobp))
  8194. (let* ((pos (org-get-at-bol 'org-hd-marker))
  8195. (tophl (and pos (org-find-top-headline pos))))
  8196. (when (and tophl (funcall (if negative 'identity 'not)
  8197. (string= hl tophl)))
  8198. (org-agenda-filter-hide-line 'top-headline)))
  8199. (beginning-of-line 2)))
  8200. (when (get-char-property (point) 'invisible)
  8201. (org-agenda-previous-line))
  8202. (setq org-agenda-top-headline-filter hl
  8203. org-agenda-filtered-by-top-headline t))
  8204. (defun org-agenda-filter-hide-line (type)
  8205. "If current line is TYPE, hide it in the agenda buffer."
  8206. (let* (buffer-invisibility-spec
  8207. (beg (max (point-min) (1- (line-beginning-position))))
  8208. (end (line-end-position)))
  8209. (let ((inhibit-read-only t))
  8210. (add-text-properties
  8211. beg end `(invisible org-filtered org-filter-type ,type)))))
  8212. (defun org-agenda-remove-filter (type)
  8213. "Remove filter of type TYPE from the agenda buffer."
  8214. (interactive)
  8215. (save-excursion
  8216. (goto-char (point-min))
  8217. (let ((inhibit-read-only t) pos)
  8218. (while (setq pos (text-property-any (point) (point-max)
  8219. 'org-filter-type type))
  8220. (goto-char pos)
  8221. (remove-text-properties
  8222. (point) (next-single-property-change (point) 'org-filter-type)
  8223. `(invisible org-filtered org-filter-type ,type))))
  8224. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  8225. (setq org-agenda-filter-form nil)
  8226. (org-agenda-set-mode-name)
  8227. (org-agenda-finalize)))
  8228. (defun org-agenda-filter-show-all-tag nil
  8229. (org-agenda-remove-filter 'tag))
  8230. (defun org-agenda-filter-show-all-re nil
  8231. (org-agenda-remove-filter 'regexp))
  8232. (defun org-agenda-filter-show-all-effort nil
  8233. (org-agenda-remove-filter 'effort))
  8234. (defun org-agenda-filter-show-all-cat nil
  8235. (org-agenda-remove-filter 'category))
  8236. (defun org-agenda-filter-show-all-top-filter nil
  8237. (org-agenda-remove-filter 'top-headline))
  8238. (defun org-agenda-manipulate-query-add ()
  8239. "Manipulate the query by adding a search term with positive selection.
  8240. Positive selection means the term must be matched for selection of an entry."
  8241. (interactive)
  8242. (org-agenda-manipulate-query ?\[))
  8243. (defun org-agenda-manipulate-query-subtract ()
  8244. "Manipulate the query by adding a search term with negative selection.
  8245. Negative selection means term must not be matched for selection of an entry."
  8246. (interactive)
  8247. (org-agenda-manipulate-query ?\]))
  8248. (defun org-agenda-manipulate-query-add-re ()
  8249. "Manipulate the query by adding a search regexp with positive selection.
  8250. Positive selection means the regexp must match for selection of an entry."
  8251. (interactive)
  8252. (org-agenda-manipulate-query ?\{))
  8253. (defun org-agenda-manipulate-query-subtract-re ()
  8254. "Manipulate the query by adding a search regexp with negative selection.
  8255. Negative selection means regexp must not match for selection of an entry."
  8256. (interactive)
  8257. (org-agenda-manipulate-query ?\}))
  8258. (defun org-agenda-manipulate-query (char)
  8259. (cond
  8260. ((eq org-agenda-type 'agenda)
  8261. (let ((org-agenda-include-inactive-timestamps t))
  8262. (org-agenda-redo))
  8263. (message "Display now includes inactive timestamps as well"))
  8264. ((eq org-agenda-type 'search)
  8265. (org-add-to-string
  8266. 'org-agenda-query-string
  8267. (if org-agenda-last-search-view-search-was-boolean
  8268. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  8269. (?\{ . " +{}") (?\} . " -{}"))))
  8270. " "))
  8271. (setq org-agenda-redo-command
  8272. (list 'org-search-view
  8273. (car (get-text-property (min (1- (point-max)) (point))
  8274. 'org-last-args))
  8275. org-agenda-query-string
  8276. (+ (length org-agenda-query-string)
  8277. (if (member char '(?\{ ?\})) 0 1))))
  8278. (set-register org-agenda-query-register org-agenda-query-string)
  8279. (let ((org-agenda-overriding-arguments
  8280. (cdr org-agenda-redo-command)))
  8281. (org-agenda-redo)))
  8282. (t (error "Cannot manipulate query for %s-type agenda buffers"
  8283. org-agenda-type))))
  8284. (defun org-add-to-string (var string)
  8285. (set var (concat (symbol-value var) string)))
  8286. (defun org-agenda-goto-date (date)
  8287. "Jump to DATE in the agenda buffer.
  8288. When called interactively, prompt for the date.
  8289. When called from Lisp, DATE should be a date as returned by
  8290. `org-read-date'.
  8291. See also:
  8292. `org-agenda-earlier' (\\[org-agenda-earlier])
  8293. `org-agenda-later' (\\[org-agenda-later])
  8294. `org-agenda-goto-today' (\\[org-agenda-goto-today])"
  8295. (interactive
  8296. (list
  8297. (let ((org-read-date-prefer-future org-agenda-jump-prefer-future))
  8298. (org-read-date))))
  8299. (let* ((day (time-to-days (org-time-string-to-time date)))
  8300. (org-agenda-sticky-orig org-agenda-sticky)
  8301. (org-agenda-buffer-tmp-name (buffer-name))
  8302. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8303. (0-arg (or current-prefix-arg (car args)))
  8304. (2-arg (nth 2 args))
  8305. (with-hour-p (nth 4 org-agenda-redo-command))
  8306. (newcmd (list 'org-agenda-list 0-arg date
  8307. (org-agenda-span-to-ndays
  8308. 2-arg (org-time-string-to-absolute date))
  8309. with-hour-p))
  8310. (newargs (cdr newcmd))
  8311. (inhibit-read-only t)
  8312. org-agenda-sticky)
  8313. (if (not (org-agenda-check-type t 'agenda))
  8314. (error "Not available in non-agenda views")
  8315. (add-text-properties (point-min) (point-max)
  8316. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  8317. (org-agenda-redo)
  8318. (goto-char (point-min))
  8319. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  8320. (save-excursion (move-beginning-of-line 2) (eobp))))
  8321. (move-beginning-of-line 2))
  8322. (setq org-agenda-sticky org-agenda-sticky-orig
  8323. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  8324. (defun org-agenda-goto-today ()
  8325. "Go to today's date in the agenda buffer.
  8326. See also:
  8327. `org-agenda-later' (\\[org-agenda-later])
  8328. `org-agenda-earlier' (\\[org-agenda-earlier])
  8329. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8330. (interactive)
  8331. (org-agenda-check-type t 'agenda)
  8332. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8333. (curspan (nth 2 args))
  8334. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  8335. (cond
  8336. (tdpos (goto-char tdpos))
  8337. ((eq org-agenda-type 'agenda)
  8338. (let* ((sd (org-agenda-compute-starting-span
  8339. (org-today) (or curspan org-agenda-span)))
  8340. (org-agenda-overriding-arguments args))
  8341. (setf (nth 1 org-agenda-overriding-arguments) sd)
  8342. (org-agenda-redo)
  8343. (org-agenda-find-same-or-today-or-agenda)))
  8344. (t (error "Cannot find today")))))
  8345. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  8346. (goto-char
  8347. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  8348. (text-property-any (point-min) (point-max) 'org-today t)
  8349. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  8350. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  8351. (org-agenda-backward-block))
  8352. (point-min))))
  8353. (defun org-agenda-backward-block ()
  8354. "Move backward by one agenda block."
  8355. (interactive)
  8356. (org-agenda-forward-block 'backward))
  8357. (defun org-agenda-forward-block (&optional backward)
  8358. "Move forward by one agenda block.
  8359. When optional argument BACKWARD is set, go backward."
  8360. (interactive)
  8361. (cond ((not (derived-mode-p 'org-agenda-mode))
  8362. (user-error
  8363. "Cannot execute this command outside of org-agenda-mode buffers"))
  8364. ((looking-at (if backward "\\`" "\\'"))
  8365. (message "Already at the %s block" (if backward "first" "last")))
  8366. (t (let ((_pos (prog1 (point)
  8367. (ignore-errors (if backward (backward-char 1)
  8368. (move-end-of-line 1)))))
  8369. (f (if backward
  8370. #'previous-single-property-change
  8371. #'next-single-property-change))
  8372. moved dest)
  8373. (while (and (setq dest (funcall
  8374. f (point) 'org-agenda-structural-header))
  8375. (not (get-text-property
  8376. (point) 'org-agenda-structural-header)))
  8377. (setq moved t)
  8378. (goto-char dest))
  8379. (if moved (move-beginning-of-line 1)
  8380. (goto-char (if backward (point-min) (point-max)))
  8381. (move-beginning-of-line 1)
  8382. (message "No %s block" (if backward "previous" "further")))))))
  8383. (defun org-agenda-later (arg)
  8384. "Go forward in time by the current span in the agenda buffer.
  8385. With prefix ARG, go forward that many times the current span.
  8386. See also:
  8387. `org-agenda-earlier' (\\[org-agenda-earlier])
  8388. `org-agenda-goto-today' (\\[org-agenda-goto-today])
  8389. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8390. (interactive "p")
  8391. (org-agenda-check-type t 'agenda)
  8392. (let* ((wstart (window-start))
  8393. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8394. (span (or (nth 2 args) org-agenda-current-span))
  8395. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  8396. (greg (calendar-gregorian-from-absolute sd))
  8397. (cnt (org-get-at-bol 'org-day-cnt))
  8398. greg2)
  8399. (cond
  8400. ((numberp span)
  8401. (setq sd (+ (* span arg) sd)))
  8402. ((eq span 'day)
  8403. (setq sd (+ arg sd)))
  8404. ((eq span 'week)
  8405. (setq sd (+ (* 7 arg) sd)))
  8406. ((eq span 'fortnight)
  8407. (setq sd (+ (* 14 arg) sd)))
  8408. ((eq span 'month)
  8409. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  8410. sd (calendar-absolute-from-gregorian greg2))
  8411. (setcar greg2 (1+ (car greg2))))
  8412. ((eq span 'year)
  8413. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  8414. sd (calendar-absolute-from-gregorian greg2))
  8415. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  8416. (t
  8417. (setq sd (+ (* span arg) sd))))
  8418. (let ((org-agenda-overriding-cmd
  8419. ;; `cmd' may have been set by `org-agenda-run-series' which
  8420. ;; uses `org-agenda-overriding-cmd' to decide whether
  8421. ;; overriding is allowed for `cmd'
  8422. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  8423. (org-agenda-overriding-arguments
  8424. (list (car args) sd span)))
  8425. (org-agenda-redo)
  8426. (org-agenda-find-same-or-today-or-agenda cnt))
  8427. (set-window-start nil wstart)))
  8428. (defun org-agenda-earlier (arg)
  8429. "Go backward in time by the current span in the agenda buffer.
  8430. With prefix ARG, go backward that many times the current span.
  8431. See also:
  8432. `org-agenda-later' (\\[org-agenda-later])
  8433. `org-agenda-goto-today' (\\[org-agenda-goto-today])
  8434. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8435. (interactive "p")
  8436. (org-agenda-later (- arg)))
  8437. (defun org-agenda-view-mode-dispatch ()
  8438. "Call one of the view mode commands."
  8439. (interactive)
  8440. (org-unlogged-message
  8441. "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  8442. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  8443. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  8444. (pcase (read-char-exclusive)
  8445. (?\ (call-interactively 'org-agenda-reset-view))
  8446. (?d (call-interactively 'org-agenda-day-view))
  8447. (?w (call-interactively 'org-agenda-week-view))
  8448. (?t (call-interactively 'org-agenda-fortnight-view))
  8449. (?m (call-interactively 'org-agenda-month-view))
  8450. (?y (call-interactively 'org-agenda-year-view))
  8451. (?l (call-interactively 'org-agenda-log-mode))
  8452. (?L (org-agenda-log-mode '(4)))
  8453. (?c (org-agenda-log-mode 'clockcheck))
  8454. ((or ?F ?f) (call-interactively 'org-agenda-follow-mode))
  8455. (?a (call-interactively 'org-agenda-archives-mode))
  8456. (?A (org-agenda-archives-mode 'files))
  8457. ((or ?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  8458. ((or ?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  8459. (?G (call-interactively 'org-agenda-toggle-time-grid))
  8460. (?D (call-interactively 'org-agenda-toggle-diary))
  8461. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  8462. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  8463. (org-agenda-check-type t 'agenda)
  8464. (org-agenda-redo))
  8465. (message "Display now includes inactive timestamps as well"))
  8466. (?q (message "Abort"))
  8467. (key (user-error "Invalid key: %s" key))))
  8468. (defun org-agenda-reset-view ()
  8469. "Switch to default view for agenda."
  8470. (interactive)
  8471. (org-agenda-change-time-span org-agenda-span))
  8472. (defun org-agenda-day-view (&optional day-of-month)
  8473. "Switch to daily view for agenda.
  8474. With argument DAY-OF-MONTH, switch to that day of the month."
  8475. (interactive "P")
  8476. (org-agenda-change-time-span 'day day-of-month))
  8477. (defun org-agenda-week-view (&optional iso-week)
  8478. "Switch to weekly view for agenda.
  8479. With argument ISO-WEEK, switch to the corresponding ISO week.
  8480. If ISO-WEEK has more then 2 digits, only the last two encode
  8481. the week. Any digits before this encode a year. So 200712
  8482. means week 12 of year 2007. Years ranging from 70 years ago
  8483. to 30 years in the future can also be written as 2-digit years."
  8484. (interactive "P")
  8485. (org-agenda-change-time-span 'week iso-week))
  8486. (defun org-agenda-fortnight-view (&optional iso-week)
  8487. "Switch to fortnightly view for agenda.
  8488. With argument ISO-WEEK, switch to the corresponding ISO week.
  8489. If ISO-WEEK has more then 2 digits, only the last two encode
  8490. the week. Any digits before this encode a year. So 200712
  8491. means week 12 of year 2007. Years ranging from 70 years ago
  8492. to 30 years in the future can also be written as 2-digit years."
  8493. (interactive "P")
  8494. (org-agenda-change-time-span 'fortnight iso-week))
  8495. (defun org-agenda-month-view (&optional month)
  8496. "Switch to monthly view for agenda.
  8497. With argument MONTH, switch to that month. If MONTH has more
  8498. then 2 digits, only the last two encode the month. Any digits
  8499. before this encode a year. So 200712 means December year 2007.
  8500. Years ranging from 70 years ago to 30 years in the future can
  8501. also be written as 2-digit years."
  8502. (interactive "P")
  8503. (org-agenda-change-time-span 'month month))
  8504. (defun org-agenda-year-view (&optional year)
  8505. "Switch to yearly view for agenda.
  8506. With argument YEAR, switch to that year. Years ranging from 70
  8507. years ago to 30 years in the future can also be written as
  8508. 2-digit years."
  8509. (interactive "P")
  8510. (when year
  8511. (setq year (org-small-year-to-year year)))
  8512. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  8513. (org-agenda-change-time-span 'year year)
  8514. (error "Abort")))
  8515. (defun org-agenda-change-time-span (span &optional n)
  8516. "Change the agenda view to SPAN.
  8517. SPAN may be `day', `week', `fortnight', `month', `year'."
  8518. (org-agenda-check-type t 'agenda)
  8519. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8520. (curspan (nth 2 args)))
  8521. (when (and (not n) (equal curspan span))
  8522. (error "Viewing span is already \"%s\"" span))
  8523. (let* ((sd (or (org-get-at-bol 'day)
  8524. (nth 1 args)
  8525. org-starting-day))
  8526. (sd (org-agenda-compute-starting-span sd span n))
  8527. (org-agenda-overriding-cmd
  8528. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  8529. (org-agenda-overriding-arguments
  8530. (list (car args) sd span)))
  8531. (org-agenda-redo)
  8532. (org-agenda-find-same-or-today-or-agenda))
  8533. (org-agenda-set-mode-name)
  8534. (message "Switched to %s view" span)))
  8535. (defun org-agenda-compute-starting-span (sd span &optional n)
  8536. "Compute starting date for agenda.
  8537. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  8538. is a cons cell with the starting date and the number of days,
  8539. so that the date SD will be in that range."
  8540. (let* ((greg (calendar-gregorian-from-absolute sd))
  8541. ;; (dg (nth 1 greg))
  8542. (mg (car greg))
  8543. (yg (nth 2 greg)))
  8544. (cond
  8545. ((eq span 'day)
  8546. (when n
  8547. (setq sd (+ (calendar-absolute-from-gregorian
  8548. (list mg 1 yg))
  8549. n -1))))
  8550. ((or (eq span 'week) (eq span 'fortnight))
  8551. (let* ((nt (calendar-day-of-week
  8552. (calendar-gregorian-from-absolute sd)))
  8553. (d (if org-agenda-start-on-weekday
  8554. (- nt org-agenda-start-on-weekday)
  8555. 0))
  8556. y1)
  8557. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  8558. (when n
  8559. (require 'cal-iso)
  8560. (when (> n 99)
  8561. (setq y1 (org-small-year-to-year (/ n 100))
  8562. n (mod n 100)))
  8563. (setq sd
  8564. (calendar-iso-to-absolute
  8565. (list n 1
  8566. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  8567. ((eq span 'month)
  8568. (let (y1)
  8569. (when (and n (> n 99))
  8570. (setq y1 (org-small-year-to-year (/ n 100))
  8571. n (mod n 100)))
  8572. (setq sd (calendar-absolute-from-gregorian
  8573. (list (or n mg) 1 (or y1 yg))))))
  8574. ((eq span 'year)
  8575. (setq sd (calendar-absolute-from-gregorian
  8576. (list 1 1 (or n yg))))))
  8577. sd))
  8578. (defun org-agenda-next-date-line (&optional arg)
  8579. "Jump to the next line indicating a date in agenda buffer."
  8580. (interactive "p")
  8581. (org-agenda-check-type t 'agenda)
  8582. (beginning-of-line 1)
  8583. ;; This does not work if user makes date format that starts with a blank
  8584. (when (looking-at-p "^\\S-") (forward-char 1))
  8585. (unless (re-search-forward "^\\S-" nil t arg)
  8586. (backward-char 1)
  8587. (error "No next date after this line in this buffer"))
  8588. (goto-char (match-beginning 0)))
  8589. (defun org-agenda-previous-date-line (&optional arg)
  8590. "Jump to the previous line indicating a date in agenda buffer."
  8591. (interactive "p")
  8592. (org-agenda-check-type t 'agenda)
  8593. (beginning-of-line 1)
  8594. (unless (re-search-backward "^\\S-" nil t arg)
  8595. (error "No previous date before this line in this buffer")))
  8596. ;; Initialize the highlight
  8597. (defvar org-hl (make-overlay 1 1))
  8598. (overlay-put org-hl 'face 'highlight)
  8599. (defun org-highlight (begin end &optional buffer)
  8600. "Highlight a region with overlay."
  8601. (move-overlay org-hl begin end (or buffer (current-buffer))))
  8602. (defun org-unhighlight ()
  8603. "Detach overlay INDEX."
  8604. (delete-overlay org-hl))
  8605. (defun org-unhighlight-once ()
  8606. "Remove the highlight from its position, and this function from the hook."
  8607. (remove-hook 'pre-command-hook #'org-unhighlight-once)
  8608. (org-unhighlight))
  8609. (defvar org-agenda-pre-follow-window-conf nil)
  8610. (defun org-agenda-follow-mode ()
  8611. "Toggle follow mode in an agenda buffer."
  8612. (interactive)
  8613. (unless org-agenda-follow-mode
  8614. (setq org-agenda-pre-follow-window-conf
  8615. (current-window-configuration)))
  8616. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  8617. (unless org-agenda-follow-mode
  8618. (set-window-configuration org-agenda-pre-follow-window-conf))
  8619. (org-agenda-set-mode-name)
  8620. (org-agenda-do-context-action)
  8621. (message "Follow mode is %s"
  8622. (if org-agenda-follow-mode "on" "off")))
  8623. (defun org-agenda-entry-text-mode (&optional arg)
  8624. "Toggle entry text mode in an agenda buffer."
  8625. (interactive "P")
  8626. (if (or org-agenda-tag-filter
  8627. org-agenda-category-filter
  8628. org-agenda-regexp-filter
  8629. org-agenda-top-headline-filter)
  8630. (user-error "Can't show entry text in filtered views")
  8631. (setq org-agenda-entry-text-mode (or (integerp arg)
  8632. (not org-agenda-entry-text-mode)))
  8633. (org-agenda-entry-text-hide)
  8634. (and org-agenda-entry-text-mode
  8635. (let ((org-agenda-entry-text-maxlines
  8636. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  8637. (org-agenda-entry-text-show)))
  8638. (org-agenda-set-mode-name)
  8639. (message "Entry text mode is %s%s"
  8640. (if org-agenda-entry-text-mode "on" "off")
  8641. (if (not org-agenda-entry-text-mode) ""
  8642. (format " (maximum number of lines is %d)"
  8643. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  8644. (defun org-agenda-clockreport-mode ()
  8645. "Toggle clocktable mode in an agenda buffer."
  8646. (interactive)
  8647. (org-agenda-check-type t 'agenda)
  8648. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  8649. (org-agenda-set-mode-name)
  8650. (org-agenda-redo)
  8651. (message "Clocktable mode is %s"
  8652. (if org-agenda-clockreport-mode "on" "off")))
  8653. (defun org-agenda-log-mode (&optional special)
  8654. "Toggle log mode in an agenda buffer.
  8655. With argument SPECIAL, show all possible log items, not only the ones
  8656. configured in `org-agenda-log-mode-items'.
  8657. With a `\\[universal-argument] \\[universal-argument]' prefix, show *only* \
  8658. log items, nothing else."
  8659. (interactive "P")
  8660. (org-agenda-check-type t 'agenda)
  8661. (setq org-agenda-show-log
  8662. (cond
  8663. ((equal special '(16)) 'only)
  8664. ((eq special 'clockcheck)
  8665. (if (eq org-agenda-show-log 'clockcheck)
  8666. nil 'clockcheck))
  8667. (special '(closed clock state))
  8668. (t (not org-agenda-show-log))))
  8669. (org-agenda-set-mode-name)
  8670. (org-agenda-redo)
  8671. (message "Log mode is %s" (if org-agenda-show-log "on" "off")))
  8672. (defun org-agenda-archives-mode (&optional with-files)
  8673. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  8674. When called with a prefix argument, include all archive files as well."
  8675. (interactive "P")
  8676. (setq org-agenda-archives-mode
  8677. (cond ((and with-files (eq org-agenda-archives-mode t)) nil)
  8678. (with-files t)
  8679. (org-agenda-archives-mode nil)
  8680. (t 'trees)))
  8681. (org-agenda-set-mode-name)
  8682. (org-agenda-redo)
  8683. (message
  8684. "%s"
  8685. (cond
  8686. ((eq org-agenda-archives-mode nil)
  8687. "No archives are included")
  8688. ((eq org-agenda-archives-mode 'trees)
  8689. (format "Trees with :%s: tag are included" org-archive-tag))
  8690. ((eq org-agenda-archives-mode t)
  8691. (format "Trees with :%s: tag and all active archive files are included"
  8692. org-archive-tag)))))
  8693. (defun org-agenda-toggle-diary ()
  8694. "Toggle diary inclusion in an agenda buffer."
  8695. (interactive)
  8696. (org-agenda-check-type t 'agenda)
  8697. (setq org-agenda-include-diary (not org-agenda-include-diary))
  8698. (org-agenda-redo)
  8699. (org-agenda-set-mode-name)
  8700. (message "Diary inclusion turned %s"
  8701. (if org-agenda-include-diary "on" "off")))
  8702. (defun org-agenda-toggle-deadlines ()
  8703. "Toggle inclusion of entries with a deadline in an agenda buffer."
  8704. (interactive)
  8705. (org-agenda-check-type t 'agenda)
  8706. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  8707. (org-agenda-redo)
  8708. (org-agenda-set-mode-name)
  8709. (message "Deadlines inclusion turned %s"
  8710. (if org-agenda-include-deadlines "on" "off")))
  8711. (defun org-agenda-toggle-time-grid ()
  8712. "Toggle time grid in an agenda buffer."
  8713. (interactive)
  8714. (org-agenda-check-type t 'agenda)
  8715. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  8716. (org-agenda-redo)
  8717. (org-agenda-set-mode-name)
  8718. (message "Time-grid turned %s"
  8719. (if org-agenda-use-time-grid "on" "off")))
  8720. (defun org-agenda-set-mode-name ()
  8721. "Set the mode name to indicate all the small mode settings."
  8722. (setq mode-name
  8723. (list "Org-Agenda"
  8724. (if (get 'org-agenda-files 'org-restrict) " []" "")
  8725. " "
  8726. '(:eval (org-agenda-span-name org-agenda-current-span))
  8727. (if org-agenda-follow-mode " Follow" "")
  8728. (if org-agenda-entry-text-mode " ETxt" "")
  8729. (if org-agenda-include-diary " Diary" "")
  8730. (if org-agenda-include-deadlines " Ddl" "")
  8731. (if org-agenda-use-time-grid " Grid" "")
  8732. (if (and (boundp 'org-habit-show-habits)
  8733. org-habit-show-habits)
  8734. " Habit" "")
  8735. (cond
  8736. ((consp org-agenda-show-log) " LogAll")
  8737. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  8738. (org-agenda-show-log " Log")
  8739. (t ""))
  8740. (if (org-agenda-filter-any) " " "")
  8741. (if (or org-agenda-category-filter
  8742. (assoc-default 'category org-agenda-filters-preset))
  8743. '(:eval (propertize
  8744. (concat "["
  8745. (mapconcat
  8746. #'identity
  8747. (append
  8748. (assoc-default 'category org-agenda-filters-preset)
  8749. org-agenda-category-filter)
  8750. "")
  8751. "]")
  8752. 'face 'org-agenda-filter-category
  8753. 'help-echo "Category used in filtering"))
  8754. "")
  8755. (if (or org-agenda-tag-filter
  8756. (assoc-default 'tag org-agenda-filters-preset))
  8757. '(:eval (propertize
  8758. (concat (mapconcat
  8759. #'identity
  8760. (append
  8761. (assoc-default 'tag org-agenda-filters-preset)
  8762. org-agenda-tag-filter)
  8763. ""))
  8764. 'face 'org-agenda-filter-tags
  8765. 'help-echo "Tags used in filtering"))
  8766. "")
  8767. (if (or org-agenda-effort-filter
  8768. (assoc-default 'effort org-agenda-filters-preset))
  8769. '(:eval (propertize
  8770. (concat (mapconcat
  8771. #'identity
  8772. (append
  8773. (assoc-default 'effort org-agenda-filters-preset)
  8774. org-agenda-effort-filter)
  8775. ""))
  8776. 'face 'org-agenda-filter-effort
  8777. 'help-echo "Effort conditions used in filtering"))
  8778. "")
  8779. (if (or org-agenda-regexp-filter
  8780. (assoc-default 'regexp org-agenda-filters-preset))
  8781. '(:eval (propertize
  8782. (concat (mapconcat
  8783. (lambda (x) (concat (substring x 0 1) "/" (substring x 1) "/"))
  8784. (append
  8785. (assoc-default 'regexp org-agenda-filters-preset)
  8786. org-agenda-regexp-filter)
  8787. ""))
  8788. 'face 'org-agenda-filter-regexp
  8789. 'help-echo "Regexp used in filtering"))
  8790. "")
  8791. (if org-agenda-archives-mode
  8792. (if (eq org-agenda-archives-mode t)
  8793. " Archives"
  8794. (format " :%s:" org-archive-tag))
  8795. "")
  8796. (if org-agenda-clockreport-mode " Clock" "")))
  8797. (force-mode-line-update))
  8798. (defun org-agenda-update-agenda-type ()
  8799. "Update the agenda type after each command."
  8800. (setq org-agenda-type
  8801. (or (get-text-property (point) 'org-agenda-type)
  8802. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  8803. (defun org-agenda-next-line ()
  8804. "Move cursor to the next line, and show if follow mode is active."
  8805. (interactive)
  8806. (call-interactively 'next-line)
  8807. (org-agenda-do-context-action))
  8808. (defun org-agenda-previous-line ()
  8809. "Move cursor to the previous line, and show if follow-mode is active."
  8810. (interactive)
  8811. (call-interactively 'previous-line)
  8812. (org-agenda-do-context-action))
  8813. (defun org-agenda-next-item (n)
  8814. "Move cursor to next agenda item."
  8815. (interactive "p")
  8816. (let ((col (current-column)))
  8817. (dotimes (_ n)
  8818. (when (next-single-property-change (line-end-position) 'org-marker)
  8819. (move-end-of-line 1)
  8820. (goto-char (next-single-property-change (point) 'org-marker))))
  8821. (org-move-to-column col))
  8822. (org-agenda-do-context-action))
  8823. (defun org-agenda-previous-item (n)
  8824. "Move cursor to next agenda item."
  8825. (interactive "p")
  8826. (dotimes (_ n)
  8827. (let ((col (current-column))
  8828. (goto (save-excursion
  8829. (move-end-of-line 0)
  8830. (previous-single-property-change (point) 'org-marker))))
  8831. (when goto (goto-char goto))
  8832. (org-move-to-column col)))
  8833. (org-agenda-do-context-action))
  8834. (defun org-agenda-do-context-action ()
  8835. "Show outline path and, maybe, follow mode window."
  8836. (let ((m (org-get-at-bol 'org-marker)))
  8837. (when (and (markerp m) (marker-buffer m))
  8838. (and org-agenda-follow-mode
  8839. (if org-agenda-follow-indirect
  8840. (org-agenda-tree-to-indirect-buffer nil)
  8841. (org-agenda-show)))
  8842. (and org-agenda-show-outline-path
  8843. (org-with-point-at m (org-display-outline-path t))))))
  8844. (defun org-agenda-show-tags ()
  8845. "Show the tags applicable to the current item."
  8846. (interactive)
  8847. (let* ((tags (org-get-at-bol 'tags)))
  8848. (if tags
  8849. (message "Tags are :%s:"
  8850. (org-no-properties (mapconcat #'identity tags ":")))
  8851. (message "No tags associated with this line"))))
  8852. (defun org-agenda-goto (&optional highlight)
  8853. "Go to the entry at point in the corresponding Org file."
  8854. (interactive)
  8855. (let* ((marker (or (org-get-at-bol 'org-marker)
  8856. (org-agenda-error)))
  8857. (buffer (marker-buffer marker))
  8858. (pos (marker-position marker)))
  8859. ;; FIXME: use `org-switch-to-buffer-other-window'?
  8860. (switch-to-buffer-other-window buffer)
  8861. (widen)
  8862. (push-mark)
  8863. (goto-char pos)
  8864. (when (derived-mode-p 'org-mode)
  8865. (org-fold-show-context 'agenda)
  8866. (recenter (/ (window-height) 2))
  8867. (org-back-to-heading t)
  8868. (let ((case-fold-search nil))
  8869. (when (re-search-forward org-complex-heading-regexp nil t)
  8870. (goto-char (match-beginning 4)))))
  8871. (run-hooks 'org-agenda-after-show-hook)
  8872. (and highlight (org-highlight (line-beginning-position)
  8873. (line-end-position)))))
  8874. (defvar org-agenda-after-show-hook nil
  8875. "Normal hook run after an item has been shown from the agenda.
  8876. Point is in the buffer where the item originated.")
  8877. ;; Defined later in org-agenda.el
  8878. (defvar org-agenda-loop-over-headlines-in-active-region nil)
  8879. (defun org-agenda-do-in-region (beg end cmd &optional arg force-arg delete)
  8880. "Between region BEG and END, call agenda command CMD.
  8881. When optional argument ARG is non-nil or FORCE-ARG is t, pass
  8882. ARG to CMD. When optional argument DELETE is non-nil, assume CMD
  8883. deletes the agenda entry and don't move to the next entry."
  8884. (save-excursion
  8885. (goto-char beg)
  8886. (let ((mend (move-marker (make-marker) end))
  8887. (all (eq org-agenda-loop-over-headlines-in-active-region t))
  8888. (match (and (stringp org-agenda-loop-over-headlines-in-active-region)
  8889. org-agenda-loop-over-headlines-in-active-region))
  8890. (level (and (eq org-agenda-loop-over-headlines-in-active-region 'start-level)
  8891. (org-get-at-bol 'level))))
  8892. (while (< (point) mend)
  8893. (let ((ov (make-overlay (point) (line-end-position))))
  8894. (if (not (or all
  8895. (and match (looking-at-p match))
  8896. (eq level (org-get-at-bol 'level))))
  8897. (org-agenda-next-item 1)
  8898. (overlay-put ov 'face 'region)
  8899. (if (or arg force-arg) (funcall cmd arg) (funcall cmd))
  8900. (when (not delete) (org-agenda-next-item 1))
  8901. (delete-overlay ov)))))))
  8902. ;; org-agenda-[schedule,deadline,date-prompt,todo,[toggle]archive*,
  8903. ;; kill,set-property,set-effort] commands may loop over agenda
  8904. ;; entries. Commands `org-agenda-set-tags' and `org-agenda-bulk-mark'
  8905. ;; use their own mechanisms on active regions.
  8906. (defmacro org-agenda-maybe-loop (cmd arg force-arg delete &rest body)
  8907. "Maybe loop over agenda entries and perform CMD.
  8908. Pass ARG, FORCE-ARG, DELETE and BODY to `org-agenda-do-in-region'."
  8909. (declare (debug t))
  8910. `(if (and (called-interactively-p 'any)
  8911. org-agenda-loop-over-headlines-in-active-region
  8912. (org-region-active-p))
  8913. (org-agenda-do-in-region
  8914. (region-beginning) (region-end) ,cmd ,arg ,force-arg ,delete)
  8915. ,@body))
  8916. (defun org-agenda-kill ()
  8917. "Kill the entry or subtree belonging to the current agenda entry."
  8918. (interactive)
  8919. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8920. (org-agenda-maybe-loop
  8921. #'org-agenda-kill nil nil t
  8922. (let* ((bufname-orig (buffer-name))
  8923. (marker (or (org-get-at-bol 'org-marker)
  8924. (org-agenda-error)))
  8925. (buffer (marker-buffer marker))
  8926. (pos (marker-position marker))
  8927. (type (org-get-at-bol 'type))
  8928. dbeg dend (n 0))
  8929. (org-with-remote-undo buffer
  8930. (with-current-buffer buffer
  8931. (save-excursion
  8932. (goto-char pos)
  8933. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  8934. (setq dbeg (progn (org-back-to-heading t) (point))
  8935. dend (org-end-of-subtree t t))
  8936. (setq dbeg (line-beginning-position)
  8937. dend (min (point-max) (1+ (line-end-position)))))
  8938. (goto-char dbeg)
  8939. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  8940. (when (or (eq t org-agenda-confirm-kill)
  8941. (and (numberp org-agenda-confirm-kill)
  8942. (> n org-agenda-confirm-kill)))
  8943. (let ((win-conf (current-window-configuration)))
  8944. (unwind-protect
  8945. (and
  8946. (prog2
  8947. (org-agenda-tree-to-indirect-buffer nil)
  8948. (not (y-or-n-p
  8949. (format "Delete entry with %d lines in buffer \"%s\"? "
  8950. n (buffer-name buffer))))
  8951. (kill-buffer org-last-indirect-buffer))
  8952. (error "Abort"))
  8953. (set-window-configuration win-conf))))
  8954. (let ((org-agenda-buffer-name bufname-orig))
  8955. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  8956. (with-current-buffer buffer (delete-region dbeg dend))
  8957. (message "Agenda item and source killed")))))
  8958. (defvar org-archive-default-command) ; defined in org-archive.el
  8959. (defun org-agenda-archive-default ()
  8960. "Archive the entry or subtree belonging to the current agenda entry."
  8961. (interactive)
  8962. (require 'org-archive)
  8963. (funcall-interactively
  8964. #'org-agenda-archive-with org-archive-default-command))
  8965. (defun org-agenda-archive-default-with-confirmation ()
  8966. "Archive the entry or subtree belonging to the current agenda entry."
  8967. (interactive)
  8968. (require 'org-archive)
  8969. (funcall-interactively
  8970. #'org-agenda-archive-with org-archive-default-command 'confirm))
  8971. (defun org-agenda-archive ()
  8972. "Archive the entry or subtree belonging to the current agenda entry."
  8973. (interactive)
  8974. (funcall-interactively
  8975. #'org-agenda-archive-with 'org-archive-subtree))
  8976. (defun org-agenda-archive-to-archive-sibling ()
  8977. "Move the entry to the archive sibling."
  8978. (interactive)
  8979. (funcall-interactively
  8980. #'org-agenda-archive-with 'org-archive-to-archive-sibling))
  8981. (defvar org-archive-from-agenda)
  8982. (defun org-agenda-archive-with (cmd &optional confirm)
  8983. "Move the entry to the archive sibling."
  8984. (interactive)
  8985. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8986. (org-agenda-maybe-loop
  8987. #'org-agenda-archive-with cmd nil t
  8988. (let* ((bufname-orig (buffer-name))
  8989. (marker (or (org-get-at-bol 'org-marker)
  8990. (org-agenda-error)))
  8991. (buffer (marker-buffer marker))
  8992. (pos (marker-position marker)))
  8993. (org-with-remote-undo buffer
  8994. (with-current-buffer buffer
  8995. (if (derived-mode-p 'org-mode)
  8996. (if (and confirm
  8997. (not (y-or-n-p "Archive this subtree or entry? ")))
  8998. (error "Abort")
  8999. (save-window-excursion
  9000. (goto-char pos)
  9001. (let ((org-agenda-buffer-name bufname-orig))
  9002. (org-remove-subtree-entries-from-agenda))
  9003. (org-back-to-heading t)
  9004. (let ((org-archive-from-agenda t))
  9005. (funcall cmd))))
  9006. (error "Archiving works only in Org files")))))))
  9007. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  9008. "Remove all lines in the agenda that correspond to a given subtree.
  9009. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  9010. If this information is not given, the function uses the tree at point."
  9011. (let ((buf (or buf (current-buffer))) m p)
  9012. (save-excursion
  9013. (unless (and beg end)
  9014. (org-back-to-heading t)
  9015. (setq beg (point))
  9016. (org-end-of-subtree t)
  9017. (setq end (point)))
  9018. (set-buffer (get-buffer org-agenda-buffer-name))
  9019. (save-excursion
  9020. (goto-char (point-max))
  9021. (beginning-of-line 1)
  9022. (while (not (bobp))
  9023. (when (and (setq m (org-get-at-bol 'org-marker))
  9024. (equal buf (marker-buffer m))
  9025. (setq p (marker-position m))
  9026. (>= p beg)
  9027. (< p end))
  9028. (let ((inhibit-read-only t))
  9029. (delete-region (line-beginning-position)
  9030. (1+ (line-end-position)))))
  9031. (beginning-of-line 0))))))
  9032. (defun org-agenda-refile (&optional goto rfloc no-update)
  9033. "Refile the item at point.
  9034. When called with `\\[universal-argument] \\[universal-argument]', \
  9035. go to the location of the last
  9036. refiled item.
  9037. When called with `\\[universal-argument] \\[universal-argument] \
  9038. \\[universal-argument]' prefix or when GOTO is 0, clear
  9039. the refile cache.
  9040. RFLOC can be a refile location obtained in a different way.
  9041. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  9042. (interactive "P")
  9043. (cond
  9044. ((member goto '(0 (64)))
  9045. (org-refile-cache-clear))
  9046. ((equal goto '(16))
  9047. (org-refile-goto-last-stored))
  9048. (t
  9049. (let* ((buffer-orig (buffer-name))
  9050. (marker (or (org-get-at-bol 'org-hd-marker)
  9051. (org-agenda-error)))
  9052. (buffer (marker-buffer marker))
  9053. ;; (pos (marker-position marker))
  9054. (rfloc (or rfloc
  9055. (org-refile-get-location
  9056. (if goto "Goto" "Refile to") buffer
  9057. org-refile-allow-creating-parent-nodes))))
  9058. (with-current-buffer buffer
  9059. (org-with-wide-buffer
  9060. (goto-char marker)
  9061. (let ((org-agenda-buffer-name buffer-orig))
  9062. (org-remove-subtree-entries-from-agenda))
  9063. (org-refile goto buffer rfloc))))
  9064. (unless no-update (org-agenda-redo)))))
  9065. (defun org-agenda-open-link (&optional arg)
  9066. "Open the link(s) in the current entry, if any.
  9067. This looks for a link in the displayed line in the agenda.
  9068. It also looks at the text of the entry itself."
  9069. (interactive "P")
  9070. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  9071. (org-get-at-bol 'org-marker)))
  9072. (buffer (and marker (marker-buffer marker)))
  9073. (prefix (buffer-substring (line-beginning-position)
  9074. (line-end-position)))
  9075. (lkall (and buffer (org-offer-links-in-entry
  9076. buffer marker arg prefix)))
  9077. (lk0 (car lkall))
  9078. (lk (if (stringp lk0) (list lk0) lk0))
  9079. (lkend (cdr lkall))
  9080. trg)
  9081. (cond
  9082. ((and buffer lk)
  9083. (mapcar (lambda(l)
  9084. (with-current-buffer buffer
  9085. (setq trg (and (string-match org-link-bracket-re l)
  9086. (match-string 1 l)))
  9087. (if (or (not trg) (string-match org-link-any-re trg))
  9088. ;; Don't use `org-with-wide-buffer' here as
  9089. ;; opening the link may result in moving the point
  9090. (save-restriction
  9091. (widen)
  9092. (goto-char marker)
  9093. (when (search-forward l nil lkend)
  9094. (goto-char (match-beginning 0))
  9095. (org-open-at-point)))
  9096. ;; This is an internal link, widen the buffer
  9097. ;; FIXME: use `org-switch-to-buffer-other-window'?
  9098. (switch-to-buffer-other-window buffer)
  9099. (widen)
  9100. (goto-char marker)
  9101. (when (search-forward l nil lkend)
  9102. (goto-char (match-beginning 0))
  9103. (org-open-at-point)))))
  9104. lk))
  9105. ((or (org-in-regexp (concat "\\(" org-link-bracket-re "\\)"))
  9106. (save-excursion
  9107. (beginning-of-line 1)
  9108. (looking-at (concat ".*?\\(" org-link-bracket-re "\\)"))))
  9109. (org-link-open-from-string (match-string 1)))
  9110. (t (message "No link to open here")))))
  9111. (defun org-agenda-copy-local-variable (var)
  9112. "Get a variable from a referenced buffer and install it here."
  9113. (let ((m (org-get-at-bol 'org-marker)))
  9114. (when (and m (buffer-live-p (marker-buffer m)))
  9115. (set (make-local-variable var)
  9116. (with-current-buffer (marker-buffer m)
  9117. (symbol-value var))))))
  9118. (defun org-agenda-switch-to (&optional delete-other-windows)
  9119. "Go to the Org mode file which contains the item at point.
  9120. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  9121. displayed Org file fills the frame."
  9122. (interactive)
  9123. (if (and org-return-follows-link
  9124. (not (org-get-at-bol 'org-marker))
  9125. (org-in-regexp org-link-bracket-re))
  9126. (org-link-open-from-string (match-string 0))
  9127. (let* ((marker (or (org-get-at-bol 'org-marker)
  9128. (org-agenda-error)))
  9129. (buffer (marker-buffer marker))
  9130. (pos (marker-position marker)))
  9131. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  9132. (pop-to-buffer-same-window buffer)
  9133. (when delete-other-windows (delete-other-windows))
  9134. (widen)
  9135. (goto-char pos)
  9136. (when (derived-mode-p 'org-mode)
  9137. (org-fold-show-context 'agenda)
  9138. (run-hooks 'org-agenda-after-show-hook)))))
  9139. (defun org-agenda-goto-mouse (ev)
  9140. "Go to the Org file which contains the item at the mouse click."
  9141. (interactive "e")
  9142. (mouse-set-point ev)
  9143. (org-agenda-goto))
  9144. (defun org-agenda-show (&optional full-entry)
  9145. "Display the Org file which contains the item at point.
  9146. With prefix argument FULL-ENTRY, make the entire entry visible
  9147. if it was hidden in the outline."
  9148. (interactive "P")
  9149. (let ((win (selected-window)))
  9150. (org-agenda-goto t)
  9151. (when full-entry (org-fold-show-entry 'hide-drawers))
  9152. (select-window win)))
  9153. (defvar org-agenda-show-window nil)
  9154. (defun org-agenda-show-and-scroll-up (&optional arg)
  9155. "Display the Org file which contains the item at point.
  9156. When called repeatedly, scroll the window that is displaying the buffer.
  9157. With a `\\[universal-argument]' prefix argument, display the item, but \
  9158. fold drawers."
  9159. (interactive "P")
  9160. (let ((win (selected-window)))
  9161. (if (and (window-live-p org-agenda-show-window)
  9162. (eq this-command last-command))
  9163. (progn
  9164. (select-window org-agenda-show-window)
  9165. (ignore-errors (scroll-up)))
  9166. (org-agenda-goto t)
  9167. (org-fold-show-entry 'hide-drawers)
  9168. (if arg (org-cycle-hide-drawers 'children)
  9169. (org-with-wide-buffer
  9170. (narrow-to-region (org-entry-beginning-position)
  9171. (org-entry-end-position))
  9172. (org-fold-show-all '(drawers))))
  9173. (setq org-agenda-show-window (selected-window)))
  9174. (select-window win)))
  9175. (defun org-agenda-show-scroll-down ()
  9176. "Scroll down the window showing the agenda."
  9177. (interactive)
  9178. (let ((win (selected-window)))
  9179. (when (window-live-p org-agenda-show-window)
  9180. (select-window org-agenda-show-window)
  9181. (ignore-errors (scroll-down))
  9182. (select-window win))))
  9183. (defun org-agenda-show-1 (&optional more)
  9184. "Display the Org file which contains the item at point.
  9185. The prefix arg selects the amount of information to display:
  9186. 0 hide the subtree
  9187. 1 just show the entry according to defaults.
  9188. 2 show the children view
  9189. 3 show the subtree view
  9190. 4 show the entire subtree and any drawers
  9191. With prefix argument FULL-ENTRY, make the entire entry visible
  9192. if it was hidden in the outline."
  9193. (interactive "p")
  9194. (let ((win (selected-window)))
  9195. (org-agenda-goto t)
  9196. (org-back-to-heading)
  9197. (set-window-start (selected-window) (line-beginning-position))
  9198. (cond
  9199. ((= more 0)
  9200. (org-fold-subtree t)
  9201. (save-excursion
  9202. (org-back-to-heading)
  9203. (run-hook-with-args 'org-cycle-hook 'folded))
  9204. (message "Remote: FOLDED"))
  9205. ((and (called-interactively-p 'any) (= more 1))
  9206. (message "Remote: show with default settings"))
  9207. ((= more 2)
  9208. (org-fold-show-entry 'hide-drawers)
  9209. (org-fold-show-children)
  9210. (save-excursion
  9211. (org-back-to-heading)
  9212. (run-hook-with-args 'org-cycle-hook 'children))
  9213. (message "Remote: CHILDREN"))
  9214. ((= more 3)
  9215. (org-fold-show-subtree)
  9216. (save-excursion
  9217. (org-back-to-heading)
  9218. (run-hook-with-args 'org-cycle-hook 'subtree))
  9219. (message "Remote: SUBTREE"))
  9220. ((> more 3)
  9221. (org-fold-show-subtree)
  9222. (message "Remote: SUBTREE AND ALL DRAWERS")))
  9223. (select-window win)))
  9224. (defvar org-agenda-cycle-counter nil)
  9225. (defun org-agenda-cycle-show (&optional n)
  9226. "Show the current entry in another window, with default settings.
  9227. Default settings are taken from `org-show-context-detail'. When
  9228. use repeatedly in immediate succession, the remote entry will
  9229. cycle through visibility
  9230. children -> subtree -> folded
  9231. When called with a numeric prefix arg, that arg will be passed through to
  9232. `org-agenda-show-1'. For the interpretation of that argument, see the
  9233. docstring of `org-agenda-show-1'."
  9234. (interactive "P")
  9235. (if (integerp n)
  9236. (setq org-agenda-cycle-counter n)
  9237. (if (not (eq last-command this-command))
  9238. (setq org-agenda-cycle-counter 1)
  9239. (if (equal org-agenda-cycle-counter 0)
  9240. (setq org-agenda-cycle-counter 2)
  9241. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  9242. (when (> org-agenda-cycle-counter 3)
  9243. (setq org-agenda-cycle-counter 0)))))
  9244. (org-agenda-show-1 org-agenda-cycle-counter))
  9245. (defun org-agenda-recenter (arg)
  9246. "Display the Org file which contains the item at point and recenter."
  9247. (interactive "P")
  9248. (let ((win (selected-window)))
  9249. (org-agenda-goto t)
  9250. (recenter arg)
  9251. (select-window win)))
  9252. (defun org-agenda-show-mouse (ev)
  9253. "Display the Org file which contains the item at the mouse click."
  9254. (interactive "e")
  9255. (mouse-set-point ev)
  9256. (org-agenda-show))
  9257. (defun org-agenda-check-no-diary ()
  9258. "Check if the entry is a diary link and abort if yes."
  9259. (when (org-get-at-bol 'org-agenda-diary-link)
  9260. (org-agenda-error)))
  9261. (defun org-agenda-error ()
  9262. "Throw an error when a command is not allowed in the agenda."
  9263. (user-error "Command not allowed in this line"))
  9264. (defun org-agenda-tree-to-indirect-buffer (arg)
  9265. "Show the subtree corresponding to the current entry in an indirect buffer.
  9266. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  9267. With a numerical prefix ARG, go up to this level and then take that tree.
  9268. With a negative numeric ARG, go up by this number of levels.
  9269. With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
  9270. i.e. don't use
  9271. the dedicated frame."
  9272. (interactive "P")
  9273. (if current-prefix-arg
  9274. (org-agenda-do-tree-to-indirect-buffer arg)
  9275. (let ((agenda-buffer (buffer-name))
  9276. (agenda-window (selected-window))
  9277. (indirect-window
  9278. (and org-last-indirect-buffer
  9279. (get-buffer-window org-last-indirect-buffer))))
  9280. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  9281. (unless (or (eq org-indirect-buffer-display 'new-frame)
  9282. (eq org-indirect-buffer-display 'dedicated-frame))
  9283. (unwind-protect
  9284. (unless (and indirect-window (window-live-p indirect-window))
  9285. (setq indirect-window (split-window agenda-window)))
  9286. (and indirect-window (select-window indirect-window))
  9287. (switch-to-buffer org-last-indirect-buffer :norecord)
  9288. (fit-window-to-buffer indirect-window)))
  9289. (select-window (get-buffer-window agenda-buffer))
  9290. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  9291. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  9292. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  9293. (org-agenda-check-no-diary)
  9294. (let* ((marker (or (org-get-at-bol 'org-marker)
  9295. (org-agenda-error)))
  9296. (buffer (marker-buffer marker))
  9297. (pos (marker-position marker)))
  9298. (with-current-buffer buffer
  9299. (save-excursion
  9300. (goto-char pos)
  9301. (org-tree-to-indirect-buffer arg)))))
  9302. (defvar org-last-heading-marker (make-marker)
  9303. "Marker pointing to the headline that last changed its TODO state
  9304. by a remote command from the agenda.")
  9305. (defun org-agenda-todo-nextset ()
  9306. "Switch TODO entry to next sequence."
  9307. (interactive)
  9308. (org-agenda-todo 'nextset))
  9309. (defun org-agenda-todo-previousset ()
  9310. "Switch TODO entry to previous sequence."
  9311. (interactive)
  9312. (org-agenda-todo 'previousset))
  9313. (defvar org-agenda-headline-snapshot-before-repeat)
  9314. (defun org-agenda-todo (&optional arg)
  9315. "Cycle TODO state of line at point, also in Org file.
  9316. This changes the line at point, all other lines in the agenda referring to
  9317. the same tree node, and the headline of the tree node in the Org file."
  9318. (interactive "P")
  9319. (org-agenda-check-no-diary)
  9320. (org-agenda-maybe-loop
  9321. #'org-agenda-todo arg nil nil
  9322. (let* ((col (current-column))
  9323. (marker (or (org-get-at-bol 'org-marker)
  9324. (org-agenda-error)))
  9325. (buffer (marker-buffer marker))
  9326. (pos (marker-position marker))
  9327. (hdmarker (org-get-at-bol 'org-hd-marker))
  9328. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  9329. (inhibit-read-only t)
  9330. org-loop-over-headlines-in-active-region
  9331. org-agenda-headline-snapshot-before-repeat newhead just-one)
  9332. (org-with-remote-undo buffer
  9333. (with-current-buffer buffer
  9334. (widen)
  9335. (goto-char pos)
  9336. (org-fold-show-context 'agenda)
  9337. (let ((current-prefix-arg arg))
  9338. (call-interactively 'org-todo)
  9339. ;; Make sure that log is recorded in current undo.
  9340. (when (and org-log-setup
  9341. (not (eq org-log-note-how 'note)))
  9342. (org-add-log-note)))
  9343. (and (bolp) (forward-char 1))
  9344. (setq newhead (org-get-heading))
  9345. (when (and org-agenda-headline-snapshot-before-repeat
  9346. (not (equal org-agenda-headline-snapshot-before-repeat
  9347. newhead))
  9348. todayp)
  9349. (setq newhead org-agenda-headline-snapshot-before-repeat
  9350. just-one t))
  9351. (save-excursion
  9352. (org-back-to-heading)
  9353. (move-marker org-last-heading-marker (point))))
  9354. (beginning-of-line 1)
  9355. (save-window-excursion
  9356. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  9357. (when (bound-and-true-p org-clock-out-when-done)
  9358. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  9359. newhead)
  9360. (org-agenda-unmark-clocking-task))
  9361. (org-move-to-column col)
  9362. (org-agenda-mark-clocking-task)))))
  9363. (defun org-agenda-add-note (&optional _arg)
  9364. "Add a time-stamped note to the entry at point."
  9365. (interactive) ;; "P"
  9366. (org-agenda-check-no-diary)
  9367. (let* ((marker (or (org-get-at-bol 'org-marker)
  9368. (org-agenda-error)))
  9369. (buffer (marker-buffer marker))
  9370. (pos (marker-position marker))
  9371. (_hdmarker (org-get-at-bol 'org-hd-marker))
  9372. (inhibit-read-only t))
  9373. (with-current-buffer buffer
  9374. (widen)
  9375. (goto-char pos)
  9376. (org-fold-show-context 'agenda)
  9377. (org-add-note))))
  9378. (defun org-agenda-change-all-lines (newhead hdmarker
  9379. &optional fixface just-this)
  9380. "Change all lines in the agenda buffer which match HDMARKER.
  9381. The new content of the line will be NEWHEAD (as modified by
  9382. `org-agenda-format-item'). HDMARKER is checked with
  9383. `equal' against all `org-hd-marker' text properties in the file.
  9384. If FIXFACE is non-nil, the face of each item is modified according to
  9385. the new TODO state.
  9386. If JUST-THIS is non-nil, change just the current line, not all.
  9387. If FORCE-TAGS is non-nil, the car of it returns the new tags."
  9388. (let* ((inhibit-read-only t)
  9389. (line (org-current-line))
  9390. (org-agenda-buffer (current-buffer))
  9391. (thetags (with-current-buffer (marker-buffer hdmarker)
  9392. (org-get-tags hdmarker)))
  9393. props m undone-face done-face finish new dotime level cat tags
  9394. effort effort-minutes) ;; pl
  9395. (save-excursion
  9396. (goto-char (point-max))
  9397. (beginning-of-line 1)
  9398. (while (not finish)
  9399. (setq finish (bobp))
  9400. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  9401. (or (not just-this) (= (org-current-line) line))
  9402. (equal m hdmarker))
  9403. (setq props (text-properties-at (point))
  9404. dotime (org-get-at-bol 'dotime)
  9405. cat (org-agenda-get-category)
  9406. level (org-get-at-bol 'level)
  9407. tags thetags
  9408. effort (org-get-at-bol 'effort)
  9409. effort-minutes (org-get-at-bol 'effort-minutes)
  9410. new
  9411. (let ((org-prefix-format-compiled
  9412. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  9413. org-prefix-format-compiled))
  9414. (extra (org-get-at-bol 'extra)))
  9415. (with-current-buffer (marker-buffer hdmarker)
  9416. (org-with-wide-buffer
  9417. (org-agenda-format-item extra
  9418. (org-add-props newhead nil
  9419. 'effort effort
  9420. 'effort-minutes effort-minutes)
  9421. level cat tags dotime))))
  9422. ;; pl (text-property-any (line-beginning-position)
  9423. ;; (line-end-position) 'org-heading t)
  9424. undone-face (org-get-at-bol 'undone-face)
  9425. done-face (org-get-at-bol 'done-face))
  9426. (beginning-of-line 1)
  9427. (cond
  9428. ((equal new "") (delete-region (point) (line-beginning-position 2)))
  9429. ((looking-at ".*")
  9430. ;; When replacing the whole line, preserve bulk mark
  9431. ;; overlay, if any.
  9432. (let ((mark (catch :overlay
  9433. (dolist (o (overlays-in (point) (+ 2 (point))))
  9434. (when (eq (overlay-get o 'type)
  9435. 'org-marked-entry-overlay)
  9436. (throw :overlay o))))))
  9437. (replace-match new t t)
  9438. (beginning-of-line)
  9439. (when mark (move-overlay mark (point) (+ 2 (point)))))
  9440. (add-text-properties (line-beginning-position)
  9441. (line-end-position) props)
  9442. (when fixface
  9443. (add-text-properties
  9444. (line-beginning-position) (line-end-position)
  9445. (list 'face
  9446. (if org-last-todo-state-is-todo
  9447. undone-face done-face))))
  9448. (org-agenda-highlight-todo 'line)
  9449. (beginning-of-line 1))
  9450. (t (error "Line update did not work")))
  9451. (save-restriction
  9452. (narrow-to-region (line-beginning-position) (line-end-position))
  9453. (org-agenda-finalize)))
  9454. (beginning-of-line 0)))))
  9455. (defun org-agenda-align-tags (&optional line)
  9456. "Align all tags in agenda items to `org-agenda-tags-column'.
  9457. When optional argument LINE is non-nil, align tags only on the
  9458. current line."
  9459. (let ((inhibit-read-only t)
  9460. (org-agenda-tags-column (if (eq 'auto org-agenda-tags-column)
  9461. (- (window-max-chars-per-line))
  9462. org-agenda-tags-column))
  9463. (end (and line (line-end-position)))
  9464. l c)
  9465. (org-fold-core-ignore-modifications
  9466. (save-excursion
  9467. (goto-char (if line (line-beginning-position) (point-min)))
  9468. (while (re-search-forward org-tag-group-re end t)
  9469. (add-text-properties
  9470. (match-beginning 1) (match-end 1)
  9471. (list 'face (delq nil (let ((prop (get-text-property
  9472. (match-beginning 1) 'face)))
  9473. (or (listp prop) (setq prop (list prop)))
  9474. (if (memq 'org-tag prop)
  9475. prop
  9476. (cons 'org-tag prop))))))
  9477. (setq l (string-width (match-string 1))
  9478. c (if (< org-agenda-tags-column 0)
  9479. (- (abs org-agenda-tags-column) l)
  9480. org-agenda-tags-column))
  9481. (goto-char (match-beginning 1))
  9482. (delete-region (save-excursion (skip-chars-backward " \t") (point))
  9483. (point))
  9484. (insert (org-add-props
  9485. (make-string (max 1 (- c (current-column))) ?\s)
  9486. (plist-put (copy-sequence (text-properties-at (point)))
  9487. 'face nil))))
  9488. (goto-char (point-min))
  9489. (org-font-lock-add-tag-faces (point-max))))))
  9490. (defun org-agenda-priority-up ()
  9491. "Increase the priority of line at point, also in Org file."
  9492. (interactive)
  9493. (org-agenda-priority 'up))
  9494. (defun org-agenda-priority-down ()
  9495. "Decrease the priority of line at point, also in Org file."
  9496. (interactive)
  9497. (org-agenda-priority 'down))
  9498. (defun org-agenda-priority (&optional force-direction)
  9499. "Set the priority of line at point, also in Org file.
  9500. This changes the line at point, all other lines in the agenda
  9501. referring to the same tree node, and the headline of the tree
  9502. node in the Org file.
  9503. Called with one universal prefix arg, show the priority instead
  9504. of setting it.
  9505. When called programmatically, FORCE-DIRECTION can be `set', `up',
  9506. `down', or a character."
  9507. (interactive "P")
  9508. (unless org-priority-enable-commands
  9509. (user-error "Priority commands are disabled"))
  9510. (org-agenda-check-no-diary)
  9511. (let* ((col (current-column))
  9512. (hdmarker (org-get-at-bol 'org-hd-marker))
  9513. (buffer (marker-buffer hdmarker))
  9514. (pos (marker-position hdmarker))
  9515. (inhibit-read-only t)
  9516. newhead)
  9517. (org-with-remote-undo buffer
  9518. (with-current-buffer buffer
  9519. (widen)
  9520. (goto-char pos)
  9521. (org-fold-show-context 'agenda)
  9522. (org-priority force-direction)
  9523. (end-of-line 1)
  9524. (setq newhead (org-get-heading)))
  9525. (org-agenda-change-all-lines newhead hdmarker)
  9526. (org-move-to-column col))))
  9527. ;; FIXME: should fix the tags property of the agenda line.
  9528. (defun org-agenda-set-tags (&optional tag onoff)
  9529. "Set tags for the current headline."
  9530. (interactive)
  9531. (org-agenda-check-no-diary)
  9532. (if (and (org-region-active-p) (called-interactively-p 'any))
  9533. (call-interactively 'org-change-tag-in-region)
  9534. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9535. (org-agenda-error)))
  9536. (buffer (marker-buffer hdmarker))
  9537. (pos (marker-position hdmarker))
  9538. (inhibit-read-only t)
  9539. newhead)
  9540. (org-with-remote-undo buffer
  9541. (with-current-buffer buffer
  9542. (widen)
  9543. (goto-char pos)
  9544. (org-fold-show-context 'agenda)
  9545. (if tag
  9546. (org-toggle-tag tag onoff)
  9547. (call-interactively #'org-set-tags-command))
  9548. (end-of-line 1)
  9549. (setq newhead (org-get-heading)))
  9550. (org-agenda-change-all-lines newhead hdmarker)
  9551. (beginning-of-line 1)))))
  9552. (defun org-agenda-set-property ()
  9553. "Set a property for the current headline."
  9554. (interactive)
  9555. (org-agenda-check-no-diary)
  9556. (org-agenda-maybe-loop
  9557. #'org-agenda-set-property nil nil nil
  9558. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9559. (org-agenda-error)))
  9560. (buffer (marker-buffer hdmarker))
  9561. (pos (marker-position hdmarker))
  9562. (inhibit-read-only t)
  9563. ) ;; newhead
  9564. (org-with-remote-undo buffer
  9565. (with-current-buffer buffer
  9566. (widen)
  9567. (goto-char pos)
  9568. (org-fold-show-context 'agenda)
  9569. (call-interactively 'org-set-property))))))
  9570. (defun org-agenda-set-effort ()
  9571. "Set the effort property for the current headline."
  9572. (interactive)
  9573. (org-agenda-check-no-diary)
  9574. (org-agenda-maybe-loop
  9575. #'org-agenda-set-effort nil nil nil
  9576. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9577. (org-agenda-error)))
  9578. (buffer (marker-buffer hdmarker))
  9579. (pos (marker-position hdmarker))
  9580. (inhibit-read-only t)
  9581. newhead)
  9582. (org-with-remote-undo buffer
  9583. (with-current-buffer buffer
  9584. (widen)
  9585. (goto-char pos)
  9586. (org-fold-show-context 'agenda)
  9587. (call-interactively 'org-set-effort)
  9588. (end-of-line 1)
  9589. (setq newhead (org-get-heading)))
  9590. (org-agenda-change-all-lines newhead hdmarker)))))
  9591. (defun org-agenda-toggle-archive-tag ()
  9592. "Toggle the archive tag for the current entry."
  9593. (interactive)
  9594. (org-agenda-check-no-diary)
  9595. (org-agenda-maybe-loop
  9596. #'org-agenda-toggle-archive-tag nil nil nil
  9597. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9598. (org-agenda-error)))
  9599. (buffer (marker-buffer hdmarker))
  9600. (pos (marker-position hdmarker))
  9601. (inhibit-read-only t)
  9602. newhead)
  9603. (org-with-remote-undo buffer
  9604. (with-current-buffer buffer
  9605. (widen)
  9606. (goto-char pos)
  9607. (org-fold-show-context 'agenda)
  9608. (call-interactively 'org-toggle-archive-tag)
  9609. (end-of-line 1)
  9610. (setq newhead (org-get-heading)))
  9611. (org-agenda-change-all-lines newhead hdmarker)
  9612. (beginning-of-line 1)))))
  9613. (defun org-agenda-do-date-later (arg)
  9614. (interactive "P")
  9615. (cond
  9616. ((or (equal arg '(16))
  9617. (memq last-command
  9618. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9619. (setq this-command 'org-agenda-date-later-minutes)
  9620. (org-agenda-date-later-minutes 1))
  9621. ((or (equal arg '(4))
  9622. (memq last-command
  9623. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9624. (setq this-command 'org-agenda-date-later-hours)
  9625. (org-agenda-date-later-hours 1))
  9626. (t
  9627. (org-agenda-date-later (prefix-numeric-value arg)))))
  9628. (defun org-agenda-do-date-earlier (arg)
  9629. (interactive "P")
  9630. (cond
  9631. ((or (equal arg '(16))
  9632. (memq last-command
  9633. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9634. (setq this-command 'org-agenda-date-earlier-minutes)
  9635. (org-agenda-date-earlier-minutes 1))
  9636. ((or (equal arg '(4))
  9637. (memq last-command
  9638. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9639. (setq this-command 'org-agenda-date-earlier-hours)
  9640. (org-agenda-date-earlier-hours 1))
  9641. (t
  9642. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  9643. (defun org-agenda-date-later (arg &optional what)
  9644. "Change the date of this item to ARG day(s) later."
  9645. (interactive "p")
  9646. (org-agenda-check-type t 'agenda)
  9647. (org-agenda-check-no-diary)
  9648. (let* ((marker (or (org-get-at-bol 'org-marker)
  9649. (org-agenda-error)))
  9650. (buffer (marker-buffer marker))
  9651. (pos (marker-position marker))
  9652. cdate today)
  9653. (org-with-remote-undo buffer
  9654. (with-current-buffer buffer
  9655. (widen)
  9656. (goto-char pos)
  9657. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9658. (when (and org-agenda-move-date-from-past-immediately-to-today
  9659. (equal arg 1)
  9660. (or (not what) (eq what 'day))
  9661. (not (save-match-data (org-at-date-range-p))))
  9662. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  9663. cdate (calendar-absolute-from-gregorian
  9664. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  9665. today (org-today))
  9666. (when (> today cdate)
  9667. ;; immediately shift to today
  9668. (setq arg (- today cdate))))
  9669. (org-timestamp-change arg (or what 'day))
  9670. (when (and (org-at-date-range-p)
  9671. (re-search-backward org-tr-regexp-both
  9672. (line-beginning-position)))
  9673. (let ((end org-last-changed-timestamp))
  9674. (org-timestamp-change arg (or what 'day))
  9675. (setq org-last-changed-timestamp
  9676. (concat org-last-changed-timestamp "--" end)))))
  9677. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9678. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  9679. (defun org-agenda-date-earlier (arg &optional what)
  9680. "Change the date of this item to ARG day(s) earlier."
  9681. (interactive "p")
  9682. (org-agenda-date-later (- arg) what))
  9683. (defun org-agenda-date-later-minutes (arg)
  9684. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9685. (interactive "p")
  9686. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9687. (org-agenda-date-later arg 'minute))
  9688. (defun org-agenda-date-earlier-minutes (arg)
  9689. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9690. (interactive "p")
  9691. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9692. (org-agenda-date-earlier arg 'minute))
  9693. (defun org-agenda-date-later-hours (arg)
  9694. "Change the time of this item, in hour steps."
  9695. (interactive "p")
  9696. (org-agenda-date-later arg 'hour))
  9697. (defun org-agenda-date-earlier-hours (arg)
  9698. "Change the time of this item, in hour steps."
  9699. (interactive "p")
  9700. (org-agenda-date-earlier arg 'hour))
  9701. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  9702. "Show new date stamp via text properties."
  9703. ;; We use text properties to make this undoable
  9704. (let ((inhibit-read-only t))
  9705. (setq stamp (concat prefix " => " stamp " "))
  9706. (save-excursion
  9707. (goto-char (point-max))
  9708. (while (not (bobp))
  9709. (when (equal marker (org-get-at-bol 'org-marker))
  9710. (remove-text-properties (line-beginning-position)
  9711. (line-end-position)
  9712. '(display nil))
  9713. (org-move-to-column
  9714. (- (window-max-chars-per-line)
  9715. (length stamp))
  9716. t)
  9717. (add-text-properties
  9718. (1- (point)) (line-end-position)
  9719. (list 'display (org-add-props stamp nil
  9720. 'face '(secondary-selection default))))
  9721. (beginning-of-line 1))
  9722. (beginning-of-line 0)))))
  9723. (defun org-agenda-date-prompt (arg)
  9724. "Change the date of this item. Date is prompted for, with default today.
  9725. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  9726. be used to request time specification in the time stamp."
  9727. (interactive "P")
  9728. (org-agenda-check-type t 'agenda)
  9729. (org-agenda-check-no-diary)
  9730. (org-agenda-maybe-loop
  9731. #'org-agenda-date-prompt arg t nil
  9732. (let* ((marker (or (org-get-at-bol 'org-marker)
  9733. (org-agenda-error)))
  9734. (buffer (marker-buffer marker))
  9735. (pos (marker-position marker)))
  9736. (org-with-remote-undo buffer
  9737. (with-current-buffer buffer
  9738. (widen)
  9739. (goto-char pos)
  9740. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9741. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  9742. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9743. (message "Time stamp changed to %s" org-last-changed-timestamp))))
  9744. (defun org-agenda-schedule (arg &optional time)
  9745. "Schedule the item at point.
  9746. ARG is passed through to `org-schedule'."
  9747. (interactive "P")
  9748. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9749. (org-agenda-check-no-diary)
  9750. (org-agenda-maybe-loop
  9751. #'org-agenda-schedule arg t nil
  9752. (let* ((marker (or (org-get-at-bol 'org-marker)
  9753. (org-agenda-error)))
  9754. ;; (type (marker-insertion-type marker))
  9755. (buffer (marker-buffer marker))
  9756. (pos (marker-position marker))
  9757. ts)
  9758. (set-marker-insertion-type marker t)
  9759. (org-with-remote-undo buffer
  9760. (with-current-buffer buffer
  9761. (widen)
  9762. (goto-char pos)
  9763. (setq ts (org-schedule arg time)))
  9764. (org-agenda-show-new-time marker ts " S"))
  9765. (message "%s" ts))))
  9766. (defun org-agenda-deadline (arg &optional time)
  9767. "Schedule the item at point.
  9768. ARG is passed through to `org-deadline'."
  9769. (interactive "P")
  9770. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9771. (org-agenda-check-no-diary)
  9772. (org-agenda-maybe-loop
  9773. #'org-agenda-deadline arg t nil
  9774. (let* ((marker (or (org-get-at-bol 'org-marker)
  9775. (org-agenda-error)))
  9776. (buffer (marker-buffer marker))
  9777. (pos (marker-position marker))
  9778. ts)
  9779. (org-with-remote-undo buffer
  9780. (with-current-buffer buffer
  9781. (widen)
  9782. (goto-char pos)
  9783. (setq ts (org-deadline arg time)))
  9784. (org-agenda-show-new-time marker ts " D"))
  9785. (message "%s" ts))))
  9786. (defun org-agenda-clock-in (&optional arg)
  9787. "Start the clock on the currently selected item."
  9788. (interactive "P")
  9789. (org-agenda-check-no-diary)
  9790. (if (equal arg '(4))
  9791. (org-clock-in arg)
  9792. (let* ((marker (or (org-get-at-bol 'org-marker)
  9793. (org-agenda-error)))
  9794. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  9795. (pos (marker-position marker))
  9796. (col (current-column))
  9797. newhead)
  9798. (org-with-remote-undo (marker-buffer marker)
  9799. (with-current-buffer (marker-buffer marker)
  9800. (widen)
  9801. (goto-char pos)
  9802. (org-fold-show-context 'agenda)
  9803. (org-clock-in arg)
  9804. (setq newhead (org-get-heading)))
  9805. (org-agenda-change-all-lines newhead hdmarker))
  9806. (org-move-to-column col))))
  9807. (defun org-agenda-clock-out ()
  9808. "Stop the currently running clock."
  9809. (interactive)
  9810. (unless (marker-buffer org-clock-marker)
  9811. (user-error "No running clock"))
  9812. (let ((marker (make-marker)) (col (current-column)) newhead)
  9813. (org-with-remote-undo (marker-buffer org-clock-marker)
  9814. (with-current-buffer (marker-buffer org-clock-marker)
  9815. (org-with-wide-buffer
  9816. (goto-char org-clock-marker)
  9817. (org-back-to-heading t)
  9818. (move-marker marker (point))
  9819. (org-clock-out)
  9820. (setq newhead (org-get-heading)))))
  9821. (org-agenda-change-all-lines newhead marker)
  9822. (move-marker marker nil)
  9823. (org-move-to-column col)
  9824. (org-agenda-unmark-clocking-task)))
  9825. (defun org-agenda-clock-cancel (&optional _arg)
  9826. "Cancel the currently running clock."
  9827. (interactive) ;; "P"
  9828. (unless (marker-buffer org-clock-marker)
  9829. (user-error "No running clock"))
  9830. (org-with-remote-undo (marker-buffer org-clock-marker)
  9831. (org-clock-cancel)))
  9832. (defun org-agenda-clock-goto ()
  9833. "Jump to the currently clocked in task within the agenda.
  9834. If the currently clocked in task is not listed in the agenda
  9835. buffer, display it in another window."
  9836. (interactive)
  9837. (let (pos)
  9838. (mapc (lambda (o)
  9839. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  9840. (setq pos (overlay-start o))))
  9841. (overlays-in (point-min) (point-max)))
  9842. (cond (pos (goto-char pos))
  9843. ;; If the currently clocked entry is not in the agenda
  9844. ;; buffer, we visit it in another window:
  9845. ((bound-and-true-p org-clock-current-task)
  9846. (org-switch-to-buffer-other-window (org-clock-goto)))
  9847. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  9848. (defun org-agenda-diary-entry-in-org-file ()
  9849. "Make a diary entry in the file `org-agenda-diary-file'."
  9850. (let (d1 d2 char (text "") dp1 dp2)
  9851. (if (equal (buffer-name) "*Calendar*")
  9852. (setq d1 (calendar-cursor-to-date t)
  9853. d2 (car calendar-mark-ring))
  9854. (setq dp1 (get-text-property (line-beginning-position) 'day))
  9855. (unless dp1 (user-error "No date defined in current line"))
  9856. (setq d1 (calendar-gregorian-from-absolute dp1)
  9857. d2 (and (ignore-errors (mark))
  9858. (save-excursion
  9859. (goto-char (mark))
  9860. (setq dp2 (get-text-property (line-beginning-position) 'day)))
  9861. (calendar-gregorian-from-absolute dp2))))
  9862. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  9863. (setq char (read-char-exclusive))
  9864. (cond
  9865. ((equal char ?d)
  9866. (setq text (read-string "Day entry: "))
  9867. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  9868. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9869. ((equal char ?a)
  9870. (setq d1 (list (car d1) (nth 1 d1)
  9871. (read-number (format "Reference year [%d]: " (nth 2 d1))
  9872. (nth 2 d1))))
  9873. (setq text (read-string "Anniversary (use %d to show years): "))
  9874. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  9875. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9876. ((equal char ?b)
  9877. (setq text (read-string "Block entry: "))
  9878. (unless (and d1 d2 (not (equal d1 d2)))
  9879. (user-error "No block of days selected"))
  9880. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  9881. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9882. ((equal char ?j)
  9883. (org-switch-to-buffer-other-window
  9884. (find-file-noselect org-agenda-diary-file))
  9885. (require 'org-datetree)
  9886. (org-datetree-find-date-create d1)
  9887. (org-fold-reveal t))
  9888. (t (user-error "Invalid selection character `%c'" char)))))
  9889. (defcustom org-agenda-insert-diary-strategy 'date-tree
  9890. "Where in `org-agenda-diary-file' should new entries be added?
  9891. Valid values:
  9892. date-tree in the date tree, as first child of the date
  9893. date-tree-last in the date tree, as last child of the date
  9894. top-level as top-level entries at the end of the file."
  9895. :group 'org-agenda
  9896. :type '(choice
  9897. (const :tag "first in a date tree" date-tree)
  9898. (const :tag "last in a date tree" date-tree-last)
  9899. (const :tag "as top level at end of file" top-level)))
  9900. (defcustom org-agenda-insert-diary-extract-time nil
  9901. "Non-nil means extract any time specification from the diary entry."
  9902. :group 'org-agenda
  9903. :version "24.1"
  9904. :type 'boolean)
  9905. (defcustom org-agenda-bulk-mark-char ">"
  9906. "A single-character string to be used as the bulk mark."
  9907. :group 'org-agenda
  9908. :version "24.1"
  9909. :type 'string)
  9910. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  9911. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  9912. If TEXT is not empty, it will become the headline of the new entry, and
  9913. the resulting entry will not be shown. When TEXT is empty, switch to
  9914. `org-agenda-diary-file' and let the user finish the entry there."
  9915. (let ((cw (current-window-configuration)))
  9916. (org-switch-to-buffer-other-window
  9917. (find-file-noselect org-agenda-diary-file))
  9918. (widen)
  9919. (goto-char (point-min))
  9920. (cl-case type
  9921. (anniversary
  9922. (or (re-search-forward "^\\*[ \t]+Anniversaries" nil t)
  9923. (progn
  9924. (or (org-at-heading-p)
  9925. (progn
  9926. (outline-next-heading)
  9927. (insert "* Anniversaries\n\n")
  9928. (beginning-of-line -1)))))
  9929. (outline-next-heading)
  9930. (org-back-over-empty-lines)
  9931. (backward-char 1)
  9932. (insert "\n")
  9933. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  9934. (nth 2 d1) (car d1) (nth 1 d1) text)))
  9935. (day
  9936. (let ((org-prefix-has-time t)
  9937. (org-agenda-time-leading-zero t)
  9938. fmt time time2)
  9939. (when org-agenda-insert-diary-extract-time
  9940. ;; Use org-agenda-format-item to parse text for a time-range and
  9941. ;; remove it. FIXME: This is a hack, we should refactor
  9942. ;; that function to make time extraction available separately
  9943. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  9944. time (get-text-property 0 'time fmt)
  9945. time2 (if (> (length time) 0)
  9946. ;; split-string removes trailing ...... if
  9947. ;; no end time given. First space
  9948. ;; separates time from date.
  9949. (concat " " (car (split-string time "\\.")))
  9950. nil)
  9951. text (get-text-property 0 'txt fmt)))
  9952. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9953. (org-agenda-insert-diary-as-top-level text)
  9954. (require 'org-datetree)
  9955. (org-datetree-find-date-create d1)
  9956. (org-agenda-insert-diary-make-new-entry text))
  9957. (org-insert-time-stamp (org-time-from-absolute
  9958. (calendar-absolute-from-gregorian d1))
  9959. nil nil nil nil time2))
  9960. (end-of-line 0))
  9961. ((block) ;; Wrap this in (strictly unnecessary) parens because
  9962. ;; otherwise the indentation gets confused by the
  9963. ;; special meaning of 'block
  9964. (when (> (calendar-absolute-from-gregorian d1)
  9965. (calendar-absolute-from-gregorian d2))
  9966. (setq d1 (prog1 d2 (setq d2 d1))))
  9967. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9968. (org-agenda-insert-diary-as-top-level text)
  9969. (require 'org-datetree)
  9970. (org-datetree-find-date-create d1)
  9971. (org-agenda-insert-diary-make-new-entry text))
  9972. (org-insert-time-stamp (org-time-from-absolute
  9973. (calendar-absolute-from-gregorian d1)))
  9974. (insert "--")
  9975. (org-insert-time-stamp (org-time-from-absolute
  9976. (calendar-absolute-from-gregorian d2)))
  9977. (end-of-line 0)))
  9978. (if (string-match "\\S-" text)
  9979. (progn
  9980. (set-window-configuration cw)
  9981. (message "%s entry added to %s"
  9982. (capitalize (symbol-name type))
  9983. (abbreviate-file-name org-agenda-diary-file)))
  9984. (org-fold-reveal t)
  9985. (message "Please finish entry here"))))
  9986. (defun org-agenda-insert-diary-as-top-level (text)
  9987. "Make new entry as a top-level entry at the end of the file.
  9988. Add TEXT as headline, and position the cursor in the second line so that
  9989. a timestamp can be added there."
  9990. (widen)
  9991. (goto-char (point-max))
  9992. (unless (bolp) (insert "\n"))
  9993. (org-insert-heading nil t t)
  9994. (insert text)
  9995. (org-end-of-meta-data)
  9996. (unless (bolp) (insert "\n"))
  9997. (when org-adapt-indentation (indent-to-column 2)))
  9998. (defun org-agenda-insert-diary-make-new-entry (text)
  9999. "Make a new entry with TEXT as a child of the current subtree.
  10000. Position the point in the heading's first body line so that
  10001. a timestamp can be added there."
  10002. (cond
  10003. ((eq org-agenda-insert-diary-strategy 'date-tree-last)
  10004. (end-of-line)
  10005. (org-insert-heading '(4) t)
  10006. (org-do-demote))
  10007. (t
  10008. (outline-next-heading)
  10009. (org-back-over-empty-lines)
  10010. (unless (looking-at "[ \t]*$") (save-excursion (insert "\n")))
  10011. (org-insert-heading nil t)
  10012. (org-do-demote)))
  10013. (let ((col (current-column)))
  10014. (insert text)
  10015. (org-end-of-meta-data)
  10016. ;; Ensure point is left on a blank line, at proper indentation.
  10017. (unless (bolp) (insert "\n"))
  10018. (unless (looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
  10019. (when org-adapt-indentation (indent-to-column col)))
  10020. (org-fold-show-set-visibility 'lineage))
  10021. (defun org-agenda-diary-entry ()
  10022. "Make a diary entry, like the `i' command from the calendar.
  10023. All the standard commands work: block, weekly etc.
  10024. When `org-agenda-diary-file' points to a file,
  10025. `org-agenda-diary-entry-in-org-file' is called instead to create
  10026. entries in that Org file."
  10027. (interactive)
  10028. (if (not (eq org-agenda-diary-file 'diary-file))
  10029. (org-agenda-diary-entry-in-org-file)
  10030. (require 'diary-lib)
  10031. (let* ((char (read-char-exclusive
  10032. "Diary entry: [d]ay [w]eekly [m]onthly [y]early\
  10033. [a]nniversary [b]lock [c]yclic"))
  10034. (cmd (cdr (assoc char
  10035. '((?d . diary-insert-entry)
  10036. (?w . diary-insert-weekly-entry)
  10037. (?m . diary-insert-monthly-entry)
  10038. (?y . diary-insert-yearly-entry)
  10039. (?a . diary-insert-anniversary-entry)
  10040. (?b . diary-insert-block-entry)
  10041. (?c . diary-insert-cyclic-entry)))))
  10042. (oldf (symbol-function 'calendar-cursor-to-date))
  10043. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  10044. (point (point))
  10045. (mark (or (mark t) (point))))
  10046. (unless cmd
  10047. (user-error "No command associated with <%c>" char))
  10048. (unless (and (get-text-property point 'day)
  10049. (or (not (equal ?b char))
  10050. (get-text-property mark 'day)))
  10051. (user-error "Don't know which date to use for diary entry"))
  10052. ;; We implement this by hacking the `calendar-cursor-to-date' function
  10053. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  10054. (let ((calendar-mark-ring
  10055. (list (calendar-gregorian-from-absolute
  10056. (or (get-text-property mark 'day)
  10057. (get-text-property point 'day))))))
  10058. (unwind-protect
  10059. (progn
  10060. (fset 'calendar-cursor-to-date
  10061. (lambda (&optional _error _dummy)
  10062. (calendar-gregorian-from-absolute
  10063. (get-text-property point 'day))))
  10064. (call-interactively cmd))
  10065. (fset 'calendar-cursor-to-date oldf))))))
  10066. (defun org-agenda-execute-calendar-command (cmd)
  10067. "Execute a calendar command from the agenda with date from cursor."
  10068. (org-agenda-check-type t 'agenda)
  10069. (require 'diary-lib)
  10070. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  10071. (user-error "Don't know which date to use for the calendar command"))
  10072. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  10073. (point (point))
  10074. (date (calendar-gregorian-from-absolute
  10075. (get-text-property point 'day))))
  10076. ;; the following 2 vars are needed in the calendar
  10077. (org-dlet
  10078. ((displayed-month (car date))
  10079. (displayed-year (nth 2 date)))
  10080. (unwind-protect
  10081. (progn
  10082. (fset 'calendar-cursor-to-date
  10083. (lambda (&optional _error _dummy)
  10084. (calendar-gregorian-from-absolute
  10085. (get-text-property point 'day))))
  10086. (call-interactively cmd))
  10087. (fset 'calendar-cursor-to-date oldf)))))
  10088. (defun org-agenda-phases-of-moon ()
  10089. "Display the phases of the moon for the 3 months around the cursor date."
  10090. (interactive)
  10091. (org-agenda-execute-calendar-command 'calendar-lunar-phases))
  10092. (defun org-agenda-holidays ()
  10093. "Display the holidays for the 3 months around the cursor date."
  10094. (interactive)
  10095. (org-agenda-execute-calendar-command 'calendar-list-holidays))
  10096. (defvar calendar-longitude) ; defined in calendar.el
  10097. (defvar calendar-latitude) ; defined in calendar.el
  10098. (defvar calendar-location-name) ; defined in calendar.el
  10099. (defun org-agenda-sunrise-sunset (arg)
  10100. "Display sunrise and sunset for the cursor date.
  10101. Latitude and longitude can be specified with the variables
  10102. `calendar-latitude' and `calendar-longitude'. When called with prefix
  10103. argument, latitude and longitude will be prompted for."
  10104. (interactive "P")
  10105. (require 'solar)
  10106. (let ((calendar-longitude (if arg nil calendar-longitude))
  10107. (calendar-latitude (if arg nil calendar-latitude))
  10108. (calendar-location-name
  10109. (if arg "the given coordinates" calendar-location-name)))
  10110. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  10111. (defun org-agenda-goto-calendar ()
  10112. "Open the Emacs calendar with the date at the cursor."
  10113. (interactive)
  10114. (org-agenda-check-type t 'agenda)
  10115. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  10116. (user-error "Don't know which date to open in calendar")))
  10117. (date (calendar-gregorian-from-absolute day))
  10118. (calendar-move-hook nil)
  10119. (calendar-view-holidays-initially-flag nil)
  10120. (calendar-view-diary-initially-flag nil))
  10121. (calendar)
  10122. (calendar-goto-date date)))
  10123. ;;;###autoload
  10124. (defun org-calendar-goto-agenda ()
  10125. "Compute the Org agenda for the calendar date displayed at the cursor.
  10126. This is a command that has to be installed in `calendar-mode-map'."
  10127. (interactive)
  10128. ;; Temporarily disable sticky agenda since user clearly wants to
  10129. ;; refresh view anyway.
  10130. (let ((org-agenda-buffer-tmp-name "*Org Agenda(a)*")
  10131. (org-agenda-sticky nil))
  10132. (org-agenda-list nil (calendar-absolute-from-gregorian
  10133. (calendar-cursor-to-date))
  10134. nil)))
  10135. (defun org-agenda-convert-date ()
  10136. (interactive)
  10137. (org-agenda-check-type t 'agenda)
  10138. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  10139. date s)
  10140. (unless day
  10141. (user-error "Don't know which date to convert"))
  10142. (setq date (calendar-gregorian-from-absolute day))
  10143. (setq s (concat
  10144. "Gregorian: " (calendar-date-string date) "\n"
  10145. "ISO: " (calendar-iso-date-string date) "\n"
  10146. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  10147. "Julian: " (calendar-julian-date-string date) "\n"
  10148. "Astron. JD: " (calendar-astro-date-string date)
  10149. " (Julian date number at noon UTC)\n"
  10150. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  10151. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  10152. "French: " (calendar-french-date-string date) "\n"
  10153. "Bahá’í: " (calendar-bahai-date-string date) " (until sunset)\n"
  10154. "Mayan: " (calendar-mayan-date-string date) "\n"
  10155. "Coptic: " (calendar-coptic-date-string date) "\n"
  10156. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  10157. "Persian: " (calendar-persian-date-string date) "\n"
  10158. "Chinese: " (calendar-chinese-date-string date) "\n"))
  10159. (with-output-to-temp-buffer "*Dates*"
  10160. (princ s))
  10161. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  10162. ;;; Bulk commands
  10163. (defun org-agenda-bulk-marked-p ()
  10164. "Non-nil when current entry is marked for bulk action."
  10165. (eq (get-char-property (line-beginning-position) 'type)
  10166. 'org-marked-entry-overlay))
  10167. (defun org-agenda-bulk-mark (&optional arg)
  10168. "Mark entries for future bulk action.
  10169. When ARG is nil or one and region is not active then mark the
  10170. entry at point.
  10171. When ARG is nil or one and region is active then mark the entries
  10172. in the region.
  10173. When ARG is greater than one mark ARG lines."
  10174. (interactive "p")
  10175. (when (and (or (not arg) (= arg 1)) (use-region-p))
  10176. (setq arg (count-lines (region-beginning) (region-end)))
  10177. (goto-char (region-beginning))
  10178. (deactivate-mark))
  10179. (dotimes (_ (or arg 1))
  10180. (unless (org-get-at-bol 'org-agenda-diary-link)
  10181. (let* ((m (org-get-at-bol 'org-hd-marker))
  10182. ov)
  10183. (unless (org-agenda-bulk-marked-p)
  10184. (unless m (user-error "Nothing to mark at point"))
  10185. (push m org-agenda-bulk-marked-entries)
  10186. (setq ov (make-overlay (line-beginning-position)
  10187. (+ 2 (line-beginning-position))))
  10188. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  10189. (org-get-todo-face "TODO")
  10190. 'evaporate)
  10191. (overlay-put ov 'type 'org-marked-entry-overlay))
  10192. (end-of-line 1)
  10193. (or (ignore-errors
  10194. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  10195. (beginning-of-line 2))
  10196. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  10197. (beginning-of-line 2)))))
  10198. (message "%d entries marked for bulk action"
  10199. (length org-agenda-bulk-marked-entries)))
  10200. (defun org-agenda-bulk-mark-all ()
  10201. "Mark all entries for future agenda bulk action."
  10202. (interactive)
  10203. (org-agenda-bulk-mark-regexp "."))
  10204. (defun org-agenda-bulk-mark-regexp (regexp)
  10205. "Mark entries matching REGEXP for future agenda bulk action."
  10206. (interactive "sMark entries matching regexp: ")
  10207. (let ((entries-marked 0) txt-at-point)
  10208. (save-excursion
  10209. (goto-char (point-min))
  10210. (goto-char (next-single-property-change (point) 'org-hd-marker))
  10211. (while (and (re-search-forward regexp nil t)
  10212. (setq txt-at-point
  10213. (get-text-property (match-beginning 0) 'txt)))
  10214. (if (get-char-property (point) 'invisible)
  10215. (beginning-of-line 2)
  10216. (when (string-match-p regexp txt-at-point)
  10217. (setq entries-marked (1+ entries-marked))
  10218. (call-interactively 'org-agenda-bulk-mark)))))
  10219. (unless entries-marked
  10220. (message "No entry matching this regexp."))))
  10221. (defun org-agenda-bulk-unmark (&optional arg)
  10222. "Unmark the entry at point for future bulk action."
  10223. (interactive "P")
  10224. (if arg
  10225. (org-agenda-bulk-unmark-all)
  10226. (cond ((org-agenda-bulk-marked-p)
  10227. (org-agenda-bulk-remove-overlays
  10228. (line-beginning-position) (+ 2 (line-beginning-position)))
  10229. (setq org-agenda-bulk-marked-entries
  10230. (delete (org-get-at-bol 'org-hd-marker)
  10231. org-agenda-bulk-marked-entries))
  10232. (end-of-line 1)
  10233. (or (ignore-errors
  10234. (goto-char (next-single-property-change (point) 'txt)))
  10235. (beginning-of-line 2))
  10236. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  10237. (beginning-of-line 2))
  10238. (message "%d entries left marked for bulk action"
  10239. (length org-agenda-bulk-marked-entries)))
  10240. (t (message "No entry to unmark here")))))
  10241. (defun org-agenda-bulk-toggle-all ()
  10242. "Toggle all marks for bulk action."
  10243. (interactive)
  10244. (save-excursion
  10245. (goto-char (point-min))
  10246. (while (ignore-errors
  10247. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  10248. (org-agenda-bulk-toggle))))
  10249. (defun org-agenda-bulk-toggle ()
  10250. "Toggle the mark at point for bulk action."
  10251. (interactive)
  10252. (if (org-agenda-bulk-marked-p)
  10253. (org-agenda-bulk-unmark)
  10254. (org-agenda-bulk-mark)))
  10255. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  10256. "Remove the mark overlays between BEG and END in the agenda buffer.
  10257. BEG and END default to the buffer limits.
  10258. This only removes the overlays, it does not remove the markers
  10259. from the list in `org-agenda-bulk-marked-entries'."
  10260. (interactive)
  10261. (mapc (lambda (ov)
  10262. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  10263. (delete-overlay ov)))
  10264. (overlays-in (or beg (point-min)) (or end (point-max)))))
  10265. (defun org-agenda-bulk-unmark-all ()
  10266. "Remove all marks in the agenda buffer.
  10267. This will remove the markers and the overlays."
  10268. (interactive)
  10269. (if (null org-agenda-bulk-marked-entries)
  10270. (message "No entry to unmark")
  10271. (setq org-agenda-bulk-marked-entries nil)
  10272. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  10273. (defcustom org-agenda-persistent-marks nil
  10274. "Non-nil means marked items will stay marked after a bulk action.
  10275. You can toggle this interactively by typing `p' when prompted for a
  10276. bulk action."
  10277. :group 'org-agenda
  10278. :version "24.1"
  10279. :type 'boolean)
  10280. (defcustom org-agenda-loop-over-headlines-in-active-region t
  10281. "Shall some commands act upon headlines in the active region?
  10282. When set to t, some commands will be performed in all headlines
  10283. within the active region.
  10284. When set to `start-level', some commands will be performed in all
  10285. headlines within the active region, provided that these headlines
  10286. are of the same level than the first one.
  10287. When set to a regular expression, those commands will be
  10288. performed on the matching headlines within the active region.
  10289. The list of commands is: `org-agenda-schedule',
  10290. `org-agenda-deadline', `org-agenda-date-prompt',
  10291. `org-agenda-todo', `org-agenda-archive*', `org-agenda-kill'.
  10292. See `org-loop-over-headlines-in-active-region' for the equivalent
  10293. option for Org buffers."
  10294. :type '(choice (const :tag "Don't loop" nil)
  10295. (const :tag "All headlines in active region" t)
  10296. (const :tag "In active region, headlines at the same level than the first one" start-level)
  10297. (regexp :tag "Regular expression matcher"))
  10298. :version "27.1"
  10299. :package-version '(Org . "9.4")
  10300. :group 'org-agenda)
  10301. (defun org-agenda-bulk-action (&optional arg)
  10302. "Execute an remote-editing action on all marked entries.
  10303. The prefix arg is passed through to the command if possible."
  10304. (interactive "P")
  10305. ;; When there is no mark, act on the agenda entry at point.
  10306. (if (not org-agenda-bulk-marked-entries)
  10307. (save-excursion (org-agenda-bulk-mark)))
  10308. (dolist (m org-agenda-bulk-marked-entries)
  10309. (unless (and (markerp m)
  10310. (marker-buffer m)
  10311. (buffer-live-p (marker-buffer m))
  10312. (marker-position m))
  10313. (user-error "Marker %s for bulk command is invalid" m)))
  10314. ;; Prompt for the bulk command.
  10315. (org-unlogged-message
  10316. (concat "Bulk (" (if org-agenda-persistent-marks "" "don't ") "[p]ersist marks): "
  10317. "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  10318. "[S]catter [f]unction "
  10319. (and org-agenda-bulk-custom-functions
  10320. (format " Custom: [%s]"
  10321. (mapconcat (lambda (f) (char-to-string (car f)))
  10322. org-agenda-bulk-custom-functions
  10323. "")))))
  10324. (catch 'exit
  10325. (let* ((org-log-refile (if org-log-refile 'time nil))
  10326. (entries (reverse org-agenda-bulk-marked-entries))
  10327. (org-overriding-default-time
  10328. (and (get-text-property (point) 'org-agenda-date-header)
  10329. (org-get-cursor-date)))
  10330. redo-at-end
  10331. cmd)
  10332. (pcase (read-char-exclusive)
  10333. (?p
  10334. (let ((org-agenda-persistent-marks
  10335. (not org-agenda-persistent-marks)))
  10336. (org-agenda-bulk-action)
  10337. (throw 'exit nil)))
  10338. (?$
  10339. (setq cmd #'org-agenda-archive))
  10340. (?A
  10341. (setq cmd #'org-agenda-archive-to-archive-sibling))
  10342. ((or ?r ?w)
  10343. (let ((refile-location
  10344. (org-refile-get-location
  10345. "Refile to"
  10346. (marker-buffer (car entries))
  10347. org-refile-allow-creating-parent-nodes)))
  10348. (when (nth 3 refile-location)
  10349. (setcar (nthcdr 3 refile-location)
  10350. (move-marker
  10351. (make-marker)
  10352. (nth 3 refile-location)
  10353. (or (get-file-buffer (nth 1 refile-location))
  10354. (find-buffer-visiting (nth 1 refile-location))
  10355. (error "This should not happen")))))
  10356. (setq cmd (lambda () (org-agenda-refile nil refile-location t)))
  10357. (setq redo-at-end t)))
  10358. (?t
  10359. (let ((state (completing-read
  10360. "Todo state: "
  10361. (with-current-buffer (marker-buffer (car entries))
  10362. (mapcar #'list org-todo-keywords-1)))))
  10363. (setq cmd (lambda ()
  10364. (let ((org-inhibit-blocking t)
  10365. (org-inhibit-logging 'note))
  10366. (org-agenda-todo state))))))
  10367. ((and (or ?- ?+) action)
  10368. (let ((tag (completing-read
  10369. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  10370. (with-current-buffer (marker-buffer (car entries))
  10371. (delq nil
  10372. (mapcar (lambda (x) (and (stringp (car x)) x))
  10373. org-current-tag-alist))))))
  10374. (setq cmd
  10375. (lambda ()
  10376. (org-agenda-set-tags tag
  10377. (if (eq action ?+) 'on 'off))))))
  10378. ((and (or ?s ?d) c)
  10379. (let* ((schedule? (eq c ?s))
  10380. (prompt (if schedule? "(Re)Schedule to" "(Re)Set Deadline to"))
  10381. (time
  10382. (and (not arg)
  10383. (let ((new (org-read-date
  10384. nil nil nil prompt org-overriding-default-time)))
  10385. ;; A "double plus" answer applies to every
  10386. ;; scheduled time. Do not turn it into
  10387. ;; a fixed date yet.
  10388. (if (string-match-p "\\`[ \t]*\\+\\+"
  10389. org-read-date-final-answer)
  10390. org-read-date-final-answer
  10391. new)))))
  10392. ;; Make sure to not prompt for a note when bulk
  10393. ;; rescheduling/resetting deadline as Org cannot cope with
  10394. ;; simultaneous notes. Besides, it could be annoying
  10395. ;; depending on the number of marked items.
  10396. (setq cmd
  10397. (if schedule?
  10398. (lambda ()
  10399. (let ((org-log-reschedule
  10400. (and org-log-reschedule 'time)))
  10401. (org-agenda-schedule arg time)))
  10402. (lambda ()
  10403. (let ((org-log-redeadline (and org-log-redeadline 'time)))
  10404. (org-agenda-deadline arg time)))))))
  10405. (?S
  10406. (unless (org-agenda-check-type nil 'agenda 'todo)
  10407. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type))
  10408. (let ((days (read-number
  10409. (format "Scatter tasks across how many %sdays: "
  10410. (if arg "week" ""))
  10411. 7)))
  10412. (setq cmd
  10413. (lambda ()
  10414. (let ((distance (1+ (random days))))
  10415. (when arg
  10416. (let ((dist distance)
  10417. (day-of-week
  10418. (calendar-day-of-week
  10419. (calendar-gregorian-from-absolute (org-today)))))
  10420. (dotimes (_ (1+ dist))
  10421. (while (member day-of-week org-agenda-weekend-days)
  10422. (cl-incf distance)
  10423. (cl-incf day-of-week)
  10424. (when (= day-of-week 7)
  10425. (setq day-of-week 0)))
  10426. (cl-incf day-of-week)
  10427. (when (= day-of-week 7)
  10428. (setq day-of-week 0)))))
  10429. ;; Silently fail when try to replan a sexp entry.
  10430. (ignore-errors
  10431. (let* ((date (calendar-gregorian-from-absolute
  10432. (+ (org-today) distance)))
  10433. (time (org-encode-time
  10434. 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  10435. (org-agenda-schedule nil time))))))))
  10436. (?f
  10437. (setq cmd
  10438. (intern
  10439. (completing-read "Function: " obarray #'fboundp t nil nil))))
  10440. (action
  10441. (setq cmd
  10442. (pcase (assoc action org-agenda-bulk-custom-functions)
  10443. (`(,_ ,fn)
  10444. fn)
  10445. (`(,_ ,fn ,arg-fn)
  10446. (apply #'apply-partially fn (funcall arg-fn)))
  10447. (_
  10448. (user-error "Invalid bulk action: %c" action))))
  10449. (setq redo-at-end t)))
  10450. ;; Sort the markers, to make sure that parents are handled
  10451. ;; before children.
  10452. (setq entries (sort entries
  10453. (lambda (a b)
  10454. (cond
  10455. ((eq (marker-buffer a) (marker-buffer b))
  10456. (< (marker-position a) (marker-position b)))
  10457. (t
  10458. (string< (buffer-name (marker-buffer a))
  10459. (buffer-name (marker-buffer b))))))))
  10460. ;; Now loop over all markers and apply CMD.
  10461. (let ((processed 0)
  10462. (skipped 0))
  10463. (dolist (e entries)
  10464. (let ((pos (text-property-any (point-min) (point-max) 'org-hd-marker e)))
  10465. (if (not pos)
  10466. (progn (message "Skipping removed entry at %s" e)
  10467. (cl-incf skipped))
  10468. (goto-char pos)
  10469. (let (org-loop-over-headlines-in-active-region) (funcall cmd))
  10470. ;; `post-command-hook' is not run yet. We make sure any
  10471. ;; pending log note is processed.
  10472. (when org-log-setup (org-add-log-note))
  10473. (cl-incf processed))))
  10474. (when redo-at-end (org-agenda-redo))
  10475. (unless org-agenda-persistent-marks (org-agenda-bulk-unmark-all))
  10476. (message "Acted on %d entries%s%s"
  10477. processed
  10478. (if (= skipped 0)
  10479. ""
  10480. (format ", skipped %d (disappeared before their turn)"
  10481. skipped))
  10482. (if (not org-agenda-persistent-marks) "" " (kept marked)"))))))
  10483. (defun org-agenda-capture (&optional with-time)
  10484. "Call `org-capture' with the date at point.
  10485. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  10486. current HH:MM time."
  10487. (interactive "P")
  10488. (if (not (eq major-mode 'org-agenda-mode))
  10489. (user-error "You cannot do this outside of agenda buffers")
  10490. (let ((org-overriding-default-time
  10491. (org-get-cursor-date (equal with-time 1))))
  10492. (call-interactively 'org-capture))))
  10493. ;;; Dragging agenda lines forward/backward
  10494. (defun org-agenda-reapply-filters ()
  10495. "Re-apply all agenda filters."
  10496. (mapcar
  10497. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f) t)))
  10498. `((,org-agenda-tag-filter tag)
  10499. (,org-agenda-category-filter category)
  10500. (,org-agenda-regexp-filter regexp)
  10501. (,org-agenda-effort-filter effort)
  10502. (,(assoc-default 'tag org-agenda-filters-preset) tag)
  10503. (,(assoc-default 'category org-agenda-filters-preset) category)
  10504. (,(assoc-default 'effort org-agenda-filters-preset) effort)
  10505. (,(assoc-default 'regexp org-agenda-filters-preset) regexp))))
  10506. (defun org-agenda-drag-line-forward (arg &optional backward)
  10507. "Drag an agenda line forward by ARG lines.
  10508. When the optional argument `backward' is non-nil, move backward."
  10509. (interactive "p")
  10510. (let ((inhibit-read-only t) lst line)
  10511. (if (or (not (get-text-property (point) 'txt))
  10512. (save-excursion
  10513. (dotimes (_ arg)
  10514. (move-beginning-of-line (if backward 0 2))
  10515. (push (not (get-text-property (point) 'txt)) lst))
  10516. (delq nil lst)))
  10517. (message "Cannot move line forward")
  10518. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  10519. (move-beginning-of-line 1)
  10520. (setq line (buffer-substring (point) end))
  10521. (delete-region (point) end)
  10522. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  10523. (insert line)
  10524. (org-agenda-reapply-filters)
  10525. (org-agenda-mark-clocking-task)
  10526. (move-beginning-of-line 0)))))
  10527. (defun org-agenda-drag-line-backward (arg)
  10528. "Drag an agenda line backward by ARG lines."
  10529. (interactive "p")
  10530. (org-agenda-drag-line-forward arg t))
  10531. ;;; Flagging notes
  10532. (defun org-agenda-show-the-flagging-note ()
  10533. "Display the flagging note in the other window.
  10534. When called a second time in direct sequence, offer to remove the FLAGGING
  10535. tag and (if present) the flagging note."
  10536. (interactive)
  10537. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  10538. (win (selected-window))
  10539. note) ;; heading newhead
  10540. (unless hdmarker
  10541. (user-error "No linked entry at point"))
  10542. (if (and (eq this-command last-command)
  10543. (y-or-n-p "Unflag and remove any flagging note? "))
  10544. (progn
  10545. (org-agenda-remove-flag hdmarker)
  10546. (let ((win (get-buffer-window "*Flagging Note*")))
  10547. (and win (delete-window win)))
  10548. (message "Entry unflagged"))
  10549. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  10550. (unless note
  10551. (user-error "No flagging note"))
  10552. (org-kill-new note)
  10553. (org-switch-to-buffer-other-window "*Flagging Note*")
  10554. (erase-buffer)
  10555. (insert note)
  10556. (goto-char (point-min))
  10557. (while (re-search-forward "\\\\n" nil t)
  10558. (replace-match "\n" t t))
  10559. (goto-char (point-min))
  10560. (select-window win)
  10561. (message "%s" (substitute-command-keys "Flagging note pushed to \
  10562. kill ring. Press `\\[org-agenda-show-the-flagging-note]' again to remove \
  10563. tag and note")))))
  10564. (defun org-agenda-remove-flag (marker)
  10565. "Remove the FLAGGED tag and any flagging note in the entry."
  10566. (let ((newhead
  10567. (org-with-point-at marker
  10568. (org-toggle-tag "FLAGGED" 'off)
  10569. (org-entry-delete nil "THEFLAGGINGNOTE")
  10570. (org-get-heading))))
  10571. (org-agenda-change-all-lines newhead marker)
  10572. (message "Entry unflagged")))
  10573. (defun org-agenda-get-any-marker (&optional pos)
  10574. (or (get-text-property (or pos (line-beginning-position)) 'org-hd-marker)
  10575. (get-text-property (or pos (line-beginning-position)) 'org-marker)))
  10576. ;;; Appointment reminders
  10577. (defvar appt-time-msg-list) ; defined in appt.el
  10578. ;;;###autoload
  10579. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  10580. "Activate appointments found in `org-agenda-files'.
  10581. With a `\\[universal-argument]' prefix, refresh the list of \
  10582. appointments.
  10583. If FILTER is t, interactively prompt the user for a regular
  10584. expression, and filter out entries that don't match it.
  10585. If FILTER is a string, use this string as a regular expression
  10586. for filtering entries out.
  10587. If FILTER is a function, filter out entries against which
  10588. calling the function returns nil. This function takes one
  10589. argument: an entry from `org-agenda-get-day-entries'.
  10590. FILTER can also be an alist with the car of each cell being
  10591. either `headline' or `category'. For example:
  10592. ((headline \"IMPORTANT\")
  10593. (category \"Work\"))
  10594. will only add headlines containing IMPORTANT or headlines
  10595. belonging to the \"Work\" category.
  10596. ARGS are symbols indicating what kind of entries to consider.
  10597. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  10598. \(i.e., deadlines and scheduled items with a hh:mm specification)
  10599. and :timestamp entries. See the docstring of `org-diary' for
  10600. details and examples.
  10601. If an entry has a APPT_WARNTIME property, its value will be used
  10602. to override `appt-message-warning-time'."
  10603. (interactive "P")
  10604. (when refresh (setq appt-time-msg-list nil))
  10605. (when (eq filter t)
  10606. (setq filter (read-from-minibuffer "Regexp filter: ")))
  10607. (let* ((cnt 0) ; count added events
  10608. (scope (or args '(:deadline* :scheduled* :timestamp)))
  10609. (org-agenda-new-buffers nil)
  10610. (org-deadline-warning-days 0)
  10611. ;; Do not use `org-today' here because appt only takes
  10612. ;; time and without date as argument, so it may pass wrong
  10613. ;; information otherwise
  10614. (today (org-date-to-gregorian
  10615. (time-to-days nil)))
  10616. (org-agenda-restrict nil)
  10617. (files (org-agenda-files 'unrestricted)) entries file
  10618. (org-agenda-buffer nil))
  10619. ;; Get all entries which may contain an appt
  10620. (org-agenda-prepare-buffers files)
  10621. (while (setq file (pop files))
  10622. (setq entries
  10623. (delq nil
  10624. (append entries
  10625. (apply #'org-agenda-get-day-entries
  10626. file today scope)))))
  10627. ;; Map through entries and find if we should filter them out
  10628. (mapc
  10629. (lambda (x)
  10630. (let* ((evt (org-trim
  10631. (replace-regexp-in-string
  10632. org-link-bracket-re "\\2"
  10633. (or (get-text-property 1 'txt x) ""))))
  10634. (cat (get-text-property (1- (length x)) 'org-category x))
  10635. (tod (get-text-property 1 'time-of-day x))
  10636. (ok (or (null filter)
  10637. (and (stringp filter) (string-match filter evt))
  10638. (and (functionp filter) (funcall filter x))
  10639. (and (listp filter)
  10640. (let ((cat-filter (cadr (assq 'category filter)))
  10641. (evt-filter (cadr (assq 'headline filter))))
  10642. (or (and (stringp cat-filter)
  10643. (string-match cat-filter cat))
  10644. (and (stringp evt-filter)
  10645. (string-match evt-filter evt)))))))
  10646. (wrn (get-text-property 1 'warntime x)))
  10647. ;; FIXME: Shall we remove text-properties for the appt text?
  10648. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  10649. (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
  10650. (setq tod (concat "00" (number-to-string tod)))
  10651. (setq tod (when (string-match
  10652. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  10653. (concat (match-string 1 tod) ":"
  10654. (match-string 2 tod))))
  10655. (when (appt-add tod evt wrn)
  10656. (setq cnt (1+ cnt))))))
  10657. entries)
  10658. (org-release-buffers org-agenda-new-buffers)
  10659. (if (eq cnt 0)
  10660. (message "No event to add")
  10661. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  10662. (defun org-agenda-today-p (date)
  10663. "Non-nil when DATE means today.
  10664. DATE is either a list of the form (month day year) or a number of
  10665. days as returned by `calendar-absolute-from-gregorian' or
  10666. `org-today'. This function considers `org-extend-today-until'
  10667. when defining today."
  10668. (eq (org-today)
  10669. (if (consp date) (calendar-absolute-from-gregorian date) date)))
  10670. (defun org-agenda-todo-yesterday (&optional arg)
  10671. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  10672. (interactive "P")
  10673. (let* ((org-use-effective-time t)
  10674. (hour (nth 2 (decode-time (org-current-time))))
  10675. (org-extend-today-until (1+ hour)))
  10676. (org-agenda-todo arg)))
  10677. (defun org-agenda-ctrl-c-ctrl-c ()
  10678. "Set tags in agenda buffer."
  10679. (interactive)
  10680. (org-agenda-set-tags))
  10681. (provide 'org-agenda)
  10682. ;;; org-agenda.el ends here