org-agenda.el 421 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2004-2021 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten.dominik@gmail.com>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: 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 'cl-lib)
  42. (require 'ol)
  43. (require 'org)
  44. (require 'org-macs)
  45. (require 'org-refile)
  46. (declare-function diary-add-to-list "diary-lib"
  47. (date string specifier &optional marker globcolor literal))
  48. (declare-function calendar-iso-to-absolute "cal-iso" (date))
  49. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  50. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  51. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  52. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  53. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  54. (declare-function calendar-french-date-string "cal-french" (&optional date))
  55. (declare-function calendar-goto-date "cal-move" (date))
  56. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  57. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  58. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  59. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  60. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  61. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  62. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  63. (declare-function calendar-check-holidays "holidays" (date))
  64. (declare-function org-columns-remove-overlays "org-colview" ())
  65. (declare-function org-datetree-find-date-create "org-datetree"
  66. (date &optional keep-restriction))
  67. (declare-function org-columns-quit "org-colview" ())
  68. (declare-function diary-date-display-form "diary-lib" (&optional type))
  69. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  70. (declare-function org-habit-insert-consistency-graphs
  71. "org-habit" (&optional line))
  72. (declare-function org-is-habit-p "org-habit" (&optional pom))
  73. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  74. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  75. (declare-function org-agenda-columns "org-colview" ())
  76. (declare-function org-add-archive-files "org-archive" (files))
  77. (declare-function org-capture "org-capture" (&optional goto keys))
  78. (declare-function org-clock-modify-effort-estimate "org-clock" (&optional value))
  79. (defvar calendar-mode-map)
  80. (defvar org-clock-current-task)
  81. (defvar org-current-tag-alist)
  82. (defvar org-mobile-force-id-on-agenda-items)
  83. (defvar org-habit-show-habits)
  84. (defvar org-habit-show-habits-only-for-today)
  85. (defvar org-habit-show-all-today)
  86. (defvar org-habit-scheduled-past-days)
  87. ;; Defined somewhere in this file, but used before definition.
  88. (defvar org-agenda-buffer-name "*Org Agenda*")
  89. (defvar org-agenda-overriding-header nil)
  90. (defvar org-agenda-title-append nil)
  91. ;; (with-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  92. ;; (with-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  93. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  94. (defvar org-agenda-undo-list nil
  95. "List of undoable operations in the agenda since last refresh.")
  96. (defvar org-agenda-pending-undo-list nil
  97. "In a series of undo commands, this is the list of remaining undo items.")
  98. (defcustom org-agenda-confirm-kill 1
  99. "When set, remote killing from the agenda buffer needs confirmation.
  100. When t, a confirmation is always needed. When a number N, confirmation is
  101. only needed when the text to be killed contains more than N non-white lines."
  102. :group 'org-agenda
  103. :type '(choice
  104. (const :tag "Never" nil)
  105. (const :tag "Always" t)
  106. (integer :tag "When more than N lines")))
  107. (defcustom org-agenda-compact-blocks nil
  108. "Non-nil means make the block agenda more compact.
  109. This is done globally by leaving out lines like the agenda span
  110. name and week number or the separator lines."
  111. :group 'org-agenda
  112. :type 'boolean)
  113. (defcustom org-agenda-block-separator ?=
  114. "The separator between blocks in the agenda.
  115. If this is a string, it will be used as the separator, with a newline added.
  116. If it is a character, it will be repeated to fill the window width.
  117. If nil the separator is disabled. In `org-agenda-custom-commands' this
  118. addresses the separator between the current and the previous block."
  119. :group 'org-agenda
  120. :type '(choice
  121. (const :tag "Disabled" nil)
  122. (character)
  123. (string)))
  124. (defgroup org-agenda-export nil
  125. "Options concerning exporting agenda views in Org mode."
  126. :tag "Org Agenda Export"
  127. :group 'org-agenda)
  128. (defcustom org-agenda-with-colors t
  129. "Non-nil means use colors in agenda views."
  130. :group 'org-agenda-export
  131. :type 'boolean)
  132. (defcustom org-agenda-exporter-settings nil
  133. ;; FIXME: Do we really want to evaluate those settings and thus force
  134. ;; the user to use `quote' all the time?
  135. "Alist of variable/value pairs that should be active during agenda export.
  136. This is a good place to set options for ps-print and for htmlize.
  137. Note that the way this is implemented, the values will be evaluated
  138. before assigned to the variables. So make sure to quote values you do
  139. *not* want evaluated, for example
  140. (setq org-agenda-exporter-settings
  141. \\='((ps-print-color-p \\='black-white)))"
  142. :group 'org-agenda-export
  143. :type '(repeat
  144. (list
  145. (variable)
  146. (sexp :tag "Value"))))
  147. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  148. "Hook run in a temporary buffer before writing the agenda to an export file.
  149. A useful function for this hook is `org-agenda-add-entry-text'."
  150. :group 'org-agenda-export
  151. :type 'hook
  152. :options '(org-agenda-add-entry-text))
  153. (defcustom org-agenda-add-entry-text-maxlines 0
  154. "Maximum number of entry text lines to be added to agenda.
  155. This is only relevant when `org-agenda-add-entry-text' is part of
  156. `org-agenda-before-write-hook', which is the default.
  157. When this is 0, nothing will happen. When it is greater than 0, it
  158. specifies the maximum number of lines that will be added for each entry
  159. that is listed in the agenda view.
  160. Note that this variable is not used during display, only when exporting
  161. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  162. and `org-agenda-entry-text-maxlines'."
  163. :group 'org-agenda
  164. :type 'integer)
  165. (defcustom org-agenda-add-entry-text-descriptive-links t
  166. "Non-nil means export org-links as descriptive links in agenda added text.
  167. This variable applies to the text added to the agenda when
  168. `org-agenda-add-entry-text-maxlines' is larger than 0.
  169. When this variable is nil, the URL will (also) be shown."
  170. :group 'org-agenda
  171. :type 'boolean)
  172. (defcustom org-agenda-export-html-style nil
  173. "The style specification for exported HTML Agenda files.
  174. If this variable contains a string, it will replace the default <style>
  175. section as produced by `htmlize'.
  176. Since there are different ways of setting style information, this variable
  177. needs to contain the full HTML structure to provide a style, including the
  178. surrounding HTML tags. The style specifications should include definitions
  179. the fonts used by the agenda, here is an example:
  180. <style type=\"text/css\">
  181. p { font-weight: normal; color: gray; }
  182. .org-agenda-structure {
  183. font-size: 110%;
  184. color: #003399;
  185. font-weight: 600;
  186. }
  187. .org-todo {
  188. color: #cc6666;
  189. font-weight: bold;
  190. }
  191. .org-agenda-done {
  192. color: #339933;
  193. }
  194. .org-done {
  195. color: #339933;
  196. }
  197. .title { text-align: center; }
  198. .todo, .deadline { color: red; }
  199. .done { color: green; }
  200. </style>
  201. or, if you want to keep the style in a file,
  202. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  203. As the value of this option simply gets inserted into the HTML <head> header,
  204. you can \"misuse\" it to also add other text to the header."
  205. :group 'org-agenda-export
  206. :group 'org-export-html
  207. :type '(choice
  208. (const nil)
  209. (string)))
  210. (defcustom org-agenda-persistent-filter nil
  211. "When set, keep filters from one agenda view to the next."
  212. :group 'org-agenda
  213. :type 'boolean)
  214. (defgroup org-agenda-custom-commands nil
  215. "Options concerning agenda views in Org mode."
  216. :tag "Org Agenda Custom Commands"
  217. :group 'org-agenda)
  218. (defconst org-sorting-choice
  219. '(choice
  220. (const time-up) (const time-down)
  221. (const timestamp-up) (const timestamp-down)
  222. (const scheduled-up) (const scheduled-down)
  223. (const deadline-up) (const deadline-down)
  224. (const ts-up) (const ts-down)
  225. (const tsia-up) (const tsia-down)
  226. (const category-keep) (const category-up) (const category-down)
  227. (const tag-down) (const tag-up)
  228. (const priority-up) (const priority-down)
  229. (const todo-state-up) (const todo-state-down)
  230. (const effort-up) (const effort-down)
  231. (const habit-up) (const habit-down)
  232. (const alpha-up) (const alpha-down)
  233. (const user-defined-up) (const user-defined-down))
  234. "Sorting choices.")
  235. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  236. ;; the new variable `org-agenda-tag-filter-preset'.
  237. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  238. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  239. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  240. "List of types searched for when creating the daily/weekly agenda.
  241. This variable is a list of symbols that controls the types of
  242. items that appear in the daily/weekly agenda. Allowed symbols in this
  243. list are
  244. :timestamp List items containing a date stamp or date range matching
  245. the selected date. This includes sexp entries in angular
  246. brackets.
  247. :sexp List entries resulting from plain diary-like sexps.
  248. :deadline List deadline due on that date. When the date is today,
  249. also list any deadlines past due, or due within
  250. `org-deadline-warning-days'.
  251. :deadline* Same as above, but only include the deadline if it has an
  252. hour specification as [h]h:mm.
  253. :scheduled List all items which are scheduled for the given date.
  254. The diary for *today* also contains items which were
  255. scheduled earlier and are not yet marked DONE.
  256. :scheduled* Same as above, but only include the scheduled item if it
  257. has an hour specification as [h]h:mm.
  258. By default, all four non-starred types are turned on.
  259. When :scheduled* or :deadline* are included, :schedule or :deadline
  260. will be ignored.
  261. Never set this variable globally using `setq', because then it
  262. will apply to all future agenda commands. Instead, bind it with
  263. `let' to scope it dynamically into the agenda-constructing
  264. command. A good way to set it is through options in
  265. `org-agenda-custom-commands'. For a more flexible (though
  266. somewhat less efficient) way of determining what is included in
  267. the daily/weekly agenda, see `org-agenda-skip-function'.")
  268. (defconst org-agenda-custom-commands-local-options
  269. `(repeat :tag "Local settings for this command. Remember to quote values"
  270. (choice :tag "Setting"
  271. (list :tag "Heading for this block"
  272. (const org-agenda-overriding-header)
  273. (string :tag "Headline"))
  274. (list :tag "Files to be searched"
  275. (const org-agenda-files)
  276. (list
  277. (const :format "" quote)
  278. (repeat (file))))
  279. (list :tag "Sorting strategy"
  280. (const org-agenda-sorting-strategy)
  281. (list
  282. (const :format "" quote)
  283. (repeat
  284. ,org-sorting-choice)))
  285. (list :tag "Prefix format"
  286. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  287. (string))
  288. (list :tag "Number of days in agenda"
  289. (const org-agenda-span)
  290. (list
  291. (const :format "" quote)
  292. (choice (const :tag "Day" day)
  293. (const :tag "Week" week)
  294. (const :tag "Fortnight" fortnight)
  295. (const :tag "Month" month)
  296. (const :tag "Year" year)
  297. (integer :tag "Custom"))))
  298. (list :tag "Fixed starting date"
  299. (const org-agenda-start-day)
  300. (string :value "2007-11-01"))
  301. (list :tag "Start on day of week"
  302. (const org-agenda-start-on-weekday)
  303. (choice :value 1
  304. (const :tag "Today" nil)
  305. (integer :tag "Weekday No.")))
  306. (list :tag "Include data from diary"
  307. (const org-agenda-include-diary)
  308. (boolean))
  309. (list :tag "Deadline Warning days"
  310. (const org-deadline-warning-days)
  311. (integer :value 1))
  312. (list :tag "Category filter preset"
  313. (const org-agenda-category-filter-preset)
  314. (list
  315. (const :format "" quote)
  316. (repeat
  317. (string :tag "+category or -category"))))
  318. (list :tag "Tags filter preset"
  319. (const org-agenda-tag-filter-preset)
  320. (list
  321. (const :format "" quote)
  322. (repeat
  323. (string :tag "+tag or -tag"))))
  324. (list :tag "Effort filter preset"
  325. (const org-agenda-effort-filter-preset)
  326. (list
  327. (const :format "" quote)
  328. (repeat
  329. (string :tag "+=10 or -=10 or +<10 or ->10"))))
  330. (list :tag "Regexp filter preset"
  331. (const org-agenda-regexp-filter-preset)
  332. (list
  333. (const :format "" quote)
  334. (repeat
  335. (string :tag "+regexp or -regexp"))))
  336. (list :tag "Set daily/weekly entry types"
  337. (const org-agenda-entry-types)
  338. (list
  339. (const :format "" quote)
  340. (set :greedy t :value ,org-agenda-entry-types
  341. (const :deadline)
  342. (const :scheduled)
  343. (const :deadline*)
  344. (const :scheduled*)
  345. (const :timestamp)
  346. (const :sexp))))
  347. (list :tag "Columns format"
  348. (const org-overriding-columns-format)
  349. (string :tag "Format"))
  350. (list :tag "Standard skipping condition"
  351. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  352. (const org-agenda-skip-function)
  353. (list
  354. (const :format "" quote)
  355. (list
  356. (choice
  357. :tag "Skipping range"
  358. (const :tag "Skip entry" org-agenda-skip-entry-if)
  359. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  360. (repeat :inline t :tag "Conditions for skipping"
  361. (choice
  362. :tag "Condition type"
  363. (list :tag "Regexp matches" :inline t
  364. (const :format "" regexp)
  365. (regexp))
  366. (list :tag "Regexp does not match" :inline t
  367. (const :format "" notregexp)
  368. (regexp))
  369. (list :tag "TODO state is" :inline t
  370. (const todo)
  371. (choice
  372. (const :tag "Any not-done state" todo)
  373. (const :tag "Any done state" done)
  374. (const :tag "Any state" any)
  375. (list :tag "Keyword list"
  376. (const :format "" quote)
  377. (repeat (string :tag "Keyword")))))
  378. (list :tag "TODO state is not" :inline t
  379. (const nottodo)
  380. (choice
  381. (const :tag "Any not-done state" todo)
  382. (const :tag "Any done state" done)
  383. (const :tag "Any state" any)
  384. (list :tag "Keyword list"
  385. (const :format "" quote)
  386. (repeat (string :tag "Keyword")))))
  387. (const :tag "scheduled" scheduled)
  388. (const :tag "not scheduled" notscheduled)
  389. (const :tag "deadline" deadline)
  390. (const :tag "no deadline" notdeadline)
  391. (const :tag "timestamp" timestamp)
  392. (const :tag "no timestamp" nottimestamp))))))
  393. (list :tag "Non-standard skipping condition"
  394. :value (org-agenda-skip-function)
  395. (const org-agenda-skip-function)
  396. (sexp :tag "Function or form (quoted!)"))
  397. (list :tag "Any variable"
  398. (variable :tag "Variable")
  399. (sexp :tag "Value (sexp)"))))
  400. "Selection of examples for agenda command settings.
  401. This will be spliced into the custom type of
  402. `org-agenda-custom-commands'.")
  403. (defcustom org-agenda-custom-commands
  404. '(("n" "Agenda and all TODOs" ((agenda "") (alltodo ""))))
  405. "Custom commands for the agenda.
  406. \\<org-mode-map>
  407. These commands will be offered on the splash screen displayed by the
  408. agenda dispatcher `\\[org-agenda]'. Each entry is a list like this:
  409. (key desc type match settings files)
  410. key The key (one or more characters as a string) to be associated
  411. with the command.
  412. desc A description of the command, when omitted or nil, a default
  413. description is built using MATCH.
  414. type The command type, any of the following symbols:
  415. agenda The daily/weekly agenda.
  416. todo Entries with a specific TODO keyword, in all agenda files.
  417. search Entries containing search words entry or headline.
  418. tags Tags/Property/TODO match in all agenda files.
  419. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  420. todo-tree Sparse tree of specific TODO keyword in *current* file.
  421. tags-tree Sparse tree with all tags matches in *current* file.
  422. occur-tree Occur sparse tree for *current* file.
  423. ... A user-defined function.
  424. match What to search for:
  425. - a single keyword for TODO keyword searches
  426. - a tags/property/todo match expression for searches
  427. - a word search expression for text searches.
  428. - a regular expression for occur searches
  429. For all other commands, this should be the empty string.
  430. settings A list of option settings, similar to that in a let form, so like
  431. this: ((opt1 val1) (opt2 val2) ...). The values will be
  432. evaluated at the moment of execution, so quote them when needed.
  433. files A list of files to write the produced agenda buffer to with
  434. the command `org-store-agenda-views'.
  435. If a file name ends in \".html\", an HTML version of the buffer
  436. is written out. If it ends in \".ps\", a postscript version is
  437. produced. Otherwise, only the plain text is written to the file.
  438. You can also define a set of commands, to create a composite agenda buffer.
  439. In this case, an entry looks like this:
  440. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  441. where
  442. desc A description string to be displayed in the dispatcher menu.
  443. cmd An agenda command, similar to the above. However, tree commands
  444. are not allowed, but instead you can get agenda and global todo list.
  445. So valid commands for a set are:
  446. (agenda \"\" settings)
  447. (alltodo \"\" settings)
  448. (stuck \"\" settings)
  449. (todo \"match\" settings files)
  450. (search \"match\" settings files)
  451. (tags \"match\" settings files)
  452. (tags-todo \"match\" settings files)
  453. Each command can carry a list of options, and another set of options can be
  454. given for the whole set of commands. Individual command options take
  455. precedence over the general options.
  456. When using several characters as key to a command, the first characters
  457. are prefix commands. For the dispatcher to display useful information, you
  458. should provide a description for the prefix, like
  459. (setq org-agenda-custom-commands
  460. \\='((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  461. (\"hl\" tags \"+HOME+Lisa\")
  462. (\"hp\" tags \"+HOME+Peter\")
  463. (\"hk\" tags \"+HOME+Kim\")))"
  464. :group 'org-agenda-custom-commands
  465. :type `(repeat
  466. (choice :value ("x" "Describe command here" tags "" nil)
  467. (list :tag "Single command"
  468. (string :tag "Access Key(s) ")
  469. (option (string :tag "Description"))
  470. (choice
  471. (const :tag "Agenda" agenda)
  472. (const :tag "TODO list" alltodo)
  473. (const :tag "Search words" search)
  474. (const :tag "Stuck projects" stuck)
  475. (const :tag "Tags/Property match (all agenda files)" tags)
  476. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  477. (const :tag "TODO keyword search (all agenda files)" todo)
  478. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  479. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  480. (const :tag "Occur tree (current buffer)" occur-tree)
  481. (sexp :tag "Other, user-defined function"))
  482. (string :tag "Match (only for some commands)")
  483. ,org-agenda-custom-commands-local-options
  484. (option (repeat :tag "Export" (file :tag "Export to"))))
  485. (list :tag "Command series, all agenda files"
  486. (string :tag "Access Key(s)")
  487. (string :tag "Description ")
  488. (repeat :tag "Component"
  489. (choice
  490. (list :tag "Agenda"
  491. (const :format "" agenda)
  492. (const :tag "" :format "" "")
  493. ,org-agenda-custom-commands-local-options)
  494. (list :tag "TODO list (all keywords)"
  495. (const :format "" alltodo)
  496. (const :tag "" :format "" "")
  497. ,org-agenda-custom-commands-local-options)
  498. (list :tag "Search words"
  499. (const :format "" search)
  500. (string :tag "Match")
  501. ,org-agenda-custom-commands-local-options)
  502. (list :tag "Stuck projects"
  503. (const :format "" stuck)
  504. (const :tag "" :format "" "")
  505. ,org-agenda-custom-commands-local-options)
  506. (list :tag "Tags/Property match (all agenda files)"
  507. (const :format "" tags)
  508. (string :tag "Match")
  509. ,org-agenda-custom-commands-local-options)
  510. (list :tag "Tags/Property match of TODO entries (all agenda files)"
  511. (const :format "" tags-todo)
  512. (string :tag "Match")
  513. ,org-agenda-custom-commands-local-options)
  514. (list :tag "TODO keyword search"
  515. (const :format "" todo)
  516. (string :tag "Match")
  517. ,org-agenda-custom-commands-local-options)
  518. (list :tag "Other, user-defined function"
  519. (symbol :tag "function")
  520. (string :tag "Match")
  521. ,org-agenda-custom-commands-local-options)))
  522. (repeat :tag "Settings for entire command set"
  523. (list (variable :tag "Any variable")
  524. (sexp :tag "Value")))
  525. (option (repeat :tag "Export" (file :tag "Export to"))))
  526. (cons :tag "Prefix key documentation"
  527. (string :tag "Access Key(s)")
  528. (string :tag "Description ")))))
  529. (defcustom org-agenda-query-register ?o
  530. "The register holding the current query string.
  531. The purpose of this is that if you construct a query string interactively,
  532. you can then use it to define a custom command."
  533. :group 'org-agenda-custom-commands
  534. :type 'character)
  535. (defcustom org-stuck-projects
  536. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  537. "How to identify stuck projects.
  538. This is a list of four items:
  539. 1. A tags/todo/property matcher string that is used to identify a project.
  540. See the manual for a description of tag and property searches.
  541. The entire tree below a headline matched by this is considered one project.
  542. 2. A list of TODO keywords identifying non-stuck projects.
  543. If the project subtree contains any headline with one of these todo
  544. keywords, the project is considered to be not stuck. If you specify
  545. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  546. 3. A list of tags identifying non-stuck projects.
  547. If the project subtree contains any headline with one of these tags,
  548. the project is considered to be not stuck. If you specify \"*\" as
  549. a tag, any tag will mark the project unstuck. Note that this is about
  550. the explicit presence of a tag somewhere in the subtree, inherited
  551. tags do not count here. If inherited tags make a project not stuck,
  552. use \"-TAG\" in the tags part of the matcher under (1.) above.
  553. 4. An arbitrary regular expression matching non-stuck projects.
  554. If the project turns out to be not stuck, search continues also in the
  555. subtree to see if any of the subtasks have project status.
  556. See also the variable `org-tags-match-list-sublevels' which applies
  557. to projects matched by this search as well.
  558. After defining this variable, you may use `org-agenda-list-stuck-projects'
  559. \(bound to `\\[org-agenda] #') to produce the list."
  560. :group 'org-agenda-custom-commands
  561. :type '(list
  562. (string :tag "Tags/TODO match to identify a project")
  563. (repeat :tag "Projects are *not* stuck if they have an entry with \
  564. TODO keyword any of" (string))
  565. (repeat :tag "Projects are *not* stuck if they have an entry with \
  566. TAG being any of" (string))
  567. (regexp :tag "Projects are *not* stuck if this regexp matches inside \
  568. the subtree")))
  569. (defgroup org-agenda-skip nil
  570. "Options concerning skipping parts of agenda files."
  571. :tag "Org Agenda Skip"
  572. :group 'org-agenda)
  573. (defcustom org-agenda-skip-function-global nil
  574. "Function to be called at each match during agenda construction.
  575. If this function returns nil, the current match should not be skipped.
  576. If the function decided to skip an agenda match, is must return the
  577. buffer position from which the search should be continued.
  578. This may also be a Lisp form, which will be evaluated.
  579. This variable will be applied to every agenda match, including
  580. tags/property searches and TODO lists. So try to make the test function
  581. do its checking as efficiently as possible. To implement a skipping
  582. condition just for specific agenda commands, use the variable
  583. `org-agenda-skip-function' which can be set in the options section
  584. of custom agenda commands."
  585. :group 'org-agenda-skip
  586. :type 'sexp)
  587. (defgroup org-agenda-daily/weekly nil
  588. "Options concerning the daily/weekly agenda."
  589. :tag "Org Agenda Daily/Weekly"
  590. :group 'org-agenda)
  591. (defgroup org-agenda-todo-list nil
  592. "Options concerning the global todo list agenda view."
  593. :tag "Org Agenda Todo List"
  594. :group 'org-agenda)
  595. (defgroup org-agenda-match-view nil
  596. "Options concerning the general tags/property/todo match agenda view."
  597. :tag "Org Agenda Match View"
  598. :group 'org-agenda)
  599. (defgroup org-agenda-search-view nil
  600. "Options concerning the search agenda view."
  601. :tag "Org Agenda Search View"
  602. :group 'org-agenda)
  603. (defvar org-agenda-archives-mode nil
  604. "Non-nil means the agenda will include archived items.
  605. If this is the symbol `trees', trees in the selected agenda scope
  606. that are marked with the ARCHIVE tag will be included anyway. When this is
  607. t, also all archive files associated with the current selection of agenda
  608. files will be included.")
  609. (defcustom org-agenda-restriction-lock-highlight-subtree t
  610. "Non-nil means highlight the whole subtree when restriction is active.
  611. Otherwise only highlight the headline. Highlighting the whole subtree is
  612. useful to ensure no edits happen beyond the restricted region."
  613. :group 'org-agenda
  614. :type 'boolean)
  615. (defcustom org-agenda-skip-comment-trees t
  616. "Non-nil means skip trees that start with the COMMENT keyword.
  617. When nil, these trees are also scanned by agenda commands."
  618. :group 'org-agenda-skip
  619. :type 'boolean)
  620. (defcustom org-agenda-todo-list-sublevels t
  621. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  622. When nil, the sublevels of a TODO entry are not checked, resulting in
  623. potentially much shorter TODO lists."
  624. :group 'org-agenda-skip
  625. :group 'org-agenda-todo-list
  626. :type 'boolean)
  627. (defcustom org-agenda-todo-ignore-with-date nil
  628. "Non-nil means don't show entries with a date in the global todo list.
  629. You can use this if you prefer to mark mere appointments with a TODO keyword,
  630. but don't want them to show up in the TODO list.
  631. When this is set, it also covers deadlines and scheduled items, the settings
  632. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  633. will be ignored.
  634. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  635. :group 'org-agenda-skip
  636. :group 'org-agenda-todo-list
  637. :type 'boolean)
  638. (defcustom org-agenda-todo-ignore-timestamp nil
  639. "Non-nil means don't show entries with a timestamp.
  640. This applies when creating the global todo list.
  641. Valid values are:
  642. past Don't show entries for today or in the past.
  643. future Don't show entries with a timestamp in the future.
  644. The idea behind this is that if it has a future
  645. timestamp, you don't want to think about it until the
  646. date.
  647. all Don't show any entries with a timestamp in the global todo list.
  648. The idea behind this is that by setting a timestamp, you
  649. have already \"taken care\" of this item.
  650. This variable can also have an integer as a value. If positive (N),
  651. todos with a timestamp N or more days in the future will be ignored. If
  652. negative (-N), todos with a timestamp N or more days in the past will be
  653. ignored. If 0, todos with a timestamp either today or in the future will
  654. be ignored. For example, a value of -1 will exclude todos with a
  655. timestamp in the past (yesterday or earlier), while a value of 7 will
  656. exclude todos with a timestamp a week or more in the future.
  657. See also `org-agenda-todo-ignore-with-date'.
  658. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  659. to make his option also apply to the tags-todo list."
  660. :group 'org-agenda-skip
  661. :group 'org-agenda-todo-list
  662. :version "24.1"
  663. :type '(choice
  664. (const :tag "Ignore future timestamp todos" future)
  665. (const :tag "Ignore past or present timestamp todos" past)
  666. (const :tag "Ignore all timestamp todos" all)
  667. (const :tag "Show timestamp todos" nil)
  668. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  669. (defcustom org-agenda-todo-ignore-scheduled nil
  670. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  671. This applies when creating the global todo list.
  672. Valid values are:
  673. past Don't show entries scheduled today or in the past.
  674. future Don't show entries scheduled in the future.
  675. The idea behind this is that by scheduling it, you don't want to
  676. think about it until the scheduled date.
  677. all Don't show any scheduled entries in the global todo list.
  678. The idea behind this is that by scheduling it, you have already
  679. \"taken care\" of this item.
  680. t Same as `all', for backward compatibility.
  681. This variable can also have an integer as a value. See
  682. `org-agenda-todo-ignore-timestamp' for more details.
  683. See also `org-agenda-todo-ignore-with-date'.
  684. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  685. to make his option also apply to the tags-todo list."
  686. :group 'org-agenda-skip
  687. :group 'org-agenda-todo-list
  688. :type '(choice
  689. (const :tag "Ignore future-scheduled todos" future)
  690. (const :tag "Ignore past- or present-scheduled todos" past)
  691. (const :tag "Ignore all scheduled todos" all)
  692. (const :tag "Ignore all scheduled todos (compatibility)" t)
  693. (const :tag "Show scheduled todos" nil)
  694. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  695. (defcustom org-agenda-todo-ignore-deadlines nil
  696. "Non-nil means ignore some deadline TODO items when making TODO list.
  697. There are different motivations for using different values, please think
  698. carefully when configuring this variable.
  699. This applies when creating the global TODO list.
  700. Valid values are:
  701. near Don't show near deadline entries. A deadline is near when it is
  702. closer than `org-deadline-warning-days' days. The idea behind this
  703. is that such items will appear in the agenda anyway.
  704. far Don't show TODO entries where a deadline has been defined, but
  705. is not going to happen anytime soon. This is useful if you want to use
  706. the TODO list to figure out what to do now.
  707. past Don't show entries with a deadline timestamp for today or in the past.
  708. future Don't show entries with a deadline timestamp in the future, not even
  709. when they become `near' ones. Use it with caution.
  710. all Ignore all TODO entries that do have a deadline.
  711. t Same as `near', for backward compatibility.
  712. This variable can also have an integer as a value. See
  713. `org-agenda-todo-ignore-timestamp' for more details.
  714. See also `org-agenda-todo-ignore-with-date'.
  715. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  716. to make his option also apply to the tags-todo list."
  717. :group 'org-agenda-skip
  718. :group 'org-agenda-todo-list
  719. :type '(choice
  720. (const :tag "Ignore near deadlines" near)
  721. (const :tag "Ignore near deadlines (compatibility)" t)
  722. (const :tag "Ignore far deadlines" far)
  723. (const :tag "Ignore all TODOs with a deadlines" all)
  724. (const :tag "Show all TODOs, even if they have a deadline" nil)
  725. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  726. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  727. "Time unit to use when possibly ignoring an agenda item.
  728. See the docstring of various `org-agenda-todo-ignore-*' options.
  729. The default is to compare time stamps using days. An item is thus
  730. considered to be in the future if it is at least one day after today.
  731. Non-nil means to compare time stamps using seconds. An item is then
  732. considered future if it has a time value later than current time."
  733. :group 'org-agenda-skip
  734. :group 'org-agenda-todo-list
  735. :version "24.4"
  736. :package-version '(Org . "8.0")
  737. :type '(choice
  738. (const :tag "Compare time with days" nil)
  739. (const :tag "Compare time with seconds" t)))
  740. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  741. "Non-nil means honor todo-list ignores options also in tags-todo search.
  742. The variables
  743. `org-agenda-todo-ignore-with-date',
  744. `org-agenda-todo-ignore-timestamp',
  745. `org-agenda-todo-ignore-scheduled',
  746. `org-agenda-todo-ignore-deadlines'
  747. make the global TODO list skip entries that have time stamps of certain
  748. kinds. If this option is set, the same options will also apply for the
  749. tags-todo search, which is the general tags/property matcher
  750. restricted to unfinished TODO entries only."
  751. :group 'org-agenda-skip
  752. :group 'org-agenda-todo-list
  753. :group 'org-agenda-match-view
  754. :type 'boolean)
  755. (defcustom org-agenda-skip-scheduled-if-done nil
  756. "Non-nil means don't show scheduled items in agenda when they are done.
  757. This is relevant for the daily/weekly agenda, not for the TODO list. It
  758. applies only to the actual date of the scheduling. Warnings about an item
  759. with a past scheduling dates are always turned off when the item is DONE."
  760. :group 'org-agenda-skip
  761. :group 'org-agenda-daily/weekly
  762. :type 'boolean)
  763. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  764. "Non-nil means skip scheduling line if same entry shows because of deadline.
  765. In the agenda of today, an entry can show up multiple times
  766. because it is both scheduled and has a nearby deadline, and maybe
  767. a plain time stamp as well.
  768. When this variable is nil, the entry will be shown several times.
  769. When set to t, then only the deadline is shown and the fact that
  770. the entry is scheduled today or was scheduled previously is not
  771. shown.
  772. When set to the symbol `not-today', skip scheduled previously,
  773. but not scheduled today.
  774. When set to the symbol `repeated-after-deadline', skip scheduled
  775. items if they are repeated beyond the current deadline."
  776. :group 'org-agenda-skip
  777. :group 'org-agenda-daily/weekly
  778. :type '(choice
  779. (const :tag "Never" nil)
  780. (const :tag "Always" t)
  781. (const :tag "Not when scheduled today" not-today)
  782. (const :tag "When repeated past deadline" repeated-after-deadline)))
  783. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  784. "Non-nil means skip timestamp line if same entry shows because of deadline.
  785. In the agenda of today, an entry can show up multiple times
  786. because it has both a plain timestamp and has a nearby deadline.
  787. When this variable is t, then only the deadline is shown and the
  788. fact that the entry has a timestamp for or including today is not
  789. shown. When this variable is nil, the entry will be shown
  790. several times."
  791. :group 'org-agenda-skip
  792. :group 'org-agenda-daily/weekly
  793. :version "24.1"
  794. :type '(choice
  795. (const :tag "Never" nil)
  796. (const :tag "Always" t)))
  797. (defcustom org-agenda-skip-deadline-if-done nil
  798. "Non-nil means don't show deadlines when the corresponding item is done.
  799. When nil, the deadline is still shown and should give you a happy feeling.
  800. This is relevant for the daily/weekly agenda. It applies only to the
  801. actual date of the deadline. Warnings about approaching and past-due
  802. deadlines are always turned off when the item is DONE."
  803. :group 'org-agenda-skip
  804. :group 'org-agenda-daily/weekly
  805. :type 'boolean)
  806. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  807. "Non-nil means skip deadline prewarning when entry is also scheduled.
  808. This will apply on all days where a prewarning for the deadline would
  809. be shown, but not at the day when the entry is actually due. On that day,
  810. the deadline will be shown anyway.
  811. This variable may be set to nil, t, the symbol `pre-scheduled',
  812. or a number which will then give the number of days before the actual
  813. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  814. eliminates the deadline prewarning only prior to the scheduled date.
  815. This can be used in a workflow where the first showing of the deadline will
  816. trigger you to schedule it, and then you don't want to be reminded of it
  817. because you will take care of it on the day when scheduled."
  818. :group 'org-agenda-skip
  819. :group 'org-agenda-daily/weekly
  820. :version "24.1"
  821. :type '(choice
  822. (const :tag "Always show prewarning" nil)
  823. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  824. (const :tag "Remove prewarning if entry is scheduled" t)
  825. (integer :tag "Restart prewarning N days before deadline")))
  826. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  827. "Non-nil means skip scheduled delay when entry also has a deadline.
  828. This variable may be set to nil, t, the symbol `post-deadline',
  829. or a number which will then give the number of days after the actual
  830. scheduled date when the delay should expire. The symbol `post-deadline'
  831. eliminates the schedule delay when the date is posterior to the deadline."
  832. :group 'org-agenda-skip
  833. :group 'org-agenda-daily/weekly
  834. :version "24.4"
  835. :package-version '(Org . "8.0")
  836. :type '(choice
  837. (const :tag "Always honor delay" nil)
  838. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  839. (const :tag "Ignore delay if entry has a deadline" t)
  840. (integer :tag "Honor delay up until N days after the scheduled date")))
  841. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  842. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  843. When non-nil, after the search for timestamps has matched once in an
  844. entry, the rest of the entry will not be searched."
  845. :group 'org-agenda-skip
  846. :type 'boolean)
  847. (defcustom org-agenda-skip-timestamp-if-done nil
  848. "Non-nil means don't select item by timestamp or -range if it is DONE."
  849. :group 'org-agenda-skip
  850. :group 'org-agenda-daily/weekly
  851. :type 'boolean)
  852. (defcustom org-agenda-dim-blocked-tasks t
  853. "Non-nil means dim blocked tasks in the agenda display.
  854. This causes some overhead during agenda construction, but if you
  855. have turned on `org-enforce-todo-dependencies',
  856. `org-enforce-todo-checkbox-dependencies', or any other blocking
  857. mechanism, this will create useful feedback in the agenda.
  858. Instead of t, this variable can also have the value `invisible'.
  859. Then blocked tasks will be invisible and only become visible when
  860. they become unblocked. An exemption to this behavior is when a task is
  861. blocked because of unchecked checkboxes below it. Since checkboxes do
  862. not show up in the agenda views, making this task invisible you remove any
  863. trace from agenda views that there is something to do. Therefore, a task
  864. that is blocked because of checkboxes will never be made invisible, it
  865. will only be dimmed."
  866. :group 'org-agenda-daily/weekly
  867. :group 'org-agenda-todo-list
  868. :version "24.3"
  869. :type '(choice
  870. (const :tag "Do not dim" nil)
  871. (const :tag "Dim to a gray face" t)
  872. (const :tag "Make invisible" invisible)))
  873. (defgroup org-agenda-startup nil
  874. "Options concerning initial settings in the Agenda in Org Mode."
  875. :tag "Org Agenda Startup"
  876. :group 'org-agenda)
  877. (defcustom org-agenda-menu-show-matcher t
  878. "Non-nil means show the match string in the agenda dispatcher menu.
  879. When nil, the matcher string is not shown, but is put into the help-echo
  880. property so than moving the mouse over the command shows it.
  881. Setting it to nil is good if matcher strings are very long and/or if
  882. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  883. :group 'org-agenda
  884. :version "24.1"
  885. :type 'boolean)
  886. (defcustom org-agenda-menu-two-columns nil
  887. "Non-nil means, use two columns to show custom commands in the dispatcher.
  888. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  889. to nil."
  890. :group 'org-agenda
  891. :version "24.1"
  892. :type 'boolean)
  893. (defcustom org-agenda-finalize-hook nil
  894. "Hook run just before displaying an agenda buffer.
  895. The buffer is still writable when the hook is called.
  896. You can modify some of the buffer substrings but you should be
  897. extra careful not to modify the text properties of the agenda
  898. headlines as the agenda display heavily relies on them."
  899. :group 'org-agenda-startup
  900. :type 'hook)
  901. (defcustom org-agenda-filter-hook nil
  902. "Hook run just after filtering with `org-agenda-filter'."
  903. :group 'org-agenda-startup
  904. :package-version '(Org . "9.4")
  905. :type 'hook)
  906. (defcustom org-agenda-mouse-1-follows-link nil
  907. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  908. A longer mouse click will still set point. Needs to be set
  909. before org.el is loaded."
  910. :group 'org-agenda-startup
  911. :type 'boolean)
  912. (defcustom org-agenda-start-with-follow-mode nil
  913. "The initial value of follow mode in a newly created agenda window."
  914. :group 'org-agenda-startup
  915. :type 'boolean)
  916. (defcustom org-agenda-follow-indirect nil
  917. "Non-nil means `org-agenda-follow-mode' displays only the
  918. current item's tree, in an indirect buffer."
  919. :group 'org-agenda
  920. :version "24.1"
  921. :type 'boolean)
  922. (defcustom org-agenda-show-outline-path t
  923. "Non-nil means show outline path in echo area after line motion."
  924. :group 'org-agenda-startup
  925. :type 'boolean)
  926. (defcustom org-agenda-start-with-entry-text-mode nil
  927. "The initial value of entry-text-mode in a newly created agenda window."
  928. :group 'org-agenda-startup
  929. :type 'boolean)
  930. (defcustom org-agenda-entry-text-maxlines 5
  931. "Number of text lines to be added when `E' is pressed in the agenda.
  932. Note that this variable only used during agenda display. To add entry text
  933. when exporting the agenda, configure the variable
  934. `org-agenda-add-entry-text-maxlines'."
  935. :group 'org-agenda
  936. :type 'integer)
  937. (defcustom org-agenda-entry-text-exclude-regexps nil
  938. "List of regular expressions to clean up entry text.
  939. The complete matches of all regular expressions in this list will be
  940. removed from entry text before it is shown in the agenda."
  941. :group 'org-agenda
  942. :type '(repeat (regexp)))
  943. (defcustom org-agenda-entry-text-leaders " > "
  944. "Text prepended to the entry text in agenda buffers."
  945. :version "24.4"
  946. :package-version '(Org . "8.0")
  947. :group 'org-agenda
  948. :type 'string)
  949. (defvar org-agenda-entry-text-cleanup-hook nil
  950. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  951. This cleanup is done in a temporary buffer, so the function may inspect and
  952. change the entire buffer.
  953. Some default stuff like drawers and scheduling/deadline dates will already
  954. have been removed when this is called, as will any matches for regular
  955. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  956. (defvar org-agenda-include-inactive-timestamps nil
  957. "Non-nil means include inactive time stamps in agenda.
  958. Dynamically scoped.")
  959. (defgroup org-agenda-windows nil
  960. "Options concerning the windows used by the Agenda in Org Mode."
  961. :tag "Org Agenda Windows"
  962. :group 'org-agenda)
  963. (defcustom org-agenda-window-setup 'reorganize-frame
  964. "How the agenda buffer should be displayed.
  965. Possible values for this option are:
  966. current-window Show agenda in the current window, keeping all other windows.
  967. other-window Use `switch-to-buffer-other-window' to display agenda.
  968. only-window Show agenda, deleting all other windows.
  969. reorganize-frame Show only two windows on the current frame, the current
  970. window and the agenda.
  971. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  972. Also, when exiting the agenda, kill that frame.
  973. other-tab Use `switch-to-buffer-other-tab' to display the
  974. agenda, making use of the `tab-bar-mode' introduced
  975. in Emacs version 27.1. Also, kill that tab when
  976. exiting the agenda view.
  977. See also the variable `org-agenda-restore-windows-after-quit'."
  978. :group 'org-agenda-windows
  979. :type '(choice
  980. (const current-window)
  981. (const other-frame)
  982. (const other-tab)
  983. (const other-window)
  984. (const only-window)
  985. (const reorganize-frame))
  986. :package-version '(Org . "9.4"))
  987. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  988. "The min and max height of the agenda window as a fraction of frame height.
  989. The value of the variable is a cons cell with two numbers between 0 and 1.
  990. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  991. :group 'org-agenda-windows
  992. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  993. (defcustom org-agenda-restore-windows-after-quit nil
  994. "Non-nil means restore window configuration upon exiting agenda.
  995. Before the window configuration is changed for displaying the
  996. agenda, the current status is recorded. When the agenda is
  997. exited with `q' or `x' and this option is set, the old state is
  998. restored. If `org-agenda-window-setup' is `other-frame' or
  999. `other-tab', the value of this option will be ignored."
  1000. :group 'org-agenda-windows
  1001. :type 'boolean)
  1002. (defcustom org-agenda-span 'week
  1003. "Number of days to include in overview display.
  1004. Can be day, week, month, year, or any number of days.
  1005. Custom commands can set this variable in the options section."
  1006. :group 'org-agenda-daily/weekly
  1007. :type '(choice (const :tag "Day" day)
  1008. (const :tag "Week" week)
  1009. (const :tag "Fortnight" fortnight)
  1010. (const :tag "Month" month)
  1011. (const :tag "Year" year)
  1012. (integer :tag "Custom")))
  1013. (defcustom org-agenda-start-on-weekday 1
  1014. "Non-nil means start the overview always on the specified weekday.
  1015. 0 denotes Sunday, 1 denotes Monday, etc.
  1016. When nil, always start on the current day.
  1017. Custom commands can set this variable in the options section."
  1018. :group 'org-agenda-daily/weekly
  1019. :type '(choice (const :tag "Today" nil)
  1020. (integer :tag "Weekday No.")))
  1021. (defcustom org-agenda-show-all-dates t
  1022. "Non-nil means `org-agenda' shows every day in the selected range.
  1023. When nil, only the days which actually have entries are shown."
  1024. :group 'org-agenda-daily/weekly
  1025. :type 'boolean)
  1026. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1027. "Format string for displaying dates in the agenda.
  1028. Used by the daily/weekly agenda. This should be a format string
  1029. understood by `format-time-string', or a function returning the
  1030. formatted date as a string. The function must take a single
  1031. argument, a calendar-style date list like (month day year)."
  1032. :group 'org-agenda-daily/weekly
  1033. :type '(choice
  1034. (string :tag "Format string")
  1035. (function :tag "Function")))
  1036. (defun org-agenda-end-of-line ()
  1037. "Go to the end of visible line."
  1038. (interactive)
  1039. (goto-char (line-end-position)))
  1040. (defun org-agenda-format-date-aligned (date)
  1041. "Format a DATE string for display in the daily/weekly agenda.
  1042. This function makes sure that dates are aligned for easy reading."
  1043. (require 'cal-iso)
  1044. (let* ((dayname (calendar-day-name date))
  1045. (day (cadr date))
  1046. (day-of-week (calendar-day-of-week date))
  1047. (month (car date))
  1048. (monthname (calendar-month-name month))
  1049. (year (nth 2 date))
  1050. (iso-week (org-days-to-iso-week
  1051. (calendar-absolute-from-gregorian date)))
  1052. ;; (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1053. ;; (1- year))
  1054. ;; ((and (= month 12) (<= iso-week 1))
  1055. ;; (1+ year))
  1056. ;; (t year)))
  1057. (weekstring (if (= day-of-week 1)
  1058. (format " W%02d" iso-week)
  1059. "")))
  1060. (format "%-10s %2d %s %4d%s"
  1061. dayname day monthname year weekstring)))
  1062. (defcustom org-agenda-time-leading-zero nil
  1063. "Non-nil means use leading zero for military times in agenda.
  1064. For example, 9:30am would become 09:30 rather than 9:30."
  1065. :group 'org-agenda-daily/weekly
  1066. :version "24.1"
  1067. :type 'boolean)
  1068. (defcustom org-agenda-timegrid-use-ampm nil
  1069. "When set, show AM/PM style timestamps on the timegrid."
  1070. :group 'org-agenda
  1071. :version "24.1"
  1072. :type 'boolean)
  1073. (defun org-agenda-time-of-day-to-ampm (time)
  1074. "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
  1075. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1076. (minute (substring time -2))
  1077. (ampm "am"))
  1078. (cond
  1079. ((equal hour-number 12)
  1080. (setq ampm "pm"))
  1081. ((> hour-number 12)
  1082. (setq ampm "pm")
  1083. (setq hour-number (- hour-number 12))))
  1084. (concat
  1085. (if org-agenda-time-leading-zero
  1086. (format "%02d" hour-number)
  1087. (format "%02s" (number-to-string hour-number)))
  1088. ":" minute ampm)))
  1089. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1090. "Conditionally convert TIME to AM/PM format.
  1091. This is based on `org-agenda-timegrid-use-ampm'."
  1092. (if org-agenda-timegrid-use-ampm
  1093. (org-agenda-time-of-day-to-ampm time)
  1094. time))
  1095. (defcustom org-agenda-weekend-days '(6 0)
  1096. "Which days are weekend?
  1097. These days get the special face `org-agenda-date-weekend' in the agenda."
  1098. :group 'org-agenda-daily/weekly
  1099. :type '(set :greedy t
  1100. (const :tag "Monday" 1)
  1101. (const :tag "Tuesday" 2)
  1102. (const :tag "Wednesday" 3)
  1103. (const :tag "Thursday" 4)
  1104. (const :tag "Friday" 5)
  1105. (const :tag "Saturday" 6)
  1106. (const :tag "Sunday" 0)))
  1107. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1108. "Non-nil means jump to today when moving a past date forward in time.
  1109. When using S-right in the agenda to move a date forward, and the date
  1110. stamp currently points to the past, the first key press will move it
  1111. to today. When nil, just move one day forward even if the date stays
  1112. in the past."
  1113. :group 'org-agenda-daily/weekly
  1114. :version "24.1"
  1115. :type 'boolean)
  1116. (defcustom org-agenda-diary-file 'diary-file
  1117. "File to which to add new entries with the `i' key in agenda and calendar.
  1118. When this is the symbol `diary-file', the functionality in the Emacs
  1119. calendar will be used to add entries to the `diary-file'. But when this
  1120. points to a file, `org-agenda-diary-entry' will be used instead."
  1121. :group 'org-agenda
  1122. :type '(choice
  1123. (const :tag "The standard Emacs diary file" diary-file)
  1124. (file :tag "Special Org file diary entries")))
  1125. (defcustom org-agenda-include-diary nil
  1126. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1127. Custom commands can set this variable in the options section."
  1128. :group 'org-agenda-daily/weekly
  1129. :type 'boolean)
  1130. (defcustom org-agenda-include-deadlines t
  1131. "If non-nil, include entries within their deadline warning period.
  1132. Custom commands can set this variable in the options section."
  1133. :group 'org-agenda-daily/weekly
  1134. :version "24.1"
  1135. :type 'boolean)
  1136. (defcustom org-agenda-show-future-repeats t
  1137. "Non-nil shows repeated entries in the future part of the agenda.
  1138. When set to the symbol `next' only the first future repeat is shown."
  1139. :group 'org-agenda-daily/weekly
  1140. :type '(choice
  1141. (const :tag "Show all repeated entries" t)
  1142. (const :tag "Show next repeated entry" next)
  1143. (const :tag "Do not show repeated entries" nil))
  1144. :version "26.1"
  1145. :package-version '(Org . "9.1")
  1146. :safe #'symbolp)
  1147. (defcustom org-agenda-prefer-last-repeat nil
  1148. "Non-nil sets date for repeated entries to their last repeat.
  1149. When nil, display SCHEDULED and DEADLINE dates at their base
  1150. date, and in today's agenda, as a reminder. Display plain
  1151. time-stamps, on the other hand, at every repeat date in the past
  1152. in addition to the base date.
  1153. When non-nil, show a repeated entry at its latest repeat date,
  1154. possibly being today even if it wasn't marked as done. This
  1155. setting is useful if you do not always mark repeated entries as
  1156. done and, yet, consider that reaching repeat date starts the task
  1157. anew.
  1158. When set to a list of strings, prefer last repeats only for
  1159. entries with these TODO keywords."
  1160. :group 'org-agenda-daily/weekly
  1161. :type '(choice
  1162. (const :tag "Prefer last repeat" t)
  1163. (const :tag "Prefer base date" nil)
  1164. (repeat :tag "Prefer last repeat for entries with these TODO keywords"
  1165. (string :tag "TODO keyword")))
  1166. :version "26.1"
  1167. :package-version '(Org . "9.1")
  1168. :safe (lambda (x) (or (booleanp x) (consp x))))
  1169. (defcustom org-scheduled-past-days 10000
  1170. "Number of days to continue listing scheduled items not marked DONE.
  1171. When an item is scheduled on a date, it shows up in the agenda on
  1172. this day and will be listed until it is marked done or for the
  1173. number of days given here."
  1174. :group 'org-agenda-daily/weekly
  1175. :type 'integer
  1176. :safe 'integerp)
  1177. (defcustom org-deadline-past-days 10000
  1178. "Number of days to warn about missed deadlines.
  1179. When an item has deadline on a date, it shows up in the agenda on
  1180. this day and will appear as a reminder until it is marked DONE or
  1181. for the number of days given here."
  1182. :group 'org-agenda-daily/weekly
  1183. :type 'integer
  1184. :version "26.1"
  1185. :package-version '(Org . "9.1")
  1186. :safe 'integerp)
  1187. (defcustom org-agenda-log-mode-items '(closed clock)
  1188. "List of items that should be shown in agenda log mode.
  1189. \\<org-agenda-mode-map>\
  1190. This list may contain the following symbols:
  1191. closed Show entries that have been closed on that day.
  1192. clock Show entries that have received clocked time on that day.
  1193. state Show all logged state changes.
  1194. Note that instead of changing this variable, you can also press \
  1195. `\\[universal-argument] \\[org-agenda-log-mode]' in
  1196. the agenda to display all available LOG items temporarily."
  1197. :group 'org-agenda-daily/weekly
  1198. :type '(set :greedy t (const closed) (const clock) (const state)))
  1199. (defcustom org-agenda-clock-consistency-checks
  1200. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1201. :gap-ok-around ("4:00")
  1202. :default-face ((:background "DarkRed") (:foreground "white"))
  1203. :overlap-face nil :gap-face nil :no-end-time-face nil
  1204. :long-face nil :short-face nil)
  1205. "This is a property list, with the following keys:
  1206. :max-duration Mark clocking chunks that are longer than this time.
  1207. This is a time string like \"HH:MM\", or the number
  1208. of minutes as an integer.
  1209. :min-duration Mark clocking chunks that are shorter that this.
  1210. This is a time string like \"HH:MM\", or the number
  1211. of minutes as an integer.
  1212. :max-gap Mark gaps between clocking chunks that are longer than
  1213. this duration. A number of minutes, or a string
  1214. like \"HH:MM\".
  1215. :gap-ok-around List of times during the day which are usually not working
  1216. times. When a gap is detected, but the gap contains any
  1217. of these times, the gap is *not* reported. For example,
  1218. if this is (\"4:00\" \"13:00\") then gaps that contain
  1219. 4:00 in the morning (i.e. the night) and 13:00
  1220. (i.e. a typical lunch time) do not cause a warning.
  1221. You should have at least one time during the night in this
  1222. list, or otherwise the first task each morning will trigger
  1223. a warning because it follows a long gap.
  1224. Furthermore, the following properties can be used to define faces for
  1225. issue display.
  1226. :default-face the default face, if the specific face is undefined
  1227. :overlap-face face for overlapping clocks
  1228. :gap-face face for gaps between clocks
  1229. :no-end-time-face face for incomplete clocks
  1230. :long-face face for clock intervals that are too long
  1231. :short-face face for clock intervals that are too short"
  1232. :group 'org-agenda-daily/weekly
  1233. :group 'org-clock
  1234. :version "24.1"
  1235. :type 'plist)
  1236. (defcustom org-agenda-log-mode-add-notes t
  1237. "Non-nil means add first line of notes to log entries in agenda views.
  1238. If a log item like a state change or a clock entry is associated with
  1239. notes, the first line of these notes will be added to the entry in the
  1240. agenda display."
  1241. :group 'org-agenda-daily/weekly
  1242. :type 'boolean)
  1243. (defcustom org-agenda-start-with-log-mode nil
  1244. "The initial value of log-mode in a newly created agenda window.
  1245. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1246. explanations on the possible values."
  1247. :group 'org-agenda-startup
  1248. :group 'org-agenda-daily/weekly
  1249. :type '(choice (const :tag "Don't show log items" nil)
  1250. (const :tag "Show only log items" only)
  1251. (const :tag "Show all possible log items" clockcheck)
  1252. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1253. (choice (const :tag "Show closed log items" closed)
  1254. (const :tag "Show clocked log items" clock)
  1255. (const :tag "Show all logged state changes" state)))))
  1256. (defcustom org-agenda-start-with-clockreport-mode nil
  1257. "The initial value of clockreport-mode in a newly created agenda window."
  1258. :group 'org-agenda-startup
  1259. :group 'org-agenda-daily/weekly
  1260. :type 'boolean)
  1261. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1262. "Property list with parameters for the clocktable in clockreport mode.
  1263. This is the display mode that shows a clock table in the daily/weekly
  1264. agenda, the properties for this dynamic block can be set here.
  1265. The usual clocktable parameters are allowed here, but you cannot set
  1266. the properties :name, :tstart, :tend, :block, and :scope - these will
  1267. be overwritten to make sure the content accurately reflects the
  1268. current display in the agenda."
  1269. :group 'org-agenda-daily/weekly
  1270. :type 'plist)
  1271. (defvaralias 'org-agenda-search-view-search-words-only
  1272. 'org-agenda-search-view-always-boolean)
  1273. (defcustom org-agenda-search-view-always-boolean nil
  1274. "Non-nil means the search string is interpreted as individual parts.
  1275. The search string for search view can either be interpreted as a phrase,
  1276. or as a list of snippets that define a boolean search for a number of
  1277. strings.
  1278. When this is non-nil, the string will be split on whitespace, and each
  1279. snippet will be searched individually, and all must match in order to
  1280. select an entry. A snippet is then a single string of non-white
  1281. characters, or a string in double quotes, or a regexp in {} braces.
  1282. If a snippet is preceded by \"-\", the snippet must *not* match.
  1283. \"+\" is syntactic sugar for positive selection. Each snippet may
  1284. be found as a full word or a partial word, but see the variable
  1285. `org-agenda-search-view-force-full-words'.
  1286. When this is nil, search will look for the entire search phrase as one,
  1287. with each space character matching any amount of whitespace, including
  1288. line breaks.
  1289. Even when this is nil, you can still switch to Boolean search dynamically
  1290. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1291. is a regexp marked with braces like \"{abc}\", this will also switch to
  1292. boolean search."
  1293. :group 'org-agenda-search-view
  1294. :version "24.1"
  1295. :type 'boolean)
  1296. (defcustom org-agenda-search-view-force-full-words nil
  1297. "Non-nil means, search words must be matches as complete words.
  1298. When nil, they may also match part of a word."
  1299. :group 'org-agenda-search-view
  1300. :version "24.1"
  1301. :type 'boolean)
  1302. (defcustom org-agenda-search-view-max-outline-level 0
  1303. "Maximum outline level to display in search view.
  1304. E.g. when this is set to 1, the search view will only
  1305. show headlines of level 1. When set to 0, the default
  1306. value, don't limit agenda view by outline level."
  1307. :group 'org-agenda-search-view
  1308. :version "26.1"
  1309. :package-version '(Org . "8.3")
  1310. :type 'integer)
  1311. (defgroup org-agenda-time-grid nil
  1312. "Options concerning the time grid in the Org Agenda."
  1313. :tag "Org Agenda Time Grid"
  1314. :group 'org-agenda)
  1315. (defcustom org-agenda-search-headline-for-time t
  1316. "Non-nil means search headline for a time-of-day.
  1317. If the headline contains a time-of-day in one format or another, it will
  1318. be used to sort the entry into the time sequence of items for a day.
  1319. Some people have time stamps in the headline that refer to the creation
  1320. time or so, and then this produces an unwanted side effect. If this is
  1321. the case for your, use this variable to turn off searching the headline
  1322. for a time."
  1323. :group 'org-agenda-time-grid
  1324. :type 'boolean)
  1325. (defcustom org-agenda-use-time-grid t
  1326. "Non-nil means show a time grid in the agenda schedule.
  1327. A time grid is a set of lines for specific times (like every two hours between
  1328. 8:00 and 20:00). The items scheduled for a day at specific times are
  1329. sorted in between these lines.
  1330. For details about when the grid will be shown, and what it will look like, see
  1331. the variable `org-agenda-time-grid'."
  1332. :group 'org-agenda-time-grid
  1333. :type 'boolean)
  1334. (defcustom org-agenda-time-grid
  1335. '((daily today require-timed)
  1336. (800 1000 1200 1400 1600 1800 2000)
  1337. "......"
  1338. "----------------")
  1339. "The settings for time grid for agenda display.
  1340. This is a list of four items. The first item is again a list. It contains
  1341. symbols specifying conditions when the grid should be displayed:
  1342. daily if the agenda shows a single day
  1343. weekly if the agenda shows an entire week
  1344. today show grid on current date, independent of daily/weekly display
  1345. require-timed show grid only if at least one item has a time specification
  1346. remove-match skip grid times already present in an entry
  1347. The second item is a list of integers, indicating the times that
  1348. should have a grid line.
  1349. The third item is a string which will be placed right after the
  1350. times that have a grid line.
  1351. The fourth item is a string placed after the grid times. This
  1352. will align with agenda items."
  1353. :group 'org-agenda-time-grid
  1354. :type
  1355. '(list
  1356. (set :greedy t :tag "Grid Display Options"
  1357. (const :tag "Show grid in single day agenda display" daily)
  1358. (const :tag "Show grid in weekly agenda display" weekly)
  1359. (const :tag "Always show grid for today" today)
  1360. (const :tag "Show grid only if any timed entries are present"
  1361. require-timed)
  1362. (const :tag "Skip grid times already present in an entry"
  1363. remove-match))
  1364. (repeat :tag "Grid Times" (integer :tag "Time"))
  1365. (string :tag "Grid String (after agenda times)")
  1366. (string :tag "Grid String (aligns with agenda items)")))
  1367. (defcustom org-agenda-show-current-time-in-grid t
  1368. "Non-nil means show the current time in the time grid."
  1369. :group 'org-agenda-time-grid
  1370. :version "24.1"
  1371. :type 'boolean)
  1372. (defcustom org-agenda-current-time-string
  1373. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1374. "The string for the current time marker in the agenda."
  1375. :group 'org-agenda-time-grid
  1376. :version "24.1"
  1377. :type 'string)
  1378. (defgroup org-agenda-sorting nil
  1379. "Options concerning sorting in the Org Agenda."
  1380. :tag "Org Agenda Sorting"
  1381. :group 'org-agenda)
  1382. (defcustom org-agenda-sorting-strategy
  1383. '((agenda habit-down time-up priority-down category-keep)
  1384. (todo priority-down category-keep)
  1385. (tags priority-down category-keep)
  1386. (search category-keep))
  1387. "Sorting structure for the agenda items of a single day.
  1388. This is a list of symbols which will be used in sequence to determine
  1389. if an entry should be listed before another entry. The following
  1390. symbols are recognized:
  1391. time-up Put entries with time-of-day indications first, early first.
  1392. time-down Put entries with time-of-day indications first, late first.
  1393. timestamp-up Sort by any timestamp, early first.
  1394. timestamp-down Sort by any timestamp, late first.
  1395. scheduled-up Sort by scheduled timestamp, early first.
  1396. scheduled-down Sort by scheduled timestamp, late first.
  1397. deadline-up Sort by deadline timestamp, early first.
  1398. deadline-down Sort by deadline timestamp, late first.
  1399. ts-up Sort by active timestamp, early first.
  1400. ts-down Sort by active timestamp, late first.
  1401. tsia-up Sort by inactive timestamp, early first.
  1402. tsia-down Sort by inactive timestamp, late first.
  1403. category-keep Keep the default order of categories, corresponding to the
  1404. sequence in `org-agenda-files'.
  1405. category-up Sort alphabetically by category, A-Z.
  1406. category-down Sort alphabetically by category, Z-A.
  1407. tag-up Sort alphabetically by last tag, A-Z.
  1408. tag-down Sort alphabetically by last tag, Z-A.
  1409. priority-up Sort numerically by priority, high priority last.
  1410. priority-down Sort numerically by priority, high priority first.
  1411. todo-state-up Sort by todo state, tasks that are done last.
  1412. todo-state-down Sort by todo state, tasks that are done first.
  1413. effort-up Sort numerically by estimated effort, high effort last.
  1414. effort-down Sort numerically by estimated effort, high effort first.
  1415. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1416. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1417. habit-up Put entries that are habits first.
  1418. habit-down Put entries that are habits last.
  1419. alpha-up Sort headlines alphabetically.
  1420. alpha-down Sort headlines alphabetically, reversed.
  1421. The different possibilities will be tried in sequence, and testing stops
  1422. if one comparison returns a \"not-equal\". For example, the default
  1423. '(time-up category-keep priority-down)
  1424. means: Pull out all entries having a specified time of day and sort them,
  1425. in order to make a time schedule for the current day the first thing in the
  1426. agenda listing for the day. Of the entries without a time indication, keep
  1427. the grouped in categories, don't sort the categories, but keep them in
  1428. the sequence given in `org-agenda-files'. Within each category sort by
  1429. priority.
  1430. Leaving out `category-keep' would mean that items will be sorted across
  1431. categories by priority.
  1432. Instead of a single list, this can also be a set of list for specific
  1433. contents, with a context symbol in the car of the list, any of
  1434. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1435. Custom commands can bind this variable in the options section."
  1436. :group 'org-agenda-sorting
  1437. :type `(choice
  1438. (repeat :tag "General" ,org-sorting-choice)
  1439. (list :tag "Individually"
  1440. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1441. (repeat ,org-sorting-choice))
  1442. (cons (const :tag "Strategy for TODO lists" todo)
  1443. (repeat ,org-sorting-choice))
  1444. (cons (const :tag "Strategy for Tags matches" tags)
  1445. (repeat ,org-sorting-choice))
  1446. (cons (const :tag "Strategy for search matches" search)
  1447. (repeat ,org-sorting-choice)))))
  1448. (defcustom org-agenda-cmp-user-defined nil
  1449. "A function to define the comparison `user-defined'.
  1450. This function must receive two arguments, agenda entry a and b.
  1451. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1452. the user comparison, return nil.
  1453. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1454. part of an agenda sorting strategy."
  1455. :group 'org-agenda-sorting
  1456. :type 'symbol)
  1457. (defcustom org-agenda-sort-notime-is-late t
  1458. "Non-nil means items without time are considered late.
  1459. This is only relevant for sorting. When t, items which have no explicit
  1460. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1461. do have a time. When nil, the default time is before 0:00. You can use this
  1462. option to decide if the schedule for today should come before or after timeless
  1463. agenda entries."
  1464. :group 'org-agenda-sorting
  1465. :type 'boolean)
  1466. (defcustom org-agenda-sort-noeffort-is-high t
  1467. "Non-nil means items without effort estimate are sorted as high effort.
  1468. This also applies when filtering an agenda view with respect to the
  1469. < or > effort operator. Then, tasks with no effort defined will be treated
  1470. as tasks with high effort.
  1471. When nil, such items are sorted as 0 minutes effort."
  1472. :group 'org-agenda-sorting
  1473. :type 'boolean)
  1474. (defgroup org-agenda-line-format nil
  1475. "Options concerning the entry prefix in the Org agenda display."
  1476. :tag "Org Agenda Line Format"
  1477. :group 'org-agenda)
  1478. (defcustom org-agenda-prefix-format
  1479. '((agenda . " %i %-12:c%?-12t% s")
  1480. (todo . " %i %-12:c")
  1481. (tags . " %i %-12:c")
  1482. (search . " %i %-12:c"))
  1483. "Format specifications for the prefix of items in the agenda views.
  1484. An alist with one entry per agenda type. The keys of the
  1485. sublists are `agenda', `todo', `search' and `tags'. The values
  1486. are format strings.
  1487. This format works similar to a printf format, with the following meaning:
  1488. %c the category of the item, \"Diary\" for entries from the diary,
  1489. or as given by the CATEGORY keyword or derived from the file name
  1490. %e the effort required by the item
  1491. %l the level of the item (insert X space(s) if item is of level X)
  1492. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1493. %T the last tag of the item (ignore inherited tags, which come first)
  1494. %t the HH:MM time-of-day specification if one applies to the entry
  1495. %s Scheduling/Deadline information, a short string
  1496. %b show breadcrumbs, i.e., the names of the higher levels
  1497. %(expression) Eval EXPRESSION and replace the control string
  1498. by the result
  1499. All specifiers work basically like the standard `%s' of printf, but may
  1500. contain two additional characters: a question mark just after the `%'
  1501. and a whitespace/punctuation character just before the final letter.
  1502. If the first character after `%' is a question mark, the entire field
  1503. will only be included if the corresponding value applies to the current
  1504. entry. This is useful for fields which should have fixed width when
  1505. present, but zero width when absent. For example, \"%?-12t\" will
  1506. result in a 12 character time field if a time of the day is specified,
  1507. but will completely disappear in entries which do not contain a time.
  1508. If there is punctuation or whitespace character just before the
  1509. final format letter, this character will be appended to the field
  1510. value if the value is not empty. For example, the format
  1511. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1512. the category is empty, no additional colon is inserted.
  1513. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1514. which means:
  1515. - Indent the line with two space characters
  1516. - Give the category a 12 chars wide field, padded with whitespace on
  1517. the right (because of `-'). Append a colon if there is a category
  1518. (because of `:').
  1519. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1520. time, don't put in an empty field, just skip it (because of '?').
  1521. - Finally, put the scheduling information.
  1522. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1523. `org-agenda-remove-tags'.
  1524. Custom commands can set this variable in the options section."
  1525. :type '(choice
  1526. (string :tag "General format")
  1527. (list :greedy t :tag "View dependent"
  1528. (cons (const agenda) (string :tag "Format"))
  1529. (cons (const todo) (string :tag "Format"))
  1530. (cons (const tags) (string :tag "Format"))
  1531. (cons (const search) (string :tag "Format"))))
  1532. :group 'org-agenda-line-format
  1533. :version "26.1"
  1534. :package-version '(Org . "9.1"))
  1535. (defcustom org-agenda-breadcrumbs-separator "->"
  1536. "The separator of breadcrumbs in agenda lines."
  1537. :group 'org-agenda-line-format
  1538. :package-version '(Org . "9.3")
  1539. :type 'string
  1540. :safe #'stringp)
  1541. (defvar org-prefix-format-compiled nil
  1542. "The compiled prefix format and associated variables.
  1543. This is a list where first element is a list of variable bindings, and second
  1544. element is the compiled format expression. See the variable
  1545. `org-agenda-prefix-format'.")
  1546. (defcustom org-agenda-todo-keyword-format "%-1s"
  1547. "Format for the TODO keyword in agenda lines.
  1548. Set this to something like \"%-12s\" if you want all TODO keywords
  1549. to occupy a fixed space in the agenda display."
  1550. :group 'org-agenda-line-format
  1551. :type 'string)
  1552. (defcustom org-agenda-diary-sexp-prefix nil
  1553. "A regexp that matches part of a diary sexp entry
  1554. which should be treated as scheduling/deadline information in
  1555. `org-agenda'.
  1556. For example, you can use this to extract the `diary-remind-message' from
  1557. `diary-remind' entries."
  1558. :group 'org-agenda-line-format
  1559. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1560. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1561. "Text preceding timerange entries in the agenda view.
  1562. This is a list with two strings. The first applies when the range
  1563. is entirely on one day. The second applies if the range spans several days.
  1564. The strings may have two \"%d\" format specifiers which will be filled
  1565. with the sequence number of the days, and the total number of days in the
  1566. range, respectively."
  1567. :group 'org-agenda-line-format
  1568. :type '(list
  1569. (string :tag "Deadline today ")
  1570. (choice :tag "Deadline relative"
  1571. (string :tag "Format string")
  1572. (function))))
  1573. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1574. "Text preceding scheduled items in the agenda view.
  1575. This is a list with two strings. The first applies when the item is
  1576. scheduled on the current day. The second applies when it has been scheduled
  1577. previously, it may contain a %d indicating that this is the nth time that
  1578. this item is scheduled, due to automatic rescheduling of unfinished items
  1579. for the following day. So this number is one larger than the number of days
  1580. that passed since this item was scheduled first."
  1581. :group 'org-agenda-line-format
  1582. :version "24.4"
  1583. :package-version '(Org . "8.0")
  1584. :type '(list
  1585. (string :tag "Scheduled today ")
  1586. (string :tag "Scheduled previously")))
  1587. (defcustom org-agenda-inactive-leader "["
  1588. "Text preceding item pulled into the agenda by inactive time stamps.
  1589. These entries are added to the agenda when pressing \"[\"."
  1590. :group 'org-agenda-line-format
  1591. :version "24.1"
  1592. :type 'string)
  1593. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1594. "Text preceding deadline items in the agenda view.
  1595. This is a list with three strings. The first applies when the item has its
  1596. deadline on the current day. The second applies when the deadline is in the
  1597. future, the third one when it is in the past. The strings may contain %d
  1598. to capture the number of days."
  1599. :group 'org-agenda-line-format
  1600. :version "24.4"
  1601. :package-version '(Org . "8.0")
  1602. :type '(list
  1603. (string :tag "Deadline today ")
  1604. (string :tag "Deadline in the future ")
  1605. (string :tag "Deadline in the past ")))
  1606. (defcustom org-agenda-remove-times-when-in-prefix t
  1607. "Non-nil means remove duplicate time specifications in agenda items.
  1608. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1609. time-of-day specification in a headline or diary entry is extracted and
  1610. placed into the prefix. If this option is non-nil, the original specification
  1611. \(a timestamp or -range, or just a plain time(range) specification like
  1612. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1613. cluttered.
  1614. The option can be t or nil. It may also be the symbol `beg', indicating
  1615. that the time should only be removed when it is located at the beginning of
  1616. the headline/diary entry."
  1617. :group 'org-agenda-line-format
  1618. :type '(choice
  1619. (const :tag "Always" t)
  1620. (const :tag "Never" nil)
  1621. (const :tag "When at beginning of entry" beg)))
  1622. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1623. "Non-nil means remove time ranges specifications in agenda
  1624. items that span on several days."
  1625. :group 'org-agenda-line-format
  1626. :version "24.1"
  1627. :type 'boolean)
  1628. (defcustom org-agenda-default-appointment-duration nil
  1629. "Default duration for appointments that only have a starting time.
  1630. When nil, no duration is specified in such cases.
  1631. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1632. :group 'org-agenda-line-format
  1633. :type '(choice
  1634. (integer :tag "Minutes")
  1635. (const :tag "No default duration")))
  1636. (defcustom org-agenda-show-inherited-tags t
  1637. "Non-nil means show inherited tags in each agenda line.
  1638. When this option is set to `always', it takes precedence over
  1639. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1640. in every agenda.
  1641. When this option is set to t (the default), inherited tags are
  1642. shown when they are available, i.e. when the value of
  1643. `org-agenda-use-tag-inheritance' enables tag inheritance for the
  1644. given agenda type.
  1645. This can be set to a list of agenda types in which the agenda
  1646. must display the inherited tags. Available types are `todo',
  1647. `agenda' and `search'.
  1648. When set to nil, never show inherited tags in agenda lines."
  1649. :group 'org-agenda-line-format
  1650. :group 'org-agenda
  1651. :version "24.3"
  1652. :type '(choice
  1653. (const :tag "Show inherited tags when available" t)
  1654. (const :tag "Always show inherited tags" always)
  1655. (repeat :tag "Show inherited tags only in selected agenda types"
  1656. (symbol :tag "Agenda type"))))
  1657. (defcustom org-agenda-use-tag-inheritance '(todo search agenda)
  1658. "List of agenda view types where to use tag inheritance.
  1659. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1660. controlled by `org-use-tag-inheritance'. In other agenda types,
  1661. `org-use-tag-inheritance' is not used for the selection of the
  1662. agenda entries. Still, you may want the agenda to be aware of
  1663. the inherited tags anyway, e.g. for later tag filtering.
  1664. Allowed value are `todo', `search' and `agenda'.
  1665. This variable has no effect if `org-agenda-show-inherited-tags'
  1666. is set to `always'. In that case, the agenda is aware of those
  1667. tags.
  1668. The default value sets tags in every agenda type. Setting this
  1669. option to nil will speed up non-tags agenda view a lot."
  1670. :group 'org-agenda
  1671. :version "26.1"
  1672. :package-version '(Org . "9.1")
  1673. :type '(choice
  1674. (const :tag "Use tag inheritance in all agenda types" t)
  1675. (repeat :tag "Use tag inheritance in selected agenda types"
  1676. (symbol :tag "Agenda type"))))
  1677. (defcustom org-agenda-hide-tags-regexp nil
  1678. "Regular expression used to filter away specific tags in agenda views.
  1679. This means that these tags will be present, but not be shown in the agenda
  1680. line. Secondary filtering will still work on the hidden tags.
  1681. Nil means don't hide any tags."
  1682. :group 'org-agenda-line-format
  1683. :type '(choice
  1684. (const :tag "Hide none" nil)
  1685. (regexp :tag "Regexp ")))
  1686. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1687. 'org-agenda-remove-tags)
  1688. (defcustom org-agenda-remove-tags nil
  1689. "Non-nil means remove the tags from the headline copy in the agenda.
  1690. When this is the symbol `prefix', only remove tags when
  1691. `org-agenda-prefix-format' contains a `%T' specifier."
  1692. :group 'org-agenda-line-format
  1693. :type '(choice
  1694. (const :tag "Always" t)
  1695. (const :tag "Never" nil)
  1696. (const :tag "When prefix format contains %T" prefix)))
  1697. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1698. (defcustom org-agenda-tags-column 'auto
  1699. "Shift tags in agenda items to this column.
  1700. If set to `auto', tags will be automatically aligned to the right
  1701. edge of the window.
  1702. If set to a positive number, tags will be left-aligned to that
  1703. column. If set to a negative number, tags will be right-aligned
  1704. to that column. For example, -80 works well for a normal 80
  1705. character screen."
  1706. :group 'org-agenda-line-format
  1707. :type '(choice
  1708. (const :tag "Automatically align to right edge of window" auto)
  1709. (integer :tag "Specific column" -80))
  1710. :package-version '(Org . "9.1")
  1711. :version "26.1")
  1712. (defcustom org-agenda-fontify-priorities 'cookies
  1713. "Non-nil means highlight low and high priorities in agenda.
  1714. When t, the highest priority entries are bold, lowest priority italic.
  1715. However, settings in `org-priority-faces' will overrule these faces.
  1716. When this variable is the symbol `cookies', only fontify the
  1717. cookies, not the entire task.
  1718. This may also be an association list of priority faces, whose
  1719. keys are the character values of `org-priority-highest',
  1720. `org-priority-default', and `org-priority-lowest' (the default values
  1721. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1722. color as a string, or a list like `(:background \"Red\")'.
  1723. If it is a color, the variable `org-faces-easy-properties'
  1724. determines if it is a foreground or a background color."
  1725. :group 'org-agenda-line-format
  1726. :type '(choice
  1727. (const :tag "Never" nil)
  1728. (const :tag "Defaults" t)
  1729. (const :tag "Cookies only" cookies)
  1730. (repeat :tag "Specify"
  1731. (list (character :tag "Priority" :value ?A)
  1732. (choice :tag "Face "
  1733. (string :tag "Color")
  1734. (sexp :tag "Face"))))))
  1735. (defcustom org-agenda-day-face-function nil
  1736. "Function called to determine what face should be used to display a day.
  1737. The only argument passed to that function is the day. It should
  1738. returns a face, or nil if does not want to specify a face and let
  1739. the normal rules apply."
  1740. :group 'org-agenda-line-format
  1741. :version "24.1"
  1742. :type '(choice (const nil) (function)))
  1743. (defcustom org-agenda-category-icon-alist nil
  1744. "Alist of category icon to be displayed in agenda views.
  1745. Each entry should have the following format:
  1746. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1747. Where CATEGORY-REGEXP is a regexp matching the categories where
  1748. the icon should be displayed.
  1749. FILE-OR-DATA either a file path or a string containing image data.
  1750. The other fields can be omitted safely if not needed:
  1751. TYPE indicates the image type.
  1752. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1753. image data.
  1754. PROPS are additional image attributes to assign to the image,
  1755. like, e.g. `:ascent center'.
  1756. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1757. If you want to set the display properties yourself, just put a
  1758. list as second element:
  1759. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1760. For example, to display a 16px horizontal space for Emacs
  1761. category, you can use:
  1762. (\"Emacs\" \\='(space . (:width (16))))"
  1763. :group 'org-agenda-line-format
  1764. :version "24.1"
  1765. :type '(alist :key-type (regexp :tag "Regexp matching category")
  1766. :value-type (choice (list :tag "Icon"
  1767. (string :tag "File or data")
  1768. (symbol :tag "Type")
  1769. (boolean :tag "Data?")
  1770. (repeat :tag "Extra image properties" :inline t sexp))
  1771. (list :tag "Display properties" sexp))))
  1772. (defgroup org-agenda-column-view nil
  1773. "Options concerning column view in the agenda."
  1774. :tag "Org Agenda Column View"
  1775. :group 'org-agenda)
  1776. (defcustom org-agenda-view-columns-initially nil
  1777. "When non-nil, switch to columns view right after creating the agenda."
  1778. :group 'org-agenda-column-view
  1779. :type 'boolean
  1780. :version "26.1"
  1781. :package-version '(Org . "9.0")
  1782. :safe #'booleanp)
  1783. (defcustom org-agenda-columns-show-summaries t
  1784. "Non-nil means show summaries for columns displayed in the agenda view."
  1785. :group 'org-agenda-column-view
  1786. :type 'boolean)
  1787. (defcustom org-agenda-columns-compute-summary-properties t
  1788. "Non-nil means recompute all summary properties before column view.
  1789. When column view in the agenda is listing properties that have a summary
  1790. operator, it can go to all relevant buffers and recompute the summaries
  1791. there. This can mean overhead for the agenda column view, but is necessary
  1792. to have thing up to date.
  1793. As a special case, a CLOCKSUM property also makes sure that the clock
  1794. computations are current."
  1795. :group 'org-agenda-column-view
  1796. :type 'boolean)
  1797. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1798. "Non-nil means the duration of an appointment will add to day effort.
  1799. The property to which appointment durations will be added is the one given
  1800. in the option `org-effort-property'. If an appointment does not have
  1801. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1802. is not set, an appointment without end time will not contribute to the time
  1803. estimate."
  1804. :group 'org-agenda-column-view
  1805. :type 'boolean)
  1806. (defcustom org-agenda-auto-exclude-function nil
  1807. "A function called with a tag to decide if it is filtered on \
  1808. \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
  1809. The sole argument to the function, which is called once for each
  1810. possible tag, is a string giving the name of the tag. The
  1811. function should return either nil if the tag should be included
  1812. as normal, \"-<TAG>\" to exclude the tag, or \"+<TAG>\" to exclude
  1813. lines not carrying this tag.
  1814. Note that for the purpose of tag filtering, only the lower-case version of
  1815. all tags will be considered, so that this function will only ever see
  1816. the lower-case version of all tags."
  1817. :group 'org-agenda
  1818. :type '(choice (const nil) (function)))
  1819. (defcustom org-agenda-bulk-custom-functions nil
  1820. "Alist of characters and custom functions for bulk actions.
  1821. For example, this value makes those two functions available:
  1822. \\='((?R set-category)
  1823. (?C bulk-cut))
  1824. With selected entries in an agenda buffer, `B R' will call
  1825. the custom function `set-category' on the selected entries.
  1826. Note that functions in this alist don't need to be quoted.
  1827. You can also specify a function which collects arguments to be
  1828. used for each call to your bulk custom function. The argument
  1829. collecting function will be run once and should return a list of
  1830. arguments to pass to the bulk function. For example:
  1831. \\='((?R set-category get-category))
  1832. Now, `B R' will call the custom `get-category' which would prompt
  1833. the user once for a category. That category is then passed as an
  1834. argument to `set-category' for each entry it's called against."
  1835. :type
  1836. '(alist :key-type character
  1837. :value-type
  1838. (group (function :tag "Bulk Custom Function")
  1839. (choice (function :tag "Bulk Custom Argument Function")
  1840. (const :tag "No Bulk Custom Argument Function" nil))))
  1841. :package-version '(Org . "9.5")
  1842. :group 'org-agenda)
  1843. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1844. "Execute BODY with point at location given by `org-hd-marker' property.
  1845. If STRING is non-nil, the text property will be fetched from position 0
  1846. in that string. If STRING is nil, it will be fetched from the beginning
  1847. of the current line."
  1848. (declare (debug t))
  1849. (org-with-gensyms (marker)
  1850. `(let ((,marker (get-text-property (if ,string 0 (point-at-bol))
  1851. 'org-hd-marker ,string)))
  1852. (with-current-buffer (marker-buffer ,marker)
  1853. (save-excursion
  1854. (goto-char ,marker)
  1855. ,@body)))))
  1856. (defun org-add-agenda-custom-command (entry)
  1857. "Replace or add a command in `org-agenda-custom-commands'.
  1858. This is mostly for hacking and trying a new command - once the command
  1859. works you probably want to add it to `org-agenda-custom-commands' for good."
  1860. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1861. (if ass
  1862. (setcdr ass (cdr entry))
  1863. (push entry org-agenda-custom-commands))))
  1864. (defmacro org-agenda--insert-overriding-header (default)
  1865. "Insert header into agenda view.
  1866. The inserted header depends on `org-agenda-overriding-header'.
  1867. If the empty string, don't insert a header. If any other string,
  1868. insert it as a header. If nil, insert DEFAULT, which should
  1869. evaluate to a string. If a function, call it and insert the
  1870. string that it returns."
  1871. (declare (debug (form)) (indent defun))
  1872. `(cond
  1873. ((not org-agenda-overriding-header) (insert ,default))
  1874. ((equal org-agenda-overriding-header "") nil)
  1875. ((stringp org-agenda-overriding-header)
  1876. (insert (propertize org-agenda-overriding-header
  1877. 'face 'org-agenda-structure)
  1878. "\n"))
  1879. ((functionp org-agenda-overriding-header)
  1880. (insert (funcall org-agenda-overriding-header)))
  1881. (t (user-error "Invalid value for `org-agenda-overriding-header': %S"
  1882. org-agenda-overriding-header))))
  1883. ;;; Define the org-agenda-mode
  1884. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1885. (defvar org-agenda-mode-map (make-sparse-keymap)
  1886. "Keymap for `org-agenda-mode'.")
  1887. (org-remap org-agenda-mode-map 'move-end-of-line 'org-agenda-end-of-line)
  1888. (defvar org-agenda-menu) ; defined later in this file.
  1889. (defvar org-agenda-restrict nil) ; defined later in this file.
  1890. (defvar org-agenda-follow-mode nil)
  1891. (defvar org-agenda-entry-text-mode nil)
  1892. (defvar org-agenda-clockreport-mode nil)
  1893. (defvar org-agenda-show-log nil
  1894. "When non-nil, show the log in the agenda.
  1895. Do not set this directly; instead use
  1896. `org-agenda-start-with-log-mode', which see.")
  1897. (defvar org-agenda-redo-command nil)
  1898. (defvar org-agenda-query-string nil)
  1899. (defvar org-agenda-mode-hook nil
  1900. "Hook run after `org-agenda-mode' is turned on.
  1901. The buffer is still writable when this hook is called.")
  1902. (defvar org-agenda-type nil)
  1903. (defvar org-agenda-force-single-file nil)
  1904. (defvar org-agenda-bulk-marked-entries nil
  1905. "List of markers that refer to marked entries in the agenda.")
  1906. (defvar org-agenda-current-date nil
  1907. "Active date when building the agenda.")
  1908. ;;; Multiple agenda buffers support
  1909. (defcustom org-agenda-sticky nil
  1910. "Non-nil means agenda q key will bury agenda buffers.
  1911. Agenda commands will then show existing buffer instead of generating new ones.
  1912. When nil, `q' will kill the single agenda buffer."
  1913. :group 'org-agenda
  1914. :version "24.3"
  1915. :type 'boolean)
  1916. ;;;###autoload
  1917. (defun org-toggle-sticky-agenda (&optional arg)
  1918. "Toggle `org-agenda-sticky'."
  1919. (interactive "P")
  1920. (let ((new-value (if arg
  1921. (> (prefix-numeric-value arg) 0)
  1922. (not org-agenda-sticky))))
  1923. (if (equal new-value org-agenda-sticky)
  1924. (and (called-interactively-p 'interactive)
  1925. (message "Sticky agenda was already %s"
  1926. (if org-agenda-sticky "enabled" "disabled")))
  1927. (setq org-agenda-sticky new-value)
  1928. (org-agenda-kill-all-agenda-buffers)
  1929. (and (called-interactively-p 'interactive)
  1930. (message "Sticky agenda %s"
  1931. (if org-agenda-sticky "enabled" "disabled"))))))
  1932. (defvar org-agenda-buffer nil
  1933. "Agenda buffer currently being generated.")
  1934. (defvar org-agenda-last-prefix-arg nil)
  1935. (defvar org-agenda-this-buffer-name nil)
  1936. (defvar org-agenda-doing-sticky-redo nil)
  1937. (defvar org-agenda-this-buffer-is-sticky nil)
  1938. (defvar org-agenda-last-indirect-buffer nil
  1939. "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
  1940. (defconst org-agenda-local-vars
  1941. '(org-agenda-this-buffer-name
  1942. org-agenda-undo-list
  1943. org-agenda-pending-undo-list
  1944. org-agenda-follow-mode
  1945. org-agenda-entry-text-mode
  1946. org-agenda-clockreport-mode
  1947. org-agenda-show-log
  1948. org-agenda-redo-command
  1949. org-agenda-query-string
  1950. org-agenda-type
  1951. org-agenda-bulk-marked-entries
  1952. org-agenda-undo-has-started-in
  1953. org-agenda-info
  1954. org-agenda-pre-window-conf
  1955. org-agenda-columns-active
  1956. org-agenda-tag-filter
  1957. org-agenda-category-filter
  1958. org-agenda-top-headline-filter
  1959. org-agenda-regexp-filter
  1960. org-agenda-effort-filter
  1961. org-agenda-markers
  1962. org-agenda-last-search-view-search-was-boolean
  1963. org-agenda-last-indirect-buffer
  1964. org-agenda-filtered-by-category
  1965. org-agenda-filter-form
  1966. org-agenda-cycle-counter
  1967. org-agenda-last-prefix-arg)
  1968. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1969. (defun org-agenda-mode ()
  1970. "Mode for time-sorted view on action items in Org files.
  1971. The following commands are available:
  1972. \\{org-agenda-mode-map}"
  1973. (interactive)
  1974. (ignore-errors (require 'face-remap))
  1975. (let ((agenda-local-vars-to-keep
  1976. '(text-scale-mode-amount
  1977. text-scale-mode
  1978. text-scale-mode-lighter
  1979. face-remapping-alist))
  1980. (save (buffer-local-variables)))
  1981. (kill-all-local-variables)
  1982. (cl-flet ((reset-saved (var-set)
  1983. "Reset variables in VAR-SET to possibly stored value in SAVE."
  1984. (dolist (elem save)
  1985. (pcase elem
  1986. (`(,var . ,val) ;ignore unbound variables
  1987. (when (and val (memq var var-set))
  1988. (set var val)))))))
  1989. (cond (org-agenda-doing-sticky-redo
  1990. ;; Refreshing sticky agenda-buffer
  1991. ;;
  1992. ;; Preserve the value of `org-agenda-local-vars' variables.
  1993. (mapc #'make-local-variable org-agenda-local-vars)
  1994. (reset-saved org-agenda-local-vars)
  1995. (setq-local org-agenda-this-buffer-is-sticky t))
  1996. (org-agenda-sticky
  1997. ;; Creating a sticky Agenda buffer for the first time
  1998. (mapc #'make-local-variable org-agenda-local-vars)
  1999. (setq-local org-agenda-this-buffer-is-sticky t))
  2000. (t
  2001. ;; Creating a non-sticky agenda buffer
  2002. (setq-local org-agenda-this-buffer-is-sticky nil)))
  2003. (mapc #'make-local-variable agenda-local-vars-to-keep)
  2004. (reset-saved agenda-local-vars-to-keep)))
  2005. (setq org-agenda-undo-list nil
  2006. org-agenda-pending-undo-list nil
  2007. org-agenda-bulk-marked-entries nil)
  2008. (setq major-mode 'org-agenda-mode)
  2009. ;; Keep global-font-lock-mode from turning on font-lock-mode
  2010. (setq-local font-lock-global-modes (list 'not major-mode))
  2011. (setq mode-name "Org-Agenda")
  2012. (setq indent-tabs-mode nil)
  2013. (use-local-map org-agenda-mode-map)
  2014. (when org-startup-truncated (setq truncate-lines t))
  2015. (setq-local line-move-visual nil)
  2016. (add-hook 'post-command-hook #'org-agenda-update-agenda-type nil 'local)
  2017. (add-hook 'pre-command-hook #'org-unhighlight nil 'local)
  2018. ;; Make sure properties are removed when copying text
  2019. (if (boundp 'filter-buffer-substring-functions)
  2020. (add-hook 'filter-buffer-substring-functions
  2021. (lambda (fun start end delete)
  2022. (substring-no-properties (funcall fun start end delete)))
  2023. nil t)
  2024. ;; Emacs >= 24.4.
  2025. (add-function :filter-return (local 'filter-buffer-substring-function)
  2026. #'substring-no-properties))
  2027. (unless org-agenda-keep-modes
  2028. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  2029. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  2030. org-agenda-show-log org-agenda-start-with-log-mode
  2031. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode))
  2032. (add-to-invisibility-spec '(org-filtered))
  2033. (add-to-invisibility-spec '(org-link))
  2034. (easy-menu-change
  2035. '("Agenda") "Agenda Files"
  2036. (append
  2037. (list
  2038. (vector
  2039. (if (get 'org-agenda-files 'org-restrict)
  2040. "Restricted to single file"
  2041. "Edit File List")
  2042. '(org-edit-agenda-file-list)
  2043. (not (get 'org-agenda-files 'org-restrict)))
  2044. "--")
  2045. (mapcar #'org-file-menu-entry (org-agenda-files))))
  2046. (org-agenda-set-mode-name)
  2047. (run-mode-hooks 'org-agenda-mode-hook))
  2048. (substitute-key-definition #'undo #'org-agenda-undo
  2049. org-agenda-mode-map global-map)
  2050. (org-defkey org-agenda-mode-map "\C-i" #'org-agenda-goto)
  2051. (org-defkey org-agenda-mode-map [(tab)] #'org-agenda-goto)
  2052. (org-defkey org-agenda-mode-map "\C-m" #'org-agenda-switch-to)
  2053. (org-defkey org-agenda-mode-map "\C-k" #'org-agenda-kill)
  2054. (org-defkey org-agenda-mode-map "\C-c\C-w" #'org-agenda-refile)
  2055. (org-defkey org-agenda-mode-map [(meta down)] #'org-agenda-drag-line-forward)
  2056. (org-defkey org-agenda-mode-map [(meta up)] #'org-agenda-drag-line-backward)
  2057. (org-defkey org-agenda-mode-map "m" #'org-agenda-bulk-mark)
  2058. (org-defkey org-agenda-mode-map "\M-m" #'org-agenda-bulk-toggle)
  2059. (org-defkey org-agenda-mode-map "*" #'org-agenda-bulk-mark-all)
  2060. (org-defkey org-agenda-mode-map "\M-*" #'org-agenda-bulk-toggle-all)
  2061. (org-defkey org-agenda-mode-map "#" #'org-agenda-dim-blocked-tasks)
  2062. (org-defkey org-agenda-mode-map "%" #'org-agenda-bulk-mark-regexp)
  2063. (org-defkey org-agenda-mode-map "u" #'org-agenda-bulk-unmark)
  2064. (org-defkey org-agenda-mode-map "U" #'org-agenda-bulk-unmark-all)
  2065. (org-defkey org-agenda-mode-map "B" #'org-agenda-bulk-action)
  2066. (org-defkey org-agenda-mode-map "k" #'org-agenda-capture)
  2067. (org-defkey org-agenda-mode-map "A" #'org-agenda-append-agenda)
  2068. (org-defkey org-agenda-mode-map "\C-c\C-x!" #'org-reload)
  2069. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" #'org-agenda-archive-default)
  2070. (org-defkey org-agenda-mode-map "\C-c\C-xa" #'org-agenda-toggle-archive-tag)
  2071. (org-defkey org-agenda-mode-map "\C-c\C-xA" #'org-agenda-archive-to-archive-sibling)
  2072. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" #'org-agenda-archive)
  2073. (org-defkey org-agenda-mode-map "\C-c$" #'org-agenda-archive)
  2074. (org-defkey org-agenda-mode-map "$" #'org-agenda-archive)
  2075. (org-defkey org-agenda-mode-map "\C-c\C-o" #'org-agenda-open-link)
  2076. (org-defkey org-agenda-mode-map " " #'org-agenda-show-and-scroll-up)
  2077. (org-defkey org-agenda-mode-map [backspace] #'org-agenda-show-scroll-down)
  2078. (org-defkey org-agenda-mode-map "\d" #'org-agenda-show-scroll-down)
  2079. (org-defkey org-agenda-mode-map [(control shift right)] #'org-agenda-todo-nextset)
  2080. (org-defkey org-agenda-mode-map [(control shift left)] #'org-agenda-todo-previousset)
  2081. (org-defkey org-agenda-mode-map "\C-c\C-xb" #'org-agenda-tree-to-indirect-buffer)
  2082. (org-defkey org-agenda-mode-map "o" #'delete-other-windows)
  2083. (org-defkey org-agenda-mode-map "L" #'org-agenda-recenter)
  2084. (org-defkey org-agenda-mode-map "\C-c\C-t" #'org-agenda-todo)
  2085. (org-defkey org-agenda-mode-map "t" #'org-agenda-todo)
  2086. (org-defkey org-agenda-mode-map "a" #'org-agenda-archive-default-with-confirmation)
  2087. (org-defkey org-agenda-mode-map ":" #'org-agenda-set-tags)
  2088. (org-defkey org-agenda-mode-map "\C-c\C-q" #'org-agenda-set-tags)
  2089. (org-defkey org-agenda-mode-map "." #'org-agenda-goto-today)
  2090. (org-defkey org-agenda-mode-map "j" #'org-agenda-goto-date)
  2091. (org-defkey org-agenda-mode-map "d" #'org-agenda-day-view)
  2092. (org-defkey org-agenda-mode-map "w" #'org-agenda-week-view)
  2093. (org-defkey org-agenda-mode-map "y" #'org-agenda-year-view)
  2094. (org-defkey org-agenda-mode-map "\C-c\C-z" #'org-agenda-add-note)
  2095. (org-defkey org-agenda-mode-map "z" #'org-agenda-add-note)
  2096. (org-defkey org-agenda-mode-map [(shift right)] #'org-agenda-do-date-later)
  2097. (org-defkey org-agenda-mode-map [(shift left)] #'org-agenda-do-date-earlier)
  2098. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] #'org-agenda-do-date-later)
  2099. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] #'org-agenda-do-date-earlier)
  2100. (org-defkey org-agenda-mode-map ">" #'org-agenda-date-prompt)
  2101. (org-defkey org-agenda-mode-map "\C-c\C-s" #'org-agenda-schedule)
  2102. (org-defkey org-agenda-mode-map "\C-c\C-d" #'org-agenda-deadline)
  2103. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  2104. (while l (org-defkey org-agenda-mode-map
  2105. (number-to-string (pop l)) #'digit-argument)))
  2106. (org-defkey org-agenda-mode-map "F" #'org-agenda-follow-mode)
  2107. (org-defkey org-agenda-mode-map "R" #'org-agenda-clockreport-mode)
  2108. (org-defkey org-agenda-mode-map "E" #'org-agenda-entry-text-mode)
  2109. (org-defkey org-agenda-mode-map "l" #'org-agenda-log-mode)
  2110. (org-defkey org-agenda-mode-map "v" #'org-agenda-view-mode-dispatch)
  2111. (org-defkey org-agenda-mode-map "D" #'org-agenda-toggle-diary)
  2112. (org-defkey org-agenda-mode-map "!" #'org-agenda-toggle-deadlines)
  2113. (org-defkey org-agenda-mode-map "G" #'org-agenda-toggle-time-grid)
  2114. (org-defkey org-agenda-mode-map "r" #'org-agenda-redo)
  2115. (org-defkey org-agenda-mode-map "g" #'org-agenda-redo-all)
  2116. (org-defkey org-agenda-mode-map "e" #'org-agenda-set-effort)
  2117. (org-defkey org-agenda-mode-map "\C-c\C-xe" #'org-agenda-set-effort)
  2118. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  2119. #'org-clock-modify-effort-estimate)
  2120. (org-defkey org-agenda-mode-map "\C-c\C-xp" #'org-agenda-set-property)
  2121. (org-defkey org-agenda-mode-map "q" #'org-agenda-quit)
  2122. (org-defkey org-agenda-mode-map "Q" #'org-agenda-Quit)
  2123. (org-defkey org-agenda-mode-map "x" #'org-agenda-exit)
  2124. (org-defkey org-agenda-mode-map "\C-x\C-w" #'org-agenda-write)
  2125. (org-defkey org-agenda-mode-map "\C-x\C-s" #'org-save-all-org-buffers)
  2126. (org-defkey org-agenda-mode-map "s" #'org-save-all-org-buffers)
  2127. (org-defkey org-agenda-mode-map "T" #'org-agenda-show-tags)
  2128. (org-defkey org-agenda-mode-map "n" #'org-agenda-next-line)
  2129. (org-defkey org-agenda-mode-map "p" #'org-agenda-previous-line)
  2130. (org-defkey org-agenda-mode-map "N" #'org-agenda-next-item)
  2131. (org-defkey org-agenda-mode-map "P" #'org-agenda-previous-item)
  2132. (substitute-key-definition #'next-line #'org-agenda-next-line
  2133. org-agenda-mode-map global-map)
  2134. (substitute-key-definition #'previous-line #'org-agenda-previous-line
  2135. org-agenda-mode-map global-map)
  2136. (org-defkey org-agenda-mode-map "\C-c\C-a" #'org-attach)
  2137. (org-defkey org-agenda-mode-map "\C-c\C-n" #'org-agenda-next-date-line)
  2138. (org-defkey org-agenda-mode-map "\C-c\C-p" #'org-agenda-previous-date-line)
  2139. (org-defkey org-agenda-mode-map "\C-c," #'org-agenda-priority)
  2140. (org-defkey org-agenda-mode-map "," #'org-agenda-priority)
  2141. (org-defkey org-agenda-mode-map "i" #'org-agenda-diary-entry)
  2142. (org-defkey org-agenda-mode-map "c" #'org-agenda-goto-calendar)
  2143. (org-defkey org-agenda-mode-map "C" #'org-agenda-convert-date)
  2144. (org-defkey org-agenda-mode-map "M" #'org-agenda-phases-of-moon)
  2145. (org-defkey org-agenda-mode-map "S" #'org-agenda-sunrise-sunset)
  2146. (org-defkey org-agenda-mode-map "h" #'org-agenda-holidays)
  2147. (org-defkey org-agenda-mode-map "H" #'org-agenda-holidays)
  2148. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" #'org-agenda-clock-in)
  2149. (org-defkey org-agenda-mode-map "I" #'org-agenda-clock-in)
  2150. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" #'org-agenda-clock-out)
  2151. (org-defkey org-agenda-mode-map "O" #'org-agenda-clock-out)
  2152. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" #'org-agenda-clock-cancel)
  2153. (org-defkey org-agenda-mode-map "X" #'org-agenda-clock-cancel)
  2154. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" #'org-clock-goto)
  2155. (org-defkey org-agenda-mode-map "J" #'org-agenda-clock-goto)
  2156. (org-defkey org-agenda-mode-map "+" #'org-agenda-priority-up)
  2157. (org-defkey org-agenda-mode-map "-" #'org-agenda-priority-down)
  2158. (org-defkey org-agenda-mode-map [(shift up)] #'org-agenda-priority-up)
  2159. (org-defkey org-agenda-mode-map [(shift down)] #'org-agenda-priority-down)
  2160. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] #'org-agenda-priority-up)
  2161. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] #'org-agenda-priority-down)
  2162. (org-defkey org-agenda-mode-map "f" #'org-agenda-later)
  2163. (org-defkey org-agenda-mode-map "b" #'org-agenda-earlier)
  2164. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" #'org-agenda-columns)
  2165. (org-defkey org-agenda-mode-map "\C-c\C-x>" #'org-agenda-remove-restriction-lock)
  2166. (org-defkey org-agenda-mode-map "\C-c\C-x<" #'org-agenda-set-restriction-lock-from-agenda)
  2167. (org-defkey org-agenda-mode-map "[" #'org-agenda-manipulate-query-add)
  2168. (org-defkey org-agenda-mode-map "]" #'org-agenda-manipulate-query-subtract)
  2169. (org-defkey org-agenda-mode-map "{" #'org-agenda-manipulate-query-add-re)
  2170. (org-defkey org-agenda-mode-map "}" #'org-agenda-manipulate-query-subtract-re)
  2171. (org-defkey org-agenda-mode-map "\\" #'org-agenda-filter-by-tag)
  2172. (org-defkey org-agenda-mode-map "_" #'org-agenda-filter-by-effort)
  2173. (org-defkey org-agenda-mode-map "=" #'org-agenda-filter-by-regexp)
  2174. (org-defkey org-agenda-mode-map "/" #'org-agenda-filter)
  2175. (org-defkey org-agenda-mode-map "|" #'org-agenda-filter-remove-all)
  2176. (org-defkey org-agenda-mode-map "~" #'org-agenda-limit-interactively)
  2177. (org-defkey org-agenda-mode-map "<" #'org-agenda-filter-by-category)
  2178. (org-defkey org-agenda-mode-map "^" #'org-agenda-filter-by-top-headline)
  2179. (org-defkey org-agenda-mode-map ";" #'org-timer-set-timer)
  2180. (org-defkey org-agenda-mode-map "\C-c\C-x_" #'org-timer-stop)
  2181. (org-defkey org-agenda-mode-map "?" #'org-agenda-show-the-flagging-note)
  2182. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" #'org-mobile-pull)
  2183. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" #'org-mobile-push)
  2184. (org-defkey org-agenda-mode-map "\C-c\C-xI" #'org-info-find-node)
  2185. (org-defkey org-agenda-mode-map [mouse-2] #'org-agenda-goto-mouse)
  2186. (org-defkey org-agenda-mode-map [mouse-3] #'org-agenda-show-mouse)
  2187. (org-defkey org-agenda-mode-map [remap forward-paragraph] #'org-agenda-forward-block)
  2188. (org-defkey org-agenda-mode-map [remap backward-paragraph] #'org-agenda-backward-block)
  2189. (org-defkey org-agenda-mode-map "\C-c\C-c" #'org-agenda-ctrl-c-ctrl-c)
  2190. (when org-agenda-mouse-1-follows-link
  2191. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2192. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu."
  2193. '("Agenda"
  2194. ("Agenda Files")
  2195. "--"
  2196. ("Agenda Dates"
  2197. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda)]
  2198. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2199. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2200. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2201. "--"
  2202. ("View"
  2203. ["Day View" org-agenda-day-view
  2204. :active (org-agenda-check-type nil 'agenda)
  2205. :style radio :selected (eq org-agenda-current-span 'day)
  2206. :keys "v d (or just d)"]
  2207. ["Week View" org-agenda-week-view
  2208. :active (org-agenda-check-type nil 'agenda)
  2209. :style radio :selected (eq org-agenda-current-span 'week)
  2210. :keys "v w"]
  2211. ["Fortnight View" org-agenda-fortnight-view
  2212. :active (org-agenda-check-type nil 'agenda)
  2213. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2214. :keys "v t"]
  2215. ["Month View" org-agenda-month-view
  2216. :active (org-agenda-check-type nil 'agenda)
  2217. :style radio :selected (eq org-agenda-current-span 'month)
  2218. :keys "v m"]
  2219. ["Year View" org-agenda-year-view
  2220. :active (org-agenda-check-type nil 'agenda)
  2221. :style radio :selected (eq org-agenda-current-span 'year)
  2222. :keys "v y"]
  2223. "--"
  2224. ["Include Diary" org-agenda-toggle-diary
  2225. :style toggle :selected org-agenda-include-diary
  2226. :active (org-agenda-check-type nil 'agenda)]
  2227. ["Include Deadlines" org-agenda-toggle-deadlines
  2228. :style toggle :selected org-agenda-include-deadlines
  2229. :active (org-agenda-check-type nil 'agenda)]
  2230. ["Use Time Grid" org-agenda-toggle-time-grid
  2231. :style toggle :selected org-agenda-use-time-grid
  2232. :active (org-agenda-check-type nil 'agenda)]
  2233. "--"
  2234. ["Show clock report" org-agenda-clockreport-mode
  2235. :style toggle :selected org-agenda-clockreport-mode
  2236. :active (org-agenda-check-type nil 'agenda)]
  2237. ["Show some entry text" org-agenda-entry-text-mode
  2238. :style toggle :selected org-agenda-entry-text-mode
  2239. :active t]
  2240. "--"
  2241. ["Show Logbook entries" org-agenda-log-mode
  2242. :style toggle :selected org-agenda-show-log
  2243. :active (org-agenda-check-type nil 'agenda)
  2244. :keys "v l (or just l)"]
  2245. ["Include archived trees" org-agenda-archives-mode
  2246. :style toggle :selected org-agenda-archives-mode :active t
  2247. :keys "v a"]
  2248. ["Include archive files" (org-agenda-archives-mode t)
  2249. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2250. :keys "v A"]
  2251. "--"
  2252. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2253. ("Filter current view"
  2254. ["with generic interface" org-agenda-filter t]
  2255. "--"
  2256. ["by category at cursor" org-agenda-filter-by-category t]
  2257. ["by tag" org-agenda-filter-by-tag t]
  2258. ["by effort" org-agenda-filter-by-effort t]
  2259. ["by regexp" org-agenda-filter-by-regexp t]
  2260. ["by top-level headline" org-agenda-filter-by-top-headline t]
  2261. "--"
  2262. ["Remove all filtering" org-agenda-filter-remove-all t]
  2263. "--"
  2264. ["limit" org-agenda-limit-interactively t])
  2265. ["Rebuild buffer" org-agenda-redo t]
  2266. ["Write view to file" org-agenda-write t]
  2267. ["Save all Org buffers" org-save-all-org-buffers t]
  2268. "--"
  2269. ["Show original entry" org-agenda-show t]
  2270. ["Go To (other window)" org-agenda-goto t]
  2271. ["Go To (this window)" org-agenda-switch-to t]
  2272. ["Capture with cursor date" org-agenda-capture t]
  2273. ["Follow Mode" org-agenda-follow-mode
  2274. :style toggle :selected org-agenda-follow-mode :active t]
  2275. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2276. "--"
  2277. ("TODO"
  2278. ["Cycle TODO" org-agenda-todo t]
  2279. ["Next TODO set" org-agenda-todo-nextset t]
  2280. ["Previous TODO set" org-agenda-todo-previousset t]
  2281. ["Add note" org-agenda-add-note t])
  2282. ("Archive/Refile/Delete"
  2283. ["Archive default" org-agenda-archive-default t]
  2284. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2285. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2286. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2287. ["Archive subtree" org-agenda-archive t]
  2288. "--"
  2289. ["Refile" org-agenda-refile t]
  2290. "--"
  2291. ["Delete subtree" org-agenda-kill t])
  2292. ("Bulk action"
  2293. ["Mark entry" org-agenda-bulk-mark t]
  2294. ["Mark all" org-agenda-bulk-mark-all t]
  2295. ["Unmark entry" org-agenda-bulk-unmark t]
  2296. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2297. ["Toggle mark" org-agenda-bulk-toggle t]
  2298. ["Toggle all" org-agenda-bulk-toggle-all t]
  2299. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2300. ["Act on all marked" org-agenda-bulk-action t]
  2301. "--"
  2302. ("Tags and Properties"
  2303. ["Show all Tags" org-agenda-show-tags t]
  2304. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2305. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2306. "--"
  2307. ["Column View" org-columns t])
  2308. ("Deadline/Schedule"
  2309. ["Schedule" org-agenda-schedule t]
  2310. ["Set Deadline" org-agenda-deadline t]
  2311. "--"
  2312. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda)]
  2313. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda)]
  2314. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u S-right"]
  2315. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u S-left"]
  2316. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-right"]
  2317. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-left"]
  2318. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda)])
  2319. ("Clock and Effort"
  2320. ["Clock in" org-agenda-clock-in t]
  2321. ["Clock out" org-agenda-clock-out t]
  2322. ["Clock cancel" org-agenda-clock-cancel t]
  2323. ["Goto running clock" org-clock-goto t]
  2324. "--"
  2325. ["Set Effort" org-agenda-set-effort t]
  2326. ["Change clocked effort" org-clock-modify-effort-estimate
  2327. (org-clock-is-active)])
  2328. ("Priority"
  2329. ["Set Priority" org-agenda-priority t]
  2330. ["Increase Priority" org-agenda-priority-up t]
  2331. ["Decrease Priority" org-agenda-priority-down t]
  2332. ["Show Priority" org-priority-show t])
  2333. ("Calendar/Diary"
  2334. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda)]
  2335. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda)]
  2336. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda)]
  2337. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda)]
  2338. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda)]
  2339. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda)]
  2340. "--"
  2341. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2342. "--"
  2343. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2344. "--"
  2345. ("MobileOrg"
  2346. ["Push Files and Views" org-mobile-push t]
  2347. ["Get Captured and Flagged" org-mobile-pull t]
  2348. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "\\[org-agenda] ?"]
  2349. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2350. "--"
  2351. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2352. "--"
  2353. ["Quit" org-agenda-quit t]
  2354. ["Exit and Release Buffers" org-agenda-exit t]
  2355. ))
  2356. ;;; Agenda undo
  2357. (defvar org-agenda-allow-remote-undo t
  2358. "Non-nil means allow remote undo from the agenda buffer.")
  2359. (defvar org-agenda-undo-has-started-in nil
  2360. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2361. (defun org-agenda-undo ()
  2362. "Undo a remote editing step in the agenda.
  2363. This undoes changes both in the agenda buffer and in the remote buffer
  2364. that have been changed along."
  2365. (interactive)
  2366. (or org-agenda-allow-remote-undo
  2367. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2368. (when (not (eq this-command last-command))
  2369. (setq org-agenda-undo-has-started-in nil
  2370. org-agenda-pending-undo-list org-agenda-undo-list))
  2371. (when (not org-agenda-pending-undo-list)
  2372. (user-error "No further undo information"))
  2373. (let* ((entry (pop org-agenda-pending-undo-list))
  2374. buf line cmd rembuf)
  2375. (setq cmd (pop entry) line (pop entry))
  2376. (setq rembuf (nth 2 entry))
  2377. (org-with-remote-undo rembuf
  2378. (while (bufferp (setq buf (pop entry)))
  2379. (when (pop entry)
  2380. (with-current-buffer buf
  2381. (let (;; (last-undo-buffer buf)
  2382. (inhibit-read-only t))
  2383. (unless (memq buf org-agenda-undo-has-started-in)
  2384. (push buf org-agenda-undo-has-started-in)
  2385. (make-local-variable 'pending-undo-list)
  2386. (undo-start))
  2387. (while (and pending-undo-list
  2388. (listp pending-undo-list)
  2389. (not (car pending-undo-list)))
  2390. (pop pending-undo-list))
  2391. (undo-more 1))))))
  2392. (org-goto-line line)
  2393. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2394. (defun org-verify-change-for-undo (l1 l2)
  2395. "Verify that a real change occurred between the undo lists L1 and L2."
  2396. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2397. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2398. (not (eq l1 l2)))
  2399. ;;; Agenda dispatch
  2400. (defvar org-agenda-restrict-begin (make-marker))
  2401. (defvar org-agenda-restrict-end (make-marker))
  2402. (defvar org-agenda-last-dispatch-buffer nil)
  2403. (defvar org-agenda-overriding-restriction nil)
  2404. (defcustom org-agenda-custom-commands-contexts nil
  2405. "Alist of custom agenda keys and contextual rules.
  2406. For example, if you have a custom agenda command \"p\" and you
  2407. want this command to be accessible only from plain text files,
  2408. use this:
  2409. \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
  2410. Here are the available contexts definitions:
  2411. in-file: command displayed only in matching files
  2412. in-mode: command displayed only in matching modes
  2413. not-in-file: command not displayed in matching files
  2414. not-in-mode: command not displayed in matching modes
  2415. in-buffer: command displayed only in matching buffers
  2416. not-in-buffer: command not displayed in matching buffers
  2417. [function]: a custom function taking no argument
  2418. If you define several checks, the agenda command will be
  2419. accessible if there is at least one valid check.
  2420. You can also bind a key to another agenda custom command
  2421. depending on contextual rules.
  2422. \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
  2423. Here it means: in .txt files, use \"p\" as the key for the
  2424. agenda command otherwise associated with \"q\". (The command
  2425. originally associated with \"q\" is not displayed to avoid
  2426. duplicates.)"
  2427. :version "24.3"
  2428. :group 'org-agenda-custom-commands
  2429. :type '(repeat (list :tag "Rule"
  2430. (string :tag " Agenda key")
  2431. (string :tag "Replace by command")
  2432. (repeat :tag "Available when"
  2433. (choice
  2434. (cons :tag "Condition"
  2435. (choice
  2436. (const :tag "In file" in-file)
  2437. (const :tag "Not in file" not-in-file)
  2438. (const :tag "In buffer" in-buffer)
  2439. (const :tag "Not in buffer" not-in-buffer)
  2440. (const :tag "In mode" in-mode)
  2441. (const :tag "Not in mode" not-in-mode))
  2442. (regexp))
  2443. (function :tag "Custom function"))))))
  2444. (defcustom org-agenda-max-entries nil
  2445. "Maximum number of entries to display in an agenda.
  2446. This can be nil (no limit) or an integer or an alist of agenda
  2447. types with an associated number of entries to display in this
  2448. type."
  2449. :version "24.4"
  2450. :package-version '(Org . "8.0")
  2451. :group 'org-agenda-custom-commands
  2452. :type '(choice (symbol :tag "No limit" nil)
  2453. (integer :tag "Max number of entries")
  2454. (repeat
  2455. (cons (choice :tag "Agenda type"
  2456. (const agenda)
  2457. (const todo)
  2458. (const tags)
  2459. (const search))
  2460. (integer :tag "Max number of entries")))))
  2461. (defcustom org-agenda-max-todos nil
  2462. "Maximum number of TODOs to display in an agenda.
  2463. This can be nil (no limit) or an integer or an alist of agenda
  2464. types with an associated number of entries to display in this
  2465. type."
  2466. :version "24.4"
  2467. :package-version '(Org . "8.0")
  2468. :group 'org-agenda-custom-commands
  2469. :type '(choice (symbol :tag "No limit" nil)
  2470. (integer :tag "Max number of TODOs")
  2471. (repeat
  2472. (cons (choice :tag "Agenda type"
  2473. (const agenda)
  2474. (const todo)
  2475. (const tags)
  2476. (const search))
  2477. (integer :tag "Max number of TODOs")))))
  2478. (defcustom org-agenda-max-tags nil
  2479. "Maximum number of tagged entries to display in an agenda.
  2480. This can be nil (no limit) or an integer or an alist of agenda
  2481. types with an associated number of entries to display in this
  2482. type."
  2483. :version "24.4"
  2484. :package-version '(Org . "8.0")
  2485. :group 'org-agenda-custom-commands
  2486. :type '(choice (symbol :tag "No limit" nil)
  2487. (integer :tag "Max number of tagged entries")
  2488. (repeat
  2489. (cons (choice :tag "Agenda type"
  2490. (const agenda)
  2491. (const todo)
  2492. (const tags)
  2493. (const search))
  2494. (integer :tag "Max number of tagged entries")))))
  2495. (defcustom org-agenda-max-effort nil
  2496. "Maximum cumulated effort duration for the agenda.
  2497. This can be nil (no limit) or a number of minutes (as an integer)
  2498. or an alist of agenda types with an associated number of minutes
  2499. to limit entries to in this type."
  2500. :version "24.4"
  2501. :package-version '(Org . "8.0")
  2502. :group 'org-agenda-custom-commands
  2503. :type '(choice (symbol :tag "No limit" nil)
  2504. (integer :tag "Max number of minutes")
  2505. (repeat
  2506. (cons (choice :tag "Agenda type"
  2507. (const agenda)
  2508. (const todo)
  2509. (const tags)
  2510. (const search))
  2511. (integer :tag "Max number of minutes")))))
  2512. (defvar org-agenda-keep-restricted-file-list nil)
  2513. (defvar org-keys nil)
  2514. (defvar org-match nil)
  2515. ;;;###autoload
  2516. (defun org-agenda (&optional arg keys restriction)
  2517. "Dispatch agenda commands to collect entries to the agenda buffer.
  2518. Prompts for a command to execute. Any prefix arg will be passed
  2519. on to the selected command. The default selections are:
  2520. a Call `org-agenda-list' to display the agenda for current day or week.
  2521. t Call `org-todo-list' to display the global todo list.
  2522. T Call `org-todo-list' to display the global todo list, select only
  2523. entries with a specific TODO keyword (the user gets a prompt).
  2524. m Call `org-tags-view' to display headlines with tags matching
  2525. a condition (the user is prompted for the condition).
  2526. M Like `m', but select only TODO entries, no ordinary headlines.
  2527. e Export views to associated files.
  2528. s Search entries for keywords.
  2529. S Search entries for keywords, only with TODO keywords.
  2530. / Multi occur across all agenda files and also files listed
  2531. in `org-agenda-text-search-extra-files'.
  2532. < Restrict agenda commands to buffer, subtree, or region.
  2533. Press several times to get the desired effect.
  2534. > Remove a previous restriction.
  2535. # List \"stuck\" projects.
  2536. ! Configure what \"stuck\" means.
  2537. C Configure custom agenda commands.
  2538. More commands can be added by configuring the variable
  2539. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2540. searches can be pre-defined in this way.
  2541. If the current buffer is in Org mode and visiting a file, you can also
  2542. first press `<' once to indicate that the agenda should be temporarily
  2543. \(until the next use of `\\[org-agenda]') restricted to the current file.
  2544. Pressing `<' twice means to restrict to the current subtree or region
  2545. \(if active)."
  2546. (interactive "P")
  2547. (catch 'exit
  2548. (let* ((org-keys keys)
  2549. (prefix-descriptions nil)
  2550. (org-agenda-buffer-name org-agenda-buffer-name)
  2551. (org-agenda-window-setup (if (equal (buffer-name)
  2552. org-agenda-buffer-name)
  2553. 'current-window
  2554. org-agenda-window-setup))
  2555. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2556. (org-agenda-custom-commands
  2557. ;; normalize different versions
  2558. (delq nil
  2559. (mapcar
  2560. (lambda (x)
  2561. (cond ((stringp (cdr x))
  2562. (push x prefix-descriptions)
  2563. nil)
  2564. ((stringp (nth 1 x)) x)
  2565. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2566. (t (cons (car x) (cons "" (cdr x))))))
  2567. org-agenda-custom-commands)))
  2568. (org-agenda-custom-commands
  2569. (org-contextualize-keys
  2570. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2571. ;; (buf (current-buffer))
  2572. (bfn (buffer-file-name (buffer-base-buffer)))
  2573. entry type org-match lprops ans) ;; key
  2574. ;; Turn off restriction unless there is an overriding one,
  2575. (unless org-agenda-overriding-restriction
  2576. (unless org-agenda-keep-restricted-file-list
  2577. ;; There is a request to keep the file list in place
  2578. (put 'org-agenda-files 'org-restrict nil))
  2579. (setq org-agenda-restrict nil)
  2580. (move-marker org-agenda-restrict-begin nil)
  2581. (move-marker org-agenda-restrict-end nil))
  2582. ;; Delete old local properties
  2583. (put 'org-agenda-redo-command 'org-lprops nil)
  2584. ;; Delete previously set last-arguments
  2585. (put 'org-agenda-redo-command 'last-args nil)
  2586. ;; Remember where this call originated
  2587. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2588. (unless org-keys
  2589. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2590. org-keys (car ans)
  2591. restriction (cdr ans)))
  2592. ;; If we have sticky agenda buffers, set a name for the buffer,
  2593. ;; depending on the invoking keys. The user may still set this
  2594. ;; as a command option, which will overwrite what we do here.
  2595. (when org-agenda-sticky
  2596. (setq org-agenda-buffer-name
  2597. (format "*Org Agenda(%s)*" org-keys)))
  2598. ;; Establish the restriction, if any
  2599. (when (and (not org-agenda-overriding-restriction) restriction)
  2600. (put 'org-agenda-files 'org-restrict (list bfn))
  2601. (cond
  2602. ((eq restriction 'region)
  2603. (setq org-agenda-restrict (current-buffer))
  2604. (move-marker org-agenda-restrict-begin (region-beginning))
  2605. (move-marker org-agenda-restrict-end (region-end)))
  2606. ((eq restriction 'subtree)
  2607. (save-excursion
  2608. (setq org-agenda-restrict (current-buffer))
  2609. (org-back-to-heading t)
  2610. (move-marker org-agenda-restrict-begin (point))
  2611. (move-marker org-agenda-restrict-end
  2612. (progn (org-end-of-subtree t)))))
  2613. ((and (eq restriction 'buffer)
  2614. (or (< 1 (point-min))
  2615. (< (point-max) (1+ (buffer-size)))))
  2616. (setq org-agenda-restrict (current-buffer))
  2617. (move-marker org-agenda-restrict-begin (point-min))
  2618. (move-marker org-agenda-restrict-end (point-max)))))
  2619. ;; For example the todo list should not need it (but does...)
  2620. (cond
  2621. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2622. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2623. (progn
  2624. ;; FIXME: Is (nth 3 entry) supposed to have access (via dynvars)
  2625. ;; to some of the local variables? There's no doc about
  2626. ;; that for `org-agenda-custom-commands'.
  2627. (setq type (nth 2 entry) org-match (eval (nth 3 entry) t)
  2628. lprops (nth 4 entry))
  2629. (when org-agenda-sticky
  2630. (setq org-agenda-buffer-name
  2631. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2632. (format "*Org Agenda(%s)*" org-keys))))
  2633. (put 'org-agenda-redo-command 'org-lprops lprops)
  2634. (cl-progv
  2635. (mapcar #'car lprops)
  2636. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  2637. (pcase type
  2638. (`agenda
  2639. (org-agenda-list current-prefix-arg))
  2640. (`agenda*
  2641. (org-agenda-list current-prefix-arg nil nil t))
  2642. (`alltodo
  2643. (org-todo-list current-prefix-arg))
  2644. (`search
  2645. (org-search-view current-prefix-arg org-match nil))
  2646. (`stuck
  2647. (org-agenda-list-stuck-projects current-prefix-arg))
  2648. (`tags
  2649. (org-tags-view current-prefix-arg org-match))
  2650. (`tags-todo
  2651. (org-tags-view '(4) org-match))
  2652. (`todo
  2653. (org-todo-list org-match))
  2654. (`tags-tree
  2655. (org-check-for-org-mode)
  2656. (org-match-sparse-tree current-prefix-arg org-match))
  2657. (`todo-tree
  2658. (org-check-for-org-mode)
  2659. (org-occur (concat "^" org-outline-regexp "[ \t]*"
  2660. (regexp-quote org-match) "\\>")))
  2661. (`occur-tree
  2662. (org-check-for-org-mode)
  2663. (org-occur org-match))
  2664. ((pred functionp)
  2665. (funcall type org-match))
  2666. ;; FIXME: Will signal an error since it's not `functionp'!
  2667. ((pred fboundp) (funcall type org-match))
  2668. (_ (user-error "Invalid custom agenda command type %s" type)))))
  2669. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2670. ((equal org-keys "C")
  2671. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2672. (customize-variable 'org-agenda-custom-commands))
  2673. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2674. ((equal org-keys "s") (call-interactively 'org-search-view))
  2675. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2676. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2677. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2678. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2679. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2680. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2681. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2682. (add-hook
  2683. 'post-command-hook
  2684. (lambda ()
  2685. (unless (current-message)
  2686. (let* ((m (org-agenda-get-any-marker))
  2687. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2688. (when note
  2689. (message "FLAGGING-NOTE ([?] for more info): %s"
  2690. (org-add-props
  2691. (replace-regexp-in-string
  2692. "\\\\n" "//"
  2693. (copy-sequence note))
  2694. nil 'face 'org-warning))))))
  2695. t t))
  2696. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2697. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2698. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2699. (t (user-error "Invalid agenda key"))))))
  2700. (defvar org-agenda-multi)
  2701. (defun org-agenda-append-agenda ()
  2702. "Append another agenda view to the current one.
  2703. This function allows interactive building of block agendas.
  2704. Agenda views are separated by `org-agenda-block-separator'."
  2705. (interactive)
  2706. (unless (derived-mode-p 'org-agenda-mode)
  2707. (user-error "Can only append from within agenda buffer"))
  2708. (let ((org-agenda-multi t))
  2709. (org-agenda)
  2710. (widen)
  2711. (org-agenda-finalize)
  2712. (setq buffer-read-only t)
  2713. (org-agenda-fit-window-to-buffer)))
  2714. (defun org-agenda-normalize-custom-commands (cmds)
  2715. "Normalize custom commands CMDS."
  2716. (delq nil
  2717. (mapcar
  2718. (lambda (x)
  2719. (cond ((stringp (cdr x)) nil)
  2720. ((stringp (nth 1 x)) x)
  2721. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2722. (t (cons (car x) (cons "" (cdr x))))))
  2723. cmds)))
  2724. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2725. "The user interface for selecting an agenda command."
  2726. (catch 'exit
  2727. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2728. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2729. (region-p (org-region-active-p))
  2730. (custom org-agenda-custom-commands)
  2731. (selstring "")
  2732. restriction second-time
  2733. c entry key type match prefixes rmheader header-end custom1 desc
  2734. line lines left right n n1)
  2735. (save-window-excursion
  2736. (delete-other-windows)
  2737. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2738. (erase-buffer)
  2739. (insert (eval-when-compile
  2740. (let ((header
  2741. (copy-sequence
  2742. "Press key for an agenda command:
  2743. -------------------------------- < Buffer, subtree/region restriction
  2744. a Agenda for current week or day > Remove restriction
  2745. t List of all TODO entries e Export agenda views
  2746. m Match a TAGS/PROP/TODO query T Entries with special TODO kwd
  2747. s Search for keywords M Like m, but only TODO entries
  2748. / Multi-occur S Like s, but only TODO entries
  2749. ? Find :FLAGGED: entries C Configure custom agenda commands
  2750. * Toggle sticky agenda views # List stuck projects (!=configure)
  2751. "))
  2752. (start 0))
  2753. (while (string-match
  2754. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2755. header start)
  2756. (setq start (match-end 0))
  2757. (add-text-properties (match-beginning 2) (match-end 2)
  2758. '(face bold) header))
  2759. header)))
  2760. (setq header-end (point-marker))
  2761. (while t
  2762. (setq custom1 custom)
  2763. (when (eq rmheader t)
  2764. (org-goto-line 1)
  2765. (re-search-forward ":" nil t)
  2766. (delete-region (match-end 0) (point-at-eol))
  2767. (forward-char 1)
  2768. (looking-at "-+")
  2769. (delete-region (match-end 0) (point-at-eol))
  2770. (move-marker header-end (match-end 0)))
  2771. (goto-char header-end)
  2772. (delete-region (point) (point-max))
  2773. ;; Produce all the lines that describe custom commands and prefixes
  2774. (setq lines nil)
  2775. (while (setq entry (pop custom1))
  2776. (setq key (car entry) desc (nth 1 entry)
  2777. type (nth 2 entry)
  2778. match (nth 3 entry))
  2779. (if (> (length key) 1)
  2780. (cl-pushnew (string-to-char key) prefixes :test #'equal)
  2781. (setq line
  2782. (format
  2783. "%-4s%-14s"
  2784. (org-add-props (copy-sequence key)
  2785. '(face bold))
  2786. (cond
  2787. ((string-match "\\S-" desc) desc)
  2788. ((eq type 'agenda) "Agenda for current week or day")
  2789. ((eq type 'agenda*) "Appointments for current week or day")
  2790. ((eq type 'alltodo) "List of all TODO entries")
  2791. ((eq type 'search) "Word search")
  2792. ((eq type 'stuck) "List of stuck projects")
  2793. ((eq type 'todo) "TODO keyword")
  2794. ((eq type 'tags) "Tags query")
  2795. ((eq type 'tags-todo) "Tags (TODO)")
  2796. ((eq type 'tags-tree) "Tags tree")
  2797. ((eq type 'todo-tree) "TODO kwd tree")
  2798. ((eq type 'occur-tree) "Occur tree")
  2799. ((functionp type) (if (symbolp type)
  2800. (symbol-name type)
  2801. "Lambda expression"))
  2802. (t "???"))))
  2803. (cond
  2804. ((not (org-string-nw-p match)) nil)
  2805. (org-agenda-menu-show-matcher
  2806. (setq line
  2807. (concat line ": "
  2808. (cond
  2809. ((stringp match)
  2810. (propertize match 'face 'org-warning))
  2811. ((listp type)
  2812. (format "set of %d commands" (length type)))))))
  2813. (t
  2814. (org-add-props line nil 'help-echo (concat "Matcher: " match))))
  2815. (push line lines)))
  2816. (setq lines (nreverse lines))
  2817. (when prefixes
  2818. (mapc (lambda (x)
  2819. (push
  2820. (format "%s %s"
  2821. (org-add-props (char-to-string x)
  2822. nil 'face 'bold)
  2823. (or (cdr (assoc (concat selstring
  2824. (char-to-string x))
  2825. prefix-descriptions))
  2826. "Prefix key"))
  2827. lines))
  2828. prefixes))
  2829. ;; Check if we should display in two columns
  2830. (if org-agenda-menu-two-columns
  2831. (progn
  2832. (setq n (length lines)
  2833. n1 (+ (/ n 2) (mod n 2))
  2834. right (nthcdr n1 lines)
  2835. left (copy-sequence lines))
  2836. (setcdr (nthcdr (1- n1) left) nil))
  2837. (setq left lines right nil))
  2838. (while left
  2839. (insert "\n" (pop left))
  2840. (when right
  2841. (if (< (current-column) 40)
  2842. (move-to-column 40 t)
  2843. (insert " "))
  2844. (insert (pop right))))
  2845. ;; Make the window the right size
  2846. (goto-char (point-min))
  2847. (if second-time
  2848. (when (not (pos-visible-in-window-p (point-max)))
  2849. (org-fit-window-to-buffer))
  2850. (setq second-time t)
  2851. (org-fit-window-to-buffer))
  2852. ;; Hint to navigation if window too small for all information
  2853. (setq header-line-format
  2854. (when (not (pos-visible-in-window-p (point-max)))
  2855. "Use C-v, M-v, C-n or C-p to navigate."))
  2856. ;; Ask for selection
  2857. (cl-loop
  2858. do (progn
  2859. (message "Press key for agenda command%s:"
  2860. (if (or restrict-ok org-agenda-overriding-restriction)
  2861. (if org-agenda-overriding-restriction
  2862. " (restriction lock active)"
  2863. (if restriction
  2864. (format " (restricted to %s)" restriction)
  2865. " (unrestricted)"))
  2866. ""))
  2867. (setq c (read-char-exclusive)))
  2868. until (not (memq c '(14 16 22 134217846)))
  2869. do (org-scroll c))
  2870. (message "")
  2871. (cond
  2872. ((assoc (char-to-string c) custom)
  2873. (setq selstring (concat selstring (char-to-string c)))
  2874. (throw 'exit (cons selstring restriction)))
  2875. ((memq c prefixes)
  2876. (setq selstring (concat selstring (char-to-string c))
  2877. prefixes nil
  2878. rmheader (or rmheader t)
  2879. custom (delq nil (mapcar
  2880. (lambda (x)
  2881. (if (or (= (length (car x)) 1)
  2882. (/= (string-to-char (car x)) c))
  2883. nil
  2884. (cons (substring (car x) 1) (cdr x))))
  2885. custom))))
  2886. ((eq c ?*)
  2887. (call-interactively 'org-toggle-sticky-agenda)
  2888. (sit-for 2))
  2889. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2890. (message "Restriction is only possible in Org buffers")
  2891. (ding) (sit-for 1))
  2892. ((eq c ?1)
  2893. (org-agenda-remove-restriction-lock 'noupdate)
  2894. (setq restriction 'buffer))
  2895. ((eq c ?0)
  2896. (org-agenda-remove-restriction-lock 'noupdate)
  2897. (setq restriction (if region-p 'region 'subtree)))
  2898. ((eq c ?<)
  2899. (org-agenda-remove-restriction-lock 'noupdate)
  2900. (setq restriction
  2901. (cond
  2902. ((eq restriction 'buffer)
  2903. (if region-p 'region 'subtree))
  2904. ((memq restriction '(subtree region))
  2905. nil)
  2906. (t 'buffer))))
  2907. ((eq c ?>)
  2908. (org-agenda-remove-restriction-lock 'noupdate)
  2909. (setq restriction nil))
  2910. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2911. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2912. ((and (> (length selstring) 0) (eq c ?\d))
  2913. (delete-window)
  2914. (org-agenda-get-restriction-and-command prefix-descriptions))
  2915. ((equal c ?q) (user-error "Abort"))
  2916. (t (user-error "Invalid key %c" c))))))))
  2917. (defun org-agenda-fit-window-to-buffer ()
  2918. "Fit the window to the buffer size."
  2919. (and (memq org-agenda-window-setup '(reorganize-frame))
  2920. (fboundp 'fit-window-to-buffer)
  2921. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2922. (= (car org-agenda-window-frame-fractions) 1.0))
  2923. (delete-other-windows)
  2924. (org-fit-window-to-buffer
  2925. nil
  2926. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2927. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2928. (defvar org-cmd nil)
  2929. (defvar org-agenda-overriding-cmd nil)
  2930. (defvar org-agenda-overriding-arguments nil)
  2931. (defvar org-agenda-overriding-cmd-arguments nil)
  2932. (defun org-let (list &rest body) ;FIXME: So many kittens are suffering here.
  2933. (declare (indent 1) (obsolete cl-progv "2021"))
  2934. (eval (cons 'let (cons list body))))
  2935. (defun org-let2 (list1 list2 &rest body) ;FIXME: Where did our karma go?
  2936. (declare (indent 2) (obsolete cl-progv "2021"))
  2937. (eval (cons 'let (cons list1 (list (cons 'let (cons list2 body)))))))
  2938. (defun org-agenda-run-series (name series)
  2939. "Run agenda NAME as a SERIES of agenda commands."
  2940. (let* ((gprops (nth 1 series))
  2941. (gvars (mapcar #'car gprops))
  2942. (gvals (mapcar (lambda (binding) (eval (cadr binding) t)) gprops)))
  2943. (cl-progv gvars gvals (org-agenda-prepare name))
  2944. ;; We need to reset agenda markers here, because when constructing a
  2945. ;; block agenda, the individual blocks do not do that.
  2946. (org-agenda-reset-markers)
  2947. (with-no-warnings
  2948. (defvar match)) ;Used via the `eval' below.
  2949. (let* ((org-agenda-multi t)
  2950. ;; FIXME: Redo should contain lists of (FUNS . ARGS) rather
  2951. ;; than expressions, so you don't need to `quote' the args
  2952. ;; and you just need to `apply' instead of `eval' when using it.
  2953. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2954. (cmds (car series))
  2955. match
  2956. org-cmd type lprops)
  2957. (while (setq org-cmd (pop cmds))
  2958. (setq type (car org-cmd))
  2959. (setq match (eval (nth 1 org-cmd) t))
  2960. (setq lprops (nth 2 org-cmd))
  2961. (let ((org-agenda-overriding-arguments
  2962. (if (eq org-agenda-overriding-cmd org-cmd)
  2963. (or org-agenda-overriding-arguments
  2964. org-agenda-overriding-cmd-arguments)))
  2965. (lvars (mapcar #'car lprops))
  2966. (lvals (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)))
  2967. (cl-progv (append gvars lvars) (append gvals lvals)
  2968. (pcase type
  2969. (`agenda
  2970. (call-interactively 'org-agenda-list))
  2971. (`agenda*
  2972. (funcall 'org-agenda-list nil nil t))
  2973. (`alltodo
  2974. (call-interactively 'org-todo-list))
  2975. (`search
  2976. (org-search-view current-prefix-arg match nil))
  2977. (`stuck
  2978. (call-interactively 'org-agenda-list-stuck-projects))
  2979. (`tags
  2980. (org-tags-view current-prefix-arg match))
  2981. (`tags-todo
  2982. (org-tags-view '(4) match))
  2983. (`todo
  2984. (org-todo-list match))
  2985. ((pred fboundp)
  2986. (funcall type match))
  2987. (_ (error "Invalid type in command series"))))))
  2988. (widen)
  2989. (let ((inhibit-read-only t))
  2990. (add-text-properties (point-min) (point-max)
  2991. `(org-series t org-series-redo-cmd ,redo)))
  2992. (setq org-agenda-redo-command redo)
  2993. (goto-char (point-min)))
  2994. (org-agenda-fit-window-to-buffer)
  2995. (cl-progv gvars gvals (org-agenda-finalize))))
  2996. (defun org-agenda--split-plist (plist)
  2997. ;; We could/should arguably use `map-keys' and `map-values'.
  2998. (let (keys vals)
  2999. (while plist
  3000. (push (pop plist) keys)
  3001. (push (pop plist) vals))
  3002. (cons (nreverse keys) (nreverse vals))))
  3003. ;;;###autoload
  3004. (defmacro org-batch-agenda (cmd-key &rest parameters)
  3005. "Run an agenda command in batch mode and send the result to STDOUT.
  3006. If CMD-KEY is a string of length 1, it is used as a key in
  3007. `org-agenda-custom-commands' and triggers this command. If it is a
  3008. longer string it is used as a tags/todo match string.
  3009. Parameters are alternating variable names and values that will be bound
  3010. before running the agenda command."
  3011. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3012. `(org--batch-agenda ,cmd-key ',vars (list ,@exps))))
  3013. (defun org--batch-agenda (cmd-key vars vals)
  3014. ;; `org-batch-agenda' is a macro because every other "parameter" is
  3015. ;; a variable name rather than an expression to evaluate. Yuck!
  3016. (cl-progv vars vals
  3017. (let (org-agenda-sticky)
  3018. (if (> (length cmd-key) 1)
  3019. (org-tags-view nil cmd-key)
  3020. (org-agenda nil cmd-key))))
  3021. (set-buffer org-agenda-buffer-name)
  3022. (princ (buffer-string)))
  3023. (defvar org-agenda-info nil)
  3024. ;;;###autoload
  3025. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  3026. "Run an agenda command in batch mode and send the result to STDOUT.
  3027. If CMD-KEY is a string of length 1, it is used as a key in
  3028. `org-agenda-custom-commands' and triggers this command. If it is a
  3029. longer string it is used as a tags/todo match string.
  3030. Parameters are alternating variable names and values that will be bound
  3031. before running the agenda command.
  3032. The output gives a line for each selected agenda item. Each
  3033. item is a list of comma-separated values, like this:
  3034. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  3035. category The category of the item
  3036. head The headline, without TODO kwd, TAGS and PRIORITY
  3037. type The type of the agenda entry, can be
  3038. todo selected in TODO match
  3039. tagsmatch selected in tags match
  3040. diary imported from diary
  3041. deadline a deadline on given date
  3042. scheduled scheduled on given date
  3043. timestamp entry has timestamp on given date
  3044. closed entry was closed on given date
  3045. upcoming-deadline warning about deadline
  3046. past-scheduled forwarded scheduled item
  3047. block entry has date block including g. date
  3048. todo The todo keyword, if any
  3049. tags All tags including inherited ones, separated by colons
  3050. date The relevant date, like 2007-2-14
  3051. time The time, like 15:00-16:50
  3052. extra String with extra planning info
  3053. priority-l The priority letter if any was given
  3054. priority-n The computed numerical priority
  3055. agenda-day The day in the agenda where this is listed"
  3056. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3057. `(org--batch-agenda-csv ,cmd-key ',vars (list ,@exps))))
  3058. (defun org--batch-agenda-csv (cmd-key vars vals)
  3059. ;; `org-batch-agenda-csv' is a macro because every other "parameter" is
  3060. ;; a variable name rather than an expression to evaluate. Yuck!
  3061. (let ((org-agenda-remove-tags t))
  3062. (cl-progv vars vals
  3063. ;; FIXME: Shouldn't this be 1 (see commit 10173ad6d610b)?
  3064. (if (> (length cmd-key) 2)
  3065. (org-tags-view nil cmd-key)
  3066. (org-agenda nil cmd-key))))
  3067. (set-buffer org-agenda-buffer-name)
  3068. (let ((lines (org-split-string (buffer-string) "\n")))
  3069. (dolist (line lines)
  3070. (when (get-text-property 0 'org-category line)
  3071. (setq org-agenda-info
  3072. (org-fix-agenda-info (text-properties-at 0 line)))
  3073. (princ
  3074. (mapconcat #'org-agenda-export-csv-mapper
  3075. '(org-category txt type todo tags date time extra
  3076. priority-letter priority agenda-day)
  3077. ","))
  3078. (princ "\n")))))
  3079. (defun org-fix-agenda-info (props)
  3080. "Make sure all properties on an agenda item have a canonical form.
  3081. This ensures the export commands can easily use it."
  3082. (let (tmp re)
  3083. (when (setq tmp (plist-get props 'tags))
  3084. (setq props (plist-put props 'tags (mapconcat #'identity tmp ":"))))
  3085. (when (setq tmp (plist-get props 'date))
  3086. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3087. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3088. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  3089. (setq tmp (calendar-date-string tmp)))
  3090. (setq props (plist-put props 'date tmp)))
  3091. (when (setq tmp (plist-get props 'day))
  3092. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3093. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3094. (setq tmp (calendar-date-string tmp)))
  3095. (setq props (plist-put props 'day tmp))
  3096. (setq props (plist-put props 'agenda-day tmp)))
  3097. (when (setq tmp (plist-get props 'txt))
  3098. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  3099. (plist-put props 'priority-letter (match-string 1 tmp))
  3100. (setq tmp (replace-match "" t t tmp)))
  3101. (when (and (setq re (plist-get props 'org-todo-regexp))
  3102. (setq re (concat "\\`\\.*" re " ?"))
  3103. (let ((case-fold-search nil)) (string-match re tmp)))
  3104. (plist-put props 'todo (match-string 1 tmp))
  3105. (setq tmp (replace-match "" t t tmp)))
  3106. (plist-put props 'txt tmp)))
  3107. props)
  3108. (defun org-agenda-export-csv-mapper (prop)
  3109. (let ((res (plist-get org-agenda-info prop)))
  3110. (setq res
  3111. (cond
  3112. ((not res) "")
  3113. ((stringp res) res)
  3114. (t (prin1-to-string res))))
  3115. (org-trim (replace-regexp-in-string "," ";" res nil t))))
  3116. ;;;###autoload
  3117. (defun org-store-agenda-views (&rest _parameters)
  3118. "Store agenda views."
  3119. (interactive)
  3120. (org--batch-store-agenda-views nil nil))
  3121. ;;;###autoload
  3122. (defmacro org-batch-store-agenda-views (&rest parameters)
  3123. "Run all custom agenda commands that have a file argument."
  3124. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3125. `(org--batch-store-agenda-views ',vars (list ,@exps))))
  3126. (defun org--batch-store-agenda-views (vars vals)
  3127. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  3128. (pop-up-frames nil)
  3129. (dir default-directory)
  3130. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  3131. (save-window-excursion
  3132. (while cmds
  3133. (setq cmd (pop cmds)
  3134. thiscmdkey (car cmd)
  3135. thiscmdcmd (cdr cmd)
  3136. match (nth 2 thiscmdcmd)
  3137. bufname (if org-agenda-sticky
  3138. (or (and (stringp match)
  3139. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  3140. (format "*Org Agenda(%s)*" thiscmdkey))
  3141. org-agenda-buffer-name)
  3142. cmd-or-set (nth 2 cmd)
  3143. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  3144. files (nth (if (listp cmd-or-set) 4 5) cmd))
  3145. (if (stringp files) (setq files (list files)))
  3146. (when files
  3147. (let* ((opts (append org-agenda-exporter-settings opts))
  3148. (vars (append (mapcar #'car opts) vars))
  3149. (vals (append (mapcar (lambda (binding) (eval (cadr binding) t))
  3150. opts)
  3151. vals)))
  3152. (cl-progv vars vals
  3153. (org-agenda nil thiscmdkey))
  3154. (set-buffer bufname)
  3155. (while files
  3156. (cl-progv vars vals
  3157. (org-agenda-write (expand-file-name (pop files) dir)
  3158. nil t bufname))))
  3159. (and (get-buffer bufname)
  3160. (kill-buffer bufname)))))))
  3161. (defvar org-agenda-current-span nil
  3162. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3163. (defun org-agenda-mark-header-line (pos)
  3164. "Mark the line at POS as an agenda structure header."
  3165. (save-excursion
  3166. (goto-char pos)
  3167. (put-text-property (point-at-bol) (point-at-eol)
  3168. 'org-agenda-structural-header t)
  3169. (when org-agenda-title-append
  3170. (put-text-property (point-at-bol) (point-at-eol)
  3171. 'org-agenda-title-append org-agenda-title-append))))
  3172. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  3173. (defvar org-agenda-write-buffer-name "Agenda View")
  3174. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  3175. "Write the current buffer (an agenda view) as a file.
  3176. Depending on the extension of the file name, plain text (.txt),
  3177. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  3178. If the extension is .ics, translate visible agenda into iCalendar
  3179. format. If the extension is .org, collect all subtrees
  3180. corresponding to the agenda entries and add them in an .org file.
  3181. With prefix argument OPEN, open the new file immediately. If
  3182. NOSETTINGS is given, do not scope the settings of
  3183. `org-agenda-exporter-settings' into the export commands. This is
  3184. used when the settings have already been scoped and we do not
  3185. wish to overrule other, higher priority settings. If
  3186. AGENDA-BUFFER-NAME is provided, use this as the buffer name for
  3187. the agenda to write."
  3188. (interactive "FWrite agenda to file: \nP")
  3189. (if (or (not (file-writable-p file))
  3190. (and (file-exists-p file)
  3191. (if (called-interactively-p 'any)
  3192. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3193. (user-error "Cannot write agenda to file %s" file))
  3194. (cl-progv
  3195. (if nosettings nil (mapcar #'car org-agenda-exporter-settings))
  3196. (if nosettings nil (mapcar (lambda (binding) (eval (cadr binding) t))
  3197. org-agenda-exporter-settings))
  3198. (save-excursion
  3199. (save-window-excursion
  3200. (let ((bs (copy-sequence (buffer-string)))
  3201. (extension (file-name-extension file))
  3202. (default-directory (file-name-directory file))
  3203. ) ;; beg content
  3204. (with-temp-buffer
  3205. (rename-buffer org-agenda-write-buffer-name t)
  3206. (set-buffer-modified-p nil)
  3207. (insert bs)
  3208. (org-agenda-remove-marked-text 'invisible 'org-filtered)
  3209. (run-hooks 'org-agenda-before-write-hook)
  3210. (cond
  3211. ((bound-and-true-p org-mobile-creating-agendas)
  3212. (org-mobile-write-agenda-for-mobile file))
  3213. ((string= "org" extension)
  3214. (let (content p m message-log-max)
  3215. (goto-char (point-min))
  3216. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3217. (goto-char p)
  3218. (setq m (get-text-property (point) 'org-hd-marker))
  3219. (when m
  3220. (push (with-current-buffer (marker-buffer m)
  3221. (goto-char m)
  3222. (org-copy-subtree 1 nil t t)
  3223. org-subtree-clip)
  3224. content)))
  3225. (find-file file)
  3226. (erase-buffer)
  3227. (dolist (s content) (org-paste-subtree 1 s))
  3228. (write-file file)
  3229. (kill-buffer (current-buffer))
  3230. (message "Org file written to %s" file)))
  3231. ((member extension '("html" "htm"))
  3232. (or (require 'htmlize nil t)
  3233. (error "Please install htmlize from https://github.com/hniksic/emacs-htmlize"))
  3234. (declare-function htmlize-buffer "htmlize" (&optional buffer))
  3235. (set-buffer (htmlize-buffer (current-buffer)))
  3236. (when org-agenda-export-html-style
  3237. ;; replace <style> section with org-agenda-export-html-style
  3238. (goto-char (point-min))
  3239. (kill-region (- (search-forward "<style") 6)
  3240. (search-forward "</style>"))
  3241. (insert org-agenda-export-html-style))
  3242. (write-file file)
  3243. (kill-buffer (current-buffer))
  3244. (message "HTML written to %s" file))
  3245. ((string= "ps" extension)
  3246. (require 'ps-print)
  3247. (ps-print-buffer-with-faces file)
  3248. (message "Postscript written to %s" file))
  3249. ((string= "pdf" extension)
  3250. (require 'ps-print)
  3251. (ps-print-buffer-with-faces
  3252. (concat (file-name-sans-extension file) ".ps"))
  3253. (call-process "ps2pdf" nil nil nil
  3254. (expand-file-name
  3255. (concat (file-name-sans-extension file) ".ps"))
  3256. (expand-file-name file))
  3257. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3258. (message "PDF written to %s" file))
  3259. ((string= "ics" extension)
  3260. (require 'ox-icalendar)
  3261. (declare-function org-icalendar-export-current-agenda
  3262. "ox-icalendar" (file))
  3263. (org-icalendar-export-current-agenda (expand-file-name file)))
  3264. (t
  3265. (let ((bs (buffer-string)))
  3266. (find-file file)
  3267. (erase-buffer)
  3268. (insert bs)
  3269. (save-buffer 0)
  3270. (kill-buffer (current-buffer))
  3271. (message "Plain text written to %s" file))))))))
  3272. (set-buffer (or agenda-bufname
  3273. ;; FIXME: I'm pretty sure called-interactively-p
  3274. ;; doesn't do what we want here!
  3275. (and (called-interactively-p 'any) (buffer-name))
  3276. org-agenda-buffer-name)))
  3277. (when open (org-open-file file)))
  3278. (defun org-agenda-remove-marked-text (property &optional value)
  3279. "Delete all text marked with VALUE of PROPERTY.
  3280. VALUE defaults to t."
  3281. (let (beg)
  3282. (setq value (or value t))
  3283. (while (setq beg (text-property-any (point-min) (point-max)
  3284. property value))
  3285. (delete-region
  3286. beg (or (next-single-property-change beg property)
  3287. (point-max))))))
  3288. (defun org-agenda-add-entry-text ()
  3289. "Add entry text to agenda lines.
  3290. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3291. entry text following headings shown in the agenda.
  3292. Drawers will be excluded, also the line with scheduling/deadline info."
  3293. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3294. (not (bound-and-true-p org-mobile-creating-agendas)))
  3295. (let (m txt)
  3296. (goto-char (point-min))
  3297. (while (not (eobp))
  3298. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3299. (beginning-of-line 2)
  3300. (setq txt (org-agenda-get-some-entry-text
  3301. m org-agenda-add-entry-text-maxlines " > "))
  3302. (end-of-line 1)
  3303. (if (string-match "\\S-" txt)
  3304. (insert "\n" txt)
  3305. (or (eobp) (forward-char 1))))))))
  3306. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3307. &rest keep)
  3308. "Extract entry text from MARKER, at most N-LINES lines.
  3309. This will ignore drawers etc, just get the text.
  3310. If INDENT is given, prefix every line with this string. If KEEP is
  3311. given, it is a list of symbols, defining stuff that should not be
  3312. removed from the entry content. Currently only `planning' is allowed here."
  3313. (let (txt drawer-re kwd-time-re ind)
  3314. (save-excursion
  3315. (with-current-buffer (marker-buffer marker)
  3316. (if (not (derived-mode-p 'org-mode))
  3317. (setq txt "")
  3318. (org-with-wide-buffer
  3319. (goto-char marker)
  3320. (end-of-line 1)
  3321. (setq txt (buffer-substring
  3322. (min (1+ (point)) (point-max))
  3323. (progn (outline-next-heading) (point)))
  3324. drawer-re org-drawer-regexp
  3325. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3326. ".*\n?"))
  3327. (with-temp-buffer
  3328. (insert txt)
  3329. (when org-agenda-add-entry-text-descriptive-links
  3330. (goto-char (point-min))
  3331. (while (org-activate-links (point-max))
  3332. (goto-char (match-end 0))))
  3333. (goto-char (point-min))
  3334. (while (re-search-forward org-link-bracket-re (point-max) t)
  3335. (set-text-properties (match-beginning 0) (match-end 0)
  3336. nil))
  3337. (goto-char (point-min))
  3338. (while (re-search-forward drawer-re nil t)
  3339. (delete-region
  3340. (match-beginning 0)
  3341. (progn (re-search-forward
  3342. "^[ \t]*:END:.*\n?" nil 'move)
  3343. (point))))
  3344. (unless (member 'planning keep)
  3345. (goto-char (point-min))
  3346. (while (re-search-forward kwd-time-re nil t)
  3347. (replace-match "")))
  3348. (goto-char (point-min))
  3349. (when org-agenda-entry-text-exclude-regexps
  3350. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3351. (while (setq re (pop re-list))
  3352. (goto-char (point-min))
  3353. (while (re-search-forward re nil t)
  3354. (replace-match "")))))
  3355. (goto-char (point-max))
  3356. (skip-chars-backward " \t\n")
  3357. (when (looking-at "[ \t\n]+\\'") (replace-match ""))
  3358. ;; find and remove min common indentation
  3359. (goto-char (point-min))
  3360. (untabify (point-min) (point-max))
  3361. (setq ind (current-indentation))
  3362. (while (not (eobp))
  3363. (unless (looking-at "[ \t]*$")
  3364. (setq ind (min ind (current-indentation))))
  3365. (beginning-of-line 2))
  3366. (goto-char (point-min))
  3367. (while (not (eobp))
  3368. (unless (looking-at "[ \t]*$")
  3369. (move-to-column ind)
  3370. (delete-region (point-at-bol) (point)))
  3371. (beginning-of-line 2))
  3372. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3373. (goto-char (point-min))
  3374. (when indent
  3375. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3376. (replace-match indent t t)))
  3377. (goto-char (point-min))
  3378. (while (looking-at "[ \t]*\n") (replace-match ""))
  3379. (goto-char (point-max))
  3380. (when (> (org-current-line)
  3381. n-lines)
  3382. (org-goto-line (1+ n-lines))
  3383. (backward-char 1))
  3384. (setq txt (buffer-substring (point-min) (point))))))))
  3385. txt))
  3386. (defun org-check-for-org-mode ()
  3387. "Make sure current buffer is in Org mode. Error if not."
  3388. (or (derived-mode-p 'org-mode)
  3389. (error "Cannot execute Org agenda command on buffer in %s"
  3390. major-mode)))
  3391. ;;; Agenda prepare and finalize
  3392. (defvar org-agenda-multi nil) ; dynamically scoped
  3393. (defvar org-agenda-pre-window-conf nil)
  3394. (defvar org-agenda-columns-active nil)
  3395. (defvar org-agenda-name nil)
  3396. (defvar org-agenda-tag-filter nil)
  3397. (defvar org-agenda-category-filter nil)
  3398. (defvar org-agenda-regexp-filter nil)
  3399. (defvar org-agenda-effort-filter nil)
  3400. (defvar org-agenda-top-headline-filter nil)
  3401. (defvar org-agenda-represented-categories nil
  3402. "Cache for the list of all categories in the agenda.")
  3403. (defvar org-agenda-represented-tags nil
  3404. "Cache for the list of all categories in the agenda.")
  3405. (defvar org-agenda-tag-filter-preset nil
  3406. "A preset of the tags filter used for secondary agenda filtering.
  3407. This must be a list of strings, each string must be a single tag preceded
  3408. by \"+\" or \"-\".
  3409. This variable should not be set directly, but agenda custom commands can
  3410. bind it in the options section. The preset filter is a global property of
  3411. the entire agenda view. In a block agenda, it will not work reliably to
  3412. define a filter for one of the individual blocks. You need to set it in
  3413. the global options and expect it to be applied to the entire view.")
  3414. (defconst org-agenda-filter-variables
  3415. '((category . org-agenda-category-filter)
  3416. (tag . org-agenda-tag-filter)
  3417. (effort . org-agenda-effort-filter)
  3418. (regexp . org-agenda-regexp-filter))
  3419. "Alist of filter types and associated variables.")
  3420. (defun org-agenda-filter-any ()
  3421. "Is any filter active?"
  3422. (cl-some (lambda (x)
  3423. (or (symbol-value (cdr x))
  3424. (get :preset-filter x)))
  3425. org-agenda-filter-variables))
  3426. (defvar org-agenda-category-filter-preset nil
  3427. "A preset of the category filter used for secondary agenda filtering.
  3428. This must be a list of strings, each string must be a single category
  3429. preceded by \"+\" or \"-\".
  3430. This variable should not be set directly, but agenda custom commands can
  3431. bind it in the options section. The preset filter is a global property of
  3432. the entire agenda view. In a block agenda, it will not work reliably to
  3433. define a filter for one of the individual blocks. You need to set it in
  3434. the global options and expect it to be applied to the entire view.")
  3435. (defvar org-agenda-regexp-filter-preset nil
  3436. "A preset of the regexp filter used for secondary agenda filtering.
  3437. This must be a list of strings, each string must be a single regexp
  3438. preceded by \"+\" or \"-\".
  3439. This variable should not be set directly, but agenda custom commands can
  3440. bind it in the options section. The preset filter is a global property of
  3441. the entire agenda view. In a block agenda, it will not work reliably to
  3442. define a filter for one of the individual blocks. You need to set it in
  3443. the global options and expect it to be applied to the entire view.")
  3444. (defvar org-agenda-effort-filter-preset nil
  3445. "A preset of the effort condition used for secondary agenda filtering.
  3446. This must be a list of strings, each string must be a single regexp
  3447. preceded by \"+\" or \"-\".
  3448. This variable should not be set directly, but agenda custom commands can
  3449. bind it in the options section. The preset filter is a global property of
  3450. the entire agenda view. In a block agenda, it will not work reliably to
  3451. define a filter for one of the individual blocks. You need to set it in
  3452. the global options and expect it to be applied to the entire view.")
  3453. (defun org-agenda-use-sticky-p ()
  3454. "Return non-nil if an agenda buffer named
  3455. `org-agenda-buffer-name' exists and should be shown instead of
  3456. generating a new one."
  3457. (and
  3458. ;; turned off by user
  3459. org-agenda-sticky
  3460. ;; For multi-agenda buffer already exists
  3461. (not org-agenda-multi)
  3462. ;; buffer found
  3463. (get-buffer org-agenda-buffer-name)
  3464. ;; C-u parameter is same as last call
  3465. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3466. (and
  3467. (equal current-prefix-arg
  3468. org-agenda-last-prefix-arg)
  3469. ;; In case user turned stickiness on, while having existing
  3470. ;; Agenda buffer active, don't reuse that buffer, because it
  3471. ;; does not have org variables local
  3472. org-agenda-this-buffer-is-sticky))))
  3473. (defvar org-agenda-buffer-tmp-name nil)
  3474. (defun org-agenda--get-buffer-name (sticky-name)
  3475. (or org-agenda-buffer-tmp-name
  3476. (and org-agenda-doing-sticky-redo org-agenda-buffer-name)
  3477. sticky-name
  3478. "*Org Agenda*"))
  3479. (defun org-agenda-prepare-window (abuf filter-alist)
  3480. "Setup agenda buffer in the window.
  3481. ABUF is the buffer for the agenda window.
  3482. FILTER-ALIST is an alist of filters we need to apply when
  3483. `org-agenda-persistent-filter' is non-nil."
  3484. (let* ((awin (get-buffer-window abuf)) wconf)
  3485. (cond
  3486. ((equal (current-buffer) abuf) nil)
  3487. (awin (select-window awin))
  3488. ((not (setq wconf (current-window-configuration))))
  3489. ((eq org-agenda-window-setup 'current-window)
  3490. (pop-to-buffer-same-window abuf))
  3491. ((eq org-agenda-window-setup 'other-window)
  3492. (org-switch-to-buffer-other-window abuf))
  3493. ((eq org-agenda-window-setup 'other-frame)
  3494. (switch-to-buffer-other-frame abuf))
  3495. ((eq org-agenda-window-setup 'other-tab)
  3496. (if (fboundp 'switch-to-buffer-other-tab)
  3497. (switch-to-buffer-other-tab abuf)
  3498. (user-error "Your version of Emacs does not have tab bar support")))
  3499. ((eq org-agenda-window-setup 'only-window)
  3500. (delete-other-windows)
  3501. (pop-to-buffer-same-window abuf))
  3502. ((eq org-agenda-window-setup 'reorganize-frame)
  3503. (delete-other-windows)
  3504. (org-switch-to-buffer-other-window abuf)))
  3505. (setq org-agenda-tag-filter (cdr (assq 'tag filter-alist)))
  3506. (setq org-agenda-category-filter (cdr (assq 'cat filter-alist)))
  3507. (setq org-agenda-effort-filter (cdr (assq 'effort filter-alist)))
  3508. (setq org-agenda-regexp-filter (cdr (assq 're filter-alist)))
  3509. ;; Additional test in case agenda is invoked from within agenda
  3510. ;; buffer via elisp link.
  3511. (unless (equal (current-buffer) abuf)
  3512. (pop-to-buffer-same-window abuf))
  3513. (setq org-agenda-pre-window-conf
  3514. (or wconf org-agenda-pre-window-conf))))
  3515. (defun org-agenda-prepare (&optional name)
  3516. (let ((filter-alist (when org-agenda-persistent-filter
  3517. (with-current-buffer
  3518. (get-buffer-create org-agenda-buffer-name)
  3519. `((tag . ,org-agenda-tag-filter)
  3520. (re . ,org-agenda-regexp-filter)
  3521. (effort . ,org-agenda-effort-filter)
  3522. (cat . ,org-agenda-category-filter))))))
  3523. (if (org-agenda-use-sticky-p)
  3524. (progn
  3525. (put 'org-agenda-tag-filter :preset-filter nil)
  3526. (put 'org-agenda-category-filter :preset-filter nil)
  3527. (put 'org-agenda-regexp-filter :preset-filter nil)
  3528. (put 'org-agenda-effort-filter :preset-filter nil)
  3529. ;; Popup existing buffer
  3530. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3531. filter-alist)
  3532. (message "Sticky Agenda buffer, use `r' to refresh")
  3533. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3534. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3535. (setq org-todo-keywords-for-agenda nil)
  3536. (put 'org-agenda-tag-filter :preset-filter
  3537. org-agenda-tag-filter-preset)
  3538. (put 'org-agenda-category-filter :preset-filter
  3539. org-agenda-category-filter-preset)
  3540. (put 'org-agenda-regexp-filter :preset-filter
  3541. org-agenda-regexp-filter-preset)
  3542. (put 'org-agenda-effort-filter :preset-filter
  3543. org-agenda-effort-filter-preset)
  3544. (if org-agenda-multi
  3545. (progn
  3546. (setq buffer-read-only nil)
  3547. (goto-char (point-max))
  3548. (unless (or (bobp) org-agenda-compact-blocks
  3549. (not org-agenda-block-separator))
  3550. (insert "\n"
  3551. (if (stringp org-agenda-block-separator)
  3552. org-agenda-block-separator
  3553. (make-string (window-width) org-agenda-block-separator))
  3554. "\n"))
  3555. (narrow-to-region (point) (point-max)))
  3556. (setq org-done-keywords-for-agenda nil)
  3557. ;; Setting any org variables that are in org-agenda-local-vars
  3558. ;; list need to be done after the prepare call
  3559. (org-agenda-prepare-window
  3560. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3561. (setq buffer-read-only nil)
  3562. (org-agenda-reset-markers)
  3563. (let ((inhibit-read-only t)) (erase-buffer))
  3564. (org-agenda-mode)
  3565. (setq org-agenda-buffer (current-buffer))
  3566. (setq org-agenda-contributing-files nil)
  3567. (setq org-agenda-columns-active nil)
  3568. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3569. (setq org-todo-keywords-for-agenda
  3570. (org-uniquify org-todo-keywords-for-agenda))
  3571. (setq org-done-keywords-for-agenda
  3572. (org-uniquify org-done-keywords-for-agenda))
  3573. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3574. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3575. (and name (not org-agenda-name)
  3576. (setq-local org-agenda-name name)))
  3577. (setq buffer-read-only nil))))
  3578. (defvar org-overriding-columns-format)
  3579. (defvar org-local-columns-format)
  3580. (defun org-agenda-finalize ()
  3581. "Finishing touch for the agenda buffer.
  3582. This function is called just before displaying the agenda. If
  3583. you want to add your own functions to the finalization of the
  3584. agenda display, configure `org-agenda-finalize-hook'."
  3585. (unless org-agenda-multi
  3586. (let ((inhibit-read-only t))
  3587. (save-excursion
  3588. (goto-char (point-min))
  3589. (save-excursion
  3590. (while (org-activate-links (point-max))
  3591. (goto-char (match-end 0))))
  3592. (unless (eq org-agenda-remove-tags t)
  3593. (org-agenda-align-tags))
  3594. (unless org-agenda-with-colors
  3595. (remove-text-properties (point-min) (point-max) '(face nil)))
  3596. (when (bound-and-true-p org-overriding-columns-format)
  3597. (setq-local org-local-columns-format
  3598. org-overriding-columns-format))
  3599. (when org-agenda-view-columns-initially
  3600. (org-agenda-columns))
  3601. (when org-agenda-fontify-priorities
  3602. (org-agenda-fontify-priorities))
  3603. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3604. (org-agenda-dim-blocked-tasks))
  3605. (org-agenda-mark-clocking-task)
  3606. (when org-agenda-entry-text-mode
  3607. (org-agenda-entry-text-hide)
  3608. (org-agenda-entry-text-show))
  3609. (when (and (featurep 'org-habit)
  3610. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3611. (org-habit-insert-consistency-graphs))
  3612. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3613. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3614. (and (listp org-agenda-show-inherited-tags)
  3615. (memq org-agenda-type org-agenda-show-inherited-tags))
  3616. (and (eq org-agenda-show-inherited-tags t)
  3617. (or (eq org-agenda-use-tag-inheritance t)
  3618. (and (listp org-agenda-use-tag-inheritance)
  3619. (not (memq org-agenda-type
  3620. org-agenda-use-tag-inheritance))))))
  3621. (let (mrk)
  3622. (save-excursion
  3623. (goto-char (point-min))
  3624. (while (equal (forward-line) 0)
  3625. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3626. (put-text-property (point-at-bol) (point-at-eol)
  3627. 'tags
  3628. (org-with-point-at mrk
  3629. (org-get-tags))))))))
  3630. (setq org-agenda-represented-tags nil
  3631. org-agenda-represented-categories nil)
  3632. (when org-agenda-top-headline-filter
  3633. (org-agenda-filter-top-headline-apply
  3634. org-agenda-top-headline-filter))
  3635. (when org-agenda-tag-filter
  3636. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3637. (when (get 'org-agenda-tag-filter :preset-filter)
  3638. (org-agenda-filter-apply
  3639. (get 'org-agenda-tag-filter :preset-filter) 'tag t))
  3640. (when org-agenda-category-filter
  3641. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3642. (when (get 'org-agenda-category-filter :preset-filter)
  3643. (org-agenda-filter-apply
  3644. (get 'org-agenda-category-filter :preset-filter) 'category))
  3645. (when org-agenda-regexp-filter
  3646. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3647. (when (get 'org-agenda-regexp-filter :preset-filter)
  3648. (org-agenda-filter-apply
  3649. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3650. (when org-agenda-effort-filter
  3651. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3652. (when (get 'org-agenda-effort-filter :preset-filter)
  3653. (org-agenda-filter-apply
  3654. (get 'org-agenda-effort-filter :preset-filter) 'effort))
  3655. (add-hook 'kill-buffer-hook #'org-agenda-reset-markers 'append 'local))
  3656. (run-hooks 'org-agenda-finalize-hook))))
  3657. (defun org-agenda-mark-clocking-task ()
  3658. "Mark the current clock entry in the agenda if it is present."
  3659. ;; We need to widen when `org-agenda-finalize' is called from
  3660. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in').
  3661. (when (bound-and-true-p org-clock-current-task)
  3662. (save-restriction
  3663. (widen)
  3664. (org-agenda-unmark-clocking-task)
  3665. (when (marker-buffer org-clock-hd-marker)
  3666. (save-excursion
  3667. (goto-char (point-min))
  3668. (let (s ov)
  3669. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3670. (goto-char s)
  3671. (when (equal (org-get-at-bol 'org-hd-marker)
  3672. org-clock-hd-marker)
  3673. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3674. (overlay-put ov 'type 'org-agenda-clocking)
  3675. (overlay-put ov 'face 'org-agenda-clocking)
  3676. (overlay-put ov 'help-echo
  3677. "The clock is running in this item")))))))))
  3678. (defun org-agenda-unmark-clocking-task ()
  3679. "Unmark the current clocking task."
  3680. (mapc (lambda (o)
  3681. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  3682. (delete-overlay o)))
  3683. (overlays-in (point-min) (point-max))))
  3684. (defun org-agenda-fontify-priorities ()
  3685. "Make highest priority lines bold, and lowest italic."
  3686. (interactive)
  3687. (mapc (lambda (o) (when (eq (overlay-get o 'org-type) 'org-priority)
  3688. (delete-overlay o)))
  3689. (overlays-in (point-min) (point-max)))
  3690. (save-excursion
  3691. (let (b e p ov h l)
  3692. (goto-char (point-min))
  3693. (while (re-search-forward org-priority-regexp nil t)
  3694. (setq h (or (get-char-property (point) 'org-priority-highest)
  3695. org-priority-highest)
  3696. l (or (get-char-property (point) 'org-priority-lowest)
  3697. org-priority-lowest)
  3698. p (string-to-char (match-string 2))
  3699. b (match-beginning 1)
  3700. e (if (eq org-agenda-fontify-priorities 'cookies)
  3701. (1+ (match-end 2))
  3702. (point-at-eol))
  3703. ov (make-overlay b e))
  3704. (overlay-put
  3705. ov 'face
  3706. (let ((special-face
  3707. (cond ((org-face-from-face-or-color
  3708. 'priority 'org-priority
  3709. (cdr (assoc p org-priority-faces))))
  3710. ((and (listp org-agenda-fontify-priorities)
  3711. (org-face-from-face-or-color
  3712. 'priority 'org-priority
  3713. (cdr (assoc p org-agenda-fontify-priorities)))))
  3714. ((equal p l) 'italic)
  3715. ((equal p h) 'bold))))
  3716. (if special-face (list special-face 'org-priority) 'org-priority)))
  3717. (overlay-put ov 'org-type 'org-priority)))))
  3718. (defvar org-depend-tag-blocked)
  3719. (defun org-agenda-dim-blocked-tasks (&optional _invisible)
  3720. "Dim currently blocked TODOs in the agenda display.
  3721. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3722. dimming them." ;FIXME: The arg isn't used, actually!
  3723. (interactive "P")
  3724. (when (called-interactively-p 'interactive)
  3725. (message "Dim or hide blocked tasks..."))
  3726. (dolist (o (overlays-in (point-min) (point-max)))
  3727. (when (eq (overlay-get o 'face) 'org-agenda-dimmed-todo-face)
  3728. (delete-overlay o)))
  3729. (save-excursion
  3730. (let ((inhibit-read-only t))
  3731. (goto-char (point-min))
  3732. (while (let ((pos (text-property-not-all
  3733. (point) (point-max) 'org-todo-blocked nil)))
  3734. (when pos (goto-char pos)))
  3735. (let* ((invisible
  3736. (eq (org-get-at-bol 'org-todo-blocked) 'invisible))
  3737. (todo-blocked
  3738. (eq (org-get-at-bol 'org-filter-type) 'todo-blocked))
  3739. (ov (make-overlay (if invisible
  3740. (line-end-position 0)
  3741. (line-beginning-position))
  3742. (line-end-position))))
  3743. (when todo-blocked
  3744. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3745. (when invisible
  3746. (org-agenda-filter-hide-line 'todo-blocked)))
  3747. (if (= (point-max) (line-end-position))
  3748. (goto-char (point-max))
  3749. (move-beginning-of-line 2)))))
  3750. (when (called-interactively-p 'interactive)
  3751. (message "Dim or hide blocked tasks...done")))
  3752. (defun org-agenda--mark-blocked-entry (entry)
  3753. "If ENTRY is blocked, mark it for fontification or invisibility.
  3754. If the header at `org-hd-marker' is blocked according to
  3755. `org-entry-blocked-p', then if `org-agenda-dim-blocked-tasks' is
  3756. 'invisible and the header is not blocked by checkboxes, set the
  3757. text property `org-todo-blocked' to `invisible', otherwise set it
  3758. to t."
  3759. (when (get-text-property 0 'todo-state entry)
  3760. (let ((entry-marker (get-text-property 0 'org-hd-marker entry))
  3761. (org-blocked-by-checkboxes nil)
  3762. ;; Necessary so that `org-entry-blocked-p' does not change
  3763. ;; the buffer.
  3764. (org-depend-tag-blocked nil))
  3765. (when entry-marker
  3766. (let ((blocked
  3767. (with-current-buffer (marker-buffer entry-marker)
  3768. (save-excursion
  3769. (goto-char entry-marker)
  3770. (org-entry-blocked-p)))))
  3771. (when blocked
  3772. (let ((really-invisible
  3773. (and (not org-blocked-by-checkboxes)
  3774. (eq org-agenda-dim-blocked-tasks 'invisible))))
  3775. (put-text-property
  3776. 0 (length entry) 'org-todo-blocked
  3777. (if really-invisible 'invisible t)
  3778. entry)
  3779. (put-text-property
  3780. 0 (length entry) 'org-filter-type 'todo-blocked entry)))))))
  3781. entry)
  3782. (defvar org-agenda-skip-function nil
  3783. "Function to be called at each match during agenda construction.
  3784. If this function returns nil, the current match should not be skipped.
  3785. Otherwise, the function must return a position from where the search
  3786. should be continued.
  3787. This may also be a Lisp form, it will be evaluated.
  3788. Never set this variable using `setq' or so, because then it will apply
  3789. to all future agenda commands. If you do want a global skipping condition,
  3790. use the option `org-agenda-skip-function-global' instead.
  3791. The correct usage for `org-agenda-skip-function' is to bind it with
  3792. `let' to scope it dynamically into the agenda-constructing command.
  3793. A good way to set it is through options in `org-agenda-custom-commands'.")
  3794. (defun org-agenda-skip ()
  3795. "Throw to `:skip' in places that should be skipped.
  3796. Also moves point to the end of the skipped region, so that search can
  3797. continue from there."
  3798. (let ((p (point-at-bol)) to)
  3799. (when (or
  3800. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3801. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3802. (or (and (get-text-property p :org-archived)
  3803. (org-end-of-subtree t))
  3804. (and (member org-archive-tag org-file-tags)
  3805. (goto-char (point-max)))))
  3806. (and org-agenda-skip-comment-trees
  3807. (get-text-property p :org-comment)
  3808. (org-end-of-subtree t))
  3809. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3810. (org-agenda-skip-eval org-agenda-skip-function)))
  3811. (goto-char to))
  3812. (org-in-src-block-p t))
  3813. (throw :skip t))))
  3814. (defun org-agenda-skip-eval (form)
  3815. "If FORM is a function or a list, call (or eval) it and return the result.
  3816. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3817. and match data are returned to the previous state no matter what these
  3818. functions do."
  3819. (let (fp)
  3820. (and form
  3821. (or (setq fp (functionp form))
  3822. (consp form))
  3823. (save-excursion
  3824. (save-match-data
  3825. (if fp
  3826. (funcall form)
  3827. (eval form t)))))))
  3828. (defvar org-agenda-markers nil
  3829. "List of all currently active markers created by `org-agenda'.")
  3830. (defvar org-agenda-last-marker-time (float-time)
  3831. "Creation time of the last agenda marker.")
  3832. (defun org-agenda-new-marker (&optional pos)
  3833. "Return a new agenda marker.
  3834. Marker is at point, or at POS if non-nil. Org mode keeps a list
  3835. of these markers and resets them when they are no longer in use."
  3836. (let ((m (copy-marker (or pos (point)) t)))
  3837. (setq org-agenda-last-marker-time (float-time))
  3838. (if org-agenda-buffer
  3839. (with-current-buffer org-agenda-buffer
  3840. (push m org-agenda-markers))
  3841. (push m org-agenda-markers))
  3842. m))
  3843. (defun org-agenda-reset-markers ()
  3844. "Reset markers created by `org-agenda'."
  3845. (while org-agenda-markers
  3846. (move-marker (pop org-agenda-markers) nil)))
  3847. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3848. "Save relative positions of markers in region.
  3849. This check for agenda markers in all agenda buffers currently active."
  3850. (dolist (buf (buffer-list))
  3851. (with-current-buffer buf
  3852. (when (eq major-mode 'org-agenda-mode)
  3853. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3854. org-agenda-markers)))))
  3855. ;;; Entry text mode
  3856. (defun org-agenda-entry-text-show-here ()
  3857. "Add some text from the entry as context to the current line."
  3858. (let (m txt o)
  3859. (setq m (org-get-at-bol 'org-hd-marker))
  3860. (unless (marker-buffer m)
  3861. (error "No marker points to an entry here"))
  3862. (setq txt (concat "\n" (org-no-properties
  3863. (org-agenda-get-some-entry-text
  3864. m org-agenda-entry-text-maxlines
  3865. org-agenda-entry-text-leaders))))
  3866. (when (string-match "\\S-" txt)
  3867. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3868. (overlay-put o 'evaporate t)
  3869. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3870. (overlay-put o 'after-string txt))))
  3871. (defun org-agenda-entry-text-show ()
  3872. "Add entry context for all agenda lines."
  3873. (interactive)
  3874. (save-excursion
  3875. (goto-char (point-max))
  3876. (beginning-of-line 1)
  3877. (while (not (bobp))
  3878. (when (org-get-at-bol 'org-hd-marker)
  3879. (org-agenda-entry-text-show-here))
  3880. (beginning-of-line 0))))
  3881. (defun org-agenda-entry-text-hide ()
  3882. "Remove any shown entry context."
  3883. (mapc (lambda (o)
  3884. (when (eq (overlay-get o 'org-overlay-type)
  3885. 'agenda-entry-content)
  3886. (delete-overlay o)))
  3887. (overlays-in (point-min) (point-max))))
  3888. (defun org-agenda-get-day-face (date)
  3889. "Return the face DATE should be displayed with."
  3890. (cond ((and (functionp org-agenda-day-face-function)
  3891. (funcall org-agenda-day-face-function date)))
  3892. ((and (org-agenda-today-p date)
  3893. (memq (calendar-day-of-week date) org-agenda-weekend-days))
  3894. 'org-agenda-date-weekend-today)
  3895. ((org-agenda-today-p date) 'org-agenda-date-today)
  3896. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3897. 'org-agenda-date-weekend)
  3898. (t 'org-agenda-date)))
  3899. (defvar org-agenda-show-log-scoped)
  3900. ;;; Agenda Daily/Weekly
  3901. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3902. "Start day for the agenda view.
  3903. Custom commands can set this variable in the options section.
  3904. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3905. input allowed when reading a date through the Org calendar.
  3906. See the docstring of `org-read-date' for details.")
  3907. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3908. (defvar org-arg-loc nil) ; local variable
  3909. ;;;###autoload
  3910. (defun org-agenda-list (&optional arg start-day span with-hour)
  3911. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3912. The view will be for the current day or week, but from the overview buffer
  3913. you will be able to go to other days/weeks.
  3914. With a numeric prefix argument in an interactive call, the agenda will
  3915. span ARG days. Lisp programs should instead specify SPAN to change
  3916. the number of days. SPAN defaults to `org-agenda-span'.
  3917. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3918. given in `org-agenda-start-on-weekday'.
  3919. When WITH-HOUR is non-nil, only include scheduled and deadline
  3920. items if they have an hour specification like [h]h:mm."
  3921. (interactive "P")
  3922. (when org-agenda-overriding-arguments
  3923. (setq arg (car org-agenda-overriding-arguments)
  3924. start-day (nth 1 org-agenda-overriding-arguments)
  3925. span (nth 2 org-agenda-overriding-arguments)))
  3926. (when (and (integerp arg) (> arg 0))
  3927. (setq span arg arg nil))
  3928. (when (numberp span)
  3929. (unless (< 0 span)
  3930. (user-error "Agenda creation impossible for this span(=%d days)" span)))
  3931. (catch 'exit
  3932. (setq org-agenda-buffer-name
  3933. (org-agenda--get-buffer-name
  3934. (and org-agenda-sticky
  3935. (cond ((and org-keys (stringp org-match))
  3936. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3937. (org-keys
  3938. (format "*Org Agenda(%s)*" org-keys))
  3939. (t "*Org Agenda(a)*")))))
  3940. (org-agenda-prepare "Day/Week")
  3941. (setq start-day (or start-day org-agenda-start-day))
  3942. (when (stringp start-day)
  3943. ;; Convert to an absolute day number
  3944. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3945. (org-compile-prefix-format 'agenda)
  3946. (org-set-sorting-strategy 'agenda)
  3947. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
  3948. (today (org-today))
  3949. (sd (or start-day today))
  3950. (ndays (org-agenda-span-to-ndays span sd))
  3951. (org-agenda-start-on-weekday
  3952. (and (or (eq ndays 7) (eq ndays 14))
  3953. org-agenda-start-on-weekday))
  3954. (thefiles (org-agenda-files nil 'ifmode))
  3955. (files thefiles)
  3956. (start (if (or (null org-agenda-start-on-weekday)
  3957. (< ndays 7))
  3958. sd
  3959. (let* ((nt (calendar-day-of-week
  3960. (calendar-gregorian-from-absolute sd)))
  3961. (n1 org-agenda-start-on-weekday)
  3962. (d (- nt n1)))
  3963. (- sd (+ (if (< d 0) 7 0) d)))))
  3964. (day-numbers (list start))
  3965. (day-cnt 0)
  3966. (inhibit-redisplay (not debug-on-error))
  3967. (org-agenda-show-log-scoped org-agenda-show-log)
  3968. s rtn rtnall file date d start-pos end-pos todayp ;; e
  3969. clocktable-start clocktable-end) ;; filter
  3970. (setq org-agenda-redo-command
  3971. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3972. (dotimes (_ (1- ndays))
  3973. (push (1+ (car day-numbers)) day-numbers))
  3974. (setq day-numbers (nreverse day-numbers))
  3975. (setq clocktable-start (car day-numbers)
  3976. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3977. (setq-local org-starting-day (car day-numbers))
  3978. (setq-local org-arg-loc arg)
  3979. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  3980. (unless org-agenda-compact-blocks
  3981. (let* ((d1 (car day-numbers))
  3982. (d2 (org-last day-numbers))
  3983. (w1 (org-days-to-iso-week d1))
  3984. (w2 (org-days-to-iso-week d2)))
  3985. (setq s (point))
  3986. (org-agenda--insert-overriding-header
  3987. (concat (org-agenda-span-name span)
  3988. "-agenda"
  3989. (cond ((<= 350 (- d2 d1)) "")
  3990. ((= w1 w2) (format " (W%02d)" w1))
  3991. (t (format " (W%02d-W%02d)" w1 w2)))
  3992. ":\n")))
  3993. ;; Add properties if we actually inserted a header.
  3994. (when (> (point) s)
  3995. (add-text-properties s (1- (point))
  3996. (list 'face 'org-agenda-structure
  3997. 'org-date-line t))
  3998. (org-agenda-mark-header-line s)))
  3999. (while (setq d (pop day-numbers))
  4000. (setq date (calendar-gregorian-from-absolute d)
  4001. s (point))
  4002. (if (or (setq todayp (= d today))
  4003. (and (not start-pos) (= d sd)))
  4004. (setq start-pos (point))
  4005. (when (and start-pos (not end-pos))
  4006. (setq end-pos (point))))
  4007. (setq files thefiles
  4008. rtnall nil)
  4009. (while (setq file (pop files))
  4010. (catch 'nextfile
  4011. (org-check-agenda-file file)
  4012. (let ((org-agenda-entry-types org-agenda-entry-types))
  4013. ;; Starred types override non-starred equivalents
  4014. (when (member :deadline* org-agenda-entry-types)
  4015. (setq org-agenda-entry-types
  4016. (delq :deadline org-agenda-entry-types)))
  4017. (when (member :scheduled* org-agenda-entry-types)
  4018. (setq org-agenda-entry-types
  4019. (delq :scheduled org-agenda-entry-types)))
  4020. ;; Honor with-hour
  4021. (when with-hour
  4022. (when (member :deadline org-agenda-entry-types)
  4023. (setq org-agenda-entry-types
  4024. (delq :deadline org-agenda-entry-types))
  4025. (push :deadline* org-agenda-entry-types))
  4026. (when (member :scheduled org-agenda-entry-types)
  4027. (setq org-agenda-entry-types
  4028. (delq :scheduled org-agenda-entry-types))
  4029. (push :scheduled* org-agenda-entry-types)))
  4030. (unless org-agenda-include-deadlines
  4031. (setq org-agenda-entry-types
  4032. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  4033. (cond
  4034. ((memq org-agenda-show-log-scoped '(only clockcheck))
  4035. (setq rtn (org-agenda-get-day-entries
  4036. file date :closed)))
  4037. (org-agenda-show-log-scoped
  4038. (setq rtn (apply #'org-agenda-get-day-entries
  4039. file date
  4040. (append '(:closed) org-agenda-entry-types))))
  4041. (t
  4042. (setq rtn (apply #'org-agenda-get-day-entries
  4043. file date
  4044. org-agenda-entry-types)))))
  4045. (setq rtnall (append rtnall rtn)))) ;; all entries
  4046. (when org-agenda-include-diary
  4047. (let ((org-agenda-search-headline-for-time t))
  4048. (require 'diary-lib)
  4049. (setq rtn (org-get-entries-from-diary date))
  4050. (setq rtnall (append rtnall rtn))))
  4051. (when (or rtnall org-agenda-show-all-dates)
  4052. (setq day-cnt (1+ day-cnt))
  4053. (insert
  4054. (if (stringp org-agenda-format-date)
  4055. (format-time-string org-agenda-format-date
  4056. (org-time-from-absolute date))
  4057. (funcall org-agenda-format-date date))
  4058. "\n")
  4059. (put-text-property s (1- (point)) 'face
  4060. (org-agenda-get-day-face date))
  4061. (put-text-property s (1- (point)) 'org-date-line t)
  4062. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  4063. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  4064. (when todayp
  4065. (put-text-property s (1- (point)) 'org-today t))
  4066. (setq rtnall
  4067. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  4068. (when rtnall (insert ;; all entries
  4069. (org-agenda-finalize-entries rtnall 'agenda)
  4070. "\n"))
  4071. (put-text-property s (1- (point)) 'day d)
  4072. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)))
  4073. (when (and org-agenda-clockreport-mode clocktable-start)
  4074. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  4075. ;; the above line is to ensure the restricted range!
  4076. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  4077. tbl)
  4078. (setq p (org-plist-delete p :block))
  4079. (setq p (plist-put p :tstart clocktable-start))
  4080. (setq p (plist-put p :tend clocktable-end))
  4081. (setq p (plist-put p :scope 'agenda))
  4082. (setq tbl (apply #'org-clock-get-clocktable p))
  4083. (insert tbl)))
  4084. (goto-char (point-min))
  4085. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4086. (unless (or (not (get-buffer-window org-agenda-buffer-name))
  4087. (and (pos-visible-in-window-p (point-min))
  4088. (pos-visible-in-window-p (point-max))))
  4089. (goto-char (1- (point-max)))
  4090. (recenter -1)
  4091. (when (not (pos-visible-in-window-p (or start-pos 1)))
  4092. (goto-char (or start-pos 1))
  4093. (recenter 1)))
  4094. (goto-char (or start-pos 1))
  4095. (add-text-properties (point-min) (point-max)
  4096. `(org-agenda-type agenda
  4097. org-last-args (,arg ,start-day ,span)
  4098. org-redo-cmd ,org-agenda-redo-command
  4099. org-series-cmd ,org-cmd))
  4100. (when (eq org-agenda-show-log-scoped 'clockcheck)
  4101. (org-agenda-show-clocking-issues))
  4102. (org-agenda-finalize)
  4103. (setq buffer-read-only t)
  4104. (message ""))))
  4105. (defun org-agenda-ndays-to-span (n)
  4106. "Return a span symbol for a span of N days, or N if none matches."
  4107. (cond ((symbolp n) n)
  4108. ((= n 1) 'day)
  4109. ((= n 7) 'week)
  4110. ((= n 14) 'fortnight)
  4111. (t n)))
  4112. (defun org-agenda-span-to-ndays (span &optional start-day)
  4113. "Return ndays from SPAN, possibly starting at START-DAY.
  4114. START-DAY is an absolute time value."
  4115. (cond ((numberp span) span)
  4116. ((eq span 'day) 1)
  4117. ((eq span 'week) 7)
  4118. ((eq span 'fortnight) 14)
  4119. ((eq span 'month)
  4120. (let ((date (calendar-gregorian-from-absolute start-day)))
  4121. (calendar-last-day-of-month (car date) (cl-caddr date))))
  4122. ((eq span 'year)
  4123. (let ((date (calendar-gregorian-from-absolute start-day)))
  4124. (if (calendar-leap-year-p (cl-caddr date)) 366 365)))))
  4125. (defun org-agenda-span-name (span)
  4126. "Return a SPAN name."
  4127. (if (null span)
  4128. ""
  4129. (if (symbolp span)
  4130. (capitalize (symbol-name span))
  4131. (format "%d days" span))))
  4132. ;;; Agenda word search
  4133. (defvar org-agenda-search-history nil)
  4134. (defvar org-search-syntax-table nil
  4135. "Special syntax table for Org search.
  4136. In this table, we have single quotes not as word constituents, to
  4137. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4138. (defvar org-mode-syntax-table) ; From org.el
  4139. (defun org-search-syntax-table ()
  4140. (unless org-search-syntax-table
  4141. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4142. (modify-syntax-entry ?' "." org-search-syntax-table)
  4143. (modify-syntax-entry ?` "." org-search-syntax-table))
  4144. org-search-syntax-table)
  4145. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4146. ;;;###autoload
  4147. (defun org-search-view (&optional todo-only string edit-at)
  4148. "Show all entries that contain a phrase or words or regular expressions.
  4149. With optional prefix argument TODO-ONLY, only consider entries that are
  4150. TODO entries. The argument STRING can be used to pass a default search
  4151. string into this function. If EDIT-AT is non-nil, it means that the
  4152. user should get a chance to edit this string, with cursor at position
  4153. EDIT-AT.
  4154. The search string can be viewed either as a phrase that should be found as
  4155. is, or it can be broken into a number of snippets, each of which must match
  4156. in a Boolean way to select an entry. The default depends on the variable
  4157. `org-agenda-search-view-always-boolean'.
  4158. Even if this is turned off (the default) you can always switch to
  4159. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4160. The default is a direct search of the whole phrase, where each space in
  4161. the search string can expand to an arbitrary amount of whitespace,
  4162. including newlines.
  4163. If using a Boolean search, the search string is split on whitespace and
  4164. each snippet is searched separately, with logical AND to select an entry.
  4165. Words prefixed with a minus must *not* occur in the entry. Words without
  4166. a prefix or prefixed with a plus must occur in the entry. Matching is
  4167. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4168. match whole words, not parts of a word) if
  4169. `org-agenda-search-view-force-full-words' is set (default is nil).
  4170. Boolean search snippets enclosed by curly braces are interpreted as
  4171. regular expressions that must or (when preceded with \"-\") must not
  4172. match in the entry. Snippets enclosed into double quotes will be taken
  4173. as a whole, to include whitespace.
  4174. - If the search string starts with an asterisk, search only in headlines.
  4175. - If (possibly after the leading star) the search string starts with an
  4176. exclamation mark, this also means to look at TODO entries only, an effect
  4177. that can also be achieved with a prefix argument.
  4178. - If (possibly after star and exclamation mark) the search string starts
  4179. with a colon, this will mean that the (non-regexp) snippets of the
  4180. Boolean search must match as full words.
  4181. This command searches the agenda files, and in addition the files
  4182. listed in `org-agenda-text-search-extra-files' unless a restriction lock
  4183. is active."
  4184. (interactive "P")
  4185. (when org-agenda-overriding-arguments
  4186. (setq todo-only (car org-agenda-overriding-arguments)
  4187. string (nth 1 org-agenda-overriding-arguments)
  4188. edit-at (nth 2 org-agenda-overriding-arguments)))
  4189. (let* ((props (list 'face nil
  4190. 'done-face 'org-agenda-done
  4191. 'org-not-done-regexp org-not-done-regexp
  4192. 'org-todo-regexp org-todo-regexp
  4193. 'org-complex-heading-regexp org-complex-heading-regexp
  4194. 'mouse-face 'highlight
  4195. 'help-echo "mouse-2 or RET jump to location"))
  4196. (full-words org-agenda-search-view-force-full-words)
  4197. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4198. regexp rtn rtnall files file pos inherited-tags
  4199. marker category level tags c neg re boolean
  4200. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4201. (unless (and (not edit-at)
  4202. (stringp string)
  4203. (string-match "\\S-" string))
  4204. (setq string (read-string
  4205. (if org-agenda-search-view-always-boolean
  4206. "[+-]Word/{Regexp} ...: "
  4207. "Phrase or [+-]Word/{Regexp} ...: ")
  4208. (cond
  4209. ((integerp edit-at) (cons string edit-at))
  4210. (edit-at string))
  4211. 'org-agenda-search-history)))
  4212. (catch 'exit
  4213. (setq org-agenda-buffer-name
  4214. (org-agenda--get-buffer-name
  4215. (and org-agenda-sticky
  4216. (if (stringp string)
  4217. (format "*Org Agenda(%s:%s)*"
  4218. (or org-keys (or (and todo-only "S") "s"))
  4219. string)
  4220. (format "*Org Agenda(%s)*"
  4221. (or (and todo-only "S") "s"))))))
  4222. (org-agenda-prepare "SEARCH")
  4223. (org-compile-prefix-format 'search)
  4224. (org-set-sorting-strategy 'search)
  4225. (setq org-agenda-redo-command
  4226. (list 'org-search-view (if todo-only t nil)
  4227. (list 'if 'current-prefix-arg nil string)))
  4228. (setq org-agenda-query-string string)
  4229. (if (equal (string-to-char string) ?*)
  4230. (setq hdl-only t
  4231. words (substring string 1))
  4232. (setq words string))
  4233. (when (equal (string-to-char words) ?!)
  4234. (setq todo-only t
  4235. words (substring words 1)))
  4236. (when (equal (string-to-char words) ?:)
  4237. (setq full-words t
  4238. words (substring words 1)))
  4239. (when (or org-agenda-search-view-always-boolean
  4240. (member (string-to-char words) '(?- ?+ ?\{)))
  4241. (setq boolean t))
  4242. (setq words (split-string words))
  4243. (let (www w)
  4244. (while (setq w (pop words))
  4245. (while (and (string-match "\\\\\\'" w) words)
  4246. (setq w (concat (substring w 0 -1) " " (pop words))))
  4247. (push w www))
  4248. (setq words (nreverse www) www nil)
  4249. (while (setq w (pop words))
  4250. (when (and (string-match "\\`[-+]?{" w)
  4251. (not (string-match "}\\'" w)))
  4252. (while (and words (not (string-match "}\\'" (car words))))
  4253. (setq w (concat w " " (pop words))))
  4254. (setq w (concat w " " (pop words))))
  4255. (push w www))
  4256. (setq words (nreverse www)))
  4257. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4258. (when boolean
  4259. (let (wds w)
  4260. (while (setq w (pop words))
  4261. (when (or (equal (substring w 0 1) "\"")
  4262. (and (> (length w) 1)
  4263. (member (substring w 0 1) '("+" "-"))
  4264. (equal (substring w 1 2) "\"")))
  4265. (while (and words (not (equal (substring w -1) "\"")))
  4266. (setq w (concat w " " (pop words)))))
  4267. (and (string-match "\\`\\([-+]?\\)\"" w)
  4268. (setq w (replace-match "\\1" nil nil w)))
  4269. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4270. (push w wds))
  4271. (setq words (nreverse wds))))
  4272. (if boolean
  4273. (mapc (lambda (w)
  4274. (setq c (string-to-char w))
  4275. (if (equal c ?-)
  4276. (setq neg t w (substring w 1))
  4277. (if (equal c ?+)
  4278. (setq neg nil w (substring w 1))
  4279. (setq neg nil)))
  4280. (if (string-match "\\`{.*}\\'" w)
  4281. (setq re (substring w 1 -1))
  4282. (if full-words
  4283. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4284. (setq re (regexp-quote (downcase w)))))
  4285. (if neg (push re regexps-) (push re regexps+)))
  4286. words)
  4287. (push (mapconcat #'regexp-quote words "\\s-+")
  4288. regexps+))
  4289. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4290. (if (not regexps+)
  4291. (setq regexp org-outline-regexp-bol)
  4292. (setq regexp (pop regexps+))
  4293. (when hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4294. regexp))))
  4295. (setq files (org-agenda-files nil 'ifmode))
  4296. ;; Add `org-agenda-text-search-extra-files' unless there is some
  4297. ;; restriction.
  4298. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4299. (pop org-agenda-text-search-extra-files)
  4300. (unless (get 'org-agenda-files 'org-restrict)
  4301. (setq files (org-add-archive-files files))))
  4302. ;; Uniquify files. However, let `org-check-agenda-file' handle
  4303. ;; non-existent ones.
  4304. (setq files (cl-remove-duplicates
  4305. (append files org-agenda-text-search-extra-files)
  4306. :test (lambda (a b)
  4307. (and (file-exists-p a)
  4308. (file-exists-p b)
  4309. (file-equal-p a b))))
  4310. rtnall nil)
  4311. (while (setq file (pop files))
  4312. (setq ee nil)
  4313. (catch 'nextfile
  4314. (org-check-agenda-file file)
  4315. (setq buffer (if (file-exists-p file)
  4316. (org-get-agenda-file-buffer file)
  4317. (error "No such file %s" file)))
  4318. (unless buffer
  4319. ;; If file does not exist, make sure an error message is sent
  4320. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4321. file))))
  4322. (with-current-buffer buffer
  4323. (with-syntax-table (org-search-syntax-table)
  4324. (unless (derived-mode-p 'org-mode)
  4325. (error "Agenda file %s is not in Org mode" file))
  4326. (let ((case-fold-search t))
  4327. (save-excursion
  4328. (save-restriction
  4329. (if (eq buffer org-agenda-restrict)
  4330. (narrow-to-region org-agenda-restrict-begin
  4331. org-agenda-restrict-end)
  4332. (widen))
  4333. (goto-char (point-min))
  4334. (unless (or (org-at-heading-p)
  4335. (outline-next-heading))
  4336. (throw 'nextfile t))
  4337. (goto-char (max (point-min) (1- (point))))
  4338. (while (re-search-forward regexp nil t)
  4339. (org-back-to-heading t)
  4340. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4341. (> (org-reduced-level (org-outline-level))
  4342. org-agenda-search-view-max-outline-level)
  4343. (forward-line -1)
  4344. (org-back-to-heading t)))
  4345. (skip-chars-forward "* ")
  4346. (setq beg (point-at-bol)
  4347. beg1 (point)
  4348. end (progn
  4349. (outline-next-heading)
  4350. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4351. (> (org-reduced-level (org-outline-level))
  4352. org-agenda-search-view-max-outline-level)
  4353. (forward-line 1)
  4354. (outline-next-heading)))
  4355. (point)))
  4356. (catch :skip
  4357. (goto-char beg)
  4358. (org-agenda-skip)
  4359. (setq str (buffer-substring-no-properties
  4360. (point-at-bol)
  4361. (if hdl-only (point-at-eol) end)))
  4362. (mapc (lambda (wr) (when (string-match wr str)
  4363. (goto-char (1- end))
  4364. (throw :skip t)))
  4365. regexps-)
  4366. (mapc (lambda (wr) (unless (string-match wr str)
  4367. (goto-char (1- end))
  4368. (throw :skip t)))
  4369. (if todo-only
  4370. (cons (concat "^\\*+[ \t]+"
  4371. org-not-done-regexp)
  4372. regexps+)
  4373. regexps+))
  4374. (goto-char beg)
  4375. (setq marker (org-agenda-new-marker (point))
  4376. category (org-get-category)
  4377. level (make-string (org-reduced-level (org-outline-level)) ? )
  4378. inherited-tags
  4379. (or (eq org-agenda-show-inherited-tags 'always)
  4380. (and (listp org-agenda-show-inherited-tags)
  4381. (memq 'todo org-agenda-show-inherited-tags))
  4382. (and (eq org-agenda-show-inherited-tags t)
  4383. (or (eq org-agenda-use-tag-inheritance t)
  4384. (memq 'todo org-agenda-use-tag-inheritance))))
  4385. tags (org-get-tags nil (not inherited-tags))
  4386. txt (org-agenda-format-item
  4387. ""
  4388. (buffer-substring-no-properties
  4389. beg1 (point-at-eol))
  4390. level category tags t))
  4391. (org-add-props txt props
  4392. 'org-marker marker 'org-hd-marker marker
  4393. 'org-todo-regexp org-todo-regexp
  4394. 'level level
  4395. 'org-complex-heading-regexp org-complex-heading-regexp
  4396. 'priority 1000
  4397. 'type "search")
  4398. (push txt ee)
  4399. (goto-char (1- end))))))))))
  4400. (setq rtn (nreverse ee))
  4401. (setq rtnall (append rtnall rtn)))
  4402. (org-agenda--insert-overriding-header
  4403. (with-temp-buffer
  4404. (insert "Search words: ")
  4405. (add-text-properties (point-min) (1- (point))
  4406. (list 'face 'org-agenda-structure))
  4407. (setq pos (point))
  4408. (insert string "\n")
  4409. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4410. (setq pos (point))
  4411. (unless org-agenda-multi
  4412. (insert (substitute-command-keys "\\<org-agenda-mode-map>\
  4413. Press `\\[org-agenda-manipulate-query-add]', \
  4414. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4415. `\\[org-agenda-manipulate-query-add-re]', \
  4416. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4417. `\\[universal-argument] \\[org-agenda-redo]' for a fresh search\n"))
  4418. (add-text-properties pos (1- (point))
  4419. (list 'face 'org-agenda-structure-secondary)))
  4420. (buffer-string)))
  4421. (org-agenda-mark-header-line (point-min))
  4422. (when rtnall
  4423. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4424. (goto-char (point-min))
  4425. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4426. (add-text-properties (point-min) (point-max)
  4427. `(org-agenda-type search
  4428. org-last-args (,todo-only ,string ,edit-at)
  4429. org-redo-cmd ,org-agenda-redo-command
  4430. org-series-cmd ,org-cmd))
  4431. (org-agenda-finalize)
  4432. (setq buffer-read-only t))))
  4433. ;;; Agenda TODO list
  4434. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4435. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4436. (concat
  4437. (if (or (equal keywords "ALL") (not keywords))
  4438. (propertize "ALL" 'face 'org-agenda-structure-filter)
  4439. (mapconcat
  4440. (lambda (kw)
  4441. (propertize kw 'face (list (org-get-todo-face kw) 'org-agenda-structure)))
  4442. (org-split-string keywords "|")
  4443. "|"))
  4444. "\n"))
  4445. (defvar org-select-this-todo-keyword nil)
  4446. (defvar org-last-arg nil)
  4447. (defvar crm-separator)
  4448. ;;;###autoload
  4449. (defun org-todo-list (&optional arg)
  4450. "Show all (not done) TODO entries from all agenda file in a single list.
  4451. The prefix arg can be used to select a specific TODO keyword and limit
  4452. the list to these. When using `\\[universal-argument]', you will be prompted
  4453. for a keyword. A numeric prefix directly selects the Nth keyword in
  4454. `org-todo-keywords-1'."
  4455. (interactive "P")
  4456. (when org-agenda-overriding-arguments
  4457. (setq arg org-agenda-overriding-arguments))
  4458. (when (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4459. (let* ((today (org-today))
  4460. (date (calendar-gregorian-from-absolute today))
  4461. (completion-ignore-case t)
  4462. kwds org-select-this-todo-keyword rtn rtnall files file pos)
  4463. (catch 'exit
  4464. (setq org-agenda-buffer-name
  4465. (org-agenda--get-buffer-name
  4466. (and org-agenda-sticky
  4467. (if (stringp org-select-this-todo-keyword)
  4468. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4469. org-select-this-todo-keyword)
  4470. (format "*Org Agenda(%s)*" (or org-keys "t"))))))
  4471. (org-agenda-prepare "TODO")
  4472. (setq kwds org-todo-keywords-for-agenda
  4473. org-select-this-todo-keyword (if (stringp arg) arg
  4474. (and (integerp arg)
  4475. (> arg 0)
  4476. (nth (1- arg) kwds))))
  4477. (when (equal arg '(4))
  4478. (setq org-select-this-todo-keyword
  4479. (mapconcat #'identity
  4480. (let ((crm-separator "|"))
  4481. (completing-read-multiple
  4482. "Keyword (or KWD1|KWD2|...): "
  4483. (mapcar #'list kwds) nil nil))
  4484. "|")))
  4485. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4486. (org-compile-prefix-format 'todo)
  4487. (org-set-sorting-strategy 'todo)
  4488. (setq org-agenda-redo-command
  4489. `(org-todo-list (or (and (numberp current-prefix-arg)
  4490. current-prefix-arg)
  4491. ,org-select-this-todo-keyword
  4492. current-prefix-arg ,arg)))
  4493. (setq files (org-agenda-files nil 'ifmode)
  4494. rtnall nil)
  4495. (while (setq file (pop files))
  4496. (catch 'nextfile
  4497. (org-check-agenda-file file)
  4498. (setq rtn (org-agenda-get-day-entries file date :todo))
  4499. (setq rtnall (append rtnall rtn))))
  4500. (org-agenda--insert-overriding-header
  4501. (with-temp-buffer
  4502. (insert "Global list of TODO items of type: ")
  4503. (add-text-properties (point-min) (1- (point))
  4504. (list 'face 'org-agenda-structure
  4505. 'short-heading
  4506. (concat "ToDo: "
  4507. (or org-select-this-todo-keyword "ALL"))))
  4508. (org-agenda-mark-header-line (point-min))
  4509. (insert (org-agenda-propertize-selected-todo-keywords
  4510. org-select-this-todo-keyword))
  4511. (setq pos (point))
  4512. (unless org-agenda-multi
  4513. (insert (substitute-command-keys "Press \
  4514. \\<org-agenda-mode-map>`N \\[org-agenda-redo]' (e.g. `0 \\[org-agenda-redo]') \
  4515. to search again: (0)[ALL]"))
  4516. (let ((n 0))
  4517. (dolist (k kwds)
  4518. (let ((s (format "(%d)%s" (cl-incf n) k)))
  4519. (when (> (+ (current-column) (string-width s) 1) (window-width))
  4520. (insert "\n "))
  4521. (insert " " s))))
  4522. (insert "\n"))
  4523. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-secondary))
  4524. (buffer-string)))
  4525. (org-agenda-mark-header-line (point-min))
  4526. (when rtnall
  4527. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4528. (goto-char (point-min))
  4529. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4530. (add-text-properties (point-min) (point-max)
  4531. `(org-agenda-type todo
  4532. org-last-args ,arg
  4533. org-redo-cmd ,org-agenda-redo-command
  4534. org-series-cmd ,org-cmd))
  4535. (org-agenda-finalize)
  4536. (setq buffer-read-only t))))
  4537. ;;; Agenda tags match
  4538. ;;;###autoload
  4539. (defun org-tags-view (&optional todo-only match)
  4540. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4541. The prefix arg TODO-ONLY limits the search to TODO entries."
  4542. (interactive "P")
  4543. (when org-agenda-overriding-arguments
  4544. (setq todo-only (car org-agenda-overriding-arguments)
  4545. match (nth 1 org-agenda-overriding-arguments)))
  4546. (let* ((org-tags-match-list-sublevels
  4547. org-tags-match-list-sublevels)
  4548. (completion-ignore-case t)
  4549. (org--matcher-tags-todo-only todo-only)
  4550. rtn rtnall files file pos matcher
  4551. buffer)
  4552. (when (and (stringp match) (not (string-match "\\S-" match)))
  4553. (setq match nil))
  4554. (catch 'exit
  4555. (setq org-agenda-buffer-name
  4556. (org-agenda--get-buffer-name
  4557. (and org-agenda-sticky
  4558. (if (stringp match)
  4559. (format "*Org Agenda(%s:%s)*"
  4560. (or org-keys (or (and todo-only "M") "m"))
  4561. match)
  4562. (format "*Org Agenda(%s)*"
  4563. (or (and todo-only "M") "m"))))))
  4564. (setq matcher (org-make-tags-matcher match))
  4565. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4566. ;; expanding tags within `org-make-tags-matcher'
  4567. (org-agenda-prepare (concat "TAGS " match))
  4568. (setq match (car matcher)
  4569. matcher (cdr matcher))
  4570. (org-compile-prefix-format 'tags)
  4571. (org-set-sorting-strategy 'tags)
  4572. (setq org-agenda-query-string match)
  4573. (setq org-agenda-redo-command
  4574. (list 'org-tags-view
  4575. `(quote ,org--matcher-tags-todo-only)
  4576. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4577. (setq files (org-agenda-files nil 'ifmode)
  4578. rtnall nil)
  4579. (while (setq file (pop files))
  4580. (catch 'nextfile
  4581. (org-check-agenda-file file)
  4582. (setq buffer (if (file-exists-p file)
  4583. (org-get-agenda-file-buffer file)
  4584. (error "No such file %s" file)))
  4585. (if (not buffer)
  4586. ;; If file does not exist, error message to agenda
  4587. (setq rtn (list
  4588. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4589. rtnall (append rtnall rtn))
  4590. (with-current-buffer buffer
  4591. (unless (derived-mode-p 'org-mode)
  4592. (error "Agenda file %s is not in Org mode" file))
  4593. (save-excursion
  4594. (save-restriction
  4595. (if (eq buffer org-agenda-restrict)
  4596. (narrow-to-region org-agenda-restrict-begin
  4597. org-agenda-restrict-end)
  4598. (widen))
  4599. (setq rtn (org-scan-tags 'agenda
  4600. matcher
  4601. org--matcher-tags-todo-only))
  4602. (setq rtnall (append rtnall rtn))))))))
  4603. (org-agenda--insert-overriding-header
  4604. (with-temp-buffer
  4605. (insert "Headlines with TAGS match: ")
  4606. (add-text-properties (point-min) (1- (point))
  4607. (list 'face 'org-agenda-structure
  4608. 'short-heading
  4609. (concat "Match: " match)))
  4610. (setq pos (point))
  4611. (insert match "\n")
  4612. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4613. (setq pos (point))
  4614. (unless org-agenda-multi
  4615. (insert (substitute-command-keys
  4616. "Press \
  4617. \\<org-agenda-mode-map>`\\[universal-argument] \\[org-agenda-redo]' \
  4618. to search again\n")))
  4619. (add-text-properties pos (1- (point))
  4620. (list 'face 'org-agenda-structure-secondary))
  4621. (buffer-string)))
  4622. (org-agenda-mark-header-line (point-min))
  4623. (when rtnall
  4624. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4625. (goto-char (point-min))
  4626. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4627. (add-text-properties
  4628. (point-min) (point-max)
  4629. `(org-agenda-type tags
  4630. org-last-args (,org--matcher-tags-todo-only ,match)
  4631. org-redo-cmd ,org-agenda-redo-command
  4632. org-series-cmd ,org-cmd))
  4633. (org-agenda-finalize)
  4634. (setq buffer-read-only t))))
  4635. ;;; Agenda Finding stuck projects
  4636. (defvar org-agenda-skip-regexp nil
  4637. "Regular expression used in skipping subtrees for the agenda.
  4638. This is basically a temporary global variable that can be set and then
  4639. used by user-defined selections using `org-agenda-skip-function'.")
  4640. (defvar org-agenda-overriding-header nil
  4641. "When set during agenda, todo and tags searches it replaces the header.
  4642. If an empty string, no header will be inserted. If any other
  4643. string, it will be inserted as a header. If a function, insert
  4644. the string returned by the function as a header. If nil, a
  4645. header will be generated automatically according to the command.
  4646. This variable should not be set directly, but custom commands can
  4647. bind it in the options section.")
  4648. (defun org-agenda-skip-entry-if (&rest conditions)
  4649. "Skip entry if any of CONDITIONS is true.
  4650. See `org-agenda-skip-if' for details."
  4651. (org-agenda-skip-if nil conditions))
  4652. (defun org-agenda-skip-subtree-if (&rest conditions)
  4653. "Skip subtree if any of CONDITIONS is true.
  4654. See `org-agenda-skip-if' for details."
  4655. (org-agenda-skip-if t conditions))
  4656. (defun org-agenda-skip-if (subtree conditions)
  4657. "Check current entity for CONDITIONS.
  4658. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4659. the entry (i.e. the text before the next heading) is checked.
  4660. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4661. from different tests. Valid conditions are:
  4662. scheduled Check if there is a scheduled cookie
  4663. notscheduled Check if there is no scheduled cookie
  4664. deadline Check if there is a deadline
  4665. notdeadline Check if there is no deadline
  4666. timestamp Check if there is a timestamp (also deadline or scheduled)
  4667. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4668. regexp Check if regexp matches
  4669. notregexp Check if regexp does not match.
  4670. todo Check if TODO keyword matches
  4671. nottodo Check if TODO keyword does not match
  4672. The regexp is taken from the conditions list, it must come right after
  4673. the `regexp' or `notregexp' element.
  4674. `todo' and `nottodo' accept as an argument a list of todo
  4675. keywords, which may include \"*\" to match any todo keyword.
  4676. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4677. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4678. Instead of a list, a keyword class may be given. For example:
  4679. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4680. would skip entries that haven't been marked with any of \"DONE\"
  4681. keywords. Possible classes are: `todo', `done', `any'.
  4682. If any of these conditions is met, this function returns the end point of
  4683. the entity, causing the search to continue from there. This is a function
  4684. that can be put into `org-agenda-skip-function' for the duration of a command."
  4685. (org-back-to-heading t)
  4686. (let* (;; (beg (point))
  4687. (end (if subtree (save-excursion (org-end-of-subtree t) (point))
  4688. (org-entry-end-position)))
  4689. (planning-end (if subtree end (line-end-position 2)))
  4690. m)
  4691. (and
  4692. (or (and (memq 'scheduled conditions)
  4693. (re-search-forward org-scheduled-time-regexp planning-end t))
  4694. (and (memq 'notscheduled conditions)
  4695. (not
  4696. (save-excursion
  4697. (re-search-forward org-scheduled-time-regexp planning-end t))))
  4698. (and (memq 'deadline conditions)
  4699. (re-search-forward org-deadline-time-regexp planning-end t))
  4700. (and (memq 'notdeadline conditions)
  4701. (not
  4702. (save-excursion
  4703. (re-search-forward org-deadline-time-regexp planning-end t))))
  4704. (and (memq 'timestamp conditions)
  4705. (re-search-forward org-ts-regexp end t))
  4706. (and (memq 'nottimestamp conditions)
  4707. (not (save-excursion (re-search-forward org-ts-regexp end t))))
  4708. (and (setq m (memq 'regexp conditions))
  4709. (stringp (nth 1 m))
  4710. (re-search-forward (nth 1 m) end t))
  4711. (and (setq m (memq 'notregexp conditions))
  4712. (stringp (nth 1 m))
  4713. (not (save-excursion (re-search-forward (nth 1 m) end t))))
  4714. (and (or
  4715. (setq m (memq 'nottodo conditions))
  4716. (setq m (memq 'todo-unblocked conditions))
  4717. (setq m (memq 'nottodo-unblocked conditions))
  4718. (setq m (memq 'todo conditions)))
  4719. (org-agenda-skip-if-todo m end)))
  4720. end)))
  4721. (defun org-agenda-skip-if-todo (args end)
  4722. "Helper function for `org-agenda-skip-if', do not use it directly.
  4723. ARGS is a list with first element either `todo', `nottodo',
  4724. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4725. a list of TODO keywords, or a state symbol `todo' or `done' or
  4726. `any'."
  4727. (let ((todo-re
  4728. (concat "^\\*+[ \t]+"
  4729. (regexp-opt
  4730. (pcase args
  4731. (`(,_ todo)
  4732. (org-delete-all org-done-keywords
  4733. (copy-sequence org-todo-keywords-1)))
  4734. (`(,_ done) org-done-keywords)
  4735. (`(,_ any) org-todo-keywords-1)
  4736. (`(,_ ,(pred atom))
  4737. (error "Invalid TODO class or type: %S" args))
  4738. (`(,_ ,(pred (member "*"))) org-todo-keywords-1)
  4739. (`(,_ ,todo-list) todo-list))
  4740. 'words))))
  4741. (pcase args
  4742. (`(todo . ,_)
  4743. (let (case-fold-search) (re-search-forward todo-re end t)))
  4744. (`(nottodo . ,_)
  4745. (not (let (case-fold-search) (re-search-forward todo-re end t))))
  4746. (`(todo-unblocked . ,_)
  4747. (catch :unblocked
  4748. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4749. (when (org-entry-blocked-p) (throw :unblocked t)))
  4750. nil))
  4751. (`(nottodo-unblocked . ,_)
  4752. (catch :unblocked
  4753. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4754. (when (org-entry-blocked-p) (throw :unblocked nil)))
  4755. t))
  4756. (`(,type . ,_) (error "Unknown TODO skip type: %S" type)))))
  4757. ;;;###autoload
  4758. (defun org-agenda-list-stuck-projects (&rest _ignore)
  4759. "Create agenda view for projects that are stuck.
  4760. Stuck projects are project that have no next actions. For the definitions
  4761. of what a project is and how to check if it stuck, customize the variable
  4762. `org-stuck-projects'."
  4763. (interactive)
  4764. (let* ((org-agenda-overriding-header
  4765. (or org-agenda-overriding-header "List of stuck projects: "))
  4766. (matcher (nth 0 org-stuck-projects))
  4767. (todo (nth 1 org-stuck-projects))
  4768. (tags (nth 2 org-stuck-projects))
  4769. (gen-re (org-string-nw-p (nth 3 org-stuck-projects)))
  4770. (todo-wds
  4771. (if (not (member "*" todo)) todo
  4772. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  4773. (org-delete-all org-done-keywords-for-agenda
  4774. (copy-sequence org-todo-keywords-for-agenda))))
  4775. (todo-re (and todo
  4776. (format "^\\*+[ \t]+\\(%s\\)\\>"
  4777. (mapconcat #'identity todo-wds "\\|"))))
  4778. (tags-re (cond ((null tags) nil)
  4779. ((member "*" tags) org-tag-line-re)
  4780. (tags
  4781. (let ((other-tags (format "\\(?:%s:\\)*" org-tag-re)))
  4782. (concat org-outline-regexp-bol
  4783. ".*?[ \t]:"
  4784. other-tags
  4785. (regexp-opt tags t)
  4786. ":" other-tags "[ \t]*$")))
  4787. (t nil)))
  4788. (re-list (delq nil (list todo-re tags-re gen-re)))
  4789. (skip-re
  4790. (if (null re-list)
  4791. (error "Missing information to identify unstuck projects")
  4792. (mapconcat #'identity re-list "\\|")))
  4793. (org-agenda-skip-function
  4794. ;; Skip entry if `org-agenda-skip-regexp' matches anywhere
  4795. ;; in the subtree.
  4796. (lambda ()
  4797. (and (save-excursion
  4798. (let ((case-fold-search nil))
  4799. (re-search-forward
  4800. skip-re (save-excursion (org-end-of-subtree t)) t)))
  4801. (progn (outline-next-heading) (point))))))
  4802. (org-tags-view nil matcher)
  4803. (setq org-agenda-buffer-name (buffer-name))
  4804. (with-current-buffer org-agenda-buffer-name
  4805. (setq org-agenda-redo-command
  4806. `(org-agenda-list-stuck-projects ,current-prefix-arg))
  4807. (let ((inhibit-read-only t))
  4808. (add-text-properties
  4809. (point-min) (point-max)
  4810. `(org-redo-cmd ,org-agenda-redo-command))))))
  4811. ;;; Diary integration
  4812. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4813. (defvar diary-list-entries-hook)
  4814. (defvar diary-time-regexp)
  4815. (defvar diary-modify-entry-list-string-function)
  4816. (defvar diary-file-name-prefix)
  4817. (defvar diary-display-function)
  4818. (defun org-get-entries-from-diary (date)
  4819. "Get the (Emacs Calendar) diary entries for DATE."
  4820. (require 'diary-lib)
  4821. (declare-function diary-fancy-display "diary-lib" ())
  4822. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4823. (diary-display-function #'diary-fancy-display)
  4824. (pop-up-frames nil)
  4825. (diary-list-entries-hook
  4826. (cons 'org-diary-default-entry diary-list-entries-hook))
  4827. (diary-file-name-prefix nil) ; turn this feature off
  4828. (diary-modify-entry-list-string-function
  4829. #'org-modify-diary-entry-string)
  4830. (diary-time-regexp (concat "^" diary-time-regexp))
  4831. entries
  4832. (org-disable-agenda-to-diary t))
  4833. (save-excursion
  4834. (save-window-excursion
  4835. (diary-list-entries date 1)))
  4836. (if (not (get-buffer diary-fancy-buffer))
  4837. (setq entries nil)
  4838. (with-current-buffer diary-fancy-buffer
  4839. (setq buffer-read-only nil)
  4840. (if (zerop (buffer-size))
  4841. ;; No entries
  4842. (setq entries nil)
  4843. ;; Omit the date and other unnecessary stuff
  4844. (org-agenda-cleanup-fancy-diary)
  4845. ;; Add prefix to each line and extend the text properties
  4846. (if (zerop (buffer-size))
  4847. (setq entries nil)
  4848. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4849. (setq entries
  4850. (with-temp-buffer
  4851. (insert entries) (goto-char (point-min))
  4852. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4853. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4854. (replace-match (concat "; " (match-string 1)))))
  4855. (buffer-string)))))
  4856. (set-buffer-modified-p nil)
  4857. (kill-buffer diary-fancy-buffer)))
  4858. (when entries
  4859. (setq entries (org-split-string entries "\n"))
  4860. (setq entries
  4861. (mapcar
  4862. (lambda (x)
  4863. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4864. ;; Extend the text properties to the beginning of the line
  4865. (org-add-props x (text-properties-at (1- (length x)) x)
  4866. 'type "diary" 'date date 'face 'org-agenda-diary))
  4867. entries)))))
  4868. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4869. "Hook run when the fancy diary buffer is cleaned up.")
  4870. (defun org-agenda-cleanup-fancy-diary ()
  4871. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4872. This gets rid of the date, the underline under the date, and the
  4873. dummy entry installed by Org mode to ensure non-empty diary for
  4874. each date. It also removes lines that contain only whitespace."
  4875. (goto-char (point-min))
  4876. (if (looking-at ".*?:[ \t]*")
  4877. (progn
  4878. (replace-match "")
  4879. (re-search-forward "\n=+$" nil t)
  4880. (replace-match "")
  4881. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4882. (re-search-forward "\n=+$" nil t)
  4883. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4884. (goto-char (point-min))
  4885. (while (re-search-forward "^ +\n" nil t)
  4886. (replace-match ""))
  4887. (goto-char (point-min))
  4888. (when (re-search-forward "^Org mode dummy\n?" nil t)
  4889. (replace-match ""))
  4890. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4891. (defun org-modify-diary-entry-string (string)
  4892. "Add text properties to string, allowing Org to act on it."
  4893. (org-add-props string nil
  4894. 'mouse-face 'highlight
  4895. 'help-echo (if buffer-file-name
  4896. (format "mouse-2 or RET jump to diary file %s"
  4897. (abbreviate-file-name buffer-file-name))
  4898. "")
  4899. 'org-agenda-diary-link t
  4900. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4901. (defun org-diary-default-entry ()
  4902. "Add a dummy entry to the diary.
  4903. Needed to avoid empty dates which mess up holiday display."
  4904. ;; Catch the error if dealing with the new add-to-diary-alist
  4905. (when org-disable-agenda-to-diary
  4906. (diary-add-to-list original-date "Org mode dummy" "")))
  4907. (defvar org-diary-last-run-time nil)
  4908. ;;;###autoload
  4909. (defun org-diary (&rest args)
  4910. "Return diary information from org files.
  4911. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4912. It accesses org files and extracts information from those files to be
  4913. listed in the diary. The function accepts arguments specifying what
  4914. items should be listed. For a list of arguments allowed here, see the
  4915. variable `org-agenda-entry-types'.
  4916. The call in the diary file should look like this:
  4917. &%%(org-diary) ~/path/to/some/orgfile.org
  4918. Use a separate line for each org file to check. Or, if you omit the file name,
  4919. all files listed in `org-agenda-files' will be checked automatically:
  4920. &%%(org-diary)
  4921. If you don't give any arguments (as in the example above), the default value
  4922. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4923. So the example above may also be written as
  4924. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4925. The function expects the lisp variables `entry' and `date' to be provided
  4926. by the caller, because this is how the calendar works. Don't use this
  4927. function from a program - use `org-agenda-get-day-entries' instead."
  4928. (with-no-warnings (defvar date) (defvar entry))
  4929. (when (> (- (float-time)
  4930. org-agenda-last-marker-time)
  4931. 5)
  4932. ;; I am not sure if this works with sticky agendas, because the marker
  4933. ;; list is then no longer a global variable.
  4934. (org-agenda-reset-markers))
  4935. (org-compile-prefix-format 'agenda)
  4936. (org-set-sorting-strategy 'agenda)
  4937. (setq args (or args org-agenda-entry-types))
  4938. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4939. (list entry)
  4940. (org-agenda-files t)))
  4941. (time (float-time))
  4942. file rtn results)
  4943. (when (or (not org-diary-last-run-time)
  4944. (> (- time
  4945. org-diary-last-run-time)
  4946. 3))
  4947. (org-agenda-prepare-buffers files))
  4948. (setq org-diary-last-run-time time)
  4949. ;; If this is called during org-agenda, don't return any entries to
  4950. ;; the calendar. Org Agenda will list these entries itself.
  4951. (when org-disable-agenda-to-diary (setq files nil))
  4952. (while (setq file (pop files))
  4953. (setq rtn (apply #'org-agenda-get-day-entries file date args))
  4954. (setq results (append results rtn)))
  4955. (when results
  4956. (setq results
  4957. (mapcar (lambda (i) (replace-regexp-in-string
  4958. org-link-bracket-re "\\2" i))
  4959. results))
  4960. (concat (org-agenda-finalize-entries results) "\n"))))
  4961. ;;; Agenda entry finders
  4962. (defun org-agenda--timestamp-to-absolute (&rest args)
  4963. "Call `org-time-string-to-absolute' with ARGS.
  4964. However, throw `:skip' whenever an error is raised."
  4965. (condition-case e
  4966. (apply #'org-time-string-to-absolute args)
  4967. (org-diary-sexp-no-match (throw :skip nil))
  4968. (error
  4969. (message "%s; Skipping entry" (error-message-string e))
  4970. (throw :skip nil))))
  4971. (defun org-agenda-get-day-entries (file date &rest args)
  4972. "Does the work for `org-diary' and `org-agenda'.
  4973. FILE is the path to a file to be checked for entries. DATE is date like
  4974. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4975. which kind of entries should be extracted. For details about these, see
  4976. the documentation of `org-diary'."
  4977. (let* ((org-startup-folded nil)
  4978. (org-startup-align-all-tables nil)
  4979. (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
  4980. (error "No such file %s" file))))
  4981. (if (not buffer)
  4982. ;; If file does not exist, signal it in diary nonetheless.
  4983. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4984. (with-current-buffer buffer
  4985. (unless (derived-mode-p 'org-mode)
  4986. (error "Agenda file %s is not in Org mode" file))
  4987. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4988. (setf org-agenda-current-date date)
  4989. (save-excursion
  4990. (save-restriction
  4991. (if (eq buffer org-agenda-restrict)
  4992. (narrow-to-region org-agenda-restrict-begin
  4993. org-agenda-restrict-end)
  4994. (widen))
  4995. ;; Rationalize ARGS. Also make sure `:deadline' comes
  4996. ;; first in order to populate DEADLINES before passing it.
  4997. ;;
  4998. ;; We use `delq' since `org-uniquify' duplicates ARGS,
  4999. ;; guarding us from modifying `org-agenda-entry-types'.
  5000. (setf args (org-uniquify (or args org-agenda-entry-types)))
  5001. (when (and (memq :scheduled args) (memq :scheduled* args))
  5002. (setf args (delq :scheduled* args)))
  5003. (cond
  5004. ((memq :deadline args)
  5005. (setf args (cons :deadline
  5006. (delq :deadline (delq :deadline* args)))))
  5007. ((memq :deadline* args)
  5008. (setf args (cons :deadline* (delq :deadline* args)))))
  5009. ;; Collect list of headlines. Return them flattened.
  5010. (let ((case-fold-search nil) results deadlines)
  5011. (org-dlet
  5012. ((date date))
  5013. (dolist (arg args (apply #'nconc (nreverse results)))
  5014. (pcase arg
  5015. ((and :todo (guard (org-agenda-today-p date)))
  5016. (push (org-agenda-get-todos) results))
  5017. (:timestamp
  5018. (push (org-agenda-get-blocks) results)
  5019. (push (org-agenda-get-timestamps deadlines) results))
  5020. (:sexp
  5021. (push (org-agenda-get-sexps) results))
  5022. (:scheduled
  5023. (push (org-agenda-get-scheduled deadlines) results))
  5024. (:scheduled*
  5025. (push (org-agenda-get-scheduled deadlines t) results))
  5026. (:closed
  5027. (push (org-agenda-get-progress) results))
  5028. (:deadline
  5029. (setf deadlines (org-agenda-get-deadlines))
  5030. (push deadlines results))
  5031. (:deadline*
  5032. (setf deadlines (org-agenda-get-deadlines t))
  5033. (push deadlines results))))))))))))
  5034. (defsubst org-em (x y list)
  5035. "Is X or Y a member of LIST?"
  5036. (or (memq x list) (memq y list)))
  5037. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  5038. (defvar org-agenda-sorting-strategy-selected nil)
  5039. (defun org-agenda-entry-get-agenda-timestamp (pom)
  5040. "Retrieve timestamp information for sorting agenda views.
  5041. Given a point or marker POM, returns a cons cell of the timestamp
  5042. and the timestamp type relevant for the sorting strategy in
  5043. `org-agenda-sorting-strategy-selected'."
  5044. (let (ts ts-date-type)
  5045. (save-match-data
  5046. (cond ((org-em 'scheduled-up 'scheduled-down
  5047. org-agenda-sorting-strategy-selected)
  5048. (setq ts (org-entry-get pom "SCHEDULED")
  5049. ts-date-type " scheduled"))
  5050. ((org-em 'deadline-up 'deadline-down
  5051. org-agenda-sorting-strategy-selected)
  5052. (setq ts (org-entry-get pom "DEADLINE")
  5053. ts-date-type " deadline"))
  5054. ((org-em 'ts-up 'ts-down
  5055. org-agenda-sorting-strategy-selected)
  5056. (setq ts (org-entry-get pom "TIMESTAMP")
  5057. ts-date-type " timestamp"))
  5058. ((org-em 'tsia-up 'tsia-down
  5059. org-agenda-sorting-strategy-selected)
  5060. (setq ts (org-entry-get pom "TIMESTAMP_IA")
  5061. ts-date-type " timestamp_ia"))
  5062. ((org-em 'timestamp-up 'timestamp-down
  5063. org-agenda-sorting-strategy-selected)
  5064. (setq ts (or (org-entry-get pom "SCHEDULED")
  5065. (org-entry-get pom "DEADLINE")
  5066. (org-entry-get pom "TIMESTAMP")
  5067. (org-entry-get pom "TIMESTAMP_IA"))
  5068. ts-date-type ""))
  5069. (t (setq ts-date-type "")))
  5070. (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
  5071. ts-date-type))))
  5072. (defun org-agenda-get-todos ()
  5073. "Return the TODO information for agenda display."
  5074. (let* ((props (list 'face nil
  5075. 'done-face 'org-agenda-done
  5076. 'org-not-done-regexp org-not-done-regexp
  5077. 'org-todo-regexp org-todo-regexp
  5078. 'org-complex-heading-regexp org-complex-heading-regexp
  5079. 'mouse-face 'highlight
  5080. 'help-echo
  5081. (format "mouse-2 or RET jump to org file %s"
  5082. (abbreviate-file-name buffer-file-name))))
  5083. (case-fold-search nil)
  5084. (regexp (format org-heading-keyword-regexp-format
  5085. (cond
  5086. ((and org-select-this-todo-keyword
  5087. (equal org-select-this-todo-keyword "*"))
  5088. org-todo-regexp)
  5089. (org-select-this-todo-keyword
  5090. (concat "\\("
  5091. (mapconcat #'identity
  5092. (org-split-string
  5093. org-select-this-todo-keyword
  5094. "|")
  5095. "\\|")
  5096. "\\)"))
  5097. (t org-not-done-regexp))))
  5098. marker priority category level tags todo-state
  5099. ts-date ts-date-type ts-date-pair
  5100. ee txt beg end inherited-tags todo-state-end-pos)
  5101. (goto-char (point-min))
  5102. (while (re-search-forward regexp nil t)
  5103. (catch :skip
  5104. (save-match-data
  5105. (beginning-of-line)
  5106. (org-agenda-skip)
  5107. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  5108. (unless (and (setq todo-state (org-get-todo-state))
  5109. (setq todo-state-end-pos (match-end 2)))
  5110. (goto-char end)
  5111. (throw :skip nil))
  5112. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  5113. (goto-char (1+ beg))
  5114. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  5115. (throw :skip nil)))
  5116. (goto-char (match-beginning 2))
  5117. (setq marker (org-agenda-new-marker (match-beginning 0))
  5118. category (org-get-category)
  5119. ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
  5120. ts-date (car ts-date-pair)
  5121. ts-date-type (cdr ts-date-pair)
  5122. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  5123. inherited-tags
  5124. (or (eq org-agenda-show-inherited-tags 'always)
  5125. (and (listp org-agenda-show-inherited-tags)
  5126. (memq 'todo org-agenda-show-inherited-tags))
  5127. (and (eq org-agenda-show-inherited-tags t)
  5128. (or (eq org-agenda-use-tag-inheritance t)
  5129. (memq 'todo org-agenda-use-tag-inheritance))))
  5130. tags (org-get-tags nil (not inherited-tags))
  5131. level (make-string (org-reduced-level (org-outline-level)) ? )
  5132. txt (org-agenda-format-item "" txt level category tags t)
  5133. priority (1+ (org-get-priority txt)))
  5134. (org-add-props txt props
  5135. 'org-marker marker 'org-hd-marker marker
  5136. 'priority priority
  5137. 'level level
  5138. 'ts-date ts-date
  5139. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  5140. (push txt ee)
  5141. (if org-agenda-todo-list-sublevels
  5142. (goto-char todo-state-end-pos)
  5143. (org-end-of-subtree 'invisible))))
  5144. (nreverse ee)))
  5145. (defun org-agenda-todo-custom-ignore-p (time n)
  5146. "Check whether timestamp is farther away than n number of days.
  5147. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5148. `org-agenda-todo-ignore-scheduled' or
  5149. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5150. (let ((days (org-time-stamp-to-now
  5151. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5152. (if (>= n 0)
  5153. (>= days n)
  5154. (<= days n))))
  5155. ;;;###autoload
  5156. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5157. (&optional end)
  5158. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5159. (when (or org-agenda-todo-ignore-with-date
  5160. org-agenda-todo-ignore-scheduled
  5161. org-agenda-todo-ignore-deadlines
  5162. org-agenda-todo-ignore-timestamp)
  5163. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5164. (save-excursion
  5165. (or (and org-agenda-todo-ignore-with-date
  5166. (re-search-forward org-ts-regexp end t))
  5167. (and org-agenda-todo-ignore-scheduled
  5168. (re-search-forward org-scheduled-time-regexp end t)
  5169. (cond
  5170. ((eq org-agenda-todo-ignore-scheduled 'future)
  5171. (> (org-time-stamp-to-now
  5172. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5173. 0))
  5174. ((eq org-agenda-todo-ignore-scheduled 'past)
  5175. (<= (org-time-stamp-to-now
  5176. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5177. 0))
  5178. ((numberp org-agenda-todo-ignore-scheduled)
  5179. (org-agenda-todo-custom-ignore-p
  5180. (match-string 1) org-agenda-todo-ignore-scheduled))
  5181. (t)))
  5182. (and org-agenda-todo-ignore-deadlines
  5183. (re-search-forward org-deadline-time-regexp end t)
  5184. (cond
  5185. ((eq org-agenda-todo-ignore-deadlines 'all) t)
  5186. ((eq org-agenda-todo-ignore-deadlines 'far)
  5187. (not (org-deadline-close-p (match-string 1))))
  5188. ((eq org-agenda-todo-ignore-deadlines 'future)
  5189. (> (org-time-stamp-to-now
  5190. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5191. 0))
  5192. ((eq org-agenda-todo-ignore-deadlines 'past)
  5193. (<= (org-time-stamp-to-now
  5194. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5195. 0))
  5196. ((numberp org-agenda-todo-ignore-deadlines)
  5197. (org-agenda-todo-custom-ignore-p
  5198. (match-string 1) org-agenda-todo-ignore-deadlines))
  5199. (t (org-deadline-close-p (match-string 1)))))
  5200. (and org-agenda-todo-ignore-timestamp
  5201. (let ((buffer (current-buffer))
  5202. (regexp
  5203. (concat
  5204. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5205. (start (point)))
  5206. ;; Copy current buffer into a temporary one
  5207. (with-temp-buffer
  5208. (insert-buffer-substring buffer start end)
  5209. (goto-char (point-min))
  5210. ;; Delete SCHEDULED and DEADLINE items
  5211. (while (re-search-forward regexp end t)
  5212. (delete-region (match-beginning 0) (match-end 0)))
  5213. (goto-char (point-min))
  5214. ;; No search for timestamp left
  5215. (when (re-search-forward org-ts-regexp nil t)
  5216. (cond
  5217. ((eq org-agenda-todo-ignore-timestamp 'future)
  5218. (> (org-time-stamp-to-now
  5219. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5220. 0))
  5221. ((eq org-agenda-todo-ignore-timestamp 'past)
  5222. (<= (org-time-stamp-to-now
  5223. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5224. 0))
  5225. ((numberp org-agenda-todo-ignore-timestamp)
  5226. (org-agenda-todo-custom-ignore-p
  5227. (match-string 1) org-agenda-todo-ignore-timestamp))
  5228. (t))))))))))
  5229. (defun org-agenda-get-timestamps (&optional deadlines)
  5230. "Return the date stamp information for agenda display.
  5231. Optional argument DEADLINES is a list of deadline items to be
  5232. displayed in agenda view."
  5233. (with-no-warnings (defvar date))
  5234. (let* ((props (list 'face 'org-agenda-calendar-event
  5235. 'org-not-done-regexp org-not-done-regexp
  5236. 'org-todo-regexp org-todo-regexp
  5237. 'org-complex-heading-regexp org-complex-heading-regexp
  5238. 'mouse-face 'highlight
  5239. 'help-echo
  5240. (format "mouse-2 or RET jump to Org file %s"
  5241. (abbreviate-file-name buffer-file-name))))
  5242. (current (calendar-absolute-from-gregorian date))
  5243. (today (org-today))
  5244. (deadline-position-alist
  5245. (mapcar (lambda (d)
  5246. (let ((m (get-text-property 0 'org-hd-marker d)))
  5247. (and m (marker-position m))))
  5248. deadlines))
  5249. ;; Match time-stamps set to current date, time-stamps with
  5250. ;; a repeater, and S-exp time-stamps.
  5251. (regexp
  5252. (concat
  5253. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5254. (regexp-quote
  5255. (substring
  5256. (format-time-string
  5257. (car org-time-stamp-formats)
  5258. (encode-time ; DATE bound by calendar
  5259. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5260. 1 11))
  5261. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5262. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5263. timestamp-items)
  5264. (goto-char (point-min))
  5265. (while (re-search-forward regexp nil t)
  5266. ;; Skip date ranges, scheduled and deadlines, which are handled
  5267. ;; specially. Also skip time-stamps before first headline as
  5268. ;; there would be no entry to add to the agenda. Eventually,
  5269. ;; ignore clock entries.
  5270. (catch :skip
  5271. (save-match-data
  5272. (when (or (org-at-date-range-p)
  5273. (org-at-planning-p)
  5274. (org-before-first-heading-p)
  5275. (and org-agenda-include-inactive-timestamps
  5276. (org-at-clock-log-p)))
  5277. (throw :skip nil))
  5278. (org-agenda-skip))
  5279. (let* ((pos (match-beginning 0))
  5280. (repeat (match-string 1))
  5281. (sexp-entry (match-string 3))
  5282. (time-stamp (if (or repeat sexp-entry) (match-string 0)
  5283. (save-excursion
  5284. (goto-char pos)
  5285. (looking-at org-ts-regexp-both)
  5286. (match-string 0))))
  5287. (todo-state (org-get-todo-state))
  5288. (warntime (get-text-property (point) 'org-appt-warntime))
  5289. (done? (member todo-state org-done-keywords)))
  5290. ;; Possibly skip done tasks.
  5291. (when (and done? org-agenda-skip-timestamp-if-done)
  5292. (throw :skip t))
  5293. ;; S-exp entry doesn't match current day: skip it.
  5294. (when (and sexp-entry (not (org-diary-sexp-entry sexp-entry "" date)))
  5295. (throw :skip nil))
  5296. (when repeat
  5297. (let* ((past
  5298. ;; A repeating time stamp is shown at its base
  5299. ;; date and every repeated date up to TODAY. If
  5300. ;; `org-agenda-prefer-last-repeat' is non-nil,
  5301. ;; however, only the last repeat before today
  5302. ;; (inclusive) is shown.
  5303. (org-agenda--timestamp-to-absolute
  5304. repeat
  5305. (if (or (> current today)
  5306. (eq org-agenda-prefer-last-repeat t)
  5307. (member todo-state org-agenda-prefer-last-repeat))
  5308. today
  5309. current)
  5310. 'past (current-buffer) pos))
  5311. (future
  5312. ;; Display every repeated date past TODAY
  5313. ;; (exclusive) unless
  5314. ;; `org-agenda-show-future-repeats' is nil. If
  5315. ;; this variable is set to `next', only display
  5316. ;; the first repeated date after TODAY
  5317. ;; (exclusive).
  5318. (cond
  5319. ((<= current today) past)
  5320. ((not org-agenda-show-future-repeats) past)
  5321. (t
  5322. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5323. (1+ today)
  5324. current)))
  5325. (org-agenda--timestamp-to-absolute
  5326. repeat base 'future (current-buffer) pos))))))
  5327. (when (and (/= current past) (/= current future))
  5328. (throw :skip nil))))
  5329. (save-excursion
  5330. (re-search-backward org-outline-regexp-bol nil t)
  5331. ;; Possibly skip time-stamp when a deadline is set.
  5332. (when (and org-agenda-skip-timestamp-if-deadline-is-shown
  5333. (assq (point) deadline-position-alist))
  5334. (throw :skip nil))
  5335. (let* ((category (org-get-category pos))
  5336. (inherited-tags
  5337. (or (eq org-agenda-show-inherited-tags 'always)
  5338. (and (consp org-agenda-show-inherited-tags)
  5339. (memq 'agenda org-agenda-show-inherited-tags))
  5340. (and (eq org-agenda-show-inherited-tags t)
  5341. (or (eq org-agenda-use-tag-inheritance t)
  5342. (memq 'agenda
  5343. org-agenda-use-tag-inheritance)))))
  5344. (tags (org-get-tags nil (not inherited-tags)))
  5345. (level (make-string (org-reduced-level (org-outline-level))
  5346. ?\s))
  5347. (head (and (looking-at "\\*+[ \t]+\\(.*\\)")
  5348. (match-string 1)))
  5349. (inactive? (= (char-after pos) ?\[))
  5350. (habit? (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5351. (item
  5352. (org-agenda-format-item
  5353. (and inactive? org-agenda-inactive-leader)
  5354. head level category tags time-stamp org-ts-regexp habit?)))
  5355. (org-add-props item props
  5356. 'priority (if habit?
  5357. (org-habit-get-priority (org-habit-parse-todo))
  5358. (org-get-priority item))
  5359. 'org-marker (org-agenda-new-marker pos)
  5360. 'org-hd-marker (org-agenda-new-marker)
  5361. 'date date
  5362. 'level level
  5363. 'ts-date (if repeat (org-agenda--timestamp-to-absolute repeat)
  5364. current)
  5365. 'todo-state todo-state
  5366. 'warntime warntime
  5367. 'type "timestamp")
  5368. (push item timestamp-items))))
  5369. (when org-agenda-skip-additional-timestamps-same-entry
  5370. (outline-next-heading))))
  5371. (nreverse timestamp-items)))
  5372. (defun org-agenda-get-sexps ()
  5373. "Return the sexp information for agenda display."
  5374. (require 'diary-lib)
  5375. (with-no-warnings (defvar date) (defvar entry))
  5376. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5377. 'mouse-face 'highlight
  5378. 'help-echo
  5379. (format "mouse-2 or RET jump to org file %s"
  5380. (abbreviate-file-name buffer-file-name))))
  5381. (regexp "^&?%%(")
  5382. ;; FIXME: Is this `entry' binding intended to be dynamic,
  5383. ;; so as to "hide" any current binding for it?
  5384. marker category extra level ee txt tags entry
  5385. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5386. (goto-char (point-min))
  5387. (while (re-search-forward regexp nil t)
  5388. (catch :skip
  5389. (org-agenda-skip)
  5390. (setq beg (match-beginning 0))
  5391. (goto-char (1- (match-end 0)))
  5392. (setq b (point))
  5393. (forward-sexp 1)
  5394. (setq sexp (buffer-substring b (point)))
  5395. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5396. (org-trim (match-string 1))
  5397. ""))
  5398. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5399. (when result
  5400. (setq marker (org-agenda-new-marker beg)
  5401. level (make-string (org-reduced-level (org-outline-level)) ? )
  5402. category (org-get-category beg)
  5403. inherited-tags
  5404. (or (eq org-agenda-show-inherited-tags 'always)
  5405. (and (listp org-agenda-show-inherited-tags)
  5406. (memq 'agenda org-agenda-show-inherited-tags))
  5407. (and (eq org-agenda-show-inherited-tags t)
  5408. (or (eq org-agenda-use-tag-inheritance t)
  5409. (memq 'agenda org-agenda-use-tag-inheritance))))
  5410. tags (org-get-tags nil (not inherited-tags))
  5411. todo-state (org-get-todo-state)
  5412. warntime (get-text-property (point) 'org-appt-warntime)
  5413. extra nil)
  5414. (dolist (r (if (stringp result)
  5415. (list result)
  5416. result)) ;; we expect a list here
  5417. (when (and org-agenda-diary-sexp-prefix
  5418. (string-match org-agenda-diary-sexp-prefix r))
  5419. (setq extra (match-string 0 r)
  5420. r (replace-match "" nil nil r)))
  5421. (if (string-match "\\S-" r)
  5422. (setq txt r)
  5423. (setq txt "SEXP entry returned empty string"))
  5424. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5425. (org-add-props txt props 'org-marker marker
  5426. 'date date 'todo-state todo-state
  5427. 'level level 'type "sexp" 'warntime warntime)
  5428. (push txt ee)))))
  5429. (nreverse ee)))
  5430. ;; Calendar sanity: define some functions that are independent of
  5431. ;; `calendar-date-style'.
  5432. (defun org-anniversary (year month day &optional mark)
  5433. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5434. (with-no-warnings
  5435. (let ((calendar-date-style 'iso))
  5436. (diary-anniversary year month day mark))))
  5437. (defun org-cyclic (N year month day &optional mark)
  5438. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5439. (with-no-warnings
  5440. (let ((calendar-date-style 'iso))
  5441. (diary-cyclic N year month day mark))))
  5442. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5443. "Like `diary-block', but with fixed (ISO) order of arguments."
  5444. (with-no-warnings
  5445. (let ((calendar-date-style 'iso))
  5446. (diary-block Y1 M1 D1 Y2 M2 D2 mark))))
  5447. (defun org-date (year month day &optional mark)
  5448. "Like `diary-date', but with fixed (ISO) order of arguments."
  5449. (with-no-warnings
  5450. (let ((calendar-date-style 'iso))
  5451. (diary-date year month day mark))))
  5452. ;; Define the `org-class' function
  5453. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5454. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5455. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5456. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5457. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5458. `holidays', then any date that is known by the Emacs calendar to be a
  5459. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5460. then those holidays will be skipped."
  5461. (with-no-warnings (defvar date) (defvar entry))
  5462. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5463. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5464. (d (calendar-absolute-from-gregorian date))
  5465. (h (when skip-weeks (calendar-check-holidays date))))
  5466. (and
  5467. (<= date1 d)
  5468. (<= d date2)
  5469. (= (calendar-day-of-week date) dayname)
  5470. (or (not skip-weeks)
  5471. (progn
  5472. (require 'cal-iso)
  5473. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5474. (not (or (and h (memq 'holidays skip-weeks))
  5475. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5476. entry)))
  5477. (defalias 'org-get-closed #'org-agenda-get-progress)
  5478. (defun org-agenda-get-progress ()
  5479. "Return the logged TODO entries for agenda display."
  5480. (with-no-warnings (defvar date))
  5481. (let* ((props (list 'mouse-face 'highlight
  5482. 'org-not-done-regexp org-not-done-regexp
  5483. 'org-todo-regexp org-todo-regexp
  5484. 'org-complex-heading-regexp org-complex-heading-regexp
  5485. 'help-echo
  5486. (format "mouse-2 or RET jump to org file %s"
  5487. (abbreviate-file-name buffer-file-name))))
  5488. (items (if (consp org-agenda-show-log-scoped)
  5489. org-agenda-show-log-scoped
  5490. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5491. '(clock)
  5492. org-agenda-log-mode-items)))
  5493. (parts
  5494. (delq nil
  5495. (list
  5496. (when (memq 'closed items) (concat "\\<" org-closed-string))
  5497. (when (memq 'clock items) (concat "\\<" org-clock-string))
  5498. (when (memq 'state items)
  5499. (format "- +State \"%s\".*?" org-todo-regexp)))))
  5500. (parts-re (if parts (mapconcat #'identity parts "\\|")
  5501. (error "`org-agenda-log-mode-items' is empty")))
  5502. (regexp (concat
  5503. "\\(" parts-re "\\)"
  5504. " *\\["
  5505. (regexp-quote
  5506. (substring
  5507. (format-time-string
  5508. (car org-time-stamp-formats)
  5509. (encode-time ; DATE bound by calendar
  5510. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5511. 1 11))))
  5512. (org-agenda-search-headline-for-time nil)
  5513. marker hdmarker priority category level tags closedp type
  5514. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5515. (goto-char (point-min))
  5516. (while (re-search-forward regexp nil t)
  5517. (catch :skip
  5518. (org-agenda-skip)
  5519. (setq marker (org-agenda-new-marker (match-beginning 0))
  5520. closedp (equal (match-string 1) org-closed-string)
  5521. statep (equal (string-to-char (match-string 1)) ?-)
  5522. clockp (not (or closedp statep))
  5523. state (and statep (match-string 2))
  5524. category (org-get-category (match-beginning 0))
  5525. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5526. (when (string-match "\\]" timestr)
  5527. ;; substring should only run to end of time stamp
  5528. (setq rest (substring timestr (match-end 0))
  5529. timestr (substring timestr 0 (match-end 0)))
  5530. (if (and (not closedp) (not statep)
  5531. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5532. rest))
  5533. (progn (setq timestr (concat (substring timestr 0 -1)
  5534. "-" (match-string 1 rest) "]"))
  5535. (setq clocked (match-string 2 rest)))
  5536. (setq clocked "-")))
  5537. (save-excursion
  5538. (setq extra
  5539. (cond
  5540. ((not org-agenda-log-mode-add-notes) nil)
  5541. (statep
  5542. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5543. (match-string 1)))
  5544. (clockp
  5545. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5546. (match-string 1)))))
  5547. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5548. (throw :skip nil)
  5549. (goto-char (match-beginning 0))
  5550. (setq hdmarker (org-agenda-new-marker)
  5551. inherited-tags
  5552. (or (eq org-agenda-show-inherited-tags 'always)
  5553. (and (listp org-agenda-show-inherited-tags)
  5554. (memq 'todo org-agenda-show-inherited-tags))
  5555. (and (eq org-agenda-show-inherited-tags t)
  5556. (or (eq org-agenda-use-tag-inheritance t)
  5557. (memq 'todo org-agenda-use-tag-inheritance))))
  5558. tags (org-get-tags nil (not inherited-tags))
  5559. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5560. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5561. (setq txt (match-string 1))
  5562. (when extra
  5563. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5564. (setq txt (concat (substring txt 0 (match-beginning 1))
  5565. " - " extra " " (match-string 2 txt)))
  5566. (setq txt (concat txt " - " extra))))
  5567. (setq txt (org-agenda-format-item
  5568. (cond
  5569. (closedp "Closed: ")
  5570. (statep (concat "State: (" state ")"))
  5571. (t (concat "Clocked: (" clocked ")")))
  5572. txt level category tags timestr)))
  5573. (setq type (cond (closedp "closed")
  5574. (statep "state")
  5575. (t "clock")))
  5576. (setq priority 100000)
  5577. (org-add-props txt props
  5578. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5579. 'priority priority 'level level
  5580. 'type type 'date date
  5581. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5582. (push txt ee))
  5583. (goto-char (point-at-eol))))
  5584. (nreverse ee)))
  5585. (defun org-agenda-show-clocking-issues ()
  5586. "Add overlays, showing issues with clocking.
  5587. See also the user option `org-agenda-clock-consistency-checks'."
  5588. (interactive)
  5589. (let* ((pl org-agenda-clock-consistency-checks)
  5590. (re (concat "^[ \t]*"
  5591. org-clock-string
  5592. "[ \t]+"
  5593. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5594. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5595. (tlstart 0.)
  5596. (tlend 0.)
  5597. (maxtime (org-duration-to-minutes
  5598. (or (plist-get pl :max-duration) "24:00")))
  5599. (mintime (org-duration-to-minutes
  5600. (or (plist-get pl :min-duration) 0)))
  5601. (maxgap (org-duration-to-minutes
  5602. ;; default 30:00 means never complain
  5603. (or (plist-get pl :max-gap) "30:00")))
  5604. (gapok (mapcar #'org-duration-to-minutes
  5605. (plist-get pl :gap-ok-around)))
  5606. (def-face (or (plist-get pl :default-face)
  5607. '((:background "DarkRed") (:foreground "white"))))
  5608. issue face m te ts dt ov)
  5609. (goto-char (point-min))
  5610. (while (re-search-forward " Clocked: +(\\(?:-\\|\\([0-9]+:[0-9]+\\)\\))" nil t)
  5611. (setq issue nil face def-face)
  5612. (catch 'next
  5613. (setq m (org-get-at-bol 'org-marker)
  5614. te nil ts nil)
  5615. (unless (and m (markerp m))
  5616. (setq issue "No valid clock line") (throw 'next t))
  5617. (org-with-point-at m
  5618. (save-excursion
  5619. (goto-char (point-at-bol))
  5620. (unless (looking-at re)
  5621. (error "No valid Clock line")
  5622. (throw 'next t))
  5623. (unless (match-end 3)
  5624. (setq issue
  5625. (format
  5626. "No end time: (%s)"
  5627. (org-duration-from-minutes
  5628. (floor
  5629. (- (float-time (org-current-time))
  5630. (float-time (org-time-string-to-time (match-string 1))))
  5631. 60)))
  5632. face (or (plist-get pl :no-end-time-face) face))
  5633. (throw 'next t))
  5634. (setq ts (match-string 1)
  5635. te (match-string 3)
  5636. ts (float-time (org-time-string-to-time ts))
  5637. te (float-time (org-time-string-to-time te))
  5638. dt (- te ts))))
  5639. (cond
  5640. ((> dt (* 60 maxtime))
  5641. ;; a very long clocking chunk
  5642. (setq issue (format "Clocking interval is very long: %s"
  5643. (org-duration-from-minutes (floor dt 60)))
  5644. face (or (plist-get pl :long-face) face)))
  5645. ((< dt (* 60 mintime))
  5646. ;; a very short clocking chunk
  5647. (setq issue (format "Clocking interval is very short: %s"
  5648. (org-duration-from-minutes (floor dt 60)))
  5649. face (or (plist-get pl :short-face) face)))
  5650. ((and (> tlend 0) (< ts tlend))
  5651. ;; Two clock entries are overlapping
  5652. (setq issue (format "Clocking overlap: %d minutes"
  5653. (/ (- tlend ts) 60))
  5654. face (or (plist-get pl :overlap-face) face)))
  5655. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5656. ;; There is a gap, lets see if we need to report it
  5657. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5658. (setq issue (format "Clocking gap: %d minutes"
  5659. (/ (- ts tlend) 60))
  5660. face (or (plist-get pl :gap-face) face))))
  5661. (t nil)))
  5662. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5663. (when issue
  5664. ;; OK, there was some issue, add an overlay to show the issue
  5665. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5666. (overlay-put ov 'before-string
  5667. (concat
  5668. (org-add-props
  5669. (format "%-43s" (concat " " issue))
  5670. nil
  5671. 'face face)
  5672. "\n"))
  5673. (overlay-put ov 'evaporate t)))))
  5674. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5675. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5676. (catch 'exit
  5677. (unless ok-list
  5678. ;; there are no OK times for gaps...
  5679. (throw 'exit nil))
  5680. (when (> (- (/ t2 36000) (/ t1 36000)) 24)
  5681. ;; This is more than 24 hours, so it is OK.
  5682. ;; because we have at least one OK time, that must be in the
  5683. ;; 24 hour interval.
  5684. (throw 'exit t))
  5685. ;; We have a shorter gap.
  5686. ;; Now we have to get the minute of the day when these times are
  5687. (let* ((t1dec (decode-time t1))
  5688. (t2dec (decode-time t2))
  5689. ;; compute the minute on the day
  5690. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5691. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5692. (when (< min2 min1)
  5693. ;; if min2 is smaller than min1, this means it is on the next day.
  5694. ;; Wrap it to after midnight.
  5695. (setq min2 (+ min2 1440)))
  5696. ;; Now check if any of the OK times is in the gap
  5697. (mapc (lambda (x)
  5698. ;; Wrap the time to after midnight if necessary
  5699. (when (< x min1) (setq x (+ x 1440)))
  5700. ;; Check if in interval
  5701. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5702. ok-list)
  5703. ;; Nope, this gap is not OK
  5704. nil)))
  5705. (defun org-agenda-get-deadlines (&optional with-hour)
  5706. "Return the deadline information for agenda display.
  5707. When WITH-HOUR is non-nil, only return deadlines with an hour
  5708. specification like [h]h:mm."
  5709. (with-no-warnings (defvar date))
  5710. (let* ((props (list 'mouse-face 'highlight
  5711. 'org-not-done-regexp org-not-done-regexp
  5712. 'org-todo-regexp org-todo-regexp
  5713. 'org-complex-heading-regexp org-complex-heading-regexp
  5714. 'help-echo
  5715. (format "mouse-2 or RET jump to org file %s"
  5716. (abbreviate-file-name buffer-file-name))))
  5717. (regexp (if with-hour
  5718. org-deadline-time-hour-regexp
  5719. org-deadline-time-regexp))
  5720. (today (org-today))
  5721. (today? (org-agenda-today-p date)) ; DATE bound by calendar.
  5722. (current (calendar-absolute-from-gregorian date))
  5723. deadline-items)
  5724. (goto-char (point-min))
  5725. (while (re-search-forward regexp nil t)
  5726. (catch :skip
  5727. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5728. (org-agenda-skip)
  5729. (let* ((s (match-string 1))
  5730. (pos (1- (match-beginning 1)))
  5731. (todo-state (save-match-data (org-get-todo-state)))
  5732. (done? (member todo-state org-done-keywords))
  5733. (sexp? (string-prefix-p "%%" s))
  5734. ;; DEADLINE is the deadline date for the entry. It is
  5735. ;; either the base date or the last repeat, according
  5736. ;; to `org-agenda-prefer-last-repeat'.
  5737. (deadline
  5738. (cond
  5739. (sexp? (org-agenda--timestamp-to-absolute s current))
  5740. ((or (eq org-agenda-prefer-last-repeat t)
  5741. (member todo-state org-agenda-prefer-last-repeat))
  5742. (org-agenda--timestamp-to-absolute
  5743. s today 'past (current-buffer) pos))
  5744. (t (org-agenda--timestamp-to-absolute s))))
  5745. ;; REPEAT is the future repeat closest from CURRENT,
  5746. ;; according to `org-agenda-show-future-repeats'. If
  5747. ;; the latter is nil, or if the time stamp has no
  5748. ;; repeat part, default to DEADLINE.
  5749. (repeat
  5750. (cond
  5751. (sexp? deadline)
  5752. ((<= current today) deadline)
  5753. ((not org-agenda-show-future-repeats) deadline)
  5754. (t
  5755. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5756. (1+ today)
  5757. current)))
  5758. (org-agenda--timestamp-to-absolute
  5759. s base 'future (current-buffer) pos)))))
  5760. (diff (- deadline current))
  5761. (suppress-prewarning
  5762. (let ((scheduled
  5763. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5764. (org-entry-get nil "SCHEDULED"))))
  5765. (cond
  5766. ((not scheduled) nil)
  5767. ;; The current item has a scheduled date, so
  5768. ;; evaluate its prewarning lead time.
  5769. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5770. ;; Use global prewarning-restart lead time.
  5771. org-agenda-skip-deadline-prewarning-if-scheduled)
  5772. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5773. 'pre-scheduled)
  5774. ;; Set pre-warning to no earlier than SCHEDULED.
  5775. (min (- deadline
  5776. (org-agenda--timestamp-to-absolute scheduled))
  5777. org-deadline-warning-days))
  5778. ;; Set pre-warning to deadline.
  5779. (t 0))))
  5780. (wdays (or suppress-prewarning (org-get-wdays s))))
  5781. (cond
  5782. ;; Only display deadlines at their base date, at future
  5783. ;; repeat occurrences or in today agenda.
  5784. ((= current deadline) nil)
  5785. ((= current repeat) nil)
  5786. ((not today?) (throw :skip nil))
  5787. ;; Upcoming deadline: display within warning period WDAYS.
  5788. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  5789. ;; Overdue deadline: warn about it for
  5790. ;; `org-deadline-past-days' duration.
  5791. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  5792. ;; Possibly skip done tasks.
  5793. (when (and done?
  5794. (or org-agenda-skip-deadline-if-done
  5795. (/= deadline current)))
  5796. (throw :skip nil))
  5797. (save-excursion
  5798. (re-search-backward "^\\*+[ \t]+" nil t)
  5799. (goto-char (match-end 0))
  5800. (let* ((category (org-get-category))
  5801. (level (make-string (org-reduced-level (org-outline-level))
  5802. ?\s))
  5803. (head (buffer-substring (point) (line-end-position)))
  5804. (inherited-tags
  5805. (or (eq org-agenda-show-inherited-tags 'always)
  5806. (and (listp org-agenda-show-inherited-tags)
  5807. (memq 'agenda org-agenda-show-inherited-tags))
  5808. (and (eq org-agenda-show-inherited-tags t)
  5809. (or (eq org-agenda-use-tag-inheritance t)
  5810. (memq 'agenda
  5811. org-agenda-use-tag-inheritance)))))
  5812. (tags (org-get-tags nil (not inherited-tags)))
  5813. (time
  5814. (cond
  5815. ;; No time of day designation if it is only
  5816. ;; a reminder.
  5817. ((and (/= current deadline) (/= current repeat)) nil)
  5818. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5819. (concat (substring s (match-beginning 1)) " "))
  5820. (t 'time)))
  5821. (item
  5822. (org-agenda-format-item
  5823. ;; Insert appropriate suffixes before deadlines.
  5824. ;; Those only apply to today agenda.
  5825. (pcase-let ((`(,now ,future ,past)
  5826. org-agenda-deadline-leaders))
  5827. (cond
  5828. ((and today? (< deadline today)) (format past (- diff)))
  5829. ((and today? (> deadline today)) (format future diff))
  5830. (t now)))
  5831. head level category tags time))
  5832. (face (org-agenda-deadline-face
  5833. (- 1 (/ (float diff) (max wdays 1)))))
  5834. (upcoming? (and today? (> deadline today)))
  5835. (warntime (get-text-property (point) 'org-appt-warntime)))
  5836. (org-add-props item props
  5837. 'org-marker (org-agenda-new-marker pos)
  5838. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5839. 'warntime warntime
  5840. 'level level
  5841. 'ts-date deadline
  5842. 'priority
  5843. ;; Adjust priority to today reminders about deadlines.
  5844. ;; Overdue deadlines get the highest priority
  5845. ;; increase, then imminent deadlines and eventually
  5846. ;; more distant deadlines.
  5847. (let ((adjust (if today? (- diff) 0)))
  5848. (+ adjust (org-get-priority item)))
  5849. 'todo-state todo-state
  5850. 'type (if upcoming? "upcoming-deadline" "deadline")
  5851. 'date (if upcoming? date deadline)
  5852. 'face (if done? 'org-agenda-done face)
  5853. 'undone-face face
  5854. 'done-face 'org-agenda-done)
  5855. (push item deadline-items))))))
  5856. (nreverse deadline-items)))
  5857. (defun org-agenda-deadline-face (fraction)
  5858. "Return the face to displaying a deadline item.
  5859. FRACTION is what fraction of the head-warning time has passed."
  5860. (assoc-default fraction org-agenda-deadline-faces #'<=))
  5861. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  5862. "Return the scheduled information for agenda display.
  5863. Optional argument DEADLINES is a list of deadline items to be
  5864. displayed in agenda view. When WITH-HOUR is non-nil, only return
  5865. scheduled items with an hour specification like [h]h:mm."
  5866. (with-no-warnings (defvar date))
  5867. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5868. 'org-todo-regexp org-todo-regexp
  5869. 'org-complex-heading-regexp org-complex-heading-regexp
  5870. 'done-face 'org-agenda-done
  5871. 'mouse-face 'highlight
  5872. 'help-echo
  5873. (format "mouse-2 or RET jump to Org file %s"
  5874. (abbreviate-file-name buffer-file-name))))
  5875. (regexp (if with-hour
  5876. org-scheduled-time-hour-regexp
  5877. org-scheduled-time-regexp))
  5878. (today (org-today))
  5879. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  5880. (current (calendar-absolute-from-gregorian date))
  5881. (deadline-pos
  5882. (mapcar (lambda (d)
  5883. (let ((m (get-text-property 0 'org-hd-marker d)))
  5884. (and m (marker-position m))))
  5885. deadlines))
  5886. scheduled-items)
  5887. (goto-char (point-min))
  5888. (while (re-search-forward regexp nil t)
  5889. (catch :skip
  5890. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5891. (org-agenda-skip)
  5892. (let* ((s (match-string 1))
  5893. (pos (1- (match-beginning 1)))
  5894. (todo-state (save-match-data (org-get-todo-state)))
  5895. (donep (member todo-state org-done-keywords))
  5896. (sexp? (string-prefix-p "%%" s))
  5897. ;; SCHEDULE is the scheduled date for the entry. It is
  5898. ;; either the bare date or the last repeat, according
  5899. ;; to `org-agenda-prefer-last-repeat'.
  5900. (schedule
  5901. (cond
  5902. (sexp? (org-agenda--timestamp-to-absolute s current))
  5903. ((or (eq org-agenda-prefer-last-repeat t)
  5904. (member todo-state org-agenda-prefer-last-repeat))
  5905. (org-agenda--timestamp-to-absolute
  5906. s today 'past (current-buffer) pos))
  5907. (t (org-agenda--timestamp-to-absolute s))))
  5908. ;; REPEAT is the future repeat closest from CURRENT,
  5909. ;; according to `org-agenda-show-future-repeats'. If
  5910. ;; the latter is nil, or if the time stamp has no
  5911. ;; repeat part, default to SCHEDULE.
  5912. (repeat
  5913. (cond
  5914. (sexp? schedule)
  5915. ((<= current today) schedule)
  5916. ((not org-agenda-show-future-repeats) schedule)
  5917. (t
  5918. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5919. (1+ today)
  5920. current)))
  5921. (org-agenda--timestamp-to-absolute
  5922. s base 'future (current-buffer) pos)))))
  5923. (diff (- current schedule))
  5924. (warntime (get-text-property (point) 'org-appt-warntime))
  5925. (pastschedp (< schedule today))
  5926. (futureschedp (> schedule today))
  5927. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5928. (suppress-delay
  5929. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  5930. (org-entry-get nil "DEADLINE"))))
  5931. (cond
  5932. ((not deadline) nil)
  5933. ;; The current item has a deadline date, so
  5934. ;; evaluate its delay time.
  5935. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5936. ;; Use global delay time.
  5937. (- org-agenda-skip-scheduled-delay-if-deadline))
  5938. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5939. 'post-deadline)
  5940. ;; Set delay to no later than DEADLINE.
  5941. (min (- schedule
  5942. (org-agenda--timestamp-to-absolute deadline))
  5943. org-scheduled-delay-days))
  5944. (t 0))))
  5945. (ddays
  5946. (cond
  5947. ;; Nullify delay when a repeater triggered already
  5948. ;; and the delay is of the form --Xd.
  5949. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  5950. (> schedule (org-agenda--timestamp-to-absolute s)))
  5951. 0)
  5952. (suppress-delay
  5953. (let ((org-scheduled-delay-days suppress-delay))
  5954. (org-get-wdays s t t)))
  5955. (t (org-get-wdays s t)))))
  5956. ;; Display scheduled items at base date (SCHEDULE), today if
  5957. ;; scheduled before the current date, and at any repeat past
  5958. ;; today. However, skip delayed items and items that have
  5959. ;; been displayed for more than `org-scheduled-past-days'.
  5960. (unless (and todayp
  5961. habitp
  5962. (bound-and-true-p org-habit-show-all-today))
  5963. (when (or (and (> ddays 0) (< diff ddays))
  5964. (> diff (or (and habitp org-habit-scheduled-past-days)
  5965. org-scheduled-past-days))
  5966. (> schedule current)
  5967. (and (/= current schedule)
  5968. (/= current today)
  5969. (/= current repeat)))
  5970. (throw :skip nil)))
  5971. ;; Possibly skip done tasks.
  5972. (when (and donep
  5973. (or org-agenda-skip-scheduled-if-done
  5974. (/= schedule current)))
  5975. (throw :skip nil))
  5976. ;; Skip entry if it already appears as a deadline, per
  5977. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  5978. ;; doesn't apply to habits.
  5979. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  5980. ((guard
  5981. (or (not (memq (line-beginning-position 0) deadline-pos))
  5982. habitp))
  5983. nil)
  5984. (`repeated-after-deadline
  5985. (let ((deadline (time-to-days
  5986. (org-get-deadline-time (point)))))
  5987. (and (<= schedule deadline) (> current deadline))))
  5988. (`not-today pastschedp)
  5989. (`t t)
  5990. (_ nil))
  5991. (throw :skip nil))
  5992. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  5993. ;; only show them for today. Also skip done habits.
  5994. (when (and habitp
  5995. (or donep
  5996. (not (bound-and-true-p org-habit-show-habits))
  5997. (and (not todayp)
  5998. (bound-and-true-p
  5999. org-habit-show-habits-only-for-today))))
  6000. (throw :skip nil))
  6001. (save-excursion
  6002. (re-search-backward "^\\*+[ \t]+" nil t)
  6003. (goto-char (match-end 0))
  6004. (let* ((category (org-get-category))
  6005. (inherited-tags
  6006. (or (eq org-agenda-show-inherited-tags 'always)
  6007. (and (listp org-agenda-show-inherited-tags)
  6008. (memq 'agenda org-agenda-show-inherited-tags))
  6009. (and (eq org-agenda-show-inherited-tags t)
  6010. (or (eq org-agenda-use-tag-inheritance t)
  6011. (memq 'agenda
  6012. org-agenda-use-tag-inheritance)))))
  6013. (tags (org-get-tags nil (not inherited-tags)))
  6014. (level (make-string (org-reduced-level (org-outline-level))
  6015. ?\s))
  6016. (head (buffer-substring (point) (line-end-position)))
  6017. (time
  6018. (cond
  6019. ;; No time of day designation if it is only a
  6020. ;; reminder, except for habits, which always show
  6021. ;; the time of day. Habits are an exception
  6022. ;; because if there is a time of day, that is
  6023. ;; interpreted to mean they should usually happen
  6024. ;; then, even if doing the habit was missed.
  6025. ((and
  6026. (not habitp)
  6027. (/= current schedule)
  6028. (/= current repeat))
  6029. nil)
  6030. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6031. (concat (substring s (match-beginning 1)) " "))
  6032. (t 'time)))
  6033. (item
  6034. (org-agenda-format-item
  6035. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  6036. ;; Show a reminder of a past scheduled today.
  6037. (if (and todayp pastschedp)
  6038. (format past diff)
  6039. first))
  6040. head level category tags time nil habitp))
  6041. (face (cond ((and (not habitp) pastschedp)
  6042. 'org-scheduled-previously)
  6043. ((and habitp futureschedp)
  6044. 'org-agenda-done)
  6045. (todayp 'org-scheduled-today)
  6046. (t 'org-scheduled)))
  6047. (habitp (and habitp (org-habit-parse-todo))))
  6048. (org-add-props item props
  6049. 'undone-face face
  6050. 'face (if donep 'org-agenda-done face)
  6051. 'org-marker (org-agenda-new-marker pos)
  6052. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6053. 'type (if pastschedp "past-scheduled" "scheduled")
  6054. 'date (if pastschedp schedule date)
  6055. 'ts-date schedule
  6056. 'warntime warntime
  6057. 'level level
  6058. 'priority (if habitp (org-habit-get-priority habitp)
  6059. (+ 99 diff (org-get-priority item)))
  6060. 'org-habit-p habitp
  6061. 'todo-state todo-state)
  6062. (push item scheduled-items))))))
  6063. (nreverse scheduled-items)))
  6064. (defun org-agenda-get-blocks ()
  6065. "Return the date-range information for agenda display."
  6066. (with-no-warnings (defvar date))
  6067. (let* ((props (list 'face nil
  6068. 'org-not-done-regexp org-not-done-regexp
  6069. 'org-todo-regexp org-todo-regexp
  6070. 'org-complex-heading-regexp org-complex-heading-regexp
  6071. 'mouse-face 'highlight
  6072. 'help-echo
  6073. (format "mouse-2 or RET jump to org file %s"
  6074. (abbreviate-file-name buffer-file-name))))
  6075. (regexp org-tr-regexp)
  6076. (d0 (calendar-absolute-from-gregorian date))
  6077. marker hdmarker ee txt d1 d2 s1 s2 category
  6078. level todo-state tags pos head donep inherited-tags)
  6079. (goto-char (point-min))
  6080. (while (re-search-forward regexp nil t)
  6081. (catch :skip
  6082. (org-agenda-skip)
  6083. (setq pos (point))
  6084. (let ((start-time (match-string 1))
  6085. (end-time (match-string 2)))
  6086. (setq s1 (match-string 1)
  6087. s2 (match-string 2)
  6088. d1 (time-to-days
  6089. (condition-case err
  6090. (org-time-string-to-time s1)
  6091. (error
  6092. (error
  6093. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6094. s1
  6095. pos
  6096. (current-buffer)
  6097. (error-message-string err)))))
  6098. d2 (time-to-days
  6099. (condition-case err
  6100. (org-time-string-to-time s2)
  6101. (error
  6102. (error
  6103. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6104. s2
  6105. pos
  6106. (current-buffer)
  6107. (error-message-string err))))))
  6108. (when (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  6109. ;; Only allow days between the limits, because the normal
  6110. ;; date stamps will catch the limits.
  6111. (save-excursion
  6112. (setq todo-state (org-get-todo-state))
  6113. (setq donep (member todo-state org-done-keywords))
  6114. (when (and donep org-agenda-skip-timestamp-if-done)
  6115. (throw :skip t))
  6116. (setq marker (org-agenda-new-marker (point))
  6117. category (org-get-category))
  6118. (if (not (re-search-backward org-outline-regexp-bol nil t))
  6119. (throw :skip nil)
  6120. (goto-char (match-beginning 0))
  6121. (setq hdmarker (org-agenda-new-marker (point))
  6122. inherited-tags
  6123. (or (eq org-agenda-show-inherited-tags 'always)
  6124. (and (listp org-agenda-show-inherited-tags)
  6125. (memq 'agenda org-agenda-show-inherited-tags))
  6126. (and (eq org-agenda-show-inherited-tags t)
  6127. (or (eq org-agenda-use-tag-inheritance t)
  6128. (memq 'agenda org-agenda-use-tag-inheritance))))
  6129. tags (org-get-tags nil (not inherited-tags)))
  6130. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  6131. (looking-at "\\*+[ \t]+\\(.*\\)")
  6132. (setq head (match-string 1))
  6133. (let ((remove-re
  6134. (if org-agenda-remove-timeranges-from-blocks
  6135. (concat
  6136. "<" (regexp-quote s1) ".*?>"
  6137. "--"
  6138. "<" (regexp-quote s2) ".*?>")
  6139. nil)))
  6140. (setq txt (org-agenda-format-item
  6141. (format
  6142. (nth (if (= d1 d2) 0 1)
  6143. org-agenda-timerange-leaders)
  6144. (1+ (- d0 d1)) (1+ (- d2 d1)))
  6145. head level category tags
  6146. (save-match-data
  6147. (let ((hhmm1 (and (string-match org-ts-regexp1 s1)
  6148. (match-string 6 s1)))
  6149. (hhmm2 (and (string-match org-ts-regexp1 s2)
  6150. (match-string 6 s2))))
  6151. (cond ((string= hhmm1 hhmm2)
  6152. (concat "<" start-time ">--<" end-time ">"))
  6153. ((and (= d1 d0) (= d2 d0))
  6154. (concat "<" start-time ">--<" end-time ">"))
  6155. ((= d1 d0)
  6156. (concat "<" start-time ">"))
  6157. ((= d2 d0)
  6158. (concat "<" end-time ">")))))
  6159. remove-re))))
  6160. (org-add-props txt props
  6161. 'org-marker marker 'org-hd-marker hdmarker
  6162. 'type "block" 'date date
  6163. 'level level
  6164. 'todo-state todo-state
  6165. 'priority (org-get-priority txt))
  6166. (push txt ee))))
  6167. (goto-char pos)))
  6168. ;; Sort the entries by expiration date.
  6169. (nreverse ee)))
  6170. ;;; Agenda presentation and sorting
  6171. (defvar org-prefix-has-time nil
  6172. "A flag, set by `org-compile-prefix-format'.
  6173. The flag is set if the currently compiled format contains a `%t'.")
  6174. (defvar org-prefix-has-tag nil
  6175. "A flag, set by `org-compile-prefix-format'.
  6176. The flag is set if the currently compiled format contains a `%T'.")
  6177. (defvar org-prefix-has-effort nil
  6178. "A flag, set by `org-compile-prefix-format'.
  6179. The flag is set if the currently compiled format contains a `%e'.")
  6180. (defvar org-prefix-has-breadcrumbs nil
  6181. "A flag, set by `org-compile-prefix-format'.
  6182. The flag is set if the currently compiled format contains a `%b'.")
  6183. (defvar org-prefix-category-length nil
  6184. "Used by `org-compile-prefix-format' to remember the category field width.")
  6185. (defvar org-prefix-category-max-length nil
  6186. "Used by `org-compile-prefix-format' to remember the category field width.")
  6187. (defun org-agenda-get-category-icon (category)
  6188. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  6189. (cl-dolist (entry org-agenda-category-icon-alist)
  6190. (when (string-match-p (car entry) category)
  6191. (if (listp (cadr entry))
  6192. (cl-return (cadr entry))
  6193. (cl-return (apply #'create-image (cdr entry)))))))
  6194. (defun org-agenda-format-item (extra txt &optional with-level with-category tags dotime
  6195. remove-re habitp)
  6196. "Format TXT to be inserted into the agenda buffer.
  6197. In particular, add the prefix and corresponding text properties.
  6198. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  6199. WITH-LEVEL may be a string to replace the `%l' specifier.
  6200. WITH-CATEGORY (a string, a symbol or nil) may be used to overrule the default
  6201. category taken from local variable or file name. It will replace the `%c'
  6202. specifier in the format.
  6203. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  6204. TXT for sorting of this entry, and for the `%t' specifier in the format.
  6205. When DOTIME is a string, this string is searched for a time before TXT is.
  6206. TAGS can be the tags of the headline.
  6207. Any match of REMOVE-RE will be removed from TXT."
  6208. ;; We keep the org-prefix-* variable values along with a compiled
  6209. ;; formatter, so that multiple agendas existing at the same time do
  6210. ;; not step on each other toes.
  6211. ;;
  6212. ;; It was inconvenient to make these variables buffer local in
  6213. ;; Agenda buffers, because this function expects to be called with
  6214. ;; the buffer where item comes from being current, and not agenda
  6215. ;; buffer
  6216. (let* ((bindings (car org-prefix-format-compiled))
  6217. (formatter (cadr org-prefix-format-compiled)))
  6218. (cl-loop for (var value) in bindings
  6219. do (set var value))
  6220. (save-match-data
  6221. ;; Diary entries sometimes have extra whitespace at the beginning
  6222. (setq txt (org-trim txt))
  6223. ;; Fix the tags part in txt
  6224. (setq txt (org-agenda-fix-displayed-tags
  6225. txt tags
  6226. org-agenda-show-inherited-tags
  6227. org-agenda-hide-tags-regexp))
  6228. (with-no-warnings
  6229. ;; `time', `tag', `effort' are needed for the eval of the prefix format.
  6230. ;; Based on what I see in `org-compile-prefix-format', I added
  6231. ;; a few more.
  6232. (defvar breadcrumbs) (defvar category) (defvar category-icon)
  6233. (defvar effort) (defvar extra)
  6234. (defvar level) (defvar tag) (defvar time))
  6235. (let* ((category (or with-category
  6236. (if buffer-file-name
  6237. (file-name-sans-extension
  6238. (file-name-nondirectory buffer-file-name))
  6239. "")))
  6240. (category-icon (org-agenda-get-category-icon category))
  6241. (category-icon (if category-icon
  6242. (propertize " " 'display category-icon)
  6243. ""))
  6244. (effort (and (not (string= txt ""))
  6245. (get-text-property 1 'effort txt)))
  6246. (tag (if tags (nth (1- (length tags)) tags) ""))
  6247. (time-grid-trailing-characters (nth 2 org-agenda-time-grid))
  6248. (extra (or (and (not habitp) extra) ""))
  6249. time
  6250. (ts (when dotime (concat
  6251. (if (stringp dotime) dotime "")
  6252. (and org-agenda-search-headline-for-time txt))))
  6253. (time-of-day (and dotime (org-get-time-of-day ts)))
  6254. stamp plain s0 s1 s2 rtn srp l
  6255. duration breadcrumbs)
  6256. (and (derived-mode-p 'org-mode) buffer-file-name
  6257. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6258. (when (and dotime time-of-day)
  6259. ;; Extract starting and ending time and move them to prefix
  6260. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6261. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6262. (setq s0 (match-string 0 ts)
  6263. srp (and stamp (match-end 3))
  6264. s1 (match-string (if plain 1 2) ts)
  6265. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6266. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6267. ;; them, we might want to remove them there to avoid duplication.
  6268. ;; The user can turn this off with a variable.
  6269. (when (and org-prefix-has-time
  6270. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6271. (string-match (concat (regexp-quote s0) " *") txt)
  6272. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6273. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6274. (= (match-beginning 0) 0)
  6275. t))
  6276. (setq txt (replace-match "" nil nil txt))))
  6277. ;; Normalize the time(s) to 24 hour.
  6278. (when s1 (setq s1 (org-get-time-of-day s1 t)))
  6279. (when s2 (setq s2 (org-get-time-of-day s2 t)))
  6280. ;; Try to set s2 if s1 and
  6281. ;; `org-agenda-default-appointment-duration' are set
  6282. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6283. (setq s2
  6284. (org-duration-from-minutes
  6285. (+ (org-duration-to-minutes s1 t)
  6286. org-agenda-default-appointment-duration)
  6287. nil t)))
  6288. ;; Compute the duration
  6289. (when s2
  6290. (setq duration (- (org-duration-to-minutes s2)
  6291. (org-duration-to-minutes s1))))
  6292. ;; Format S1 and S2 for display.
  6293. (when s1 (setq s1 (org-get-time-of-day s1 'overtime)))
  6294. (when s2 (setq s2 (org-get-time-of-day s2 'overtime))))
  6295. (when (string-match org-tag-group-re txt)
  6296. ;; Tags are in the string
  6297. (if (or (eq org-agenda-remove-tags t)
  6298. (and org-agenda-remove-tags
  6299. org-prefix-has-tag))
  6300. (setq txt (replace-match "" t t txt))
  6301. (setq txt (replace-match
  6302. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6303. (match-string 1 txt))
  6304. t t txt))))
  6305. (when remove-re
  6306. (while (string-match remove-re txt)
  6307. (setq txt (replace-match "" t t txt))))
  6308. ;; Set org-heading property on `txt' to mark the start of the
  6309. ;; heading.
  6310. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6311. ;; Prepare the variables needed in the eval of the compiled format
  6312. (when org-prefix-has-breadcrumbs
  6313. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6314. (let ((s (org-format-outline-path (org-get-outline-path)
  6315. (1- (frame-width))
  6316. nil org-agenda-breadcrumbs-separator)))
  6317. (if (eq "" s) "" (concat s org-agenda-breadcrumbs-separator))))))
  6318. (setq time (cond (s2 (concat
  6319. (org-agenda-time-of-day-to-ampm-maybe s1)
  6320. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6321. (when org-agenda-timegrid-use-ampm " ")))
  6322. (s1 (concat
  6323. (org-agenda-time-of-day-to-ampm-maybe s1)
  6324. (if org-agenda-timegrid-use-ampm
  6325. (concat time-grid-trailing-characters " ")
  6326. time-grid-trailing-characters)))
  6327. (t ""))
  6328. category (if (symbolp category) (symbol-name category) category)
  6329. level (or with-level ""))
  6330. (if (string-match org-link-bracket-re category)
  6331. (progn
  6332. (setq l (string-width (or (match-string 2) (match-string 1))))
  6333. (when (< l (or org-prefix-category-length 0))
  6334. (setq category (copy-sequence category))
  6335. (org-add-props category nil
  6336. 'extra-space (make-string
  6337. (- org-prefix-category-length l 1) ?\ ))))
  6338. (when (and org-prefix-category-max-length
  6339. (>= (length category) org-prefix-category-max-length))
  6340. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6341. ;; Evaluate the compiled format
  6342. (setq rtn (concat (eval formatter t) txt))
  6343. ;; And finally add the text properties
  6344. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6345. (org-add-props rtn nil
  6346. 'org-category category
  6347. 'tags tags
  6348. 'org-priority-highest org-priority-highest
  6349. 'org-priority-lowest org-priority-lowest
  6350. 'time-of-day time-of-day
  6351. 'duration duration
  6352. 'breadcrumbs breadcrumbs
  6353. 'txt txt
  6354. 'level level
  6355. 'time time
  6356. 'extra extra
  6357. 'format org-prefix-format-compiled
  6358. 'dotime dotime)))))
  6359. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6360. "Remove tags string from TXT, and add a modified list of tags.
  6361. The modified list may contain inherited tags, and tags matched by
  6362. `org-agenda-hide-tags-regexp' will be removed."
  6363. (when (or add-inherited hide-re)
  6364. (when (string-match org-tag-group-re txt)
  6365. (setq txt (substring txt 0 (match-beginning 0))))
  6366. (setq tags
  6367. (delq nil
  6368. (mapcar (lambda (tg)
  6369. (if (or (and hide-re (string-match hide-re tg))
  6370. (and (not add-inherited)
  6371. (get-text-property 0 'inherited tg)))
  6372. nil
  6373. tg))
  6374. tags)))
  6375. (when tags
  6376. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6377. i)
  6378. (setq txt (concat txt " :"
  6379. (mapconcat
  6380. (lambda (x)
  6381. (setq i (get-text-property 0 'inherited x))
  6382. (if (and have-i (not i))
  6383. (progn
  6384. (setq have-i nil)
  6385. (concat ":" x))
  6386. x))
  6387. tags ":")
  6388. (if have-i "::" ":"))))))
  6389. txt)
  6390. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6391. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6392. "Add a time-grid for agenda items which need it.
  6393. LIST is the list of agenda items formatted by `org-agenda-list'.
  6394. NDAYS is the span of the current agenda view.
  6395. TODAYP is t when the current agenda view is on today."
  6396. (catch 'exit
  6397. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6398. ((and todayp (member 'today (car org-agenda-time-grid))))
  6399. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6400. ((member 'weekly (car org-agenda-time-grid)))
  6401. (t (throw 'exit list)))
  6402. (let* ((have (delq nil (mapcar
  6403. (lambda (x) (get-text-property 1 'time-of-day x))
  6404. list)))
  6405. (string (nth 3 org-agenda-time-grid))
  6406. (gridtimes (nth 1 org-agenda-time-grid))
  6407. (req (car org-agenda-time-grid))
  6408. (remove (member 'remove-match req))
  6409. new time)
  6410. (when (and (member 'require-timed req) (not have))
  6411. ;; don't show empty grid
  6412. (throw 'exit list))
  6413. (while (setq time (pop gridtimes))
  6414. (unless (and remove (member time have))
  6415. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6416. (push (org-agenda-format-item
  6417. nil string nil "" nil
  6418. (concat (substring time 0 -2) ":" (substring time -2)))
  6419. new)
  6420. (put-text-property
  6421. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6422. (when (and todayp org-agenda-show-current-time-in-grid)
  6423. (push (org-agenda-format-item
  6424. nil org-agenda-current-time-string nil "" nil
  6425. (format-time-string "%H:%M "))
  6426. new)
  6427. (put-text-property
  6428. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6429. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6430. (append new list)
  6431. (append list new)))))
  6432. (defun org-compile-prefix-format (key)
  6433. "Compile the prefix format into a Lisp form that can be evaluated.
  6434. The resulting form and associated variable bindings is returned
  6435. and stored in the variable `org-prefix-format-compiled'."
  6436. (setq org-prefix-has-time nil
  6437. org-prefix-has-tag nil
  6438. org-prefix-category-length nil
  6439. org-prefix-has-effort nil
  6440. org-prefix-has-breadcrumbs nil)
  6441. (let ((s (cond
  6442. ((stringp org-agenda-prefix-format)
  6443. org-agenda-prefix-format)
  6444. ((assq key org-agenda-prefix-format)
  6445. (cdr (assq key org-agenda-prefix-format)))
  6446. (t " %-12:c%?-12t% s")))
  6447. (start 0)
  6448. varform vars var c f opt) ;; e
  6449. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+?)\\)"
  6450. s start)
  6451. (setq var (or (cdr (assoc (match-string 4 s)
  6452. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6453. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6454. 'eval)
  6455. c (or (match-string 3 s) "")
  6456. opt (match-beginning 1)
  6457. start (1+ (match-beginning 0)))
  6458. (cl-case var
  6459. (time (setq org-prefix-has-time t))
  6460. (tag (setq org-prefix-has-tag t))
  6461. (effort (setq org-prefix-has-effort t))
  6462. (breadcrumbs (setq org-prefix-has-breadcrumbs t)))
  6463. (setq f (concat "%" (match-string 2 s) "s"))
  6464. (when (eq var 'category)
  6465. (setq org-prefix-category-length
  6466. (floor (abs (string-to-number (match-string 2 s)))))
  6467. (setq org-prefix-category-max-length
  6468. (let ((x (match-string 2 s)))
  6469. (save-match-data
  6470. (and (string-match "\\.[0-9]+" x)
  6471. (string-to-number (substring (match-string 0 x) 1)))))))
  6472. (if (eq var 'eval)
  6473. (setq varform `(format ,f (org-eval ,(read (substring s (match-beginning 4))))))
  6474. (if opt
  6475. (setq varform
  6476. `(if (member ,var '("" nil))
  6477. ""
  6478. (format ,f (concat ,var ,c))))
  6479. (setq varform
  6480. `(format ,f (if (member ,var '("" nil)) ""
  6481. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6482. (if (eq var 'eval)
  6483. (setf (substring s (match-beginning 0)
  6484. (+ (match-beginning 4)
  6485. (length (format "%S" (read (substring s (match-beginning 4)))))))
  6486. "%s")
  6487. (setq s (replace-match "%s" t nil s)))
  6488. (push varform vars))
  6489. (setq vars (nreverse vars))
  6490. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6491. (setq org-prefix-format-compiled
  6492. (list
  6493. `((org-prefix-has-time ,org-prefix-has-time)
  6494. (org-prefix-has-tag ,org-prefix-has-tag)
  6495. (org-prefix-category-length ,org-prefix-category-length)
  6496. (org-prefix-has-effort ,org-prefix-has-effort)
  6497. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6498. `(format ,s ,@vars))))))
  6499. (defun org-set-sorting-strategy (key)
  6500. (setq org-agenda-sorting-strategy-selected
  6501. (if (symbolp (car org-agenda-sorting-strategy))
  6502. ;; the old format
  6503. org-agenda-sorting-strategy
  6504. (or (cdr (assq key org-agenda-sorting-strategy))
  6505. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6506. '(time-up category-keep priority-down)))))
  6507. (defun org-get-time-of-day (s &optional string)
  6508. "Check string S for a time of day.
  6509. If found, return it as a military time number between 0 and 2400.
  6510. If not found, return nil.
  6511. The optional STRING argument forces conversion into a 5 character wide string
  6512. HH:MM. When it is `overtime', any time above 24:00 is turned into \"+H:MM\"
  6513. where H:MM is the duration above midnight."
  6514. (let ((case-fold-search t)
  6515. (time-regexp
  6516. (rx word-start
  6517. (group (opt (any "012")) digit) ;group 1: hours
  6518. (or (and ":" (group (any "012345") digit) ;group 2: minutes
  6519. (opt (group (or "am" "pm")))) ;group 3: am/pm
  6520. ;; Special "HHam/pm" case.
  6521. (group-n 3 (or "am" "pm")))
  6522. word-end)))
  6523. (save-match-data
  6524. (when (and (string-match time-regexp s)
  6525. (not (eq 'org-link (get-text-property 1 'face s))))
  6526. (let ((hours
  6527. (let* ((ampm (and (match-end 3) (downcase (match-string 3 s))))
  6528. (am-p (equal ampm "am")))
  6529. (pcase (string-to-number (match-string 1 s))
  6530. ((and (guard (not ampm)) h) h)
  6531. (12 (if am-p 0 12))
  6532. (h (+ h (if am-p 0 12))))))
  6533. (minutes
  6534. (if (match-end 2)
  6535. (string-to-number (match-string 2 s))
  6536. 0)))
  6537. (pcase string
  6538. (`nil (+ minutes (* hours 100)))
  6539. ((and `overtime
  6540. (guard (or (> hours 24)
  6541. (and (= hours 24)
  6542. (> minutes 0)))))
  6543. (format "+%d:%02d" (- hours 24) minutes))
  6544. ((guard org-agenda-time-leading-zero)
  6545. (format "%02d:%02d" hours minutes))
  6546. (_
  6547. (format "%d:%02d" hours minutes))))))))
  6548. (defvar org-agenda-before-sorting-filter-function nil
  6549. "Function to be applied to agenda items prior to sorting.
  6550. Prior to sorting also means just before they are inserted into the agenda.
  6551. To aid sorting, you may revisit the original entries and add more text
  6552. properties which will later be used by the sorting functions.
  6553. The function should take a string argument, an agenda line.
  6554. It has access to the text properties in that line, which contain among
  6555. other things, the property `org-hd-marker' that points to the entry
  6556. where the line comes from. Note that not all lines going into the agenda
  6557. have this property, only most.
  6558. The function should return the modified string. It is probably best
  6559. to ONLY change text properties.
  6560. You can also use this function as a filter, by returning nil for lines
  6561. you don't want to have in the agenda at all. For this application, you
  6562. could bind the variable in the options section of a custom command.")
  6563. (defun org-agenda-finalize-entries (list &optional type)
  6564. "Sort, limit and concatenate the LIST of agenda items.
  6565. The optional argument TYPE tells the agenda type."
  6566. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6567. (cdr (assoc type org-agenda-max-effort)))
  6568. (t org-agenda-max-effort)))
  6569. (max-todo (cond ((listp org-agenda-max-todos)
  6570. (cdr (assoc type org-agenda-max-todos)))
  6571. (t org-agenda-max-todos)))
  6572. (max-tags (cond ((listp org-agenda-max-tags)
  6573. (cdr (assoc type org-agenda-max-tags)))
  6574. (t org-agenda-max-tags)))
  6575. (max-entries (cond ((listp org-agenda-max-entries)
  6576. (cdr (assoc type org-agenda-max-entries)))
  6577. (t org-agenda-max-entries))))
  6578. (when org-agenda-before-sorting-filter-function
  6579. (setq list
  6580. (delq nil
  6581. (mapcar
  6582. org-agenda-before-sorting-filter-function list))))
  6583. (setq list (mapcar #'org-agenda-highlight-todo list)
  6584. list (mapcar #'identity (sort list #'org-entries-lessp)))
  6585. (when max-effort
  6586. (setq list (org-agenda-limit-entries
  6587. list 'effort-minutes max-effort
  6588. (lambda (e) (or e (if org-agenda-sort-noeffort-is-high
  6589. 32767 -1))))))
  6590. (when max-todo
  6591. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6592. (when max-tags
  6593. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6594. (when max-entries
  6595. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6596. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  6597. (setq list (mapcar #'org-agenda--mark-blocked-entry list)))
  6598. (mapconcat #'identity list "\n")))
  6599. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6600. "Limit the number of agenda entries."
  6601. (let ((include (and limit (< limit 0))))
  6602. (if limit
  6603. (let ((fun (or fn (lambda (p) (when p 1))))
  6604. (lim 0))
  6605. (delq nil
  6606. (mapcar
  6607. (lambda (e)
  6608. (let ((pval (funcall
  6609. fun (get-text-property (1- (length e))
  6610. prop e))))
  6611. (when pval (setq lim (+ lim pval)))
  6612. (cond ((and pval (<= lim (abs limit))) e)
  6613. ((and include (not pval)) e))))
  6614. list)))
  6615. list)))
  6616. (defun org-agenda-limit-interactively (remove)
  6617. "In agenda, interactively limit entries to various maximums."
  6618. (interactive "P")
  6619. (if remove
  6620. (progn (setq org-agenda-max-entries nil
  6621. org-agenda-max-todos nil
  6622. org-agenda-max-tags nil
  6623. org-agenda-max-effort nil)
  6624. (org-agenda-redo))
  6625. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6626. (msg (cond ((= max ?E) "How many minutes? ")
  6627. ((= max ?e) "How many entries? ")
  6628. ((= max ?t) "How many TODO entries? ")
  6629. ((= max ?T) "How many tagged entries? ")
  6630. (t (user-error "Wrong input"))))
  6631. (num (string-to-number (read-from-minibuffer msg))))
  6632. (cond ((equal max ?e)
  6633. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6634. ((equal max ?t)
  6635. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6636. ((equal max ?T)
  6637. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6638. ((equal max ?E)
  6639. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  6640. (org-agenda-fit-window-to-buffer))
  6641. (defun org-agenda-highlight-todo (x)
  6642. (let ((org-done-keywords org-done-keywords-for-agenda)
  6643. (case-fold-search nil)
  6644. re)
  6645. (if (eq x 'line)
  6646. (save-excursion
  6647. (beginning-of-line 1)
  6648. (setq re (org-get-at-bol 'org-todo-regexp))
  6649. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6650. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6651. (add-text-properties (match-beginning 0) (match-end 1)
  6652. (list 'face (org-get-todo-face 1)))
  6653. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6654. (delete-region (match-beginning 1) (1- (match-end 0)))
  6655. (goto-char (match-beginning 1))
  6656. (insert (format org-agenda-todo-keyword-format s)))))
  6657. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6658. (setq re (get-text-property 0 'org-todo-regexp x))
  6659. (when (and re
  6660. ;; Test `pl' because if there's no heading content,
  6661. ;; there's no point matching to highlight. Note
  6662. ;; that if we didn't test `pl' first, and there
  6663. ;; happened to be no keyword from `org-todo-regexp'
  6664. ;; on this heading line, then the `equal' comparison
  6665. ;; afterwards would spuriously succeed in the case
  6666. ;; where `pl' is nil -- causing an args-out-of-range
  6667. ;; error when we try to add text properties to text
  6668. ;; that isn't there.
  6669. pl
  6670. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6671. x pl)
  6672. pl))
  6673. (add-text-properties
  6674. (or (match-end 1) (match-end 0)) (match-end 0)
  6675. (list 'face (org-get-todo-face (match-string 2 x)))
  6676. x)
  6677. (when (match-end 1)
  6678. (setq x
  6679. (concat
  6680. (substring x 0 (match-end 1))
  6681. (unless (string= org-agenda-todo-keyword-format "")
  6682. (format org-agenda-todo-keyword-format
  6683. (match-string 2 x)))
  6684. ;; Remove `display' property as the icon could leak
  6685. ;; on the white space.
  6686. (org-add-props " " (org-plist-delete (text-properties-at 0 x)
  6687. 'display))
  6688. (substring x (match-end 3)))))))
  6689. x)))
  6690. (defsubst org-cmp-values (a b property)
  6691. "Compare the numeric value of text PROPERTY for string A and B."
  6692. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  6693. (pb (or (get-text-property (1- (length b)) property b) 0)))
  6694. (cond ((> pa pb) +1)
  6695. ((< pa pb) -1))))
  6696. (defsubst org-cmp-effort (a b)
  6697. "Compare the effort values of string A and B."
  6698. (let* ((def (if org-agenda-sort-noeffort-is-high 32767 -1))
  6699. ;; `effort-minutes' property is not directly accessible from
  6700. ;; the strings, but is stored as a property in `txt'.
  6701. (ea (or (get-text-property
  6702. 0 'effort-minutes (get-text-property 0 'txt a))
  6703. def))
  6704. (eb (or (get-text-property
  6705. 0 'effort-minutes (get-text-property 0 'txt b))
  6706. def)))
  6707. (cond ((> ea eb) +1)
  6708. ((< ea eb) -1))))
  6709. (defsubst org-cmp-category (a b)
  6710. "Compare the string values of categories of strings A and B."
  6711. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  6712. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  6713. (cond ((string-lessp ca cb) -1)
  6714. ((string-lessp cb ca) +1))))
  6715. (defsubst org-cmp-todo-state (a b)
  6716. "Compare the todo states of strings A and B."
  6717. (let* ((ma (or (get-text-property 1 'org-marker a)
  6718. (get-text-property 1 'org-hd-marker a)))
  6719. (mb (or (get-text-property 1 'org-marker b)
  6720. (get-text-property 1 'org-hd-marker b)))
  6721. (fa (and ma (marker-buffer ma)))
  6722. (fb (and mb (marker-buffer mb)))
  6723. (todo-kwds
  6724. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6725. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6726. (ta (or (get-text-property 1 'todo-state a) ""))
  6727. (tb (or (get-text-property 1 'todo-state b) ""))
  6728. (la (- (length (member ta todo-kwds))))
  6729. (lb (- (length (member tb todo-kwds))))
  6730. (donepa (member ta org-done-keywords-for-agenda))
  6731. (donepb (member tb org-done-keywords-for-agenda)))
  6732. (cond ((and donepa (not donepb)) -1)
  6733. ((and (not donepa) donepb) +1)
  6734. ((< la lb) -1)
  6735. ((< lb la) +1))))
  6736. (defsubst org-cmp-alpha (a b)
  6737. "Compare the headlines, alphabetically."
  6738. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6739. (plb (text-property-any 0 (length b) 'org-heading t b))
  6740. (ta (and pla (substring a pla)))
  6741. (tb (and plb (substring b plb)))
  6742. (case-fold-search nil))
  6743. (when pla
  6744. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6745. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  6746. ta)
  6747. (setq ta (substring ta (match-end 0))))
  6748. (setq ta (downcase ta)))
  6749. (when plb
  6750. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6751. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  6752. tb)
  6753. (setq tb (substring tb (match-end 0))))
  6754. (setq tb (downcase tb)))
  6755. (cond ((not (or ta tb)) nil)
  6756. ((not ta) +1)
  6757. ((not tb) -1)
  6758. ((string-lessp ta tb) -1)
  6759. ((string-lessp tb ta) +1))))
  6760. (defsubst org-cmp-tag (a b)
  6761. "Compare the string values of the first tags of A and B."
  6762. (let ((ta (car (last (get-text-property 1 'tags a))))
  6763. (tb (car (last (get-text-property 1 'tags b)))))
  6764. (cond ((not (or ta tb)) nil)
  6765. ((not ta) +1)
  6766. ((not tb) -1)
  6767. ((string-lessp ta tb) -1)
  6768. ((string-lessp tb ta) +1))))
  6769. (defsubst org-cmp-time (a b)
  6770. "Compare the time-of-day values of strings A and B."
  6771. (let* ((def (if org-agenda-sort-notime-is-late 9901 -1))
  6772. (ta (or (get-text-property 1 'time-of-day a) def))
  6773. (tb (or (get-text-property 1 'time-of-day b) def)))
  6774. (cond ((< ta tb) -1)
  6775. ((< tb ta) +1))))
  6776. (defsubst org-cmp-ts (a b type)
  6777. "Compare the timestamps values of entries A and B.
  6778. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  6779. \"timestamp_ia\", compare within each of these type. When TYPE
  6780. is the empty string, compare all timestamps without respect of
  6781. their type."
  6782. (let* ((def (and (not org-agenda-sort-notime-is-late) -1))
  6783. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  6784. (get-text-property 1 'ts-date a))
  6785. def))
  6786. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  6787. (get-text-property 1 'ts-date b))
  6788. def)))
  6789. (cond ((if ta (and tb (< ta tb)) tb) -1)
  6790. ((if tb (and ta (< tb ta)) ta) +1))))
  6791. (defsubst org-cmp-habit-p (a b)
  6792. "Compare the todo states of strings A and B."
  6793. (let ((ha (get-text-property 1 'org-habit-p a))
  6794. (hb (get-text-property 1 'org-habit-p b)))
  6795. (cond ((and ha (not hb)) -1)
  6796. ((and (not ha) hb) +1))))
  6797. (defun org-entries-lessp (a b)
  6798. "Predicate for sorting agenda entries."
  6799. ;; The following variables will be used when the form is evaluated.
  6800. ;; So even though the compiler complains, keep them.
  6801. (let ((ss org-agenda-sorting-strategy-selected))
  6802. (org-dlet
  6803. ((timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6804. (org-cmp-ts a b "")))
  6805. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6806. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6807. (org-cmp-ts a b "scheduled")))
  6808. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6809. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6810. (org-cmp-ts a b "deadline")))
  6811. (deadline-down (if deadline-up (- deadline-up) nil))
  6812. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6813. (org-cmp-ts a b "timestamp_ia")))
  6814. (tsia-down (if tsia-up (- tsia-up) nil))
  6815. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6816. (org-cmp-ts a b "timestamp")))
  6817. (ts-down (if ts-up (- ts-up) nil))
  6818. (time-up (and (org-em 'time-up 'time-down ss)
  6819. (org-cmp-time a b)))
  6820. (time-down (if time-up (- time-up) nil))
  6821. (stats-up (and (org-em 'stats-up 'stats-down ss)
  6822. (org-cmp-values a b 'org-stats)))
  6823. (stats-down (if stats-up (- stats-up) nil))
  6824. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6825. (org-cmp-values a b 'priority)))
  6826. (priority-down (if priority-up (- priority-up) nil))
  6827. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6828. (org-cmp-effort a b)))
  6829. (effort-down (if effort-up (- effort-up) nil))
  6830. (category-up (and (or (org-em 'category-up 'category-down ss)
  6831. (memq 'category-keep ss))
  6832. (org-cmp-category a b)))
  6833. (category-down (if category-up (- category-up) nil))
  6834. (category-keep (if category-up +1 nil))
  6835. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6836. (org-cmp-tag a b)))
  6837. (tag-down (if tag-up (- tag-up) nil))
  6838. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6839. (org-cmp-todo-state a b)))
  6840. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6841. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6842. (org-cmp-habit-p a b)))
  6843. (habit-down (if habit-up (- habit-up) nil))
  6844. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6845. (org-cmp-alpha a b)))
  6846. (alpha-down (if alpha-up (- alpha-up) nil))
  6847. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6848. user-defined-up user-defined-down)
  6849. (when (and need-user-cmp org-agenda-cmp-user-defined
  6850. (functionp org-agenda-cmp-user-defined))
  6851. (setq user-defined-up
  6852. (funcall org-agenda-cmp-user-defined a b)
  6853. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6854. (cdr (assoc
  6855. (eval (cons 'or org-agenda-sorting-strategy-selected) t)
  6856. '((-1 . t) (1 . nil) (nil . nil)))))))
  6857. ;;; Agenda restriction lock
  6858. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6859. "Overlay to mark the headline to which agenda commands are restricted.")
  6860. (overlay-put org-agenda-restriction-lock-overlay
  6861. 'face 'org-agenda-restriction-lock)
  6862. (overlay-put org-agenda-restriction-lock-overlay
  6863. 'help-echo "Agendas are currently limited to this subtree.")
  6864. (delete-overlay org-agenda-restriction-lock-overlay)
  6865. (defun org-agenda-set-restriction-lock-from-agenda (arg)
  6866. "Set the restriction lock to the agenda item at point from within the agenda.
  6867. When called with a `\\[universal-argument]' prefix, restrict to
  6868. the file which contains the item.
  6869. Argument ARG is the prefix argument."
  6870. (interactive "P")
  6871. (unless (derived-mode-p 'org-agenda-mode)
  6872. (user-error "Not in an Org agenda buffer"))
  6873. (let* ((marker (or (org-get-at-bol 'org-marker)
  6874. (org-agenda-error)))
  6875. (buffer (marker-buffer marker))
  6876. (pos (marker-position marker)))
  6877. (with-current-buffer buffer
  6878. (goto-char pos)
  6879. (org-agenda-set-restriction-lock arg))))
  6880. ;;;###autoload
  6881. (defun org-agenda-set-restriction-lock (&optional type)
  6882. "Set restriction lock for agenda to current subtree or file.
  6883. When in a restricted subtree, remove it.
  6884. The restriction will span over the entire file if TYPE is `file',
  6885. or if type is '(4), or if the cursor is before the first headline
  6886. in the file. Otherwise, only apply the restriction to the current
  6887. subtree."
  6888. (interactive "P")
  6889. (if (and org-agenda-overriding-restriction
  6890. (member org-agenda-restriction-lock-overlay
  6891. (overlays-at (point)))
  6892. (equal (overlay-start org-agenda-restriction-lock-overlay)
  6893. (point)))
  6894. (org-agenda-remove-restriction-lock 'noupdate)
  6895. (org-agenda-remove-restriction-lock 'noupdate)
  6896. (and (equal type '(4)) (setq type 'file))
  6897. (setq type (cond
  6898. (type type)
  6899. ((org-at-heading-p) 'subtree)
  6900. ((condition-case nil (org-back-to-heading t) (error nil))
  6901. 'subtree)
  6902. (t 'file)))
  6903. (if (eq type 'subtree)
  6904. (progn
  6905. (setq org-agenda-restrict (current-buffer))
  6906. (setq org-agenda-overriding-restriction 'subtree)
  6907. (put 'org-agenda-files 'org-restrict
  6908. (list (buffer-file-name (buffer-base-buffer))))
  6909. (org-back-to-heading t)
  6910. (move-overlay org-agenda-restriction-lock-overlay
  6911. (point)
  6912. (if org-agenda-restriction-lock-highlight-subtree
  6913. (save-excursion (org-end-of-subtree t t) (point))
  6914. (point-at-eol)))
  6915. (move-marker org-agenda-restrict-begin (point))
  6916. (move-marker org-agenda-restrict-end
  6917. (save-excursion (org-end-of-subtree t t)))
  6918. (message "Locking agenda restriction to subtree"))
  6919. (put 'org-agenda-files 'org-restrict
  6920. (list (buffer-file-name (buffer-base-buffer))))
  6921. (setq org-agenda-restrict nil)
  6922. (setq org-agenda-overriding-restriction 'file)
  6923. (move-marker org-agenda-restrict-begin nil)
  6924. (move-marker org-agenda-restrict-end nil)
  6925. (message "Locking agenda restriction to file"))
  6926. (setq current-prefix-arg nil))
  6927. (org-agenda-maybe-redo))
  6928. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6929. "Remove agenda restriction lock."
  6930. (interactive "P")
  6931. (if (not org-agenda-restrict)
  6932. (message "No agenda restriction to remove.")
  6933. (delete-overlay org-agenda-restriction-lock-overlay)
  6934. (delete-overlay org-speedbar-restriction-lock-overlay)
  6935. (setq org-agenda-overriding-restriction nil)
  6936. (setq org-agenda-restrict nil)
  6937. (put 'org-agenda-files 'org-restrict nil)
  6938. (move-marker org-agenda-restrict-begin nil)
  6939. (move-marker org-agenda-restrict-end nil)
  6940. (setq current-prefix-arg nil)
  6941. (message "Agenda restriction lock removed")
  6942. (or noupdate (org-agenda-maybe-redo))))
  6943. (defun org-agenda-maybe-redo ()
  6944. "If there is any window showing the agenda view, update it."
  6945. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  6946. org-agenda-buffer-name)
  6947. t))
  6948. (w0 (selected-window)))
  6949. (when w
  6950. (select-window w)
  6951. (org-agenda-redo)
  6952. (select-window w0)
  6953. (if org-agenda-overriding-restriction
  6954. (message "Agenda view shifted to new %s restriction"
  6955. org-agenda-overriding-restriction)
  6956. (message "Agenda restriction lock removed")))))
  6957. ;;; Agenda commands
  6958. (defun org-agenda-check-type (error &rest types)
  6959. "Check if agenda buffer or component is of allowed type.
  6960. If ERROR is non-nil, throw an error, otherwise just return nil.
  6961. Allowed types are `agenda' `todo' `tags' `search'."
  6962. (cond ((not org-agenda-type)
  6963. (error "No Org agenda currently displayed"))
  6964. ((memq org-agenda-type types) t)
  6965. (error
  6966. (error "Not allowed in '%s'-type agenda buffer or component" org-agenda-type))
  6967. (t nil)))
  6968. (defun org-agenda-Quit ()
  6969. "Exit the agenda, killing the agenda buffer.
  6970. Like `org-agenda-quit', but kill the buffer even when
  6971. `org-agenda-sticky' is non-nil."
  6972. (interactive)
  6973. (org-agenda--quit))
  6974. (defun org-agenda-quit ()
  6975. "Exit the agenda.
  6976. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  6977. instead of killing it.
  6978. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  6979. the pre-agenda window configuration.
  6980. When column view is active, exit column view instead of the
  6981. agenda."
  6982. (interactive)
  6983. (org-agenda--quit org-agenda-sticky))
  6984. (defun org-agenda--quit (&optional bury)
  6985. (if org-agenda-columns-active
  6986. (org-columns-quit)
  6987. (let ((wconf org-agenda-pre-window-conf)
  6988. (buf (current-buffer))
  6989. (org-agenda-last-indirect-window
  6990. (and (eq org-indirect-buffer-display 'other-window)
  6991. org-agenda-last-indirect-buffer
  6992. (get-buffer-window org-agenda-last-indirect-buffer))))
  6993. (cond
  6994. ((eq org-agenda-window-setup 'other-frame)
  6995. (delete-frame))
  6996. ((eq org-agenda-window-setup 'other-tab)
  6997. (if (fboundp 'tab-bar-close-tab)
  6998. (tab-bar-close-tab)
  6999. (user-error "Your version of Emacs does not have tab bar mode support")))
  7000. ((and org-agenda-restore-windows-after-quit
  7001. wconf)
  7002. ;; Maybe restore the pre-agenda window configuration. Reset
  7003. ;; `org-agenda-pre-window-conf' before running
  7004. ;; `set-window-configuration', which loses the current buffer.
  7005. (setq org-agenda-pre-window-conf nil)
  7006. (set-window-configuration wconf))
  7007. (t
  7008. (when org-agenda-last-indirect-window
  7009. (delete-window org-agenda-last-indirect-window))
  7010. (and (not (eq org-agenda-window-setup 'current-window))
  7011. (not (one-window-p))
  7012. (delete-window))))
  7013. (if bury
  7014. ;; Set the agenda buffer as the current buffer instead of
  7015. ;; passing it as an argument to `bury-buffer' so that
  7016. ;; `bury-buffer' removes it from the window.
  7017. (with-current-buffer buf
  7018. (bury-buffer))
  7019. (kill-buffer buf)
  7020. (setq org-agenda-archives-mode nil
  7021. org-agenda-buffer nil)))))
  7022. (defun org-agenda-exit ()
  7023. "Exit the agenda, killing Org buffers loaded by the agenda.
  7024. Like `org-agenda-Quit', but kill any buffers that were created by
  7025. the agenda. Org buffers visited directly by the user will not be
  7026. touched. Also, exit the agenda even if it is in column view."
  7027. (interactive)
  7028. (when org-agenda-columns-active
  7029. (org-columns-quit))
  7030. (org-release-buffers org-agenda-new-buffers)
  7031. (setq org-agenda-new-buffers nil)
  7032. (org-agenda-Quit))
  7033. (defun org-agenda-kill-all-agenda-buffers ()
  7034. "Kill all buffers in `org-agenda-mode'.
  7035. This is used when toggling sticky agendas."
  7036. (interactive)
  7037. (let (blist)
  7038. (dolist (buf (buffer-list))
  7039. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  7040. (push buf blist)))
  7041. (mapc #'kill-buffer blist)))
  7042. (defun org-agenda-execute (arg)
  7043. "Execute another agenda command, keeping same window.
  7044. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  7045. in the agenda."
  7046. (interactive "P")
  7047. (let ((org-agenda-window-setup 'current-window))
  7048. (org-agenda arg)))
  7049. (defun org-agenda-redo (&optional all)
  7050. "Rebuild possibly ALL agenda view(s) in the current buffer."
  7051. (interactive "P")
  7052. (defvar org-agenda-tag-filter-while-redo) ;FIXME: Where is this var used?
  7053. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  7054. (cpa (unless (eq all t) current-prefix-arg))
  7055. (org-agenda-doing-sticky-redo org-agenda-sticky)
  7056. (org-agenda-sticky nil)
  7057. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  7058. org-agenda-buffer-name))
  7059. (org-agenda-keep-modes t)
  7060. (tag-filter org-agenda-tag-filter)
  7061. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  7062. (top-hl-filter org-agenda-top-headline-filter)
  7063. (cat-filter org-agenda-category-filter)
  7064. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  7065. (re-filter org-agenda-regexp-filter)
  7066. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  7067. (effort-filter org-agenda-effort-filter)
  7068. (effort-preset (get 'org-agenda-effort-filter :preset-filter))
  7069. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  7070. (cols org-agenda-columns-active)
  7071. (line (org-current-line))
  7072. (window-line (- line (org-current-line (window-start))))
  7073. (lprops (get 'org-agenda-redo-command 'org-lprops))
  7074. (redo-cmd (get-text-property p 'org-redo-cmd))
  7075. (last-args (get-text-property p 'org-last-args))
  7076. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  7077. (org-agenda-overriding-cmd-arguments
  7078. (unless (eq all t)
  7079. (cond ((listp last-args)
  7080. (cons (or cpa (car last-args)) (cdr last-args)))
  7081. ((stringp last-args)
  7082. last-args))))
  7083. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  7084. (put 'org-agenda-tag-filter :preset-filter nil)
  7085. (put 'org-agenda-category-filter :preset-filter nil)
  7086. (put 'org-agenda-regexp-filter :preset-filter nil)
  7087. (put 'org-agenda-effort-filter :preset-filter nil)
  7088. (and cols (org-columns-quit))
  7089. (message "Rebuilding agenda buffer...")
  7090. (if series-redo-cmd
  7091. (eval series-redo-cmd t)
  7092. (cl-progv
  7093. (mapcar #'car lprops)
  7094. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  7095. (eval redo-cmd t)))
  7096. (setq org-agenda-undo-list nil
  7097. org-agenda-pending-undo-list nil
  7098. org-agenda-tag-filter tag-filter
  7099. org-agenda-category-filter cat-filter
  7100. org-agenda-regexp-filter re-filter
  7101. org-agenda-effort-filter effort-filter
  7102. org-agenda-top-headline-filter top-hl-filter)
  7103. (message "Rebuilding agenda buffer...done")
  7104. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  7105. (put 'org-agenda-category-filter :preset-filter cat-preset)
  7106. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  7107. (put 'org-agenda-effort-filter :preset-filter effort-preset)
  7108. (let ((tag (or tag-filter tag-preset))
  7109. (cat (or cat-filter cat-preset))
  7110. (effort (or effort-filter effort-preset))
  7111. (re (or re-filter re-preset)))
  7112. (when tag (org-agenda-filter-apply tag 'tag t))
  7113. (when cat (org-agenda-filter-apply cat 'category))
  7114. (when effort (org-agenda-filter-apply effort 'effort))
  7115. (when re (org-agenda-filter-apply re 'regexp)))
  7116. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  7117. (and cols (called-interactively-p 'any) (org-agenda-columns))
  7118. (org-goto-line line)
  7119. (when (called-interactively-p 'any) (recenter window-line))))
  7120. (defun org-agenda-redo-all (&optional exhaustive)
  7121. "Rebuild all agenda views in the current buffer.
  7122. With a prefix argument, do so in all agenda buffers."
  7123. (interactive "P")
  7124. (if exhaustive
  7125. (dolist (buffer (buffer-list))
  7126. (with-current-buffer buffer
  7127. (when (derived-mode-p 'org-agenda-mode)
  7128. (org-agenda-redo t))))
  7129. (org-agenda-redo t)))
  7130. (defvar org-global-tags-completion-table nil)
  7131. (defvar org-agenda-filter-form nil)
  7132. (defvar org-agenda-filtered-by-category nil)
  7133. (defsubst org-agenda-get-category ()
  7134. "Return the category of the agenda line."
  7135. (org-get-at-bol 'org-category))
  7136. (defun org-agenda-filter-by-category (strip)
  7137. "Filter lines in the agenda buffer that have a specific category.
  7138. The category is that of the current line.
  7139. With a `\\[universal-argument]' prefix argument, exclude the lines of that category.
  7140. When there is already a category filter in place, this command removes the
  7141. filter."
  7142. (interactive "P")
  7143. (if (and org-agenda-filtered-by-category
  7144. org-agenda-category-filter)
  7145. (org-agenda-filter-show-all-cat)
  7146. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  7147. (cond
  7148. ((and cat strip)
  7149. (org-agenda-filter-apply
  7150. (push (concat "-" cat) org-agenda-category-filter) 'category))
  7151. (cat
  7152. (org-agenda-filter-apply
  7153. (setq org-agenda-category-filter
  7154. (list (concat "+" cat)))
  7155. 'category))
  7156. (t (error "No category at point"))))))
  7157. (defun org-find-top-headline (&optional pos)
  7158. "Find the topmost parent headline and return it.
  7159. POS when non-nil is the marker or buffer position to start the
  7160. search from."
  7161. (save-excursion
  7162. (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
  7163. (when pos (goto-char pos))
  7164. ;; Skip up to the topmost parent.
  7165. (while (org-up-heading-safe))
  7166. (ignore-errors
  7167. (replace-regexp-in-string
  7168. "^\\[[0-9]+/[0-9]+\\] *\\|^\\[%[0-9]+\\] *" ""
  7169. (nth 4 (org-heading-components)))))))
  7170. (defvar org-agenda-filtered-by-top-headline nil)
  7171. (defun org-agenda-filter-by-top-headline (strip)
  7172. "Keep only those lines that are descendants from the same top headline.
  7173. The top headline is that of the current line. With prefix arg STRIP, hide
  7174. all lines of the category at point."
  7175. (interactive "P")
  7176. (if org-agenda-filtered-by-top-headline
  7177. (progn
  7178. (setq org-agenda-filtered-by-top-headline nil
  7179. org-agenda-top-headline-filter nil)
  7180. (org-agenda-filter-show-all-top-filter))
  7181. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  7182. (if toph (org-agenda-filter-top-headline-apply toph strip)
  7183. (error "No top-level headline at point")))))
  7184. (defvar org-agenda-regexp-filter nil)
  7185. (defun org-agenda-filter-by-regexp (strip-or-accumulate)
  7186. "Filter agenda entries by a regular expressions.
  7187. You will be prompted for the regular expression, and the agenda
  7188. view will only show entries that are matched by that expression.
  7189. With one `\\[universal-argument]' prefix argument, hide entries matching the regexp.
  7190. When there is already a regexp filter active, this command removed the
  7191. filter. However, with two `\\[universal-argument]' prefix arguments, add a new condition to
  7192. an already existing regexp filter."
  7193. (interactive "P")
  7194. (let* ((strip (equal strip-or-accumulate '(4)))
  7195. (accumulate (equal strip-or-accumulate '(16))))
  7196. (cond
  7197. ((and org-agenda-regexp-filter (not accumulate))
  7198. (org-agenda-filter-show-all-re)
  7199. (message "Regexp filter removed"))
  7200. (t (let ((flt (concat (if strip "-" "+")
  7201. (read-from-minibuffer
  7202. (if strip
  7203. "Hide entries matching regexp: "
  7204. "Narrow to entries matching regexp: ")))))
  7205. (push flt org-agenda-regexp-filter)
  7206. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))))))
  7207. (defvar org-agenda-effort-filter nil)
  7208. (defun org-agenda-filter-by-effort (strip-or-accumulate)
  7209. "Filter agenda entries by effort.
  7210. With no `\\[universal-argument]' prefix argument, keep entries matching the effort condition.
  7211. With one `\\[universal-argument]' prefix argument, filter out entries matching the condition.
  7212. With two `\\[universal-argument]' prefix arguments, add a second condition to the existing filter.
  7213. This last option is in practice not very useful, but it is available for
  7214. consistency with the other filter commands."
  7215. (interactive "P")
  7216. (let* ((efforts (split-string
  7217. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7218. org-global-properties
  7219. t))
  7220. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
  7221. ;; XXX: the following handles only up to 10 different
  7222. ;; effort values.
  7223. (allowed-keys (if (null efforts) nil
  7224. (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
  7225. (number-sequence 1 (length efforts)))))
  7226. (keep (equal strip-or-accumulate '(16)))
  7227. (negative (equal strip-or-accumulate '(4)))
  7228. (current org-agenda-effort-filter)
  7229. (op nil))
  7230. (while (not (memq op '(?< ?> ?= ?_)))
  7231. (setq op (read-char-exclusive
  7232. "Effort operator? (> = or <) or press `_' again to remove filter")))
  7233. ;; Select appropriate duration. Ignore non-digit characters.
  7234. (if (eq op ?_)
  7235. (progn
  7236. (org-agenda-filter-show-all-effort)
  7237. (message "Effort filter removed"))
  7238. (let ((prompt
  7239. (apply #'format
  7240. (concat "Effort %c "
  7241. (mapconcat (lambda (s) (concat "[%d]" s))
  7242. efforts
  7243. " "))
  7244. op allowed-keys))
  7245. (eff -1))
  7246. (while (not (memq eff allowed-keys))
  7247. (message prompt)
  7248. (setq eff (- (read-char-exclusive) 48)))
  7249. (org-agenda-filter-show-all-effort)
  7250. (setq org-agenda-effort-filter
  7251. (append
  7252. (list (concat (if negative "-" "+")
  7253. (char-to-string op)
  7254. ;; Numbering is 1 2 3 ... 9 0, but we want
  7255. ;; 0 1 2 ... 8 9.
  7256. (nth (mod (1- eff) 10) efforts)))
  7257. (if keep current nil)))
  7258. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))))
  7259. (defun org-agenda-filter (&optional strip-or-accumulate)
  7260. "Prompt for a general filter string and apply it to the agenda.
  7261. The string may contain filter elements like
  7262. +category
  7263. +tag
  7264. +<effort > and = are also allowed as effort operators
  7265. +/regexp/
  7266. Instead of `+', `-' is allowed to strip the agenda of matching entries.
  7267. `+' is optional if it is not required to separate two string parts.
  7268. Multiple filter elements can be concatenated without spaces, for example
  7269. +work-John<0:10-/plot/
  7270. selects entries with category `work' and effort estimates below 10 minutes,
  7271. and deselects entries with tag `John' or matching the regexp `plot'.
  7272. During entry of the filter, completion for tags, categories and effort
  7273. values is offered. Since the syntax for categories and tags is identical
  7274. there should be no overlap between categories and tags. If there is, tags
  7275. get priority.
  7276. A single `\\[universal-argument]' prefix arg STRIP-OR-ACCUMULATE will negate the
  7277. entire filter, which can be useful in connection with the prompt history.
  7278. A double `\\[universal-argument] \\[universal-argument]' prefix arg will add the new filter elements to the
  7279. existing ones. A shortcut for this is to add an additional `+' at the
  7280. beginning of the string, like `+-John'.
  7281. With a triple prefix argument, execute the computed filtering defined in
  7282. the variable `org-agenda-auto-exclude-function'."
  7283. (interactive "P")
  7284. (if (equal strip-or-accumulate '(64))
  7285. ;; Execute the auto-exclude action
  7286. (if (not org-agenda-auto-exclude-function)
  7287. (user-error "`org-agenda-auto-exclude-function' is undefined")
  7288. (org-agenda-filter-show-all-tag)
  7289. (setq org-agenda-tag-filter nil)
  7290. (dolist (tag (org-agenda-get-represented-tags))
  7291. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7292. (when modifier
  7293. (push modifier org-agenda-tag-filter))))
  7294. (unless (null org-agenda-tag-filter)
  7295. (org-agenda-filter-apply org-agenda-tag-filter 'tag 'expand)))
  7296. ;; Prompt for a filter and act
  7297. (let* ((tag-list (org-agenda-get-represented-tags))
  7298. (category-list (org-agenda-get-represented-categories))
  7299. (negate (equal strip-or-accumulate '(4)))
  7300. (cf (mapconcat #'identity org-agenda-category-filter ""))
  7301. (tf (mapconcat #'identity org-agenda-tag-filter ""))
  7302. ;; (rpl-fn (lambda (c) (replace-regexp-in-string "^\\+" "" (or (car c) ""))))
  7303. (ef (replace-regexp-in-string "^\\+" "" (or (car org-agenda-effort-filter) "")))
  7304. (rf (replace-regexp-in-string "^\\+" "" (or (car org-agenda-regexp-filter) "")))
  7305. (ff (concat cf tf ef (when (not (equal rf "")) (concat "/" rf "/"))))
  7306. (f-string (completing-read
  7307. (concat
  7308. (if negate "Negative filter" "Filter")
  7309. " [+cat-tag<0:10-/regexp/]: ")
  7310. #'org-agenda-filter-completion-function
  7311. nil nil ff))
  7312. (keep (or (if (string-match "^\\+[+-]" f-string)
  7313. (progn (setq f-string (substring f-string 1)) t))
  7314. (equal strip-or-accumulate '(16))))
  7315. (fc (if keep org-agenda-category-filter))
  7316. (ft (if keep org-agenda-tag-filter))
  7317. (fe (if keep org-agenda-effort-filter))
  7318. (fr (if keep org-agenda-regexp-filter))
  7319. pm s)
  7320. ;; If the filter contains a double-quoted string, replace a
  7321. ;; single hyphen by the arbitrary and temporary string "~~~"
  7322. ;; to disambiguate such hyphens from syntactic ones.
  7323. (setq f-string (replace-regexp-in-string
  7324. "\"\\([^\"]*\\)-\\([^\"]*\\)\"" "\"\\1~~~\\2\"" f-string))
  7325. (while (string-match "^[ \t]*\\([-+]\\)?\\(\\([^-+<>=/ \t]+\\)\\|\\([<>=][0-9:]+\\)\\|\\(/\\([^/]+\\)/?\\)\\)" f-string)
  7326. (setq pm (if (match-beginning 1) (match-string 1 f-string) "+"))
  7327. (when negate
  7328. (setq pm (if (equal pm "+") "-" "+")))
  7329. (cond
  7330. ((match-beginning 3)
  7331. ;; category or tag
  7332. (setq s (replace-regexp-in-string ; Remove the temporary special string.
  7333. "~~~" "-" (match-string 3 f-string)))
  7334. (cond
  7335. ((member s tag-list)
  7336. (org-pushnew-to-end (concat pm s) ft))
  7337. ((member s category-list)
  7338. (org-pushnew-to-end (concat pm ; Remove temporary double quotes.
  7339. (replace-regexp-in-string "\"\\(.*\\)\"" "\\1" s))
  7340. fc))
  7341. (t (message
  7342. "`%s%s' filter ignored because tag/category is not represented"
  7343. pm s))))
  7344. ((match-beginning 4)
  7345. ;; effort
  7346. (org-pushnew-to-end (concat pm (match-string 4 f-string)) fe))
  7347. ((match-beginning 5)
  7348. ;; regexp
  7349. (org-pushnew-to-end (concat pm (match-string 6 f-string)) fr)))
  7350. (setq f-string (substring f-string (match-end 0))))
  7351. (org-agenda-filter-remove-all)
  7352. (and fc (org-agenda-filter-apply
  7353. (setq org-agenda-category-filter fc) 'category))
  7354. (and ft (org-agenda-filter-apply
  7355. (setq org-agenda-tag-filter ft) 'tag 'expand))
  7356. (and fe (org-agenda-filter-apply
  7357. (setq org-agenda-effort-filter fe) 'effort))
  7358. (and fr (org-agenda-filter-apply
  7359. (setq org-agenda-regexp-filter fr) 'regexp))
  7360. (run-hooks 'org-agenda-filter-hook))))
  7361. (defun org-agenda-filter-completion-function (string _predicate &optional flag)
  7362. "Complete a complex filter string.
  7363. FLAG specifies the type of completion operation to perform. This
  7364. function is passed as a collection function to `completing-read',
  7365. which see."
  7366. (let ((completion-ignore-case t) ;tags are case-sensitive
  7367. (confirm (lambda (x) (stringp x)))
  7368. (prefix "")
  7369. (operator "")
  7370. table)
  7371. (when (string-match "^\\(.*\\([-+<>=]\\)\\)\\([^-+<>=]*\\)$" string)
  7372. (setq prefix (match-string 1 string)
  7373. operator (match-string 2 string)
  7374. string (match-string 3 string)))
  7375. (cond
  7376. ((member operator '("+" "-" "" nil))
  7377. (setq table (append (org-agenda-get-represented-categories)
  7378. (org-agenda-get-represented-tags))))
  7379. ((member operator '("<" ">" "="))
  7380. (setq table (split-string
  7381. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7382. org-global-properties
  7383. t))
  7384. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")
  7385. " +")))
  7386. (t (setq table nil)))
  7387. (pcase flag
  7388. (`t (all-completions string table confirm))
  7389. (`lambda (assoc string table)) ;exact match?
  7390. (`nil
  7391. (pcase (try-completion string table confirm)
  7392. ((and completion (pred stringp))
  7393. (concat prefix completion))
  7394. (completion completion)))
  7395. (_ nil))))
  7396. (defun org-agenda-filter-remove-all ()
  7397. "Remove all filters from the current agenda buffer."
  7398. (interactive)
  7399. (when org-agenda-tag-filter
  7400. (org-agenda-filter-show-all-tag))
  7401. (when org-agenda-category-filter
  7402. (org-agenda-filter-show-all-cat))
  7403. (when org-agenda-regexp-filter
  7404. (org-agenda-filter-show-all-re))
  7405. (when org-agenda-top-headline-filter
  7406. (org-agenda-filter-show-all-top-filter))
  7407. (when org-agenda-effort-filter
  7408. (org-agenda-filter-show-all-effort))
  7409. (org-agenda-finalize)
  7410. (when (called-interactively-p 'interactive)
  7411. (message "All agenda filters removed")))
  7412. (defun org-agenda-filter-by-tag (strip-or-accumulate &optional char exclude)
  7413. "Keep only those lines in the agenda buffer that have a specific tag.
  7414. The tag is selected with its fast selection letter, as configured.
  7415. With a `\\[universal-argument]' prefix, apply the filter negatively, stripping all matches.
  7416. With a `\\[universal-argument] \\[universal-argument]' prefix, add the new tag to the existing filter
  7417. instead of replacing it.
  7418. With a `\\[universal-argument] \\[universal-argument] \\[universal-argument]' prefix, filter the literal tag, \
  7419. i.e. don't
  7420. filter on all its group members.
  7421. A Lisp caller can specify CHAR. EXCLUDE means that the new tag
  7422. should be used to exclude the search - the interactive user can
  7423. also press `-' or `+' to switch between filtering and excluding."
  7424. (interactive "P")
  7425. (let* ((alist org-tag-alist-for-agenda)
  7426. (seen-chars nil)
  7427. (tag-chars (mapconcat
  7428. (lambda (x) (if (and (not (symbolp (car x)))
  7429. (cdr x)
  7430. (not (member (cdr x) seen-chars)))
  7431. (progn
  7432. (push (cdr x) seen-chars)
  7433. (char-to-string (cdr x)))
  7434. ""))
  7435. org-tag-alist-for-agenda ""))
  7436. (valid-char-list (append '(?\t ?\r ?\\ ?. ?\s ?q)
  7437. (string-to-list tag-chars)))
  7438. (exclude (or exclude (equal strip-or-accumulate '(4))))
  7439. (accumulate (equal strip-or-accumulate '(16)))
  7440. (expand (not (equal strip-or-accumulate '(64))))
  7441. (inhibit-read-only t)
  7442. (current org-agenda-tag-filter)
  7443. a tag) ;; n
  7444. (unless char
  7445. (while (not (memq char valid-char-list))
  7446. (org-unlogged-message
  7447. "%s by tag%s: [%s ]tag-char [TAB]tag %s[\\]off [q]uit"
  7448. (if exclude "Exclude[+]" "Filter[-]")
  7449. (if expand "" " (no grouptag expand)")
  7450. tag-chars
  7451. (if org-agenda-auto-exclude-function "[RET] " ""))
  7452. (setq char (read-char-exclusive))
  7453. ;; Excluding or filtering down
  7454. (cond ((eq char ?-) (setq exclude t))
  7455. ((eq char ?+) (setq exclude nil)))))
  7456. (when (eq char ?\t)
  7457. (unless (local-variable-p 'org-global-tags-completion-table)
  7458. (setq-local org-global-tags-completion-table
  7459. (org-global-tags-completion-table)))
  7460. (let ((completion-ignore-case t))
  7461. (setq tag (completing-read
  7462. "Tag: " org-global-tags-completion-table nil t))))
  7463. (cond
  7464. ((eq char ?\r)
  7465. (org-agenda-filter-show-all-tag)
  7466. (when org-agenda-auto-exclude-function
  7467. (setq org-agenda-tag-filter nil)
  7468. (dolist (tag (org-agenda-get-represented-tags))
  7469. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7470. (when modifier
  7471. (push modifier org-agenda-tag-filter))))
  7472. (unless (null org-agenda-tag-filter)
  7473. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  7474. ((eq char ?\\)
  7475. (org-agenda-filter-show-all-tag)
  7476. (when (get 'org-agenda-tag-filter :preset-filter)
  7477. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  7478. ((eq char ?.)
  7479. (setq org-agenda-tag-filter
  7480. (mapcar (lambda(tag) (concat "+" tag))
  7481. (org-get-at-bol 'tags)))
  7482. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7483. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  7484. ((or (eq char ?\s)
  7485. (setq a (rassoc char alist))
  7486. (and tag (setq a (cons tag nil))))
  7487. (org-agenda-filter-show-all-tag)
  7488. (setq tag (car a))
  7489. (setq org-agenda-tag-filter
  7490. (cons (concat (if exclude "-" "+") tag)
  7491. (if accumulate current nil)))
  7492. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7493. (t (error "Invalid tag selection character %c" char)))))
  7494. (defun org-agenda-get-represented-categories ()
  7495. "Return a list of all categories used in this agenda buffer."
  7496. (or org-agenda-represented-categories
  7497. (when (derived-mode-p 'org-agenda-mode)
  7498. (let ((pos (point-min)) categories)
  7499. (while (and (< pos (point-max))
  7500. (setq pos (next-single-property-change
  7501. pos 'org-category nil (point-max))))
  7502. (push (get-text-property pos 'org-category) categories))
  7503. (setq org-agenda-represented-categories
  7504. ;; Enclose category names with a hyphen in double
  7505. ;; quotes to process them specially in `org-agenda-filter'.
  7506. (mapcar (lambda (s) (if (string-match-p "-" s) (format "\"%s\"" s) s))
  7507. (nreverse (org-uniquify (delq nil categories)))))))))
  7508. (defvar org-tag-groups-alist-for-agenda)
  7509. (defun org-agenda-get-represented-tags ()
  7510. "Return a list of all tags used in this agenda buffer.
  7511. These will be lower-case, for filtering."
  7512. (or org-agenda-represented-tags
  7513. (when (derived-mode-p 'org-agenda-mode)
  7514. (let ((pos (point-min)) tags-lists tt)
  7515. (while (and (< pos (point-max))
  7516. (setq pos (next-single-property-change
  7517. pos 'tags nil (point-max))))
  7518. (setq tt (get-text-property pos 'tags))
  7519. (if tt (push tt tags-lists)))
  7520. (setq tags-lists
  7521. (nreverse (org-uniquify
  7522. (delq nil (apply #'append tags-lists)))))
  7523. (dolist (tag tags-lists)
  7524. (mapc
  7525. (lambda (group)
  7526. (when (member tag group)
  7527. (push (car group) tags-lists)))
  7528. org-tag-groups-alist-for-agenda))
  7529. (setq org-agenda-represented-tags tags-lists)))))
  7530. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  7531. "Create the form that tests a line for agenda filter.
  7532. Optional argument EXPAND can be used for the TYPE tag and will
  7533. expand the tags in the FILTER if any of the tags in FILTER are
  7534. grouptags."
  7535. (let ((multi-pos-cats
  7536. (and (eq type 'category)
  7537. (string-match-p "\\+.*\\+"
  7538. (mapconcat (lambda (cat) (substring cat 0 1))
  7539. filter ""))))
  7540. f f1)
  7541. (cond
  7542. ;; Tag filter
  7543. ((eq type 'tag)
  7544. (setq filter
  7545. (delete-dups
  7546. (append (get 'org-agenda-tag-filter :preset-filter)
  7547. filter)))
  7548. (dolist (x filter)
  7549. (let ((op (string-to-char x)))
  7550. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  7551. (setq x (list x)))
  7552. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  7553. (push f1 f))))
  7554. ;; Category filter
  7555. ((eq type 'category)
  7556. (setq filter
  7557. (delete-dups
  7558. (append (get 'org-agenda-category-filter :preset-filter)
  7559. filter)))
  7560. (dolist (x filter)
  7561. (if (equal "-" (substring x 0 1))
  7562. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  7563. (setq f1 (list 'equal (substring x 1) 'cat)))
  7564. (push f1 f)))
  7565. ;; Regexp filter
  7566. ((eq type 'regexp)
  7567. (setq filter
  7568. (delete-dups
  7569. (append (get 'org-agenda-regexp-filter :preset-filter)
  7570. filter)))
  7571. (dolist (x filter)
  7572. (if (equal "-" (substring x 0 1))
  7573. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  7574. (setq f1 (list 'string-match (substring x 1) 'txt)))
  7575. (push f1 f)))
  7576. ;; Effort filter
  7577. ((eq type 'effort)
  7578. (setq filter
  7579. (delete-dups
  7580. (append (get 'org-agenda-effort-filter :preset-filter)
  7581. filter)))
  7582. (dolist (x filter)
  7583. (push (org-agenda-filter-effort-form x) f))))
  7584. (cons (if multi-pos-cats 'or 'and) (nreverse f))))
  7585. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  7586. "Return a form associated to tag-expression TAGS.
  7587. Build a form testing a line for agenda filter for
  7588. tag-expressions. OP is an operator of type CHAR that allows the
  7589. function to set the right switches in the returned form."
  7590. (let (form)
  7591. ;; Any of the expressions can match if OP is +, all must match if
  7592. ;; the operator is -.
  7593. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  7594. (let* ((tag (substring x 1))
  7595. (f (cond
  7596. ((string= "" tag) 'tags)
  7597. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  7598. ;; TAG is a regexp.
  7599. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  7600. (t (list 'member tag 'tags)))))
  7601. (push (if (eq op ?-) (list 'not f) f) form)))))
  7602. (defun org-agenda-filter-effort-form (e)
  7603. "Return the form to compare the effort of the current line with what E says.
  7604. E looks like \"+<2:25\"."
  7605. (let (op)
  7606. (setq e (substring e 1))
  7607. (setq op (string-to-char e) e (substring e 1))
  7608. (setq op (cond ((equal op ?<) '<=)
  7609. ((equal op ?>) '>=)
  7610. ((equal op ??) op)
  7611. (t '=)))
  7612. (list 'org-agenda-compare-effort (list 'quote op)
  7613. (org-duration-to-minutes e))))
  7614. (defun org-agenda-compare-effort (op value)
  7615. "Compare the effort of the current line with VALUE, using OP.
  7616. If the line does not have an effort defined, return nil."
  7617. ;; `effort-minutes' property cannot be extracted directly from
  7618. ;; current line but is stored as a property in `txt'.
  7619. (let ((effort (get-text-property 0 'effort-minutes (org-get-at-bol 'txt))))
  7620. (funcall op
  7621. (or effort (if org-agenda-sort-noeffort-is-high 32767 -1))
  7622. value)))
  7623. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  7624. "Expand group tags in FILTER for the agenda.
  7625. When NO-OPERATOR is non-nil, do not add the + operator to
  7626. returned tags."
  7627. (if org-group-tags
  7628. (let (case-fold-search rtn)
  7629. (mapc
  7630. (lambda (f)
  7631. (let (f0 dir)
  7632. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  7633. (setq dir (match-string 1 f) f0 (match-string 2 f))
  7634. (setq dir (if no-operator "" "+") f0 f))
  7635. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  7636. (org-tags-expand f0 t))
  7637. rtn))))
  7638. filter)
  7639. (reverse rtn))
  7640. filter))
  7641. (defun org-agenda-filter-apply (filter type &optional expand)
  7642. "Set FILTER as the new agenda filter and apply it.
  7643. Optional argument EXPAND can be used for the TYPE tag and will
  7644. expand the tags in the FILTER if any of the tags in FILTER are
  7645. grouptags."
  7646. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  7647. (when org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  7648. (setq org-agenda-filter-form (org-agenda-filter-make-matcher
  7649. filter type expand))
  7650. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  7651. ;; category is used as the filter:
  7652. (setq org-agenda-filtered-by-category
  7653. (and (eq type 'category)
  7654. (not (equal (substring (car filter) 0 1) "-"))))
  7655. (org-agenda-set-mode-name)
  7656. (save-excursion
  7657. (goto-char (point-min))
  7658. (while (not (eobp))
  7659. (when (or (org-get-at-bol 'org-hd-marker)
  7660. (org-get-at-bol 'org-marker))
  7661. (org-dlet
  7662. ((tags (org-get-at-bol 'tags))
  7663. (cat (org-agenda-get-category))
  7664. (txt (or (org-get-at-bol 'txt) "")))
  7665. (unless (eval org-agenda-filter-form t)
  7666. (org-agenda-filter-hide-line type))))
  7667. (beginning-of-line 2)))
  7668. (when (get-char-property (point) 'invisible)
  7669. (ignore-errors (org-agenda-previous-line))))
  7670. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  7671. "Filter by top headline HL."
  7672. (org-agenda-set-mode-name)
  7673. (save-excursion
  7674. (goto-char (point-min))
  7675. (while (not (eobp))
  7676. (let* ((pos (org-get-at-bol 'org-hd-marker))
  7677. (tophl (and pos (org-find-top-headline pos))))
  7678. (when (and tophl (funcall (if negative 'identity 'not)
  7679. (string= hl tophl)))
  7680. (org-agenda-filter-hide-line 'top-headline)))
  7681. (beginning-of-line 2)))
  7682. (when (get-char-property (point) 'invisible)
  7683. (org-agenda-previous-line))
  7684. (setq org-agenda-top-headline-filter hl
  7685. org-agenda-filtered-by-top-headline t))
  7686. (defun org-agenda-filter-hide-line (type)
  7687. "If current line is TYPE, hide it in the agenda buffer."
  7688. (let* (buffer-invisibility-spec
  7689. (beg (max (point-min) (1- (point-at-bol))))
  7690. (end (point-at-eol)))
  7691. (let ((inhibit-read-only t))
  7692. (add-text-properties
  7693. beg end `(invisible org-filtered org-filter-type ,type)))))
  7694. (defun org-agenda-remove-filter (type)
  7695. "Remove filter of type TYPE from the agenda buffer."
  7696. (interactive)
  7697. (save-excursion
  7698. (goto-char (point-min))
  7699. (let ((inhibit-read-only t) pos)
  7700. (while (setq pos (text-property-any (point) (point-max)
  7701. 'org-filter-type type))
  7702. (goto-char pos)
  7703. (remove-text-properties
  7704. (point) (next-single-property-change (point) 'org-filter-type)
  7705. `(invisible org-filtered org-filter-type ,type))))
  7706. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  7707. (setq org-agenda-filter-form nil)
  7708. (org-agenda-set-mode-name)
  7709. (org-agenda-finalize)))
  7710. (defun org-agenda-filter-show-all-tag nil
  7711. (org-agenda-remove-filter 'tag))
  7712. (defun org-agenda-filter-show-all-re nil
  7713. (org-agenda-remove-filter 'regexp))
  7714. (defun org-agenda-filter-show-all-effort nil
  7715. (org-agenda-remove-filter 'effort))
  7716. (defun org-agenda-filter-show-all-cat nil
  7717. (org-agenda-remove-filter 'category))
  7718. (defun org-agenda-filter-show-all-top-filter nil
  7719. (org-agenda-remove-filter 'top-headline))
  7720. (defun org-agenda-manipulate-query-add ()
  7721. "Manipulate the query by adding a search term with positive selection.
  7722. Positive selection means the term must be matched for selection of an entry."
  7723. (interactive)
  7724. (org-agenda-manipulate-query ?\[))
  7725. (defun org-agenda-manipulate-query-subtract ()
  7726. "Manipulate the query by adding a search term with negative selection.
  7727. Negative selection means term must not be matched for selection of an entry."
  7728. (interactive)
  7729. (org-agenda-manipulate-query ?\]))
  7730. (defun org-agenda-manipulate-query-add-re ()
  7731. "Manipulate the query by adding a search regexp with positive selection.
  7732. Positive selection means the regexp must match for selection of an entry."
  7733. (interactive)
  7734. (org-agenda-manipulate-query ?\{))
  7735. (defun org-agenda-manipulate-query-subtract-re ()
  7736. "Manipulate the query by adding a search regexp with negative selection.
  7737. Negative selection means regexp must not match for selection of an entry."
  7738. (interactive)
  7739. (org-agenda-manipulate-query ?\}))
  7740. (defun org-agenda-manipulate-query (char)
  7741. (cond
  7742. ((eq org-agenda-type 'agenda)
  7743. (let ((org-agenda-include-inactive-timestamps t))
  7744. (org-agenda-redo))
  7745. (message "Display now includes inactive timestamps as well"))
  7746. ((eq org-agenda-type 'search)
  7747. (org-add-to-string
  7748. 'org-agenda-query-string
  7749. (if org-agenda-last-search-view-search-was-boolean
  7750. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7751. (?\{ . " +{}") (?\} . " -{}"))))
  7752. " "))
  7753. (setq org-agenda-redo-command
  7754. (list 'org-search-view
  7755. (car (get-text-property (min (1- (point-max)) (point))
  7756. 'org-last-args))
  7757. org-agenda-query-string
  7758. (+ (length org-agenda-query-string)
  7759. (if (member char '(?\{ ?\})) 0 1))))
  7760. (set-register org-agenda-query-register org-agenda-query-string)
  7761. (let ((org-agenda-overriding-arguments
  7762. (cdr org-agenda-redo-command)))
  7763. (org-agenda-redo)))
  7764. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7765. org-agenda-type))))
  7766. (defun org-add-to-string (var string)
  7767. (set var (concat (symbol-value var) string)))
  7768. (defun org-agenda-goto-date (date)
  7769. "Jump to DATE in agenda."
  7770. (interactive
  7771. (list
  7772. (let ((org-read-date-prefer-future org-agenda-jump-prefer-future))
  7773. (org-read-date))))
  7774. (let* ((day (time-to-days (org-time-string-to-time date)))
  7775. (org-agenda-sticky-orig org-agenda-sticky)
  7776. (org-agenda-buffer-tmp-name (buffer-name))
  7777. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7778. (0-arg (or current-prefix-arg (car args)))
  7779. (2-arg (nth 2 args))
  7780. (with-hour-p (nth 4 org-agenda-redo-command))
  7781. (newcmd (list 'org-agenda-list 0-arg date
  7782. (org-agenda-span-to-ndays
  7783. 2-arg (org-time-string-to-absolute date))
  7784. with-hour-p))
  7785. (newargs (cdr newcmd))
  7786. (inhibit-read-only t)
  7787. org-agenda-sticky)
  7788. (if (not (org-agenda-check-type t 'agenda))
  7789. (error "Not available in non-agenda views")
  7790. (add-text-properties (point-min) (point-max)
  7791. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7792. (org-agenda-redo)
  7793. (goto-char (point-min))
  7794. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7795. (save-excursion (move-beginning-of-line 2) (eobp))))
  7796. (move-beginning-of-line 2))
  7797. (setq org-agenda-sticky org-agenda-sticky-orig
  7798. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7799. (defun org-agenda-goto-today ()
  7800. "Go to today."
  7801. (interactive)
  7802. (org-agenda-check-type t 'agenda)
  7803. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7804. (curspan (nth 2 args))
  7805. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7806. (cond
  7807. (tdpos (goto-char tdpos))
  7808. ((eq org-agenda-type 'agenda)
  7809. (let* ((sd (org-agenda-compute-starting-span
  7810. (org-today) (or curspan org-agenda-span)))
  7811. (org-agenda-overriding-arguments args))
  7812. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7813. (org-agenda-redo)
  7814. (org-agenda-find-same-or-today-or-agenda)))
  7815. (t (error "Cannot find today")))))
  7816. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7817. (goto-char
  7818. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7819. (text-property-any (point-min) (point-max) 'org-today t)
  7820. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7821. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7822. (org-agenda-backward-block))
  7823. (point-min))))
  7824. (defun org-agenda-backward-block ()
  7825. "Move backward by one agenda block."
  7826. (interactive)
  7827. (org-agenda-forward-block 'backward))
  7828. (defun org-agenda-forward-block (&optional backward)
  7829. "Move forward by one agenda block.
  7830. When optional argument BACKWARD is set, go backward."
  7831. (interactive)
  7832. (cond ((not (derived-mode-p 'org-agenda-mode))
  7833. (user-error
  7834. "Cannot execute this command outside of org-agenda-mode buffers"))
  7835. ((looking-at (if backward "\\`" "\\'"))
  7836. (message "Already at the %s block" (if backward "first" "last")))
  7837. (t (let ((_pos (prog1 (point)
  7838. (ignore-errors (if backward (backward-char 1)
  7839. (move-end-of-line 1)))))
  7840. (f (if backward
  7841. #'previous-single-property-change
  7842. #'next-single-property-change))
  7843. moved dest)
  7844. (while (and (setq dest (funcall
  7845. f (point) 'org-agenda-structural-header))
  7846. (not (get-text-property
  7847. (point) 'org-agenda-structural-header)))
  7848. (setq moved t)
  7849. (goto-char dest))
  7850. (if moved (move-beginning-of-line 1)
  7851. (goto-char (if backward (point-min) (point-max)))
  7852. (move-beginning-of-line 1)
  7853. (message "No %s block" (if backward "previous" "further")))))))
  7854. (defun org-agenda-later (arg)
  7855. "Go forward in time by the current span.
  7856. With prefix ARG, go forward that many times the current span."
  7857. (interactive "p")
  7858. (org-agenda-check-type t 'agenda)
  7859. (let* ((wstart (window-start))
  7860. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7861. (span (or (nth 2 args) org-agenda-current-span))
  7862. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7863. (greg (calendar-gregorian-from-absolute sd))
  7864. (cnt (org-get-at-bol 'org-day-cnt))
  7865. greg2)
  7866. (cond
  7867. ((numberp span)
  7868. (setq sd (+ (* span arg) sd)))
  7869. ((eq span 'day)
  7870. (setq sd (+ arg sd)))
  7871. ((eq span 'week)
  7872. (setq sd (+ (* 7 arg) sd)))
  7873. ((eq span 'fortnight)
  7874. (setq sd (+ (* 14 arg) sd)))
  7875. ((eq span 'month)
  7876. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7877. sd (calendar-absolute-from-gregorian greg2))
  7878. (setcar greg2 (1+ (car greg2))))
  7879. ((eq span 'year)
  7880. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7881. sd (calendar-absolute-from-gregorian greg2))
  7882. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7883. (t
  7884. (setq sd (+ (* span arg) sd))))
  7885. (let ((org-agenda-overriding-cmd
  7886. ;; `cmd' may have been set by `org-agenda-run-series' which
  7887. ;; uses `org-agenda-overriding-cmd' to decide whether
  7888. ;; overriding is allowed for `cmd'
  7889. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7890. (org-agenda-overriding-arguments
  7891. (list (car args) sd span)))
  7892. (org-agenda-redo)
  7893. (org-agenda-find-same-or-today-or-agenda cnt))
  7894. (set-window-start nil wstart)))
  7895. (defun org-agenda-earlier (arg)
  7896. "Go backward in time by the current span.
  7897. With prefix ARG, go backward that many times the current span."
  7898. (interactive "p")
  7899. (org-agenda-later (- arg)))
  7900. (defun org-agenda-view-mode-dispatch ()
  7901. "Call one of the view mode commands."
  7902. (interactive)
  7903. (org-unlogged-message
  7904. "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  7905. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7906. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7907. (pcase (read-char-exclusive)
  7908. (?\ (call-interactively 'org-agenda-reset-view))
  7909. (?d (call-interactively 'org-agenda-day-view))
  7910. (?w (call-interactively 'org-agenda-week-view))
  7911. (?t (call-interactively 'org-agenda-fortnight-view))
  7912. (?m (call-interactively 'org-agenda-month-view))
  7913. (?y (call-interactively 'org-agenda-year-view))
  7914. (?l (call-interactively 'org-agenda-log-mode))
  7915. (?L (org-agenda-log-mode '(4)))
  7916. (?c (org-agenda-log-mode 'clockcheck))
  7917. ((or ?F ?f) (call-interactively 'org-agenda-follow-mode))
  7918. (?a (call-interactively 'org-agenda-archives-mode))
  7919. (?A (org-agenda-archives-mode 'files))
  7920. ((or ?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7921. ((or ?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7922. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7923. (?D (call-interactively 'org-agenda-toggle-diary))
  7924. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7925. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7926. (org-agenda-check-type t 'agenda)
  7927. (org-agenda-redo))
  7928. (message "Display now includes inactive timestamps as well"))
  7929. (?q (message "Abort"))
  7930. (key (user-error "Invalid key: %s" key))))
  7931. (defun org-agenda-reset-view ()
  7932. "Switch to default view for agenda."
  7933. (interactive)
  7934. (org-agenda-change-time-span org-agenda-span))
  7935. (defun org-agenda-day-view (&optional day-of-month)
  7936. "Switch to daily view for agenda.
  7937. With argument DAY-OF-MONTH, switch to that day of the month."
  7938. (interactive "P")
  7939. (org-agenda-change-time-span 'day day-of-month))
  7940. (defun org-agenda-week-view (&optional iso-week)
  7941. "Switch to weekly view for agenda.
  7942. With argument ISO-WEEK, switch to the corresponding ISO week.
  7943. If ISO-WEEK has more then 2 digits, only the last two encode
  7944. the week. Any digits before this encode a year. So 200712
  7945. means week 12 of year 2007. Years ranging from 70 years ago
  7946. to 30 years in the future can also be written as 2-digit years."
  7947. (interactive "P")
  7948. (org-agenda-change-time-span 'week iso-week))
  7949. (defun org-agenda-fortnight-view (&optional iso-week)
  7950. "Switch to fortnightly view for agenda.
  7951. With argument ISO-WEEK, switch to the corresponding ISO week.
  7952. If ISO-WEEK has more then 2 digits, only the last two encode
  7953. the week. Any digits before this encode a year. So 200712
  7954. means week 12 of year 2007. Years ranging from 70 years ago
  7955. to 30 years in the future can also be written as 2-digit years."
  7956. (interactive "P")
  7957. (org-agenda-change-time-span 'fortnight iso-week))
  7958. (defun org-agenda-month-view (&optional month)
  7959. "Switch to monthly view for agenda.
  7960. With argument MONTH, switch to that month. If MONTH has more
  7961. then 2 digits, only the last two encode the month. Any digits
  7962. before this encode a year. So 200712 means December year 2007.
  7963. Years ranging from 70 years ago to 30 years in the future can
  7964. also be written as 2-digit years."
  7965. (interactive "P")
  7966. (org-agenda-change-time-span 'month month))
  7967. (defun org-agenda-year-view (&optional year)
  7968. "Switch to yearly view for agenda.
  7969. With argument YEAR, switch to that year. Years ranging from 70
  7970. years ago to 30 years in the future can also be written as
  7971. 2-digit years."
  7972. (interactive "P")
  7973. (when year
  7974. (setq year (org-small-year-to-year year)))
  7975. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7976. (org-agenda-change-time-span 'year year)
  7977. (error "Abort")))
  7978. (defun org-agenda-change-time-span (span &optional n)
  7979. "Change the agenda view to SPAN.
  7980. SPAN may be `day', `week', `fortnight', `month', `year'."
  7981. (org-agenda-check-type t 'agenda)
  7982. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7983. (curspan (nth 2 args)))
  7984. (when (and (not n) (equal curspan span))
  7985. (error "Viewing span is already \"%s\"" span))
  7986. (let* ((sd (or (org-get-at-bol 'day)
  7987. (nth 1 args)
  7988. org-starting-day))
  7989. (sd (org-agenda-compute-starting-span sd span n))
  7990. (org-agenda-overriding-cmd
  7991. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7992. (org-agenda-overriding-arguments
  7993. (list (car args) sd span)))
  7994. (org-agenda-redo)
  7995. (org-agenda-find-same-or-today-or-agenda))
  7996. (org-agenda-set-mode-name)
  7997. (message "Switched to %s view" span)))
  7998. (defun org-agenda-compute-starting-span (sd span &optional n)
  7999. "Compute starting date for agenda.
  8000. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  8001. is a cons cell with the starting date and the number of days,
  8002. so that the date SD will be in that range."
  8003. (let* ((greg (calendar-gregorian-from-absolute sd))
  8004. ;; (dg (nth 1 greg))
  8005. (mg (car greg))
  8006. (yg (nth 2 greg)))
  8007. (cond
  8008. ((eq span 'day)
  8009. (when n
  8010. (setq sd (+ (calendar-absolute-from-gregorian
  8011. (list mg 1 yg))
  8012. n -1))))
  8013. ((or (eq span 'week) (eq span 'fortnight))
  8014. (let* ((nt (calendar-day-of-week
  8015. (calendar-gregorian-from-absolute sd)))
  8016. (d (if org-agenda-start-on-weekday
  8017. (- nt org-agenda-start-on-weekday)
  8018. 0))
  8019. y1)
  8020. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  8021. (when n
  8022. (require 'cal-iso)
  8023. (when (> n 99)
  8024. (setq y1 (org-small-year-to-year (/ n 100))
  8025. n (mod n 100)))
  8026. (setq sd
  8027. (calendar-iso-to-absolute
  8028. (list n 1
  8029. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  8030. ((eq span 'month)
  8031. (let (y1)
  8032. (when (and n (> n 99))
  8033. (setq y1 (org-small-year-to-year (/ n 100))
  8034. n (mod n 100)))
  8035. (setq sd (calendar-absolute-from-gregorian
  8036. (list (or n mg) 1 (or y1 yg))))))
  8037. ((eq span 'year)
  8038. (setq sd (calendar-absolute-from-gregorian
  8039. (list 1 1 (or n yg))))))
  8040. sd))
  8041. (defun org-agenda-next-date-line (&optional arg)
  8042. "Jump to the next line indicating a date in agenda buffer."
  8043. (interactive "p")
  8044. (org-agenda-check-type t 'agenda)
  8045. (beginning-of-line 1)
  8046. ;; This does not work if user makes date format that starts with a blank
  8047. (when (looking-at-p "^\\S-") (forward-char 1))
  8048. (unless (re-search-forward "^\\S-" nil t arg)
  8049. (backward-char 1)
  8050. (error "No next date after this line in this buffer"))
  8051. (goto-char (match-beginning 0)))
  8052. (defun org-agenda-previous-date-line (&optional arg)
  8053. "Jump to the previous line indicating a date in agenda buffer."
  8054. (interactive "p")
  8055. (org-agenda-check-type t 'agenda)
  8056. (beginning-of-line 1)
  8057. (unless (re-search-backward "^\\S-" nil t arg)
  8058. (error "No previous date before this line in this buffer")))
  8059. ;; Initialize the highlight
  8060. (defvar org-hl (make-overlay 1 1))
  8061. (overlay-put org-hl 'face 'highlight)
  8062. (defun org-highlight (begin end &optional buffer)
  8063. "Highlight a region with overlay."
  8064. (move-overlay org-hl begin end (or buffer (current-buffer))))
  8065. (defun org-unhighlight ()
  8066. "Detach overlay INDEX."
  8067. (delete-overlay org-hl))
  8068. (defun org-unhighlight-once ()
  8069. "Remove the highlight from its position, and this function from the hook."
  8070. (remove-hook 'pre-command-hook #'org-unhighlight-once)
  8071. (org-unhighlight))
  8072. (defvar org-agenda-pre-follow-window-conf nil)
  8073. (defun org-agenda-follow-mode ()
  8074. "Toggle follow mode in an agenda buffer."
  8075. (interactive)
  8076. (unless org-agenda-follow-mode
  8077. (setq org-agenda-pre-follow-window-conf
  8078. (current-window-configuration)))
  8079. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  8080. (unless org-agenda-follow-mode
  8081. (set-window-configuration org-agenda-pre-follow-window-conf))
  8082. (org-agenda-set-mode-name)
  8083. (org-agenda-do-context-action)
  8084. (message "Follow mode is %s"
  8085. (if org-agenda-follow-mode "on" "off")))
  8086. (defun org-agenda-entry-text-mode (&optional arg)
  8087. "Toggle entry text mode in an agenda buffer."
  8088. (interactive "P")
  8089. (if (or org-agenda-tag-filter
  8090. org-agenda-category-filter
  8091. org-agenda-regexp-filter
  8092. org-agenda-top-headline-filter)
  8093. (user-error "Can't show entry text in filtered views")
  8094. (setq org-agenda-entry-text-mode (or (integerp arg)
  8095. (not org-agenda-entry-text-mode)))
  8096. (org-agenda-entry-text-hide)
  8097. (and org-agenda-entry-text-mode
  8098. (let ((org-agenda-entry-text-maxlines
  8099. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  8100. (org-agenda-entry-text-show)))
  8101. (org-agenda-set-mode-name)
  8102. (message "Entry text mode is %s%s"
  8103. (if org-agenda-entry-text-mode "on" "off")
  8104. (if (not org-agenda-entry-text-mode) ""
  8105. (format " (maximum number of lines is %d)"
  8106. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  8107. (defun org-agenda-clockreport-mode ()
  8108. "Toggle clocktable mode in an agenda buffer."
  8109. (interactive)
  8110. (org-agenda-check-type t 'agenda)
  8111. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  8112. (org-agenda-set-mode-name)
  8113. (org-agenda-redo)
  8114. (message "Clocktable mode is %s"
  8115. (if org-agenda-clockreport-mode "on" "off")))
  8116. (defun org-agenda-log-mode (&optional special)
  8117. "Toggle log mode in an agenda buffer.
  8118. With argument SPECIAL, show all possible log items, not only the ones
  8119. configured in `org-agenda-log-mode-items'.
  8120. With a `\\[universal-argument] \\[universal-argument]' prefix, show *only* \
  8121. log items, nothing else."
  8122. (interactive "P")
  8123. (org-agenda-check-type t 'agenda)
  8124. (setq org-agenda-show-log
  8125. (cond
  8126. ((equal special '(16)) 'only)
  8127. ((eq special 'clockcheck)
  8128. (if (eq org-agenda-show-log 'clockcheck)
  8129. nil 'clockcheck))
  8130. (special '(closed clock state))
  8131. (t (not org-agenda-show-log))))
  8132. (org-agenda-set-mode-name)
  8133. (org-agenda-redo)
  8134. (message "Log mode is %s" (if org-agenda-show-log "on" "off")))
  8135. (defun org-agenda-archives-mode (&optional with-files)
  8136. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  8137. When called with a prefix argument, include all archive files as well."
  8138. (interactive "P")
  8139. (setq org-agenda-archives-mode
  8140. (cond ((and with-files (eq org-agenda-archives-mode t)) nil)
  8141. (with-files t)
  8142. (org-agenda-archives-mode nil)
  8143. (t 'trees)))
  8144. (org-agenda-set-mode-name)
  8145. (org-agenda-redo)
  8146. (message
  8147. "%s"
  8148. (cond
  8149. ((eq org-agenda-archives-mode nil)
  8150. "No archives are included")
  8151. ((eq org-agenda-archives-mode 'trees)
  8152. (format "Trees with :%s: tag are included" org-archive-tag))
  8153. ((eq org-agenda-archives-mode t)
  8154. (format "Trees with :%s: tag and all active archive files are included"
  8155. org-archive-tag)))))
  8156. (defun org-agenda-toggle-diary ()
  8157. "Toggle diary inclusion in an agenda buffer."
  8158. (interactive)
  8159. (org-agenda-check-type t 'agenda)
  8160. (setq org-agenda-include-diary (not org-agenda-include-diary))
  8161. (org-agenda-redo)
  8162. (org-agenda-set-mode-name)
  8163. (message "Diary inclusion turned %s"
  8164. (if org-agenda-include-diary "on" "off")))
  8165. (defun org-agenda-toggle-deadlines ()
  8166. "Toggle inclusion of entries with a deadline in an agenda buffer."
  8167. (interactive)
  8168. (org-agenda-check-type t 'agenda)
  8169. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  8170. (org-agenda-redo)
  8171. (org-agenda-set-mode-name)
  8172. (message "Deadlines inclusion turned %s"
  8173. (if org-agenda-include-deadlines "on" "off")))
  8174. (defun org-agenda-toggle-time-grid ()
  8175. "Toggle time grid in an agenda buffer."
  8176. (interactive)
  8177. (org-agenda-check-type t 'agenda)
  8178. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  8179. (org-agenda-redo)
  8180. (org-agenda-set-mode-name)
  8181. (message "Time-grid turned %s"
  8182. (if org-agenda-use-time-grid "on" "off")))
  8183. (defun org-agenda-set-mode-name ()
  8184. "Set the mode name to indicate all the small mode settings."
  8185. (setq mode-name
  8186. (list "Org-Agenda"
  8187. (if (get 'org-agenda-files 'org-restrict) " []" "")
  8188. " "
  8189. '(:eval (org-agenda-span-name org-agenda-current-span))
  8190. (if org-agenda-follow-mode " Follow" "")
  8191. (if org-agenda-entry-text-mode " ETxt" "")
  8192. (if org-agenda-include-diary " Diary" "")
  8193. (if org-agenda-include-deadlines " Ddl" "")
  8194. (if org-agenda-use-time-grid " Grid" "")
  8195. (if (and (boundp 'org-habit-show-habits)
  8196. org-habit-show-habits)
  8197. " Habit" "")
  8198. (cond
  8199. ((consp org-agenda-show-log) " LogAll")
  8200. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  8201. (org-agenda-show-log " Log")
  8202. (t ""))
  8203. (if (org-agenda-filter-any) " " "")
  8204. (if (or org-agenda-category-filter
  8205. (get 'org-agenda-category-filter :preset-filter))
  8206. '(:eval (propertize
  8207. (concat "["
  8208. (mapconcat
  8209. #'identity
  8210. (append
  8211. (get 'org-agenda-category-filter :preset-filter)
  8212. org-agenda-category-filter)
  8213. "")
  8214. "]")
  8215. 'face 'org-agenda-filter-category
  8216. 'help-echo "Category used in filtering"))
  8217. "")
  8218. (if (or org-agenda-tag-filter
  8219. (get 'org-agenda-tag-filter :preset-filter))
  8220. '(:eval (propertize
  8221. (concat (mapconcat
  8222. #'identity
  8223. (append
  8224. (get 'org-agenda-tag-filter :preset-filter)
  8225. org-agenda-tag-filter)
  8226. ""))
  8227. 'face 'org-agenda-filter-tags
  8228. 'help-echo "Tags used in filtering"))
  8229. "")
  8230. (if (or org-agenda-effort-filter
  8231. (get 'org-agenda-effort-filter :preset-filter))
  8232. '(:eval (propertize
  8233. (concat (mapconcat
  8234. #'identity
  8235. (append
  8236. (get 'org-agenda-effort-filter :preset-filter)
  8237. org-agenda-effort-filter)
  8238. ""))
  8239. 'face 'org-agenda-filter-effort
  8240. 'help-echo "Effort conditions used in filtering"))
  8241. "")
  8242. (if (or org-agenda-regexp-filter
  8243. (get 'org-agenda-regexp-filter :preset-filter))
  8244. '(:eval (propertize
  8245. (concat (mapconcat
  8246. (lambda (x) (concat (substring x 0 1) "/" (substring x 1) "/"))
  8247. (append
  8248. (get 'org-agenda-regexp-filter :preset-filter)
  8249. org-agenda-regexp-filter)
  8250. ""))
  8251. 'face 'org-agenda-filter-regexp
  8252. 'help-echo "Regexp used in filtering"))
  8253. "")
  8254. (if org-agenda-archives-mode
  8255. (if (eq org-agenda-archives-mode t)
  8256. " Archives"
  8257. (format " :%s:" org-archive-tag))
  8258. "")
  8259. (if org-agenda-clockreport-mode " Clock" "")))
  8260. (force-mode-line-update))
  8261. (defun org-agenda-update-agenda-type ()
  8262. "Update the agenda type after each command."
  8263. (setq org-agenda-type
  8264. (or (get-text-property (point) 'org-agenda-type)
  8265. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  8266. (defun org-agenda-next-line ()
  8267. "Move cursor to the next line, and show if follow mode is active."
  8268. (interactive)
  8269. (call-interactively 'next-line)
  8270. (org-agenda-do-context-action))
  8271. (defun org-agenda-previous-line ()
  8272. "Move cursor to the previous line, and show if follow-mode is active."
  8273. (interactive)
  8274. (call-interactively 'previous-line)
  8275. (org-agenda-do-context-action))
  8276. (defun org-agenda-next-item (n)
  8277. "Move cursor to next agenda item."
  8278. (interactive "p")
  8279. (let ((col (current-column)))
  8280. (dotimes (_ n)
  8281. (when (next-single-property-change (point-at-eol) 'org-marker)
  8282. (move-end-of-line 1)
  8283. (goto-char (next-single-property-change (point) 'org-marker))))
  8284. (org-move-to-column col))
  8285. (org-agenda-do-context-action))
  8286. (defun org-agenda-previous-item (n)
  8287. "Move cursor to next agenda item."
  8288. (interactive "p")
  8289. (dotimes (_ n)
  8290. (let ((col (current-column))
  8291. (goto (save-excursion
  8292. (move-end-of-line 0)
  8293. (previous-single-property-change (point) 'org-marker))))
  8294. (when goto (goto-char goto))
  8295. (org-move-to-column col)))
  8296. (org-agenda-do-context-action))
  8297. (defun org-agenda-do-context-action ()
  8298. "Show outline path and, maybe, follow mode window."
  8299. (let ((m (org-get-at-bol 'org-marker)))
  8300. (when (and (markerp m) (marker-buffer m))
  8301. (and org-agenda-follow-mode
  8302. (if org-agenda-follow-indirect
  8303. (org-agenda-tree-to-indirect-buffer nil)
  8304. (org-agenda-show)))
  8305. (and org-agenda-show-outline-path
  8306. (org-with-point-at m (org-display-outline-path t))))))
  8307. (defun org-agenda-show-tags ()
  8308. "Show the tags applicable to the current item."
  8309. (interactive)
  8310. (let* ((tags (org-get-at-bol 'tags)))
  8311. (if tags
  8312. (message "Tags are :%s:"
  8313. (org-no-properties (mapconcat #'identity tags ":")))
  8314. (message "No tags associated with this line"))))
  8315. (defun org-agenda-goto (&optional highlight)
  8316. "Go to the entry at point in the corresponding Org file."
  8317. (interactive)
  8318. (let* ((marker (or (org-get-at-bol 'org-marker)
  8319. (org-agenda-error)))
  8320. (buffer (marker-buffer marker))
  8321. (pos (marker-position marker)))
  8322. ;; FIXME: use `org-switch-to-buffer-other-window'?
  8323. (switch-to-buffer-other-window buffer)
  8324. (widen)
  8325. (push-mark)
  8326. (goto-char pos)
  8327. (when (derived-mode-p 'org-mode)
  8328. (org-show-context 'agenda)
  8329. (recenter (/ (window-height) 2))
  8330. (org-back-to-heading t)
  8331. (let ((case-fold-search nil))
  8332. (when (re-search-forward org-complex-heading-regexp nil t)
  8333. (goto-char (match-beginning 4)))))
  8334. (run-hooks 'org-agenda-after-show-hook)
  8335. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  8336. (defvar org-agenda-after-show-hook nil
  8337. "Normal hook run after an item has been shown from the agenda.
  8338. Point is in the buffer where the item originated.")
  8339. ;; Defined later in org-agenda.el
  8340. (defvar org-agenda-loop-over-headlines-in-active-region nil)
  8341. (defun org-agenda-do-in-region (beg end cmd &optional arg force-arg delete)
  8342. "Between region BEG and END, call agenda command CMD.
  8343. When optional argument ARG is non-nil or FORCE-ARG is t, pass
  8344. ARG to CMD. When optional argument DELETE is non-nil, assume CMD
  8345. deletes the agenda entry and don't move to the next entry."
  8346. (save-excursion
  8347. (goto-char beg)
  8348. (let ((mend (move-marker (make-marker) end))
  8349. (all (eq org-agenda-loop-over-headlines-in-active-region t))
  8350. (match (and (stringp org-agenda-loop-over-headlines-in-active-region)
  8351. org-agenda-loop-over-headlines-in-active-region))
  8352. (level (and (eq org-agenda-loop-over-headlines-in-active-region 'start-level)
  8353. (org-get-at-bol 'level))))
  8354. (while (< (point) mend)
  8355. (let ((ov (make-overlay (point) (point-at-eol))))
  8356. (if (not (or all
  8357. (and match (looking-at-p match))
  8358. (eq level (org-get-at-bol 'level))))
  8359. (org-agenda-next-item 1)
  8360. (overlay-put ov 'face 'region)
  8361. (if (or arg force-arg) (funcall cmd arg) (funcall cmd))
  8362. (when (not delete) (org-agenda-next-item 1))
  8363. (delete-overlay ov)))))))
  8364. ;; org-agenda-[schedule,deadline,date-prompt,todo,[toggle]archive*,
  8365. ;; kill,set-property,set-effort] commands may loop over agenda
  8366. ;; entries. Commands `org-agenda-set-tags' and `org-agenda-bulk-mark'
  8367. ;; use their own mechanisms on active regions.
  8368. (defmacro org-agenda-maybe-loop (cmd arg force-arg delete &rest body)
  8369. "Maybe loop over agenda entries and perform CMD.
  8370. Pass ARG, FORCE-ARG, DELETE and BODY to `org-agenda-do-in-region'."
  8371. (declare (debug t))
  8372. `(if (and (called-interactively-p 'any)
  8373. org-agenda-loop-over-headlines-in-active-region
  8374. (org-region-active-p))
  8375. (org-agenda-do-in-region
  8376. (region-beginning) (region-end) ,cmd ,arg ,force-arg ,delete)
  8377. ,@body))
  8378. (defun org-agenda-kill ()
  8379. "Kill the entry or subtree belonging to the current agenda entry."
  8380. (interactive)
  8381. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8382. (org-agenda-maybe-loop
  8383. #'org-agenda-kill nil nil t
  8384. (let* ((bufname-orig (buffer-name))
  8385. (marker (or (org-get-at-bol 'org-marker)
  8386. (org-agenda-error)))
  8387. (buffer (marker-buffer marker))
  8388. (pos (marker-position marker))
  8389. (type (org-get-at-bol 'type))
  8390. dbeg dend (n 0))
  8391. (org-with-remote-undo buffer
  8392. (with-current-buffer buffer
  8393. (save-excursion
  8394. (goto-char pos)
  8395. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  8396. (setq dbeg (progn (org-back-to-heading t) (point))
  8397. dend (org-end-of-subtree t t))
  8398. (setq dbeg (point-at-bol)
  8399. dend (min (point-max) (1+ (point-at-eol)))))
  8400. (goto-char dbeg)
  8401. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  8402. (when (or (eq t org-agenda-confirm-kill)
  8403. (and (numberp org-agenda-confirm-kill)
  8404. (> n org-agenda-confirm-kill)))
  8405. (let ((win-conf (current-window-configuration)))
  8406. (unwind-protect
  8407. (and
  8408. (prog2
  8409. (org-agenda-tree-to-indirect-buffer nil)
  8410. (not (y-or-n-p
  8411. (format "Delete entry with %d lines in buffer \"%s\"? "
  8412. n (buffer-name buffer))))
  8413. (kill-buffer org-last-indirect-buffer))
  8414. (error "Abort"))
  8415. (set-window-configuration win-conf))))
  8416. (let ((org-agenda-buffer-name bufname-orig))
  8417. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  8418. (with-current-buffer buffer (delete-region dbeg dend))
  8419. (message "Agenda item and source killed")))))
  8420. (defvar org-archive-default-command) ; defined in org-archive.el
  8421. (defun org-agenda-archive-default ()
  8422. "Archive the entry or subtree belonging to the current agenda entry."
  8423. (interactive)
  8424. (require 'org-archive)
  8425. (funcall-interactively
  8426. #'org-agenda-archive-with org-archive-default-command))
  8427. (defun org-agenda-archive-default-with-confirmation ()
  8428. "Archive the entry or subtree belonging to the current agenda entry."
  8429. (interactive)
  8430. (require 'org-archive)
  8431. (funcall-interactively
  8432. #'org-agenda-archive-with org-archive-default-command 'confirm))
  8433. (defun org-agenda-archive ()
  8434. "Archive the entry or subtree belonging to the current agenda entry."
  8435. (interactive)
  8436. (funcall-interactively
  8437. #'org-agenda-archive-with 'org-archive-subtree))
  8438. (defun org-agenda-archive-to-archive-sibling ()
  8439. "Move the entry to the archive sibling."
  8440. (interactive)
  8441. (funcall-interactively
  8442. #'org-agenda-archive-with 'org-archive-to-archive-sibling))
  8443. (defvar org-archive-from-agenda)
  8444. (defun org-agenda-archive-with (cmd &optional confirm)
  8445. "Move the entry to the archive sibling."
  8446. (interactive)
  8447. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8448. (org-agenda-maybe-loop
  8449. #'org-agenda-archive-with cmd nil t
  8450. (let* ((bufname-orig (buffer-name))
  8451. (marker (or (org-get-at-bol 'org-marker)
  8452. (org-agenda-error)))
  8453. (buffer (marker-buffer marker))
  8454. (pos (marker-position marker)))
  8455. (org-with-remote-undo buffer
  8456. (with-current-buffer buffer
  8457. (if (derived-mode-p 'org-mode)
  8458. (if (and confirm
  8459. (not (y-or-n-p "Archive this subtree or entry? ")))
  8460. (error "Abort")
  8461. (save-window-excursion
  8462. (goto-char pos)
  8463. (let ((org-agenda-buffer-name bufname-orig))
  8464. (org-remove-subtree-entries-from-agenda))
  8465. (org-back-to-heading t)
  8466. (let ((org-archive-from-agenda t))
  8467. (funcall cmd))))
  8468. (error "Archiving works only in Org files")))))))
  8469. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  8470. "Remove all lines in the agenda that correspond to a given subtree.
  8471. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  8472. If this information is not given, the function uses the tree at point."
  8473. (let ((buf (or buf (current-buffer))) m p)
  8474. (save-excursion
  8475. (unless (and beg end)
  8476. (org-back-to-heading t)
  8477. (setq beg (point))
  8478. (org-end-of-subtree t)
  8479. (setq end (point)))
  8480. (set-buffer (get-buffer org-agenda-buffer-name))
  8481. (save-excursion
  8482. (goto-char (point-max))
  8483. (beginning-of-line 1)
  8484. (while (not (bobp))
  8485. (when (and (setq m (org-get-at-bol 'org-marker))
  8486. (equal buf (marker-buffer m))
  8487. (setq p (marker-position m))
  8488. (>= p beg)
  8489. (< p end))
  8490. (let ((inhibit-read-only t))
  8491. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  8492. (beginning-of-line 0))))))
  8493. (defun org-agenda-refile (&optional goto rfloc no-update)
  8494. "Refile the item at point.
  8495. When called with `\\[universal-argument] \\[universal-argument]', \
  8496. go to the location of the last
  8497. refiled item.
  8498. When called with `\\[universal-argument] \\[universal-argument] \
  8499. \\[universal-argument]' prefix or when GOTO is 0, clear
  8500. the refile cache.
  8501. RFLOC can be a refile location obtained in a different way.
  8502. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  8503. (interactive "P")
  8504. (cond
  8505. ((member goto '(0 (64)))
  8506. (org-refile-cache-clear))
  8507. ((equal goto '(16))
  8508. (org-refile-goto-last-stored))
  8509. (t
  8510. (let* ((buffer-orig (buffer-name))
  8511. (marker (or (org-get-at-bol 'org-hd-marker)
  8512. (org-agenda-error)))
  8513. (buffer (marker-buffer marker))
  8514. ;; (pos (marker-position marker))
  8515. (rfloc (or rfloc
  8516. (org-refile-get-location
  8517. (if goto "Goto" "Refile to") buffer
  8518. org-refile-allow-creating-parent-nodes))))
  8519. (with-current-buffer buffer
  8520. (org-with-wide-buffer
  8521. (goto-char marker)
  8522. (let ((org-agenda-buffer-name buffer-orig))
  8523. (org-remove-subtree-entries-from-agenda))
  8524. (org-refile goto buffer rfloc))))
  8525. (unless no-update (org-agenda-redo)))))
  8526. (defun org-agenda-open-link (&optional arg)
  8527. "Open the link(s) in the current entry, if any.
  8528. This looks for a link in the displayed line in the agenda.
  8529. It also looks at the text of the entry itself."
  8530. (interactive "P")
  8531. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  8532. (org-get-at-bol 'org-marker)))
  8533. (buffer (and marker (marker-buffer marker)))
  8534. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  8535. (lkall (and buffer (org-offer-links-in-entry
  8536. buffer marker arg prefix)))
  8537. (lk0 (car lkall))
  8538. (lk (if (stringp lk0) (list lk0) lk0))
  8539. (lkend (cdr lkall))
  8540. trg)
  8541. (cond
  8542. ((and buffer lk)
  8543. (mapcar (lambda(l)
  8544. (with-current-buffer buffer
  8545. (setq trg (and (string-match org-link-bracket-re l)
  8546. (match-string 1 l)))
  8547. (if (or (not trg) (string-match org-link-any-re trg))
  8548. ;; Don't use `org-with-wide-buffer' here as
  8549. ;; opening the link may result in moving the point
  8550. (save-restriction
  8551. (widen)
  8552. (goto-char marker)
  8553. (when (search-forward l nil lkend)
  8554. (goto-char (match-beginning 0))
  8555. (org-open-at-point)))
  8556. ;; This is an internal link, widen the buffer
  8557. ;; FIXME: use `org-switch-to-buffer-other-window'?
  8558. (switch-to-buffer-other-window buffer)
  8559. (widen)
  8560. (goto-char marker)
  8561. (when (search-forward l nil lkend)
  8562. (goto-char (match-beginning 0))
  8563. (org-open-at-point)))))
  8564. lk))
  8565. ((or (org-in-regexp (concat "\\(" org-link-bracket-re "\\)"))
  8566. (save-excursion
  8567. (beginning-of-line 1)
  8568. (looking-at (concat ".*?\\(" org-link-bracket-re "\\)"))))
  8569. (org-link-open-from-string (match-string 1)))
  8570. (t (message "No link to open here")))))
  8571. (defun org-agenda-copy-local-variable (var)
  8572. "Get a variable from a referenced buffer and install it here."
  8573. (let ((m (org-get-at-bol 'org-marker)))
  8574. (when (and m (buffer-live-p (marker-buffer m)))
  8575. (set (make-local-variable var)
  8576. (with-current-buffer (marker-buffer m)
  8577. (symbol-value var))))))
  8578. (defun org-agenda-switch-to (&optional delete-other-windows)
  8579. "Go to the Org mode file which contains the item at point.
  8580. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  8581. displayed Org file fills the frame."
  8582. (interactive)
  8583. (if (and org-return-follows-link
  8584. (not (org-get-at-bol 'org-marker))
  8585. (org-in-regexp org-link-bracket-re))
  8586. (org-link-open-from-string (match-string 0))
  8587. (let* ((marker (or (org-get-at-bol 'org-marker)
  8588. (org-agenda-error)))
  8589. (buffer (marker-buffer marker))
  8590. (pos (marker-position marker)))
  8591. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  8592. (pop-to-buffer-same-window buffer)
  8593. (when delete-other-windows (delete-other-windows))
  8594. (widen)
  8595. (goto-char pos)
  8596. (when (derived-mode-p 'org-mode)
  8597. (org-show-context 'agenda)
  8598. (run-hooks 'org-agenda-after-show-hook)))))
  8599. (defun org-agenda-goto-mouse (ev)
  8600. "Go to the Org file which contains the item at the mouse click."
  8601. (interactive "e")
  8602. (mouse-set-point ev)
  8603. (org-agenda-goto))
  8604. (defun org-agenda-show (&optional full-entry)
  8605. "Display the Org file which contains the item at point.
  8606. With prefix argument FULL-ENTRY, make the entire entry visible
  8607. if it was hidden in the outline."
  8608. (interactive "P")
  8609. (let ((win (selected-window)))
  8610. (org-agenda-goto t)
  8611. (when full-entry (org-show-entry))
  8612. (select-window win)))
  8613. (defvar org-agenda-show-window nil)
  8614. (defun org-agenda-show-and-scroll-up (&optional arg)
  8615. "Display the Org file which contains the item at point.
  8616. When called repeatedly, scroll the window that is displaying the buffer.
  8617. With a `\\[universal-argument]' prefix argument, display the item, but \
  8618. fold drawers."
  8619. (interactive "P")
  8620. (let ((win (selected-window)))
  8621. (if (and (window-live-p org-agenda-show-window)
  8622. (eq this-command last-command))
  8623. (progn
  8624. (select-window org-agenda-show-window)
  8625. (ignore-errors (scroll-up)))
  8626. (org-agenda-goto t)
  8627. (org-show-entry)
  8628. (if arg (org-cycle-hide-drawers 'children)
  8629. (org-with-wide-buffer
  8630. (narrow-to-region (org-entry-beginning-position)
  8631. (org-entry-end-position))
  8632. (org-show-all '(drawers))))
  8633. (setq org-agenda-show-window (selected-window)))
  8634. (select-window win)))
  8635. (defun org-agenda-show-scroll-down ()
  8636. "Scroll down the window showing the agenda."
  8637. (interactive)
  8638. (let ((win (selected-window)))
  8639. (when (window-live-p org-agenda-show-window)
  8640. (select-window org-agenda-show-window)
  8641. (ignore-errors (scroll-down))
  8642. (select-window win))))
  8643. (defun org-agenda-show-1 (&optional more)
  8644. "Display the Org file which contains the item at point.
  8645. The prefix arg selects the amount of information to display:
  8646. 0 hide the subtree
  8647. 1 just show the entry according to defaults.
  8648. 2 show the children view
  8649. 3 show the subtree view
  8650. 4 show the entire subtree and any drawers
  8651. With prefix argument FULL-ENTRY, make the entire entry visible
  8652. if it was hidden in the outline."
  8653. (interactive "p")
  8654. (let ((win (selected-window)))
  8655. (org-agenda-goto t)
  8656. (org-back-to-heading)
  8657. (set-window-start (selected-window) (point-at-bol))
  8658. (cond
  8659. ((= more 0)
  8660. (org-flag-subtree t)
  8661. (save-excursion
  8662. (org-back-to-heading)
  8663. (run-hook-with-args 'org-cycle-hook 'folded))
  8664. (message "Remote: FOLDED"))
  8665. ((and (called-interactively-p 'any) (= more 1))
  8666. (message "Remote: show with default settings"))
  8667. ((= more 2)
  8668. (outline-show-entry)
  8669. (org-show-children)
  8670. (save-excursion
  8671. (org-back-to-heading)
  8672. (run-hook-with-args 'org-cycle-hook 'children))
  8673. (message "Remote: CHILDREN"))
  8674. ((= more 3)
  8675. (outline-show-subtree)
  8676. (save-excursion
  8677. (org-back-to-heading)
  8678. (run-hook-with-args 'org-cycle-hook 'subtree))
  8679. (message "Remote: SUBTREE"))
  8680. ((> more 3)
  8681. (outline-show-subtree)
  8682. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8683. (select-window win)))
  8684. (defvar org-agenda-cycle-counter nil)
  8685. (defun org-agenda-cycle-show (&optional n)
  8686. "Show the current entry in another window, with default settings.
  8687. Default settings are taken from `org-show-context-detail'. When
  8688. use repeatedly in immediate succession, the remote entry will
  8689. cycle through visibility
  8690. children -> subtree -> folded
  8691. When called with a numeric prefix arg, that arg will be passed through to
  8692. `org-agenda-show-1'. For the interpretation of that argument, see the
  8693. docstring of `org-agenda-show-1'."
  8694. (interactive "P")
  8695. (if (integerp n)
  8696. (setq org-agenda-cycle-counter n)
  8697. (if (not (eq last-command this-command))
  8698. (setq org-agenda-cycle-counter 1)
  8699. (if (equal org-agenda-cycle-counter 0)
  8700. (setq org-agenda-cycle-counter 2)
  8701. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8702. (when (> org-agenda-cycle-counter 3)
  8703. (setq org-agenda-cycle-counter 0)))))
  8704. (org-agenda-show-1 org-agenda-cycle-counter))
  8705. (defun org-agenda-recenter (arg)
  8706. "Display the Org file which contains the item at point and recenter."
  8707. (interactive "P")
  8708. (let ((win (selected-window)))
  8709. (org-agenda-goto t)
  8710. (recenter arg)
  8711. (select-window win)))
  8712. (defun org-agenda-show-mouse (ev)
  8713. "Display the Org file which contains the item at the mouse click."
  8714. (interactive "e")
  8715. (mouse-set-point ev)
  8716. (org-agenda-show))
  8717. (defun org-agenda-check-no-diary ()
  8718. "Check if the entry is a diary link and abort if yes."
  8719. (when (org-get-at-bol 'org-agenda-diary-link)
  8720. (org-agenda-error)))
  8721. (defun org-agenda-error ()
  8722. "Throw an error when a command is not allowed in the agenda."
  8723. (user-error "Command not allowed in this line"))
  8724. (defun org-agenda-tree-to-indirect-buffer (arg)
  8725. "Show the subtree corresponding to the current entry in an indirect buffer.
  8726. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  8727. With a numerical prefix ARG, go up to this level and then take that tree.
  8728. With a negative numeric ARG, go up by this number of levels.
  8729. With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
  8730. i.e. don't use
  8731. the dedicated frame."
  8732. (interactive "P")
  8733. (if current-prefix-arg
  8734. (org-agenda-do-tree-to-indirect-buffer arg)
  8735. (let ((agenda-buffer (buffer-name))
  8736. (agenda-window (selected-window))
  8737. (indirect-window
  8738. (and org-last-indirect-buffer
  8739. (get-buffer-window org-last-indirect-buffer))))
  8740. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  8741. (unless (or (eq org-indirect-buffer-display 'new-frame)
  8742. (eq org-indirect-buffer-display 'dedicated-frame))
  8743. (unwind-protect
  8744. (unless (and indirect-window (window-live-p indirect-window))
  8745. (setq indirect-window (split-window agenda-window)))
  8746. (and indirect-window (select-window indirect-window))
  8747. (switch-to-buffer org-last-indirect-buffer :norecord)
  8748. (fit-window-to-buffer indirect-window)))
  8749. (select-window (get-buffer-window agenda-buffer))
  8750. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  8751. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  8752. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  8753. (org-agenda-check-no-diary)
  8754. (let* ((marker (or (org-get-at-bol 'org-marker)
  8755. (org-agenda-error)))
  8756. (buffer (marker-buffer marker))
  8757. (pos (marker-position marker)))
  8758. (with-current-buffer buffer
  8759. (save-excursion
  8760. (goto-char pos)
  8761. (org-tree-to-indirect-buffer arg)))))
  8762. (defvar org-last-heading-marker (make-marker)
  8763. "Marker pointing to the headline that last changed its TODO state
  8764. by a remote command from the agenda.")
  8765. (defun org-agenda-todo-nextset ()
  8766. "Switch TODO entry to next sequence."
  8767. (interactive)
  8768. (org-agenda-todo 'nextset))
  8769. (defun org-agenda-todo-previousset ()
  8770. "Switch TODO entry to previous sequence."
  8771. (interactive)
  8772. (org-agenda-todo 'previousset))
  8773. (defvar org-agenda-headline-snapshot-before-repeat)
  8774. (defun org-agenda-todo (&optional arg)
  8775. "Cycle TODO state of line at point, also in Org file.
  8776. This changes the line at point, all other lines in the agenda referring to
  8777. the same tree node, and the headline of the tree node in the Org file."
  8778. (interactive "P")
  8779. (org-agenda-check-no-diary)
  8780. (org-agenda-maybe-loop
  8781. #'org-agenda-todo arg nil nil
  8782. (let* ((col (current-column))
  8783. (marker (or (org-get-at-bol 'org-marker)
  8784. (org-agenda-error)))
  8785. (buffer (marker-buffer marker))
  8786. (pos (marker-position marker))
  8787. (hdmarker (org-get-at-bol 'org-hd-marker))
  8788. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  8789. (inhibit-read-only t)
  8790. org-loop-over-headlines-in-active-region
  8791. org-agenda-headline-snapshot-before-repeat newhead just-one)
  8792. (org-with-remote-undo buffer
  8793. (with-current-buffer buffer
  8794. (widen)
  8795. (goto-char pos)
  8796. (org-show-context 'agenda)
  8797. (let ((current-prefix-arg arg))
  8798. (call-interactively 'org-todo)
  8799. ;; Make sure that log is recorded in current undo.
  8800. (when (and org-log-setup
  8801. (not (eq org-log-note-how 'note)))
  8802. (org-add-log-note)))
  8803. (and (bolp) (forward-char 1))
  8804. (setq newhead (org-get-heading))
  8805. (when (and org-agenda-headline-snapshot-before-repeat
  8806. (not (equal org-agenda-headline-snapshot-before-repeat
  8807. newhead))
  8808. todayp)
  8809. (setq newhead org-agenda-headline-snapshot-before-repeat
  8810. just-one t))
  8811. (save-excursion
  8812. (org-back-to-heading)
  8813. (move-marker org-last-heading-marker (point))))
  8814. (beginning-of-line 1)
  8815. (save-window-excursion
  8816. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8817. (when (bound-and-true-p org-clock-out-when-done)
  8818. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  8819. newhead)
  8820. (org-agenda-unmark-clocking-task))
  8821. (org-move-to-column col)
  8822. (org-agenda-mark-clocking-task)))))
  8823. (defun org-agenda-add-note (&optional _arg)
  8824. "Add a time-stamped note to the entry at point."
  8825. (interactive) ;; "P"
  8826. (org-agenda-check-no-diary)
  8827. (let* ((marker (or (org-get-at-bol 'org-marker)
  8828. (org-agenda-error)))
  8829. (buffer (marker-buffer marker))
  8830. (pos (marker-position marker))
  8831. (_hdmarker (org-get-at-bol 'org-hd-marker))
  8832. (inhibit-read-only t))
  8833. (with-current-buffer buffer
  8834. (widen)
  8835. (goto-char pos)
  8836. (org-show-context 'agenda)
  8837. (org-add-note))))
  8838. (defun org-agenda-change-all-lines (newhead hdmarker
  8839. &optional fixface just-this)
  8840. "Change all lines in the agenda buffer which match HDMARKER.
  8841. The new content of the line will be NEWHEAD (as modified by
  8842. `org-agenda-format-item'). HDMARKER is checked with
  8843. `equal' against all `org-hd-marker' text properties in the file.
  8844. If FIXFACE is non-nil, the face of each item is modified according to
  8845. the new TODO state.
  8846. If JUST-THIS is non-nil, change just the current line, not all.
  8847. If FORCE-TAGS is non-nil, the car of it returns the new tags."
  8848. (let* ((inhibit-read-only t)
  8849. (line (org-current-line))
  8850. (org-agenda-buffer (current-buffer))
  8851. (thetags (with-current-buffer (marker-buffer hdmarker)
  8852. (org-get-tags hdmarker)))
  8853. props m undone-face done-face finish new dotime level cat tags) ;; pl
  8854. (save-excursion
  8855. (goto-char (point-max))
  8856. (beginning-of-line 1)
  8857. (while (not finish)
  8858. (setq finish (bobp))
  8859. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8860. (or (not just-this) (= (org-current-line) line))
  8861. (equal m hdmarker))
  8862. (setq props (text-properties-at (point))
  8863. dotime (org-get-at-bol 'dotime)
  8864. cat (org-agenda-get-category)
  8865. level (org-get-at-bol 'level)
  8866. tags thetags
  8867. new
  8868. (let ((org-prefix-format-compiled
  8869. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8870. org-prefix-format-compiled))
  8871. (extra (org-get-at-bol 'extra)))
  8872. (with-current-buffer (marker-buffer hdmarker)
  8873. (org-with-wide-buffer
  8874. (org-agenda-format-item extra newhead level cat tags dotime))))
  8875. ;; pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  8876. undone-face (org-get-at-bol 'undone-face)
  8877. done-face (org-get-at-bol 'done-face))
  8878. (beginning-of-line 1)
  8879. (cond
  8880. ((equal new "") (delete-region (point) (line-beginning-position 2)))
  8881. ((looking-at ".*")
  8882. ;; When replacing the whole line, preserve bulk mark
  8883. ;; overlay, if any.
  8884. (let ((mark (catch :overlay
  8885. (dolist (o (overlays-in (point) (+ 2 (point))))
  8886. (when (eq (overlay-get o 'type)
  8887. 'org-marked-entry-overlay)
  8888. (throw :overlay o))))))
  8889. (replace-match new t t)
  8890. (beginning-of-line)
  8891. (when mark (move-overlay mark (point) (+ 2 (point)))))
  8892. (add-text-properties (point-at-bol) (point-at-eol) props)
  8893. (when fixface
  8894. (add-text-properties
  8895. (point-at-bol) (point-at-eol)
  8896. (list 'face
  8897. (if org-last-todo-state-is-todo
  8898. undone-face done-face))))
  8899. (org-agenda-highlight-todo 'line)
  8900. (beginning-of-line 1))
  8901. (t (error "Line update did not work")))
  8902. (save-restriction
  8903. (narrow-to-region (point-at-bol) (point-at-eol))
  8904. (org-agenda-finalize)))
  8905. (beginning-of-line 0)))))
  8906. (defun org-agenda-align-tags (&optional line)
  8907. "Align all tags in agenda items to `org-agenda-tags-column'.
  8908. When optional argument LINE is non-nil, align tags only on the
  8909. current line."
  8910. (let ((inhibit-read-only t)
  8911. (org-agenda-tags-column (if (eq 'auto org-agenda-tags-column)
  8912. (- (window-text-width))
  8913. org-agenda-tags-column))
  8914. (end (and line (line-end-position)))
  8915. l c)
  8916. (save-excursion
  8917. (goto-char (if line (line-beginning-position) (point-min)))
  8918. (while (re-search-forward org-tag-group-re end t)
  8919. (add-text-properties
  8920. (match-beginning 1) (match-end 1)
  8921. (list 'face (delq nil (let ((prop (get-text-property
  8922. (match-beginning 1) 'face)))
  8923. (or (listp prop) (setq prop (list prop)))
  8924. (if (memq 'org-tag prop)
  8925. prop
  8926. (cons 'org-tag prop))))))
  8927. (setq l (string-width (match-string 1))
  8928. c (if (< org-agenda-tags-column 0)
  8929. (- (abs org-agenda-tags-column) l)
  8930. org-agenda-tags-column))
  8931. (goto-char (match-beginning 1))
  8932. (delete-region (save-excursion (skip-chars-backward " \t") (point))
  8933. (point))
  8934. (insert (org-add-props
  8935. (make-string (max 1 (- c (current-column))) ?\s)
  8936. (plist-put (copy-sequence (text-properties-at (point)))
  8937. 'face nil))))
  8938. (goto-char (point-min))
  8939. (org-font-lock-add-tag-faces (point-max)))))
  8940. (defun org-agenda-priority-up ()
  8941. "Increase the priority of line at point, also in Org file."
  8942. (interactive)
  8943. (org-agenda-priority 'up))
  8944. (defun org-agenda-priority-down ()
  8945. "Decrease the priority of line at point, also in Org file."
  8946. (interactive)
  8947. (org-agenda-priority 'down))
  8948. (defun org-agenda-priority (&optional force-direction)
  8949. "Set the priority of line at point, also in Org file.
  8950. This changes the line at point, all other lines in the agenda
  8951. referring to the same tree node, and the headline of the tree
  8952. node in the Org file.
  8953. Called with one universal prefix arg, show the priority instead
  8954. of setting it.
  8955. When called programmatically, FORCE-DIRECTION can be `set', `up',
  8956. `down', or a character."
  8957. (interactive "P")
  8958. (unless org-priority-enable-commands
  8959. (user-error "Priority commands are disabled"))
  8960. (org-agenda-check-no-diary)
  8961. (let* ((col (current-column))
  8962. (hdmarker (org-get-at-bol 'org-hd-marker))
  8963. (buffer (marker-buffer hdmarker))
  8964. (pos (marker-position hdmarker))
  8965. (inhibit-read-only t)
  8966. newhead)
  8967. (org-with-remote-undo buffer
  8968. (with-current-buffer buffer
  8969. (widen)
  8970. (goto-char pos)
  8971. (org-show-context 'agenda)
  8972. (org-priority force-direction)
  8973. (end-of-line 1)
  8974. (setq newhead (org-get-heading)))
  8975. (org-agenda-change-all-lines newhead hdmarker)
  8976. (org-move-to-column col))))
  8977. ;; FIXME: should fix the tags property of the agenda line.
  8978. (defun org-agenda-set-tags (&optional tag onoff)
  8979. "Set tags for the current headline."
  8980. (interactive)
  8981. (org-agenda-check-no-diary)
  8982. (if (and (org-region-active-p) (called-interactively-p 'any))
  8983. (call-interactively 'org-change-tag-in-region)
  8984. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8985. (org-agenda-error)))
  8986. (buffer (marker-buffer hdmarker))
  8987. (pos (marker-position hdmarker))
  8988. (inhibit-read-only t)
  8989. newhead)
  8990. (org-with-remote-undo buffer
  8991. (with-current-buffer buffer
  8992. (widen)
  8993. (goto-char pos)
  8994. (org-show-context 'agenda)
  8995. (if tag
  8996. (org-toggle-tag tag onoff)
  8997. (call-interactively #'org-set-tags-command))
  8998. (end-of-line 1)
  8999. (setq newhead (org-get-heading)))
  9000. (org-agenda-change-all-lines newhead hdmarker)
  9001. (beginning-of-line 1)))))
  9002. (defun org-agenda-set-property ()
  9003. "Set a property for the current headline."
  9004. (interactive)
  9005. (org-agenda-check-no-diary)
  9006. (org-agenda-maybe-loop
  9007. #'org-agenda-set-property nil nil nil
  9008. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9009. (org-agenda-error)))
  9010. (buffer (marker-buffer hdmarker))
  9011. (pos (marker-position hdmarker))
  9012. (inhibit-read-only t)
  9013. ) ;; newhead
  9014. (org-with-remote-undo buffer
  9015. (with-current-buffer buffer
  9016. (widen)
  9017. (goto-char pos)
  9018. (org-show-context 'agenda)
  9019. (call-interactively 'org-set-property))))))
  9020. (defun org-agenda-set-effort ()
  9021. "Set the effort property for the current headline."
  9022. (interactive)
  9023. (org-agenda-check-no-diary)
  9024. (org-agenda-maybe-loop
  9025. #'org-agenda-set-effort nil nil nil
  9026. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9027. (org-agenda-error)))
  9028. (buffer (marker-buffer hdmarker))
  9029. (pos (marker-position hdmarker))
  9030. (inhibit-read-only t)
  9031. newhead)
  9032. (org-with-remote-undo buffer
  9033. (with-current-buffer buffer
  9034. (widen)
  9035. (goto-char pos)
  9036. (org-show-context 'agenda)
  9037. (call-interactively 'org-set-effort)
  9038. (end-of-line 1)
  9039. (setq newhead (org-get-heading)))
  9040. (org-agenda-change-all-lines newhead hdmarker)))))
  9041. (defun org-agenda-toggle-archive-tag ()
  9042. "Toggle the archive tag for the current entry."
  9043. (interactive)
  9044. (org-agenda-check-no-diary)
  9045. (org-agenda-maybe-loop
  9046. #'org-agenda-toggle-archive-tag nil nil nil
  9047. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9048. (org-agenda-error)))
  9049. (buffer (marker-buffer hdmarker))
  9050. (pos (marker-position hdmarker))
  9051. (inhibit-read-only t)
  9052. newhead)
  9053. (org-with-remote-undo buffer
  9054. (with-current-buffer buffer
  9055. (widen)
  9056. (goto-char pos)
  9057. (org-show-context 'agenda)
  9058. (call-interactively 'org-toggle-archive-tag)
  9059. (end-of-line 1)
  9060. (setq newhead (org-get-heading)))
  9061. (org-agenda-change-all-lines newhead hdmarker)
  9062. (beginning-of-line 1)))))
  9063. (defun org-agenda-do-date-later (arg)
  9064. (interactive "P")
  9065. (cond
  9066. ((or (equal arg '(16))
  9067. (memq last-command
  9068. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9069. (setq this-command 'org-agenda-date-later-minutes)
  9070. (org-agenda-date-later-minutes 1))
  9071. ((or (equal arg '(4))
  9072. (memq last-command
  9073. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9074. (setq this-command 'org-agenda-date-later-hours)
  9075. (org-agenda-date-later-hours 1))
  9076. (t
  9077. (org-agenda-date-later (prefix-numeric-value arg)))))
  9078. (defun org-agenda-do-date-earlier (arg)
  9079. (interactive "P")
  9080. (cond
  9081. ((or (equal arg '(16))
  9082. (memq last-command
  9083. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9084. (setq this-command 'org-agenda-date-earlier-minutes)
  9085. (org-agenda-date-earlier-minutes 1))
  9086. ((or (equal arg '(4))
  9087. (memq last-command
  9088. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9089. (setq this-command 'org-agenda-date-earlier-hours)
  9090. (org-agenda-date-earlier-hours 1))
  9091. (t
  9092. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  9093. (defun org-agenda-date-later (arg &optional what)
  9094. "Change the date of this item to ARG day(s) later."
  9095. (interactive "p")
  9096. (org-agenda-check-type t 'agenda)
  9097. (org-agenda-check-no-diary)
  9098. (let* ((marker (or (org-get-at-bol 'org-marker)
  9099. (org-agenda-error)))
  9100. (buffer (marker-buffer marker))
  9101. (pos (marker-position marker))
  9102. cdate today)
  9103. (org-with-remote-undo buffer
  9104. (with-current-buffer buffer
  9105. (widen)
  9106. (goto-char pos)
  9107. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9108. (when (and org-agenda-move-date-from-past-immediately-to-today
  9109. (equal arg 1)
  9110. (or (not what) (eq what 'day))
  9111. (not (save-match-data (org-at-date-range-p))))
  9112. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  9113. cdate (calendar-absolute-from-gregorian
  9114. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  9115. today (org-today))
  9116. (when (> today cdate)
  9117. ;; immediately shift to today
  9118. (setq arg (- today cdate))))
  9119. (org-timestamp-change arg (or what 'day))
  9120. (when (and (org-at-date-range-p)
  9121. (re-search-backward org-tr-regexp-both (point-at-bol)))
  9122. (let ((end org-last-changed-timestamp))
  9123. (org-timestamp-change arg (or what 'day))
  9124. (setq org-last-changed-timestamp
  9125. (concat org-last-changed-timestamp "--" end)))))
  9126. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9127. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  9128. (defun org-agenda-date-earlier (arg &optional what)
  9129. "Change the date of this item to ARG day(s) earlier."
  9130. (interactive "p")
  9131. (org-agenda-date-later (- arg) what))
  9132. (defun org-agenda-date-later-minutes (arg)
  9133. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9134. (interactive "p")
  9135. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9136. (org-agenda-date-later arg 'minute))
  9137. (defun org-agenda-date-earlier-minutes (arg)
  9138. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9139. (interactive "p")
  9140. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9141. (org-agenda-date-earlier arg 'minute))
  9142. (defun org-agenda-date-later-hours (arg)
  9143. "Change the time of this item, in hour steps."
  9144. (interactive "p")
  9145. (org-agenda-date-later arg 'hour))
  9146. (defun org-agenda-date-earlier-hours (arg)
  9147. "Change the time of this item, in hour steps."
  9148. (interactive "p")
  9149. (org-agenda-date-earlier arg 'hour))
  9150. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  9151. "Show new date stamp via text properties."
  9152. ;; We use text properties to make this undoable
  9153. (let ((inhibit-read-only t))
  9154. (setq stamp (concat prefix " => " stamp " "))
  9155. (save-excursion
  9156. (goto-char (point-max))
  9157. (while (not (bobp))
  9158. (when (equal marker (org-get-at-bol 'org-marker))
  9159. (remove-text-properties (line-beginning-position)
  9160. (line-end-position)
  9161. '(display nil))
  9162. (org-move-to-column
  9163. (- (if (fboundp 'window-font-width)
  9164. (/ (window-width nil t) (window-font-width))
  9165. ;; Fall back to pre-9.3.3 behavior on Emacs <25.
  9166. (window-width))
  9167. (length stamp))
  9168. t)
  9169. (add-text-properties
  9170. (1- (point)) (point-at-eol)
  9171. (list 'display (org-add-props stamp nil
  9172. 'face '(secondary-selection default))))
  9173. (beginning-of-line 1))
  9174. (beginning-of-line 0)))))
  9175. (defun org-agenda-date-prompt (arg)
  9176. "Change the date of this item. Date is prompted for, with default today.
  9177. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  9178. be used to request time specification in the time stamp."
  9179. (interactive "P")
  9180. (org-agenda-check-type t 'agenda)
  9181. (org-agenda-check-no-diary)
  9182. (org-agenda-maybe-loop
  9183. #'org-agenda-date-prompt arg t nil
  9184. (let* ((marker (or (org-get-at-bol 'org-marker)
  9185. (org-agenda-error)))
  9186. (buffer (marker-buffer marker))
  9187. (pos (marker-position marker)))
  9188. (org-with-remote-undo buffer
  9189. (with-current-buffer buffer
  9190. (widen)
  9191. (goto-char pos)
  9192. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9193. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  9194. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9195. (message "Time stamp changed to %s" org-last-changed-timestamp))))
  9196. (defun org-agenda-schedule (arg &optional time)
  9197. "Schedule the item at point.
  9198. ARG is passed through to `org-schedule'."
  9199. (interactive "P")
  9200. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9201. (org-agenda-check-no-diary)
  9202. (org-agenda-maybe-loop
  9203. #'org-agenda-schedule arg t nil
  9204. (let* ((marker (or (org-get-at-bol 'org-marker)
  9205. (org-agenda-error)))
  9206. ;; (type (marker-insertion-type marker))
  9207. (buffer (marker-buffer marker))
  9208. (pos (marker-position marker))
  9209. ts)
  9210. (set-marker-insertion-type marker t)
  9211. (org-with-remote-undo buffer
  9212. (with-current-buffer buffer
  9213. (widen)
  9214. (goto-char pos)
  9215. (setq ts (org-schedule arg time)))
  9216. (org-agenda-show-new-time marker ts " S"))
  9217. (message "%s" ts))))
  9218. (defun org-agenda-deadline (arg &optional time)
  9219. "Schedule the item at point.
  9220. ARG is passed through to `org-deadline'."
  9221. (interactive "P")
  9222. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9223. (org-agenda-check-no-diary)
  9224. (org-agenda-maybe-loop
  9225. #'org-agenda-deadline arg t nil
  9226. (let* ((marker (or (org-get-at-bol 'org-marker)
  9227. (org-agenda-error)))
  9228. (buffer (marker-buffer marker))
  9229. (pos (marker-position marker))
  9230. ts)
  9231. (org-with-remote-undo buffer
  9232. (with-current-buffer buffer
  9233. (widen)
  9234. (goto-char pos)
  9235. (setq ts (org-deadline arg time)))
  9236. (org-agenda-show-new-time marker ts " D"))
  9237. (message "%s" ts))))
  9238. (defun org-agenda-clock-in (&optional arg)
  9239. "Start the clock on the currently selected item."
  9240. (interactive "P")
  9241. (org-agenda-check-no-diary)
  9242. (if (equal arg '(4))
  9243. (org-clock-in arg)
  9244. (let* ((marker (or (org-get-at-bol 'org-marker)
  9245. (org-agenda-error)))
  9246. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  9247. (pos (marker-position marker))
  9248. (col (current-column))
  9249. newhead)
  9250. (org-with-remote-undo (marker-buffer marker)
  9251. (with-current-buffer (marker-buffer marker)
  9252. (widen)
  9253. (goto-char pos)
  9254. (org-show-context 'agenda)
  9255. (org-clock-in arg)
  9256. (setq newhead (org-get-heading)))
  9257. (org-agenda-change-all-lines newhead hdmarker))
  9258. (org-move-to-column col))))
  9259. (defun org-agenda-clock-out ()
  9260. "Stop the currently running clock."
  9261. (interactive)
  9262. (unless (marker-buffer org-clock-marker)
  9263. (user-error "No running clock"))
  9264. (let ((marker (make-marker)) (col (current-column)) newhead)
  9265. (org-with-remote-undo (marker-buffer org-clock-marker)
  9266. (with-current-buffer (marker-buffer org-clock-marker)
  9267. (org-with-wide-buffer
  9268. (goto-char org-clock-marker)
  9269. (org-back-to-heading t)
  9270. (move-marker marker (point))
  9271. (org-clock-out)
  9272. (setq newhead (org-get-heading)))))
  9273. (org-agenda-change-all-lines newhead marker)
  9274. (move-marker marker nil)
  9275. (org-move-to-column col)
  9276. (org-agenda-unmark-clocking-task)))
  9277. (defun org-agenda-clock-cancel (&optional _arg)
  9278. "Cancel the currently running clock."
  9279. (interactive) ;; "P"
  9280. (unless (marker-buffer org-clock-marker)
  9281. (user-error "No running clock"))
  9282. (org-with-remote-undo (marker-buffer org-clock-marker)
  9283. (org-clock-cancel)))
  9284. (defun org-agenda-clock-goto ()
  9285. "Jump to the currently clocked in task within the agenda.
  9286. If the currently clocked in task is not listed in the agenda
  9287. buffer, display it in another window."
  9288. (interactive)
  9289. (let (pos)
  9290. (mapc (lambda (o)
  9291. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  9292. (setq pos (overlay-start o))))
  9293. (overlays-in (point-min) (point-max)))
  9294. (cond (pos (goto-char pos))
  9295. ;; If the currently clocked entry is not in the agenda
  9296. ;; buffer, we visit it in another window:
  9297. ((bound-and-true-p org-clock-current-task)
  9298. (org-switch-to-buffer-other-window (org-clock-goto)))
  9299. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  9300. (defun org-agenda-diary-entry-in-org-file ()
  9301. "Make a diary entry in the file `org-agenda-diary-file'."
  9302. (let (d1 d2 char (text "") dp1 dp2)
  9303. (if (equal (buffer-name) "*Calendar*")
  9304. (setq d1 (calendar-cursor-to-date t)
  9305. d2 (car calendar-mark-ring))
  9306. (setq dp1 (get-text-property (point-at-bol) 'day))
  9307. (unless dp1 (user-error "No date defined in current line"))
  9308. (setq d1 (calendar-gregorian-from-absolute dp1)
  9309. d2 (and (ignore-errors (mark))
  9310. (save-excursion
  9311. (goto-char (mark))
  9312. (setq dp2 (get-text-property (point-at-bol) 'day)))
  9313. (calendar-gregorian-from-absolute dp2))))
  9314. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  9315. (setq char (read-char-exclusive))
  9316. (cond
  9317. ((equal char ?d)
  9318. (setq text (read-string "Day entry: "))
  9319. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  9320. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9321. ((equal char ?a)
  9322. (setq d1 (list (car d1) (nth 1 d1)
  9323. (read-number (format "Reference year [%d]: " (nth 2 d1))
  9324. (nth 2 d1))))
  9325. (setq text (read-string "Anniversary (use %d to show years): "))
  9326. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  9327. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9328. ((equal char ?b)
  9329. (setq text (read-string "Block entry: "))
  9330. (unless (and d1 d2 (not (equal d1 d2)))
  9331. (user-error "No block of days selected"))
  9332. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  9333. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9334. ((equal char ?j)
  9335. (org-switch-to-buffer-other-window
  9336. (find-file-noselect org-agenda-diary-file))
  9337. (require 'org-datetree)
  9338. (org-datetree-find-date-create d1)
  9339. (org-reveal t))
  9340. (t (user-error "Invalid selection character `%c'" char)))))
  9341. (defcustom org-agenda-insert-diary-strategy 'date-tree
  9342. "Where in `org-agenda-diary-file' should new entries be added?
  9343. Valid values:
  9344. date-tree in the date tree, as first child of the date
  9345. date-tree-last in the date tree, as last child of the date
  9346. top-level as top-level entries at the end of the file."
  9347. :group 'org-agenda
  9348. :type '(choice
  9349. (const :tag "first in a date tree" date-tree)
  9350. (const :tag "last in a date tree" date-tree-last)
  9351. (const :tag "as top level at end of file" top-level)))
  9352. (defcustom org-agenda-insert-diary-extract-time nil
  9353. "Non-nil means extract any time specification from the diary entry."
  9354. :group 'org-agenda
  9355. :version "24.1"
  9356. :type 'boolean)
  9357. (defcustom org-agenda-bulk-mark-char ">"
  9358. "A single-character string to be used as the bulk mark."
  9359. :group 'org-agenda
  9360. :version "24.1"
  9361. :type 'string)
  9362. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  9363. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  9364. If TEXT is not empty, it will become the headline of the new entry, and
  9365. the resulting entry will not be shown. When TEXT is empty, switch to
  9366. `org-agenda-diary-file' and let the user finish the entry there."
  9367. (let ((cw (current-window-configuration)))
  9368. (org-switch-to-buffer-other-window
  9369. (find-file-noselect org-agenda-diary-file))
  9370. (widen)
  9371. (goto-char (point-min))
  9372. (cl-case type
  9373. (anniversary
  9374. (or (re-search-forward "^\\*[ \t]+Anniversaries" nil t)
  9375. (progn
  9376. (or (org-at-heading-p t)
  9377. (progn
  9378. (outline-next-heading)
  9379. (insert "* Anniversaries\n\n")
  9380. (beginning-of-line -1)))))
  9381. (outline-next-heading)
  9382. (org-back-over-empty-lines)
  9383. (backward-char 1)
  9384. (insert "\n")
  9385. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  9386. (nth 2 d1) (car d1) (nth 1 d1) text)))
  9387. (day
  9388. (let ((org-prefix-has-time t)
  9389. (org-agenda-time-leading-zero t)
  9390. fmt time time2)
  9391. (when org-agenda-insert-diary-extract-time
  9392. ;; Use org-agenda-format-item to parse text for a time-range and
  9393. ;; remove it. FIXME: This is a hack, we should refactor
  9394. ;; that function to make time extraction available separately
  9395. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  9396. time (get-text-property 0 'time fmt)
  9397. time2 (if (> (length time) 0)
  9398. ;; split-string removes trailing ...... if
  9399. ;; no end time given. First space
  9400. ;; separates time from date.
  9401. (concat " " (car (split-string time "\\.")))
  9402. nil)
  9403. text (get-text-property 0 'txt fmt)))
  9404. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9405. (org-agenda-insert-diary-as-top-level text)
  9406. (require 'org-datetree)
  9407. (org-datetree-find-date-create d1)
  9408. (org-agenda-insert-diary-make-new-entry text))
  9409. (org-insert-time-stamp (org-time-from-absolute
  9410. (calendar-absolute-from-gregorian d1))
  9411. nil nil nil nil time2))
  9412. (end-of-line 0))
  9413. ((block) ;; Wrap this in (strictly unnecessary) parens because
  9414. ;; otherwise the indentation gets confused by the
  9415. ;; special meaning of 'block
  9416. (when (> (calendar-absolute-from-gregorian d1)
  9417. (calendar-absolute-from-gregorian d2))
  9418. (setq d1 (prog1 d2 (setq d2 d1))))
  9419. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9420. (org-agenda-insert-diary-as-top-level text)
  9421. (require 'org-datetree)
  9422. (org-datetree-find-date-create d1)
  9423. (org-agenda-insert-diary-make-new-entry text))
  9424. (org-insert-time-stamp (org-time-from-absolute
  9425. (calendar-absolute-from-gregorian d1)))
  9426. (insert "--")
  9427. (org-insert-time-stamp (org-time-from-absolute
  9428. (calendar-absolute-from-gregorian d2)))
  9429. (end-of-line 0)))
  9430. (if (string-match "\\S-" text)
  9431. (progn
  9432. (set-window-configuration cw)
  9433. (message "%s entry added to %s"
  9434. (capitalize (symbol-name type))
  9435. (abbreviate-file-name org-agenda-diary-file)))
  9436. (org-reveal t)
  9437. (message "Please finish entry here"))))
  9438. (defun org-agenda-insert-diary-as-top-level (text)
  9439. "Make new entry as a top-level entry at the end of the file.
  9440. Add TEXT as headline, and position the cursor in the second line so that
  9441. a timestamp can be added there."
  9442. (widen)
  9443. (goto-char (point-max))
  9444. (unless (bolp) (insert "\n"))
  9445. (org-insert-heading nil t t)
  9446. (insert text)
  9447. (org-end-of-meta-data)
  9448. (unless (bolp) (insert "\n"))
  9449. (when org-adapt-indentation (indent-to-column 2)))
  9450. (defun org-agenda-insert-diary-make-new-entry (text)
  9451. "Make a new entry with TEXT as a child of the current subtree.
  9452. Position the point in the heading's first body line so that
  9453. a timestamp can be added there."
  9454. (cond
  9455. ((eq org-agenda-insert-diary-strategy 'date-tree-last)
  9456. (end-of-line)
  9457. (org-insert-heading '(4) t)
  9458. (org-do-demote))
  9459. (t
  9460. (outline-next-heading)
  9461. (org-back-over-empty-lines)
  9462. (unless (looking-at "[ \t]*$") (save-excursion (insert "\n")))
  9463. (org-insert-heading nil t)
  9464. (org-do-demote)))
  9465. (let ((col (current-column)))
  9466. (insert text)
  9467. (org-end-of-meta-data)
  9468. ;; Ensure point is left on a blank line, at proper indentation.
  9469. (unless (bolp) (insert "\n"))
  9470. (unless (looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
  9471. (when org-adapt-indentation (indent-to-column col)))
  9472. (org-show-set-visibility 'lineage))
  9473. (defun org-agenda-diary-entry ()
  9474. "Make a diary entry, like the `i' command from the calendar.
  9475. All the standard commands work: block, weekly etc.
  9476. When `org-agenda-diary-file' points to a file,
  9477. `org-agenda-diary-entry-in-org-file' is called instead to create
  9478. entries in that Org file."
  9479. (interactive)
  9480. (if (not (eq org-agenda-diary-file 'diary-file))
  9481. (org-agenda-diary-entry-in-org-file)
  9482. (require 'diary-lib)
  9483. (let* ((char (read-char-exclusive
  9484. "Diary entry: [d]ay [w]eekly [m]onthly [y]early\
  9485. [a]nniversary [b]lock [c]yclic"))
  9486. (cmd (cdr (assoc char
  9487. '((?d . diary-insert-entry)
  9488. (?w . diary-insert-weekly-entry)
  9489. (?m . diary-insert-monthly-entry)
  9490. (?y . diary-insert-yearly-entry)
  9491. (?a . diary-insert-anniversary-entry)
  9492. (?b . diary-insert-block-entry)
  9493. (?c . diary-insert-cyclic-entry)))))
  9494. (oldf (symbol-function 'calendar-cursor-to-date))
  9495. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  9496. (point (point))
  9497. (mark (or (mark t) (point))))
  9498. (unless cmd
  9499. (user-error "No command associated with <%c>" char))
  9500. (unless (and (get-text-property point 'day)
  9501. (or (not (equal ?b char))
  9502. (get-text-property mark 'day)))
  9503. (user-error "Don't know which date to use for diary entry"))
  9504. ;; We implement this by hacking the `calendar-cursor-to-date' function
  9505. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  9506. (let ((calendar-mark-ring
  9507. (list (calendar-gregorian-from-absolute
  9508. (or (get-text-property mark 'day)
  9509. (get-text-property point 'day))))))
  9510. (unwind-protect
  9511. (progn
  9512. (fset 'calendar-cursor-to-date
  9513. (lambda (&optional _error _dummy)
  9514. (calendar-gregorian-from-absolute
  9515. (get-text-property point 'day))))
  9516. (call-interactively cmd))
  9517. (fset 'calendar-cursor-to-date oldf))))))
  9518. (defun org-agenda-execute-calendar-command (cmd)
  9519. "Execute a calendar command from the agenda with date from cursor."
  9520. (org-agenda-check-type t 'agenda)
  9521. (require 'diary-lib)
  9522. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  9523. (user-error "Don't know which date to use for the calendar command"))
  9524. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  9525. (point (point))
  9526. (date (calendar-gregorian-from-absolute
  9527. (get-text-property point 'day))))
  9528. ;; the following 2 vars are needed in the calendar
  9529. (org-dlet
  9530. ((displayed-month (car date))
  9531. (displayed-year (nth 2 date)))
  9532. (unwind-protect
  9533. (progn
  9534. (fset 'calendar-cursor-to-date
  9535. (lambda (&optional _error _dummy)
  9536. (calendar-gregorian-from-absolute
  9537. (get-text-property point 'day))))
  9538. (call-interactively cmd))
  9539. (fset 'calendar-cursor-to-date oldf)))))
  9540. (defun org-agenda-phases-of-moon ()
  9541. "Display the phases of the moon for the 3 months around the cursor date."
  9542. (interactive)
  9543. (org-agenda-execute-calendar-command 'calendar-lunar-phases))
  9544. (defun org-agenda-holidays ()
  9545. "Display the holidays for the 3 months around the cursor date."
  9546. (interactive)
  9547. (org-agenda-execute-calendar-command 'calendar-list-holidays))
  9548. (defvar calendar-longitude) ; defined in calendar.el
  9549. (defvar calendar-latitude) ; defined in calendar.el
  9550. (defvar calendar-location-name) ; defined in calendar.el
  9551. (defun org-agenda-sunrise-sunset (arg)
  9552. "Display sunrise and sunset for the cursor date.
  9553. Latitude and longitude can be specified with the variables
  9554. `calendar-latitude' and `calendar-longitude'. When called with prefix
  9555. argument, latitude and longitude will be prompted for."
  9556. (interactive "P")
  9557. (require 'solar)
  9558. (let ((calendar-longitude (if arg nil calendar-longitude))
  9559. (calendar-latitude (if arg nil calendar-latitude))
  9560. (calendar-location-name
  9561. (if arg "the given coordinates" calendar-location-name)))
  9562. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  9563. (defun org-agenda-goto-calendar ()
  9564. "Open the Emacs calendar with the date at the cursor."
  9565. (interactive)
  9566. (org-agenda-check-type t 'agenda)
  9567. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  9568. (user-error "Don't know which date to open in calendar")))
  9569. (date (calendar-gregorian-from-absolute day))
  9570. (calendar-move-hook nil)
  9571. (calendar-view-holidays-initially-flag nil)
  9572. (calendar-view-diary-initially-flag nil))
  9573. (calendar)
  9574. (calendar-goto-date date)))
  9575. ;;;###autoload
  9576. (defun org-calendar-goto-agenda ()
  9577. "Compute the Org agenda for the calendar date displayed at the cursor.
  9578. This is a command that has to be installed in `calendar-mode-map'."
  9579. (interactive)
  9580. ;; Temporarily disable sticky agenda since user clearly wants to
  9581. ;; refresh view anyway.
  9582. (let ((org-agenda-buffer-tmp-name "*Org Agenda(a)*")
  9583. (org-agenda-sticky nil))
  9584. (org-agenda-list nil (calendar-absolute-from-gregorian
  9585. (calendar-cursor-to-date))
  9586. nil)))
  9587. (defun org-agenda-convert-date ()
  9588. (interactive)
  9589. (org-agenda-check-type t 'agenda)
  9590. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  9591. date s)
  9592. (unless day
  9593. (user-error "Don't know which date to convert"))
  9594. (setq date (calendar-gregorian-from-absolute day))
  9595. (setq s (concat
  9596. "Gregorian: " (calendar-date-string date) "\n"
  9597. "ISO: " (calendar-iso-date-string date) "\n"
  9598. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  9599. "Julian: " (calendar-julian-date-string date) "\n"
  9600. "Astron. JD: " (calendar-astro-date-string date)
  9601. " (Julian date number at noon UTC)\n"
  9602. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  9603. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  9604. "French: " (calendar-french-date-string date) "\n"
  9605. "Bahá’í: " (calendar-bahai-date-string date) " (until sunset)\n"
  9606. "Mayan: " (calendar-mayan-date-string date) "\n"
  9607. "Coptic: " (calendar-coptic-date-string date) "\n"
  9608. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  9609. "Persian: " (calendar-persian-date-string date) "\n"
  9610. "Chinese: " (calendar-chinese-date-string date) "\n"))
  9611. (with-output-to-temp-buffer "*Dates*"
  9612. (princ s))
  9613. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  9614. ;;; Bulk commands
  9615. (defun org-agenda-bulk-marked-p ()
  9616. "Non-nil when current entry is marked for bulk action."
  9617. (eq (get-char-property (point-at-bol) 'type)
  9618. 'org-marked-entry-overlay))
  9619. (defun org-agenda-bulk-mark (&optional arg)
  9620. "Mark entries for future bulk action.
  9621. When ARG is nil or one and region is not active then mark the
  9622. entry at point.
  9623. When ARG is nil or one and region is active then mark the entries
  9624. in the region.
  9625. When ARG is greater than one mark ARG lines."
  9626. (interactive "p")
  9627. (when (and (or (not arg) (= arg 1)) (use-region-p))
  9628. (setq arg (count-lines (region-beginning) (region-end)))
  9629. (goto-char (region-beginning))
  9630. (deactivate-mark))
  9631. (dotimes (_ (or arg 1))
  9632. (unless (org-get-at-bol 'org-agenda-diary-link)
  9633. (let* ((m (org-get-at-bol 'org-hd-marker))
  9634. ov)
  9635. (unless (org-agenda-bulk-marked-p)
  9636. (unless m (user-error "Nothing to mark at point"))
  9637. (push m org-agenda-bulk-marked-entries)
  9638. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  9639. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  9640. (org-get-todo-face "TODO")
  9641. 'evaporate)
  9642. (overlay-put ov 'type 'org-marked-entry-overlay))
  9643. (end-of-line 1)
  9644. (or (ignore-errors
  9645. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  9646. (beginning-of-line 2))
  9647. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9648. (beginning-of-line 2)))))
  9649. (message "%d entries marked for bulk action"
  9650. (length org-agenda-bulk-marked-entries)))
  9651. (defun org-agenda-bulk-mark-all ()
  9652. "Mark all entries for future agenda bulk action."
  9653. (interactive)
  9654. (org-agenda-bulk-mark-regexp "."))
  9655. (defun org-agenda-bulk-mark-regexp (regexp)
  9656. "Mark entries matching REGEXP for future agenda bulk action."
  9657. (interactive "sMark entries matching regexp: ")
  9658. (let ((entries-marked 0) txt-at-point)
  9659. (save-excursion
  9660. (goto-char (point-min))
  9661. (goto-char (next-single-property-change (point) 'org-hd-marker))
  9662. (while (and (re-search-forward regexp nil t)
  9663. (setq txt-at-point
  9664. (get-text-property (match-beginning 0) 'txt)))
  9665. (if (get-char-property (point) 'invisible)
  9666. (beginning-of-line 2)
  9667. (when (string-match-p regexp txt-at-point)
  9668. (setq entries-marked (1+ entries-marked))
  9669. (call-interactively 'org-agenda-bulk-mark)))))
  9670. (unless entries-marked
  9671. (message "No entry matching this regexp."))))
  9672. (defun org-agenda-bulk-unmark (&optional arg)
  9673. "Unmark the entry at point for future bulk action."
  9674. (interactive "P")
  9675. (if arg
  9676. (org-agenda-bulk-unmark-all)
  9677. (cond ((org-agenda-bulk-marked-p)
  9678. (org-agenda-bulk-remove-overlays
  9679. (point-at-bol) (+ 2 (point-at-bol)))
  9680. (setq org-agenda-bulk-marked-entries
  9681. (delete (org-get-at-bol 'org-hd-marker)
  9682. org-agenda-bulk-marked-entries))
  9683. (end-of-line 1)
  9684. (or (ignore-errors
  9685. (goto-char (next-single-property-change (point) 'txt)))
  9686. (beginning-of-line 2))
  9687. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9688. (beginning-of-line 2))
  9689. (message "%d entries left marked for bulk action"
  9690. (length org-agenda-bulk-marked-entries)))
  9691. (t (message "No entry to unmark here")))))
  9692. (defun org-agenda-bulk-toggle-all ()
  9693. "Toggle all marks for bulk action."
  9694. (interactive)
  9695. (save-excursion
  9696. (goto-char (point-min))
  9697. (while (ignore-errors
  9698. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  9699. (org-agenda-bulk-toggle))))
  9700. (defun org-agenda-bulk-toggle ()
  9701. "Toggle the mark at point for bulk action."
  9702. (interactive)
  9703. (if (org-agenda-bulk-marked-p)
  9704. (org-agenda-bulk-unmark)
  9705. (org-agenda-bulk-mark)))
  9706. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  9707. "Remove the mark overlays between BEG and END in the agenda buffer.
  9708. BEG and END default to the buffer limits.
  9709. This only removes the overlays, it does not remove the markers
  9710. from the list in `org-agenda-bulk-marked-entries'."
  9711. (interactive)
  9712. (mapc (lambda (ov)
  9713. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  9714. (delete-overlay ov)))
  9715. (overlays-in (or beg (point-min)) (or end (point-max)))))
  9716. (defun org-agenda-bulk-unmark-all ()
  9717. "Remove all marks in the agenda buffer.
  9718. This will remove the markers and the overlays."
  9719. (interactive)
  9720. (if (null org-agenda-bulk-marked-entries)
  9721. (message "No entry to unmark")
  9722. (setq org-agenda-bulk-marked-entries nil)
  9723. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  9724. (defcustom org-agenda-persistent-marks nil
  9725. "Non-nil means marked items will stay marked after a bulk action.
  9726. You can toggle this interactively by typing `p' when prompted for a
  9727. bulk action."
  9728. :group 'org-agenda
  9729. :version "24.1"
  9730. :type 'boolean)
  9731. (defcustom org-agenda-loop-over-headlines-in-active-region t
  9732. "Shall some commands act upon headlines in the active region?
  9733. When set to t, some commands will be performed in all headlines
  9734. within the active region.
  9735. When set to `start-level', some commands will be performed in all
  9736. headlines within the active region, provided that these headlines
  9737. are of the same level than the first one.
  9738. When set to a regular expression, those commands will be
  9739. performed on the matching headlines within the active region.
  9740. The list of commands is: `org-agenda-schedule',
  9741. `org-agenda-deadline', `org-agenda-date-prompt',
  9742. `org-agenda-todo', `org-agenda-archive*', `org-agenda-kill'.
  9743. See `org-loop-over-headlines-in-active-region' for the equivalent
  9744. option for Org buffers."
  9745. :type '(choice (const :tag "Don't loop" nil)
  9746. (const :tag "All headlines in active region" t)
  9747. (const :tag "In active region, headlines at the same level than the first one" start-level)
  9748. (regexp :tag "Regular expression matcher"))
  9749. :version "27.1"
  9750. :package-version '(Org . "9.4")
  9751. :group 'org-agenda)
  9752. (defun org-agenda-bulk-action (&optional arg)
  9753. "Execute an remote-editing action on all marked entries.
  9754. The prefix arg is passed through to the command if possible."
  9755. (interactive "P")
  9756. ;; When there is no mark, act on the agenda entry at point.
  9757. (if (not org-agenda-bulk-marked-entries)
  9758. (save-excursion (org-agenda-bulk-mark)))
  9759. (dolist (m org-agenda-bulk-marked-entries)
  9760. (unless (and (markerp m)
  9761. (marker-buffer m)
  9762. (buffer-live-p (marker-buffer m))
  9763. (marker-position m))
  9764. (user-error "Marker %s for bulk command is invalid" m)))
  9765. ;; Prompt for the bulk command.
  9766. (org-unlogged-message
  9767. (concat "Bulk (" (if org-agenda-persistent-marks "" "don't ") "[p]ersist marks): "
  9768. "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  9769. "[S]catter [f]unction "
  9770. (and org-agenda-bulk-custom-functions
  9771. (format " Custom: [%s]"
  9772. (mapconcat (lambda (f) (char-to-string (car f)))
  9773. org-agenda-bulk-custom-functions
  9774. "")))))
  9775. (catch 'exit
  9776. (let* ((org-log-refile (if org-log-refile 'time nil))
  9777. (entries (reverse org-agenda-bulk-marked-entries))
  9778. (org-overriding-default-time
  9779. (and (get-text-property (point) 'org-agenda-date-header)
  9780. (org-get-cursor-date)))
  9781. redo-at-end
  9782. cmd)
  9783. (pcase (read-char-exclusive)
  9784. (?p
  9785. (let ((org-agenda-persistent-marks
  9786. (not org-agenda-persistent-marks)))
  9787. (org-agenda-bulk-action)
  9788. (throw 'exit nil)))
  9789. (?$
  9790. (setq cmd #'org-agenda-archive))
  9791. (?A
  9792. (setq cmd #'org-agenda-archive-to-archive-sibling))
  9793. ((or ?r ?w)
  9794. (let ((refile-location
  9795. (org-refile-get-location
  9796. "Refile to"
  9797. (marker-buffer (car entries))
  9798. org-refile-allow-creating-parent-nodes)))
  9799. (when (nth 3 refile-location)
  9800. (setcar (nthcdr 3 refile-location)
  9801. (move-marker
  9802. (make-marker)
  9803. (nth 3 refile-location)
  9804. (or (get-file-buffer (nth 1 refile-location))
  9805. (find-buffer-visiting (nth 1 refile-location))
  9806. (error "This should not happen")))))
  9807. (setq cmd (lambda () (org-agenda-refile nil refile-location t)))
  9808. (setq redo-at-end t)))
  9809. (?t
  9810. (let ((state (completing-read
  9811. "Todo state: "
  9812. (with-current-buffer (marker-buffer (car entries))
  9813. (mapcar #'list org-todo-keywords-1)))))
  9814. (setq cmd (lambda ()
  9815. (let ((org-inhibit-blocking t)
  9816. (org-inhibit-logging 'note))
  9817. (org-agenda-todo state))))))
  9818. ((and (or ?- ?+) action)
  9819. (let ((tag (completing-read
  9820. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  9821. (with-current-buffer (marker-buffer (car entries))
  9822. (delq nil
  9823. (mapcar (lambda (x) (and (stringp (car x)) x))
  9824. org-current-tag-alist))))))
  9825. (setq cmd
  9826. (lambda ()
  9827. (org-agenda-set-tags tag
  9828. (if (eq action ?+) 'on 'off))))))
  9829. ((and (or ?s ?d) c)
  9830. (let* ((schedule? (eq c ?s))
  9831. (prompt (if schedule? "(Re)Schedule to" "(Re)Set Deadline to"))
  9832. (time
  9833. (and (not arg)
  9834. (let ((new (org-read-date
  9835. nil nil nil prompt org-overriding-default-time)))
  9836. ;; A "double plus" answer applies to every
  9837. ;; scheduled time. Do not turn it into
  9838. ;; a fixed date yet.
  9839. (if (string-match-p "\\`[ \t]*\\+\\+"
  9840. org-read-date-final-answer)
  9841. org-read-date-final-answer
  9842. new)))))
  9843. ;; Make sure to not prompt for a note when bulk
  9844. ;; rescheduling/resetting deadline as Org cannot cope with
  9845. ;; simultaneous notes. Besides, it could be annoying
  9846. ;; depending on the number of marked items.
  9847. (setq cmd
  9848. (if schedule?
  9849. (lambda ()
  9850. (let ((org-log-reschedule
  9851. (and org-log-reschedule 'time)))
  9852. (org-agenda-schedule arg time)))
  9853. (lambda ()
  9854. (let ((org-log-redeadline (and org-log-redeadline 'time)))
  9855. (org-agenda-deadline arg time)))))))
  9856. (?S
  9857. (unless (org-agenda-check-type nil 'agenda 'todo)
  9858. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type))
  9859. (let ((days (read-number
  9860. (format "Scatter tasks across how many %sdays: "
  9861. (if arg "week" ""))
  9862. 7)))
  9863. (setq cmd
  9864. (lambda ()
  9865. (let ((distance (1+ (random days))))
  9866. (when arg
  9867. (let ((dist distance)
  9868. (day-of-week
  9869. (calendar-day-of-week
  9870. (calendar-gregorian-from-absolute (org-today)))))
  9871. (dotimes (_ (1+ dist))
  9872. (while (member day-of-week org-agenda-weekend-days)
  9873. (cl-incf distance)
  9874. (cl-incf day-of-week)
  9875. (when (= day-of-week 7)
  9876. (setq day-of-week 0)))
  9877. (cl-incf day-of-week)
  9878. (when (= day-of-week 7)
  9879. (setq day-of-week 0)))))
  9880. ;; Silently fail when try to replan a sexp entry.
  9881. (ignore-errors
  9882. (let* ((date (calendar-gregorian-from-absolute
  9883. (+ (org-today) distance)))
  9884. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  9885. (nth 2 date))))
  9886. (org-agenda-schedule nil time))))))))
  9887. (?f
  9888. (setq cmd
  9889. (intern
  9890. (completing-read "Function: " obarray #'fboundp t nil nil))))
  9891. (action
  9892. (setq cmd
  9893. (pcase (assoc action org-agenda-bulk-custom-functions)
  9894. (`(,_ ,fn)
  9895. fn)
  9896. (`(,_ ,fn ,arg-fn)
  9897. (apply #'apply-partially fn (funcall arg-fn)))
  9898. (_
  9899. (user-error "Invalid bulk action: %c" action))))
  9900. (setq redo-at-end t)))
  9901. ;; Sort the markers, to make sure that parents are handled
  9902. ;; before children.
  9903. (setq entries (sort entries
  9904. (lambda (a b)
  9905. (cond
  9906. ((eq (marker-buffer a) (marker-buffer b))
  9907. (< (marker-position a) (marker-position b)))
  9908. (t
  9909. (string< (buffer-name (marker-buffer a))
  9910. (buffer-name (marker-buffer b))))))))
  9911. ;; Now loop over all markers and apply CMD.
  9912. (let ((processed 0)
  9913. (skipped 0))
  9914. (dolist (e entries)
  9915. (let ((pos (text-property-any (point-min) (point-max) 'org-hd-marker e)))
  9916. (if (not pos)
  9917. (progn (message "Skipping removed entry at %s" e)
  9918. (cl-incf skipped))
  9919. (goto-char pos)
  9920. (let (org-loop-over-headlines-in-active-region) (funcall cmd))
  9921. ;; `post-command-hook' is not run yet. We make sure any
  9922. ;; pending log note is processed.
  9923. (when org-log-setup (org-add-log-note))
  9924. (cl-incf processed))))
  9925. (when redo-at-end (org-agenda-redo))
  9926. (unless org-agenda-persistent-marks (org-agenda-bulk-unmark-all))
  9927. (message "Acted on %d entries%s%s"
  9928. processed
  9929. (if (= skipped 0)
  9930. ""
  9931. (format ", skipped %d (disappeared before their turn)"
  9932. skipped))
  9933. (if (not org-agenda-persistent-marks) "" " (kept marked)"))))))
  9934. (defun org-agenda-capture (&optional with-time)
  9935. "Call `org-capture' with the date at point.
  9936. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  9937. current HH:MM time."
  9938. (interactive "P")
  9939. (if (not (eq major-mode 'org-agenda-mode))
  9940. (user-error "You cannot do this outside of agenda buffers")
  9941. (let ((org-overriding-default-time
  9942. (org-get-cursor-date (equal with-time 1))))
  9943. (call-interactively 'org-capture))))
  9944. ;;; Dragging agenda lines forward/backward
  9945. (defun org-agenda-reapply-filters ()
  9946. "Re-apply all agenda filters."
  9947. (mapcar
  9948. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f) t)))
  9949. `((,org-agenda-tag-filter tag)
  9950. (,org-agenda-category-filter category)
  9951. (,org-agenda-regexp-filter regexp)
  9952. (,org-agenda-effort-filter effort)
  9953. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  9954. (,(get 'org-agenda-category-filter :preset-filter) category)
  9955. (,(get 'org-agenda-effort-filter :preset-filter) effort)
  9956. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  9957. (defun org-agenda-drag-line-forward (arg &optional backward)
  9958. "Drag an agenda line forward by ARG lines.
  9959. When the optional argument `backward' is non-nil, move backward."
  9960. (interactive "p")
  9961. (let ((inhibit-read-only t) lst line)
  9962. (if (or (not (get-text-property (point) 'txt))
  9963. (save-excursion
  9964. (dotimes (_ arg)
  9965. (move-beginning-of-line (if backward 0 2))
  9966. (push (not (get-text-property (point) 'txt)) lst))
  9967. (delq nil lst)))
  9968. (message "Cannot move line forward")
  9969. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  9970. (move-beginning-of-line 1)
  9971. (setq line (buffer-substring (point) end))
  9972. (delete-region (point) end)
  9973. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  9974. (insert line)
  9975. (org-agenda-reapply-filters)
  9976. (org-agenda-mark-clocking-task)
  9977. (move-beginning-of-line 0)))))
  9978. (defun org-agenda-drag-line-backward (arg)
  9979. "Drag an agenda line backward by ARG lines."
  9980. (interactive "p")
  9981. (org-agenda-drag-line-forward arg t))
  9982. ;;; Flagging notes
  9983. (defun org-agenda-show-the-flagging-note ()
  9984. "Display the flagging note in the other window.
  9985. When called a second time in direct sequence, offer to remove the FLAGGING
  9986. tag and (if present) the flagging note."
  9987. (interactive)
  9988. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  9989. (win (selected-window))
  9990. note) ;; heading newhead
  9991. (unless hdmarker
  9992. (user-error "No linked entry at point"))
  9993. (if (and (eq this-command last-command)
  9994. (y-or-n-p "Unflag and remove any flagging note? "))
  9995. (progn
  9996. (org-agenda-remove-flag hdmarker)
  9997. (let ((win (get-buffer-window "*Flagging Note*")))
  9998. (and win (delete-window win)))
  9999. (message "Entry unflagged"))
  10000. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  10001. (unless note
  10002. (user-error "No flagging note"))
  10003. (org-kill-new note)
  10004. (org-switch-to-buffer-other-window "*Flagging Note*")
  10005. (erase-buffer)
  10006. (insert note)
  10007. (goto-char (point-min))
  10008. (while (re-search-forward "\\\\n" nil t)
  10009. (replace-match "\n" t t))
  10010. (goto-char (point-min))
  10011. (select-window win)
  10012. (message "%s" (substitute-command-keys "Flagging note pushed to \
  10013. kill ring. Press `\\[org-agenda-show-the-flagging-note]' again to remove \
  10014. tag and note")))))
  10015. (defun org-agenda-remove-flag (marker)
  10016. "Remove the FLAGGED tag and any flagging note in the entry."
  10017. (let ((newhead
  10018. (org-with-point-at marker
  10019. (org-toggle-tag "FLAGGED" 'off)
  10020. (org-entry-delete nil "THEFLAGGINGNOTE")
  10021. (org-get-heading))))
  10022. (org-agenda-change-all-lines newhead marker)
  10023. (message "Entry unflagged")))
  10024. (defun org-agenda-get-any-marker (&optional pos)
  10025. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  10026. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  10027. ;;; Appointment reminders
  10028. (defvar appt-time-msg-list) ; defined in appt.el
  10029. ;;;###autoload
  10030. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  10031. "Activate appointments found in `org-agenda-files'.
  10032. With a `\\[universal-argument]' prefix, refresh the list of \
  10033. appointments.
  10034. If FILTER is t, interactively prompt the user for a regular
  10035. expression, and filter out entries that don't match it.
  10036. If FILTER is a string, use this string as a regular expression
  10037. for filtering entries out.
  10038. If FILTER is a function, filter out entries against which
  10039. calling the function returns nil. This function takes one
  10040. argument: an entry from `org-agenda-get-day-entries'.
  10041. FILTER can also be an alist with the car of each cell being
  10042. either `headline' or `category'. For example:
  10043. \\='((headline \"IMPORTANT\")
  10044. (category \"Work\"))
  10045. will only add headlines containing IMPORTANT or headlines
  10046. belonging to the \"Work\" category.
  10047. ARGS are symbols indicating what kind of entries to consider.
  10048. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  10049. \(i.e., deadlines and scheduled items with a hh:mm specification)
  10050. and :timestamp entries. See the docstring of `org-diary' for
  10051. details and examples.
  10052. If an entry has a APPT_WARNTIME property, its value will be used
  10053. to override `appt-message-warning-time'."
  10054. (interactive "P")
  10055. (when refresh (setq appt-time-msg-list nil))
  10056. (when (eq filter t)
  10057. (setq filter (read-from-minibuffer "Regexp filter: ")))
  10058. (let* ((cnt 0) ; count added events
  10059. (scope (or args '(:deadline* :scheduled* :timestamp)))
  10060. (org-agenda-new-buffers nil)
  10061. (org-deadline-warning-days 0)
  10062. ;; Do not use `org-today' here because appt only takes
  10063. ;; time and without date as argument, so it may pass wrong
  10064. ;; information otherwise
  10065. (today (org-date-to-gregorian
  10066. (time-to-days nil)))
  10067. (org-agenda-restrict nil)
  10068. (files (org-agenda-files 'unrestricted)) entries file
  10069. (org-agenda-buffer nil))
  10070. ;; Get all entries which may contain an appt
  10071. (org-agenda-prepare-buffers files)
  10072. (while (setq file (pop files))
  10073. (setq entries
  10074. (delq nil
  10075. (append entries
  10076. (apply #'org-agenda-get-day-entries
  10077. file today scope)))))
  10078. ;; Map through entries and find if we should filter them out
  10079. (mapc
  10080. (lambda (x)
  10081. (let* ((evt (org-trim
  10082. (replace-regexp-in-string
  10083. org-link-bracket-re "\\2"
  10084. (or (get-text-property 1 'txt x) ""))))
  10085. (cat (get-text-property (1- (length x)) 'org-category x))
  10086. (tod (get-text-property 1 'time-of-day x))
  10087. (ok (or (null filter)
  10088. (and (stringp filter) (string-match filter evt))
  10089. (and (functionp filter) (funcall filter x))
  10090. (and (listp filter)
  10091. (let ((cat-filter (cadr (assq 'category filter)))
  10092. (evt-filter (cadr (assq 'headline filter))))
  10093. (or (and (stringp cat-filter)
  10094. (string-match cat-filter cat))
  10095. (and (stringp evt-filter)
  10096. (string-match evt-filter evt)))))))
  10097. (wrn (get-text-property 1 'warntime x)))
  10098. ;; FIXME: Shall we remove text-properties for the appt text?
  10099. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  10100. (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
  10101. (setq tod (concat "00" (number-to-string tod)))
  10102. (setq tod (when (string-match
  10103. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  10104. (concat (match-string 1 tod) ":"
  10105. (match-string 2 tod))))
  10106. (when (appt-add tod evt wrn)
  10107. (setq cnt (1+ cnt))))))
  10108. entries)
  10109. (org-release-buffers org-agenda-new-buffers)
  10110. (if (eq cnt 0)
  10111. (message "No event to add")
  10112. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  10113. (defun org-agenda-today-p (date)
  10114. "Non-nil when DATE means today.
  10115. DATE is either a list of the form (month day year) or a number of
  10116. days as returned by `calendar-absolute-from-gregorian' or
  10117. `org-today'. This function considers `org-extend-today-until'
  10118. when defining today."
  10119. (eq (org-today)
  10120. (if (consp date) (calendar-absolute-from-gregorian date) date)))
  10121. (defun org-agenda-todo-yesterday (&optional arg)
  10122. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  10123. (interactive "P")
  10124. (let* ((org-use-effective-time t)
  10125. (hour (nth 2 (decode-time (org-current-time))))
  10126. (org-extend-today-until (1+ hour)))
  10127. (org-agenda-todo arg)))
  10128. (defun org-agenda-ctrl-c-ctrl-c ()
  10129. "Set tags in agenda buffer."
  10130. (interactive)
  10131. (org-agenda-set-tags))
  10132. (provide 'org-agenda)
  10133. ;;; org-agenda.el ends here